From patchwork Thu Dec 22 02:15:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9484021 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 D2B7F601D5 for ; Thu, 22 Dec 2016 02:17:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C297D24B48 for ; Thu, 22 Dec 2016 02:17:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B7A1027C2D; Thu, 22 Dec 2016 02:17:42 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 60DD324B48 for ; Thu, 22 Dec 2016 02:17:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cJsuk-0001Xb-RV; Thu, 22 Dec 2016 02:15:26 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cJsuj-0001WC-3T for xen-devel@lists.xenproject.org; Thu, 22 Dec 2016 02:15:25 +0000 Received: from [85.158.139.211] by server-16.bemta-5.messagelabs.com id 50/2D-21460-C373B585; Thu, 22 Dec 2016 02:15:24 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRWlGSWpSXmKPExsVybKJsh661eXS Eweo1Shbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bsqb+YCraKVDy8fYixgfG7QBcjF4eQwFRG iW3/VrFAOAeZJHZ17GDsYuTkYBMwlPj7ZBMbiC0iICGxqWEFE4jNLGAtce/ND3YQW1ign1Fix nFREJtFQFXi64KlQPUcHLwCbhLHdsqAhCUE5CROHpvMCmJzCrhL7Jw3G6xVSKCdUaJ9VzVETY bEvJ45rBC2l8SiG5egbDWJq+c2MU9g5FvAyLCKUaM4tagstUjX0FAvqSgzPaMkNzEzR9fQwFQ vN7W4ODE9NScxqVgvOT93EyMwTBiAYAfjynbnQ4ySHExKoryntKMjhPiS8lMqMxKLM+KLSnNS iw8xynBwKEnwvjIFygkWpaanVqRl5gADFiYtwcGjJMJ7FCTNW1yQmFucmQ6ROsWoKCXOuwgkI QCSyCjNg2uDRcklRlkpYV5GoEOEeApSi3IzS1DlXzGKczAqCfMqgkzhycwrgZv+CmgxE9Dihd 3hIItLEhFSUg2MsitPf5U5Vjx1q13U3pigD/UqwcK54R2zv3Q0fRXtbbmY8uZjPudMFo2OKQ6 LZm2a+e+6p9Zpxv9BMbMXCG1IeuPzacusxy8qeNacvbNG4NbWb363S3rPOjx+x59nO/Htj76E 8vSUrlNf9HZPON9voVV1xeUWz6XMsprYlnd307YWdBZv/ycTosRSnJFoqMVcVJwIAOme4nKNA gAA X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-3.tower-206.messagelabs.com!1482372922!73083930!1 X-Originating-IP: [198.145.29.136] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 10577 invoked from network); 22 Dec 2016 02:15:23 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.136) by server-3.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Dec 2016 02:15:23 -0000 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D93EF2034A; Thu, 22 Dec 2016 02:15:20 +0000 (UTC) Received: from sstabellini-ThinkPad-X260.hsd1.ca.comcast.net (96-82-76-110-static.hfc.comcastbusiness.net [96.82.76.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7CAA82038A; Thu, 22 Dec 2016 02:15:19 +0000 (UTC) From: Stefano Stabellini To: julien.grall@arm.com Date: Wed, 21 Dec 2016 18:15:13 -0800 Message-Id: <1482372913-18366-4-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1482372913-18366-1-git-send-email-sstabellini@kernel.org> References: <1482372913-18366-1-git-send-email-sstabellini@kernel.org> X-Virus-Scanned: ClamAV using ClamSMTP Cc: xen-devel@lists.xenproject.org, sstabellini@kernel.org Subject: [Xen-devel] [PATCH v2 4/4] The locking order is: first rank lock, then vgic lock. The order is respected everywhere, except for gic_update_one_lr. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP gic_update_one_lr is called with the vgic lock held, but it calls vgic_get_target_vcpu, which tries to obtain the rank lock. This can cause deadlocks. We already have a version of vgic_get_target_vcpu that doesn't take the rank lock: __vgic_get_target_vcpu. Solve the lock inversion problem, by not taking the rank lock in gic_update_one_lr (calling __vgic_get_target_vcpu instead of vgic_get_target_vcpu). This is safe, because vcpu target modifications are protected by the same vgic vcpu lock. Signed-off-by: Stefano Stabellini --- xen/arch/arm/gic.c | 2 +- xen/arch/arm/vgic.c | 4 +--- xen/include/asm-arm/vgic.h | 1 + 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index 51148b4..28ab2f9 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -509,7 +509,7 @@ static void gic_update_one_lr(struct vcpu *v, int i) list_del_init(&p->inflight); if ( test_and_clear_bit(GIC_IRQ_GUEST_MIGRATING, &p->status) ) { - struct vcpu *v_target = vgic_get_target_vcpu(v, irq); + struct vcpu *v_target = __vgic_get_target_vcpu(v, irq); irq_set_affinity(p->desc, cpumask_of(v_target->processor)); } /* diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c index cceac24..c89b85f 100644 --- a/xen/arch/arm/vgic.c +++ b/xen/arch/arm/vgic.c @@ -221,12 +221,10 @@ int vcpu_vgic_free(struct vcpu *v) } /* The function should be called by rank lock taken. */ -static struct vcpu *__vgic_get_target_vcpu(struct vcpu *v, unsigned int virq) +struct vcpu *__vgic_get_target_vcpu(struct vcpu *v, unsigned int virq) { struct vgic_irq_rank *rank = vgic_rank_irq(v, virq); - ASSERT(spin_is_locked(&rank->lock)); - return v->domain->vcpu[rank->vcpu[virq & INTERRUPT_RANK_MASK]]; } diff --git a/xen/include/asm-arm/vgic.h b/xen/include/asm-arm/vgic.h index dce2f84..26594b0 100644 --- a/xen/include/asm-arm/vgic.h +++ b/xen/include/asm-arm/vgic.h @@ -295,6 +295,7 @@ extern int domain_vgic_init(struct domain *d, unsigned int nr_spis); extern void domain_vgic_free(struct domain *d); extern int vcpu_vgic_init(struct vcpu *v); extern struct vcpu *vgic_get_target_vcpu(struct vcpu *v, unsigned int virq); +extern struct vcpu *__vgic_get_target_vcpu(struct vcpu *v, unsigned int virq); extern void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int virq); extern void vgic_vcpu_inject_spi(struct domain *d, unsigned int virq); extern void vgic_clear_pending_irqs(struct vcpu *v);