Commit a807b78a authored by Emanuele Giuseppe Esposito's avatar Emanuele Giuseppe Esposito Committed by Paolo Bonzini

kvm: vmx: Add IA32_FLUSH_CMD guest support

Expose IA32_FLUSH_CMD to the guest if the guest CPUID enumerates
support for this MSR. As with IA32_PRED_CMD, permission for
unintercepted writes to this MSR will be granted to the guest after
the first non-zero write.
Co-developed-by: default avatarJim Mattson <jmattson@google.com>
Signed-off-by: default avatarJim Mattson <jmattson@google.com>
Signed-off-by: default avatarEmanuele Giuseppe Esposito <eesposit@redhat.com>
Message-Id: <20230201132905.549148-2-eesposit@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent fbc722aa
...@@ -654,6 +654,9 @@ static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu, ...@@ -654,6 +654,9 @@ static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu,
nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0, nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0,
MSR_IA32_PRED_CMD, MSR_TYPE_W); MSR_IA32_PRED_CMD, MSR_TYPE_W);
nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0,
MSR_IA32_FLUSH_CMD, MSR_TYPE_W);
kvm_vcpu_unmap(vcpu, &vmx->nested.msr_bitmap_map, false); kvm_vcpu_unmap(vcpu, &vmx->nested.msr_bitmap_map, false);
vmx->nested.force_msr_bitmap_recalc = false; vmx->nested.force_msr_bitmap_recalc = false;
......
...@@ -2133,6 +2133,39 @@ static u64 vmx_get_supported_debugctl(struct kvm_vcpu *vcpu, bool host_initiated ...@@ -2133,6 +2133,39 @@ static u64 vmx_get_supported_debugctl(struct kvm_vcpu *vcpu, bool host_initiated
return debugctl; return debugctl;
} }
static int vmx_set_msr_ia32_cmd(struct kvm_vcpu *vcpu,
struct msr_data *msr_info,
bool guest_has_feat, u64 cmd,
int x86_feature_bit)
{
if (!msr_info->host_initiated && !guest_has_feat)
return 1;
if (!(msr_info->data & ~cmd))
return 1;
if (!boot_cpu_has(x86_feature_bit))
return 1;
if (!msr_info->data)
return 0;
wrmsrl(msr_info->index, cmd);
/*
* For non-nested:
* When it's written (to non-zero) for the first time, pass
* it through.
*
* For nested:
* The handling of the MSR bitmap for L2 guests is done in
* nested_vmx_prepare_msr_bitmap. We should not touch the
* vmcs02.msr_bitmap here since it gets completely overwritten
* in the merging.
*/
vmx_disable_intercept_for_msr(vcpu, msr_info->index, MSR_TYPE_W);
return 0;
}
/* /*
* Writes msr value into the appropriate "register". * Writes msr value into the appropriate "register".
* Returns 0 on success, non-0 otherwise. * Returns 0 on success, non-0 otherwise.
...@@ -2286,31 +2319,16 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) ...@@ -2286,31 +2319,16 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
return 1; return 1;
goto find_uret_msr; goto find_uret_msr;
case MSR_IA32_PRED_CMD: case MSR_IA32_PRED_CMD:
if (!msr_info->host_initiated && ret = vmx_set_msr_ia32_cmd(vcpu, msr_info,
!guest_has_pred_cmd_msr(vcpu)) guest_has_pred_cmd_msr(vcpu),
return 1; PRED_CMD_IBPB,
X86_FEATURE_IBPB);
if (data & ~PRED_CMD_IBPB) break;
return 1; case MSR_IA32_FLUSH_CMD:
if (!boot_cpu_has(X86_FEATURE_IBPB)) ret = vmx_set_msr_ia32_cmd(vcpu, msr_info,
return 1; guest_cpuid_has(vcpu, X86_FEATURE_FLUSH_L1D),
if (!data) L1D_FLUSH,
break; X86_FEATURE_FLUSH_L1D);
wrmsrl(MSR_IA32_PRED_CMD, PRED_CMD_IBPB);
/*
* For non-nested:
* When it's written (to non-zero) for the first time, pass
* it through.
*
* For nested:
* The handling of the MSR bitmap for L2 guests is done in
* nested_vmx_prepare_msr_bitmap. We should not touch the
* vmcs02.msr_bitmap here since it gets completely overwritten
* in the merging.
*/
vmx_disable_intercept_for_msr(vcpu, MSR_IA32_PRED_CMD, MSR_TYPE_W);
break; break;
case MSR_IA32_CR_PAT: case MSR_IA32_CR_PAT:
if (!kvm_pat_valid(data)) if (!kvm_pat_valid(data))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment