Skip to contentSkip to conversation

target/s390x: Allow 2G hugepages guest backing

PATCH Superseded Claudio Imbrenda 2 participants 6 messages Jul 29 – Jul 31

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover target/s390x: Allow 2G hugepages guest backing

Allow mapping guest with 2G hugepages on hosts that support it.

Add new helper functions to check whether hpages are in effect, and which size.

v1->v2:
* Rename the global variable to cap_hpage
* Use different values of cap_hpage to distinguish between hpage sizes
* Add wrappers to test for specific hpage sizes

Claudio Imbrenda (1):
target/s390x: Allow 2G hugepages guest backing

 target/s390x/diag.c          |  2 +-
 target/s390x/kvm/kvm.c       | 40 +++++++++++++++++++++++-------------
 target/s390x/kvm/kvm_s390x.h |  2 ++
 target/s390x/kvm/stubs.c     | 10 +++++++++
 4 files changed, 39 insertions(+), 15 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH v2 1/1 target/s390x: Allow 2G hugepages guest backing

Allow mapping guest with 2G hugepages on hosts that support it.

Add new helper functions to check whether hpages are in effect, and which size.

---
 target/s390x/diag.c          |  2 +-
 target/s390x/kvm/kvm.c       | 40 +++++++++++++++++++++++-------------
 target/s390x/kvm/kvm_s390x.h |  2 ++
 target/s390x/kvm/stubs.c     | 10 +++++++++
 4 files changed, 39 insertions(+), 15 deletions(-)
target/s390x/diag.c +1 -1
index 80f0958478..46d191b87d 100644
@@ -185,7 +185,7 @@ out:
             return false;
         }
 
-        if (kvm_enabled() && kvm_s390_get_hpage_1m()) {
+        if (kvm_enabled() && kvm_s390_get_hpage()) {
             error_report("Protected VMs can currently not be backed with "
                          "huge pages");
             env->regs[r1 + 1] = DIAG_308_RC_INVAL_FOR_PV;
target/s390x/kvm/kvm.c +26 -14
index 72031a5714..0d04e940ef 100644
@@ -145,7 +145,7 @@ static int cap_mem_op;
 static int cap_mem_op_extension;
 static int cap_s390_irq;
 static int cap_ri;
-static int cap_hpage_1m;
+static int cap_hpage;
 static int cap_vcpu_resets;
 static int cap_protected;
 static int cap_zpci_op;
@@ -231,7 +231,7 @@ static void kvm_s390_enable_cmma(void)
         .attr = KVM_S390_VM_MEM_ENABLE_CMMA,
     };
 
-    if (cap_hpage_1m) {
+    if (cap_hpage) {
         warn_report("CMM will not be enabled because it is not "
                     "compatible with huge memory backings.");
         return;
@@ -298,24 +298,36 @@ void kvm_s390_set_max_pagesize(uint64_t pagesize, Error **errp)
         return;
     }
 
-    if (pagesize != 1 * MiB) {
-        error_setg(errp, "Memory backing with 2G pages was specified, "
-                   "but KVM does not support this memory backing");
-        return;
-    }
-
-    if (kvm_vm_enable_cap(kvm_state, KVM_CAP_S390_HPAGE_1M, 0)) {
-        error_setg(errp, "Memory backing with 1M pages was specified, "
-                   "but KVM does not support this memory backing");
-        return;
+    if (pagesize == 2 * GiB) {
+        if (kvm_vm_enable_cap(kvm_state, KVM_CAP_S390_HPAGE_2G, 0)) {
+            error_setg(errp, "Memory backing with 2G pages was specified, "
+                       "but KVM does not support this memory backing");
+            return;
+        }
+        cap_hpage = 2;
+    } else if (pagesize == MiB) {
+        if (kvm_vm_enable_cap(kvm_state, KVM_CAP_S390_HPAGE_1M, 0)) {
+            error_setg(errp, "Memory backing with 1M pages was specified, "
+                       "but KVM does not support this memory backing");
+            return;
+        }
+        cap_hpage = 1;
     }
+}
 
-    cap_hpage_1m = 1;
+int kvm_s390_get_hpage(void)
+{
+    return cap_hpage;
 }
 
 int kvm_s390_get_hpage_1m(void)
 {
-    return cap_hpage_1m;
+    return cap_hpage == 1;
+}
+
+int kvm_s390_get_hpage_2g(void)
+{
+    return cap_hpage == 2;
 }
 
 static void ccw_machine_class_foreach(ObjectClass *oc, void *opaque)
target/s390x/kvm/kvm_s390x.h +2 -0
index 7b1cce3e60..ccc615abed 100644
@@ -25,7 +25,9 @@ void kvm_s390_program_interrupt(S390CPU *cpu, uint16_t code);
 int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state);
 void kvm_s390_vcpu_interrupt_pre_save(S390CPU *cpu);
 int kvm_s390_vcpu_interrupt_post_load(S390CPU *cpu);
+int kvm_s390_get_hpage(void);
 int kvm_s390_get_hpage_1m(void);
+int kvm_s390_get_hpage_2g(void);
 int kvm_s390_get_protected_dump(void);
 int kvm_s390_get_ri(void);
 int kvm_s390_get_zpci_op(void);
target/s390x/kvm/stubs.c +10 -0
index 196127baa5..06e865f806 100644
@@ -143,11 +143,21 @@ int kvm_s390_vcpu_interrupt_post_load(S390CPU *cpu)
     g_assert_not_reached();
 }
 
+int kvm_s390_get_hpage(void)
+{
+    g_assert_not_reached();
+}
+
 int kvm_s390_get_hpage_1m(void)
 {
     g_assert_not_reached();
 }
 
+int kvm_s390_get_hpage_2g(void)
+{
+    g_assert_not_reached();
+}
+
 void kvm_s390_enable_css_support(S390CPU *cpu)
 {
     g_assert_not_reached();
Signature · 1 line
2.55.0
#2 lore raw
Quoted 3 lines
target/s390x/diag.c +1 -1
-        if (kvm_enabled() && kvm_s390_get_hpage_1m()) {
+        if (kvm_enabled() && kvm_s390_get_hpage()) {

...

Quoted 7 lines
target/s390x/kvm/kvm.c +3 -1
-    cap_hpage_1m = 1;
+int kvm_s390_get_hpage(void)
+{
+    return cap_hpage;
 }
 

target/s390x/kvm/kvm.c void kvm_s390_set_max_pagesize(uint64_t pagesize, Error **errp) · line 331

Quoted 10 lines
target/s390x/kvm/kvm.c +6 -1
 int kvm_s390_get_hpage_1m(void)
 {
-    return cap_hpage_1m;
+    return cap_hpage == 1;
+}
+
+int kvm_s390_get_hpage_2g(void)
+{
+    return cap_hpage == 2;
 }

Hey Claudio,

Thanks for changing things to differentiate between 1m and 2g for the cap.

Overall LGTM but this patch now makes kvm_s390_get_hpage_1m() dead code (not referenced anywhere) as well as introduces a new function kvm_s390_get_hpage_2g() that is also unused.

Since this patch is by itself, why not just remove the functions until/if they are needed and only provide kvm_s390_get_hpage()?

Do you have planned future patches that you are confident will soon make use of these get_hpage_1m() and get_hpage_2g() helpers?

Thanks,
Matt

#3 lore raw
Quoted 31 lines · On Wed, 29 Jul 2026 13:53:01 -0400 Matthew Rosato <[email protected]>…
Quoted 2 lines
target/s390x/diag.c +1 -1
-        if (kvm_enabled() && kvm_s390_get_hpage_1m()) {
+        if (kvm_enabled() && kvm_s390_get_hpage()) {  

...

Quoted 7 lines
target/s390x/kvm/kvm.c +3 -1
-    cap_hpage_1m = 1;
+int kvm_s390_get_hpage(void)
+{
+    return cap_hpage;
 }
 

target/s390x/kvm/kvm.c void kvm_s390_set_max_pagesize(uint64_t pagesize, Error **errp) · line 331

Quoted 10 lines
target/s390x/kvm/kvm.c +6 -1
 int kvm_s390_get_hpage_1m(void)
 {
-    return cap_hpage_1m;
+    return cap_hpage == 1;
+}
+
+int kvm_s390_get_hpage_2g(void)
+{
+    return cap_hpage == 2;
 }  

Hey Claudio,

Thanks for changing things to differentiate between 1m and 2g for the cap.

Overall LGTM but this patch now makes kvm_s390_get_hpage_1m() dead code (not referenced anywhere) as well as introduces a new function kvm_s390_get_hpage_2g() that is also unused.

Quoted 5 lines

Since this patch is by itself, why not just remove the functions until/if they are needed and only provide kvm_s390_get_hpage()?

Do you have planned future patches that you are confident will soon make use of these get_hpage_1m() and get_hpage_2g() helpers?

yes, which is why I put them there :)

but I understand that dead code is annoying, if you want I can simply respin without the unused functions, and introduce them later when they are actually needed.

Quoted 6 lines

Thanks,
Matt

Reviewed-by
#4 lore raw
Quoted 7 lines
Quoted 4 lines

Do you have planned future patches that you are confident will soon make use of these get_hpage_1m() and get_hpage_2g() helpers?

yes, which is why I put them there :)

OK, I won't ask for a respin if you're planning to use them soon.

Thanks!

#5 lore raw
Quoted 11 lines · On Thu, 30 Jul 2026 14:59:19 -0400 Matthew Rosato <[email protected]>…
Quoted 6 lines
Quoted 3 lines

Do you have planned future patches that you are confident will soon make use of these get_hpage_1m() and get_hpage_2g() helpers?

yes, which is why I put them there :)

OK, I won't ask for a respin if you're planning to use them soon.

Thanks!

aaaand I just realized I can simplify things further... I think I will need to do a respin anyway