From owner-freebsd-scsi@FreeBSD.ORG Tue Mar 22 16:53:09 2005 Return-Path: Delivered-To: freebsd-scsi@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4B0CB16A4CE for ; Tue, 22 Mar 2005 16:53:09 +0000 (GMT) Received: from nargothrond.kdm.org (nargothrond.kdm.org [70.56.43.81]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9965343D68 for ; Tue, 22 Mar 2005 16:53:08 +0000 (GMT) (envelope-from ken@nargothrond.kdm.org) Received: from nargothrond.kdm.org (localhost [127.0.0.1]) by nargothrond.kdm.org (8.12.11/8.12.11) with ESMTP id j2MGqpKY026155; Tue, 22 Mar 2005 09:52:51 -0700 (MST) (envelope-from ken@nargothrond.kdm.org) Received: (from ken@localhost) by nargothrond.kdm.org (8.12.11/8.12.5/Submit) id j2MGqpIi026154; Tue, 22 Mar 2005 09:52:51 -0700 (MST) (envelope-from ken) Date: Tue, 22 Mar 2005 09:52:51 -0700 From: "Kenneth D. Merry" To: Henry Miller Message-ID: <20050322165251.GA26122@nargothrond.kdm.org> References: <380-220053222163355859@blackhole.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <380-220053222163355859@blackhole.com> User-Agent: Mutt/1.4.2i X-Virus-Scanned: ClamAV 0.83/779/Tue Mar 22 05:34:41 2005 on nargothrond.kdm.org X-Virus-Status: Clean cc: freebsd-scsi@freebsd.org Subject: Re: scsi_ch issues X-BeenThere: freebsd-scsi@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: SCSI subsystem List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Mar 2005 16:53:09 -0000 On Tue, Mar 22, 2005 at 10:33:55 -0600, Henry Miller wrote: > > I posted a summery of this to -questions earlier this morning (you > can read it there if you want background), I've dug into it more, and > I think there is a bug in > cam/scsi/scsi_ch.c > function chgetelemstatus. > > The short summery is my tape changer says that PVOLTAG in pg_hdr is > FALSE, (or zeroed latter) in the first request of > scsi_read_element_status() (which freeBSD uses only to get the length > of the data) on one of my changers, and thus chio(1) will not show > the bar code label. pg_hdr is not updated to reflect the location > of result of the second call, when this flag is set. Worse, it looks > like the results of the first call is a dead pointer by the time it > checks anyway. Unless free/malloc work different in the kernel from > userland this is a problem. > > I've sniped out a lot of extra code so you can see what I mean. > > > data = (caddr_t)malloc(1024, M_DEVBUF, M_WAITOK); > --- Fill data to get size > pg_hdr = \* data + some offset *\ > /* > * Reallocate storage for descriptors and get them from the > * device. > */ > free(data, M_DEVBUF); > data = (caddr_t)malloc(size, M_DEVBUF, M_WAITOK); > --- Fill data > copy_element_status(softc, pg_hdr->flags, desc, ces); > > Note that pg_hdr is not valid at this point anyway. Yes, that looks like a problem. > This more or less happens in 4.x, 5.x and current if I read the code > correctly. It hasn't changed in a while, so I'm sure it's the same in every branch. > Can someone who knows kernel code better than I look at this. > Should I send a pr? > > Here is a patch against 4.9 (where I first found this problem) that > might help to understand the fix. I think it needs to be ported to > all versions. (and perhaps netbsd if there is where we get the > code?) > > > *** scsi_ch.c.old Tue Mar 22 11:16:15 2005 > --- scsi_ch.c Tue Mar 22 11:09:13 2005 > *************** > *** 1184,1189 **** > --- 1184,1192 ---- > * Fill in the user status array. > */ > st_hdr = (struct read_element_status_header *)data; > + pg_hdr = (struct read_element_status_page_header > *)((uintptr_t)st_hdr > + > + sizeof(struct read_element_status_header)); > + > avail = scsi_2btoul(st_hdr->count); > > if (avail != cesr->cesr_element_count) { > When you apply the above patch, does everything work as expected? If so, I can check in the patch. (It looks correct.) If not, we'll need to do some more debugging to track down the problem. Ken -- Kenneth Merry ken@kdm.org