linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: David Hildenbrand <david@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Muchun Song <muchun.song@linux.dev>,
	Andrew Morton <akpm@linux-foundation.org>,
	Guillaume Morin <guillaume@morinfr.org>
Subject: Re: [PATCH v1] mm/hugetlb: don't map folios writable without VM_WRITE when copying during fork()
Date: Wed, 4 Dec 2024 11:13:06 -0500	[thread overview]
Message-ID: <Z1B_kl7YZ4DBX7yP@x1n> (raw)
In-Reply-To: <20241204153100.1967364-1-david@redhat.com>

On Wed, Dec 04, 2024 at 04:31:00PM +0100, David Hildenbrand wrote:
> If we have to trigger a hugetlb folio copy during fork() because the anon
> folio might be pinned, we currently unconditionally create a writable
> PTE.
> 
> However, the VMA might not have write permissions (VM_WRITE) at that
> point.
> 
> Fix it by checking the VMA for VM_WRITE. Make the code less error prone
> by moving checking for VM_WRITE into make_huge_pte(), and letting
> callers only specify whether we should try making it writable.
> 
> A simple reproducer that longter-pins the folios using liburing to then
> mprotect(PROT_READ) the folios befor fork() [1] results in:
> 
> Before:
> [FAIL] access should not have worked
> 
> After:
> [PASS] access did not work as expected
> 
> [1] https://gitlab.com/davidhildenbrand/scratchspace/-/raw/main/reproducers/hugetlb-mkwrite-fork.c
> 
> This is rather a corner case, so stable might not be warranted.
> 
> Fixes: 4eae4efa2c29 ("hugetlb: do early cow when page pinned on src mm")
> Cc: Muchun Song <muchun.song@linux.dev>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Peter Xu <peterx@redhat.com>
> Cc: Guillaume Morin <guillaume@morinfr.org>
> Signed-off-by: David Hildenbrand <david@redhat.com>

Acked-by: Peter Xu <peterx@redhat.com>

Thanks,

-- 
Peter Xu



      reply	other threads:[~2024-12-04 16:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-04 15:31 David Hildenbrand
2024-12-04 16:13 ` Peter Xu [this message]

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=Z1B_kl7YZ4DBX7yP@x1n \
    --to=peterx@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=guillaume@morinfr.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    /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