Skip to content

Commit 7ca7a7b

Browse files
AndybnACTpalmer-dabbelt
authored andcommitted
riscv: Add sysctl to set the default vector rule for new processes
To support Vector extension, the series exports variable-length vector registers on the signal frame. However, this potentially breaks abi if processing vector registers is required in the signal handler for old binaries. For example, there is such need if user-level context switch is triggerred via signals[1]. For this reason, it is best to leave a decision to distro maintainers, where the enablement of userspace Vector for new launching programs can be controlled. Developers may also need the switch to experiment with. The parameter is configurable through sysctl interface so a distro may turn off Vector early at init script if the break really happens in the wild. The switch will only take effects on new execve() calls once set. This will not effect existing processes that do not call execve(), nor processes which has been set with a non-default vstate_ctrl by making explicit PR_RISCV_V_SET_CONTROL prctl() calls. Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Andy Chiu <[email protected]> Reviewed-by: Greentime Hu <[email protected]> Reviewed-by: Vincent Chen <[email protected]> Reviewed-by: Björn Töpel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 1fd96a3 commit 7ca7a7b

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

arch/riscv/kernel/vector.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ void riscv_v_vstate_ctrl_init(struct task_struct *tsk)
180180

181181
next = riscv_v_ctrl_get_next(tsk);
182182
if (!next) {
183-
if (riscv_v_implicit_uacc)
183+
if (READ_ONCE(riscv_v_implicit_uacc))
184184
cur = PR_RISCV_V_VSTATE_CTRL_ON;
185185
else
186186
cur = PR_RISCV_V_VSTATE_CTRL_OFF;
@@ -243,3 +243,34 @@ long riscv_v_vstate_ctrl_set_current(unsigned long arg)
243243

244244
return -EINVAL;
245245
}
246+
247+
#ifdef CONFIG_SYSCTL
248+
249+
static struct ctl_table riscv_v_default_vstate_table[] = {
250+
{
251+
.procname = "riscv_v_default_allow",
252+
.data = &riscv_v_implicit_uacc,
253+
.maxlen = sizeof(riscv_v_implicit_uacc),
254+
.mode = 0644,
255+
.proc_handler = proc_dobool,
256+
},
257+
{ }
258+
};
259+
260+
static int __init riscv_v_sysctl_init(void)
261+
{
262+
if (has_vector())
263+
if (!register_sysctl("abi", riscv_v_default_vstate_table))
264+
return -EINVAL;
265+
return 0;
266+
}
267+
268+
#else /* ! CONFIG_SYSCTL */
269+
static int __init riscv_v_sysctl_init(void) { return 0; }
270+
#endif /* ! CONFIG_SYSCTL */
271+
272+
static int riscv_v_init(void)
273+
{
274+
return riscv_v_sysctl_init();
275+
}
276+
core_initcall(riscv_v_init);

0 commit comments

Comments
 (0)