linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Potential bug in soft-dirty bits (with test case)
@ 2020-11-25 14:15 Mohamed Alzayat
  2020-11-27 16:40 ` Vlastimil Babka
  0 siblings, 1 reply; 7+ messages in thread
From: Mohamed Alzayat @ 2020-11-25 14:15 UTC (permalink / raw)
  To: linux-mm

Hi Everyone,

I have noticed a change in the synchrony of updating the soft-dirty
bits in recent kernel versions (5.6+). More precisely, up to kernel
v5.5, the soft-dirty bits as parsed from /proc/pid/pagemap accurately
capture the dirtied pages. Recently, I started testing on kernels v5.6
- v5.9, and I noticed that the soft-dirty bits are not immediately
updated.

I have prepared a short test that repeatedly causes at least one
memory page to be dirtied, then scans /proc/pid/pagemap counting the
soft-dirty bits. The test fails if this count is zero. In my
observation, this test fails once in every 10-20 trials. The test
defaults to 100 trials and can be found at
https://gitlab.mpi-sws.org/-/snippets/1696

Is this non-synchronous propagation of soft dirty bits intended? If
yes, is there a way to force the soft-dirty bits to be propagated to
the page map entries immediately, or is there an alternative interface
that has the synchronous behavior?

Thanks in advance,
Mohamed Alzayat


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

* Re: Potential bug in soft-dirty bits (with test case)
  2020-11-25 14:15 Potential bug in soft-dirty bits (with test case) Mohamed Alzayat
@ 2020-11-27 16:40 ` Vlastimil Babka
  2020-11-30 10:37   ` Mohamed Alzayat
  0 siblings, 1 reply; 7+ messages in thread
From: Vlastimil Babka @ 2020-11-27 16:40 UTC (permalink / raw)
  To: Mohamed Alzayat, linux-mm

On 11/25/20 3:15 PM, Mohamed Alzayat wrote:
> Hi Everyone,
> 
> I have noticed a change in the synchrony of updating the soft-dirty
> bits in recent kernel versions (5.6+). More precisely, up to kernel
> v5.5, the soft-dirty bits as parsed from /proc/pid/pagemap accurately
> capture the dirtied pages. Recently, I started testing on kernels v5.6
> - v5.9, and I noticed that the soft-dirty bits are not immediately
> updated.
> 
> I have prepared a short test that repeatedly causes at least one
> memory page to be dirtied, then scans /proc/pid/pagemap counting the
> soft-dirty bits. The test fails if this count is zero. In my
> observation, this test fails once in every 10-20 trials. The test
> defaults to 100 trials and can be found at
> https://gitlab.mpi-sws.org/-/snippets/1696
> 
> Is this non-synchronous propagation of soft dirty bits intended? If

AFAIK, not. The tracking is done by write-protecting the pages to cause a page 
fault, so it should be quite synchronous update of page table entries, and 
reading pagemap is a page table walk of those very entries.

But as you have the test, it should be possible to git bisect it? Just do enough 
trials to be sure enough that no fail means indeed a "good" kernel.

> yes, is there a way to force the soft-dirty bits to be propagated to
> the page map entries immediately, or is there an alternative interface
> that has the synchronous behavior?
> 
> Thanks in advance,
> Mohamed Alzayat
> 



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

* Re: Potential bug in soft-dirty bits (with test case)
  2020-11-27 16:40 ` Vlastimil Babka
@ 2020-11-30 10:37   ` Mohamed Alzayat
  2020-11-30 11:51     ` Vlastimil Babka
  0 siblings, 1 reply; 7+ messages in thread
From: Mohamed Alzayat @ 2020-11-30 10:37 UTC (permalink / raw)
  To: Vlastimil Babka; +Cc: linux-mm

On Fri, Nov 27, 2020 at 5:40 PM Vlastimil Babka <vbabka@suse.cz> wrote:
>
> On 11/25/20 3:15 PM, Mohamed Alzayat wrote:
> > Hi Everyone,
> >
> > I have noticed a change in the synchrony of updating the soft-dirty
> > bits in recent kernel versions (5.6+). More precisely, up to kernel
> > v5.5, the soft-dirty bits as parsed from /proc/pid/pagemap accurately
> > capture the dirtied pages. Recently, I started testing on kernels v5.6
> > - v5.9, and I noticed that the soft-dirty bits are not immediately
> > updated.
> >
> > I have prepared a short test that repeatedly causes at least one
> > memory page to be dirtied, then scans /proc/pid/pagemap counting the
> > soft-dirty bits. The test fails if this count is zero. In my
> > observation, this test fails once in every 10-20 trials. The test
> > defaults to 100 trials and can be found at
> > https://gitlab.mpi-sws.org/-/snippets/1696
> >
> > Is this non-synchronous propagation of soft dirty bits intended? If
>
> AFAIK, not. The tracking is done by write-protecting the pages to cause a page
> fault, so it should be quite synchronous update of page table entries, and
> reading pagemap is a page table walk of those very entries.
>
> But as you have the test, it should be possible to git bisect it? Just do enough
> trials to be sure enough that no fail means indeed a "good" kernel.

Thanks for confirming, Vlastimil!

The first bad commit is: 0758cd8304942292e95a0f750c374533db378b32
asm-generic/tlb: avoid potential double flush
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0758cd8304942292e95a0f750c374533db378b32

Reverting this commit solves the problem, but this might not be the
right way of fixing it.



>
> > yes, is there a way to force the soft-dirty bits to be propagated to
> > the page map entries immediately, or is there an alternative interface
> > that has the synchronous behavior?
> >
> > Thanks in advance,
> > Mohamed Alzayat
> >
>
>


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

* Re: Potential bug in soft-dirty bits (with test case)
  2020-11-30 10:37   ` Mohamed Alzayat
@ 2020-11-30 11:51     ` Vlastimil Babka
  2020-11-30 12:02       ` Peter Zijlstra
  0 siblings, 1 reply; 7+ messages in thread
From: Vlastimil Babka @ 2020-11-30 11:51 UTC (permalink / raw)
  To: Mohamed Alzayat, Peter Zijlstra, Aneesh Kumar K.V; +Cc: linux-mm

On 11/30/20 11:37 AM, Mohamed Alzayat wrote:
> On Fri, Nov 27, 2020 at 5:40 PM Vlastimil Babka <vbabka@suse.cz> wrote:
>>
>> On 11/25/20 3:15 PM, Mohamed Alzayat wrote:
>> > Hi Everyone,
>> >
>> > I have noticed a change in the synchrony of updating the soft-dirty
>> > bits in recent kernel versions (5.6+). More precisely, up to kernel
>> > v5.5, the soft-dirty bits as parsed from /proc/pid/pagemap accurately
>> > capture the dirtied pages. Recently, I started testing on kernels v5.6
>> > - v5.9, and I noticed that the soft-dirty bits are not immediately
>> > updated.
>> >
>> > I have prepared a short test that repeatedly causes at least one
>> > memory page to be dirtied, then scans /proc/pid/pagemap counting the
>> > soft-dirty bits. The test fails if this count is zero. In my
>> > observation, this test fails once in every 10-20 trials. The test
>> > defaults to 100 trials and can be found at
>> > https://gitlab.mpi-sws.org/-/snippets/1696
>> >
>> > Is this non-synchronous propagation of soft dirty bits intended? If
>>
>> AFAIK, not. The tracking is done by write-protecting the pages to cause a page
>> fault, so it should be quite synchronous update of page table entries, and
>> reading pagemap is a page table walk of those very entries.
>>
>> But as you have the test, it should be possible to git bisect it? Just do enough
>> trials to be sure enough that no fail means indeed a "good" kernel.
> 
> Thanks for confirming, Vlastimil!
> 
> The first bad commit is: 0758cd8304942292e95a0f750c374533db378b32
> asm-generic/tlb: avoid potential double flush
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0758cd8304942292e95a0f750c374533db378b32
> 
> Reverting this commit solves the problem, but this might not be the
> right way of fixing it.

Thanks for bisecting! Let's CC people involved in that commit. All important 
should be in the quoted conversation above.

Vlastimil

> 
>>
>> > yes, is there a way to force the soft-dirty bits to be propagated to
>> > the page map entries immediately, or is there an alternative interface
>> > that has the synchronous behavior?
>> >
>> > Thanks in advance,
>> > Mohamed Alzayat
>> >
>>
>>
> 



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

* Re: Potential bug in soft-dirty bits (with test case)
  2020-11-30 11:51     ` Vlastimil Babka
@ 2020-11-30 12:02       ` Peter Zijlstra
  2020-11-30 12:50         ` Will Deacon
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Zijlstra @ 2020-11-30 12:02 UTC (permalink / raw)
  To: Vlastimil Babka; +Cc: Mohamed Alzayat, Aneesh Kumar K.V, linux-mm, Will Deacon

On Mon, Nov 30, 2020 at 12:51:59PM +0100, Vlastimil Babka wrote:
> On 11/30/20 11:37 AM, Mohamed Alzayat wrote:

> > Thanks for confirming, Vlastimil!
> > 
> > The first bad commit is: 0758cd8304942292e95a0f750c374533db378b32
> > asm-generic/tlb: avoid potential double flush
> > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0758cd8304942292e95a0f750c374533db378b32
> > 
> > Reverting this commit solves the problem, but this might not be the
> > right way of fixing it.
> 
> Thanks for bisecting! Let's CC people involved in that commit. All important
> should be in the quoted conversation above.

There's a thread about it here:

  https://lkml.kernel.org/r/20201120143557.6715-1-will@kernel.org

That softdirty code really shouldn't be using mmu_gather imo, but I'm
still not clear on what exactly is broken why there.



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

* Re: Potential bug in soft-dirty bits (with test case)
  2020-11-30 12:02       ` Peter Zijlstra
@ 2020-11-30 12:50         ` Will Deacon
  2021-04-20 18:32           ` Mohamed Alzayat
  0 siblings, 1 reply; 7+ messages in thread
From: Will Deacon @ 2020-11-30 12:50 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Vlastimil Babka, Mohamed Alzayat, Aneesh Kumar K.V, linux-mm

On Mon, Nov 30, 2020 at 01:02:41PM +0100, Peter Zijlstra wrote:
> On Mon, Nov 30, 2020 at 12:51:59PM +0100, Vlastimil Babka wrote:
> > On 11/30/20 11:37 AM, Mohamed Alzayat wrote:
> 
> > > Thanks for confirming, Vlastimil!
> > > 
> > > The first bad commit is: 0758cd8304942292e95a0f750c374533db378b32
> > > asm-generic/tlb: avoid potential double flush
> > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0758cd8304942292e95a0f750c374533db378b32
> > > 
> > > Reverting this commit solves the problem, but this might not be the
> > > right way of fixing it.
> > 
> > Thanks for bisecting! Let's CC people involved in that commit. All important
> > should be in the quoted conversation above.
> 
> There's a thread about it here:
> 
>   https://lkml.kernel.org/r/20201120143557.6715-1-will@kernel.org
> 
> That softdirty code really shouldn't be using mmu_gather imo, but I'm
> still not clear on what exactly is broken why there.

I'll spin a v2 of that series soon, so I'll add folks here to cc. The
fact that a test noticed the missing invalidation is a pretty good reason
for us to add it back!

Will


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

* Re: Potential bug in soft-dirty bits (with test case)
  2020-11-30 12:50         ` Will Deacon
@ 2021-04-20 18:32           ` Mohamed Alzayat
  0 siblings, 0 replies; 7+ messages in thread
From: Mohamed Alzayat @ 2021-04-20 18:32 UTC (permalink / raw)
  To: Will Deacon; +Cc: Peter Zijlstra, Vlastimil Babka, Aneesh Kumar K.V, linux-mm

Thanks a lot Vlastimil, and Peter for the pointers! Many thanks Will
for actually fixing it (v5.12)!

Thanks,
Mohamed

On Mon, Nov 30, 2020 at 1:50 PM Will Deacon <will@kernel.org> wrote:
>
> On Mon, Nov 30, 2020 at 01:02:41PM +0100, Peter Zijlstra wrote:
> > On Mon, Nov 30, 2020 at 12:51:59PM +0100, Vlastimil Babka wrote:
> > > On 11/30/20 11:37 AM, Mohamed Alzayat wrote:
> >
> > > > Thanks for confirming, Vlastimil!
> > > >
> > > > The first bad commit is: 0758cd8304942292e95a0f750c374533db378b32
> > > > asm-generic/tlb: avoid potential double flush
> > > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0758cd8304942292e95a0f750c374533db378b32
> > > >
> > > > Reverting this commit solves the problem, but this might not be the
> > > > right way of fixing it.
> > >
> > > Thanks for bisecting! Let's CC people involved in that commit. All important
> > > should be in the quoted conversation above.
> >
> > There's a thread about it here:
> >
> >   https://lkml.kernel.org/r/20201120143557.6715-1-will@kernel.org
> >
> > That softdirty code really shouldn't be using mmu_gather imo, but I'm
> > still not clear on what exactly is broken why there.
>
> I'll spin a v2 of that series soon, so I'll add folks here to cc. The
> fact that a test noticed the missing invalidation is a pretty good reason
> for us to add it back!

Thanks, everyone! I appreciate your helpful comments and pointers,
looking forward to the v2 of that series. Until then, reverting to
double TLB flush works fine on recent kernels (tested on v5.10-rc5).

Thanks,
Mohamed

>
> Will
>


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

end of thread, other threads:[~2021-04-20 18:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-25 14:15 Potential bug in soft-dirty bits (with test case) Mohamed Alzayat
2020-11-27 16:40 ` Vlastimil Babka
2020-11-30 10:37   ` Mohamed Alzayat
2020-11-30 11:51     ` Vlastimil Babka
2020-11-30 12:02       ` Peter Zijlstra
2020-11-30 12:50         ` Will Deacon
2021-04-20 18:32           ` Mohamed Alzayat

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).