Skip to content

Commit

Permalink
mm: make generic pXd_addr_end() macros inline functions
Browse files Browse the repository at this point in the history
Since pXd_addr_end() macros take pXd page-table entry as a
parameter it makes sense to check the entry type on compile.
Even though most archs do not make use of page-table entries
in pXd_addr_end() calls, checking the type in traversal code
paths could help to avoid subtle bugs.

Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
  • Loading branch information
Alexander Gordeev authored and intel-lab-lkp committed Sep 7, 2020
1 parent faf6094 commit b01038f
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions include/linux/pgtable.h
Expand Up @@ -656,31 +656,35 @@ static inline int arch_unmap_one(struct mm_struct *mm,
*/

#ifndef pgd_addr_end
#define pgd_addr_end(pgd, addr, end) \
({ unsigned long __boundary = ((addr) + PGDIR_SIZE) & PGDIR_MASK; \
(__boundary - 1 < (end) - 1)? __boundary: (end); \
})
#define pgd_addr_end pgd_addr_end
static inline unsigned long pgd_addr_end(pgd_t pgd, unsigned long addr, unsigned long end)
{ unsigned long __boundary = (addr + PGDIR_SIZE) & PGDIR_MASK;
return (__boundary - 1 < end - 1) ? __boundary : end;
}
#endif

#ifndef p4d_addr_end
#define p4d_addr_end(p4d, addr, end) \
({ unsigned long __boundary = ((addr) + P4D_SIZE) & P4D_MASK; \
(__boundary - 1 < (end) - 1)? __boundary: (end); \
})
#define p4d_addr_end p4d_addr_end
static inline unsigned long p4d_addr_end(p4d_t p4d, unsigned long addr, unsigned long end)
{ unsigned long __boundary = (addr + P4D_SIZE) & P4D_MASK;
return (__boundary - 1 < end - 1) ? __boundary : end;
}
#endif

#ifndef pud_addr_end
#define pud_addr_end(pud, addr, end) \
({ unsigned long __boundary = ((addr) + PUD_SIZE) & PUD_MASK; \
(__boundary - 1 < (end) - 1)? __boundary: (end); \
})
#define pud_addr_end pud_addr_end
static inline unsigned long pud_addr_end(pud_t pud, unsigned long addr, unsigned long end)
{ unsigned long __boundary = (addr + PUD_SIZE) & PUD_MASK;
return (__boundary - 1 < end - 1) ? __boundary : end;
}
#endif

#ifndef pmd_addr_end
#define pmd_addr_end(pmd, addr, end) \
({ unsigned long __boundary = ((addr) + PMD_SIZE) & PMD_MASK; \
(__boundary - 1 < (end) - 1)? __boundary: (end); \
})
#define pmd_addr_end pmd_addr_end
static inline unsigned long pmd_addr_end(pmd_t pmd, unsigned long addr, unsigned long end)
{ unsigned long __boundary = (addr + PMD_SIZE) & PMD_MASK;
return (__boundary - 1 < end - 1) ? __boundary : end;
}
#endif

/*
Expand Down

0 comments on commit b01038f

Please sign in to comment.