From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D33D606A927 for ; Mon, 2 Nov 2026 15:35:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PfFcHu8I Received: from boromir.ozlabs.org (localhost [127.0.0.1]) by lists.ozlabs.org (Postfix) with ESMTP id 4jJG3n29NKz3dSK; Tue, 03 Nov 2026 02:35:01 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip="2600:3c0a:e001:78e:0:1991:8:25" ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1793633701; cv=none; b=nFKykdv9a5R9IuOsV5acTWdcGj5bwiQbQ3Q6b9I/oze2mgsmNhRgEiwfZYsy1o/YVGYB9JJ9G5QUx3pV80BETiBuBipFJYuFd0a5SFmwfTI1oBbdrznuEdqLBG3ahSV/WVhZ2a/kmSpcMpPSCfPlB5Q53DWMVqEmlQrbQ/00rK0hFcVeaE/pbKPKlLCzNkIVgf0qm7dI8D+vwirx7sWZJm60/rkrrYGzlZeyVySaiRFSczCAfbqidM3PhdIHv19uJkI9fculbJl6fh9KFxxRbFF3CurlJHWnKY3Z6N2kcS4RIyHpMWk5lr86DhJ+aEkVML6+PXEOHEsuOGSbm3NZ9w== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1793633701; c=relaxed/relaxed; bh=ulWAa08tPZnJZAAMojZfgqs4wxYXZkHD77FK42yiGkc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=A80OH3g0Zs3pQQg2kXl3N6P6eWD9CH3bB3XCeGi6jcnWDY6Dz7x7aY3GJcsukEAkHLAMgIHXTocqPKhGXtasnpnAjoQ1ObSgewWDC3+PSTq97dGN92eopdDdqAY/tkIXh6YuCWy5yZGZ9Ox/Io2OI9CF6NHsNm79nX/3yC+HOqE12XzgIJCyG+GYYXVW8PIVhYSM2GSFrx0uAx7nZuHwFFVU0Ogr/qxQxzpIPzCYQfJTPdFrEjrVzX0ItdtDsBbTLtZP728BZUuAz/VN0hGadorjoToakHoAlMX/OOV9rNPLdB/+F9jmQWTH76RloX+Ww0Nqkf8MtBYdahXBhHbnEA== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PfFcHu8I; dkim-atps=neutral; spf=pass (client-ip=2600:3c0a:e001:78e:0:1991:8:25; helo=sea.source.kernel.org; envelope-from=brauner@kernel.org; receiver=lists.ozlabs.org) smtp.mailfrom=kernel.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PfFcHu8I; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=2600:3c0a:e001:78e:0:1991:8:25; helo=sea.source.kernel.org; envelope-from=brauner@kernel.org; receiver=lists.ozlabs.org) Received: from sea.source.kernel.org (sea.source.kernel.org [IPv6:2600:3c0a:e001:78e:0:1991:8:25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4jJG3m3VXCz3dRt for ; Tue, 03 Nov 2026 02:35:00 +1100 (AEDT) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id D17DA436EA; Mon, 2 Nov 2026 15:34:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B0F51F00A16; Mon, 2 Nov 2026 15:34:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793633698; bh=ulWAa08tPZnJZAAMojZfgqs4wxYXZkHD77FK42yiGkc=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=PfFcHu8IBWcir3zWLPuevPTmn2FH1O7NAWSytCLKB2vywNn2OURo4QLe3pteKKhQ5 Bfjp3z46zNPbSSOcldRfo1MfN/eHjNC/FEZwM+hOZZ1SrgUl2987I3wnN/6Qhpz8u+ h+Zo+EgQmtTxYjKVO1PK7PTyk+17j3IQ3luoVrnilEYf97ksMn2/9hMDi2C1SdwzP5 pEgh4EbwBnwEYCiQ9Fpriwr/KAxat0dZyL36NrcXB+GoWNXGpvEfmeQXawM9lhuJcn bRYIHlfjqYj93JSJ18MlNaEuFao8XaMk8JIhJ71DX2G29goCMENz6tPu/GCcoBJiCg s2hgrd9oFJynw== From: Christian Brauner Date: Mon, 02 Nov 2026 16:07:25 +0100 Subject: [PATCH RFC 11/11] samples/kfifo: let procfs copy out reads X-Mailing-List: linuxppc-dev@lists.ozlabs.org List-Id: List-Help: List-Owner: List-Post: List-Archive: , List-Subscribe: , , Precedence: list X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261102-work-procfs-net-v1-11-982104a4f592@kernel.org> References: <20261102-work-procfs-net-v1-0-982104a4f592@kernel.org> In-Reply-To: <20261102-work-procfs-net-v1-0-982104a4f592@kernel.org> To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Jann Horn , Josef Bacik , Chris Mason , Jeff Layton , NeilBrown , Eric Dumazet , Thomas Gleixner , Al Viro , Jonathan Corbet , Christoph Hellwig , Greg Kroah-Hartman , Joel Granados , Kees Cook , Jan Kara , Jan Kara , linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, linux-um@lists.infradead.org, linux-wireless@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, netdev@vger.kernel.org, ntfs3@lists.linux.dev, platform-driver-x86@vger.kernel.org, coreteam@netfilter.org, kexec@lists.infradead.org, linux-pci@vger.kernel.org, linux-sound@vger.kernel.org, netfilter-devel@vger.kernel.org, dri-devel@lists.freedesktop.org, ibm-acpi-devel@lists.sourceforge.net, jfs-discussion@lists.sourceforge.net, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-cifs@vger.kernel.org, linux-fbdev@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-mm@kvack.org, linux-sh@vger.kernel.org, linux-usb@vger.kernel.org, samba-technical@lists.samba.org, sparclinux@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-doc@vger.kernel.org, linux-serial@vger.kernel.org, linux-atm-general@lists.sourceforge.net, Takashi Iwai , linux-input@vger.kernel.org, linux-raid@vger.kernel.org, linux-ext4@vger.kernel.org, linux-modules@vger.kernel.org, linux-debuggers@vger.kernel.org, "Christian Brauner (Amutable)" , Chuck Lever X-Mailer: b4 0.17-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3702; i=brauner@kernel.org; h=from:subject:message-id; bh=20rJkgesQhfyVvX+iP+2cn2t9uRQnDiG02PYUBwi/V4=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWS9WG7yZ/7FDwsifooGMJc3ds/I7m6u/fBp6rcCmRo+t imb4pR+dZSyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAEzEUpXhf7HCvd1Ci3ccsanY xP6t4JnXXklWPoW34sI98hwf12YZtDL8j3zfcmDGjjt/p/CWFp7ZuWC587OTkueWSXM+eMQevaW EiwEA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Implement ->proc_read_buf() so procfs copies what is read to userspace after it unpinned the entry, and take the data out of the fifo with kfifo_out() instead of kfifo_to_user(). A reader that passes a bad buffer loses what was taken out for it now, kfifo_to_user() left that in the fifo. The samples can be spliced now too, and a sendfile() from them into a target that fails or takes less than was read drops what was taken out in between, like for the rtas error log. Signed-off-by: Christian Brauner (Amutable) --- samples/kfifo/bytestream-example.c | 9 +++------ samples/kfifo/inttype-example.c | 10 ++++------ samples/kfifo/record-example.c | 9 +++------ 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/samples/kfifo/bytestream-example.c b/samples/kfifo/bytestream-example.c index 8c58fb46a2bf..214e46a64cc1 100644 --- a/samples/kfifo/bytestream-example.c +++ b/samples/kfifo/bytestream-example.c @@ -125,26 +125,23 @@ static ssize_t fifo_write(struct file *file, char *buf, return copied; } -static ssize_t fifo_read(struct file *file, char __user *buf, +static ssize_t fifo_read(struct file *file, char *buf, size_t count, loff_t *ppos) { - int ret; unsigned int copied; if (mutex_lock_interruptible(&read_access)) return -ERESTARTSYS; - ret = kfifo_to_user(&test, buf, count, &copied); + copied = kfifo_out(&test, buf, count); mutex_unlock(&read_access); - if (ret) - return ret; return copied; } static const struct proc_ops fifo_proc_ops = { - .proc_read = fifo_read, + .proc_read_buf = fifo_read, .proc_write_buf = fifo_write, .proc_lseek = noop_llseek, }; diff --git a/samples/kfifo/inttype-example.c b/samples/kfifo/inttype-example.c index c5d16b815e73..8384d7f8de6c 100644 --- a/samples/kfifo/inttype-example.c +++ b/samples/kfifo/inttype-example.c @@ -119,26 +119,24 @@ static ssize_t fifo_write(struct file *file, char *buf, return copied; } -static ssize_t fifo_read(struct file *file, char __user *buf, +static ssize_t fifo_read(struct file *file, char *buf, size_t count, loff_t *ppos) { - int ret; unsigned int copied; if (mutex_lock_interruptible(&read_access)) return -ERESTARTSYS; - ret = kfifo_to_user(&test, buf, count, &copied); + copied = kfifo_out(&test, (int *)buf, count / sizeof(int)) * + sizeof(int); mutex_unlock(&read_access); - if (ret) - return ret; return copied; } static const struct proc_ops fifo_proc_ops = { - .proc_read = fifo_read, + .proc_read_buf = fifo_read, .proc_write_buf = fifo_write, .proc_lseek = noop_llseek, }; diff --git a/samples/kfifo/record-example.c b/samples/kfifo/record-example.c index dcc749247c64..29d08e90a63d 100644 --- a/samples/kfifo/record-example.c +++ b/samples/kfifo/record-example.c @@ -132,26 +132,23 @@ static ssize_t fifo_write(struct file *file, char *buf, return copied; } -static ssize_t fifo_read(struct file *file, char __user *buf, +static ssize_t fifo_read(struct file *file, char *buf, size_t count, loff_t *ppos) { - int ret; unsigned int copied; if (mutex_lock_interruptible(&read_access)) return -ERESTARTSYS; - ret = kfifo_to_user(&test, buf, count, &copied); + copied = kfifo_out(&test, buf, count); mutex_unlock(&read_access); - if (ret) - return ret; return copied; } static const struct proc_ops fifo_proc_ops = { - .proc_read = fifo_read, + .proc_read_buf = fifo_read, .proc_write_buf = fifo_write, .proc_lseek = noop_llseek, /* kfifo_from_user() cut a record to what its length byte holds */ -- 2.53.0