diff options
-rw-r--r-- | arch/x86/include/asm/pgtable-2level.h | 50 | ||||
-rw-r--r-- | arch/x86/include/asm/pgtable-3level.h | 1 | ||||
-rw-r--r-- | arch/x86/include/asm/pgtable.h | 14 | ||||
-rw-r--r-- | arch/x86/include/asm/pgtable_64.h | 20 | ||||
-rw-r--r-- | mm/swapfile.c | 9 |
5 files changed, 75 insertions, 19 deletions
diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h index b17edfd23628..e0d199fe1d83 100644 --- a/arch/x86/include/asm/pgtable-2level.h +++ b/arch/x86/include/asm/pgtable-2level.h | |||
@@ -56,23 +56,55 @@ static inline pte_t native_ptep_get_and_clear(pte_t *xp) | |||
56 | #define pte_none(x) (!(x).pte_low) | 56 | #define pte_none(x) (!(x).pte_low) |
57 | 57 | ||
58 | /* | 58 | /* |
59 | * Bits 0, 6 and 7 are taken, split up the 29 bits of offset | 59 | * Bits _PAGE_BIT_PRESENT, _PAGE_BIT_FILE and _PAGE_BIT_PROTNONE are taken, |
60 | * into this range: | 60 | * split up the 29 bits of offset into this range: |
61 | */ | 61 | */ |
62 | #define PTE_FILE_MAX_BITS 29 | 62 | #define PTE_FILE_MAX_BITS 29 |
63 | #define PTE_FILE_SHIFT1 (_PAGE_BIT_PRESENT + 1) | ||
64 | #if _PAGE_BIT_FILE < _PAGE_BIT_PROTNONE | ||
65 | #define PTE_FILE_SHIFT2 (_PAGE_BIT_FILE + 1) | ||
66 | #define PTE_FILE_SHIFT3 (_PAGE_BIT_PROTNONE + 1) | ||
67 | #else | ||
68 | #define PTE_FILE_SHIFT2 (_PAGE_BIT_PROTNONE + 1) | ||
69 | #define PTE_FILE_SHIFT3 (_PAGE_BIT_FILE + 1) | ||
70 | #endif | ||
71 | #define PTE_FILE_BITS1 (PTE_FILE_SHIFT2 - PTE_FILE_SHIFT1 - 1) | ||
72 | #define PTE_FILE_BITS2 (PTE_FILE_SHIFT3 - PTE_FILE_SHIFT2 - 1) | ||
63 | 73 | ||
64 | #define pte_to_pgoff(pte) \ | 74 | #define pte_to_pgoff(pte) \ |
65 | ((((pte).pte_low >> 1) & 0x1f) + (((pte).pte_low >> 8) << 5)) | 75 | ((((pte).pte_low >> PTE_FILE_SHIFT1) \ |
76 | & ((1U << PTE_FILE_BITS1) - 1)) \ | ||
77 | + ((((pte).pte_low >> PTE_FILE_SHIFT2) \ | ||
78 | & ((1U << PTE_FILE_BITS2) - 1)) << PTE_FILE_BITS1) \ | ||
79 | + (((pte).pte_low >> PTE_FILE_SHIFT3) \ | ||
80 | << (PTE_FILE_BITS1 + PTE_FILE_BITS2))) | ||
66 | 81 | ||
67 | #define pgoff_to_pte(off) \ | 82 | #define pgoff_to_pte(off) \ |
68 | ((pte_t) { .pte_low = (((off) & 0x1f) << 1) + \ | 83 | ((pte_t) { .pte_low = \ |
69 | (((off) >> 5) << 8) + _PAGE_FILE }) | 84 | (((off) & ((1U << PTE_FILE_BITS1) - 1)) << PTE_FILE_SHIFT1) \ |
85 | + ((((off) >> PTE_FILE_BITS1) & ((1U << PTE_FILE_BITS2) - 1)) \ | ||
86 | << PTE_FILE_SHIFT2) \ | ||
87 | + (((off) >> (PTE_FILE_BITS1 + PTE_FILE_BITS2)) \ | ||
88 | << PTE_FILE_SHIFT3) \ | ||
89 | + _PAGE_FILE }) | ||
70 | 90 | ||
71 | /* Encode and de-code a swap entry */ | 91 | /* Encode and de-code a swap entry */ |
72 | #define __swp_type(x) (((x).val >> 1) & 0x1f) | 92 | #if _PAGE_BIT_FILE < _PAGE_BIT_PROTNONE |
73 | #define __swp_offset(x) ((x).val >> 8) | 93 | #define SWP_TYPE_BITS (_PAGE_BIT_FILE - _PAGE_BIT_PRESENT - 1) |
74 | #define __swp_entry(type, offset) \ | 94 | #define SWP_OFFSET_SHIFT (_PAGE_BIT_PROTNONE + 1) |
75 | ((swp_entry_t) { ((type) << 1) | ((offset) << 8) }) | 95 | #else |
96 | #define SWP_TYPE_BITS (_PAGE_BIT_PROTNONE - _PAGE_BIT_PRESENT - 1) | ||
97 | #define SWP_OFFSET_SHIFT (_PAGE_BIT_FILE + 1) | ||
98 | #endif | ||
99 | |||
100 | #define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS) | ||
101 | |||
102 | #define __swp_type(x) (((x).val >> (_PAGE_BIT_PRESENT + 1)) \ | ||
103 | & ((1U << SWP_TYPE_BITS) - 1)) | ||
104 | #define __swp_offset(x) ((x).val >> SWP_OFFSET_SHIFT) | ||
105 | #define __swp_entry(type, offset) ((swp_entry_t) { \ | ||
106 | ((type) << (_PAGE_BIT_PRESENT + 1)) \ | ||
107 | | ((offset) << SWP_OFFSET_SHIFT) }) | ||
76 | #define __pte_to_swp_entry(pte) ((swp_entry_t) { (pte).pte_low }) | 108 | #define __pte_to_swp_entry(pte) ((swp_entry_t) { (pte).pte_low }) |
77 | #define __swp_entry_to_pte(x) ((pte_t) { .pte = (x).val }) | 109 | #define __swp_entry_to_pte(x) ((pte_t) { .pte = (x).val }) |
78 | 110 | ||
diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h index 52597aeadfff..447da43cddb3 100644 --- a/arch/x86/include/asm/pgtable-3level.h +++ b/arch/x86/include/asm/pgtable-3level.h | |||
@@ -166,6 +166,7 @@ static inline int pte_none(pte_t pte) | |||
166 | #define PTE_FILE_MAX_BITS 32 | 166 | #define PTE_FILE_MAX_BITS 32 |
167 | 167 | ||
168 | /* Encode and de-code a swap entry */ | 168 | /* Encode and de-code a swap entry */ |
169 | #define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > 5) | ||
169 | #define __swp_type(x) (((x).val) & 0x1f) | 170 | #define __swp_type(x) (((x).val) & 0x1f) |
170 | #define __swp_offset(x) ((x).val >> 5) | 171 | #define __swp_offset(x) ((x).val >> 5) |
171 | #define __swp_entry(type, offset) ((swp_entry_t){(type) | (offset) << 5}) | 172 | #define __swp_entry(type, offset) ((swp_entry_t){(type) | (offset) << 5}) |
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index c012f3b11671..b7c2ecdb7658 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h | |||
@@ -10,7 +10,6 @@ | |||
10 | #define _PAGE_BIT_PCD 4 /* page cache disabled */ | 10 | #define _PAGE_BIT_PCD 4 /* page cache disabled */ |
11 | #define _PAGE_BIT_ACCESSED 5 /* was accessed (raised by CPU) */ | 11 | #define _PAGE_BIT_ACCESSED 5 /* was accessed (raised by CPU) */ |
12 | #define _PAGE_BIT_DIRTY 6 /* was written to (raised by CPU) */ | 12 | #define _PAGE_BIT_DIRTY 6 /* was written to (raised by CPU) */ |
13 | #define _PAGE_BIT_FILE 6 | ||
14 | #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */ | 13 | #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */ |
15 | #define _PAGE_BIT_PAT 7 /* on 4KB pages */ | 14 | #define _PAGE_BIT_PAT 7 /* on 4KB pages */ |
16 | #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */ | 15 | #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */ |
@@ -22,6 +21,12 @@ | |||
22 | #define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1 | 21 | #define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1 |
23 | #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */ | 22 | #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */ |
24 | 23 | ||
24 | /* If _PAGE_BIT_PRESENT is clear, we use these: */ | ||
25 | /* - if the user mapped it with PROT_NONE; pte_present gives true */ | ||
26 | #define _PAGE_BIT_PROTNONE _PAGE_BIT_GLOBAL | ||
27 | /* - set: nonlinear file mapping, saved PTE; unset:swap */ | ||
28 | #define _PAGE_BIT_FILE _PAGE_BIT_DIRTY | ||
29 | |||
25 | #define _PAGE_PRESENT (_AT(pteval_t, 1) << _PAGE_BIT_PRESENT) | 30 | #define _PAGE_PRESENT (_AT(pteval_t, 1) << _PAGE_BIT_PRESENT) |
26 | #define _PAGE_RW (_AT(pteval_t, 1) << _PAGE_BIT_RW) | 31 | #define _PAGE_RW (_AT(pteval_t, 1) << _PAGE_BIT_RW) |
27 | #define _PAGE_USER (_AT(pteval_t, 1) << _PAGE_BIT_USER) | 32 | #define _PAGE_USER (_AT(pteval_t, 1) << _PAGE_BIT_USER) |
@@ -46,11 +51,8 @@ | |||
46 | #define _PAGE_NX (_AT(pteval_t, 0)) | 51 | #define _PAGE_NX (_AT(pteval_t, 0)) |
47 | #endif | 52 | #endif |
48 | 53 | ||
49 | /* If _PAGE_PRESENT is clear, we use these: */ | 54 | #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE) |
50 | #define _PAGE_FILE _PAGE_DIRTY /* nonlinear file mapping, | 55 | #define _PAGE_PROTNONE (_AT(pteval_t, 1) << _PAGE_BIT_PROTNONE) |
51 | * saved PTE; unset:swap */ | ||
52 | #define _PAGE_PROTNONE _PAGE_PSE /* if the user mapped it with PROT_NONE; | ||
53 | pte_present gives true */ | ||
54 | 56 | ||
55 | #define _PAGE_TABLE (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | \ | 57 | #define _PAGE_TABLE (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | \ |
56 | _PAGE_ACCESSED | _PAGE_DIRTY) | 58 | _PAGE_ACCESSED | _PAGE_DIRTY) |
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) | |||
250 | extern int direct_gbpages; | 250 | extern 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 | ||
diff --git a/mm/swapfile.c b/mm/swapfile.c index 90cb67a5417c..54a9f87e5162 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c | |||
@@ -1462,6 +1462,15 @@ static int __init procswaps_init(void) | |||
1462 | __initcall(procswaps_init); | 1462 | __initcall(procswaps_init); |
1463 | #endif /* CONFIG_PROC_FS */ | 1463 | #endif /* CONFIG_PROC_FS */ |
1464 | 1464 | ||
1465 | #ifdef MAX_SWAPFILES_CHECK | ||
1466 | static int __init max_swapfiles_check(void) | ||
1467 | { | ||
1468 | MAX_SWAPFILES_CHECK(); | ||
1469 | return 0; | ||
1470 | } | ||
1471 | late_initcall(max_swapfiles_check); | ||
1472 | #endif | ||
1473 | |||
1465 | /* | 1474 | /* |
1466 | * Written 01/25/92 by Simmule Turner, heavily changed by Linus. | 1475 | * Written 01/25/92 by Simmule Turner, heavily changed by Linus. |
1467 | * | 1476 | * |