Skip to content

Commit 7b39b6c

Browse files
committed
KVM: selftests: Add support for #DE exception fixup
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>
1 parent 6650711 commit 7b39b6c

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

tools/testing/selftests/kvm/include/x86/processor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,12 @@ struct idt_entry {
11791179
void vm_install_exception_handler(struct kvm_vm *vm, int vector,
11801180
void (*handler)(struct ex_regs *));
11811181

1182+
/*
1183+
* Exception fixup morphs #DE to an arbitrary magic vector so that '0' can be
1184+
* used to signal "no expcetion".
1185+
*/
1186+
#define KVM_MAGIC_DE_VECTOR 0xff
1187+
11821188
/* If a toddler were to say "abracadabra". */
11831189
#define KVM_EXCEPTION_MAGIC 0xabacadabaULL
11841190

tools/testing/selftests/kvm/lib/x86/processor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ static bool kvm_fixup_exception(struct ex_regs *regs)
557557
return false;
558558

559559
if (regs->vector == DE_VECTOR)
560-
return false;
560+
regs->vector = KVM_MAGIC_DE_VECTOR;
561561

562562
regs->rip = regs->r11;
563563
regs->r9 = regs->vector;

0 commit comments

Comments
 (0)