diff mbox

i386/kvm: mask MSR_IA32_BNDCFGS if MPX is not enabled in guest cpuid

Message ID 20170703152338.20024-1-haozhong.zhang@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Haozhong Zhang July 3, 2017, 3:23 p.m. UTC
Otherwise, QEMU on a host with MPX support will try to set guest
MSR_IA32_BNDCFGS although guest MPX is not enabled, and result in
abort.

For example,
   qemu-system-x86_64 -enable-kvm -cpu qemu64,-mpx ...
aborts with messages:
   qemu-system-x86_64: error: failed to set MSR 0xd90 to 0x0
   qemu-system-x86_64: /root/qemu.git/target/i386/kvm.c:1832: kvm_put_msrs: Assertion `ret == cpu->kvm_msr_buf->nmsrs' failed

Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
---
 target/i386/kvm.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Paolo Bonzini July 3, 2017, 3:45 p.m. UTC | #1
On 03/07/2017 17:23, Haozhong Zhang wrote:
> Otherwise, QEMU on a host with MPX support will try to set guest
> MSR_IA32_BNDCFGS although guest MPX is not enabled, and result in
> abort.
> 
> For example,
>    qemu-system-x86_64 -enable-kvm -cpu qemu64,-mpx ...
> aborts with messages:
>    qemu-system-x86_64: error: failed to set MSR 0xd90 to 0x0
>    qemu-system-x86_64: /root/qemu.git/target/i386/kvm.c:1832: kvm_put_msrs: Assertion `ret == cpu->kvm_msr_buf->nmsrs' failed

I think the fix should be in KVM, allowing BNDCFGS = 0 if
host_initiated, even if MPX is not enabled.

Paolo

> Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
> ---
>  target/i386/kvm.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/target/i386/kvm.c b/target/i386/kvm.c
> index ee36502789..7b3a310a31 100644
> --- a/target/i386/kvm.c
> +++ b/target/i386/kvm.c
> @@ -943,6 +943,11 @@ int kvm_arch_init_vcpu(CPUState *cs)
>          has_msr_mcg_ext_ctl = has_msr_feature_control = true;
>      }
>  
> +    if (has_msr_bndcfgs) {
> +        c = cpuid_find_entry(&cpuid_data.cpuid, 7, 0);
> +        has_msr_bndcfgs = c && (c->ebx & CPUID_7_0_EBX_MPX);
> +    }
> +
>      if (!env->user_tsc_khz) {
>          if ((env->features[FEAT_8000_0007_EDX] & CPUID_APM_INVTSC) &&
>              invtsc_mig_blocker == NULL) {
>
Haozhong Zhang July 4, 2017, 2:30 a.m. UTC | #2
On 07/03/17 17:45 +0200, Paolo Bonzini wrote:
> 
> 
> On 03/07/2017 17:23, Haozhong Zhang wrote:
> > Otherwise, QEMU on a host with MPX support will try to set guest
> > MSR_IA32_BNDCFGS although guest MPX is not enabled, and result in
> > abort.
> > 
> > For example,
> >    qemu-system-x86_64 -enable-kvm -cpu qemu64,-mpx ...
> > aborts with messages:
> >    qemu-system-x86_64: error: failed to set MSR 0xd90 to 0x0
> >    qemu-system-x86_64: /root/qemu.git/target/i386/kvm.c:1832: kvm_put_msrs: Assertion `ret == cpu->kvm_msr_buf->nmsrs' failed
> 
> I think the fix should be in KVM, allowing BNDCFGS = 0 if
> host_initiated, even if MPX is not enabled.
> 

Agree. I've sent a KVM patch to fix this issue.

Thanks,
Haozhong
diff mbox

Patch

diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index ee36502789..7b3a310a31 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -943,6 +943,11 @@  int kvm_arch_init_vcpu(CPUState *cs)
         has_msr_mcg_ext_ctl = has_msr_feature_control = true;
     }
 
+    if (has_msr_bndcfgs) {
+        c = cpuid_find_entry(&cpuid_data.cpuid, 7, 0);
+        has_msr_bndcfgs = c && (c->ebx & CPUID_7_0_EBX_MPX);
+    }
+
     if (!env->user_tsc_khz) {
         if ((env->features[FEAT_8000_0007_EDX] & CPUID_APM_INVTSC) &&
             invtsc_mig_blocker == NULL) {