318f655
From:	Samu Kallio <>
318f655
Subject: [PATCH] x86: mm: Fix vmalloc_fault oops during lazy MMU updates.
318f655
Date: Sun, 17 Feb 2013 04:35:52 +0200
318f655
318f655
In paravirtualized x86_64 kernels, vmalloc_fault may cause an oops
318f655
when lazy MMU updates are enabled, because set_pgd effects are being
318f655
deferred.
318f655
318f655
One instance of this problem is during process mm cleanup with memory
318f655
cgroups enabled. The chain of events is as follows:
318f655
318f655
- zap_pte_range enables lazy MMU updates
318f655
- zap_pte_range eventually calls mem_cgroup_charge_statistics,
318f655
  which accesses the vmalloc'd mem_cgroup per-cpu stat area
318f655
- vmalloc_fault is triggered which tries to sync the corresponding
318f655
  PGD entry with set_pgd, but the update is deferred
318f655
- vmalloc_fault oopses due to a mismatch in the PUD entries
318f655
318f655
Calling arch_flush_lazy_mmu_mode immediately after set_pgd makes the
318f655
changes visible to the consistency checks.
318f655
318f655
Signed-off-by: Samu Kallio <samu.kallio@aberdeencloud.com>
318f655
---
318f655
 arch/x86/mm/fault.c | 6 ++++--
318f655
 1 file changed, 4 insertions(+), 2 deletions(-)
318f655
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
318f655
index 8e13ecb..0a45298 100644
318f655
--- a/arch/x86/mm/fault.c
318f655
+++ b/arch/x86/mm/fault.c
318f655
@@ -378,10 +378,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
318f655
 	if (pgd_none(*pgd_ref))
318f655
 		return -1;
318f655
 
318f655
-	if (pgd_none(*pgd))
318f655
+	if (pgd_none(*pgd)) {
318f655
 		set_pgd(pgd, *pgd_ref);
318f655
-	else
318f655
+		arch_flush_lazy_mmu_mode();
318f655
+	} else {
318f655
 		BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
318f655
+	}
318f655
 
318f655
 	/*
318f655
 	 * Below here mismatches are bugs because these lower tables
318f655
-- 
318f655
1.8.1.3
318f655
318f655