From nobody Mon Mar 18 15:53:22 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 4TyzsZ51txz5F07y; Mon, 18 Mar 2024 15:53:22 +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 4TyzsZ21Tdz4cfT; Mon, 18 Mar 2024 15:53:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1710777202; 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=WW/DDlmXtZHPTmJ4G1SLgwuHKUlAsF9rIfYJmMNRR/k=; b=eYiMCJ7aW6TVu+JzkwxD3YgIr6Dl+IIfBPfe9nBuxJy/r3vAcdDUMKYBFKP9iyN861IQCR ptoj2+DtTko1y2wEVlCwFosUlLIkFsbBhue958VOszihBiwbY3FgqihH6XtU6wrFN1ayG4 KZxYzgxMM4itXM9TXpG75GmarMkdPyKncTNJzVz5GimXCBG+XCIq2CWIsIQ8mwva/Qz/7D LHVPIXqXOZH8mJIGbke9MTPhmDgKqMyPu8NXg+htUqLPFzYHLhqi4tUPF2o3IXxQ97Zq8+ aDIZjBkyUJOAxYLMaW7zoGpy8TZDrlmvRNtwdcEZdf+JbSeX+kAPpNfnQuq5LQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1710777202; a=rsa-sha256; cv=none; b=nqWu6gPkrVO8st3P8x+iCOurhoTfW1i1qCrCkcRLnhoD90ZccIRWb52iiQlAikvhNbN7DF iEr/ZnzkXwWieuwN5uR0m9AH5FamEMooyqXThtBEDUMlVhphZcPfZW+xmImT1QrWIbWHfg WnWhYmzQIiqADh8dEq4fSosYgHaDa/TI8jNyv8vNDUzFiy14cdcRMSKdg9k/HkKd0vbp0/ Est4gPK+9Hj/jU6Iw8oCsPx2Ub5fyLJ7AZXNS+hNxIVIQj3idrzEGFdG9XrmNOREDGyjdW AOXzWuoaKoJIqByeFWcFswMku0ubqYu7Mbgem8AtyutIhDB31kfqDB2nGl0t2w== 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=1710777202; 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=WW/DDlmXtZHPTmJ4G1SLgwuHKUlAsF9rIfYJmMNRR/k=; b=eEDWLdse21h46dkkWH/a3GckLMdw/NeQ+DpWT1I8lwbg4Pr0N565N19Hre/363Vby5yYkr VGCsa5qMeA+/JB4Uzu2ULdQzNU10N1B7WU+ltW+rLYfYlEnDxa51xCZE6OonQzVrXYM0ue V3gjKf8nKFjvfOP83j6Yajjr5VE5kNzZF9ET7RsE/Pv0mkJtplrwKr/Q+XT/vxSUPtGs9f FqER5FnB9eMYPjb66fAo2PQ5kQZsO2MsvYp/fzkuPos8dTfcpc7BwlOByoQc+gP8ZJYsHD +PdOSdDogun6YbByGxWQXmywN+aAS9T3Zb3ot1NTeuvQDAcNg+Mi1qsbi6pHFg== 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 4TyzsZ1dsKzSjb; Mon, 18 Mar 2024 15:53:22 +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 42IFrMj3001351; Mon, 18 Mar 2024 15:53:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 42IFrMc5001348; Mon, 18 Mar 2024 15:53:22 GMT (envelope-from git) Date: Mon, 18 Mar 2024 15:53:22 GMT Message-Id: <202403181553.42IFrMc5001348@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: 160788caa3c9 - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 160788caa3c9cac5f21d70962ce330e18a4fe9d5 Auto-Submitted: auto-generated The branch stable/14 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=160788caa3c9cac5f21d70962ce330e18a4fe9d5 commit 160788caa3c9cac5f21d70962ce330e18a4fe9d5 Author: Kyle Evans AuthorDate: 2024-03-05 04:14:07 +0000 Commit: Kyle Evans CommitDate: 2024-03-18 15:52:58 +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 (cherry picked from commit 47ad4f2d45e406c6316909bc12bc760b2fdd6afb) --- 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 75b81457402b..4c1936edc301 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -769,7 +769,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 d0d0b1efa354..f3fd39079a82 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -579,7 +579,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 c7c2e6544902..85b2214eaeb9 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -791,7 +791,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 */