Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* Unaligned traps on kernel startup
@ 1998-08-31  6:01 Michal Jaegermann
  1998-08-31  7:55 ` furio ercolessi
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Michal Jaegermann @ 1998-08-31  6:01 UTC (permalink / raw)
  To: axp-list


If on Alpha CONFIG_BLK_DEV_IDE is defined then with current kernels
(2.0.3x) one see the following on a startup:

kernel: unaligned trap at fffffc00003a3278: fffffc00000061be 28 1
kernel: unaligned trap at fffffc00003a328c: fffffc00000061c2 28 2
kernel: unaligned trap at fffffc00003a3278: fffffc00000061ce 28 1
kernel: unaligned trap at fffffc00003a328c: fffffc00000061d2 28 2

Here is the corresponding kernel code:

0xfffffc00003a3278 <msdos_partition+568>:	ldl	t0,0(t2)
0xfffffc00003a327c <msdos_partition+572>:	extbl	t0,0x2,t0
0xfffffc00003a3280 <msdos_partition+576>:	and	t0,0x3f,t0
0xfffffc00003a3284 <msdos_partition+580>:	cmpeq	t0,0x1,t0
0xfffffc00003a3288 <msdos_partition+584>:	
    beq	t0,0xfffffc00003a32ec <msdos_partition+684>
0xfffffc00003a328c <msdos_partition+588>:	ldl	t1,4(t2)
0xfffffc00003a3290 <msdos_partition+592>:	extbl	t1,0x2,t0
0xfffffc00003a3294 <msdos_partition+596>:	and	t0,0x3f,t0
0xfffffc00003a3298 <msdos_partition+600>:	cmpeq	t0,0x3f,t0
0xfffffc00003a329c <msdos_partition+604>:	

It is from linux/drivers/block/genhd.c and traps happen on lines
marked with '---->':

329				for (i = 0; i < 4 ; i++) {
330					struct partition *q = &p[i];
331					if (NR_SECTS(q)
332				----->	   && (q->sector & 63) == 1
333				----->	   && (q->end_sector & 63) == 63) {

sizeof(struct partition) appears to be 16 so maybe I miss something
but it seems a bit of strange that I see only two pairs of traps and
not four.

I realize that this is likely a cosmetic issue but does anybody has
an idea how to fix that?  It seems likely that something of that sort
is also responsible for all these complaints you see every time when
you fire 'fdisk'.  All of this does not give a warm fuzzy feeling
to a newbie.

  Thanks,
  Michal

p.s. A code  quoted above is a  part of a  bigger piece which tries to
gues a "correct" C/H/S translation for IDE disks.  This guessing looks
somewhat fishy anyway, especially on Alpha  without an Intel BIOS, but
we are likely stuck with it - at least for a time beeing.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unaligned traps on kernel startup
  1998-08-31  6:01 Unaligned traps on kernel startup Michal Jaegermann
@ 1998-08-31  7:55 ` furio ercolessi
  1998-08-31 12:19 ` Uncle George
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: furio ercolessi @ 1998-08-31  7:55 UTC (permalink / raw)
  To: axp-list

> If on Alpha CONFIG_BLK_DEV_IDE is defined then with current kernels
> (2.0.3x) one see the following on a startup:
> 
> kernel: unaligned trap at fffffc00003a3278: fffffc00000061be 28 1
> kernel: unaligned trap at fffffc00003a328c: fffffc00000061c2 28 2
> kernel: unaligned trap at fffffc00003a3278: fffffc00000061ce 28 1
> kernel: unaligned trap at fffffc00003a328c: fffffc00000061d2 28 2

> It is from linux/drivers/block/genhd.c

As an additional comment,  I observed that this occurs on egcs-compiled
kernels (both 1.0.2 and 1.0.3) but not on those compiled with gcc
(2.7.2.3).
 
furio ercolessi
Spin - Trieste (Italy)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unaligned traps on kernel startup
  1998-08-31  6:01 Unaligned traps on kernel startup Michal Jaegermann
  1998-08-31  7:55 ` furio ercolessi
@ 1998-08-31 12:19 ` Uncle George
  1998-08-31 17:51 ` Mike "Ford" Ditto
  1998-08-31 19:10 ` Richard Henderson
  3 siblings, 0 replies; 7+ messages in thread
From: Uncle George @ 1998-08-31 12:19 UTC (permalink / raw)
  To: axp-list

doesn't mean that &p[i] is aligned ( sorry not looking at kern code ) from what
appears should be on an int boundary. is appears that 61be/61c2/61ce/61d2 are
aligned on a short boundary.
fix? well u can memmov the unaligned struct to an aligned struct

 for (i = 0; i < 4 ; i++) {
330                                     struct partition q;
                                            memcpy(&q, &p[i], sizeof ( struct
partition));
331                                     if (NR_SECTS(q)
332                             ----->     && (q.sector & 63) == 1
333                             ----->     && (q.end_sector & 63) == 63) {
Michal Jaegermann wrote:

> If on Alpha CONFIG_BLK_DEV_IDE is defined then with current kernels
> (2.0.3x) one see the following on a startup:
>




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unaligned traps on kernel startup
  1998-08-31  6:01 Unaligned traps on kernel startup Michal Jaegermann
  1998-08-31  7:55 ` furio ercolessi
  1998-08-31 12:19 ` Uncle George
@ 1998-08-31 17:51 ` Mike "Ford" Ditto
  1998-09-01  1:49   ` Michal Jaegermann
  1998-08-31 19:10 ` Richard Henderson
  3 siblings, 1 reply; 7+ messages in thread
From: Mike "Ford" Ditto @ 1998-08-31 17:51 UTC (permalink / raw)
  To: axp-list

> It is from linux/drivers/block/genhd.c and traps happen on lines
> marked with '---->':
>
> 329				for (i = 0; i < 4 ; i++) {
> 330					struct partition *q = &p[i];
> 331					if (NR_SECTS(q)
> 332				----->	   && (q->sector & 63) == 1
> 333				----->	   && (q->end_sector & 63) == 63) {
>
> sizeof(struct partition) appears to be 16 so maybe I miss something
> but it seems a bit of strange that I see only two pairs of traps and
> not four.

Maybe you only have two actual partitions on that disk?

The traps occur because p points to the partition table portion of a
disk sector.  The disk sector is properly aligned, but the partition
table (at offset 0xFBE by IBM's/Microsoft's design) is not properly
aligned within the sector.

The fix for the traps is to have those marked lines use get_aligned the
way the line immediately above them does, as explained at the top of
genhd.c:

	/*
	 * Many architectures don't like unaligned accesses, which is
	 * frequently the case with the nr_sects and start_sect partition
	 * table entries.
	 */
	#include <asm/unaligned.h>

	#define SYS_IND(p)	get_unaligned(&p->sys_ind)
	#define NR_SECTS(p)	get_unaligned(&p->nr_sects)
	#define START_SECT(p)	get_unaligned(&p->start_sect)

Add two similar macros for sector and end_sector and use them.

					-=] Ford [=-

"But everybody wants a rock		(In Real Life:  Mike Ditto)
 to wind a piece of string around."	ford@omnicron.com
 - They Might be Giants,		http://www.omnicron.com/~ford/ford.html
   "We want a rock"


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unaligned traps on kernel startup
  1998-08-31  6:01 Unaligned traps on kernel startup Michal Jaegermann
                   ` (2 preceding siblings ...)
  1998-08-31 17:51 ` Mike "Ford" Ditto
@ 1998-08-31 19:10 ` Richard Henderson
  1998-09-01  5:55   ` Michal Jaegermann
  3 siblings, 1 reply; 7+ messages in thread
From: Richard Henderson @ 1998-08-31 19:10 UTC (permalink / raw)
  To: axp-list, torvalds

On Mon, Aug 31, 1998 at 12:01:06AM -0600, Michal Jaegermann wrote:
> If on Alpha CONFIG_BLK_DEV_IDE is defined then with current kernels
> (2.0.3x) one see the following on a startup:
> 
> kernel: unaligned trap at fffffc00003a3278: fffffc00000061be 28 1
> kernel: unaligned trap at fffffc00003a328c: fffffc00000061c2 28 2
> kernel: unaligned trap at fffffc00003a3278: fffffc00000061ce 28 1
> kernel: unaligned trap at fffffc00003a328c: fffffc00000061d2 28 2
> 
> Here is the corresponding kernel code:
> 
> 0xfffffc00003a3278 <msdos_partition+568>:	ldl	t0,0(t2)
> 0xfffffc00003a327c <msdos_partition+572>:	extbl	t0,0x2,t0
> 0xfffffc00003a3280 <msdos_partition+576>:	and	t0,0x3f,t0
> 0xfffffc00003a3284 <msdos_partition+580>:	cmpeq	t0,0x1,t0
> 0xfffffc00003a3288 <msdos_partition+584>:	
>     beq	t0,0xfffffc00003a32ec <msdos_partition+684>
> 0xfffffc00003a328c <msdos_partition+588>:	ldl	t1,4(t2)
> 0xfffffc00003a3290 <msdos_partition+592>:	extbl	t1,0x2,t0
> 0xfffffc00003a3294 <msdos_partition+596>:	and	t0,0x3f,t0
> 0xfffffc00003a3298 <msdos_partition+600>:	cmpeq	t0,0x3f,t0
> 0xfffffc00003a329c <msdos_partition+604>:	
> 
> It is from linux/drivers/block/genhd.c and traps happen on lines
> marked with '---->':
> 
> 329				for (i = 0; i < 4 ; i++) {
> 330					struct partition *q = &p[i];
> 331					if (NR_SECTS(q)
> 332				----->	   && (q->sector & 63) == 1
> 333				----->	   && (q->end_sector & 63) == 63) {

Linus, the compiler has gotten smart.  It sees that those two character
loads are contained in a structure with known alignment, and optimizes.

I don't see a solution at the moment less gross than just marking the
structure as packed.  Alternately, I suppose we could turn off the 
unaligned access message in the kernel for the 2.2 release.


r~


--- include/linux/genhd.h.orig	Mon Aug 31 12:04:52 1998
+++ include/linux/genhd.h	Mon Aug 31 12:05:09 1998
@@ -49,7 +49,7 @@ struct partition {
 	unsigned char end_cyl;		/* end cylinder */
 	unsigned int start_sect;	/* starting sector counting from 0 */
 	unsigned int nr_sects;		/* nr of sectors in partition */
-};
+} __attribute__((packed));
 
 struct hd_struct {
 	long start_sect;


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unaligned traps on kernel startup
  1998-08-31 17:51 ` Mike "Ford" Ditto
@ 1998-09-01  1:49   ` Michal Jaegermann
  0 siblings, 0 replies; 7+ messages in thread
From: Michal Jaegermann @ 1998-09-01  1:49 UTC (permalink / raw)
  To: axp-list

Mike \"Ford\" Ditto wrote:
> 
> > It is from linux/drivers/block/genhd.c and traps happen on lines
> > marked with '---->':
> >
> > 329				for (i = 0; i < 4 ; i++) {
> > 330					struct partition *q = &p[i];
> > 331					if (NR_SECTS(q)
> > 332				----->	   && (q->sector & 63) == 1
> > 333				----->	   && (q->end_sector & 63) == 63) {
> >
> > sizeof(struct partition) appears to be 16 so maybe I miss something
> > but it seems a bit of strange that I see only two pairs of traps and
> > not four.
> 
> Maybe you only have two actual partitions on that disk?

No. Actually there are four.  Something seems to align the other two.

> The fix for the traps is to have those marked lines use get_aligned the
> way the line immediately above them does, as explained at the top of
> genhd.c:

Ah, thanks.  I missed an existence of this macro.  I will have to 
try that.

   Michal


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Unaligned traps on kernel startup
  1998-08-31 19:10 ` Richard Henderson
@ 1998-09-01  5:55   ` Michal Jaegermann
  0 siblings, 0 replies; 7+ messages in thread
From: Michal Jaegermann @ 1998-09-01  5:55 UTC (permalink / raw)
  To: rth; +Cc: axp-list, torvalds

Richard Henderson wrote:
> 
> On Mon, Aug 31, 1998 at 12:01:06AM -0600, Michal Jaegermann wrote:
.....
> > It is from linux/drivers/block/genhd.c and traps happen on lines
> > marked with '---->':
> > 
> > 329				for (i = 0; i < 4 ; i++) {
> > 330					struct partition *q = &p[i];
> > 331					if (NR_SECTS(q)
> > 332				----->	   && (q->sector & 63) == 1
> > 333				----->	   && (q->end_sector & 63) == 63) {
> 
> Linus, the compiler has gotten smart.  It sees that those two character
> loads are contained in a structure with known alignment, and optimizes.
> 
> I don't see a solution at the moment less gross than just marking the
> structure as packed.  Alternately, I suppose we could turn off the 
> unaligned access message in the kernel for the 2.2 release.

Actually a suggestion from Mike "Ford" Ditto seems to work pretty well.
I replaced the lines in question with:
                          && (get_unaligned(&q->sector) & 63) == 1
                          && (get_unaligned(&q->end_sector) & 63) == 63) {
and now everything seems to be happy.

A macro "get_unaligned" is defined for all architectures.

  Michal


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1998-09-01  5:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-08-31  6:01 Unaligned traps on kernel startup Michal Jaegermann
1998-08-31  7:55 ` furio ercolessi
1998-08-31 12:19 ` Uncle George
1998-08-31 17:51 ` Mike "Ford" Ditto
1998-09-01  1:49   ` Michal Jaegermann
1998-08-31 19:10 ` Richard Henderson
1998-09-01  5:55   ` Michal Jaegermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox