From patchwork Thu May 11 17:53:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9722635 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 B07366031B for ; Thu, 11 May 2017 17:53:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFFA2286D0 for ; Thu, 11 May 2017 17:53:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4D49286E5; Thu, 11 May 2017 17:53:30 +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 40150286D0 for ; Thu, 11 May 2017 17:53:30 +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 1d8sFl-0000kL-CA; Thu, 11 May 2017 17:51:53 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d8sFj-0000cV-ME for xen-devel@lists.xenproject.org; Thu, 11 May 2017 17:51:51 +0000 Received: from [85.158.137.68] by server-11.bemta-3.messagelabs.com id EA/D9-01744-7B4A4195; Thu, 11 May 2017 17:51:51 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRWlGSWpSXmKPExsVysyfVTXfbEpF Ig1frDC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyLT+cxFdyTqTj64y9zA2OHWBcjF4eQwGZG iVmnp7NDOMsZJfb23WDpYuTkYBPQldhx8zUziC0iECrxdMF3ZpAiZoE1jBLnFv1kA0kIC1hK3 O1dzAhiswioSiyc1wnWzCtgLfHn/mswW0JATqLh/H2wQZxA8SXTZ4HFhQSsJHbtPs06gZF7AS PDKkb14tSistQiXQu9pKLM9IyS3MTMHF1DA2O93NTi4sT01JzEpGK95PzcTYxADzMAwQ7GC+3 OhxglOZiURHkZJ4pECvEl5adUZiQWZ8QXleakFh9ilOHgUJLgvbYIKCdYlJqeWpGWmQMMNZi0 BAePkgjvZpA0b3FBYm5xZjpE6hSjopQ4L89ioIQASCKjNA+uDRbelxhlpYR5GYEOEeIpSC3Kz SxBlX/FKM7BqCTMawcyhSczrwRu+iugxUxAi/v/CIMsLklESEk1MK57vVvu7Ic8sdJtGfPzfg Xv3fI9fqtAyI60tHMcjFbfBPQ07HZf/tzc/lcwV8w/9GJw9zSTlLA/S1j2/gzLD7DRbW1bc5X lT/21X9/085c5B2am/Jk77Xbm0TuMTJo/7VUNF7msqPfe1LYvXrIxaJtDq1pRvaRW6iLx063i UwtCmF/PP9n2VomlOCPRUIu5qDgRAMRsJPFqAgAA X-Env-Sender: andre.przywara@arm.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1494525110!100005742!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 49526 invoked from network); 11 May 2017 17:51:50 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-14.tower-31.messagelabs.com with SMTP; 11 May 2017 17:51:50 -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 CDC481AED; Thu, 11 May 2017 10:51:49 -0700 (PDT) Received: from e104803-lin.lan (unknown [10.1.207.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A593B3F4FF; Thu, 11 May 2017 10:51:48 -0700 (PDT) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Thu, 11 May 2017 18:53:30 +0100 Message-Id: <20170511175340.8448-19-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 18/28] ARM: vITS: handle CLEAR command 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 introduces the ITS command handler for the CLEAR command, which clears the pending state of an LPI. This removes a not-yet injected, but already queued IRQ from a VCPU. As read_itte() is now eventually used, we add the static keyword. Signed-off-by: Andre Przywara --- xen/arch/arm/vgic-v3-its.c | 59 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/vgic-v3-its.c b/xen/arch/arm/vgic-v3-its.c index 8f1c217..8a200e9 100644 --- a/xen/arch/arm/vgic-v3-its.c +++ b/xen/arch/arm/vgic-v3-its.c @@ -52,6 +52,7 @@ */ struct virt_its { struct domain *d; + paddr_t doorbell_address; unsigned int devid_bits; unsigned int evid_bits; spinlock_t vcmd_lock; /* Protects the virtual command buffer, which */ @@ -251,8 +252,8 @@ static bool read_itte_locked(struct virt_its *its, uint32_t devid, * This function takes care of the locking by taking the its_lock itself, so * a caller shall not hold this. Before returning, the lock is dropped again. */ -bool read_itte(struct virt_its *its, uint32_t devid, uint32_t evid, - struct vcpu **vcpu_ptr, uint32_t *vlpi_ptr) +static bool read_itte(struct virt_its *its, uint32_t devid, uint32_t evid, + struct vcpu **vcpu_ptr, uint32_t *vlpi_ptr) { bool ret; @@ -362,6 +363,57 @@ static int its_handle_mapc(struct virt_its *its, uint64_t *cmdptr) return 0; } +/* + * CLEAR removes the pending state from an LPI. */ +static int its_handle_clear(struct virt_its *its, uint64_t *cmdptr) +{ + uint32_t devid = its_cmd_get_deviceid(cmdptr); + uint32_t eventid = its_cmd_get_id(cmdptr); + struct pending_irq *p; + struct vcpu *vcpu; + uint32_t vlpi; + unsigned long flags; + int ret = -1; + + spin_lock(&its->its_lock); + + /* Translate the DevID/EvID pair into a vCPU/vLPI pair. */ + if ( !read_itte_locked(its, devid, eventid, &vcpu, &vlpi) ) + goto out_unlock; + + p = gicv3_its_get_event_pending_irq(its->d, its->doorbell_address, + devid, eventid); + /* Protect against an invalid LPI number. */ + if ( unlikely(!p) ) + goto out_unlock; + + spin_lock_irqsave(&vcpu->arch.vgic.lock, flags); + + /* + * If the LPI is already visible on the guest, it is too late to + * clear the pending state. However this is a benign race that can + * happen on real hardware, too: If the LPI has already been forwarded + * to a CPU interface, a CLEAR request reaching the redistributor has + * no effect on that LPI anymore. Since LPIs are edge triggered and + * have no active state, we don't need to care about this here. + */ + if ( !test_bit(GIC_IRQ_GUEST_VISIBLE, &p->status) ) + { + /* Remove a pending, but not yet injected guest IRQ. */ + clear_bit(GIC_IRQ_GUEST_QUEUED, &p->status); + list_del_init(&p->inflight); + list_del_init(&p->lr_queue); + } + + spin_unlock_irqrestore(&vcpu->arch.vgic.lock, flags); + ret = 0; + +out_unlock: + spin_unlock(&its->its_lock); + + return ret; +} + #define ITS_CMD_BUFFER_SIZE(baser) ((((baser) & 0xff) + 1) << 12) #define ITS_CMD_OFFSET(reg) ((reg) & GENMASK(19, 5)) @@ -391,6 +443,9 @@ static int vgic_its_handle_cmds(struct domain *d, struct virt_its *its) switch ( its_cmd_get_command(command) ) { + case GITS_CMD_CLEAR: + ret = its_handle_clear(its, command); + break; case GITS_CMD_INT: ret = its_handle_int(its, command); break;