aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/include/asm/pgtable_64.h
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@novell.com>2008-12-16 06:35:24 -0500
committerIngo Molnar <mingo@elte.hu>2008-12-16 12:34:51 -0500
commit1796316a8b028a148be48ba5d4e7be493a39d173 (patch)
tree628848bb98909632bbb503b1db27c2a6db9291e6 /arch/x86/include/asm/pgtable_64.h
parent9470565579f29486f4ed0ffa50774268b64994b0 (diff)
x86: consolidate __swp_XXX() macros
Impact: cleanup, code robustization The __swp_...() macros silently relied upon which bits are used for _PAGE_FILE and _PAGE_PROTNONE. After having changed _PAGE_PROTNONE in our Xen kernel to no longer overlap _PAGE_PAT, live locks and crashes were reported that could have been avoided if these macros properly used the symbolic constants. Since, as pointed out earlier, for Xen Dom0 support mainline likewise will need to eliminate the conflict between _PAGE_PAT and _PAGE_PROTNONE, this patch does all the necessary adjustments, plus it introduces a mechanism to check consistency between MAX_SWAPFILES_SHIFT and the actual encoding macros. This also fixes a latent bug in that x86-64 used a 6-bit mask in __swp_type(), and if MAX_SWAPFILES_SHIFT was increased beyond 5 in (the seemingly unrelated) linux/swap.h, this would have resulted in a collision with _PAGE_FILE. Non-PAE 32-bit code gets similarly adjusted for its pte_to_pgoff() and pgoff_to_pte() calculations. Signed-off-by: Jan Beulich <jbeulich@novell.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/x86/include/asm/pgtable_64.h')
-rw-r--r--arch/x86/include/asm/pgtable_64.h20
1 files changed, 16 insertions, 4 deletions
diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
index 545a0e042bb2..65b6be6677c7 100644
--- a/arch/x86/include/asm/pgtable_64.h
+++ b/arch/x86/include/asm/pgtable_64.h
@@ -250,10 +250,22 @@ static inline int pud_large(pud_t pte)
250extern int direct_gbpages; 250extern int direct_gbpages;
251 251
252/* Encode and de-code a swap entry */ 252/* Encode and de-code a swap entry */
253#define __swp_type(x) (((x).val >> 1) & 0x3f) 253#if _PAGE_BIT_FILE < _PAGE_BIT_PROTNONE
254#define __swp_offset(x) ((x).val >> 8) 254#define SWP_TYPE_BITS (_PAGE_BIT_FILE - _PAGE_BIT_PRESENT - 1)
255#define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 1) | \ 255#define SWP_OFFSET_SHIFT (_PAGE_BIT_PROTNONE + 1)
256 ((offset) << 8) }) 256#else
257#define SWP_TYPE_BITS (_PAGE_BIT_PROTNONE - _PAGE_BIT_PRESENT - 1)
258#define SWP_OFFSET_SHIFT (_PAGE_BIT_FILE + 1)
259#endif
260
261#define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS)
262
263#define __swp_type(x) (((x).val >> (_PAGE_BIT_PRESENT + 1)) \
264 & ((1U << SWP_TYPE_BITS) - 1))
265#define __swp_offset(x) ((x).val >> SWP_OFFSET_SHIFT)
266#define __swp_entry(type, offset) ((swp_entry_t) { \
267 ((type) << (_PAGE_BIT_PRESENT + 1)) \
268 | ((offset) << SWP_OFFSET_SHIFT) })
257#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val((pte)) }) 269#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val((pte)) })
258#define __swp_entry_to_pte(x) ((pte_t) { .pte = (x).val }) 270#define __swp_entry_to_pte(x) ((pte_t) { .pte = (x).val })
259 271