riscv_set_icache_flush_ctx(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 β€” allows fence.i in user space ✨
  • PR_RISCV_CTX_SW_FENCEI_OFF β€” disallows fence.i in user space. every thread in a process gets affected when scope == PR_RISCV_SCOPE_PER_PROCESS, so like… caution, bestie 😭 use this flag only when you can guarantee that no thread in the process will emit fence.i from 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