Skip to content

Commit dd307d0

Browse files
committed
KVM: x86: emulate sldt and str
These are needed to handle the descriptor table vmexits when emulating UMIP. Reviewed-by: Wanpeng Li <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent ae3e61e commit dd307d0

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

arch/x86/kvm/emulate.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3633,17 +3633,27 @@ static int em_rdmsr(struct x86_emulate_ctxt *ctxt)
36333633
return X86EMUL_CONTINUE;
36343634
}
36353635

3636-
static int em_mov_rm_sreg(struct x86_emulate_ctxt *ctxt)
3636+
static int em_store_sreg(struct x86_emulate_ctxt *ctxt, int segment)
36373637
{
3638-
if (ctxt->modrm_reg > VCPU_SREG_GS)
3639-
return emulate_ud(ctxt);
3638+
if (segment > VCPU_SREG_GS &&
3639+
(ctxt->ops->get_cr(ctxt, 4) & X86_CR4_UMIP) &&
3640+
ctxt->ops->cpl(ctxt) > 0)
3641+
return emulate_gp(ctxt, 0);
36403642

3641-
ctxt->dst.val = get_segment_selector(ctxt, ctxt->modrm_reg);
3643+
ctxt->dst.val = get_segment_selector(ctxt, segment);
36423644
if (ctxt->dst.bytes == 4 && ctxt->dst.type == OP_MEM)
36433645
ctxt->dst.bytes = 2;
36443646
return X86EMUL_CONTINUE;
36453647
}
36463648

3649+
static int em_mov_rm_sreg(struct x86_emulate_ctxt *ctxt)
3650+
{
3651+
if (ctxt->modrm_reg > VCPU_SREG_GS)
3652+
return emulate_ud(ctxt);
3653+
3654+
return em_store_sreg(ctxt, ctxt->modrm_reg);
3655+
}
3656+
36473657
static int em_mov_sreg_rm(struct x86_emulate_ctxt *ctxt)
36483658
{
36493659
u16 sel = ctxt->src.val;
@@ -3659,6 +3669,11 @@ static int em_mov_sreg_rm(struct x86_emulate_ctxt *ctxt)
36593669
return load_segment_descriptor(ctxt, sel, ctxt->modrm_reg);
36603670
}
36613671

3672+
static int em_sldt(struct x86_emulate_ctxt *ctxt)
3673+
{
3674+
return em_store_sreg(ctxt, VCPU_SREG_LDTR);
3675+
}
3676+
36623677
static int em_lldt(struct x86_emulate_ctxt *ctxt)
36633678
{
36643679
u16 sel = ctxt->src.val;
@@ -3668,6 +3683,11 @@ static int em_lldt(struct x86_emulate_ctxt *ctxt)
36683683
return load_segment_descriptor(ctxt, sel, VCPU_SREG_LDTR);
36693684
}
36703685

3686+
static int em_str(struct x86_emulate_ctxt *ctxt)
3687+
{
3688+
return em_store_sreg(ctxt, VCPU_SREG_TR);
3689+
}
3690+
36713691
static int em_ltr(struct x86_emulate_ctxt *ctxt)
36723692
{
36733693
u16 sel = ctxt->src.val;
@@ -4372,8 +4392,8 @@ static const struct opcode group5[] = {
43724392
};
43734393

43744394
static const struct opcode group6[] = {
4375-
DI(Prot | DstMem, sldt),
4376-
DI(Prot | DstMem, str),
4395+
II(Prot | DstMem, em_sldt, sldt),
4396+
II(Prot | DstMem, em_str, str),
43774397
II(Prot | Priv | SrcMem16, em_lldt, lldt),
43784398
II(Prot | Priv | SrcMem16, em_ltr, ltr),
43794399
N, N, N, N,

0 commit comments

Comments
 (0)