From patchwork Thu Dec 7 16:14:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 121019 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8556366qgn; Thu, 7 Dec 2017 08:16:43 -0800 (PST) X-Google-Smtp-Source: AGs4zMZj1c5nz/G8K6vgVQY5N5Ov7ssA7Fe0NR0uu8fBspSlzpfQ6POhqK4HOoEgjXb/IWToWxks X-Received: by 10.36.60.212 with SMTP id m203mr1894166ita.96.1512663403213; Thu, 07 Dec 2017 08:16:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512663403; cv=none; d=google.com; s=arc-20160816; b=Ws0zMhdCQkjaOaUNKPkfCRn8priMmBEs96GQfkALqPEAWX5luopwWS/jA1fjF92jFa 3j9iumQeAjkQWBq63zktWLAF08s28Bs5WXqo6j5bFEo72dc79D/vVcq6cNZqZRtj1Wcw GTmWza0Ouq/DJvFsckGSfcICoCQzhvILVEW5kFPc06h4SSFiJa58LZz7eYoEyZ22XtBW GbC3mCwdSkJ0xrFN/gN9uT4rIUE0pfHzs+KZT0WZLIugFisyPxh8ZcXgTwyxr1crAksw 5j9mjy+WVd4KubQ3nvZiuKZnpENv0nW2x2jVtUpRpdNrIqXR3YzBNxuuQSA7SpVMS5Ks 56dQ== 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=mu0m8YWIUGtfXqW49ihMLymcOda7ZLG/WQb1yw0mbts=; b=X1qyjJp4y3/mfbNMbHYYcMXRWT80j9b/tj7I/lCTcUs5UZ4IySMTSt9aX0vKs1pml9 p9LUCQI/L8EGGw2e43freLP7IW4AlTRomDzd7kJcocELJRanmcF9fY8XtrbCRirvHhrv rDYaEgCIjzR5k+BFUi7diBjPwxxUIu1EQ1iJw/ZdntgozE5UPISd30MH+wFLz/djidAB 7xoB2f5bil1gTa0dC0U5Pl7yogtqdV0Enc1DH9b1aaCI46XKrP85DrbF4HerQlEENBKj 8k12WYdWEhu/S8i7TWckDcpg54Sz6wpTtXIRPUSGi2zRmYlG977+NT5VZMyyO7mzi1ge yS6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=j7fB5itl; 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 g74si3674236iod.27.2017.12.07.08.16.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Dec 2017 08:16:43 -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=j7fB5itl; 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 1eMyob-0002Ey-24; Thu, 07 Dec 2017 16:14:25 +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 1eMyoa-0002Dc-8u for xen-devel@lists.xenproject.org; Thu, 07 Dec 2017 16:14:24 +0000 X-Inumbo-ID: a1d9d1ec-db69-11e7-b4a6-bc764e045a96 Received: from mail-wr0-x244.google.com (unknown [2a00:1450:400c:c0c::244]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id a1d9d1ec-db69-11e7-b4a6-bc764e045a96; Thu, 07 Dec 2017 17:13:59 +0100 (CET) Received: by mail-wr0-x244.google.com with SMTP id z34so8033042wrz.10 for ; Thu, 07 Dec 2017 08:14:23 -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=Avt4BIS9qBbnrFc4YdYhW4IpkrTa3XtLJry/jD2Qobo=; b=j7fB5itliSeJWindUcMtkqH9lMcrADraRKPX7mhY+l2m0p8IGit5PPU8QLVPV/rLs2 1ajRoj1BxfAMPqgAW4iRv44iCzdSuFvfg7QtKntVZp8djt9KuVLlZTxjdjTEhQoDQNDR +IyD2IE/kZjS9EGkjbWpg2YV4KBAvOk8TFQ0I= 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=Avt4BIS9qBbnrFc4YdYhW4IpkrTa3XtLJry/jD2Qobo=; b=Xu4VRAABxdJe2uIeW3xfz1Zh5PCvGKIwJdy6cKul/nQcGcJOPqAzXTYID5nQawZjM4 GdWotDs3R3nh4r9Ng1disZa9S+5fTnGhHT37hifctHJ5RaJ9nbQg7JjXeO53tUWnswEo hmFg0AU8Xqx6PziyfwVHFrkZ5mJ0Vdc1DrgqXPlN/mytMLA7kl4gF7pT/M5Rgrmafkim jbb7WEpdg9LtZOC3+sbcy1Hw95Jci9KZe8R1bI8T2WcnK6aJ94r4vaziNbwwQqHnd2IR p/jKiW0DldJ0mNYg2ZxEaomqgDBa0NvQWoWeHLBJjRbLSDkIHKako8PQFjU/kupDKukh lONQ== X-Gm-Message-State: AJaThX4sBYJJT02SDOUIpMeqrpGtdGO1PU2mzrQsJZn7AR/BdIr816ka uTMSZ0n+AI/4yDfbjlgEN77LAw== X-Received: by 10.223.139.8 with SMTP id n8mr24030955wra.225.1512663262160; Thu, 07 Dec 2017 08:14:22 -0800 (PST) Received: from e104803-lin.lan (mail.andrep.de. [217.160.17.100]) by smtp.gmail.com with ESMTPSA id f18sm6090624wrg.66.2017.12.07.08.14.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Dec 2017 08:14:21 -0800 (PST) From: Andre Przywara To: Stefano Stabellini , Julien Grall Date: Thu, 7 Dec 2017 16:14:13 +0000 Message-Id: <20171207161415.20380-9-andre.przywara@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171207161415.20380-1-andre.przywara@linaro.org> References: <20171207161415.20380-1-andre.przywara@linaro.org> Cc: xen-devel@lists.xenproject.org Subject: [Xen-devel] [PATCH v2 08/10] ARM: VGIC: factor out vgic_connect_hw_irq() 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" At the moment we happily access VGIC internal data structures like the rank and struct pending_irq in gic.c, which should be VGIC agnostic. Factor out a new function vgic_connect_hw_irq(), which allows a virtual IRQ to be connected to a hardware IRQ (using the hw bit in the LR). This removes said accesses to VGIC data structures and improves abstraction. Signed-off-by: Andre Przywara Acked-by: Stefano Stabellini --- xen/arch/arm/gic-vgic.c | 31 +++++++++++++++++++++++++++++++ xen/arch/arm/gic.c | 42 ++++++------------------------------------ xen/include/asm-arm/vgic.h | 2 ++ 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/xen/arch/arm/gic-vgic.c b/xen/arch/arm/gic-vgic.c index 90b827c574..37f005d99c 100644 --- a/xen/arch/arm/gic-vgic.c +++ b/xen/arch/arm/gic-vgic.c @@ -414,6 +414,37 @@ void gic_dump_vgic_info(struct vcpu *v) printk("Pending irq=%d\n", p->irq); } +int vgic_connect_hw_irq(struct domain *d, struct vcpu *v, unsigned int virq, + struct irq_desc *desc) +{ + unsigned long flags; + /* Use vcpu0 to retrieve the pending_irq struct. Given that we only + * route SPIs to guests, it doesn't make any difference. */ + struct vcpu *v_target = vgic_get_target_vcpu(d->vcpu[0], virq); + struct vgic_irq_rank *rank = vgic_rank_irq(v_target, virq); + struct pending_irq *p = irq_to_pending(v_target, virq); + int ret = 0; + + /* We are taking to rank lock to prevent parallel connections. */ + vgic_lock_rank(v_target, rank, flags); + + if ( desc ) + { + /* The VIRQ should not be already enabled by the guest */ + if ( !p->desc && + !test_bit(GIC_IRQ_GUEST_ENABLED, &p->status) ) + p->desc = desc; + else + ret = -EBUSY; + } + else + p->desc = NULL; + + vgic_unlock_rank(v_target, rank, flags); + + return ret; +} + /* * Local variables: * mode: C diff --git a/xen/arch/arm/gic.c b/xen/arch/arm/gic.c index 4cb74d449e..d46a6d54b3 100644 --- a/xen/arch/arm/gic.c +++ b/xen/arch/arm/gic.c @@ -128,27 +128,12 @@ void gic_route_irq_to_xen(struct irq_desc *desc, unsigned int priority) int gic_route_irq_to_guest(struct domain *d, unsigned int virq, struct irq_desc *desc, unsigned int priority) { - unsigned long flags; - /* Use vcpu0 to retrieve the pending_irq struct. Given that we only - * route SPIs to guests, it doesn't make any difference. */ - struct vcpu *v_target = vgic_get_target_vcpu(d->vcpu[0], virq); - struct vgic_irq_rank *rank = vgic_rank_irq(v_target, virq); - struct pending_irq *p = irq_to_pending(v_target, virq); - int res = -EBUSY; - ASSERT(spin_is_locked(&desc->lock)); /* Caller has already checked that the IRQ is an SPI */ ASSERT(virq >= 32); ASSERT(virq < vgic_num_irqs(d)); ASSERT(!is_lpi(virq)); - vgic_lock_rank(v_target, rank, flags); - - if ( p->desc || - /* The VIRQ should not be already enabled by the guest */ - test_bit(GIC_IRQ_GUEST_ENABLED, &p->status) ) - goto out; - desc->handler = gic_hw_ops->gic_guest_irq_type; set_bit(_IRQ_GUEST, &desc->status); @@ -156,31 +141,19 @@ int gic_route_irq_to_guest(struct domain *d, unsigned int virq, gic_set_irq_type(desc, desc->arch.type); gic_set_irq_priority(desc, priority); - p->desc = desc; - res = 0; - -out: - vgic_unlock_rank(v_target, rank, flags); - - return res; + return vgic_connect_hw_irq(d, NULL, virq, desc); } /* This function only works with SPIs for now */ int gic_remove_irq_from_guest(struct domain *d, unsigned int virq, struct irq_desc *desc) { - struct vcpu *v_target = vgic_get_target_vcpu(d->vcpu[0], virq); - struct vgic_irq_rank *rank = vgic_rank_irq(v_target, virq); - struct pending_irq *p = irq_to_pending(v_target, virq); - unsigned long flags; + int ret; ASSERT(spin_is_locked(&desc->lock)); ASSERT(test_bit(_IRQ_GUEST, &desc->status)); - ASSERT(p->desc == desc); ASSERT(!is_lpi(virq)); - vgic_lock_rank(v_target, rank, flags); - if ( d->is_dying ) { desc->handler->shutdown(desc); @@ -198,19 +171,16 @@ int gic_remove_irq_from_guest(struct domain *d, unsigned int virq, */ if ( test_bit(_IRQ_INPROGRESS, &desc->status) || !test_bit(_IRQ_DISABLED, &desc->status) ) - { - vgic_unlock_rank(v_target, rank, flags); return -EBUSY; - } } + ret = vgic_connect_hw_irq(d, NULL, virq, NULL); + if ( ret ) + return ret; + clear_bit(_IRQ_GUEST, &desc->status); desc->handler = &no_irq_type; - p->desc = NULL; - - vgic_unlock_rank(v_target, rank, flags); - return 0; } diff --git a/xen/include/asm-arm/vgic.h b/xen/include/asm-arm/vgic.h index 22c8502c95..f4240df371 100644 --- a/xen/include/asm-arm/vgic.h +++ b/xen/include/asm-arm/vgic.h @@ -219,6 +219,8 @@ int vgic_v2_init(struct domain *d, int *mmio_count); int vgic_v3_init(struct domain *d, int *mmio_count); bool vgic_evtchn_irq_pending(struct vcpu *v); +int vgic_connect_hw_irq(struct domain *d, struct vcpu *v, unsigned int virq, + struct irq_desc *desc); extern int domain_vgic_register(struct domain *d, int *mmio_count); extern int vcpu_vgic_free(struct vcpu *v);