From patchwork Wed Aug 17 19:38:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 74124 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1160qga; Wed, 17 Aug 2016 12:38:57 -0700 (PDT) X-Received: by 10.66.66.42 with SMTP id c10mr76628008pat.83.1471462737769; Wed, 17 Aug 2016 12:38:57 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id fv3si605877pad.63.2016.08.17.12.38.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Aug 2016 12:38:57 -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 1ba6el-0002jv-ES; Wed, 17 Aug 2016 19:37:43 +0000 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1ba6eQ-0002cf-5J for linux-arm-kernel@lists.infradead.org; Wed, 17 Aug 2016 19:37:26 +0000 Received: by mail-wm0-x229.google.com with SMTP id q128so216062806wma.1 for ; Wed, 17 Aug 2016 12:37:04 -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=aXSLkYf+pGBpFx29VSbdDfJgGwz5GbmtQusO+G8tIP8=; b=Wm2Gtufo6wbcFpo25UiZfpD+IqaWH+XHARl0ek4Id8KxfLSe3frogfssZGPM5CJM9T 8ieS9LQPzQE50DxQzEGUtqrL9wcv38LAJDXyoz+w3rqN+5+AGM5bvKJEhIL1cQOdBjp+ oLwfc3DDTEwBUJUs5dffqC+QxQwUvZr0ZhP6s= 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=aXSLkYf+pGBpFx29VSbdDfJgGwz5GbmtQusO+G8tIP8=; b=WwTTwKnvlFa0Da2OsP9wI0ZS62guhv5AGBjppQ4ScLBnk19pWhNPrTxuOn70B84aB8 +Q8ntsMHWGEJVVn4uDPF7R9GBnyWVdaCmYwAQtnMuonWOm1oKHhDThpdN/d+4ZJKltJr 2gmYwlUFP7Htjoi6QO2hbxgglmmdrA/oQPQP/K8W4VdgH7hDUXSnXdhtW2hAFrrMyquk InZZ5O+eSCzwoKlQPpjLfJayY/vqlb0bDBYIO8Jq7F4U4LM9uVcLO17DDj/XcA9wFdqU JkYui8OCc1uZ/1GGDSTKfRQ9gjicgaCE/MtTcP2jmUYuVybMfeT6WG59lA6eYqBNYQCJ +hzg== X-Gm-Message-State: AEkoouukjtxHU0AViv+C5DEgNdS2whPbKmulrl9gKvvZBTyg0mvux8ZMg618VXFXMd110jG1 X-Received: by 10.28.96.11 with SMTP id u11mr28121585wmb.5.1471462622886; Wed, 17 Aug 2016 12:37:02 -0700 (PDT) Received: from localhost.localdomain ([94.18.191.146]) by smtp.gmail.com with ESMTPSA id jv9sm26185622wjb.45.2016.08.17.12.37.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Aug 2016 12:37:02 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PULL 03/12] KVM: arm64: vgic-its: Plug race in vgic_put_irq Date: Wed, 17 Aug 2016 21:38:50 +0200 Message-Id: <20160817193859.15726-4-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160817193859.15726-1-christoffer.dall@linaro.org> References: <20160817193859.15726-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160817_123722_439236_5AAEAA0C X-CRM114-Status: GOOD ( 11.49 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -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: Marc Zyngier , Christoffer Dall , 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. Reviewed-by: Andre Przywara Signed-off-by: Christoffer Dall --- 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);