From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793633699; b=esQj8vtkbyHNcLt+pVaWcUfnR6yseeGahFvHY0Ocl8s9Ay8yxEKeZYWu6ODXv59Oenvp 9J5pzjWLmW2Ab2K70Gr4UuaAhvz6cq5/0gLtZ8Pm6D6PKSxD+aKIUOjR9giEnWuRFNi8J RE/oG/wubvTAGZiyoO54x6SXx8wUCJB1BtrYymjyjef4YyZAz9yEOBBHuCeZX2C42FPfH pfmqTiny4SduMLCoesHxUGjnSY4Xse5QexbAQnMInJdlOzWH5h4oGJoImOQLchJUv9NJb uv/Wbfyd/qqdp6suz0jegTLSy2Hk3H5uQ2KeCTQ8pDGggDaBA9IRj/Xrb/AIBL72B5g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793633699; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=ulWAa08tPZnJZAAMojZfgqs4wxYXZkHD77FK42yiGkc=; b=czVdPfLyelhkizXqK26HNdPz88qsJ2H6B6sAovGPWMpFZnbSAq8iHqhG+95WT04ZCNgX AsQA+tU8xVMGfMSKeLILTmN2NSVfEZ+QPPj/j5dV/6RukKEYn/NjLUwXpU7MGq9oBatcO LhOzN6z5+KEYTRZVSBgtOH5oI8TehIrE4RR376lr7qFgFGHZEArexYBO/8irF92PeJ7/L jfoRZryLDqUUaR0/wlRQ3gXxWJT1mXnApbX0NamrXe6kggWu9AM9/DWutMpk+L1UJCKGS qET1F16pwUkCNUHwN5O6hE0xvLA2C8pmgq3gjAWdsptx8od7dePxwa56flVbmhU5sgQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=PfFcHu8I; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (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 1DB2E608B042; Mon, 2 Nov 2026 15:34:58 +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: 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: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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