diff options
| author | Hugh Dickins <hugh@veritas.com> | 2005-03-13 00:17:41 -0800 |
|---|---|---|
| committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-03-13 00:17:41 -0800 |
| commit | 5ba3dbb4cc71d11064061b4b4eb744e09aa6c2b1 (patch) | |
| tree | 83dfd8c9c372f357ce944955efa4d0e22d7b7413 /include/asm-generic | |
| parent | ec24decb0630105ef24cd12af1b90f636819d0a0 (diff) | |
[PATCH] ptwalk: change_protection
Begin the pagetable walker cleanup with a straightforward example,
mprotect's change_protection. Started out from Nick Piggin's for_each
proposal, but I prefer less hidden; and these are all do while loops,
which degrade slightly when converted to for loops.
Firmly agree with Andi and Nick that addr,end is the way to go: size is
good at the user interface level, but unhelpful down in the loops. And
the habit of an "address" which is actually an offset from some base has
bitten us several times: use proper address at each level, whyever not?
Don't apply each mask at two levels: all we need is a set of macros
pgd_addr_end, pud_addr_end, pmd_addr_end to give the address of the end
of each range. Which need to take the min of two addresses, with 0 as
the greatest. Started out with a different macro, assumed end never 0;
but clear_page_range (alone) might be passed end 0 by some out-of-tree
memory layouts: could special case it, but this macro compiles smaller.
Check "addr != end" instead of "addr < end" to work on that end 0 case.
Signed-off-by: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include/asm-generic')
| -rw-r--r-- | include/asm-generic/pgtable.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h index b9d72dd2996e..20f401dcffda 100644 --- a/include/asm-generic/pgtable.h +++ b/include/asm-generic/pgtable.h @@ -135,6 +135,27 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addres #define pgd_offset_gate(mm, addr) pgd_offset(mm, addr) #endif +/* + * When walking page tables, get the address of the next boundary, or + * the end address of the range if that comes earlier. Although end might + * wrap to 0 only in clear_page_range, __boundary may wrap to 0 throughout. + */ + +#define pgd_addr_end(addr, end) \ +({ unsigned long __boundary = ((addr) + PGDIR_SIZE) & PGDIR_MASK; \ + (__boundary - 1 < (end) - 1)? __boundary: (end); \ +}) + +#define pud_addr_end(addr, end) \ +({ unsigned long __boundary = ((addr) + PUD_SIZE) & PUD_MASK; \ + (__boundary - 1 < (end) - 1)? __boundary: (end); \ +}) + +#define pmd_addr_end(addr, end) \ +({ unsigned long __boundary = ((addr) + PMD_SIZE) & PMD_MASK; \ + (__boundary - 1 < (end) - 1)? __boundary: (end); \ +}) + #ifndef __ASSEMBLY__ /* * When walking page tables, we usually want to skip any p?d_none entries; |
