From nobody Sun Dec 14 05:51:26 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=1752535174; cv=none; d=zohomail.com; s=zohoarc; b=d8ICCvGIlJmrhmdEPak02IpzlPQDat0AXkkH/WATY5Kc7UrmkwzBGUPIVGU1avVh8IAvUCYi7hjHvk8VxFnq/0QNjsbCj0luy4jB3k2P/kb+eTdwGX6ZWfMQotF8f3a5jjLPXZTKGPW665TO2klJq380oGL8+0yXYuOvfESmy5Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752535174; h=Content-Type: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=oh92UO1fq7giggZS3iJdAbKSiUem3Rj0QL6NYcmrhqo=; b=DXQ83BzCe8FdvNEo4/obmajG1LB8+QDfY9CXfLwcBmoUSlpkb1wVMex2mnHl5n26P2l7IvAY0PJgz/jKzoGwBBl0DeiI3cWqniztv1rBWPdNH2vB/SMUSpBFLVDEYjqvJjmyVfxA6PyADZRM8wI4s4VI/hfipDh5oeG39RmzOmA= 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 1752535174634330.25242477234076; Mon, 14 Jul 2025 16:19:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubSFn-0001RV-1v; Mon, 14 Jul 2025 19:06:35 -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 1ubSFk-0001O5-Q4 for qemu-devel@nongnu.org; Mon, 14 Jul 2025 19:06:32 -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 1ubSFi-0005Lb-SN for qemu-devel@nongnu.org; Mon, 14 Jul 2025 19:06:32 -0400 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-554-I0DDYzgXNkugz1Kb9NLaCg-1; Mon, 14 Jul 2025 19:06:28 -0400 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3a52bfda108so2378673f8f.3 for ; Mon, 14 Jul 2025 16:06:28 -0700 (PDT) Received: from redhat.com ([2a0d:6fc0:150d:fc00:de3:4725:47c6:6809]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-456101b616csm72711185e9.4.2025.07.14.16.06.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jul 2025 16:06:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752534390; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oh92UO1fq7giggZS3iJdAbKSiUem3Rj0QL6NYcmrhqo=; b=SNWAPitPhd0/9/nwTD1Z2q+YlySoeImvTD398JB/qK3o4RPIl8/LkAHFUVqbqd1XLCkat4 XyYh6fy/fopOZ8iwWTgoYsUuuVHutcJgf0UkZxYFtKQRKTDHbGqVExO/zI7M4GLL1OObdN uqPzuPfOhTFmaBn2OrX83f5ZcMmdaDs= X-MC-Unique: I0DDYzgXNkugz1Kb9NLaCg-1 X-Mimecast-MFC-AGG-ID: I0DDYzgXNkugz1Kb9NLaCg_1752534388 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752534387; x=1753139187; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=oh92UO1fq7giggZS3iJdAbKSiUem3Rj0QL6NYcmrhqo=; b=BDfGywz5QZo3TJI079T87SY+WXjtz+TFE68hbtgB379zqZv61Q9OVShl+5hs0g/fXX M+9H4kqiSt0UNFxN1K20V6Hefje3PMxkWos3oIaO3hzqW8vZKXla5GEtF9jfKz9bUAyC PLYDaJNu6AIwGmIrYpJxM9ApAhstDBG10wp9IZaOGo5q2HDgmEQ6r9FbaJt5AQpyyDHX SCR+K3NVaZwB6Y+/4fOqepsnjUftc/ZwnkS+BvB03jKuOglGPiSGnOagNVAuMcblnT9j yhoOvs7vOgKr4wZiBowd6eeOyjLG54MajFkmGoyVcUYgcA2sTJaJyS2oSkmb+nSS+oq5 bRCw== X-Gm-Message-State: AOJu0YxUHswlzjtb1j87MVNnQwI5ZDavA3CL+MAXt2m3O5QjU8dcHQQc CR5TTcQln55R0e/tWENnjxkwQ7NCtMZF21GpRCwB0dvaKGDtuF4fEQueqgohhvtiSuJdgDmUBIX pOpKn/jRNQ3yC7pEAxhpMPi2M73D6Wwwt9TIohCYfM8/JMApNUdgs75hBTznjUK6mvbt1Umk80w SjGKY+DH/XmyI4x+5KhgqB+rJnGSgEeV7lTg== X-Gm-Gg: ASbGncv8l5mFRp2k5WU+PozmNkDcEQG0rDw8eVVpvfMr4/hMuy9TV5RqcOKPQLvc/eK zUG5s88epU1buqIWP6FLqulONYettLabC3MikLsFdvE1mntf379Bz/3JiGEqSfXZKwBbbDS4w7t S9xesMwQrgw2XlfgIu+MyfiA7zjDPBpqJsekiOeaJCgx4v34OCsRR4ngsRLZ2xvv1jmVPm1vSIb DdEARRpggsyaYmTbu3YovGHhNsE9A44v+CqIF9s5/mKJT7JcjnZnY6chXOrJc3ZnD4Jiek9YdoS yWjuu7RvszQKxgzSFVLsQhN5VhR+Myr1 X-Received: by 2002:a5d:64cc:0:b0:3a4:d98d:76b9 with SMTP id ffacd0b85a97d-3b5f358567emr9811363f8f.41.1752534387172; Mon, 14 Jul 2025 16:06:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHls3U2TziYi9zjRa+UpyGNvsL3Gj81CzXJBSAPO3w9ufb077+PE3BPZ9kifJg9zV4DKgKJhw== X-Received: by 2002:a5d:64cc:0:b0:3a4:d98d:76b9 with SMTP id ffacd0b85a97d-3b5f358567emr9811348f8f.41.1752534386706; Mon, 14 Jul 2025 16:06:26 -0700 (PDT) Date: Mon, 14 Jul 2025 19:06:25 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Akihiko Odaki , Jason Wang Subject: [PULL 04/97] virtio-net: Retrieve peer hashing capability Message-ID: <7b6e7e49905d0682f67ae4d02fc9edc4a2ec7df5.1752534227.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent 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=mst@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: 1752535176211116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Akihiko Odaki Retrieve peer hashing capability instead of hardcoding. Signed-off-by: Akihiko Odaki Message-Id: <20250530-vdpa-v1-4-5af4109b1c19@daynix.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio-net.h | 5 ++- hw/net/virtio-net.c | 71 +++++++++++++++++++++++++++------- net/vhost-vdpa.c | 4 +- 3 files changed, 64 insertions(+), 16 deletions(-) diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index b9ea9e824e..c4957c44c0 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -144,7 +144,10 @@ typedef struct VirtioNetRssData { bool enabled_software_rss; bool redirect; bool populate_hash; - uint32_t hash_types; + bool peer_hash_available; + uint32_t runtime_hash_types; + uint32_t supported_hash_types; + uint32_t peer_hash_types; uint8_t key[VIRTIO_NET_RSS_MAX_KEY_SIZE]; uint16_t indirections_len; uint16_t *indirections_table; diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 34fe5909c5..9888ff22bd 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -158,7 +158,7 @@ static void virtio_net_get_config(VirtIODevice *vdev, u= int8_t *config) virtio_host_has_feature(vdev, VIRTIO_NET_F_RSS) ? VIRTIO_NET_RSS_MAX_TABLE_LEN : 1); virtio_stl_p(vdev, &netcfg.supported_hash_types, - VIRTIO_NET_RSS_SUPPORTED_HASHES); + n->rss_data.supported_hash_types); memcpy(config, &netcfg, n->config_size); =20 /* @@ -1178,7 +1178,7 @@ static void rss_data_to_rss_config(struct VirtioNetRs= sData *data, { config->redirect =3D data->redirect; config->populate_hash =3D data->populate_hash; - config->hash_types =3D data->hash_types; + config->hash_types =3D data->runtime_hash_types; config->indirections_len =3D data->indirections_len; config->default_queue =3D data->default_queue; } @@ -1213,6 +1213,10 @@ static void virtio_net_detach_ebpf_rss(VirtIONet *n) =20 static void virtio_net_commit_rss_config(VirtIONet *n) { + if (n->rss_data.peer_hash_available) { + return; + } + if (n->rss_data.enabled) { n->rss_data.enabled_software_rss =3D n->rss_data.populate_hash; if (n->rss_data.populate_hash) { @@ -1227,7 +1231,7 @@ static void virtio_net_commit_rss_config(VirtIONet *n) } =20 trace_virtio_net_rss_enable(n, - n->rss_data.hash_types, + n->rss_data.runtime_hash_types, n->rss_data.indirections_len, sizeof(n->rss_data.key)); } else { @@ -1338,7 +1342,7 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, err_value =3D (uint32_t)s; goto error; } - n->rss_data.hash_types =3D virtio_ldl_p(vdev, &cfg.hash_types); + n->rss_data.runtime_hash_types =3D virtio_ldl_p(vdev, &cfg.hash_types); n->rss_data.indirections_len =3D virtio_lduw_p(vdev, &cfg.indirection_table_mask); if (!do_rss) { @@ -1401,12 +1405,12 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, err_value =3D temp.b; goto error; } - if (!temp.b && n->rss_data.hash_types) { + if (!temp.b && n->rss_data.runtime_hash_types) { err_msg =3D "No key provided"; err_value =3D 0; goto error; } - if (!temp.b && !n->rss_data.hash_types) { + if (!temp.b && !n->rss_data.runtime_hash_types) { virtio_net_disable_rss(n); return queue_pairs; } @@ -1808,7 +1812,7 @@ static int virtio_net_process_rss(NetClientState *nc,= const uint8_t *buf, net_rx_pkt_set_protocols(pkt, &iov, 1, n->host_hdr_len); net_rx_pkt_get_protocols(pkt, &hasip4, &hasip6, &l4hdr_proto); net_hash_type =3D virtio_net_get_hash_type(hasip4, hasip6, l4hdr_proto, - n->rss_data.hash_types); + n->rss_data.runtime_hash_type= s); if (net_hash_type > NetPktRssIpV6UdpEx) { if (n->rss_data.populate_hash) { hdr->hash_value =3D VIRTIO_NET_HASH_REPORT_NONE; @@ -3008,6 +3012,14 @@ static uint64_t virtio_net_get_features(VirtIODevice= *vdev, uint64_t features, { VirtIONet *n =3D VIRTIO_NET(vdev); NetClientState *nc =3D qemu_get_queue(n->nic); + uint32_t supported_hash_types =3D n->rss_data.supported_hash_types; + uint32_t peer_hash_types =3D n->rss_data.peer_hash_types; + bool use_own_hash =3D + (supported_hash_types & VIRTIO_NET_RSS_SUPPORTED_HASHES) =3D=3D + supported_hash_types; + bool use_peer_hash =3D + n->rss_data.peer_hash_available && + (supported_hash_types & peer_hash_types) =3D=3D supported_hash_typ= es; =20 /* Firstly sync all virtio-net possible supported features */ features |=3D n->host_features; @@ -3044,12 +3056,28 @@ static uint64_t virtio_net_get_features(VirtIODevic= e *vdev, uint64_t features, } =20 if (!get_vhost_net(nc->peer)) { + if (!use_own_hash) { + virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT); + virtio_clear_feature(&features, VIRTIO_NET_F_RSS); + } else if (virtio_has_feature(features, VIRTIO_NET_F_RSS)) { + virtio_net_load_ebpf(n, errp); + } + return features; } =20 - if (!ebpf_rss_is_loaded(&n->ebpf_rss)) { - virtio_clear_feature(&features, VIRTIO_NET_F_RSS); + if (!use_peer_hash) { + virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT); + + if (!use_own_hash || !virtio_net_attach_ebpf_to_backend(n->nic, -1= )) { + if (!virtio_net_load_ebpf(n, errp)) { + return features; + } + + virtio_clear_feature(&features, VIRTIO_NET_F_RSS); + } } + features =3D vhost_net_get_features(get_vhost_net(nc->peer), features); vdev->backend_features =3D features; =20 @@ -3314,6 +3342,17 @@ static const VMStateDescription vmstate_virtio_net_h= as_vnet =3D { }, }; =20 +static int virtio_net_rss_post_load(void *opaque, int version_id) +{ + VirtIONet *n =3D VIRTIO_NET(opaque); + + if (version_id =3D=3D 1) { + n->rss_data.supported_hash_types =3D VIRTIO_NET_RSS_SUPPORTED_HASH= ES; + } + + return 0; +} + static bool virtio_net_rss_needed(void *opaque) { return VIRTIO_NET(opaque)->rss_data.enabled; @@ -3321,14 +3360,16 @@ static bool virtio_net_rss_needed(void *opaque) =20 static const VMStateDescription vmstate_virtio_net_rss =3D { .name =3D "virtio-net-device/rss", - .version_id =3D 1, + .version_id =3D 2, .minimum_version_id =3D 1, + .post_load =3D virtio_net_rss_post_load, .needed =3D virtio_net_rss_needed, .fields =3D (const VMStateField[]) { VMSTATE_BOOL(rss_data.enabled, VirtIONet), VMSTATE_BOOL(rss_data.redirect, VirtIONet), VMSTATE_BOOL(rss_data.populate_hash, VirtIONet), - VMSTATE_UINT32(rss_data.hash_types, VirtIONet), + VMSTATE_UINT32(rss_data.runtime_hash_types, VirtIONet), + VMSTATE_UINT32_V(rss_data.supported_hash_types, VirtIONet, 2), VMSTATE_UINT16(rss_data.indirections_len, VirtIONet), VMSTATE_UINT16(rss_data.default_queue, VirtIONet), VMSTATE_UINT8_ARRAY(rss_data.key, VirtIONet, @@ -3915,8 +3956,12 @@ static void virtio_net_device_realize(DeviceState *d= ev, Error **errp) =20 net_rx_pkt_init(&n->rx_pkt); =20 - if (virtio_has_feature(n->host_features, VIRTIO_NET_F_RSS)) { - virtio_net_load_ebpf(n, errp); + if (qemu_get_vnet_hash_supported_types(qemu_get_queue(n->nic)->peer, + &n->rss_data.peer_hash_types)) { + n->rss_data.peer_hash_available =3D true; + n->rss_data.supported_hash_types =3D n->rss_data.peer_hash_types; + } else { + n->rss_data.supported_hash_types =3D VIRTIO_NET_RSS_SUPPORTED_HASH= ES; } } =20 diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index cb63e09453..3452835ca9 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -865,13 +865,13 @@ static int vhost_vdpa_net_load_rss(VhostVDPAState *s,= const VirtIONet *n, * configuration only at live migration. */ if (!n->rss_data.enabled || - n->rss_data.hash_types =3D=3D VIRTIO_NET_HASH_REPORT_NONE) { + n->rss_data.runtime_hash_types =3D=3D VIRTIO_NET_HASH_REPORT_NONE)= { return 0; } =20 table =3D g_malloc_n(n->rss_data.indirections_len, sizeof(n->rss_data.indirections_table[0])); - cfg.hash_types =3D cpu_to_le32(n->rss_data.hash_types); + cfg.hash_types =3D cpu_to_le32(n->rss_data.runtime_hash_types); =20 if (do_rss) { /* --=20 MST