• Axel Rasmussen's avatar
    mm: make PTE_MARKER_SWAPIN_ERROR more general · af19487f
    Axel Rasmussen authored
    Patch series "add UFFDIO_POISON to simulate memory poisoning with UFFD",
    v4.
    
    This series adds a new userfaultfd feature, UFFDIO_POISON. See commit 4
    for a detailed description of the feature.
    
    
    This patch (of 8):
    
    Future patches will reuse PTE_MARKER_SWAPIN_ERROR to implement
    UFFDIO_POISON, so make some various preparations for that:
    
    First, rename it to just PTE_MARKER_POISONED.  The "SWAPIN" can be
    confusing since we're going to re-use it for something not really related
    to swap.  This can be particularly confusing for things like hugetlbfs,
    which doesn't support swap whatsoever.  Also rename some various helper
    functions.
    
    Next, fix pte marker copying for hugetlbfs.  Previously, it would WARN on
    seeing a PTE_MARKER_SWAPIN_ERROR, since hugetlbfs doesn't support swap. 
    But, since we're going to re-use it, we want it to go ahead and copy it
    just like non-hugetlbfs memory does today.  Since the code to do this is
    more complicated now, pull it out into a helper which can be re-used in
    both places.  While we're at it, also make it slightly more explicit in
    its handling of e.g.  uffd wp markers.
    
    For non-hugetlbfs page faults, instead of returning VM_FAULT_SIGBUS for an
    error entry, return VM_FAULT_HWPOISON.  For most cases this change doesn't
    matter, e.g.  a userspace program would receive a SIGBUS either way.  But
    for UFFDIO_POISON, this change will let KVM guests get an MCE out of the
    box, instead of giving a SIGBUS to the hypervisor and requiring it to
    somehow inject an MCE.
    
    Finally, for hugetlbfs faults, handle PTE_MARKER_POISONED, and return
    VM_FAULT_HWPOISON_LARGE in such cases.  Note that this can't happen today
    because the lack of swap support means we'll never end up with such a PTE
    anyway, but this behavior will be needed once such entries *can* show up
    via UFFDIO_POISON.
    
    Link: https://lkml.kernel.org/r/20230707215540.2324998-1-axelrasmussen@google.com
    Link: https://lkml.kernel.org/r/20230707215540.2324998-2-axelrasmussen@google.comSigned-off-by: default avatarAxel Rasmussen <axelrasmussen@google.com>
    Acked-by: default avatarPeter Xu <peterx@redhat.com>
    Cc: Al Viro <viro@zeniv.linux.org.uk>
    Cc: Brian Geffon <bgeffon@google.com>
    Cc: Christian Brauner <brauner@kernel.org>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: Gaosheng Cui <cuigaosheng1@huawei.com>
    Cc: Huang, Ying <ying.huang@intel.com>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: James Houghton <jthoughton@google.com>
    Cc: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
    Cc: Jiaqi Yan <jiaqiyan@google.com>
    Cc: Jonathan Corbet <corbet@lwn.net>
    Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
    Cc: Liam R. Howlett <Liam.Howlett@oracle.com>
    Cc: Miaohe Lin <linmiaohe@huawei.com>
    Cc: Mike Kravetz <mike.kravetz@oracle.com>
    Cc: Mike Rapoport (IBM) <rppt@kernel.org>
    Cc: Muchun Song <muchun.song@linux.dev>
    Cc: Nadav Amit <namit@vmware.com>
    Cc: Naoya Horiguchi <naoya.horiguchi@nec.com>
    Cc: Ryan Roberts <ryan.roberts@arm.com>
    Cc: Shuah Khan <shuah@kernel.org>
    Cc: Suleiman Souhlal <suleiman@google.com>
    Cc: Suren Baghdasaryan <surenb@google.com>
    Cc: T.J. Alumbaugh <talumbau@google.com>
    Cc: Yu Zhao <yuzhao@google.com>
    Cc: ZhangPeng <zhangpeng362@huawei.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    af19487f
swapfile.c 92.4 KB