From patchwork Tue Aug 9 11:16:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 73542 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp429265qga; Tue, 9 Aug 2016 04:16:17 -0700 (PDT) X-Received: by 10.98.9.11 with SMTP id e11mr171869022pfd.153.1470741377492; Tue, 09 Aug 2016 04:16:17 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id x87si42278139pfa.79.2016.08.09.04.16.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Aug 2016 04:16:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bX50E-0008IF-N3; Tue, 09 Aug 2016 11:15:22 +0000 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bX4zc-0007Gq-2D for linux-arm-kernel@lists.infradead.org; Tue, 09 Aug 2016 11:14:45 +0000 Received: by mail-wm0-x22a.google.com with SMTP id o80so27308061wme.1 for ; Tue, 09 Aug 2016 04:14:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rDZKkD56s3fzprALTB4AmeHeirH2gqN334AZW3AjK/g=; b=XepIM63psHPTxWqaJryGmU7KTnSTEJO5YH+QnXbrCdq7XGEhjtVA5LN2yFaNtqJLM9 RpliXYdaavyNbMwf1HcayMmN8x7fdHVirCGd/qsUZiNWDp/N+rUkkZd+5gjgXjy6vtLu kFcwTaSNVMxeaiCbJrjCeHMg2Xe7b0RmyXXjE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rDZKkD56s3fzprALTB4AmeHeirH2gqN334AZW3AjK/g=; b=PGpwOgmPbBZg7af8zM6IxHQqbdOXi7oy1f83/yOaoYwXLTzUM17/vv8Y3VuJu2uWkW svx6VtoykpGWpIPp2SLKKhqtbgp2ewUR5tDiEgfMQ6e0BAX2BG+miS6YvwBTkjdwZHJG 35QyVxcD6PC84EFV/1uuJWY9TT3ryRtrM6U+9xbrths7xpvO3jv6h5QIxAbRGRSiZ1Lp nDT7V5kThi1eAVM845qO5MAWqq8JKmBeXHaahnwgmREmlToTqyctnKTClcOUNQNp5yMu e0PkB1Rzj1/6Uom6maDfIyFIktPWx3F2kfmA5iaFAE7R1c1KkENNJOe7kIQliHwPH+Jc 6dGA== X-Gm-Message-State: AEkooutOVLw8qdE807Le/jlaIpZ2QWu/vN/64jOEFkgXbHnmtpinwULV9J4w2OA1VUG9TC3x X-Received: by 10.194.171.131 with SMTP id au3mr89845750wjc.125.1470741262426; Tue, 09 Aug 2016 04:14:22 -0700 (PDT) Received: from localhost.localdomain ([94.18.191.146]) by smtp.gmail.com with ESMTPSA id 190sm2796816wmk.13.2016.08.09.04.14.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 Aug 2016 04:14:21 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, Marc Zyngier , Andre Przywara Subject: [PATCH v2 2/3] KVM: arm64: vgic-its: Plug race in vgic_put_irq Date: Tue, 9 Aug 2016 13:16:05 +0200 Message-Id: <20160809111606.28744-3-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160809111606.28744-1-christoffer.dall@linaro.org> References: <20160809111606.28744-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160809_041444_320111_820A5D9F X-CRM114-Status: GOOD ( 12.57 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:22a listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Christoffer Dall , linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Right now the following sequence of events can happen: 1. Thread X calls vgic_put_irq 2. Thread Y calls vgic_add_lpi 3. Thread Y gets lpi_list_lock 4. Thread X drops the ref count to 0 and blocks on lpi_list_lock 5. Thread Y finds the irq via the lpi_list_lock, raises the ref count to 1, and release the lpi_list_lock. 6. Thread X proceeds and frees the irq. Avoid this by holding the spinlock around the kref_put. Signed-off-by: Christoffer Dall --- Notes: Changes since v1: - Stylistic change: Don't use else branch virt/kvm/arm/vgic/vgic.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) -- 2.9.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index e7aeac7..e83b7fe 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -117,17 +117,17 @@ static void vgic_irq_release(struct kref *ref) void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq) { - struct vgic_dist *dist; + struct vgic_dist *dist = &kvm->arch.vgic; if (irq->intid < VGIC_MIN_LPI) return; - if (!kref_put(&irq->refcount, vgic_irq_release)) + spin_lock(&dist->lpi_list_lock); + if (!kref_put(&irq->refcount, vgic_irq_release)) { + spin_unlock(&dist->lpi_list_lock); return; + }; - dist = &kvm->arch.vgic; - - spin_lock(&dist->lpi_list_lock); list_del(&irq->lpi_list); dist->lpi_list_count--; spin_unlock(&dist->lpi_list_lock);