Skip to content

Commit e96ec8c

Browse files
committed
Merge tag 'x86-mm-2020-08-03' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 mmm update from Ingo Molnar: "The biggest change is to not sync the vmalloc and ioremap ranges for x86-64 anymore" * tag 'x86-mm-2020-08-03' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/mm/64: Make sync_global_pgds() static x86/mm/64: Do not sync vmalloc/ioremap mappings x86/mm: Pre-allocate P4D/PUD pages for vmalloc area
2 parents c813e8c + 2b32ab0 commit e96ec8c

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

arch/x86/include/asm/pgtable_64.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ static inline void native_pgd_clear(pgd_t *pgd)
168168
native_set_pgd(pgd, native_make_pgd(0));
169169
}
170170

171-
extern void sync_global_pgds(unsigned long start, unsigned long end);
172-
173171
/*
174172
* Conversion functions: convert a page and protection to a page entry,
175173
* and a page entry and page directory to the page they refer to.

arch/x86/include/asm/pgtable_64_types.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,4 @@ extern unsigned int ptrs_per_p4d;
159159

160160
#define PGD_KERNEL_START ((PAGE_SIZE / 2) / sizeof(pgd_t))
161161

162-
#define ARCH_PAGE_TABLE_SYNC_MASK (pgtable_l5_enabled() ? PGTBL_PGD_MODIFIED : PGTBL_P4D_MODIFIED)
163-
164162
#endif /* _ASM_X86_PGTABLE_64_DEFS_H */

arch/x86/mm/init_64.c

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,14 @@ static void sync_global_pgds_l4(unsigned long start, unsigned long end)
209209
* When memory was added make sure all the processes MM have
210210
* suitable PGD entries in the local PGD level page.
211211
*/
212-
void sync_global_pgds(unsigned long start, unsigned long end)
212+
static void sync_global_pgds(unsigned long start, unsigned long end)
213213
{
214214
if (pgtable_l5_enabled())
215215
sync_global_pgds_l5(start, end);
216216
else
217217
sync_global_pgds_l4(start, end);
218218
}
219219

220-
void arch_sync_kernel_mappings(unsigned long start, unsigned long end)
221-
{
222-
sync_global_pgds(start, end);
223-
}
224-
225220
/*
226221
* NOTE: This function is marked __ref because it calls __init function
227222
* (alloc_bootmem_pages). It's safe to do it ONLY when after_bootmem == 0.
@@ -1238,6 +1233,56 @@ static void __init register_page_bootmem_info(void)
12381233
#endif
12391234
}
12401235

1236+
/*
1237+
* Pre-allocates page-table pages for the vmalloc area in the kernel page-table.
1238+
* Only the level which needs to be synchronized between all page-tables is
1239+
* allocated because the synchronization can be expensive.
1240+
*/
1241+
static void __init preallocate_vmalloc_pages(void)
1242+
{
1243+
unsigned long addr;
1244+
const char *lvl;
1245+
1246+
for (addr = VMALLOC_START; addr <= VMALLOC_END; addr = ALIGN(addr + 1, PGDIR_SIZE)) {
1247+
pgd_t *pgd = pgd_offset_k(addr);
1248+
p4d_t *p4d;
1249+
pud_t *pud;
1250+
1251+
p4d = p4d_offset(pgd, addr);
1252+
if (p4d_none(*p4d)) {
1253+
/* Can only happen with 5-level paging */
1254+
p4d = p4d_alloc(&init_mm, pgd, addr);
1255+
if (!p4d) {
1256+
lvl = "p4d";
1257+
goto failed;
1258+
}
1259+
}
1260+
1261+
if (pgtable_l5_enabled())
1262+
continue;
1263+
1264+
pud = pud_offset(p4d, addr);
1265+
if (pud_none(*pud)) {
1266+
/* Ends up here only with 4-level paging */
1267+
pud = pud_alloc(&init_mm, p4d, addr);
1268+
if (!pud) {
1269+
lvl = "pud";
1270+
goto failed;
1271+
}
1272+
}
1273+
}
1274+
1275+
return;
1276+
1277+
failed:
1278+
1279+
/*
1280+
* The pages have to be there now or they will be missing in
1281+
* process page-tables later.
1282+
*/
1283+
panic("Failed to pre-allocate %s pages for vmalloc area\n", lvl);
1284+
}
1285+
12411286
void __init mem_init(void)
12421287
{
12431288
pci_iommu_alloc();
@@ -1261,6 +1306,8 @@ void __init mem_init(void)
12611306
if (get_gate_vma(&init_mm))
12621307
kclist_add(&kcore_vsyscall, (void *)VSYSCALL_ADDR, PAGE_SIZE, KCORE_USER);
12631308

1309+
preallocate_vmalloc_pages();
1310+
12641311
mem_init_print_info(NULL);
12651312
}
12661313

0 commit comments

Comments
 (0)