~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/powerpc/tm/tm-signal-context-chk-fpu.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Copyright 2016, Cyril Bur, IBM Corp.
  4  *
  5  * Test the kernel's signal frame code.
  6  *
  7  * The kernel sets up two sets of ucontexts if the signal was to be
  8  * delivered while the thread was in a transaction (referred too as
  9  * first and second contexts).
 10  * Expected behaviour is that the checkpointed state is in the user
 11  * context passed to the signal handler (first context). The speculated
 12  * state can be accessed with the uc_link pointer (second context).
 13  *
 14  * The rationale for this is that if TM unaware code (which linked
 15  * against TM libs) installs a signal handler it will not know of the
 16  * speculative nature of the 'live' registers and may infer the wrong
 17  * thing.
 18  */
 19 
 20 #include <stdlib.h>
 21 #include <stdio.h>
 22 #include <signal.h>
 23 #include <unistd.h>
 24 
 25 #include <altivec.h>
 26 
 27 #include "utils.h"
 28 #include "tm.h"
 29 
 30 #define MAX_ATTEMPT 500000
 31 
 32 #define NV_FPU_REGS 18 /* Number of non-volatile FP registers */
 33 #define FPR14 14 /* First non-volatile FP register to check in f14-31 subset */
 34 
 35 long tm_signal_self_context_load(pid_t pid, long *gprs, double *fps, vector int *vms, vector int *vss);
 36 
 37 /* Test only non-volatile registers, i.e. 18 fpr registers from f14 to f31 */
 38 static double fps[] = {
 39         /* First context will be set with these values, i.e. non-speculative */
 40          1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
 41         /* Second context will be set with these values, i.e. speculative */
 42         -1,-2,-3,-4,-5,-6,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18
 43 };
 44 
 45 static sig_atomic_t fail, broken;
 46 
 47 static void signal_usr1(int signum, siginfo_t *info, void *uc)
 48 {
 49         int i;
 50         ucontext_t *ucp = uc;
 51         ucontext_t *tm_ucp = ucp->uc_link;
 52 
 53         for (i = 0; i < NV_FPU_REGS; i++) {
 54                 /* Check first context. Print all mismatches. */
 55                 fail = (ucp->uc_mcontext.fp_regs[FPR14 + i] != fps[i]);
 56                 if (fail) {
 57                         broken = 1;
 58                         printf("FPR%d (1st context) == %g instead of %g (expected)\n",
 59                                 FPR14 + i, ucp->uc_mcontext.fp_regs[FPR14 + i], fps[i]);
 60                 }
 61         }
 62 
 63         for (i = 0; i < NV_FPU_REGS; i++) {
 64                 /* Check second context. Print all mismatches. */
 65                 fail = (tm_ucp->uc_mcontext.fp_regs[FPR14 + i] != fps[NV_FPU_REGS + i]);
 66                 if (fail) {
 67                         broken = 1;
 68                         printf("FPR%d (2nd context) == %g instead of %g (expected)\n",
 69                                 FPR14 + i, tm_ucp->uc_mcontext.fp_regs[FPR14 + i], fps[NV_FPU_REGS + i]);
 70                 }
 71         }
 72 }
 73 
 74 static int tm_signal_context_chk_fpu()
 75 {
 76         struct sigaction act;
 77         int i;
 78         long rc;
 79         pid_t pid = getpid();
 80 
 81         SKIP_IF(!have_htm());
 82         SKIP_IF(htm_is_synthetic());
 83 
 84         act.sa_sigaction = signal_usr1;
 85         sigemptyset(&act.sa_mask);
 86         act.sa_flags = SA_SIGINFO;
 87         if (sigaction(SIGUSR1, &act, NULL) < 0) {
 88                 perror("sigaction sigusr1");
 89                 exit(1);
 90         }
 91 
 92         i = 0;
 93         while (i < MAX_ATTEMPT && !broken) {
 94                 /*
 95                  * tm_signal_self_context_load will set both first and second
 96                  * contexts accordingly to the values passed through non-NULL
 97                  * array pointers to it, in that case 'fps', and invoke the
 98                  * signal handler installed for SIGUSR1.
 99                  */
100                 rc = tm_signal_self_context_load(pid, NULL, fps, NULL, NULL);
101                 FAIL_IF(rc != pid);
102                 i++;
103         }
104 
105         return (broken);
106 }
107 
108 int main(void)
109 {
110         return test_harness(tm_signal_context_chk_fpu, "tm_signal_context_chk_fpu");
111 }
112 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php