From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"Hanna Czenczek" <hreitz@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Stefano Garzarella" <sgarzare@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Gonglei (Arei)" <arei.gonglei@huawei.com>
Subject: [PULL 01/18] virtio: Allow .get_vhost() without vhost_started
Date: Wed, 11 Sep 2024 09:51:25 -0400 [thread overview]
Message-ID: <00adced5c3166ee65b6880b48c1e0826b7304f76.1726062663.git.mst@redhat.com> (raw)
In-Reply-To: <cover.1726062663.git.mst@redhat.com>
From: Hanna Czenczek <hreitz@redhat.com>
Historically, .get_vhost() was probably only called when
vdev->vhost_started is true. However, we now decidedly want to call it
also when vhost_started is false, specifically so we can issue a reset
to the vhost back-end while device operation is stopped.
Some .get_vhost() implementations dereference some pointers (or return
offsets from them) that are probably guaranteed to be non-NULL when
vhost_started is true, but not necessarily otherwise. This patch makes
all such implementations check all such pointers, returning NULL if any
is NULL.
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
Message-Id: <20240723163941.48775-2-hreitz@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
include/hw/virtio/virtio.h | 1 +
hw/display/vhost-user-gpu.c | 2 +-
hw/net/virtio-net.c | 19 +++++++++++++++++--
hw/virtio/virtio-crypto.c | 18 +++++++++++++++---
4 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 0fcbc5c0c6..f526ecc8fc 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -223,6 +223,7 @@ struct VirtioDeviceClass {
int (*post_load)(VirtIODevice *vdev);
const VMStateDescription *vmsd;
bool (*primary_unplug_pending)(void *opaque);
+ /* May be called even when vdev->vhost_started is false */
struct vhost_dev *(*get_vhost)(VirtIODevice *vdev);
void (*toggle_device_iotlb)(VirtIODevice *vdev);
};
diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c
index c0c66910f1..14548f1a57 100644
--- a/hw/display/vhost-user-gpu.c
+++ b/hw/display/vhost-user-gpu.c
@@ -642,7 +642,7 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error **errp)
static struct vhost_dev *vhost_user_gpu_get_vhost(VirtIODevice *vdev)
{
VhostUserGPU *g = VHOST_USER_GPU(vdev);
- return &g->vhost->dev;
+ return g->vhost ? &g->vhost->dev : NULL;
}
static Property vhost_user_gpu_properties[] = {
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index ed33a32877..fb84d142ee 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -3896,8 +3896,23 @@ static bool dev_unplug_pending(void *opaque)
static struct vhost_dev *virtio_net_get_vhost(VirtIODevice *vdev)
{
VirtIONet *n = VIRTIO_NET(vdev);
- NetClientState *nc = qemu_get_queue(n->nic);
- struct vhost_net *net = get_vhost_net(nc->peer);
+ NetClientState *nc;
+ struct vhost_net *net;
+
+ if (!n->nic) {
+ return NULL;
+ }
+
+ nc = qemu_get_queue(n->nic);
+ if (!nc) {
+ return NULL;
+ }
+
+ net = get_vhost_net(nc->peer);
+ if (!net) {
+ return NULL;
+ }
+
return &net->dev;
}
diff --git a/hw/virtio/virtio-crypto.c b/hw/virtio/virtio-crypto.c
index 5034768bff..0793f56965 100644
--- a/hw/virtio/virtio-crypto.c
+++ b/hw/virtio/virtio-crypto.c
@@ -1247,9 +1247,21 @@ static bool virtio_crypto_guest_notifier_pending(VirtIODevice *vdev, int idx)
static struct vhost_dev *virtio_crypto_get_vhost(VirtIODevice *vdev)
{
VirtIOCrypto *vcrypto = VIRTIO_CRYPTO(vdev);
- CryptoDevBackend *b = vcrypto->cryptodev;
- CryptoDevBackendClient *cc = b->conf.peers.ccs[0];
- CryptoDevBackendVhost *vhost_crypto = cryptodev_get_vhost(cc, b, 0);
+ CryptoDevBackend *b;
+ CryptoDevBackendClient *cc;
+ CryptoDevBackendVhost *vhost_crypto;
+
+ b = vcrypto->cryptodev;
+ if (!b) {
+ return NULL;
+ }
+
+ cc = b->conf.peers.ccs[0];
+ vhost_crypto = cryptodev_get_vhost(cc, b, 0);
+ if (!vhost_crypto) {
+ return NULL;
+ }
+
return &vhost_crypto->dev;
}
--
MST
next prev parent reply other threads:[~2024-09-11 14:32 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-11 13:51 [PULL 00/18] virtio,pc,pci: features, fixes, cleanups Michael S. Tsirkin
2024-09-11 13:51 ` Michael S. Tsirkin [this message]
2024-09-11 13:51 ` [PULL 02/18] virtio: Always reset vhost devices Michael S. Tsirkin
2024-09-11 13:51 ` [PULL 03/18] hw: Move declaration of IRQState to header and add init function Michael S. Tsirkin
2024-09-11 13:51 ` [PULL 04/18] hw/isa/vt82c686.c: Embed i8259 irq in device state instead of allocating Michael S. Tsirkin
2024-09-11 13:51 ` [PULL 05/18] pci: don't skip function 0 occupancy verification for devfn auto assign Michael S. Tsirkin
2024-09-11 13:51 ` [PULL 06/18] hw/pci/pci-hmp-cmds: Avoid displaying bogus size in 'info pci' Michael S. Tsirkin
2024-09-11 13:51 ` [PULL 07/18] virtio: rename virtio_split_packed_update_used_idx Michael S. Tsirkin
2024-09-11 13:51 ` [PULL 08/18] intel_iommu: Fix invalidation descriptor type field Michael S. Tsirkin
2024-09-11 13:51 ` [PULL 09/18] intel_iommu: Make PASID-cache and PIOTLB type invalid in legacy mode Michael S. Tsirkin
2024-09-11 13:51 ` [PULL 10/18] tests/acpi: pc: allow DSDT acpi table changes Michael S. Tsirkin
2024-09-11 13:51 ` [PULL 11/18] hw/i386/acpi-build: Return a pre-computed _PRT table Michael S. Tsirkin
2024-09-11 13:52 ` [PULL 12/18] tests/acpi: pc: update golden masters for DSDT Michael S. Tsirkin
2024-09-11 13:52 ` [PULL 13/18] vhost_net: configure all host notifiers in a single MR transaction Michael S. Tsirkin
2024-09-11 13:52 ` [PULL 14/18] virtio-pci: Add lookup subregion of VirtIOPCIRegion MR Michael S. Tsirkin
2024-09-17 20:19 ` Peter Xu
2024-09-11 13:52 ` [PULL 15/18] hw/cxl: fix physical address field in get scan media results output Michael S. Tsirkin
2024-09-11 13:52 ` [PULL 16/18] hw/audio/virtio-sound: fix heap buffer overflow Michael S. Tsirkin
2024-09-13 18:47 ` Volker Rümelin
2024-09-11 13:52 ` [PULL 17/18] virtio-mem: don't warn about THP sizes on a kernel without THP support Michael S. Tsirkin
2024-09-11 13:52 ` [PULL 18/18] hw/acpi/ich9: Add periodic and swsmi timer Michael S. Tsirkin
2024-09-13 9:24 ` [PULL 00/18] virtio,pc,pci: features, fixes, cleanups Peter Maydell
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=00adced5c3166ee65b6880b48c1e0826b7304f76.1726062663.git.mst@redhat.com \
--to=mst@redhat.com \
--cc=arei.gonglei@huawei.com \
--cc=hreitz@redhat.com \
--cc=jasowang@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.com \
--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 NNTP newsgroup(s).