NetBSD Problem Report #56745

From www@netbsd.org  Sun Mar 13 15:13:16 2022
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 455E31A921F
	for <gnats-bugs@gnats.NetBSD.org>; Sun, 13 Mar 2022 15:13:16 +0000 (UTC)
Message-Id: <20220313151314.BFA681A9239@mollari.NetBSD.org>
Date: Sun, 13 Mar 2022 15:13:14 +0000 (UTC)
From: perseant@hhhh.org
Reply-To: perseant@hhhh.org
To: gnats-bugs@NetBSD.org
Subject: ATA bus interrupt handling causes permanent channel freeze
X-Send-Pr-Version: www-1.0

>Number:         56745
>Category:       kern
>Synopsis:       ATA bus interrupt handling causes permanent channel freeze
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Mar 13 15:15:00 +0000 2022
>Closed-Date:    Tue Mar 15 04:43:15 +0000 2022
>Last-Modified:  Tue Mar 15 18:05:01 +0000 2022
>Originator:     Konrad Schroder
>Release:        9.2
>Organization:
University of Washington
>Environment:
NetBSD apu1c.bastion.coral.washington.edu 9.2_STABLE NetBSD 9.2_STABLE (APU1C) #24: Sat Mar 12 21:45:40 PST 2022  root@backup.coral.washington.edu:/backups/ovar/src-9/sys/arch/i386/compile/obj/APU1C i386

>Description:
When a read error occurs (and possibly at other times), ata_thread_run can be called twice with flags=0 (wake up thread, do not wait) before the worker thread runs.  This results in an extra freeze because the second wakeup is not accounted.  In a kernel with

options ATADEBUG
options ATADEBUG_WD_MASK=0x38
options ATADEBUG_MASK=0x38

this manifests as

[ 11284.1587904] ata_channel_freeze_locked(chp=0xc3cf0120) -> 1
[ 11284.1787594] ata_channel_thaw_locked(chp=0xc3cf0120) -> 0
[ 11284.1787594] ata_thread_run flags 0x0 ch_flags 0x0 type 0x8000 arg 0x481
[ 11284.1787594] ata_channel_freeze_locked(chp=0xc3cf0120) -> 1                         -- interrupt is over, channel has flags 0x8000
[ 11284.2252056] ata_channel_freeze_locked(chp=0xc3cf0120) -> 2
[ 11284.2371669] ata_channel_thaw_locked(chp=0xc3cf0120) -> 1
[ 11284.2371669] ata_thread_run flags 0x0 ch_flags 0x8000 type 0x8000 arg 0x8451
[ 11284.2371669] ata_channel_freeze_locked(chp=0xc3cf0120) -> 2                         -- this extra freeze will never be released
...
[ 11284.3258549] wd0e: error reading fsbn 2117888 of 2117888-2117951 (wd0 bn 10506464; cn 10423 tn 1 sn 17), xfer 340, retry 0
[ 11284.3258549] wd0: (aborted command, interface CRC error)

At this point wd0 effectively no longer functions.

>How-To-Repeat:
Get a computer with a flaky wd and exercise it.  There may be other requirements to ensure that you get two interrupts before the thread runs, but I can trigger it easily on an APU1C.
>Fix:
I'll commit this once I'm done testing in -current (today or tomorrow):

--- sys/dev/ata/ata.c   25 May 2019 16:30:18 -0000      1.149
+++ sys/dev/ata/ata.c   13 Mar 2022 05:36:15 -0000
@@ -1588,14 +1625,16 @@
                 * Block execution of other commands while reset is scheduled
                 * to a thread.
                 */
-               ata_channel_freeze_locked(chp);
-               chp->ch_flags |= type;
+               if (!(chp->ch_flags & type)) {
+                       ata_channel_freeze_locked(chp);
+                       chp->ch_flags |= type;
+               }

                cv_signal(&chp->ch_thr_idle);
                return;
        }

        /* Block execution of other commands during reset */
        ata_channel_freeze_locked(chp);

        /*

>Release-Note:

>Audit-Trail:

From: "Konrad Schroder" <perseant@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/56745 CVS commit: src/sys/dev/ata
Date: Mon, 14 Mar 2022 22:15:51 +0000

 Module Name:	src
 Committed By:	perseant
 Date:		Mon Mar 14 22:15:51 UTC 2022

 Modified Files:
 	src/sys/dev/ata: ata.c

 Log Message:
 Avoid an unaccounted extra channel freeze, if a reset is requested
 more than once before the thread services the request.  Closes PR#56745.


 To generate a diff of this commit:
 cvs rdiff -u -r1.166 -r1.167 src/sys/dev/ata/ata.c

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

State-Changed-From-To: open->closed
State-Changed-By: perseant@NetBSD.org
State-Changed-When: Tue, 15 Mar 2022 04:43:15 +0000
State-Changed-Why:
Applied patch


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/56745 CVS commit: [netbsd-9] src/sys/dev/ata
Date: Tue, 15 Mar 2022 18:00:27 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Tue Mar 15 18:00:27 UTC 2022

 Modified Files:
 	src/sys/dev/ata [netbsd-9]: ata.c

 Log Message:
 Pull up following revision(s) (requested by perseant in ticket #1435):

 	sys/dev/ata/ata.c: revision 1.167

 Avoid an unaccounted extra channel freeze, if a reset is requested
 more than once before the thread services the request. Closes PR#56745.


 To generate a diff of this commit:
 cvs rdiff -u -r1.149 -r1.149.2.1 src/sys/dev/ata/ata.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.