From: David Hildenbrand <dhildenb@redhat.com>
To: Oscar Salvador <osalvador@suse.de>,
Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Muchun Song <muchun.song@linux.dev>,
Vishal Moola <vishal.moola@gmail.com>
Subject: Re: [PATCH] mm/hugetlb: Move vmf_anon_prepare upfront in hugetlb_wp
Date: Mon, 27 May 2024 15:17:01 +0200 [thread overview]
Message-ID: <9f3371fa-0d46-4e93-a00b-0f5cb30b58bb@redhat.com> (raw)
In-Reply-To: <ZlRKI_tJ2CYhmekw@localhost.localdomain>
Am 27.05.24 um 10:53 schrieb Oscar Salvador:
> On Tue, May 21, 2024 at 09:34:46AM +0200, Oscar Salvador wrote:
>> I did not hit this bug, I just spotted this because I was looking at hugetlb_wp
>> for some other reason. And I did not want to get creative to see if I could
>> trigger this so I could get a backtrace.
>> My assumption is that we could trigger this if 1) this was a shared mapping,
>> so no anon_vma and 2) we call in GUP code with FOLL_WRITE, which would cause
>> the FLAG_UNSHARE to be passed, so we will end up in hugetlb_wp().
>
> So I checked this again and I have to confess I am bit confused.
>
> hugetlb_wp() can be called from either hugetlb_fault() or hugetlb_no_page().
>
> hugetlb_fault()->hugetlb_wp() upon FAULT_FLAG_{WRITE,UNSHARE}
> hugetlb_no_page->hugetlb_wp()-> upon FAULT_FLAG_WRITE && !VM_SHARED
>
> hugetlb_no_page()->vmf_anon_prepare() upon !VM_SHARED, which means that VM_SHARED
> mappings do not have vma->anon_vma, while others do.
>
> hugetlb_wp() will call set_huge_ptep_writable() right away and return if it sees
> that the mapping is shared.
> So the only other we have to end up in hugetlb_wp() is via FAULT_FLAG_UNSHARE.
> For that to happen gup_must_unshare() must return true, which means the following
> assumptions must hold.
>
> - For Anonymous pages:
> 1) !PageAnonExclusive
> - For Filebacked pages:
> 2) We do not have a vma
> 3) It is a COW mapping
>
> 1) If gup_must_unshare() returns true for Anonymous pages because the page is not
> exclusive and must be unshared, hugetlb_wp() will already see the
> vma->anon_prepare being initialized because of the previous
> hugetlb_no_page()->vmf_anon_prepare.
>
> 2) I do not quite understand this case.
gup_must_unshare() without a VMA is only used for GUP-fast. Before triggering a
page fault we always fallback to GUP-slow first, where we have a VMA.
IMHO we better not make assumptions that hugetlb_wp() will always already have
an anon VMA.
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2024-05-27 13:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-21 7:34 Oscar Salvador
2024-05-21 9:56 ` David Hildenbrand
2024-05-21 10:23 ` Oscar Salvador
2024-05-27 8:53 ` Oscar Salvador
2024-05-27 13:17 ` David Hildenbrand [this message]
2024-05-27 13:54 ` Oscar Salvador
2024-06-12 20:27 ` Oscar Salvador
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=9f3371fa-0d46-4e93-a00b-0f5cb30b58bb@redhat.com \
--to=dhildenb@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=vishal.moola@gmail.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