Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3002060yba; Mon, 22 Apr 2019 17:34:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxkcmub0uyVzND0CZ5PC55+qtg1y3N7f0yDobfFNzObKiiRK18sMoBI1OWuNHsn+K5jjuog X-Received: by 2002:a62:f20e:: with SMTP id m14mr24455593pfh.228.1555979654529; Mon, 22 Apr 2019 17:34:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555979654; cv=none; d=google.com; s=arc-20160816; b=K5/w3eg8cI/7TwZ67d7RsyJF/SwEQbXuyjm5TlrdMt7VWqCmXBS3JMwUeflz7d6PRp lLVaaY8cDviJeevt1RaxCiCp28xDH4B9YFBRvXcNuyEJAmne6gZKwGRJy9BxX2OGV/EY nNXflCJB46r/IaxUmDTcIHujLBPy6uTixfoGxX8f6nxIhPeFFkbfyj9F6vpSxAq3hAqK ZOlpRj3qSVsEqLmRrFxLSBC9pXAYqlmC8GHFMc0A5+9D1L5FMYAF9AUWMw9BsI+1z1as 7IOgPNdfsGk/FZVOGkIRkoywDhGDBUTcax7ly3ug98vSfmJ4SgphfQL9IIoRW2T4fh4L kapg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BFdsbZfE72mur91vB4maBnniJIW22Lni300BzmjpF3c=; b=pdZ00jtdv+1oN91eFha8dX7ccGJLYy36hWhbEGqY2tA2EfGL5ackMXaEzlSLqJ7qPh Dv36hnY48oXu/QsMXU5Ip3WTWJr8Jz3OhEVjhii4ML7HeRTmH+fkDKU/3MOltZtxydZy 2hJEA+A0qJnB9djUN98ae58u+/Bmzx6vNJP6AUIRzATWRCyyBTlzy5JqNoVuH+mm0Zs7 qLP68es2hNrWTR3InIYd1+dCqhfMDgq7z+79pbmgn6skzRzb7wgPLxZOriVGkU3Vn3mj otG3Gz0ofRvudj3RAR/eWpVDIMQW6xGrTuT2qtQGS0kY7erjZP9z0Uy4lWyPWXgd+lOV 0y8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vwlva7io; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u71si13478427pgd.147.2019.04.22.17.33.58; Mon, 22 Apr 2019 17:34:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vwlva7io; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732536AbfDVUKM (ORCPT + 99 others); Mon, 22 Apr 2019 16:10:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:43294 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728987AbfDVTmv (ORCPT ); Mon, 22 Apr 2019 15:42:51 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 842FE2177B; Mon, 22 Apr 2019 19:42:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962170; bh=m2VyGhpKaiCFUUZIItae6YUpt6d1B42+QDdg8sO8vAc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vwlva7ioz1HPLTxl8ENCv2D7Hl8cKfVozbDLlppehFXSIHHoE4UqgnJ2rzU3yeGNE pfi7xDgSO4T23fWfNoJMi2h8Sd72ocW7BYgV7RHPnEckuH2eurKJc9QgfybwlJtwvn ZjUIOFz1RizXVFK5vXs0RoI3OOW0UQPP+62mfjbU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Marc Zyngier , Sasha Levin , kvmarm@lists.cs.columbia.edu Subject: [PATCH AUTOSEL 5.0 28/98] KVM: arm/arm64: vgic-its: Take the srcu lock when parsing the memslots Date: Mon, 22 Apr 2019 15:40:55 -0400 Message-Id: <20190422194205.10404-28-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194205.10404-1-sashal@kernel.org> References: <20190422194205.10404-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Zyngier [ Upstream commit 7494cec6cb3ba7385a6a223b81906384f15aae34 ] 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: bf308242ab98 ("KVM: arm/arm64: VGIC/ITS: protect kvm_read_guest() calls with SRCU lock") Reviewed-by: Eric Auger Signed-off-by: Marc Zyngier Signed-off-by: Sasha Levin (Microsoft) --- virt/kvm/arm/vgic/vgic-its.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index c41e11fd841c..fcb2fceaa4a5 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -754,8 +754,9 @@ static bool vgic_its_check_id(struct vgic_its *its, u64 baser, u32 id, u64 indirect_ptr, type = GITS_BASER_TYPE(baser); phys_addr_t base = GITS_BASER_ADDR_48_to_52(baser); int esz = GITS_BASER_ENTRY_SIZE(baser); - int index; + int index, idx; gfn_t gfn; + bool ret; switch (type) { case GITS_BASER_TYPE_DEVICE: @@ -782,7 +783,8 @@ static bool vgic_its_check_id(struct vgic_its *its, u64 baser, u32 id, if (eaddr) *eaddr = addr; - return kvm_is_visible_gfn(its->dev->kvm, gfn); + + goto out; } /* calculate and check the index into the 1st level */ @@ -812,7 +814,12 @@ static bool vgic_its_check_id(struct vgic_its *its, u64 baser, u32 id, if (eaddr) *eaddr = indirect_ptr; - return kvm_is_visible_gfn(its->dev->kvm, gfn); + +out: + idx = srcu_read_lock(&its->dev->kvm->srcu); + ret = kvm_is_visible_gfn(its->dev->kvm, gfn); + srcu_read_unlock(&its->dev->kvm->srcu, idx); + return ret; } static int vgic_its_alloc_collection(struct vgic_its *its, -- 2.19.1