Skip to content

Commit

Permalink
arm64/ptrace: Don't flush ZA/ZT storage when writing ZA via ptrace
Browse files Browse the repository at this point in the history
When writing ZA we currently unconditionally flush the buffer used to store
it as part of ensuring that it is allocated. Since this buffer is shared
with ZT0 this means that a write to ZA when PSTATE.ZA is already set will
corrupt the value of ZT0 on a SME2 system. Fix this by only flushing the
backing storage if PSTATE.ZA was not previously set.

This will mean that short or failed writes may leave stale data in the
buffer, this seems as correct as our current behaviour and unlikely to be
something that userspace will rely on.

Fixes: f90b529 ("arm64/sme: Implement ZT0 ptrace support")
Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20240115-arm64-fix-ptrace-za-zt-v1-1-48617517028a@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
  • Loading branch information
Mark Brown authored and Will Deacon committed Jan 18, 2024
1 parent da59f1d commit b7c510d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions arch/arm64/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1107,12 +1107,13 @@ static int za_set(struct task_struct *target,
}
}

/* Allocate/reinit ZA storage */
sme_alloc(target, true);
if (!target->thread.sme_state) {
ret = -ENOMEM;
goto out;
}
/*
* Only flush the storage if PSTATE.ZA was not already set,
* otherwise preserve any existing data.
*/
sme_alloc(target, !thread_za_enabled(&target->thread));
if (!target->thread.sme_state)
return -ENOMEM;

/* If there is no data then disable ZA */
if (!count) {
Expand Down

0 comments on commit b7c510d

Please sign in to comment.