From nobody Sun Mar 22 14:10:11 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1774024799; cv=none; d=zohomail.com; s=zohoarc; b=nP7nkGaBggxLksBAt9prQZlN8nGkFQMD3QvK1/f6O1m+/TACYB7N2KyUtok7saA6njJFaESmcmZ5QM6ryWPWceTGraqi6NzxXsCrl2BV4Z0w+MUEjFI3Vj0a1yMcqyc/H5d3xrdShF2snH/3FLgROcu4FANfme0Ha9ydR3kZil0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774024799; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ojVgpHPdozufTm2eUCtk3vbv6e1CEZRkZVvHlIrz0JI=; b=RmKZpc0cfMMqOGa88OOe5skCGiQ6F68ZlHsOuYu2jOokgVb4lT02+81DyutF0kytG9Uus2YCna9WUm1lWUQlYacnlqosUvQ6lkOTZhTTNYQ57KEvgxTXb7ilAblT4Q5w1vfmVmuYdoE51rfiwrDzlcwBYEaF7Tj6yOGhf7MG9X0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1774024799697418.6086901723429; Fri, 20 Mar 2026 09:39:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w3csb-0003IL-36; Fri, 20 Mar 2026 12:39:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w3csG-0003He-JA for qemu-devel@nongnu.org; Fri, 20 Mar 2026 12:39:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w3cs9-0006P5-3h for qemu-devel@nongnu.org; Fri, 20 Mar 2026 12:38:56 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-93-04JXGDxbO2enli6-BCpruA-1; Fri, 20 Mar 2026 12:38:48 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2FF98195609D for ; Fri, 20 Mar 2026 16:38:48 +0000 (UTC) Received: from lenovo-t14s.redhat.com (unknown [10.45.224.233]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 16A1B1800763; Fri, 20 Mar 2026 16:38:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774024730; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ojVgpHPdozufTm2eUCtk3vbv6e1CEZRkZVvHlIrz0JI=; b=e9Psw3N3qKS01L+hoON/ug8flSEZODEn+supIXS4jRY9gIFD6dmTqQ/X37Srk14KQqeHhw fsNecdfo4C/P/iY1vLcuk5hRMcXejiNL2B9T5ubmVnv/2+HD12lhBBhO2nHVkAB7R/FYCN uvbpRaa3afLHaoEh2S4AjRUBYvA8hAI= X-MC-Unique: 04JXGDxbO2enli6-BCpruA-1 X-Mimecast-MFC-AGG-ID: 04JXGDxbO2enli6-BCpruA_1774024728 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Jason Wang , "Michael S. Tsirkin" , Stefano Garzarella , Laurent Vivier Subject: [PATCH] virtio-net: allow vhost-user backends to provide config space Date: Fri, 20 Mar 2026 17:38:44 +0100 Message-ID: <20260320163844.754762-1-lvivier@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=lvivier@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1774024802550158500 Content-Type: text/plain; charset="utf-8" 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 --- 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, u= int64_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; } =20 void vhost_net_ack_features_ex(struct vhost_net *net, const uint64_t *feat= ures) 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, u= int64_t *features) int vhost_net_get_config(struct vhost_net *net, uint8_t *config, uint32_t config_len) { + if (net =3D=3D 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 =3D=3D NULL) { + return -EINVAL; + } + return vhost_dev_set_config(&net->dev, data, offset, size, flags); } =20 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); =20 - /* - * 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 =3D=3D NET_CLIENT_DRIVER_VHOST_VD= PA) { - ret =3D vhost_net_get_config(get_vhost_net(nc->peer), (uint8_t *)&= netcfg, - n->config_size); - if (ret =3D=3D -1) { - return; - } - + ret =3D vhost_net_get_config(get_vhost_net(nc->peer), (uint8_t *)&netc= fg, + n->config_size); + if (ret >=3D 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); } =20 - /* - * 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 =3D=3D NET_CLIENT_DRIVER_VHOST_VD= PA) { - 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); } =20 static bool virtio_net_started(VirtIONet *n, uint8_t status) @@ -3868,6 +3854,7 @@ static void virtio_net_device_realize(DeviceState *de= v, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VirtIONet *n =3D VIRTIO_NET(dev); + struct virtio_net_config netcfg =3D {}; NetClientState *nc; int i; =20 @@ -4023,12 +4010,9 @@ static void virtio_net_device_realize(DeviceState *d= ev, Error **errp) nc =3D qemu_get_queue(n->nic); nc->rxfilter_notify_enabled =3D 1; =20 - if (nc->peer && nc->peer->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDP= A) { - struct virtio_net_config netcfg =3D {}; - 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_FRONTEN= D); - } + 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 =3D dev; =20 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; } =20 - /* - * We will use all the protocol features we support - although - * we suppress F_CONFIG if we know QEMUs internal code can not sup= port - * it. - */ protocol_features &=3D VHOST_USER_PROTOCOL_FEATURE_MASK; =20 - 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-use= r 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 no= t."); - protocol_features &=3D ~(1ULL << VHOST_USER_PROTOCOL_F_CON= FIG); - } + /* + * 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 ba= ckend does " + "not support it."); + return -EPROTO; } =20 if (!u->user->supports_inflight_migration || --=20 2.53.0