NetBSD Problem Report #57229
From buhrow@nfbcal.org Mon Feb 13 17:15:24 2023
Return-Path: <buhrow@nfbcal.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 5340B1A9239
for <gnats-bugs@gnats.NetBSD.org>; Mon, 13 Feb 2023 17:15:24 +0000 (UTC)
Message-Id: <202302131715.31DHFKFY006240@nfbcal.org>
Date: Mon, 13 Feb 2023 09:15:21 -0800 (PST)
From: buhrow@nfbcal.org
Reply-To: buhrow@nfbcal.org
To: gnats-bugs@NetBSD.org
Subject: Fix for devsw_attach
X-Send-Pr-Version: 3.95
>Number: 57229
>Category: kern
>Synopsis: Fix for devsw_attach
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: buhrow
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Feb 13 17:20:00 +0000 2023
>Closed-Date: Tue Feb 14 17:25:27 +0000 2023
>Last-Modified: Tue Feb 14 17:25:27 +0000 2023
>Originator: Brian Buhrow
>Release:
>Organization:
NFB of California
>Environment:
System: NetBSD loth-9.nfbcal.org 9.99.77 NetBSD 9.99.77 (XEN3_DOMU) #0: Wed Jan 13 02:37:15 PST 2021 buhrow@loth-9.nfbcal.org:/usr/local/netbsd/obj-current/sys/arch/amd64/compile/XEN3_DOMU amd64
>Description:
When a device driver calls devsw_attach() it has the option of attaching a block device
structure and a character device structure, or, just the character device structure.
With the existing code, if a driver elects not to attach a block device structure and if it
asks for a major number to be dynamically assigned to its character interface,
that driver will not be able to detach and reattach its character driver interface. This is a very
long standing bug which didn't come to light until we began using loadable kernel modules more
heavily. this patch fixes this problem. With this patch in place, drivers that implement only
a character device interface may detach and reattach that character interface as often as they
like.
>How-To-Repeat:
Try to load a kernel module that implements only a character driver interface, unload it and
then try to load it again. It will not load because devsw_attach() wil return EINVAL.
>Fix:
Index: subr_devsw.c
===================================================================
RCS file: /cvsroot/src/sys/kern/subr_devsw.c,v
retrieving revision 1.49
diff -u -r1.49 subr_devsw.c
--- subr_devsw.c 29 Oct 2022 10:52:36 -0000 1.49
+++ subr_devsw.c 13 Feb 2023 17:03:04 -0000
@@ -1,4 +1,4 @@
-/* $NetBSD$ */
+/* $NetBSD: subr_devsw.c,v 1.49 2022/10/29 10:52:36 riastradh Exp $ */
/*-
* Copyright (c) 2001, 2002, 2007, 2008 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD$");
+__KERNEL_RCSID(0, "$NetBSD: subr_devsw.c,v 1.49 2022/10/29 10:52:36 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_dtrace.h"
@@ -397,7 +397,7 @@
if (conv->d_name == NULL || strcmp(devname, conv->d_name) != 0)
continue;
- if (*bmajor < 0)
+ if ((bdev != NULL) && (*bmajor < 0))
*bmajor = conv->d_bmajor;
if (*cmajor < 0)
*cmajor = conv->d_cmajor;
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: gnats-admin->buhrow
Responsible-Changed-By: buhrow@NetBSD.org
Responsible-Changed-When: Mon, 13 Feb 2023 18:55:47 +0000
Responsible-Changed-Why:
Brian will shepherd this bug to closure.
From: "Brian Buhrow" <buhrow@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/57229 CVS commit: src/sys/kern
Date: Mon, 13 Feb 2023 19:07:14 +0000
Module Name: src
Committed By: buhrow
Date: Mon Feb 13 19:07:14 UTC 2023
Modified Files:
src/sys/kern: subr_devsw.c
Log Message:
When a device driver calls devsw_attach() it has the option of attaching a block device
structure and a character device structure, or, just the character device structure.
With the existing code, if a driver elects not to attach a block device structure and if it
asks for a major number to be dynamically assigned to its character interface,
that driver will not be able to detach and reattach its character driver interface. This is a very
long standing bug which didn't come to light until we began using loadable kernel modules more
heavily. this patch fixes this problem. With this patch in place, drivers that implement only
a character device interface may detach and reattach that character interface as often as they
need to.
Fixes PR kern/57229
To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/kern/subr_devsw.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->pending-pullups
State-Changed-By: buhrow@NetBSD.org
State-Changed-When: Tue, 14 Feb 2023 00:20:06 +0000
State-Changed-Why:
Requested pullup-9#1595 and pullup-10#84
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/57229 CVS commit: [netbsd-10] src/sys/kern
Date: Tue, 14 Feb 2023 16:16:30 +0000
Module Name: src
Committed By: martin
Date: Tue Feb 14 16:16:30 UTC 2023
Modified Files:
src/sys/kern [netbsd-10]: subr_devsw.c
Log Message:
Pull up following revision(s) (requested by buhrow in ticket #84):
sys/kern/subr_devsw.c: revision 1.50
When a device driver calls devsw_attach() it has the option of attaching a block device
structure and a character device structure, or, just the character device structure.
With the existing code, if a driver elects not to attach a block device structure and if it
asks for a major number to be dynamically assigned to its character interface,
that driver will not be able to detach and reattach its character driver interface. This is a very
long standing bug which didn't come to light until we began using loadable kernel modules more
heavily. this patch fixes this problem. With this patch in place, drivers that implement only
a character device interface may detach and reattach that character interface as often as they
need to.
Fixes PR kern/57229
To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.49.2.1 src/sys/kern/subr_devsw.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/57229 CVS commit: [netbsd-9] src/sys/kern
Date: Tue, 14 Feb 2023 16:19:00 +0000
Module Name: src
Committed By: martin
Date: Tue Feb 14 16:19:00 UTC 2023
Modified Files:
src/sys/kern [netbsd-9]: subr_devsw.c
Log Message:
Pull up following revision(s) (requested by buhrow in ticket #1595):
sys/kern/subr_devsw.c: revision 1.50
When a device driver calls devsw_attach() it has the option of attaching a block device
structure and a character device structure, or, just the character device structure.
With the existing code, if a driver elects not to attach a block device structure and if it
asks for a major number to be dynamically assigned to its character interface,
that driver will not be able to detach and reattach its character driver interface. This is a very
long standing bug which didn't come to light until we began using loadable kernel modules more
heavily. this patch fixes this problem. With this patch in place, drivers that implement only
a character device interface may detach and reattach that character interface as often as they
need to.
Fixes PR kern/57229
To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.38.8.1 src/sys/kern/subr_devsw.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->closed
State-Changed-By: buhrow@NetBSD.org
State-Changed-When: Tue, 14 Feb 2023 17:25:27 +0000
State-Changed-Why:
Pullups committed.
>Unformatted:
Confidential: no
Devsw_attach, when called with character interfaces only, prevents detaching and reattaching.
Severity: serious
Priority: medium
Category: kern
Class: sw-bug
Release: NetBSD 9.99.77, but applies to many versions of NetBSD
<Please check that the above is correct for the bug being reported,>
<and append source date of snapshot, if applicable (one line).>
(Contact us)
$NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2023
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.