* [PATCH v4 1/9] mm/kmsan: undo the shadow mapping when the origin mapping fails
[not found] <20261110112546.261415-1-hao.ge@linux.dev>
@ 2026-11-10 11:25 ` Hao Ge
2026-11-11 21:03 ` Suren Baghdasaryan
0 siblings, 1 reply; 4+ messages in thread
From: Hao Ge @ 2026-11-10 11:25 UTC (permalink / raw)
To: Uladzislau Rezki, Dev Jain, Suren Baghdasaryan, Andrew Morton,
Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy (CS GROUP), Ritesh Harjani (IBM),
Shrikanth Hegde, Alexander Potapenko, Marco Elver, Dmitry Vyukov,
Dennis Zhou, Tejun Heo, Christoph Lameter
Cc: linuxppc-dev, linux-kernel, kasan-dev, linux-mm, Hao Ge, stable
kmsan_vmap_pages_range_noflush() first maps the shadow pages and then
the origin pages. If the second mapping fails, the first one is left
mapped, and the callers do not roll it back. The next vmap of the
same metadata range hits the stale PTEs again and fails with a
WARN_ON() and -EBUSY in vmap_pages_pte_range().
Undo the shadow mapping on that error path, the same way
kmsan_ioremap_page_range() cleans up after a partial failure.
__vunmap_range_noflush() only clears the PTEs; nothing has touched
the shadow mapping, so no TLB flush is needed.
Fixes: 47ebd0310e89 ("mm: kmsan: handle alloc failures in kmsan_vmap_pages_range_noflush()")
Cc: stable@vger.kernel.org
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Reviewed-by: Dev Jain <dev.jain@arm.com>
Signed-off-by: Hao Ge <hao.ge@linux.dev>
---
mm/kmsan/shadow.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/mm/kmsan/shadow.c b/mm/kmsan/shadow.c
index 0c88d89bf0d6..2166086d3dc3 100644
--- a/mm/kmsan/shadow.c
+++ b/mm/kmsan/shadow.c
@@ -258,6 +258,10 @@ int kmsan_vmap_pages_range_noflush(unsigned long start, unsigned long end,
o_pages, page_shift);
kmsan_leave_runtime();
if (mapped) {
+ /* Undo the shadow mapping set up above. */
+ kmsan_enter_runtime();
+ __vunmap_range_noflush(shadow_start, shadow_end);
+ kmsan_leave_runtime();
err = mapped;
goto ret;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v4 1/9] mm/kmsan: undo the shadow mapping when the origin mapping fails
2026-11-10 11:25 ` [PATCH v4 1/9] mm/kmsan: undo the shadow mapping when the origin mapping fails Hao Ge
@ 2026-11-11 21:03 ` Suren Baghdasaryan
2026-11-12 7:50 ` Hao Ge
0 siblings, 1 reply; 4+ messages in thread
From: Suren Baghdasaryan @ 2026-11-11 21:03 UTC (permalink / raw)
To: Hao Ge
Cc: Uladzislau Rezki, Dev Jain, Andrew Morton, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter, linuxppc-dev, linux-kernel, kasan-dev,
linux-mm, stable
On Tue, Nov 10, 2026 at 11:24 AM Hao Ge <hao.ge@linux.dev> wrote:
>
> kmsan_vmap_pages_range_noflush() first maps the shadow pages and then
> the origin pages. If the second mapping fails, the first one is left
> mapped, and the callers do not roll it back. The next vmap of the
> same metadata range hits the stale PTEs again and fails with a
> WARN_ON() and -EBUSY in vmap_pages_pte_range().
>
> Undo the shadow mapping on that error path, the same way
> kmsan_ioremap_page_range() cleans up after a partial failure.
> __vunmap_range_noflush() only clears the PTEs; nothing has touched
> the shadow mapping, so no TLB flush is needed.
>
> Fixes: 47ebd0310e89 ("mm: kmsan: handle alloc failures in kmsan_vmap_pages_range_noflush()")
> Cc: stable@vger.kernel.org
> Reviewed-by: Suren Baghdasaryan <surenb@google.com>
> Reviewed-by: Dev Jain <dev.jain@arm.com>
> Signed-off-by: Hao Ge <hao.ge@linux.dev>
> ---
> mm/kmsan/shadow.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/mm/kmsan/shadow.c b/mm/kmsan/shadow.c
> index 0c88d89bf0d6..2166086d3dc3 100644
> --- a/mm/kmsan/shadow.c
> +++ b/mm/kmsan/shadow.c
> @@ -258,6 +258,10 @@ int kmsan_vmap_pages_range_noflush(unsigned long start, unsigned long end,
> o_pages, page_shift);
> kmsan_leave_runtime();
> if (mapped) {
> + /* Undo the shadow mapping set up above. */
> + kmsan_enter_runtime();
> + __vunmap_range_noflush(shadow_start, shadow_end);
Sorry, there is a problem here. You introduce "can_resched" check to
avoid calling cond_resched() later in the series (in patch #7), but at
this point __vunmap_range_noflush() can be called with GFP flags which
do not allow blocking. Before recent Ulad's change called "kmsan:
remove hard-coded GFP_KERNEL flags" this function was called only with
GPF_KERNEL but now that's not the case. I think you can move
introduction of can_resched flag into this patch.
> + kmsan_leave_runtime();
> err = mapped;
> goto ret;
> }
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v4 1/9] mm/kmsan: undo the shadow mapping when the origin mapping fails
2026-11-11 21:03 ` Suren Baghdasaryan
@ 2026-11-12 7:50 ` Hao Ge
2026-11-12 15:50 ` Suren Baghdasaryan
0 siblings, 1 reply; 4+ messages in thread
From: Hao Ge @ 2026-11-12 7:50 UTC (permalink / raw)
To: Suren Baghdasaryan
Cc: Uladzislau Rezki, Dev Jain, Andrew Morton, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter, linuxppc-dev, linux-kernel, kasan-dev,
linux-mm, stable
Hi Suren
On 2026/11/12 05:03, Suren Baghdasaryan wrote:
> On Tue, Nov 10, 2026 at 11:24 AM Hao Ge <hao.ge@linux.dev> wrote:
>>
>> kmsan_vmap_pages_range_noflush() first maps the shadow pages and then
>> the origin pages. If the second mapping fails, the first one is left
>> mapped, and the callers do not roll it back. The next vmap of the
>> same metadata range hits the stale PTEs again and fails with a
>> WARN_ON() and -EBUSY in vmap_pages_pte_range().
>>
>> Undo the shadow mapping on that error path, the same way
>> kmsan_ioremap_page_range() cleans up after a partial failure.
>> __vunmap_range_noflush() only clears the PTEs; nothing has touched
>> the shadow mapping, so no TLB flush is needed.
>>
>> Fixes: 47ebd0310e89 ("mm: kmsan: handle alloc failures in kmsan_vmap_pages_range_noflush()")
>> Cc: stable@vger.kernel.org
>> Reviewed-by: Suren Baghdasaryan <surenb@google.com>
>> Reviewed-by: Dev Jain <dev.jain@arm.com>
>> Signed-off-by: Hao Ge <hao.ge@linux.dev>
>> ---
>> mm/kmsan/shadow.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> diff --git a/mm/kmsan/shadow.c b/mm/kmsan/shadow.c
>> index 0c88d89bf0d6..2166086d3dc3 100644
>> --- a/mm/kmsan/shadow.c
>> +++ b/mm/kmsan/shadow.c
>> @@ -258,6 +258,10 @@ int kmsan_vmap_pages_range_noflush(unsigned long start, unsigned long end,
>> o_pages, page_shift);
>> kmsan_leave_runtime();
>> if (mapped) {
>> + /* Undo the shadow mapping set up above. */
>> + kmsan_enter_runtime();
>> + __vunmap_range_noflush(shadow_start, shadow_end);
>
> Sorry, there is a problem here. You introduce "can_resched" check to
> avoid calling cond_resched() later in the series (in patch #7), but at
> this point __vunmap_range_noflush() can be called with GFP flags which
> do not allow blocking. Before recent Ulad's change called "kmsan:
> remove hard-coded GFP_KERNEL flags" this function was called only with
> GPF_KERNEL but now that's not the case. I think you can move
> introduction of can_resched flag into this patch.
Agree. I just went back and looked at Ulad's b186a94227b7 ("kmsan:
remove hard-coded GFP_KERNEL flags").
So will do next version. But perhaps it is better to make it a separate
prep patch in the same series? Because besides this call site, the other
places that call __vunmap_range_noflush() need to be changed as well.
Thanks
Best Regards
Hao
>
>> + kmsan_leave_runtime();
>> err = mapped;
>> goto ret;
>> }
>> --
>> 2.25.1
>>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v4 1/9] mm/kmsan: undo the shadow mapping when the origin mapping fails
2026-11-12 7:50 ` Hao Ge
@ 2026-11-12 15:50 ` Suren Baghdasaryan
0 siblings, 0 replies; 4+ messages in thread
From: Suren Baghdasaryan @ 2026-11-12 15:50 UTC (permalink / raw)
To: Hao Ge
Cc: Uladzislau Rezki, Dev Jain, Andrew Morton, Madhavan Srinivasan,
Michael Ellerman, Nicholas Piggin, Christophe Leroy (CS GROUP),
Ritesh Harjani (IBM), Shrikanth Hegde, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Dennis Zhou, Tejun Heo,
Christoph Lameter, linuxppc-dev, linux-kernel, kasan-dev,
linux-mm, stable
On Wed, Nov 11, 2026 at 11:49 PM Hao Ge <hao.ge@linux.dev> wrote:
>
> Hi Suren
>
> On 2026/11/12 05:03, Suren Baghdasaryan wrote:
> > On Tue, Nov 10, 2026 at 11:24 AM Hao Ge <hao.ge@linux.dev> wrote:
> >>
> >> kmsan_vmap_pages_range_noflush() first maps the shadow pages and then
> >> the origin pages. If the second mapping fails, the first one is left
> >> mapped, and the callers do not roll it back. The next vmap of the
> >> same metadata range hits the stale PTEs again and fails with a
> >> WARN_ON() and -EBUSY in vmap_pages_pte_range().
> >>
> >> Undo the shadow mapping on that error path, the same way
> >> kmsan_ioremap_page_range() cleans up after a partial failure.
> >> __vunmap_range_noflush() only clears the PTEs; nothing has touched
> >> the shadow mapping, so no TLB flush is needed.
> >>
> >> Fixes: 47ebd0310e89 ("mm: kmsan: handle alloc failures in kmsan_vmap_pages_range_noflush()")
> >> Cc: stable@vger.kernel.org
> >> Reviewed-by: Suren Baghdasaryan <surenb@google.com>
> >> Reviewed-by: Dev Jain <dev.jain@arm.com>
> >> Signed-off-by: Hao Ge <hao.ge@linux.dev>
> >> ---
> >> mm/kmsan/shadow.c | 4 ++++
> >> 1 file changed, 4 insertions(+)
> >>
> >> diff --git a/mm/kmsan/shadow.c b/mm/kmsan/shadow.c
> >> index 0c88d89bf0d6..2166086d3dc3 100644
> >> --- a/mm/kmsan/shadow.c
> >> +++ b/mm/kmsan/shadow.c
> >> @@ -258,6 +258,10 @@ int kmsan_vmap_pages_range_noflush(unsigned long start, unsigned long end,
> >> o_pages, page_shift);
> >> kmsan_leave_runtime();
> >> if (mapped) {
> >> + /* Undo the shadow mapping set up above. */
> >> + kmsan_enter_runtime();
> >> + __vunmap_range_noflush(shadow_start, shadow_end);
> >
> > Sorry, there is a problem here. You introduce "can_resched" check to
> > avoid calling cond_resched() later in the series (in patch #7), but at
> > this point __vunmap_range_noflush() can be called with GFP flags which
> > do not allow blocking. Before recent Ulad's change called "kmsan:
> > remove hard-coded GFP_KERNEL flags" this function was called only with
> > GPF_KERNEL but now that's not the case. I think you can move
> > introduction of can_resched flag into this patch.
>
> Agree. I just went back and looked at Ulad's b186a94227b7 ("kmsan:
> remove hard-coded GFP_KERNEL flags").
>
> So will do next version. But perhaps it is better to make it a separate
> prep patch in the same series? Because besides this call site, the other
> places that call __vunmap_range_noflush() need to be changed as well.
Agree. Moving that into a separate patch at the beginning of the
series with its own changelog and explanation would be cleaner.
>
> Thanks
> Best Regards
> Hao
>
> >
> >> + kmsan_leave_runtime();
> >> err = mapped;
> >> goto ret;
> >> }
> >> --
> >> 2.25.1
> >>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-12 15:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261110112546.261415-1-hao.ge@linux.dev>
2026-11-10 11:25 ` [PATCH v4 1/9] mm/kmsan: undo the shadow mapping when the origin mapping fails Hao Ge
2026-11-11 21:03 ` Suren Baghdasaryan
2026-11-12 7:50 ` Hao Ge
2026-11-12 15:50 ` Suren Baghdasaryan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox