]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: selftests: Add support for #DE exception fixup
authorSean Christopherson <seanjc@google.com>
Tue, 9 Sep 2025 20:28:32 +0000 (13:28 -0700)
committerSean Christopherson <seanjc@google.com>
Thu, 11 Sep 2025 15:55:44 +0000 (08:55 -0700)
Add support for handling #DE (divide error) exceptions in KVM selftests
so that the fastops test can verify KVM correctly handles #DE when
emulating DIV or IDIV on behalf of the guest.  Morph #DE to 0xff (i.e.
to -1) as a mostly-arbitrary vector to indicate #DE, so that '0' (the
real #DE vector) can still be used to indicate "no exception".

Link: https://lore.kernel.org/r/20250909202835.333554-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/include/x86/processor.h
tools/testing/selftests/kvm/lib/x86/processor.c

index 488d516c4f6f02c0e8dfa624fb88a0950e129646..efcc4b1de523a05c50453b6a2a76fd147ff2ec77 100644 (file)
@@ -1179,6 +1179,12 @@ struct idt_entry {
 void vm_install_exception_handler(struct kvm_vm *vm, int vector,
                        void (*handler)(struct ex_regs *));
 
+/*
+ * Exception fixup morphs #DE to an arbitrary magic vector so that '0' can be
+ * used to signal "no expcetion".
+ */
+#define KVM_MAGIC_DE_VECTOR 0xff
+
 /* If a toddler were to say "abracadabra". */
 #define KVM_EXCEPTION_MAGIC 0xabacadabaULL
 
index d4c19ac885a95a92da2816d62ee4dcf26a983308..3b63c99f7b9639e0de8e629ae9db7f5cb6d78d90 100644 (file)
@@ -557,7 +557,7 @@ static bool kvm_fixup_exception(struct ex_regs *regs)
                return false;
 
        if (regs->vector == DE_VECTOR)
-               return false;
+               regs->vector = KVM_MAGIC_DE_VECTOR;
 
        regs->rip = regs->r11;
        regs->r9 = regs->vector;