From nobody Tue Mar 05 05:44:17 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Tpkyp3N82z5BsK4; Tue, 5 Mar 2024 05:44:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Tpkyp0J4Sz3xg0; Tue, 5 Mar 2024 05:44:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709617458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8UQ/jEIZ/2Qn0OjQz86pr/lrFyV4wgIEyT7KPKT4aag=; b=imCKpMIDLHZVK3UrqHU8/K9iEnFloCkqCbPYdxsSNFy8d2pYaJX8RqkXwB9wMsFtiBpkQX pTaFmpVEAN2bzemtAnd16JNz72NdlGqKeWgVdsyV7AhI7abO4/T7AOMVztI++605g+ASpu c43WMcmDzxLG/nlccQmgomt7AnTxu1pMhul5D8k22dgRvm/hNrJt79FrIjQP8ATZTT9gJd QcVX4JShEiN+LI6GFHfGvFcOKcfi41XUQgDbbRuotvdrnW8RMzKVB1iaXOJqyfXg8uHB7D JAw7to7elYHc4AjWuhYXhWwZWskW6Qh79CbuJEzAuCSq+7qh+dHpmS2XOEH0vQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1709617458; a=rsa-sha256; cv=none; b=VAGnTNSVUwjblOdS8NthHmWIxOQXUzkjT9za0H2c5xRG4JulNtuUeK53ixF2FiEa4e021D mwfZb14PUDByL9PPaeqfU40o+v8Hbvyz9MVD1x8E5B8H9rRrLQ56iLPRL2YtfUrl5whaEX kcibDmxNn+SZLDBVy7WDI/hlzOKb2s7IP/088F90Ymuab80SD3mCjhBp2F/Un1CAiZx26H EHbyWKch8d8TLuDs3KbtJUTGYthvU39edehqezqwTTktit6D4C0HNhHfO8ZUEQIb430D8K ZCYeoTaLfKuLF14z6l5lJVLSRT3E+AUd9jQF6tudMy8CYzVOcbBdLZcFN/+aaw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709617458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8UQ/jEIZ/2Qn0OjQz86pr/lrFyV4wgIEyT7KPKT4aag=; b=Dk3sb79KkqR2OlDc4o5y0sRGamePxLRXMUcIJQuY10yzh/qBZspzl5AAej1oCA3mERCUTh xaoRp47CCsm1nQwtUDo6VGKioyIkS2rkeWs2X/Qi1mfWFRr/ewDVFLf7OhvWoCFVo5+TQ2 PtrT8XwsnL78aK2wGcfyNZAoT54mu/KNXjegmR6/z0I2oOx3bRNHvl+vnMhxTZrh41IqNc 4WWQRLAdgXQ8LIxUCy72vmuIvlmSgFp/INo52NTeCAf8R03dzY1j/3IOJAg73giaY5SKW+ 2Wypb+/GUqYPZa0TfaT4mBwseeUcIU+ni/bx+aAVzg/DqbbZERKNUPQcUzBaRg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Tpkyn5SZnztT9; Tue, 5 Mar 2024 05:44:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 4255iHnY011517; Tue, 5 Mar 2024 05:44:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4255iHCP011514; Tue, 5 Mar 2024 05:44:17 GMT (envelope-from git) Date: Tue, 5 Mar 2024 05:44:17 GMT Message-Id: <202403050544.4255iHCP011514@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 47ad4f2d45e4 - main - ktrace: log genio events on failed write List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 47ad4f2d45e406c6316909bc12bc760b2fdd6afb Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=47ad4f2d45e406c6316909bc12bc760b2fdd6afb commit 47ad4f2d45e406c6316909bc12bc760b2fdd6afb Author: Kyle Evans AuthorDate: 2024-03-05 04:14:07 +0000 Commit: Kyle Evans CommitDate: 2024-03-05 05:44:09 +0000 ktrace: log genio events on failed write Visibility into the contents of the buffer when a write(2) has failed can be immensely useful in debugging IPC issues -- pushing this to discuss the idea, or maybe an alternative where we can set a flag like KTRFAC_ERRIO to enable it. When a genio event is potentially raised after an error, currently we'll just free the uio and return. However, such data can be useful when debugging communication between processes to, e.g., understand what the remote side should have grabbed before closing a pipe. Tap out the entire buffer on failure rather than simply discarding it. Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D43799 --- sys/kern/kern_ktrace.c | 2 +- sys/kern/sys_generic.c | 3 ++- sys/kern/uipc_syscalls.c | 3 ++- sys/netinet/sctp_syscalls.c | 6 ++++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index 877a25ffa4cd..6ace3ea52c64 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -767,7 +767,7 @@ ktrgenio(int fd, enum uio_rw rw, struct uio *uio, int error) int datalen; char *buf; - if (error) { + if (error != 0 && (rw == UIO_READ || error == EFAULT)) { freeuio(uio); return; } diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index f6190c3fb05f..b926f98892a5 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -577,7 +577,8 @@ dofilewrite(struct thread *td, int fd, struct file *fp, struct uio *auio, cnt -= auio->uio_resid; #ifdef KTRACE if (ktruio != NULL) { - ktruio->uio_resid = cnt; + if (error == 0) + ktruio->uio_resid = cnt; ktrgenio(fd, UIO_WRITE, ktruio, error); } #endif diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index dce0ab9b53d4..b2d03d932b99 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -772,7 +772,8 @@ kern_sendit(struct thread *td, int s, struct msghdr *mp, int flags, td->td_retval[0] = len - auio.uio_resid; #ifdef KTRACE if (ktruio != NULL) { - ktruio->uio_resid = td->td_retval[0]; + if (error == 0) + ktruio->uio_resid = td->td_retval[0]; ktrgenio(s, UIO_WRITE, ktruio, error); } #endif diff --git a/sys/netinet/sctp_syscalls.c b/sys/netinet/sctp_syscalls.c index a5e4fa8f9603..d67e260b6f99 100644 --- a/sys/netinet/sctp_syscalls.c +++ b/sys/netinet/sctp_syscalls.c @@ -290,7 +290,8 @@ sys_sctp_generic_sendmsg(struct thread *td, struct sctp_generic_sendmsg_args *ua td->td_retval[0] = len - auio.uio_resid; #ifdef KTRACE if (ktruio != NULL) { - ktruio->uio_resid = td->td_retval[0]; + if (error == 0) + ktruio->uio_resid = td->td_retval[0]; ktrgenio(uap->sd, UIO_WRITE, ktruio, error); } #endif /* KTRACE */ @@ -404,7 +405,8 @@ sys_sctp_generic_sendmsg_iov(struct thread *td, struct sctp_generic_sendmsg_iov_ td->td_retval[0] = len - auio.uio_resid; #ifdef KTRACE if (ktruio != NULL) { - ktruio->uio_resid = td->td_retval[0]; + if (error == 0) + ktruio->uio_resid = td->td_retval[0]; ktrgenio(uap->sd, UIO_WRITE, ktruio, error); } #endif /* KTRACE */