From: Olivier Dion via lttng-dev <lttng-dev@lists.lttng.org>
To: Dmitry Vyukov <dvyukov@google.com>
Cc: lttng-dev@lists.lttng.org, "Paul E. McKenney" <paulmck@kernel.org>
Subject: Re: [lttng-dev] [PATCH 00/11] Add support for TSAN to liburcu
Date: Tue, 23 May 2023 12:05:07 -0400 [thread overview]
Message-ID: <87v8gj11ak.fsf@laura> (raw)
In-Reply-To: <87ttwbj9uz.fsf@laura>
[-- Attachment #1: Type: text/plain, Size: 209 bytes --]
Hi Dmitry,
We do have a new issue and we think it might be a limitation from TSAN.
Find attached a test program that we believe is correct. You can
compile it with `gcc -fsanitize=thread test.c -pthread'.
[-- Attachment #2: test.c --]
[-- Type: application/octet-stream, Size: 2035 bytes --]
#include <stdlib.h>
#include <stdint.h>
#include <pthread.h>
#define LOOP 1000
struct node {
struct node *next;
};
static pthread_barrier_t barrier;
static struct node the_terminal_node = { .next = &the_terminal_node };
static struct node pending_stack = { &the_terminal_node };
extern void __tsan_acquire(void*);
extern void __tsan_release(void*);
extern void __tsan_ignore_thread_begin();
extern void __tsan_ignore_thread_end();
static void *push_worker(void *nil)
{
(void) nil;
pthread_barrier_wait(&barrier);
for (size_t k=0; k<LOOP; ++k){
struct node *new_node, *old_node;
new_node = calloc(1, sizeof(struct node));
old_node = __atomic_exchange_n(&pending_stack.next,
new_node,
__ATOMIC_SEQ_CST);
/* Works if RELEASE. */
__atomic_store_n(&new_node->next, old_node, __ATOMIC_RELAXED);
/* Also works if: */
#if 0
__tsan_ignore_thread_begin();
__atomic_store_n(&new_node->next, old_node, __ATOMIC_RELAXED);
__tsan_ignore_thread_end();
#endif
/* Why is this not working? */
#if 0
__tsan_release(&new_node->next);
__atomic_store_n(&new_node->next, old_node, __ATOMIC_RELAXED);
#endif
}
return NULL;
}
static void *pop_worker(void *nil)
{
(void) nil;
size_t k = 0;
pthread_barrier_wait(&barrier);
while (k < LOOP) {
struct node *current_stack;
struct node *next_node;
current_stack = __atomic_exchange_n(&pending_stack.next,
&the_terminal_node,
__ATOMIC_SEQ_CST);
while (current_stack != &the_terminal_node) {
retry_load:
next_node = __atomic_load_n(¤t_stack->next,
__ATOMIC_CONSUME);
if (!next_node) {
goto retry_load;
}
free(current_stack);
current_stack = next_node;
++k;
}
}
return NULL;
}
int main(void)
{
pthread_t ths[2];
pthread_barrier_init(&barrier, NULL, 3);
pthread_create(&ths[0], NULL, push_worker, NULL);
pthread_create(&ths[1], NULL, pop_worker, NULL);
pthread_barrier_wait(&barrier);
pthread_join(ths[0], NULL);
pthread_join(ths[1], NULL);
return 0;
}
[-- Attachment #3: Type: text/plain, Size: 821 bytes --]
TSAN flags a race condition between the atomic store relaxed at line 36
and the free at line 81.
We can solve the issue by replacing the atomic store relaxed with a
atomic store release. However, the preceding atomic exchange with
sequential consistency already acts as an implicit release (in term of
memory barrier) for the following store, making the release semantic
redundant.
We've found an alternative to fix this by ignoring the thread during the
relaxed store (line 39). However, what we would like is to annotate the
memory stored (line 45).
My theory (I don't know the internal of TSAN much) is that TSAN thinks
for some reason that the atomic store relaxed happen at the same epoch
as the free, resulting in a false positive. If so, m
Thought?
--
Olivier Dion
EfficiOS Inc.
https://www.efficios.com
[-- Attachment #4: Type: text/plain, Size: 156 bytes --]
_______________________________________________
lttng-dev mailing list
lttng-dev@lists.lttng.org
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
next prev parent reply other threads:[~2023-05-23 16:05 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-15 20:17 [lttng-dev] [PATCH 00/11] Add support for TSAN to liburcu Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 01/11] configure: Add --disable-atomic-builtins option Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 02/11] urcu/uatomic: Use atomic builtins if configured Olivier Dion via lttng-dev
2023-06-21 23:19 ` Paul E. McKenney via lttng-dev
2023-06-22 15:55 ` Mathieu Desnoyers via lttng-dev
2023-06-22 18:32 ` Paul E. McKenney via lttng-dev
2023-06-22 19:53 ` Olivier Dion via lttng-dev
2023-06-22 19:56 ` Mathieu Desnoyers via lttng-dev
2023-06-22 20:10 ` Olivier Dion via lttng-dev
2023-06-22 20:11 ` Paul E. McKenney via lttng-dev
2023-06-22 19:54 ` Mathieu Desnoyers via lttng-dev
2023-06-29 17:22 ` Olivier Dion via lttng-dev
2023-06-29 17:27 ` Olivier Dion via lttng-dev
2023-06-29 18:33 ` Mathieu Desnoyers via lttng-dev
2023-06-29 18:29 ` Mathieu Desnoyers via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 03/11] urcu/compiler: " Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 04/11] urcu/arch/generic: " Olivier Dion via lttng-dev
2023-06-21 23:22 ` Paul E. McKenney via lttng-dev
2023-06-22 0:53 ` Olivier Dion via lttng-dev
2023-06-22 1:48 ` Mathieu Desnoyers via lttng-dev
2023-06-22 3:44 ` Paul E. McKenney via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 05/11] urcu/system: " Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 06/11] urcu/uatomic: Add CMM memory model Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 07/11] urcu-wait: Fix wait state load/store Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 08/11] tests: Use uatomic for accessing global states Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 09/11] benchmark: " Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 10/11] tests/unit/test_build: Quiet unused return value Olivier Dion via lttng-dev
2023-05-15 20:17 ` [lttng-dev] [PATCH 11/11] urcu/annotate: Add CMM annotation Olivier Dion via lttng-dev
2023-05-16 15:57 ` Olivier Dion via lttng-dev
2023-05-16 8:18 ` [lttng-dev] [PATCH 00/11] Add support for TSAN to liburcu Dmitry Vyukov via lttng-dev
2023-05-16 15:47 ` Olivier Dion via lttng-dev
2023-05-17 10:21 ` Dmitry Vyukov via lttng-dev
2023-05-17 10:57 ` Dmitry Vyukov via lttng-dev
2023-05-17 14:44 ` Olivier Dion via lttng-dev
2023-05-23 16:05 ` Olivier Dion via lttng-dev [this message]
2023-05-24 8:14 ` Dmitry Vyukov via lttng-dev
2023-05-26 5:33 ` Ondřej Surý via lttng-dev
2023-05-26 6:08 ` Dmitry Vyukov via lttng-dev
2023-05-26 6:10 ` Dmitry Vyukov via lttng-dev
2023-05-26 10:06 ` Ondřej Surý via lttng-dev
2023-05-26 10:08 ` Dmitry Vyukov via lttng-dev
2023-05-26 14:20 ` Olivier Dion via lttng-dev
2023-05-26 15:15 ` Olivier Dion via lttng-dev
2023-05-17 14:44 ` Olivier Dion via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 00/12] " Olivier Dion via lttng-dev
2023-06-07 19:04 ` Ondřej Surý via lttng-dev
2023-06-07 19:20 ` Olivier Dion via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 01/12] configure: Add --disable-atomic-builtins option Olivier Dion via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 02/12] urcu/compiler: Use atomic builtins if configured Olivier Dion via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 03/12] urcu/arch/generic: " Olivier Dion via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 04/12] urcu/system: " Olivier Dion via lttng-dev
2023-06-21 23:23 ` Paul E. McKenney via lttng-dev
2023-07-04 14:43 ` Olivier Dion via lttng-dev
2023-07-05 18:48 ` Paul E. McKenney via lttng-dev
2023-07-05 19:03 ` Olivier Dion via lttng-dev
2023-07-05 19:28 ` Paul E. McKenney via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 05/12] urcu/uatomic: Add CMM memory model Olivier Dion via lttng-dev
2023-06-21 23:28 ` Paul E. McKenney via lttng-dev
2023-06-29 16:49 ` Olivier Dion via lttng-dev
2023-06-29 18:40 ` Paul E. McKenney via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 06/12] urcu-wait: Fix wait state load/store Olivier Dion via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 07/12] tests: Use uatomic for accessing global states Olivier Dion via lttng-dev
2023-06-21 23:37 ` Paul E. McKenney via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 08/12] benchmark: " Olivier Dion via lttng-dev
2023-06-21 23:38 ` Paul E. McKenney via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 09/12] tests/unit/test_build: Quiet unused return value Olivier Dion via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 10/12] urcu/annotate: Add CMM annotation Olivier Dion via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 11/12] Add cmm_emit_legacy_smp_mb() Olivier Dion via lttng-dev
2023-06-07 18:53 ` [lttng-dev] [PATCH v2 12/12] tests: Add tests for checking race conditions Olivier Dion via lttng-dev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87v8gj11ak.fsf@laura \
--to=lttng-dev@lists.lttng.org \
--cc=dvyukov@google.com \
--cc=odion@efficios.com \
--cc=paulmck@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).