From patchwork Thu May 11 17:53:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9722655 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 1E9EA60236 for ; Thu, 11 May 2017 17:54:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EC87286D9 for ; Thu, 11 May 2017 17:54:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12168286EC; Thu, 11 May 2017 17:54:00 +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 76F65286D9 for ; Thu, 11 May 2017 17:53:59 +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 1d8sFR-0000GY-Ih; Thu, 11 May 2017 17:51:33 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d8sFQ-0000FT-ID for xen-devel@lists.xenproject.org; Thu, 11 May 2017 17:51:32 +0000 Received: from [85.158.139.211] by server-1.bemta-5.messagelabs.com id E9/7E-01992-3A4A4195; Thu, 11 May 2017 17:51:31 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRWlGSWpSXmKPExsVysyfVTXfBEpF IgxeLBSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oydRy+wFLzkr5i/+BhzA2MfbxcjF4eQwGZG iZZdD1i6GDmBnOWMEueumILYbAK6EjtuvmYGsUUEQiWeLvjODNLALLAGqGbRTzaQhLBApMSPL 7+AEhwcLAKqEqdOeIKEeQWsJI42nAArkRCQk2g4fx9sDqeAtcSS6bOgdllJ7Np9mnUCI/cCRo ZVjBrFqUVlqUW6hmZ6SUWZ6RkluYmZObqGBqZ6uanFxYnpqTmJScV6yfm5mxiB/mUAgh2M509 7HmKU5GBSEuVlnCgSKcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mC9+pioJxgUWp6akVaZg4w0GDS Ehw8SiK8mxcBpXmLCxJzizPTIVKnGBWlxHnbQfoEQBIZpXlwbbDgvsQoKyXMywh0iBBPQWpRb mYJqvwrRnEORiVh3p0gU3gy80rgpr8CWswEtLj/jzDI4pJEhJRUA+OsB89/uScv6tp1wED2mF LIponhm9SfzjuiwP3Mrldy72uGXbH8rdfXxemULOyZbqhl2X9USuSTwKrgcL0sn3V54WwzGoM YfzjteZDpJzn9RANH9aMrH1Rqfq1cuOpB26OLUetnXw9rfVVoHjX33Z+WmEULJ21+k8T+RXP2 oVdaxwp+P1/CJntJiaU4I9FQi7moOBEA2RZCl2kCAAA= X-Env-Sender: andre.przywara@arm.com X-Msg-Ref: server-15.tower-206.messagelabs.com!1494525087!83623524!1 X-Originating-IP: [217.140.101.70] 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 52922 invoked from network); 11 May 2017 17:51:28 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-15.tower-206.messagelabs.com with SMTP; 11 May 2017 17:51:28 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 72BBD15BE; Thu, 11 May 2017 10:51:27 -0700 (PDT) Received: from e104803-lin.lan (unknown [10.1.207.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4C0E03F4FF; Thu, 11 May 2017 10:51:26 -0700 (PDT) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Thu, 11 May 2017 18:53:14 +0100 Message-Id: <20170511175340.8448-3-andre.przywara@arm.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170511175340.8448-1-andre.przywara@arm.com> References: <20170511175340.8448-1-andre.przywara@arm.com> Cc: xen-devel@lists.xenproject.org, Vijaya Kumar K , Vijay Kilari , Shanker Donthineni Subject: [Xen-devel] [PATCH v9 02/28] ARM: VGIC: move irq_to_pending() calls under the VGIC VCPU lock 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 So far irq_to_pending() is just a convenience function to lookup statically allocated arrays. This will change with LPIs, which are more dynamic. The proper answer to the issue of preventing stale pointers is ref-counting, which requires more rework and will be introduced with a later rework. For now move the irq_to_pending() calls that are used with LPIs under the VGIC VCPU lock, and only use the returned pointer while holding the lock. This prevents the memory from being freed while we use it. Signed-off-by: Andre Przywara --- xen/arch/arm/gic.c | 5 ++++- xen/arch/arm/vgic.c | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index da19130..dcb1783 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -402,10 +402,13 @@ static inline void gic_add_to_lr_pending(struct vcpu *v, struct pending_irq *n) void gic_remove_from_queues(struct vcpu *v, unsigned int virtual_irq) { - struct pending_irq *p = irq_to_pending(v, virtual_irq); + struct pending_irq *p; unsigned long flags; spin_lock_irqsave(&v->arch.vgic.lock, flags); + + p = irq_to_pending(v, virtual_irq); + if ( !list_empty(&p->lr_queue) ) list_del_init(&p->lr_queue); spin_unlock_irqrestore(&v->arch.vgic.lock, flags); diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c index 83569b0..d30f324 100644 --- a/xen/arch/arm/vgic.c +++ b/xen/arch/arm/vgic.c @@ -466,7 +466,7 @@ void vgic_clear_pending_irqs(struct vcpu *v) void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int virq) { uint8_t priority; - struct pending_irq *iter, *n = irq_to_pending(v, virq); + struct pending_irq *iter, *n; unsigned long flags; bool running; @@ -474,6 +474,8 @@ void vgic_vcpu_inject_irq(struct vcpu *v, unsigned int virq) spin_lock_irqsave(&v->arch.vgic.lock, flags); + n = irq_to_pending(v, virq); + /* vcpu offline */ if ( test_bit(_VPF_down, &v->pause_flags) ) {