Hi stable maintainers,

When pkey_sighandler_tests_64 is run on machines with CPUs that don't
support pkeys, instead of skipping the tests return SIGILL(illegal
instruction).

# gdb  ./pkey_sighandler_tests_64

(gdb) info registers rip
rip            0x402779            0x402779 <thread_segv_with_pkey0_disabled+9>
(gdb) disassemble /r $rip-8,$rip+8
Dump of assembler code from 0x402771 to 0x402781:
   0x0000000000402771 <thread_segv_with_pkey0_disabled+1>:      c9              
        leave
   0x0000000000402772 <thread_segv_with_pkey0_disabled+2>:      b8 55 55 55 55  
        mov    $0x55555555,%eax
   0x0000000000402777 <thread_segv_with_pkey0_disabled+7>:      89 ca           
        mov    %ecx,%edx
=> 0x0000000000402779 <thread_segv_with_pkey0_disabled+9>:      0f 01 ef        
        wrpkru
   0x000000000040277c <thread_segv_with_pkey0_disabled+12>:     0f 01 ee        
        rdpkru
   0x000000000040277f <thread_segv_with_pkey0_disabled+15>:     3d 55 55 55 55  
        cmp

Tests result in:

./pkey_sighandler_tests_64
TAP version 13
1..5
Illegal instruction (core dumped)

This is because 6.12.y commit: 1c6b1d4889d7 ("selftests/mm: skip
pkey_sighandler_tests if support is missing") like upstream and
backporting that needed few prerequsites, during this process I have
seen a few build warnings, so also included patches that help fix these
build warnings in the selftests.

All are clean cherry-picks. After patching the selftests the test is
correctly skipped. These additional backports cleansup the code and
avoids the need for conflict resolution and might help future backports.

After these backports.

# ./pkey_sighandler_tests_64
TAP version 13
1..5
ok 2 # SKIP pkeys not supported
# Planned tests != run tests (5 != 1)
# Totals: pass:0 fail:0 xfail:0 xpass:0 skip:1 error:0

And these build warnings are also cleaned up.
====

write_to_hugetlbfs.c: In function ‘main’:
write_to_hugetlbfs.c:92:25: warning: ‘strncpy’ specified bound 256 equals 
destination size [-Wstringop-truncation]
   92 |                         strncpy(path, optarg, sizeof(path));
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mremap_test.c: In function ‘run_mremap_test_case.constprop’:
mremap_test.c:530:50: warning: ‘dest_preamble_addr’ may be used uninitialized 
in this function [-Wmaybe-uninitialized]
  530 |                 if (((char *) dest_preamble_addr)[d] != rand_addr[d]) {
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
mremap_test.c:387:45: note: ‘dest_preamble_addr’ was declared here
  387 |         void *addr, *src_addr, *dest_addr, *dest_preamble_addr;
      |                                             ^~~~~~~~~~~~~~~~~~
ksm_tests.c: In function ‘main’:
ksm_tests.c:947:16: warning: ‘ret’ may be used uninitialized in this function 
[-Wmaybe-uninitialized]
  947 |         return ret;
      |                ^~~
uffd-unit-tests.c: In function ‘uffd_move_test_common.constprop’:
uffd-unit-tests.c:1196:26: warning: ‘orig_area_dst’ may be used uninitialized 
in this function [-Wmaybe-uninitialized]
 1196 |                 area_dst = orig_area_dst;
      |                 ~~~~~~~~~^~~~~~~~~~~~~~~
uffd-unit-tests.c:1195:26: warning: ‘orig_area_src’ may be used uninitialized 
in this function [-Wmaybe-uninitialized]
 1195 |                 area_src = orig_area_src;
      |                 ~~~~~~~~~^~~~~~~~~~~~~~~
====


All the upstream commits are present in 6.14-rc1+, so 6.12.y stable
branch only needs these, newer stable branches are already patched.

Please review, thanks!

Regards,
Harshit

Kevin Brodsky (14):
  selftests/mm: fix condition in uffd_move_test_common()
  selftests/mm: fix -Wmaybe-uninitialized warnings
  selftests/mm: fix strncpy() length
  selftests/mm: Define PKEY_UNRESTRICTED for pkey_sighandler_tests
  selftests/mm: Use generic pkey register manipulation
  selftests/mm: fix -Warray-bounds warnings in pkey_sighandler_tests
  selftests/mm: remove unused pkey helpers
  selftests/mm: define types using typedef in pkey-helpers.h
  selftests/mm: ensure pkey-*.h define inline functions only
  selftests/mm: remove empty pkey helper definition
  selftests/mm: ensure non-global pkey symbols are marked static
  selftests/mm: use sys_pkey helpers consistently
  selftests/mm: rename pkey register macro
  selftests/mm: skip pkey_sighandler_tests if support is missing

 tools/testing/selftests/mm/Makefile           |   4 +
 tools/testing/selftests/mm/ksm_tests.c        |   2 +-
 tools/testing/selftests/mm/mremap_test.c      |   2 +-
 tools/testing/selftests/mm/pkey-arm64.h       |   7 +-
 tools/testing/selftests/mm/pkey-helpers.h     |  68 ++----
 tools/testing/selftests/mm/pkey-powerpc.h     |   4 +-
 tools/testing/selftests/mm/pkey-x86.h         |   8 +-
 .../selftests/mm/pkey_sighandler_tests.c      |  81 +++++--
 tools/testing/selftests/mm/pkey_util.c        |  40 ++++
 tools/testing/selftests/mm/protection_keys.c  | 212 +++++++-----------
 tools/testing/selftests/mm/soft-dirty.c       |   2 +-
 tools/testing/selftests/mm/uffd-unit-tests.c  |   4 +-
 .../testing/selftests/mm/write_to_hugetlbfs.c |   2 +-
 13 files changed, 216 insertions(+), 220 deletions(-)
 create mode 100644 tools/testing/selftests/mm/pkey_util.c

-- 
2.47.3


Reply via email to