]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: x86: Route non-canonical checks in emulator through emulate_ops
authorMaxim Levitsky <mlevitsk@redhat.com>
Wed, 23 Jul 2025 15:14:13 +0000 (11:14 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 1 Aug 2025 08:48:46 +0000 (09:48 +0100)
[ Upstream commit 16ccadefa295af434ca296e566f078223ecd79ca ]

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 <mlevitsk@redhat.com>
Link: https://lore.kernel.org/r/20240906221824.491834-3-mlevitsk@redhat.com
[sean: separate from additional of flags, massage changelog]
Signed-off-by: Sean Christopherson <seanjc@google.com>
Stable-dep-of: fa787ac07b3c ("KVM: x86/hyper-v: Skip non-canonical addresses during PV TLB flush")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/emulate.c
arch/x86/kvm/kvm_emulate.h
arch/x86/kvm/x86.c

index e72aed25d72126ae18e328cf2b014687972313e6..3ce83f57d267d7115874f5f2c42652e33a43097c 100644 (file)
@@ -653,7 +653,7 @@ static inline u8 ctxt_virt_addr_bits(struct x86_emulate_ctxt *ctxt)
 static inline bool emul_is_noncanonical_address(u64 la,
                                                struct x86_emulate_ctxt *ctxt)
 {
-       return !__is_canonical_address(la, ctxt_virt_addr_bits(ctxt));
+       return !ctxt->ops->is_canonical_addr(ctxt, la);
 }
 
 /*
index 55a18e2f2dcd999cc4b150f899e25fac73e3f963..1b1843ff210fd201f9083e55489c82a39ea4e6ff 100644 (file)
@@ -235,6 +235,8 @@ struct x86_emulate_ops {
 
        gva_t (*get_untagged_addr)(struct x86_emulate_ctxt *ctxt, gva_t addr,
                                   unsigned int flags);
+
+       bool (*is_canonical_addr)(struct x86_emulate_ctxt *ctxt, gva_t addr);
 };
 
 /* Type, address-of, and value of an instruction's operand. */
index 27d0d6fdd418eeeef694b3fa945924968635e83f..37681edc5638b5057557883d027bb1d9f5dae994 100644 (file)
@@ -8608,6 +8608,12 @@ static gva_t emulator_get_untagged_addr(struct x86_emulate_ctxt *ctxt,
                                               addr, flags);
 }
 
+static bool emulator_is_canonical_addr(struct x86_emulate_ctxt *ctxt,
+                                      gva_t addr)
+{
+       return !is_noncanonical_address(addr, emul_to_vcpu(ctxt));
+}
+
 static const struct x86_emulate_ops emulate_ops = {
        .vm_bugged           = emulator_vm_bugged,
        .read_gpr            = emulator_read_gpr,
@@ -8654,6 +8660,7 @@ static const struct x86_emulate_ops emulate_ops = {
        .triple_fault        = emulator_triple_fault,
        .set_xcr             = emulator_set_xcr,
        .get_untagged_addr   = emulator_get_untagged_addr,
+       .is_canonical_addr   = emulator_is_canonical_addr,
 };
 
 static void toggle_interruptibility(struct kvm_vcpu *vcpu, u32 mask)