Skip to contentSkip to conversation

selftests/powerpc: Add uaccess flush test

PATCH Applied Daniel Axtens 2 participants 2 messages Feb 25, 2021 – Apr 29, 2021

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

PATCH 1/1 selftests/powerpc: Add uaccess flush test

From: Thadeu Lima de Souza Cascardo <[email protected]>

Also based on the RFI and entry flush tests, it counts the L1D misses by doing a syscall that does user access: uname, in this case.

[dja: forward port, rename function]

---

This applies on top of Russell's change to use better constants:
https://patchwork.ozlabs.org/project/linuxppc-dev/patch/[email protected]/

It's possible that we could share some more code between the tests, but it hardly seems worth it.

---
 .../selftests/powerpc/security/Makefile       |   3 +-
 .../selftests/powerpc/security/flush_utils.c  |  13 ++
 .../selftests/powerpc/security/flush_utils.h  |   3 +
 .../powerpc/security/uaccess_flush.c          | 158 ++++++++++++++++++
 4 files changed, 176 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/powerpc/security/uaccess_flush.c
tools/testing/selftests/powerpc/security/Makefile +2 -1
index f25e854fe370..844d18cd5f93 100644
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0+
 
-TEST_GEN_PROGS := rfi_flush entry_flush spectre_v2
+TEST_GEN_PROGS := rfi_flush entry_flush uaccess_flush spectre_v2
 top_srcdir = ../../../../..
 
 CFLAGS += -I../../../../../usr/include
@@ -13,3 +13,4 @@ $(OUTPUT)/spectre_v2: CFLAGS += -m64
 $(OUTPUT)/spectre_v2: ../pmu/event.c branch_loops.S
 $(OUTPUT)/rfi_flush: flush_utils.c
 $(OUTPUT)/entry_flush: flush_utils.c
+$(OUTPUT)/uaccess_flush: flush_utils.c
tools/testing/selftests/powerpc/security/flush_utils.c +13 -0
index 0c3c4c40c7fb..4d95965cb751 100644
@@ -13,6 +13,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+#include <sys/utsname.h>
 #include "utils.h"
 #include "flush_utils.h"
 
@@ -35,6 +36,18 @@ void syscall_loop(char *p, unsigned long iterations,
 	}
 }
 
+void syscall_loop_uaccess(char *p, unsigned long iterations,
+			  unsigned long zero_size)
+{
+	struct utsname utsname;
+
+	for (unsigned long i = 0; i < iterations; i++) {
+		for (unsigned long j = 0; j < zero_size; j += CACHELINE_SIZE)
+			load(p + j);
+		uname(&utsname);
+	}
+}
+
 static void sigill_handler(int signr, siginfo_t *info, void *unused)
 {
 	static int warned;
tools/testing/selftests/powerpc/security/flush_utils.h +3 -0
index 7a3d60292916..e1e68281f7ac 100644
@@ -16,6 +16,9 @@
 void syscall_loop(char *p, unsigned long iterations,
 		  unsigned long zero_size);
 
+void syscall_loop_uaccess(char *p, unsigned long iterations,
+			  unsigned long zero_size);
+
 void set_dscr(unsigned long val);
 
 #endif /* _SELFTESTS_POWERPC_SECURITY_FLUSH_UTILS_H */
tools/testing/selftests/powerpc/security/uaccess_flush.c new file +158 -0

158 lines not on this page · raw message

Signature · 1 line
2.27.0