NetBSD Problem Report #58167

From www@netbsd.org  Wed Apr 17 18:46:52 2024
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 16E541A9238
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 17 Apr 2024 18:46:52 +0000 (UTC)
Message-Id: <20240417184650.D56611A923A@mollari.NetBSD.org>
Date: Wed, 17 Apr 2024 18:46:50 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: unnecessary mutex_tryenter in tap(4)
X-Send-Pr-Version: www-1.0

>Number:         58167
>Category:       kern
>Synopsis:       unnecessary mutex_tryenter in tap(4)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Apr 17 18:50:01 +0000 2024
>Last-Modified:  Wed Apr 17 18:55:03 +0000 2024
>Originator:     Taylor R Campbell
>Release:        current, 10, 9, 8, ...
>Organization:
The TryTAP Foundation
>Environment:
>Description:
    875 	/* In the TAP_NBIO case, we have to make sure we won't be sleeping */
    876 	if ((sc->sc_flags & TAP_NBIO) != 0) {
    877 		if (!mutex_tryenter(&sc->sc_lock))
    878 			return EWOULDBLOCK;
    879 	} else
    880 		mutex_enter(&sc->sc_lock);

https://nxr.netbsd.org/xref/src/sys/net/if_tap.c#875

This lock is only used to serialize access to the packet queue, not to serialize operations that sleep for I/O or anything -- it's a spin lock anyway (though I'm not sure there's any reason for it to be).  So there is no need to make tap_dev_read flakier and harder to understand by using mutex_tryenter.
>How-To-Repeat:
code inspection
>Fix:
just use mutex_enter unconditionally

>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58167 CVS commit: src/sys/net
Date: Wed, 17 Apr 2024 18:52:55 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Wed Apr 17 18:52:54 UTC 2024

 Modified Files:
 	src/sys/net: if_tap.c

 Log Message:
 tap(4): Just use mutex_enter.

 PR kern/58167


 To generate a diff of this commit:
 cvs rdiff -u -r1.131 -r1.132 src/sys/net/if_tap.c

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

NetBSD Home
NetBSD PR Database Search

(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-2024 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.