Skip to content

Commit 1fc1d9b

Browse files
sean-jcgregkh
authored andcommitted
KVM: x86: Convert vcpu_run()'s immediate exit param into a generic bitmap
[ Upstream commit 2478b1b ] Convert kvm_x86_ops.vcpu_run()'s "force_immediate_exit" boolean parameter into an a generic bitmap so that similar "take action" information can be passed to vendor code without creating a pile of boolean parameters. This will allow dropping kvm_x86_ops.set_dr6() in favor of a new flag, and will also allow for adding similar functionality for re-loading debugctl in the active VMCS. Opportunistically massage the TDX WARN and comment to prepare for adding more run_flags, all of which are expected to be mutually exclusive with TDX, i.e. should be WARNed on. No functional change intended. Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]> [sean: drop TDX changes] Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent a831c3e commit 1fc1d9b

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,10 @@ static inline u16 kvm_lapic_irq_dest_mode(bool dest_mode_logical)
16271627
return dest_mode_logical ? APIC_DEST_LOGICAL : APIC_DEST_PHYSICAL;
16281628
}
16291629

1630+
enum kvm_x86_run_flags {
1631+
KVM_RUN_FORCE_IMMEDIATE_EXIT = BIT(0),
1632+
};
1633+
16301634
struct kvm_x86_ops {
16311635
const char *name;
16321636

@@ -1706,7 +1710,7 @@ struct kvm_x86_ops {
17061710

17071711
int (*vcpu_pre_run)(struct kvm_vcpu *vcpu);
17081712
enum exit_fastpath_completion (*vcpu_run)(struct kvm_vcpu *vcpu,
1709-
bool force_immediate_exit);
1713+
u64 run_flags);
17101714
int (*handle_exit)(struct kvm_vcpu *vcpu,
17111715
enum exit_fastpath_completion exit_fastpath);
17121716
int (*skip_emulated_instruction)(struct kvm_vcpu *vcpu);

arch/x86/kvm/svm/svm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4226,9 +4226,9 @@ static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu, bool spec_ctrl_in
42264226
guest_state_exit_irqoff();
42274227
}
42284228

4229-
static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu,
4230-
bool force_immediate_exit)
4229+
static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags)
42314230
{
4231+
bool force_immediate_exit = run_flags & KVM_RUN_FORCE_IMMEDIATE_EXIT;
42324232
struct vcpu_svm *svm = to_svm(vcpu);
42334233
bool spec_ctrl_intercepted = msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL);
42344234

arch/x86/kvm/vmx/vmx.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7353,8 +7353,9 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu,
73537353
guest_state_exit_irqoff();
73547354
}
73557355

7356-
fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu, bool force_immediate_exit)
7356+
fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags)
73577357
{
7358+
bool force_immediate_exit = run_flags & KVM_RUN_FORCE_IMMEDIATE_EXIT;
73587359
struct vcpu_vmx *vmx = to_vmx(vcpu);
73597360
unsigned long cr3, cr4;
73607361

arch/x86/kvm/vmx/x86_ops.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void vmx_vm_destroy(struct kvm *kvm);
2121
int vmx_vcpu_precreate(struct kvm *kvm);
2222
int vmx_vcpu_create(struct kvm_vcpu *vcpu);
2323
int vmx_vcpu_pre_run(struct kvm_vcpu *vcpu);
24-
fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu, bool force_immediate_exit);
24+
fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags);
2525
void vmx_vcpu_free(struct kvm_vcpu *vcpu);
2626
void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event);
2727
void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu);

arch/x86/kvm/x86.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10711,6 +10711,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
1071110711
dm_request_for_irq_injection(vcpu) &&
1071210712
kvm_cpu_accept_dm_intr(vcpu);
1071310713
fastpath_t exit_fastpath;
10714+
u64 run_flags;
1071410715

1071510716
bool req_immediate_exit = false;
1071610717

@@ -10955,8 +10956,11 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
1095510956
goto cancel_injection;
1095610957
}
1095710958

10958-
if (req_immediate_exit)
10959+
run_flags = 0;
10960+
if (req_immediate_exit) {
10961+
run_flags |= KVM_RUN_FORCE_IMMEDIATE_EXIT;
1095910962
kvm_make_request(KVM_REQ_EVENT, vcpu);
10963+
}
1096010964

1096110965
fpregs_assert_state_consistent();
1096210966
if (test_thread_flag(TIF_NEED_FPU_LOAD))
@@ -10992,8 +10996,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
1099210996
WARN_ON_ONCE((kvm_vcpu_apicv_activated(vcpu) != kvm_vcpu_apicv_active(vcpu)) &&
1099310997
(kvm_get_apic_mode(vcpu) != LAPIC_MODE_DISABLED));
1099410998

10995-
exit_fastpath = kvm_x86_call(vcpu_run)(vcpu,
10996-
req_immediate_exit);
10999+
exit_fastpath = kvm_x86_call(vcpu_run)(vcpu, run_flags);
1099711000
if (likely(exit_fastpath != EXIT_FASTPATH_REENTER_GUEST))
1099811001
break;
1099911002

@@ -11005,6 +11008,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
1100511008
break;
1100611009
}
1100711010

11011+
run_flags = 0;
11012+
1100811013
/* Note, VM-Exits that go down the "slow" path are accounted below. */
1100911014
++vcpu->stat.exits;
1101011015
}

0 commit comments

Comments
 (0)