From: Luis Gerhorst <luis.gerhorst@fau.de>
To: Lukas Gerlach <lukas.gerlach@cispa.de>
Cc: <ast@kernel.org>, <bjorn@kernel.org>, <bpf@vger.kernel.org>,
<daniel.weber@cispa.de>, <daniel@iogearbox.net>,
<jo.vanbulck@kuleuven.be>, <linux-riscv@lists.infradead.org>,
<luke.r.nels@gmail.com>, <marton.bognar@kuleuven.be>,
<michael.schwarz@cispa.de>, <palmer@dabbelt.com>,
<pjw@kernel.org>, <xi.wang@gmail.com>, <cleger@rivosinc.com>,
<palmer@rivosinc.com>, <conor.dooley@microchip.com>,
<andrew@sifive.com>
Subject: Re: [PATCH] riscv, bpf: Emit fence.i for BPF_NOSPEC
Date: Wed, 07 Jan 2026 18:52:24 +0100 [thread overview]
Message-ID: <87sechz4x3.fsf@fau.de> (raw)
In-Reply-To: <20260107095406.4082-1-lukas.gerlach@cispa.de> (Lukas Gerlach's message of "Wed, 7 Jan 2026 10:54:05 +0100")
Lukas Gerlach <lukas.gerlach@cispa.de> writes:
> Regarding bpf_jit_bypass_spec_v1/v4(): currently this is per-architecture.
> What we need is per-processor granularity, so we can disable mitigations
> on in-order cores and keep them enabled on vulnerable out-of-order processors.
Yes, sorry this was unclear. I just wanted to point out that once you
have that infrastructure you can implement them as follows:
bpf_jit_bypass_spec_v1/v4() {
if (RV_CPU_IN_ORDER())
return true;
else
return false;
}
But you are right that the definition of RV_CPU_IN_ORDER() is still
missing of course.
> Regarding fence.i being an extension: all RISC-V processors supported by the
> kernel that are vulnerable to these attacks support this instruction.
I am not sure if I misunderstand the "that are vulnerable to these
attacks".
If you mean that vulnerable CPUs always have fence.i: What if a CPU
still does not support the instruction (no matter if it is vulnerable or
not)?
If I understand the RISC-V JIT correctly, it will then still generate
fence.i with this patch. When this eBPF program is then invoked the
CPU will panic upon reaching the fence.i which is a invalid opcode as
far as this CPU is concerned. Or is there some ifdef I am missing here?
I would assume you need something like this:
case BPF_ST | BPF_NOSPEC:
if (riscv_has_extension_likely(RISCV_ISA_EXT_ZIFENCEI))
emit_fence_i(ctx);
break;
Or is there some guarantee that this extension is always available? I
read [3] as implying that this is no longer the case with the 2.0
instruction set for unprivileged. Does this also mean it is an optional
extension for the privileged ISA?
RISC-V cpufeature.c had this in [2]:
/*
* Linux requires the following extensions, so we may as well
* always set them.
*/
set_bit(RISCV_ISA_EXT_ZICSR, this_isa);
set_bit(RISCV_ISA_EXT_ZIFENCEI, this_isa);
But as of [1] it was changed to:
if (acpi_disabled) {
set_bit(RISCV_ISA_EXT_ZICSR, source_isa);
set_bit(RISCV_ISA_EXT_ZIFENCEI, source_isa);
So based on that I would assume fence.i may not always be supported.
But I also found that 921ebd8f2c08 ("RISC-V: Allow userspace to flush
the instruction cache") seems to assume that fence.i always works (see
local_flush_icache_all() which I assume runs in the kernel).
Even if the CPU is known vulnerable but does not support the extension,
it will be better not to generate the instruction. If we still want to
do something about these CPUs, maybe add a warning message to advise the
user that unpriv eBPF should definately be kept disabled on this CPU?
[1] https://lore.kernel.org/all/20230711224600.10879-1-palmer@rivosinc.com/
[2] https://lore.kernel.org/all/20230607-nest-collision-5796b6be8be6@spud/
[3] https://docs.riscv.org/reference/isa/unpriv/zifencei.html
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2026-01-07 17:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-28 17:37 [PATCH] riscv, bpf: Emit fence.i for BPF_NOSPEC Lukas Gerlach
2026-01-05 23:28 ` Paul Walmsley
2026-01-06 8:44 ` [PATCH] riscv, bpf: add a speculation barrier " Lukas Gerlach
2026-01-07 8:26 ` Luis Gerhorst
2026-01-07 9:54 ` [PATCH] riscv, bpf: Emit fence.i " Lukas Gerlach
2026-01-07 17:52 ` Luis Gerhorst [this message]
2026-01-07 23:30 ` Samuel Holland
2026-01-08 10:05 ` Luis Gerhorst
2026-01-09 3:41 ` Bo Gan
2026-01-09 5:36 ` [tech-speculation-barriers] " Stefan O'Rear
2026-01-12 16:19 ` Luis Gerhorst
2026-01-12 18:33 ` Bo Gan
2026-01-13 1:51 ` Paul Walmsley
2026-01-15 13:13 ` Lukas Gerlach
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87sechz4x3.fsf@fau.de \
--to=luis.gerhorst@fau.de \
--cc=andrew@sifive.com \
--cc=ast@kernel.org \
--cc=bjorn@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cleger@rivosinc.com \
--cc=conor.dooley@microchip.com \
--cc=daniel.weber@cispa.de \
--cc=daniel@iogearbox.net \
--cc=jo.vanbulck@kuleuven.be \
--cc=linux-riscv@lists.infradead.org \
--cc=lukas.gerlach@cispa.de \
--cc=luke.r.nels@gmail.com \
--cc=marton.bognar@kuleuven.be \
--cc=michael.schwarz@cispa.de \
--cc=palmer@dabbelt.com \
--cc=palmer@rivosinc.com \
--cc=pjw@kernel.org \
--cc=xi.wang@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox