All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Marco Elver <elver@google.com>
Cc: linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com,
	Jan Kara <jack@suse.cz>,
	Timothy Day <timday@thelustrecollective.com>,
	linux-ext4@vger.kernel.org, Theodore Tso <tytso@mit.edu>,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] once_lite: Simplify condition handling and fix context analysis
Date: Mon, 7 Sep 2026 15:13:34 -0700	[thread overview]
Message-ID: <20260907221334.GA1619741@ax162> (raw)
In-Reply-To: <20260903101843.3462767-1-elver@google.com>

On Thu, Sep 03, 2026 at 10:16:38AM +0000, Marco Elver wrote:
> When WARN_ON_ONCE() wraps a conditional lock acquisition (such as
> down_write_trylock()) on architectures relying on DO_ONCE_LITE_IF()
> (e.g. arm), Clang's context analysis (Thread Safety Analysis) failed
> with a false positive:
> 
>   fs/ext2/xattr.c:825:6: error: rw_semaphore 'EXT2_I().xattr_sem' is not held on every path through here [-Werror,-Wthread-safety-analysis]
>     825 |         if (WARN_ON_ONCE(!down_write_trylock(&EXT2_I(inode)->xattr_sem)))
>         |             ^
> 
> This happens because DO_ONCE_LITE_IF() branches on __ONCE_LITE_IF()'s
> return value (__ret_once), creating an intermediate branch merge point
> where the lock may or may not be held depending on whether the once-flag
> (__already_done) was already set. Because the merge branch condition is
> __ret_once rather than the trylock predicate (__ret_do_once), Clang
> cannot reconcile the lockset at the branch merge points.
> 
> Fix it by refactoring __ONCE_LITE_IF() into an unconditional
> __ONCE_LITE() primitive and redefining __ONCE_LITE_IF(condition) as:
> 
>   (unlikely(condition) && __ONCE_LITE())
> 
> This simplifies the implementation, short-circuits evaluation so that
> __ONCE_LITE() is not called when the condition is false, and ensures
> that DO_ONCE_LITE_IF() only enters __ONCE_LITE() when __ret_do_once is
> true.
> 
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Link: https://lore.kernel.org/all/20260903072759.GA1750084@ax162/
> Signed-off-by: Marco Elver <elver@google.com>

Thanks, this fixes that warning for me across all my builds.

Tested-by: Nathan Chancellor <nathan@kernel.org> # build

-- 
Cheers,
Nathan

  parent reply	other threads:[~2026-09-07 22:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-03 10:16 [PATCH] once_lite: Simplify condition handling and fix context analysis Marco Elver
2026-09-03 10:25 ` sashiko-bot
2026-09-07 22:13 ` Nathan Chancellor [this message]
2026-09-07 22:17   ` Marco Elver
2026-09-08 10:15     ` Jan Kara
2026-09-09  0:20       ` Nathan Chancellor
2026-09-09  9:46         ` Jan Kara

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=20260907221334.GA1619741@ax162 \
    --to=nathan@kernel.org \
    --cc=elver@google.com \
    --cc=jack@suse.cz \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=timday@thelustrecollective.com \
    --cc=tytso@mit.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.