All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Akinobu Mita <akinobu.mita@gmail.com>,
	Christoph Lameter <cl@linux.com>,
	David Rientjes <rientjes@google.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	"Naveen N. Rao" <naveen.n.rao@linux.ibm.com>,
	Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>,
	"David S. Miller" <davem@davemloft.net>,
	Steven Rostedt <rostedt@goodmis.org>,
	Mark Rutland <mark.rutland@arm.com>, Jiri Olsa <jolsa@kernel.org>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Hyeonggon Yoo <42.hyeyoo@gmail.com>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	bpf@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH RFC 2/4] error-injection: support static keys around injectable functions
Date: Sun, 2 Jun 2024 23:19:50 +0900	[thread overview]
Message-ID: <20240602231950.cbb7bc65fce96934fb10dc06@kernel.org> (raw)
In-Reply-To: <20240531-fault-injection-statickeys-v1-2-a513fd0a9614@suse.cz>

On Fri, 31 May 2024 11:33:33 +0200
Vlastimil Babka <vbabka@suse.cz> wrote:

> Error injectable functions cannot be inlined and since some are called
> from hot paths, this incurrs overhead even if no error injection is
> enabled for them.
> 
> To remove this overhead when disabled, allow the callsites of error
> injectable functions to put the calls behind a static key, which the
> framework can control when error injection is enabled or disabled for
> the function.
> 
> Introduce a new ALLOW_ERROR_INJECTION_KEY() macro that adds a parameter
> with the static key's address, and store it in struct
> error_injection_entry. This new field has caused a mismatch when
> populating the injection list from the _error_injection_whitelist
> section with the current STRUCT_ALIGN(), so change the alignment to 8.
> 
> During the population, copy the key's address also to struct ei_entry,
> and make it possible to retrieve it along with the error type by
> get_injectable_error_type().
> 
> Finally, make the processing of writes to the debugfs inject file enable
> the static key when the function is added to the injection list, and
> disable when removed.
> 
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> ---
>  include/asm-generic/error-injection.h | 13 ++++++++++++-
>  include/asm-generic/vmlinux.lds.h     |  2 +-
>  include/linux/error-injection.h       |  9 ++++++---
>  kernel/fail_function.c                | 22 +++++++++++++++++++---
>  lib/error-inject.c                    |  6 +++++-
>  5 files changed, 43 insertions(+), 9 deletions(-)
> 
> diff --git a/include/asm-generic/error-injection.h b/include/asm-generic/error-injection.h
> index b05253f68eaa..eed2731f3820 100644
> --- a/include/asm-generic/error-injection.h
> +++ b/include/asm-generic/error-injection.h
> @@ -12,6 +12,7 @@ enum {
>  
>  struct error_injection_entry {
>  	unsigned long	addr;
> +	unsigned long	static_key_addr;
>  	int		etype;
>  };
>  
> @@ -25,16 +26,26 @@ struct pt_regs;
>   * 'Error Injectable Functions' section.
>   */
>  #define ALLOW_ERROR_INJECTION(fname, _etype)				\
> -static struct error_injection_entry __used				\
> +static struct error_injection_entry __used __aligned(8)			\
>  	__section("_error_injection_whitelist")				\
>  	_eil_addr_##fname = {						\
>  		.addr = (unsigned long)fname,				\
>  		.etype = EI_ETYPE_##_etype,				\
>  	}
>  
> +#define ALLOW_ERROR_INJECTION_KEY(fname, _etype, key)			\
> +static struct error_injection_entry __used __aligned(8)			\
> +	__section("_error_injection_whitelist")				\
> +	_eil_addr_##fname = {						\
> +		.addr = (unsigned long)fname,				\
> +		.static_key_addr = (unsigned long)key,			\
> +		.etype = EI_ETYPE_##_etype,				\
> +	}
> +
>  void override_function_with_return(struct pt_regs *regs);
>  #else
>  #define ALLOW_ERROR_INJECTION(fname, _etype)
> +#define ALLOW_ERROR_INJECTION_KEY(fname, _etype, key)
>  
>  static inline void override_function_with_return(struct pt_regs *regs) { }
>  #endif
> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> index 5703526d6ebf..1b15a0af2a00 100644
> --- a/include/asm-generic/vmlinux.lds.h
> +++ b/include/asm-generic/vmlinux.lds.h
> @@ -248,7 +248,7 @@
>  
>  #ifdef CONFIG_FUNCTION_ERROR_INJECTION
>  #define ERROR_INJECT_WHITELIST()			\
> -	STRUCT_ALIGN();					\
> +	. = ALIGN(8);					\
>  	BOUNDED_SECTION(_error_injection_whitelist)
>  #else
>  #define ERROR_INJECT_WHITELIST()
> diff --git a/include/linux/error-injection.h b/include/linux/error-injection.h
> index 20e738f4eae8..bec81b57a9d5 100644
> --- a/include/linux/error-injection.h
> +++ b/include/linux/error-injection.h
> @@ -6,10 +6,12 @@
>  #include <linux/errno.h>
>  #include <asm-generic/error-injection.h>
>  
> +struct static_key;
> +
>  #ifdef CONFIG_FUNCTION_ERROR_INJECTION
>  
> -extern bool within_error_injection_list(unsigned long addr);
> -extern int get_injectable_error_type(unsigned long addr);
> +bool within_error_injection_list(unsigned long addr);
> +int get_injectable_error_type(unsigned long addr, struct static_key **key_addr);

This seems like an add-hoc change. Since this is called in a cold path
(only used when adding new function), can you add new 
`struct static_key *get_injection_key(unsigned long addr)`
to find the static_key from the address?

Other part looks good to me.

Thank you,



-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

  reply	other threads:[~2024-06-02 14:19 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-31  9:33 [PATCH RFC 0/4] static key support for error injection functions Vlastimil Babka
2024-05-31  9:33 ` [PATCH RFC 1/4] fault-inject: add support for static keys around fault injection sites Vlastimil Babka
2024-05-31  9:33 ` [PATCH RFC 2/4] error-injection: support static keys around injectable functions Vlastimil Babka
2024-06-02 14:19   ` Masami Hiramatsu [this message]
2024-05-31  9:33 ` [PATCH RFC 3/4] mm, slab: add static key for should_failslab() Vlastimil Babka
2024-05-31 16:43   ` Alexei Starovoitov
2024-05-31 17:17     ` Yosry Ahmed
2024-06-01 20:57     ` Vlastimil Babka
2024-06-02 19:12       ` Alexei Starovoitov
2024-05-31 23:44   ` Roman Gushchin
2024-05-31  9:33 ` [PATCH RFC 4/4] mm, page_alloc: add static key for should_fail_alloc_page() Vlastimil Babka
2024-05-31 23:50   ` Roman Gushchin
2024-05-31 15:31 ` [PATCH RFC 0/4] static key support for error injection functions Mark Rutland
2024-06-01 20:48   ` Vlastimil Babka
2024-05-31 23:39 ` Roman Gushchin
2024-06-01 20:53   ` Vlastimil Babka
2024-06-02 11:36 ` Wei Yang
2024-06-02 11:36   ` Wei Yang
2024-06-02 20:47 ` David Rientjes
2024-06-02 21:08   ` Vlastimil Babka

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=20240602231950.cbb7bc65fce96934fb10dc06@kernel.org \
    --to=mhiramat@kernel.org \
    --cc=42.hyeyoo@gmail.com \
    --cc=akinobu.mita@gmail.com \
    --cc=andrii@kernel.org \
    --cc=anil.s.keshavamurthy@intel.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cl@linux.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=naveen.n.rao@linux.ibm.com \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=rostedt@goodmis.org \
    --cc=vbabka@suse.cz \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.