Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-23 Thread Xiao Guangrong
On 08/23/2012 03:50 AM, Andrea Arcangeli wrote: > Hi Andrew, > > On Wed, Aug 22, 2012 at 12:15:35PM -0700, Andrew Morton wrote: >> On Wed, 22 Aug 2012 18:29:55 +0200 >> Andrea Arcangeli wrote: >> >>> On Wed, Aug 22, 2012 at 02:03:41PM +0800, Xiao Guangrong wrote: On 08/21/2012 11:06 PM,

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-23 Thread Xiao Guangrong
On 08/23/2012 12:37 AM, Andrea Arcangeli wrote: > On Wed, Aug 22, 2012 at 11:51:17AM +0800, Xiao Guangrong wrote: >> Hmm, in KSM code, i found this code in replace_page: >> >> set_pte_at_notify(mm, addr, ptep, mk_pte(kpage, vma->vm_page_prot)); >> >> It is possible to establish a writable pte, no?

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-23 Thread Xiao Guangrong
On 08/23/2012 12:37 AM, Andrea Arcangeli wrote: On Wed, Aug 22, 2012 at 11:51:17AM +0800, Xiao Guangrong wrote: Hmm, in KSM code, i found this code in replace_page: set_pte_at_notify(mm, addr, ptep, mk_pte(kpage, vma-vm_page_prot)); It is possible to establish a writable pte, no? Hugh

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-23 Thread Xiao Guangrong
On 08/23/2012 03:50 AM, Andrea Arcangeli wrote: Hi Andrew, On Wed, Aug 22, 2012 at 12:15:35PM -0700, Andrew Morton wrote: On Wed, 22 Aug 2012 18:29:55 +0200 Andrea Arcangeli aarca...@redhat.com wrote: On Wed, Aug 22, 2012 at 02:03:41PM +0800, Xiao Guangrong wrote: On 08/21/2012 11:06 PM,

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-22 Thread Andrea Arcangeli
On Wed, Aug 22, 2012 at 12:58:05PM -0700, Andrew Morton wrote: > If you can suggest some text I'll type it in right now. Ok ;), I tried below: This is safe to start by updating the secondary MMUs, because the relevant primary MMU pte invalidate must have already happened with a ptep_clear_flush

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-22 Thread Andrew Morton
On Wed, 22 Aug 2012 21:50:43 +0200 Andrea Arcangeli wrote: > Hi Andrew, > > On Wed, Aug 22, 2012 at 12:15:35PM -0700, Andrew Morton wrote: > > On Wed, 22 Aug 2012 18:29:55 +0200 > > Andrea Arcangeli wrote: > > > > > On Wed, Aug 22, 2012 at 02:03:41PM +0800, Xiao Guangrong wrote: > > > > On

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-22 Thread Andrea Arcangeli
Hi Andrew, On Wed, Aug 22, 2012 at 12:15:35PM -0700, Andrew Morton wrote: > On Wed, 22 Aug 2012 18:29:55 +0200 > Andrea Arcangeli wrote: > > > On Wed, Aug 22, 2012 at 02:03:41PM +0800, Xiao Guangrong wrote: > > > On 08/21/2012 11:06 PM, Andrea Arcangeli wrote: > > > > CPU0

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-22 Thread Andrew Morton
On Wed, 22 Aug 2012 18:29:55 +0200 Andrea Arcangeli wrote: > On Wed, Aug 22, 2012 at 02:03:41PM +0800, Xiao Guangrong wrote: > > On 08/21/2012 11:06 PM, Andrea Arcangeli wrote: > > > CPU0 CPU1 > > > oldpage[1] == 0 (both guest & host) > > >

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-22 Thread Andrea Arcangeli
On Wed, Aug 22, 2012 at 11:51:17AM +0800, Xiao Guangrong wrote: > Hmm, in KSM code, i found this code in replace_page: > > set_pte_at_notify(mm, addr, ptep, mk_pte(kpage, vma->vm_page_prot)); > > It is possible to establish a writable pte, no? Hugh already answered this thanks. Further details

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-22 Thread Andrea Arcangeli
On Wed, Aug 22, 2012 at 02:03:41PM +0800, Xiao Guangrong wrote: > On 08/21/2012 11:06 PM, Andrea Arcangeli wrote: > > CPU0CPU1 > > oldpage[1] == 0 (both guest & host) > > oldpage[0] = 1 > > trigger do_wp_page > > We always do

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-22 Thread Xiao Guangrong
On 08/21/2012 11:06 PM, Andrea Arcangeli wrote: > On Tue, Aug 21, 2012 at 05:46:39PM +0800, Xiao Guangrong wrote: >> 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

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-22 Thread Xiao Guangrong
On 08/21/2012 11:06 PM, Andrea Arcangeli wrote: On Tue, Aug 21, 2012 at 05:46:39PM +0800, Xiao Guangrong wrote: 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

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-22 Thread Andrea Arcangeli
On Wed, Aug 22, 2012 at 02:03:41PM +0800, Xiao Guangrong wrote: On 08/21/2012 11:06 PM, Andrea Arcangeli wrote: CPU0CPU1 oldpage[1] == 0 (both guest host) oldpage[0] = 1 trigger do_wp_page We always do ptep_clear_flush before

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-22 Thread Andrea Arcangeli
On Wed, Aug 22, 2012 at 11:51:17AM +0800, Xiao Guangrong wrote: Hmm, in KSM code, i found this code in replace_page: set_pte_at_notify(mm, addr, ptep, mk_pte(kpage, vma-vm_page_prot)); It is possible to establish a writable pte, no? Hugh already answered this thanks. Further details on the

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-22 Thread Andrew Morton
On Wed, 22 Aug 2012 18:29:55 +0200 Andrea Arcangeli aarca...@redhat.com wrote: On Wed, Aug 22, 2012 at 02:03:41PM +0800, Xiao Guangrong wrote: On 08/21/2012 11:06 PM, Andrea Arcangeli wrote: CPU0 CPU1 oldpage[1] == 0 (both guest

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-22 Thread Andrea Arcangeli
Hi Andrew, On Wed, Aug 22, 2012 at 12:15:35PM -0700, Andrew Morton wrote: On Wed, 22 Aug 2012 18:29:55 +0200 Andrea Arcangeli aarca...@redhat.com wrote: On Wed, Aug 22, 2012 at 02:03:41PM +0800, Xiao Guangrong wrote: On 08/21/2012 11:06 PM, Andrea Arcangeli wrote: CPU0

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-22 Thread Andrew Morton
On Wed, 22 Aug 2012 21:50:43 +0200 Andrea Arcangeli aarca...@redhat.com wrote: Hi Andrew, On Wed, Aug 22, 2012 at 12:15:35PM -0700, Andrew Morton wrote: On Wed, 22 Aug 2012 18:29:55 +0200 Andrea Arcangeli aarca...@redhat.com wrote: On Wed, Aug 22, 2012 at 02:03:41PM +0800, Xiao

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-22 Thread Andrea Arcangeli
On Wed, Aug 22, 2012 at 12:58:05PM -0700, Andrew Morton wrote: If you can suggest some text I'll type it in right now. Ok ;), I tried below: This is safe to start by updating the secondary MMUs, because the relevant primary MMU pte invalidate must have already happened with a ptep_clear_flush

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-21 Thread Xiao Guangrong
On 08/22/2012 12:12 PM, Hugh Dickins wrote: > On Wed, 22 Aug 2012, Xiao Guangrong wrote: >> On 08/21/2012 11:06 PM, Andrea Arcangeli wrote: >>> >>> The KSM usage of it looks safe because it will only establish readonly >>> ptes with it. >> >> Hmm, in KSM code, i found this code in replace_page: >>

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-21 Thread Hugh Dickins
On Wed, 22 Aug 2012, Xiao Guangrong wrote: > On 08/21/2012 11:06 PM, Andrea Arcangeli wrote: > > > > The KSM usage of it looks safe because it will only establish readonly > > ptes with it. > > Hmm, in KSM code, i found this code in replace_page: > > set_pte_at_notify(mm, addr, ptep,

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-21 Thread Xiao Guangrong
On 08/21/2012 11:06 PM, Andrea Arcangeli wrote: > On Tue, Aug 21, 2012 at 05:46:39PM +0800, Xiao Guangrong wrote: >> 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

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-21 Thread Andrea Arcangeli
On Tue, Aug 21, 2012 at 05:46:39PM +0800, Xiao Guangrong wrote: > 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

[PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-21 Thread Xiao Guangrong
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

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-21 Thread Xiao Guangrong
On 08/21/2012 11:06 PM, Andrea Arcangeli wrote: On Tue, Aug 21, 2012 at 05:46:39PM +0800, Xiao Guangrong wrote: 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

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-21 Thread Hugh Dickins
On Wed, 22 Aug 2012, Xiao Guangrong wrote: On 08/21/2012 11:06 PM, Andrea Arcangeli wrote: The KSM usage of it looks safe because it will only establish readonly ptes with it. Hmm, in KSM code, i found this code in replace_page: set_pte_at_notify(mm, addr, ptep, mk_pte(kpage,

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-21 Thread Xiao Guangrong
On 08/22/2012 12:12 PM, Hugh Dickins wrote: On Wed, 22 Aug 2012, Xiao Guangrong wrote: On 08/21/2012 11:06 PM, Andrea Arcangeli wrote: The KSM usage of it looks safe because it will only establish readonly ptes with it. Hmm, in KSM code, i found this code in replace_page:

[PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-21 Thread Xiao Guangrong
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

Re: [PATCH] mm: mmu_notifier: fix inconsistent memory between secondary MMU and host

2012-08-21 Thread Andrea Arcangeli
On Tue, Aug 21, 2012 at 05:46:39PM +0800, Xiao Guangrong wrote: 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,