Skip to content

Commit af52f5a

Browse files
sean-jcbonzini
authored andcommitted
KVM: SVM: Use kvm_vcpu_is_blocking() in AVIC load to handle preemption
Use kvm_vcpu_is_blocking() to determine whether or not the vCPU should be marked running during avic_vcpu_load(). Drop avic_is_running, which really should have been named "vcpu_is_not_blocking", as it tracked if the vCPU was blocking, not if it was actually running, e.g. it was set during svm_create_vcpu() when the vCPU was obviously not running. This is technically a teeny tiny functional change, as the vCPU will be marked IsRunning=1 on being reloaded if the vCPU is preempted between svm_vcpu_blocking() and prepare_to_rcuwait(). But that's a benign change as the vCPU will be marked IsRunning=0 when KVM voluntarily schedules out the vCPU. Signed-off-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent e422b88 commit af52f5a

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

arch/x86/kvm/svm/avic.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ void avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
975975
{
976976
u64 entry;
977977
/* ID = 0xff (broadcast), ID > 0xff (reserved) */
978+
bool is_blocking = kvm_vcpu_is_blocking(vcpu);
978979
int h_physical_id = kvm_cpu_get_apicid(cpu);
979980
struct vcpu_svm *svm = to_svm(vcpu);
980981

@@ -992,12 +993,17 @@ void avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
992993
entry |= (h_physical_id & AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK);
993994

994995
entry &= ~AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK;
995-
if (svm->avic_is_running)
996+
997+
/*
998+
* Don't mark the vCPU as running if its blocking, i.e. if the vCPU is
999+
* preempted after svm_vcpu_blocking() but before KVM voluntarily
1000+
* schedules out the vCPU.
1001+
*/
1002+
if (!is_blocking)
9961003
entry |= AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK;
9971004

9981005
WRITE_ONCE(*(svm->avic_physical_id_cache), entry);
999-
avic_update_iommu_vcpu_affinity(vcpu, h_physical_id,
1000-
svm->avic_is_running);
1006+
avic_update_iommu_vcpu_affinity(vcpu, h_physical_id, !is_blocking);
10011007
}
10021008

10031009
void avic_vcpu_put(struct kvm_vcpu *vcpu)
@@ -1018,11 +1024,9 @@ void avic_vcpu_put(struct kvm_vcpu *vcpu)
10181024
*/
10191025
static void avic_set_running(struct kvm_vcpu *vcpu, bool is_run)
10201026
{
1021-
struct vcpu_svm *svm = to_svm(vcpu);
10221027
int cpu = get_cpu();
10231028

10241029
WARN_ON(cpu != vcpu->cpu);
1025-
svm->avic_is_running = is_run;
10261030

10271031
if (kvm_vcpu_apicv_active(vcpu)) {
10281032
if (is_run)

arch/x86/kvm/svm/svm.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,12 +1440,6 @@ static int svm_create_vcpu(struct kvm_vcpu *vcpu)
14401440
if (err)
14411441
goto error_free_vmsa_page;
14421442

1443-
/* We initialize this flag to true to make sure that the is_running
1444-
* bit would be set the first time the vcpu is loaded.
1445-
*/
1446-
if (irqchip_in_kernel(vcpu->kvm) && kvm_apicv_activated(vcpu->kvm))
1447-
svm->avic_is_running = true;
1448-
14491443
svm->msrpm = svm_vcpu_alloc_msrpm();
14501444
if (!svm->msrpm) {
14511445
err = -ENOMEM;

arch/x86/kvm/svm/svm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ struct vcpu_svm {
225225
u32 dfr_reg;
226226
struct page *avic_backing_page;
227227
u64 *avic_physical_id_cache;
228-
bool avic_is_running;
229228

230229
/*
231230
* Per-vcpu list of struct amd_svm_iommu_ir:

0 commit comments

Comments
 (0)