Skip to content

Commit d158a06

Browse files
brooniectmarinas
authored andcommitted
arm64/sme: More sensibly define the size for the ZA register set
Since the vector length configuration mechanism is identical between SVE and SME we share large elements of the code including the definition for the maximum vector length. Unfortunately when we were defining the ABI for SVE we included not only the actual maximum vector length of 2048 bits but also the value possible if all the bits reserved in the architecture for expansion of the LEN field were used, 16384 bits. This starts creating problems if we try to allocate anything for the ZA matrix based on the maximum possible vector length, as we do for the regset used with ptrace during the process of generating a core dump. While the maximum potential size for ZA with the current architecture is a reasonably managable 64K with the higher reserved limit ZA would be 64M which leads to entirely reasonable complaints from the memory management code when we try to allocate a buffer of that size. Avoid these issues by defining the actual maximum vector length for the architecture and using it for the SME regsets. Also use the full ZA_PT_SIZE() with the header rather than just the actual register payload when specifying the size, fixing support for the largest vector lengths now that we have this new, lower define. With the SVE maximum this did not cause problems due to the extra headroom we had. While we're at it add a comment clarifying why even though ZA is a single register we tell the regset code that it is a multi-register regset. Reported-by: Qian Cai <[email protected]> Signed-off-by: Mark Brown <[email protected]> Tested-by: Naresh Kamboju <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 2e29b99 commit d158a06

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

arch/arm64/include/asm/fpsimd.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@
3232
#define VFP_STATE_SIZE ((32 * 8) + 4)
3333
#endif
3434

35+
/*
36+
* When we defined the maximum SVE vector length we defined the ABI so
37+
* that the maximum vector length included all the reserved for future
38+
* expansion bits in ZCR rather than those just currently defined by
39+
* the architecture. While SME follows a similar pattern the fact that
40+
* it includes a square matrix means that any allocations that attempt
41+
* to cover the maximum potential vector length (such as happen with
42+
* the regset used for ptrace) end up being extremely large. Define
43+
* the much lower actual limit for use in such situations.
44+
*/
45+
#define SME_VQ_MAX 16
46+
3547
struct task_struct;
3648

3749
extern void fpsimd_save_state(struct user_fpsimd_state *state);

arch/arm64/kernel/ptrace.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ static const struct user_regset aarch64_regsets[] = {
14381438
#ifdef CONFIG_ARM64_SME
14391439
[REGSET_SSVE] = { /* Streaming mode SVE */
14401440
.core_note_type = NT_ARM_SSVE,
1441-
.n = DIV_ROUND_UP(SVE_PT_SIZE(SVE_VQ_MAX, SVE_PT_REGS_SVE),
1441+
.n = DIV_ROUND_UP(SVE_PT_SIZE(SME_VQ_MAX, SVE_PT_REGS_SVE),
14421442
SVE_VQ_BYTES),
14431443
.size = SVE_VQ_BYTES,
14441444
.align = SVE_VQ_BYTES,
@@ -1447,7 +1447,15 @@ static const struct user_regset aarch64_regsets[] = {
14471447
},
14481448
[REGSET_ZA] = { /* SME ZA */
14491449
.core_note_type = NT_ARM_ZA,
1450-
.n = DIV_ROUND_UP(ZA_PT_ZA_SIZE(SVE_VQ_MAX), SVE_VQ_BYTES),
1450+
/*
1451+
* ZA is a single register but it's variably sized and
1452+
* the ptrace core requires that the size of any data
1453+
* be an exact multiple of the configured register
1454+
* size so report as though we had SVE_VQ_BYTES
1455+
* registers. These values aren't exposed to
1456+
* userspace.
1457+
*/
1458+
.n = DIV_ROUND_UP(ZA_PT_SIZE(SME_VQ_MAX), SVE_VQ_BYTES),
14511459
.size = SVE_VQ_BYTES,
14521460
.align = SVE_VQ_BYTES,
14531461
.regset_get = za_get,

0 commit comments

Comments
 (0)