Skip to content

Commit bcf7f2d

Browse files
ruscurgregkh
authored andcommitted
selftests/powerpc: rfi_flush: disable entry flush if present
commit fcb4845 upstream. 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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3154432 commit bcf7f2d

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
@@ -50,16 +50,30 @@ int rfi_flush_test(void)
5050
__u64 l1d_misses_total = 0;
5151
unsigned long iterations = 100000, zero_size = 24 * 1024;
5252
unsigned long l1d_misses_expected;
53-
int rfi_flush_org, rfi_flush;
53+
int rfi_flush_orig, rfi_flush;
54+
int have_entry_flush, entry_flush_orig;
5455

5556
SKIP_IF(geteuid() != 0);
5657

57-
if (read_debugfs_file("powerpc/rfi_flush", &rfi_flush_org)) {
58+
if (read_debugfs_file("powerpc/rfi_flush", &rfi_flush_orig) < 0) {
5859
perror("Unable to read powerpc/rfi_flush debugfs file");
5960
SKIP_IF(1);
6061
}
6162

62-
rfi_flush = rfi_flush_org;
63+
if (read_debugfs_file("powerpc/entry_flush", &entry_flush_orig) < 0) {
64+
have_entry_flush = 0;
65+
} else {
66+
have_entry_flush = 1;
67+
68+
if (entry_flush_orig != 0) {
69+
if (write_debugfs_file("powerpc/entry_flush", 0) < 0) {
70+
perror("error writing to powerpc/entry_flush debugfs file");
71+
return 1;
72+
}
73+
}
74+
}
75+
76+
rfi_flush = rfi_flush_orig;
6377

6478
fd = perf_event_open_counter(PERF_TYPE_RAW, /* L1d miss */ 0x400f0, -1);
6579
FAIL_IF(fd < 0);
@@ -68,6 +82,7 @@ int rfi_flush_test(void)
6882

6983
FAIL_IF(perf_event_enable(fd));
7084

85+
// disable L1 prefetching
7186
set_dscr(1);
7287

7388
iter = repetitions;
@@ -109,8 +124,8 @@ int rfi_flush_test(void)
109124
repetitions * l1d_misses_expected / 2,
110125
passes, repetitions);
111126

112-
if (rfi_flush == rfi_flush_org) {
113-
rfi_flush = !rfi_flush_org;
127+
if (rfi_flush == rfi_flush_orig) {
128+
rfi_flush = !rfi_flush_orig;
114129
if (write_debugfs_file("powerpc/rfi_flush", rfi_flush) < 0) {
115130
perror("error writing to powerpc/rfi_flush debugfs file");
116131
return 1;
@@ -126,11 +141,19 @@ int rfi_flush_test(void)
126141

127142
set_dscr(0);
128143

129-
if (write_debugfs_file("powerpc/rfi_flush", rfi_flush_org) < 0) {
144+
if (write_debugfs_file("powerpc/rfi_flush", rfi_flush_orig) < 0) {
130145
perror("unable to restore original value of powerpc/rfi_flush debugfs file");
131146
return 1;
132147
}
133148

149+
if (have_entry_flush) {
150+
if (write_debugfs_file("powerpc/entry_flush", entry_flush_orig) < 0) {
151+
perror("unable to restore original value of powerpc/entry_flush "
152+
"debugfs file");
153+
return 1;
154+
}
155+
}
156+
134157
return rc;
135158
}
136159

0 commit comments

Comments
 (0)