Add usercopy fixup accuracy tests
cover Add usercopy fixup accuracy tests
This adds a selftest subtarget that can be used to verify the accuracy of the usercopy fixup routines.
The patch contains a test module that integrates with the selftest framework and can be specified as a subtarget for the arm64 selftest target. It can be invoked through the same method as the other subtargets, provided that test_usercopy_fixup is installed prior to the run. This enables debugging of modifications made to the usercopy fixup routines, and/or provides a method of verification across system configurations.
Comments are welcome regarding the suitability of this location for these tests, and any other suggestions would also be greatly appreciated.
This was used in conjunction with lib/test_user_copy.c to help verify the following usercopy fixup patches:
https://lore.kernel.org/lkml/[email protected]/
Thanks in advance,
Oli
Oliver Swede (1):
kselftest: arm64: Add usercopy fixup accuracy tests
arch/arm64/Kconfig.debug | 7 + arch/arm64/lib/Makefile | 2 + arch/arm64/lib/test_usercopy_fixup.c | 276 ++++++++++++++++++ tools/testing/selftests/arm64/Makefile | 2 +- tools/testing/selftests/arm64/README | 2 +- .../testing/selftests/arm64/usercopy/Makefile | 3 + tools/testing/selftests/arm64/usercopy/config | 1 + .../arm64/usercopy/run_fixup_tests.sh | 4 + 8 files changed, 295 insertions(+), 2 deletions(-) create mode 100644 arch/arm64/lib/test_usercopy_fixup.c create mode 100644 tools/testing/selftests/arm64/usercopy/Makefile create mode 100644 tools/testing/selftests/arm64/usercopy/config create mode 100755 tools/testing/selftests/arm64/usercopy/run_fixup_tests.sh
Signature · 7 lines
2.17.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 1/1 kselftest: arm64: Add usercopy fixup accuracy tests
This test module checks the accuracy of the usercopy fixup routines.
In kernel mode copy_*_user() can be invoked directly, removing the dependencies on implementations of syscalls (e.g. any reductions to the original copy size from within read/write), as well as potentially reducing other overheads. This is also exposed to copy_in_user() allowing it to be verified should its fixup differ from the recovery from copy_{from,to}_user in the future.
This module is intended to be used in a more specific way than lib/test_user_copy.c, which is expected to be used to verify the usercopy functionality overall rather than exclusively the correctness of the values returned by the fixups.
The behaviour of the copy algorithm varies depending on the copy size, and the tests are currently exhaustive to ensure this is covered by the fixup implementation.
Each testcase runs the usercopy function so that the user buffer base address is set to be close to an invalid page so the copy intentionally faults at the specified index. The return value (number of bytes not copied due to the fault) is then compared against the number of bytes remaining in the user buffer.
--- arch/arm64/Kconfig.debug | 7 + arch/arm64/lib/Makefile | 2 + arch/arm64/lib/test_usercopy_fixup.c | 276 ++++++++++++++++++ tools/testing/selftests/arm64/Makefile | 2 +- tools/testing/selftests/arm64/README | 2 +- .../testing/selftests/arm64/usercopy/Makefile | 3 + tools/testing/selftests/arm64/usercopy/config | 1 + .../arm64/usercopy/run_fixup_tests.sh | 4 + 8 files changed, 295 insertions(+), 2 deletions(-) create mode 100644 arch/arm64/lib/test_usercopy_fixup.c create mode 100644 tools/testing/selftests/arm64/usercopy/Makefile create mode 100644 tools/testing/selftests/arm64/usercopy/config create mode 100755 tools/testing/selftests/arm64/usercopy/run_fixup_tests.sh
arch/arm64/Kconfig.debug +7 -0
@@ -20,4 +20,11 @@ config ARM64_RELOC_TEST depends on m tristate "Relocation testing module" +config TEST_USERCOPY_FIXUP + tristate "Test correctness of the usercopy fixup" + depends on m + help + This test module allows for the verification of the correctness + of the fixup routines for each of the usercopy functions. + source "drivers/hwtracing/coresight/Kconfig"
arch/arm64/lib/Makefile +2 -0
@@ -16,3 +16,5 @@ lib-$(CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE) += uaccess_flushcache.o obj-$(CONFIG_CRC32) += crc32.o obj-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o + +obj-$(CONFIG_TEST_USERCOPY_FIXUP) += test_usercopy_fixup.o
arch/arm64/lib/test_usercopy_fixup.c new file +276 -0
276 lines not on this page · raw message
tools/testing/selftests/arm64/Makefile +1 -1
@@ -4,7 +4,7 @@ ARCH ?= $(shell uname -m 2>/dev/null || echo not) ifneq (,$(filter $(ARCH),aarch64 arm64)) -ARM64_SUBTARGETS ?= tags signal +ARM64_SUBTARGETS ?= tags signal usercopy else ARM64_SUBTARGETS := endif
tools/testing/selftests/arm64/README +1 -1
@@ -18,7 +18,7 @@ KSelfTest ARM64 or, alternatively, only specific arm64/ subtargets can be picked: - $ make -C tools/testing/selftests TARGETS=arm64 ARM64_SUBTARGETS="tags signal" \ + $ make -C tools/testing/selftests TARGETS=arm64 ARM64_SUBTARGETS="tags signal usercopy" \ INSTALL_PATH=<your-installation-path> install Further details on building and running KFST can be found in:
tools/testing/selftests/arm64/usercopy/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 +TEST_PROGS := run_fixup_tests.sh +include ../../lib.mk
tools/testing/selftests/arm64/usercopy/config new file +1 -0
@@ -0,0 +1 @@ +CONFIG_TEST_USERCOPY_FIXUP=m
tools/testing/selftests/arm64/usercopy/run_fixup_tests.sh new file +4 -0
@@ -0,0 +1,4 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +$(dirname $0)/../../kselftest/module.sh "run_fixup_tests" test_usercopy_fixup
Signature · 7 lines
2.17.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel