NetBSD Problem Report #58349
From www@netbsd.org Mon Jun 17 23:05:14 2024
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
client-signature RSA-PSS (2048 bits) client-digest SHA256)
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id D6E061A9238
for <gnats-bugs@gnats.NetBSD.org>; Mon, 17 Jun 2024 23:05:14 +0000 (UTC)
Message-Id: <20240617230513.656A61A923A@mollari.NetBSD.org>
Date: Mon, 17 Jun 2024 23:05:13 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: tsan expects cacheline-aligned thread-local variables but ld.elf_so only supports pointer-aligned
X-Send-Pr-Version: www-1.0
>Number: 58349
>Category: lib
>Synopsis: tsan expects cacheline-aligned thread-local variables but ld.elf_so only supports pointer-aligned
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: lib-bug-people
>State: analyzed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Jun 17 23:10:00 +0000 2024
>Closed-Date:
>Last-Modified: Tue Oct 08 23:38:37 +0000 2024
>Originator: Taylor R Campbell
>Release: current
>Organization:
The ld.elf_aligned Foundation
>Environment:
>Description:
Fail: regexp WARNING: ThreadSanitizer: data race not in stderr
ThreadSanitizer: CHECK failed: tsan_rtl.cpp:149 "((reinterpret_cast<uptr>(this) % 64)) == ((0))" (0x10, 0x0) (tid=16992)
ThreadSanitizer:DEADLYSIGNAL
==16992==ERROR: ThreadSanitizer: SEGV on unknown address 0x000000000017 (pc 0x7f7ff4e5d14e bp 0x7f7fffffe350 sp 0x7f7fffffe2c0 T16992)
==16992==The signal is caused by a READ memory access.
==16992==Hint: address points to the zero page.
ThreadSanitizer:DEADLYSIGNAL
ThreadSanitizer: nested bug in the same thread, aborting.
https://releng.netbsd.org/b5reports/amd64/2024/2024.06.16.19.21.46/test.html#usr.bin_cc_t_tsan_data_race_data_race
The issue is likely the following change in the gcc12 update:
__attribute__((tls_model("initial-exec")))
-THREADLOCAL char cur_thread_placeholder[sizeof(ThreadState)] ALIGNED(64);
+THREADLOCAL char cur_thread_placeholder[sizeof(ThreadState)] ALIGNED(
+ SANITIZER_CACHE_LINE_SIZE);
...
+ThreadState::ThreadState(Context *ctx, Tid tid, int unique_id, u64 epoch,
+ unsigned reuse_count, uptr stk_addr, uptr stk_size,
uptr tls_addr, uptr tls_size)
...
+ CHECK_EQ(reinterpret_cast<uptr>(this) % SANITIZER_CACHE_LINE_SIZE, 0);
http://cvsweb.netbsd.org/bsdweb.cgi/src/external/gpl3/gcc/dist/libsanitizer/tsan/tsan_rtl.cpp.diff?r1=1.2&r2=1.3&only_with_tag=MAIN
The alignment requirement is not new (the magic number 64 just got a name SANITIZER_CACHE_LINE_SIZE), but there is a new check to verify it at runtime which is now failing.
>How-To-Repeat:
cd /usr/tests/usr.bin/cc && atf-run t_tsan_data_race
>Fix:
Yes, please!
Possible options:
1. Delete the check like before.
2. Teach ld.elf_so/xmalloc.c to support larger alignments.
3. Teach ld.elf_so/tls.c to fudge larger 2^k-byte alignments for n-byte allocations by allocating n + 2^k - 1 bytes at p and returning q := (p + 2^k - 1) & ~(2^k - 1). (May require some twiddling to figure out what p was originally in order to free it later.)
>Release-Note:
>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/58349 CVS commit: src/external/gpl3/gcc/dist/libsanitizer/tsan
Date: Mon, 17 Jun 2024 23:35:52 +0000
Module Name: src
Committed By: riastradh
Date: Mon Jun 17 23:35:52 UTC 2024
Modified Files:
src/external/gpl3/gcc/dist/libsanitizer/tsan:
tsan_interceptors_posix.cpp tsan_rtl.cpp tsan_rtl.h
Log Message:
libtsan: Work around large TLS alignment issue.
PR lib/58349: tsan expects cacheline-aligned thread-local variables
but ld.elf_so only supports pointer-aligned
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \
src/external/gpl3/gcc/dist/libsanitizer/tsan/tsan_interceptors_posix.cpp \
src/external/gpl3/gcc/dist/libsanitizer/tsan/tsan_rtl.cpp
cvs rdiff -u -r1.4 -r1.5 \
src/external/gpl3/gcc/dist/libsanitizer/tsan/tsan_rtl.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/58349 CVS commit: src/doc
Date: Tue, 18 Jun 2024 18:55:32 +0000
Module Name: src
Committed By: riastradh
Date: Tue Jun 18 18:55:32 UTC 2024
Modified Files:
src/doc: HACKS
Log Message:
doc/HACKS: Note tsan TLS alignment workaround for PR lib/58349.
To generate a diff of this commit:
cvs rdiff -u -r1.245 -r1.246 src/doc/HACKS
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->analyzed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Tue, 08 Oct 2024 23:38:37 +0000
State-Changed-Why:
problem is understood and worked around but not properly fixed
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2024
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.