From nobody Tue Nov 5 11:04:31 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1726363561; cv=none; d=zohomail.com; s=zohoarc; b=jVX/BqDiEiodHvNqxenYpyValQA/AYX0yBAUs8l7tkVlTO4M6qjBPRHDBespvEvJbpDCSGcx1Cqfrxc0OyzZLTOYokVw5hxJZGVrdudivoiLiRZ+6CWDIw9jM/MsKuUM6qLJghudyvJfVwJ7722X0QsNRVyzSe9lhJNEWeWcVBo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726363561; h=Content-Type: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=yN4IPLpzUJOoQP0bUmbKLVptw/fXWtyeCd8LXlwgVCQ=; b=ajGHXPiPfAMsK34R5TihRHZVI5KUQxWKnyZlwxS3SRjJ3+zS93XddSK+C/mXVsF1eK2PiqIS/xgigj6ueT1Ce1df/ewujFZB5AITJqFNlQOe+PSy2MIw2l92FNLnemK8HiHDPiuToh8oo6KmrkaLdHA4CNz1Rwhvk5FLBJcjLro= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726363561876821.9276344866581; Sat, 14 Sep 2024 18:26:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spe0W-0003Bk-Ai; Sat, 14 Sep 2024 21:24:56 -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 1spe0T-0003Ac-Vp for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:24:53 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spe0S-0005Rf-0e for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:24:53 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-2055136b612so42142525ad.0 for ; Sat, 14 Sep 2024 18:24:51 -0700 (PDT) Received: from localhost ([210.160.217.68]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-207946010e4sm14933415ad.73.2024.09.14.18.24.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 14 Sep 2024 18:24:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1726363490; x=1726968290; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=yN4IPLpzUJOoQP0bUmbKLVptw/fXWtyeCd8LXlwgVCQ=; b=ogrsUlW6BS2PRXcPqBoHHUKz2IfZxRVMWpIk954m5X/poWe7F42yRS+lXy3E0rogjK SwxgQi/SpoS7rCV1oE/IrLiip0prOKqlxC11/IyPhqAMXlqTrE3rDSMA1PO18crL0aR2 Ykz1TtgRqw+vEt23+NJ12FA1GYrxXwm2ToMtUuOhuyNV0QwrM4q3qSl3ry5QYfU2d4el OGVdITVwXMiUTDhLNi0moXPAE5wNeNgaU0gHtsdNLuxo+WhK9Xcc2FxbbNIMJvooo1bS 3/CO/X0dxQE/yX0UxbAhSSiQ5U1RKqFCnQd81QTIzAg2FNTq3cL7QfkD1ndURSy2WCV6 hvYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726363490; x=1726968290; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yN4IPLpzUJOoQP0bUmbKLVptw/fXWtyeCd8LXlwgVCQ=; b=Ah5VLujA2r9csWc3NyIkv/hoyXHH5VSEceiXnsOdNE59iqVDU9hJ/kFAz1rOU5gbbX AUWineG8nl7OY84LFbRbaJunFIJ8NEnzVGtVs8FHfuX2+tBDJRSvxkX98uJ+J2as3Bt1 00zjgExUiP7V3MEo2oDbJo6qgLJeE2gRqaTbtSCj59BjsFzbtLrpTHloqbYqjoXHv+kD Js5CIro6Ebl6PWM0YbhHothIRCpgoyUK/7W88gDspzVVqMuotdKsd56OxaC+YwEs56p9 A2gp+Ro5HNFbKlx7NKU9wi2DC+J9Auple8rkK5ZSibX82SLQuVaTdj+/9VQoEOGe4SdF n61w== X-Gm-Message-State: AOJu0YyDNp7kKwu6zDLNDWA5LYUWg0u72wPhqN5UCHjABSEZVwrKzIqX 5ZwEj06OxRsALCuqcWEfjTnP64pdjmUcfQ9r7jRayse0OOoOTZYMq7A4Jt1WDbo2CIE4RJjCXf3 3Sfw= X-Google-Smtp-Source: AGHT+IEav6YWKN0VQVTWJi66uSrLCzrhGoJkfnF7L8prqH/KGhWA3/i9bwAHx8iDuV5K/HwYXzgvRQ== X-Received: by 2002:a17:902:d510:b0:206:b4cf:3107 with SMTP id d9443c01a7336-2076e422055mr184255655ad.49.1726363490522; Sat, 14 Sep 2024 18:24:50 -0700 (PDT) From: Akihiko Odaki Date: Sun, 15 Sep 2024 10:23:45 +0900 Subject: [PATCH RFC v3 04/11] virtio-net: Retrieve peer hashing capability MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240915-hash-v3-4-79cb08d28647@daynix.com> References: <20240915-hash-v3-0-79cb08d28647@daynix.com> In-Reply-To: <20240915-hash-v3-0-79cb08d28647@daynix.com> To: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang Cc: Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 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: none client-ip=2607:f8b0:4864:20::631; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x631.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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 @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726363564024116600 Retrieve peer hashing capability instead of hardcoding. Signed-off-by: Akihiko Odaki --- include/hw/virtio/virtio-net.h | 5 +++- hw/net/virtio-net.c | 67 ++++++++++++++++++++++++++++++++++----= ---- net/vhost-vdpa.c | 4 +-- 3 files changed, 60 insertions(+), 16 deletions(-) diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 060c23c04d2d..202016ec74fc 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 206b0335169d..3da15a60eaa5 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -157,7 +157,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 /* @@ -1175,7 +1175,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; } @@ -1209,6 +1209,10 @@ static void virtio_net_detach_epbf_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) { @@ -1222,7 +1226,7 @@ static void virtio_net_commit_rss_config(VirtIONet *n) } } =20 - trace_virtio_net_rss_enable(n->rss_data.hash_types, + trace_virtio_net_rss_enable(n->rss_data.runtime_hash_types, n->rss_data.indirections_len, sizeof(n->rss_data.key)); } else { @@ -1324,7 +1328,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); n->rss_data.indirections_len++; @@ -1387,12 +1391,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; } @@ -1793,7 +1797,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; @@ -2973,6 +2977,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; @@ -3009,12 +3021,24 @@ 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); + } + 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_load_ebpf(n)) { + 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 @@ -3279,6 +3303,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; @@ -3286,14 +3321,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, @@ -3768,8 +3805,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); + 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 af0c3c448c1f..4af87ea226b4 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -884,13 +884,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 2.46.0