Skip to content

Commit 423ad0b

Browse files
Marc Zyngiergregkh
Marc Zyngier
authored andcommitted
KVM: arm/arm64: vgic-its: Take the srcu lock when parsing the memslots
[ Upstream commit 7494cec ] Calling kvm_is_visible_gfn() implies that we're parsing the memslots, and doing this without the srcu lock is frown upon: [12704.164532] ============================= [12704.164544] WARNING: suspicious RCU usage [12704.164560] 5.1.0-rc1-00008-g600025238f51-dirty #16 Tainted: G W [12704.164573] ----------------------------- [12704.164589] ./include/linux/kvm_host.h:605 suspicious rcu_dereference_check() usage! [12704.164602] other info that might help us debug this: [12704.164616] rcu_scheduler_active = 2, debug_locks = 1 [12704.164631] 6 locks held by qemu-system-aar/13968: [12704.164644] #0: 000000007ebdae4f (&kvm->lock){+.+.}, at: vgic_its_set_attr+0x244/0x3a0 [12704.164691] #1: 000000007d751022 (&its->its_lock){+.+.}, at: vgic_its_set_attr+0x250/0x3a0 [12704.164726] #2: 00000000219d2706 (&vcpu->mutex){+.+.}, at: lock_all_vcpus+0x64/0xd0 [12704.164761] #3: 00000000a760aecd (&vcpu->mutex){+.+.}, at: lock_all_vcpus+0x64/0xd0 [12704.164794] #4: 000000000ef8e31d (&vcpu->mutex){+.+.}, at: lock_all_vcpus+0x64/0xd0 [12704.164827] #5: 000000007a872093 (&vcpu->mutex){+.+.}, at: lock_all_vcpus+0x64/0xd0 [12704.164861] stack backtrace: [12704.164878] CPU: 2 PID: 13968 Comm: qemu-system-aar Tainted: G W 5.1.0-rc1-00008-g600025238f51-dirty #16 [12704.164887] Hardware name: rockchip evb_rk3399/evb_rk3399, BIOS 2019.04-rc3-00124-g2feec69fb1 03/15/2019 [12704.164896] Call trace: [12704.164910] dump_backtrace+0x0/0x138 [12704.164920] show_stack+0x24/0x30 [12704.164934] dump_stack+0xbc/0x104 [12704.164946] lockdep_rcu_suspicious+0xcc/0x110 [12704.164958] gfn_to_memslot+0x174/0x190 [12704.164969] kvm_is_visible_gfn+0x28/0x70 [12704.164980] vgic_its_check_id.isra.0+0xec/0x1e8 [12704.164991] vgic_its_save_tables_v0+0x1ac/0x330 [12704.165001] vgic_its_set_attr+0x298/0x3a0 [12704.165012] kvm_device_ioctl_attr+0x9c/0xd8 [12704.165022] kvm_device_ioctl+0x8c/0xf8 [12704.165035] do_vfs_ioctl+0xc8/0x960 [12704.165045] ksys_ioctl+0x8c/0xa0 [12704.165055] __arm64_sys_ioctl+0x28/0x38 [12704.165067] el0_svc_common+0xd8/0x138 [12704.165078] el0_svc_handler+0x38/0x78 [12704.165089] el0_svc+0x8/0xc Make sure the lock is taken when doing this. Fixes: bf30824 ("KVM: arm/arm64: VGIC/ITS: protect kvm_read_guest() calls with SRCU lock") Reviewed-by: Eric Auger <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Signed-off-by: Sasha Levin (Microsoft) <[email protected]>
1 parent 10a0ba2 commit 423ad0b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

virt/kvm/arm/vgic/vgic-its.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,9 @@ static bool vgic_its_check_id(struct vgic_its *its, u64 baser, u32 id,
704704
int l1_tbl_size = GITS_BASER_NR_PAGES(baser) * SZ_64K;
705705
u64 indirect_ptr, type = GITS_BASER_TYPE(baser);
706706
int esz = GITS_BASER_ENTRY_SIZE(baser);
707-
int index;
707+
int index, idx;
708708
gfn_t gfn;
709+
bool ret;
709710

710711
switch (type) {
711712
case GITS_BASER_TYPE_DEVICE:
@@ -732,7 +733,8 @@ static bool vgic_its_check_id(struct vgic_its *its, u64 baser, u32 id,
732733

733734
if (eaddr)
734735
*eaddr = addr;
735-
return kvm_is_visible_gfn(its->dev->kvm, gfn);
736+
737+
goto out;
736738
}
737739

738740
/* calculate and check the index into the 1st level */
@@ -766,7 +768,12 @@ static bool vgic_its_check_id(struct vgic_its *its, u64 baser, u32 id,
766768

767769
if (eaddr)
768770
*eaddr = indirect_ptr;
769-
return kvm_is_visible_gfn(its->dev->kvm, gfn);
771+
772+
out:
773+
idx = srcu_read_lock(&its->dev->kvm->srcu);
774+
ret = kvm_is_visible_gfn(its->dev->kvm, gfn);
775+
srcu_read_unlock(&its->dev->kvm->srcu, idx);
776+
return ret;
770777
}
771778

772779
static int vgic_its_alloc_collection(struct vgic_its *its,

0 commit comments

Comments
 (0)