All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ivan Kokshaysky <ink@unseen.parts>
To: Magnus Lindholm <linmag7@gmail.com>
Cc: "Maciej W. Rozycki" <macro@orcam.me.uk>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	Michael Cree <mcree@orcon.net.nz>,
	John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
	rcu@vger.kernel.org, linux-alpha@vger.kernel.org
Subject: Re: Kernel Oops on alpha with kernel version >=6.9.x
Date: Sat, 25 Jan 2025 16:15:32 +0100	[thread overview]
Message-ID: <Z5UAFAD6xCSpKJYw@minute> (raw)
In-Reply-To: <CA+=Fv5QmSkP4Ysp1zHNmUPftXYbSquTCsO_o3Rcgi2T5RcPj5A@mail.gmail.com>

On Fri, Jan 24, 2025 at 05:57:05PM +0100, Magnus Lindholm wrote:
> Are there other parts of the code that might unalign the stack, even
> if the stack is properly aligned to begin with? i.e passing an uneven
> number of function arguments on the stack or inside interrupt
> handlers? Alpha does not make use of a separate interrupt stack,
> right?

Good questions. No, there is no separate interrupt stack, it's always the
kernel one. Stack frames from interrupts in user mode are 64-byte aligned
though. Interrupts in kernel mode, user mode syscalls and exceptions all
use 6 x 64-bit word frames and do not change the stack [mis]alignment.

So, what we have now:
1. The "normal" kernel stack is always misaligned by 8, thanks to
   the sizeof(struct pt_regs);
2. Syscalls and exceptions handlers receive 16-byte aligned stack, as it
   gets "fixed" by SAVE_ALL macro in entry.S, which pushes the odd number
   of registers on the stack;
3. Interrupt handlers may, or may not, have got an aligned stack depending
   on kernel/user mode in which the interrupt had come.

Ugh.

> On stack alignment in "ALPHA Calling Standard":
> D.3.1 Stack Alignment
> 
> "This standard requires that stacks be octaword aligned at the time a
> new procedure is invoked. During the body of a procedure, however,
> there is no requirement to keep this level of alignment (even though
> it may be beneficial). This implies that any asynchronous interrupt
> handlers must properly align the stack before any standard calls are
> made."

I hope we can rely on GCC changing $sp only by multiplies of 16.

Magnus, can you please try this variant?

(Yes, there is still the UAPI issue that Maciej pointed out, but that's
another story.)

Ivan.

diff --git a/arch/alpha/include/uapi/asm/ptrace.h b/arch/alpha/include/uapi/asm/ptrace.h
index 5ca45934fcbb..72ed913a910f 100644
--- a/arch/alpha/include/uapi/asm/ptrace.h
+++ b/arch/alpha/include/uapi/asm/ptrace.h
@@ -42,6 +42,8 @@ struct pt_regs {
 	unsigned long trap_a0;
 	unsigned long trap_a1;
 	unsigned long trap_a2;
+/* This makes the stack 16-byte aligned as GCC expects */
+	unsigned long __pad0;
 /* These are saved by PAL-code: */
 	unsigned long ps;
 	unsigned long pc;
diff --git a/arch/alpha/kernel/asm-offsets.c b/arch/alpha/kernel/asm-offsets.c
index 4cfeae42c79a..e9dad60b147f 100644
--- a/arch/alpha/kernel/asm-offsets.c
+++ b/arch/alpha/kernel/asm-offsets.c
@@ -19,9 +19,13 @@ static void __used foo(void)
 	DEFINE(TI_STATUS, offsetof(struct thread_info, status));
 	BLANK();
 
+	DEFINE(SP_OFF, offsetof(struct pt_regs, ps));
 	DEFINE(SIZEOF_PT_REGS, sizeof(struct pt_regs));
 	BLANK();
 
+	DEFINE(SWITCH_STACK_SIZE, sizeof(struct switch_stack));
+	BLANK();
+
 	DEFINE(HAE_CACHE, offsetof(struct alpha_machine_vector, hae_cache));
 	DEFINE(HAE_REG, offsetof(struct alpha_machine_vector, hae_register));
 }
diff --git a/arch/alpha/kernel/entry.S b/arch/alpha/kernel/entry.S
index dd26062d75b3..6fb38365539d 100644
--- a/arch/alpha/kernel/entry.S
+++ b/arch/alpha/kernel/entry.S
@@ -15,10 +15,6 @@
 	.set noat
 	.cfi_sections	.debug_frame
 
-/* Stack offsets.  */
-#define SP_OFF			184
-#define SWITCH_STACK_SIZE	64
-
 .macro	CFI_START_OSF_FRAME	func
 	.align	4
 	.globl	\func

  reply	other threads:[~2025-01-25 15:16 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-30 22:22 Kernel Oops on alpha with kernel version >=6.9.x Magnus Lindholm
2024-12-01  4:31 ` Paul E. McKenney
2024-12-01 10:09   ` Magnus Lindholm
2024-12-01 17:04     ` Paul E. McKenney
2024-12-04 22:22       ` Magnus Lindholm
2024-12-05 15:39         ` John Paul Adrian Glaubitz
2024-12-05 17:02           ` Magnus Lindholm
2024-12-06 15:39             ` Magnus Lindholm
2024-12-06 17:05               ` John Paul Adrian Glaubitz
2024-12-07 12:33                 ` Magnus Lindholm
2024-12-07 12:39                   ` John Paul Adrian Glaubitz
2024-12-07 17:33                     ` Magnus Lindholm
2024-12-07 18:38                       ` John Paul Adrian Glaubitz
2024-12-08  9:43                         ` Magnus Lindholm
2024-12-08 21:39                           ` Magnus Lindholm
2024-12-08 23:18                             ` Michael Cree
2024-12-08 23:31                               ` John Paul Adrian Glaubitz
2024-12-09  8:11                                 ` Magnus Lindholm
2024-12-12 23:23                                   ` Magnus Lindholm
2024-12-09  8:05                               ` Magnus Lindholm
2024-12-16 22:10                                 ` Michael Cree
2024-12-17  6:23                                   ` Magnus Lindholm
2024-12-18 19:33                                     ` Magnus Lindholm
2024-12-18 20:31                                       ` Paul E. McKenney
2024-12-18 21:54                                         ` Magnus Lindholm
2024-12-18 22:50                                           ` Paul E. McKenney
2024-12-19 22:38                                             ` Magnus Lindholm
2024-12-19 23:03                                               ` Paul E. McKenney
2024-12-20  0:00                                                 ` Maciej W. Rozycki
2024-12-27 10:42                                                   ` Magnus Lindholm
2024-12-27 11:48                                                     ` John Paul Adrian Glaubitz
2024-12-27 16:30                                                     ` Maciej W. Rozycki
2024-12-31 10:43                                                       ` Magnus Lindholm
2025-01-12 23:25                                                         ` Magnus Lindholm
2025-01-13  0:19                                                           ` Maciej W. Rozycki
2025-01-13  3:08                                                             ` Maciej W. Rozycki
2025-01-13  5:59                                                             ` Magnus Lindholm
2025-01-13  8:04                                                               ` Maciej W. Rozycki
2025-01-13 16:52                                                               ` Magnus Lindholm
2025-01-20 13:01                                                                 ` Magnus Lindholm
2025-01-20 13:19                                                                   ` Maciej W. Rozycki
2025-01-21 13:39                                                                     ` Ivan Kokshaysky
2025-01-23 18:36                                                                       ` Ivan Kokshaysky
2025-01-23 23:00                                                                         ` Magnus Lindholm
2025-01-23 23:51                                                                           ` Michael Cree
2025-01-23 23:57                                                                         ` Maciej W. Rozycki
2025-01-24  6:06                                                                           ` Magnus Lindholm
2025-01-24 10:55                                                                           ` Ivan Kokshaysky
2025-01-24 16:57                                                                             ` Magnus Lindholm
2025-01-25 15:15                                                                               ` Ivan Kokshaysky [this message]
2025-01-25 17:01                                                                                 ` Maciej W. Rozycki
2025-01-25 17:43                                                                                   ` Ivan Kokshaysky
2025-01-25 18:25                                                                                     ` Maciej W. Rozycki
2025-01-25 18:59                                                                                       ` Maciej W. Rozycki
2025-01-25 19:48                                                                                         ` Ivan Kokshaysky
2025-01-25 22:06                                                                                           ` Maciej W. Rozycki
2025-01-25 23:02                                                                                             ` Ivan Kokshaysky
2025-01-26 14:00                                                                                               ` Ivan Kokshaysky
2025-01-26 19:15                                                                                                 ` Magnus Lindholm
2025-01-27 11:48                                                                                                   ` Ivan Kokshaysky
2025-01-27 11:56                                                                                                     ` John Paul Adrian Glaubitz
2025-01-25 18:07                                                                                 ` Magnus Lindholm
2025-01-25 15:35                                                                             ` Maciej W. Rozycki
2025-01-25 17:09                                                                               ` Ivan Kokshaysky
2025-01-24  6:54                                                                         ` John Paul Adrian Glaubitz
  -- strict thread matches above, loose matches on Subject: below --
2024-11-24 21:47 Magnus Lindholm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z5UAFAD6xCSpKJYw@minute \
    --to=ink@unseen.parts \
    --cc=glaubitz@physik.fu-berlin.de \
    --cc=linmag7@gmail.com \
    --cc=linux-alpha@vger.kernel.org \
    --cc=macro@orcam.me.uk \
    --cc=mcree@orcon.net.nz \
    --cc=paulmck@kernel.org \
    --cc=rcu@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.