From: Peter Zijlstra <peterz@infradead.org>
To: linux-kernel@vger.kernel.org
Cc: linux-tip-commits@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
Ingo Molnar <mingo@kernel.org>,
x86@kernel.org, Josh Poimboeuf <jpoimboe@redhat.com>,
Steven Rostedt <rostedt@goodmis.org>,
jbaron@akamai.com, ardb@kernel.org, frederic@kernel.org
Subject: Re: [tip: locking/core] static_call: Fix function type mismatch
Date: Tue, 23 Mar 2021 16:49:02 +0100 [thread overview]
Message-ID: <YFoN7nCl8OfGtpeh@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <YFmavWCgUOOfibXR@hirez.programming.kicks-ass.net>
On Tue, Mar 23, 2021 at 08:37:33AM +0100, Peter Zijlstra wrote:
> On Mon, Mar 22, 2021 at 11:30:07PM -0000, tip-bot2 for Arnd Bergmann wrote:
> > The following commit has been merged into the locking/core branch of tip:
> >
> > Commit-ID: 335c73e7c8f7deb23537afbbbe4f8ab48bd5de52
> > Gitweb: https://git.kernel.org/tip/335c73e7c8f7deb23537afbbbe4f8ab48bd5de52
> > Author: Arnd Bergmann <arnd@arndb.de>
> > AuthorDate: Mon, 22 Mar 2021 22:42:24 +01:00
> > Committer: Ingo Molnar <mingo@kernel.org>
> > CommitterDate: Tue, 23 Mar 2021 00:08:53 +01:00
> >
> > static_call: Fix function type mismatch
> >
> > The __static_call_return0() function is declared to return a 'long',
> > while it aliases a couple of functions that all return 'int'. When
> > building with 'make W=1', gcc warns about this:
> >
> > kernel/sched/core.c:5420:37: error: cast between incompatible function types from 'long int (*)(void)' to 'int (*)(void)' [-Werror=cast-function-type]
> > 5420 | static_call_update(might_resched, (typeof(&__cond_resched)) __static_call_return0);
> >
> > Change all these function to return 'long' as well, but remove the cast to
> > ensure we get a warning if any of the types ever change.
> >
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> > Signed-off-by: Ingo Molnar <mingo@kernel.org>
> > Link: https://lore.kernel.org/r/20210322214309.730556-1-arnd@kernel.org
>
> So I strongly disagree and think the warning is bad and should be
> disabled. I'll go uncommit this patch.
How's this then? I haven't yet build GCC11 myself, but seeing how adding
the (void *) cast fixed the ftrace case, it should work here too.
And note that if you remove the (void *) cast, you get a nice warning:
../include/linux/static_call.h:121:41: error: initialization of ‘int (*)(void)’ from incompatible pointer type ‘long int (*)(void)’ [-Werror=incompatible-pointer-types]
No fancy new compiler fail^Wfeatures needed.
Also note the irony, how a warning that was supposed to strengthen types
leads to weakening them.
---
Subject: static_call: Relax static_call_update() function argument type
static_call_update() had stronger type requirements than regular C,
relax them to match. Instead of requiring the @func argument has the
exact matching type, allow any type which C is willing to promote to the
right (function) pointer type. Specifically this allows (void *)
arguments.
This cleans up a bunch of static_call_update() callers for
PREEMPT_DYNAMIC and should get around silly GCC11 warnings for free.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
include/linux/static_call.h | 4 ++--
kernel/sched/core.c | 18 +++++++++---------
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/include/linux/static_call.h b/include/linux/static_call.h
index e01b61ab86b1..fc94faa53b5b 100644
--- a/include/linux/static_call.h
+++ b/include/linux/static_call.h
@@ -118,9 +118,9 @@ extern void arch_static_call_transform(void *site, void *tramp, void *func, bool
#define static_call_update(name, func) \
({ \
- BUILD_BUG_ON(!__same_type(*(func), STATIC_CALL_TRAMP(name))); \
+ typeof(&STATIC_CALL_TRAMP(name)) __F = (func); \
__static_call_update(&STATIC_CALL_KEY(name), \
- STATIC_CALL_TRAMP_ADDR(name), func); \
+ STATIC_CALL_TRAMP_ADDR(name), __F); \
})
#define static_call_query(name) (READ_ONCE(STATIC_CALL_KEY(name).func))
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 3384ea74cad4..42f9bedc666c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5402,25 +5402,25 @@ static void sched_dynamic_update(int mode)
switch (mode) {
case preempt_dynamic_none:
static_call_update(cond_resched, __cond_resched);
- static_call_update(might_resched, (typeof(&__cond_resched)) __static_call_return0);
- static_call_update(preempt_schedule, (typeof(&preempt_schedule)) NULL);
- static_call_update(preempt_schedule_notrace, (typeof(&preempt_schedule_notrace)) NULL);
- static_call_update(irqentry_exit_cond_resched, (typeof(&irqentry_exit_cond_resched)) NULL);
+ static_call_update(might_resched, (void *)&__static_call_return0);
+ static_call_update(preempt_schedule, NULL);
+ static_call_update(preempt_schedule_notrace, NULL);
+ static_call_update(irqentry_exit_cond_resched, NULL);
pr_info("Dynamic Preempt: none\n");
break;
case preempt_dynamic_voluntary:
static_call_update(cond_resched, __cond_resched);
static_call_update(might_resched, __cond_resched);
- static_call_update(preempt_schedule, (typeof(&preempt_schedule)) NULL);
- static_call_update(preempt_schedule_notrace, (typeof(&preempt_schedule_notrace)) NULL);
- static_call_update(irqentry_exit_cond_resched, (typeof(&irqentry_exit_cond_resched)) NULL);
+ static_call_update(preempt_schedule, NULL);
+ static_call_update(preempt_schedule_notrace, NULL);
+ static_call_update(irqentry_exit_cond_resched, NULL);
pr_info("Dynamic Preempt: voluntary\n");
break;
case preempt_dynamic_full:
- static_call_update(cond_resched, (typeof(&__cond_resched)) __static_call_return0);
- static_call_update(might_resched, (typeof(&__cond_resched)) __static_call_return0);
+ static_call_update(cond_resched, (void *)&__static_call_return0);
+ static_call_update(might_resched, (void *)&__static_call_return0);
static_call_update(preempt_schedule, __preempt_schedule_func);
static_call_update(preempt_schedule_notrace, __preempt_schedule_notrace_func);
static_call_update(irqentry_exit_cond_resched, irqentry_exit_cond_resched);
next prev parent reply other threads:[~2021-03-23 16:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-22 21:42 [PATCH] [v2] static_call: fix " Arnd Bergmann
2021-03-22 23:30 ` [tip: locking/core] static_call: Fix " tip-bot2 for Arnd Bergmann
2021-03-23 7:37 ` Peter Zijlstra
2021-03-23 15:49 ` Peter Zijlstra [this message]
2021-04-09 11:30 ` [tip: locking/core] static_call: Relax static_call_update() function argument type tip-bot2 for Peter Zijlstra
2021-03-23 7:33 ` [PATCH] [v2] static_call: fix function type mismatch Peter Zijlstra
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=YFoN7nCl8OfGtpeh@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=frederic@kernel.org \
--cc=jbaron@akamai.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=rostedt@goodmis.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®