All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] arm64: kasan: do not instrument stacktrace.c
@ 2022-05-21 23:50 ` andrey.konovalov
  0 siblings, 0 replies; 8+ messages in thread
From: andrey.konovalov @ 2022-05-21 23:50 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Andrey Konovalov, Marco Elver, Alexander Potapenko,
	Dmitry Vyukov, Andrey Ryabinin, kasan-dev, Catalin Marinas,
	Vincenzo Frascino, Will Deacon, linux-arm-kernel, linux-kernel,
	Andrey Konovalov

From: Andrey Konovalov <andreyknvl@google.com>

Disable KASAN instrumentation of arch/arm64/kernel/stacktrace.c.

This speeds up Generic KASAN by 5-20%.

As a side-effect, KASAN is now unable to detect bugs in the stack trace
collection code. This is taken as an acceptable downside.

Also replace READ_ONCE_NOCHECK() with READ_ONCE() in stacktrace.c.
As the file is now not instrumented, there is no need to use the
NOCHECK version of READ_ONCE().

Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
 arch/arm64/kernel/Makefile     | 3 +++
 arch/arm64/kernel/stacktrace.c | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index fa7981d0d917..da8cf6905c76 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -14,6 +14,9 @@ CFLAGS_REMOVE_return_address.o = $(CC_FLAGS_FTRACE)
 CFLAGS_REMOVE_syscall.o	 = -fstack-protector -fstack-protector-strong
 CFLAGS_syscall.o	+= -fno-stack-protector
 
+# Do not instrument to improve performance.
+KASAN_SANITIZE_stacktrace.o := n
+
 # It's not safe to invoke KCOV when portions of the kernel environment aren't
 # available or are out-of-sync with HW state. Since `noinstr` doesn't always
 # inhibit KCOV instrumentation, disable it for the entire compilation unit.
diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index e4103e085681..33e96ae4b15f 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -110,8 +110,8 @@ static int notrace unwind_frame(struct task_struct *tsk,
 	 * Record this frame record's values and location. The prev_fp and
 	 * prev_type are only meaningful to the next unwind_frame() invocation.
 	 */
-	frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp));
-	frame->pc = READ_ONCE_NOCHECK(*(unsigned long *)(fp + 8));
+	frame->fp = READ_ONCE(*(unsigned long *)(fp));
+	frame->pc = READ_ONCE(*(unsigned long *)(fp + 8));
 	frame->prev_fp = fp;
 	frame->prev_type = info.type;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 1/2] arm64: kasan: do not instrument stacktrace.c
@ 2022-05-21 23:50 ` andrey.konovalov
  0 siblings, 0 replies; 8+ messages in thread
From: andrey.konovalov @ 2022-05-21 23:50 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Andrey Konovalov, Marco Elver, Alexander Potapenko,
	Dmitry Vyukov, Andrey Ryabinin, kasan-dev, Catalin Marinas,
	Vincenzo Frascino, Will Deacon, linux-arm-kernel, linux-kernel,
	Andrey Konovalov

From: Andrey Konovalov <andreyknvl@google.com>

Disable KASAN instrumentation of arch/arm64/kernel/stacktrace.c.

This speeds up Generic KASAN by 5-20%.

As a side-effect, KASAN is now unable to detect bugs in the stack trace
collection code. This is taken as an acceptable downside.

Also replace READ_ONCE_NOCHECK() with READ_ONCE() in stacktrace.c.
As the file is now not instrumented, there is no need to use the
NOCHECK version of READ_ONCE().

Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
 arch/arm64/kernel/Makefile     | 3 +++
 arch/arm64/kernel/stacktrace.c | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index fa7981d0d917..da8cf6905c76 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -14,6 +14,9 @@ CFLAGS_REMOVE_return_address.o = $(CC_FLAGS_FTRACE)
 CFLAGS_REMOVE_syscall.o	 = -fstack-protector -fstack-protector-strong
 CFLAGS_syscall.o	+= -fno-stack-protector
 
+# Do not instrument to improve performance.
+KASAN_SANITIZE_stacktrace.o := n
+
 # It's not safe to invoke KCOV when portions of the kernel environment aren't
 # available or are out-of-sync with HW state. Since `noinstr` doesn't always
 # inhibit KCOV instrumentation, disable it for the entire compilation unit.
diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index e4103e085681..33e96ae4b15f 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -110,8 +110,8 @@ static int notrace unwind_frame(struct task_struct *tsk,
 	 * Record this frame record's values and location. The prev_fp and
 	 * prev_type are only meaningful to the next unwind_frame() invocation.
 	 */
-	frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp));
-	frame->pc = READ_ONCE_NOCHECK(*(unsigned long *)(fp + 8));
+	frame->fp = READ_ONCE(*(unsigned long *)(fp));
+	frame->pc = READ_ONCE(*(unsigned long *)(fp + 8));
 	frame->prev_fp = fp;
 	frame->prev_type = info.type;
 
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] arm64: stacktrace: use non-atomic __set_bit
  2022-05-21 23:50 ` andrey.konovalov
@ 2022-05-21 23:50   ` andrey.konovalov
  -1 siblings, 0 replies; 8+ messages in thread
From: andrey.konovalov @ 2022-05-21 23:50 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Andrey Konovalov, Marco Elver, Alexander Potapenko,
	Dmitry Vyukov, Andrey Ryabinin, kasan-dev, Catalin Marinas,
	Vincenzo Frascino, Will Deacon, linux-arm-kernel, linux-kernel,
	Andrey Konovalov

From: Andrey Konovalov <andreyknvl@google.com>

Use the non-atomic version of set_bit() in arch/arm64/kernel/stacktrace.c,
as there is no concurrent accesses to frame->prev_type.

This speeds up stack trace collection and improves the boot time of
Generic KASAN by 2-5%.

Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
 arch/arm64/kernel/stacktrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index 33e96ae4b15f..03593d451b0a 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -103,7 +103,7 @@ static int notrace unwind_frame(struct task_struct *tsk,
 		if (fp <= frame->prev_fp)
 			return -EINVAL;
 	} else {
-		set_bit(frame->prev_type, frame->stacks_done);
+		__set_bit(frame->prev_type, frame->stacks_done);
 	}
 
 	/*
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] arm64: stacktrace: use non-atomic __set_bit
@ 2022-05-21 23:50   ` andrey.konovalov
  0 siblings, 0 replies; 8+ messages in thread
From: andrey.konovalov @ 2022-05-21 23:50 UTC (permalink / raw)
  To: Mark Rutland
  Cc: Andrey Konovalov, Marco Elver, Alexander Potapenko,
	Dmitry Vyukov, Andrey Ryabinin, kasan-dev, Catalin Marinas,
	Vincenzo Frascino, Will Deacon, linux-arm-kernel, linux-kernel,
	Andrey Konovalov

From: Andrey Konovalov <andreyknvl@google.com>

Use the non-atomic version of set_bit() in arch/arm64/kernel/stacktrace.c,
as there is no concurrent accesses to frame->prev_type.

This speeds up stack trace collection and improves the boot time of
Generic KASAN by 2-5%.

Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
 arch/arm64/kernel/stacktrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index 33e96ae4b15f..03593d451b0a 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -103,7 +103,7 @@ static int notrace unwind_frame(struct task_struct *tsk,
 		if (fp <= frame->prev_fp)
 			return -EINVAL;
 	} else {
-		set_bit(frame->prev_type, frame->stacks_done);
+		__set_bit(frame->prev_type, frame->stacks_done);
 	}
 
 	/*
-- 
2.25.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] arm64: kasan: do not instrument stacktrace.c
  2022-05-21 23:50 ` andrey.konovalov
@ 2022-05-23 11:33   ` Mark Rutland
  -1 siblings, 0 replies; 8+ messages in thread
From: Mark Rutland @ 2022-05-23 11:33 UTC (permalink / raw)
  To: andrey.konovalov
  Cc: Andrey Konovalov, Marco Elver, Alexander Potapenko,
	Dmitry Vyukov, Andrey Ryabinin, kasan-dev, Catalin Marinas,
	Vincenzo Frascino, Will Deacon, linux-arm-kernel, linux-kernel,
	Andrey Konovalov

On Sun, May 22, 2022 at 01:50:58AM +0200, andrey.konovalov@linux.dev wrote:
> From: Andrey Konovalov <andreyknvl@google.com>
> 
> Disable KASAN instrumentation of arch/arm64/kernel/stacktrace.c.
> 
> This speeds up Generic KASAN by 5-20%.
> 
> As a side-effect, KASAN is now unable to detect bugs in the stack trace
> collection code. This is taken as an acceptable downside.
> 
> Also replace READ_ONCE_NOCHECK() with READ_ONCE() in stacktrace.c.
> As the file is now not instrumented, there is no need to use the
> NOCHECK version of READ_ONCE().
> 
> Suggested-by: Mark Rutland <mark.rutland@arm.com>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> ---
>  arch/arm64/kernel/Makefile     | 3 +++
>  arch/arm64/kernel/stacktrace.c | 4 ++--
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
> index fa7981d0d917..da8cf6905c76 100644
> --- a/arch/arm64/kernel/Makefile
> +++ b/arch/arm64/kernel/Makefile
> @@ -14,6 +14,9 @@ CFLAGS_REMOVE_return_address.o = $(CC_FLAGS_FTRACE)
>  CFLAGS_REMOVE_syscall.o	 = -fstack-protector -fstack-protector-strong
>  CFLAGS_syscall.o	+= -fno-stack-protector
>  
> +# Do not instrument to improve performance.
> +KASAN_SANITIZE_stacktrace.o := n

Can we make that a little more descriptive? e.g.

# When KASAN is enabled, a stacktrace is recorded for every alloc/free, which
# can significantly impact performance. Avoid instrumenting the stacktrace code
# to minimize this impact.
KASAN_SANITIZE_stacktrace.o := n

With that:

  Acked-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> +
>  # It's not safe to invoke KCOV when portions of the kernel environment aren't
>  # available or are out-of-sync with HW state. Since `noinstr` doesn't always
>  # inhibit KCOV instrumentation, disable it for the entire compilation unit.
> diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
> index e4103e085681..33e96ae4b15f 100644
> --- a/arch/arm64/kernel/stacktrace.c
> +++ b/arch/arm64/kernel/stacktrace.c
> @@ -110,8 +110,8 @@ static int notrace unwind_frame(struct task_struct *tsk,
>  	 * Record this frame record's values and location. The prev_fp and
>  	 * prev_type are only meaningful to the next unwind_frame() invocation.
>  	 */
> -	frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp));
> -	frame->pc = READ_ONCE_NOCHECK(*(unsigned long *)(fp + 8));
> +	frame->fp = READ_ONCE(*(unsigned long *)(fp));
> +	frame->pc = READ_ONCE(*(unsigned long *)(fp + 8));
>  	frame->prev_fp = fp;
>  	frame->prev_type = info.type;
>  
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] arm64: kasan: do not instrument stacktrace.c
@ 2022-05-23 11:33   ` Mark Rutland
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Rutland @ 2022-05-23 11:33 UTC (permalink / raw)
  To: andrey.konovalov
  Cc: Andrey Konovalov, Marco Elver, Alexander Potapenko,
	Dmitry Vyukov, Andrey Ryabinin, kasan-dev, Catalin Marinas,
	Vincenzo Frascino, Will Deacon, linux-arm-kernel, linux-kernel,
	Andrey Konovalov

On Sun, May 22, 2022 at 01:50:58AM +0200, andrey.konovalov@linux.dev wrote:
> From: Andrey Konovalov <andreyknvl@google.com>
> 
> Disable KASAN instrumentation of arch/arm64/kernel/stacktrace.c.
> 
> This speeds up Generic KASAN by 5-20%.
> 
> As a side-effect, KASAN is now unable to detect bugs in the stack trace
> collection code. This is taken as an acceptable downside.
> 
> Also replace READ_ONCE_NOCHECK() with READ_ONCE() in stacktrace.c.
> As the file is now not instrumented, there is no need to use the
> NOCHECK version of READ_ONCE().
> 
> Suggested-by: Mark Rutland <mark.rutland@arm.com>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> ---
>  arch/arm64/kernel/Makefile     | 3 +++
>  arch/arm64/kernel/stacktrace.c | 4 ++--
>  2 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
> index fa7981d0d917..da8cf6905c76 100644
> --- a/arch/arm64/kernel/Makefile
> +++ b/arch/arm64/kernel/Makefile
> @@ -14,6 +14,9 @@ CFLAGS_REMOVE_return_address.o = $(CC_FLAGS_FTRACE)
>  CFLAGS_REMOVE_syscall.o	 = -fstack-protector -fstack-protector-strong
>  CFLAGS_syscall.o	+= -fno-stack-protector
>  
> +# Do not instrument to improve performance.
> +KASAN_SANITIZE_stacktrace.o := n

Can we make that a little more descriptive? e.g.

# When KASAN is enabled, a stacktrace is recorded for every alloc/free, which
# can significantly impact performance. Avoid instrumenting the stacktrace code
# to minimize this impact.
KASAN_SANITIZE_stacktrace.o := n

With that:

  Acked-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> +
>  # It's not safe to invoke KCOV when portions of the kernel environment aren't
>  # available or are out-of-sync with HW state. Since `noinstr` doesn't always
>  # inhibit KCOV instrumentation, disable it for the entire compilation unit.
> diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
> index e4103e085681..33e96ae4b15f 100644
> --- a/arch/arm64/kernel/stacktrace.c
> +++ b/arch/arm64/kernel/stacktrace.c
> @@ -110,8 +110,8 @@ static int notrace unwind_frame(struct task_struct *tsk,
>  	 * Record this frame record's values and location. The prev_fp and
>  	 * prev_type are only meaningful to the next unwind_frame() invocation.
>  	 */
> -	frame->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp));
> -	frame->pc = READ_ONCE_NOCHECK(*(unsigned long *)(fp + 8));
> +	frame->fp = READ_ONCE(*(unsigned long *)(fp));
> +	frame->pc = READ_ONCE(*(unsigned long *)(fp + 8));
>  	frame->prev_fp = fp;
>  	frame->prev_type = info.type;
>  
> -- 
> 2.25.1
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] arm64: stacktrace: use non-atomic __set_bit
  2022-05-21 23:50   ` andrey.konovalov
@ 2022-05-23 11:34     ` Mark Rutland
  -1 siblings, 0 replies; 8+ messages in thread
From: Mark Rutland @ 2022-05-23 11:34 UTC (permalink / raw)
  To: andrey.konovalov
  Cc: Andrey Konovalov, Marco Elver, Alexander Potapenko,
	Dmitry Vyukov, Andrey Ryabinin, kasan-dev, Catalin Marinas,
	Vincenzo Frascino, Will Deacon, linux-arm-kernel, linux-kernel,
	Andrey Konovalov

On Sun, May 22, 2022 at 01:50:59AM +0200, andrey.konovalov@linux.dev wrote:
> From: Andrey Konovalov <andreyknvl@google.com>
> 
> Use the non-atomic version of set_bit() in arch/arm64/kernel/stacktrace.c,
> as there is no concurrent accesses to frame->prev_type.
> 
> This speeds up stack trace collection and improves the boot time of
> Generic KASAN by 2-5%.
> 
> Suggested-by: Mark Rutland <mark.rutland@arm.com>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>

Acked-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> ---
>  arch/arm64/kernel/stacktrace.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
> index 33e96ae4b15f..03593d451b0a 100644
> --- a/arch/arm64/kernel/stacktrace.c
> +++ b/arch/arm64/kernel/stacktrace.c
> @@ -103,7 +103,7 @@ static int notrace unwind_frame(struct task_struct *tsk,
>  		if (fp <= frame->prev_fp)
>  			return -EINVAL;
>  	} else {
> -		set_bit(frame->prev_type, frame->stacks_done);
> +		__set_bit(frame->prev_type, frame->stacks_done);
>  	}
>  
>  	/*
> -- 
> 2.25.1
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] arm64: stacktrace: use non-atomic __set_bit
@ 2022-05-23 11:34     ` Mark Rutland
  0 siblings, 0 replies; 8+ messages in thread
From: Mark Rutland @ 2022-05-23 11:34 UTC (permalink / raw)
  To: andrey.konovalov
  Cc: Andrey Konovalov, Marco Elver, Alexander Potapenko,
	Dmitry Vyukov, Andrey Ryabinin, kasan-dev, Catalin Marinas,
	Vincenzo Frascino, Will Deacon, linux-arm-kernel, linux-kernel,
	Andrey Konovalov

On Sun, May 22, 2022 at 01:50:59AM +0200, andrey.konovalov@linux.dev wrote:
> From: Andrey Konovalov <andreyknvl@google.com>
> 
> Use the non-atomic version of set_bit() in arch/arm64/kernel/stacktrace.c,
> as there is no concurrent accesses to frame->prev_type.
> 
> This speeds up stack trace collection and improves the boot time of
> Generic KASAN by 2-5%.
> 
> Suggested-by: Mark Rutland <mark.rutland@arm.com>
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>

Acked-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> ---
>  arch/arm64/kernel/stacktrace.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
> index 33e96ae4b15f..03593d451b0a 100644
> --- a/arch/arm64/kernel/stacktrace.c
> +++ b/arch/arm64/kernel/stacktrace.c
> @@ -103,7 +103,7 @@ static int notrace unwind_frame(struct task_struct *tsk,
>  		if (fp <= frame->prev_fp)
>  			return -EINVAL;
>  	} else {
> -		set_bit(frame->prev_type, frame->stacks_done);
> +		__set_bit(frame->prev_type, frame->stacks_done);
>  	}
>  
>  	/*
> -- 
> 2.25.1
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-05-23 12:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-21 23:50 [PATCH 1/2] arm64: kasan: do not instrument stacktrace.c andrey.konovalov
2022-05-21 23:50 ` andrey.konovalov
2022-05-21 23:50 ` [PATCH 2/2] arm64: stacktrace: use non-atomic __set_bit andrey.konovalov
2022-05-21 23:50   ` andrey.konovalov
2022-05-23 11:34   ` Mark Rutland
2022-05-23 11:34     ` Mark Rutland
2022-05-23 11:33 ` [PATCH 1/2] arm64: kasan: do not instrument stacktrace.c Mark Rutland
2022-05-23 11:33   ` Mark Rutland

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.