From: Mike Kravetz <mike.kravetz@oracle.com>
To: Peter Xu <peterx@redhat.com>
Cc: David Hildenbrand <david@redhat.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Andrew Morton <akpm@linux-foundation.org>,
Muchun Song <songmuchun@bytedance.com>,
Peter Feiner <pfeiner@google.com>,
"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
Subject: Re: [PATCH v1 2/2] mm/hugetlb: support write-faults in shared mappings
Date: Fri, 5 Aug 2022 16:08:08 -0700 [thread overview]
Message-ID: <Yu2i2K421LgaMyxp@monkey> (raw)
In-Reply-To: <Yu1dkZeBwv0SUQMq@xz-m1.local>
On 08/05/22 14:12, Peter Xu wrote:
> On Fri, Aug 05, 2022 at 01:03:29PM +0200, David Hildenbrand wrote:
> > Let's add a safety net if we ever get (again) a write-fault on a R/O-mapped
> > page in a shared mapping, in which case we simply have to map the
> > page writable.
> >
> > + if (WARN_ON_ONCE(!(vma->vm_flags & VM_WRITE)))
> > + return VM_FAULT_SIGSEGV;
>
> I had a feeling that you just want to double check we have write
> permission, but IIUC this should be checked far earlier or we'll have
> problem.
Back when I was exploring hugetlb softdirty support, this patch handled
this condition by not calling into hugetlb_wp (was hugetlb_cow).
https://lore.kernel.org/linux-mm/20210211000322.159437-3-mike.kravetz@oracle.com/
Here is a quickly updated version that was only tested with David's program.
--
Mike Kravetz
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index a23f1cffaf49..86d38d41fddf 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -5758,9 +5758,10 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
* spinlock. For private mappings, we also lookup the pagecache
* page now as it is used to determine if a reservation has been
* consumed.
+ * Only private/non-shared mappings are sent to hugetlb_wp.
*/
if ((flags & (FAULT_FLAG_WRITE|FAULT_FLAG_UNSHARE)) &&
- !huge_pte_write(entry)) {
+ !huge_pte_write(entry) && !(vma->vm_flags & VM_MAYSHARE)) {
if (vma_needs_reservation(h, vma, haddr) < 0) {
ret = VM_FAULT_OOM;
goto out_mutex;
@@ -5768,8 +5769,7 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
/* Just decrements count, does not deallocate */
vma_end_reservation(h, vma, haddr);
- if (!(vma->vm_flags & VM_MAYSHARE))
- pagecache_page = hugetlbfs_pagecache_page(h,
+ pagecache_page = hugetlbfs_pagecache_page(h,
vma, haddr);
}
@@ -5815,9 +5815,14 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
if (flags & (FAULT_FLAG_WRITE|FAULT_FLAG_UNSHARE)) {
if (!huge_pte_write(entry)) {
- ret = hugetlb_wp(mm, vma, address, ptep, flags,
+ if (!(vma->vm_flags & VM_MAYSHARE)) {
+ ret = hugetlb_wp(mm, vma, address, ptep, flags,
pagecache_page, ptl);
- goto out_put_page;
+ goto out_put_page;
+ }
+
+ entry = huge_pte_mkwrite(entry);
+ entry = huge_pte_mkdirty(entry);
} else if (likely(flags & FAULT_FLAG_WRITE)) {
entry = huge_pte_mkdirty(entry);
}
prev parent reply other threads:[~2022-08-05 23:08 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-05 11:03 [PATCH v1 0/2] mm/hugetlb: fix write-fault handling for " David Hildenbrand
2022-08-05 11:03 ` [PATCH v1 1/2] mm/hugetlb: fix hugetlb not supporting write-notify David Hildenbrand
2022-08-05 18:14 ` Peter Xu
2022-08-05 18:22 ` David Hildenbrand
2022-08-05 18:23 ` Mike Kravetz
2022-08-05 18:25 ` David Hildenbrand
2022-08-05 18:33 ` Mike Kravetz
2022-08-05 18:57 ` David Hildenbrand
2022-08-05 20:48 ` Mike Kravetz
2022-08-05 23:13 ` Peter Xu
2022-08-05 23:33 ` Mike Kravetz
2022-08-08 16:10 ` Peter Xu
2022-08-08 16:36 ` David Hildenbrand
2022-08-08 19:28 ` Peter Xu
2022-08-10 9:29 ` David Hildenbrand
2022-08-05 11:03 ` [PATCH v1 2/2] mm/hugetlb: support write-faults in shared mappings David Hildenbrand
2022-08-05 18:12 ` Peter Xu
2022-08-05 18:20 ` David Hildenbrand
2022-08-08 16:05 ` Peter Xu
2022-08-08 16:25 ` David Hildenbrand
2022-08-08 20:21 ` Peter Xu
2022-08-08 22:08 ` Peter Xu
2022-08-10 9:37 ` David Hildenbrand
2022-08-10 9:45 ` David Hildenbrand
2022-08-10 19:29 ` Peter Xu
2022-08-10 19:40 ` David Hildenbrand
2022-08-10 19:52 ` Peter Xu
2022-08-10 23:55 ` Mike Kravetz
2022-08-11 8:48 ` David Hildenbrand
2022-08-05 23:08 ` Mike Kravetz [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=Yu2i2K421LgaMyxp@monkey \
--to=mike.kravetz@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=peterx@redhat.com \
--cc=pfeiner@google.com \
--cc=songmuchun@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