diff mbox series

[v5,6/6] kasan: Forbid kunit tests when async mode is enabled

Message ID 20210121163943.9889-7-vincenzo.frascino@arm.com (mailing list archive)
State New, archived
Headers show
Series arm64: ARMv8.5-A: MTE: Add async mode support | expand

Commit Message

Vincenzo Frascino Jan. 21, 2021, 4:39 p.m. UTC
Architectures supported by KASAN_HW_TAGS can provide a sync or async
mode of execution. KASAN KUNIT tests can be executed only when sync
mode is enabled.

Forbid the execution of the KASAN KUNIT tests when async mode is
enabled.

Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
---
 lib/test_kasan.c | 5 +++++
 mm/kasan/kasan.h | 2 ++
 2 files changed, 7 insertions(+)

Comments

Andrey Konovalov Jan. 21, 2021, 5:40 p.m. UTC | #1
On Thu, Jan 21, 2021 at 5:40 PM Vincenzo Frascino
<vincenzo.frascino@arm.com> wrote:
>
> Architectures supported by KASAN_HW_TAGS can provide a sync or async
> mode of execution. KASAN KUNIT tests can be executed only when sync
> mode is enabled.
>
> Forbid the execution of the KASAN KUNIT tests when async mode is
> enabled.
>
> Cc: Dmitry Vyukov <dvyukov@google.com>
> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
> Cc: Alexander Potapenko <glider@google.com>
> Cc: Andrey Konovalov <andreyknvl@google.com>
> Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
> ---
>  lib/test_kasan.c | 5 +++++
>  mm/kasan/kasan.h | 2 ++
>  2 files changed, 7 insertions(+)
>
> diff --git a/lib/test_kasan.c b/lib/test_kasan.c
> index 7285dcf9fcc1..1306f707b4fe 100644
> --- a/lib/test_kasan.c
> +++ b/lib/test_kasan.c
> @@ -52,6 +52,11 @@ static int kasan_test_init(struct kunit *test)
>                 return -1;
>         }
>
> +       if (!hw_is_mode_sync()) {
> +               kunit_err(test, "can't run KASAN tests in async mode");
> +               return -1;
> +       }

I'd rather implement this check at the KASAN level, than in arm64
code. Just the way kasan_stack_collection_enabled() is implemented.

Feel free to drop this change and the previous patch, I'll implement
this myself later.

> +
>         multishot = kasan_save_enable_multi_shot();
>         hw_set_tagging_report_once(false);
>         return 0;
> diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
> index 3923d9744105..3464113042ab 100644
> --- a/mm/kasan/kasan.h
> +++ b/mm/kasan/kasan.h
> @@ -296,6 +296,7 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag)
>
>  #define hw_enable_tagging_sync()               arch_enable_tagging_sync()
>  #define hw_enable_tagging_async()              arch_enable_tagging_async()
> +#define hw_is_mode_sync()                      arch_is_mode_sync()
>  #define hw_init_tags(max_tag)                  arch_init_tags(max_tag)
>  #define hw_set_tagging_report_once(state)      arch_set_tagging_report_once(state)
>  #define hw_get_random_tag()                    arch_get_random_tag()
> @@ -306,6 +307,7 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag)
>
>  #define hw_enable_tagging_sync()
>  #define hw_enable_tagging_async()
> +#define hw_is_mode_sync()
>  #define hw_set_tagging_report_once(state)
>
>  #endif /* CONFIG_KASAN_HW_TAGS */
> --
> 2.30.0
>
kernel test robot Jan. 22, 2021, 4:04 a.m. UTC | #2
Hi Vincenzo,

I love your patch! Yet something to improve:

[auto build test ERROR on next-20210121]
[cannot apply to arm64/for-next/core arm/for-next soc/for-next xlnx/master kvmarm/next linus/master hnaz-linux-mm/master v5.11-rc4 v5.11-rc3 v5.11-rc2 v5.11-rc4]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Vincenzo-Frascino/arm64-ARMv8-5-A-MTE-Add-async-mode-support/20210122-004631
base:    bc085f8fc88fc16796c9f2364e2bfb3fef305cad
config: riscv-randconfig-r003-20210122 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project bd3a387ee76f58caa0d7901f3f84e9bb3d006f27)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install riscv cross compiling tool for clang build
        # apt-get install binutils-riscv64-linux-gnu
        # https://github.com/0day-ci/linux/commit/0ac23ec8a70b5fd68efdec0a6a501bdccddf4d5e
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Vincenzo-Frascino/arm64-ARMv8-5-A-MTE-Add-async-mode-support/20210122-004631
        git checkout 0ac23ec8a70b5fd68efdec0a6a501bdccddf4d5e
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=riscv 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> lib/test_kasan.c:55:24: error: expected expression
           if (!hw_is_mode_sync()) {
                                 ^
   1 error generated.


vim +55 lib/test_kasan.c

    41	
    42	/*
    43	 * Temporarily enable multi-shot mode. Otherwise, KASAN would only report the
    44	 * first detected bug and panic the kernel if panic_on_warn is enabled. For
    45	 * hardware tag-based KASAN also allow tag checking to be reenabled for each
    46	 * test, see the comment for KUNIT_EXPECT_KASAN_FAIL().
    47	 */
    48	static int kasan_test_init(struct kunit *test)
    49	{
    50		if (!kasan_enabled()) {
    51			kunit_err(test, "can't run KASAN tests with KASAN disabled");
    52			return -1;
    53		}
    54	
  > 55		if (!hw_is_mode_sync()) {
    56			kunit_err(test, "can't run KASAN tests in async mode");
    57			return -1;
    58		}
    59	
    60		multishot = kasan_save_enable_multi_shot();
    61		hw_set_tagging_report_once(false);
    62		return 0;
    63	}
    64	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Vincenzo Frascino Jan. 22, 2021, 11:26 a.m. UTC | #3
On 1/21/21 5:40 PM, Andrey Konovalov wrote:
>> diff --git a/lib/test_kasan.c b/lib/test_kasan.c
>> index 7285dcf9fcc1..1306f707b4fe 100644
>> --- a/lib/test_kasan.c
>> +++ b/lib/test_kasan.c
>> @@ -52,6 +52,11 @@ static int kasan_test_init(struct kunit *test)
>>                 return -1;
>>         }
>>
>> +       if (!hw_is_mode_sync()) {
>> +               kunit_err(test, "can't run KASAN tests in async mode");
>> +               return -1;
>> +       }
> I'd rather implement this check at the KASAN level, than in arm64
> code. Just the way kasan_stack_collection_enabled() is implemented.
> 
> Feel free to drop this change and the previous patch, I'll implement
> this myself later.
> 

Fine by me, will drop 5 and 6 in v5.
Catalin Marinas Jan. 22, 2021, noon UTC | #4
On Thu, Jan 21, 2021 at 06:40:35PM +0100, Andrey Konovalov wrote:
> On Thu, Jan 21, 2021 at 5:40 PM Vincenzo Frascino
> <vincenzo.frascino@arm.com> wrote:
> >
> > Architectures supported by KASAN_HW_TAGS can provide a sync or async
> > mode of execution. KASAN KUNIT tests can be executed only when sync
> > mode is enabled.
> >
> > Forbid the execution of the KASAN KUNIT tests when async mode is
> > enabled.
> >
> > Cc: Dmitry Vyukov <dvyukov@google.com>
> > Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
> > Cc: Alexander Potapenko <glider@google.com>
> > Cc: Andrey Konovalov <andreyknvl@google.com>
> > Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
> > ---
> >  lib/test_kasan.c | 5 +++++
> >  mm/kasan/kasan.h | 2 ++
> >  2 files changed, 7 insertions(+)
> >
> > diff --git a/lib/test_kasan.c b/lib/test_kasan.c
> > index 7285dcf9fcc1..1306f707b4fe 100644
> > --- a/lib/test_kasan.c
> > +++ b/lib/test_kasan.c
> > @@ -52,6 +52,11 @@ static int kasan_test_init(struct kunit *test)
> >                 return -1;
> >         }
> >
> > +       if (!hw_is_mode_sync()) {
> > +               kunit_err(test, "can't run KASAN tests in async mode");
> > +               return -1;
> > +       }
> 
> I'd rather implement this check at the KASAN level, than in arm64
> code. Just the way kasan_stack_collection_enabled() is implemented.
> 
> Feel free to drop this change and the previous patch, I'll implement
> this myself later.

I agree, it makes sense.
diff mbox series

Patch

diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index 7285dcf9fcc1..1306f707b4fe 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -52,6 +52,11 @@  static int kasan_test_init(struct kunit *test)
 		return -1;
 	}
 
+	if (!hw_is_mode_sync()) {
+		kunit_err(test, "can't run KASAN tests in async mode");
+		return -1;
+	}
+
 	multishot = kasan_save_enable_multi_shot();
 	hw_set_tagging_report_once(false);
 	return 0;
diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h
index 3923d9744105..3464113042ab 100644
--- a/mm/kasan/kasan.h
+++ b/mm/kasan/kasan.h
@@ -296,6 +296,7 @@  static inline const void *arch_kasan_set_tag(const void *addr, u8 tag)
 
 #define hw_enable_tagging_sync()		arch_enable_tagging_sync()
 #define hw_enable_tagging_async()		arch_enable_tagging_async()
+#define hw_is_mode_sync()			arch_is_mode_sync()
 #define hw_init_tags(max_tag)			arch_init_tags(max_tag)
 #define hw_set_tagging_report_once(state)	arch_set_tagging_report_once(state)
 #define hw_get_random_tag()			arch_get_random_tag()
@@ -306,6 +307,7 @@  static inline const void *arch_kasan_set_tag(const void *addr, u8 tag)
 
 #define hw_enable_tagging_sync()
 #define hw_enable_tagging_async()
+#define hw_is_mode_sync()
 #define hw_set_tagging_report_once(state)
 
 #endif /* CONFIG_KASAN_HW_TAGS */