Skip to content

Commit c87df9c

Browse files
mrutland-armctmarinas
authored andcommitted
arm64: pt_regs: assert pt_regs is a multiple of 16 bytes
To ensure that the stack is correctly aligned when branching to C code, we require that struct pt_regs is a multiple of 16 bytes, as noted in a comment. Add an explicit assertion for this, so that any accidental violation of this requirement will be caught by the compiler. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Reviewed-by: Mark Brown <broonie@kernel.org> Reviewed-by: Miroslav Benes <mbenes@suse.cz> Reviewed-by: Puranjay Mohan <puranjay12@gmail.com> Cc: Ard Biesheuvel <ardb@kernel.org> Cc: Josh Poimboeuf <jpoimboe@kernel.org> Cc: Kalesh Singh <kaleshsingh@google.com> Cc: Madhavan T. Venkataraman <madvenka@linux.microsoft.com> Cc: Marc Zyngier <maz@kernel.org> Cc: Will Deacon <will@kernel.org> Link: https://lore.kernel.org/r/20241017092538.1859841-2-mark.rutland@arm.com Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 9852d85 commit c87df9c

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

arch/arm64/include/asm/ptrace.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ static inline unsigned long pstate_to_compat_psr(const unsigned long pstate)
149149

150150
/*
151151
* This struct defines the way the registers are stored on the stack during an
152-
* exception. Note that sizeof(struct pt_regs) has to be a multiple of 16 (for
153-
* stack alignment). struct user_pt_regs must form a prefix of struct pt_regs.
152+
* exception. struct user_pt_regs must form a prefix of struct pt_regs.
154153
*/
155154
struct pt_regs {
156155
union {
@@ -180,6 +179,9 @@ struct pt_regs {
180179
u64 exit_rcu;
181180
};
182181

182+
/* For correct stack alignment, pt_regs has to be a multiple of 16 bytes. */
183+
static_assert(IS_ALIGNED(sizeof(struct pt_regs), 16));
184+
183185
static inline bool in_syscall(struct pt_regs const *regs)
184186
{
185187
return regs->syscallno != NO_SYSCALL;

0 commit comments

Comments
 (0)