We correctly default to SS when BP is used as a base in 16-bit address mode,
but we don't do that for 32-bit mode.

Fix by adjusting the default to SS when either ESP or EBP is used as the base
register.

Signed-off-by: Avi Kivity <[email protected]>
---
 arch/x86/kvm/emulate.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 5b6f99d..0088e2d 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -1077,8 +1077,12 @@ static int decode_modrm(struct x86_emulate_ctxt *ctxt,
 
                        if ((base_reg & 7) == 5 && ctxt->modrm_mod == 0)
                                modrm_ea += insn_fetch(s32, ctxt);
-                       else
+                       else {
                                modrm_ea += ctxt->regs[base_reg];
+                               if (base_reg == VCPU_REGS_RSP
+                                   || base_reg == VCPU_REGS_RBP)
+                                       ctxt->modrm_seg = VCPU_SREG_SS;
+                       }
                        if (index_reg != 4)
                                modrm_ea += ctxt->regs[index_reg] << scale;
                } else if ((ctxt->modrm_rm & 7) == 5 && ctxt->modrm_mod == 0) {
-- 
1.7.10.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to