Skip to content

alpha: stack fixes

Ivan Kokshaysky linux-alpha lkml stable 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 6 repliesIn review
  2. v24 patches 13 repliesApplied
  3. v14 patches 5 repliesSuperseded

Changes in v3 from the cover letter

- patch #1 dropped for the time being;
- updated commit messages as Maciej suggested.
---
Ivan Kokshaysky (3):
alpha: replace hardcoded stack offsets with autogenerated ones
alpha: make stack 16-byte aligned (most cases)
alpha: align stack for page fault and user unaligned trap handlers

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3alpha: replace hardcoded stack offsets with autogenerated onesarch/alpha/kernel/asm-offsets.c arch/alpha/kernel/entry.S+4 -41 reply
2/3alpha: make stack 16-byte aligned (most cases)arch/alpha/include/uapi/asm/ptrace.h+2 -01 reply
3/3alpha: align stack for page fault and user unaligned trap handlersarch/alpha/kernel/entry.S arch/alpha/kernel/traps.c arch/alpha/mm/fault.c+13 -131 reply

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchMaciej W. RozyckiMagnus Lindholm
1/3R-b T-b
2/3R-b T-b T-b
3/3R-b T-b T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 0/3] alpha: stack fixes

This series fixes oopses on Alpha/SMP observed since kernel v6.9. [1] Thanks to Magnus Lindholm for identifying that remarkably longstanding bug.

The problem is that GCC expects 16-byte alignment of the incoming stack since early 2004, as Maciej found out [2]:
Having actually dug speculatively I can see that the psABI was changed in
GCC 3.5 with commit e5e10fb4a350 ("re PR target/14539 (128-bit long double improperly aligned)") back in Mar 2004, when the stack pointer alignment was increased from 8 bytes to 16 bytes, and arch/alpha/kernel/entry.S has various suspicious stack pointer adjustments, starting with SP_OFF which is not a whole multiple of 16.

Also, as Magnus noted, "ALPHA Calling Standard" [3] required the same:
D.3.1 Stack Alignment
This standard requires that stacks be octaword aligned at the time a new procedure is invoked.

However:
- the "normal" kernel stack is always misaligned by 8 bytes, thanks to the odd number of 64-bit words in 'struct pt_regs', which is the very first thing pushed onto the kernel thread stack;
- syscall, fault, interrupt etc. handlers may, or may not, receive aligned stack depending on numerous factors.

Somehow we got away with it until recently, when we ended up with a stack corruption in kernel/smp.c:smp_call_function_single() due to its use of 32-byte aligned local data and the compiler doing clever things allocating it on the stack.

Patche 1 is preparatory; 2 - the main fix; 3 - fixes remaining special cases.

Ivan.

[1] https://lore.kernel.org/rcu/CA+=Fv5R9NG+1SHU9QV9hjmavycHKpnNyerQ=Ei90G98ukRcRJA@mail.gmail.com/#r
[2] https://lore.kernel.org/rcu/[email protected]/
[3] https://bitsavers.org/pdf/dec/alpha/Alpha_Calling_Standard_Rev_2.0_19900427.pdf
---
Changes in v2:
- patch #1: provide empty 'struct pt_regs' to fix compile failure in libbpf,
reported by John Paul Adrian Glaubitz <[email protected]>;
update comment and commit message accordingly;
- cc'ed <[email protected]> as older kernels ought to be fixed as well.

Changes in v3:
- patch #1 dropped for the time being;
- updated commit messages as Maciej suggested.
---
Ivan Kokshaysky (3):
alpha: replace hardcoded stack offsets with autogenerated ones
alpha: make stack 16-byte aligned (most cases)
alpha: align stack for page fault and user unaligned trap handlers

 arch/alpha/include/uapi/asm/ptrace.h |  2 ++
 arch/alpha/kernel/asm-offsets.c      |  4 ++++
 arch/alpha/kernel/entry.S            | 24 ++++++++++--------------
 arch/alpha/kernel/traps.c            |  2 +-
 arch/alpha/mm/fault.c                |  4 ++--
 5 files changed, 19 insertions(+), 17 deletions(-)
Signature · 1 line
2.47.2