2022-03-24 14:29:29

by andrey.konovalov

[permalink] [raw]
Subject: [PATCH v2 4/4] kasan: use stack_trace_save_shadow

From: Andrey Konovalov <[email protected]>

Now that stack_trace_save_shadow() is implemented by arm64, use it
whenever CONFIG_HAVE_SHADOW_STACKTRACE is enabled. This improves the
boot time of a defconfig build by ~30% for all KASAN modes.

Signed-off-by: Andrey Konovalov <[email protected]>
---
mm/kasan/common.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/mm/kasan/common.c b/mm/kasan/common.c
index d9079ec11f31..8d9d35c6562b 100644
--- a/mm/kasan/common.c
+++ b/mm/kasan/common.c
@@ -33,10 +33,13 @@
depot_stack_handle_t kasan_save_stack(gfp_t flags, bool can_alloc)
{
unsigned long entries[KASAN_STACK_DEPTH];
- unsigned int nr_entries;
+ unsigned int size;

- nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0);
- return __stack_depot_save(entries, nr_entries, flags, can_alloc);
+ if (IS_ENABLED(CONFIG_HAVE_SHADOW_STACKTRACE))
+ size = stack_trace_save_shadow(entries, ARRAY_SIZE(entries), 0);
+ else
+ size = stack_trace_save(entries, ARRAY_SIZE(entries), 0);
+ return __stack_depot_save(entries, size, flags, can_alloc);
}

void kasan_set_track(struct kasan_track *track, gfp_t flags)
--
2.25.1


2022-03-28 21:12:35

by Marco Elver

[permalink] [raw]
Subject: Re: [PATCH v2 4/4] kasan: use stack_trace_save_shadow

On Wed, 23 Mar 2022 at 16:33, <[email protected]> wrote:
>
> From: Andrey Konovalov <[email protected]>
>
> Now that stack_trace_save_shadow() is implemented by arm64, use it
> whenever CONFIG_HAVE_SHADOW_STACKTRACE is enabled. This improves the
> boot time of a defconfig build by ~30% for all KASAN modes.
>
> Signed-off-by: Andrey Konovalov <[email protected]>
> ---
> mm/kasan/common.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/mm/kasan/common.c b/mm/kasan/common.c
> index d9079ec11f31..8d9d35c6562b 100644
> --- a/mm/kasan/common.c
> +++ b/mm/kasan/common.c
> @@ -33,10 +33,13 @@
> depot_stack_handle_t kasan_save_stack(gfp_t flags, bool can_alloc)
> {
> unsigned long entries[KASAN_STACK_DEPTH];
> - unsigned int nr_entries;
> + unsigned int size;

Why did this variable name change?

> - nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0);
> - return __stack_depot_save(entries, nr_entries, flags, can_alloc);
> + if (IS_ENABLED(CONFIG_HAVE_SHADOW_STACKTRACE))

Would it be more reliable to check the return-code? I.e. do:

int size;

size = stack_trace_save_shadow(...)
if (size < 0)
size = stack_trace_save(...);

> + size = stack_trace_save_shadow(entries, ARRAY_SIZE(entries), 0);
> + else
> + size = stack_trace_save(entries, ARRAY_SIZE(entries), 0);
> + return __stack_depot_save(entries, size, flags, can_alloc);
> }
>
> void kasan_set_track(struct kasan_track *track, gfp_t flags)
> --
> 2.25.1

2022-03-31 03:11:43

by Andrey Konovalov

[permalink] [raw]
Subject: Re: [PATCH v2 4/4] kasan: use stack_trace_save_shadow

On Mon, Mar 28, 2022 at 2:49 PM Marco Elver <[email protected]> wrote:
>
> > diff --git a/mm/kasan/common.c b/mm/kasan/common.c
> > index d9079ec11f31..8d9d35c6562b 100644
> > --- a/mm/kasan/common.c
> > +++ b/mm/kasan/common.c
> > @@ -33,10 +33,13 @@
> > depot_stack_handle_t kasan_save_stack(gfp_t flags, bool can_alloc)
> > {
> > unsigned long entries[KASAN_STACK_DEPTH];
> > - unsigned int nr_entries;
> > + unsigned int size;
>
> Why did this variable name change?

So the lines below fit within one line. It won't be needed with the
other change you suggested.

> > - nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0);
> > - return __stack_depot_save(entries, nr_entries, flags, can_alloc);
> > + if (IS_ENABLED(CONFIG_HAVE_SHADOW_STACKTRACE))
>
> Would it be more reliable to check the return-code? I.e. do:
>
> int size;
>
> size = stack_trace_save_shadow(...)
> if (size < 0)
> size = stack_trace_save(...);

Sounds good, will do in v3.

Thanks!