Skip to content

Commit 8bd6964

Browse files
committed
Merge branch 'x86-mm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 mm changes from Ingo Molnar: "A cleanup, a fix and ASLR support for hugetlb mappings" * 'x86-mm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/mm/numa: Fix 32-bit kernel NUMA boot x86/mm: Implement ASLR for hugetlb mappings x86/mm: Unify pte_to_pgoff() and pgoff_to_pte() helpers
2 parents 2bb2c5e + f3d815c commit 8bd6964

File tree

5 files changed

+70
-54
lines changed

5 files changed

+70
-54
lines changed

arch/x86/include/asm/page.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ extern bool __virt_addr_valid(unsigned long kaddr);
7171
#include <asm-generic/getorder.h>
7272

7373
#define __HAVE_ARCH_GATE_AREA 1
74+
#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
7475

7576
#endif /* __KERNEL__ */
7677
#endif /* _ASM_X86_PAGE_H */

arch/x86/include/asm/page_32.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55

66
#ifndef __ASSEMBLY__
77

8-
#ifdef CONFIG_HUGETLB_PAGE
9-
#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
10-
#endif
11-
128
#define __phys_addr_nodebug(x) ((x) - PAGE_OFFSET)
139
#ifdef CONFIG_DEBUG_VIRTUAL
1410
extern unsigned long __phys_addr(unsigned long);

arch/x86/include/asm/pgtable-2level.h

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
5555
#define native_pmdp_get_and_clear(xp) native_local_pmdp_get_and_clear(xp)
5656
#endif
5757

58+
/* Bit manipulation helper on pte/pgoff entry */
59+
static inline unsigned long pte_bitop(unsigned long value, unsigned int rightshift,
60+
unsigned long mask, unsigned int leftshift)
61+
{
62+
return ((value >> rightshift) & mask) << leftshift;
63+
}
64+
5865
#ifdef CONFIG_MEM_SOFT_DIRTY
5966

6067
/*
@@ -71,31 +78,34 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
7178
#define PTE_FILE_BITS2 (PTE_FILE_SHIFT3 - PTE_FILE_SHIFT2 - 1)
7279
#define PTE_FILE_BITS3 (PTE_FILE_SHIFT4 - PTE_FILE_SHIFT3 - 1)
7380

74-
#define pte_to_pgoff(pte) \
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)) \
79-
<< (PTE_FILE_BITS1)) \
80-
+ ((((pte).pte_low >> (PTE_FILE_SHIFT3)) \
81-
& ((1U << PTE_FILE_BITS3) - 1)) \
82-
<< (PTE_FILE_BITS1 + PTE_FILE_BITS2)) \
83-
+ ((((pte).pte_low >> (PTE_FILE_SHIFT4))) \
84-
<< (PTE_FILE_BITS1 + PTE_FILE_BITS2 + PTE_FILE_BITS3))
85-
86-
#define pgoff_to_pte(off) \
87-
((pte_t) { .pte_low = \
88-
((((off)) & ((1U << PTE_FILE_BITS1) - 1)) << PTE_FILE_SHIFT1) \
89-
+ ((((off) >> PTE_FILE_BITS1) \
90-
& ((1U << PTE_FILE_BITS2) - 1)) \
91-
<< PTE_FILE_SHIFT2) \
92-
+ ((((off) >> (PTE_FILE_BITS1 + PTE_FILE_BITS2)) \
93-
& ((1U << PTE_FILE_BITS3) - 1)) \
94-
<< PTE_FILE_SHIFT3) \
95-
+ ((((off) >> \
96-
(PTE_FILE_BITS1 + PTE_FILE_BITS2 + PTE_FILE_BITS3))) \
97-
<< PTE_FILE_SHIFT4) \
98-
+ _PAGE_FILE })
81+
#define PTE_FILE_MASK1 ((1U << PTE_FILE_BITS1) - 1)
82+
#define PTE_FILE_MASK2 ((1U << PTE_FILE_BITS2) - 1)
83+
#define PTE_FILE_MASK3 ((1U << PTE_FILE_BITS3) - 1)
84+
85+
#define PTE_FILE_LSHIFT2 (PTE_FILE_BITS1)
86+
#define PTE_FILE_LSHIFT3 (PTE_FILE_BITS1 + PTE_FILE_BITS2)
87+
#define PTE_FILE_LSHIFT4 (PTE_FILE_BITS1 + PTE_FILE_BITS2 + PTE_FILE_BITS3)
88+
89+
static __always_inline pgoff_t pte_to_pgoff(pte_t pte)
90+
{
91+
return (pgoff_t)
92+
(pte_bitop(pte.pte_low, PTE_FILE_SHIFT1, PTE_FILE_MASK1, 0) +
93+
pte_bitop(pte.pte_low, PTE_FILE_SHIFT2, PTE_FILE_MASK2, PTE_FILE_LSHIFT2) +
94+
pte_bitop(pte.pte_low, PTE_FILE_SHIFT3, PTE_FILE_MASK3, PTE_FILE_LSHIFT3) +
95+
pte_bitop(pte.pte_low, PTE_FILE_SHIFT4, -1UL, PTE_FILE_LSHIFT4));
96+
}
97+
98+
static __always_inline pte_t pgoff_to_pte(pgoff_t off)
99+
{
100+
return (pte_t){
101+
.pte_low =
102+
pte_bitop(off, 0, PTE_FILE_MASK1, PTE_FILE_SHIFT1) +
103+
pte_bitop(off, PTE_FILE_LSHIFT2, PTE_FILE_MASK2, PTE_FILE_SHIFT2) +
104+
pte_bitop(off, PTE_FILE_LSHIFT3, PTE_FILE_MASK3, PTE_FILE_SHIFT3) +
105+
pte_bitop(off, PTE_FILE_LSHIFT4, -1UL, PTE_FILE_SHIFT4) +
106+
_PAGE_FILE,
107+
};
108+
}
99109

100110
#else /* CONFIG_MEM_SOFT_DIRTY */
101111

@@ -115,22 +125,30 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
115125
#define PTE_FILE_BITS1 (PTE_FILE_SHIFT2 - PTE_FILE_SHIFT1 - 1)
116126
#define PTE_FILE_BITS2 (PTE_FILE_SHIFT3 - PTE_FILE_SHIFT2 - 1)
117127

118-
#define pte_to_pgoff(pte) \
119-
((((pte).pte_low >> PTE_FILE_SHIFT1) \
120-
& ((1U << PTE_FILE_BITS1) - 1)) \
121-
+ ((((pte).pte_low >> PTE_FILE_SHIFT2) \
122-
& ((1U << PTE_FILE_BITS2) - 1)) << PTE_FILE_BITS1) \
123-
+ (((pte).pte_low >> PTE_FILE_SHIFT3) \
124-
<< (PTE_FILE_BITS1 + PTE_FILE_BITS2)))
125-
126-
#define pgoff_to_pte(off) \
127-
((pte_t) { .pte_low = \
128-
(((off) & ((1U << PTE_FILE_BITS1) - 1)) << PTE_FILE_SHIFT1) \
129-
+ ((((off) >> PTE_FILE_BITS1) & ((1U << PTE_FILE_BITS2) - 1)) \
130-
<< PTE_FILE_SHIFT2) \
131-
+ (((off) >> (PTE_FILE_BITS1 + PTE_FILE_BITS2)) \
132-
<< PTE_FILE_SHIFT3) \
133-
+ _PAGE_FILE })
128+
#define PTE_FILE_MASK1 ((1U << PTE_FILE_BITS1) - 1)
129+
#define PTE_FILE_MASK2 ((1U << PTE_FILE_BITS2) - 1)
130+
131+
#define PTE_FILE_LSHIFT2 (PTE_FILE_BITS1)
132+
#define PTE_FILE_LSHIFT3 (PTE_FILE_BITS1 + PTE_FILE_BITS2)
133+
134+
static __always_inline pgoff_t pte_to_pgoff(pte_t pte)
135+
{
136+
return (pgoff_t)
137+
(pte_bitop(pte.pte_low, PTE_FILE_SHIFT1, PTE_FILE_MASK1, 0) +
138+
pte_bitop(pte.pte_low, PTE_FILE_SHIFT2, PTE_FILE_MASK2, PTE_FILE_LSHIFT2) +
139+
pte_bitop(pte.pte_low, PTE_FILE_SHIFT3, -1UL, PTE_FILE_LSHIFT3));
140+
}
141+
142+
static __always_inline pte_t pgoff_to_pte(pgoff_t off)
143+
{
144+
return (pte_t){
145+
.pte_low =
146+
pte_bitop(off, 0, PTE_FILE_MASK1, PTE_FILE_SHIFT1) +
147+
pte_bitop(off, PTE_FILE_LSHIFT2, PTE_FILE_MASK2, PTE_FILE_SHIFT2) +
148+
pte_bitop(off, PTE_FILE_LSHIFT3, -1UL, PTE_FILE_SHIFT3) +
149+
_PAGE_FILE,
150+
};
151+
}
134152

135153
#endif /* CONFIG_MEM_SOFT_DIRTY */
136154

arch/x86/mm/hugetlbpage.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ int pmd_huge_support(void)
8787
}
8888
#endif
8989

90-
/* x86_64 also uses this file */
91-
92-
#ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
90+
#ifdef CONFIG_HUGETLB_PAGE
9391
static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
9492
unsigned long addr, unsigned long len,
9593
unsigned long pgoff, unsigned long flags)
@@ -99,7 +97,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
9997

10098
info.flags = 0;
10199
info.length = len;
102-
info.low_limit = TASK_UNMAPPED_BASE;
100+
info.low_limit = current->mm->mmap_legacy_base;
103101
info.high_limit = TASK_SIZE;
104102
info.align_mask = PAGE_MASK & ~huge_page_mask(h);
105103
info.align_offset = 0;
@@ -172,8 +170,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
172170
return hugetlb_get_unmapped_area_topdown(file, addr, len,
173171
pgoff, flags);
174172
}
175-
176-
#endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
173+
#endif /* CONFIG_HUGETLB_PAGE */
177174

178175
#ifdef CONFIG_X86_64
179176
static __init int setup_hugepagesz(char *opt)

arch/x86/mm/numa.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,13 @@ static void __init setup_node_data(int nid, u64 start, u64 end)
211211
*/
212212
nd_pa = memblock_alloc_nid(nd_size, SMP_CACHE_BYTES, nid);
213213
if (!nd_pa) {
214-
pr_err("Cannot find %zu bytes in node %d\n",
215-
nd_size, nid);
216-
return;
214+
nd_pa = __memblock_alloc_base(nd_size, SMP_CACHE_BYTES,
215+
MEMBLOCK_ALLOC_ACCESSIBLE);
216+
if (!nd_pa) {
217+
pr_err("Cannot find %zu bytes in node %d\n",
218+
nd_size, nid);
219+
return;
220+
}
217221
}
218222
nd = __va(nd_pa);
219223

0 commit comments

Comments
 (0)