From nobody Thu Apr 23 15:48:11 2026 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 4g1gV35KP0z6b0Xw for ; Thu, 23 Apr 2026 15:48:11 +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 "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g1gV34gSZz40gS for ; Thu, 23 Apr 2026 15:48:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776959291; 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=z2Cy9dgbtEWeDt7VzgJ+Iho7CHLjxk3oomNz30u3KKQ=; b=nxPpX4jlO47MsoKfvVWtH0QUKtIv6LFgcg5+Eei+F0Ez1aYftVWsvQvQNbvWRRnRiIT0GX 1E3OfLLpf5vhuBThoptPz28vlkpue+uYYSyq/FfXrW6rnpql5B1tg4EQQ23e+99Iiddp2H lrBhn0QThXs86Jbw35Aw7XCuZ/kXUdsKg6pgCctCAMNbdyLxNUP++Wd9/GXAPlCxbj/HOf jRztFtMJiA0hFvt4FZMFpUoGXNL97l+b0LMBLv3GDBeagHCtDnPOfLLberJ8s5VB/neXoK AbnXzB5W8sGA88s+E1tEowAUejPbSxYpR1C0o/S0U3OSOtCiIFTKvDQwPBLXbw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776959291; a=rsa-sha256; cv=none; b=sdnpERfTc4we9qpoBIG6XNRXdkrjNjziwru8j3pnqIL4qj4cnHuG+a19XM4baiQR2XsahX z9uIIlYikRqNX/gFfNkQKphV+43uAEJRtkEiTvfAjWgRZYVaZWcycHGeMsqJ5slkGb26r8 8Qt/kKmehtb8l7WSyC50tl3eV4t0eyuY1UDBh3/eD78tX25Zxc1KQ/yanuBEpjE3f3asXL S6tK+nypkPOvkRe7zGjTKQSzXhhNl3OHBH13w3sPeEKPxg+sbwyvsDb20jKgWZPUeVvOsL saDcfujFSEKmhNHhJRoMNvHAwiNjdqmaOTK3cJQ4g38RH8pKlMd+mUvpNKnxkA== 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=1776959291; 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=z2Cy9dgbtEWeDt7VzgJ+Iho7CHLjxk3oomNz30u3KKQ=; b=kG+CTfmAGEWAQ784aCcy6S8e6ICmnI13R/yeYm70ce/4VX8yVTde4Jr5CXDw2oHobTIM2z OpdhwAlj87tLspb484q7oW6FzyzQ1tEag2WoaZzNhODsiyV0ohEhvqVIrPsJ4W9Q4PBxc0 FzDL7l/+HS5uI7hYZWkWR3fAq59Y9Lo3yk5Czd/bCSbulJoNQP7eQXcQ2TX9ScnaU8B/E4 c/6nDWN0ER5UQREk3PYBVciOyIxsBTBJy0QBSIlwsW9kZHw7h5HUE2pe/czdLPvds9bj4z deGWPNyATqiIbGqOf+rI24lsoO4OwlcELyl6W2HblH8/IlFfsF5LCk0oVsfZxA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g1gV34Cd2z7jc for ; Thu, 23 Apr 2026 15:48:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 37598 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 23 Apr 2026 15:48:11 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: f4418cf954c2 - main - LinuxKPI: Update seq_file to properly implement the iterator interface 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f4418cf954c299fa0934f110d6f5e9d50f2d24c5 Auto-Submitted: auto-generated Date: Thu, 23 Apr 2026 15:48:11 +0000 Message-Id: <69ea3f3b.37598.3a29eb6c@gitrepo.freebsd.org> The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=f4418cf954c299fa0934f110d6f5e9d50f2d24c5 commit f4418cf954c299fa0934f110d6f5e9d50f2d24c5 Author: John Baldwin AuthorDate: 2026-04-23 15:46:54 +0000 Commit: John Baldwin CommitDate: 2026-04-23 15:46:54 +0000 LinuxKPI: Update seq_file to properly implement the iterator interface The seq_file.rst documentation in the Linux kernel documents the iterator interface for the seq_file structure. In particular, the ppos passed to seq_read is a logical offset into a seq_file managed by the iterator interface, not an offset into the generated data. For example, if a seq_file outputs state for each node in a linked-list or array, *ppos might be used as the index of the node to output, not a byte offset. Rewrite seq_read to honor this contract which fixes a few bugs: - Treat *ppos as a logical iterator offset that is only updated by the next callback after outputting a single item via the show method. - Use a loop to permit outputting descriptions of multiple items if the user buffer is large enough. - Always invoke the stop method after terminating the loop to cleanup any state setup by start (e.g. if start allocated a buffer or obtained a lock, the stop method is called to cleanup). While here, implement support for SEQ_SKIP as documented in the Linux documentation even though it is not currently used in the tree. Reviewed by: bz Sponsored by: AFRL, DARPA Differential Revision: https://reviews.freebsd.org/D55899 --- .../linuxkpi/common/include/linux/seq_file.h | 2 + sys/compat/linuxkpi/common/src/linux_seq_file.c | 64 +++++++++++++++++++--- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/seq_file.h b/sys/compat/linuxkpi/common/include/linux/seq_file.h index 786c09bd6a20..be03c4768b07 100644 --- a/sys/compat/linuxkpi/common/include/linux/seq_file.h +++ b/sys/compat/linuxkpi/common/include/linux/seq_file.h @@ -39,6 +39,8 @@ #undef file #define inode vnode +#define SEQ_SKIP 1 + MALLOC_DECLARE(M_LSEQ); #define DEFINE_SHOW_ATTRIBUTE(__name) \ diff --git a/sys/compat/linuxkpi/common/src/linux_seq_file.c b/sys/compat/linuxkpi/common/src/linux_seq_file.c index eae414ea696e..efa41b28c6b1 100644 --- a/sys/compat/linuxkpi/common/src/linux_seq_file.c +++ b/sys/compat/linuxkpi/common/src/linux_seq_file.c @@ -45,23 +45,73 @@ seq_read(struct linux_file *f, char __user *ubuf, size_t size, off_t *ppos) struct seq_file *m; struct sbuf *sbuf; void *p; - ssize_t rc; + ssize_t rc, oldlen; + size_t todo; m = f->private_data; sbuf = m->buf; sbuf_clear(sbuf); p = m->op->start(m, ppos); - rc = m->op->show(m, p); - if (rc) + if (p == NULL) + return (0); + + rc = 0; + while (size > sbuf_len(sbuf)) { + oldlen = sbuf_len(sbuf); + rc = m->op->show(m, p); + if (rc < 0) + break; + + if (rc == SEQ_SKIP) { + /* Discard any data written in show callback. */ + sbuf_setpos(sbuf, oldlen); + rc = 0; + } + + /* + * If the sbuf has overflowed, bail. Discard any + * partial output from the show callback for this item + * preserving output from any earlier items. Since we + * break before calling the next callback to update + * *ppos, a subsequent read() will start by displaying + * the current item. However, if the current item + * could not be displayed by itself, still fail with + * ENOMEM rather than returning EOF. + */ + if (sbuf_error(sbuf)) { + if (oldlen != 0) + sbuf_setpos(sbuf, oldlen); + break; + } + + /* + * XXX: The seq_file documentation claims that Linux + * warns if this callback doesn't update the value in + * *ppos. We don't bother warning here. + */ + p = m->op->next(m, p, ppos); + if (p == NULL) + break; + } + m->op->stop(m, p); + + if (rc < 0) return (rc); rc = sbuf_finish(sbuf); - if (rc) - return (rc); + if (rc != 0) + return (-rc); + + todo = sbuf_len(sbuf); + if (todo > size) + todo = size; + + rc = copy_to_user(ubuf, sbuf_data(sbuf), todo); + if (rc != 0) + return (-EFAULT); - return (simple_read_from_buffer(ubuf, size, ppos, sbuf_data(sbuf), - sbuf_len(sbuf))); + return (todo); } int