From patchwork Wed Mar 21 16:32:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 132208 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp2355927ljb; Wed, 21 Mar 2018 09:34:52 -0700 (PDT) X-Google-Smtp-Source: AIpwx48two3iadqwycyLpbPMDgVzVPraC2RaiRW0qsA2fI/Wz9RGSE+Oh8NPiqeopF37OgsksVGc X-Received: by 2002:a24:2289:: with SMTP id o131-v6mr4749211ito.95.1521650092207; Wed, 21 Mar 2018 09:34:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521650092; cv=none; d=google.com; s=arc-20160816; b=LUNH6Rx5RzjI3koIUWnLwn4Lpl9VtbmPMGHU57MA0+11JlLnCyEx9qD7wPUdVqhNj3 7yl6OYmuxGnsQ/kLqRjM0Y/NhhvAKi7MA9QiWa5DP+93UU76TFUzGoSXtRRroPl0xn39 7XjoAPNlYq6Ih1v5Mu5+Ckx+/+bFm9suP7defISD6Gt9ROyCWGoddcKrMbsbSLNX2QOL kU0HIYcxhu055Ih/N+EoH3gINQQAhpKLtM9W5+cM/avQVn7aLlYehiyGhQn5QJkqOkoj j/Hi6dt34xxSb73aH4EYDeN83RM8MTVRyRoGk/KPS7Abb2eu5Ja0YBr4FbcST2KNXWrT i8wQ== 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:cc :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=egc670A50FwE4L/YwnYg3jRWo7/gVzGQp7BfMoP+8wc=; b=VYEs3i4aPBjR3Pf3hJ8xf7eSLK18n/VOSjIPwQWjmeUTO2UjPlNy7pUz4TE3bolNtO 2eGWjZCbnmbAl7a+iHRc1PBnfD7zjSnRvt8N9djQ/oS3qb7pTp+thZ2g/U/kXNR3Vkry O6+LwHuSVpSMA9AWDZWhfMtnP66hNkmfWSLy0XmWY+88AmMCFSv+P4eyVWksqHBWS5W+ hXlICBZsh98v9qY2w+vy7i5GVbIrsPgLpwy9/g6ZO2tN+exM7AstzI9/Ti99omYJA3hi L8RK9ufkeqWORK00dBF9kjKT4ClpnpYAZApmhYeVA9k86O5jWYCQwx+vIYVR+O150lR0 4R7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=RlS51ftO; 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 w73si3489225iod.167.2018.03.21.09.34.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Mar 2018 09:34:52 -0700 (PDT) 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=RlS51ftO; 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.89) (envelope-from ) id 1eygfr-0002YT-HS; Wed, 21 Mar 2018 16:33:15 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1eygfp-0002Up-UV for xen-devel@lists.xenproject.org; Wed, 21 Mar 2018 16:33:13 +0000 X-Inumbo-ID: 82f74b2f-2d25-11e8-9728-bc764e045a96 Received: from mail-wr0-x243.google.com (unknown [2a00:1450:400c:c0c::243]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 82f74b2f-2d25-11e8-9728-bc764e045a96; Wed, 21 Mar 2018 17:32:57 +0100 (CET) Received: by mail-wr0-x243.google.com with SMTP id 80so4751583wrb.2 for ; Wed, 21 Mar 2018 09:33:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KbFD/NykhgfOH8Sqsd0U9Ani0iUCMPK3bzDMVlbDAb0=; b=RlS51ftO3+K1ct+GK2RGAnsSBDi0rmayn65v1tJUsBDquPdzpAUKiYlCIyQvoCsZJ9 H8DfxdcLFffslA6ib4ktMSra3hNkDthgQO6/6s+3X+nqrvlA9UaEWS5Fc2REORBZWPgg hncueGOsxASU5CMuQXr+G2jD8NXeLanWw9i6g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KbFD/NykhgfOH8Sqsd0U9Ani0iUCMPK3bzDMVlbDAb0=; b=JYX50y72E2F2q+Fy1FUyXPAlmZfZOHKYcD4UPsfSg4WILtsv6NbnzXcDZw//brsLTR mlCgXBEGX6KlQpm3NA9scw6Ecdcbk7wE4Zt6MNGAJpokEL/hxzH+FtrY7AXc07CNQqIf b4bXkKxce3A06PRrcBoSTUgg8jBOtOq8g6wPrb/+RnsaQXF1v9WzGntB6F8eR/0mKnqu 89MnJk0Jp6RaKsD869+4dTYIkZzq4y3+U4gYfO+7aTiwMXQU6vpjcqllTrltAPJn6wb3 m4PnSsTdYku5D4nXL7JLYQMVBYlWzaLB5JGLsWWcqtRlS/N6H3GMwLXsRRnlwJ0YmxdF 8+WQ== X-Gm-Message-State: AElRT7Hq58ZFMQ+GQglXgYBmO3nRQ8fmWq2UIlHAfrlQEitGfDjTBDL/ IoRwj+aWQh103fW7jiullyY3/A== X-Received: by 10.223.193.129 with SMTP id x1mr8503671wre.166.1521649991055; Wed, 21 Mar 2018 09:33:11 -0700 (PDT) Received: from e104803-lin.lan (mail.andrep.de. [217.160.17.100]) by smtp.gmail.com with ESMTPSA id n64sm4423724wmd.11.2018.03.21.09.33.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Mar 2018 09:33:10 -0700 (PDT) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Wed, 21 Mar 2018 16:32:17 +0000 Message-Id: <20180321163235.12529-22-andre.przywara@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180321163235.12529-1-andre.przywara@linaro.org> References: <20180321163235.12529-1-andre.przywara@linaro.org> Subject: [Xen-devel] [PATCH v3 21/39] ARM: new VGIC: Add ACTIVE registers handlers X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: xen-devel@lists.xenproject.org, Andre Przywara MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The active register handlers are shared between the v2 and v3 emulation, so their implementation goes into vgic-mmio.c, to be easily referenced from the v3 emulation as well later. Since activation/deactivation of an interrupt may happen entirely in the guest without it ever exiting, we need some extra logic to properly track the active state. For clearing the active state, we would basically have to halt the guest to make sure this is properly propagated into the respective VCPUs. This is not yet implemented in Xen. Fortunately this feature is mostly used to reset a just in initialised GIC, so chances are we are tasked to clear bits that are already zero. Add a simple check to avoid pointless warnings in this case. Signed-off-by: Andre Przywara Reviewed-by: Julien Grall --- xen/arch/arm/vgic/vgic-mmio-v2.c | 4 +- xen/arch/arm/vgic/vgic-mmio.c | 91 ++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/vgic/vgic-mmio.h | 11 +++++ 3 files changed, 104 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/vgic/vgic-mmio-v2.c b/xen/arch/arm/vgic/vgic-mmio-v2.c index a48c554040..724681e0f8 100644 --- a/xen/arch/arm/vgic/vgic-mmio-v2.c +++ b/xen/arch/arm/vgic/vgic-mmio-v2.c @@ -101,10 +101,10 @@ static const struct vgic_register_region vgic_v2_dist_registers[] = { vgic_mmio_read_pending, vgic_mmio_write_cpending, 1, VGIC_ACCESS_32bit), REGISTER_DESC_WITH_BITS_PER_IRQ(GICD_ISACTIVER, - vgic_mmio_read_raz, vgic_mmio_write_wi, 1, + vgic_mmio_read_active, vgic_mmio_write_sactive, 1, VGIC_ACCESS_32bit), REGISTER_DESC_WITH_BITS_PER_IRQ(GICD_ICACTIVER, - vgic_mmio_read_raz, vgic_mmio_write_wi, 1, + vgic_mmio_read_active, vgic_mmio_write_cactive, 1, VGIC_ACCESS_32bit), REGISTER_DESC_WITH_BITS_PER_IRQ(GICD_IPRIORITYR, vgic_mmio_read_raz, vgic_mmio_write_wi, 8, diff --git a/xen/arch/arm/vgic/vgic-mmio.c b/xen/arch/arm/vgic/vgic-mmio.c index 53b8978c02..b79e431f50 100644 --- a/xen/arch/arm/vgic/vgic-mmio.c +++ b/xen/arch/arm/vgic/vgic-mmio.c @@ -281,6 +281,97 @@ void vgic_mmio_write_cpending(struct vcpu *vcpu, } } +/* + * The actual active bit for a virtual IRQ is held in the LR. Our shadow + * copy in struct vgic_irq is only synced when needed and may not be + * up-to-date all of the time. + * Returning the actual active state is quite costly (stopping all + * VCPUs processing any affected vIRQs), so we use a simple implementation + * to get the best possible answer. + */ +unsigned long vgic_mmio_read_active(struct vcpu *vcpu, + paddr_t addr, unsigned int len) +{ + uint32_t intid = VGIC_ADDR_TO_INTID(addr, 1); + uint32_t value = 0; + unsigned int i; + + /* Loop over all IRQs affected by this read */ + for ( i = 0; i < len * 8; i++ ) + { + struct vgic_irq *irq = vgic_get_irq(vcpu->domain, vcpu, intid + i); + + if ( irq->active ) + value |= (1U << i); + + vgic_put_irq(vcpu->domain, irq); + } + + return value; +} + +/* + * We don't actually support clearing the active state of an IRQ (yet). + * However there is a chance that most guests use this for initialization. + * We check whether this MMIO access would actually affect any active IRQ, + * and only print our warning in this case. So clearing already non-active + * IRQs would not be moaned about in the logs. + */ +void vgic_mmio_write_cactive(struct vcpu *vcpu, + paddr_t addr, unsigned int len, + unsigned long val) +{ + uint32_t intid = VGIC_ADDR_TO_INTID(addr, 1); + unsigned int i; + + for_each_set_bit( i, &val, len * 8 ) + { + struct vgic_irq *irq = vgic_get_irq(vcpu->domain, vcpu, intid + i); + + /* + * If we know that the IRQ is active or we can't be sure about + * it (because it is currently in a CPU), log the not properly + * emulated MMIO access. + */ + if ( irq->active || irq->vcpu ) + printk(XENLOG_G_ERR + "%pv: vGICD: IRQ%u: clearing active state not supported\n", + vcpu, irq->intid); + + vgic_put_irq(vcpu->domain, irq); + } +} + +/* + * We don't actually support setting the active state of an IRQ (yet). + * We check whether this MMIO access would actually affect any non-active IRQ, + * and only print our warning in this case. + */ +void vgic_mmio_write_sactive(struct vcpu *vcpu, + paddr_t addr, unsigned int len, + unsigned long val) +{ + uint32_t intid = VGIC_ADDR_TO_INTID(addr, 1); + unsigned int i; + + for_each_set_bit( i, &val, len * 8 ) + { + struct vgic_irq *irq = vgic_get_irq(vcpu->domain, vcpu, intid + i); + + /* + * If we know that the IRQ is not active or we can't be sure about + * it (because it is currently in a CPU), log the not properly + * emulated MMIO access. + */ + if ( !irq->active || irq->vcpu ) + printk(XENLOG_G_ERR + "%pv: vGICD: IRQ%u: setting active state not supported\n", + vcpu, irq->intid); + + vgic_put_irq(vcpu->domain, irq); + } +} + static int match_region(const void *key, const void *elt) { const unsigned int offset = (unsigned long)key; diff --git a/xen/arch/arm/vgic/vgic-mmio.h b/xen/arch/arm/vgic/vgic-mmio.h index 5c927f28b0..832e2eb3d8 100644 --- a/xen/arch/arm/vgic/vgic-mmio.h +++ b/xen/arch/arm/vgic/vgic-mmio.h @@ -108,6 +108,17 @@ void vgic_mmio_write_cpending(struct vcpu *vcpu, paddr_t addr, unsigned int len, unsigned long val); +unsigned long vgic_mmio_read_active(struct vcpu *vcpu, + paddr_t addr, unsigned int len); + +void vgic_mmio_write_cactive(struct vcpu *vcpu, + paddr_t addr, unsigned int len, + unsigned long val); + +void vgic_mmio_write_sactive(struct vcpu *vcpu, + paddr_t addr, unsigned int len, + unsigned long val); + unsigned int vgic_v2_init_dist_iodev(struct vgic_io_device *dev); #endif