Skip to content

Commit aedb5b1

Browse files
legoaterpaulusmack
authored andcommitted
KVM: PPC: Book3S HV: XIVE: Take the srcu read lock when accessing memslots
According to Documentation/virtual/kvm/locking.txt, the srcu read lock should be taken when accessing the memslots of the VM. The XIVE KVM device needs to do so when configuring the page of the OS event queue of vCPU for a given priority and when marking the same page dirty before migration. This avoids warnings such as : [ 208.224882] ============================= [ 208.224884] WARNING: suspicious RCU usage [ 208.224889] 5.2.0-rc2-xive+ #47 Not tainted [ 208.224890] ----------------------------- [ 208.224894] ../include/linux/kvm_host.h:633 suspicious rcu_dereference_check() usage! [ 208.224896] other info that might help us debug this: [ 208.224898] rcu_scheduler_active = 2, debug_locks = 1 [ 208.224901] no locks held by qemu-system-ppc/3923. [ 208.224902] stack backtrace: [ 208.224907] CPU: 64 PID: 3923 Comm: qemu-system-ppc Kdump: loaded Not tainted 5.2.0-rc2-xive+ #47 [ 208.224909] Call Trace: [ 208.224918] [c000200cdd98fa30] [c000000000be1934] dump_stack+0xe8/0x164 (unreliable) [ 208.224924] [c000200cdd98fa80] [c0000000001aec80] lockdep_rcu_suspicious+0x110/0x180 [ 208.224935] [c000200cdd98fb00] [c0080000075933a0] gfn_to_memslot+0x1c8/0x200 [kvm] [ 208.224943] [c000200cdd98fb40] [c008000007599600] gfn_to_pfn+0x28/0x60 [kvm] [ 208.224951] [c000200cdd98fb70] [c008000007599658] gfn_to_page+0x20/0x40 [kvm] [ 208.224959] [c000200cdd98fb90] [c0080000075b495c] kvmppc_xive_native_set_attr+0x8b4/0x1480 [kvm] [ 208.224967] [c000200cdd98fca0] [c00800000759261c] kvm_device_ioctl_attr+0x64/0xb0 [kvm] [ 208.224974] [c000200cdd98fcf0] [c008000007592730] kvm_device_ioctl+0xc8/0x110 [kvm] [ 208.224979] [c000200cdd98fd10] [c000000000433a24] do_vfs_ioctl+0xd4/0xcd0 [ 208.224981] [c000200cdd98fdb0] [c000000000434724] ksys_ioctl+0x104/0x120 [ 208.224984] [c000200cdd98fe00] [c000000000434768] sys_ioctl+0x28/0x80 [ 208.224988] [c000200cdd98fe20] [c00000000000b888] system_call+0x5c/0x70 legoater@boss01:~$ Fixes: 13ce329 ("KVM: PPC: Book3S HV: XIVE: Add controls for the EQ configuration") Fixes: e6714bd ("KVM: PPC: Book3S HV: XIVE: Add a control to dirty the XIVE EQ pages") Signed-off-by: Cédric Le Goater <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent ef97402 commit aedb5b1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

arch/powerpc/kvm/book3s_xive_native.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ static int kvmppc_xive_native_set_queue_config(struct kvmppc_xive *xive,
535535
struct xive_q *q;
536536
gfn_t gfn;
537537
unsigned long page_size;
538+
int srcu_idx;
538539

539540
/*
540541
* Demangle priority/server tuple from the EQ identifier
@@ -610,20 +611,24 @@ static int kvmppc_xive_native_set_queue_config(struct kvmppc_xive *xive,
610611
return -EINVAL;
611612
}
612613

614+
srcu_idx = srcu_read_lock(&kvm->srcu);
613615
gfn = gpa_to_gfn(kvm_eq.qaddr);
614616
page = gfn_to_page(kvm, gfn);
615617
if (is_error_page(page)) {
618+
srcu_read_unlock(&kvm->srcu, srcu_idx);
616619
pr_err("Couldn't get queue page %llx!\n", kvm_eq.qaddr);
617620
return -EINVAL;
618621
}
619622

620623
page_size = kvm_host_page_size(kvm, gfn);
621624
if (1ull << kvm_eq.qshift > page_size) {
625+
srcu_read_unlock(&kvm->srcu, srcu_idx);
622626
pr_warn("Incompatible host page size %lx!\n", page_size);
623627
return -EINVAL;
624628
}
625629

626630
qaddr = page_to_virt(page) + (kvm_eq.qaddr & ~PAGE_MASK);
631+
srcu_read_unlock(&kvm->srcu, srcu_idx);
627632

628633
/*
629634
* Backup the queue page guest address to the mark EQ page
@@ -854,6 +859,7 @@ static int kvmppc_xive_native_vcpu_eq_sync(struct kvm_vcpu *vcpu)
854859
{
855860
struct kvmppc_xive_vcpu *xc = vcpu->arch.xive_vcpu;
856861
unsigned int prio;
862+
int srcu_idx;
857863

858864
if (!xc)
859865
return -ENOENT;
@@ -865,7 +871,9 @@ static int kvmppc_xive_native_vcpu_eq_sync(struct kvm_vcpu *vcpu)
865871
continue;
866872

867873
/* Mark EQ page dirty for migration */
874+
srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
868875
mark_page_dirty(vcpu->kvm, gpa_to_gfn(q->guest_qaddr));
876+
srcu_read_unlock(&vcpu->kvm->srcu, srcu_idx);
869877
}
870878
return 0;
871879
}

0 commit comments

Comments
 (0)