Skip to content

Commit

Permalink
arch, pagetables: fix IS_ADDR_SPACE_VA() macro
Browse files Browse the repository at this point in the history
The IS_ADDR_SPACE_VA() macro was using incorrect comparison for an
address belonging to an address space. Masking (&) could return
incorrect result for a shifted user address space mappings.

Signed-off-by: Pawel Wieczorkiewicz <[email protected]>
  • Loading branch information
wipawel committed Jul 11, 2022
1 parent 6f8cc20 commit a53e1b4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/arch/x86/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ typedef unsigned long mfn_t;
#define PADDR_INVALID (0UL)
#define MFN_INVALID (0UL)

#define IS_ADDR_SPACE_VA(va, as) ((_ul(va) & (as)) == (as))
#define IS_ADDR_SPACE_VA(va, as) (_ul(va) >= (as))

/* External declarations */

Expand Down Expand Up @@ -210,6 +210,7 @@ static inline void *mfn_to_virt(mfn_t mfn) { return paddr_to_virt(mfn << PAGE_SH
static inline paddr_t virt_to_paddr(const void *va) {
paddr_t pa = (paddr_t) va;

/* Order matters here */
if (IS_ADDR_SPACE_VA(va, VIRT_KERNEL_BASE))
return pa - VIRT_KERNEL_BASE;
if (IS_ADDR_SPACE_VA(va, VIRT_KERNEL_MAP))
Expand Down

0 comments on commit a53e1b4

Please sign in to comment.