Skip to contentSkip to conversation

kvm: Emulate MOVBE

PATCH Borislav Petkov 2 participants 2 messages Jul 15, 2013 – Jul 16, 2013 10 messages not in the archive KVM

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw

Fix kvm ML already.

Quoted 37 lines · Borislav Petkov
Quoted 7 lines · Gleb Natapov

KVM does not enables emulation because QEMU called KVM_GET_EMULATED_CPUID. KVM enables emulation because QEMU sets MOVBE bit in a guest visible cpuid using KVM_SET_CPUID2. QEMU does that either because host and cpu model QEMU uses both have it, or because user asked for it specifically and KVM reports that it can be emulated. Why emulator should care what is the reason MOVBE is enabled?

Ok, I think I know what you mean:

arch/x86/kvm/emulate.c +8 -1
index 6fe5a838116a..c963ff8e43dd 100644
@@ -3147,10 +3147,18 @@ static int em_mov(struct x86_emulate_ctxt *ctxt)
        return X86EMUL_CONTINUE;
 }
 
+#undef F
+#define F(x) bit(X86_FEATURE_##x)
+
 static int em_movbe(struct x86_emulate_ctxt *ctxt)
 {
+       u32 ebx, ecx, edx, eax = 1;
        u16 tmp;
 
+       ctxt->ops->get_cpuid(ctxt, &eax, &ebx, &ecx, &edx);
+       if (!(ecx & F(MOVBE)))
+               return X86EMUL_PROPAGATE_FAULT;
+
        switch (ctxt->op_bytes) {
        case 2:
                /*
---

Right?

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--
#11 lore raw
Quoted 39 lines · Borislav Petkov

Fix kvm ML already.

Quoted 36 lines · Borislav Petkov
Quoted 7 lines · Gleb Natapov

KVM does not enables emulation because QEMU called KVM_GET_EMULATED_CPUID. KVM enables emulation because QEMU sets MOVBE bit in a guest visible cpuid using KVM_SET_CPUID2. QEMU does that either because host and cpu model QEMU uses both have it, or because user asked for it specifically and KVM reports that it can be emulated. Why emulator should care what is the reason MOVBE is enabled?

Ok, I think I know what you mean:

arch/x86/kvm/emulate.c +8 -1
index 6fe5a838116a..c963ff8e43dd 100644
@@ -3147,10 +3147,18 @@ static int em_mov(struct x86_emulate_ctxt *ctxt)
        return X86EMUL_CONTINUE;
 }
 
+#undef F
+#define F(x) bit(X86_FEATURE_##x)
+
 static int em_movbe(struct x86_emulate_ctxt *ctxt)
 {
+       u32 ebx, ecx, edx, eax = 1;
        u16 tmp;
 
+       ctxt->ops->get_cpuid(ctxt, &eax, &ebx, &ecx, &edx);
+       if (!(ecx & F(MOVBE)))
+               return X86EMUL_PROPAGATE_FAULT;
+
        switch (ctxt->op_bytes) {
        case 2:
                /*
---
Quoted 2 lines
Quoted 1 line

Right?

Right, just replace return X86EMUL_PROPAGATE_FAULT; with return emulate_ud(ctxt);

--
Gleb.