diff mbox series

[RFC,4/6] KVM: arm64: Add hypercall support for retrieving migration errata bitmap

Message ID 20241011075053.80540-5-shameerali.kolothum.thodi@huawei.com (mailing list archive)
State New, archived
Headers show
Series KVM: arm64: Errata management for VM Live migration | expand

Commit Message

Shameerali Kolothum Thodi Oct. 11, 2024, 7:50 a.m. UTC
If the VM requires migration and has set the list of target CPUs, retrieve
the errata bitmap for those targets. The Guest can use this hypercall
to get the errata bitmap. The bitmaps will be returned in R0-R3 registers.

ToDo: For now, reused one of the reserved pKVM hypercall value for this
as I noticed that the vendor_hyp_bmap size needs to be adjusted to have
anything > 63 set.

Signed-off-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com>
---
 arch/arm64/include/uapi/asm/kvm.h |  1 +
 arch/arm64/kvm/hypercalls.c       | 20 ++++++++++++++++++++
 include/linux/arm-smccc.h         |  8 +++++++-
 3 files changed, 28 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h
index 321f86d747c8..a518cb3a744b 100644
--- a/arch/arm64/include/uapi/asm/kvm.h
+++ b/arch/arm64/include/uapi/asm/kvm.h
@@ -379,6 +379,7 @@  enum {
 enum {
 	KVM_REG_ARM_VENDOR_HYP_BIT_FUNC_FEAT	= 0,
 	KVM_REG_ARM_VENDOR_HYP_BIT_PTP		= 1,
+	KVM_REG_ARM_VENDOR_HYP_BIT_MIGRN_ERRATA	= 5,
 #ifdef __KERNEL__
 	KVM_REG_ARM_VENDOR_HYP_BMAP_BIT_COUNT,
 #endif
diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c
index 5763d979d8ca..4433cd56cbc2 100644
--- a/arch/arm64/kvm/hypercalls.c
+++ b/arch/arm64/kvm/hypercalls.c
@@ -116,6 +116,9 @@  static bool kvm_smccc_test_fw_bmap(struct kvm_vcpu *vcpu, u32 func_id)
 	case ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID:
 		return test_bit(KVM_REG_ARM_VENDOR_HYP_BIT_PTP,
 				&smccc_feat->vendor_hyp_bmap);
+	case ARM_SMCCC_VENDOR_HYP_KVM_MIGRN_ERRATA:
+		return test_bit(KVM_REG_ARM_VENDOR_HYP_BIT_MIGRN_ERRATA,
+				&smccc_feat->vendor_hyp_bmap);
 	default:
 		return false;
 	}
@@ -364,6 +367,23 @@  int kvm_smccc_call_handler(struct kvm_vcpu *vcpu)
 	case ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID:
 		kvm_ptp_get_time(vcpu, val);
 		break;
+	case ARM_SMCCC_VENDOR_HYP_KVM_MIGRN_ERRATA: {
+		struct migrn_target_cpu *migrn_cpu = vcpu->kvm->arch.migrn_cpu;
+		unsigned long *errata_map;
+
+		if (!migrn_cpu || (ARM64_NCAPS > (BITS_PER_LONG * 4)))
+			goto out;
+
+		errata_map = bitmap_zalloc(ARM64_NCAPS, GFP_KERNEL);
+		if (!errata_map)
+			goto out;
+		for (int i = 0; i < vcpu->kvm->arch.num_migrn_cpus; i++, migrn_cpu++)
+			arm_get_migrn_errata_map(migrn_cpu, errata_map);
+
+		bitmap_to_arr64(val, errata_map, ARM64_NCAPS);
+		bitmap_free(errata_map);
+		break;
+	}
 	case ARM_SMCCC_TRNG_VERSION:
 	case ARM_SMCCC_TRNG_FEATURES:
 	case ARM_SMCCC_TRNG_GET_UUID:
diff --git a/include/linux/arm-smccc.h b/include/linux/arm-smccc.h
index f59099a213d0..839b3dfad590 100644
--- a/include/linux/arm-smccc.h
+++ b/include/linux/arm-smccc.h
@@ -119,7 +119,7 @@ 
 #define ARM_SMCCC_KVM_FUNC_HYP_MEMINFO		2
 #define ARM_SMCCC_KVM_FUNC_MEM_SHARE		3
 #define ARM_SMCCC_KVM_FUNC_MEM_UNSHARE		4
-#define ARM_SMCCC_KVM_FUNC_PKVM_RESV_5		5
+#define ARM_SMCCC_KVM_FUNC_MIGRN_ERRATA		5
 #define ARM_SMCCC_KVM_FUNC_PKVM_RESV_6		6
 #define ARM_SMCCC_KVM_FUNC_MMIO_GUARD		7
 #define ARM_SMCCC_KVM_FUNC_PKVM_RESV_8		8
@@ -225,6 +225,12 @@ 
 			   ARM_SMCCC_OWNER_VENDOR_HYP,			\
 			   ARM_SMCCC_KVM_FUNC_MMIO_GUARD)
 
+#define ARM_SMCCC_VENDOR_HYP_KVM_MIGRN_ERRATA			\
+	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,			\
+			   ARM_SMCCC_SMC_64,			\
+			   ARM_SMCCC_OWNER_VENDOR_HYP,		\
+			   ARM_SMCCC_KVM_FUNC_MIGRN_ERRATA)
+
 /* ptp_kvm counter type ID */
 #define KVM_PTP_VIRT_COUNTER			0
 #define KVM_PTP_PHYS_COUNTER			1