OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
From: Konstantin Khorenko <khorenko@virtuozzo.com>
To: Liu Kui <kui.liu@virtuozzo.com>, Alexey Kuznetsov <kuznet@virtuozzo.com>
Cc: devel@openvz.org, azaitsev@virtuozzo.com
Subject: Re: [Devel] [PATCH hci-8.1 2/3] fs/fuse kio: refactor transmit path in pcs_sockio_send()
Date: Wed, 30 Sep 2026 18:29:49 +0200	[thread overview]
Message-ID: <ffc1f3f9-4f7e-4467-922f-add298982ce4@virtuozzo.com> (raw)
In-Reply-To: <010701a0f1440774-f1f5445f-b7af-4457-b7c7-de74d1f50ea4-000000@eu-central-1.amazonses.com>

i have commited this patch, but this review looks valid, is you agree,
please consider sending an incremental patch like

  diff --git a/fs/fuse/kio/pcs/pcs_sock_io.c b/fs/fuse/kio/pcs/pcs_sock_io.c
  index 2da6d51c898b0..3a2228088540a 100644
  --- a/fs/fuse/kio/pcs/pcs_sock_io.c
  +++ b/fs/fuse/kio/pcs/pcs_sock_io.c
  @@ -307,6 +307,12 @@ static int do_sockio_sendmsg(struct pcs_sockio *sio, struct pcs_msg *msg)
                if (!iov_iter_count(it)) {
                        /* Current iter is exhausted, init new one */
                        msg->get_iter(msg, sio->write_offset, it, WRITE);
  +
  +                     /* An empty refill would spin this loop forever */
  +                     if (WARN_ON(!iov_iter_count(it))) {
  +                             clear_and_wake_up_bit(PCS_MSG_BUSY, &msg->flags);
  +                             return -PCS_ERR_NET_ABORT;
  +                     }
                }

                BUG_ON(iov_iter_count(it) > left);

--
Best regards,

Konstantin Khorenko,
Virtuozzo Linux Kernel Team

On 9/30/26 09:42, no-reply@sashiko.virtuozzo.com wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [Medium] fs/fuse kio: do_sockio_sendmsg() can spin forever on an empty get_iter() refill
> - [Low] fs/fuse kio: iov_iter_sendpages_ok() under-checks pages of unaligned multi-page bvecs
> --
> 
> commit 2b6fc40ff00b50732f7cf6408214e55943ba4135
> Author: Liu Kui <kui.liu@virtuozzo.com>
> 
> fs/fuse kio: refactor transmit path in pcs_sockio_send()
> 
> This patch replaces do_send_one_seg() with do_sockio_sendmsg(). The new
> function submits the whole iov_iter in one sock_sendmsg() call, and uses
> MSG_SPLICE_PAGES when all pages qualify. It also clears PCS_MSG_BUSY in
> the transport whenever IO on the msg ends.
> 
> Link: https://virtuozzo.atlassian.net/browse/VSTOR-142167
> 
>> diff --git a/fs/fuse/kio/pcs/pcs_sock_io.c b/fs/fuse/kio/pcs/pcs_sock_io.c
>> --- a/fs/fuse/kio/pcs/pcs_sock_io.c
>> +++ b/fs/fuse/kio/pcs/pcs_sock_io.c
> [ ... ]
> 
>> +static bool iov_iter_sendpages_ok(struct iov_iter *it)
>> +{
>> +	const struct bio_vec *bvec = it->bvec;
>> +
>> +	if (!iov_iter_is_bvec(it))
>> +		return false;
>> +
>> +	while (bvec < (it->bvec + it->nr_segs)) {
>> +		if (!sendpages_ok(bvec->bv_page, bvec->bv_len, bvec->bv_offset))
>> +			return false;
>> +		bvec++;
>> +	}
>> +
>> +	return true;
>> +}
> [Severity: Low]
> Can iov_iter_sendpages_ok() skip the last page of a multi-page bvec that
> has an unaligned bv_offset?
> 
> sendpages_ok() starts at page + (offset >> PAGE_SHIFT) and steps
> PAGE_SIZE for len bytes.  For example, with bv_offset=2048 and
> bv_len=4096 the range covers two pages, but only one is checked with
> sendpage_ok().
> 
> The bvec builder in pcs_krpc.c (umem branch) sets bv_offset to a
> non-page-aligned value and bv_len up to the contiguous length, so such
> bvecs look possible:
> 
>     bvec->bv_offset = offset;
>     ...
>     bvec->bv_len = len < contig ? len : contig;
> 
> If that happens, MSG_SPLICE_PAGES could be set in do_sockio_sendmsg()
> while the unchecked page is a slab page or has a zero refcount.  That
> page would then be spliced into the socket by reference instead of being
> copied.  Is the page check meant to cover the pages that the byte range
> actually touches?
> 
>> +static int do_sockio_sendmsg(struct pcs_sockio *sio, struct pcs_msg *msg)
>> +{
> [ ... ]
> 
>> +	while (sio->write_offset < msg->size) {
>> +		size_t left = msg->size - sio->write_offset;
>> +		struct msghdr sockmsg = {.msg_flags = flags};
>> +
>> +		TRACE("sio(%px) offset:%d msg:%px left:%zu, it->len:%zu\n", sio, sio->write_offset, msg, left, iov_iter_count(it));
>> +
>> +		if (!iov_iter_count(it)) {
>> +			/* Current iter is exhausted, init new one */
>> +			msg->get_iter(msg, sio->write_offset, it, WRITE);
>> +		}
>> +
>> +		BUG_ON(iov_iter_count(it) > left);
> [ ... ]
> 
>> +		while (iov_iter_count(it)) {
> [Severity: Medium]
> Can do_sockio_sendmsg() spin forever here if msg->get_iter() returns an
> iterator with a zero count while sio->write_offset < msg->size?
> 
> In that case the BUG_ON(iov_iter_count(it) > left) check passes, the
> inner while (iov_iter_count(it)) loop is skipped, and sock_sendmsg() is
> never called.  WARN_ON(msg_data_left(&sockmsg)) sees zero and does not
> fire.  write_offset does not change, so the outer loop repeats with the
> same state and no exit, which would be a soft lockup.
> 
> The old do_send_one_seg() returned 0 for an empty segment, and
> pcs_sockio_send() turned that into a WARN_ON and sio_abort(). I did not
> find a get_iter() callback that returns an empty iterator for an
> in-range offset (krpc_msg_get_data() and pcs_get_iter_inline() look
> fine), so this looks latent.  Would it make sense to add a check that
> fails the message when get_iter() returns an empty iterator?
> 
>> +			int ret;
> [ ... ]
> 
> -- Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20260930-sockio-refactor-8-1-v1-0-806348b9eb26@virtuozzo.com?part=2
> 

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  reply	other threads:[~2026-09-30 16:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30  7:34 [Devel] [PATCH hci-8.1 0/3] fs/fuse kio: cut per-4k-page sendmsg/recvmsg calls in the sockio path Liu Kui
2026-09-30  7:34 ` [Devel] [PATCH hci-8.1 1/3] fs/fuse kio: teach pcs_umem about hugepage-backed mappings Liu Kui
2026-09-30  7:41   ` no-reply
2026-09-30  7:34 ` [Devel] [PATCH hci-8.1 2/3] fs/fuse kio: refactor transmit path in pcs_sockio_send() Liu Kui
2026-09-30  7:42   ` no-reply
2026-09-30 16:29     ` Konstantin Khorenko [this message]
2026-09-30  7:34 ` [Devel] [PATCH hci-8.1 3/3] fs/fuse kio: refactor receive path in pcs_sockio_recv() Liu Kui
2026-09-30  7:42   ` no-reply
2026-09-30 16:09 ` [Devel] [PATCH hci-8.1 0/3] fs/fuse kio: cut per-4k-page sendmsg/recvmsg calls in the sockio path Konstantin Khorenko

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=ffc1f3f9-4f7e-4467-922f-add298982ce4@virtuozzo.com \
    --to=khorenko@virtuozzo.com \
    --cc=azaitsev@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=kui.liu@virtuozzo.com \
    --cc=kuznet@virtuozzo.com \
    /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