# Re: \[PATCH v5 7/7\] KVM: SVM: hyper-v: Direct Virtual Flush support

- From: Vineeth Pillai \<hidden\>
- Date: 2021-06-15 14:25:20 
- List: linux-hyperv
- Page: https://ratatoskr.run/linux-hyperv/2021/06/1415000
- Thread: https://ratatoskr.run/kvm/2021/06/1401340/t.md

```text
Hi Vitaly,
>> +
>> +static inline void svm_hv_update_vp_id(struct vmcb *vmcb,
>> +		struct kvm_vcpu *vcpu)
>> +{
>> +	struct hv_enlightenments *hve =
>> +		(struct hv_enlightenments *)vmcb->control.reserved_sw;
>> +
>> +	if (hve->hv_vp_id != to_hv_vcpu(vcpu)->vp_index) {
>> +		hve->hv_vp_id = to_hv_vcpu(vcpu)->vp_index;
>> +		vmcb_mark_dirty(vmcb, VMCB_HV_NESTED_ENLIGHTENMENTS);
>> +	}
> This blows up in testing when no Hyper-V context was created on a vCPU,
> e.g. when running KVM selftests (to_hv_vcpu(vcpu) is NULL when no
> Hyper-V emulation features were requested on a vCPU but
> svm_hv_update_vp_id() is called unconditionally by svm_vcpu_run()).
>
> I'll be sending a patch to fix the immediate issue but I was wondering
> why we need to call svm_hv_update_vp_id() from svm_vcpu_run() as VP
> index is unlikely to change; we can probably just call it from
> kvm_hv_set_msr() instead.
Thanks a lot for catching this.

I think you are right, updating at kvm_hv_set_msr() makes sense. I was
following the vmx logic where it also sets the vp_id in vmx_vcpu_run. But it
calls a wrapper "kvm_hv_get_vpindex" which actually checks if hv_vcpu is not
null before the assignment. I should have used that instead, my mistake.
I will look a bit more into it and send out a patch for vmx and svm after little
more investigation.

Thanks,
Vineeth

```
