Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/powerpc: Move set_dscr() into rfi_flush.c

This version of set_dscr() was added for the RFI flush test, and is
fairly specific to it. It also clashes with the version of set_dscr()
in dscr/dscr.h. So move it into the RFI flush test where it's used.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200819015727.1977134-3-mpe@ellerman.id.au

+35 -36
-1
tools/testing/selftests/powerpc/include/utils.h
··· 35 35 int read_debugfs_file(char *debugfs_file, int *result); 36 36 int write_debugfs_file(char *debugfs_file, int result); 37 37 int read_sysfs_file(char *debugfs_file, char *result, size_t result_size); 38 - void set_dscr(unsigned long val); 39 38 int perf_event_open_counter(unsigned int type, 40 39 unsigned long config, int group_fd); 41 40 int perf_event_enable(int fd);
+35
tools/testing/selftests/powerpc/security/rfi_flush.c
··· 10 10 #include <stdint.h> 11 11 #include <malloc.h> 12 12 #include <unistd.h> 13 + #include <signal.h> 13 14 #include <stdlib.h> 14 15 #include <string.h> 15 16 #include <stdio.h> ··· 40 39 load(p + j); 41 40 getppid(); 42 41 } 42 + } 43 + 44 + static void sigill_handler(int signr, siginfo_t *info, void *unused) 45 + { 46 + static int warned = 0; 47 + ucontext_t *ctx = (ucontext_t *)unused; 48 + unsigned long *pc = &UCONTEXT_NIA(ctx); 49 + 50 + /* mtspr 3,RS to check for move to DSCR below */ 51 + if ((*((unsigned int *)*pc) & 0xfc1fffff) == 0x7c0303a6) { 52 + if (!warned++) 53 + printf("WARNING: Skipping over dscr setup. Consider running 'ppc64_cpu --dscr=1' manually.\n"); 54 + *pc += 4; 55 + } else { 56 + printf("SIGILL at %p\n", pc); 57 + abort(); 58 + } 59 + } 60 + 61 + static void set_dscr(unsigned long val) 62 + { 63 + static int init = 0; 64 + struct sigaction sa; 65 + 66 + if (!init) { 67 + memset(&sa, 0, sizeof(sa)); 68 + sa.sa_sigaction = sigill_handler; 69 + sa.sa_flags = SA_SIGINFO; 70 + if (sigaction(SIGILL, &sa, NULL)) 71 + perror("sigill_handler"); 72 + init = 1; 73 + } 74 + 75 + asm volatile("mtspr %1,%0" : : "r" (val), "i" (SPRN_DSCR)); 43 76 } 44 77 45 78 int rfi_flush_test(void)
-35
tools/testing/selftests/powerpc/utils.c
··· 10 10 #include <fcntl.h> 11 11 #include <link.h> 12 12 #include <sched.h> 13 - #include <signal.h> 14 13 #include <stdio.h> 15 14 #include <stdlib.h> 16 15 #include <string.h> ··· 270 271 } 271 272 272 273 return 0; 273 - } 274 - 275 - static void sigill_handler(int signr, siginfo_t *info, void *unused) 276 - { 277 - static int warned = 0; 278 - ucontext_t *ctx = (ucontext_t *)unused; 279 - unsigned long *pc = &UCONTEXT_NIA(ctx); 280 - 281 - /* mtspr 3,RS to check for move to DSCR below */ 282 - if ((*((unsigned int *)*pc) & 0xfc1fffff) == 0x7c0303a6) { 283 - if (!warned++) 284 - printf("WARNING: Skipping over dscr setup. Consider running 'ppc64_cpu --dscr=1' manually.\n"); 285 - *pc += 4; 286 - } else { 287 - printf("SIGILL at %p\n", pc); 288 - abort(); 289 - } 290 - } 291 - 292 - void set_dscr(unsigned long val) 293 - { 294 - static int init = 0; 295 - struct sigaction sa; 296 - 297 - if (!init) { 298 - memset(&sa, 0, sizeof(sa)); 299 - sa.sa_sigaction = sigill_handler; 300 - sa.sa_flags = SA_SIGINFO; 301 - if (sigaction(SIGILL, &sa, NULL)) 302 - perror("sigill_handler"); 303 - init = 1; 304 - } 305 - 306 - asm volatile("mtspr %1,%0" : : "r" (val), "i" (SPRN_DSCR)); 307 274 } 308 275 309 276 int using_hash_mmu(bool *using_hash)