Skip to content

Commit fcb4845

Browse files
ruscurmpe
authored andcommitted
selftests/powerpc: rfi_flush: disable entry flush if present
We are about to add an entry flush. The rfi (exit) flush test measures the number of L1D flushes over a syscall with the RFI flush enabled and disabled. But if the entry flush is also enabled, the effect of enabling and disabling the RFI flush is masked. If there is a debugfs entry for the entry flush, disable it during the RFI flush and restore it later. Reported-by: Spoorthy S <spoorts2@in.ibm.com> Signed-off-by: Russell Currey <ruscur@russell.cc> Signed-off-by: Daniel Axtens <dja@axtens.net> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 3cea11c commit fcb4845

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

tools/testing/selftests/powerpc/security/rfi_flush.c

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,33 @@ int rfi_flush_test(void)
8585
__u64 l1d_misses_total = 0;
8686
unsigned long iterations = 100000, zero_size = 24 * 1024;
8787
unsigned long l1d_misses_expected;
88-
int rfi_flush_org, rfi_flush;
88+
int rfi_flush_orig, rfi_flush;
89+
int have_entry_flush, entry_flush_orig;
8990

9091
SKIP_IF(geteuid() != 0);
9192

9293
// The PMU event we use only works on Power7 or later
9394
SKIP_IF(!have_hwcap(PPC_FEATURE_ARCH_2_06));
9495

95-
if (read_debugfs_file("powerpc/rfi_flush", &rfi_flush_org)) {
96+
if (read_debugfs_file("powerpc/rfi_flush", &rfi_flush_orig) < 0) {
9697
perror("Unable to read powerpc/rfi_flush debugfs file");
9798
SKIP_IF(1);
9899
}
99100

100-
rfi_flush = rfi_flush_org;
101+
if (read_debugfs_file("powerpc/entry_flush", &entry_flush_orig) < 0) {
102+
have_entry_flush = 0;
103+
} else {
104+
have_entry_flush = 1;
105+
106+
if (entry_flush_orig != 0) {
107+
if (write_debugfs_file("powerpc/entry_flush", 0) < 0) {
108+
perror("error writing to powerpc/entry_flush debugfs file");
109+
return 1;
110+
}
111+
}
112+
}
113+
114+
rfi_flush = rfi_flush_orig;
101115

102116
fd = perf_event_open_counter(PERF_TYPE_RAW, /* L1d miss */ 0x400f0, -1);
103117
FAIL_IF(fd < 0);
@@ -106,6 +120,7 @@ int rfi_flush_test(void)
106120

107121
FAIL_IF(perf_event_enable(fd));
108122

123+
// disable L1 prefetching
109124
set_dscr(1);
110125

111126
iter = repetitions;
@@ -147,8 +162,8 @@ int rfi_flush_test(void)
147162
repetitions * l1d_misses_expected / 2,
148163
passes, repetitions);
149164

150-
if (rfi_flush == rfi_flush_org) {
151-
rfi_flush = !rfi_flush_org;
165+
if (rfi_flush == rfi_flush_orig) {
166+
rfi_flush = !rfi_flush_orig;
152167
if (write_debugfs_file("powerpc/rfi_flush", rfi_flush) < 0) {
153168
perror("error writing to powerpc/rfi_flush debugfs file");
154169
return 1;
@@ -164,11 +179,19 @@ int rfi_flush_test(void)
164179

165180
set_dscr(0);
166181

167-
if (write_debugfs_file("powerpc/rfi_flush", rfi_flush_org) < 0) {
182+
if (write_debugfs_file("powerpc/rfi_flush", rfi_flush_orig) < 0) {
168183
perror("unable to restore original value of powerpc/rfi_flush debugfs file");
169184
return 1;
170185
}
171186

187+
if (have_entry_flush) {
188+
if (write_debugfs_file("powerpc/entry_flush", entry_flush_orig) < 0) {
189+
perror("unable to restore original value of powerpc/entry_flush "
190+
"debugfs file");
191+
return 1;
192+
}
193+
}
194+
172195
return rc;
173196
}
174197

0 commit comments

Comments
 (0)