From: <dan.j.williams@intel.com>
To: Nathan Chancellor <nathan@kernel.org>, <dan.j.williams@intel.com>
Cc: Andy Shevchenko <andriy.shevchenko@intel.com>,
<linux-cxl@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Alison Schofield <alison.schofield@intel.com>,
Dave Jiang <dave.jiang@intel.com>,
"David Lechner" <dlechner@baylibre.com>,
Davidlohr Bueso <dave@stgolabs.net>,
"Fabio M. De Francesco" <fabio.m.de.francesco@linux.intel.com>,
Ingo Molnar <mingo@kernel.org>, Ira Weiny <ira.weiny@intel.com>,
Jonathan Cameron <jonathan.cameron@huawei.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
"Peter Zijlstra (Intel)" <peterz@infradead.org>,
Shiju Jose <shiju.jose@huawei.com>,
Vishal Verma <vishal.l.verma@intel.com>
Subject: Re: [PATCH v3 0/8] cleanup: Introduce ACQUIRE(), a guard() for conditional locks
Date: Fri, 1 Aug 2025 16:51:48 -0700 [thread overview]
Message-ID: <688d5314c0e82_cff991007c@dwillia2-xfh.jf.intel.com.notmuch> (raw)
In-Reply-To: <20250801190203.GA939298@ax162>
Nathan Chancellor wrote:
> On Fri, Aug 01, 2025 at 11:49:22AM -0700, dan.j.williams@intel.com wrote:
> > Andy Shevchenko wrote:
> > > This series broke `make W=1` build vor clang. +Cc Nathan.
> > >
> > > Par exemple:
> > >
> > > /kernel/time/posix-timers.c:89:1: error: unused function 'class_lock_timer_lock_err' [-Werror,-Wunused-function]
> > > 89 | DEFINE_CLASS_IS_COND_GUARD(lock_timer);
> > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > > /include/linux/cleanup.h:376:2: note: expanded from macro 'DEFINE_CLASS_IS_COND_GUARD'
> > > 376 | __DEFINE_GUARD_LOCK_PTR(_name, _T)
> > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > > /include/linux/cleanup.h:358:20: note: expanded from macro '__DEFINE_GUARD_LOCK_PTR'
> > > 358 | static inline int class_##_name##_lock_err(class_##_name##_t *_T) \
> > > | ^~~~~~~~~~~~~~~~~~~~~~~~
> > > <scratch space>:24:1: note: expanded from here
> > > 24 | class_lock_timer_lock_err
> > > | ^~~~~~~~~~~~~~~~~~~~~~~~~
> > > 1 error generated.
> >
> > A few observations:
> >
> > - This is odd, the inline should have been compiled away if not used.
> > - __always_inline does not help
> > - Seems to go away with __maybe_unused, but that seems more like a
> > compiler band-aid than a fix
>
> See commit 6863f5643dd7 ("kbuild: allow Clang to find unused static
> inline functions for W=1 build") for more information on the difference
> between GCC and Clang when it comes to how 'static inline' functions
> behave with -Wunused-function, namely that Clang will warn for functions
> defined in .c files (but not .h files), whereas GCC will not warn for
> either.
Ah, thanks!
> > - This locking pattern is not immediately amenable to the ACQUIRE_ERR()
> > approach because the unlock object is the return code from the
> > constructor.
> >
> > Given all that, and that an ACQUIRE_ERR() would end up being messier
> > than the scoped_timer_get_or_fail() approach, I think the best fix is to
> > quiet the warning, but maybe Peter and Nathan have other ideas?
>
> Yes, this is what I would recommend, as we never care if this function
> is unused, right?
Hmm, it would be nice to care. For example, if someone did something
like use ACQUIRE() without a corresponding ACQUIRE_ERR(). It would be
nice to catch that, but that warning would only fire for clang builds
where the lock guard is defined in a C file.
> You could probably outright substitute '__maybe_unused' for 'inline'
> in this case, since the compiler is already free to ignore it and the
> attribute takes care of any potential unused warnings, which I think
> 'inline' is primarily used for nowadays.
Oh, true, good point.
Another option is make scoped_cond_guard() use the lock error helper.
The compiler should always elide that __guard_err() call, and in the
meantime maybe catch a true positive unused symbol for
class_##_name##_lock_err.
-- 8< --
diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h
index 4eb83dd71cfe..534723b14d92 100644
--- a/include/linux/cleanup.h
+++ b/include/linux/cleanup.h
@@ -421,13 +421,14 @@ _label: \
#define scoped_guard(_name, args...) \
__scoped_guard(_name, __UNIQUE_ID(label), args)
-#define __scoped_cond_guard(_name, _fail, _label, args...) \
- for (CLASS(_name, scope)(args); true; ({ goto _label; })) \
- if (!__guard_ptr(_name)(&scope)) { \
- BUILD_BUG_ON(!__is_cond_ptr(_name)); \
- _fail; \
-_label: \
- break; \
+#define __scoped_cond_guard(_name, _fail, _label, args...) \
+ for (CLASS(_name, scope)(args); true; ({ goto _label; })) \
+ if (!__guard_ptr(_name)(&scope) || \
+ __guard_err(_name)(&scope)) { \
+ BUILD_BUG_ON(!__is_cond_ptr(_name)); \
+ _fail; \
+_label: \
+ break; \
} else
#define scoped_cond_guard(_name, _fail, args...) \
prev parent reply other threads:[~2025-08-01 23:51 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-11 23:49 Dan Williams
2025-07-11 23:49 ` [PATCH v3 1/8] cleanup: Introduce ACQUIRE() and ACQUIRE_ERR() " Dan Williams
2025-07-15 15:34 ` Jonathan Cameron
2025-07-11 23:49 ` [PATCH v3 2/8] cxl/mbox: Convert poison list mutex to ACQUIRE() Dan Williams
2025-07-11 23:49 ` [PATCH v3 3/8] cxl/decoder: Move decoder register programming to a helper Dan Williams
2025-07-11 23:49 ` [PATCH v3 4/8] cxl/decoder: Drop pointless locking Dan Williams
2025-07-11 23:49 ` [PATCH v3 5/8] cxl/region: Split commit_store() into __commit() and queue_reset() helpers Dan Williams
2025-07-14 21:49 ` Fabio M. De Francesco
2025-07-11 23:49 ` [PATCH v3 6/8] cxl/region: Move ready-to-probe state check to a helper Dan Williams
2025-07-14 22:02 ` Fabio M. De Francesco
2025-07-15 15:33 ` Jonathan Cameron
2025-07-15 17:08 ` dan.j.williams
2025-07-11 23:49 ` [PATCH v3 7/8] cxl/region: Consolidate cxl_decoder_kill_region() and cxl_region_detach() Dan Williams
2025-07-14 18:17 ` Dave Jiang
2025-07-15 17:07 ` dan.j.williams
2025-07-14 22:09 ` Fabio M. De Francesco
2025-07-15 15:56 ` Jonathan Cameron
2025-07-15 16:44 ` dan.j.williams
2025-07-16 10:32 ` Jonathan Cameron
2025-07-11 23:49 ` [PATCH v3 8/8] cxl: Convert to ACQUIRE() for conditional rwsem locking Dan Williams
2025-07-14 16:28 ` Shiju Jose
2025-07-14 19:21 ` dan.j.williams
2025-07-14 18:39 ` Dave Jiang
2025-07-14 22:12 ` Fabio M. De Francesco
2025-07-15 16:20 ` Jonathan Cameron
2025-07-15 17:13 ` dan.j.williams
2025-07-15 17:38 ` Dave Jiang
2025-07-16 20:52 ` [PATCH v3 0/8] cleanup: Introduce ACQUIRE(), a guard() for conditional locks Dave Jiang
2025-07-30 15:10 ` Andy Shevchenko
2025-08-01 18:49 ` dan.j.williams
2025-08-01 19:02 ` Nathan Chancellor
2025-08-01 23:51 ` dan.j.williams [this message]
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=688d5314c0e82_cff991007c@dwillia2-xfh.jf.intel.com.notmuch \
--to=dan.j.williams@intel.com \
--cc=alison.schofield@intel.com \
--cc=andriy.shevchenko@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=dlechner@baylibre.com \
--cc=fabio.m.de.francesco@linux.intel.com \
--cc=ira.weiny@intel.com \
--cc=jonathan.cameron@huawei.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=nathan@kernel.org \
--cc=peterz@infradead.org \
--cc=shiju.jose@huawei.com \
--cc=torvalds@linux-foundation.org \
--cc=vishal.l.verma@intel.com \
/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®