]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: s390: Allow for 2G hugepages
authorClaudio Imbrenda <imbrenda@linux.ibm.com>
Tue, 9 Jun 2026 15:09:29 +0000 (17:09 +0200)
committerClaudio Imbrenda <imbrenda@linux.ibm.com>
Tue, 9 Jun 2026 15:30:57 +0000 (17:30 +0200)
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>
Message-ID: <20260609150930.665370-4-imbrenda@linux.ibm.com>

arch/s390/kvm/gmap.c

index f8bd6c135e3c2eb490f0057b49a8fd20c8b8e0ad..402573cb2590e75f1130097d98e5058bf80395f2 100644 (file)
@@ -624,10 +624,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);
 }
 
 /**