Skip to content

Commit 0e59041

Browse files
ankita-nvnvmochs
authored andcommitted
KVM: arm64: Expose new KVM cap for cacheable PFNMAP
BugLink: https://bugs.launchpad.net/bugs/2116207 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> (backported from commit f55ce5a linux-next) [mochs: minor context conflicts in docs and the header file] Signed-off-by: Matthew R. Ochs <mochs@nvidia.com> Acked-by: Carol L Soto <csoto@nvidia.com> Acked-by: Jamie Nguyen <jamien@nvidia.com> Acked-by: Nirmoy Das <nirmoyd@nvidia.com> Acked-by: Jacob Martin <jacob.martin@canonical.com> Acked-by: Noah Wager <noah.wager@canonical.com> Signed-off--by: Brad Figg <bfigg@nvidia.com>
1 parent 1caa6f2 commit 0e59041

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

Documentation/virt/kvm/api.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8258,6 +8258,17 @@ KVM exits with the register state of either the L1 or L2 guest
82588258
depending on which executed at the time of an exit. Userspace must
82598259
take care to differentiate between these cases.
82608260

8261+
7.37 KVM_CAP_ARM_CACHEABLE_PFNMAP_SUPPORTED
8262+
-------------------------------------------
8263+
8264+
:Architectures: arm64
8265+
:Target: VM
8266+
:Parameters: None
8267+
8268+
This capability indicate to the userspace whether a PFNMAP memory region
8269+
can be safely mapped as cacheable. This relies on the presence of
8270+
force write back (FWB) feature support on the hardware.
8271+
82618272
8. Other capabilities.
82628273
======================
82638274

arch/arm64/kvm/arm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,13 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
393393
case KVM_CAP_ARM_SUPPORTED_REG_MASK_RANGES:
394394
r = BIT(0);
395395
break;
396+
case KVM_CAP_ARM_CACHEABLE_PFNMAP_SUPPORTED:
397+
if (!kvm)
398+
r = -EINVAL;
399+
else
400+
r = kvm_supports_cacheable_pfnmap();
401+
break;
402+
396403
default:
397404
r = 0;
398405
}

include/uapi/linux/kvm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ struct kvm_enable_cap {
929929
#define KVM_CAP_PRE_FAULT_MEMORY 236
930930
#define KVM_CAP_X86_APIC_BUS_CYCLES_NS 237
931931
#define KVM_CAP_X86_GUEST_MODE 238
932+
#define KVM_CAP_ARM_CACHEABLE_PFNMAP_SUPPORTED 243
932933

933934
struct kvm_irq_routing_irqchip {
934935
__u32 irqchip;

0 commit comments

Comments
 (0)