Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright 2015, Michael Neuling, IBM Corp.
0004  *
0005  * Original: Michael Neuling 4/12/2013
0006  * Edited: Rashmica Gupta 4/12/2015
0007  *
0008  * See if the altivec state is leaked out of an aborted transaction due to
0009  * kernel vmx copy loops.
0010  *
0011  * When the transaction aborts, VSR values should rollback to the values
0012  * they held before the transaction commenced. Using VSRs while transaction
0013  * is suspended should not affect the checkpointed values.
0014  *
0015  * (1) write A to a VSR
0016  * (2) start transaction
0017  * (3) suspend transaction
0018  * (4) change the VSR to B
0019  * (5) trigger kernel vmx copy loop
0020  * (6) abort transaction
0021  * (7) check that the VSR value is A
0022  */
0023 
0024 #include <inttypes.h>
0025 #include <stdio.h>
0026 #include <stdlib.h>
0027 #include <unistd.h>
0028 #include <sys/mman.h>
0029 #include <string.h>
0030 #include <assert.h>
0031 
0032 #include "tm.h"
0033 #include "utils.h"
0034 
0035 int test_vmxcopy()
0036 {
0037     long double vecin = 1.3;
0038     long double vecout;
0039     unsigned long pgsize = getpagesize();
0040     int i;
0041     int fd;
0042     int size = pgsize*16;
0043     char tmpfile[] = "/tmp/page_faultXXXXXX";
0044     char buf[pgsize];
0045     char *a;
0046     uint64_t aborted = 0;
0047 
0048     SKIP_IF(!have_htm());
0049     SKIP_IF(htm_is_synthetic());
0050     SKIP_IF(!is_ppc64le());
0051 
0052     fd = mkstemp(tmpfile);
0053     assert(fd >= 0);
0054 
0055     memset(buf, 0, pgsize);
0056     for (i = 0; i < size; i += pgsize)
0057         assert(write(fd, buf, pgsize) == pgsize);
0058 
0059     unlink(tmpfile);
0060 
0061     a = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
0062     assert(a != MAP_FAILED);
0063 
0064     asm __volatile__(
0065         "lxvd2x 40,0,%[vecinptr];"  /* set 40 to initial value*/
0066         "tbegin.;"
0067         "beq    3f;"
0068         "tsuspend.;"
0069         "xxlxor 40,40,40;"      /* set 40 to 0 */
0070         "std    5, 0(%[map]);"      /* cause kernel vmx copy page */
0071         "tabort. 0;"
0072         "tresume.;"
0073         "tend.;"
0074         "li %[res], 0;"
0075         "b  5f;"
0076 
0077         /* Abort handler */
0078         "3:;"
0079         "li %[res], 1;"
0080 
0081         "5:;"
0082         "stxvd2x 40,0,%[vecoutptr];"
0083         : [res]"=&r"(aborted)
0084         : [vecinptr]"r"(&vecin),
0085           [vecoutptr]"r"(&vecout),
0086           [map]"r"(a)
0087         : "memory", "r0", "r3", "r4", "r5", "r6", "r7");
0088 
0089     if (aborted && (vecin != vecout)){
0090         printf("FAILED: vector state leaked on abort %f != %f\n",
0091                (double)vecin, (double)vecout);
0092         return 1;
0093     }
0094 
0095     munmap(a, size);
0096 
0097     close(fd);
0098 
0099     return 0;
0100 }
0101 
0102 int main(void)
0103 {
0104     return test_harness(test_vmxcopy, "tm_vmxcopy");
0105 }