RE: [PATCH v2 09/25] KVM: VMX: Switch FRED RSP0 between host and guest

From: Li, Xin3
Date: Fri Apr 19 2024 - 12:37:40 EST


> >+ if (unlikely(vmx->msr_host_fred_rsp0 == 0))
> >+ vmx->msr_host_fred_rsp0 =
> read_msr(MSR_IA32_FRED_RSP0);
>
> can we just drop this and use "(unsigned long)task_stack_page(current) +
> THREAD_SIZE"
> as host fred rsp0?

I thought about it, however, don't see a strong reason that it's better,
i.e., is RDMSR slower than reading 'stack' from current task_struct?

>
> >+ wrmsrl(MSR_IA32_FRED_RSP0, vmx->msr_guest_fred_rsp0);
>
> any reason to not use wrmsrns?

Good call!


> >+ }
> > #else
> > savesegment(fs, fs_sel);
> > savesegment(gs, gs_sel);
> >@@ -1381,6 +1391,11 @@ static void vmx_prepare_switch_to_host(struct
> vcpu_vmx *vmx)
> > invalidate_tss_limit();
> > #ifdef CONFIG_X86_64
> > wrmsrl(MSR_KERNEL_GS_BASE, vmx->msr_host_kernel_gs_base);
> >+
> >+ if (guest_can_use(&vmx->vcpu, X86_FEATURE_FRED)) {
> >+ vmx->msr_guest_fred_rsp0 = read_msr(MSR_IA32_FRED_RSP0);
> >+ wrmsrl(MSR_IA32_FRED_RSP0, vmx->msr_host_fred_rsp0);
>
> same question.

Will do!

Thanks!
Xin