Skip to content

Commit c0c82c2

Browse files
Maxim Levitskygregkh
authored andcommitted
KVM: x86: Add X86EMUL_F_MSR and X86EMUL_F_DT_LOAD to aid canonical checks
[ Upstream commit c534b37 ] Add emulation flags for MSR accesses and Descriptor Tables loads, and pass the new flags as appropriate to emul_is_noncanonical_address(). The flags will be used to perform the correct canonical check, as the type of access affects whether or not CR4.LA57 is consulted when determining the canonical bit. No functional change is intended. Signed-off-by: Maxim Levitsky <[email protected]> Link: https://lore.kernel.org/r/[email protected] [sean: split to separate patch, massage changelog] Signed-off-by: Sean Christopherson <[email protected]> Stable-dep-of: fa787ac ("KVM: x86/hyper-v: Skip non-canonical addresses during PV TLB flush") Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 62dd913 commit c0c82c2

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

arch/x86/kvm/emulate.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,10 @@ static inline u8 ctxt_virt_addr_bits(struct x86_emulate_ctxt *ctxt)
651651
}
652652

653653
static inline bool emul_is_noncanonical_address(u64 la,
654-
struct x86_emulate_ctxt *ctxt)
654+
struct x86_emulate_ctxt *ctxt,
655+
unsigned int flags)
655656
{
656-
return !ctxt->ops->is_canonical_addr(ctxt, la);
657+
return !ctxt->ops->is_canonical_addr(ctxt, la, flags);
657658
}
658659

659660
/*
@@ -1733,7 +1734,8 @@ static int __load_segment_descriptor(struct x86_emulate_ctxt *ctxt,
17331734
if (ret != X86EMUL_CONTINUE)
17341735
return ret;
17351736
if (emul_is_noncanonical_address(get_desc_base(&seg_desc) |
1736-
((u64)base3 << 32), ctxt))
1737+
((u64)base3 << 32), ctxt,
1738+
X86EMUL_F_DT_LOAD))
17371739
return emulate_gp(ctxt, err_code);
17381740
}
17391741

@@ -2516,8 +2518,8 @@ static int em_sysexit(struct x86_emulate_ctxt *ctxt)
25162518
ss_sel = cs_sel + 8;
25172519
cs.d = 0;
25182520
cs.l = 1;
2519-
if (emul_is_noncanonical_address(rcx, ctxt) ||
2520-
emul_is_noncanonical_address(rdx, ctxt))
2521+
if (emul_is_noncanonical_address(rcx, ctxt, 0) ||
2522+
emul_is_noncanonical_address(rdx, ctxt, 0))
25212523
return emulate_gp(ctxt, 0);
25222524
break;
25232525
}
@@ -3494,7 +3496,8 @@ static int em_lgdt_lidt(struct x86_emulate_ctxt *ctxt, bool lgdt)
34943496
if (rc != X86EMUL_CONTINUE)
34953497
return rc;
34963498
if (ctxt->mode == X86EMUL_MODE_PROT64 &&
3497-
emul_is_noncanonical_address(desc_ptr.address, ctxt))
3499+
emul_is_noncanonical_address(desc_ptr.address, ctxt,
3500+
X86EMUL_F_DT_LOAD))
34983501
return emulate_gp(ctxt, 0);
34993502
if (lgdt)
35003503
ctxt->ops->set_gdt(ctxt, &desc_ptr);

arch/x86/kvm/kvm_emulate.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ struct x86_instruction_info {
9494
#define X86EMUL_F_FETCH BIT(1)
9595
#define X86EMUL_F_IMPLICIT BIT(2)
9696
#define X86EMUL_F_INVLPG BIT(3)
97+
#define X86EMUL_F_MSR BIT(4)
98+
#define X86EMUL_F_DT_LOAD BIT(5)
9799

98100
struct x86_emulate_ops {
99101
void (*vm_bugged)(struct x86_emulate_ctxt *ctxt);
@@ -236,7 +238,8 @@ struct x86_emulate_ops {
236238
gva_t (*get_untagged_addr)(struct x86_emulate_ctxt *ctxt, gva_t addr,
237239
unsigned int flags);
238240

239-
bool (*is_canonical_addr)(struct x86_emulate_ctxt *ctxt, gva_t addr);
241+
bool (*is_canonical_addr)(struct x86_emulate_ctxt *ctxt, gva_t addr,
242+
unsigned int flags);
240243
};
241244

242245
/* Type, address-of, and value of an instruction's operand. */

arch/x86/kvm/x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8609,7 +8609,7 @@ static gva_t emulator_get_untagged_addr(struct x86_emulate_ctxt *ctxt,
86098609
}
86108610

86118611
static bool emulator_is_canonical_addr(struct x86_emulate_ctxt *ctxt,
8612-
gva_t addr)
8612+
gva_t addr, unsigned int flags)
86138613
{
86148614
return !is_noncanonical_address(addr, emul_to_vcpu(ctxt));
86158615
}

0 commit comments

Comments
 (0)