From nobody Sun Dec 14 08:05:25 2025 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=1752239284; cv=none; d=zohomail.com; s=zohoarc; b=Bh7Fjwv/FB2yC5ZTK0gj4dUg1JFIeOpIpIIIjnXqe4napr5ghMsDkKWrEmxBByqZNbBmJXpjMlDNwIMVQdVzgWu/jElmqJQ8KH8TioM9YSu2yqb8rxB+3Ikk1RlaDRxYkTfxVsXg18kXRtCjvemKzUdvLLu6ADu7og4e0Y0pJb4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752239284; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=32lZPJFOdTlazqMfP+4COXRGoU2Ht4q+BadMeycbCg0=; b=IuLz/5Nbhnsdw56eJq9lWh//+FkNYQQAJ05n4JTD6sWLJziuFSJgy1OpolFBBaklNxQc9cAgl42ud2vmARV0Qp3f3yAb5ladwUjkT4t+s1UTvat0kTFXNNik4E+x9FNaNgFrN/N97nPJz2jgJBtzYpXun/iOf5dptrLf8qS1Kkg= 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 1752239284957685.6713727811119; Fri, 11 Jul 2025 06:08:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uaDSY-0004gy-OO; Fri, 11 Jul 2025 09:06:38 -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 1uaDPz-0000ll-67 for qemu-devel@nongnu.org; Fri, 11 Jul 2025 09:04:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uaDPx-0004A3-5f for qemu-devel@nongnu.org; Fri, 11 Jul 2025 09:03:58 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-136-eqARMib3Na28K_UUr0ZYHQ-1; Fri, 11 Jul 2025 09:03:51 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 88FBC1808984; Fri, 11 Jul 2025 13:03:49 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.44.33.145]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BFD7D19560B6; Fri, 11 Jul 2025 13:03:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752239036; 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: in-reply-to:in-reply-to:references:references; bh=32lZPJFOdTlazqMfP+4COXRGoU2Ht4q+BadMeycbCg0=; b=Lf6jS8DIOtzDVCObtezGWRs63/UrxfzwL8qB1jqP+O7NYK+vW3hkLNbnUDQaQUcE4qXdti nCjBc1A2Ztne+zyUcHrfwQN/nqsbsa1m7Zbcrnvfc2SMX07XFndGQ2FXiB4BAYy5gvKAxb fyqYZQJO/hPZOmKDsLH3GAYwCMnrWb8= X-MC-Unique: eqARMib3Na28K_UUr0ZYHQ-1 X-Mimecast-MFC-AGG-ID: eqARMib3Na28K_UUr0ZYHQ_1752239029 From: Paolo Abeni To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Dmitry Fleytman , Akihiko Odaki , Jason Wang , Sriram Yagnaraman , "Michael S. Tsirkin" , Stefano Garzarella , Cornelia Huck , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Eric Blake , Markus Armbruster , kvm@vger.kernel.org Subject: [PATCH RFC v2 10/13] vhost-net: implement extended features support Date: Fri, 11 Jul 2025 15:02:15 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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.133.124; envelope-from=pabeni@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: 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: 1752239285614116600 Content-Type: text/plain; charset="utf-8" Provide extended version of the features manipulation helpers, and let the device initialization deal with the full features space, adjusting the relevant format strings accordingly. Signed-off-by: Paolo Abeni --- v1 -> v2: - uint128_t -> uint64_t[] - provide extended variant of the features manipulation helpers --- hw/net/vhost_net-stub.c | 8 +++---- hw/net/vhost_net.c | 48 +++++++++++++++++++++++------------------ include/net/vhost_net.h | 33 +++++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 29 deletions(-) diff --git a/hw/net/vhost_net-stub.c b/hw/net/vhost_net-stub.c index 72df6d757e..f20b8a216d 100644 --- a/hw/net/vhost_net-stub.c +++ b/hw/net/vhost_net-stub.c @@ -47,9 +47,8 @@ void vhost_net_cleanup(struct vhost_net *net) { } =20 -uint64_t vhost_net_get_features(struct vhost_net *net, uint64_t features) +void vhost_net_get_features_ex(struct vhost_net *net, uint64_t *features) { - return features; } =20 int vhost_net_get_config(struct vhost_net *net, uint8_t *config, @@ -63,13 +62,12 @@ int vhost_net_set_config(struct vhost_net *net, const u= int8_t *data, return 0; } =20 -void vhost_net_ack_features(struct vhost_net *net, uint64_t features) +void vhost_net_ack_features_ex(struct vhost_net *net, const uint64_t *feat= ures) { } =20 -uint64_t vhost_net_get_acked_features(VHostNetState *net) +void vhost_net_get_acked_features_ex(VHostNetState *net, uint64_t *feature= s) { - return 0; } =20 bool vhost_net_virtqueue_pending(VHostNetState *net, int idx) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 891f235a0a..bae595607a 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -121,10 +121,9 @@ static const int *vhost_net_get_feature_bits(struct vh= ost_net *net) return feature_bits; } =20 -uint64_t vhost_net_get_features(struct vhost_net *net, uint64_t features) +void vhost_net_get_features_ex(struct vhost_net *net, uint64_t *features) { - return vhost_get_features(&net->dev, vhost_net_get_feature_bits(net), - features); + vhost_get_features_ex(&net->dev, vhost_net_get_feature_bits(net), feat= ures); } int vhost_net_get_config(struct vhost_net *net, uint8_t *config, uint32_t config_len) @@ -137,10 +136,11 @@ int vhost_net_set_config(struct vhost_net *net, const= uint8_t *data, return vhost_dev_set_config(&net->dev, data, offset, size, flags); } =20 -void vhost_net_ack_features(struct vhost_net *net, uint64_t features) +void vhost_net_ack_features_ex(struct vhost_net *net, const uint64_t *feat= ures) { - net->dev.acked_features =3D net->dev.backend_features; - vhost_ack_features(&net->dev, vhost_net_get_feature_bits(net), feature= s); + virtio_features_copy(net->dev.acked_features_array, + net->dev.backend_features_array); + vhost_ack_features_ex(&net->dev, vhost_net_get_feature_bits(net), feat= ures); } =20 uint64_t vhost_net_get_max_queues(VHostNetState *net) @@ -148,9 +148,9 @@ uint64_t vhost_net_get_max_queues(VHostNetState *net) return net->dev.max_queues; } =20 -uint64_t vhost_net_get_acked_features(VHostNetState *net) +void vhost_net_get_acked_features_ex(VHostNetState *net, uint64_t *feature= s) { - return net->dev.acked_features; + virtio_features_copy(features, net->dev.acked_features_array); } =20 void vhost_net_save_acked_features(NetClientState *nc) @@ -320,7 +320,8 @@ struct vhost_net *vhost_net_init(VhostNetOptions *optio= ns) int r; bool backend_kernel =3D options->backend_type =3D=3D VHOST_BACKEND_TYP= E_KERNEL; struct vhost_net *net =3D g_new0(struct vhost_net, 1); - uint64_t features =3D 0; + uint64_t missing_features[VIRTIO_FEATURES_DWORDS]; + uint64_t features[VIRTIO_FEATURES_DWORDS]; Error *local_err =3D NULL; =20 if (!options->net_backend) { @@ -343,7 +344,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *optio= ns) net->backend =3D r; net->dev.protocol_features =3D 0; } else { - net->dev.backend_features =3D 0; + virtio_features_clear(net->dev.backend_features_array); net->dev.protocol_features =3D 0; net->backend =3D -1; =20 @@ -361,12 +362,15 @@ struct vhost_net *vhost_net_init(VhostNetOptions *opt= ions) if (backend_kernel) { if (!qemu_has_vnet_hdr_len(options->net_backend, sizeof(struct virtio_net_hdr_mrg_rxbuf))) { - net->dev.features &=3D ~(1ULL << VIRTIO_NET_F_MRG_RXBUF); + net->dev.features &=3D ~VIRTIO_BIT(VIRTIO_NET_F_MRG_RXBUF); } - if (~net->dev.features & net->dev.backend_features) { - fprintf(stderr, "vhost lacks feature mask 0x%" PRIx64 - " for backend\n", - (uint64_t)(~net->dev.features & net->dev.backend_featur= es)); + + virtio_features_andnot(missing_features, + net->dev.backend_features_array, + net->dev.features_array); + if (!virtio_features_is_empty(missing_features)) { + fprintf(stderr, "vhost lacks feature mask 0x" VIRTIO_FEATURES_= FMT + " for backend\n", VIRTIO_FEATURES_PR(missing_features)); goto fail; } } @@ -374,17 +378,19 @@ struct vhost_net *vhost_net_init(VhostNetOptions *opt= ions) /* Set sane init value. Override when guest acks. */ #ifdef CONFIG_VHOST_NET_USER if (net->nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_USER) { - features =3D vhost_user_get_acked_features(net->nc); - if (~net->dev.features & features) { - fprintf(stderr, "vhost lacks feature mask 0x%" PRIx64 - " for backend\n", - (uint64_t)(~net->dev.features & features)); + virtio_features_from_u64(features, + vhost_user_get_acked_features(net->nc)); + virtio_features_andnot(missing_features, features, + net->dev.features_array); + if (!virtio_features_is_empty(missing_features)) { + fprintf(stderr, "vhost lacks feature mask 0x" VIRTIO_FEATURES_= FMT + " for backend\n", VIRTIO_FEATURES_PR(missing_features)= ); goto fail; } } #endif =20 - vhost_net_ack_features(net, features); + vhost_net_ack_features_ex(net, features); =20 return net; =20 diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index c6a5361a2a..f30a206e73 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -2,6 +2,7 @@ #define VHOST_NET_H =20 #include "net/net.h" +#include "hw/virtio/virtio-features.h" #include "hw/virtio/vhost-backend.h" =20 struct vhost_net; @@ -25,8 +26,26 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *n= cs, =20 void vhost_net_cleanup(VHostNetState *net); =20 -uint64_t vhost_net_get_features(VHostNetState *net, uint64_t features); -void vhost_net_ack_features(VHostNetState *net, uint64_t features); +void vhost_net_get_features_ex(VHostNetState *net, uint64_t *features); +static inline uint64_t vhost_net_get_features(VHostNetState *net, + uint64_t features) +{ + uint64_t features_array[VIRTIO_FEATURES_DWORDS]; + + virtio_features_from_u64(features_array, features); + vhost_net_get_features_ex(net, features_array); + return features_array[0]; +} + +void vhost_net_ack_features_ex(VHostNetState *net, const uint64_t *feature= s); +static inline void vhost_net_ack_features(VHostNetState *net, + uint64_t features) +{ + uint64_t features_array[VIRTIO_FEATURES_DWORDS]; + + virtio_features_from_u64(features_array, features); + vhost_net_ack_features_ex(net, features_array); +} =20 int vhost_net_get_config(struct vhost_net *net, uint8_t *config, uint32_t config_len); @@ -43,7 +62,15 @@ VHostNetState *get_vhost_net(NetClientState *nc); =20 int vhost_set_vring_enable(NetClientState * nc, int enable); =20 -uint64_t vhost_net_get_acked_features(VHostNetState *net); +void vhost_net_get_acked_features_ex(VHostNetState *net, uint64_t *feature= s); +static inline uint64_t vhost_net_get_acked_features(VHostNetState *net) +{ + uint64_t features[VIRTIO_FEATURES_DWORDS]; + + vhost_net_get_acked_features_ex(net, features); + assert(!virtio_features_use_extended(features)); + return features[0]; +} =20 int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); =20 --=20 2.50.0