From patchwork Wed Mar 21 16:32:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 132211 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp2355974ljb; Wed, 21 Mar 2018 09:34:55 -0700 (PDT) X-Google-Smtp-Source: AG47ELuKMGYXr3vksBtXsmO6VnjAh6MqZqFtYP5jprnaGW1cAwa6JA73tG/v41YIJJWGxY/4wBXM X-Received: by 10.107.19.144 with SMTP id 16mr21035340iot.276.1521650095029; Wed, 21 Mar 2018 09:34:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521650095; cv=none; d=google.com; s=arc-20160816; b=i9IDT4HZIdoZ0gDzR+1cs7Fg9/XZNJa1cjMw2xiE8SRWWHryFbmPsIrkFz3ZNkZny8 Pi8cy3SAhoqEQV+5nzPMCdoiQlFps8ZV+qcyWyBSEZauvWsygc2aE/jB7+aGyOdXFi9A HRtxgpJe+S8RTmKs3YqN40yWbXFYZgKXB7RcRKko4Vs8yB7f5EWAPnNAN1ChM8S2qMp1 aiFuoUAfrc1+F94iCA/UQ/5PbiwtpM6FSQH7ae+Y0Td0ehr35BHB81163Rziz3JPY7NX WQC0MRCFN/iRCr0CfBw0qbuNu2idGCfjdW2mtzP3ilEMcyLlBWFaJ8UhBWsVEyl41Eai P0Xw== 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=ofgs2STs6JMaK81auMtiassSBXtbJvx8VSSSZYYxtNs=; b=sYXsXJivxVvA1K2lhdHvD/2lj15JJUdnhj7Wgb4vJ4mjCc0iwkr08erL4qtBa/byPx Wtnko7ejQNhvVFQ/1WwiM9BmElT0G8FwPmRfoJrj5u3n4am/hO4Fxo1NlGlNfSgwJTsx JKYqULj4WUiJuD1as4z2fuWO60nu+ubBj7FVu+g3FRRFUXOoyj45AkyQWOGyqQGKxluZ BhvYFMREZ3V29B/2ZyzZU0vecFb4ZudvcY71lLu0gpOelGFkGQsRbYGWUYwpJbjzTUrI DV8uxqKC8OX14HjMHyJNzB9/IRCruXWTR7w7J1hJF5AT4uIkCzjywr+pP9J3gDKGgJnz 1kpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=IB68x1NT; 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 w15si3463247iof.6.2018.03.21.09.34.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Mar 2018 09:34:55 -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=IB68x1NT; 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 1eygfo-0002Ry-Ei; Wed, 21 Mar 2018 16:33:12 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1eygfn-0002OY-1D for xen-devel@lists.xenproject.org; Wed, 21 Mar 2018 16:33:11 +0000 X-Inumbo-ID: 811b4655-2d25-11e8-9728-bc764e045a96 Received: from mail-wr0-x241.google.com (unknown [2a00:1450:400c:c0c::241]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 811b4655-2d25-11e8-9728-bc764e045a96; Wed, 21 Mar 2018 17:32:54 +0100 (CET) Received: by mail-wr0-x241.google.com with SMTP id d10so5834896wrf.3 for ; Wed, 21 Mar 2018 09:33:09 -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=F8vfhgFRcBJqlDcJx2F0StunDeogV8MgyMEJGsIKohQ=; b=IB68x1NTLsevur4NrY6XbHRH9cbqG6ssCE2PxutVjvTnLRtP99QTfHOIvGol1P97hE 7a1L91k3fZwJHXfU1Jae4o/8EoMZJ5H9mBLlEsUTKRMO4hkpjwRmOsVK85Euen3PqqBB 1ypt8EMEPtHJDf7S6NGtVopNW3FmljLgCFm5A= 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=F8vfhgFRcBJqlDcJx2F0StunDeogV8MgyMEJGsIKohQ=; b=H7afjF7miiviGlzrGNd7QwIs/kiABx3qd0nhr4bewyNJhqF4XnSx0BjzomMvLY9eOS VPmxu1WttcZE4BViTuXXyr5S1GotGEvuiEacsreJGiODkybUhf2S5nVmK7xZTRaCIf37 vQBfBX/FgVRdMe+9xMPz9VQbDDBULvGYyE/hJZQfQC00rYtUYhEaGHGZeAqNa6GCgTFS nrtvbYO6elTql6OBCZ6zIkO10G4m97R80ox8shTayGYu24JiHRt2SuCv0h7s7ibWnD+Y Mh3zmXbVm44/0hKzVTwTNsyhftiOAmQY2DVeypVS0y/RjXdytQ+HcnPt3xOv7sB1eAhs dZqw== X-Gm-Message-State: AElRT7HKFrUZBlYmVIAwxtW11krogMg/TpJPrZ8UIUAh78+738Cap2xR JhQEPPKggDnmEU4B0siBtOuRUg== X-Received: by 10.223.138.234 with SMTP id z39mr17963512wrz.35.1521649987822; Wed, 21 Mar 2018 09:33:07 -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.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Mar 2018 09:33:07 -0700 (PDT) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Wed, 21 Mar 2018 16:32:14 +0000 Message-Id: <20180321163235.12529-19-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 18/39] ARM: new VGIC: Add CTLR, TYPER and IIDR 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" Those three registers are v2 emulation specific, so their implementation lives entirely in vgic-mmio-v2.c. Also they are handled in one function, as their implementation is pretty simple. We choose to piggy-back on the existing KVM identification registers, but use a different variant (major revision). When the guest enables the distributor, we kick all VCPUs to get potentially pending interrupts serviced. This is based on Linux commit 2b0cda878965, written by Marc Zyngier. Signed-off-by: Andre Przywara Reviewed-by: Julien Grall Acked-by: Stefano Stabellini --- Changelog v2 ... v3: - fix misleading comment about PRODUCT_ID letter - clarify on meaning of VARIANT_ID_XEN Changelog v1 ... v2: use new IIDR values (KVM product ID, Xen revision) - add comment on handling GICD enablement - use new vcpu_kick() function xen/arch/arm/vgic/vgic-mmio-v2.c | 63 +++++++++++++++++++++++++++++++++++++++- xen/arch/arm/vgic/vgic.c | 15 ++++++++++ xen/arch/arm/vgic/vgic.h | 9 ++++++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/vgic/vgic-mmio-v2.c b/xen/arch/arm/vgic/vgic-mmio-v2.c index 6f10cf16ca..43c1ab5906 100644 --- a/xen/arch/arm/vgic/vgic-mmio-v2.c +++ b/xen/arch/arm/vgic/vgic-mmio-v2.c @@ -20,9 +20,70 @@ #include "vgic.h" #include "vgic-mmio.h" +static unsigned long vgic_mmio_read_v2_misc(struct vcpu *vcpu, + paddr_t addr, unsigned int len) +{ + uint32_t value; + + switch ( addr & 0x0c ) /* filter for the 4 registers handled here */ + { + case GICD_CTLR: + value = vcpu->domain->arch.vgic.enabled ? GICD_CTL_ENABLE : 0; + break; + case GICD_TYPER: + value = vcpu->domain->arch.vgic.nr_spis + VGIC_NR_PRIVATE_IRQS; + value = (value >> 5) - 1; + value |= (vcpu->domain->max_vcpus - 1) << 5; + break; + case GICD_IIDR: + value = (PRODUCT_ID_KVM << 24) | + (VARIANT_ID_XEN << 16) | + (IMPLEMENTER_ARM << 0); + break; + default: + return 0; + } + + return value; +} + +static void vgic_mmio_write_v2_misc(struct vcpu *vcpu, + paddr_t addr, unsigned int len, + unsigned long val) +{ + struct vgic_dist *dist = &vcpu->domain->arch.vgic; + bool enabled; + + switch ( addr & 0x0c ) /* filter for the 4 registers handled here */ + { + case GICD_CTLR: + domain_lock(vcpu->domain); + + /* + * Store the new enabled state in our distributor structure. + * Work out whether it was disabled before and now got enabled, + * so that we signal all VCPUs to check for interrupts to be injected. + */ + enabled = dist->enabled; + dist->enabled = val & GICD_CTL_ENABLE; + enabled = !enabled && dist->enabled; + + domain_unlock(vcpu->domain); + + if ( enabled ) + vgic_kick_vcpus(vcpu->domain); + + break; + case GICD_TYPER: + case GICD_IIDR: + /* read-only, writes ignored */ + return; + } +} + static const struct vgic_register_region vgic_v2_dist_registers[] = { REGISTER_DESC_WITH_LENGTH(GICD_CTLR, - vgic_mmio_read_raz, vgic_mmio_write_wi, 12, + vgic_mmio_read_v2_misc, vgic_mmio_write_v2_misc, 12, VGIC_ACCESS_32bit), REGISTER_DESC_WITH_BITS_PER_IRQ(GICD_IGROUPR, vgic_mmio_read_rao, vgic_mmio_write_wi, 1, diff --git a/xen/arch/arm/vgic/vgic.c b/xen/arch/arm/vgic/vgic.c index 925cda4580..37b425a16c 100644 --- a/xen/arch/arm/vgic/vgic.c +++ b/xen/arch/arm/vgic/vgic.c @@ -684,6 +684,21 @@ int vgic_vcpu_pending_irq(struct vcpu *vcpu) return ret; } +void vgic_kick_vcpus(struct domain *d) +{ + struct vcpu *vcpu; + + /* + * We've injected an interrupt, time to find out who deserves + * a good kick... + */ + for_each_vcpu( d, vcpu ) + { + if ( vgic_vcpu_pending_irq(vcpu) ) + vcpu_kick(vcpu); + } +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/vgic/vgic.h b/xen/arch/arm/vgic/vgic.h index 7f221fd195..aed7e4179a 100644 --- a/xen/arch/arm/vgic/vgic.h +++ b/xen/arch/arm/vgic/vgic.h @@ -17,6 +17,14 @@ #ifndef __XEN_ARM_VGIC_VGIC_H__ #define __XEN_ARM_VGIC_VGIC_H__ +/* + * We piggy-back on the already used KVM product ID, but use a different + * variant (major revision) for Xen. + */ +#define PRODUCT_ID_KVM 0x4b /* ASCII code K */ +#define VARIANT_ID_XEN 0x01 +#define IMPLEMENTER_ARM 0x43b + #define vgic_irq_is_sgi(intid) ((intid) < VGIC_NR_SGIS) static inline bool irq_is_pending(struct vgic_irq *irq) @@ -37,6 +45,7 @@ struct vgic_irq *vgic_get_irq(struct domain *d, struct vcpu *vcpu, void vgic_put_irq(struct domain *d, struct vgic_irq *irq); void vgic_queue_irq_unlock(struct domain *d, struct vgic_irq *irq, unsigned long flags); +void vgic_kick_vcpus(struct domain *d); static inline void vgic_get_irq_kref(struct vgic_irq *irq) {