tm-vmxcopy.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright 2015, Michael Neuling, IBM Corp.
  3. * Licensed under GPLv2.
  4. *
  5. * Original: Michael Neuling 4/12/2013
  6. * Edited: Rashmica Gupta 4/12/2015
  7. *
  8. * See if the altivec state is leaked out of an aborted transaction due to
  9. * kernel vmx copy loops.
  10. *
  11. * When the transaction aborts, VSR values should rollback to the values
  12. * they held before the transaction commenced. Using VSRs while transaction
  13. * is suspended should not affect the checkpointed values.
  14. *
  15. * (1) write A to a VSR
  16. * (2) start transaction
  17. * (3) suspend transaction
  18. * (4) change the VSR to B
  19. * (5) trigger kernel vmx copy loop
  20. * (6) abort transaction
  21. * (7) check that the VSR value is A
  22. */
  23. #include <inttypes.h>
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <unistd.h>
  27. #include <sys/mman.h>
  28. #include <string.h>
  29. #include <assert.h>
  30. #include "tm.h"
  31. #include "utils.h"
  32. int test_vmxcopy()
  33. {
  34. long double vecin = 1.3;
  35. long double vecout;
  36. unsigned long pgsize = getpagesize();
  37. int i;
  38. int fd;
  39. int size = pgsize*16;
  40. char tmpfile[] = "/tmp/page_faultXXXXXX";
  41. char buf[pgsize];
  42. char *a;
  43. uint64_t aborted = 0;
  44. SKIP_IF(!have_htm());
  45. fd = mkstemp(tmpfile);
  46. assert(fd >= 0);
  47. memset(buf, 0, pgsize);
  48. for (i = 0; i < size; i += pgsize)
  49. assert(write(fd, buf, pgsize) == pgsize);
  50. unlink(tmpfile);
  51. a = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
  52. assert(a != MAP_FAILED);
  53. asm __volatile__(
  54. "lxvd2x 40,0,%[vecinptr];" /* set 40 to initial value*/
  55. "tbegin.;"
  56. "beq 3f;"
  57. "tsuspend.;"
  58. "xxlxor 40,40,40;" /* set 40 to 0 */
  59. "std 5, 0(%[map]);" /* cause kernel vmx copy page */
  60. "tabort. 0;"
  61. "tresume.;"
  62. "tend.;"
  63. "li %[res], 0;"
  64. "b 5f;"
  65. /* Abort handler */
  66. "3:;"
  67. "li %[res], 1;"
  68. "5:;"
  69. "stxvd2x 40,0,%[vecoutptr];"
  70. : [res]"=r"(aborted)
  71. : [vecinptr]"r"(&vecin),
  72. [vecoutptr]"r"(&vecout),
  73. [map]"r"(a)
  74. : "memory", "r0", "r3", "r4", "r5", "r6", "r7");
  75. if (aborted && (vecin != vecout)){
  76. printf("FAILED: vector state leaked on abort %f != %f\n",
  77. (double)vecin, (double)vecout);
  78. return 1;
  79. }
  80. munmap(a, size);
  81. close(fd);
  82. return 0;
  83. }
  84. int main(void)
  85. {
  86. return test_harness(test_vmxcopy, "tm_vmxcopy");
  87. }