public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Cc: Sami Tolvanen <samitolvanen@google.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Steven Rostedt <rostedt@goodmis.org>,
	Arnd Bergmann <arnd@kernel.org>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Jason Baron <jbaron@akamai.com>, Ingo Molnar <mingo@redhat.com>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Ard Biesheuvel <ardb@kernel.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Daniel Bristot de Oliveira <bristot@redhat.com>,
	Frederic Weisbecker <frederic@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] static_call: fix function type mismatch
Date: Wed, 24 Mar 2021 20:16:06 +0100	[thread overview]
Message-ID: <YFuP9sRT8tYShLUm@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <YFt382FImjQQ+10f@hirez.programming.kicks-ass.net>

On Wed, Mar 24, 2021 at 06:33:39PM +0100, Peter Zijlstra wrote:
> On Wed, Mar 24, 2021 at 05:45:52PM +0100, Rasmus Villemoes wrote:
> > Sorry, I think I misread the code. The static calls are indeed
> > initialized with a function with the right prototype. Try adding
> > "preempt=full" on the command line so that we exercise these lines
> > 
> >                static_call_update(cond_resched,
> > (typeof(&__cond_resched)) __static_call_return0);
> >                 static_call_update(might_resched,
> > (typeof(&__cond_resched)) __static_call_return0);
> > 
> > I would expect that to blow up, since we end up calling a long (*)(void)
> > function using a function pointer of type int (*)(void).
> 
> Note that on x86 there won't actually be any calling of function
> pointers. See what arch/x86/kernel/static_call.c does :-)
> 
> But I think some of this code might need some __va_function() love when
> combined with CFI.
> 
> But yes, this is why I think something like -fcdecl might be a good
> idea, that ought to tell the compiler about the calling convention,
> which ought to be enough for the compiler to figure out that this magic
> really is ok.
> 
> Notable things we rely on:
> 
>  - caller cleanup of stack; the function caller sets up any stack
>    arguments and is also responsible for cleanin up the stack once the
>    function returns.

  - the arguments are pushed on stack right to left;

>  - the return value is in a register.
> 
> Per the first we can call a function that has a partial (empty per
> extremum) argument list. 

That extra constraint is required to make partial args work; as it
happens we only use empty args, and as such don't really care about this
atm.

> Per the second we can call a function with a
> different return type as long as they all fit in the same register.
> 
> The calling of a 'long (*)()' function for a 'int (*)()' type then
> becomes idential to something like: 'int x = (long)y', and that is
> something C is perfectly fine with.
> 
> We then slightly push things with the other __static_call_return0()
> usage in the kernel, where we basically end up with: 'void *x =
> (long)y', which is something C really rather would have a cast on.

  reply	other threads:[~2021-03-24 19:21 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22 17:06 [PATCH] static_call: fix function type mismatch Arnd Bergmann
2021-03-22 19:32 ` Steven Rostedt
2021-03-22 20:47   ` Peter Zijlstra
2021-03-22 21:18     ` Arnd Bergmann
2021-03-22 21:29       ` Steven Rostedt
2021-03-23  7:47         ` Peter Zijlstra
2021-03-24 12:46           ` Rasmus Villemoes
2021-03-24 16:01             ` Sami Tolvanen
2021-03-24 16:45               ` Rasmus Villemoes
2021-03-24 17:33                 ` Peter Zijlstra
2021-03-24 19:16                   ` Peter Zijlstra [this message]
2021-03-24 21:51                   ` Rasmus Villemoes
2021-03-24 22:34                     ` Sami Tolvanen
2021-03-24 22:53                       ` Rasmus Villemoes
2021-03-24 23:40                         ` Sami Tolvanen
2021-03-25  0:42                           ` Rasmus Villemoes
2021-03-25  7:42                             ` Peter Zijlstra
2021-03-25  7:45                               ` Ard Biesheuvel
2021-03-25  8:27                               ` Rasmus Villemoes
2021-03-23  7:35       ` 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=YFuP9sRT8tYShLUm@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=ardb@kernel.org \
    --cc=arnd@kernel.org \
    --cc=bristot@redhat.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=frederic@kernel.org \
    --cc=jbaron@akamai.com \
    --cc=jpoimboe@redhat.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=rasmus.villemoes@prevas.dk \
    --cc=rostedt@goodmis.org \
    --cc=samitolvanen@google.com \
    --cc=vincent.guittot@linaro.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