]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: arm64: Expose new KVM cap for cacheable PFNMAP
authorAnkit Agrawal <ankita@nvidia.com>
Sat, 5 Jul 2025 07:17:17 +0000 (07:17 +0000)
committerOliver Upton <oliver.upton@linux.dev>
Mon, 7 Jul 2025 23:54:52 +0000 (16:54 -0700)
Introduce a new KVM capability to expose to the userspace whether
cacheable mapping of PFNMAP is supported.

The ability to safely do the cacheable mapping of PFNMAP is contingent
on S2FWB and ARM64_HAS_CACHE_DIC. S2FWB allows KVM to avoid flushing
the D cache, ARM64_HAS_CACHE_DIC allows KVM to avoid flushing the icache
and turns icache_inval_pou() into a NOP. The cap would be false if
those requirements are missing and is checked by making use of
kvm_arch_supports_cacheable_pfnmap.

This capability would allow userspace to discover the support.
It could for instance be used by userspace to prevent live-migration
across FWB and non-FWB hosts.

CC: Catalin Marinas <catalin.marinas@arm.com>
CC: Jason Gunthorpe <jgg@nvidia.com>
CC: Oliver Upton <oliver.upton@linux.dev>
CC: David Hildenbrand <david@redhat.com>
Suggested-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Tested-by: Donald Dutile <ddutile@redhat.com>
Signed-off-by: Ankit Agrawal <ankita@nvidia.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Link: https://lore.kernel.org/r/20250705071717.5062-7-ankita@nvidia.com
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Documentation/virt/kvm/api.rst
arch/arm64/kvm/arm.c
include/uapi/linux/kvm.h

index 9abf93ee5f65adf01af5ecc21560821eb6253356..53e0179d52949d186016f6bbc3cbbaa70af05ecd 100644 (file)
@@ -8585,7 +8585,7 @@ ENOSYS for the others.
 When enabled, KVM will exit to userspace with KVM_EXIT_SYSTEM_EVENT of
 type KVM_SYSTEM_EVENT_SUSPEND to process the guest suspend request.
 
-7.37 KVM_CAP_ARM_WRITABLE_IMP_ID_REGS
+7.42 KVM_CAP_ARM_WRITABLE_IMP_ID_REGS
 -------------------------------------
 
 :Architectures: arm64
@@ -8614,6 +8614,17 @@ given VM.
 When this capability is enabled, KVM resets the VCPU when setting
 MP_STATE_INIT_RECEIVED through IOCTL.  The original MP_STATE is preserved.
 
+7.43 KVM_CAP_ARM_CACHEABLE_PFNMAP_SUPPORTED
+-------------------------------------------
+
+:Architectures: arm64
+:Target: VM
+:Parameters: None
+
+This capability indicate to the userspace whether a PFNMAP memory region
+can be safely mapped as cacheable. This relies on the presence of
+force write back (FWB) feature support on the hardware.
+
 8. Other capabilities.
 ======================
 
index 38a91bb5d4c75145daf890ec988288bdcec0ab3e..25609aab032cec799c8f945dc825e8f3069b7895 100644 (file)
@@ -408,6 +408,13 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
        case KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES:
                r = BIT(0);
                break;
+       case KVM_CAP_ARM_CACHEABLE_PFNMAP_SUPPORTED:
+               if (!kvm)
+                       r = -EINVAL;
+               else
+                       r = kvm_supports_cacheable_pfnmap();
+               break;
+
        default:
                r = 0;
        }
index 37891580d05d061a8c96e62d3bce8547e2fdda8a..e4e566ff348b023499e8e063e80e6c29d3e2901f 100644 (file)
@@ -956,6 +956,7 @@ struct kvm_enable_cap {
 #define KVM_CAP_ARM_EL2 240
 #define KVM_CAP_ARM_EL2_E2H0 241
 #define KVM_CAP_RISCV_MP_STATE_RESET 242
+#define KVM_CAP_ARM_CACHEABLE_PFNMAP_SUPPORTED 243
 
 struct kvm_irq_routing_irqchip {
        __u32 irqchip;