Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

KVM: arm64: Add standard hypervisor firmware register

Introduce the firmware register to hold the standard hypervisor
service calls (owner value 5) as a bitmap. The bitmap represents
the features that'll be enabled for the guest, as configured by
the user-space. Currently, this includes support only for
Paravirtualized time, represented by bit-0.

Signed-off-by: Raghavendra Rao Ananta <rananta@google.com>
Reviewed-by: Gavin Shan <gshan@redhat.com>
[maz: tidy-up bitmap values]
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220502233853.1233742-4-rananta@google.com

authored by

Raghavendra Rao Ananta and committed by
Marc Zyngier
428fd678 05714cab

+29 -3
+2
arch/arm64/include/asm/kvm_host.h
··· 105 105 * struct kvm_smccc_features: Descriptor of the hypercall services exposed to the guests 106 106 * 107 107 * @std_bmap: Bitmap of standard secure service calls 108 + * @std_hyp_bmap: Bitmap of standard hypervisor service calls 108 109 */ 109 110 struct kvm_smccc_features { 110 111 unsigned long std_bmap; 112 + unsigned long std_hyp_bmap; 111 113 }; 112 114 113 115 struct kvm_arch {
+7
arch/arm64/include/uapi/asm/kvm.h
··· 345 345 KVM_REG_ARM_STD_BMAP_BIT_COUNT, 346 346 }; 347 347 348 + #define KVM_REG_ARM_STD_HYP_BMAP KVM_REG_ARM_FW_FEAT_BMAP_REG(1) 349 + 350 + enum { 351 + KVM_REG_ARM_STD_HYP_BIT_PV_TIME = 0, 352 + KVM_REG_ARM_STD_HYP_BMAP_BIT_COUNT, 353 + }; 354 + 348 355 /* Device Control API: ARM VGIC */ 349 356 #define KVM_DEV_ARM_VGIC_GRP_ADDR 0 350 357 #define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1
+20 -3
arch/arm64/kvm/hypercalls.c
··· 11 11 12 12 #define KVM_ARM_SMCCC_STD_FEATURES \ 13 13 GENMASK(KVM_REG_ARM_STD_BMAP_BIT_COUNT - 1, 0) 14 + #define KVM_ARM_SMCCC_STD_HYP_FEATURES \ 15 + GENMASK(KVM_REG_ARM_STD_HYP_BMAP_BIT_COUNT - 1, 0) 14 16 15 17 static void kvm_ptp_get_time(struct kvm_vcpu *vcpu, u64 *val) 16 18 { ··· 73 71 */ 74 72 case ARM_SMCCC_VERSION_FUNC_ID: 75 73 case ARM_SMCCC_ARCH_FEATURES_FUNC_ID: 76 - case ARM_SMCCC_HV_PV_TIME_FEATURES: 77 - case ARM_SMCCC_HV_PV_TIME_ST: 78 74 case ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID: 79 75 case ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID: 80 76 case ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID: ··· 106 106 case ARM_SMCCC_TRNG_RND64: 107 107 return test_bit(KVM_REG_ARM_STD_BIT_TRNG_V1_0, 108 108 &smccc_feat->std_bmap); 109 + case ARM_SMCCC_HV_PV_TIME_FEATURES: 110 + case ARM_SMCCC_HV_PV_TIME_ST: 111 + return test_bit(KVM_REG_ARM_STD_HYP_BIT_PV_TIME, 112 + &smccc_feat->std_hyp_bmap); 109 113 default: 110 114 return kvm_hvc_call_default_allowed(func_id); 111 115 } ··· 117 113 118 114 int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) 119 115 { 116 + struct kvm_smccc_features *smccc_feat = &vcpu->kvm->arch.smccc_feat; 120 117 u32 func_id = smccc_get_function(vcpu); 121 118 u64 val[4] = {SMCCC_RET_NOT_SUPPORTED}; 122 119 u32 feature; ··· 181 176 } 182 177 break; 183 178 case ARM_SMCCC_HV_PV_TIME_FEATURES: 184 - val[0] = SMCCC_RET_SUCCESS; 179 + if (test_bit(KVM_REG_ARM_STD_HYP_BIT_PV_TIME, 180 + &smccc_feat->std_hyp_bmap)) 181 + val[0] = SMCCC_RET_SUCCESS; 185 182 break; 186 183 } 187 184 break; ··· 229 222 KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2, 230 223 KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_3, 231 224 KVM_REG_ARM_STD_BMAP, 225 + KVM_REG_ARM_STD_HYP_BMAP, 232 226 }; 233 227 234 228 void kvm_arm_init_hypercalls(struct kvm *kvm) ··· 237 229 struct kvm_smccc_features *smccc_feat = &kvm->arch.smccc_feat; 238 230 239 231 smccc_feat->std_bmap = KVM_ARM_SMCCC_STD_FEATURES; 232 + smccc_feat->std_hyp_bmap = KVM_ARM_SMCCC_STD_HYP_FEATURES; 240 233 } 241 234 242 235 int kvm_arm_get_fw_num_regs(struct kvm_vcpu *vcpu) ··· 326 317 case KVM_REG_ARM_STD_BMAP: 327 318 val = READ_ONCE(smccc_feat->std_bmap); 328 319 break; 320 + case KVM_REG_ARM_STD_HYP_BMAP: 321 + val = READ_ONCE(smccc_feat->std_hyp_bmap); 322 + break; 329 323 default: 330 324 return -ENOENT; 331 325 } ··· 350 338 case KVM_REG_ARM_STD_BMAP: 351 339 fw_reg_bmap = &smccc_feat->std_bmap; 352 340 fw_reg_features = KVM_ARM_SMCCC_STD_FEATURES; 341 + break; 342 + case KVM_REG_ARM_STD_HYP_BMAP: 343 + fw_reg_bmap = &smccc_feat->std_hyp_bmap; 344 + fw_reg_features = KVM_ARM_SMCCC_STD_HYP_FEATURES; 353 345 break; 354 346 default: 355 347 return -ENOENT; ··· 455 439 456 440 return 0; 457 441 case KVM_REG_ARM_STD_BMAP: 442 + case KVM_REG_ARM_STD_HYP_BMAP: 458 443 return kvm_arm_set_fw_reg_bmap(vcpu, reg->id, val); 459 444 default: 460 445 return -ENOENT;