* [PATCH v2 0/4] KVM: s390: Add support for 2G hugepages
@ 2026-06-09 15:09 Claudio Imbrenda
2026-06-09 15:09 ` [PATCH v2 1/4] KVM: s390: Add module parameter to fence " Claudio Imbrenda
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Claudio Imbrenda @ 2026-06-09 15:09 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, borntraeger, frankja, david, seiden, nrb,
schlameuss, gra
Add support for 2G hugepages.
In theory, since kernel 7.0, userspace could already use 2G hugepages
to back guest memory, but KVM would use 4k or 1M pages in gmap to
actually map the guest.
This series allows KVM on s390 to actually use 2G hugepages in gmap to
map guest memory that is backed by 2G hugepages in userspace.
Nested guests remain possible.
v1->v2:
* Fix possible race between clearing the GMAP_FLAG_ALLOW_HPAGE_2G flag
and gmap_split_huge_pages().
* Add documentation for the KVM_CAP_S390_HPAGE_2G capability.
Claudio Imbrenda (4):
KVM: s390: Add module parameter to fence 2G hugepages
KVM: s390: Add capability to support 2G hugepages
KVM: s390: Allow for 2G hugepages
KVM: s390: Document the KVM_CAP_S390_HPAGE_2G capability
Documentation/virt/kvm/api.rst | 15 ++++++++++++++
arch/s390/kvm/gmap.c | 24 ++++++++++++++++++++-
arch/s390/kvm/kvm-s390.c | 38 +++++++++++++++++++++++++++++++++-
arch/s390/kvm/pv.c | 5 ++++-
include/uapi/linux/kvm.h | 1 +
5 files changed, 80 insertions(+), 3 deletions(-)
--
2.54.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/4] KVM: s390: Add module parameter to fence 2G hugepages
2026-06-09 15:09 [PATCH v2 0/4] KVM: s390: Add support for 2G hugepages Claudio Imbrenda
@ 2026-06-09 15:09 ` Claudio Imbrenda
2026-06-10 8:34 ` Janosch Frank
2026-06-09 15:09 ` [PATCH v2 2/4] KVM: s390: Add capability to support " Claudio Imbrenda
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Claudio Imbrenda @ 2026-06-09 15:09 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.
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
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 [flat|nested] 6+ messages in thread
* [PATCH v2 2/4] KVM: s390: Add capability to support 2G hugepages
2026-06-09 15:09 [PATCH v2 0/4] KVM: s390: Add support for 2G hugepages Claudio Imbrenda
2026-06-09 15:09 ` [PATCH v2 1/4] KVM: s390: Add module parameter to fence " Claudio Imbrenda
@ 2026-06-09 15:09 ` Claudio Imbrenda
2026-06-09 15:09 ` [PATCH v2 3/4] KVM: s390: Allow for " Claudio Imbrenda
2026-06-09 15:09 ` [PATCH v2 4/4] KVM: s390: Document the KVM_CAP_S390_HPAGE_2G capability Claudio Imbrenda
3 siblings, 0 replies; 6+ messages in thread
From: Claudio Imbrenda @ 2026-06-09 15:09 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.
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
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 | 5 ++++-
include/uapi/linux/kvm.h | 1 +
4 files changed, 36 insertions(+), 1 deletion(-)
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..1beacc841ca8 100644
--- a/arch/s390/kvm/pv.c
+++ b/arch/s390/kvm/pv.c
@@ -740,7 +740,10 @@ 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;
- clear_bit(GMAP_FLAG_ALLOW_HPAGE_1M, &kvm->arch.gmap->flags);
+ scoped_guard(write_lock, &kvm->mmu_lock) {
+ 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 [flat|nested] 6+ messages in thread
* [PATCH v2 3/4] KVM: s390: Allow for 2G hugepages
2026-06-09 15:09 [PATCH v2 0/4] KVM: s390: Add support for 2G hugepages Claudio Imbrenda
2026-06-09 15:09 ` [PATCH v2 1/4] KVM: s390: Add module parameter to fence " Claudio Imbrenda
2026-06-09 15:09 ` [PATCH v2 2/4] KVM: s390: Add capability to support " Claudio Imbrenda
@ 2026-06-09 15:09 ` Claudio Imbrenda
2026-06-09 15:09 ` [PATCH v2 4/4] KVM: s390: Document the KVM_CAP_S390_HPAGE_2G capability Claudio Imbrenda
3 siblings, 0 replies; 6+ messages in thread
From: Claudio Imbrenda @ 2026-06-09 15:09 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.
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
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 [flat|nested] 6+ messages in thread
* [PATCH v2 4/4] KVM: s390: Document the KVM_CAP_S390_HPAGE_2G capability
2026-06-09 15:09 [PATCH v2 0/4] KVM: s390: Add support for 2G hugepages Claudio Imbrenda
` (2 preceding siblings ...)
2026-06-09 15:09 ` [PATCH v2 3/4] KVM: s390: Allow for " Claudio Imbrenda
@ 2026-06-09 15:09 ` Claudio Imbrenda
3 siblings, 0 replies; 6+ messages in thread
From: Claudio Imbrenda @ 2026-06-09 15:09 UTC (permalink / raw)
To: linux-kernel
Cc: kvm, linux-s390, borntraeger, frankja, david, seiden, nrb,
schlameuss, gra
Document the KVM_CAP_S390_HPAGE_2G capability, which behaves very
similarly to the existing KVM_CAP_S390_HPAGE_1M.
Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
Documentation/virt/kvm/api.rst | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst
index 52bbbb553ce1..3fdd0729f6ee 100644
--- a/Documentation/virt/kvm/api.rst
+++ b/Documentation/virt/kvm/api.rst
@@ -8904,6 +8904,21 @@ helpful if user space wants to emulate instructions which are not
This capability can be enabled dynamically even if VCPUs were already
created and are running.
+7.47 KVM_CAP_S390_HPAGE_2G
+--------------------------
+
+:Architectures: s390
+:Parameters: none
+:Returns: 0 on success; -EINVAL if hpage_2g module parameter was not set,
+ cmma is enabled, or the VM has the KVM_VM_S390_UCONTROL
+ flag set; -EBUSY if vCPUs were already created for the VM.
+
+With this capability the KVM support for memory backing with 2g pages
+through hugetlbfs can be enabled for a VM. After the capability is
+enabled, cmma can't be enabled anymore and pfmfi and the storage key
+interpretation are disabled. If cmma has already been enabled or the
+hpage_2g module parameter is not set to 1, -EINVAL is returned.
+
8. Other capabilities.
======================
--
2.54.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/4] KVM: s390: Add module parameter to fence 2G hugepages
2026-06-09 15:09 ` [PATCH v2 1/4] KVM: s390: Add module parameter to fence " Claudio Imbrenda
@ 2026-06-10 8:34 ` Janosch Frank
0 siblings, 0 replies; 6+ messages in thread
From: Janosch Frank @ 2026-06-10 8:34 UTC (permalink / raw)
To: Claudio Imbrenda, linux-kernel
Cc: kvm, linux-s390, borntraeger, david, seiden, nrb, schlameuss, gra
On 6/9/26 17:09, 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.
>
Instead of adding yet another parameter could we make it an int and say
that hpage=2 equals edat1 and edat2?
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-06-10 8:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-09 15:09 [PATCH v2 0/4] KVM: s390: Add support for 2G hugepages Claudio Imbrenda
2026-06-09 15:09 ` [PATCH v2 1/4] KVM: s390: Add module parameter to fence " Claudio Imbrenda
2026-06-10 8:34 ` Janosch Frank
2026-06-09 15:09 ` [PATCH v2 2/4] KVM: s390: Add capability to support " Claudio Imbrenda
2026-06-09 15:09 ` [PATCH v2 3/4] KVM: s390: Allow for " Claudio Imbrenda
2026-06-09 15:09 ` [PATCH v2 4/4] KVM: s390: Document the KVM_CAP_S390_HPAGE_2G capability Claudio Imbrenda
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®