param tests: membarrier: pre-decode pointer offset
[librseq.git] / tests / param_test.c
index ede647139146ac5b45a8ee1d0ca52eb8637708d5..252a0a7dec663743681bf750371089803882abc2 100644 (file)
@@ -80,14 +80,12 @@ int yield_mod_cnt, nr_abort;
        , INJECT_ASM_REG
 
 /*
- * "mov asm_loop_cnt_" #n ", %%" INJECT_ASM_REG "\n\t" causes the
- * following linker warning:
- *
- * /usr/bin/ld: param_test.o: warning: relocation in read-only section `.text'
- * /usr/bin/ld: warning: creating DT_TEXTREL in a PIE
+ * Use ip-relative addressing to get the loop counter.
  */
-#define RSEQ_INJECT_ASM(n) \
-       "mov asm_loop_cnt_" #n ", %%" INJECT_ASM_REG "\n\t" \
+#define __RSEQ_INJECT_ASM(n, ref_ip, ref_label) \
+       "movl " __rseq_str(ref_ip) ", %%" INJECT_ASM_REG "\n\t" \
+       "leal ( asm_loop_cnt_" #n " - " __rseq_str(ref_label) "b)(%%" INJECT_ASM_REG "), %%" INJECT_ASM_REG "\n\t" \
+       "movl (%%" INJECT_ASM_REG "), %%" INJECT_ASM_REG "\n\t" \
        "test %%" INJECT_ASM_REG ",%%" INJECT_ASM_REG "\n\t" \
        "jz 333f\n\t" \
        "222:\n\t" \
@@ -95,6 +93,9 @@ int yield_mod_cnt, nr_abort;
        "jnz 222b\n\t" \
        "333:\n\t"
 
+#define RSEQ_INJECT_ASM(n) \
+       __RSEQ_INJECT_ASM(n, %[ref_ip], RSEQ_ASM_REF_LABEL)
+
 #elif defined(__x86_64__)
 
 #define INJECT_ASM_REG_P       "rax"
@@ -1362,6 +1363,7 @@ bool membarrier_private_expedited_rseq_available(void)
 /* Test MEMBARRIER_CMD_PRIVATE_RESTART_RSEQ_ON_CPU membarrier command. */
 #ifdef TEST_MEMBARRIER
 struct test_membarrier_thread_args {
+       struct rseq_percpu_pool *mempool;
        struct percpu_list __rseq_percpu *percpu_list_ptr;
        int stop;
 };
@@ -1389,12 +1391,12 @@ void *test_membarrier_worker_thread(void *arg)
 
                do {
                        int cpu = get_current_cpu_id();
-                       struct percpu_list __rseq_percpu *list = RSEQ_READ_ONCE(args->percpu_list_ptr);
-                       struct percpu_list *cpulist = rseq_percpu_ptr(list, cpu);
+                       ptrdiff_t mempool_offset = rseq_percpu_pool_ptr_offset(args->mempool, cpu);
 
-                       ret = rseq_load_cbne_load_add_store__ptr(RSEQ_MO_RELAXED, RSEQ_PERCPU,
-                               (intptr_t *) &args->percpu_list_ptr, (intptr_t) list,
-                               &cpulist->head->data, 1, cpu);
+                       ret = rseq_load_add_load_load_add_store__ptr(RSEQ_MO_RELAXED, RSEQ_PERCPU,
+                               (intptr_t *) &args->percpu_list_ptr,
+                               mempool_offset + offsetof(struct percpu_list, head),
+                               1, cpu);
                } while (rseq_unlikely(ret));
        }
 
@@ -1462,6 +1464,7 @@ void *test_membarrier_manager_thread(void *arg)
                perror("rseq_percpu_pool_create");
                abort();
        }
+       args->mempool = mempool;
 
        if (rseq_register_current_thread()) {
                fprintf(stderr, "Error: rseq_register_current_thread(...) failed(%d): %s\n",
This page took 0.023707 seconds and 4 git commands to generate.