Re: [PATCH v3 1/4] KVM: SVM: Get rid of set_ghcb_msr() and *ghcb_msr_bits() functions

From: Sean Christopherson
Date: Fri Sep 24 2021 - 16:05:07 EST


On Mon, Sep 13, 2021, Joerg Roedel wrote:
> static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm)
> @@ -2377,16 +2371,14 @@ static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm)
>
> switch (ghcb_info) {
> case GHCB_MSR_SEV_INFO_REQ:
> - set_ghcb_msr(svm, GHCB_MSR_SEV_INFO(GHCB_VERSION_MAX,
> - GHCB_VERSION_MIN,
> - sev_enc_bit));
> + svm->vmcb->control.ghcb_gpa = GHCB_MSR_SEV_INFO(GHCB_VERSION_MAX,
> + GHCB_VERSION_MIN,
> + sev_enc_bit);

Nit, "svm->vmcb->control." can be "control->".

With that fixed,

Reviewed-by: Sean Christopherson <seanjc@xxxxxxxxxx>

> break;
> case GHCB_MSR_CPUID_REQ: {
> u64 cpuid_fn, cpuid_reg, cpuid_value;
>
> - cpuid_fn = get_ghcb_msr_bits(svm,
> - GHCB_MSR_CPUID_FUNC_MASK,
> - GHCB_MSR_CPUID_FUNC_POS);
> + cpuid_fn = GHCB_MSR_CPUID_FN(control->ghcb_gpa);
>
> /* Initialize the registers needed by the CPUID intercept */
> vcpu->arch.regs[VCPU_REGS_RAX] = cpuid_fn;
> @@ -2398,9 +2390,8 @@ static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm)
> break;
> }
>
> - cpuid_reg = get_ghcb_msr_bits(svm,
> - GHCB_MSR_CPUID_REG_MASK,
> - GHCB_MSR_CPUID_REG_POS);
> + cpuid_reg = GHCB_MSR_CPUID_REG(control->ghcb_gpa);
> +
> if (cpuid_reg == 0)
> cpuid_value = vcpu->arch.regs[VCPU_REGS_RAX];
> else if (cpuid_reg == 1)
> @@ -2410,26 +2401,19 @@ static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm)
> else
> cpuid_value = vcpu->arch.regs[VCPU_REGS_RDX];
>
> - set_ghcb_msr_bits(svm, cpuid_value,
> - GHCB_MSR_CPUID_VALUE_MASK,
> - GHCB_MSR_CPUID_VALUE_POS);
> + svm->vmcb->control.ghcb_gpa = ghcb_msr_cpuid_resp(cpuid_reg, cpuid_value);
>
> - set_ghcb_msr_bits(svm, GHCB_MSR_CPUID_RESP,
> - GHCB_MSR_INFO_MASK,
> - GHCB_MSR_INFO_POS);

I don't mind using a helper instead of a macro (I completely agree the helper is
easier to read), but we should be consistent, i.e. get rid of GHCB_MSR_SEV_INFO.
And IMO that helper should handle the min/max version, not the callers. Add this
after patch 01 (modulo the above nit)?