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.
This commit is contained in:
christos 2006-11-30 16:23:20 +00:00
parent 8c4a6d7ec4
commit d5272d5b35
3 changed files with 36 additions and 36 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: scsipi_all.h,v 1.29 2005/12/11 12:23:50 christos Exp $ */ /* $NetBSD: scsipi_all.h,v 1.30 2006/11/30 16:23:20 christos Exp $ */
/* /*
* SCSI and SCSI-like general interface description * SCSI and SCSI-like general interface description
@ -62,7 +62,7 @@ struct scsipi_inquiry {
u_int8_t unused[2]; u_int8_t unused[2];
u_int8_t length; u_int8_t length;
u_int8_t control; u_int8_t control;
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
#define START_STOP 0x1b #define START_STOP 0x1b
struct scsipi_start_stop { struct scsipi_start_stop {
@ -74,7 +74,7 @@ struct scsipi_start_stop {
#define SSS_START 0x01 #define SSS_START 0x01
#define SSS_LOEJ 0x02 #define SSS_LOEJ 0x02
u_int8_t control; u_int8_t control;
}; } __attribute__((__packed__, __aligned__(4)));
/* /*
* inquiry data format * inquiry data format
@ -163,6 +163,6 @@ struct scsipi_inquiry_data {
/*58*/ u_int8_t reserved; /*58*/ u_int8_t reserved;
/*59*/ char version_descriptor[8][2]; /*59*/ char version_descriptor[8][2];
#define SCSIPI_INQUIRY_LENGTH_SCSI3 74 #define SCSIPI_INQUIRY_LENGTH_SCSI3 74
} __attribute__((packed)); /* 74 Bytes */ } __attribute__((__packed__, __aligned__(4)));
#endif /* _DEV_SCSIPI_SCSIPI_ALL_H_ */ #endif /* _DEV_SCSIPI_SCSIPI_ALL_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: scsipi_cd.h,v 1.14 2005/12/20 01:44:22 reinoud Exp $ */ /* $NetBSD: scsipi_cd.h,v 1.15 2006/11/30 16:23:20 christos Exp $ */
/* /*
* Written by Julian Elischer (julian@tfs.com) * Written by Julian Elischer (julian@tfs.com)
@ -35,7 +35,7 @@ struct scsipi_load_unload {
u_int8_t unused2[3]; u_int8_t unused2[3];
u_int8_t slot; u_int8_t slot;
u_int8_t unused3[3]; u_int8_t unused3[3];
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
#define PAUSE 0x4b /* cdrom pause in 'play audio' mode */ #define PAUSE 0x4b /* cdrom pause in 'play audio' mode */
struct scsipi_pause { struct scsipi_pause {
@ -44,7 +44,7 @@ struct scsipi_pause {
u_int8_t unused[6]; u_int8_t unused[6];
u_int8_t resume; u_int8_t resume;
u_int8_t control; u_int8_t control;
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
#define PA_PAUSE 0x00 #define PA_PAUSE 0x00
#define PA_RESUME 0x01 #define PA_RESUME 0x01
@ -60,7 +60,7 @@ struct scsipi_play_msf {
u_int8_t end_s; u_int8_t end_s;
u_int8_t end_f; u_int8_t end_f;
u_int8_t control; u_int8_t control;
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
#define PLAY 0x45 /* cdrom play 'play audio' mode */ #define PLAY 0x45 /* cdrom play 'play audio' mode */
struct scsipi_play { struct scsipi_play {
@ -70,7 +70,7 @@ struct scsipi_play {
u_int8_t unused; u_int8_t unused;
u_int8_t xfer_len[2]; u_int8_t xfer_len[2];
u_int8_t control; u_int8_t control;
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
#define READ_HEADER 0x44 /* cdrom read header */ #define READ_HEADER 0x44 /* cdrom read header */
struct scsipi_read_header { struct scsipi_read_header {
@ -80,7 +80,7 @@ struct scsipi_read_header {
u_int8_t unused; u_int8_t unused;
u_int8_t data_len[2]; u_int8_t data_len[2];
u_int8_t control; u_int8_t control;
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
#define READ_SUBCHANNEL 0x42 /* cdrom read Subchannel */ #define READ_SUBCHANNEL 0x42 /* cdrom read Subchannel */
struct scsipi_read_subchannel { struct scsipi_read_subchannel {
@ -93,7 +93,7 @@ struct scsipi_read_subchannel {
u_int8_t track; u_int8_t track;
u_int8_t data_len[2]; u_int8_t data_len[2];
u_int8_t control; u_int8_t control;
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
#define READ_TOC 0x43 /* cdrom read TOC */ #define READ_TOC 0x43 /* cdrom read TOC */
struct scsipi_read_toc { struct scsipi_read_toc {
@ -104,13 +104,13 @@ struct scsipi_read_toc {
u_int8_t from_track; /* session nr in format 2 */ u_int8_t from_track; /* session nr in format 2 */
u_int8_t data_len[2]; u_int8_t data_len[2];
u_int8_t control; u_int8_t control;
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
struct scsipi_toc_header { struct scsipi_toc_header {
uint8_t length[2]; uint8_t length[2];
uint8_t first; /* track or session */ uint8_t first; /* track or session */
uint8_t last; uint8_t last;
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
/* read TOC form 0 result entries */ /* read TOC form 0 result entries */
struct scsipi_toc_formatted { struct scsipi_toc_formatted {
@ -119,7 +119,7 @@ struct scsipi_toc_formatted {
uint8_t tracknr; uint8_t tracknr;
uint8_t unused2; uint8_t unused2;
uint8_t msf_lba[4]; /* union msf_lba from cdio.h */ uint8_t msf_lba[4]; /* union msf_lba from cdio.h */
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
/* read TOC form 1 result entries */ /* read TOC form 1 result entries */
struct scsipi_toc_msinfo { struct scsipi_toc_msinfo {
@ -128,7 +128,7 @@ struct scsipi_toc_msinfo {
uint8_t tracknr; /* first track last compl. session */ uint8_t tracknr; /* first track last compl. session */
uint8_t unused2; uint8_t unused2;
uint8_t msf_lba[4]; /* union msf_lba from cdio.h */ uint8_t msf_lba[4]; /* union msf_lba from cdio.h */
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
/* read TOC form 2 result entries */ /* read TOC form 2 result entries */
struct scsipi_toc_rawtoc { struct scsipi_toc_rawtoc {
@ -143,7 +143,7 @@ struct scsipi_toc_rawtoc {
uint8_t pmin; uint8_t pmin;
uint8_t psec; uint8_t psec;
uint8_t pframe; uint8_t pframe;
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
/* read TOC form 3, 4 and 5 obmitted yet */ /* read TOC form 3, 4 and 5 obmitted yet */
@ -156,21 +156,21 @@ struct scsipi_get_configuration {
uint8_t unused[3]; uint8_t unused[3];
uint8_t data_len[2]; uint8_t data_len[2];
uint8_t control; uint8_t control;
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
struct scsipi_get_conf_data { struct scsipi_get_conf_data {
uint8_t data_len[4]; uint8_t data_len[4];
uint8_t unused[2]; uint8_t unused[2];
uint8_t mmc_profile[2]; /* current mmc profile for disk */ uint8_t mmc_profile[2]; /* current mmc profile for disk */
uint8_t feature_desc[1]; /* feature descriptors follow */ uint8_t feature_desc[1]; /* feature descriptors follow */
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
struct scsipi_get_conf_feature { /* feature descriptor */ struct scsipi_get_conf_feature { /* feature descriptor */
uint8_t featurecode[2]; uint8_t featurecode[2];
uint8_t flags; uint8_t flags;
uint8_t additional_length; /* length of feature dependent */ uint8_t additional_length; /* length of feature dependent */
uint8_t feature_dependent[256]; uint8_t feature_dependent[256];
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
#define FEATUREFLAG_CURRENT 1 #define FEATUREFLAG_CURRENT 1
#define FEATUREFLAG_PERSISTENT 2 #define FEATUREFLAG_PERSISTENT 2
@ -181,7 +181,7 @@ struct scsipi_read_discinfo {
uint8_t unused[6]; uint8_t unused[6];
uint8_t data_len[2]; uint8_t data_len[2];
uint8_t control; uint8_t control;
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
#define READ_DISCINFO_SMALLSIZE 12 #define READ_DISCINFO_SMALLSIZE 12
#define READ_DISCINFO_BIGSIZE 34 /* + entries */ #define READ_DISCINFO_BIGSIZE 34 /* + entries */
@ -204,7 +204,7 @@ struct scsipi_read_discinfo_data {
uint8_t application_code; uint8_t application_code;
uint8_t num_opc_table_entries; uint8_t num_opc_table_entries;
uint8_t opc_table_entries[1]; /* opc table entries follow */ uint8_t opc_table_entries[1]; /* opc table entries follow */
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
#define READ_TRACKINFO 0x52 #define READ_TRACKINFO 0x52
@ -215,7 +215,7 @@ struct scsipi_read_trackinfo {
uint8_t nothing; uint8_t nothing;
uint8_t data_len[2]; uint8_t data_len[2];
uint8_t control; uint8_t control;
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
#define READ_TRACKINFO_ADDR_LBA 0 #define READ_TRACKINFO_ADDR_LBA 0
#define READ_TRACKINFO_ADDR_TRACK 1 #define READ_TRACKINFO_ADDR_TRACK 1
#define READ_TRACKINFO_ADDR_SESS 2 #define READ_TRACKINFO_ADDR_SESS 2
@ -237,7 +237,7 @@ struct scsipi_read_trackinfo_data {
uint8_t track_msb; uint8_t track_msb;
uint8_t session_msb; uint8_t session_msb;
uint8_t unused2[2]; uint8_t unused2[2];
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
#define READ_TRACKINFO_RETURNSIZE 36 #define READ_TRACKINFO_RETURNSIZE 36
@ -248,12 +248,12 @@ struct scsipi_read_cd_capacity {
u_int8_t addr[4]; u_int8_t addr[4];
u_int8_t unused[3]; u_int8_t unused[3];
u_int8_t control; u_int8_t control;
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
struct scsipi_read_cd_cap_data { struct scsipi_read_cd_cap_data {
u_int8_t addr[4]; u_int8_t addr[4];
u_int8_t length[4]; u_int8_t length[4];
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
/* mod pages common to scsi and atapi */ /* mod pages common to scsi and atapi */

View File

@ -1,4 +1,4 @@
/* $NetBSD: scsipi_disk.h,v 1.16 2005/12/11 12:23:50 christos Exp $ */ /* $NetBSD: scsipi_disk.h,v 1.17 2006/11/30 16:23:20 christos Exp $ */
/* /*
* SCSI and SCSI-like interfaces description * SCSI and SCSI-like interfaces description
@ -70,7 +70,7 @@ struct scsipi_rw_10 {
u_int8_t reserved; u_int8_t reserved;
u_int8_t length[2]; u_int8_t length[2];
u_int8_t control; u_int8_t control;
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
#define READ_12 0xa8 #define READ_12 0xa8
#define WRITE_12 0xaa #define WRITE_12 0xaa
@ -81,7 +81,7 @@ struct scsipi_rw_12 {
u_int8_t length[4]; u_int8_t length[4];
u_int8_t byte11; u_int8_t byte11;
u_int8_t control; u_int8_t control;
}; } __attribute__((__packed__, __aligned__(4)));
#define READ_16 0x88 #define READ_16 0x88
#define WRITE_16 0x8a #define WRITE_16 0x8a
@ -92,7 +92,7 @@ struct scsipi_rw_16 {
u_int8_t length[4]; u_int8_t length[4];
u_int8_t byte15; u_int8_t byte15;
u_int8_t control; u_int8_t control;
}; } __attribute__((__packed__, __aligned__(4)));
#define READ_CAPACITY_10 0x25 #define READ_CAPACITY_10 0x25
struct scsipi_read_capacity_10 { struct scsipi_read_capacity_10 {
@ -101,14 +101,14 @@ struct scsipi_read_capacity_10 {
u_int8_t addr[4]; u_int8_t addr[4];
u_int8_t unused[3]; u_int8_t unused[3];
u_int8_t control; u_int8_t control;
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
/* DATAs definitions for the above commands */ /* DATAs definitions for the above commands */
struct scsipi_read_capacity_10_data { struct scsipi_read_capacity_10_data {
u_int8_t addr[4]; u_int8_t addr[4];
u_int8_t length[4]; u_int8_t length[4];
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
#define READ_CAPACITY_16 0x9e /* really SERVICE ACTION IN */ #define READ_CAPACITY_16 0x9e /* really SERVICE ACTION IN */
struct scsipi_read_capacity_16 { struct scsipi_read_capacity_16 {
@ -120,7 +120,7 @@ struct scsipi_read_capacity_16 {
u_int8_t byte15; u_int8_t byte15;
#define SRC16_PMI 0x01 #define SRC16_PMI 0x01
u_int8_t control; u_int8_t control;
}; } __attribute__((__packed__, __aligned__(4)));
struct scsipi_read_capacity_16_data { struct scsipi_read_capacity_16_data {
u_int8_t addr[8]; u_int8_t addr[8];
@ -129,7 +129,7 @@ struct scsipi_read_capacity_16_data {
#define SRC16D_PROT_EN 0x01 #define SRC16D_PROT_EN 0x01
#define SRC16D_RTO_EN 0x02 #define SRC16D_RTO_EN 0x02
u_int8_t reserved[19]; u_int8_t reserved[19];
}; } __attribute__((__packed__, __aligned__(4)));
/* XXX SBC-2 says this is vendor-specific */ /* XXX SBC-2 says this is vendor-specific */
#define READ_FORMAT_CAPACITIES 0x23 #define READ_FORMAT_CAPACITIES 0x23
@ -139,18 +139,18 @@ struct scsipi_read_format_capacities {
u_int8_t reserved1[5]; u_int8_t reserved1[5];
u_int8_t length[2]; u_int8_t length[2];
u_int8_t reserved2[3]; u_int8_t reserved2[3];
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
struct scsipi_capacity_list_header { struct scsipi_capacity_list_header {
u_int8_t reserved[3]; u_int8_t reserved[3];
u_int8_t length; u_int8_t length;
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
struct scsipi_capacity_descriptor { struct scsipi_capacity_descriptor {
u_int8_t nblks[4]; u_int8_t nblks[4];
u_int8_t byte5; u_int8_t byte5;
u_int8_t blklen[3]; u_int8_t blklen[3];
} __attribute__((packed)); } __attribute__((__packed__, __aligned__(4)));
/* codes only valid in the current/maximum capacity descriptor */ /* codes only valid in the current/maximum capacity descriptor */
#define SCSIPI_CAP_DESC_CODE_MASK 0x3 #define SCSIPI_CAP_DESC_CODE_MASK 0x3