Skip to content

Commit 2a1d794

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull kvm fix from Paolo Bonzini: "Fix SRCU bug introduced in the merge window" * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: x86/xen: Take srcu lock when accessing kvm_memslots()
2 parents 799bac5 + 9c1a074 commit 2a1d794

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

arch/x86/kvm/x86.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4025,44 +4025,42 @@ static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)
40254025
{
40264026
struct kvm_host_map map;
40274027
struct kvm_steal_time *st;
4028-
int idx;
40294028

40304029
if (!(vcpu->arch.st.msr_val & KVM_MSR_ENABLED))
40314030
return;
40324031

40334032
if (vcpu->arch.st.preempted)
40344033
return;
40354034

4036-
/*
4037-
* Take the srcu lock as memslots will be accessed to check the gfn
4038-
* cache generation against the memslots generation.
4039-
*/
4040-
idx = srcu_read_lock(&vcpu->kvm->srcu);
4041-
40424035
if (kvm_map_gfn(vcpu, vcpu->arch.st.msr_val >> PAGE_SHIFT, &map,
40434036
&vcpu->arch.st.cache, true))
4044-
goto out;
4037+
return;
40454038

40464039
st = map.hva +
40474040
offset_in_page(vcpu->arch.st.msr_val & KVM_STEAL_VALID_BITS);
40484041

40494042
st->preempted = vcpu->arch.st.preempted = KVM_VCPU_PREEMPTED;
40504043

40514044
kvm_unmap_gfn(vcpu, &map, &vcpu->arch.st.cache, true, true);
4052-
4053-
out:
4054-
srcu_read_unlock(&vcpu->kvm->srcu, idx);
40554045
}
40564046

40574047
void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
40584048
{
4049+
int idx;
4050+
40594051
if (vcpu->preempted && !vcpu->arch.guest_state_protected)
40604052
vcpu->arch.preempted_in_kernel = !static_call(kvm_x86_get_cpl)(vcpu);
40614053

4054+
/*
4055+
* Take the srcu lock as memslots will be accessed to check the gfn
4056+
* cache generation against the memslots generation.
4057+
*/
4058+
idx = srcu_read_lock(&vcpu->kvm->srcu);
40624059
if (kvm_xen_msr_enabled(vcpu->kvm))
40634060
kvm_xen_runstate_set_preempted(vcpu);
40644061
else
40654062
kvm_steal_time_set_preempted(vcpu);
4063+
srcu_read_unlock(&vcpu->kvm->srcu, idx);
40664064

40674065
static_call(kvm_x86_vcpu_put)(vcpu);
40684066
vcpu->arch.last_host_tsc = rdtsc();

0 commit comments

Comments
 (0)