From nobody@FreeBSD.org  Fri Sep  4 22:17:32 2009
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 7C022106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  4 Sep 2009 22:17:32 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 60F588FC1D
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  4 Sep 2009 22:17:32 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n84MHVVa089171
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 4 Sep 2009 22:17:31 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id n84MHVi4089170;
	Fri, 4 Sep 2009 22:17:31 GMT
	(envelope-from nobody)
Message-Id: <200909042217.n84MHVi4089170@www.freebsd.org>
Date: Fri, 4 Sep 2009 22:17:31 GMT
From: Brad Huntting <huntting@glarp.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: sysutils/smartmontools
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         138540
>Category:       ports
>Synopsis:       sysutils/smartmontools
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    avl
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Sep 04 22:20:00 UTC 2009
>Closed-Date:    Fri Sep 11 13:42:38 UTC 2009
>Last-Modified:  Fri Sep 11 13:50:01 UTC 2009
>Originator:     Brad Huntting
>Release:        7.2-PRERELEASE
>Organization:
>Environment:
FreeBSD PharLap-00005045b076 7.2-PRERELEASE FreeBSD 7.2-PRERELEASE #0: Mon Aug 31 14:58:08 MDT 2009    * amd64

>Description:
smartctl likes to read SMART data into 512 byte buffers which it allocates on the stack.  While this _should_ work just fine, I have found that sometimes, when using SATA over SAS (-d sat) with an MPT Fusion HBA, smartctl's buffer gets broken into 2 Scatter Gather Elements (probably because the 512 byte buffer stradles a page boundary).  Sometimes, only the first of these gets filled before the mpt driver records a timeout and subsequently resets the SAS bus.

I have not fully diagnosed the problem or had time to write a sample code'let that can reproduce it.  But in the mean time, this patch moves the data buffer from the stack to the heap where it will be aligned to avoid a page boundary.

Hopefully I will have time to diagnose the real problem and either fix it (if it's in the driver) or send in a bug report to LSI (if it's in the MPT controller).

thanx,
brad
>How-To-Repeat:
pray.  Then on a 64bit system, with an 8gig LSI MPT SAS controler
           Mpi Version 1.5.20.0
             FWVersion 1.28.0.0
or           FWVersion 1.28.2.0
connected to a SATA drive, turn on all available debugging in CAM and the MPT driver.

run smartctl -d sat -r ioctl -a /dev/da<foo>

sometimes, if you're 'lucky', you'll see a bus reset, and smartcl will fail to get some of it's SMART data.
>Fix:
Attached is a patch to the port that adds a patch that makes shure the data buffers used to read smart attributes and logs do not straddle page boundaries.

Patch attached with submission follows:

diff -Nru /usr/ports/sysutils/smartmontools/Makefile /home/huntting/src/Copan/smartmontools/Makefile
--- /usr/ports/sysutils/smartmontools/Makefile	2009-07-08 13:56:07.000000000 -0600
+++ /home/huntting/src/Copan/smartmontools/Makefile	2009-09-04 14:58:21.000000000 -0600
@@ -25,7 +25,7 @@
 MAN5=		smartd.conf.5
 MAN8=		smartd.8 smartctl.8
 
-CFLAGS:=	${CFLAGS:S/-O2/-O/}
+CFLAGS:=	${CFLAGS:S/-O2/-O/} -Wno-write-strings
 
 post-patch:
 	@${REINPLACE_CMD} -e 's| install-initdDATA | |' ${WRKSRC}/Makefile.in
diff -Nru /usr/ports/sysutils/smartmontools/files/patch-scsiata.cpp /home/huntting/src/Copan/smartmontools/files/patch-scsiata.cpp
--- /usr/ports/sysutils/smartmontools/files/patch-scsiata.cpp	1969-12-31 17:00:00.000000000 -0700
+++ /home/huntting/src/Copan/smartmontools/files/patch-scsiata.cpp	2009-09-04 14:28:13.000000000 -0600
@@ -0,0 +1,22 @@
+--- scsiata.cpp.orig	2007-12-02 19:14:20.000000000 -0700
++++ scsiata.cpp	2009-09-04 14:27:48.000000000 -0600
+@@ -380,14 +380,14 @@
+    return 1, else 0 */
+ int has_sat_pass_through(int device, int packet_interface)
+ {
+-    char data[512];
++    int ret;
++    char *data = (char *)malloc(512);	// (alignment)
+     smart_command_set command;
+ 
+     command = packet_interface ? PIDENTIFY : IDENTIFY;
+-    if (0 == sat_command_interface(device, command, 0, data))
+-        return 1;
+-    else
+-        return 0;
++    ret = ( 0 == sat_command_interface(device, command, 0, data) ? 1 : 0 );
++    free(data);
++    return ret;
+ }
+ 
+ /* Next two functions are borrowed from sg_lib.c in the sg3_utils


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->marck 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Fri Sep 4 22:20:12 UTC 2009 
Responsible-Changed-Why:  
Over to maintainer (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=138540 
Responsible-Changed-From-To: marck->freebsd-ports-bugs 
Responsible-Changed-By: marck 
Responsible-Changed-When: Sat Sep 5 07:29:35 UTC 2009 
Responsible-Changed-Why:  
Looks ok, please commit (PORTREVISION bump required too). 


http://www.freebsd.org/cgi/query-pr.cgi?pr=138540 
Responsible-Changed-From-To: freebsd-ports-bugs->avl 
Responsible-Changed-By: avl 
Responsible-Changed-When: Thu Sep 10 08:15:02 UTC 2009 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=138540 
State-Changed-From-To: open->closed 
State-Changed-By: avl 
State-Changed-When: Fri Sep 11 13:42:37 UTC 2009 
State-Changed-Why:  
Committed. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=138540 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/138540: commit references a PR
Date: Fri, 11 Sep 2009 13:42:14 +0000 (UTC)

 avl         2009-09-11 13:41:59 UTC
 
   FreeBSD ports repository
 
   Modified files:
     sysutils/smartmontools Makefile 
   Added files:
     sysutils/smartmontools/files patch-scsiata.cpp 
   Log:
   - Add a patch that makes shure the data buffers used to read smart
     attributes and logs do not straddle page boundaries
   
   PR:             ports/138540
   Submitted by:   Brad Huntting <huntting AT glarp.com>
   Approved by:    tabthorpe, glarkin (mentors, implicit), marck (maintainer)
   
   Revision  Changes    Path
   1.43      +2 -2      ports/sysutils/smartmontools/Makefile
   1.1       +22 -0     ports/sysutils/smartmontools/files/patch-scsiata.cpp (new)
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
