NetBSD Problem Report #58378

From www@netbsd.org  Sat Jun 29 01:47:30 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)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits)
	 client-signature RSA-PSS (2048 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 422F01A923A
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 29 Jun 2024 01:47:30 +0000 (UTC)
Message-Id: <20240629014729.156DC1A923C@mollari.NetBSD.org>
Date: Sat, 29 Jun 2024 01:47:29 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: Kernel error code origination lacks dtrace probes
X-Send-Pr-Version: www-1.0

>Number:         58378
>Category:       kern
>Synopsis:       Kernel error code origination lacks dtrace probes
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jun 29 01:50:00 +0000 2024
>Last-Modified:  Sat Jun 29 13:05:12 +0000 2024
>Originator:     Taylor R Campbell
>Release:        current, 10, 9, ...
>Organization:
The ENETBSD Notfoundation
>Environment:
>Description:
When some deeply nested kernel subroutine decides it's time to return EINVAL, and EINVAL comes flying back down the stack and out of a syscall to return to userland, even with the help of ktrace to see syscall arguments and I/O it can be an arduous task to statically analyze code paths to identify which one led to EINVAL.

It should be possible to set a dtrace probe on the origination of EINVAL, e.g. to print a stack trace.
>How-To-Repeat:
try to figure out where EINVAL or ENOBUFS or what have you came from
>Fix:
Change all instances of

        return EINVAL;

to

        return SET_ERROR(EINVAL);

throughout the kernel, using the dtrace SET_ERROR probe.

May require moving SET_ERROR from external/cddl/osnet/ to somewhere under sys/.

>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58378 CVS commit: src/sys/sys
Date: Sat, 29 Jun 2024 03:01:29 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sat Jun 29 03:01:29 UTC 2024

 Modified Files:
 	src/sys/sys: sdt.h

 Log Message:
 sys/sdt.h: Make SDT_PROBE* work as expressions.

 This way, they can be used inside other expressions with the comma
 operator, such as in the SET_ERROR macro.

 In preparation for PR kern/58378.


 To generate a diff of this commit:
 cvs rdiff -u -r1.22 -r1.23 src/sys/sys/sdt.h

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

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58378 CVS commit: src
Date: Sat, 29 Jun 2024 13:03:02 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sat Jun 29 13:03:02 UTC 2024

 Modified Files:
 	src/external/cddl/osnet/sys/kern: opensolaris.c
 	src/external/cddl/osnet/sys/sys: sdt.h
 	src/sys/kern: kern_sdt.c
 	src/sys/sys: sdt.h

 Log Message:
 sys/sdt.h: Define SET_ERROR(err) macro in sys/sdt.h.

 err must be an errno(3) EFOO constant.  SET_ERROR(err) yields err,
 with a dtrace probe sdt:::set-error(err), so you have a better chance
 of finding where EFOO first turned up in some twisty maze of kernel
 logic.

 Don't limit this to the opensolaris source compat layer -- this will
 enable us to use it throughout the regular kernel sources, not just
 zfs.

 PR kern/58378

 XXX kernel revbump -- moves sdt:::set-error probe symbol definition
 from solaris.kmod to main netbsd kernel


 To generate a diff of this commit:
 cvs rdiff -u -r1.4 -r1.5 src/external/cddl/osnet/sys/kern/opensolaris.c
 cvs rdiff -u -r1.9 -r1.10 src/external/cddl/osnet/sys/sys/sdt.h
 cvs rdiff -u -r1.3 -r1.4 src/sys/kern/kern_sdt.c
 cvs rdiff -u -r1.23 -r1.24 src/sys/sys/sdt.h

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

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/58378 CVS commit: src/sys/sys
Date: Sat, 29 Jun 2024 13:04:20 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sat Jun 29 13:04:20 UTC 2024

 Modified Files:
 	src/sys/sys: param.h

 Log Message:
 Welcome to NetBSD 10.99.11, courtesy of sdt:::set-error probe.

 PR kern/58378

 (and also if_stat..._ref API change, PR kern/58377)


 To generate a diff of this commit:
 cvs rdiff -u -r1.733 -r1.734 src/sys/sys/param.h

 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.