Subject: port-alpha/8126: unaligned accesses of mbrlabel on Alpha (maybe others)
To: None <gnats-bugs@gnats.netbsd.org>
From: None <cpg@aladdin.de>
List: netbsd-bugs
Date: 08/01/1999 07:36:33
>Number:         8126
>Category:       port-alpha
>Synopsis:       unaligned accesses of mbrlabel on Alpha (maybe others)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    port-alpha-maintainer (NetBSD/alpha Portmaster)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Aug  1 07:35:00 1999
>Last-Modified:
>Originator:     Charlie Root
>Organization:
	
>Release:        current-19990723
>Environment:
	
System: NetBSD alpha 1.4G NetBSD 1.4G (SIXTYFOUR) #1: Sun Jul 25 17:48:26 CEST 1999 chris@alpha:/net/scharfzahn/alpha/netbsd/sys/arch/alpha/compile/SIXTYFOUR alpha

some more info:

AlphaStation 200 4/100, 100MHz
8192 byte page size, 1 processor.
cpu0 at mainbus0: ID 0 (primary), 21064-0 (pass 2 or 2.1)
cpu0: VAX FP support, IEEE FP support, Primary Eligible


>Description:
	Executing mbrlabel on the Alpha machine generates a bunch of
	unaligned accesses.

	  alpha:~# ~chris/mbrlabel-before sd0
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff382 pc=0x120001050 ra=0x120000fe0 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff382 pc=0x12000109c ra=0x12000109c op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff392 pc=0x120001050 ra=0x1200010b8 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff3a2 pc=0x120001050 ra=0x1200010b8 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff3a2 pc=0x12000109c ra=0x12000109c op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff3b2 pc=0x120001050 ra=0x1200010b8 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff382 pc=0x120001170 ra=0x1200010b8 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff392 pc=0x120001170 ra=0x1200010b8 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff132 pc=0x120001050 ra=0x120000fe0 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff132 pc=0x12000109c ra=0x12000109c op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff142 pc=0x120001050 ra=0x1200010b8 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff152 pc=0x120001050 ra=0x1200010b8 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff162 pc=0x120001050 ra=0x1200010b8 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff132 pc=0x120001170 ra=0x1200010b8 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff142 pc=0x120001170 ra=0x1200010b8 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1ffffeee2 pc=0x120001050 ra=0x120000fe0 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1ffffeee2 pc=0x12000109c ra=0x12000109c op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1ffffeef2 pc=0x120001050 ra=0x1200010b8 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1ffffef02 pc=0x120001050 ra=0x1200010b8 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1ffffef12 pc=0x120001050 ra=0x1200010b8 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1ffffeee2 pc=0x120001170 ra=0x1200010b8 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1ffffeef2 pc=0x120001170 ra=0x1200010b8 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1ffffef02 pc=0x120001170 ra=0x1200011a4 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1ffffef12 pc=0x120001170 ra=0x1200011a4 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff152 pc=0x120001170 ra=0x1200011a4 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff162 pc=0x120001170 ra=0x1200011a4 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff3a2 pc=0x120001170 ra=0x1200011a4 op=ldl
	  pid 491 (mbrlabel-before): unaligned access: va=0x1fffff3b2 pc=0x120001170 ra=0x1200011a4 op=ldl
	  alpha:~# 

	The disk in question (sd0) has a MBR and contains NT and Linux partitions.

>How-To-Repeat:
	Run mbrlabel on Alpha. Maybe make sure the mbrlabel utility is compiled
	for the EV4, 21064 processor (-mcpu=ev4), I think the compiler generates 
	better structure access sequences for newer processors.
	
>Fix:
	The fix I found is to tell the compiler that it should always assume,
	the struct diskpart_mbr access is unaligned. This is the case as there
	are many sequences in the code (not only in mbrlabel.c) which do something
	like
	          mpart = (void *)(buf + MBR_PARTOFF);
	
	The bug is in fact not in mbrlabel.c but in sys/disklabel_mbr.h.
	That's my supposed patch:


--- sys/disklabel_mbr.h.org	Fri May 21 03:04:38 1999
+++ sys/disklabel_mbr.h	Sun Aug  1 16:11:54 1999
@@ -59,7 +59,7 @@
 	u_int8_t	mbrp_ecyl;	/* end cylinder */
 	u_int32_t	mbrp_start;	/* absolute starting sector number */
 	u_int32_t	mbrp_size;	/* partition size in sectors */
-};
+} __attribute__ ((packed));  /* will be accessed from unaligned base address */
 #endif
 
 /* Known MBR partition types: */

>Audit-Trail:
>Unformatted: