* [PATCH v1 1/3] KVM: s390: Add module parameter to fence 2G hugepages
2026-06-03 15:47 [PATCH v1 0/3] KVM: s390: Add support for 2G hugepages Claudio Imbrenda
@ 2026-06-03 15:47 ` Claudio Imbrenda
2026-06-08 12:50 ` Steffen Eiden
2026-06-03 15:47 ` [PATCH v1 2/3] KVM: s390: Add capability to support " Claudio Imbrenda
2026-06-03 15:47 ` [PATCH v1 3/3] KVM: s390: Allow for " Claudio Imbrenda
2 siblings, 1 reply; 7+ messages in thread
From: Claudio Imbrenda @ 2026-06-03 15:47 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, borntraeger, frankja, david, seiden, nrb,
schlameuss, gra
Add the hpage_2g module parameter to KVM to allow enabling or disabling
2G hugepages in KVM.
If hpage_2g is enabled but hpage is not enabled, print a message and
disable hpage_2g.
Opportunistically fix the comment for the hpage module parameter.
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
arch/s390/kvm/kvm-s390.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index ffb20a64d328..801a622691b6 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -204,11 +204,16 @@ static int nested;
module_param(nested, int, S_IRUGO);
MODULE_PARM_DESC(nested, "Nested virtualization support");
-/* allow 1m huge page guest backing, if !nested */
+/* allow 1m huge page guest backing */
static int hpage;
module_param(hpage, int, 0444);
MODULE_PARM_DESC(hpage, "1m huge page backing support");
+/* allow 2g huge page guest backing */
+static int hpage_2g;
+module_param(hpage_2g, int, 0444);
+MODULE_PARM_DESC(hpage_2g, "2g huge page backing support");
+
/* maximum percentage of steal time for polling. >100 is treated like 100 */
static u8 halt_poll_max_steal = 10;
module_param(halt_poll_max_steal, byte, 0644);
@@ -5820,6 +5825,11 @@ static int __init kvm_s390_init(void)
return -ENODEV;
}
+ if (hpage_2g && !hpage) {
+ hpage_2g = 0;
+ pr_info("Disabling 2G hugepage support, since 1M hugepage support is not enabled.\n");
+ }
+
for (i = 0; i < 16; i++)
kvm_s390_fac_base[i] |=
stfle_fac_list[i] & nonhyp_mask(i);
--
2.54.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v1 1/3] KVM: s390: Add module parameter to fence 2G hugepages
2026-06-03 15:47 ` [PATCH v1 1/3] KVM: s390: Add module parameter to fence " Claudio Imbrenda
@ 2026-06-08 12:50 ` Steffen Eiden
0 siblings, 0 replies; 7+ messages in thread
From: Steffen Eiden @ 2026-06-08 12:50 UTC (permalink / raw)
To: Claudio Imbrenda
Cc: linux-kernel, kvm, linux-s390, borntraeger, frankja, david, nrb,
schlameuss, gra
On Wed, Jun 03, 2026 at 05:47:56PM +0200, Claudio Imbrenda wrote:
> Add the hpage_2g module parameter to KVM to allow enabling or disabling
> 2G hugepages in KVM.
>
> If hpage_2g is enabled but hpage is not enabled, print a message and
> disable hpage_2g.
>
> Opportunistically fix the comment for the hpage module parameter.
>
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v1 2/3] KVM: s390: Add capability to support 2G hugepages
2026-06-03 15:47 [PATCH v1 0/3] KVM: s390: Add support for 2G hugepages Claudio Imbrenda
2026-06-03 15:47 ` [PATCH v1 1/3] KVM: s390: Add module parameter to fence " Claudio Imbrenda
@ 2026-06-03 15:47 ` Claudio Imbrenda
2026-06-08 12:51 ` Steffen Eiden
2026-06-03 15:47 ` [PATCH v1 3/3] KVM: s390: Allow for " Claudio Imbrenda
2 siblings, 1 reply; 7+ messages in thread
From: Claudio Imbrenda @ 2026-06-03 15:47 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, borntraeger, frankja, david, seiden, nrb,
schlameuss, gra
Add KVM_CAP_S390_HPAGE_2G to signal to userspace that 2G hugepages may
be used to back the guest; restrictions apply similar to 1M hugepages.
Enable the (for now still ignored) GMAP_FLAG_ALLOW_HPAGE_2G flag for
the guest gmap, and propagate / disable it as necessary.
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
arch/s390/kvm/gmap.c | 5 +++++
arch/s390/kvm/kvm-s390.c | 26 ++++++++++++++++++++++++++
arch/s390/kvm/pv.c | 1 +
include/uapi/linux/kvm.h | 1 +
4 files changed, 33 insertions(+)
diff --git a/arch/s390/kvm/gmap.c b/arch/s390/kvm/gmap.c
index 52d55ddea8d4..c9e348149ba1 100644
--- a/arch/s390/kvm/gmap.c
+++ b/arch/s390/kvm/gmap.c
@@ -105,6 +105,11 @@ static void gmap_add_child(struct gmap *parent, struct gmap *child)
else
clear_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &child->flags);
+ if (test_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &parent->flags))
+ set_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &child->flags);
+ else
+ clear_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &child->flags);
+
if (kvm_is_ucontrol(parent->kvm))
clear_bit(GMAP_FLAG_OWNS_PAGETABLES, &child->flags);
list_add(&child->list, &parent->children);
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index 801a622691b6..616d1db7c0d9 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -645,6 +645,11 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
if (hpage && !(kvm && kvm_is_ucontrol(kvm)))
r = 1;
break;
+ case KVM_CAP_S390_HPAGE_2G:
+ r = 0;
+ if (hpage_2g && !(kvm && kvm_is_ucontrol(kvm)))
+ r = 1;
+ break;
case KVM_CAP_S390_MEM_OP:
r = MEM_OP_MAX_SIZE;
break;
@@ -901,6 +906,27 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, struct kvm_enable_cap *cap)
VM_EVENT(kvm, 3, "ENABLE: CAP_S390_HPAGE %s",
r ? "(not available)" : "(success)");
break;
+ case KVM_CAP_S390_HPAGE_2G:
+ mutex_lock(&kvm->lock);
+ if (kvm->created_vcpus) {
+ r = -EBUSY;
+ } else if (!hpage_2g || kvm->arch.use_cmma || kvm_is_ucontrol(kvm)) {
+ r = -EINVAL;
+ } else {
+ r = 0;
+ set_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &kvm->arch.gmap->flags);
+ /*
+ * We might have to create fake 4k page
+ * tables. To avoid that the hardware works on
+ * stale PGSTEs, we emulate these instructions.
+ */
+ kvm->arch.use_skf = 0;
+ kvm->arch.use_pfmfi = 0;
+ }
+ mutex_unlock(&kvm->lock);
+ VM_EVENT(kvm, 3, "ENABLE: CAP_S390_HPAGE_2G %s",
+ r ? "(not available)" : "(success)");
+ break;
case KVM_CAP_S390_USER_STSI:
VM_EVENT(kvm, 3, "%s", "ENABLE: CAP_S390_USER_STSI");
kvm->arch.user_stsi = 1;
diff --git a/arch/s390/kvm/pv.c b/arch/s390/kvm/pv.c
index 4b865e75351c..0f818149e644 100644
--- a/arch/s390/kvm/pv.c
+++ b/arch/s390/kvm/pv.c
@@ -741,6 +741,7 @@ int kvm_s390_pv_init_vm(struct kvm *kvm, u16 *rc, u16 *rrc)
uvcb.flags.ap_instr_intr = kvm->arch.model.uv_feat_guest.ap_intr;
clear_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &kvm->arch.gmap->flags);
+ clear_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &kvm->arch.gmap->flags);
gmap_split_huge_pages(kvm->arch.gmap);
cc = uv_call_sched(0, (u64)&uvcb);
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 6c8afa2047bf..419011097fa8 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -996,6 +996,7 @@ struct kvm_enable_cap {
#define KVM_CAP_S390_USER_OPEREXEC 246
#define KVM_CAP_S390_KEYOP 247
#define KVM_CAP_S390_VSIE_ESAMODE 248
+#define KVM_CAP_S390_HPAGE_2G 249
struct kvm_irq_routing_irqchip {
__u32 irqchip;
--
2.54.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v1 2/3] KVM: s390: Add capability to support 2G hugepages
2026-06-03 15:47 ` [PATCH v1 2/3] KVM: s390: Add capability to support " Claudio Imbrenda
@ 2026-06-08 12:51 ` Steffen Eiden
0 siblings, 0 replies; 7+ messages in thread
From: Steffen Eiden @ 2026-06-08 12:51 UTC (permalink / raw)
To: Claudio Imbrenda
Cc: linux-kernel, kvm, linux-s390, borntraeger, frankja, david, nrb,
schlameuss, gra
On Wed, Jun 03, 2026 at 05:47:57PM +0200, Claudio Imbrenda wrote:
> Add KVM_CAP_S390_HPAGE_2G to signal to userspace that 2G hugepages may
> be used to back the guest; restrictions apply similar to 1M hugepages.
>
> Enable the (for now still ignored) GMAP_FLAG_ALLOW_HPAGE_2G flag for
> the guest gmap, and propagate / disable it as necessary.
>
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v1 3/3] KVM: s390: Allow for 2G hugepages
2026-06-03 15:47 [PATCH v1 0/3] KVM: s390: Add support for 2G hugepages Claudio Imbrenda
2026-06-03 15:47 ` [PATCH v1 1/3] KVM: s390: Add module parameter to fence " Claudio Imbrenda
2026-06-03 15:47 ` [PATCH v1 2/3] KVM: s390: Add capability to support " Claudio Imbrenda
@ 2026-06-03 15:47 ` Claudio Imbrenda
2026-06-08 12:53 ` Steffen Eiden
2 siblings, 1 reply; 7+ messages in thread
From: Claudio Imbrenda @ 2026-06-03 15:47 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, borntraeger, frankja, david, seiden, nrb,
schlameuss, gra
Change gmap_2g_allowed() to perform the necessary checks to allow for
2G hugepages to be used, instead of returning false. The
GMAP_FLAG_ALLOW_HPAGE_2G gmap flag is now taken into account.
Also add appropriate kerneldoc comments.
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
arch/s390/kvm/gmap.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/arch/s390/kvm/gmap.c b/arch/s390/kvm/gmap.c
index c9e348149ba1..c5a8132eaa22 100644
--- a/arch/s390/kvm/gmap.c
+++ b/arch/s390/kvm/gmap.c
@@ -635,10 +635,27 @@ int gmap_try_fixup_minor(struct gmap *gmap, struct guest_fault *fault)
return rc;
}
+/**
+ * gmap_2g_allowed() - Check whether a 2G hugepage is allowed.
+ * @gmap: The gmap of the guest.
+ * @f: Describes the fault that is being resolved.
+ * @slot: The memslot the faulting address belongs to.
+ *
+ * The function checks whether the GMAP_FLAG_ALLOW_HPAGE_2G flag is set for
+ * @gmap, whether the offset of the address in the 2G virtual frame is the
+ * same as the offset in the physical 2G frame, and finally whether the whole
+ * 2G page would fit in the given memslot.
+ *
+ * Return: true if a 2G hugepage is allowed to back the faulting address, false
+ * otherwise.
+ */
static inline bool gmap_2g_allowed(struct gmap *gmap, struct guest_fault *f,
struct kvm_memory_slot *slot)
{
- return false;
+ return test_bit(GMAP_FLAG_ALLOW_HPAGE_2G, &gmap->flags) &&
+ !((f->gfn ^ f->pfn) & ~_REGION3_FR_MASK) &&
+ slot->base_gfn <= ALIGN_DOWN(f->gfn, _PAGES_PER_REGION3) &&
+ slot->base_gfn + slot->npages >= ALIGN(f->gfn + 1, _PAGES_PER_REGION3);
}
/**
--
2.54.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH v1 3/3] KVM: s390: Allow for 2G hugepages
2026-06-03 15:47 ` [PATCH v1 3/3] KVM: s390: Allow for " Claudio Imbrenda
@ 2026-06-08 12:53 ` Steffen Eiden
0 siblings, 0 replies; 7+ messages in thread
From: Steffen Eiden @ 2026-06-08 12:53 UTC (permalink / raw)
To: Claudio Imbrenda
Cc: linux-kernel, kvm, linux-s390, borntraeger, frankja, david, nrb,
schlameuss, gra
On Wed, Jun 03, 2026 at 05:47:58PM +0200, Claudio Imbrenda wrote:
> Change gmap_2g_allowed() to perform the necessary checks to allow for
> 2G hugepages to be used, instead of returning false. The
> GMAP_FLAG_ALLOW_HPAGE_2G gmap flag is now taken into account.
>
> Also add appropriate kerneldoc comments.
>
> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
^ permalink raw reply [flat|nested] 7+ messages in thread