Skip to content

Commit 62dd913

Browse files
Maxim Levitskygregkh
authored andcommitted
KVM: x86: Route non-canonical checks in emulator through emulate_ops
[ Upstream commit 16ccade ] Add emulate_ops.is_canonical_addr() to perform (non-)canonical checks in the emulator, which will allow extending is_noncanonical_address() to support different flavors of canonical checks, e.g. for descriptor table bases vs. MSRs, without needing duplicate logic in the emulator. No functional change is intended. Signed-off-by: Maxim Levitsky <[email protected]> Link: https://lore.kernel.org/r/[email protected] [sean: separate from additional of flags, 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 94620f9 commit 62dd913

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

arch/x86/kvm/emulate.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ static inline u8 ctxt_virt_addr_bits(struct x86_emulate_ctxt *ctxt)
653653
static inline bool emul_is_noncanonical_address(u64 la,
654654
struct x86_emulate_ctxt *ctxt)
655655
{
656-
return !__is_canonical_address(la, ctxt_virt_addr_bits(ctxt));
656+
return !ctxt->ops->is_canonical_addr(ctxt, la);
657657
}
658658

659659
/*

arch/x86/kvm/kvm_emulate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ struct x86_emulate_ops {
235235

236236
gva_t (*get_untagged_addr)(struct x86_emulate_ctxt *ctxt, gva_t addr,
237237
unsigned int flags);
238+
239+
bool (*is_canonical_addr)(struct x86_emulate_ctxt *ctxt, gva_t addr);
238240
};
239241

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

arch/x86/kvm/x86.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8608,6 +8608,12 @@ static gva_t emulator_get_untagged_addr(struct x86_emulate_ctxt *ctxt,
86088608
addr, flags);
86098609
}
86108610

8611+
static bool emulator_is_canonical_addr(struct x86_emulate_ctxt *ctxt,
8612+
gva_t addr)
8613+
{
8614+
return !is_noncanonical_address(addr, emul_to_vcpu(ctxt));
8615+
}
8616+
86118617
static const struct x86_emulate_ops emulate_ops = {
86128618
.vm_bugged = emulator_vm_bugged,
86138619
.read_gpr = emulator_read_gpr,
@@ -8654,6 +8660,7 @@ static const struct x86_emulate_ops emulate_ops = {
86548660
.triple_fault = emulator_triple_fault,
86558661
.set_xcr = emulator_set_xcr,
86568662
.get_untagged_addr = emulator_get_untagged_addr,
8663+
.is_canonical_addr = emulator_is_canonical_addr,
86578664
};
86588665

86598666
static void toggle_interruptibility(struct kvm_vcpu *vcpu, u32 mask)

0 commit comments

Comments
 (0)