From owner-freebsd-arm@FreeBSD.ORG Wed Feb 17 16:47:19 2010 Return-Path: Delivered-To: freebsd-arm@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 20648106566B for ; Wed, 17 Feb 2010 16:47:19 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from harmony.bsdimp.com (bsdimp.com [199.45.160.85]) by mx1.freebsd.org (Postfix) with ESMTP id B98F18FC13 for ; Wed, 17 Feb 2010 16:47:18 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by harmony.bsdimp.com (8.14.3/8.14.1) with ESMTP id o1HGiVM0048257; Wed, 17 Feb 2010 09:44:31 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Wed, 17 Feb 2010 09:44:44 -0700 (MST) Message-Id: <20100217.094444.4959786828202967.imp@bsdimp.com> To: gjb@semihalf.com From: "M. Warner Losh" In-Reply-To: <4B7BFAA4.4040607@semihalf.com> References: <4B7BFAA4.4040607@semihalf.com> X-Mailer: Mew version 6.3 on Emacs 22.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Cc: freebsd-arm@FreeBSD.org Subject: Re: kdump on ARM X-BeenThere: freebsd-arm@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to the StrongARM Processor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Feb 2010 16:47:19 -0000 In message: <4B7BFAA4.4040607@semihalf.com> Grzegorz Bernacki writes: : Hi, : : I've noticed that kdump on ARM doesn't work properly, it generates bus : error. The problem is that structures dumped into ktrace.out are not : aligned. Processing such a structure causes Aligment Fault. One : solution is to copy structure into local variable and then process it, : please see patch below. But I am not sure if this is the best solution : and maybe someone has a better idea. : : grzesiek : : : diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c : index 386221e..5a15886 100644 : --- a/usr.bin/kdump/kdump.c : +++ b/usr.bin/kdump/kdump.c : @@ -1325,6 +1325,10 @@ ktrstat(struct stat *statp) : void : ktrstruct(char *buf, size_t buflen) : { : +#if defined(__arm__) : + struct stat stat; : + struct sockaddr sockaddr; : +#endif Lose the ifdefs. Also, sockaddr is the wrong structure, it should be sockaddr_storage. : char *name, *data; : size_t namelen, datalen; : int i; : @@ -1348,12 +1352,22 @@ ktrstruct(char *buf, size_t buflen) : if (strcmp(name, "stat") == 0) { : if (datalen != sizeof(struct stat)) : goto invalid; : +#if defined(__arm__) : + memcpy(&stat, data, sizeof(struct stat)); : + ktrstat(&stat); : +#else : ktrstat((struct stat *)data); : +#endif This is needlessly complicated. Replace with: stat = *(struct stat *)data; ktrstat(&stat); : } else if (strcmp(name, "sockaddr") == 0) { : if (datalen < sizeof(struct sockaddr) || : datalen != ((struct sockaddr *)(data))->sa_len) : goto invalid; : +#if defined(__arm__) : + memcpy(&sockaddr, data, sizeof(struct sockaddr)); : + ktrsockaddr(&sockaddr); : +#else : ktrsockaddr((struct sockaddr *)data); : +#endif This is actually wrong. You're only copying part of the structure and it will be wrong for IPv6 addresses. Consider memcpy(&sockaddr, data, datalen); ktrsockaddr(&sockaddr); instead. However, this is already too late. We've already dereferenced through data in its unaligned state. Warner