From: David Hildenbrand <david@redhat.com>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
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>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Shuah Khan <shuah@kernel.org>,
linux-kselftest@vger.kernel.org, linux-api@vger.kernel.org,
John Hubbard <jhubbard@nvidia.com>,
Juan Yescas <jyescas@google.com>,
Kalesh Singh <kaleshsingh@google.com>
Subject: Re: [PATCH 1/4] mm: allow guard regions in file-backed and read-only mappings
Date: Tue, 18 Feb 2025 17:17:20 +0100 [thread overview]
Message-ID: <90a00957-02b5-440a-9168-de93c760fea7@redhat.com> (raw)
In-Reply-To: <4d6d2942-10a1-46e8-93a6-7ce52b6af3ad@lucifer.local>
On 18.02.25 17:12, Lorenzo Stoakes wrote:
> On Tue, Feb 18, 2025 at 05:01:16PM +0100, David Hildenbrand wrote:
>> On 13.02.25 19:17, Lorenzo Stoakes wrote:
>>> There is no reason to disallow guard regions in file-backed mappings -
>>> readahead and fault-around both function correctly in the presence of PTE
>>> markers, equally other operations relating to memory-mapped files function
>>> correctly.
>>>
>>> Additionally, read-only mappings if introducing guard-regions, only
>>> restrict the mapping further, which means there is no violation of any
>>> access rights by permitting this to be so.
>>>
>>> Removing this restriction allows for read-only mapped files (such as
>>> executable files) correctly which would otherwise not be permitted.
>>>
>>> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
>>> ---
>>> mm/madvise.c | 8 +-------
>>> 1 file changed, 1 insertion(+), 7 deletions(-)
>>>
>>> diff --git a/mm/madvise.c b/mm/madvise.c
>>> index 6ecead476a80..e01e93e179a8 100644
>>> --- a/mm/madvise.c
>>> +++ b/mm/madvise.c
>>> @@ -1051,13 +1051,7 @@ static bool is_valid_guard_vma(struct vm_area_struct *vma, bool allow_locked)
>>> if (!allow_locked)
>>> disallowed |= VM_LOCKED;
>>> - if (!vma_is_anonymous(vma))
>>> - return false;
>>> -
>>> - if ((vma->vm_flags & (VM_MAYWRITE | disallowed)) != VM_MAYWRITE)
>>> - return false;
>>> -
>>> - return true;
>>> + return !(vma->vm_flags & disallowed);
>>> }
>>> static bool is_guard_pte_marker(pte_t ptent)
>>
>> Acked-by: David Hildenbrand <david@redhat.com>
>
> Thanks!
>
>>
>> I assume these markers cannot completely prevent us from allocating
>> pages/folios for these underlying file/pageache ranges of these markers in
>> case of shmem during page faults, right?
>
> If the markers are in place, then page faulting will result in a
> segfault. If we faulted in a shmem page then installed markers (which would
> zap the range), then the page cache will be populated, but obviously
> subject to standard reclaim.
Well, yes, (a) if there is swap and (b), if the noswap option was not
specified for tmpfs.
Okay, so installing a guard entry might require punshing a hole to get
rid of any already-existing memory. But readahead (below) might mess it up.
>
> If we perform synchronous readahead prior to a guard region that includes
> (partially or fully) a guard region we might major fault entries into the
> page cache that are then not accessable _from that mapping_, this is rather
> unavoidable as this doesn't account for page table mappings and should be
> largely trivial overhead (also these folios are reclaimable).
Right, that's what I had in mind: assume I have a single marker in a
PMD, shmem might allocate a PMD THP to back that region, ignoring the
marker hint. (so I think)
Thanks!
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2025-02-18 16:17 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-13 18:16 [PATCH 0/4] mm: permit guard regions for file-backed/shmem mappings Lorenzo Stoakes
2025-02-13 18:17 ` [PATCH 1/4] mm: allow guard regions in file-backed and read-only mappings Lorenzo Stoakes
2025-02-18 14:15 ` Vlastimil Babka
2025-02-18 16:01 ` David Hildenbrand
2025-02-18 16:12 ` Lorenzo Stoakes
2025-02-18 16:17 ` David Hildenbrand [this message]
2025-02-18 16:21 ` Lorenzo Stoakes
2025-02-18 16:27 ` David Hildenbrand
2025-02-18 16:49 ` Lorenzo Stoakes
2025-02-18 17:00 ` David Hildenbrand
2025-02-18 17:04 ` Lorenzo Stoakes
2025-02-24 14:02 ` Lorenzo Stoakes
2025-02-13 18:17 ` [PATCH 2/4] selftests/mm: rename guard-pages to guard-regions Lorenzo Stoakes
2025-02-18 14:15 ` Vlastimil Babka
2025-03-02 8:35 ` Lorenzo Stoakes
2025-02-13 18:17 ` [PATCH 3/4] tools/selftests: expand all guard region tests to file-backed Lorenzo Stoakes
2025-02-18 14:17 ` Vlastimil Babka
2025-04-22 10:37 ` Ryan Roberts
2025-04-22 10:47 ` Lorenzo Stoakes
2025-04-22 11:03 ` Ryan Roberts
2025-04-22 11:07 ` Lorenzo Stoakes
2025-04-22 11:11 ` Ryan Roberts
2025-02-13 18:17 ` [PATCH 4/4] tools/selftests: add file/shmem-backed mapping guard region tests Lorenzo Stoakes
2025-02-18 14:18 ` Vlastimil Babka
2025-02-18 12:12 ` [PATCH 0/4] mm: permit guard regions for file-backed/shmem mappings Vlastimil Babka
2025-02-18 13:05 ` Lorenzo Stoakes
2025-02-18 14:35 ` David Hildenbrand
2025-02-18 14:53 ` Lorenzo Stoakes
2025-02-18 15:20 ` David Hildenbrand
2025-02-18 16:43 ` Lorenzo Stoakes
2025-02-18 17:14 ` David Hildenbrand
2025-02-18 17:20 ` Lorenzo Stoakes
2025-02-18 17:25 ` David Hildenbrand
2025-02-18 17:28 ` Lorenzo Stoakes
2025-02-18 17:31 ` David Hildenbrand
2025-02-25 15:54 ` Vlastimil Babka
2025-02-25 16:31 ` David Hildenbrand
2025-02-25 16:37 ` Lorenzo Stoakes
2025-02-25 16:48 ` David Hildenbrand
2025-02-19 8:25 ` Kalesh Singh
2025-02-19 8:35 ` Kalesh Singh
2025-02-19 9:15 ` Lorenzo Stoakes
2025-02-19 17:32 ` Liam R. Howlett
2025-02-19 9:03 ` Lorenzo Stoakes
2025-02-19 9:15 ` David Hildenbrand
2025-02-19 9:17 ` Lorenzo Stoakes
2025-02-19 18:52 ` Kalesh Singh
2025-02-19 19:20 ` Lorenzo Stoakes
2025-02-19 20:56 ` Kalesh Singh
2025-02-20 8:51 ` Lorenzo Stoakes
2025-02-20 8:57 ` David Hildenbrand
2025-02-20 9:04 ` Lorenzo Stoakes
2025-02-20 9:23 ` David Hildenbrand
2025-02-20 9:47 ` Lorenzo Stoakes
2025-02-20 10:03 ` David Hildenbrand
2025-02-20 10:15 ` Lorenzo Stoakes
2025-02-20 12:44 ` David Hildenbrand
2025-02-20 13:18 ` Lorenzo Stoakes
2025-02-20 16:21 ` Suren Baghdasaryan
2025-02-20 18:08 ` Kalesh Singh
2025-02-21 11:04 ` Lorenzo Stoakes
2025-02-21 17:24 ` Kalesh Singh
2025-02-20 9:22 ` Vlastimil Babka
2025-02-20 9:53 ` Lorenzo Stoakes
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=90a00957-02b5-440a-9168-de93c760fea7@redhat.com \
--to=david@redhat.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=jannh@google.com \
--cc=jhubbard@nvidia.com \
--cc=jyescas@google.com \
--cc=kaleshsingh@google.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--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;
as well as URLs for NNTP newsgroup(s).