• Axel Rasmussen's avatar
    selftests/mm: add uffd unit test for UFFDIO_POISON · 99aa7721
    Axel Rasmussen authored
    The test is pretty basic, and exercises UFFDIO_POISON straightforwardly. 
    We register a region with userfaultfd, in missing fault mode.  For each
    fault, we either UFFDIO_COPY a zeroed page (odd pages) or UFFDIO_POISON
    (even pages).  We do this mix to test "something like a real use case",
    where guest memory would be some mix of poisoned and non-poisoned pages.
    
    We read each page in the region, and assert that the odd pages are zeroed
    as expected, and the even pages yield a SIGBUS as expected.
    
    Why UFFDIO_COPY instead of UFFDIO_ZEROPAGE?  Because hugetlb doesn't
    support UFFDIO_ZEROPAGE, and we don't want to have special case code.
    
    Link: https://lkml.kernel.org/r/20230707215540.2324998-9-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>
    99aa7721
uffd-unit-tests.c 33.2 KB