Skip to content

Commit 6c3d4b9

Browse files
committed
KVM: x86: Add a fastpath handler for INVD
Add a fastpath handler for INVD so that the common fastpath logic can be trivially tested on both Intel and AMD. Under KVM, INVD is always: (a) intercepted, (b) available to the guest, and (c) emulated as a nop, with no side effects. Combined with INVD not having any inputs or outputs, i.e. no register constraints, INVD is the perfect instruction for exercising KVM's fastpath as it can be inserted into practically any guest-side code stream. Link: https://lore.kernel.org/r/20250805190526.1453366-19-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 8bb8b60 commit 6c3d4b9

4 files changed

Lines changed: 14 additions & 0 deletions

File tree

arch/x86/kvm/svm/svm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4200,6 +4200,8 @@ static fastpath_t svm_exit_handlers_fastpath(struct kvm_vcpu *vcpu)
42004200
return handle_fastpath_set_msr_irqoff(vcpu);
42014201
case SVM_EXIT_HLT:
42024202
return handle_fastpath_hlt(vcpu);
4203+
case SVM_EXIT_INVD:
4204+
return handle_fastpath_invd(vcpu);
42034205
default:
42044206
break;
42054207
}

arch/x86/kvm/vmx/vmx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7175,6 +7175,8 @@ static fastpath_t vmx_exit_handlers_fastpath(struct kvm_vcpu *vcpu,
71757175
return handle_fastpath_preemption_timer(vcpu, force_immediate_exit);
71767176
case EXIT_REASON_HLT:
71777177
return handle_fastpath_hlt(vcpu);
7178+
case EXIT_REASON_INVD:
7179+
return handle_fastpath_invd(vcpu);
71787180
default:
71797181
return EXIT_FASTPATH_NONE;
71807182
}

arch/x86/kvm/x86.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,6 +2087,15 @@ int kvm_emulate_invd(struct kvm_vcpu *vcpu)
20872087
}
20882088
EXPORT_SYMBOL_GPL(kvm_emulate_invd);
20892089

2090+
fastpath_t handle_fastpath_invd(struct kvm_vcpu *vcpu)
2091+
{
2092+
if (!kvm_emulate_invd(vcpu))
2093+
return EXIT_FASTPATH_EXIT_USERSPACE;
2094+
2095+
return EXIT_FASTPATH_REENTER_GUEST;
2096+
}
2097+
EXPORT_SYMBOL_GPL(handle_fastpath_invd);
2098+
20902099
int kvm_handle_invalid_op(struct kvm_vcpu *vcpu)
20912100
{
20922101
kvm_queue_exception(vcpu, UD_VECTOR);

arch/x86/kvm/x86.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
439439
int emulation_type, void *insn, int insn_len);
440440
fastpath_t handle_fastpath_set_msr_irqoff(struct kvm_vcpu *vcpu);
441441
fastpath_t handle_fastpath_hlt(struct kvm_vcpu *vcpu);
442+
fastpath_t handle_fastpath_invd(struct kvm_vcpu *vcpu);
442443

443444
extern struct kvm_caps kvm_caps;
444445
extern struct kvm_host_values kvm_host;

0 commit comments

Comments
 (0)