https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=219399

--- Comment #108 from Don Lewis <truck...@freebsd.org> ---
(In reply to Nils Beyer from comment #91)
I'm pretty sure that ryzen_segv_test is actually broken.  The first iteration
of the loop in the t2 threadx() is unlocked and there is no guarantee that it
will have initialized things before thread1() tries to use them.

Try this patch:

--- ryzen_segv_test.c.orig      2017-07-24 14:26:23.851846000 -0700
+++ ryzen_segv_test.c   2017-07-24 15:02:33.998102000 -0700
@@ -291,29 +291,32 @@
        atomic_store(&flg, 0);
 }

+void threadx_core()
+{
+       uint8_t offset;
+       uint32_t randval;
+
+       offset = random() % 256;
+       randval = random();
+       memset(func_set, 0, sizeof(func_set_t));
+       memcpy(&func_set->func[offset], func_base, FUNC_BYTES);
+       func_set->offset = offset;
+       func_set->ret = randval;
+}
+
 void threadx(void *p)
 {
        uint8_t offset;
        uint32_t randval;
        int init = 0;
-       if(p != NULL) {
-               init = 1;
-       }

        //usleep(1000);

        while(atomic_load(&flg)) {
                offset = random() % 256;
                randval = random();
-               if(!init) {
-                       lock_enter();
-               } else {
-                       if(func_set == MAP_FAILED) {
-                               fprintf(stderr, "mmap returns MAP_FAILED!\n");
-                               return;
-                       }
-                       init = 0;
-               }
+               lock_enter();
+               // threadx_core();
                memset(func_set, 0, sizeof(func_set_t));
                memcpy(&func_set->func[offset], func_base, FUNC_BYTES);
                func_set->offset = offset;
@@ -330,8 +333,7 @@
 {
        int64_t loops;
        pthread_t t1, t2, t3;
-#ifdef _MSC_VER
-#else
+#if !defined(_MSC_VER) && !defined(__FreeBSD__)
        cpu_set_t cpuset;
        int cpu;
 #endif
@@ -349,19 +351,23 @@
        n_cpus = sysconf(_SC_NPROCESSORS_ONLN);
        func_set = mmap (NULL, sizeof(func_set_t), PROT_READ | PROT_WRITE |
PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 #endif
+       if(func_set == MAP_FAILED) {
+               fprintf(stderr, "mmap returns MAP_FAILED!\n");
+               exit (1);
+       }

        atomic_store(&flg, 1);
        atomic_store(&locked, 1);

        srandom(time(NULL) + pid);
        // You should confirm assembly of generated code, just in case the
compiler reorders mfence instruction
+       threadx_core();
        mfence(); // Assure that flags are stored properly
        pthread_create(&t1, NULL, (void*)thread1, &loops);
-       pthread_create(&t2, NULL, (void*)threadx, (void*)1);
+       pthread_create(&t2, NULL, (void*)threadx, NULL);
        pthread_create(&t3, NULL, (void*)threadx, NULL);

-#ifdef _MSC_VER
-#else
+#if !defined(_MSC_VER) && !defined(__FreeBSD__)
        cpu = random() % n_cpus;
        CPU_ZERO(&cpuset);
        CPU_SET(cpu, &cpuset);

-- 
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
freebsd-bugs@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "freebsd-bugs-unsubscr...@freebsd.org"

Reply via email to