Commit 76e9f683 authored by Will Deacon's avatar Will Deacon
Browse files

Merge branch 'for-next/selftests' into for-next/core

* for-next/selftests:
  kselftest/arm64: Raise default number of loops in fp-pidbench
  kselftest/arm64: Add a no-SVE loop after SVE in fp-pidbench
  kselftest/arm64: Add missing file in .gitignore
  kselftest/arm64: Add HWCAP test for FEAT_LS64
  kselftest/arm64: Use syscall() macro over nolibc my_syscall()
  kselftest/arm64: Support FORCE_TARGETS
parents d4cfa05a b661d753
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -30,13 +30,15 @@ all:
	@for DIR in $(ARM64_SUBTARGETS); do				\
		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
		mkdir -p $$BUILD_TARGET;			\
		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
		make OUTPUT=$$BUILD_TARGET -C $$DIR $@		\
			$(if $(FORCE_TARGETS),|| exit); \
	done

install: all
	@for DIR in $(ARM64_SUBTARGETS); do				\
		BUILD_TARGET=$(OUTPUT)/$$DIR;			\
		make OUTPUT=$$BUILD_TARGET -C $$DIR $@;		\
		make OUTPUT=$$BUILD_TARGET -C $$DIR $@		\
			$(if $(FORCE_TARGETS),|| exit); \
	done

run_tests: all
+49 −0
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <linux/auxvec.h>
#include <linux/compiler.h>
#include <sys/auxv.h>
#include <sys/prctl.h>
#include <asm/hwcap.h>
@@ -595,6 +597,45 @@ static void lrcpc3_sigill(void)
	              : "=r" (data0), "=r" (data1) : "r" (src) :);
}

static void ignore_signal(int sig, siginfo_t *info, void *context)
{
	ucontext_t *uc = context;

	uc->uc_mcontext.pc += 4;
}

static void ls64_sigill(void)
{
	struct sigaction ign, old;
	char src[64] __aligned(64) = { 1 };

	/*
	 * LS64 requires target memory to be Device/Non-cacheable (if
	 * FEAT_LS64WB not supported) and the completer supports these
	 * instructions, otherwise we'll receive a SIGBUS. Since we are only
	 * testing the ABI here, so just ignore the SIGBUS and see if we can
	 * execute the instructions without receiving a SIGILL. Restore the
	 * handler of SIGBUS after this test.
	 */
	ign.sa_sigaction = ignore_signal;
	ign.sa_flags = SA_SIGINFO | SA_RESTART;
	sigemptyset(&ign.sa_mask);
	sigaction(SIGBUS, &ign, &old);

	register void *xn asm ("x8") = src;
	register u64 xt_1 asm ("x0");

	/* LD64B x0, [x8] */
	asm volatile(".inst 0xf83fd100" : "=r" (xt_1) : "r" (xn)
		     : "x1", "x2", "x3", "x4", "x5", "x6", "x7");

	/* ST64B x0, [x8] */
	asm volatile(".inst 0xf83f9100" : : "r" (xt_1), "r" (xn)
		     : "x1", "x2", "x3", "x4", "x5", "x6", "x7");

	sigaction(SIGBUS, &old, NULL);
}

static const struct hwcap_data {
	const char *name;
	unsigned long at_hwcap;
@@ -1134,6 +1175,14 @@ static const struct hwcap_data {
		.hwcap_bit = HWCAP3_MTE_STORE_ONLY,
		.cpuinfo = "mtestoreonly",
	},
	{
		.name = "LS64",
		.at_hwcap = AT_HWCAP3,
		.hwcap_bit = HWCAP3_LS64,
		.cpuinfo = "ls64",
		.sigill_fn = ls64_sigill,
		.sigill_reliable = true,
	},
};

typedef void (*sighandler_fn)(int, siginfo_t *, void *);
+1 −2
Original line number Diff line number Diff line
@@ -128,8 +128,7 @@ static int sys_clone(unsigned long clone_flags, unsigned long newsp,
		     int *parent_tidptr, unsigned long tls,
		     int *child_tidptr)
{
	return my_syscall5(__NR_clone, clone_flags, newsp, parent_tidptr, tls,
			   child_tidptr);
	return syscall(__NR_clone, clone_flags, newsp, parent_tidptr, tls, child_tidptr);
}

#define __STACK_SIZE (8 * 1024 * 1024)
+5 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@
function _start
	puts	"Iterations per test: "
	mov	x20, #10000
	lsl	x20, x20, #8
	lsl	x20, x20, #12
	mov	x0, x20
	bl	putdec
	puts	"\n"
@@ -63,6 +63,10 @@ function _start
	puts	"SVE used per syscall: "
	test_loop "rdvl x0, #8"

	// Test non-SVE execution after SVE
	puts	"No SVE after SVE: "
	test_loop

	//  And we're done
out:
	mov	x0, #0
+16 −24
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ static size_t page_size = 65536;
static  __attribute__((noinline)) void valid_gcs_function(void)
{
	/* Do something the compiler can't optimise out */
	my_syscall1(__NR_prctl, PR_SVE_GET_VL);
	syscall(__NR_prctl, PR_SVE_GET_VL);
}

static inline int gcs_set_status(unsigned long mode)
@@ -36,12 +36,10 @@ static inline int gcs_set_status(unsigned long mode)
	 * other 3 values passed in registers to the syscall are zero
	 * since the kernel validates them.
	 */
	ret = my_syscall5(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, mode,
			  0, 0, 0);
	ret = syscall(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, mode, 0, 0, 0);

	if (ret == 0) {
		ret = my_syscall5(__NR_prctl, PR_GET_SHADOW_STACK_STATUS,
				  &new_mode, 0, 0, 0);
		ret = syscall(__NR_prctl, PR_GET_SHADOW_STACK_STATUS, &new_mode, 0, 0, 0);
		if (ret == 0) {
			if (new_mode != mode) {
				ksft_print_msg("Mode set to %lx not %lx\n",
@@ -49,7 +47,7 @@ static inline int gcs_set_status(unsigned long mode)
				ret = -EINVAL;
			}
		} else {
			ksft_print_msg("Failed to validate mode: %d\n", ret);
			ksft_print_msg("Failed to validate mode: %d\n", errno);
		}

		if (enabling != chkfeat_gcs()) {
@@ -69,10 +67,9 @@ static bool read_status(void)
	unsigned long state;
	int ret;

	ret = my_syscall5(__NR_prctl, PR_GET_SHADOW_STACK_STATUS,
			  &state, 0, 0, 0);
	ret = syscall(__NR_prctl, PR_GET_SHADOW_STACK_STATUS, &state, 0, 0, 0);
	if (ret != 0) {
		ksft_print_msg("Failed to read state: %d\n", ret);
		ksft_print_msg("Failed to read state: %d\n", errno);
		return false;
	}

@@ -188,9 +185,8 @@ static bool map_guarded_stack(void)
	int elem;
	bool pass = true;

	buf = (void *)my_syscall3(__NR_map_shadow_stack, 0, page_size,
				  SHADOW_STACK_SET_MARKER |
				  SHADOW_STACK_SET_TOKEN);
	buf = (void *)syscall(__NR_map_shadow_stack, 0, page_size,
			      SHADOW_STACK_SET_MARKER | SHADOW_STACK_SET_TOKEN);
	if (buf == MAP_FAILED) {
		ksft_print_msg("Failed to map %lu byte GCS: %d\n",
			       page_size, errno);
@@ -257,8 +253,7 @@ static bool test_fork(void)
		valid_gcs_function();
		get_gcspr();

		ret = my_syscall5(__NR_prctl, PR_GET_SHADOW_STACK_STATUS,
				  &child_mode, 0, 0, 0);
		ret = syscall(__NR_prctl, PR_GET_SHADOW_STACK_STATUS, &child_mode, 0, 0, 0);
		if (ret == 0 && !(child_mode & PR_SHADOW_STACK_ENABLE)) {
			ksft_print_msg("GCS not enabled in child\n");
			ret = -EINVAL;
@@ -321,8 +316,7 @@ static bool test_vfork(void)
		valid_gcs_function();
		get_gcspr();

		ret = my_syscall5(__NR_prctl, PR_GET_SHADOW_STACK_STATUS,
				  &child_mode, 0, 0, 0);
		ret = syscall(__NR_prctl, PR_GET_SHADOW_STACK_STATUS, &child_mode, 0, 0, 0);
		if (ret == 0 && !(child_mode & PR_SHADOW_STACK_ENABLE)) {
			ksft_print_msg("GCS not enabled in child\n");
			ret = EXIT_FAILURE;
@@ -390,17 +384,15 @@ int main(void)
	if (!(getauxval(AT_HWCAP) & HWCAP_GCS))
		ksft_exit_skip("SKIP GCS not supported\n");

	ret = my_syscall5(__NR_prctl, PR_GET_SHADOW_STACK_STATUS,
			  &gcs_mode, 0, 0, 0);
	ret = syscall(__NR_prctl, PR_GET_SHADOW_STACK_STATUS, &gcs_mode, 0, 0, 0);
	if (ret != 0)
		ksft_exit_fail_msg("Failed to read GCS state: %d\n", ret);
		ksft_exit_fail_msg("Failed to read GCS state: %d\n", errno);

	if (!(gcs_mode & PR_SHADOW_STACK_ENABLE)) {
		gcs_mode = PR_SHADOW_STACK_ENABLE;
		ret = my_syscall5(__NR_prctl, PR_SET_SHADOW_STACK_STATUS,
				  gcs_mode, 0, 0, 0);
		ret = syscall(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, gcs_mode, 0, 0, 0);
		if (ret != 0)
			ksft_exit_fail_msg("Failed to enable GCS: %d\n", ret);
			ksft_exit_fail_msg("Failed to enable GCS: %d\n", errno);
	}

	ksft_set_plan(ARRAY_SIZE(tests));
@@ -410,9 +402,9 @@ int main(void)
	}

	/* One last test: disable GCS, we can do this one time */
	ret = my_syscall5(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, 0, 0, 0, 0);
	ret = syscall(__NR_prctl, PR_SET_SHADOW_STACK_STATUS, 0, 0, 0, 0);
	if (ret != 0)
		ksft_print_msg("Failed to disable GCS: %d\n", ret);
		ksft_print_msg("Failed to disable GCS: %d\n", errno);

	ksft_finished();

Loading