mbox series

[00/14] pkeys kselftests improvements

Message ID 20241209095019.1732120-1-kevin.brodsky@arm.com (mailing list archive)
Headers show
Series pkeys kselftests improvements | expand

Message

Kevin Brodsky Dec. 9, 2024, 9:50 a.m. UTC
This series brings various cleanups and fixes for the mm (mostly
pkeys) kselftests. The original goal was to make the pkeys tests work
out of the box and without build warning - it turned out to be more
involved than expected.

The most important change is enabling -O2 when building all mm
kselftests (patch 5). This is actually needed for the pkeys tests to run
successfully (see gcc command line at the top of protection_keys.c and
pkey_sighandler_tests.c), and seems to have no negative impact on the
other tests. It certainly can't hurt performance!

The following patches address a few obvious issues in the pkeys tests
(unused code, bad scope for functions/variables, etc.) and finally make
a couple of small improvements.

There is one ugliness that this series does not fix: some functions in
pkey-<arch>.h call functions that are actually defined in
protection_keys.c. For instance, expect_fault_on_read_execonly_key() in
pkey-x86.h calls expected_pkey_fault(). This means that other test
programs that use pkey-helpers.h (namely pkey_sighandler_tests) would
fail to link if they called such functions defined in pkey-<arch>.h.
Fixing this would require a more comprehensive reorganisation of the
pkey-* headers, which doesn't seem worth it (patch 9 adds a comment to
pkey-helpers.h to clarify the situation).

Some more details on the patches:

- Patch 1 is an unrelated fix that was revealed by inspecting a warning.
  It seems fairly harmless though, so I thought I'd just post it as part
  of this series.

- Patch 2-5 fix various warnings that come up by building the mm tests
  at -O2 and finally enable -O2.

- Patch 6-12 are various cleanups for the pkeys tests. Patch 11 in
  particular enables is_pkeys_supported() to be called from outside
  protection_keys.c (patch 13 relies on this).

- Patch 13-14 are small improvements to pkey_sighandler_tests.c.


Many thanks to Ryan Roberts for checking that the mm tests still run
fine on arm64 with those patches applied. I've also checked that the
pkeys tests run fine on arm64 and x86.

- Kevin

---
Cc: akpm@linux-foundation.org
Cc: aruna.ramakrishna@oracle.com
Cc: catalin.marinas@arm.com
Cc: dave.hansen@linux.intel.com
Cc: joey.gouly@arm.com
Cc: keith.lucas@oracle.com
Cc: ryan.roberts@arm.com
Cc: shuah@kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kselftest@vger.kernel.org
Cc: x86@kernel.org
---
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: Fix -Warray-bounds warnings in pkey_sighandler_tests
  selftests/mm: Build with -O2
  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
  selftests/mm: Remove X permission from sigaltstack mapping

 tools/testing/selftests/mm/Makefile           |   6 +-
 tools/testing/selftests/mm/ksm_tests.c        |   2 +-
 tools/testing/selftests/mm/mremap_test.c      |   2 +-
 tools/testing/selftests/mm/pkey-arm64.h       |   6 +-
 tools/testing/selftests/mm/pkey-helpers.h     |  61 ++---
 tools/testing/selftests/mm/pkey-powerpc.h     |   4 +-
 tools/testing/selftests/mm/pkey-x86.h         |   6 +-
 .../selftests/mm/pkey_sighandler_tests.c      |  32 +--
 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, 163 insertions(+), 216 deletions(-)
 create mode 100644 tools/testing/selftests/mm/pkey_util.c