linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Jann Horn <jannh@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jonathan Corbet <corbet@lwn.net>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	Alice Ryhl <aliceryhl@google.com>,
	Boqun Feng <boqun.feng@gmail.com>,
	Matthew Wilcox <willy@infradead.org>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Hillf Danton <hdanton@sina.com>, SeongJae Park <sj@kernel.org>,
	Bagas Sanjaya <bagasdotme@gmail.com>,
	linux-mm@kvack.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Matteo Rizzo <matteorizzo@google.com>
Subject: Re: [PATCH v2] docs/mm: add more warnings around page table access
Date: Tue, 19 Nov 2024 07:48:42 +0000	[thread overview]
Message-ID: <b915ff26-e90d-4151-ab2f-607f3c59f501@lucifer.local> (raw)
In-Reply-To: <21195425-53d9-4007-a020-8106f94158dc@bytedance.com>

On Tue, Nov 19, 2024 at 02:53:52PM +0800, Qi Zheng wrote:
>
>
> On 2024/11/19 00:47, Jann Horn wrote:
> > Make it clearer that holding the mmap lock in read mode is not enough
> > to traverse page tables, and that just having a stable VMA is not enough
> > to read PTEs.
> >
> > Suggested-by: Matteo Rizzo <matteorizzo@google.com>
> > Suggested-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> > Signed-off-by: Jann Horn <jannh@google.com>
>
> Acked-by: Qi Zheng <zhengqi.arch@bytedance.com>
>
> > +
> > +* On 32-bit architectures, they may be in high memory (meaning they need to be
> > +  mapped into kernel memory to be accessible).
> > +* When empty, they can be unlinked and RCU-freed while holding an mmap lock or
> > +  rmap lock for reading in combination with the PTE and PMD page table locks.
> > +  In particular, this happens in :c:func:`!retract_page_tables` when handling
> > +  :c:macro:`!MADV_COLLAPSE`.
> > +  So accessing PTE-level page tables requires at least holding an RCU read lock;
> > +  but that only suffices for readers that can tolerate racing with concurrent
> > +  page table updates such that an empty PTE is observed (in a page table that
> > +  has actually already been detached and marked for RCU freeing) while another
> > +  new page table has been installed in the same location and filled with
> > +  entries. Writers normally need to take the PTE lock and revalidate that the
> > +  PMD entry still refers to the same PTE-level page table.
> > +
>
> In practice, this also happens in the retract_page_tables(). Maybe can
> add a note about this after my patch[1] is merged. ;)
>
> [1]. https://lore.kernel.org/lkml/e5b321ffc3ebfcc46e53830e917ad246f7d2825f.1731566457.git.zhengqi.arch@bytedance.com/

You could even queue the doc change up there? :>)

I think one really nice thing with having docs in-tree like this is when we
change things that alter the doc's accuracy we can queue them up with the
patch so the doc always stays in sync.

I feel you may have accidentally self-volunteered there ;)

>
> Thanks!
>
> >


  reply	other threads:[~2024-11-19  7:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-18 16:47 Jann Horn
2024-11-18 17:33 ` Lorenzo Stoakes
2024-11-19  6:53 ` Qi Zheng
2024-11-19  7:48   ` Lorenzo Stoakes [this message]
2024-11-19  8:02     ` Qi Zheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b915ff26-e90d-4151-ab2f-607f3c59f501@lucifer.local \
    --to=lorenzo.stoakes@oracle.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=aliceryhl@google.com \
    --cc=bagasdotme@gmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=corbet@lwn.net \
    --cc=hdanton@sina.com \
    --cc=jannh@google.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=matteorizzo@google.com \
    --cc=rppt@kernel.org \
    --cc=sj@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    --cc=zhengqi.arch@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox