mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Josh Poimboeuf <jpoimboe@kernel.org>, "x86@kernel.org" <x86@kernel.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Jason Baron <jbaron@akamai.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ard Biesheuvel <ardb@kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>,
	Sami Tolvanen <samitolvanen@google.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Will McVicker <willmcvicker@google.com>,
	Kees Cook <keescook@chromium.org>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v2 09/11] static_call: Make NULL static calls consistent
Date: Wed, 22 Mar 2023 15:04:36 +0000	[thread overview]
Message-ID: <dadf372b-9dc2-0c71-2860-1db7c59068b4@csgroup.eu> (raw)
In-Reply-To: <7638861ae89606b1277ad4235654bba2b880f313.1679456900.git.jpoimboe@kernel.org>



Le 22/03/2023 à 05:00, Josh Poimboeuf a écrit :
> NULL static calls have inconsistent behavior.  With HAVE_STATIC_CALL=y
> they're a NOP, but with HAVE_STATIC_CALL=n they go boom.
> 
> That's guaranteed to cause subtle bugs.  Make the behavior consistent by
> making NULL static calls a NOP with HAVE_STATIC_CALL=n.
> 
> This is probably easier than doing the reverse (making NULL static calls
> panic with HAVE_STATIC_CALL=y).  And it seems to match the current use
> cases better: there are several call sites which rely on the NOP
> behavior, whereas no call sites rely on the crashing behavior.
> 
> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
> ---

> diff --git a/arch/x86/kernel/static_call.c b/arch/x86/kernel/static_call.c
> index b70670a98597..27c095c7fc96 100644
> --- a/arch/x86/kernel/static_call.c
> +++ b/arch/x86/kernel/static_call.c
> @@ -89,7 +89,7 @@ static void __ref __static_call_transform(void *insn, enum insn_type type,
>   
>   	case JCC:
>   		if (!func) {
> -			func = __static_call_return;
> +			func = __static_call_return; //FIXME use __static_call_nop()?
>   			if (cpu_feature_enabled(X86_FEATURE_RETHUNK))
>   				func = x86_return_thunk;
>   		}
> @@ -139,33 +139,35 @@ static void __static_call_validate(u8 *insn, bool tail, bool tramp)
>   	BUG();
>   }
>   
> -static inline enum insn_type __sc_insn(bool null, bool tail)
> +static inline enum insn_type __sc_insn(bool nop, bool tail)
>   {
>   	/*
>   	 * Encode the following table without branches:
>   	 *
> -	 *	tail	null	insn
> +	 *	tail	nop	insn
>   	 *	-----+-------+------
>   	 *	  0  |   0   |  CALL
>   	 *	  0  |   1   |  NOP
>   	 *	  1  |   0   |  JMP
>   	 *	  1  |   1   |  RET
>   	 */
> -	return 2*tail + null;
> +	return 2*tail + nop;
>   }
>   
>   void arch_static_call_transform(void *site, void *tramp, void *func, bool tail)
>   {
> +	bool nop = (func == __static_call_nop);
> +

Would be clearer to call it 'is_nop', wouldn't it ?

>   	mutex_lock(&text_mutex);
>   
>   	if (tramp) {
>   		__static_call_validate(tramp, true, true);
> -		__static_call_transform(tramp, __sc_insn(!func, true), func, false);
> +		__static_call_transform(tramp, __sc_insn(nop, true), func, false);
>   	}
>   
>   	if (IS_ENABLED(CONFIG_HAVE_STATIC_CALL_INLINE) && site) {
>   		__static_call_validate(site, tail, false);
> -		__static_call_transform(site, __sc_insn(!func, tail), func, false);
> +		__static_call_transform(site, __sc_insn(nop, tail), func, false);
>   	}
>   
>   	mutex_unlock(&text_mutex);

Christophe

  parent reply	other threads:[~2023-03-22 15:05 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-22  4:00 [PATCH v2 00/11] static_call: Improve NULL/ret0 handling Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 01/11] static_call: Improve key type abstraction Josh Poimboeuf
2023-03-22  4:53   ` Josh Poimboeuf
2023-03-22  5:02   ` [PATCH v2.1 " Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 02/11] static_call: Flip key type union bit Josh Poimboeuf
2023-03-22  5:03   ` [PATCH v2.1 " Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 03/11] static_call: Remove static_call_mod_init() declaration Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 04/11] static_call: Remove static_call.h dependency on cpu.h Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 05/11] static_call: Make ARCH_ADD_TRAMP_KEY() generic Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 06/11] static_call: "EXPORT_STATIC_CALL_TRAMP" -> "EXPORT_STATIC_CALL_RO" Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 07/11] static_call: Reorganize static call headers Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 08/11] arm64/static_call: Fix static call CFI violations Josh Poimboeuf
2023-03-22 12:22   ` Mark Rutland
2023-03-22 14:19     ` Peter Zijlstra
2023-03-22 18:26       ` Josh Poimboeuf
2023-03-22 18:09     ` Josh Poimboeuf
2023-03-22 18:07   ` Sami Tolvanen
2023-03-22 18:33     ` Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 09/11] static_call: Make NULL static calls consistent Josh Poimboeuf
2023-03-22 14:45   ` Peter Zijlstra
2023-03-22 14:59   ` Peter Zijlstra
2023-03-22 18:35     ` Josh Poimboeuf
2023-03-22 15:04   ` Christophe Leroy [this message]
2023-03-22  4:00 ` [PATCH v2 10/11] static_call: Remove static_call_cond() Josh Poimboeuf
2023-03-22  4:00 ` [PATCH v2 11/11] static_call: Remove DEFINE_STATIC_CALL_RET0() Josh Poimboeuf
2023-03-22 15:04   ` Christophe Leroy
2023-03-22 18:50     ` Josh Poimboeuf
2023-03-22 15:15   ` Peter Zijlstra
2023-03-22 18:45     ` Josh Poimboeuf

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=dadf372b-9dc2-0c71-2860-1db7c59068b4@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=ardb@kernel.org \
    --cc=jbaron@akamai.com \
    --cc=jpoimboe@kernel.org \
    --cc=keescook@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=ndesaulniers@google.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=samitolvanen@google.com \
    --cc=seanjc@google.com \
    --cc=willmcvicker@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

all inboxes | Powered by JetHome®