• Samuel Holland's avatar
    riscv: Use IPIs for remote cache/TLB flushes by default · dc892fb4
    Samuel Holland authored
    An IPI backend is always required in an SMP configuration, but an SBI
    implementation is not. For example, SBI will be unavailable when the
    kernel runs in M mode. For this reason, consider IPI delivery of cache
    and TLB flushes to be the base case, and any other implementation (such
    as the SBI remote fence extension) to be an optimization.
    
    Generally, if IPIs can be delivered without firmware assistance, they
    are assumed to be faster than SBI calls due to the SBI context switch
    overhead. However, when SBI is used as the IPI backend, then the context
    switch cost must be paid anyway, and performing the cache/TLB flush
    directly in the SBI implementation is more efficient than injecting an
    interrupt to S-mode. This is the only existing scenario where
    riscv_ipi_set_virq_range() is called with use_for_rfence set to false.
    
    sbi_ipi_init() already checks riscv_ipi_have_virq_range(), so it only
    calls riscv_ipi_set_virq_range() when no other IPI device is available.
    This allows moving the static key and dropping the use_for_rfence
    parameter. This decouples the static key from the irqchip driver probe
    order.
    
    Furthermore, the static branch only makes sense when CONFIG_RISCV_SBI is
    enabled. Optherwise, IPIs must be used. Add a fallback definition of
    riscv_use_sbi_for_rfence() which handles this case and removes the need
    to check CONFIG_RISCV_SBI elsewhere, such as in cacheflush.c.
    Reviewed-by: default avatarAnup Patel <anup@brainfault.org>
    Signed-off-by: default avatarSamuel Holland <samuel.holland@sifive.com>
    Reviewed-by: default avatarAlexandre Ghiti <alexghiti@rivosinc.com>
    Link: https://lore.kernel.org/r/20240327045035.368512-4-samuel.holland@sifive.comSigned-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
    dc892fb4
cacheflush.c 4 KB