Skip to content

Commit 16ccade

Browse files
Maxim Levitskysean-jc
authored andcommitted
KVM: x86: Route non-canonical checks in emulator through emulate_ops
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]>
1 parent e52ad1d commit 16ccade

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
@@ -8619,6 +8619,12 @@ static gva_t emulator_get_untagged_addr(struct x86_emulate_ctxt *ctxt,
86198619
addr, flags);
86208620
}
86218621

8622+
static bool emulator_is_canonical_addr(struct x86_emulate_ctxt *ctxt,
8623+
gva_t addr)
8624+
{
8625+
return !is_noncanonical_address(addr, emul_to_vcpu(ctxt));
8626+
}
8627+
86228628
static const struct x86_emulate_ops emulate_ops = {
86238629
.vm_bugged = emulator_vm_bugged,
86248630
.read_gpr = emulator_read_gpr,
@@ -8665,6 +8671,7 @@ static const struct x86_emulate_ops emulate_ops = {
86658671
.triple_fault = emulator_triple_fault,
86668672
.set_xcr = emulator_set_xcr,
86678673
.get_untagged_addr = emulator_get_untagged_addr,
8674+
.is_canonical_addr = emulator_is_canonical_addr,
86688675
};
86698676

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

0 commit comments

Comments
 (0)