All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jan Kara <jack@suse.cz>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	Mateusz Guzik <mjguzik@gmail.com>,
	Rasmus Villemoes <ravi@prevas.dk>,
	"Gautham R. Shenoy" <gautham.shenoy@amd.com>,
	Neeraj.Upadhyay@amd.com, Ananth.narayan@amd.com,
	Swapnil Sapkal <swapnil.sapkal@amd.com>
Subject: Re: [PATCH v2 1/4] fs/pipe: Limit the slots in pipe_resize_ring()
Date: Fri, 7 Mar 2025 23:30:20 +0100	[thread overview]
Message-ID: <20250307223020.GA28762@redhat.com> (raw)
In-Reply-To: <7cbc5845-e890-4bf5-9488-cd2496642f7e@amd.com>

On 03/07, K Prateek Nayak wrote:
>
> On 3/7/2025 8:21 PM, Oleg Nesterov wrote:
> >On 03/07, K Prateek Nayak wrote:
> >>
> >>--- a/fs/pipe.c
> >>+++ b/fs/pipe.c
> >>@@ -1271,6 +1271,10 @@ int pipe_resize_ring(struct pipe_inode_info *pipe, unsigned int nr_slots)
> >>  	struct pipe_buffer *bufs;
> >>  	unsigned int head, tail, mask, n;
> >>
> >>+	/* nr_slots larger than limits of pipe->{head,tail} */
> >>+	if (unlikely(nr_slots > (pipe_index_t)-1u))
> >>+		return -EINVAL;
> >
> >The whole series look "obviously" good to me,
> >
> >Reviewed-by: Oleg Nesterov <oleg@redhat.com>

So, in case it wasn't clear, you could safely ignore everything else below ;)

> >pipe_resize_ring() has another caller, watch_queue_set_size(), but it has
> >its own hard limits...
>
> "nr_notes" for watch queues cannot cross 512 so we should be covered there.

Yes, yes, this is what I meant,

> As for round_pipe_size(), we can do:
>
> diff --git a/fs/pipe.c b/fs/pipe.c
> index ce1af7592780..f82098aaa510 100644
> --- a/fs/pipe.c
> +++ b/fs/pipe.c
> @@ -1253,6 +1253,8 @@ const struct file_operations pipefifo_fops = {
>   */
>  unsigned int round_pipe_size(unsigned int size)
>  {
> +	unsigned int max_slots;
> +
>  	if (size > (1U << 31))
>  		return 0;
> @@ -1260,7 +1262,14 @@ unsigned int round_pipe_size(unsigned int size)
>  	if (size < PAGE_SIZE)
>  		return PAGE_SIZE;
> -	return roundup_pow_of_two(size);
> +	size = roundup_pow_of_two(size);
> +	max_slots = size >> PAGE_SHIFT;
> +
> +	/* Max slots cannot be covered pipe->{head,tail} limits */
> +	if (max_slots > (pipe_index_t)-1U)
> +		return 0;

Sure, this will work, but still it doesn't look clear/clean to me.
But no, no, I don't blame your suggestion.

To me, round_pipe_size() looks confusing with or without the changes we
discuss. Why does it use "1U << 31" as a maximum size? OK, this is because
that "1 << 31" is the maximum power-of-2 which can fit into u32.

But, even if this code assumes that pipe->head/tail are u32, why this
restriction? Most probably I missed something, but I don't understand.

> Since pipe_resize_ring() can be called without actually looking at
> "pipe_max_size"

Again, only if the caller is watch_queue_set_size(), but it has its own
hard limit.

So. I won't argue either way. Whatever looks better to you. My ack
still stands.

Sorry for (yet another) confusing and almost off-topic email from me.

Oleg.


  reply	other threads:[~2025-03-07 22:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-07  5:29 [PATCH v2 0/4] pipe: Trivial cleanups K Prateek Nayak
2025-03-07  5:29 ` [PATCH v2 1/4] fs/pipe: Limit the slots in pipe_resize_ring() K Prateek Nayak
2025-03-07 14:51   ` Oleg Nesterov
2025-03-07 16:16     ` K Prateek Nayak
2025-03-07 22:30       ` Oleg Nesterov [this message]
2025-03-07  5:29 ` [PATCH v2 2/4] kernel/watch_queue: Use pipe_buf() to retrieve the pipe buffer K Prateek Nayak
2025-03-07  5:29 ` [PATCH v2 3/4] fs/pipe: Use pipe_buf() helper to retrieve " K Prateek Nayak
2025-03-07  5:29 ` [PATCH v2 4/4] fs/splice: " K Prateek Nayak
2025-03-10  7:59 ` [PATCH v2 0/4] pipe: Trivial cleanups Christian Brauner

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=20250307223020.GA28762@redhat.com \
    --to=oleg@redhat.com \
    --cc=Ananth.narayan@amd.com \
    --cc=Neeraj.Upadhyay@amd.com \
    --cc=brauner@kernel.org \
    --cc=gautham.shenoy@amd.com \
    --cc=jack@suse.cz \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mjguzik@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.