selftests/powerpc: Add test for rfi_flush
v2 cover selftests/powerpc: Add test for rfi_flush
This is v2 of:
https://patchwork.ozlabs.org/patch/895765/
Changes:
- Patch 1 is new.
- Patch 2 uses the new macro introduced in the first patch. The output message has also been slightly tweaked to make things clearer.
- Naveen
Naveen N. Rao (2):
selftests/powerpc: Move UCONTEXT_NIA() into utils.h selftests/powerpc: Add test to verify rfi flush across a system call
tools/testing/selftests/powerpc/Makefile | 3 +- .../testing/selftests/powerpc/include/utils.h | 18 +++ .../primitives/load_unaligned_zeropad.c | 8 - .../selftests/powerpc/security/Makefile | 7 + .../selftests/powerpc/security/rfi_flush.c | 132 +++++++++++++++ tools/testing/selftests/powerpc/utils.c | 153 ++++++++++++++++++ 6 files changed, 312 insertions(+), 9 deletions(-) create mode 100644 tools/testing/selftests/powerpc/security/Makefile create mode 100644 tools/testing/selftests/powerpc/security/rfi_flush.c
Signature · 1 line
2.17.0
PATCH v2 1/2 selftests/powerpc: Move UCONTEXT_NIA() into utils.h
... so that it can be used by others.
--- tools/testing/selftests/powerpc/include/utils.h | 8 ++++++++ .../selftests/powerpc/primitives/load_unaligned_zeropad.c | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-)
tools/testing/selftests/powerpc/include/utils.h +8 -0
@@ -78,4 +78,12 @@ do { \#define PPC_FEATURE2_ARCH_3_00 0x00800000#endif +#if defined(__powerpc64__) +#define UCONTEXT_NIA (UC ) (UC)->uc_mcontext.gp_regs[PT_NIP] +#elif defined(__powerpc__) +#define UCONTEXT_NIA (UC ) (UC)->uc_mcontext.uc_regs->gregs[PT_NIP] +#else +#error implement UCONTEXT_NIA +#endif +#endif /* _SELFTESTS_POWERPC_UTILS_H */
tools/testing/selftests/powerpc/primitives/load_unaligned_zeropad.c +0 -8
@@ -65,14 +65,6 @@ static int unprotect_region(void)extern char __start___ex_table[];extern char __stop___ex_table[]; -#if defined(__powerpc64__) -#define UCONTEXT_NIA (UC ) (UC)->uc_mcontext.gp_regs[PT_NIP] -#elif defined(__powerpc__) -#define UCONTEXT_NIA (UC ) (UC)->uc_mcontext.uc_regs->gregs[PT_NIP] -#else -#error implement UCONTEXT_NIA -#endif -struct extbl_entry {int insn;int fixup;
Signature · 1 line
2.17.0
PATCH v2 2/2 selftests/powerpc: Add test to verify rfi flush across a system call
In reply to Naveen N. RaoThis adds a test to verify proper functioning of the rfi flush capability implemented to mitigate meltdown. The test works by measuring the number of L1d cache misses encountered while loading data from memory. Across a system call, since the L1d cache is flushed when rfi_flush is enabled, the number of cache misses is expected to be relative to the number of cachelines corresponding to the data being loaded.
The current system setting is reflected via powerpc/rfi_flush under debugfs (assumed to be /sys/kernel/debug/). This test verifies the expected result with rfi_flush enabled as well as when it is disabled.
--- tools/testing/selftests/powerpc/Makefile | 3 +- .../testing/selftests/powerpc/include/utils.h | 10 ++ .../selftests/powerpc/security/Makefile | 7 + .../selftests/powerpc/security/rfi_flush.c | 132 +++++++++++++++ tools/testing/selftests/powerpc/utils.c | 153 ++++++++++++++++++ 5 files changed, 304 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/powerpc/security/Makefile create mode 100644 tools/testing/selftests/powerpc/security/rfi_flush.c
tools/testing/selftests/powerpc/Makefile +2 -1
@@ -28,7 +28,8 @@ SUB_DIRS = alignment \ tm \ vphn \ math \ - ptrace + ptrace \ + security endif
tools/testing/selftests/powerpc/include/utils.h +10 -0
@@ -11,6 +11,7 @@#include <stdint.h> #include <stdbool.h> #include <linux/auxvec.h> +#include <linux/perf_event.h> #include "reg.h" /* Avoid headaches with PRI?64 - just use %ll? always */
@@ -31,6 +32,15 @@ void *get_auxv_entry(int type);int pick_online_cpu (void ); +int read_debugfs_file (char *debugfs_file,int *result); +int write_debugfs_file (char *debugfs_file,int result); +void set_dscr (unsigned long val); +int perf_event_open_counter (unsigned int type, +unsigned long config,int group_fd); +int perf_event_enable (int fd); +int perf_event_disable (int fd); +int perf_event_reset (int fd); +static inline bool have_hwcap (unsigned long ftr) {return ((unsigned long )get_auxv_entry (AT_HWCAP ) & ftr) == ftr;
tools/testing/selftests/powerpc/security/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +TEST_GEN_PROGS := rfi_flush + +CFLAGS += -I../../../../../usr/include + +include ../../lib.mk + +$(TEST_GEN_PROGS): ../harness.c ../utils.c
tools/testing/selftests/powerpc/security/rfi_flush.c new file +132 -0
132 lines not on this page · raw message
tools/testing/selftests/powerpc/utils.c +153 -0
169 lines not on this page · raw message
Signature · 1 line
2.17.0
Michael Ellerman
reviewerRe: [PATCH v2 2/2] selftests/powerpc: Add test to verify rfi flush across a system call
Quoted 6 lines · Naveen N. Rao
tools/testing/selftests/powerpc/security/rfi_flush.c new file +0
-0@@ -0,0 +1,132 @@
...
Quoted 8 lines
tools/testing/selftests/powerpc/security/rfi_flush.c new file +8
-0+ +int rfi_flush_test (void ) +{ +char *p; +int repetitions =10 ; +int fd, passes =0 , iter, rc =0 ; +struct perf_event_read v; +uint64_t l1d_misses_total =0 ;
tools/testing/selftests/powerpc/security/rfi_flush.c line 51
Quoted 10 lines
tools/testing/selftests/powerpc/security/rfi_flush.c new file +10
-0+unsigned long iterations =100000 , zero_size =24 *1024 ; +int rfi_flush_org, rfi_flush; + +SKIP_IF (geteuid () !=0 ); + +if (read_debugfs_file ("powerpc/rfi_flush" , &rfi_flush_org)) { +perror ("error reading powerpc/rfi_flush debugfs file" ); +printf ("unable to determine current rfi_flush setting" ); +return 1 ; + }
This leads to a hard error on old kernels, which I don't want (breaks my CI).
So I changed it to:
if (read_debugfs_file("powerpc/rfi_flush", &rfi_flush_org)) {
perror("Unable to read powerpc/rfi_flush debugfs file");
SKIP_IF(1);
}cheers
Re: [PATCH v2 2/2] selftests/powerpc: Add test to verify rfi flush across a system call
Quoted 2 lines · Michael Ellerman
tool=
Quoted 1 line · Naveen N. Rao
tool= renamed from tools/testing/selftests/powerpc/security/rfi_flush.c +0
-0
s/testing/selftests/powerpc/security/rfi_flush.c
Quoted 18 lines
Quoted 5 lines
new file mode 100644
index 000000000000..a20fe8eca161tools/testing/selftests/powerpc/security/rfi_flush.c new file +0
-0@@ -0,0 +1,132 @@...
Quoted 12 lines
tools/testing/selftests/powerpc/security/rfi_flush.c new file +12
-0+ +int rfi_flush_test (void ) +{ +char *p; + int repetitions =3D 10; + int fd, passes =3D 0, iter, rc =3D 0; +struct perf_event_read v; + uint64_t l1d_misses_total =3D 0; + unsigned long iterations =3D 100000, zero_size =3D 24*1024; +int rfi_flush_org, rfi_flush; + + SKIP_IF(geteuid() !=3D 0);
Quoted 8 lines
tools/testing/selftests/powerpc/security/rfi_flush.c line 51
Quoted 6 lines
tools/testing/selftests/powerpc/security/rfi_flush.c new file +6
-0+ +if (read_debugfs_file ("powerpc/rfi_flush" , &rfi_flush_org)) { +perror ("error reading powerpc/rfi_flush debugfs file" ); +printf ("unable to determine current rfi_flush setting" ); +return 1 ; + }=20
This leads to a hard error on old kernels, which I don't want (breaks my =
CI).
Hmm... didn't realize new tests would be run on older kernels. Are those=20 older stable/distro releases, or actually just earlier kernel versions?
Quoted 7 lines
=20
So I changed it to:
=20if (read_debugfs_file("powerpc/rfi_flush", &rfi_flush_org)) { perror("Unable to read powerpc/rfi_flush debugfs file"); SKIP_IF(1); }
Sure, thanks!
- Naveen
=
Michael Ellerman
reviewerRe: [PATCH v2 2/2] selftests/powerpc: Add test to verify rfi flush across a system call
Quoted 30 lines · Naveen N. Rao
Quoted 20 lines · Michael Ellerman
Quoted 6 lines · Naveen N. Rao
tools/testing/selftests/powerpc/security/rfi_flush.c new file +0
-0@@ -0,0 +1,132 @@...
Quoted 12 lines
tools/testing/selftests/powerpc/security/rfi_flush.c new file +12
-0+ +int rfi_flush_test (void ) +{ +char *p; +int repetitions =10 ; +int fd, passes =0 , iter, rc =0 ; +struct perf_event_read v; +uint64_t l1d_misses_total =0 ; +unsigned long iterations =100000 , zero_size =24 *1024 ; +int rfi_flush_org, rfi_flush; + +SKIP_IF (geteuid () !=0 );Quoted 8 lines
tools/testing/selftests/powerpc/security/rfi_flush.c line 51
Quoted 6 lines
tools/testing/selftests/powerpc/security/rfi_flush.c new file +6
-0+ +if (read_debugfs_file ("powerpc/rfi_flush" , &rfi_flush_org)) { +perror ("error reading powerpc/rfi_flush debugfs file" ); +printf ("unable to determine current rfi_flush setting" ); +return 1 ; + }This leads to a hard error on old kernels, which I don't want (breaks my CI).
Quoted 2 lines
Hmm... didn't realize new tests would be run on older kernels. Are those older stable/distro releases, or actually just earlier kernel versions?
All of the above :)
Obviously keeping all the tests working across all kernel versions ever is impossible, but when it's relatively easy like in this case, it's nice to do.
So that was mostly just an FYI, I don't expect test writers to get their tests running across all kernel versions.
cheers
Re: [PATCH v2 2/2] selftests/powerpc: Add test to verify rfi flush across a system call
Quoted 4 lines · Michael Ellerman
Quoted 3 lines · Naveen N. Rao
Quoted 2 lines · Michael Ellerman
to=
Quoted 1 line · Naveen N. Rao
to= renamed from tools/testing/selftests/powerpc/security/rfi_flush.c +0
-0
ols/testing/selftests/powerpc/security/rfi_flush.c
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 5 lines
new file mode 100644
index 000000000000..a20fe8eca161tools/testing/selftests/powerpc/security/rfi_flush.c new file +0
-0@@ -0,0 +1,132 @@...
Quoted 12 lines
tools/testing/selftests/powerpc/security/rfi_flush.c new file +12
-0+ +int rfi_flush_test (void ) +{ +char *p; + int repetitions =3D 10; + int fd, passes =3D 0, iter, rc =3D 0; +struct perf_event_read v; + uint64_t l1d_misses_total =3D 0; + unsigned long iterations =3D 100000, zero_size =3D 24*1024; +int rfi_flush_org, rfi_flush; + + SKIP_IF(geteuid() !=3D 0);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
tools/testing/selftests/powerpc/security/rfi_flush.c line 51
Quoted 6 lines
tools/testing/selftests/powerpc/security/rfi_flush.c new file +6
-0+ +if (read_debugfs_file ("powerpc/rfi_flush" , &rfi_flush_org)) { +perror ("error reading powerpc/rfi_flush debugfs file" ); +printf ("unable to determine current rfi_flush setting" ); +return 1 ; + }=20
This leads to a hard error on old kernels, which I don't want (breaks m=
y CI).
Quoted 2 lines
Quoted 2 lines
Hmm... didn't realize new tests would be run on older kernels. Are those=
=20
Quoted 10 lines
Quoted 1 line
older stable/distro releases, or actually just earlier kernel versions?
=20
All of the above :)
=20
Obviously keeping all the tests working across all kernel versions ever is impossible, but when it's relatively easy like in this case, it's nice to do.
=20
So that was mostly just an FYI, I don't expect test writers to get their tests running across all kernel versions.
Good to know, thanks!
- Naveen
=
Re: [v2,1/2] selftests/powerpc: Move UCONTEXT_NIA() into utils.h
In reply to Naveen N. RaoQuoted 3 lines · Naveen N. Rao
... so that it can be used by others.
Signed-off-by Naveen N. Rao <[email protected]>
Series applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/db3848515aff369404c31ef5a63699
cheers