public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Kalesh Singh <kaleshsingh@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Jonathan Corbet <corbet@lwn.net>, Shuah Khan <shuah@kernel.org>,
	David Hildenbrand <david@redhat.com>,
	Suren Baghdasaryan <surenb@google.com>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Matthew Wilcox <willy@infradead.org>,
	Vlastimil Babka <vbabka@suse.cz>,
	"Paul E . McKenney" <paulmck@kernel.org>,
	Jann Horn <jannh@google.com>, Juan Yescas <jyescas@google.com>,
	linux-mm@kvack.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-api@vger.kernel.org
Subject: Re: [PATCH 1/2] fs/proc/task_mmu: add guard region bit to pagemap
Date: Fri, 21 Feb 2025 17:45:51 +0000	[thread overview]
Message-ID: <f5a896b9-039b-464a-b2d1-eac0ddfcce65@lucifer.local> (raw)
In-Reply-To: <CAC_TJvf-R6MuSS9e0b4orhxLrFwXTnvZV-vf3sB+BnSbEqsprw@mail.gmail.com>

On Fri, Feb 21, 2025 at 09:10:42AM -0800, Kalesh Singh wrote:
> On Fri, Feb 21, 2025 at 4:05 AM Lorenzo Stoakes
> <lorenzo.stoakes@oracle.com> wrote:
> >
> > Currently there is no means by which users can determine whether a given
> > page in memory is in fact a guard region, that is having had the
> > MADV_GUARD_INSTALL madvise() flag applied to it.
> >
> > This is intentional, as to provide this information in VMA metadata would
> > contradict the intent of the feature (providing a means to change fault
> > behaviour at a page table level rather than a VMA level), and would require
> > VMA metadata operations to scan page tables, which is unacceptable.
> >
> > In many cases, users have no need to reflect and determine what regions
> > have been designated guard regions, as it is the user who has established
> > them in the first place.
> >
> > But in some instances, such as monitoring software, or software that relies
> > upon being able to ascertain the nature of mappings within a remote process
> > for instance, it becomes useful to be able to determine which pages have
> > the guard region marker applied.
> >
> > This patch makes use of an unused pagemap bit (58) to provide this
> > information.
> >
> > This patch updates the documentation at the same time as making the change
> > such that the implementation of the feature and the documentation of it are
> > tied together.
> >
> > Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> > ---
> >  Documentation/admin-guide/mm/pagemap.rst | 3 ++-
> >  fs/proc/task_mmu.c                       | 6 +++++-
> >  2 files changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/Documentation/admin-guide/mm/pagemap.rst b/Documentation/admin-guide/mm/pagemap.rst
> > index caba0f52dd36..a297e824f990 100644
> > --- a/Documentation/admin-guide/mm/pagemap.rst
> > +++ b/Documentation/admin-guide/mm/pagemap.rst
> > @@ -21,7 +21,8 @@ There are four components to pagemap:
> >      * Bit  56    page exclusively mapped (since 4.2)
> >      * Bit  57    pte is uffd-wp write-protected (since 5.13) (see
> >        Documentation/admin-guide/mm/userfaultfd.rst)
> > -    * Bits 58-60 zero
> > +    * Bit  58    pte is a guard region (since 6.15) (see madvise (2) man page)
>
> Should this be 6.14 ?

We're aiming for the 6.15 merge window so this is correct :>) I don't think
this could be considered a hotfix haha!

>
> Other than that: Reviewed-by: Kalesh Singh <kaleshsingh@google.com>

Thanks! And thanks for review on the other patch also! Appreciated.

>
> Thanks,
> Kalesh
>
> > +    * Bits 59-60 zero
> >      * Bit  61    page is file-page or shared-anon (since 3.5)
> >      * Bit  62    page swapped
> >      * Bit  63    page present
> > diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> > index f02cd362309a..c17615e21a5d 100644
> > --- a/fs/proc/task_mmu.c
> > +++ b/fs/proc/task_mmu.c
> > @@ -1632,6 +1632,7 @@ struct pagemapread {
> >  #define PM_SOFT_DIRTY          BIT_ULL(55)
> >  #define PM_MMAP_EXCLUSIVE      BIT_ULL(56)
> >  #define PM_UFFD_WP             BIT_ULL(57)
> > +#define PM_GUARD_REGION                BIT_ULL(58)
> >  #define PM_FILE                        BIT_ULL(61)
> >  #define PM_SWAP                        BIT_ULL(62)
> >  #define PM_PRESENT             BIT_ULL(63)
> > @@ -1732,6 +1733,8 @@ static pagemap_entry_t pte_to_pagemap_entry(struct pagemapread *pm,
> >                         page = pfn_swap_entry_to_page(entry);
> >                 if (pte_marker_entry_uffd_wp(entry))
> >                         flags |= PM_UFFD_WP;
> > +               if (is_guard_swp_entry(entry))
> > +                       flags |=  PM_GUARD_REGION;
> >         }
> >
> >         if (page) {
> > @@ -1931,7 +1934,8 @@ static const struct mm_walk_ops pagemap_ops = {
> >   * Bit  55    pte is soft-dirty (see Documentation/admin-guide/mm/soft-dirty.rst)
> >   * Bit  56    page exclusively mapped
> >   * Bit  57    pte is uffd-wp write-protected
> > - * Bits 58-60 zero
> > + * Bit  58    pte is a guard region
> > + * Bits 59-60 zero
> >   * Bit  61    page is file-page or shared-anon
> >   * Bit  62    page swapped
> >   * Bit  63    page present
> > --
> > 2.48.1
> >


  reply	other threads:[~2025-02-21 17:46 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-21 12:05 [PATCH 0/2] fs/proc/task_mmu: add guard region bit to pagemap Lorenzo Stoakes
2025-02-21 12:05 ` [PATCH 1/2] " Lorenzo Stoakes
2025-02-21 17:10   ` Kalesh Singh
2025-02-21 17:45     ` Lorenzo Stoakes [this message]
2025-02-24  9:27   ` David Hildenbrand
2025-02-24 10:18     ` Lorenzo Stoakes
2025-02-24 10:37       ` David Hildenbrand
2025-02-24 10:49         ` Lorenzo Stoakes
2025-02-24 13:28           ` David Hildenbrand
2025-03-19 18:22         ` Andrei Vagin
2025-03-19 19:12           ` Lorenzo Stoakes
2025-03-19 23:57             ` Greg Kroah-Hartman
2025-02-21 12:05 ` [PATCH 2/2] tools/selftests: add guard region test for /proc/$pid/pagemap Lorenzo Stoakes
2025-02-21 13:51   ` Lorenzo Stoakes
2025-02-21 17:14     ` Kalesh Singh

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=f5a896b9-039b-464a-b2d1-eac0ddfcce65@lucifer.local \
    --to=lorenzo.stoakes@oracle.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=corbet@lwn.net \
    --cc=david@redhat.com \
    --cc=jannh@google.com \
    --cc=jyescas@google.com \
    --cc=kaleshsingh@google.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=paulmck@kernel.org \
    --cc=shuah@kernel.org \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    /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