riscv_set_icache_flush_ctx(9)
π riscv_set_icache_flush_ctx(9) β the Kernel API Manual page, bestie edition π
okay so this is a page straight out of the Kernel API Manual and it's literally all about whether your userspace is allowed to yeet fence.i instructions around π
β¨ NAME β¨
riscv_set_icache_flush_ctx β turn icache flushing instructions on or off in userspace, no cap π«Ά
πΈ SYNOPSIS πΈ
int riscv_set_icache_flush_ctx(unsigned long ctx, unsigned long scope);
π¦ ARGUMENTS π¦
ctxβ this one sets the type of icache flushing instructions that are permitted or prohibited in userspace. the supported values are described down below, keep scrolling πscopeβ and this sets the scope of where those icache flushing instructions are allowed to be emitted. supported values also below, i gotchu β
π DESCRIPTION π
π supported values for ctx:
PR_RISCV_CTX_SW_FENCEI_ONβ allowsfence.iin user space β¨PR_RISCV_CTX_SW_FENCEI_OFFβ disallowsfence.iin user space. every thread in a process gets affected whenscope == PR_RISCV_SCOPE_PER_PROCESS, so likeβ¦ caution, bestie π use this flag only when you can guarantee that no thread in the process will emitfence.ifrom this point onward. no take-backs, fr fr.
π§ supported values for scope:
PR_RISCV_SCOPE_PER_PROCESSβ makes sure the icache of any thread in this process is coherent with instruction storage upon migration πPR_RISCV_SCOPE_PER_THREADβ makes sure the icache of the current thread is coherent with instruction storage upon migration π¦
so when scope == PR_RISCV_SCOPE_PER_PROCESS, all threads in the process are permitted to emit icache flushing instructions. whenever any thread in the process gets migrated, the corresponding hart's icache will be guaranteed to be consistent with instruction storage π₯
but β and this is the important part β it does not enforce any guarantees outside of migration. if a thread modifies an instruction that another thread may attempt to execute, that other thread must still emit an icache flushing instruction before attempting to execute the potentially modified instruction. and yes, this has to be performed by the user-space program itself π
in per-thread context (eg. scope == PR_RISCV_SCOPE_PER_THREAD) only the thread calling this function is permitted to emit icache flushing instructions. when the thread is migrated, the corresponding hart's icache will be guaranteed to be consistent with instruction storage π
on kernels configured without SMP, this function is a nop β because migrations across harts will not occur. literally does nothing, iconic π
π SEE ALSO π
- Kernel file
./arch/riscv/mm/cacheflush.cβ go read it, iykwim β¨
and that's the whole page, bestie π«Ά this one lives in ./arch/riscv/mm, dated October 2026, and its official little name tag is riscv_set_icache_flush_ctx(9) β slay π
π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms