From: "tip-bot2 for Ingo Molnar" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Ingo Molnar <mingo@kernel.org>,
David Lechner <dlechner@baylibre.com>,
Peter Zijlstra <peterz@infradead.org>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: locking/urgent] headers/cleanup.h: Remove the if_not_guard() facility
Date: Sat, 07 Dec 2024 10:22:28 -0000 [thread overview]
Message-ID: <173356694825.412.962172886533779549.tip-bot2@tip-bot2> (raw)
In-Reply-To: <Z1LBnX9TpZLR5Dkf@gmail.com>
The following commit has been merged into the locking/urgent branch of tip:
Commit-ID: b4d83c8323b0c4a899a996fed919cfe10720d289
Gitweb: https://git.kernel.org/tip/b4d83c8323b0c4a899a996fed919cfe10720d289
Author: Ingo Molnar <mingo@kernel.org>
AuthorDate: Fri, 06 Dec 2024 10:19:31 +01:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Sat, 07 Dec 2024 11:15:14 +01:00
headers/cleanup.h: Remove the if_not_guard() facility
Linus noticed that the new if_not_guard() definition is fragile:
"This macro generates actively wrong code if it happens to be inside an
if-statement or a loop without a block.
IOW, code like this:
for (iterate-over-something)
if_not_guard(a)
return -BUSY;
looks like will build fine, but will generate completely incorrect code."
The reason is that the __if_not_guard() macro is multi-statement, so
while most kernel developers expect macros to be simple or at least
compound statements - but for __if_not_guard() it is not so:
#define __if_not_guard(_name, _id, args...) \
BUILD_BUG_ON(!__is_cond_ptr(_name)); \
CLASS(_name, _id)(args); \
if (!__guard_ptr(_name)(&_id))
To add insult to injury, the placement of the BUILD_BUG_ON() line makes
the macro appear to compile fine, but it will generate incorrect code
as Linus reported, for example if used within iteration or conditional
statements that will use the first statement of a macro as a loop body
or conditional statement body.
[ I'd also like to note that the original submission by David Lechner did
not contain the BUILD_BUG_ON() line, so it was safer than what we ended
up committing. Mea culpa. ]
It doesn't appear to be possible to turn this macro into a robust
single or compound statement that could be used in single statements,
due to the necessity to define an auto scope variable with an open
scope and the necessity of it having to expand to a partial 'if'
statement with no body.
Instead of trying to work around this fragility, just remove the
construct before it gets used.
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: David Lechner <dlechner@baylibre.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/Z1LBnX9TpZLR5Dkf@gmail.com
---
include/linux/cleanup.h | 14 --------------
1 file changed, 14 deletions(-)
diff --git a/include/linux/cleanup.h b/include/linux/cleanup.h
index 966fcc5..ec00e3f 100644
--- a/include/linux/cleanup.h
+++ b/include/linux/cleanup.h
@@ -273,12 +273,6 @@ static inline class_##_name##_t class_##_name##ext##_constructor(_init_args) \
* an anonymous instance of the (guard) class, not recommended for
* conditional locks.
*
- * if_not_guard(name, args...) { <error handling> }:
- * convenience macro for conditional guards that calls the statement that
- * follows only if the lock was not acquired (typically an error return).
- *
- * Only for conditional locks.
- *
* scoped_guard (name, args...) { }:
* similar to CLASS(name, scope)(args), except the variable (with the
* explicit name 'scope') is declard in a for-loop such that its scope is
@@ -350,14 +344,6 @@ _label: \
#define scoped_cond_guard(_name, _fail, args...) \
__scoped_cond_guard(_name, _fail, __UNIQUE_ID(label), args)
-#define __if_not_guard(_name, _id, args...) \
- BUILD_BUG_ON(!__is_cond_ptr(_name)); \
- CLASS(_name, _id)(args); \
- if (!__guard_ptr(_name)(&_id))
-
-#define if_not_guard(_name, args...) \
- __if_not_guard(_name, __UNIQUE_ID(guard), args)
-
/*
* Additional helper macros for generating lock guards with types, either for
* locks that don't have a native type (eg. RCU, preempt) or those that need a
next prev parent reply other threads:[~2024-12-07 10:22 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-18 9:03 [GIT PULL] locking changes for v6.13 Ingo Molnar
2024-11-19 20:56 ` Linus Torvalds
2024-11-20 0:02 ` Ingo Molnar
2024-11-20 11:36 ` [PATCH] headers/cleanup.h: Fix if_not_guard() fragility Ingo Molnar
2024-11-20 11:52 ` Ingo Molnar
2024-11-20 17:57 ` David Lechner
2024-11-20 18:19 ` Linus Torvalds
2024-12-06 9:19 ` [PATCH] headers/cleanup.h: Remove the if_not_guard() facility Ingo Molnar
2024-12-06 15:31 ` David Lechner
2024-12-07 10:22 ` tip-bot2 for Ingo Molnar [this message]
2024-11-19 23:33 ` [GIT PULL] locking changes for v6.13 pr-tracker-bot
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=173356694825.412.962172886533779549.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=dlechner@baylibre.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.org \
/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®