From: Peter Xu <peterx@redhat.com>
To: James Houghton <jthoughton@google.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Andrew Morton <akpm@linux-foundation.org>,
Christian Brauner <brauner@kernel.org>,
David Hildenbrand <david@redhat.com>,
Huang Ying <ying.huang@intel.com>,
Hugh Dickins <hughd@google.com>, Jiaqi Yan <jiaqiyan@google.com>,
Jonathan Corbet <corbet@lwn.net>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Miaohe Lin <linmiaohe@huawei.com>,
Mike Kravetz <mike.kravetz@oracle.com>,
"Mike Rapoport (IBM)" <rppt@kernel.org>,
Muchun Song <muchun.song@linux.dev>,
Nadav Amit <namit@vmware.com>,
Naoya Horiguchi <naoya.horiguchi@nec.com>,
Shuah Khan <shuah@kernel.org>,
ZhangPeng <zhangpeng362@huawei.com>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v2 1/6] mm: userfaultfd: add new UFFDIO_POISON ioctl
Date: Wed, 5 Jul 2023 12:15:22 -0400 [thread overview]
Message-ID: <ZKWXGnSKcOdnaeJw@x1n> (raw)
In-Reply-To: <CADrL8HXp-P44VxTXdJMkzSgPC8r_b0T21_cuPCTNy6Ub2PFBKA@mail.gmail.com>
On Wed, Jul 05, 2023 at 09:09:19AM -0700, James Houghton wrote:
> > > diff --git a/include/linux/swapops.h b/include/linux/swapops.h
> > > index 4c932cb45e0b..8259fee32421 100644
> > > --- a/include/linux/swapops.h
> > > +++ b/include/linux/swapops.h
> > > @@ -394,7 +394,8 @@ typedef unsigned long pte_marker;
> > >
> > > #define PTE_MARKER_UFFD_WP BIT(0)
> > > #define PTE_MARKER_SWAPIN_ERROR BIT(1)
> > > -#define PTE_MARKER_MASK (BIT(2) - 1)
> > > +#define PTE_MARKER_UFFD_POISON BIT(2)
> >
> > One more tab.
> >
> > Though I remembered the last time we discussed IIRC we plan to rename
> > SWAPIN_ERROR and reuse it, could you explain why a new bit is still needed?
> >
> > I think I commented this but I'll do it again: IIUC any existing host
> > swapin errors for guest pages should be reported as MCE too, afaict,
> > happened in kvm context.
>
> I think swapin errors are treated differently than poison. Swapin
> errors get VM_FAULT_SIGBUS, and poison gets VM_FAULT_HWPOISON, so
> UFFDIO_POISON should also get VM_FAULT_HWPOISON (so that's what Axel
> has implemented). And I think that needs a separate PTE marker.
My question was, should we also make SWAPIN_ERROR return VM_FAULT_HWPOISON
always?
Just to recap from what I already commented above - if a guest page got
error in swapin due to block sector failures, it should be treated as
VM_FAULT_HWPOISON too, IMHO. IOW, I think current SWAPIN_ERROR is wrong
when in kvm context and we should fix it first.
>
> >
> > > +#define PTE_MARKER_MASK (BIT(3) - 1)
> > >
> > > static inline swp_entry_t make_pte_marker_entry(pte_marker marker)
> > > {
> > > diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h
> > > index ac7b0c96d351..ac8c6854097c 100644
> > > --- a/include/linux/userfaultfd_k.h
> > > +++ b/include/linux/userfaultfd_k.h
> > > @@ -46,6 +46,7 @@ enum mfill_atomic_mode {
> > > MFILL_ATOMIC_COPY,
> > > MFILL_ATOMIC_ZEROPAGE,
> > > MFILL_ATOMIC_CONTINUE,
> > > + MFILL_ATOMIC_POISON,
> > > NR_MFILL_ATOMIC_MODES,
> > > };
> > >
> > > @@ -83,6 +84,9 @@ extern ssize_t mfill_atomic_zeropage(struct mm_struct *dst_mm,
> > > extern ssize_t mfill_atomic_continue(struct mm_struct *dst_mm, unsigned long dst_start,
> > > unsigned long len, atomic_t *mmap_changing,
> > > uffd_flags_t flags);
> > > +extern ssize_t mfill_atomic_poison(struct mm_struct *dst_mm, unsigned long start,
> > > + unsigned long len, atomic_t *mmap_changing,
> > > + uffd_flags_t flags);
> > > extern int mwriteprotect_range(struct mm_struct *dst_mm,
> > > unsigned long start, unsigned long len,
> > > bool enable_wp, atomic_t *mmap_changing);
> > > diff --git a/include/uapi/linux/userfaultfd.h b/include/uapi/linux/userfaultfd.h
> > > index 66dd4cd277bd..62151706c5a3 100644
> > > --- a/include/uapi/linux/userfaultfd.h
> > > +++ b/include/uapi/linux/userfaultfd.h
> > > @@ -39,7 +39,8 @@
> > > UFFD_FEATURE_MINOR_SHMEM | \
> > > UFFD_FEATURE_EXACT_ADDRESS | \
> > > UFFD_FEATURE_WP_HUGETLBFS_SHMEM | \
> > > - UFFD_FEATURE_WP_UNPOPULATED)
> > > + UFFD_FEATURE_WP_UNPOPULATED | \
> > > + UFFD_FEATURE_POISON)
> > > #define UFFD_API_IOCTLS \
> > > ((__u64)1 << _UFFDIO_REGISTER | \
> > > (__u64)1 << _UFFDIO_UNREGISTER | \
> > > @@ -49,12 +50,14 @@
> > > (__u64)1 << _UFFDIO_COPY | \
> > > (__u64)1 << _UFFDIO_ZEROPAGE | \
> > > (__u64)1 << _UFFDIO_WRITEPROTECT | \
> > > - (__u64)1 << _UFFDIO_CONTINUE)
> > > + (__u64)1 << _UFFDIO_CONTINUE | \
> > > + (__u64)1 << _UFFDIO_POISON)
> > > #define UFFD_API_RANGE_IOCTLS_BASIC \
> > > ((__u64)1 << _UFFDIO_WAKE | \
> > > (__u64)1 << _UFFDIO_COPY | \
> > > + (__u64)1 << _UFFDIO_WRITEPROTECT | \
> > > (__u64)1 << _UFFDIO_CONTINUE | \
> > > - (__u64)1 << _UFFDIO_WRITEPROTECT)
> > > + (__u64)1 << _UFFDIO_POISON)
> >
> > May not be a large deal, but it's still better to declare the feature &
> > ioctls after all things implemented. Maybe make these few lines
> > (UFFD_API*, and the new feature bit) as the last patch to enable the
> > feature?
>
> I agree. Another option would be to have a separate feature for
> UFFDIO_POISON for hugetlb, but I don't think we should do that. :)
Yeah let's make the features "memory-type-free" if possible. :)
Thanks,
--
Peter Xu
next prev parent reply other threads:[~2023-07-05 16:16 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-29 20:50 [PATCH v2 1/6] mm: userfaultfd: add new UFFDIO_POISON ioctl Axel Rasmussen
2023-06-29 20:50 ` [PATCH v2 2/6] mm: userfaultfd: refactor hugetlb folio allocation / lookup code Axel Rasmussen
2023-07-04 20:57 ` Peter Xu
2023-06-29 20:50 ` [PATCH v2 3/6] mm: userfaultfd: support UFFDIO_POISON for hugetlbfs Axel Rasmussen
2023-07-04 20:59 ` Peter Xu
2023-06-29 20:50 ` [PATCH v2 4/6] selftests/mm: refactor uffd_poll_thread to allow custom fault handlers Axel Rasmussen
2023-07-04 21:03 ` Peter Xu
2023-07-05 17:50 ` Axel Rasmussen
2023-07-05 18:17 ` Peter Xu
2023-06-29 20:50 ` [PATCH v2 5/6] selftests/mm: add uffd unit test for UFFDIO_POISON Axel Rasmussen
2023-07-04 21:15 ` Peter Xu
2023-06-29 20:50 ` [PATCH v2 6/6] mm: userfaultfd: add basic documentation " Axel Rasmussen
2023-06-29 21:04 ` Randy Dunlap
2023-07-04 21:16 ` Peter Xu
2023-07-04 20:38 ` [PATCH v2 1/6] mm: userfaultfd: add new UFFDIO_POISON ioctl Peter Xu
2023-07-05 16:09 ` James Houghton
2023-07-05 16:15 ` Peter Xu [this message]
2023-07-05 16:27 ` James Houghton
2023-07-05 16:38 ` Peter Xu
2023-07-05 17:56 ` Axel Rasmussen
2023-07-05 15:58 ` James Houghton
2023-07-05 18:17 ` Jiaqi Yan
2023-07-05 18:23 ` Axel Rasmussen
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=ZKWXGnSKcOdnaeJw@x1n \
--to=peterx@redhat.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=axelrasmussen@google.com \
--cc=brauner@kernel.org \
--cc=corbet@lwn.net \
--cc=david@redhat.com \
--cc=hughd@google.com \
--cc=jiaqiyan@google.com \
--cc=jthoughton@google.com \
--cc=linmiaohe@huawei.com \
--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=mike.kravetz@oracle.com \
--cc=muchun.song@linux.dev \
--cc=namit@vmware.com \
--cc=naoya.horiguchi@nec.com \
--cc=rppt@kernel.org \
--cc=shuah@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=ying.huang@intel.com \
--cc=zhangpeng362@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.