From patchwork Mon Dec 4 14:03:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10090353 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8FAFA60580 for ; Mon, 4 Dec 2017 14:04:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7834E2899A for ; Mon, 4 Dec 2017 14:04:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D0D028D48; Mon, 4 Dec 2017 14:04:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,URIBL_DBL_ABUSE_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 102C82899A for ; Mon, 4 Dec 2017 14:04:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754516AbdLDOE3 (ORCPT ); Mon, 4 Dec 2017 09:04:29 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:44858 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754481AbdLDOEL (ORCPT ); Mon, 4 Dec 2017 09:04:11 -0500 Received: by mail-wm0-f66.google.com with SMTP id t8so6002070wmc.3 for ; Mon, 04 Dec 2017 06:04:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=christofferdall-dk.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=26Q+bza+1c3SwfKc8UQVaU0+52zWwjBHo15Kp+xzYjQ=; b=ngj5+LTYFaqniir8Fc7Iw8AwxLYhfB9eYcrQKo3336FZ66hXAPUrY00ZLXRD+xsBHu lIFJHuwUOFb6DIlU6auJZmyzeLD6TH4I3u23NnX8/7/PHfC9m7u9LcYfD7+MmUieyTPz kchgCY642tsjiiqO5jwsM+cM0Qrq8PBrdiNnZjsdcmydDRk3nHyqwisZlVMabpJMQsxE wxayrLTvjC7rAh0SCAOt4/U9copJpC4OB7GbQ+uf9Gsrd0qF2P09H8wIFyw3IXdoOC9c WGD+MB0fcn2CHgo+s0/lwo9zD0zcbcyGSHv+/QaLCnZVsi7pCqhJshCROJs2aBzcFVno 8WGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=26Q+bza+1c3SwfKc8UQVaU0+52zWwjBHo15Kp+xzYjQ=; b=hyPdgehWbxUsfPrlkLfW0UjjIWgcdPdBwfFh8N6ycdELkEm4N9+RexmJYLOIy8ZepG 3wnJLEsMFTaES1C8dPQWpv9xqaYS+OJ7tr/9PPdASSrzpq8WZjQ6Kbxm4dgYJJUmWXhn rBHZO1THajmU0GspNwKSbD1o9xkMycqabLM7vIEBhVwY9ecBeF5yt6JFMe+FRW7D7VzS Gy2zrI+w4t309BFM9xGuAZWg7B/DAxj31h9mijlLk97/Nhw+ookPsHzCf+bIr41M5yP0 bnEnACJF0wlVnKVHFl1pLFbOmSjBmfOwt2D9qem7/rrKYivMBw4LV6w99bwu8G6cO5tv R8CA== X-Gm-Message-State: AKGB3mKRwEiYrzyKF3zqau4BwBRZNeA3Zgy8oW4iLArgpPJga+48Sq/j iW4e7cPwc11JLOyfmalldHZT0w== X-Google-Smtp-Source: AGs4zMarZxToZmazjtjMDBfUiuu2M1bNkwFQTGFmmpohkOXtt1u/zJsQ5rGy5ALfC8KH9OYcY0HimQ== X-Received: by 10.28.69.136 with SMTP id l8mr6824291wmi.19.1512396250482; Mon, 04 Dec 2017 06:04:10 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id g7sm22794279wra.38.2017.12.04.06.04.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Dec 2017 06:04:09 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Cc: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, Marc Zyngier , Christoffer Dall Subject: [PULL 17/19] KVM: arm/arm64: Fix spinlock acquisition in vgic_set_owner Date: Mon, 4 Dec 2017 15:03:46 +0100 Message-Id: <20171204140348.21965-15-cdall@kernel.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171204135637.21620-1-cdall@kernel.org> References: <20171204135637.21620-1-cdall@kernel.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Marc Zyngier vgic_set_owner acquires the irq lock without disabling interrupts, resulting in a lockdep splat (an interrupt could fire and result in the same lock being taken if the same virtual irq is to be injected). In practice, it is almost impossible to trigger this bug, but better safe than sorry. Convert the lock acquisition to a spin_lock_irqsave() and keep lockdep happy. Reported-by: James Morse Signed-off-by: Marc Zyngier Signed-off-by: Christoffer Dall --- virt/kvm/arm/vgic/vgic.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index 786cce7bd2ec..ecb8e25f5fe5 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -492,6 +492,7 @@ int kvm_vgic_unmap_phys_irq(struct kvm_vcpu *vcpu, unsigned int vintid) int kvm_vgic_set_owner(struct kvm_vcpu *vcpu, unsigned int intid, void *owner) { struct vgic_irq *irq; + unsigned long flags; int ret = 0; if (!vgic_initialized(vcpu->kvm)) @@ -502,12 +503,12 @@ int kvm_vgic_set_owner(struct kvm_vcpu *vcpu, unsigned int intid, void *owner) return -EINVAL; irq = vgic_get_irq(vcpu->kvm, vcpu, intid); - spin_lock(&irq->irq_lock); + spin_lock_irqsave(&irq->irq_lock, flags); if (irq->owner && irq->owner != owner) ret = -EEXIST; else irq->owner = owner; - spin_unlock(&irq->irq_lock); + spin_unlock_irqrestore(&irq->irq_lock, flags); return ret; }