From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by listman.redhat.com (Postfix) with ESMTP id 5EBAD3F732 for ; Wed, 16 Oct 2002 15:18:58 -0400 (EDT) Received: (from mail@localhost) by int-mx1.corp.redhat.com (8.11.6/8.11.6) id g9GJIwp01226 for axp-list@listman.redhat.com; Wed, 16 Oct 2002 15:18:58 -0400 Received: from mx1.redhat.com (mx1.redhat.com [172.16.48.31]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with SMTP id g9GJIwf01222 for ; Wed, 16 Oct 2002 15:18:58 -0400 Received: from handhelds.org ([192.58.209.91]) by mx1.redhat.com (8.11.6/8.11.6) with SMTP id g9GIwHw13586 for ; Wed, 16 Oct 2002 14:58:17 -0400 Received: (qmail 23273 invoked from network); 16 Oct 2002 19:18:30 -0000 Received: from localhost (HELO shadowfax.middleearth) (127.0.0.1) by localhost with SMTP; 16 Oct 2002 19:18:30 -0000 From: George France To: axp-list@redhat.com, alvin Subject: Re: unaligned traps question Date: Wed, 16 Oct 2002 15:18:29 -0400 X-Mailer: KMail [version 1.1.99] Content-Type: text/plain; charset="us-ascii" References: <01da01c273e4$d5c57320$35de2b09@Viswanadha> <3DAC6EF2.BC962839@voicenet.com> <3DADACDB.8000401@iplink.net> In-Reply-To: <3DADACDB.8000401@iplink.net> MIME-Version: 1.0 Message-Id: <02101615182900.18457@shadowfax.middleearth> Content-Transfer-Encoding: 8bit X-Loop: axp-list@redhat.com Sender: axp-list-admin@redhat.com Errors-To: axp-list-admin@redhat.com X-BeenThere: axp-list@redhat.com X-Mailman-Version: 2.0.1 Precedence: bulk Reply-To: axp-list@redhat.com List-Help: List-Post: List-Subscribe: , List-Id: Linux and Red Hat on Alpha processors List-Unsubscribe: , List-Archive: Hello Alvin, On Wednesday 16 October 2002 14:15, alvin wrote: > I have spent a good chunk of the last day or so trying to generate a > case where this problem does actually exist. Sadly I cannot recreate a > simple bug. I have a program (l2tpd) that runs a network tunneling > protocol. Anyway. This program works on streams of bytes that are the > control packets. Some of the packets have 16bit words that are unaligned > when they are going to be written. > > So I have a chunk of code like this: > > int add_message_type_avp(struct buffer *buf, _u16 type) { > _u16 *raw = (_u16 *)(buf->start + buf->len); > raw[0] = htons(0x8 | MBIT); > raw[1] = htons(VENDOR_ID); > raw[2] = 0; > raw[3] = htons(type); > buf->len += 8; > return 0; > } > > I end up converting it to this: > > int add_message_type_avp(struct buffer *buf, _u16 type) { > _u16 raw[32]; > raw[0] = htons(0x8 | MBIT); > raw[1] = htons(VENDOR_ID); > raw[2] = 0; > raw[3] = htons(type); > memcpy((char *)(buf->start + buf->len), (char *)&raw,8); > buf->len += 8; > return 0; > } > > > This is not pretty but it does work. Your converted code makes sense. A prettier method is used by the kernel in asm/unaligned.h via: get_unaligned(ptr); put_unaligned(val, ptr); More information can be found at: http://www.xml.com/ldd/chapter/book/ch10.html under the section titled "Data Alignment". > > I spent a lot of time tracking this one down and could only come to the > conclusion that the unaligned trap handler was not working correctly. If I had to take a wild guess, then I think that the unaligned trap handler is working correctly and that it is more likely that you have found a compiler optimization bug, which would explain your difficulty in reproducing the problem. Have you tried rebuilding your application with -O1, '-O2 -fno-sched-interblock' or '-O2 -fno-strength-reduce'??? > I was hoping to come up with a nice small proveable case but I just > could not seem to make things break on demand. and the only other way to > get this to break would involve kicking 40 customers off line(Not to > likely). I hope this helps. Best Regards, --George