Skip to content

Commit 6afb515

Browse files
haicheng-liH. Peter Anvin
authored andcommitted
x86, mm: Separate x86_64 vmalloc_sync_all() into separate functions
No behavior change. Move some of vmalloc_sync_all() code into a new function sync_global_pgds() that will be useful for memory hotplug. Signed-off-by: Haicheng Li <[email protected]> LKML-Reference: <[email protected]> Reviewed-by: Wu Fengguang <[email protected]> Reviewed-by: Andi Kleen <[email protected]> Signed-off-by: H. Peter Anvin <[email protected]>
1 parent 61c7732 commit 6afb515

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

arch/x86/include/asm/pgtable_64.h

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

105+
extern void sync_global_pgds(unsigned long start, unsigned long end);
106+
105107
/*
106108
* Conversion functions: convert a page and protection to a page entry,
107109
* and a page entry and page directory to the page they refer to.

arch/x86/mm/fault.c

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -326,29 +326,7 @@ static void dump_pagetable(unsigned long address)
326326

327327
void vmalloc_sync_all(void)
328328
{
329-
unsigned long address;
330-
331-
for (address = VMALLOC_START & PGDIR_MASK; address <= VMALLOC_END;
332-
address += PGDIR_SIZE) {
333-
334-
const pgd_t *pgd_ref = pgd_offset_k(address);
335-
unsigned long flags;
336-
struct page *page;
337-
338-
if (pgd_none(*pgd_ref))
339-
continue;
340-
341-
spin_lock_irqsave(&pgd_lock, flags);
342-
list_for_each_entry(page, &pgd_list, lru) {
343-
pgd_t *pgd;
344-
pgd = (pgd_t *)page_address(page) + pgd_index(address);
345-
if (pgd_none(*pgd))
346-
set_pgd(pgd, *pgd_ref);
347-
else
348-
BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
349-
}
350-
spin_unlock_irqrestore(&pgd_lock, flags);
351-
}
329+
sync_global_pgds(VMALLOC_START & PGDIR_MASK, VMALLOC_END);
352330
}
353331

354332
/*

arch/x86/mm/init_64.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,36 @@ static int __init nonx32_setup(char *str)
9797
}
9898
__setup("noexec32=", nonx32_setup);
9999

100+
/*
101+
* When memory was added/removed make sure all the processes MM have
102+
* suitable PGD entries in the local PGD level page.
103+
*/
104+
void sync_global_pgds(unsigned long start, unsigned long end)
105+
{
106+
unsigned long address;
107+
108+
for (address = start; address <= end; address += PGDIR_SIZE) {
109+
const pgd_t *pgd_ref = pgd_offset_k(address);
110+
unsigned long flags;
111+
struct page *page;
112+
113+
if (pgd_none(*pgd_ref))
114+
continue;
115+
116+
spin_lock_irqsave(&pgd_lock, flags);
117+
list_for_each_entry(page, &pgd_list, lru) {
118+
pgd_t *pgd;
119+
pgd = (pgd_t *)page_address(page) + pgd_index(address);
120+
if (pgd_none(*pgd))
121+
set_pgd(pgd, *pgd_ref);
122+
else
123+
BUG_ON(pgd_page_vaddr(*pgd)
124+
!= pgd_page_vaddr(*pgd_ref));
125+
}
126+
spin_unlock_irqrestore(&pgd_lock, flags);
127+
}
128+
}
129+
100130
/*
101131
* NOTE: This function is marked __ref because it calls __init function
102132
* (alloc_bootmem_pages). It's safe to do it ONLY when after_bootmem == 0.

0 commit comments

Comments
 (0)