Module Name:    src
Committed By:   thorpej
Date:           Tue Jul  6 12:20:52 UTC 2021

Modified Files:
        src/sys/arch/alpha/alpha: vm_machdep.c
        src/sys/arch/alpha/include: param.h

Log Message:
- Define STACK_ALIGNBYTES to override the default and ensure that
  stacks are 16-byte aligned, an assumption made by the compiler
  and recommended by the Alpha Architecture Handbook.
- cpu_lwp_fork(): Ensure 16-byte stack alignment if the caller specified
  one.

Addresses root casue of PR port-alpha/54307 and PR toolchain/56153.

Many thanks to rin@ for performing the root cause analysis and testing
changes.


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/sys/arch/alpha/alpha/vm_machdep.c
cvs rdiff -u -r1.48 -r1.49 src/sys/arch/alpha/include/param.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/alpha/alpha/vm_machdep.c
diff -u src/sys/arch/alpha/alpha/vm_machdep.c:1.119 src/sys/arch/alpha/alpha/vm_machdep.c:1.120
--- src/sys/arch/alpha/alpha/vm_machdep.c:1.119	Sun Jul  4 22:42:35 2021
+++ src/sys/arch/alpha/alpha/vm_machdep.c	Tue Jul  6 12:20:52 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: vm_machdep.c,v 1.119 2021/07/04 22:42:35 thorpej Exp $ */
+/* $NetBSD: vm_machdep.c,v 1.120 2021/07/06 12:20:52 thorpej Exp $ */
 
 /*
  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
@@ -29,7 +29,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.119 2021/07/04 22:42:35 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.120 2021/07/06 12:20:52 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -116,10 +116,12 @@ cpu_lwp_fork(struct lwp *l1, struct lwp 
 	 * Floating point state from the FP chip has already been saved.
 	 */
 	*pcb2 = *pcb1;
-	if (stack != NULL)
-		pcb2->pcb_hw.apcb_usp = (u_long)stack + stacksize;
-	else
+	if (stack != NULL) {
+		pcb2->pcb_hw.apcb_usp =
+		    ((u_long)stack + stacksize) & ~((u_long)STACK_ALIGNBYTES);
+	} else {
 		pcb2->pcb_hw.apcb_usp = alpha_pal_rdusp();
+	}
 
 	/*
 	 * Put l2 on the kernel's page tables until its first trip

Index: src/sys/arch/alpha/include/param.h
diff -u src/sys/arch/alpha/include/param.h:1.48 src/sys/arch/alpha/include/param.h:1.49
--- src/sys/arch/alpha/include/param.h:1.48	Mon May 31 14:38:55 2021
+++ src/sys/arch/alpha/include/param.h	Tue Jul  6 12:20:52 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: param.h,v 1.48 2021/05/31 14:38:55 simonb Exp $ */
+/* $NetBSD: param.h,v 1.49 2021/07/06 12:20:52 thorpej Exp $ */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -57,6 +57,12 @@
 #define ALPHA_PGSHIFT	13
 #endif
 
+/*
+ * Compiler assumes 16 byte stack alignment, per recommendation of
+ * Alpha Architecture Handbook.
+ */
+#define	STACK_ALIGNBYTES	(16 - 1)
+
 #define	NBPG		(1 << ALPHA_PGSHIFT)		/* bytes/page */
 #define	PGOFSET		(NBPG-1)			/* byte off. into pg */
 #define	PGSHIFT		ALPHA_PGSHIFT			/* LOG2(NBPG) */

Reply via email to