Skip to content

Commit

Permalink
Fix the calculation of page count to (un)map
Browse files Browse the repository at this point in the history
The offset within a page must be taken into the account when
calculating the number of pages. As there might be descriptors
with size < PAGE_SIZE and size + offset > PAGE_SIZE. Applicable
to both foreign and grant mappins.

Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
  • Loading branch information
Oleksandr Tyshchenko committed Jan 26, 2024
1 parent 89dda20 commit 274f5e9
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions demu.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ demu_map_guest_range(uint64_t addr, uint64_t size, int prot)
unsigned int i, n;
void *ptr;

size += addr & ~TARGET_PAGE_MASK;
size = P2ROUNDUP(size, TARGET_PAGE_SIZE);
n = size >> TARGET_PAGE_SHIFT;

Expand Down Expand Up @@ -271,6 +272,7 @@ demu_unmap_guest_range(void *ptr, uint64_t size)
{
unsigned int n;

size += (unsigned long)ptr & ~TARGET_PAGE_MASK;
size = P2ROUNDUP(size, TARGET_PAGE_SIZE);
n = size >> TARGET_PAGE_SHIFT;

Expand Down

0 comments on commit 274f5e9

Please sign in to comment.