KVM: arm64: pkvm_proxy: add helpers to run __pkvm_init_vcpu
Change-Id: Ic3cf8befb590c2b7a6a136af96fd450ce31a5b94
diff --git a/arch/arm64/include/uapi/asm/pkvm_proxy.h b/arch/arm64/include/uapi/asm/pkvm_proxy.h
index a343ddc..b977d10 100644
--- a/arch/arm64/include/uapi/asm/pkvm_proxy.h
+++ b/arch/arm64/include/uapi/asm/pkvm_proxy.h
@@ -17,6 +17,9 @@
#define HPROX_STRUCT_KVM_GET_OFFSET _IO(HPROX_STRUCTS_TYPE, 1)
#define HPROX_HYP_VM_GET_SIZE _IO(HPROX_STRUCTS_TYPE, 2)
#define HPROX_PGD_GET_SIZE _IO(HPROX_STRUCTS_TYPE, 3)
+#define HPROX_STRUCT_KVM_VCPU_GET_SIZE _IO(HPROX_STRUCTS_TYPE, 4)
+#define HPROX_STRUCT_KVM_VCPU_GET_OFFSET _IO(HPROX_STRUCTS_TYPE, 5)
+#define HPROX_HYP_VCPU_GET_SIZE _IO(HPROX_STRUCTS_TYPE, 6)
enum struct_kvm_fields {
HPROX_NR_MEM_SLOT_PAGES,
@@ -27,6 +30,15 @@
HPROX_ARCH_PKVM_TEARDOWN_MC,
};
+enum struct_kvm_vcpu_fields {
+ HPROX_VCPU_ID,
+ HPROX_VCPU_IDX,
+ HPROX_ARCH_CFLAGS,
+ HPROX_ARCH_FEATURES,
+ HPROX_ARCH_HCR_EL2,
+ // TODO add SVE state, for now SVE-less guests only
+};
+
// Need to match up kvm_hyp_memcache
struct hprox_hyp_memcache {
unsigned long head; // kernel address, might not be accessible, if not
diff --git a/arch/arm64/kvm/pkvm_proxy.c b/arch/arm64/kvm/pkvm_proxy.c
index e1e9625..6413f35 100644
--- a/arch/arm64/kvm/pkvm_proxy.c
+++ b/arch/arm64/kvm/pkvm_proxy.c
@@ -220,6 +220,29 @@
mmfr1 = read_sanitised_ftr_reg(SYS_ID_AA64MMFR1_EL1);
vtcr = kvm_get_vtcr(mmfr0, mmfr1, kvm_ipa_limit);
return kvm_pgtable_stage2_pgd_size(vtcr);
+ case HPROX_STRUCT_KVM_VCPU_GET_SIZE:
+ return sizeof(struct kvm_vcpu);
+ case HPROX_STRUCT_KVM_VCPU_GET_OFFSET:
+ switch (uarg) {
+ case HPROX_VCPU_ID:
+ return offsetof(struct kvm_vcpu, vcpu_id);
+ case HPROX_VCPU_IDX:
+ return offsetof(struct kvm_vcpu, vcpu_idx);
+ case HPROX_ARCH_CFLAGS:
+ return offsetof(struct kvm_vcpu, arch) +
+ offsetof(struct kvm_vcpu_arch, cflags);
+ case HPROX_ARCH_FEATURES:
+ return offsetof(struct kvm_vcpu, arch) +
+ offsetof(struct kvm_vcpu_arch, features);
+ case HPROX_ARCH_HCR_EL2:
+ return offsetof(struct kvm_vcpu, arch) +
+ offsetof(struct kvm_vcpu_arch, hcr_el2);
+ default:
+ return -EINVAL;
+ }
+
+ case HPROX_HYP_VCPU_GET_SIZE:
+ return PKVM_HYP_VCPU_SIZE;
default:
return -ENOSYS;
}