Skip to contentSkip to conversation

Testcases for protection keys feature in powerpc/next

PATCH New Thiago Jung Bauermann 1 participant 3 messages Jan 26, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Testcases for protection keys feature in powerpc/next

Ram Pai submitted a separate series containing the rework of the x86 test and also the powerpc-specific tests:

https://patchwork.ozlabs.org/project/linuxppc-dev/list/?series=24741

There's a bug in the powerpc tests where they expect the AMR, IAMR and UAMOR registers to be zeroed when a process starts. This is currently true on powernv but isn't on LPARs, where key 31 is reserved and its bits are set. This causes the tests to fail on that platform.

This series fixes the bug and now the tests pass on both powernv and LPAR machines running powerpc/next. I think it's worth submitting these tests separately from the one coming from x86 so here they are.

Thiago Jung Bauermann (2):
selftests/powerpc: Add ptrace tests for Protection Key registers selftests/powerpc: Add core file test for Protection Key registers

 tools/testing/selftests/powerpc/include/reg.h      |   1 +
 tools/testing/selftests/powerpc/ptrace/Makefile    |   8 +-
 tools/testing/selftests/powerpc/ptrace/child.h     | 130 ++++++
 tools/testing/selftests/powerpc/ptrace/core-pkey.c | 460 +++++++++++++++++++++
 .../testing/selftests/powerpc/ptrace/ptrace-pkey.c | 326 +++++++++++++++
 tools/testing/selftests/powerpc/ptrace/ptrace.h    |  37 ++
 6 files changed, 961 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/ptrace/child.h
 create mode 100644 tools/testing/selftests/powerpc/ptrace/core-pkey.c
 create mode 100644 tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#1 lore raw

PATCH 1/2 selftests/powerpc: Add ptrace tests for Protection Key registers

This test exercises read and write access to the AMR, IAMR and UAMOR.

Signed-off-by Thiago Jung Bauermann <bauerman at linux.vnet.ibm.com>
---
 tools/testing/selftests/powerpc/include/reg.h      |   1 +
 tools/testing/selftests/powerpc/ptrace/Makefile    |   5 +-
 tools/testing/selftests/powerpc/ptrace/child.h     | 130 ++++++++
 .../testing/selftests/powerpc/ptrace/ptrace-pkey.c | 326 +++++++++++++++++++++
 tools/testing/selftests/powerpc/ptrace/ptrace.h    |  37 +++
 5 files changed, 498 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/ptrace/child.h
 create mode 100644 tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c
tools/testing/selftests/powerpc/include/reg.h +1 -0
index 4afdebcce4cd..7f348c059bc2 100644
@@ -54,6 +54,7 @@
 #define SPRN_DSCR_PRIV 0x11	/* Privilege State DSCR */
 #define SPRN_DSCR      0x03	/* Data Stream Control Register */
 #define SPRN_PPR       896	/* Program Priority Register */
+#define SPRN_AMR       13	/* Authority Mask Register - problem state */
 
 /* TEXASR register bits */
 #define TEXASR_FC	0xFE00000000000000
tools/testing/selftests/powerpc/ptrace/Makefile +4 -1
index 480305266504..707ba734faf2 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 TEST_PROGS := ptrace-gpr ptrace-tm-gpr ptrace-tm-spd-gpr \
               ptrace-tar ptrace-tm-tar ptrace-tm-spd-tar ptrace-vsx ptrace-tm-vsx \
-              ptrace-tm-spd-vsx ptrace-tm-spr
+              ptrace-tm-spd-vsx ptrace-tm-spr ptrace-pkey
 
 include ../../lib.mk
 
@@ -9,6 +9,9 @@ all: $(TEST_PROGS)
 
 CFLAGS += -m64 -I../../../../../usr/include -I../tm -mhtm -fno-pie
 
+ptrace-pkey: ../harness.c ../utils.c ../lib/reg.S ptrace.h child.h ptrace-pkey.c
+	$(LINK.c) $^ $(LDLIBS) -pthread -o $@
+
 $(TEST_PROGS): ../harness.c ../utils.c ../lib/reg.S ptrace.h
 
 clean:
tools/testing/selftests/powerpc/ptrace/child.h new file +130 -0

130 lines not on this page · raw message

tools/testing/selftests/powerpc/ptrace/ptrace-pkey.c new file +326 -0

326 lines not on this page · raw message

tools/testing/selftests/powerpc/ptrace/ptrace.h +37 -0
index 19fb825270a1..d2c9c4c2b5ee 100644
@@ -102,6 +102,43 @@ int cont_trace(pid_t child)
 	return TEST_PASS;
 }
 
+int ptrace_read_regs(pid_t child, unsigned long type, unsigned long regs[],
+		     int n)
+{
+	struct iovec iov;
+	long ret;
+
+	FAIL_IF(start_trace(child));
+
+	iov.iov_base = regs;
+	iov.iov_len = n * sizeof(unsigned long);
+
+	ret = ptrace(PTRACE_GETREGSET, child, type, &iov);
+	FAIL_IF(ret != 0);
+
+	FAIL_IF(stop_trace(child));
+
+	return TEST_PASS;
+}
+
+long ptrace_write_regs(pid_t child, unsigned long type, unsigned long regs[],
+		       int n)
+{
+	struct iovec iov;
+	long ret;
+
+	FAIL_IF(start_trace(child));
+
+	iov.iov_base = regs;
+	iov.iov_len = n * sizeof(unsigned long);
+
+	ret = ptrace(PTRACE_SETREGSET, child, type, &iov);
+
+	FAIL_IF(stop_trace(child));
+
+	return ret;
+}
+
 /* TAR, PPR, DSCR */
 int show_tar_registers(pid_t child, unsigned long *out)
 {

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

PATCH 2/2 selftests/powerpc: Add core file test for Protection Key registers

In reply to Thiago Jung Bauermann

This test verifies that the AMR, IAMR and UAMOR are being written to a process' core file.

Signed-off-by Thiago Jung Bauermann <bauerman at linux.vnet.ibm.com>
---
 tools/testing/selftests/powerpc/ptrace/Makefile    |   5 +-
 tools/testing/selftests/powerpc/ptrace/core-pkey.c | 460 +++++++++++++++++++++
 2 files changed, 464 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/ptrace/core-pkey.c
tools/testing/selftests/powerpc/ptrace/Makefile +4 -1
index 707ba734faf2..a10916c3f3e1 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 TEST_PROGS := ptrace-gpr ptrace-tm-gpr ptrace-tm-spd-gpr \
               ptrace-tar ptrace-tm-tar ptrace-tm-spd-tar ptrace-vsx ptrace-tm-vsx \
-              ptrace-tm-spd-vsx ptrace-tm-spr ptrace-pkey
+              ptrace-tm-spd-vsx ptrace-tm-spr ptrace-pkey core-pkey
 
 include ../../lib.mk
 
@@ -12,6 +12,9 @@ CFLAGS += -m64 -I../../../../../usr/include -I../tm -mhtm -fno-pie
 ptrace-pkey: ../harness.c ../utils.c ../lib/reg.S ptrace.h child.h ptrace-pkey.c
 	$(LINK.c) $^ $(LDLIBS) -pthread -o $@
 
+core-pkey: ../harness.c ../utils.c ../lib/reg.S ptrace.h child.h core-pkey.c
+	$(LINK.c) $^ $(LDLIBS) -pthread -o $@
+
 $(TEST_PROGS): ../harness.c ../utils.c ../lib/reg.S ptrace.h
 
 clean:
tools/testing/selftests/powerpc/ptrace/core-pkey.c new file +460 -0

460 lines not on this page · raw message

--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html