All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: qemu-devel@nongnu.org, slp@redhat.com,
	marcandre.lureau@redhat.com, stefanha@redhat.com,
	mathieu.poirier@linaro.org, viresh.kumar@linaro.org,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"open list:virtiofs" <virtio-fs@redhat.com>
Subject: Re: [PATCH  v4 10/22] hw/virtio: move vm_running check to virtio_device_started
Date: Thu, 3 Nov 2022 17:35:53 -0400	[thread overview]
Message-ID: <20221103173542-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20221103162957-mutt-send-email-mst@kernel.org>

On Thu, Nov 03, 2022 at 04:30:48PM -0400, Michael S. Tsirkin wrote:
> On Thu, Nov 03, 2022 at 07:18:30PM +0000, Alex Bennée wrote:
> > 
> > "Michael S. Tsirkin" <mst@redhat.com> writes:
> > 
> > > On Tue, Aug 02, 2022 at 10:49:58AM +0100, Alex Bennée wrote:
> > >> All the boilerplate virtio code does the same thing (or should at
> > >> least) of checking to see if the VM is running before attempting to
> > >> start VirtIO. Push the logic up to the common function to avoid
> > >> getting a copy and paste wrong.
> > >> 
> > >> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> > >
> > > How bad is it if we drop this?
> > 
> > 
> > I assume it will break gpio. Why do we want to drop this now? It has
> > been merged awhile. However there was a follow-up patch which tweaked
> > the order of checks in virtio_device_started.
> 
> And that follow up patch trips up UBSAN:
> 
> https://gitlab.com/mitsirkin/qemu/-/pipelines/684763327
> 


And more specifically this

https://gitlab.com/mitsirkin/qemu/-/jobs/3269957848

> 
> 
> > >
> > >> ---
> > >>  include/hw/virtio/virtio.h   | 5 +++++
> > >>  hw/virtio/vhost-user-fs.c    | 6 +-----
> > >>  hw/virtio/vhost-user-i2c.c   | 6 +-----
> > >>  hw/virtio/vhost-user-rng.c   | 6 +-----
> > >>  hw/virtio/vhost-user-vsock.c | 6 +-----
> > >>  hw/virtio/vhost-vsock.c      | 6 +-----
> > >>  6 files changed, 10 insertions(+), 25 deletions(-)
> > >> 
> > >> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> > >> index 9bb2485415..74e7ad5a92 100644
> > >> --- a/include/hw/virtio/virtio.h
> > >> +++ b/include/hw/virtio/virtio.h
> > >> @@ -100,6 +100,7 @@ struct VirtIODevice
> > >>      VirtQueue *vq;
> > >>      MemoryListener listener;
> > >>      uint16_t device_id;
> > >> +    /* @vm_running: current VM running state via virtio_vmstate_change() */
> > >>      bool vm_running;
> > >>      bool broken; /* device in invalid state, needs reset */
> > >>      bool use_disabled_flag; /* allow use of 'disable' flag when needed */
> > >> @@ -376,6 +377,10 @@ static inline bool virtio_device_started(VirtIODevice *vdev, uint8_t status)
> > >>          return vdev->started;
> > >>      }
> > >>  
> > >> +    if (!vdev->vm_running) {
> > >> +        return false;
> > >> +    }
> > >> +
> > >>      return status & VIRTIO_CONFIG_S_DRIVER_OK;
> > >>  }
> > >>  
> > >> diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c
> > >> index e513e4fdda..d2bebba785 100644
> > >> --- a/hw/virtio/vhost-user-fs.c
> > >> +++ b/hw/virtio/vhost-user-fs.c
> > >> @@ -122,11 +122,7 @@ static void vuf_stop(VirtIODevice *vdev)
> > >>  static void vuf_set_status(VirtIODevice *vdev, uint8_t status)
> > >>  {
> > >>      VHostUserFS *fs = VHOST_USER_FS(vdev);
> > >> -    bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
> > >> -
> > >> -    if (!vdev->vm_running) {
> > >> -        should_start = false;
> > >> -    }
> > >> +    bool should_start = virtio_device_started(vdev, status);
> > >>  
> > >>      if (fs->vhost_dev.started == should_start) {
> > >>          return;
> > >> diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c
> > >> index 6020eee093..b930cf6d5e 100644
> > >> --- a/hw/virtio/vhost-user-i2c.c
> > >> +++ b/hw/virtio/vhost-user-i2c.c
> > >> @@ -93,11 +93,7 @@ static void vu_i2c_stop(VirtIODevice *vdev)
> > >>  static void vu_i2c_set_status(VirtIODevice *vdev, uint8_t status)
> > >>  {
> > >>      VHostUserI2C *i2c = VHOST_USER_I2C(vdev);
> > >> -    bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
> > >> -
> > >> -    if (!vdev->vm_running) {
> > >> -        should_start = false;
> > >> -    }
> > >> +    bool should_start = virtio_device_started(vdev, status);
> > >>  
> > >>      if (i2c->vhost_dev.started == should_start) {
> > >>          return;
> > >> diff --git a/hw/virtio/vhost-user-rng.c b/hw/virtio/vhost-user-rng.c
> > >> index 3a7bf8e32d..a9c1c4bc79 100644
> > >> --- a/hw/virtio/vhost-user-rng.c
> > >> +++ b/hw/virtio/vhost-user-rng.c
> > >> @@ -90,11 +90,7 @@ static void vu_rng_stop(VirtIODevice *vdev)
> > >>  static void vu_rng_set_status(VirtIODevice *vdev, uint8_t status)
> > >>  {
> > >>      VHostUserRNG *rng = VHOST_USER_RNG(vdev);
> > >> -    bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
> > >> -
> > >> -    if (!vdev->vm_running) {
> > >> -        should_start = false;
> > >> -    }
> > >> +    bool should_start = virtio_device_started(vdev, status);
> > >>  
> > >>      if (rng->vhost_dev.started == should_start) {
> > >>          return;
> > >> diff --git a/hw/virtio/vhost-user-vsock.c b/hw/virtio/vhost-user-vsock.c
> > >> index 0f8ff99f85..22c1616ebd 100644
> > >> --- a/hw/virtio/vhost-user-vsock.c
> > >> +++ b/hw/virtio/vhost-user-vsock.c
> > >> @@ -55,11 +55,7 @@ const VhostDevConfigOps vsock_ops = {
> > >>  static void vuv_set_status(VirtIODevice *vdev, uint8_t status)
> > >>  {
> > >>      VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev);
> > >> -    bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
> > >> -
> > >> -    if (!vdev->vm_running) {
> > >> -        should_start = false;
> > >> -    }
> > >> +    bool should_start = virtio_device_started(vdev, status);
> > >>  
> > >>      if (vvc->vhost_dev.started == should_start) {
> > >>          return;
> > >> diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c
> > >> index 0338de892f..8031c164a5 100644
> > >> --- a/hw/virtio/vhost-vsock.c
> > >> +++ b/hw/virtio/vhost-vsock.c
> > >> @@ -70,13 +70,9 @@ static int vhost_vsock_set_running(VirtIODevice *vdev, int start)
> > >>  static void vhost_vsock_set_status(VirtIODevice *vdev, uint8_t status)
> > >>  {
> > >>      VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev);
> > >> -    bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
> > >> +    bool should_start = virtio_device_started(vdev, status);
> > >>      int ret;
> > >>  
> > >> -    if (!vdev->vm_running) {
> > >> -        should_start = false;
> > >> -    }
> > >> -
> > >>      if (vvc->vhost_dev.started == should_start) {
> > >>          return;
> > >>      }
> > >> -- 
> > >> 2.30.2
> > 
> > 
> > -- 
> > Alex Bennée



WARNING: multiple messages have this Message-ID (diff)
From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Alex Bennée" <alex.bennee@linaro.org>
Cc: qemu-devel@nongnu.org, slp@redhat.com,
	marcandre.lureau@redhat.com, stefanha@redhat.com,
	mathieu.poirier@linaro.org, viresh.kumar@linaro.org,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"open list:virtiofs" <virtio-fs@redhat.com>
Subject: Re: [Virtio-fs] [PATCH v4 10/22] hw/virtio: move vm_running check to virtio_device_started
Date: Thu, 3 Nov 2022 17:35:53 -0400	[thread overview]
Message-ID: <20221103173542-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20221103162957-mutt-send-email-mst@kernel.org>

On Thu, Nov 03, 2022 at 04:30:48PM -0400, Michael S. Tsirkin wrote:
> On Thu, Nov 03, 2022 at 07:18:30PM +0000, Alex Bennée wrote:
> > 
> > "Michael S. Tsirkin" <mst@redhat.com> writes:
> > 
> > > On Tue, Aug 02, 2022 at 10:49:58AM +0100, Alex Bennée wrote:
> > >> All the boilerplate virtio code does the same thing (or should at
> > >> least) of checking to see if the VM is running before attempting to
> > >> start VirtIO. Push the logic up to the common function to avoid
> > >> getting a copy and paste wrong.
> > >> 
> > >> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> > >
> > > How bad is it if we drop this?
> > 
> > 
> > I assume it will break gpio. Why do we want to drop this now? It has
> > been merged awhile. However there was a follow-up patch which tweaked
> > the order of checks in virtio_device_started.
> 
> And that follow up patch trips up UBSAN:
> 
> https://gitlab.com/mitsirkin/qemu/-/pipelines/684763327
> 


And more specifically this

https://gitlab.com/mitsirkin/qemu/-/jobs/3269957848

> 
> 
> > >
> > >> ---
> > >>  include/hw/virtio/virtio.h   | 5 +++++
> > >>  hw/virtio/vhost-user-fs.c    | 6 +-----
> > >>  hw/virtio/vhost-user-i2c.c   | 6 +-----
> > >>  hw/virtio/vhost-user-rng.c   | 6 +-----
> > >>  hw/virtio/vhost-user-vsock.c | 6 +-----
> > >>  hw/virtio/vhost-vsock.c      | 6 +-----
> > >>  6 files changed, 10 insertions(+), 25 deletions(-)
> > >> 
> > >> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> > >> index 9bb2485415..74e7ad5a92 100644
> > >> --- a/include/hw/virtio/virtio.h
> > >> +++ b/include/hw/virtio/virtio.h
> > >> @@ -100,6 +100,7 @@ struct VirtIODevice
> > >>      VirtQueue *vq;
> > >>      MemoryListener listener;
> > >>      uint16_t device_id;
> > >> +    /* @vm_running: current VM running state via virtio_vmstate_change() */
> > >>      bool vm_running;
> > >>      bool broken; /* device in invalid state, needs reset */
> > >>      bool use_disabled_flag; /* allow use of 'disable' flag when needed */
> > >> @@ -376,6 +377,10 @@ static inline bool virtio_device_started(VirtIODevice *vdev, uint8_t status)
> > >>          return vdev->started;
> > >>      }
> > >>  
> > >> +    if (!vdev->vm_running) {
> > >> +        return false;
> > >> +    }
> > >> +
> > >>      return status & VIRTIO_CONFIG_S_DRIVER_OK;
> > >>  }
> > >>  
> > >> diff --git a/hw/virtio/vhost-user-fs.c b/hw/virtio/vhost-user-fs.c
> > >> index e513e4fdda..d2bebba785 100644
> > >> --- a/hw/virtio/vhost-user-fs.c
> > >> +++ b/hw/virtio/vhost-user-fs.c
> > >> @@ -122,11 +122,7 @@ static void vuf_stop(VirtIODevice *vdev)
> > >>  static void vuf_set_status(VirtIODevice *vdev, uint8_t status)
> > >>  {
> > >>      VHostUserFS *fs = VHOST_USER_FS(vdev);
> > >> -    bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
> > >> -
> > >> -    if (!vdev->vm_running) {
> > >> -        should_start = false;
> > >> -    }
> > >> +    bool should_start = virtio_device_started(vdev, status);
> > >>  
> > >>      if (fs->vhost_dev.started == should_start) {
> > >>          return;
> > >> diff --git a/hw/virtio/vhost-user-i2c.c b/hw/virtio/vhost-user-i2c.c
> > >> index 6020eee093..b930cf6d5e 100644
> > >> --- a/hw/virtio/vhost-user-i2c.c
> > >> +++ b/hw/virtio/vhost-user-i2c.c
> > >> @@ -93,11 +93,7 @@ static void vu_i2c_stop(VirtIODevice *vdev)
> > >>  static void vu_i2c_set_status(VirtIODevice *vdev, uint8_t status)
> > >>  {
> > >>      VHostUserI2C *i2c = VHOST_USER_I2C(vdev);
> > >> -    bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
> > >> -
> > >> -    if (!vdev->vm_running) {
> > >> -        should_start = false;
> > >> -    }
> > >> +    bool should_start = virtio_device_started(vdev, status);
> > >>  
> > >>      if (i2c->vhost_dev.started == should_start) {
> > >>          return;
> > >> diff --git a/hw/virtio/vhost-user-rng.c b/hw/virtio/vhost-user-rng.c
> > >> index 3a7bf8e32d..a9c1c4bc79 100644
> > >> --- a/hw/virtio/vhost-user-rng.c
> > >> +++ b/hw/virtio/vhost-user-rng.c
> > >> @@ -90,11 +90,7 @@ static void vu_rng_stop(VirtIODevice *vdev)
> > >>  static void vu_rng_set_status(VirtIODevice *vdev, uint8_t status)
> > >>  {
> > >>      VHostUserRNG *rng = VHOST_USER_RNG(vdev);
> > >> -    bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
> > >> -
> > >> -    if (!vdev->vm_running) {
> > >> -        should_start = false;
> > >> -    }
> > >> +    bool should_start = virtio_device_started(vdev, status);
> > >>  
> > >>      if (rng->vhost_dev.started == should_start) {
> > >>          return;
> > >> diff --git a/hw/virtio/vhost-user-vsock.c b/hw/virtio/vhost-user-vsock.c
> > >> index 0f8ff99f85..22c1616ebd 100644
> > >> --- a/hw/virtio/vhost-user-vsock.c
> > >> +++ b/hw/virtio/vhost-user-vsock.c
> > >> @@ -55,11 +55,7 @@ const VhostDevConfigOps vsock_ops = {
> > >>  static void vuv_set_status(VirtIODevice *vdev, uint8_t status)
> > >>  {
> > >>      VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev);
> > >> -    bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
> > >> -
> > >> -    if (!vdev->vm_running) {
> > >> -        should_start = false;
> > >> -    }
> > >> +    bool should_start = virtio_device_started(vdev, status);
> > >>  
> > >>      if (vvc->vhost_dev.started == should_start) {
> > >>          return;
> > >> diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c
> > >> index 0338de892f..8031c164a5 100644
> > >> --- a/hw/virtio/vhost-vsock.c
> > >> +++ b/hw/virtio/vhost-vsock.c
> > >> @@ -70,13 +70,9 @@ static int vhost_vsock_set_running(VirtIODevice *vdev, int start)
> > >>  static void vhost_vsock_set_status(VirtIODevice *vdev, uint8_t status)
> > >>  {
> > >>      VHostVSockCommon *vvc = VHOST_VSOCK_COMMON(vdev);
> > >> -    bool should_start = status & VIRTIO_CONFIG_S_DRIVER_OK;
> > >> +    bool should_start = virtio_device_started(vdev, status);
> > >>      int ret;
> > >>  
> > >> -    if (!vdev->vm_running) {
> > >> -        should_start = false;
> > >> -    }
> > >> -
> > >>      if (vvc->vhost_dev.started == should_start) {
> > >>          return;
> > >>      }
> > >> -- 
> > >> 2.30.2
> > 
> > 
> > -- 
> > Alex Bennée


  reply	other threads:[~2022-11-03 21:36 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-02  9:49 [PATCH v4 for 7.2 00/22] virtio-gpio and various virtio cleanups Alex Bennée
2022-08-02  9:49 ` [PATCH v4 01/22] hw/virtio: incorporate backend features in features Alex Bennée
2022-09-22 21:58   ` Philippe Mathieu-Daudé via
2022-08-02  9:49 ` [PATCH v4 02/22] hw/virtio: gracefully handle unset vhost_dev vdev Alex Bennée
2022-09-22 21:59   ` Philippe Mathieu-Daudé via
2022-08-02  9:49 ` [PATCH v4 03/22] hw/virtio: handle un-configured shutdown in virtio-pci Alex Bennée
2022-08-02  9:49 ` [PATCH v4 04/22] hw/virtio: fix vhost_user_read tracepoint Alex Bennée
2022-08-02  9:49 ` [PATCH v4 05/22] include/hw/virtio: more comment for VIRTIO_F_BAD_FEATURE Alex Bennée
2022-08-02  9:49 ` [PATCH v4 06/22] include/hw: document vhost_dev feature life-cycle Alex Bennée
2022-09-22 22:01   ` Philippe Mathieu-Daudé via
2022-08-02  9:49 ` [PATCH v4 07/22] hw/virtio: fix some coding style issues Alex Bennée
2022-09-22 22:01   ` Philippe Mathieu-Daudé via
2022-08-02  9:49 ` [PATCH v4 08/22] hw/virtio: log potentially buggy guest drivers Alex Bennée
2022-08-02  9:49 ` [PATCH v4 09/22] hw/virtio: add some vhost-user trace events Alex Bennée
2022-09-22 22:01   ` Philippe Mathieu-Daudé via
2022-08-02  9:49 ` [PATCH v4 10/22] hw/virtio: move vm_running check to virtio_device_started Alex Bennée
2022-08-02  9:49   ` [Virtio-fs] " Alex Bennée
2022-11-03 16:39   ` Michael S. Tsirkin
2022-11-03 16:39     ` [Virtio-fs] " Michael S. Tsirkin
2022-11-03 19:18     ` Alex Bennée
2022-11-03 19:18       ` [Virtio-fs] " Alex Bennée
2022-11-03 20:30       ` Michael S. Tsirkin
2022-11-03 20:30         ` [Virtio-fs] " Michael S. Tsirkin
2022-11-03 21:35         ` Michael S. Tsirkin [this message]
2022-11-03 21:35           ` Michael S. Tsirkin
2022-11-04  7:18           ` Michael S. Tsirkin
2022-11-04  7:18             ` [Virtio-fs] " Michael S. Tsirkin
2022-08-02  9:49 ` [PATCH v4 11/22] hw/virtio: move vhd->started check into helper and add FIXME Alex Bennée
2022-08-02  9:49   ` [Virtio-fs] " Alex Bennée
2022-08-07 20:13   ` Raphael Norwitz
2022-08-07 20:13     ` [Virtio-fs] " Raphael Norwitz
2022-11-03 16:39   ` Michael S. Tsirkin
2022-11-03 16:39     ` [Virtio-fs] " Michael S. Tsirkin
2022-08-02  9:50 ` [PATCH v4 12/22] hw/virtio: add boilerplate for vhost-user-gpio device Alex Bennée
2022-08-02  9:50 ` [PATCH v4 13/22] hw/virtio: add vhost-user-gpio-pci boilerplate Alex Bennée
2022-08-02  9:50 ` [PATCH v4 14/22] tests/qtest: pass stdout/stderr down to subtests Alex Bennée
2022-08-02  9:50 ` [PATCH v4 15/22] tests/qtest: add a timeout for subprocess_run_one_test Alex Bennée
2022-09-22 22:03   ` Philippe Mathieu-Daudé via
2022-08-02  9:50 ` [PATCH v4 16/22] tests/qtest: use qos_printf instead of g_test_message Alex Bennée
2022-08-02  9:50 ` [PATCH v4 17/22] tests/qtest: catch unhandled vhost-user messages Alex Bennée
2022-08-02  9:50 ` [PATCH v4 18/22] tests/qtest: plain g_assert for VHOST_USER_F_PROTOCOL_FEATURES Alex Bennée
2022-08-02  9:50 ` [PATCH v4 19/22] tests/qtest: add assert to catch bad features Alex Bennée
2022-08-02  9:50 ` [PATCH v4 20/22] tests/qtest: implement stub for VHOST_USER_GET_CONFIG Alex Bennée
2022-08-02  9:50 ` [PATCH v4 21/22] tests/qtest: add a get_features op to vhost-user-test Alex Bennée
2022-08-02  9:50 ` [PATCH v4 22/22] tests/qtest: enable tests for virtio-gpio Alex Bennée
2022-09-16  6:51 ` [PATCH v4 for 7.2 00/22] virtio-gpio and various virtio cleanups Alex Bennée
2022-09-19 16:39   ` Stefan Hajnoczi
2022-09-20 11:30     ` Alex Bennée
2022-09-20 18:25       ` Stefan Hajnoczi
2022-09-20 19:10         ` Michael S. Tsirkin
2022-09-20 21:18           ` Alex Bennée

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=20221103173542-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=dgilbert@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mathieu.poirier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=slp@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=viresh.kumar@linaro.org \
    --cc=virtio-fs@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 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.