From: Heiko Carstens <hca@linux.ibm.com>
To: Heiko Carstens <hca@linux.ibm.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>,
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: Fri, 4 Sep 2026 20:53:36 +0200 [thread overview]
Message-ID: <20260904185336.35458Aff-hca@linux.ibm.com> (raw)
In-Reply-To: <20260903172417.12158Bf0-hca@linux.ibm.com>
On Thu, Sep 03, 2026 at 07:24:17PM +0200, Heiko Carstens wrote:
> 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 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...
Actually addressing this makes the code even simpler.
Something like the below should do (untested).
---
arch/s390/kernel/uv.c | 59 ++++++++++++++++++-------------------------
1 file changed, 24 insertions(+), 35 deletions(-)
diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c
index 8ea9dd7704ff..8dea30a1166b 100644
--- a/arch/s390/kernel/uv.c
+++ b/arch/s390/kernel/uv.c
@@ -14,8 +14,8 @@
#include <linux/memblock.h>
#include <linux/pagemap.h>
#include <linux/swap.h>
-#include <linux/pagewalk.h>
#include <linux/backing-dev.h>
+#include <linux/slab.h>
#include <linux/vmalloc.h>
#include <asm/facility.h>
#include <asm/sections.h>
@@ -210,62 +210,51 @@ int uv_convert_from_secure_pte(pte_t pte)
return uv_convert_from_secure_folio(pfn_folio(pte_pfn(pte)));
}
-static int uv_free_range_cb(pte_t *ptep, unsigned long addr, void *data)
-{
- pte_t pte = ptep_get(ptep);
-
- if (!pte_present(pte))
- return 0;
- /*
- * Note: do not update the pte here, since there is no code which
- * accesses the memory range, besides bugs. The invalidation of ptes
- * and TLB flushing is deferred like for regular vfree() calls.
- */
- __free_page(pte_page(pte));
- return 0;
-}
-
void uv_free_stor_var(void *stor_var)
{
- unsigned long addr, size;
struct vm_struct *area;
+ unsigned long i;
if (!stor_var)
return;
area = find_vm_area(stor_var);
if (WARN_ON_ONCE(!area || !(area->flags & VM_SPARSE)))
return;
- size = get_vm_area_size(area);
- addr = (unsigned long)area->addr;
- apply_to_existing_page_range(&init_mm, addr, size, uv_free_range_cb, NULL);
+ /*
+ * Do not update PTEs. There is no code which accesses the memory
+ * range, besides bugs. The invalidation of PTEs and TLB flushing
+ * is deferred like for regular vfree() calls.
+ */
+ for (i = 0; i < area->nr_pages; i++)
+ __free_page(area->pages[i]);
+ kvfree(area->pages);
+ area->pages = NULL;
free_vm_area(area);
}
EXPORT_SYMBOL_FOR_MODULES(uv_free_stor_var, "kvm");
-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);
- 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)
{
+ unsigned long i, nr_pages, addr;
struct vm_struct *area;
- unsigned long addr;
size = PAGE_ALIGN(size);
+ nr_pages = size >> PAGE_SHIFT;
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))
+ area->pages = kvcalloc(nr_pages, sizeof(struct page *), GFP_KERNEL_ACCOUNT);
+ if (!area->pages)
+ goto out;
+ for (i = 0; i < nr_pages; i++) {
+ area->nr_pages = i;
+ area->pages[i] = alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO);
+ if (!area->pages[i])
+ goto out;
+ }
+ area->nr_pages = nr_pages;
+ if (vm_area_map_pages(area, addr, addr + size, area->pages))
goto out;
return area->addr;
out:
--
2.53.0
next prev parent reply other threads:[~2026-09-04 18:53 UTC|newest]
Thread overview: 32+ 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:14 ` sashiko-bot
2026-07-20 9:56 ` Christian Borntraeger
2026-07-20 10:15 ` Heiko Carstens
2026-09-03 12:28 ` Alexander Gordeev
2026-09-03 17:24 ` Heiko Carstens
2026-09-04 18:53 ` Heiko Carstens [this message]
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 9:12 ` sashiko-bot
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 9:19 ` sashiko-bot
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 9:23 ` sashiko-bot
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 9:30 ` sashiko-bot
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 9:26 ` sashiko-bot
2026-07-20 8:58 ` [PATCH v4 7/8] s390/mm: Use goto statement " Heiko Carstens
2026-07-20 9:36 ` sashiko-bot
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-20 9:48 ` sashiko-bot
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=20260904185336.35458Aff-hca@linux.ibm.com \
--to=hca@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=david@kernel.org \
--cc=frankja@linux.ibm.com \
--cc=gor@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.