1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
.\" Copyright, the authors of the Linux man-pages project
.\"
.\" SPDX-License-Identifier: Linux-man-pages-copyleft
.\"
.TH PR_RISCV_SET_ICACHE_FLUSH_CTX 2const 2025-05-17 "Linux man-pages (unreleased)"
.SH NAME
PR_RISCV_SET_ICACHE_FLUSH_CTX
\-
Enable/disable icache flushing instructions in userspace.
.SH LIBRARY
Standard C library
.RI ( libc ,\~ \-lc )
.SH SYNOPSIS
.nf
.BR "#include <linux/prctl.h>" " /* Definition of " PR_* " constants */"
.B #include <sys/prctl.h>
.P
.BI "int prctl(PR_RISCV_SET_ICACHE_FLUSH_CTX, unsigned long " ctx,
.BI " unsigned long " scope );
.fi
.SH DESCRIPTION
The context and the scope can be provided using
.I ctx
and
.I scope
respectively.
.P
When scope is set to
.B PR_RISCV_SCOPE_PER_PROCESS
all threads in the process are permitted to emit icache flushing instructions.
Whenever any thread in the process is migrated,
the corresponding hart's icache will be
guaranteed to be consistent with instruction storage.
This does not enforce any guarantees outside of migration.
If a thread modifies an instruction that another thread may attempt to execute,
the other thread must still emit an icache flushing instruction
before attempting to execute the potentially modified instruction.
This must be performed by the user-space program.
.P
In per-thread context (eg. scope is set to
.BR 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.
.P
On kernels configured without SMP, this prctl
.B PR_RISCV_SET_ICACHE_FLUSH_CTX
is a nop as migrations across harts will not occur.
.P
The following values for
.I ctx
can be specified:
.TP
.BR PR_RISCV_CTX_SW_FENCEI_ON " (since Linux 6.10)"
Allow fence.i in user space.
.TP
.BR PR_RISCV_CTX_SW_FENCEI_OFF " (since Linux 6.10)"
Disallow fence.i in user space.
All threads in a process will be affected when scope is set to
.BR PR_RISCV_SCOPE_PER_PROCESS .
Therefore, caution must be taken;
use this flag only when you can guarantee that
no thread in the process will emit fence.i from this point onward.
.P
The following values for
.I scope
can be specified:
.TP
.BR PR_RISCV_SCOPE_PER_PROCESS " (since Linux 6.10)"
Ensure the icache of any thread in this process is coherent with instruction
storage upon migration.
.TP
.BR PR_RISCV_SCOPE_PER_THREAD " (since Linux 6.10)"
Ensure the icache of the current thread is coherent with instruction storage
upon migration.
.SH EXAMPLES
The following files are meant to be compiled and linked with each other.
The modify_instruction() function
replaces an add with zero with an add with one,
causing the instruction sequence in get_value() to change from
returning a zero to returning a one.
.SS Program source: cmodx.c
.\" SRC BEGIN (cmodx.c)
.EX
#include <stdio.h>
#include <sys/prctl.h>
\&
extern int get_value(void);
extern void modify_instruction(void);
\&
int
main(void)
{
int value = get_value();
\&
printf("Value before cmodx: %d\[rs]n", value);
\&
// Call prctl before first fence.i is called
prctl(PR_RISCV_SET_ICACHE_FLUSH_CTX, PR_RISCV_CTX_SW_FENCEI_ON,
PR_RISCV_SCOPE_PER_PROCESS);
\&
modify_instruction();
\&
// Call prctl after final fence.i is called in process
prctl(PR_RISCV_SET_ICACHE_FLUSH_CTX, PR_RISCV_CTX_SW_FENCEI_OFF,
PR_RISCV_SCOPE_PER_PROCESS);
\&
value = get_value();
printf("Value after cmodx: %d\[rs]n", value);
return 0;
}
.EE
.\" SRC END
.SS Program source: cmodx.S
.EX
\&.option norvc
\&
\&.text
\&.global modify_instruction
modify_instruction:
lw a0, new_insn
lui a5,%hi(old_insn)
sw a0,%lo(old_insn)(a5)
fence.i
ret
\&
\&.section modifiable, "awx"
\&.global get_value
get_value:
li a0, 0
old_insn:
addi a0, a0, 0
ret
\&
\&.data
new_insn:
addi a0, a0, 1
.EE
.SS Expected result
.EX
Value before cmodx: 0
Value after cmodx: 1
.EE
.SH STANDARDS
Linux. RISC-V only.
.SH HISTORY
.TP
Linux 6.10 (RISC-V).
.SH SEE ALSO
.BR prctl (2)
|