linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH mm] kasan: export HW_TAGS symbols for KUnit tests
@ 2021-02-12 20:08 Andrey Konovalov
  2021-02-12 20:16 ` Andrew Morton
  0 siblings, 1 reply; 7+ messages in thread
From: Andrey Konovalov @ 2021-02-12 20:08 UTC (permalink / raw)
  To: Andrew Morton, Catalin Marinas, Vincenzo Frascino
  Cc: Will Deacon, Dmitry Vyukov, Andrey Ryabinin, Alexander Potapenko,
	Marco Elver, Peter Collingbourne, Evgenii Stepanov,
	Branislav Rankov, Kevin Brodsky, Christoph Hellwig, kasan-dev,
	linux-arm-kernel, linux-mm, linux-kernel, Andrey Konovalov

Currently, building KASAN-KUnit tests as a module fails with:

ERROR: modpost: "mte_enable_kernel" [lib/test_kasan.ko] undefined!
ERROR: modpost: "mte_set_report_once" [lib/test_kasan.ko] undefined!

This change adds KASAN wrappers for mte_enable_kernel() and
mte_set_report_once() and only defines and exports them when KASAN-KUnit
tests are enabled.

The wrappers aren't defined when tests aren't enabled to avoid misuse.
The mte_() functions aren't exported directly to avoid having low-level
KASAN ifdefs in the arch code.

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>

---

Changes v1->v2:
- Add wrappers instead of exporting MTE symbols directly.
- Only define and export wrappers when KASAN-KUnit tests are enabled.

---
 lib/test_kasan.c   |  6 +++---
 mm/kasan/hw_tags.c | 16 ++++++++++++++++
 mm/kasan/kasan.h   | 12 ++++++++++++
 3 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index 1328c468fdb5..e5647d147b35 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -53,13 +53,13 @@ static int kasan_test_init(struct kunit *test)
 	}
 
 	multishot = kasan_save_enable_multi_shot();
-	hw_set_tagging_report_once(false);
+	kasan_set_tagging_report_once(false);
 	return 0;
 }
 
 static void kasan_test_exit(struct kunit *test)
 {
-	hw_set_tagging_report_once(true);
+	kasan_set_tagging_report_once(true);
 	kasan_restore_multi_shot(multishot);
 }
 
@@ -97,7 +97,7 @@ static void kasan_test_exit(struct kunit *test)
 			READ_ONCE(fail_data.report_found));	\
 	if (IS_ENABLED(CONFIG_KASAN_HW_TAGS)) {			\
 		if (READ_ONCE(fail_data.report_found))		\
-			hw_enable_tagging();			\
+			kasan_enable_tagging();			\
 		migrate_enable();				\
 	}							\
 } while (0)
diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c
index 1dfe4f62a89e..2aad21fda156 100644
--- a/mm/kasan/hw_tags.c
+++ b/mm/kasan/hw_tags.c
@@ -185,3 +185,19 @@ struct kasan_track *kasan_get_free_track(struct kmem_cache *cache,
 
 	return &alloc_meta->free_track[0];
 }
+
+#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST)
+
+void kasan_set_tagging_report_once(bool state)
+{
+	hw_set_tagging_report_once(state);
+}
+EXPORT_SYMBOL_GPL(kasan_set_tagging_report_once);
+
+void kasan_enable_tagging(void)
+{
+	hw_enable_tagging();
+}
+EXPORT_SYMBOL_GPL(kasan_enable_tagging);
+
+#endif
diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
index cc787ba47e1b..3436c6bf7c0c 100644
--- a/mm/kasan/kasan.h
+++ b/mm/kasan/kasan.h
@@ -308,6 +308,18 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag)
 
 #endif /* CONFIG_KASAN_HW_TAGS */
 
+#if defined(CONFIG_KASAN_HW_TAGS) && IS_ENABLED(CONFIG_KASAN_KUNIT_TEST)
+
+void kasan_set_tagging_report_once(bool state);
+void kasan_enable_tagging(void);
+
+#else /* CONFIG_KASAN_HW_TAGS || CONFIG_KASAN_KUNIT_TEST */
+
+static inline void kasan_set_tagging_report_once(bool state) { }
+static inline void kasan_enable_tagging(void) { }
+
+#endif /* CONFIG_KASAN_HW_TAGS || CONFIG_KASAN_KUNIT_TEST */
+
 #ifdef CONFIG_KASAN_SW_TAGS
 u8 kasan_random_tag(void);
 #elif defined(CONFIG_KASAN_HW_TAGS)
-- 
2.30.0.478.g8a0d178c01-goog



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

* Re: [PATCH mm] kasan: export HW_TAGS symbols for KUnit tests
  2021-02-12 20:08 [PATCH mm] kasan: export HW_TAGS symbols for KUnit tests Andrey Konovalov
@ 2021-02-12 20:16 ` Andrew Morton
  2021-02-12 20:21   ` Andrey Konovalov
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2021-02-12 20:16 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: Catalin Marinas, Vincenzo Frascino, Will Deacon, Dmitry Vyukov,
	Andrey Ryabinin, Alexander Potapenko, Marco Elver,
	Peter Collingbourne, Evgenii Stepanov, Branislav Rankov,
	Kevin Brodsky, Christoph Hellwig, kasan-dev, linux-arm-kernel,
	linux-mm, linux-kernel

On Fri, 12 Feb 2021 21:08:52 +0100 Andrey Konovalov <andreyknvl@google.com> wrote:

> Currently, building KASAN-KUnit tests as a module fails with:
> 
> ERROR: modpost: "mte_enable_kernel" [lib/test_kasan.ko] undefined!
> ERROR: modpost: "mte_set_report_once" [lib/test_kasan.ko] undefined!
> 
> This change adds KASAN wrappers for mte_enable_kernel() and
> mte_set_report_once() and only defines and exports them when KASAN-KUnit
> tests are enabled.
> 
> The wrappers aren't defined when tests aren't enabled to avoid misuse.
> The mte_() functions aren't exported directly to avoid having low-level
> KASAN ifdefs in the arch code.
> 

Please confirm that this is applicable to current Linus mainline?

Today is pretty much the last day for getting material into 5.11, and
this patch has been churning somewhat.

So I think it would be better to merge this into 5.12-rc1, with a
cc:stable so it goes into 5.11.1.

For which we'll need a Fixes:, please?


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

* Re: [PATCH mm] kasan: export HW_TAGS symbols for KUnit tests
  2021-02-12 20:16 ` Andrew Morton
@ 2021-02-12 20:21   ` Andrey Konovalov
  2021-02-12 20:54     ` Andrew Morton
  0 siblings, 1 reply; 7+ messages in thread
From: Andrey Konovalov @ 2021-02-12 20:21 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Catalin Marinas, Vincenzo Frascino, Will Deacon, Dmitry Vyukov,
	Andrey Ryabinin, Alexander Potapenko, Marco Elver,
	Peter Collingbourne, Evgenii Stepanov, Branislav Rankov,
	Kevin Brodsky, Christoph Hellwig, kasan-dev, Linux ARM,
	Linux Memory Management List, LKML

On Fri, Feb 12, 2021 at 9:16 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Fri, 12 Feb 2021 21:08:52 +0100 Andrey Konovalov <andreyknvl@google.com> wrote:
>
> > Currently, building KASAN-KUnit tests as a module fails with:
> >
> > ERROR: modpost: "mte_enable_kernel" [lib/test_kasan.ko] undefined!
> > ERROR: modpost: "mte_set_report_once" [lib/test_kasan.ko] undefined!
> >
> > This change adds KASAN wrappers for mte_enable_kernel() and
> > mte_set_report_once() and only defines and exports them when KASAN-KUnit
> > tests are enabled.
> >
> > The wrappers aren't defined when tests aren't enabled to avoid misuse.
> > The mte_() functions aren't exported directly to avoid having low-level
> > KASAN ifdefs in the arch code.
> >
>
> Please confirm that this is applicable to current Linus mainline?

It's not applicable. KUnit tests for HW_TAGS aren't supported there,
the patches for that are in mm only. So no need to put it into 5.11.

> Today is pretty much the last day for getting material into 5.11, and
> this patch has been churning somewhat.
>
> So I think it would be better to merge this into 5.12-rc1, with a
> cc:stable so it goes into 5.11.1.
>
> For which we'll need a Fixes:, please?
>
> --
> You received this message because you are subscribed to the Google Groups "kasan-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20210212121610.ff05a7bb37f97caef97dc924%40linux-foundation.org.


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

* Re: [PATCH mm] kasan: export HW_TAGS symbols for KUnit tests
  2021-02-12 20:21   ` Andrey Konovalov
@ 2021-02-12 20:54     ` Andrew Morton
  2021-02-12 21:01       ` Andrey Konovalov
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2021-02-12 20:54 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: Catalin Marinas, Vincenzo Frascino, Will Deacon, Dmitry Vyukov,
	Andrey Ryabinin, Alexander Potapenko, Marco Elver,
	Peter Collingbourne, Evgenii Stepanov, Branislav Rankov,
	Kevin Brodsky, Christoph Hellwig, kasan-dev, Linux ARM,
	Linux Memory Management List, LKML

On Fri, 12 Feb 2021 21:21:39 +0100 Andrey Konovalov <andreyknvl@google.com> wrote:

> > > The wrappers aren't defined when tests aren't enabled to avoid misuse.
> > > The mte_() functions aren't exported directly to avoid having low-level
> > > KASAN ifdefs in the arch code.
> > >
> >
> > Please confirm that this is applicable to current Linus mainline?
> 
> It's not applicable. KUnit tests for HW_TAGS aren't supported there,
> the patches for that are in mm only. So no need to put it into 5.11.

So... which -mm patch does this patch fix?


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

* Re: [PATCH mm] kasan: export HW_TAGS symbols for KUnit tests
  2021-02-12 20:54     ` Andrew Morton
@ 2021-02-12 21:01       ` Andrey Konovalov
  2021-02-12 21:08         ` Andrew Morton
  0 siblings, 1 reply; 7+ messages in thread
From: Andrey Konovalov @ 2021-02-12 21:01 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Catalin Marinas, Vincenzo Frascino, Will Deacon, Dmitry Vyukov,
	Andrey Ryabinin, Alexander Potapenko, Marco Elver,
	Peter Collingbourne, Evgenii Stepanov, Branislav Rankov,
	Kevin Brodsky, Christoph Hellwig, kasan-dev, Linux ARM,
	Linux Memory Management List, LKML

On Fri, Feb 12, 2021 at 9:54 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Fri, 12 Feb 2021 21:21:39 +0100 Andrey Konovalov <andreyknvl@google.com> wrote:
>
> > > > The wrappers aren't defined when tests aren't enabled to avoid misuse.
> > > > The mte_() functions aren't exported directly to avoid having low-level
> > > > KASAN ifdefs in the arch code.
> > > >
> > >
> > > Please confirm that this is applicable to current Linus mainline?
> >
> > It's not applicable. KUnit tests for HW_TAGS aren't supported there,
> > the patches for that are in mm only. So no need to put it into 5.11.
>
> So... which -mm patch does this patch fix?

"kasan, arm64: allow using KUnit tests with HW_TAGS mode".

There will be some minor adjacent-line-changed conflicts if you decide
to squash it.

Alternatively, this can go as a separate patch after the tests series
(after "kasan: don't run tests when KASAN is not enabled").

Thanks!


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

* Re: [PATCH mm] kasan: export HW_TAGS symbols for KUnit tests
  2021-02-12 21:01       ` Andrey Konovalov
@ 2021-02-12 21:08         ` Andrew Morton
  2021-02-12 21:10           ` Andrey Konovalov
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2021-02-12 21:08 UTC (permalink / raw)
  To: Andrey Konovalov
  Cc: Catalin Marinas, Vincenzo Frascino, Will Deacon, Dmitry Vyukov,
	Andrey Ryabinin, Alexander Potapenko, Marco Elver,
	Peter Collingbourne, Evgenii Stepanov, Branislav Rankov,
	Kevin Brodsky, Christoph Hellwig, kasan-dev, Linux ARM,
	Linux Memory Management List, LKML

On Fri, 12 Feb 2021 22:01:38 +0100 Andrey Konovalov <andreyknvl@google.com> wrote:

> On Fri, Feb 12, 2021 at 9:54 PM Andrew Morton <akpm@linux-foundation.org> wrote:
> >
> > On Fri, 12 Feb 2021 21:21:39 +0100 Andrey Konovalov <andreyknvl@google.com> wrote:
> >
> > > > > The wrappers aren't defined when tests aren't enabled to avoid misuse.
> > > > > The mte_() functions aren't exported directly to avoid having low-level
> > > > > KASAN ifdefs in the arch code.
> > > > >
> > > >
> > > > Please confirm that this is applicable to current Linus mainline?
> > >
> > > It's not applicable. KUnit tests for HW_TAGS aren't supported there,
> > > the patches for that are in mm only. So no need to put it into 5.11.
> >
> > So... which -mm patch does this patch fix?
> 
> "kasan, arm64: allow using KUnit tests with HW_TAGS mode".
> 
> There will be some minor adjacent-line-changed conflicts if you decide
> to squash it.
> 
> Alternatively, this can go as a separate patch after the tests series
> (after "kasan: don't run tests when KASAN is not enabled").

Thanks - it wasn't obvious.

I staged it as a fix against "kasan, arm64: allow using KUnit tests
with HW_TAGS mode".  To make the series as nice as we can, and to avoid
bisection holes.



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

* Re: [PATCH mm] kasan: export HW_TAGS symbols for KUnit tests
  2021-02-12 21:08         ` Andrew Morton
@ 2021-02-12 21:10           ` Andrey Konovalov
  0 siblings, 0 replies; 7+ messages in thread
From: Andrey Konovalov @ 2021-02-12 21:10 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Catalin Marinas, Vincenzo Frascino, Will Deacon, Dmitry Vyukov,
	Andrey Ryabinin, Alexander Potapenko, Marco Elver,
	Peter Collingbourne, Evgenii Stepanov, Branislav Rankov,
	Kevin Brodsky, Christoph Hellwig, kasan-dev, Linux ARM,
	Linux Memory Management List, LKML

On Fri, Feb 12, 2021 at 10:08 PM Andrew Morton
<akpm@linux-foundation.org> wrote:
>
> On Fri, 12 Feb 2021 22:01:38 +0100 Andrey Konovalov <andreyknvl@google.com> wrote:
>
> > On Fri, Feb 12, 2021 at 9:54 PM Andrew Morton <akpm@linux-foundation.org> wrote:
> > >
> > > On Fri, 12 Feb 2021 21:21:39 +0100 Andrey Konovalov <andreyknvl@google.com> wrote:
> > >
> > > > > > The wrappers aren't defined when tests aren't enabled to avoid misuse.
> > > > > > The mte_() functions aren't exported directly to avoid having low-level
> > > > > > KASAN ifdefs in the arch code.
> > > > > >
> > > > >
> > > > > Please confirm that this is applicable to current Linus mainline?
> > > >
> > > > It's not applicable. KUnit tests for HW_TAGS aren't supported there,
> > > > the patches for that are in mm only. So no need to put it into 5.11.
> > >
> > > So... which -mm patch does this patch fix?
> >
> > "kasan, arm64: allow using KUnit tests with HW_TAGS mode".
> >
> > There will be some minor adjacent-line-changed conflicts if you decide
> > to squash it.
> >
> > Alternatively, this can go as a separate patch after the tests series
> > (after "kasan: don't run tests when KASAN is not enabled").
>
> Thanks - it wasn't obvious.
>
> I staged it as a fix against "kasan, arm64: allow using KUnit tests
> with HW_TAGS mode".  To make the series as nice as we can, and to avoid
> bisection holes.

Sounds good, thank you!


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

end of thread, other threads:[~2021-02-12 21:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-12 20:08 [PATCH mm] kasan: export HW_TAGS symbols for KUnit tests Andrey Konovalov
2021-02-12 20:16 ` Andrew Morton
2021-02-12 20:21   ` Andrey Konovalov
2021-02-12 20:54     ` Andrew Morton
2021-02-12 21:01       ` Andrey Konovalov
2021-02-12 21:08         ` Andrew Morton
2021-02-12 21:10           ` Andrey Konovalov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).