Skip to content

Commit ddc806b

Browse files
brooniewilldeacon
authored andcommitted
arm64/sve: Explicitly load vector length when restoring SVE state
Currently when restoring the SVE state we supply the SVE vector length as an argument to sve_load_state() and the underlying macros. This becomes inconvenient with the addition of SME since we may need to restore any combination of SVE and SME vector lengths, and we already separately restore the vector length in the KVM code. We don't need to know the vector length during the actual register load since the SME load instructions can index into the data array for us. Refactor the interface so we explicitly set the vector length separately to restoring the SVE registers in preparation for adding SME support, no functional change should be involved. Signed-off-by: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent b5bc00f commit ddc806b

File tree

5 files changed

+11
-16
lines changed

5 files changed

+11
-16
lines changed

arch/arm64/include/asm/fpsimd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static inline void *sve_pffr(struct thread_struct *thread)
6767

6868
extern void sve_save_state(void *state, u32 *pfpsr, int save_ffr);
6969
extern void sve_load_state(void const *state, u32 const *pfpsr,
70-
int restore_ffr, unsigned long vq_minus_1);
70+
int restore_ffr);
7171
extern void sve_flush_live(bool flush_ffr, unsigned long vq_minus_1);
7272
extern unsigned int sve_get_vl(void);
7373
extern void sve_set_vq(unsigned long vq_minus_1);

arch/arm64/include/asm/fpsimdmacros.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
str w\nxtmp, [\xpfpsr, #4]
242242
.endm
243243

244-
.macro __sve_load nxbase, xpfpsr, restore_ffr, nxtmp
244+
.macro sve_load nxbase, xpfpsr, restore_ffr, nxtmp
245245
_for n, 0, 31, _sve_ldr_v \n, \nxbase, \n - 34
246246
cbz \restore_ffr, 921f
247247
_sve_ldr_p 0, \nxbase
@@ -254,8 +254,3 @@
254254
ldr w\nxtmp, [\xpfpsr, #4]
255255
msr fpcr, x\nxtmp
256256
.endm
257-
258-
.macro sve_load nxbase, xpfpsr, restore_ffr, xvqminus1, nxtmp, xtmp2
259-
sve_load_vq \xvqminus1, x\nxtmp, \xtmp2
260-
__sve_load \nxbase, \xpfpsr, \restore_ffr, \nxtmp
261-
.endm

arch/arm64/kernel/entry-fpsimd.S

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ SYM_FUNC_END(sve_save_state)
5151
* x0 - pointer to buffer for state
5252
* x1 - pointer to storage for FPSR
5353
* x2 - Restore FFR if non-zero
54-
* x3 - VQ-1
5554
*/
5655
SYM_FUNC_START(sve_load_state)
57-
sve_load 0, x1, x2, x3, 4, x5
56+
sve_load 0, x1, x2, 4
5857
ret
5958
SYM_FUNC_END(sve_load_state)
6059

arch/arm64/kernel/fpsimd.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,13 @@ static void task_fpsimd_load(void)
318318
WARN_ON(!system_supports_fpsimd());
319319
WARN_ON(!have_cpu_fpsimd_context());
320320

321-
if (IS_ENABLED(CONFIG_ARM64_SVE) && test_thread_flag(TIF_SVE))
321+
if (IS_ENABLED(CONFIG_ARM64_SVE) && test_thread_flag(TIF_SVE)) {
322+
sve_set_vq(sve_vq_from_vl(task_get_sve_vl(current)) - 1);
322323
sve_load_state(sve_pffr(&current->thread),
323-
&current->thread.uw.fpsimd_state.fpsr, true,
324-
sve_vq_from_vl(task_get_sve_vl(current)) - 1);
325-
else
324+
&current->thread.uw.fpsimd_state.fpsr, true);
325+
} else {
326326
fpsimd_load_state(&current->thread.uw.fpsimd_state);
327+
}
327328
}
328329

329330
/*
@@ -1423,10 +1424,10 @@ void __efi_fpsimd_end(void)
14231424
likely(__this_cpu_read(efi_sve_state_used))) {
14241425
char const *sve_state = this_cpu_ptr(efi_sve_state);
14251426

1427+
sve_set_vq(sve_vq_from_vl(sve_get_vl()) - 1);
14261428
sve_load_state(sve_state + sve_ffr_offset(sve_max_vl()),
14271429
&this_cpu_ptr(&efi_fpsimd_state)->fpsr,
1428-
true,
1429-
sve_vq_from_vl(sve_get_vl()) - 1);
1430+
true);
14301431

14311432
__this_cpu_write(efi_sve_state_used, false);
14321433
} else {

arch/arm64/kvm/hyp/fpsimd.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ SYM_FUNC_END(__fpsimd_restore_state)
2222

2323
SYM_FUNC_START(__sve_restore_state)
2424
mov x2, #1
25-
__sve_load 0, x1, x2, 3
25+
sve_load 0, x1, x2, 3
2626
ret
2727
SYM_FUNC_END(__sve_restore_state)
2828

0 commit comments

Comments
 (0)