From patchwork Mon Mar 5 16:03:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 130674 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp2853824lja; Mon, 5 Mar 2018 08:07:12 -0800 (PST) X-Google-Smtp-Source: AG47ELtf9j6ym421nsLF8bhUKIkF/5Mg5/oxZ+6CHcCAzhIibVZioHI2yB4UgPf8WUdD5v7bU2lZ X-Received: by 10.107.8.2 with SMTP id 2mr17175458ioi.167.1520266031850; Mon, 05 Mar 2018 08:07:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520266031; cv=none; d=google.com; s=arc-20160816; b=jkD/NXWnHYq7gBbewSF3V3AIDGoOTpwf+xQa/PxF8kuMGd/E39lp3MT+3fgBaPlz9R 5FCwv8X8bTscZ9izp4X8+FMxEHN/xFxhYopneCzPj4YiYkmH8zHYfdPK7h4fJ6IhArln y307qNwGf7nDmieKT6rIk/HcRBvhAwoHCeLsi6EwhYsXU6cCEn/tFmB7zDMyjjrJ2gs1 6+EMnKN1bDm79yMDOwV3uxMx2HXrZKPi4CmtqTqrQaYWcMblNyQ0gEJn7TItMLHrqWgA blaBhCFnfTsEzh9GHx/3ecrQfbnnFsAK/bvcz1yACLTUG60G/QVU4ydobSEOgb7q9pQf c6OQ== 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:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=J+6jUhigkNZNPYpli0XwFX5aieVBPsQWeR6v9oCCUMA=; b=GqCWRTlJBZf5lzanfb65AgDWMDCVz4WLECjAE20pbJLkEnblci4XrFrlDXxLSB9Q3D CSfgJD4jUuJVXmS2hFo94kMRtLm9iUJWg5+tT1604cMnM2iLu1TQmAzP2U2mMZYGJUJe tpcOZ4ep4ev9MeS3Vmj//RMpoBTGfnH0dWl6ANdcZSA8WdiWsqiGJjY32c3Ognu2AZF4 NtIqHwUrQTVQzauHJFbzKMGryIw8IPjZZq8KS9utquy8TQ4NyLBi9BlRt6pXMwvZqGHh DWPjg0svJLxRFGa7A2yaxzqG00dqArLy8qAE0VfsspSU6rgKLU2NpRhcQIMV9WemfswK C2Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=TUJ6UmdD; 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 j123si5719396itg.43.2018.03.05.08.07.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Mar 2018 08:07:11 -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=TUJ6UmdD; 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 1essbr-0008Tk-Ai; Mon, 05 Mar 2018 16:05:07 +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 1essbp-0008Oz-Mc for xen-devel@lists.xenproject.org; Mon, 05 Mar 2018 16:05:05 +0000 X-Inumbo-ID: cfa21455-208e-11e8-ba59-bc764e045a96 Received: from mail-wm0-x244.google.com (unknown [2a00:1450:400c:c09::244]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id cfa21455-208e-11e8-ba59-bc764e045a96; Mon, 05 Mar 2018 17:03:58 +0100 (CET) Received: by mail-wm0-x244.google.com with SMTP id q83so16998579wme.5 for ; Mon, 05 Mar 2018 08:05:03 -0800 (PST) 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=ZEF1DDHHbLsjgmcCJGM6A/gpfafML0OHQyNlR3e2WIc=; b=TUJ6UmdDZ0T2xy4Fr+k3Bly4Usmnnwe6XUx0EuqLHcyNyQCXhXXR5/UjuPQB9I3Dtg GKcbB17fxOs5A7f3TROxH6eZPBdtvOfwOma0LufR1m/h2twVn78eMr1+dOd2zG/b0mk1 ojxiQfx3VYjBTHseEXujHFKyitujZNKcMUv/o= 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=ZEF1DDHHbLsjgmcCJGM6A/gpfafML0OHQyNlR3e2WIc=; b=oi+I4DxFMoli09kcwfEtMXahzwK1UDjYPHx7NLs+3pal3O2XBBL01G6Gg7FPb44bQP dZD+w/2n+ERIU1XC1vXZIlAU4t1NeyLg7QgqdaRi1D3X2FxkEUmmOPJZK30VIbZXJBqM g00K0eT8TTavxCxBgnwlJ1jYk7I7y2VtVeVj5Hv+EecdAieILzi7xbjM5BLG7ZxVwtul 5SyJECs4EQNz5X2+GpHsogQNNKglbSvRi0RDC+jB4oHi38V+Mj9e4i97QJHu4UwbcJWE i5KmEUTXO8JBVIg7RodYPvKY29Q8CLtT4FPMvMMVWARnHoxhmCEcH4AuBYoKRlIYswCB 2dJg== X-Gm-Message-State: AElRT7GlJXlv941nK65zxgy8po53D4rRzPcnAKUB5aPhiOqNAEaIrI5o fulaG5jZAIUfeFZB1tf/BFWa8w== X-Received: by 10.28.66.65 with SMTP id p62mr8239021wma.8.1520265902696; Mon, 05 Mar 2018 08:05:02 -0800 (PST) Received: from e104803-lin.lan (mail.andrep.de. [217.160.17.100]) by smtp.gmail.com with ESMTPSA id y6sm6574381wmy.14.2018.03.05.08.05.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Mar 2018 08:05:02 -0800 (PST) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Mon, 5 Mar 2018 16:03:57 +0000 Message-Id: <20180305160415.16760-40-andre.przywara@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180305160415.16760-1-andre.przywara@linaro.org> References: <20180305160415.16760-1-andre.przywara@linaro.org> Cc: xen-devel@lists.xenproject.org Subject: [Xen-devel] [PATCH 39/57] ARM: new VGIC: Add ACTIVE registers handlers 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 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 some simple check to avoid a pointless warning in this case. Signed-off-by: Andre Przywara --- Changelog RFC ... v1: - remove premature "proper ACTIVE" handler stub - avoid unnecessary warnings on NO-OP register writes - extend comments xen/arch/arm/vgic/vgic-mmio-v2.c | 4 +- xen/arch/arm/vgic/vgic-mmio.c | 103 +++++++++++++++++++++++++++++++++++++++ xen/arch/arm/vgic/vgic-mmio.h | 11 +++++ 3 files changed, 116 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/vgic/vgic-mmio-v2.c b/xen/arch/arm/vgic/vgic-mmio-v2.c index efdd73301d..c93455fbb2 100644 --- a/xen/arch/arm/vgic/vgic-mmio-v2.c +++ b/xen/arch/arm/vgic/vgic-mmio-v2.c @@ -92,10 +92,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 2e939d5e39..c44d67082f 100644 --- a/xen/arch/arm/vgic/vgic-mmio.c +++ b/xen/arch/arm/vgic/vgic-mmio.c @@ -281,6 +281,109 @@ 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; + bool bail_out = false; + + 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 ) + { + gdprintk(XENLOG_ERR, + "%pv: vGICD: IRQ%d: clearing active state not supported\n", + vcpu, irq->intid); + bail_out = true; + } + + vgic_put_irq(vcpu->domain, irq); + if ( bail_out ) + return; + } +} + +/* + * 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; + bool bail_out = false; + + 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 ) + { + gdprintk(XENLOG_ERR, + "%pv: vGICD: IRQ%d: setting active state not supported\n", + vcpu, irq->intid); + bail_out = true; + } + + vgic_put_irq(vcpu->domain, irq); + if ( bail_out ) + return; + } +} + 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 4465f3b7e5..8604720628 100644 --- a/xen/arch/arm/vgic/vgic-mmio.h +++ b/xen/arch/arm/vgic/vgic-mmio.h @@ -118,6 +118,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