Re: [PATCH 09/15] KVM: VMX: Use flag to indicate "active" uret MSRs instead of sorting list

From: Reiji Watanabe
Date: Fri May 07 2021 - 23:32:17 EST


> -static void vmx_setup_uret_msr(struct vcpu_vmx *vmx, unsigned int msr)
> +static void vmx_setup_uret_msr(struct vcpu_vmx *vmx, unsigned int msr,
> + bool load_into_hardware)
> {
> - struct vmx_uret_msr tmp;
> - int from, to;
> + struct vmx_uret_msr *uret_msr;
>
> - from = __vmx_find_uret_msr(vmx, msr);
> - if (from < 0)
> + uret_msr = vmx_find_uret_msr(vmx, msr);
> + if (!uret_msr)
> return;
> - to = vmx->nr_active_uret_msrs++;
>
> - tmp = vmx->guest_uret_msrs[to];
> - vmx->guest_uret_msrs[to] = vmx->guest_uret_msrs[from];
> - vmx->guest_uret_msrs[from] = tmp;
> + uret_msr->load_into_hardware = load_into_hardware;
> }
>
> /*
> @@ -1785,30 +1781,36 @@ static void vmx_setup_uret_msr(struct vcpu_vmx *vmx, unsigned int msr)
> */
> static void setup_msrs(struct vcpu_vmx *vmx)
> {
> - vmx->guest_uret_msrs_loaded = false;
> - vmx->nr_active_uret_msrs = 0;
> #ifdef CONFIG_X86_64
> + bool load_syscall_msrs;
> +
> /*
> * The SYSCALL MSRs are only needed on long mode guests, and only
> * when EFER.SCE is set.
> */
> - if (is_long_mode(&vmx->vcpu) && (vmx->vcpu.arch.efer & EFER_SCE)) {
> - vmx_setup_uret_msr(vmx, MSR_STAR);
> - vmx_setup_uret_msr(vmx, MSR_LSTAR);
> - vmx_setup_uret_msr(vmx, MSR_SYSCALL_MASK);
> - }
> + load_syscall_msrs = is_long_mode(&vmx->vcpu) &&
> + (vmx->vcpu.arch.efer & EFER_SCE);
> +
> + vmx_setup_uret_msr(vmx, MSR_STAR, load_syscall_msrs);
> + vmx_setup_uret_msr(vmx, MSR_LSTAR, load_syscall_msrs);
> + vmx_setup_uret_msr(vmx, MSR_SYSCALL_MASK, load_syscall_msrs);
> #endif
> - if (update_transition_efer(vmx))
> - vmx_setup_uret_msr(vmx, MSR_EFER);
> + vmx_setup_uret_msr(vmx, MSR_EFER, update_transition_efer(vmx));
>
> - if (guest_cpuid_has(&vmx->vcpu, X86_FEATURE_RDTSCP) ||
> - guest_cpuid_has(&vmx->vcpu, X86_FEATURE_RDPID))
> - vmx_setup_uret_msr(vmx, MSR_TSC_AUX);
> + vmx_setup_uret_msr(vmx, MSR_TSC_AUX,
> + guest_cpuid_has(&vmx->vcpu, X86_FEATURE_RDTSCP) ||
> + guest_cpuid_has(&vmx->vcpu, X86_FEATURE_RDPID));

Shouldn't vmx_setup_uret_msr(,MSR_TSC_AUX,) be called to update
the new flag load_into_hardware for MSR_TSC_AUX when CPUID
(X86_FEATURE_RDTSCP/X86_FEATURE_RDPID) of the vCPU is updated ?


Thanks,
Reiji