NetBSD Problem Report #55906

From khorben@defora.org  Sun Jan  3 10:44:56 2021
Return-Path: <khorben@defora.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 7202F1A9217
	for <gnats-bugs@gnats.NetBSD.org>; Sun,  3 Jan 2021 10:44:56 +0000 (UTC)
Message-Id: <20210103103530.2B4E11B983@kwarx.station.defora>
Date: Sun,  3 Jan 2021 11:35:30 +0100 (CET)
From: Pierre Pronchery <khorben@defora.org>
To: gnats-bugs@NetBSD.org
Subject: Kernel panic while loading firmware when booting netbsd-9
X-Send-Pr-Version: 3.95

>Number:         55906
>Category:       kern
>Synopsis:       Call to workqueue_enqueue() for aiodoned performed before initialisation
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          needs-pullups
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jan 03 10:45:00 +0000 2021
>Closed-Date:    
>Last-Modified:  Sun Jan 03 23:37:19 +0000 2021
>Originator:     Pierre Pronchery
>Release:        NetBSD 9.1_STABLE
>Organization:
The DeforaOS Project
The NetBSD Foundation
>Environment:
System: NetBSD localhost 9.1_STABLE NetBSD 9.1_STABLE (GENERIC_KASLR) #14: Mon Dec 28 05:45:36 CET 2020 khorben@localhost:/sys/arch/amd64/compile/GENERIC_KASLR amd64
Architecture: x86_64
Machine: amd64
>Description:
On a system booting GENERIC_KASLR together with root on cgd(4), and
loading firmware for the graphics card for the console, the kernel
panics with:

> kernel: page fault trap, code=0
> Stopped in pid 0.100 (system) at netbsd:workqueue_enqueue+0x16: testb $0x2,10(%rdi)
> workqueue_enqueue() at netbsd:workqueue_enqueue+0x16
> biodone2() at netbsd:biodone2+0xd8

The graphics card in this case is an ATI Radeon HD4870 (RV770) using
radeondrmkms(4).

After debugging I figured the culprit was not in the DRM2 code as
initially suspected, but with the workqueue for aiodoned, in the
kernel's main() routine.

>How-To-Repeat:
Boot NetBSD 9 on a system loading multiple or relatively big (?)
firmware files before running init(8).
>Fix:
The patch I sent on the tech-kern@ mailing-list does fix this issue and
seems to be correct, as confirmed by Chuck Silvers (chs@). I have
reproduced it here below.

I believe it is only relevant for the netbsd-9 branch, as it was fixed
differently in -current. It should therefore be applied there, but there
cannot be a corresponding commit in -current anymore to be pulled up.

I have not looked at the netbsd-8 branch.

The patch initialises the aiodoned queue before mounting the root file
system, as follows:

diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index bbf418df55ce..0b07c9164ade 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -668,6 +668,11 @@ main(void)
 	cpu_rootconf();
 	cpu_dumpconf();

+	/* Create the aiodone daemon kernel thread. */
+	if (workqueue_create(&uvm.aiodone_queue, "aiodoned",
+	    uvm_aiodone_worker, NULL, PRI_VM, IPL_NONE, WQ_MPSAFE))
+		panic("fork aiodoned");
+
 	/* Mount the root file system. */
 	do {
 		domountroothook(root_device);
@@ -736,11 +741,6 @@ main(void)
 	    NULL, NULL, "ioflush"))
 		panic("fork syncer");

-	/* Create the aiodone daemon kernel thread. */
-	if (workqueue_create(&uvm.aiodone_queue, "aiodoned",
-	    uvm_aiodone_worker, NULL, PRI_VM, IPL_NONE, WQ_MPSAFE))
-		panic("fork aiodoned");
-
 	/* Wait for final configure threads to complete. */
 	config_finalize_mountroot();


>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->pending-pullups
State-Changed-By: khorben@NetBSD.org
State-Changed-When: Sun, 03 Jan 2021 11:18:32 +0000
State-Changed-Why:
pullup-9 #1177


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/55906 CVS commit: [netbsd-9] src/sys/kern
Date: Sun, 3 Jan 2021 12:51:33 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Sun Jan  3 12:51:33 UTC 2021

 Modified Files:
 	src/sys/kern [netbsd-9]: init_main.c

 Log Message:
 Apply patch, requested by khorben in ticket #1177 (issue solved differently
 in -current):

 	sys/kern/init_main.c			(apply patch)

 PR kern/55906: create the aiodone workqueue before running mountroothooks.


 To generate a diff of this commit:
 cvs rdiff -u -r1.504.2.1 -r1.504.2.2 src/sys/kern/init_main.c

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

State-Changed-From-To: pending-pullups->needs-pullups
State-Changed-By: khorben@NetBSD.org
State-Changed-When: Sun, 03 Jan 2021 23:37:19 +0000
State-Changed-Why:
Pull-up to netbsd-9 done (thanks!)
It looks like a pull-up to netbsd-8 is also necessary, but it should be tested first.


>Unformatted:
 Up to and including "Ticket #1160".

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.