Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3468853pxm; Mon, 28 Feb 2022 21:38:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJz9kPDvTGvQibBCEdwocHaKRwyWIFVk57qpWj/Ki9rEgdYb03Vjt/nRH6aCvv1evb/pTQLc X-Received: by 2002:a17:906:4c4f:b0:6ce:412:1368 with SMTP id d15-20020a1709064c4f00b006ce04121368mr17523228ejw.496.1646113094997; Mon, 28 Feb 2022 21:38:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646113094; cv=none; d=google.com; s=arc-20160816; b=SiJQTj7CzswUjPY7RlN9iOIkmb/XRDk1pWM9x4f7LKb8BjNequvy+8nx0OPJ1pDbAy ByDqUsCfVoL0G6CE0Ez3hQxnLMI6Sx8Za4HCwFXrbGOkdpM6xuhHcAOLXvsO8yLZ0QFM 9XMyWn+vB3cp+3SDKXKEnSx5bcSSNBucGegbNrUcckkAgLgMUkMH9bMln8Ng/ZpyvbxN eSXXr3i7HGwhNHLjE8QDhqFaiQVTBtGOhJvAkfqG7RzMG12/7Y36oW1SwEgcnxdFLv27 3hkrtcjDFiasD8HYdRTC9U7iy8uIUlH7TCpHk38o/dlSAWxcJ73CJdn60YPWIQUEtv/N ctjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1dvQpmktLMIBE5zILdeneM+K/jB6oDBX0KNz7QqesMQ=; b=bpiklZHvmNWqmqj+MSkt5Hoo3PpUgKZf+kswgsDuGoctbnJKD8f1FP16fjE8D8SNFL F3v+EmTIb3oVBYsBnq47ED+ro4PMkTUgsiBOxBx3N51AytrAXD6YnUqykfOyzlwQTef2 XwyAFb/CXA4QT+Npu1rMxaEQHQE/BUxQv1Tpj/Esvt0NxRVesvBqj4oLTEbJc30IC2Eu ek1X8J9xkFcuwj5kS9gKg9bX3ux+cXhtWSY0ZJQM82c7Ds+31S8E+16Vcr9XuxIa57mB +RN+dg9FjGtgTYdnxuqpCaXpLR4feVRcftGXKjx2ayg9lJeN6+0FBYNMVdgDo7tdOF3P AsAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=UWot9+IK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e16-20020a170906505000b006d1288a564asi7499844ejk.120.2022.02.28.21.37.52; Mon, 28 Feb 2022 21:38:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=UWot9+IK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229979AbiCAE3X (ORCPT + 99 others); Mon, 28 Feb 2022 23:29:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232234AbiCAE3O (ORCPT ); Mon, 28 Feb 2022 23:29:14 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 109084C436 for ; Mon, 28 Feb 2022 20:28:34 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id i8so1394926wrr.8 for ; Mon, 28 Feb 2022 20:28:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1dvQpmktLMIBE5zILdeneM+K/jB6oDBX0KNz7QqesMQ=; b=UWot9+IKQnkBxOtBKqZCFbkzbWwkiSYSfH29Vs+HVQmBV1nMtXjntkuPvnTiu8eSHh MOIIomRS+JqYe4IABr2l85Ba6VB0HNhcMraLbyGKhSieqJnEPIS/U4sfEl8qcl0ulKSr neIYpYd2OLJBT4hb8tDmj2iQfHJHEpzniPxQOuXjEybdumghKw4Kd4rQ0SABJuwUbGY/ FH7lATW7s2OIt6+WaP+DVHKz7GMEpfC0mNu8Iqi5CO+rxu8gNWNXtx24317USXhFpbRl QU3B78v1AwaLevpkKehqtsiYWv59HQWSZY2G2sj0mngemRM00d1XdIr98WAsKSinhdlg SnzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1dvQpmktLMIBE5zILdeneM+K/jB6oDBX0KNz7QqesMQ=; b=v8KKTu1TU8HSJ+QrDB7/j69HXQP99bGAdzHxxAosagMHuBSTilbxWUBW3W6sh/RJT2 2s3N3EZLF5tz5tlTO3A8hbdUAOBpBdlyTYSLmVrE77geTe0nyFHePvagiZoEITm1CWGm NHUCnmWq4zoBWeyJOJNjmBIu+GZTYheNveLivKkxPyC0ZqAgFUhFSD+IdnNT4Am/UwsZ n9cp1S74ykLT+e8GqCXbhkBPNp6C15sWTTegToaE5jkgo7e5lhiFMGx5CFb74FioIted YUlXUL3auf+6TtIxXP6swi+LdYiCf80xmbk8Oj4+8NZimWC2otA6Xr4yaeuFX9NEJETB 5jBw== X-Gm-Message-State: AOAM531NAzsn/gqidLvOh6H9BzwYlgMWdaIWc38JI+QK24+d0SZ+Q8If tb9gPzn67SQq7oGBZxA/9ReRSg== X-Received: by 2002:adf:cd0a:0:b0:1ed:e0b3:428 with SMTP id w10-20020adfcd0a000000b001ede0b30428mr17792226wrm.357.1646108912581; Mon, 28 Feb 2022 20:28:32 -0800 (PST) Received: from localhost.localdomain ([122.179.35.69]) by smtp.gmail.com with ESMTPSA id 2-20020a1c1902000000b00380d3873d6asm1209107wmz.43.2022.02.28.20.28.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 20:28:32 -0800 (PST) From: Anup Patel To: Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Marc Zyngier , Daniel Lezcano Cc: Atish Patra , Alistair Francis , Anup Patel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel Subject: [PATCH v4 4/6] RISC-V: Allow marking IPIs as suitable for remote FENCEs Date: Tue, 1 Mar 2022 09:57:20 +0530 Message-Id: <20220301042722.401113-5-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220301042722.401113-1-apatel@ventanamicro.com> References: <20220301042722.401113-1-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To do remote FENCEs (i.e. remote TLB flushes) using IPI calls on the RISC-V kernel, we need hardware mechanism to directly inject IPI from the supervisor mode (i.e. RISC-V kernel) instead of using SBI calls. The upcoming AIA IMSIC devices allow direct IPI injection from the supervisor mode (i.e. RISC-V kernel). To support this, we extend the riscv_ipi_set_virq_range() function so that IPI provider (i.e. irqchip drivers can mark IPIs as suitable for remote FENCEs. Signed-off-by: Anup Patel --- arch/riscv/include/asm/ipi-mux.h | 2 ++ arch/riscv/include/asm/smp.h | 18 ++++++++++++++++-- arch/riscv/kernel/ipi-mux.c | 3 ++- arch/riscv/kernel/sbi.c | 3 ++- arch/riscv/kernel/smp.c | 11 ++++++++++- drivers/clocksource/timer-clint.c | 2 +- 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/arch/riscv/include/asm/ipi-mux.h b/arch/riscv/include/asm/ipi-mux.h index 988e2bba372a..3a5acbf51806 100644 --- a/arch/riscv/include/asm/ipi-mux.h +++ b/arch/riscv/include/asm/ipi-mux.h @@ -15,6 +15,7 @@ void riscv_ipi_mux_handle_irq(void); /* Create irq_domain for muxed IPIs */ struct irq_domain *riscv_ipi_mux_create(bool use_soft_irq, + bool use_for_rfence, void (*clear_ipi)(void), void (*send_ipi)(const struct cpumask *mask)); @@ -28,6 +29,7 @@ static inline void riscv_ipi_mux_handle_irq(void) } static inline struct irq_domain *riscv_ipi_mux_create(bool use_soft_irq, + bool use_for_rfence, void (*clear_ipi)(void), void (*send_ipi)(const struct cpumask *mask)) { diff --git a/arch/riscv/include/asm/smp.h b/arch/riscv/include/asm/smp.h index 178fe4ada592..ddd3be1c77b6 100644 --- a/arch/riscv/include/asm/smp.h +++ b/arch/riscv/include/asm/smp.h @@ -16,6 +16,9 @@ struct seq_file; extern unsigned long boot_cpu_hartid; #ifdef CONFIG_SMP + +#include + /* * Mapping between linux logical cpu index and hartid. */ @@ -46,7 +49,12 @@ void riscv_ipi_disable(void); bool riscv_ipi_have_virq_range(void); /* Set the IPI interrupt numbers for arch (called by irqchip drivers) */ -void riscv_ipi_set_virq_range(int virq, int nr_irqs); +void riscv_ipi_set_virq_range(int virq, int nr_irqs, bool use_for_rfence); + +/* Check if we can use IPIs for remote FENCEs */ +DECLARE_STATIC_KEY_FALSE(riscv_ipi_for_rfence); +#define riscv_use_ipi_for_rfence() \ + static_branch_unlikely(&riscv_ipi_for_rfence) /* Secondary hart entry */ asmlinkage void smp_callin(void); @@ -93,10 +101,16 @@ static inline bool riscv_ipi_have_virq_range(void) return false; } -static inline void riscv_ipi_set_virq_range(int virq, int nr) +static inline void riscv_ipi_set_virq_range(int virq, int nr, + bool use_for_rfence) { } +static inline bool riscv_use_ipi_for_rfence(void) +{ + return false; +} + #endif /* CONFIG_SMP */ #if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP) diff --git a/arch/riscv/kernel/ipi-mux.c b/arch/riscv/kernel/ipi-mux.c index 3a0405f0e0de..544074ea3ead 100644 --- a/arch/riscv/kernel/ipi-mux.c +++ b/arch/riscv/kernel/ipi-mux.c @@ -144,6 +144,7 @@ static int ipi_mux_starting_cpu(unsigned int cpu) } struct irq_domain *riscv_ipi_mux_create(bool use_soft_irq, + bool use_for_rfence, void (*clear_ipi)(void), void (*send_ipi)(const struct cpumask *mask)) { @@ -198,7 +199,7 @@ struct irq_domain *riscv_ipi_mux_create(bool use_soft_irq, "irqchip/riscv/ipi-mux:starting", ipi_mux_starting_cpu, ipi_mux_dying_cpu); - riscv_ipi_set_virq_range(virq, BITS_PER_LONG); + riscv_ipi_set_virq_range(virq, BITS_PER_LONG, use_for_rfence); return ipi_mux_priv.domain; diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c index ab38814f1977..909fb36a0910 100644 --- a/arch/riscv/kernel/sbi.c +++ b/arch/riscv/kernel/sbi.c @@ -652,7 +652,8 @@ static void sbi_ipi_clear(void) void __init sbi_ipi_init(void) { - if (riscv_ipi_mux_create(true, sbi_ipi_clear, sbi_send_cpumask_ipi)) + if (riscv_ipi_mux_create(true, false, + sbi_ipi_clear, sbi_send_cpumask_ipi)) pr_info("providing IPIs using SBI IPI extension\n"); } diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c index a9f1aca38358..b98d9c319f6f 100644 --- a/arch/riscv/kernel/smp.c +++ b/arch/riscv/kernel/smp.c @@ -149,7 +149,10 @@ bool riscv_ipi_have_virq_range(void) return (ipi_virq_base) ? true : false; } -void riscv_ipi_set_virq_range(int virq, int nr) +DEFINE_STATIC_KEY_FALSE(riscv_ipi_for_rfence); +EXPORT_SYMBOL_GPL(riscv_ipi_for_rfence); + +void riscv_ipi_set_virq_range(int virq, int nr, bool use_for_rfence) { int i, err; @@ -172,6 +175,12 @@ void riscv_ipi_set_virq_range(int virq, int nr) /* Enabled IPIs for boot CPU immediately */ riscv_ipi_enable(); + + /* Update RFENCE static key */ + if (use_for_rfence) + static_branch_enable(&riscv_ipi_for_rfence); + else + static_branch_disable(&riscv_ipi_for_rfence); } EXPORT_SYMBOL_GPL(riscv_ipi_set_virq_range); diff --git a/drivers/clocksource/timer-clint.c b/drivers/clocksource/timer-clint.c index b05a9e946633..607d47dab896 100644 --- a/drivers/clocksource/timer-clint.c +++ b/drivers/clocksource/timer-clint.c @@ -224,7 +224,7 @@ static int __init clint_timer_init_dt(struct device_node *np) goto fail_free_irq; } - riscv_ipi_mux_create(true, clint_clear_ipi, clint_send_ipi); + riscv_ipi_mux_create(true, true, clint_clear_ipi, clint_send_ipi); clint_clear_ipi(); return 0; -- 2.25.1