NetBSD Problem Report #34202
From khym@azeotrope.org Mon Aug 14 23:20:39 2006
Return-Path: <khym@azeotrope.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by narn.NetBSD.org (Postfix) with ESMTP id 3C57863BA82
for <gnats-bugs@gnats.NetBSD.org>; Mon, 14 Aug 2006 23:20:39 +0000 (UTC)
Message-Id: <20060814232034.A18864C821@yerfable.azeotrope.org>
Date: Mon, 14 Aug 2006 18:20:34 -0500 (CDT)
From: khym@azeotrope.org
Reply-To: khym@azeotrope.org
To: gnats-bugs@NetBSD.org
Subject: Accessing cd device on alpha causes kernel trap
X-Send-Pr-Version: 3.95
>Number: 34202
>Category: kern
>Synopsis: Accessing cd device on alpha causes kernel trap
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: martin
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Aug 14 23:25:00 +0000 2006
>Closed-Date: Fri Dec 01 22:24:01 +0000 2006
>Last-Modified: Mon Jan 15 22:20:01 +0000 2007
>Originator: Dave Huang
>Release: NetBSD 4.99.1
>Organization:
Name: Dave Huang | Mammal, mammal / their names are called /
INet: khym@azeotrope.org | they raise a paw / the bat, the cat /
FurryMUCK: Dahan | dolphin and dog / koala bear and hog -- TMBG
Dahan: Hani G Y+C 30 Y++ L+++ W- C++ T++ A+ E+ S++ V++ F- Q+++ P+ B+ PA+ PL++
>Environment:
System: NetBSD yerfable.azeotrope.org 4.99.1 NetBSD 4.99.1 (YERFABLE) #222: Sun Aug 13 05:58:06 CDT 2006 khym@yerfable.azeotrope.org:/usr2/obj.alpha/sys/arch/alpha/compile/YERFABLE alpha
Architecture: alpha
Machine: alpha
>Description:
Any attempt to open the cd(4) device on NetBSD-current/alpha causes a kernel unaligned access fault. E.g.
# mount -t cd9660 -r /dev/cd1a /cdrom
CPU 0: fatal kernel trap:
CPU 0 trap entry = 0x4 (unaligned access fault)
CPU 0 a0 = 0xfffffe000c805ace
CPU 0 a1 = 0x2c
CPU 0 a2 = 0x1
CPU 0 pc = 0xfffffc00005d775c
CPU 0 ra = 0xfffffc00003dec24
CPU 0 pv = 0xfffffc00005d7720
CPU 0 curlwp = 0x0
panic: trap
Stopped at netbsd:cpu_Debugger+0x4: ret zero,(ra)
db> t
cpu_Debugger() at netbsd:cpu_Debugger+0x4
panic() at netbsd:panic+0x1d8
trap() at netbsd:trap+0x368
XentUna() at netbsd:XentUna+0x20
--- unaligned access fault (from ipl 4) ---
cia_swiz_io_read_multi_4() at netbsd:cia_swiz_io_read_multi_4+0x3c
wdc_datain_pio() at netbsd:wdc_datain_pio+0xd4
wdc_atapi_intr() at netbsd:wdc_atapi_intr+0x8ec
wdcintr() at netbsd:wdcintr+0x124
pciide_compat_intr() at netbsd:pciide_compat_intr+0x18
alpha_shared_intr_dispatch() at netbsd:alpha_shared_intr_dispatch+0x6c
sio_iointr() at netbsd:sio_iointr+0x3c
interrupt() at netbsd:interrupt+0x1e4
XentInt() at netbsd:XentInt+0x1c
--- interrupt (from ipl 0) ---
idle() at netbsd:idle+0x4c
mi_switch() at netbsd:mi_switch+0x250
ltsleep() at netbsd:ltsleep+0x39c
scsipi_execute_xs() at netbsd:scsipi_execute_xs+0x24c
scsipi_command() at netbsd:scsipi_command+0xe0
read_cd_capacity() at netbsd:read_cd_capacity+0x1cc
cdopen() at netbsd:cdopen+0x1f4
spec_open() at netbsd:spec_open+0x324
VOP_OPEN() at netbsd:VOP_OPEN+0x44
vn_open() at netbsd:vn_open+0x368
sys_open() at netbsd:sys_open+0x104
syscall_plain() at netbsd:syscall_plain+0x154
XentSys() at netbsd:XentSys+0x5c
--- syscall (5) ---
--- user mode ---
Even a simple "dd if=/dev/rcd1c of=/dev/null bs=2k count=1" will cause
the trap.
I'm not sure, but I believe this started with the switch to gcc 4; I
first noticed it with a -current kernel from July 6 sources, and I'm still seeing a problem with a kernel from August 13 sources.
>How-To-Repeat:
Attempt to access a CD on an alpha.
>Fix:
>Release-Note:
>Audit-Trail:
From: Dave Huang <khym@azeotrope.org>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: kern/34202
Date: Sun, 26 Nov 2006 00:12:05 -0600
Well, no response for months on this, so I looked into it myself...
the problem is in:
static int
read_cd_capacity(struct scsipi_periph *periph, u_int *blksize, u_long *size)
{
struct scsipi_read_cd_capacity cap_cmd;
struct scsipi_read_cd_cap_data cap;
struct scsipi_read_discinfo di_cmd;
struct scsipi_read_discinfo_data di;
struct scsipi_read_trackinfo ti_cmd;
struct scsipi_read_trackinfo_data ti;
All of those structs consist solely of u_int8_t members and arrays of
u_int8_t, and it looks like gcc4 packs those on the stack as tightly
as possible. On a test run on my system, the structs were placed at
these addresses:
...f9: ti
...d6: di
...cc: cap_cmd
...c2: di_cmd
...b8: ti_cmd
...b0: cap
Since struct scsipi_read_discinfo_data is an odd number of bytes long
(35 bytes), ti ends up being unaligned. wdc_datain_pio() uses
bus_space_read_multi_4() to read the response from the drive, and
since ti is unaligned, it causes an unaligned access fault.
I don't know what the correct fix for this is, but adding the
aligned(4) attribute to struct scsipi_read_trackinfo_data seems to
work. If adding the attribute is the right thing to do, perhaps it
should be added to all of the scsipi structs?
Index: dev/scsipi/scsipi_cd.h
===================================================================
RCS file: /cvsroot/src/sys/dev/scsipi/scsipi_cd.h,v
retrieving revision 1.14
diff -u -r1.14 scsipi_cd.h
--- dev/scsipi/scsipi_cd.h 20 Dec 2005 01:44:22 -0000 1.14
+++ dev/scsipi/scsipi_cd.h 26 Nov 2006 05:36:47 -0000
@@ -237,7 +237,7 @@
uint8_t track_msb;
uint8_t session_msb;
uint8_t unused2[2];
-} __attribute__((packed));
+} __attribute__((packed, aligned(4)));
#define READ_TRACKINFO_RETURNSIZE 36
From: matthew green <mrg@eterna.com.au>
To: gnats-bugs@NetBSD.org
Cc: kern-bug-people@netbsd.org, gnats-admin@netbsd.org,
netbsd-bugs@netbsd.org, khym@azeotrope.org
Subject: re: kern/34202
Date: Thu, 30 Nov 2006 08:03:55 +1100
isn't this fixed by cd.c 1.249?
.mrg.
From: khym@azeotrope.org
To: matthew green <mrg@eterna.com.au>
Cc: gnats-bugs@NetBSD.org, kern-bug-people@netbsd.org,
gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: kern/34202
Date: Wed, 29 Nov 2006 15:46:01 -0600
On Thu, Nov 30, 2006 at 08:03:55AM +1100, matthew green wrote:
>
> isn't this fixed by cd.c 1.249?
Not for me... the diff between 1.248 and 1.249 is:
error = scsipi_command(periph,
(void *) &di_cmd, sizeof(di_cmd),
- (void *) &di, sizeof(di),
+ (void *) &di, READ_DISCINFO_BIGSIZE,
CDRETRIES, 30000, NULL, flags);
if (error == 0) {
msb = di.last_track_last_session_msb;
and the checkin comment says, "Even though SCSI adapters
*should* accept odd lengths, the Sun U10 (sparc64's) crashes in
bus_space_read_multi_stream_2(). That explains the crash."
So this has to do with an odd length being passed in, not the alignment
of the structure. On my alpha, the READ_DISCINFO succeeds; it's the
following READ_TRACKINFO that crashes.
State-Changed-From-To: open->closed
State-Changed-By: christos@netbsd.org
State-Changed-When: Thu, 30 Nov 2006 11:23:42 -0500
State-Changed-Why:
fixed, thanks
From: Christos Zoulas <christos@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc:
Subject: PR/34202 CVS commit: src/sys/dev/scsipi
Date: Thu, 30 Nov 2006 16:23:21 +0000 (UTC)
Module Name: src
Committed By: christos
Date: Thu Nov 30 16:23:21 UTC 2006
Modified Files:
src/sys/dev/scsipi: scsipi_all.h scsipi_cd.h scsipi_disk.h
Log Message:
PR/34202: Dave Huang: Accessing cd device on alpha causes kernel trap
From the PR:
Since struct scsipi_read_discinfo_data is an odd number of bytes long
(35 bytes), ti ends up being unaligned. wdc_datain_pio() uses
bus_space_read_multi_4() to read the response from the drive, and
since ti is unaligned, it causes an unaligned access fault.
Add __aligned__(4) to all the structures.
To generate a diff of this commit:
cvs rdiff -r1.29 -r1.30 src/sys/dev/scsipi/scsipi_all.h
cvs rdiff -r1.14 -r1.15 src/sys/dev/scsipi/scsipi_cd.h
cvs rdiff -r1.16 -r1.17 src/sys/dev/scsipi/scsipi_disk.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: closed->feedback
State-Changed-By: martin@netbsd.org
State-Changed-When: Fri, 01 Dec 2006 21:26:39 +0000
State-Changed-Why:
I fixed it differently - could you verify this works for you?
From: Martin Husemann <martin@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc:
Subject: PR/34202 CVS commit: src/sys/dev/scsipi
Date: Fri, 1 Dec 2006 21:23:57 +0000 (UTC)
Module Name: src
Committed By: martin
Date: Fri Dec 1 21:23:57 UTC 2006
Modified Files:
src/sys/dev/scsipi: cd.c
Log Message:
Fix PR kern/34202 differently, by aligning the variables "the traditional
way".
To generate a diff of this commit:
cvs rdiff -r1.259 -r1.260 src/sys/dev/scsipi/cd.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Responsible-Changed-From-To: kern-bug-people->martin
Responsible-Changed-By: martin@netbsd.org
Responsible-Changed-When: Fri, 01 Dec 2006 22:24:01 +0000
Responsible-Changed-Why:
I fixed it
State-Changed-From-To: feedback->closed
State-Changed-By: martin@netbsd.org
State-Changed-When: Fri, 01 Dec 2006 22:24:01 +0000
State-Changed-Why:
Submitter confirmed fix
From: khym@azeotrope.org
To: gnats-bugs@NetBSD.org
Cc: kern-bug-people@netbsd.org, netbsd-bugs@netbsd.org,
gnats-admin@netbsd.org, martin@netbsd.org
Subject: Re: kern/34202 (Accessing cd device on alpha causes kernel trap)
Date: Fri, 1 Dec 2006 16:21:57 -0600
On Fri, Dec 01, 2006 at 09:26:41PM +0000, martin@netbsd.org wrote:
> Synopsis: Accessing cd device on alpha causes kernel trap
>
> State-Changed-From-To: closed->feedback
> State-Changed-By: martin@netbsd.org
> State-Changed-When: Fri, 01 Dec 2006 21:26:39 +0000
> State-Changed-Why:
> I fixed it differently - could you verify this works for you?
Yes, it works. Thanks!
From: Martin Husemann <martin@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc:
Subject: PR/34202 CVS commit: src/sys/dev/scsipi
Date: Sun, 14 Jan 2007 09:29:24 +0000 (UTC)
Module Name: src
Committed By: martin
Date: Sun Jan 14 09:29:24 UTC 2007
Modified Files:
src/sys/dev/scsipi: cd.c
Log Message:
The previous fix for PR 34202 was wrong (some sizeof used the union, not
the command block) - but instead of fixing this, we can now revert it
completley: the real fix has been applied to ../ic/wdc.c in rev. 1.244,
removing the alignement constraints.
To generate a diff of this commit:
cvs rdiff -r1.260 -r1.261 src/sys/dev/scsipi/cd.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: Pavel Cahyna <pavel@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc:
Subject: PR/34202 CVS commit: [netbsd-4] src/sys/dev
Date: Mon, 15 Jan 2007 22:15:14 +0000 (UTC)
Module Name: src
Committed By: pavel
Date: Mon Jan 15 22:15:14 UTC 2007
Modified Files:
src/sys/dev/ic [netbsd-4]: wdc.c
src/sys/dev/scsipi [netbsd-4]: cd.c
Log Message:
Pull up following revision(s) (requested by martin in ticket #371):
sys/dev/scsipi/cd.c: revision 1.261
sys/dev/ic/wdc.c: revision 1.244
If __NO_STRICT_ALIGNMENT is not defined, take special care to do PIO
transfers with proper alignement - this removes alignement restrictions
of the buffer pointer passed.
Thanks to bouyer, reinoud, jdc for helping with the code, and special
thanks to Dave Huang for testing.
The previous fix for PR 34202 was wrong (some sizeof used the union, not
the command block) - but instead of fixing this, we can now revert it
completley: the real fix has been applied to ../ic/wdc.c in rev. 1.244,
removing the alignement constraints.
To generate a diff of this commit:
cvs rdiff -r1.243 -r1.243.2.1 src/sys/dev/ic/wdc.c
cvs rdiff -r1.260 -r1.260.2.1 src/sys/dev/scsipi/cd.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.