Remove the vDPA-only guard on vhost_net_get_config/set_config calls so any vhost backend that negotiates VHOST_USER_PROTOCOL_F_CONFIG can provide device configuration.
To manage backends that don't support vhost_net_get_config/set_config, modify the stubs and vhost_net_get_config/vhost_net_set_config with NULL vhost_net parameter to return -ENOSYS. Until now VHOST_USER_PROTOCOL_F_CONFIG was requisited with the supports_config flag in VhostUserState or ignored, but now stop stripping VHOST_USER_PROTOCOL_F_CONFIG when the device code doesn't explicitly require it, so vhost-user backends that advertise F_CONFIG can negotiate it. Signed-off-by: Laurent Vivier <[email protected]> --- hw/net/vhost_net-stub.c | 4 ++-- hw/net/vhost_net.c | 8 ++++++++ hw/net/virtio-net.c | 36 ++++++++++-------------------------- hw/virtio/vhost-user.c | 31 +++++++++++-------------------- 4 files changed, 31 insertions(+), 48 deletions(-) diff --git a/hw/net/vhost_net-stub.c b/hw/net/vhost_net-stub.c index 0740d5a2ebe6..6edc0a222f3b 100644 --- a/hw/net/vhost_net-stub.c +++ b/hw/net/vhost_net-stub.c @@ -53,12 +53,12 @@ void vhost_net_get_features_ex(struct vhost_net *net, uint64_t *features) int vhost_net_get_config(struct vhost_net *net, uint8_t *config, uint32_t config_len) { - return 0; + return -ENOSYS; } int vhost_net_set_config(struct vhost_net *net, const uint8_t *data, uint32_t offset, uint32_t size, uint32_t flags) { - return 0; + return -ENOSYS; } void vhost_net_ack_features_ex(struct vhost_net *net, const uint64_t *features) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index a8ee18a91266..13f926b5cfb6 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -42,11 +42,19 @@ void vhost_net_get_features_ex(struct vhost_net *net, uint64_t *features) int vhost_net_get_config(struct vhost_net *net, uint8_t *config, uint32_t config_len) { + if (net == NULL) { + return -EINVAL; + } + return vhost_dev_get_config(&net->dev, config, config_len, NULL); } int vhost_net_set_config(struct vhost_net *net, const uint8_t *data, uint32_t offset, uint32_t size, uint32_t flags) { + if (net == NULL) { + return -EINVAL; + } + return vhost_dev_set_config(&net->dev, data, offset, size, flags); } diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 2a5d642a6476..7ad2dac450d9 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -180,17 +180,9 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) n->rss_data.supported_hash_types); memcpy(config, &netcfg, n->config_size); - /* - * Is this VDPA? No peer means not VDPA: there's no way to - * disconnect/reconnect a VDPA peer. - */ - if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) { - ret = vhost_net_get_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg, - n->config_size); - if (ret == -1) { - return; - } - + ret = vhost_net_get_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg, + n->config_size); + if (ret >= 0) { /* * Some NIC/kernel combinations present 0 as the mac address. As that * is not a legal address, try to proceed with the address from the @@ -223,15 +215,9 @@ static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config) qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac); } - /* - * Is this VDPA? No peer means not VDPA: there's no way to - * disconnect/reconnect a VDPA peer. - */ - if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) { - vhost_net_set_config(get_vhost_net(nc->peer), - (uint8_t *)&netcfg, 0, n->config_size, - VHOST_SET_CONFIG_TYPE_FRONTEND); - } + vhost_net_set_config(get_vhost_net(nc->peer), + (uint8_t *)&netcfg, 0, n->config_size, + VHOST_SET_CONFIG_TYPE_FRONTEND); } static bool virtio_net_started(VirtIONet *n, uint8_t status) @@ -3868,6 +3854,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtIONet *n = VIRTIO_NET(dev); + struct virtio_net_config netcfg = {}; NetClientState *nc; int i; @@ -4023,12 +4010,9 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) nc = qemu_get_queue(n->nic); nc->rxfilter_notify_enabled = 1; - if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) { - struct virtio_net_config netcfg = {}; - memcpy(&netcfg.mac, &n->nic_conf.macaddr, ETH_ALEN); - vhost_net_set_config(get_vhost_net(nc->peer), - (uint8_t *)&netcfg, 0, ETH_ALEN, VHOST_SET_CONFIG_TYPE_FRONTEND); - } + memcpy(&netcfg.mac, &n->nic_conf.macaddr, ETH_ALEN); + vhost_net_set_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg, 0, + ETH_ALEN, VHOST_SET_CONFIG_TYPE_FRONTEND); QTAILQ_INIT(&n->rsc_chains); n->qdev = dev; diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index a8907cca74ec..2c310403851f 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -2196,28 +2196,19 @@ static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque, return -EPROTO; } - /* - * We will use all the protocol features we support - although - * we suppress F_CONFIG if we know QEMUs internal code can not support - * it. - */ protocol_features &= VHOST_USER_PROTOCOL_FEATURE_MASK; - if (supports_f_config) { - if (!virtio_has_feature(protocol_features, - VHOST_USER_PROTOCOL_F_CONFIG)) { - error_setg(errp, "vhost-user device expecting " - "VHOST_USER_PROTOCOL_F_CONFIG but the vhost-user backend does " - "not support it."); - return -EPROTO; - } - } else { - if (virtio_has_feature(protocol_features, - VHOST_USER_PROTOCOL_F_CONFIG)) { - warn_report("vhost-user backend supports " - "VHOST_USER_PROTOCOL_F_CONFIG but QEMU does not."); - protocol_features &= ~(1ULL << VHOST_USER_PROTOCOL_F_CONFIG); - } + /* + * Fail if vhost-user device expects F_CONFIG but backend doesn't + * provide it. Otherwise negotiate as usual. + */ + if (supports_f_config && + !virtio_has_feature(protocol_features, + VHOST_USER_PROTOCOL_F_CONFIG)) { + error_setg(errp, "vhost-user device expecting " + "VHOST_USER_PROTOCOL_F_CONFIG but the vhost-user backend does " + "not support it."); + return -EPROTO; } if (!u->user->supports_inflight_migration || -- 2.53.0
