Skip to content
Snippets Groups Projects
  1. Jan 06, 2022
  2. Jan 05, 2022
  3. Jan 01, 2022
  4. Dec 31, 2021
    • Mike Kravetz's avatar
      userfaultfd/selftests: fix hugetlb area allocations · f5c73297
      Mike Kravetz authored
      Currently, userfaultfd selftest for hugetlb as run from run_vmtests.sh
      or any environment where there are 'just enough' hugetlb pages will
      always fail with:
      
        testing events (fork, remap, remove):
      		ERROR: UFFDIO_COPY error: -12 (errno=12, line=616)
      
      The ENOMEM error code implies there are not enough hugetlb pages.
      However, there are free hugetlb pages but they are all reserved.  There
      is a basic problem with the way the test allocates hugetlb pages which
      has existed since the test was originally written.
      
      Due to the way 'cleanup' was done between different phases of the test,
      this issue was masked until recently.  The issue was uncovered by commit
      8ba6e864 ("userfaultfd/selftests: reinitialize test context in each
      test").
      
      For the hugetlb test, src and dst areas are allocated as PRIVATE
      mappings of a hugetlb file.  This means that at mmap time, pages are
      reserved for the src and dst areas.  At the start of event testing (and
      other tests) the src area is populated which results in allocation of
      huge pages to fill the area and consumption of reserves associated with
      the area.  Then, a child is forked to fault in the dst area.  Note that
      the dst area was allocated in the parent and hence the parent owns the
      reserves associated with the mapping.  The child has normal access to
      the dst area, but can not use the reserves created/owned by the parent.
      Thus, if there are no other huge pages available allocation of a page
      for the dst by the child will fail.
      
      Fix by not creating reserves for the dst area.  In this way the child
      can use free (non-reserved) pages.
      
      Also, MAP_PRIVATE of a file only makes sense if you are interested in
      the contents of the file before making a COW copy.  The test does not do
      this.  So, just use MAP_ANONYMOUS | MAP_HUGETLB to create an anonymous
      hugetlb mapping.  There is no need to create a hugetlb file in the
      non-shared case.
      
      Link: https://lkml.kernel.org/r/20211217172919.7861-1-mike.kravetz@oracle.com
      
      
      Signed-off-by: default avatarMike Kravetz <mike.kravetz@oracle.com>
      Cc: Axel Rasmussen <axelrasmussen@google.com>
      Cc: Peter Xu <peterx@redhat.com>
      Cc: Andrea Arcangeli <aarcange@redhat.com>
      Cc: Mina Almasry <almasrymina@google.com>
      Cc: Shuah Khan <shuah@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      f5c73297
  5. Dec 30, 2021
  6. Dec 25, 2021
  7. Dec 24, 2021
  8. Dec 20, 2021
    • Sean Christopherson's avatar
      KVM: selftests: Add test to verify TRIPLE_FAULT on invalid L2 guest state · ab1ef344
      Sean Christopherson authored
      
      Add a selftest to attempt to enter L2 with invalid guests state by
      exiting to userspace via I/O from L2, and then using KVM_SET_SREGS to set
      invalid guest state (marking TR unusable is arbitrary chosen for its
      relative simplicity).
      
      This is a regression test for a bug introduced by commit c8607e4a
      ("KVM: x86: nVMX: don't fail nested VM entry on invalid guest state if
      !from_vmentry"), which incorrectly set vmx->fail=true when L2 had invalid
      guest state and ultimately triggered a WARN due to nested_vmx_vmexit()
      seeing vmx->fail==true while attempting to synthesize a nested VM-Exit.
      
      The is also a functional test to verify that KVM sythesizes TRIPLE_FAULT
      for L2, which is somewhat arbitrary behavior, instead of emulating L2.
      KVM should never emulate L2 due to invalid guest state, as it's
      architecturally impossible for L1 to run an L2 guest with invalid state
      as nested VM-Enter should always fail, i.e. L1 needs to do the emulation.
      Stuffing state via KVM ioctl() is a non-architctural, out-of-band case,
      hence the TRIPLE_FAULT being rather arbitrary.
      
      Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
      Message-Id: <20211207193006.120997-5-seanjc@google.com>
      Reviewed-by: default avatarMaxim Levitsky <mlevitsk@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      ab1ef344
    • Andrew Jones's avatar
      selftests: KVM: Fix non-x86 compiling · 577e022b
      Andrew Jones authored
      
      Attempting to compile on a non-x86 architecture fails with
      
      include/kvm_util.h: In function ‘vm_compute_max_gfn’:
      include/kvm_util.h:79:21: error: dereferencing pointer to incomplete type ‘struct kvm_vm’
        return ((1ULL << vm->pa_bits) >> vm->page_shift) - 1;
                           ^~
      
      This is because the declaration of struct kvm_vm is in
      lib/kvm_util_internal.h as an effort to make it private to
      the test lib code. We can still provide arch specific functions,
      though, by making the generic function symbols weak. Do that to
      fix the compile error.
      
      Fixes: c8cc43c1 ("selftests: KVM: avoid failures due to reserved HyperTransport region")
      Cc: stable@vger.kernel.org
      Signed-off-by: default avatarAndrew Jones <drjones@redhat.com>
      Message-Id: <20211214151842.848314-1-drjones@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      577e022b
  9. Dec 19, 2021
  10. Dec 17, 2021
  11. Dec 16, 2021
  12. Dec 15, 2021
    • Daniel Borkmann's avatar
      bpf, selftests: Update test case for atomic cmpxchg on r0 with pointer · e523102c
      Daniel Borkmann authored
      
      Fix up unprivileged test case results for 'Dest pointer in r0' verifier tests
      given they now need to reject R0 containing a pointer value, and add a couple
      of new related ones with 32bit cmpxchg as well.
      
        root@foo:~/bpf/tools/testing/selftests/bpf# ./test_verifier
        #0/u invalid and of negative number OK
        #0/p invalid and of negative number OK
        [...]
        #1268/p XDP pkt read, pkt_meta' <= pkt_data, bad access 1 OK
        #1269/p XDP pkt read, pkt_meta' <= pkt_data, bad access 2 OK
        #1270/p XDP pkt read, pkt_data <= pkt_meta', good access OK
        #1271/p XDP pkt read, pkt_data <= pkt_meta', bad access 1 OK
        #1272/p XDP pkt read, pkt_data <= pkt_meta', bad access 2 OK
        Summary: 1900 PASSED, 0 SKIPPED, 0 FAILED
      
      Acked-by: default avatarBrendan Jackman <jackmanb@google.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      e523102c
    • Daniel Borkmann's avatar
      bpf, selftests: Add test case for atomic fetch on spilled pointer · 180486b4
      Daniel Borkmann authored
      
      Test whether unprivileged would be able to leak the spilled pointer either
      by exporting the returned value from the atomic{32,64} operation or by reading
      and exporting the value from the stack after the atomic operation took place.
      
      Note that for unprivileged, the below atomic cmpxchg test case named "Dest
      pointer in r0 - succeed" is failing. The reason is that in the dst memory
      location (r10 -8) there is the spilled register r10:
      
        0: R1=ctx(id=0,off=0,imm=0) R10=fp0
        0: (bf) r0 = r10
        1: R0_w=fp0 R1=ctx(id=0,off=0,imm=0) R10=fp0
        1: (7b) *(u64 *)(r10 -8) = r0
        2: R0_w=fp0 R1=ctx(id=0,off=0,imm=0) R10=fp0 fp-8_w=fp
        2: (b7) r1 = 0
        3: R0_w=fp0 R1_w=invP0 R10=fp0 fp-8_w=fp
        3: (db) r0 = atomic64_cmpxchg((u64 *)(r10 -8), r0, r1)
        4: R0_w=fp0 R1_w=invP0 R10=fp0 fp-8_w=mmmmmmmm
        4: (79) r1 = *(u64 *)(r0 -8)
        5: R0_w=fp0 R1_w=invP(id=0) R10=fp0 fp-8_w=mmmmmmmm
        5: (b7) r0 = 0
        6: R0_w=invP0 R1_w=invP(id=0) R10=fp0 fp-8_w=mmmmmmmm
        6: (95) exit
      
      However, allowing this case for unprivileged is a bit useless given an
      update with a new pointer will fail anyway:
      
        0: R1=ctx(id=0,off=0,imm=0) R10=fp0
        0: (bf) r0 = r10
        1: R0_w=fp0 R1=ctx(id=0,off=0,imm=0) R10=fp0
        1: (7b) *(u64 *)(r10 -8) = r0
        2: R0_w=fp0 R1=ctx(id=0,off=0,imm=0) R10=fp0 fp-8_w=fp
        2: (db) r0 = atomic64_cmpxchg((u64 *)(r10 -8), r0, r10)
        R10 leaks addr into mem
      
      Acked-by: default avatarBrendan Jackman <jackmanb@google.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
      180486b4
  13. Dec 14, 2021
  14. Dec 13, 2021
  15. Dec 12, 2021
  16. Dec 11, 2021
  17. Dec 10, 2021
  18. Dec 09, 2021
  19. Dec 08, 2021
Loading