Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp3888906ybh; Tue, 6 Aug 2019 03:04:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxr8BggRzxosiOt1ro4xyYkPFRD+H9vVqNAkrerY+JBxKJSSHIhPKMbnU2+9k0kWx7jqwzJ X-Received: by 2002:a63:f857:: with SMTP id v23mr2316206pgj.228.1565085889439; Tue, 06 Aug 2019 03:04:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565085889; cv=none; d=google.com; s=arc-20160816; b=LGL0a0P66Hsrm3Ftw33kedn0WcMz8NVCsq4DZ6fxR3kgXueGYLq2xDgxozMdkdgMcR 0rfepbyBLKrh0RtOL094RNJFypxjUOBg9/6halDeRpMNCokruzi+m8tb3gay39DfKNbh TLE6E1ylvtLuDnEdptxS/fBQsiLdsgEQW+chpml/14f/L1q6gX9nEGWiq4vmgIL2yJML yIa7dsfUCc9iuv84+sS8THTtuZBe7iZWRN0hhxkUvfA23KL+pAFPEjKXtoYuZHcFnyLi PYYZO4Nps4h9fs/9Q+8m3/WraACFRTVIT/z0W2ao/2lOsiqCifl5VSkMEDNiK1XySBAr Eaww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=pw5DVmkTwGN9kO+jAcdYaz1BZdPN+hInoVtcnwLXboE=; b=QT+ZhEKl+XTIUHUn91NzpPCstrqzO8qdz+2vIjOjY/oZ/5TIQCr7Avt4L80QCYOTcm Ja7kfHUYMACzdiKoO6IZpMILjkDeWspVXJOXGEQ1utU3GITYygEI/SOO3Km83vMg7qgz HxHWWVIWsMNw8/5KfLfNjMT9G6mQMtpTBCTbXWgHyTLSC2oUrbdWupm7UVt2d70RVZ4X 0AdDdn6o/+KveGobkTLU6WYG6U/WKwEm90Usomt6srrc4vcfGjLDIS+wk4RNdUGUWpjI 5j7Xc1yUPLjyQy/vq2Rcfjl0yNWbMXYNe11ItlvC/+jV7S+2KzfmjrXyJch++te3KiHO +Z4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c36si47426924pgl.287.2019.08.06.03.04.33; Tue, 06 Aug 2019 03:04:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732800AbfHFKCB (ORCPT + 99 others); Tue, 6 Aug 2019 06:02:01 -0400 Received: from foss.arm.com ([217.140.110.172]:59458 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732689AbfHFKBh (ORCPT ); Tue, 6 Aug 2019 06:01:37 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E8FF0337; Tue, 6 Aug 2019 03:01:36 -0700 (PDT) Received: from filthy-habits.cambridge.arm.com (filthy-habits.cambridge.arm.com [10.1.197.61]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B0A6F3F706; Tue, 6 Aug 2019 03:01:35 -0700 (PDT) From: Marc Zyngier To: Thomas Gleixner , Jason Cooper , Julien Thierry , Rob Herring Cc: John Garry , Shameerali Kolothum Thodi , Lokesh Vutla , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 06/12] irqchip/gic-v3: Dynamically allocate PPI NMI refcounts Date: Tue, 6 Aug 2019 11:01:15 +0100 Message-Id: <20190806100121.240767-7-maz@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190806100121.240767-1-maz@kernel.org> References: <20190806100121.240767-1-maz@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As we're about to have a variable number of PPIs, let's make the allocation of the NMI refcounts dynamic. Also apply some minor cleanups (moving things around). Signed-off-by: Marc Zyngier --- drivers/irqchip/irq-gic-v3.c | 47 ++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c index e03fb6d7c2ce..4253c7f67c86 100644 --- a/drivers/irqchip/irq-gic-v3.c +++ b/drivers/irqchip/irq-gic-v3.c @@ -88,7 +88,7 @@ static DEFINE_STATIC_KEY_TRUE(supports_deactivate_key); static DEFINE_STATIC_KEY_FALSE(supports_pseudo_nmis); /* ppi_nmi_refs[n] == number of cpus having ppi[n + 16] set as NMI */ -static refcount_t ppi_nmi_refs[16]; +static refcount_t *ppi_nmi_refs; static struct gic_kvm_info gic_v3_kvm_info; static DEFINE_PER_CPU(bool, has_rss); @@ -409,6 +409,16 @@ static void gic_irq_set_prio(struct irq_data *d, u8 prio) writeb_relaxed(prio, base + offset + index); } +static u32 gic_get_ppi_index(struct irq_data *d) +{ + switch (get_intid_range(d)) { + case PPI_RANGE: + return d->hwirq - 16; + default: + unreachable(); + } +} + static int gic_irq_nmi_setup(struct irq_data *d) { struct irq_desc *desc = irq_to_desc(d->irq); @@ -429,10 +439,12 @@ static int gic_irq_nmi_setup(struct irq_data *d) return -EINVAL; /* desc lock should already be held */ - if (gic_irq(d) < 32) { + if (gic_irq_in_rdist(d)) { + u32 idx = gic_get_ppi_index(d); + /* Setting up PPI as NMI, only switch handler for first NMI */ - if (!refcount_inc_not_zero(&ppi_nmi_refs[gic_irq(d) - 16])) { - refcount_set(&ppi_nmi_refs[gic_irq(d) - 16], 1); + if (!refcount_inc_not_zero(&ppi_nmi_refs[idx])) { + refcount_set(&ppi_nmi_refs[idx], 1); desc->handle_irq = handle_percpu_devid_fasteoi_nmi; } } else { @@ -464,9 +476,11 @@ static void gic_irq_nmi_teardown(struct irq_data *d) return; /* desc lock should already be held */ - if (gic_irq(d) < 32) { + if (gic_irq_in_rdist(d)) { + u32 idx = gic_get_ppi_index(d); + /* Tearing down NMI, only switch handler for last NMI */ - if (refcount_dec_and_test(&ppi_nmi_refs[gic_irq(d) - 16])) + if (refcount_dec_and_test(&ppi_nmi_refs[idx])) desc->handle_irq = handle_percpu_devid_irq; } else { desc->handle_irq = handle_fasteoi_irq; @@ -1394,7 +1408,19 @@ static void gic_enable_nmi_support(void) { int i; - for (i = 0; i < 16; i++) + if (!gic_prio_masking_enabled()) + return; + + if (gic_has_group0() && !gic_dist_security_disabled()) { + pr_warn("SCR_EL3.FIQ is cleared, cannot enable use of pseudo-NMIs\n"); + return; + } + + ppi_nmi_refs = kcalloc(gic_data.ppi_nr, sizeof(*ppi_nmi_refs), GFP_KERNEL); + if (!ppi_nmi_refs) + return; + + for (i = 0; i < gic_data.ppi_nr; i++) refcount_set(&ppi_nmi_refs[i], 0); static_branch_enable(&supports_pseudo_nmis); @@ -1472,12 +1498,7 @@ static int __init gic_init_bases(void __iomem *dist_base, gicv2m_init(handle, gic_data.domain); } - if (gic_prio_masking_enabled()) { - if (!gic_has_group0() || gic_dist_security_disabled()) - gic_enable_nmi_support(); - else - pr_warn("SCR_EL3.FIQ is cleared, cannot enable use of pseudo-NMIs\n"); - } + gic_enable_nmi_support(); return 0; -- 2.20.1