From patchwork Thu Mar 15 20:30:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 131861 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp1579448ljb; Thu, 15 Mar 2018 13:33:33 -0700 (PDT) X-Google-Smtp-Source: AG47ELvcsvQ38tKBaURc1PMAh4ZpjbM5ghgDAN6umZdThSqJbK7Z+d8Xxy5xIrqVaAhiq0FPokrS X-Received: by 10.107.14.136 with SMTP id 130mr6378599ioo.161.1521146012724; Thu, 15 Mar 2018 13:33:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521146012; cv=none; d=google.com; s=arc-20160816; b=pvINYs9+rR0c87snNxYCyxnSlR4QfnZCt0hz7miZ06jv6y9l3PjLEqbiQbeFVeQSuO OUin4Fp5L1qxDwviH1KMehsmLCf4VKMBzG9MWQyjzyxHEzl876mvGzdl+PxJQD/SIxgk PiaQ3O0JtaqGwmqjtpPEa1p1whKZYfd1umGcb+Gwy3f9T+QaygpPXLK2i5/5Noq50KaK Qz09QcwD6g1Wvy2IRH2Sz4UxonGt624zBY+ThGfnFk/lC3W9K8FXXWN3oUV/SNdzHFjn 3ZWFVPC76fcQBS3F9t4Ik6YKsugzEuxFPpzrF1NZ0vauV2pJw9JXR+XjYestFyF1KEme t5vw== 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=QRz4DQ2RHprKFTOJIWG8vdXR294KmXyip4+tplqAvxM=; b=qlZS/WPIL/nlVrkWGe9tufWe6UkgYF7YoSGEfYrc9Zz/RvDRdiQhc8qbGTJ8sYlEQu qbzT2o6X8rAAyOZZx201sIxfFgQGSpp7BDBghewPftp3gWwuc6hcHbzq0IyPvpnQExFU OGiacKZVjsaG4fCNXNZLUUGWfxSfYSiyZ4pfUm6jJ9tkX+H20cJLmv5PYxLR1jOLDy4E HMqV4NpVAsG4wnU4IWe0loRCNnbNK+IG6IrG9TmJBDIr8PeWH3Eoi2JsuwpO4j7K5G8N lr9pfFE4kJpJbJd+H072aM6+tiEyfR7nmVR2EoICna2H43VqOHI2BhscMcY5Cow+Z5DU YxMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=fYx1Rny6; 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 i125-v6si2988194iti.80.2018.03.15.13.33.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Mar 2018 13:33:32 -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=fYx1Rny6; 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 1ewZXH-0003wD-TO; Thu, 15 Mar 2018 20:31:39 +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 1ewZXH-0003uF-9w for xen-devel@lists.xenproject.org; Thu, 15 Mar 2018 20:31:39 +0000 X-Inumbo-ID: d8a92f1e-288f-11e8-9728-bc764e045a96 Received: from mail-wr0-x242.google.com (unknown [2a00:1450:400c:c0c::242]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id d8a92f1e-288f-11e8-9728-bc764e045a96; Thu, 15 Mar 2018 21:31:32 +0100 (CET) Received: by mail-wr0-x242.google.com with SMTP id h2so9563447wre.12 for ; Thu, 15 Mar 2018 13:31:37 -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=82GlRG1f4RVtKI+Tq+R43bAUTxuz0lyRPr8boAYeSMM=; b=fYx1Rny6ztaj06BCy13WFBVTj8eL4u0MTKog2ZKEVGRcxwcSCL8KJr4o7hVfBoyNK2 9ZVwzv8+JtnPCK5TYkgD/GBK23H/ZWvkacrDHPA7tk+9MpOeT/RLnrBlz5OYeaF9xeQd BmSO1mXl5zOeMHPo0rg6MSN+EafVAKDxGSREs= 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=82GlRG1f4RVtKI+Tq+R43bAUTxuz0lyRPr8boAYeSMM=; b=RF4dpWDZoWbCCMjfW3lEoHUOWLdjuo7Gl8vgRnpeyThWJTx6o18b6DAsjHg2vVk1lR zB/6+0nVmEIjw86ipNiWgJ2ugdlNeEx2k98C4etgiFg4pS9qceTJrKaTTYZr9ad5vGj4 wRJlt/PdjElFQR3iOms4Gg1lxEtzqe1gFfV/K+M4YEu0h+X588PsV8iR7AMoZ7NjXD2T 3aTO7C4v7sYsSBOkQJEJ1wTnRGud4CS3vK1a2L4yhVDavN7d7ekjdt3HNEtpj/3RaZ5K fdgExC+hAjD7OMViHd8WfzbW3uEUE+A0JtHxN3lU2RYOujTAYWG5f50ofTA6I5pswQsH 0NNA== X-Gm-Message-State: AElRT7Gxb2Zkj515moAXooeyCYHiulNeqVGxCiKd4NlIvb3wlYqiOvbY FQFj2QGxiArqUALK1PqRxJyZOQ== X-Received: by 10.223.164.26 with SMTP id d26mr1721669wra.199.1521145896498; Thu, 15 Mar 2018 13:31:36 -0700 (PDT) Received: from e104803-lin.lan (mail.andrep.de. [217.160.17.100]) by smtp.gmail.com with ESMTPSA id w125sm3217102wmw.20.2018.03.15.13.31.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Mar 2018 13:31:35 -0700 (PDT) From: Andre Przywara To: Stefano Stabellini , Julien Grall Date: Thu, 15 Mar 2018 20:30:32 +0000 Message-Id: <20180315203050.19791-28-andre.przywara@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180315203050.19791-1-andre.przywara@linaro.org> References: <20180315203050.19791-1-andre.przywara@linaro.org> Cc: xen-devel@lists.xenproject.org Subject: [Xen-devel] [PATCH v2 27/45] 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 a simple check to avoid pointless warnings in this case. Signed-off-by: Andre Przywara Reviewed-by: Julien Grall --- Changelog v1 ... v2: - print a line for every failing IRQ 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 15183c112c..170017bde3 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