From patchwork Thu Mar 8 15:24:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 131029 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp6608987lja; Thu, 8 Mar 2018 07:27:01 -0800 (PST) X-Google-Smtp-Source: AG47ELvcSFFjnq39rX8G8AaVzRLNR7QFiq3302iuuS627bzt50mwQgQ6q55MBjLTiXeopSjOqqvb X-Received: by 10.36.227.203 with SMTP id d194mr21197878ith.126.1520522821675; Thu, 08 Mar 2018 07:27:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520522821; cv=none; d=google.com; s=arc-20160816; b=1G74Yqx2vmBQQFjS/31xC1JNjHyp2FdgJvDrLFYH7J5wH2UccIV4D6426+TKQVuJfF dHYw8h4ugyiI/to8mLsFyhTtI3rSNQnMqDRAosXh1u2BJLIP14zMNjdjOEprWgl3lKj+ yHC925a1g3mYW08zK9eOvTfoUR/OoRtrt0LMV4IjpBuEDnytZvEfNKy37dl9vLpuDYns 3uaoDnURe94o6pLf9GLgf0o9JerAsnPAZ0mgJNp7/n2u5Tiwqxhh/i/rgWot7xOgL5wu 1u7bsTDFG/vKwXKTr61/5ZxrRJn4jFY/72/G2vBLfhMi2ApjcNxNWPwnYImZg+Kl71Jz RMXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:message-id:date:to:from :arc-authentication-results; bh=giF/Ybpha8TbSI0Kb3cyksZK7G51xOF0do3QnE5TrAo=; b=iz3UXUlC/NntXjQsDtqOCYRVWwR0wCmwRO89p+7+gUgPANU+200kN9pk6rFXi4bqBX oCHd1HXtQIfTaIdbQrggjnirrDcESvNPGvNjiuHbOLSsMoe0Cy51BA3W5WIJj0Tv9sgg Id7I1ZWv0hTuvKqbNwfIBl8yKcp9585Xmz60ObuxZSge0JwiCxvv0Uo0HYjRmuHN5xJ5 5e7tYhR01DdAWZ4ODToIDIskakFXErS5fJH5k5FnTPMvca9yg/uE8iYqO1BUiZkWbILP ji0bwn+tn6k2Zk7iCcEAga+tAoiJQKgjP/WTFe2Bn4qjhjak9vjyTc850Lou5L+rFB3c a2TQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id l81si14889579ioe.251.2018.03.08.07.27.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Mar 2018 07:27:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1etxP0-0000aU-B0; Thu, 08 Mar 2018 15:24:18 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1etxOz-0000aO-5K for xen-devel@lists.xenproject.org; Thu, 08 Mar 2018 15:24:17 +0000 X-Inumbo-ID: 98fe7444-22e4-11e8-ba59-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 98fe7444-22e4-11e8-ba59-bc764e045a96; Thu, 08 Mar 2018 16:23:05 +0100 (CET) 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 058C31529; Thu, 8 Mar 2018 07:24:15 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.206.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 16FA23F24A; Thu, 8 Mar 2018 07:24:13 -0800 (PST) From: julien.grall@arm.com To: xen-devel@lists.xenproject.org Date: Thu, 8 Mar 2018 15:24:04 +0000 Message-Id: <20180308152404.18160-1-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 Cc: andre.przywara@arm.com, Julien Grall , sstabellini@kernel.org Subject: [Xen-devel] [RFC] xen/arm: Restrict when a physical IRQ can be routed/removed from/to a domain X-BeenThere: xen-devel@lists.xenproject.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.xenproject.org Sender: "Xen-devel" From: Julien Grall Xen is currently allowing to route/remove an interrupt from/to the domain while it is running. However, we never sync the virtual interrupt state to the physical interrupt. This could lead to undesirable effect on the vGIC emulation and potentially the hardware. One solution would be to sync the interrupt state when routing, but I am not sure it is worth the effort as you never really when it is safe to route/remove the interrupt when a domain is running. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- RFC because I am not entirely sure what people are doing with physical interrupt today. --- xen/arch/arm/gic.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index 968e46fabb..653a815127 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -136,6 +136,14 @@ int gic_route_irq_to_guest(struct domain *d, unsigned int virq, ASSERT(virq < vgic_num_irqs(d)); ASSERT(!is_lpi(virq)); + /* + * When routing an IRQ to guest, the virtual state is not synced + * back to the physical IRQ. To prevent get unsync, restrict the + * routing to when the Domain is been created. + */ + if ( d->creation_finished ) + return -EBUSY; + ret = vgic_connect_hw_irq(d, NULL, virq, desc, true); if ( ret ) return ret; @@ -160,25 +168,19 @@ int gic_remove_irq_from_guest(struct domain *d, unsigned int virq, ASSERT(test_bit(_IRQ_GUEST, &desc->status)); ASSERT(!is_lpi(virq)); - if ( d->is_dying ) - { - desc->handler->shutdown(desc); + /* + * Removing an interrupt while the domain is running may have + * undesirable effect on the vGIC emulation. + */ + if ( !d->is_dying ) + return -EBUSY; - /* EOI the IRQ if it has not been done by the guest */ - if ( test_bit(_IRQ_INPROGRESS, &desc->status) ) - gic_hw_ops->deactivate_irq(desc); - clear_bit(_IRQ_INPROGRESS, &desc->status); - } - else - { - /* - * TODO: Handle eviction from LRs For now, deny - * remove if the IRQ is inflight or not disabled. - */ - if ( test_bit(_IRQ_INPROGRESS, &desc->status) || - !test_bit(_IRQ_DISABLED, &desc->status) ) - return -EBUSY; - } + desc->handler->shutdown(desc); + + /* EOI the IRQ if it has not been done by the guest */ + if ( test_bit(_IRQ_INPROGRESS, &desc->status) ) + gic_hw_ops->deactivate_irq(desc); + clear_bit(_IRQ_INPROGRESS, &desc->status); ret = vgic_connect_hw_irq(d, NULL, virq, desc, false); if ( ret )