selftests/powerpc: Fix L1D flushing tests for Power10
authorRussell Currey <ruscur@russell.cc>
Tue, 23 Feb 2021 07:02:27 +0000 (17:02 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 24 Mar 2021 03:09:29 +0000 (14:09 +1100)
The rfi_flush and entry_flush selftests work by using the PM_LD_MISS_L1
perf event to count L1D misses.  The value of this event has changed
over time:

- Power7 uses 0x400f0
- Power8 and Power9 use both 0x400f0 and 0x3e054
- Power10 uses only 0x3e054

Rather than relying on raw values, configure perf to count L1D read
misses in the most explicit way available.

This fixes the selftests to work on systems without 0x400f0 as
PM_LD_MISS_L1, and should change no behaviour for systems that the tests
already worked on.

The only potential downside is that referring to a specific perf event
requires PMU support implemented in the kernel for that platform.

Signed-off-by: Russell Currey <ruscur@russell.cc>
Acked-by: Daniel Axtens <dja@axtens.net>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20210223070227.2916871-1-ruscur@russell.cc
tools/testing/selftests/powerpc/security/entry_flush.c
tools/testing/selftests/powerpc/security/flush_utils.h
tools/testing/selftests/powerpc/security/rfi_flush.c

index 78cf914fa3217395a10582394d754409d7dec663..68ce377b205e91ab04ab34fb49cc67151199f545 100644 (file)
@@ -53,7 +53,7 @@ int entry_flush_test(void)
 
        entry_flush = entry_flush_orig;
 
-       fd = perf_event_open_counter(PERF_TYPE_RAW, /* L1d miss */ 0x400f0, -1);
+       fd = perf_event_open_counter(PERF_TYPE_HW_CACHE, PERF_L1D_READ_MISS_CONFIG, -1);
        FAIL_IF(fd < 0);
 
        p = (char *)memalign(zero_size, CACHELINE_SIZE);
index 07a5eb301466900645f759e6e9397bbbd08a8f4c..7a3d60292916ecfca8096760413521922f23daf5 100644 (file)
@@ -9,6 +9,10 @@
 
 #define CACHELINE_SIZE 128
 
+#define PERF_L1D_READ_MISS_CONFIG      ((PERF_COUNT_HW_CACHE_L1D) |            \
+                                       (PERF_COUNT_HW_CACHE_OP_READ << 8) |    \
+                                       (PERF_COUNT_HW_CACHE_RESULT_MISS << 16))
+
 void syscall_loop(char *p, unsigned long iterations,
                  unsigned long zero_size);
 
index 7565fd786640fc38eb280bbd9022903815caea59..f73484a6470faebb8c9ec0b9c039199bdc7902f7 100644 (file)
@@ -54,7 +54,7 @@ int rfi_flush_test(void)
 
        rfi_flush = rfi_flush_orig;
 
-       fd = perf_event_open_counter(PERF_TYPE_RAW, /* L1d miss */ 0x400f0, -1);
+       fd = perf_event_open_counter(PERF_TYPE_HW_CACHE, PERF_L1D_READ_MISS_CONFIG, -1);
        FAIL_IF(fd < 0);
 
        p = (char *)memalign(zero_size, CACHELINE_SIZE);