From patchwork Fri Feb 9 14:39:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 127831 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp679726ljc; Fri, 9 Feb 2018 06:42:06 -0800 (PST) X-Google-Smtp-Source: AH8x227CMI47uNMZeH8V5ygEbL0cOCpGTjPCFQZ/7Y+t76K2lwE2kdte1eP9iS7xmzbkdjsu7T12 X-Received: by 10.107.131.207 with SMTP id n76mr3496067ioi.268.1518187326436; Fri, 09 Feb 2018 06:42:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518187326; cv=none; d=google.com; s=arc-20160816; b=ztn8MDo4MDDbuKrcISI688WWAf/w8VVMD1CeN7OdJd+fRYAreqhLMSPll/BcVmDRif jvU0YtHcB1dLqOc/rCgDr047NdM1BNMQUT5Il/o9bJnsKZVE6vZHrKX6HbAhBCMEf4dp j4KbnfiP3nUhmI/B9nQKMM//2mwBl5++F6f8H3Z2E4oHwARa2NqKxpfq7ZQulsZ670BW +5mPVTZttO1owskrBhmy4J1FtYj8aqStQW4z/Qd+S+f+iD6HvI48HWEUK6mGu9uu8uqu gWgJKbs7DBI2So7I1ecR4rb+WQJhCEVSPTM7RYpKos+HA1EaPyCllnzccAwHvT1a7QCD s1fA== 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:references:in-reply-to:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=bNCDg+NwvIk2UmkcwxLdj3SyYt4XOLfshlyrzNdmhsg=; b=VlP3S5UIhqz2FIAe82NX2NYgim/tGGiiWgbBwljiZgSKBv/aXasPpUUkvWF7x0/zmB 8nP0uEBT8a8hPJ37QLOR7kOScK1U4nyZ5WdETDSK4HS5B8R9U2sjOGBeTEO59Mrqv55I 4c3kbKbzkNZm1DpaXXYSJtlT9eBF4tOzF059f8AwroV9n11/HVMshGka6+pYXEvVoYRV JXVvFEvHFfeqbx6LBxzGiw9W6pRngTj8R2KsgfM7KlPh2609WUHmO8C13fRkhMXayHtl +k5MwCNw7FCBMWw+uA6qee48hlbeVJ9+1p/5N8ULayvEJRHcmS3OCtp1ueomXlrETwoT f/GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=YhTVCFSw; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id 77si1679947ios.153.2018.02.09.06.42.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Feb 2018 06:42:06 -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; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=YhTVCFSw; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.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 1ek9qV-0000fX-Dm; Fri, 09 Feb 2018 14:40:11 +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 1ek9qU-0000cm-DT for xen-devel@lists.xenproject.org; Fri, 09 Feb 2018 14:40:10 +0000 X-Inumbo-ID: 0ed7e06a-0da7-11e8-ba59-bc764e045a96 Received: from mail-wr0-x244.google.com (unknown [2a00:1450:400c:c0c::244]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 0ed7e06a-0da7-11e8-ba59-bc764e045a96; Fri, 09 Feb 2018 15:39:40 +0100 (CET) Received: by mail-wr0-x244.google.com with SMTP id s5so8495728wra.0 for ; Fri, 09 Feb 2018 06:40:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=O9g16dyyp4RuEs1m1ABpLjm/bA5DfAFDtgekzOC6B/M=; b=YhTVCFSw302CuKYaS1yLagkQC54oWZJxk21pshy6A8aT7owPPjpudJpBukzzHUlHfX oZ2vHREQ3Hb6qwlgy5oambnHi31RXo9yGbpwKp3zbnwox9cSyQiw8/YcgYLukwt91ftw 9vAWoQ/1A95yQk1FWy7K67tGk7yDe0rRjHRN4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=O9g16dyyp4RuEs1m1ABpLjm/bA5DfAFDtgekzOC6B/M=; b=YXgDExpJuMrD1m1BWTaepDKHCFRfs9yRvriaP8VZp/msAGtRkH0XwmzxLKiqWJrXSn z7U6xQ/U3FdjihWgcEDb1xefGLu5i9uQIJveWlrzghPrDMS8vd215EJrKIIUDsE8s3ya QAsl7NoknzRb6gZ0qJG5VhZUZC1wGHgtUBVMF/q7nO5C8nuFClCWhdS2wkd1f5eqkgZk KRgXJCMFlbczlmAT/xmAeANlwSNLvfvgXGBQO/EjeKKIHM7wvRAHZsUKmz5we9qxQn1w wOzXzhSIkqUtayzinvLhSOc2Ut5HqxXZi2ZCAkPYAtWmKBK9B69Atzqt75gIplNvKAB4 ZNIA== X-Gm-Message-State: APf1xPDH7Rjl4Iqi/uyxTykoLibLGXoh4UMq33PvkiRUaZ42DW48/OLE pnPqahVXPdavjsCXUQX519Q2+w== X-Received: by 10.223.161.208 with SMTP id v16mr2492642wrv.11.1518187207173; Fri, 09 Feb 2018 06:40:07 -0800 (PST) Received: from e104803-lin.lan (mail.andrep.de. [217.160.17.100]) by smtp.gmail.com with ESMTPSA id b35sm2552229wra.13.2018.02.09.06.40.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Feb 2018 06:40:06 -0800 (PST) From: Andre Przywara To: Stefano Stabellini , Julien Grall , xen-devel@lists.xenproject.org Date: Fri, 9 Feb 2018 14:39:09 +0000 Message-Id: <20180209143937.28866-22-andre.przywara@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180209143937.28866-1-andre.przywara@linaro.org> References: <20180209143937.28866-1-andre.przywara@linaro.org> Subject: [Xen-devel] [RFC PATCH 21/49] ARM: new VGIC: Add acccessor to new struct vgic_irq instance 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" The new VGIC implementation centers around a struct vgic_irq instance per virtual IRQ. Provide a function to retrieve the right instance for a given IRQ number and (in case of private interrupts) the right VCPU. This also includes the corresponding put function, which does nothing for private interrupts and SPIs, but handles the ref-counting for LPIs. This is based on Linux commit 64a959d66e47, written by Christoffer Dall. Signed-off-by: Andre Przywara --- xen/arch/arm/vgic/vgic.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/vgic/vgic.h | 32 ++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 xen/arch/arm/vgic/vgic.c create mode 100644 xen/arch/arm/vgic/vgic.h diff --git a/xen/arch/arm/vgic/vgic.c b/xen/arch/arm/vgic/vgic.c new file mode 100644 index 0000000000..3075091caa --- /dev/null +++ b/xen/arch/arm/vgic/vgic.c @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2015, 2016 ARM Ltd. + * Imported from Linux ("new" KVM VGIC) and heavily adapted to Xen. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include +#include "vgic.h" + +/* + * Iterate over the VM's list of mapped LPIs to find the one with a + * matching interrupt ID and return a reference to the IRQ structure. + */ +static struct vgic_irq *vgic_get_lpi(struct domain *d, u32 intid) +{ + struct vgic_dist *dist = &d->arch.vgic; + struct vgic_irq *irq = NULL; + + spin_lock(&dist->lpi_list_lock); + + list_for_each_entry( irq, &dist->lpi_list_head, lpi_list ) + { + if ( irq->intid != intid ) + continue; + + /* + * This increases the refcount, the caller is expected to + * call vgic_put_irq() later once it's finished with the IRQ. + */ + vgic_get_irq_kref(irq); + goto out_unlock; + } + irq = NULL; + +out_unlock: + spin_unlock(&dist->lpi_list_lock); + + return irq; +} + +/* + * This looks up the virtual interrupt ID to get the corresponding + * struct vgic_irq. It also increases the refcount, so any caller is expected + * to call vgic_put_irq() once it's finished with this IRQ. + */ +struct vgic_irq *vgic_get_irq(struct domain *d, struct vcpu *vcpu, + u32 intid) +{ + /* SGIs and PPIs */ + if ( intid <= VGIC_MAX_PRIVATE ) + return &vcpu->arch.vgic_cpu.private_irqs[intid]; + + /* SPIs */ + if ( intid <= VGIC_MAX_SPI ) + return &d->arch.vgic.spis[intid - VGIC_NR_PRIVATE_IRQS]; + + /* LPIs */ + if ( intid >= VGIC_MIN_LPI ) + return vgic_get_lpi(d, intid); + + WARN(); + return NULL; +} + +void vgic_put_irq(struct domain *d, struct vgic_irq *irq) +{ + struct vgic_dist *dist = &d->arch.vgic; + + if ( irq->intid < VGIC_MIN_LPI ) + return; + + spin_lock(&dist->lpi_list_lock); + if ( !atomic_dec_and_test(&irq->refcount) ) + { + spin_unlock(&dist->lpi_list_lock); + return; + }; + + list_del(&irq->lpi_list); + dist->lpi_list_count--; + spin_unlock(&dist->lpi_list_lock); + + xfree(irq); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/vgic/vgic.h b/xen/arch/arm/vgic/vgic.h new file mode 100644 index 0000000000..7a15cfdd79 --- /dev/null +++ b/xen/arch/arm/vgic/vgic.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2015, 2016 ARM Ltd. + * Imported from Linux ("new" KVM VGIC) and heavily adapted to Xen. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef __XEN_ARM_VGIC_NEW_H__ +#define __XEN_ARM_VGIC_NEW_H__ + +struct vgic_irq *vgic_get_irq(struct domain *d, struct vcpu *vcpu, + u32 intid); +void vgic_put_irq(struct domain *d, struct vgic_irq *irq); + +static inline void vgic_get_irq_kref(struct vgic_irq *irq) +{ + if ( irq->intid < VGIC_MIN_LPI ) + return; + + atomic_inc(&irq->refcount); +} + +#endif