From patchwork Wed Apr 5 20:28:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9665703 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 1069360364 for ; Wed, 5 Apr 2017 20:31:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 049D7284FE for ; Wed, 5 Apr 2017 20:31:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EDA422856E; Wed, 5 Apr 2017 20:31:09 +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 C0AF728573 for ; Wed, 5 Apr 2017 20:31:08 +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 1cvrXv-00029I-J1; Wed, 05 Apr 2017 20:28:51 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cvrXu-000292-Bq for xen-devel@lists.xenproject.org; Wed, 05 Apr 2017 20:28:50 +0000 Received: from [85.158.143.35] by server-7.bemta-6.messagelabs.com id D5/3F-04817-18355E85; Wed, 05 Apr 2017 20:28:49 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBLMWRWlGSWpSXmKPExsVybKJsh25j8NM Ig3udTBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa0b/jFPMBbu5Ki6deszUwPiLvYuRk0NIYCqj xLvHLBD2DiaJtjmBIDabgKHE3yeb2EBsEQEJiU0NK5hAbGYBa4l7b36A9QoLhEhcPLKCGcRmE VCV+P23Gaieg4NXwE1iwy1PkLCEgJzEyWOTWUFsTgFviVVf9kCt9ZLY8eY/G0RNhsS8njmsEL aXxKIbl6BsNYmr5zYxT2DkW8DIsIpRozi1qCy1SNfQRC+pKDM9oyQ3MTNH19DATC83tbg4MT0 1JzGpWC85P3cTIzBEGIBgB+P1jQGHGCU5mJREeRV8nkQI8SXlp1RmJBZnxBeV5qQWH2KU4eBQ kuBdHfQ0QkiwKDU9tSItMwcYrDBpCQ4eJRFeH5A0b3FBYm5xZjpE6hSjopQ470mQhABIIqM0D 64NFiGXGGWlhHkZgQ4R4ilILcrNLEGVf8UozsGoJMw7EWQKT2ZeCdz0V0CLmYAWP7nzEGRxSS JCSqqBce7GqFCj9w847j05tU2uQlHmubpty787jz+vsp8VcIInUPnybKPTTyWX71kndeR699f F7c0SUUdO3gm8mHxyRpXAs+gbOhqSbaIqosYs98+5S9+8taB2f/AxxZXGjb16RxUXFMpdf2ef Xzu1VXczm9rRkNp9jqaJ8ypTposUiew4HPIxlb9fQImlOCPRUIu5qDgRAB4sc3KLAgAA X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-16.tower-21.messagelabs.com!1491424127!57913923!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.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 52174 invoked from network); 5 Apr 2017 20:28:48 -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; 5 Apr 2017 20:28:48 -0000 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 61BF420121; Wed, 5 Apr 2017 20:28:46 +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 407462011E; Wed, 5 Apr 2017 20:28:45 +0000 (UTC) From: Stefano Stabellini To: julien.grall@arm.com Date: Wed, 5 Apr 2017 13:28:42 -0700 Message-Id: <1491424123-31001-1-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-Virus-Scanned: ClamAV using ClamSMTP Cc: xen-devel@lists.xenproject.org, sstabellini@kernel.org Subject: [Xen-devel] [PATCH v7 1/2] arm: remove irq from inflight, then change physical affinity 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 This patch fixes a potential race that could happen when gic_update_one_lr and vgic_vcpu_inject_irq run simultaneously. When GIC_IRQ_GUEST_MIGRATING is set, we must make sure that the irq has been removed from inflight before changing physical affinity, to avoid concurrent accesses to p->inflight, as vgic_vcpu_inject_irq will take a different vcpu lock. Signed-off-by: Stefano Stabellini Reviewed-by: Julien Grall --- xen/arch/arm/gic.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index 9522c6c..2455d8f 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -503,6 +503,13 @@ static void gic_update_one_lr(struct vcpu *v, int i) gic_raise_guest_irq(v, irq, p->priority); else { list_del_init(&p->inflight); + /* + * Remove from inflight, then change physical affinity. It + * makes sure that when a new interrupt is received on the + * next pcpu, inflight is already cleared. No concurrent + * accesses to inflight. + */ + smp_wmb(); if ( test_and_clear_bit(GIC_IRQ_GUEST_MIGRATING, &p->status) ) { struct vcpu *v_target = vgic_get_target_vcpu(v, irq);