Re: [PATCH v4 1/8] KVM: s390: pv: Use VM_SPARSE area for guest variable storage area

From: Heiko Carstens

Date: Thu Sep 03 2026 - 13:56:01 EST


On Thu, Sep 03, 2026 at 02:28:35PM +0200, Alexander Gordeev wrote:
> On Mon, Jul 20, 2026 at 10:58:27AM +0200, Heiko Carstens wrote:
> ...
> > This assumes that s390 will gain full support for lazy_mmu_mode_enable()
> > and lazy_mmu_mode_disable() in the future, since as of now the used
> > ptep_get_and_clear() in vunmap_pte_range() does indeed invalidate and
> > flush every single pte entry, but only for s390.
> ...
> > +static int uv_alloc_range_cb(pte_t *ptep, unsigned long addr, void *data)
> > +{
> > + struct page *page;
> > + pte_t pte;
> > +
> > + page = alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO);
>
> In lazy mode this callback is called with preemption disabled, so it leads to:
>
> [ 138.709287] BUG: sleeping function called from invalid context at ./include/linux/sched/mm.h:322
> [ 138.709535] in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 6092, name: qemu-kvm

...

Any chance you missed to provide an important detail: this can only
happen with your not-yet upstream series, but as of now there is no
upstream problem?

Is this correct?

> This could be solved using the below fixup:
>
> @@ -247,7 +247,9 @@ static int uv_alloc_range_cb(pte_t *ptep, unsigned long addr, void *data)
> struct page *page;
> pte_t pte;
>
> + lazy_mmu_mode_pause();
> page = alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO);
> + lazy_mmu_mode_resume();
> if (!page)
> return -ENOMEM;
> pte = __pte(page_to_phys(page) | pgprot_val(PAGE_KERNEL));
>
> The downside is lazy_mmu_mode_resume() does not really re-enable
> the caching and the performance will stay the same even when the
> lazy mode is supported on s390.
>
> This is the same pattern as kasan_populate_vmalloc_pte() - which
> was the only occurrence so far.
>
> Alternatively, the page could be allocated atomically, but I think
> that is less preferrable.

I guess the real fix is to pre-allocate all pages, keep the pointers
to the struct pages in an array, and populate with a different
mechanism. Similar like the vmalloc code is doing.
I wanted to keep this code as simple as possible, but...

> > + if (apply_to_page_range(&init_mm, addr, size, uv_alloc_range_cb, NULL))
>
> lazy_mmu_mode_enable_with_ptes() called from apply_to_pte_range()
> disables preemption.

There is no lazy_mmu_mode_enable_with_ptes() upstream, nor does s390
select ARCH_HAS_LAZY_MMU_MODE until now. Therefore my question above.

I guess my assumption above is correct and there is real urgency to
fix this.