mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: paulmck@kernel.org
Cc: "Peter Zijlstra" <peterz@infradead.org>,
	"Ingo Molnar" <mingo@redhat.com>, "Will Deacon" <will@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>,
	"Waiman Long" <longman@redhat.com>,
	linux-kernel@vger.kernel.org, "Marco Elver" <elver@google.com>,
	"Lai Jiangshan" <jiangshanlai@gmail.com>,
	"Josh Triplett" <josh@joshtriplett.org>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Nathan Chancellor" <nathan@kernel.org>
Subject: Re: [PATCH v3 3/3] srcu: Remove check from srcu_dereference_check()
Date: Tue, 17 Nov 2026 12:03:52 -0800	[thread overview]
Message-ID: <a02a6dde-5baf-4223-a583-5270f39b00d2@acm.org> (raw)
In-Reply-To: <6f9e7e5c-eeba-4a8b-b944-b45bbe591cdb@paulmck-laptop>

On 11/17/26 10:44 AM, Paul E. McKenney wrote:
 > Right you are!  Maybe __is_constexpr() would be better?

Hi Paul,

Yes, it is. __is_constexpr() is a sizeof() trick, so its result is
always an integer constant expression that the compiler front end
computes. That's the result the Clang context analysis needs.
Unlike __builtin_constant_p(), nothing is left for the optimizer to
decide. This removes the limitation I described: if 'c' is a plain
variable, function argument or structure member, the check is now
skipped, as it should be.

include/linux/compiler.h already has a helper built on top of it:

	#define const_true(x) \
		__builtin_choose_expr(__is_constexpr(x), x, false)

so I plan to write this as follows:

	if (const_true(!(c)))
		__srcu_read_lock_must_hold(ssp);

Writing '__is_constexpr(c) && !(c)' instead gives the same results.

Results with clang -Wthread-safety, at -O0 and -O2:

	c == 0 or false                    -> checked
	c == 1                             -> not checked
	c == lockdep_is_held(&m)           -> not checked
	c == ({ (void)(&m); 1; })          -> not checked
	     (lockdep_is_held() with CONFIG_LOCKDEP=n)
	c == v, foo->flag, function arg    -> not checked (with
	                                      __builtin_constant_p()
	                                      these were false positives)
	c == lockdep_is_held(&m) || !v     -> not checked

GCC builds it without warnings. GCC doesn't run the context
analysis, and __srcu_read_lock_must_hold() is an empty inline
function, so the generated code doesn't change.

I will make this change in v4, together with the other changes I
listed earlier.

Thanks,

Bart.

  reply	other threads:[~2026-11-17 20:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 22:59 [PATCH 0/3] Fix three Clang context analysis issues Bart Van Assche
2026-11-16 22:59 ` [PATCH v3 1/3] bit_spinlock: Fix the __bitlock() definition Bart Van Assche
2026-11-16 22:59 ` [PATCH v3 2/3] cleanup: Disable context analysis for __free() helpers Bart Van Assche
2026-11-16 22:59 ` [PATCH v3 3/3] srcu: Remove check from srcu_dereference_check() Bart Van Assche
2026-11-17  0:51   ` Paul E. McKenney
2026-11-17 16:53     ` Bart Van Assche
2026-11-17 17:53       ` Paul E. McKenney
2026-11-17 18:20         ` Bart Van Assche
2026-11-17 18:44           ` Paul E. McKenney
2026-11-17 20:03             ` Bart Van Assche [this message]
2026-11-17 20:19               ` Paul E. McKenney

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=a02a6dde-5baf-4223-a583-5270f39b00d2@acm.org \
    --to=bvanassche@acm.org \
    --cc=boqun@kernel.org \
    --cc=elver@google.com \
    --cc=jiangshanlai@gmail.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@redhat.com \
    --cc=nathan@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=will@kernel.org \
    --cc=work@onurozkan.dev \
    /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

all inboxes | Powered by JetHome®