QEMU-Devel Archive mirror
 help / color / mirror / Atom feed
From: Sam Li <faithilikerun@gmail.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Stefan Hajnoczi <stefanha@redhat.com>,
	qemu-devel@nongnu.org, qemu-block@nongnu.org,
	Dmitry Fomichev <dmitry.fomichev@wdc.com>
Subject: Re: [PULL v2 10/16] block: introduce zone append write for zoned devices
Date: Sat, 3 Jun 2023 01:23:09 +0800	[thread overview]
Message-ID: <CAAAx-8L4Z3tBzV5DMEy0WnG=3y67bp_1g-+2kUhrY+rp2knNKA@mail.gmail.com> (raw)
In-Reply-To: <CAFEAcA9bDh12FSk8CjEkBZjQOEBVd6-=fVwnM9bx8aoXvQdMuw@mail.gmail.com>

Peter Maydell <peter.maydell@linaro.org> 于2023年6月3日周六 00:52写道:
>
> On Mon, 15 May 2023 at 17:06, Stefan Hajnoczi <stefanha@redhat.com> wrote:
> >
> > From: Sam Li <faithilikerun@gmail.com>
> >
> > A zone append command is a write operation that specifies the first
> > logical block of a zone as the write position. When writing to a zoned
> > block device using zone append, the byte offset of the call may point at
> > any position within the zone to which the data is being appended. Upon
> > completion the device will respond with the position where the data has
> > been written in the zone.
> >
> > Signed-off-by: Sam Li <faithilikerun@gmail.com>
> > Reviewed-by: Dmitry Fomichev <dmitry.fomichev@wdc.com>
> > Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
> > Message-id: 20230508051510.177850-3-faithilikerun@gmail.com
> > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
>
> Hi; Coverity flagged up a possible bug here (CID 1512459):
>
> > @@ -2453,8 +2454,12 @@ static int coroutine_fn raw_co_prw(BlockDriverState *bs, uint64_t offset,
> >      if (fd_open(bs) < 0)
> >          return -EIO;
> >  #if defined(CONFIG_BLKZONED)
> > -    if (type & QEMU_AIO_WRITE && bs->wps) {
> > +    if ((type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) && bs->wps) {
>
> Here we check for bs->wps being NULL, which implies that it might be NULL...
>
> >          qemu_co_mutex_lock(&bs->wps->colock);
> > +        if (type & QEMU_AIO_ZONE_APPEND && bs->bl.zone_size) {
> > +            int index = offset / bs->bl.zone_size;
> > +            offset = bs->wps->wp[index];
> > +        }
> >      }
> >  #endif
> >
> > @@ -2502,9 +2507,13 @@ out:
> >  {
> >      BlockZoneWps *wps = bs->wps;
> >      if (ret == 0) {
> > -        if (type & QEMU_AIO_WRITE && wps && bs->bl.zone_size) {
> > +        if ((type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND))
> > +            && wps && bs->bl.zone_size) {
> >              uint64_t *wp = &wps->wp[offset / bs->bl.zone_size];
> >              if (!BDRV_ZT_IS_CONV(*wp)) {
> > +                if (type & QEMU_AIO_ZONE_APPEND) {
> > +                    *s->offset = *wp;
> > +                }
> >                  /* Advance the wp if needed */
> >                  if (offset + bytes > *wp) {
> >                      *wp = offset + bytes;
> > @@ -2512,12 +2521,12 @@ out:
> >              }
> >          }
> >      } else {
> > -        if (type & QEMU_AIO_WRITE) {
> > +        if (type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) {
>
> ...but here we do not, even though update_zones_wp() can
> dereference bs->wps in some code paths.
>
> Should we be checking for NULL here before calling, or
> should update_zones_wp() handle a NULL bs->wps, or something else?

Hi Peter,

Thanks for spotting this. You are right that bs->wps is not checked in
this code path. I think the get_zones_wp() should handle a NULL
bs->wps which is the function calling wps directly.

Would you like to submit a patch for this? Or I can do it if you are
not available.

Thanks,
Sam

>
> >              update_zones_wp(bs, s->fd, 0, 1);
> >          }
> >      }
> >
> > -    if (type & QEMU_AIO_WRITE && wps) {
> > +    if ((type & (QEMU_AIO_WRITE | QEMU_AIO_ZONE_APPEND)) && wps) {
> >          qemu_co_mutex_unlock(&wps->colock);
> >      }
> >  }
>
> thanks
> -- PMM


  reply	other threads:[~2023-06-02 17:23 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-15 16:04 [PULL v2 00/16] Block patches Stefan Hajnoczi
2023-05-15 16:04 ` [PULL v2 01/16] block/block-common: add zoned device structs Stefan Hajnoczi
2023-05-15 16:04 ` [PULL v2 02/16] block/file-posix: introduce helper functions for sysfs attributes Stefan Hajnoczi
     [not found]   ` <8b0ced3c-2fb5-2479-fe78-f4956ac037a6@linux.ibm.com>
2023-06-02 18:18     ` Sam Li
2023-06-02 18:41       ` Matthew Rosato
2023-06-02 18:45         ` Sam Li
2023-05-15 16:04 ` [PULL v2 03/16] block/block-backend: add block layer APIs resembling Linux ZonedBlockDevice ioctls Stefan Hajnoczi
2024-05-03 12:33   ` Peter Maydell
2024-05-07 15:09     ` Stefan Hajnoczi
2023-05-15 16:04 ` [PULL v2 04/16] block/raw-format: add zone operations to pass through requests Stefan Hajnoczi
2023-05-15 16:04 ` [PULL v2 05/16] block: add zoned BlockDriver check to block layer Stefan Hajnoczi
2023-05-15 16:04 ` [PULL v2 06/16] iotests: test new zone operations Stefan Hajnoczi
2023-05-15 16:04 ` [PULL v2 07/16] block: add some trace events for new block layer APIs Stefan Hajnoczi
2023-05-15 16:04 ` [PULL v2 08/16] docs/zoned-storage: add zoned device documentation Stefan Hajnoczi
2023-05-15 16:04 ` [PULL v2 09/16] file-posix: add tracking of the zone write pointers Stefan Hajnoczi
2023-05-15 16:05 ` [PULL v2 10/16] block: introduce zone append write for zoned devices Stefan Hajnoczi
2023-06-02 16:51   ` Peter Maydell
2023-06-02 17:23     ` Sam Li [this message]
2023-06-02 17:30       ` Peter Maydell
2023-06-02 17:35         ` Sam Li
2023-06-02 17:52           ` Peter Maydell
2023-06-02 18:03             ` Sam Li
2023-05-15 16:05 ` [PULL v2 11/16] qemu-iotests: test zone append operation Stefan Hajnoczi
2023-05-15 16:05 ` [PULL v2 12/16] block: add some trace events for zone append Stefan Hajnoczi
2023-05-15 16:05 ` [PULL v2 13/16] virtio-blk: add zoned storage emulation for zoned devices Stefan Hajnoczi
2023-05-15 16:05 ` [PULL v2 14/16] block: add accounting for zone append operation Stefan Hajnoczi
2023-05-15 16:05 ` [PULL v2 15/16] virtio-blk: add some trace events for zoned emulation Stefan Hajnoczi
2023-05-15 16:05 ` [PULL v2 16/16] docs/zoned-storage:add zoned emulation use case Stefan Hajnoczi
2023-05-15 23:37 ` [PULL v2 00/16] Block patches Richard Henderson

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='CAAAx-8L4Z3tBzV5DMEy0WnG=3y67bp_1g-+2kUhrY+rp2knNKA@mail.gmail.com' \
    --to=faithilikerun@gmail.com \
    --cc=dmitry.fomichev@wdc.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).