Skip to content

Commit 7559b7d

Browse files
brooniectmarinas
authored andcommitted
arm64/sve: Better handle failure to allocate SVE register storage
Currently we "handle" failure to allocate the SVE register storage by doing a BUG_ON() and hoping for the best. This is obviously not great and the memory allocation failure will already be loud enough without the BUG_ON(). As the comment says it is a corner case but let's try to do a bit better, remove the BUG_ON() and add code to handle the failure in the callers. For the ptrace and signal code we can return -ENOMEM gracefully however we have no real error reporting path available to us for the SVE access trap so instead generate a SIGKILL if the allocation fails there. This at least means that we won't try to soldier on and end up trying to access the nonexistant state and while it's obviously not ideal for userspace SIGKILL doesn't allow any handling so minimises the ABI impact, making it easier to improve the interface later if we come up with a better idea. Signed-off-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent e384976 commit 7559b7d

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

arch/arm64/kernel/fpsimd.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,6 @@ void sve_alloc(struct task_struct *task)
520520
/* This is a small allocation (maximum ~8KB) and Should Not Fail. */
521521
task->thread.sve_state =
522522
kzalloc(sve_state_size(task), GFP_KERNEL);
523-
524-
/*
525-
* If future SVE revisions can have larger vectors though,
526-
* this may cease to be true:
527-
*/
528-
BUG_ON(!task->thread.sve_state);
529523
}
530524

531525

@@ -945,6 +939,10 @@ void do_sve_acc(unsigned int esr, struct pt_regs *regs)
945939
}
946940

947941
sve_alloc(current);
942+
if (!current->thread.sve_state) {
943+
force_sig(SIGKILL);
944+
return;
945+
}
948946

949947
get_cpu_fpsimd_context();
950948

arch/arm64/kernel/ptrace.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,11 @@ static int sve_set(struct task_struct *target,
845845
}
846846

847847
sve_alloc(target);
848+
if (!target->thread.sve_state) {
849+
ret = -ENOMEM;
850+
clear_tsk_thread_flag(target, TIF_SVE);
851+
goto out;
852+
}
848853

849854
/*
850855
* Ensure target->thread.sve_state is up to date with target's

arch/arm64/kernel/signal.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user)
289289
/* From now, fpsimd_thread_switch() won't touch thread.sve_state */
290290

291291
sve_alloc(current);
292+
if (!current->thread.sve_state) {
293+
clear_thread_flag(TIF_SVE);
294+
return -ENOMEM;
295+
}
296+
292297
err = __copy_from_user(current->thread.sve_state,
293298
(char __user const *)user->sve +
294299
SVE_SIG_REGS_OFFSET,

0 commit comments

Comments
 (0)