Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1442360 > unrolled thread

Re: [PATCH 0/4] [RFC][v4] Workaround for Xeon Phi PTE A/D bits erratum

Started byVlastimil Babka <vbabka@suse.cz>
First post2016-07-13 13:40 +0200
Last post2016-07-13 16:10 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH 0/4] [RFC][v4] Workaround for Xeon Phi PTE A/D bits  erratum Vlastimil Babka <vbabka@suse.cz> - 2016-07-13 13:40 +0200
    Re: [PATCH 0/4] [RFC][v4] Workaround for Xeon Phi PTE A/D bits  erratum Vlastimil Babka <vbabka@suse.cz> - 2016-07-13 14:20 +0200
    Re: [PATCH 0/4] [RFC][v4] Workaround for Xeon Phi PTE A/D bits  erratum Dave Hansen <dave@sr71.net> - 2016-07-13 16:10 +0200

#1442360 — Re: [PATCH 0/4] [RFC][v4] Workaround for Xeon Phi PTE A/D bits erratum

FromVlastimil Babka <vbabka@suse.cz>
Date2016-07-13 13:40 +0200
SubjectRe: [PATCH 0/4] [RFC][v4] Workaround for Xeon Phi PTE A/D bits erratum
Message-ID<rUqGd-2sM-19@gated-at.bofh.it>
On 07/02/2016 12:28 AM, Benjamin Herrenschmidt wrote:
> On Fri, 2016-07-01 at 10:46 -0700, Dave Hansen wrote:
>> The Intel(R) Xeon Phi(TM) Processor x200 Family (codename: Knights
>> Landing) has an erratum where a processor thread setting the Accessed
>> or Dirty bits may not do so atomically against its checks for the
>> Present bit.  This may cause a thread (which is about to page fault)
>> to set A and/or D, even though the Present bit had already been
>> atomically cleared.
>
> Interesting.... I always wondered where in the Intel docs did it specify
> that present was tested atomically with setting of A and D ... I couldn't
> find it.
>
> Isn't there a more fundamental issue however that you may actually lose
> those bits ? For example if we do an munmap, in zap_pte_range()
>
> We first exchange all the PTEs with 0 with ptep_get_and_clear_full()
> and we then transfer D that we just read into the struct page.
>
> We rely on the fact that D will never be set again, what we go it a
> "final" D bit. IE. We rely on the fact that a processor either:
>
>    - Has a cached PTE in its TLB with D set, in which case it can still
> write to the page until we flush the TLB or
>
>    - Doesn't have a cached PTE in its TLB with D set and so will fail
> to do so due to the atomic P check, thus never writing.
>
> With the errata, don't you have a situation where a processor in the second
> category will write and set D despite P having been cleared (due to the
> race) and thus causing us to miss the transfer of that D to the struct
> page and essentially completely miss that the physical page is dirty ?

Seems to me like this is indeed possible, but...

> (Leading to memory corruption).

... what memory corruption, exactly? If a process is writing to its 
memory from one thread and unmapping it from other thread at the same 
time, there are no guarantees anyway? Would anything sensible rely on 
the guarantee that if the write in such racy scenario didn't end up as a 
segfault (i.e. unmapping was faster), then it must hit the disk? Or are 
there any other scenarios where zap_pte_range() is called? Hmm, but how 
does this affect the page migration scenario, can we lose the D bit there?

And maybe related thing that just occured to me, what if page is made 
non-writable during fork() to catch COW? Any race in that one, or just 
the P bit? But maybe the argument would be the same as above...

[toc] | [next] | [standalone]


#1442383

FromVlastimil Babka <vbabka@suse.cz>
Date2016-07-13 14:20 +0200
Message-ID<rUriV-2WY-3@gated-at.bofh.it>
In reply to#1442360
On 07/13/2016 01:37 PM, Vlastimil Babka wrote:
>> > With the errata, don't you have a situation where a processor in the second
>> > category will write and set D despite P having been cleared (due to the
>> > race) and thus causing us to miss the transfer of that D to the struct
>> > page and essentially completely miss that the physical page is dirty ?
> Seems to me like this is indeed possible, but...

Nevermind, I have read the v3 thread now, where Dave says [1] that 
setting the D bit due to the erratum doesn't mean that the page is 
really actually written to (it's not). So there shouldn't be any true 
dirty bit to leave behind.

[1] http://marc.info/?l=linux-mm&m=146738965614826&w=2

[toc] | [prev] | [next] | [standalone]


#1442495

FromDave Hansen <dave@sr71.net>
Date2016-07-13 16:10 +0200
Message-ID<rUt1o-47M-25@gated-at.bofh.it>
In reply to#1442360
On 07/13/2016 04:37 AM, Vlastimil Babka wrote:
> On 07/02/2016 12:28 AM, Benjamin Herrenschmidt wrote:
>> With the errata, don't you have a situation where a processor in
>> the second category will write and set D despite P having been
>> cleared (due to the race) and thus causing us to miss the transfer
>> of that D to the struct
>> page and essentially completely miss that the physical page is dirty ?
> 
> Seems to me like this is indeed possible, but...

No, this isn't possible with the erratum.

I had some off-list follow up with Ben, and included this description in
the later post of the patch:
> These bits are truly "stray".  In the case of the Dirty bit, the
> thread associated with the stray set was *not* allowed to write to
> the page.  This means that we do not have to launder the bit(s); we
> can simply ignore them.


>> (Leading to memory corruption).
> 
> ... what memory corruption, exactly?

In this (non-existent) scenario, we would lose writes to mmap()'d files
because we did not see the dirty bit during the "get" part of
ptep_get_and_clear().

> If a process is writing to its
> memory from one thread and unmapping it from other thread at the same
> time, there are no guarantees anyway?

It's not just unmapping, it's also swap, NUMA migration, etc...  We
clear the PTE, flush, then re-populate it.

> Would anything sensible rely on
> the guarantee that if the write in such racy scenario didn't end up as a
> segfault (i.e. unmapping was faster), then it must hit the disk? Or are
> there any other scenarios where zap_pte_range() is called? Hmm, but how
> does this affect the page migration scenario, can we lose the D bit there?

Yeah, it's not just zap_pte_range(), it's everywhere that we change a
present PTE.

> And maybe related thing that just occured to me, what if page is made
> non-writable during fork() to catch COW? Any race in that one, or just
> the P bit? But maybe the argument would be the same as above...

Yeah, the argument is the same.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web