public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: Simon Glass <sjg@chromium.org>
Cc: christian.poetzsch@kernkonzept.com,
	U-Boot Mailing List <u-boot@lists.denx.de>,
	Bin Meng <bmeng.cn@gmail.com>, Adam Lackorzynski <adam@l4re.org>
Subject: Re: [PATCH] virtio: add support for SIZE_MAX & SEG_MAX features
Date: Wed, 8 Apr 2026 13:12:44 -0600	[thread overview]
Message-ID: <20260408191244.GA837666@bill-the-cat> (raw)
In-Reply-To: <CAFLszTjKtFM6RXE_ZoEFbpW1ZGPtLCcqzJeceaLGPYoTfGA9vQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3079 bytes --]

On Thu, Apr 02, 2026 at 01:41:11PM -0600, Simon Glass wrote:
> Hi Christian,
> 
> On 2026-03-27T08:18:58, Christian Pötzsch
> <christian.poetzsch@kernkonzept.com> wrote:
> > virtio: add support for SIZE_MAX & SEG_MAX features
> > virtio: add support for SIZE_MAX & SEG_MAX features
> >
> > Some virtio implementations may forward the virtio requests directly to
> > the underlying hw. The hw may have some restrictions in how many and how
> > big the requests can be. Therefore, the corresponding virtio device will
> > announce this limitations with the SIZE_MAX & SEG_MAX feature.
> >
> > Add support for those features. Split an io request into multiple virtio
> > requests if more than seg_max segments would be used. Also split a
> > single buffer request into multiple segments if the buffer is bigger
> > then size_max.
> >
> > Signed-off-by: Christian Pötzsch <christian.poetzsch@kernkonzept.com>
> > Signed-off-by: Adam Lackorzynski <adam@l4re.org>
> 
> > diff --git a/drivers/virtio/virtio_blk.c b/drivers/virtio/virtio_blk.c
> > @@ -119,7 +145,38 @@ static ulong virtio_blk_do_req(...)
> > +err_free:
> > +     for (i = 0; i < seg_cnt + 2; ++i)
> > +             free(sgs[i]);
> > +     free(sgs);
> > +
> > +     return status == VIRTIO_BLK_S_OK ? blkcnt : -EIO;
> 
> The err_free label is reached from both the success path (fall-through
> after virtqueue_get_buf()) and error paths (goto from malloc()
> failure, virtqueue_add() failure, or unknown type). On error paths,
> status is uninitialised, so the final check has undefined behaviour.
> Please can you separate the success path from the error cleanup, e.g.
> with an explicit return before the err_free label.
> 
> > diff --git a/drivers/virtio/virtio_blk.c b/drivers/virtio/virtio_blk.c
> > @@ -145,38 +145,38 @@ static ulong virtio_blk_do_req(...)
> > +     while (i < blkcnt) {
> > +             u32 blk_per_sg = min(blkcnt - i, seg_sec_cnt * priv->seg_max);
> > +
> > +             ret = virtio_blk_do_single_req(dev, sector + i, blk_per_sg,
> > +                                            buffer + i * 512, type);
> > +             if (!ret)
> > +                     return ret;
> 
> The error check is inverted. virtio_blk_do_single_req() returns blkcnt
> (positive) on success and -EIO on failure, so if (!ret) only triggers
> when ret is zero. I suspect you want if (ret < 0) here.
> 
> BTW please add a function comment for virtio_blk_do_single_req() so
> all this is clearer.

This is all true, and useful feedback.

> > diff --git a/drivers/virtio/virtio_blk.c b/drivers/virtio/virtio_blk.c
> > @@ -67,50 +74,69 @@ static void virtio_blk_init_data_sg(...)
> > +     // The virtio device may have constrains on the maximum segment size.
> 
> U-Boot follows the Linux kernel coding style which prefers /* */
> comments over //. Please can you convert these.

This hasn't been true for a number of years, Linux Kernel nor here.
We've accepted C99-style comments (when not needing to be kernel-doc)
for a long time now.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

      reply	other threads:[~2026-04-08 19:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-27  8:18 [PATCH] virtio: add support for SIZE_MAX & SEG_MAX features Christian Pötzsch
2026-04-02 19:41 ` Simon Glass
2026-04-08 19:12   ` Tom Rini [this message]

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=20260408191244.GA837666@bill-the-cat \
    --to=trini@konsulko.com \
    --cc=adam@l4re.org \
    --cc=bmeng.cn@gmail.com \
    --cc=christian.poetzsch@kernkonzept.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /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