2022-11-02 11:54:26

by Alexander Potapenko

[permalink] [raw]
Subject: [PATCH 1/5] kmsan: core: kmsan_in_runtime() should return true in NMI context

Without that, every call to __msan_poison_alloca() in NMI may end up
allocating memory, which is NMI-unsafe.

Cc: Andrew Morton <[email protected]>
Cc: Dmitry Vyukov <[email protected]>
Cc: Marco Elver <[email protected]>
Cc: Peter Zijlstra (Intel) <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]/
Signed-off-by: Alexander Potapenko <[email protected]>
---
mm/kmsan/kmsan.h | 2 ++
1 file changed, 2 insertions(+)

diff --git a/mm/kmsan/kmsan.h b/mm/kmsan/kmsan.h
index 961eb658020aa..3cd2050a33e6a 100644
--- a/mm/kmsan/kmsan.h
+++ b/mm/kmsan/kmsan.h
@@ -125,6 +125,8 @@ static __always_inline bool kmsan_in_runtime(void)
{
if ((hardirq_count() >> HARDIRQ_SHIFT) > 1)
return true;
+ if (in_nmi())
+ return true;
return kmsan_get_context()->kmsan_in_runtime;
}

--
2.38.1.273.g43a17bfeac-goog



2022-11-02 13:07:53

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH 1/5] kmsan: core: kmsan_in_runtime() should return true in NMI context

On Wed, Nov 02, 2022 at 12:06:07PM +0100, Alexander Potapenko wrote:
> Without that, every call to __msan_poison_alloca() in NMI may end up
> allocating memory, which is NMI-unsafe.
>
> Cc: Andrew Morton <[email protected]>
> Cc: Dmitry Vyukov <[email protected]>
> Cc: Marco Elver <[email protected]>
> Cc: Peter Zijlstra (Intel) <[email protected]>
> Link: https://lore.kernel.org/lkml/[email protected]/
> Signed-off-by: Alexander Potapenko <[email protected]>

Acked-by: Peter Zijlstra (Intel) <[email protected]>

> ---
> mm/kmsan/kmsan.h | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/mm/kmsan/kmsan.h b/mm/kmsan/kmsan.h
> index 961eb658020aa..3cd2050a33e6a 100644
> --- a/mm/kmsan/kmsan.h
> +++ b/mm/kmsan/kmsan.h
> @@ -125,6 +125,8 @@ static __always_inline bool kmsan_in_runtime(void)
> {
> if ((hardirq_count() >> HARDIRQ_SHIFT) > 1)
> return true;
> + if (in_nmi())
> + return true;
> return kmsan_get_context()->kmsan_in_runtime;
> }
>
> --
> 2.38.1.273.g43a17bfeac-goog
>