From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
Oleg Nesterov <oleg@redhat.com>,
Miklos Szeredi <miklos@szeredi.hu>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
Hugh Dickins <hughd@google.com>, <linux-fsdevel@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>
Cc: Jan Kara <jack@suse.cz>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
Mateusz Guzik <mjguzik@gmail.com>,
"Gautham R. Shenoy" <gautham.shenoy@amd.com>,
Rasmus Villemoes <ravi@prevas.dk>, <Neeraj.Upadhyay@amd.com>,
<Ananth.narayan@amd.com>, Swapnil Sapkal <swapnil.sapkal@amd.com>,
K Prateek Nayak <kprateek.nayak@amd.com>
Subject: [RFC PATCH 0/3] pipe: Convert pipe->{head,tail} to unsigned short
Date: Thu, 6 Mar 2025 11:39:21 +0000 [thread overview]
Message-ID: <20250306113924.20004-1-kprateek.nayak@amd.com> (raw)
In-Reply-To: <CAHk-=wjyHsGLx=rxg6PKYBNkPYAejgo7=CbyL3=HGLZLsAaJFQ@mail.gmail.com>
Here is an attempt at converting pipe->{head,tail} to unsigned short
members. All local variables storing the head and the tail have been
modified to unsigned short too the best of my knowledge)
pipe_resize_ring() has added a check to make sure nr_slots can be
contained within the limits of the pipe->{head,tail}. Building on that,
pipe->{max_usage,ring_size} were also converted to unsigned short to
catch any cases of incorrect unsigned arithmetic.
This has been tested for a few hours with anon pipes on a 5th Generation
AMD EPYC System and on a dual socket Intel Granite Rapids system without
experiencing any obvious issues.
pipe_write() was tagged with a debug trace_printk() on one of the test
machines to make sure the head has indeed wrapped around behind the tail
to ensure the wraparound scenarios are indeed happening.
Few pipe_occupancy() and pipe->max_usage based checks have been
converted to use unsigned short based arithmetic in fs/fuse/dev.c,
fs/splice.c, mm/filemap.c, and mm/filemap.c. Few of the observations
from Rasmus on a parallel thread [1] has been folded into Patch 3
(thanks a ton for chasing them).
More eyes and testing is greatly appreciated. If my tests run into any
issues, I'll report back on this thread. Series was tested with:
hackbench -g 16 -f 20 --threads --pipe -l 10000000 -s 100 # Warp around
stress-ng --oom-pipe 128 --oom-pipe-ops 100000 -t 600s # pipe resize
stress-ng --splice 128 --splice-ops 100000000 -t 600s # splice
stress-ng --vm-splice 128 --vm-splice-ops 100000000 -t 600s # splice
stress-ng --tee 128 --tee-ops 100000000 -t 600s
stress-ng --zlib 128 --zlib-ops 1000000 -t 600s
stress-ng --sigpipe 128 -t 60s
stress-ng did not report any failure in my testing.
[1] https://lore.kernel.org/all/87cyeu5zgk.fsf@prevas.dk/
--
K Prateek Nayak (3):
fs/pipe: Limit the slots in pipe_resize_ring()
fs/splice: Atomically read pipe->{head,tail} in opipe_prep()
treewide: pipe: Convert all references to
pipe->{head,tail,max_usage,ring_size} to unsigned short
fs/fuse/dev.c | 4 +++-
fs/pipe.c | 33 +++++++++++++++-----------
fs/splice.c | 50 ++++++++++++++++++++-------------------
include/linux/pipe_fs_i.h | 39 ++++++++++--------------------
kernel/watch_queue.c | 3 ++-
mm/filemap.c | 5 ++--
mm/shmem.c | 5 ++--
7 files changed, 69 insertions(+), 70 deletions(-)
base-commit: 848e076317446f9c663771ddec142d7c2eb4cb43
--
2.43.0
next parent reply other threads:[~2025-03-06 11:39 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAHk-=wjyHsGLx=rxg6PKYBNkPYAejgo7=CbyL3=HGLZLsAaJFQ@mail.gmail.com>
2025-03-06 11:39 ` K Prateek Nayak [this message]
2025-03-06 11:39 ` [RFC PATCH 1/3] fs/pipe: Limit the slots in pipe_resize_ring() K Prateek Nayak
2025-03-06 12:28 ` Oleg Nesterov
2025-03-06 15:26 ` K Prateek Nayak
2025-03-06 11:39 ` [RFC PATCH 2/3] fs/splice: Atomically read pipe->{head,tail} in opipe_prep() K Prateek Nayak
2025-03-06 11:39 ` [RFC PATCH 3/3] treewide: pipe: Convert all references to pipe->{head,tail,max_usage,ring_size} to unsigned short K Prateek Nayak
2025-03-06 12:32 ` Oleg Nesterov
2025-03-06 12:41 ` Oleg Nesterov
2025-03-06 15:33 ` K Prateek Nayak
2025-03-06 18:04 ` Linus Torvalds
2025-03-06 14:27 ` Rasmus Villemoes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250306113924.20004-1-kprateek.nayak@amd.com \
--to=kprateek.nayak@amd.com \
--cc=Ananth.narayan@amd.com \
--cc=Neeraj.Upadhyay@amd.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=gautham.shenoy@amd.com \
--cc=hughd@google.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=miklos@szeredi.hu \
--cc=mjguzik@gmail.com \
--cc=oleg@redhat.com \
--cc=ravi@prevas.dk \
--cc=swapnil.sapkal@amd.com \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox