From patchwork Wed Jan 24 18:10:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 125695 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp581009ljf; Wed, 24 Jan 2018 10:13:39 -0800 (PST) X-Google-Smtp-Source: AH8x227Nif64vESL4l5ASTQRBHSzDUW3QVCSnla6SzDykTZlgEhs6VGnVRxvcoshYJrzcl+OmxYy X-Received: by 10.36.23.140 with SMTP id 134mr9708465ith.1.1516817619506; Wed, 24 Jan 2018 10:13:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516817619; cv=none; d=google.com; s=arc-20160816; b=A//+kVb5CN4dJIsFC18CUaN+8od50FgfGbMO/C4R2wmIAaHeIgSZZ0tMvEDUDDMZkU sG48euDHx282MVEEgwPstRfmtfsK30R/Mh6uZzvXOpCjxRvCTuwEWyhjpB+QCGuBKYi6 zRR8d/4fX5XUdviA1AKQIFofW1OOB1T1GVLNUqbJ8pdpl+JnstDgjd6wlNgn/85UuY6q w3PYCycWDGYoXwoK5KNnHF9olnDqJWz7nvhrjryH/2+uTizSw6FcuWAP1nUUFLmH9pEa XREoGhGSBOfc6ccebQojyLCj3jDRS9gIBW7C9qpYK/usp7drwVzlWqqRNxBICe4mTNYO mGOA== 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=25zqqhxj32ALlkF4BQTbo4KpB9zfAPrVScSO23B+k7g=; b=ZoI84zSNm+s5o6K30ttkAQycsVwq+qKspISQDalD8o/mOmtqypeSPJEj++y3CczMZk ercvTdxvJeeIavBxwC4MFUBw5LjHV+bVHiFfWgPfsUqTxwn3s0PudptlzcEDkoZxZ4oS fpKznE9aOI2oNerpRUp5R+XCeZfFURF+m3Uj7xy9Zko/dadya6RuhX//lpAObCSpZhEr FMY5j5vOJ5v9awG4SfrRze9K1FcGdCdzNWPXfiLNpJZjShzxB77fr+dCc304DLGDmeiJ T1qHntGSIaJo5Rfa+VULPY1x3Hku76wR2nkNPlG0raO0KSdaqicBFq3pzx7Xm6eRfXk9 O8Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=AbbNrLK1; 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 d139si607029ioe.265.2018.01.24.10.13.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jan 2018 10:13:39 -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=AbbNrLK1; 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 1eePVm-00078U-Ml; Wed, 24 Jan 2018 18:11:02 +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 1eePVl-000787-KW for xen-devel@lists.xenproject.org; Wed, 24 Jan 2018 18:11:01 +0000 X-Inumbo-ID: eb9d12c2-0131-11e8-ba59-bc764e045a96 Received: from mail-wr0-x243.google.com (unknown [2a00:1450:400c:c0c::243]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id eb9d12c2-0131-11e8-ba59-bc764e045a96; Wed, 24 Jan 2018 19:10:56 +0100 (CET) Received: by mail-wr0-x243.google.com with SMTP id 100so4999857wrb.7 for ; Wed, 24 Jan 2018 10:10:59 -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=3BJ7f1UCU06xK4kAd6tw9wxGfwEUWsS7dDukSKTE1+k=; b=AbbNrLK1UrjxbfoQs0l6mgaPBTNguvtaRE7SpQ+tPQDZmVkEJ9cMeYe/BOGNdfhYqw sg5oQ5bZYdGhxg3GJw5ObC7tA/tkKpWj8VJkxtpDPFVnZ52ph5M2gwBYRkF2q1GdrHEV aSg8zwA8awAK+K9DpAt2Ws1zb6SjyNhFBtyyo= 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=3BJ7f1UCU06xK4kAd6tw9wxGfwEUWsS7dDukSKTE1+k=; b=SvW5Hq8ll8vwzC78BKLAwnCz9vRKELr121EDMRUj9T2voYWyrvsY5aFDQT6okXoapy K02uAFBzW9hPzYoW1esO9elJBbwt3kxcdO937v46oW875OkFRhNB7Yr3BwJsZAsEozEL Br6Vi8weqq2cTd/hFKzVnKe5l4h+t0SqAG7fcz+R69PHP3tZu+UryRUMY11i4CmMECib oRZu0Gd6IK9oYpBSHpz1w1wt3/QgVheXrgrGT/TdNAOLChkBxg8VMCWfDNLOlWk8w4O2 KbM2AiwAoqs5knTyo6PUrgQ3EI2tThDFS2xfjsyG4QFq2+c9hyPG4a8KGMgm7w8+C8Iw OG5Q== X-Gm-Message-State: AKwxytdewwN3NBHRFbmTWxNMYqAw7tjCj5eihN+olL7UGQrfS5+ql9pw OQWPU+rpKCwKzV84Nt1PWOfuMgJrePI= X-Received: by 10.223.141.206 with SMTP id o72mr7197540wrb.0.1516817458621; Wed, 24 Jan 2018 10:10:58 -0800 (PST) Received: from e104803-lin.lan (mail.andrep.de. [217.160.17.100]) by smtp.gmail.com with ESMTPSA id r68sm899379wmd.47.2018.01.24.10.10.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 24 Jan 2018 10:10:58 -0800 (PST) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Wed, 24 Jan 2018 18:10:55 +0000 Message-Id: <20180124181058.6157-6-andre.przywara@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180124181058.6157-1-andre.przywara@linaro.org> References: <20180124181058.6157-1-andre.przywara@linaro.org> Cc: xen-devel@lists.xenproject.org Subject: [Xen-devel] [PATCH v3 5/8] 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 0a2958c5db..d44e4dacd3 100644 --- a/xen/arch/arm/gic-vgic.c +++ b/xen/arch/arm/gic-vgic.c @@ -411,6 +411,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);