mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexander Gordeev <agordeev@linux.ibm.com>
To: Heiko Carstens <hca@linux.ibm.com>
Cc: Sven Schnelle <svens@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Janosch Frank <frankja@linux.ibm.com>,
	Claudio Imbrenda <imbrenda@linux.ibm.com>,
	David Hildenbrand <david@kernel.org>,
	linux-s390@vger.kernel.org, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 1/8] KVM: s390: pv: Use VM_SPARSE area for guest variable storage area
Date: Thu, 3 Sep 2026 14:28:35 +0200	[thread overview]
Message-ID: <e9449c63-b8d2-4ed9-a184-7dcab3e8dfce-agordeev@linux.ibm.com> (raw)
In-Reply-To: <20260720085834.898025-2-hca@linux.ibm.com>

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
    [  138.709540] preempt_count: 1, expected: 0
    [  138.709545] RCU nest depth: 0, expected: 0
    [  138.709549] locks held by qemu-kvm/6092: 1, last CPU#1:
    [  138.709554]  #0: 00000162368b8ba8 (&kvm->lock){+.+.}-{3:3}, at: kvm_s390_handle_pv+0x7c/0xf70 [kvm]
    [  138.709612] Preemption disabled at:
    [  138.709614] [<000002690b609a76>] enter_ipte_range.part.0+0x36/0xb0
    [  138.709627] CPU: 1 UID: 107 PID: 6092 Comm: qemu-kvm Not tainted 7.3.0-20260901.rc1.git22.7cbe5e7f09fc.300.mm.fc44.s390x+debug #1 PREEMPT
    [  138.709629] Hardware name: IBM 3931 A01 701 (LPAR)
    [  138.709630] Call Trace:
    [  138.709631]  [<000002690b5d0d4e>] dump_stack_lvl+0xae/0x108
    [  138.709634]  [<000002690b67bbde>] __might_resched+0x1de/0x2f0
    [  138.709637]  [<000002690ba1d23a>] prepare_alloc_pages+0x1ba/0x220
    [  138.709641]  [<000002690ba1f936>] __alloc_frozen_pages_noprof+0xc6/0x390
    [  138.709643]  [<000002690ba6e9d6>] alloc_pages_mpol+0xe6/0x220
    [  138.709647]  [<000002690ba6f1dc>] alloc_frozen_pages_noprof+0x5c/0x80
    [  138.709649]  [<000002690ba6f222>] alloc_pages_noprof+0x22/0x80
    [  138.709652]  [<000002690b5ef6a0>] uv_alloc_range_cb+0x30/0x300
    [  138.709655]  [<000002690b9d22fa>] apply_to_pte_range+0x11a/0x3b0
    [  138.709656]  [<000002690b9dbf5a>] apply_to_pmd_range+0x13a/0x250
    [  138.709658]  [<000002690b9dcef2>] __apply_to_page_range+0x232/0x4d0
    [  138.709660]  [<000002690b9dd1b8>] apply_to_page_range+0x28/0x40
    [  138.709662]  [<000002690b5eebfe>] uv_alloc_stor_var+0x5e/0x90
    [  138.709664]  [<000002688b73ffe8>] kvm_s390_pv_alloc_vm+0x118/0x1e0 [kvm]
    [  138.709685]  [<000002688b741274>] kvm_s390_pv_init_vm+0x84/0x2e0 [kvm]
    [  138.709705]  [<000002688b71cf92>] kvm_s390_handle_pv+0x502/0xf70 [kvm]
    [  138.709726]  [<000002688b71fd44>] kvm_arch_vm_ioctl+0x234/0xdd0 [kvm]
    [  138.709747]  [<000002688b7070fa>] kvm_vm_ioctl+0x33a/0x890 [kvm]
    [  138.709765]  [<000002690bb046ca>] __s390x_sys_ioctl+0xfa/0x130
    [  138.709767]  [<000002690c78cffc>] __do_syscall+0x1fc/0x700
    [  138.709772]  [<000002690c7a21e2>] system_call+0x72/0x90
    [  138.709774] locks held by qemu-kvm/6092: 1, last CPU#1:
    [  138.709775]  #0: 00000162368b8ba8 (&kvm->lock){+.+.}-{3:3}, at: kvm_s390_handle_pv+0x7c/0xf70 [kvm]

This could be solved using the below fixup:

diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c
index 8ea9dd7704ff..9af0358aa7f2 100644
--- a/arch/s390/kernel/uv.c
+++ b/arch/s390/kernel/uv.c
@@ -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.

> +	if (!page)
> +		return -ENOMEM;
> +	pte = __pte(page_to_phys(page) | pgprot_val(PAGE_KERNEL));
> +	set_pte(ptep, pte);
> +	return 0;
> +}
> +
> +void *uv_alloc_stor_var(unsigned long size)
> +{
> +	struct vm_struct *area;
> +	unsigned long addr;
> +
> +	size = PAGE_ALIGN(size);
> +	area = get_vm_area(size, VM_SPARSE);
> +	if (!area)
> +		return NULL;
> +	addr = (unsigned long)area->addr;
> +	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.

> +		goto out;
> +	return area->addr;
> +out:
> +	uv_free_stor_var(area->addr);
> +	return NULL;
> +}
> +EXPORT_SYMBOL_FOR_MODULES(uv_alloc_stor_var, "kvm");

Thanks!

  parent reply	other threads:[~2026-09-03 12:28 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-20  8:58 [PATCH v4 0/8] s390: Reintroduce support for DCACHE_WORD_ACCESS Heiko Carstens
2026-07-20  8:58 ` [PATCH v4 1/8] KVM: s390: pv: Use VM_SPARSE area for guest variable storage area Heiko Carstens
2026-07-20  9:56   ` Christian Borntraeger
2026-07-20 10:15     ` Heiko Carstens
2026-09-03 12:28   ` Alexander Gordeev [this message]
2026-09-03 17:24     ` Heiko Carstens
2026-09-04 18:53       ` Heiko Carstens
2026-07-20  8:58 ` [PATCH v4 2/8] s390/mm: Add missing mm check to do_secure_storage_access() Heiko Carstens
2026-07-20 10:44   ` Christian Borntraeger
2026-07-20  8:58 ` [PATCH v4 3/8] s390/mm: Use lock_mm_and_find_vma() in do_secure_storage_access() Heiko Carstens
2026-07-20 10:45   ` Christian Borntraeger
2026-07-20  8:58 ` [PATCH v4 4/8] s390/mm: Fix handling of vmalloc area " Heiko Carstens
2026-07-20 10:22   ` Christian Borntraeger
2026-07-20  8:58 ` [PATCH v4 5/8] s390/mm: Remove folio handling for kernel faults " Heiko Carstens
2026-07-20 10:53   ` Christian Borntraeger
2026-07-24  8:17     ` Claudio Imbrenda
2026-07-20  8:58 ` [PATCH v4 6/8] s390/mm: Use handle_fault_error() " Heiko Carstens
2026-07-20  8:58 ` [PATCH v4 7/8] s390/mm: Use goto statement " Heiko Carstens
2026-07-20 10:36   ` Christian Borntraeger
2026-07-20  8:58 ` [PATCH v4 8/8] s390: Add support for DCACHE_WORD_ACCESS (again) Heiko Carstens
2026-07-21  9:59   ` Sven Schnelle
2026-07-20  9:03 ` [PATCH v4 0/8] s390: Reintroduce support for DCACHE_WORD_ACCESS Christian Borntraeger
2026-07-20  9:40   ` Heiko Carstens
2026-07-27 10:37 ` Vasily Gorbik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e9449c63-b8d2-4ed9-a184-7dcab3e8dfce-agordeev@linux.ibm.com \
    --to=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=david@kernel.org \
    --cc=frankja@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=imbrenda@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=svens@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®