NetBSD Problem Report #38923

From martin@duskware.de  Mon Jun  9 19:57:47 2008
Return-Path: <martin@duskware.de>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by narn.NetBSD.org (Postfix) with ESMTP id 5CE3063B8BC
	for <gnats-bugs@gnats.NetBSD.org>; Mon,  9 Jun 2008 19:57:47 +0000 (UTC)
Message-Id: <20080609195745.1D9D633ABC@mail.duskware.de>
Date: Mon,  9 Jun 2008 21:57:45 +0200 (CEST)
From: martin@duskware.de
Reply-To: martin@duskware.de
To: gnats-bugs@gnats.NetBSD.org
Subject: ATAIOCCOMMAND ioctl does not work
X-Send-Pr-Version: 3.95

>Number:         38923
>Category:       kern
>Synopsis:       ATAIOCCOMMAND ioctl does not work
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jun 09 20:00:00 +0000 2008
>Closed-Date:    Tue Jun 17 15:03:35 +0000 2008
>Last-Modified:  Tue Jun 17 15:05:02 +0000 2008
>Originator:     Martin Husemann
>Release:        NetBSD 4.99.64
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD night-porter.duskware.de 4.99.64 NetBSD 4.99.64 (PORTER) #45: Mon Jun 9 17:20:17 CEST 2008 martin@night-porter.duskware.de:/usr/src/sys/arch/i386/compile/PORTER i386
Architecture: i386
Machine: i386
>Description:

The ATAIOCCOMMAND ioctl never returns, the process hangs unkillable. This
was first noticed with pkgsrc smartmontools, but can easily reproduced
with in-tree tools

>How-To-Repeat:

atactl wd0 identify

>Fix:

Fix by reinoud@NetBSD.org:

Problem started with the kern/vfs_bio.c version 1.201 to 1.202 patch. All
callers of buf_init() are now returned a buffer with buf->b_cflags = BC_BUSY.

Fix dev/ata/wd.c with this patch:

---------------------
RCS file: /cvsroot/src/sys/dev/ata/wd.c,v
retrieving revision 1.363
diff -u -p -r1.363 wd.c
--- dev/ata/wd.c	8 Jun 2008 18:34:06 -0000	1.363
+++ dev/ata/wd.c	10 Jun 2008 15:54:16 -0000
@@ -1962,6 +1962,7 @@ wi_get(void)

 	wi = malloc(sizeof(struct wd_ioctl), M_TEMP, M_WAITOK|M_ZERO);
 	buf_init(&wi->wi_bp);
+	wi->wi_bp.b_cflags = 0;	/* XXX fix PR 38923 */
 	s = splbio();
 	LIST_INSERT_HEAD(&wi_head, wi, wi_list);
 	splx(s);
---------------------

tested this patch with a similar patch to dev/scsipi/scsipi_ioctl.c

---------------------
RCS file: /cvsroot/src/sys/dev/scsipi/scsipi_ioctl.c,v
retrieving revision 1.65
diff -u -p -r1.65 scsipi_ioctl.c
--- dev/scsipi/scsipi_ioctl.c	28 Apr 2008 20:23:58 -0000	1.65
+++ dev/scsipi/scsipi_ioctl.c	10 Jun 2008 15:56:09 -0000
@@ -79,6 +79,7 @@ si_get(void)

 	si = malloc(sizeof(struct scsi_ioctl), M_TEMP, M_WAITOK|M_ZERO);
 	buf_init(&si->si_bp);
+	si->si_bp.b_cflags = 0;
 	s = splbio();
 	LIST_INSERT_HEAD(&si_head, si, si_list);
 	splx(s);
---------------------


>Release-Note:

>Audit-Trail:

From: Reinoud Zandijk <reinoud@NetBSD.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: kern/38923 ATAIOCCOMMAND ioctl does not work
Date: Tue, 10 Jun 2008 18:21:30 +0200

 Provided fix with edit-pr (sorry about that);

 summary: kern/vfs_bio.c revision 2.201 to 2.202 caused the problem for 
 buf_init() now sets b_cflags to BC_BUSY; patch explicitly sets it to zero 
 again in wi_get().

 Similar patch also fixes dev/scsipi/cd.c's si_get().


From: Michael van Elst <mlelstv@serpens.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: kern/38923: ATAIOCCOMMAND ioctl does not work
Date: Tue, 17 Jun 2008 13:59:38 +0200

 The ioctl hanging comes from physio waiting for the buffer
 to become "un-busy". Obviously this will never become true
 when the buffer isn't used yet.

 physio() is called with a buffer here:

 dev/qbus/qd.c
 dev/gpib/mt.c
 arch/hp300/dev/mt.c
 dev/ata/wd.c
 dev/scsipi/scsipi_ioctl.c

 dev/qbus/qd.c looks broken..

 dev/gpib/mt.c and
 arch/hp300/dev/mt.c don't use buf_init() but poke the structure.
 They use BC_BUSY to reserve a single command buffer that is used
 synchronously by the read/write functions and asynchronously by
 the strategy functions.

 dev/ata/wd.c and
 dev/scsipi/scsipi_ioctl.c malloc buffers and use buf_init().
 Reserving a buffer doesn't make sense, as each request uses
 its private buffer.

 When physio() isn't called with a buffer, as in most device drivers,
 then it uses getphysbuf() -> getiobuf() to allocate a private one
 from the biopl pool. getiobuf uses buf_init() which now sets BC_BUSY
 and getphysbuf() sets BC_BUSY again.


 buf_init() is called in getnewbuf() to return a fresh buffer
 from the bufpl pool. If allocating a fresh buffer is not wanted
 then a buffer is fetched from the free list and marked BC_BUSY.

 buf_init() is called in
 uvm/uvm_swap.c
 dev/ccd.c
 dev/ata/ld_ataraid.c
 dev/vnd.c
 only to get the cflags overwritten with flags from another buffer.

 buf_init() is called in
 dev/fss.c
 to get most data overwritten, maybe the cflags were forgotten.
 I'm not sure wether a busy buffer breaks fss.

 buf_init() is called in
 arch/xen/xen/xbdback.c
 arch/xen/xen/xbdback_xenbus.c
 after allocating a buffer from a pool, when that buffer is
 used, it gets overwritten, in particular cflags is set to 0.

 buf_init() is called from
 fs/udf/udf_strat_rmw.c
 and then b_cflags is set to BC_BUSY /* needed? */
 However, that buffer isn't used, but split into nested buffers.
 nestiobuf_setup() does set BC_BUSY on the nested buffer.


 Apparently buf_init() isn't supposed to declare a buffer busy
 and doing so only saves to mark the buffer busy in getnewbuf().
 E.g.:


 Index: kern/vfs_bio.c
 ===================================================================
 RCS file: /cvsroot/src/sys/kern/vfs_bio.c,v
 retrieving revision 1.203
 diff -u -r1.203 vfs_bio.c
 --- kern/vfs_bio.c	16 Jun 2008 09:47:55 -0000	1.203
 +++ kern/vfs_bio.c	17 Jun 2008 11:57:08 -0000
 @@ -1301,6 +1301,8 @@
  		if (bp != NULL) {
  			memset((char *)bp, 0, sizeof(*bp));
  			buf_init(bp);
 +			/* Buffer is busy now. */
 +			SET(bp->b_cflags, BC_BUSY);
  			mutex_enter(&bufcache_lock);
  #if defined(DIAGNOSTIC)
  			bp->b_freelistindex = -1;
 @@ -2017,7 +2019,7 @@
  	bp->b_dev = NODEV;
  	bp->b_error = 0;
  	bp->b_flags = 0;
 -	bp->b_cflags = BC_BUSY;
 +	bp->b_cflags = 0;
  	bp->b_oflags = 0;
  	bp->b_objlock = &buffer_lock;
  	bp->b_iodone = NULL;


 -- 
                                 Michael van Elst
 Internet: mlelstv@serpens.de
                                 "A potential Snark may lurk in every tree."

State-Changed-From-To: open->closed
State-Changed-By: reinoud@NetBSD.org
State-Changed-When: Tue, 17 Jun 2008 15:03:35 +0000
State-Changed-Why:
Has been fixed by a modification and extension of the last supplied patch.

Thanks mlelstv :)


From: Reinoud Zandijk <reinoud@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/38923 CVS commit: src/sys
Date: Tue, 17 Jun 2008 14:53:11 +0000 (UTC)

 Module Name:	src
 Committed By:	reinoud
 Date:		Tue Jun 17 14:53:11 UTC 2008

 Modified Files:
 	src/sys/dev: fss.c
 	src/sys/dev/ata: ata_raid.c
 	src/sys/dev/dkwedge: dk.c
 	src/sys/dev/raidframe: rf_diskqueue.c
 	src/sys/kern: vfs_bio.c
 	src/sys/ufs/ffs: ffs_snapshot.c

 Log Message:
 Mark a buffer `busy` in getnewbuf() when it came from the pool_cache since
 its not on a free list.

 Also change buf_init() to not automatically mark buffers `busy' since this
 only makes sense for bufcache buffers.

 Mark all buf_init'd buffers 'busy' on the places where they ought to be
 flagged as such to not confuse the buffer cache.

 Fixes PR 38923.


 To generate a diff of this commit:
 cvs rdiff -r1.45 -r1.46 src/sys/dev/fss.c
 cvs rdiff -r1.28 -r1.29 src/sys/dev/ata/ata_raid.c
 cvs rdiff -r1.41 -r1.42 src/sys/dev/dkwedge/dk.c
 cvs rdiff -r1.50 -r1.51 src/sys/dev/raidframe/rf_diskqueue.c
 cvs rdiff -r1.203 -r1.204 src/sys/kern/vfs_bio.c
 cvs rdiff -r1.69 -r1.70 src/sys/ufs/ffs/ffs_snapshot.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.