Skip to content

Commit fb0f3d2

Browse files
avpatelMarc Zyngier
authored andcommitted
RISC-V: Allow marking IPIs as suitable for remote FENCEs
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 <apatel@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com> Acked-by: Palmer Dabbelt <palmer@rivosinc.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20230328035223.1480939-5-apatel@ventanamicro.com
1 parent 832f15f commit fb0f3d2

4 files changed

Lines changed: 28 additions & 5 deletions

File tree

arch/riscv/include/asm/smp.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ struct seq_file;
1616
extern unsigned long boot_cpu_hartid;
1717

1818
#ifdef CONFIG_SMP
19+
20+
#include <linux/jump_label.h>
21+
1922
/*
2023
* Mapping between linux logical cpu index and hartid.
2124
*/
@@ -46,7 +49,12 @@ void riscv_ipi_disable(void);
4649
bool riscv_ipi_have_virq_range(void);
4750

4851
/* Set the IPI interrupt numbers for arch (called by irqchip drivers) */
49-
void riscv_ipi_set_virq_range(int virq, int nr);
52+
void riscv_ipi_set_virq_range(int virq, int nr, bool use_for_rfence);
53+
54+
/* Check if we can use IPIs for remote FENCEs */
55+
DECLARE_STATIC_KEY_FALSE(riscv_ipi_for_rfence);
56+
#define riscv_use_ipi_for_rfence() \
57+
static_branch_unlikely(&riscv_ipi_for_rfence)
5058

5159
/* Check other CPUs stop or not */
5260
bool smp_crash_stop_failed(void);
@@ -96,10 +104,16 @@ static inline bool riscv_ipi_have_virq_range(void)
96104
return false;
97105
}
98106

99-
static inline void riscv_ipi_set_virq_range(int virq, int nr)
107+
static inline void riscv_ipi_set_virq_range(int virq, int nr,
108+
bool use_for_rfence)
100109
{
101110
}
102111

112+
static inline bool riscv_use_ipi_for_rfence(void)
113+
{
114+
return false;
115+
}
116+
103117
#endif /* CONFIG_SMP */
104118

105119
#if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP)

arch/riscv/kernel/sbi-ipi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ void __init sbi_ipi_init(void)
7272
"irqchip/sbi-ipi:starting",
7373
sbi_ipi_starting_cpu, NULL);
7474

75-
riscv_ipi_set_virq_range(virq, BITS_PER_BYTE);
75+
riscv_ipi_set_virq_range(virq, BITS_PER_BYTE, false);
7676
pr_info("providing IPIs using SBI IPI extension\n");
7777
}

arch/riscv/kernel/smp.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ bool riscv_ipi_have_virq_range(void)
177177
return (ipi_virq_base) ? true : false;
178178
}
179179

180-
void riscv_ipi_set_virq_range(int virq, int nr)
180+
DEFINE_STATIC_KEY_FALSE(riscv_ipi_for_rfence);
181+
EXPORT_SYMBOL_GPL(riscv_ipi_for_rfence);
182+
183+
void riscv_ipi_set_virq_range(int virq, int nr, bool use_for_rfence)
181184
{
182185
int i, err;
183186

@@ -200,6 +203,12 @@ void riscv_ipi_set_virq_range(int virq, int nr)
200203

201204
/* Enabled IPIs for boot CPU immediately */
202205
riscv_ipi_enable();
206+
207+
/* Update RFENCE static key */
208+
if (use_for_rfence)
209+
static_branch_enable(&riscv_ipi_for_rfence);
210+
else
211+
static_branch_disable(&riscv_ipi_for_rfence);
203212
}
204213

205214
static const char * const ipi_names[] = {

drivers/clocksource/timer-clint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ static int __init clint_timer_init_dt(struct device_node *np)
251251
}
252252

253253
irq_set_chained_handler(clint_ipi_irq, clint_ipi_interrupt);
254-
riscv_ipi_set_virq_range(rc, BITS_PER_BYTE);
254+
riscv_ipi_set_virq_range(rc, BITS_PER_BYTE, true);
255255
clint_clear_ipi();
256256
#endif
257257

0 commit comments

Comments
 (0)