linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host
@ 2012-08-21  9:46 Xiao Guangrong
  2012-08-21 15:06 ` Andrea Arcangeli
  0 siblings, 1 reply; 14+ messages in thread
From: Xiao Guangrong @ 2012-08-21  9:46 UTC (permalink / raw)
  To: Andrew Morton, Avi Kivity, Marcelo Tosatti, Andrea Arcangeli,
	LKML, KVM, Linux Memory Management List

There has a bug in set_pte_at_notify which always set the pte to the
new page before release the old page in secondary MMU, at this time,
the process will access on the new page, but the secondary MMU still
access on the old page, the memory is inconsistent between them

Below scenario shows the bug more clearly:

at the beginning: *p = 0, and p is write-protected by KSM or shared with
parent process

CPU 0                                       CPU 1
write 1 to p to trigger COW,
set_pte_at_notify will be called:
  *pte = new_page + W; /* The W bit of pte is set */

                                     *p = 1; /* pte is valid, so no #PF */

                                     return back to secondary MMU, then
                                     the secondary MMU read p, but get:
                                     *p == 0;

                         /*
                          * !!!!!!
                          * the host has already set p to 1, but the secondary
                          * MMU still get the old value 0
                          */

  call mmu_notifier_change_pte to release
  old page in secondary MMU

We can fix it by release old page first, then set the pte to the new
page.

Note, the new page will be firstly used in secondary MMU before it is
mapped into the page table of the process, but this is safe because it
is protected by the page table lock, there is no race to change the pte

Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
---
 include/linux/mmu_notifier.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
index 1d1b1e1..8c7435a 100644
--- a/include/linux/mmu_notifier.h
+++ b/include/linux/mmu_notifier.h
@@ -317,8 +317,8 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
 	unsigned long ___address = __address;				\
 	pte_t ___pte = __pte;						\
 									\
-	set_pte_at(___mm, ___address, __ptep, ___pte);			\
 	mmu_notifier_change_pte(___mm, ___address, ___pte);		\
+	set_pte_at(___mm, ___address, __ptep, ___pte);			\
 })

 #else /* CONFIG_MMU_NOTIFIER */
-- 
1.7.7.6


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2012-08-23  7:34 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-21  9:46 [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host Xiao Guangrong
2012-08-21 15:06 ` Andrea Arcangeli
2012-08-22  3:51   ` Xiao Guangrong
2012-08-22  4:12     ` Hugh Dickins
2012-08-22  5:37       ` Xiao Guangrong
2012-08-22 16:37     ` Andrea Arcangeli
2012-08-23  7:25       ` Xiao Guangrong
2012-08-22  6:03   ` Xiao Guangrong
2012-08-22 16:29     ` Andrea Arcangeli
2012-08-22 19:15       ` Andrew Morton
2012-08-22 19:50         ` Andrea Arcangeli
2012-08-22 19:58           ` Andrew Morton
2012-08-22 20:14             ` Andrea Arcangeli
2012-08-23  7:34           ` Xiao Guangrong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).