From patchwork Sat Feb 11 02:05:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9567787 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 3328C601C3 for ; Sat, 11 Feb 2017 02:07:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1636C285CF for ; Sat, 11 Feb 2017 02:07:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A776285F2; Sat, 11 Feb 2017 02:07:52 +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 9A65D285EE for ; Sat, 11 Feb 2017 02:07:51 +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 1ccN48-0001BN-F7; Sat, 11 Feb 2017 02:05:32 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ccN47-0001Ak-IK for xen-devel@lists.xenproject.org; Sat, 11 Feb 2017 02:05:31 +0000 Received: from [85.158.143.35] by server-1.bemta-6.messagelabs.com id 0D/4B-27678-A617E985; Sat, 11 Feb 2017 02:05:30 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBLMWRWlGSWpSXmKPExsVybKJsh25W4bw Igz+7BCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozv8wIKTolWtD6/wt7AeF2gi5GTQ0hgKqPE q/bwLkYuIHsHk8SHl3MYQRJsAoYSf59sYgOxRQSUJO6tmswEYjMDxbddPskCYgsLFEisvrwTy ObgYBFQlXj4MwgkzCvgJnF41UWwVgkBOYmTxyazgticAu4Sxw90sULsdZPY+KSJEaImQ2Jezx xWCNtLYtGNS1C2msTVc5uYJzDyLWBkWMWoUZxaVJZapGtkrJdUlJmeUZKbmJmja2hgppebWly cmJ6ak5hUrJecn7uJERgiDECwg/HP/MBDjJIcTEqivM8450UI8SXlp1RmJBZnxBeV5qQWH2KU 4eBQkuB1KgDKCRalpqdWpGXmAIMVJi3BwaMkwjsRJM1bXJCYW5yZDpE6xagoJc47GSQhAJLIK M2Da4NFyCVGWSlhXkagQ4R4ClKLcjNLUOVfMYpzMCoJ80qATOHJzCuBm/4KaDET0GLXB3NBFp ckIqSkGhjF7nMsDZh5PiZK2mZFztZzU+azz1nw4P3fxc9DD+xmKbz5rZBxEpOn4Ja2mDdqdyc /mX9k4zvWc5+5Kw7sMV30sGqz+vRX7YoRBULLXP9fX8Un3PmqXaeUgX+qEYPNj+Q1WgesdBxd zSODr/PJT7XazztPsVFj2u+wZ8Z/95s6bPlxU569MLNEiaU4I9FQi7moOBEA8bDlbIsCAAA= X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-16.tower-21.messagelabs.com!1486778729!52710732!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.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 64829 invoked from network); 11 Feb 2017 02:05:30 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.136) by server-16.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 11 Feb 2017 02:05:30 -0000 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 949352021B; Sat, 11 Feb 2017 02:05:27 +0000 (UTC) Received: from sstabellini-ThinkPad-X260.hsd1.ca.comcast.net (c-50-131-44-19.hsd1.ca.comcast.net [50.131.44.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1BB802035B; Sat, 11 Feb 2017 02:05:26 +0000 (UTC) From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Fri, 10 Feb 2017 18:05:23 -0800 Message-Id: <1486778723-25586-2-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1486778723-25586-1-git-send-email-sstabellini@kernel.org> References: <1486778723-25586-1-git-send-email-sstabellini@kernel.org> X-Virus-Scanned: ClamAV using ClamSMTP Cc: julien.grall@arm.com, sstabellini@kernel.org Subject: [Xen-devel] [PATCH v4 2/2] arm: proper ordering for correct execution of gic_update_one_lr and vgic_store_itargetsr 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 Concurrent execution of gic_update_one_lr and vgic_store_itargetsr can result in the wrong pcpu being set as irq target, see http://marc.info/?l=xen-devel&m=148218667104072. To solve the issue, add barriers, remove an irq from the inflight queue, only after the affinity has been set. On the other end, write the new vcpu target, before checking GIC_IRQ_GUEST_MIGRATING and inflight. Signed-off-by: Stefano Stabellini --- xen/arch/arm/gic.c | 3 ++- xen/arch/arm/vgic-v2.c | 4 ++-- xen/arch/arm/vgic-v3.c | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index a5348f2..bb52959 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -503,12 +503,13 @@ static void gic_update_one_lr(struct vcpu *v, int i) !test_bit(GIC_IRQ_GUEST_MIGRATING, &p->status) ) gic_raise_guest_irq(v, irq, p->priority); else { - 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); irq_set_affinity(p->desc, cpumask_of(v_target->processor)); } + smp_mb(); + list_del_init(&p->inflight); } } } diff --git a/xen/arch/arm/vgic-v2.c b/xen/arch/arm/vgic-v2.c index b30379e..f47286e 100644 --- a/xen/arch/arm/vgic-v2.c +++ b/xen/arch/arm/vgic-v2.c @@ -153,6 +153,8 @@ static void vgic_store_itargetsr(struct domain *d, struct vgic_irq_rank *rank, new_target--; old_target = read_atomic(&rank->vcpu[offset]); + write_atomic(&rank->vcpu[offset], new_target); + smp_mb(); /* Only migrate the vIRQ if the target vCPU has changed */ if ( new_target != old_target ) @@ -161,8 +163,6 @@ static void vgic_store_itargetsr(struct domain *d, struct vgic_irq_rank *rank, d->vcpu[new_target], virq); } - - write_atomic(&rank->vcpu[offset], new_target); } } diff --git a/xen/arch/arm/vgic-v3.c b/xen/arch/arm/vgic-v3.c index 7dc9b6f..e826666 100644 --- a/xen/arch/arm/vgic-v3.c +++ b/xen/arch/arm/vgic-v3.c @@ -150,11 +150,13 @@ static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank, if ( !new_vcpu ) return; + write_atomic(&rank->vcpu[offset], new_vcpu->vcpu_id); + smp_mb(); + /* Only migrate the IRQ if the target vCPU has changed */ if ( new_vcpu != old_vcpu ) vgic_migrate_irq(old_vcpu, new_vcpu, virq); - write_atomic(&rank->vcpu[offset], new_vcpu->vcpu_id); } static inline bool vgic_reg64_check_access(struct hsr_dabt dabt)