From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Viresh Kumar" <viresh.kumar@linaro.org>,
"Raphael Norwitz" <raphael.norwitz@nutanix.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
qemu-block@nongnu.org, "Eric Blake" <eblake@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
"Kevin Wolf" <kwolf@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Mathieu Poirier" <mathieu.poirier@linaro.org>,
"Hanna Reitz" <hreitz@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Erik Schilling" <erik.schilling@linaro.org>,
"Gonglei (Arei)" <arei.gonglei@huawei.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Fam Zheng" <fam@euphon.net>,
virtio-fs@redhat.com, "Stefan Hajnoczi" <stefanha@redhat.com>
Subject: [RFC PATCH v3 19/20] hw/virtio: probe backend for specs if it supports it
Date: Mon, 10 Jul 2023 16:35:21 +0100 [thread overview]
Message-ID: <20230710153522.3469097-20-alex.bennee@linaro.org> (raw)
In-Reply-To: <20230710153522.3469097-1-alex.bennee@linaro.org>
Now we have detected and validated the protocol support lets do the
probe. The empty state indicates no probe took place.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
include/hw/virtio/vhost.h | 12 +++++++
hw/virtio/vhost-user.c | 73 +++++++++++++++++++++++++++++++++++----
hw/virtio/vhost.c | 2 +-
3 files changed, 79 insertions(+), 8 deletions(-)
diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h
index 912706668a..1d8de1c558 100644
--- a/include/hw/virtio/vhost.h
+++ b/include/hw/virtio/vhost.h
@@ -68,6 +68,13 @@ typedef struct VhostDevConfigOps {
struct vhost_memory;
+typedef struct VhostUserBackendSpecs {
+ uint32_t device_id;
+ uint32_t config_size;
+ uint32_t min_vqs;
+ uint32_t max_vqs;
+} VhostUserBackendSpecs;
+
/**
* struct vhost_dev - common vhost_dev structure
* @vhost_ops: backend specific ops
@@ -107,11 +114,15 @@ struct vhost_dev {
* VHOST_USER_SET_FEATURES or VHOST_NET_F_VIRTIO_NET_HDR. Its
* future use should be discouraged and the variable retired as
* its easy to confuse with the VirtIO backend_features.
+ *
+ * @specs: the results of a GET_BACKEND_SPECS probe.
*/
uint64_t features;
uint64_t acked_features;
uint64_t backend_features;
+ VhostUserBackendSpecs specs;
+
/**
* @protocol_features: is the vhost-user only feature set by
* VHOST_USER_SET_PROTOCOL_FEATURES. Protocol features are only
@@ -134,6 +145,7 @@ struct vhost_dev {
QLIST_HEAD(, vhost_iommu) iommu_list;
IOMMUNotifier n;
const VhostDevConfigOps *config_ops;
+
};
extern const VhostOps kernel_ops;
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 3116b3e46a..36aa4ec2d5 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -123,6 +123,7 @@ typedef enum VhostUserRequest {
VHOST_USER_REM_MEM_REG = 38,
VHOST_USER_SET_STATUS = 39,
VHOST_USER_GET_STATUS = 40,
+ VHOST_USER_GET_BACKEND_SPECS = 41,
VHOST_USER_MAX
} VhostUserRequest;
@@ -204,13 +205,6 @@ typedef struct VhostUserInflight {
uint16_t queue_size;
} VhostUserInflight;
-typedef struct VhostUserBackendSpecs {
- uint32_t device_id;
- uint32_t config_size;
- uint32_t min_vqs;
- uint32_t max_vqs;
-} VhostUserBackendSpecs;
-
typedef struct {
VhostUserRequest request;
@@ -1991,6 +1985,56 @@ static int vhost_user_postcopy_notifier(NotifierWithReturn *notifier,
return 0;
}
+static bool vhost_user_get_backend_specs(struct vhost_dev *dev, Error **errp)
+{
+ int ret;
+ VhostUserMsg msg = {
+ .hdr.request = VHOST_USER_GET_BACKEND_SPECS,
+ .hdr.flags = VHOST_USER_VERSION,
+ .hdr.size = VHOST_USER_HDR_SIZE,
+ };
+
+ if (!virtio_has_feature(dev->protocol_features,
+ VHOST_USER_PROTOCOL_F_STANDALONE)) {
+ error_setg(errp, "VHOST_USER_PROTOCOL_F_STANDALONE not supported");
+ return -EINVAL;
+ }
+
+ ret = vhost_user_write(dev, &msg, NULL, 0);
+ if (ret < 0) {
+ error_setg_errno(errp, -ret, "vhost_get_backend send failed");
+ return ret;
+ }
+
+ ret = vhost_user_read(dev, &msg);
+ if (ret < 0) {
+ error_setg_errno(errp, -ret, "vhost_get_backend recv failed");
+ return ret;
+ }
+
+ if (msg.hdr.request != VHOST_USER_GET_BACKEND_SPECS) {
+ error_setg(errp,
+ "Received unexpected msg type. Expected %d received %d",
+ VHOST_USER_GET_BACKEND_SPECS, msg.hdr.request);
+ return -EPROTO;
+ }
+
+ if (msg.hdr.size != sizeof(msg.payload.specs)) {
+ error_setg(errp, "Received bad msg size.");
+ return -EPROTO;
+ }
+
+ if (msg.payload.specs.config_size && !virtio_has_feature(dev->protocol_features,
+ VHOST_USER_PROTOCOL_F_CONFIG)) {
+ error_setg(errp, "VHOST_USER_PROTOCOL_F_CONFIG not supported");
+ return -EPROTO;
+ }
+
+ dev->specs = msg.payload.specs;
+
+ return 0;
+}
+
static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque,
Error **errp)
{
@@ -2073,6 +2117,21 @@ static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque,
return -EPROTO;
}
+ if (dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_STANDALONE)) {
+ err = vhost_user_get_backend_specs(dev, errp);
+ if (err < 0) {
+ error_setg_errno(errp, EPROTO, "vhost_get_backend_specs failed");
+ return -EPROTO;
+ }
+ /*
+ * If this was never set by the user we can now fill it in
+ * so we can continue the initialisation
+ */
+ if (!dev->nvqs) {
+ dev->nvqs = dev->specs.min_vqs;
+ }
+ }
+
/* query the max queues we support if backend supports Multiple Queue */
if (dev->protocol_features & (1ULL << VHOST_USER_PROTOCOL_F_MQ)) {
err = vhost_user_get_u64(dev, VHOST_USER_GET_QUEUE_NUM,
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 4c73ced3b7..d14467aa1c 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -1450,7 +1450,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaque,
}
/* Skip if we don't yet have number of vqs */
- if (hdev->vqs && hdev->nvqs) {
+ if (hdev->nvqs) {
if (!vhost_init_virtqs(hdev, busyloop_timeout, errp)) {
goto fail_busyloop;
}
--
2.39.2
next prev parent reply other threads:[~2023-07-10 15:38 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-10 15:35 [PATCH v3 00/20] virtio: add vhost-user-generic, reduce c&p and support standalone Alex Bennée
2023-07-10 15:35 ` [PATCH v3 01/20] include: attempt to document device_class_set_props Alex Bennée
2023-07-10 15:35 ` [PATCH v3 02/20] include/hw: document the device_class_set_parent_* fns Alex Bennée
2023-07-10 15:35 ` [PATCH v3 03/20] hw/virtio: fix typo in VIRTIO_CONFIG_IRQ_IDX comments Alex Bennée
2023-07-10 21:56 ` Philippe Mathieu-Daudé
2023-07-10 15:35 ` [PATCH v3 04/20] include/hw/virtio: document virtio_notify_config Alex Bennée
2023-07-10 15:35 ` [PATCH v3 05/20] include/hw/virtio: add kerneldoc for virtio_init Alex Bennée
2023-07-10 21:58 ` Philippe Mathieu-Daudé
2023-07-10 15:35 ` [PATCH v3 06/20] include/hw/virtio: document some more usage of notifiers Alex Bennée
2023-07-10 15:35 ` [PATCH v3 07/20] virtio: add vhost-user-base and a generic vhost-user-device Alex Bennée
2023-07-10 20:15 ` Michael S. Tsirkin
2023-09-05 14:19 ` Matias Ezequiel Vara Larsen
2023-09-05 17:01 ` Alex Bennée
2023-09-06 9:21 ` Matias Ezequiel Vara Larsen
2023-07-10 15:35 ` [PATCH v3 08/20] virtio: add PCI stub for vhost-user-device Alex Bennée
2023-07-10 15:35 ` [PATCH v3 09/20] hw/virtio: derive vhost-user-rng from vhost-user-device Alex Bennée
2023-07-10 15:35 ` [PATCH v3 10/20] hw/virtio: add config support to vhost-user-device Alex Bennée
2023-07-10 19:58 ` Michael S. Tsirkin
2023-08-31 14:23 ` Albert Esteve
2023-08-31 15:47 ` Alex Bennée
2023-09-01 5:56 ` Erik Schilling
2023-09-01 8:34 ` Albert Esteve
2023-07-10 15:35 ` [PATCH v3 11/20] hw/virtio: derive vhost-user-gpio from vhost-user-device Alex Bennée
2023-07-10 15:35 ` [PATCH v3 12/20] hw/virtio: derive vhost-user-i2c from vhost-user-base Alex Bennée
2023-07-10 15:35 ` [RFC PATCH v3 13/20] docs/system: add a basic enumeration of vhost-user devices Alex Bennée
2023-07-10 15:35 ` [RFC PATCH v3 14/20] docs/interop: define STANDALONE protocol feature for vhost-user Alex Bennée
2023-07-10 15:35 ` [RFC PATCH v3 15/20] hw/virtio: move vhost_user_init earlier Alex Bennée
2023-07-10 15:35 ` [RFC PATCH v3 16/20] hw/virtio: move virtq initialisation into internal helper Alex Bennée
2023-07-10 15:35 ` [RFC PATCH v3 17/20] hw/virtio: push down allocation responsibility for vhost_dev->vqs Alex Bennée
2023-07-10 15:35 ` [RFC PATCH v3 18/20] hw/virtio: validate F_STANDALONE also supports other protocol features Alex Bennée
2023-07-10 15:35 ` Alex Bennée [this message]
2023-07-10 15:35 ` [RFC PATCH v3 20/20] hw/virtio: allow vhost-user-device to be driven by backend Alex Bennée
2023-09-01 10:00 ` Albert Esteve
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=20230710153522.3469097-20-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=arei.gonglei@huawei.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=eduardo@habkost.net \
--cc=erik.schilling@linaro.org \
--cc=fam@euphon.net \
--cc=hreitz@redhat.com \
--cc=jasowang@redhat.com \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=mathieu.poirier@linaro.org \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=raphael.norwitz@nutanix.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 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).