[PATCH v3 21/23] KVM: s390: Enable 1M pages for gmap

Claudio Imbrenda posted 23 patches 1 month, 1 week ago
There is a newer version of this series
[PATCH v3 21/23] KVM: s390: Enable 1M pages for gmap
Posted by Claudio Imbrenda 1 month, 1 week ago
While userspace is allowed to have pages of any size, the new gmap
would always use 4k pages to back the guest.

Enable 1M pages for gmap.

This allows 1M pages to be used to back a guest when userspace is using
1M pages for the corresponding addresses (e.g. THP or hugetlbfs).

Remove the limitation that disallowed having nested guests and
hugepages at the same time.

Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
 arch/s390/kvm/gmap.c     | 2 +-
 arch/s390/kvm/kvm-s390.c | 6 +-----
 arch/s390/kvm/pv.c       | 3 +++
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/arch/s390/kvm/gmap.c b/arch/s390/kvm/gmap.c
index 067683da6cae..c4e759bc82b3 100644
--- a/arch/s390/kvm/gmap.c
+++ b/arch/s390/kvm/gmap.c
@@ -591,7 +591,7 @@ static inline bool gmap_2g_allowed(struct gmap *gmap, gfn_t gfn)
 
 static inline bool gmap_1m_allowed(struct gmap *gmap, gfn_t gfn)
 {
-	return false;
+	return gmap->allow_hpage_1m;
 }
 
 int gmap_link(struct kvm_s390_mmu_cache *mc, struct gmap *gmap, struct guest_fault *f)
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index fb92e9ba45bb..391644a88b4e 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -849,6 +849,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, struct kvm_enable_cap *cap)
 			r = -EINVAL;
 		else {
 			r = 0;
+			WRITE_ONCE(kvm->arch.gmap->allow_hpage_1m, 1);
 			/*
 			 * We might have to create fake 4k page
 			 * tables. To avoid that the hardware works on
@@ -5875,11 +5876,6 @@ static int __init kvm_s390_init(void)
 		return -ENODEV;
 	}
 
-	if (nested && hpage) {
-		pr_info("A KVM host that supports nesting cannot back its KVM guests with huge pages\n");
-		return -EINVAL;
-	}
-
 	for (i = 0; i < 16; i++)
 		kvm_s390_fac_base[i] |=
 			stfle_fac_list[i] & nonhyp_mask(i);
diff --git a/arch/s390/kvm/pv.c b/arch/s390/kvm/pv.c
index d8a5c7b91148..8ea5f8d7e714 100644
--- a/arch/s390/kvm/pv.c
+++ b/arch/s390/kvm/pv.c
@@ -621,6 +621,9 @@ int kvm_s390_pv_init_vm(struct kvm *kvm, u16 *rc, u16 *rrc)
 	uvcb.flags.ap_allow_instr = kvm->arch.model.uv_feat_guest.ap;
 	uvcb.flags.ap_instr_intr = kvm->arch.model.uv_feat_guest.ap_intr;
 
+	WRITE_ONCE(kvm->arch.gmap->allow_hpage_1m, 0);
+	gmap_split_huge_pages(kvm->arch.gmap);
+
 	cc = uv_call_sched(0, (u64)&uvcb);
 	*rc = uvcb.header.rc;
 	*rrc = uvcb.header.rrc;
-- 
2.51.1
Re: [PATCH v3 21/23] KVM: s390: Enable 1M pages for gmap
Posted by Christian Borntraeger 1 month, 1 week ago
Am 06.11.25 um 17:11 schrieb Claudio Imbrenda:
> While userspace is allowed to have pages of any size, the new gmap
> would always use 4k pages to back the guest.
> 
> Enable 1M pages for gmap.
> 
> This allows 1M pages to be used to back a guest when userspace is using
> 1M pages for the corresponding addresses (e.g. THP or hugetlbfs).
> 
> Remove the limitation that disallowed having nested guests and
> hugepages at the same time.

Nice. This might allow us to enable hpage=1 as new default as soon as
things stabilize.

We would also be able to use 2GB huge pages for the qemu mapping?
With this patch we then have 1MB pages for the guest mapping.

As a future improvement, maybe also allow guest mapping 2GB pages.
Re: [PATCH v3 21/23] KVM: s390: Enable 1M pages for gmap
Posted by Claudio Imbrenda 1 month, 1 week ago
On Thu, 6 Nov 2025 17:22:33 +0100
Christian Borntraeger <borntraeger@de.ibm.com> wrote:

> Am 06.11.25 um 17:11 schrieb Claudio Imbrenda:
> > While userspace is allowed to have pages of any size, the new gmap
> > would always use 4k pages to back the guest.
> > 
> > Enable 1M pages for gmap.
> > 
> > This allows 1M pages to be used to back a guest when userspace is using
> > 1M pages for the corresponding addresses (e.g. THP or hugetlbfs).
> > 
> > Remove the limitation that disallowed having nested guests and
> > hugepages at the same time.  
> 
> Nice. This might allow us to enable hpage=1 as new default as soon as
> things stabilize.
> 
> We would also be able to use 2GB huge pages for the qemu mapping?

yes, but I don't think that userspace can have 2G THPs right now

> With this patch we then have 1MB pages for the guest mapping.
> 
> As a future improvement, maybe also allow guest mapping 2GB pages.

the core of the new gmap code introduced in this series supports 2G
pages already; to enable 2G pages, a simple patch similar to this one
is all that's needed.

I refrained from enabling 2G pages in this series because this series
is already too big, and also I would not be able to test it easily.
Re: [PATCH v3 21/23] KVM: s390: Enable 1M pages for gmap
Posted by Christian Borntraeger 1 month, 1 week ago

Am 06.11.25 um 17:36 schrieb Claudio Imbrenda:
> On Thu, 6 Nov 2025 17:22:33 +0100
> Christian Borntraeger <borntraeger@de.ibm.com> wrote:
> 
>> Am 06.11.25 um 17:11 schrieb Claudio Imbrenda:
>>> While userspace is allowed to have pages of any size, the new gmap
>>> would always use 4k pages to back the guest.
>>>
>>> Enable 1M pages for gmap.
>>>
>>> This allows 1M pages to be used to back a guest when userspace is using
>>> 1M pages for the corresponding addresses (e.g. THP or hugetlbfs).
>>>
>>> Remove the limitation that disallowed having nested guests and
>>> hugepages at the same time.
>>
>> Nice. This might allow us to enable hpage=1 as new default as soon as
>> things stabilize.
>>
>> We would also be able to use 2GB huge pages for the qemu mapping?
> 
> yes, but I don't think that userspace can have 2G THPs right now

Not THP, but hugetlbfs.