From: Peter Zijlstra <peterz@infradead.org>
To: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Sami Tolvanen <samitolvanen@google.com>,
x86@kernel.org, linux-kernel@vger.kernel.org,
Mark Rutland <mark.rutland@arm.com>,
Jason Baron <jbaron@akamai.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ard Biesheuvel <ardb@kernel.org>,
Christophe Leroy <christophe.leroy@csgroup.eu>,
Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>,
Nick Desaulniers <ndesaulniers@google.com>
Subject: Re: [RFC][PATCH 1/5] static_call: Make NULL static calls consistent
Date: Tue, 14 Mar 2023 11:06:51 +0100 [thread overview]
Message-ID: <20230314100651.GD1845660@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20230314015836.p3l43w7ez7qzxylr@treble>
On Mon, Mar 13, 2023 at 06:58:36PM -0700, Josh Poimboeuf wrote:
> On Mon, Mar 13, 2023 at 10:48:58AM -0700, Sami Tolvanen wrote:
> > On Sun, Mar 12, 2023 at 8:17 AM Peter Zijlstra <peterz@infradead.org> wrote:
> > >
> > > On Fri, Mar 10, 2023 at 05:20:04PM -0800, Josh Poimboeuf wrote:
> > > > 2) Create yet another "tier" of static call implementations, for
> > > > arches which can have the unfortunate combo of CFI_CLANG +
> > > > !HAVE_STATIC_CALL. CONFIG_ALMOST_DONT_HAVE_STATIC_CALL?
> > > >
> > > > The arch can define ARCH_DEFINE_STATIC_CALL_NOP() which uses inline
> > > > asm to create a CFI-compliant NOP/BUG/whatever version of the
> > > > function (insert lots of hand-waving). Is the kcfi hash available
> > > > to inline asm at build time?
> > >
> > > Yes, clang creates magic symbol for everything it sees a declaration
> > > for. This symbols can be referenced from asm, linking will make it all
> > > work.
> > >
> > > And yes, C sucks, you can't actually create a function definition from a
> > > type :/ Otherwise this could be trivially fixable.
> >
> > Wouldn't creating a separate inline assembly nop function that
> > references the CFI hash of another function with the correct type
> > potentially solve this issue like Josh suggested?
Yes it would, and the below looks about right. It's just a shame the C
language itself cannot sanely express that. Also, having a ton of silly
little nop functions is daft, but alas.
> Right, I was thinking something like this, where the nop function gets
> generated by DEFINE_STATIC_CALL().
>
> Completely untested of course...
>
> #define STATIC_CALL_NOP_PREFIX __SCN__
> #define STATIC_CALL_NOP(name) __PASTE(STATIC_CALL_NOP_PREFIX, name)
> #define STATIC_CALL_NOP_STR(name) __stringify(STATIC_CALL_NOP(name))
>
> #define ARCH_DEFINE_STATIC_CALL_NOP(name, func) \
> asm(".align 4 \n" \
IIRC arm64 just changed (or is about to) their alignment muck. I think
you can write this like:
".balign " __stringify(CONFIG_FUNCTION_ALIGNMENT) " \n" \
or somesuch...
> ".word __kcfi_typeid_" STATIC_CALL_NOP_STR(name) " \n" \
> ".globl " STATIC_CALL_NOP_STR(name) " \n" \
> STATIC_CALL_NOP_STR(name) ": \n" \
> "bti c \n" \
> "mov x0, xzr \n" \
> "ret \n" \
> ".type " STATIC_CALL_NOP_STR(name) ", @function \n" \
> ".size " STATIC_CALL_NOP_STR(name) ", . - " STATIC_CALL_NOP_STR(name) " \n")
>
> #define DECLARE_STATIC_CALL(name, func) \
> extern struct static_call_key STATIC_CALL_KEY(name); \
> extern typeof(func) STATIC_CALL_TRAMP(name) \
> extern typeof(func) STATIC_CALL_NOP(name)
>
> #define DEFINE_STATIC_CALL(name, _func, _func_init) \
> DECLARE_STATIC_CALL(name, _func); \
> ARCH_DEFINE_STATIC_CALL_NOP(name); \
> struct static_call_key STATIC_CALL_KEY(name) = { \
> .func = _func_init, \
> }
> --
> Josh
next prev parent reply other threads:[~2023-03-14 10:07 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-10 20:31 [RFC][PATCH 0/5] Improve static call NULL handling Josh Poimboeuf
2023-03-10 20:31 ` [RFC][PATCH 1/5] static_call: Make NULL static calls consistent Josh Poimboeuf
2023-03-10 20:59 ` Peter Zijlstra
2023-03-11 1:20 ` Josh Poimboeuf
2023-03-12 15:17 ` Peter Zijlstra
2023-03-13 15:08 ` Sean Christopherson
2023-03-13 17:48 ` Sami Tolvanen
2023-03-14 1:58 ` Josh Poimboeuf
2023-03-14 10:06 ` Peter Zijlstra [this message]
2023-03-10 20:31 ` [RFC][PATCH 2/5] static_call: Make NULL static calls return 0 Josh Poimboeuf
2023-03-10 20:31 ` [RFC][PATCH 3/5] static_call: Remove static_call_cond() and its usages Josh Poimboeuf
2023-03-10 20:31 ` [RFC][PATCH 4/5] static_call: Remove DEFINE_STATIC_CALL_RET0() and its uses Josh Poimboeuf
2023-03-10 20:31 ` [RFC][PATCH 5/5] x86/kvm: Simplify static call handling Josh Poimboeuf
2023-03-10 21:07 ` Sean Christopherson
2023-03-10 21:13 ` Steven Rostedt
2023-03-10 21:29 ` Sean Christopherson
2023-03-10 22:23 ` Josh Poimboeuf
2023-03-10 21:09 ` [RFC][PATCH 0/5] Improve static call NULL handling Steven Rostedt
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=20230314100651.GD1845660@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=ardb@kernel.org \
--cc=christophe.leroy@csgroup.eu \
--cc=jbaron@akamai.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=ndesaulniers@google.com \
--cc=pbonzini@redhat.com \
--cc=rostedt@goodmis.org \
--cc=samitolvanen@google.com \
--cc=seanjc@google.com \
--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