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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/powerpc/alignment/copy_first_unaligned.c

Version: ~ [ linux-5.15-rc5 ] ~ [ linux-5.14.11 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.72 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.152 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.210 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.250 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.286 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.288 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ 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.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Copyright 2016, Chris Smart, IBM Corporation.
  4  *
  5  * Calls to copy_first which are not 128-byte aligned should be
  6  * caught and sent a SIGBUS.
  7  */
  8 
  9 #include <signal.h>
 10 #include <string.h>
 11 #include <unistd.h>
 12 #include "utils.h"
 13 #include "instructions.h"
 14 
 15 unsigned int expected_instruction = PPC_INST_COPY_FIRST;
 16 unsigned int instruction_mask = 0xfc2007fe;
 17 
 18 void signal_action_handler(int signal_num, siginfo_t *info, void *ptr)
 19 {
 20         ucontext_t *ctx = ptr;
 21 #ifdef __powerpc64__
 22         unsigned int *pc = (unsigned int *)ctx->uc_mcontext.gp_regs[PT_NIP];
 23 #else
 24         unsigned int *pc = (unsigned int *)ctx->uc_mcontext.uc_regs->gregs[PT_NIP];
 25 #endif
 26 
 27         /*
 28          * Check that the signal was on the correct instruction, using a
 29          * mask because the compiler assigns the register at RB.
 30          */
 31         if ((*pc & instruction_mask) == expected_instruction)
 32                 _exit(0); /* We hit the right instruction */
 33 
 34         _exit(1);
 35 }
 36 
 37 void setup_signal_handler(void)
 38 {
 39         struct sigaction signal_action;
 40 
 41         memset(&signal_action, 0, sizeof(signal_action));
 42         signal_action.sa_sigaction = signal_action_handler;
 43         signal_action.sa_flags = SA_SIGINFO;
 44         sigaction(SIGBUS, &signal_action, NULL);
 45 }
 46 
 47 char cacheline_buf[128] __cacheline_aligned;
 48 
 49 int test_copy_first_unaligned(void)
 50 {
 51         /* Only run this test on a P9 or later */
 52         SKIP_IF(!have_hwcap2(PPC_FEATURE2_ARCH_3_00));
 53 
 54         /* Register our signal handler with SIGBUS */
 55         setup_signal_handler();
 56 
 57         /* +1 makes buf unaligned */
 58         copy_first(cacheline_buf+1);
 59 
 60         /* We should not get here */
 61         return 1;
 62 }
 63 
 64 int main(int argc, char *argv[])
 65 {
 66         return test_harness(test_copy_first_unaligned, "test_copy_first_unaligned");
 67 }
 68 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp