Skip to content

Commit 79ab047

Browse files
Dave Martinwildea01
authored andcommitted
arm64/sve: Support vector length resetting for new processes
It's desirable to be able to reset the vector length to some sane default for new processes, since the new binary and its libraries may or may not be SVE-aware. This patch tracks the desired post-exec vector length (if any) in a new thread member sve_vl_onexec, and adds a new thread flag TIF_SVE_VL_INHERIT to control whether to inherit or reset the vector length. Currently these are inactive. Subsequent patches will provide the capability to configure them. Signed-off-by: Dave Martin <Dave.Martin@arm.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent bc0ee47 commit 79ab047

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

arch/arm64/include/asm/processor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ struct thread_struct {
107107
struct fpsimd_state fpsimd_state;
108108
void *sve_state; /* SVE registers, if any */
109109
unsigned int sve_vl; /* SVE vector length */
110+
unsigned int sve_vl_onexec; /* SVE vl after next exec */
110111
unsigned long fault_address; /* fault info */
111112
unsigned long fault_code; /* ESR_EL1 value */
112113
struct debug_info debug; /* debugging */

arch/arm64/include/asm/thread_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ void arch_release_task_struct(struct task_struct *tsk);
9595
#define TIF_SINGLESTEP 21
9696
#define TIF_32BIT 22 /* 32bit process */
9797
#define TIF_SVE 23 /* Scalable Vector Extension in use */
98+
#define TIF_SVE_VL_INHERIT 24 /* Inherit sve_vl_onexec across exec */
9899

99100
#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
100101
#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)

arch/arm64/kernel/fpsimd.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@
111111
*/
112112
static DEFINE_PER_CPU(struct fpsimd_state *, fpsimd_last_state);
113113

114+
/* Default VL for tasks that don't set it explicitly: */
115+
static int sve_default_vl = SVE_VL_MIN;
116+
114117
/*
115118
* Call __sve_free() directly only if you know task can't be scheduled
116119
* or preempted.
@@ -474,15 +477,20 @@ void fpsimd_flush_thread(void)
474477
* If a bug causes this to go wrong, we make some noise and
475478
* try to fudge thread.sve_vl to a safe value here.
476479
*/
477-
vl = current->thread.sve_vl;
478-
479-
if (vl == 0)
480-
vl = SVE_VL_MIN;
480+
vl = current->thread.sve_vl_onexec ?
481+
current->thread.sve_vl_onexec : sve_default_vl;
481482

482483
if (WARN_ON(!sve_vl_valid(vl)))
483484
vl = SVE_VL_MIN;
484485

485486
current->thread.sve_vl = vl;
487+
488+
/*
489+
* If the task is not set to inherit, ensure that the vector
490+
* length will be reset by a subsequent exec:
491+
*/
492+
if (!test_thread_flag(TIF_SVE_VL_INHERIT))
493+
current->thread.sve_vl_onexec = 0;
486494
}
487495

488496
set_thread_flag(TIF_FOREIGN_FPSTATE);

0 commit comments

Comments
 (0)