From nobody Sat Nov 15 22:33:49 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=1747827466; cv=none; d=zohomail.com; s=zohoarc; b=gjaUwIc1U2F8UKabGWi3h1bKU5dbqTHOaEcyoHFgTxaDQvZdFUs6KUtMERt500iXIu02ZxMgIJMVbup/e9TClxTNob9J8qG3+l2s/KvLvGsO+hzS6J224nsy/422a7EbqPkE/ED2Unmq8jFMmjAeqBH+ItjELNfh3GA5b5IkksY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747827466; 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=4Qnkj3gk794sIguByyjpMjyUEyEFTPe94F5f1GjfOo8=; b=A1m7BTefD6ank1LwcUlss9Fv7aHjByLUlhkfvnX7fYJEzrFi0UKqOr7eAzxKbtD2bYDnMTdAo/cI2FB75HloxI47fBnkr6b80akGl4QnS1N8acCdfX+9IrCranBfCsJp5oFozTmJZTqUl5UP3c2qUfrmmH0IF/9prKtNttgzikQ= 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 1747827466153146.20530351972468; Wed, 21 May 2025 04:37:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uHhkF-0003s4-9q; Wed, 21 May 2025 07:36:24 -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 1uHhkD-0003rl-P8 for qemu-devel@nongnu.org; Wed, 21 May 2025 07:36:21 -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 1uHhk8-00019H-T5 for qemu-devel@nongnu.org; Wed, 21 May 2025 07:36:21 -0400 Received: from mx-prod-mc-05.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-437-zSjoF4hBNNyVbJC39j5qHw-1; Wed, 21 May 2025 07:36:12 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 234431956080; Wed, 21 May 2025 11:36:11 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.45.224.39]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7251A19560B7; Wed, 21 May 2025 11:36:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747827375; 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=4Qnkj3gk794sIguByyjpMjyUEyEFTPe94F5f1GjfOo8=; b=X3RRqU2iAd3Ga9WUCTF45w5q0o5y6LbWcukTDtEeluzvq631f4gWDmkgdFB/DKXZzo82/u uX4R8GEIwMULKy0tPp37UoxH+0PekESFr29C41hqKzZuHeWwyllp2uCMTo3gEUNccBaJWI 55Gcjxn1NHaB7TVjzeZ0qbMm5+P8YEc= X-MC-Unique: zSjoF4hBNNyVbJC39j5qHw-1 X-Mimecast-MFC-AGG-ID: zSjoF4hBNNyVbJC39j5qHw_1747827371 From: Paolo Abeni To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost , Dmitry Fleytman , Akihiko Odaki , Jason Wang , Sriram Yagnaraman , "Michael S. Tsirkin" , Stefano Garzarella , Peter Xu , Fabiano Rosas , Cornelia Huck , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Eric Blake , Markus Armbruster Subject: [PATCH RFC 12/16] virtio-net: implement extended features support. Date: Wed, 21 May 2025 13:34:06 +0200 Message-ID: <8fb9f142e25a0f1b01e8cf54a6c2a0971db00d83.1747825544.git.pabeni@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 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=pabeni@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.184, 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: 1747827468195116600 Content-Type: text/plain; charset="utf-8" Use the extended types and helpers to manipulate the virtio_net features. Note that offloads are still 64bits wide, as per specification, and extended offloads will be mapped into such range. Signed-off-by: Paolo Abeni --- hw/net/virtio-net.c | 87 +++++++++++++++++++++------------- include/hw/virtio/virtio-net.h | 2 +- 2 files changed, 55 insertions(+), 34 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 9f500c64e7..193469fc27 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -90,6 +90,17 @@ VIRTIO_NET_RSS_HASH_TYPE_TCP_EX |= \ VIRTIO_NET_RSS_HASH_TYPE_UDP_EX) =20 +#define VIRTIO_OFFLOAD_MAP_MIN 46 +#define VIRTIO_OFFLOAD_MAP_LENGTH 4 +#define VIRTIO_OFFLOAD_MAP MAKE_64BIT_MASK(VIRTIO_OFFLOAD_MAP_MIN, \ + VIRTIO_OFFLOAD_MAP_LENGTH) +#define VIRTIO_FEATURES_MAP_MIN 65 +#define VIRTIO_O2F_DELTA (VIRTIO_FEATURES_MAP_MIN - \ + VIRTIO_OFFLOAD_MAP_MIN) + +#define VIRTIO_FEATURE_TO_OFFLOAD(fbit) (fbit >=3D 64 ? \ + fbit - VIRTIO_O2F_DELTA : fbit) + static const VirtIOFeature feature_sizes[] =3D { {.flags =3D 1ULL << VIRTIO_NET_F_MAC, .end =3D endof(struct virtio_net_config, mac)}, @@ -751,44 +762,45 @@ static void virtio_net_set_queue_pairs(VirtIONet *n) =20 static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue); =20 -static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t featu= res, - Error **errp) +static virtio_features_t virtio_net_get_features(VirtIODevice *vdev, + virtio_features_t feature= s, + Error **errp) { VirtIONet *n =3D VIRTIO_NET(vdev); NetClientState *nc =3D qemu_get_queue(n->nic); =20 /* Firstly sync all virtio-net possible supported features */ - features |=3D n->host_features; + features |=3D n->host_features_ex; =20 - virtio_add_feature(&features, VIRTIO_NET_F_MAC); + virtio_add_feature_ex(&features, VIRTIO_NET_F_MAC); =20 if (!peer_has_vnet_hdr(n)) { - virtio_clear_feature(&features, VIRTIO_NET_F_CSUM); - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_TSO4); - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_TSO6); - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_ECN); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_CSUM); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_HOST_TSO4); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_HOST_TSO6); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_HOST_ECN); =20 - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_CSUM); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_TSO4); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_TSO6); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_ECN); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_GUEST_CSUM); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_GUEST_TSO4); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_GUEST_TSO6); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_GUEST_ECN); =20 - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_USO); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO4); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO6); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_HOST_USO); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_GUEST_USO4); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_GUEST_USO6); =20 - virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_HASH_REPORT); } =20 if (!peer_has_vnet_hdr(n) || !peer_has_ufo(n)) { - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_UFO); - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_UFO); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_GUEST_UFO); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_HOST_UFO); } =20 if (!peer_has_uso(n)) { - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_USO); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO4); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO6); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_HOST_USO); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_GUEST_USO4); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_GUEST_USO6); } =20 if (!get_vhost_net(nc->peer)) { @@ -796,7 +808,7 @@ static uint64_t virtio_net_get_features(VirtIODevice *v= dev, uint64_t features, } =20 if (!ebpf_rss_is_loaded(&n->ebpf_rss)) { - virtio_clear_feature(&features, VIRTIO_NET_F_RSS); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_RSS); } features =3D vhost_net_get_features(get_vhost_net(nc->peer), features); vdev->backend_features_ex =3D features; @@ -818,7 +830,7 @@ static uint64_t virtio_net_get_features(VirtIODevice *v= dev, uint64_t features, * support it. */ if (!virtio_has_feature(vdev->backend_features, VIRTIO_NET_F_CTRL_VQ))= { - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_ANNOUNCE); + virtio_clear_feature_ex(&features, VIRTIO_NET_F_GUEST_ANNOUNCE); } =20 return features; @@ -851,9 +863,16 @@ static void virtio_net_apply_guest_offloads(VirtIONet = *n) !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_USO6))= ); } =20 -static uint64_t virtio_net_guest_offloads_by_features(uint64_t features) +static uint64_t virtio_net_features_to_offload(virtio_features_t features) +{ + return (features & ~VIRTIO_OFFLOAD_MAP) | + ((features >> VIRTIO_O2F_DELTA) & VIRTIO_OFFLOAD_MAP); +} + +static uint64_t +virtio_net_guest_offloads_by_features(virtio_features_t features) { - static const uint64_t guest_offloads_mask =3D + static const virtio_features_t guest_offloads_mask =3D (1ULL << VIRTIO_NET_F_GUEST_CSUM) | (1ULL << VIRTIO_NET_F_GUEST_TSO4) | (1ULL << VIRTIO_NET_F_GUEST_TSO6) | @@ -862,13 +881,13 @@ static uint64_t virtio_net_guest_offloads_by_features= (uint64_t features) (1ULL << VIRTIO_NET_F_GUEST_USO4) | (1ULL << VIRTIO_NET_F_GUEST_USO6); =20 - return guest_offloads_mask & features; + return guest_offloads_mask & virtio_net_features_to_offload(features); } =20 uint64_t virtio_net_supported_guest_offloads(const VirtIONet *n) { VirtIODevice *vdev =3D VIRTIO_DEVICE(n); - return virtio_net_guest_offloads_by_features(vdev->guest_features); + return virtio_net_guest_offloads_by_features(vdev->guest_features_ex); } =20 typedef struct { @@ -947,7 +966,8 @@ static void failover_add_primary(VirtIONet *n, Error **= errp) error_propagate(errp, err); } =20 -static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features) +static void virtio_net_set_features(VirtIODevice *vdev, + virtio_features_t features) { VirtIONet *n =3D VIRTIO_NET(vdev); Error *err =3D NULL; @@ -955,7 +975,7 @@ static void virtio_net_set_features(VirtIODevice *vdev,= uint64_t features) =20 if (n->mtu_bypass_backend && !virtio_has_feature(vdev->backend_features, VIRTIO_NET_F_MTU))= { - features &=3D ~(1ULL << VIRTIO_NET_F_MTU); + features &=3D ~VIRTIO_BIT(VIRTIO_NET_F_MTU); } =20 virtio_net_set_multiqueue(n, @@ -1962,10 +1982,11 @@ static ssize_t virtio_net_receive_rcu(NetClientStat= e *nc, const uint8_t *buf, virtio_error(vdev, "virtio-net unexpected empty queue: " "i %zd mergeable %d offset %zd, size %zd, " "guest hdr len %zd, host hdr len %zd " - "guest features 0x%" PRIx64, + "guest features 0x" VIRTIO_FEATURES_FMT, i, n->mergeable_rx_bufs, offset, size, n->guest_hdr_len, n->host_hdr_len, - vdev->guest_features); + VIRTIO_FEATURES_HI(vdev->guest_features_ex), + VIRTIO_FEATURES_LOW(vdev->guest_features_ex)); } err =3D -1; goto err; @@ -4146,8 +4167,8 @@ static void virtio_net_class_init(ObjectClass *klass,= const void *data) vdc->unrealize =3D virtio_net_device_unrealize; vdc->get_config =3D virtio_net_get_config; vdc->set_config =3D virtio_net_set_config; - vdc->get_features =3D virtio_net_get_features; - vdc->set_features =3D virtio_net_set_features; + vdc->get_features_ex =3D virtio_net_get_features; + vdc->set_features_ex =3D virtio_net_set_features; vdc->bad_features =3D virtio_net_bad_features; vdc->reset =3D virtio_net_reset; vdc->queue_reset =3D virtio_net_queue_reset; diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index b9ea9e824e..5ccdbeb253 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -178,7 +178,7 @@ struct VirtIONet { uint32_t has_vnet_hdr; size_t host_hdr_len; size_t guest_hdr_len; - uint64_t host_features; + DECLARE_FEATURES(host_features); uint32_t rsc_timeout; uint8_t rsc4_enabled; uint8_t rsc6_enabled; --=20 2.49.0