Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2445408rwi; Tue, 1 Nov 2022 07:48:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM52SFlqtK41uJqr69cP9IScWVehnXyNcMuiDkpNYAkSMJjfP6b5mVO5a2MC6s30AK0iVAWt X-Received: by 2002:a17:902:70c4:b0:178:54cf:d397 with SMTP id l4-20020a17090270c400b0017854cfd397mr19241367plt.24.1667314105043; Tue, 01 Nov 2022 07:48:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667314105; cv=none; d=google.com; s=arc-20160816; b=lLX7xYzkdDt/H0QLeaatRFN6aeVoNIofv7dWLDnUc8a/PAPUlQrfju2Z+OiIXOtZrt z9jWIrmcNxC7rEpf7nbNix/quY+K8/xZGl95M87wbRs0Iz2d8MJyisQ9MryCMs2oqhYI A3VBtl4g6NmROrfMg6doj4x+w8VIJjQlRc+COrLCeAF/IolS9tNOuJmgKgxNveV257nJ +bK/xc8vAe1+LfpyFLQ8RCEF80ybMd58nKcmsQxjjDt/zlAOO2DSbH3/QlYI3QAgPX32 w7BacbfHoQvCvmG3HAdzjqOLMx08dPXMqGAnd6Igqn/fJa6hoccwWjHA3vpM1G/mKuyT 527g== 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=9ifdhfU8MRp8KF9HZ6tJ7EpItneJOYFyI/sq447ebfo=; b=ZT1vAqwErvcM/KVavHsyMROgwIo2PPIvPxTv4yldMKb4bUZIwp4SK5QyjdCCKktVBS vtjW/d0RYbFm928opK4gFtH24BgJaPsgD5BHOxMb0h12T3rhHX2/dza8o9Uh9uWSFCEg JGCyt1GfpvtZvplVI9qlpUo144KdIwqiH05x4PT6HXPhu6YECqD4vN2uD1B/Nzon5Pg9 6MrOwScNNSue+VAdTCjrRxSjStQjqv2byfTsRmtFFfkQ+AYt7rkmRFPUOHHajKLNYvVF 7pxlVCoboYWJt7npxXv7wtJFnLsnHgjPn47z5JDGYnaQ4CwXvOBGpCnHhFUDWLkXcJ7x 3zag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=iXsZ75oh; 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 f12-20020a6547cc000000b00439dcdd3cfdsi12699345pgs.825.2022.11.01.07.48.12; Tue, 01 Nov 2022 07:48:25 -0700 (PDT) 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=iXsZ75oh; 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 S230330AbiKAOfO (ORCPT + 96 others); Tue, 1 Nov 2022 10:35:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230083AbiKAOez (ORCPT ); Tue, 1 Nov 2022 10:34:55 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4C3F1C118 for ; Tue, 1 Nov 2022 07:34:53 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id p15-20020a17090a348f00b002141615576dso1298558pjb.4 for ; Tue, 01 Nov 2022 07:34:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9ifdhfU8MRp8KF9HZ6tJ7EpItneJOYFyI/sq447ebfo=; b=iXsZ75ohvlLpVxjFccfmFbBkL6VbVZfEchOACqA6t6MtqpmZmZO1++5Rxd6JaFaH8Z U8IT5NK0BgAMRMXNcOHilOESGz40w1nGDhid5y2SOZYSn6pEP5+mcrpoeb1MVkBl7ovz SYAID8JZo1/EcdKB7NolWqkZJBEwVIcfQLPaT/kpMHgCqAG/mjbg7n9pu3xJA4qdUhrO et8uco67UUyAZUzUOg8R/4CRE1OzhjX3wWijU+xmDP1fHMLbSXkkLMG14Eu34Avmhu9r grKTmKiydkgYZUfSO2K0ZhdLgVHpgBNWYRbG7Clqsok20cPjlG236HbAt3jZ60M1VxsF N1QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9ifdhfU8MRp8KF9HZ6tJ7EpItneJOYFyI/sq447ebfo=; b=qltVIR/MzaIsT8hJ9DMLrfc3gY2mYG7gUVOQCIUhP+ikB+KSbM7zVIoTKuknARHCA9 eOZZYmgAj+NhNwd2II91z6oJvxdeC/RzyeeztPZVr/DzpGSK1VgRi1N4kXSQBQvZ1rm8 xyFLIx6AhiikNSNyygpcw0IdwCA6rb4WJCwfYWx/znLu57HOQJ4DgPoiqqqUZtDXzSPf V4amsnPw1fdysd/g7ixG/spbapMJAWYd9VPGgnLYCx50yKPEUvRA11MFoIFdZC14b/1M F9qzj593TIvf8+MopkTqqkXW4hMqEXdMvlIwn5FoK6k2yR7Rto6YrvvSq7sFaz5/IjvS iZrQ== X-Gm-Message-State: ACrzQf3FDHxtbzHKeaolxxDUOgYWNW0y8C2mv9IsKq/cEe0PJkq9+uFw K9bOAVpl/wFXpuwMPVx8A3I6Sg== X-Received: by 2002:a17:902:ea09:b0:187:3274:2460 with SMTP id s9-20020a170902ea0900b0018732742460mr5680497plg.153.1667313293078; Tue, 01 Nov 2022 07:34:53 -0700 (PDT) Received: from anup-ubuntu64-vm.. ([171.76.80.52]) by smtp.gmail.com with ESMTPSA id o20-20020a170903009400b0018685aaf41dsm6449055pld.18.2022.11.01.07.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Nov 2022 07:34:52 -0700 (PDT) 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 v10 5/7] RISC-V: Allow marking IPIs as suitable for remote FENCEs Date: Tue, 1 Nov 2022 20:03:58 +0530 Message-Id: <20221101143400.690000-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221101143400.690000-1-apatel@ventanamicro.com> References: <20221101143400.690000-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 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/smp.h | 18 ++++++++++++++++-- arch/riscv/kernel/sbi-ipi.c | 2 +- arch/riscv/kernel/smp.c | 11 ++++++++++- drivers/clocksource/timer-clint.c | 2 +- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/arch/riscv/include/asm/smp.h b/arch/riscv/include/asm/smp.h index 79ed0b73cd4e..56976e41a21e 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); +void riscv_ipi_set_virq_range(int virq, int nr, 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/sbi-ipi.c b/arch/riscv/kernel/sbi-ipi.c index f0a78420b127..ee8620104bd8 100644 --- a/arch/riscv/kernel/sbi-ipi.c +++ b/arch/riscv/kernel/sbi-ipi.c @@ -75,6 +75,6 @@ void __init sbi_ipi_init(void) "irqchip/sbi-ipi:starting", sbi_ipi_starting_cpu, sbi_ipi_dying_cpu); - riscv_ipi_set_virq_range(virq, BITS_PER_BYTE); + riscv_ipi_set_virq_range(virq, BITS_PER_BYTE, false); pr_info("providing IPIs using SBI IPI extension\n"); } diff --git a/arch/riscv/kernel/smp.c b/arch/riscv/kernel/smp.c index e8a20454d65b..74b8cb1a89ab 100644 --- a/arch/riscv/kernel/smp.c +++ b/arch/riscv/kernel/smp.c @@ -145,7 +145,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; @@ -168,6 +171,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 f9dd746a72c5..658049a5440b 100644 --- a/drivers/clocksource/timer-clint.c +++ b/drivers/clocksource/timer-clint.c @@ -249,7 +249,7 @@ static int __init clint_timer_init_dt(struct device_node *np) goto fail_free_irq; } - riscv_ipi_set_virq_range(virq, BITS_PER_BYTE); + riscv_ipi_set_virq_range(virq, BITS_PER_BYTE, true); clint_clear_ipi(clint_ipi_irq, NULL); return 0; -- 2.34.1