Article View: org.kernel.vger.linux-toolchains
Article #1Re: Thread Safety Analysis and the Linux kernel
From: Marco Elver
Date: Mon, 05 May 2025 13:44
Date: Mon, 05 May 2025 13:44
47 lines
6599 bytes
6599 bytes
On Wed, 5 Mar 2025 at 12:47, Marco Elver <elver@google.com> wrote: [...] > 1. Re-entrant acquires: rcu_read_lock(), preempt_disable(), etc. are > all re-entrant locks. My proposal is to introduce an attribute that > can be added to "ACQUIRE(..)" annotated functions to indicate they are > re-entrant. Release-count needs to then match acquire-count to fully > release a capability. FTR, reentrant locking support is taken care of: https://github.com/llvm/llvm-project/pull/137133 (should land soon). But I think we need at least #2 (basic alias analysis) as well for things to become tolerable for the kernel side. And that one looks a bit harder to implement in Clang, so it'll be a while. Thanks, -- Marco > 2. Basic alias analysis, e.g. when storing a pointer to a lock in a > function-local variable. [Complaint in: > https://lore.kernel.org/all/569186c5-8663-43df-a01c-d543f57ce5ca@kernel.org/ > -- quote: "Fix the analyzer instead."] > > 3. Ability to refer to locks in returned reference/pointer. For example: > struct foo *ret_lock_struct(void) ACQUIRE(return->somelock); > struct foo *try_ret_lock_struct(void) TRY_ACQUIRE(1, > return->somelock); // locked if non-NULL > I expect this also requires basic alias analysis to work so that > assigning the returned pointer to a function-local variable and then > later use in an unlock function works as expected. > > More complex requests: > > 4. The ability to deal with conditional locking with return values > that are not just true/non-zero and false/zero. A concrete case here > is that a lot of functions return error codes, and if the error code > is < 0, no lock is taken. If the error code is >= 0, the lock is > taken. [ Source: > https://lore.kernel.org/all/569186c5-8663-43df-a01c-d543f57ce5ca@kernel.org/ > ] > > 5. Better control-flow handling. Basic understanding of conditional > locking, which is explicitly ruled out in: > https://clang.llvm.org/docs/ThreadSafetyAnalysis.html#conditional-locks > - however, if there's some way to even get basic support, would vastly > improve things for the kernel. [...]
Technical Details
Message-ID:
<CANpmjNPRgUz9oX0H8kza2sB847Bai4rLtqfOnUSLmqt2Zm_pqA@mail.gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!archive!apf9.newsdeef.eu!nntp.lore.kernel.org!not-for-mailReferences:
<CANpmjNPquO=W1JAh1FNQb8pMQjgeZAKCPQUAd7qUg=5pjJ6x=Q@mail.gmail.com>Show Full Headers
Complete Article Headers
Message-ID: <CANpmjNPRgUz9oX0H8kza2sB847Bai4rLtqfOnUSLmqt2Zm_pqA@mail.gmail.com>
Subject: Re: Thread Safety Analysis and the Linux kernel
Date: Mon, 5 May 2025 15:44:02 +0200
From: Marco Elver <elver@google.com>
References: <CANpmjNPquO=W1JAh1FNQb8pMQjgeZAKCPQUAd7qUg=5pjJ6x=Q@mail.gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!archive!apf9.newsdeef.eu!nntp.lore.kernel.org!not-for-mail
Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88782255F24
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43
ARC-Seal: ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1746452682; cv=none; b=HfifddpgzY+9OxN77bcU9+z41jCKZRbee25gV5QmaHhjuFEmWIpzgoiCi6pi7Gt6iWwhcENfXG2WE7eLJr4ZFgv1zk2rApGdVjG64xDcHvVcnvCOkgBijO/BNibNr79kvQSe5VD/GI6YF9ID6X6WyGEDcl+QUfMez+xy2exLmHM=
ARC-Message-Signature: ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1746452682; c=relaxed/simple;
bh=6QvOvRZ/UbJMoeXSAGC96rle7AjVbTvBrmnBuUaYf68=;
h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject:
To:Cc:Content-Type; b=Y7XycVc7sRNM1ofMBDvF5R8F2ZScjEi1hJPMi+mGFB3dCjXv0a+/OddMwMsq7GFW4hf7Ke0ovmarB3DVhdla3x/Pv59mg1Vw/QvzjTP8/pf6LUbGeihUQKHwQcghK9kIbXWC67dFBrMLJUePBYEjW8gQD3eX/TZISsbEwT1/ShI=
ARC-Authentication-Results: ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=W+pVNcv/; arc=none smtp.client-ip=209.85.216.43
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com
Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="W+pVNcv/"
Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-3018e2d042bso2990157a91.2
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=google.com; s=20230601; t=1746452679; x=1747057479; darn=vger.kernel.org;
h=cc:to:subject:message-id:date:from:in-reply-to:references
:mime-version:from:to:cc:subject:date:message-id:reply-to;
bh=5kdmoNVQsFUVQTwbN99dic1kL41z+dsPAJ4dCN1KXOY=;
b=W+pVNcv/FdsOv3/6hxY7mlv6kJ1+fpENAx1QPvKIDUAf5yBMTQAZ5BeyIiheO6TPuQ
TO+ZdAOKcOEansksfqoz3ZrUoILGTRxRMiUYemxSe/mpWAnDZrA6vzD3GsEmNba2Gc8u
SR5G8aP6H3s+fYIfzc1meiqL/ac0mxlJ6hupfPOuENVudhNGELg74zVjgKijYirCc3vT
ZtGXWgxrFMooch9Y07xyVSui0fEqCSTOX1jdXvYiHHiWqmewTvKOTpfgrjUtriUljG0v
8eAJ0LkA5b1IwQ9nR17wVF+mZCc72myt2MgNxEjw2aLqvBX/Mzf6biiYrmIdlpwg5aLQ
KUFA==
X-Gm-Message-State: AOJu0YyTCzzbnmyM0NvuUOq6+C0yA5OfeZApAdy7DgtKEWRkLAfIUMlE
LYTbZtosZ6DwlMt9/Dr9PlH5PXzhSmEDcEw91cttcKRETcwK6OfC1O/WuHxsZ8UiI9jOPp6GDzL
D8a5LZfeimcDIJqiI4/KxEw2Zsdmhu/QeU/CdaAVwS4qjnHjm7dPu/YE=
X-Gm-Gg: ASbGnctEnsSoeRCV+Y9J7TLYB5jqY/qlRW5EyP8B5irEFV30cCozRhSaPzZkznqd/Dc
AJR0PjXrbn0uDgXpKhuGwhUds0ItrrVJQTA1U+dBCtmiQkP3QhEHYb6APVLY0CW5DBloPb6LZfx
CFEuuUL8qIv+tMTh/CIljHfNjtnGAEHDw9Y8J8hkLy3ggZemhgGDkh
X-Received: by 2002:a17:90b:4c12:b0:305:2d68:8d91 with SMTP id
98e67ed59e1d1-30a4e622226mr19074154a91.28.1746452679338; Mon, 05 May 2025
Precedence: bulk
X-Mailing-List: linux-toolchains@vger.kernel.org
List-Id: <linux-toolchains.vger.kernel.org>
List-Subscribe: <mailto:linux-toolchains+subscribe@vger.kernel.org>
List-Unsubscribe: <mailto:linux-toolchains+unsubscribe@vger.kernel.org>
MIME-Version: 1.0
In-Reply-To: <CANpmjNPquO=W1JAh1FNQb8pMQjgeZAKCPQUAd7qUg=5pjJ6x=Q@mail.gmail.com>
X-Gm-Features: ATxdqUFs6K5fsi07mj5QPnDApYO8Y4Qv6bhjBbyuo9NyPdbmUWE265bDD9qpTfw
To: linux-toolchains@vger.kernel.org, llvm@lists.linux.dev
Cc: aaron.puchert@sap.com, Aaron Ballman <aaron@aaronballman.com>,
Peter Zijlstra <peterz@infradead.org>, Bart Van Assche <bvanassche@acm.org>,
"Paul E. McKenney" <paulmck@kernel.org>, Boqun Feng <boqun.feng@gmail.com>
Content-Type: text/plain; charset="UTF-8"
Newsgroups: org.kernel.vger.linux-toolchains,dev.linux.lists.llvm