[-next,V17,1/7] compiler_types.h: Add __noinstr_section() for noinstr

Message ID 20230222033021.983168-2-guoren@kernel.org
State New
Headers
Series riscv: Add GENERIC_ENTRY support |

Commit Message

Guo Ren Feb. 22, 2023, 3:30 a.m. UTC
  From: Lai Jiangshan <laijs@linux.alibaba.com>

Using __noinstr_section() doesn't automatically disable all
instrumentations on the section. Inhibition for some
instrumentations requires extra code. I.E. KPROBES explicitly
avoids instrumenting on .noinstr.text.

Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Björn Töpel <bjorn@rivosinc.com>
Tested-by: Jisheng Zhang <jszhang@kernel.org>
Tested-by: Guo Ren <guoren@kernel.org>
Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
---
 include/linux/compiler_types.h | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
  

Comments

Björn Töpel March 22, 2023, 2:46 p.m. UTC | #1
guoren@kernel.org writes:

> From: Lai Jiangshan <laijs@linux.alibaba.com>
>
> Using __noinstr_section() doesn't automatically disable all
> instrumentations on the section. Inhibition for some
> instrumentations requires extra code. I.E. KPROBES explicitly
> avoids instrumenting on .noinstr.text.

Guo, the generic entry series doesn't apply cleanly on
riscv/for-next >6.2-rc1, and this patch is the issue.

Could you do a respin (potentially w/o this patch)?


Cheers,
Björn
  
Lai Jiangshan March 23, 2023, 12:43 a.m. UTC | #2
On Wed, Feb 22, 2023 at 11:56 AM <guoren@kernel.org> wrote:
>
> From: Lai Jiangshan <laijs@linux.alibaba.com>
>
> Using __noinstr_section() doesn't automatically disable all
> instrumentations on the section. Inhibition for some
> instrumentations requires extra code. I.E. KPROBES explicitly
> avoids instrumenting on .noinstr.text.
>
> Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
> Suggested-by: Peter Zijlstra <peterz@infradead.org>
> Reviewed-by: Miguel Ojeda <ojeda@kernel.org>
> Reviewed-by: Kees Cook <keescook@chromium.org>
> Reviewed-by: Björn Töpel <bjorn@rivosinc.com>
> Tested-by: Jisheng Zhang <jszhang@kernel.org>
> Tested-by: Guo Ren <guoren@kernel.org>
> Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
> Signed-off-by: Guo Ren <guoren@kernel.org>

Hello

The change has been made upstream as a part of the commit
2b5a0e425e6e(objtool/idle: Validate __cpuidle code as noinstr).

https://lore.kernel.org/r/20230112195540.373461409@infradead.org

Thanks
Lai

> ---
>  include/linux/compiler_types.h | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
> index 7c1afe0f4129..0a2ca5755be7 100644
> --- a/include/linux/compiler_types.h
> +++ b/include/linux/compiler_types.h
> @@ -231,12 +231,19 @@ struct ftrace_likely_data {
>  #define __no_sanitize_or_inline __always_inline
>  #endif
>
> -/* Section for code which can't be instrumented at all */
> -#define noinstr                                                                \
> -       noinline notrace __attribute((__section__(".noinstr.text")))    \
> -       __no_kcsan __no_sanitize_address __no_profile __no_sanitize_coverage \
> +/*
> + * Using __noinstr_section() doesn't automatically disable all instrumentations
> + * on the section.  Inhibition for some instrumentations requires extra code.
> + * I.E. KPROBES explicitly avoids instrumenting on .noinstr.text.
> + */
> +#define __noinstr_section(section)                             \
> +       noinline notrace __section(section) __no_profile        \
> +       __no_kcsan __no_sanitize_address __no_sanitize_coverage \
>         __no_sanitize_memory
>
> +/* Section for code which can't be instrumented at all */
> +#define noinstr __noinstr_section(".noinstr.text")
> +
>  #endif /* __KERNEL__ */
>
>  #endif /* __ASSEMBLY__ */
> --
> 2.36.1
>
  
Guo Ren March 24, 2023, 1:51 a.m. UTC | #3
On Wed, Mar 22, 2023 at 10:46 PM Björn Töpel <bjorn@kernel.org> wrote:
>
> guoren@kernel.org writes:
>
> > From: Lai Jiangshan <laijs@linux.alibaba.com>
> >
> > Using __noinstr_section() doesn't automatically disable all
> > instrumentations on the section. Inhibition for some
> > instrumentations requires extra code. I.E. KPROBES explicitly
> > avoids instrumenting on .noinstr.text.
>
> Guo, the generic entry series doesn't apply cleanly on
> riscv/for-next >6.2-rc1, and this patch is the issue.

It has been merged in palmer/for-next.

Thx for taking care.

54b3948f381c (HEAD -> for-next, palmer/for-next) Merge patch series
"riscv: Add GENERIC_ENTRY support"
45b32b946a97 riscv: entry: Consolidate general regs saving/restoring
ab9164dae273 riscv: entry: Consolidate ret_from_kernel_thread into ret_from_fork
0bf298ad2b61 riscv: entry: Remove extra level wrappers of
trace_hardirqs_{on,off}
f0bddf50586d riscv: entry: Convert to generic entry
d0db02c62879 riscv: entry: Add noinstr to prevent instrumentation inserted
8574bf8d0ddd riscv: ptrace: Remove duplicate operation

>
> Could you do a respin (potentially w/o this patch)?
>
>
> Cheers,
> Björn
  

Patch

diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index 7c1afe0f4129..0a2ca5755be7 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -231,12 +231,19 @@  struct ftrace_likely_data {
 #define __no_sanitize_or_inline __always_inline
 #endif
 
-/* Section for code which can't be instrumented at all */
-#define noinstr								\
-	noinline notrace __attribute((__section__(".noinstr.text")))	\
-	__no_kcsan __no_sanitize_address __no_profile __no_sanitize_coverage \
+/*
+ * Using __noinstr_section() doesn't automatically disable all instrumentations
+ * on the section.  Inhibition for some instrumentations requires extra code.
+ * I.E. KPROBES explicitly avoids instrumenting on .noinstr.text.
+ */
+#define __noinstr_section(section)				\
+	noinline notrace __section(section) __no_profile	\
+	__no_kcsan __no_sanitize_address __no_sanitize_coverage	\
 	__no_sanitize_memory
 
+/* Section for code which can't be instrumented at all */
+#define noinstr __noinstr_section(".noinstr.text")
+
 #endif /* __KERNEL__ */
 
 #endif /* __ASSEMBLY__ */