Skip to content

Commit 8738288

Browse files
mrutland-armwilldeacon
authored andcommitted
arm64/fpsimd: Factor out {sve,sme}_state_size() helpers
In subsequent patches we'll need to determine the SVE/SME state size for a given SVE VL and SME VL regardless of whether a task is currently configured with those VLs. Split the sizing logic out of sve_state_size() and sme_state_size() so that we don't need to open-code this logic elsewhere. At the same time, apply minor cleanups: * Move sve_state_size() into fpsimd.h, matching the placement of sme_state_size(). * Remove the feature checks from sve_state_size(). We only call sve_state_size() when at least one of SVE and SME are supported, and when either of the two is not supported, the task's corresponding SVE/SME vector length will be zero. Signed-off-by: Mark Rutland <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Mark Brown <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent b255be4 commit 8738288

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed

arch/arm64/include/asm/fpsimd.h

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,22 @@ static inline bool sve_vq_available(unsigned int vq)
293293
return vq_available(ARM64_VEC_SVE, vq);
294294
}
295295

296-
size_t sve_state_size(struct task_struct const *task);
296+
static inline size_t __sve_state_size(unsigned int sve_vl, unsigned int sme_vl)
297+
{
298+
unsigned int vl = max(sve_vl, sme_vl);
299+
return SVE_SIG_REGS_SIZE(sve_vq_from_vl(vl));
300+
}
301+
302+
/*
303+
* Return how many bytes of memory are required to store the full SVE
304+
* state for task, given task's currently configured vector length.
305+
*/
306+
static inline size_t sve_state_size(struct task_struct const *task)
307+
{
308+
unsigned int sve_vl = task_get_sve_vl(task);
309+
unsigned int sme_vl = task_get_sme_vl(task);
310+
return __sve_state_size(sve_vl, sme_vl);
311+
}
297312

298313
#else /* ! CONFIG_ARM64_SVE */
299314

@@ -334,6 +349,11 @@ static inline void vec_update_vq_map(enum vec_type t) { }
334349
static inline int vec_verify_vq_map(enum vec_type t) { return 0; }
335350
static inline void sve_setup(void) { }
336351

352+
static inline size_t __sve_state_size(unsigned int sve_vl, unsigned int sme_vl)
353+
{
354+
return 0;
355+
}
356+
337357
static inline size_t sve_state_size(struct task_struct const *task)
338358
{
339359
return 0;
@@ -386,22 +406,24 @@ extern int sme_set_current_vl(unsigned long arg);
386406
extern int sme_get_current_vl(void);
387407
extern void sme_suspend_exit(void);
388408

409+
static inline size_t __sme_state_size(unsigned int sme_vl)
410+
{
411+
size_t size = ZA_SIG_REGS_SIZE(sve_vq_from_vl(sme_vl));
412+
413+
if (system_supports_sme2())
414+
size += ZT_SIG_REG_SIZE;
415+
416+
return size;
417+
}
418+
389419
/*
390420
* Return how many bytes of memory are required to store the full SME
391421
* specific state for task, given task's currently configured vector
392422
* length.
393423
*/
394424
static inline size_t sme_state_size(struct task_struct const *task)
395425
{
396-
unsigned int vl = task_get_sme_vl(task);
397-
size_t size;
398-
399-
size = ZA_SIG_REGS_SIZE(sve_vq_from_vl(vl));
400-
401-
if (system_supports_sme2())
402-
size += ZT_SIG_REG_SIZE;
403-
404-
return size;
426+
return __sme_state_size(task_get_sme_vl(task));
405427
}
406428

407429
#else
@@ -422,6 +444,11 @@ static inline int sme_set_current_vl(unsigned long arg) { return -EINVAL; }
422444
static inline int sme_get_current_vl(void) { return -EINVAL; }
423445
static inline void sme_suspend_exit(void) { }
424446

447+
static inline size_t __sme_state_size(unsigned int sme_vl)
448+
{
449+
return 0;
450+
}
451+
425452
static inline size_t sme_state_size(struct task_struct const *task)
426453
{
427454
return 0;

arch/arm64/kernel/fpsimd.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -719,22 +719,6 @@ static void sve_free(struct task_struct *task)
719719
__sve_free(task);
720720
}
721721

722-
/*
723-
* Return how many bytes of memory are required to store the full SVE
724-
* state for task, given task's currently configured vector length.
725-
*/
726-
size_t sve_state_size(struct task_struct const *task)
727-
{
728-
unsigned int vl = 0;
729-
730-
if (system_supports_sve())
731-
vl = task_get_sve_vl(task);
732-
if (system_supports_sme())
733-
vl = max(vl, task_get_sme_vl(task));
734-
735-
return SVE_SIG_REGS_SIZE(sve_vq_from_vl(vl));
736-
}
737-
738722
/*
739723
* Ensure that task->thread.sve_state is allocated and sufficiently large.
740724
*

0 commit comments

Comments
 (0)