From patchwork Thu Mar 13 06:55:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 14014401 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A6585C282DE for ; Thu, 13 Mar 2025 06:56:22 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tscU1-0006QT-Um; Thu, 13 Mar 2025 02:55:58 -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 1tscTu-0006MU-NO for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:55:50 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tscTs-00063k-UA for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:55:50 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-224019ad9edso15661825ad.1 for ; Wed, 12 Mar 2025 23:55:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1741848947; x=1742453747; 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=edQrPumtjHJ/3YEvhVZ3l0G0XjyNZI+GIrglFTyNrrU=; b=Ad8g2VEku75+KTZ94JLcm8SwBeS3vFxVVHzcli3SjNyIn96vy4QCPpAc0WSgkTB5s6 iYBGljg91DC43JdJIhRIniuVJnp4reNzcjqI/4hNOxm1RHAj+LG1Gjb+BqjIh+Lt5gOZ oQZJXDnS2TUaBZWUBkKwAcQ4NHQkYug5qKkJwlSthorseNngRvPcVPb0KgWz2NDAf+Cs MtlvS5x6BVZwJj54CpBZxbmMznMUTHHTfqwp4/MH8anNhs4tjrQmVIkGIbaYWjDnW2kJ Fr8nj87CIrmrpdLKVt6lT/gDojNvKoRYZg5jnaMRx1bC+Y7Lif/Iw6Ye8vd9F16xq5Oo ZPzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741848947; x=1742453747; 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=edQrPumtjHJ/3YEvhVZ3l0G0XjyNZI+GIrglFTyNrrU=; b=ksn68lcL9GR3J99r5dPaX1/GAgdGjgjD/x7me3gQuclgFn1rQDubNW6HlF0gitIKNb qQ6qquMEBDbij4hIOYqFd9MwQmV11R7gupVeWuQY9BDsPGA9tUQNUNtiiHTYCMPGPUTL rmUv/WyUCQ8Jc7KV50TsGd/Ktu+QFnvwwyx6fu7S8jXetvriE7IDRSHQqfCtgOYniJtc i1o/c2BEpde+d1t72D6jSdlb6ec19GCaJk1bc6eTWe9iRtU8zsv+IMtHial27vBlcPa+ qUpvHA5nYCDL35O1JUUxEvoUfx7cRo7pHpb/899IITyzURGfAE5mpT8hk9Ql1rmE2n8C Gh7g== X-Gm-Message-State: AOJu0YywJ3qIE4dYK3x7QMFMKpAQ89rnqD6lUmIEeD4cBzB6Z6/auOyA AFzh/Y35s7nWF4apgYAdVfCly8r/dQFqPZEMtTYI7+x6RhQ1xX/apxhV9qTy0+qRbxfqBnjttae NCGQ= X-Gm-Gg: ASbGnct7cs4e7wcRo7UzBljS70OVPIa7TxQW/OjvurBmphmzPrlRimIzcShGqH0felD y7vSqcm6lm656qLa8VvSlU7UGSmMtwINJ5j2vu0LZhNxjTpLRhkNIePo7aQBk7620tYdYoN/Jqk kdAU4EnnTj/IuLg7aXQ4OMjgeBsvLemWXiCwTPSKiDrm9o7eRws5vaMIZgML1VAxr01HaF/3gvg Rl7ZWIFysQ0mkke+jRy5XiDasJDQ0MUHdsWb+C6sxOQOAv0dEtFK/2EPMLP9vjQILhHje8f58j0 gQJEy9feemAxiPbk/2JoKfPtSgtWbJ3cERxrlPOMH5jpo9c2MHryNk97D/0= X-Google-Smtp-Source: AGHT+IGRuGv5QCnatLYEPGLLpRsA7qJ6wbH7a83Xg0XRaDoVG7l1LOd9pZ8+k0LLAuPGowedYkH70w== X-Received: by 2002:a17:903:19cf:b0:215:94eb:adb6 with SMTP id d9443c01a7336-22428ab75cdmr436416455ad.40.1741848947228; Wed, 12 Mar 2025 23:55:47 -0700 (PDT) Received: from localhost ([157.82.205.237]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-3011824b98dsm3078434a91.27.2025.03.12.23.55.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Mar 2025 23:55:46 -0700 (PDT) From: Akihiko Odaki Date: Thu, 13 Mar 2025 15:55:27 +0900 Subject: [PATCH RFC v4 01/11] qdev-properties: Add DEFINE_PROP_ON_OFF_AUTO_BIT64() MIME-Version: 1.0 Message-Id: <20250313-hash-v4-1-c75c494b495e@daynix.com> References: <20250313-hash-v4-0-c75c494b495e@daynix.com> In-Reply-To: <20250313-hash-v4-0-c75c494b495e@daynix.com> To: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , devel@daynix.com Cc: Akihiko Odaki X-Mailer: b4 0.15-dev-edae6 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x634.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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org DEFINE_PROP_ON_OFF_AUTO_BIT64() corresponds to DEFINE_PROP_ON_OFF_AUTO() as DEFINE_PROP_BIT64() corresponds to DEFINE_PROP_BOOL(). The difference is that DEFINE_PROP_ON_OFF_AUTO_BIT64() exposes OnOffAuto instead of bool. Signed-off-by: Akihiko Odaki --- include/hw/qdev-properties.h | 18 ++++++++++++ hw/core/qdev-properties.c | 67 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 15fcec5260c7..61f13aca6cf4 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -43,11 +43,22 @@ struct PropertyInfo { ObjectPropertyRelease *release; }; +/** + * struct OnOffAutoBit64 - OnOffAuto storage with 64 elements. + * @on_bits: Bitmap of elements with "on". + * @auto_bits: Bitmap of elements with "auto". + */ +typedef struct OnOffAutoBit64 { + uint64_t on_bits; + uint64_t auto_bits; +} OnOffAutoBit64; + /*** qdev-properties.c ***/ extern const PropertyInfo qdev_prop_bit; extern const PropertyInfo qdev_prop_bit64; +extern const PropertyInfo qdev_prop_on_off_auto_bit64; extern const PropertyInfo qdev_prop_bool; extern const PropertyInfo qdev_prop_uint8; extern const PropertyInfo qdev_prop_uint16; @@ -99,6 +110,13 @@ extern const PropertyInfo qdev_prop_link; .set_default = true, \ .defval.u = (bool)_defval) +#define DEFINE_PROP_ON_OFF_AUTO_BIT64(_name, _state, _field, _bit, _defval) \ + DEFINE_PROP(_name, _state, _field, qdev_prop_on_off_auto_bit64, \ + OnOffAutoBit64, \ + .bitnr = (_bit), \ + .set_default = true, \ + .defval.i = (OnOffAuto)_defval) + #define DEFINE_PROP_BOOL(_name, _state, _field, _defval) \ DEFINE_PROP(_name, _state, _field, qdev_prop_bool, bool, \ .set_default = true, \ diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index c04df3b337ae..05a627030141 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -2,6 +2,7 @@ #include "hw/qdev-properties.h" #include "qapi/error.h" #include "qapi/qapi-types-misc.h" +#include "qapi/qapi-visit-common.h" #include "qobject/qlist.h" #include "qemu/ctype.h" #include "qemu/error-report.h" @@ -180,7 +181,8 @@ const PropertyInfo qdev_prop_bit = { static uint64_t qdev_get_prop_mask64(const Property *prop) { - assert(prop->info == &qdev_prop_bit64); + assert(prop->info == &qdev_prop_bit64 || + prop->info == &qdev_prop_on_off_auto_bit64); return 0x1ull << prop->bitnr; } @@ -225,6 +227,69 @@ const PropertyInfo qdev_prop_bit64 = { .set_default_value = set_default_value_bool, }; +static void prop_get_on_off_auto_bit64(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + Property *prop = opaque; + OnOffAutoBit64 *p = object_field_prop_ptr(obj, prop); + OnOffAuto value; + uint64_t mask = qdev_get_prop_mask64(prop); + + if (p->auto_bits & mask) { + value = ON_OFF_AUTO_AUTO; + } else if (p->on_bits & mask) { + value = ON_OFF_AUTO_ON; + } else { + value = ON_OFF_AUTO_OFF; + } + + visit_type_OnOffAuto(v, name, &value, errp); +} + +static void prop_set_on_off_auto_bit64(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + Property *prop = opaque; + OnOffAutoBit64 *p = object_field_prop_ptr(obj, prop); + OnOffAuto value; + uint64_t mask = qdev_get_prop_mask64(prop); + + if (!visit_type_OnOffAuto(v, name, &value, errp)) { + return; + } + + switch (value) { + case ON_OFF_AUTO_AUTO: + p->on_bits &= ~mask; + p->auto_bits |= mask; + break; + + case ON_OFF_AUTO_ON: + p->on_bits |= mask; + p->auto_bits &= ~mask; + break; + + case ON_OFF_AUTO_OFF: + p->on_bits &= ~mask; + p->auto_bits &= ~mask; + break; + + case ON_OFF_AUTO__MAX: + g_assert_not_reached(); + } +} + +const PropertyInfo qdev_prop_on_off_auto_bit64 = { + .type = "OnOffAuto", + .description = "on/off/auto", + .enum_table = &OnOffAuto_lookup, + .get = prop_get_on_off_auto_bit64, + .set = prop_set_on_off_auto_bit64, + .set_default_value = qdev_propinfo_set_default_value_enum, +}; + /* --- bool --- */ static void get_bool(Object *obj, Visitor *v, const char *name, void *opaque, From patchwork Thu Mar 13 06:55:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 14014411 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 41013C28B28 for ; Thu, 13 Mar 2025 06:58:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tscU7-0006Uv-KH; Thu, 13 Mar 2025 02:56:03 -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 1tscTz-0006OR-2l for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:55:55 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tscTw-00064d-HW for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:55:54 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-224191d92e4so11390795ad.3 for ; Wed, 12 Mar 2025 23:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1741848951; x=1742453751; 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=oIFfPe5cbAFiiWq1pctwdNXgTMQOFzoPIBHYx9JfyDs=; b=E5SoP6x1rX89dXredw3zNgDPW2irhIhoUxian4hiHxU+2DgCFnwlFqj3ncNCkRGGhK 87Miux2bhMe2mhYZdFnXoAFe/gGqgWipizciwLTEPL1iSNlKA8UOzJRQqArPPNroc9tD SsEEIOXpZpk9ZdEOyoTQ2gUBNClekkJcZBarhcuZ1GOm+nzJPdWhajh53IfquPWJRDW/ v4oKOvp7gpnLBrUYGNI6TyHYcUjMpKWjUEKL5iDhyegkf1lpbZ4j/6fnbF3HyFXZwy7a 7x4k05pyD9oc0DCUNHy4T7bxsntU3pwVurxw34fDiWmWsWw4Qv/O/qLFTsf6PBxy8gkK ohFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741848951; x=1742453751; 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=oIFfPe5cbAFiiWq1pctwdNXgTMQOFzoPIBHYx9JfyDs=; b=iiIC9nBmSL1xkweY3u7aw3tOjSugp5KjGVzfdS5WcfFtdWJd+w16ALvf+6oIeduNz1 EvWa0GnZlTvs+j0rQDS6tWlEHf2G77EgsJ4lIRBEpv/63cyfRYblzwUYYPaGRuOCiXOf xtqC1tiOjtdC7dzPfBur01SMdEpJC1B6VXQbhJSyTX8LYVUes+lJm/0hlIGSQvJEQGWW GO7SP58lc7U8kOuXIbu7i9g+uCkL+vG/9GwWlS2kjhj5hy2jS4d7043R+0N8K5CltWmJ bBjgwXpNErS5BrM6ifnEkrnFIz5CXAO8oT2HgXRAq4Wj7O84b9xD9JJNl2S1nTO7rXrW yv4w== X-Gm-Message-State: AOJu0Ywlw3djEM78SRCHtKouB5v2g1dV6KSvNcxVQgGaN8/PlZVxtN4x boMcFquIhQ83S8v6/s5pP+OdWf2hsnCc9FCLyN/ZXOv/HeJXxjii2QmNXyIuX0c= X-Gm-Gg: ASbGncu9daPfsXcbAhwcKg0V7AwY07g8lgdzoE+O8PxnOoJ7VmZCF2+3vJPEzQBbAqz crB+XNxBj+Ajw0ZsHo7AH4EhtUb3WFbdOfArCWCHi9k8p2vK/Cw42CE8e5VlfzDTbvh8wS0lM+8 8RYqvp43VgbYqKo07u1Q4hqJZ59eypZT1C3vKpEA2u5SYLivhlc/2UAJOmQEfSqdZyxrWocMoPP nhBcQrBLTAjx+VpvbJT9zW6GmnxGegyMNXDOe2/Ikn8iQeMiBVGXcm9Xg2OKIUp2nVnbvlDwUrq JrssU496p31Jzb4DdVU07+UfqzsZZXWr9yLOUn0urx3NfL/I X-Google-Smtp-Source: AGHT+IHM94MPnply1HiTFAMxyPX2aQdw9uOvMucL8T3ozc5n4IMo3Ydsn/+ynx3+wLagBt39kVVhcQ== X-Received: by 2002:a17:903:32ce:b0:223:4b8d:32f1 with SMTP id d9443c01a7336-22428882233mr396058055ad.1.1741848951161; Wed, 12 Mar 2025 23:55:51 -0700 (PDT) Received: from localhost ([157.82.205.237]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-73711694e74sm641742b3a.143.2025.03.12.23.55.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Mar 2025 23:55:50 -0700 (PDT) From: Akihiko Odaki Date: Thu, 13 Mar 2025 15:55:28 +0900 Subject: [PATCH RFC v4 02/11] net/vhost-vdpa: Report hashing capability MIME-Version: 1.0 Message-Id: <20250313-hash-v4-2-c75c494b495e@daynix.com> References: <20250313-hash-v4-0-c75c494b495e@daynix.com> In-Reply-To: <20250313-hash-v4-0-c75c494b495e@daynix.com> To: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , devel@daynix.com Cc: Akihiko Odaki X-Mailer: b4 0.15-dev-edae6 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62f.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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Report hashing capability so that virtio-net can deliver the correct capability information to the guest. Signed-off-by: Akihiko Odaki --- include/net/net.h | 3 +++ net/net.c | 9 +++++++++ net/vhost-vdpa.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index cdd5b109b0d2..545f4339cec8 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -60,6 +60,7 @@ typedef bool (HasVnetHdrLen)(NetClientState *, int); typedef void (SetOffload)(NetClientState *, int, int, int, int, int, int, int); typedef int (GetVnetHdrLen)(NetClientState *); typedef void (SetVnetHdrLen)(NetClientState *, int); +typedef bool (GetVnetHashSupportedTypes)(NetClientState *, uint32_t *); typedef int (SetVnetLE)(NetClientState *, bool); typedef int (SetVnetBE)(NetClientState *, bool); typedef struct SocketReadState SocketReadState; @@ -89,6 +90,7 @@ typedef struct NetClientInfo { SetVnetHdrLen *set_vnet_hdr_len; SetVnetLE *set_vnet_le; SetVnetBE *set_vnet_be; + GetVnetHashSupportedTypes *get_vnet_hash_supported_types; NetAnnounce *announce; SetSteeringEBPF *set_steering_ebpf; NetCheckPeerType *check_peer_type; @@ -189,6 +191,7 @@ void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6, int ecn, int ufo, int uso4, int uso6); int qemu_get_vnet_hdr_len(NetClientState *nc); void qemu_set_vnet_hdr_len(NetClientState *nc, int len); +bool qemu_get_vnet_hash_supported_types(NetClientState *nc, uint32_t *types); int qemu_set_vnet_le(NetClientState *nc, bool is_le); int qemu_set_vnet_be(NetClientState *nc, bool is_be); void qemu_macaddr_default_if_unset(MACAddr *macaddr); diff --git a/net/net.c b/net/net.c index 39d6f28158a3..d0ae3db0d864 100644 --- a/net/net.c +++ b/net/net.c @@ -573,6 +573,15 @@ void qemu_set_vnet_hdr_len(NetClientState *nc, int len) nc->info->set_vnet_hdr_len(nc, len); } +bool qemu_get_vnet_hash_supported_types(NetClientState *nc, uint32_t *types) +{ + if (!nc || !nc->info->get_vnet_hash_supported_types) { + return false; + } + + return nc->info->get_vnet_hash_supported_types(nc, types); +} + int qemu_set_vnet_le(NetClientState *nc, bool is_le) { #if HOST_BIG_ENDIAN diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index f7a54f46aa72..de006f3a2265 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -251,6 +251,32 @@ static bool vhost_vdpa_has_vnet_hdr(NetClientState *nc) return true; } +static bool vhost_vdpa_get_vnet_hash_supported_types(NetClientState *nc, + uint32_t *types) +{ + assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); + VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc); + uint64_t features = s->vhost_vdpa.dev->features; + int fd = s->vhost_vdpa.shared->device_fd; + struct { + struct vhost_vdpa_config hdr; + uint32_t supported_hash_types; + } config; + + if (!virtio_has_feature(features, VIRTIO_NET_F_HASH_REPORT) && + !virtio_has_feature(features, VIRTIO_NET_F_RSS)) { + return false; + } + + config.hdr.off = offsetof(struct virtio_net_config, supported_hash_types); + config.hdr.len = sizeof(config.supported_hash_types); + + assert(!ioctl(fd, VHOST_VDPA_GET_CONFIG, &config)); + *types = le32_to_cpu(config.supported_hash_types); + + return true; +} + static bool vhost_vdpa_has_ufo(NetClientState *nc) { assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); @@ -428,6 +454,7 @@ static NetClientInfo net_vhost_vdpa_info = { .stop = vhost_vdpa_net_client_stop, .cleanup = vhost_vdpa_cleanup, .has_vnet_hdr = vhost_vdpa_has_vnet_hdr, + .get_vnet_hash_supported_types = vhost_vdpa_get_vnet_hash_supported_types, .has_ufo = vhost_vdpa_has_ufo, .check_peer_type = vhost_vdpa_check_peer_type, .set_steering_ebpf = vhost_vdpa_set_steering_ebpf, @@ -1301,6 +1328,7 @@ static NetClientInfo net_vhost_vdpa_cvq_info = { .stop = vhost_vdpa_net_cvq_stop, .cleanup = vhost_vdpa_cleanup, .has_vnet_hdr = vhost_vdpa_has_vnet_hdr, + .get_vnet_hash_supported_types = vhost_vdpa_get_vnet_hash_supported_types, .has_ufo = vhost_vdpa_has_ufo, .check_peer_type = vhost_vdpa_check_peer_type, .set_steering_ebpf = vhost_vdpa_set_steering_ebpf, From patchwork Thu Mar 13 06:55:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 14014405 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 34497C282DE for ; Thu, 13 Mar 2025 06:56:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tscU8-0006Vx-Ij; Thu, 13 Mar 2025 02:56:04 -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 1tscU2-0006S7-Hn for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:55:59 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tscU0-00065J-Fb for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:55:58 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-22580c9ee0aso10608735ad.2 for ; Wed, 12 Mar 2025 23:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1741848955; x=1742453755; 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=SlV6ybuLU7WKrkJz3b71+OaSRrTTr9sSud3VMxid9GQ=; b=LxHwaX3uaAHy7BtWCaeOQ6MW4rQKHF5bO2sUDQ43mB9JnXf8J7zOtWqFdpJt4/N3p5 tdgkHcMttltKM9MD4Gw67VBkkk5R0ZHimnZq4I/KlxkezgBIo2Mv7PHRFyJw8dNr3cn6 NWCKbIO13jWC7fOk0d7Y5MrO2fVLVxP47oZJAk25ShcL5Aj+QiVQwtDeJy6Hcwra/DTd zXl7lORn5zREdEoMwc/9hnl7akVmVaW6c30e5w+/O0Taf6RfzCqLogQPg5bOcHkyOL5K P6qEMhgpVLJWVMfKc6csDsfc3QVyQrkND2eDR6Nn2AX8ZvctABhZ9/lMeOQHdA8mecq/ mC7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741848955; x=1742453755; 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=SlV6ybuLU7WKrkJz3b71+OaSRrTTr9sSud3VMxid9GQ=; b=CdDCZY2z1OhEx/iycN/FBPdrw0TsZKpEg80FPWM0JeR0BcM27ikBaaSVHvnzvACkwu nsIKtWDA1TkCI6N5I4mALI/0Hj59vGOuiDnMPYky818Daz1jQI8QJBNIzKbryVY9726Z /YJu6pmhQLQUgIk3HTVt1SplcKNBbdjECJmVv6ICVPjEzH9XYtqYj0+Bg9lUsXQ0/Yem yDykNaBVVmBkj8R+9MXq4jYdjG7uHzwWWfpydAbWqCbu/538EW6MYofZMMY1xJQa4krd S/hdkwFzOAQ0ucdvz1xJK0t2uRBam+UI5dt0vOAiqj9PfG+54qzPdC1LK+QRaeU3XCyU 59Rw== X-Gm-Message-State: AOJu0YxvQdrZk9UtSRv0Vcsd+wzTZIPdKfV5VKc8MTnYsl6PdvvPOH4X dAIKQ9DbVaSmibkelEL+GkZyQMCkqZ7cmdLu+HI4hBV0zcmnnNd69Qjgth5EZg4= X-Gm-Gg: ASbGncuUoVjonFrLB1Z+zbrI1GaiwV5HH0iLKv/Y790XW3b3ai+wWFHJXuDrBDnrhoq 0N8oztuNIprLZVndR6fc2dZIqVnry/uulSIxOkNAn1AsgKsyXO5Rf9qytdv6eovbjILnehBkS82 VmGzGP2DjZ9JanOgocgeTbBg2f70lLzw6U4f1Mazj8ps+2QHTBSQaiJ2oRhKEleyLoPgLgI4Btr uq9vEjfiT34U0YRySt8KWEoL3d7jOnCSTzCh52xArW6IdyvVWCC/CnHGx4H7GZcAMeLUODBUVFp iQ8gPmdthnX0vLZ4I9BfCC7NbbHUe2u98zHD0MdE4gd+T5kH X-Google-Smtp-Source: AGHT+IHTJdGNRh296jYk+pFzNVcSbXHroum/UKlqkUuc/KIx7yAvPrWTuf+VYCcjP2WXf9ibjg2VGg== X-Received: by 2002:a17:902:ce0a:b0:220:e338:8d2 with SMTP id d9443c01a7336-2242899474amr356581515ad.21.1741848955130; Wed, 12 Mar 2025 23:55:55 -0700 (PDT) Received: from localhost ([157.82.205.237]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-225c6bbcba7sm6396075ad.173.2025.03.12.23.55.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Mar 2025 23:55:54 -0700 (PDT) From: Akihiko Odaki Date: Thu, 13 Mar 2025 15:55:29 +0900 Subject: [PATCH RFC v4 03/11] virtio-net: Move virtio_net_get_features() down MIME-Version: 1.0 Message-Id: <20250313-hash-v4-3-c75c494b495e@daynix.com> References: <20250313-hash-v4-0-c75c494b495e@daynix.com> In-Reply-To: <20250313-hash-v4-0-c75c494b495e@daynix.com> To: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , devel@daynix.com Cc: Akihiko Odaki X-Mailer: b4 0.15-dev-edae6 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x633.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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Move virtio_net_get_features() to the later part of the file so that it can call other functions. Signed-off-by: Akihiko Odaki --- hw/net/virtio-net.c | 146 ++++++++++++++++++++++++++-------------------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index de87cfadffe1..df8de1148ba4 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -751,79 +751,6 @@ static void virtio_net_set_queue_pairs(VirtIONet *n) static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue); -static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features, - Error **errp) -{ - VirtIONet *n = VIRTIO_NET(vdev); - NetClientState *nc = qemu_get_queue(n->nic); - - /* Firstly sync all virtio-net possible supported features */ - features |= n->host_features; - - virtio_add_feature(&features, VIRTIO_NET_F_MAC); - - 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(&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(&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(&features, VIRTIO_NET_F_HASH_REPORT); - } - - 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); - } - - 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); - } - - if (!get_vhost_net(nc->peer)) { - return features; - } - - if (!ebpf_rss_is_loaded(&n->ebpf_rss)) { - virtio_clear_feature(&features, VIRTIO_NET_F_RSS); - } - features = vhost_net_get_features(get_vhost_net(nc->peer), features); - vdev->backend_features = features; - - if (n->mtu_bypass_backend && - (n->host_features & 1ULL << VIRTIO_NET_F_MTU)) { - features |= (1ULL << VIRTIO_NET_F_MTU); - } - - /* - * Since GUEST_ANNOUNCE is emulated the feature bit could be set without - * enabled. This happens in the vDPA case. - * - * Make sure the feature set is not incoherent, as the driver could refuse - * to start. - * - * TODO: QEMU is able to emulate a CVQ just for guest_announce purposes, - * helping guest to notify the new location with vDPA devices that does not - * support it. - */ - if (!virtio_has_feature(vdev->backend_features, VIRTIO_NET_F_CTRL_VQ)) { - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_ANNOUNCE); - } - - return features; -} - static uint64_t virtio_net_bad_features(VirtIODevice *vdev) { uint64_t features = 0; @@ -3080,6 +3007,79 @@ static int virtio_net_pre_load_queues(VirtIODevice *vdev) return 0; } +static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features, + Error **errp) +{ + VirtIONet *n = VIRTIO_NET(vdev); + NetClientState *nc = qemu_get_queue(n->nic); + + /* Firstly sync all virtio-net possible supported features */ + features |= n->host_features; + + virtio_add_feature(&features, VIRTIO_NET_F_MAC); + + 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(&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(&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(&features, VIRTIO_NET_F_HASH_REPORT); + } + + 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); + } + + 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); + } + + if (!get_vhost_net(nc->peer)) { + return features; + } + + if (!ebpf_rss_is_loaded(&n->ebpf_rss)) { + virtio_clear_feature(&features, VIRTIO_NET_F_RSS); + } + features = vhost_net_get_features(get_vhost_net(nc->peer), features); + vdev->backend_features = features; + + if (n->mtu_bypass_backend && + (n->host_features & 1ULL << VIRTIO_NET_F_MTU)) { + features |= (1ULL << VIRTIO_NET_F_MTU); + } + + /* + * Since GUEST_ANNOUNCE is emulated the feature bit could be set without + * enabled. This happens in the vDPA case. + * + * Make sure the feature set is not incoherent, as the driver could refuse + * to start. + * + * TODO: QEMU is able to emulate a CVQ just for guest_announce purposes, + * helping guest to notify the new location with vDPA devices that does not + * support it. + */ + if (!virtio_has_feature(vdev->backend_features, VIRTIO_NET_F_CTRL_VQ)) { + virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_ANNOUNCE); + } + + return features; +} + static int virtio_net_post_load_device(void *opaque, int version_id) { VirtIONet *n = opaque; From patchwork Thu Mar 13 06:55:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 14014402 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8B2FBC28B28 for ; Thu, 13 Mar 2025 06:56:30 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tscUB-0006X5-8G; Thu, 13 Mar 2025 02:56:07 -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 1tscU7-0006VK-QV for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:56:03 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tscU5-00065z-GJ for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:56:03 -0400 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-22548a28d0cso17021255ad.3 for ; Wed, 12 Mar 2025 23:55:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1741848958; x=1742453758; 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=qeez6nQnPC+h3f/6T7AEax1CgK0z5iWn6bN3521NMLM=; b=imeOaQgCa5h6bVULUE1OZHvbPjJq4R2Hz4MmNYtgWQqjgdJ3BsQz/VAdC6BBDN/3n5 1gg1FceEjN1dWyKfHb7Xq+MQ0pypyVsuUPrF6Ht1QvCfVUhpiBeOlyorAYX/k1rgQ0uF c8NKiGvU683JLttSEmMmDMG0WbXAp81fXNqtD9FLm91b1Gplqi+eMfOgo7Gs88sulYOI hO5KMiBtbvfcxG6+ejZ4FUITETNVw20/7ZDZVk/VwSXh2kTEzGaT40dYAfJJgXWPJJ6M aRcyMz3XZJW91rvHf+RYHoN4F/SXaRqBuqd8uHe6hzSUVTdhWlefgI5YSu7Oludr841r 6JBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741848958; x=1742453758; 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=qeez6nQnPC+h3f/6T7AEax1CgK0z5iWn6bN3521NMLM=; b=WEiiEJl/TnmHBILL+T421h3rkBEob/qOcNk40gWSeuXfCXI4jzSHX9Ocuq+89mOHPw x4UfvhrUlsZxWaaQrnB5/cEBOTIFUPxcJ0vWan1Nr/TSJb87l0Tc17IB+Bn1ObHLu1WI ZMeaAKK4pDfz3V6DPO9ocsJ0eGkCTuw5GAkMKSSRHCEH2MTYuSubQ9Ws64SSFvx5Xfr6 OnSHvVSgbjow3UTeSmH2OO/8uGt8/M98hszgEf3lLECSfr/8LqMsyfwoN0mmMsR8altK BIGJiv+NBrupaKicsPGUNdM2TZ/Qx98V6E+m2COuJHchA0NFWApRhVQU9iMSGEipDeOX uaGA== X-Gm-Message-State: AOJu0Yyefc1sR57I2hiTXUfpYSZLvtfo2EqkYs6QWrPSI59plQgMMgxv WwlJjAefS462nCZ8d0aU4F959W6KGzC/kJPL4vy35JaH6H6dGTeCEXOfBCgN5/g= X-Gm-Gg: ASbGncvbVuaD6s4oq5PcbpTLmWvVFZr8kccv5W0SSUdnruI5BBQ/B00gVXU17hCKggy AFxrkUeZsZYSwfV6mbsAOkPPkmkWdXxEt3PyiMX66v++ipw+w69tnTbmgV7nl3RzUI30+vAryX1 I34YLDgzGmgYzrTbVFFVUqMR1GBI0gCUR3UCFxpicgDEyKvJ506uSBHHGZr2OcXlVw4hleDKDiP CnM7WakAk2PTthHYPWIzV51QB7BTqR0CIQKMDBg9yN63cU7DJK3P/lzByxP+Tt622y+CC7R9+lr aQG3r16/4fOqt+e34NaWYh2DsdKXck849llMhpmHDwdptF7C X-Google-Smtp-Source: AGHT+IFxn00awTee98uXE3tJTj0eyWUbb3a45gfzBS7sXxKQ/QZjlck0VCIHo+LYoDKdvBsssZdUZg== X-Received: by 2002:a05:6a00:3d55:b0:736:5b85:a911 with SMTP id d2e1a72fcca58-736aaa1cf54mr41753854b3a.8.1741848958415; Wed, 12 Mar 2025 23:55:58 -0700 (PDT) Received: from localhost ([157.82.205.237]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-737115293a8sm649349b3a.10.2025.03.12.23.55.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Mar 2025 23:55:58 -0700 (PDT) From: Akihiko Odaki Date: Thu, 13 Mar 2025 15:55:30 +0900 Subject: [PATCH RFC v4 04/11] virtio-net: Retrieve peer hashing capability MIME-Version: 1.0 Message-Id: <20250313-hash-v4-4-c75c494b495e@daynix.com> References: <20250313-hash-v4-0-c75c494b495e@daynix.com> In-Reply-To: <20250313-hash-v4-0-c75c494b495e@daynix.com> To: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , devel@daynix.com Cc: Akihiko Odaki X-Mailer: b4 0.15-dev-edae6 Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62e.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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Retrieve peer hashing capability instead of hardcoding. Signed-off-by: Akihiko Odaki --- 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 b9ea9e824e3c..c4957c44c06e 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 df8de1148ba4..133317d8c358 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, uint8_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); /* @@ -1177,7 +1177,7 @@ static void rss_data_to_rss_config(struct VirtioNetRssData *data, { config->redirect = data->redirect; config->populate_hash = data->populate_hash; - config->hash_types = data->hash_types; + config->hash_types = data->runtime_hash_types; config->indirections_len = data->indirections_len; config->default_queue = data->default_queue; } @@ -1212,6 +1212,10 @@ static void virtio_net_detach_ebpf_rss(VirtIONet *n) 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 = n->rss_data.populate_hash; if (n->rss_data.populate_hash) { @@ -1226,7 +1230,7 @@ static void virtio_net_commit_rss_config(VirtIONet *n) } 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 { @@ -1337,7 +1341,7 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, err_value = (uint32_t)s; goto error; } - n->rss_data.hash_types = virtio_ldl_p(vdev, &cfg.hash_types); + n->rss_data.runtime_hash_types = virtio_ldl_p(vdev, &cfg.hash_types); n->rss_data.indirections_len = virtio_lduw_p(vdev, &cfg.indirection_table_mask); if (!do_rss) { @@ -1400,12 +1404,12 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, err_value = temp.b; goto error; } - if (!temp.b && n->rss_data.hash_types) { + if (!temp.b && n->rss_data.runtime_hash_types) { err_msg = "No key provided"; err_value = 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; } @@ -1810,7 +1814,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 = virtio_net_get_hash_type(hasip4, hasip6, l4hdr_proto, - n->rss_data.hash_types); + n->rss_data.runtime_hash_types); if (net_hash_type > NetPktRssIpV6UdpEx) { if (n->rss_data.populate_hash) { hdr->hash_value = VIRTIO_NET_HASH_REPORT_NONE; @@ -3012,6 +3016,14 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features, { VirtIONet *n = VIRTIO_NET(vdev); NetClientState *nc = qemu_get_queue(n->nic); + uint32_t supported_hash_types = n->rss_data.supported_hash_types; + uint32_t peer_hash_types = n->rss_data.peer_hash_types; + bool use_own_hash = + (supported_hash_types & VIRTIO_NET_RSS_SUPPORTED_HASHES) == + supported_hash_types; + bool use_peer_hash = + n->rss_data.peer_hash_available && + (supported_hash_types & peer_hash_types) == supported_hash_types; /* Firstly sync all virtio-net possible supported features */ features |= n->host_features; @@ -3048,12 +3060,28 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features, } 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; } - 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 = vhost_net_get_features(get_vhost_net(nc->peer), features); vdev->backend_features = features; @@ -3318,6 +3346,17 @@ static const VMStateDescription vmstate_virtio_net_has_vnet = { }, }; +static int virtio_net_rss_post_load(void *opaque, int version_id) +{ + VirtIONet *n = VIRTIO_NET(opaque); + + if (version_id == 1) { + n->rss_data.supported_hash_types = VIRTIO_NET_RSS_SUPPORTED_HASHES; + } + + return 0; +} + static bool virtio_net_rss_needed(void *opaque) { return VIRTIO_NET(opaque)->rss_data.enabled; @@ -3325,14 +3364,16 @@ static bool virtio_net_rss_needed(void *opaque) static const VMStateDescription vmstate_virtio_net_rss = { .name = "virtio-net-device/rss", - .version_id = 1, + .version_id = 2, .minimum_version_id = 1, + .post_load = virtio_net_rss_post_load, .needed = virtio_net_rss_needed, .fields = (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, @@ -3919,8 +3960,12 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) net_rx_pkt_init(&n->rx_pkt); - 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 = true; + n->rss_data.supported_hash_types = n->rss_data.peer_hash_types; + } else { + n->rss_data.supported_hash_types = VIRTIO_NET_RSS_SUPPORTED_HASHES; } } diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index de006f3a2265..0e9f4482ce7a 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -882,13 +882,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 == VIRTIO_NET_HASH_REPORT_NONE) { + n->rss_data.runtime_hash_types == VIRTIO_NET_HASH_REPORT_NONE) { return 0; } table = g_malloc_n(n->rss_data.indirections_len, sizeof(n->rss_data.indirections_table[0])); - cfg.hash_types = cpu_to_le32(n->rss_data.hash_types); + cfg.hash_types = cpu_to_le32(n->rss_data.runtime_hash_types); if (do_rss) { /* From patchwork Thu Mar 13 06:55:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 14014407 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 15361C282DE for ; Thu, 13 Mar 2025 06:57:28 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tscUf-0007NI-Fs; Thu, 13 Mar 2025 02:56:39 -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 1tscU8-0006W2-O8 for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:56:05 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tscU7-00067H-29 for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:56:04 -0400 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-2fec13a4067so1106213a91.2 for ; Wed, 12 Mar 2025 23:56:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1741848961; x=1742453761; 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=BsSYiRkHTorsnB7/LyjN2/FxGb+rg2Z3myQn2vfvIco=; b=EDUAeTmAZ6519yBCZYWmGr1lSjSf7w8FvwYI3MdPD9op8kop+Ed3GLQ1uVdVFofqq0 fjM2tqO7Ys0C8QQHmNXb9bWQqxPhwQmblDrHGZH2pq0JdO07HXDhhB8qKA2kjmRNiF+4 8BpYMti9hMRhRYeapPkrTJ5P2RSwI3opzZIFwg1EHYhhrYN/NCrrFJin5ccpZr+VaioP gSJLi19Cg3vyG7jsZaIAIoqrk4xTmyRRyDdJ8skCwzUDMgSoLPXaDDNblr/8syYh3/Tm aJDSEEz/iTfuTwSfHVSJOsmi87HIhTOszyjgrjq7Nk5V1V2IQXF7OnuFdmrjLN7afqoa qRRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741848961; x=1742453761; 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=BsSYiRkHTorsnB7/LyjN2/FxGb+rg2Z3myQn2vfvIco=; b=iauuYcs/VOlhkvHx9pxbA9B7I9B32iZ3dIbcBhAjz6bO1UQ5kzqYjaYjZ+F5AaXvQv STPZRpDRGKUzlqeFy/oGbzW3UmsEDxt9vMEJpb3tXgb5XJbf1Id/UA7jy5Q5mBWPgtY4 5LXsdjEL6vWQb2Osv931eD4w+IqHt80xh/cTYP235lQQCulACvmtGp7FsOE4h9+9WouO IXkLtcwpzeXAHPyCrScJFXyEVy/7HZxEyQr7teEKXQ0HxjZWIV3tkTx1WJqDTVHa7NVn IFP2hGaWYLF4ATF8wdf9DWv18Tjq7tDxhIdhepjCt8iuh/L+BoXfgZ0XZHqkdFQBtfk+ uvXQ== X-Gm-Message-State: AOJu0YwpTjkQwR80xWgIbIasd3ltHUZiyUb7IJAtA0Wp8mypAPa23eGX UzThSOpe6cOt7aDVbO4KW3IVr6l3laqTMEAB/lupQbqx9oWEh0Y+0tnR7jCKLng= X-Gm-Gg: ASbGnctr87R0LNp539Pf3bdvJZpCdOcuIjYhKO28PNj/MhnaMQZnYMUcu/Zrl3np4HV jAnlxXzbzE6Qa6SWtcX40zwhBRzrjD52+IQFHQS8nRFfnHernAENhPBwnwDtW84/sFpu8aOW9Ya sVGBR6gl1tfNWihXHxPpivfeaI2lvbh/X/wd/mxDgGnSbmrVKNA5jhLJWfCdMzgEc4WCAy/qPxD 4l2e4DA5T/UyvytDhLpIBpK/BVrWJnIU8D8ycgH4E+cJUqGpjsPWlJaXXTyDaZu+t8Tp7iHwFMN 9H6uwuCQJoSMxBMPh1YciF81rcPc8qUw3rspl1djpZY8owPn X-Google-Smtp-Source: AGHT+IGoiP7VIvkC9eV5s5w0a1tlykMrn1deS/Q7nwiYUu0KbQiYVFprFbLesxhYHM+usz9Rqw7K2Q== X-Received: by 2002:a17:90b:4c51:b0:2f9:c139:b61f with SMTP id 98e67ed59e1d1-300ff0ca64cmr15701269a91.14.1741848961677; Wed, 12 Mar 2025 23:56:01 -0700 (PDT) Received: from localhost ([157.82.205.237]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-30138b3b3c0sm607930a91.1.2025.03.12.23.55.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Mar 2025 23:56:01 -0700 (PDT) From: Akihiko Odaki Date: Thu, 13 Mar 2025 15:55:31 +0900 Subject: [PATCH RFC v4 05/11] net/vhost-vdpa: Remove dummy SetSteeringEBPF MIME-Version: 1.0 Message-Id: <20250313-hash-v4-5-c75c494b495e@daynix.com> References: <20250313-hash-v4-0-c75c494b495e@daynix.com> In-Reply-To: <20250313-hash-v4-0-c75c494b495e@daynix.com> To: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , devel@daynix.com Cc: Akihiko Odaki X-Mailer: b4 0.15-dev-edae6 Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1030.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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org It is no longer used. Signed-off-by: Akihiko Odaki --- net/vhost-vdpa.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 0e9f4482ce7a..d35348b1e742 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -238,12 +238,6 @@ static void vhost_vdpa_cleanup(NetClientState *nc) g_free(s->vhost_vdpa.shared); } -/** Dummy SetSteeringEBPF to support RSS for vhost-vdpa backend */ -static bool vhost_vdpa_set_steering_ebpf(NetClientState *nc, int prog_fd) -{ - return true; -} - static bool vhost_vdpa_has_vnet_hdr(NetClientState *nc) { assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); @@ -457,7 +451,6 @@ static NetClientInfo net_vhost_vdpa_info = { .get_vnet_hash_supported_types = vhost_vdpa_get_vnet_hash_supported_types, .has_ufo = vhost_vdpa_has_ufo, .check_peer_type = vhost_vdpa_check_peer_type, - .set_steering_ebpf = vhost_vdpa_set_steering_ebpf, }; static int64_t vhost_vdpa_get_vring_group(int device_fd, unsigned vq_index, @@ -1331,7 +1324,6 @@ static NetClientInfo net_vhost_vdpa_cvq_info = { .get_vnet_hash_supported_types = vhost_vdpa_get_vnet_hash_supported_types, .has_ufo = vhost_vdpa_has_ufo, .check_peer_type = vhost_vdpa_check_peer_type, - .set_steering_ebpf = vhost_vdpa_set_steering_ebpf, }; /* From patchwork Thu Mar 13 06:55:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 14014403 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A48F8C282DE for ; Thu, 13 Mar 2025 06:56:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tscUK-0006j2-0b; Thu, 13 Mar 2025 02:56:17 -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 1tscUB-0006c8-Uz for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:56:08 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tscUA-00067r-6M for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:56:07 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-22409077c06so16026145ad.1 for ; Wed, 12 Mar 2025 23:56:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1741848965; x=1742453765; 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=MopfiGBM9Z8oEbwyR+l0MgHiADxFvlgYbngCIIS2QmI=; b=EU5kQIESTU4jLx9nYqKz8AvdNMZTNurJjwcYjgdMLOBR5E+fys4hvwQmuGr7fFtvwb AlFb4NA5XremgJq9aFtMP7EWPYKbNel3kn4p9rlH89ed5GYaWnQ7dOx2psl+fAPNHL+p 3ewNAEIbt5hjLadmSCaxfRz6bQO1yI5OZI2aVp5eq7h4H+RJtNX7QO01GAFyXzAYwiNZ LcyaHUbBWVNJKjvsIqqEWnck05qLgyZTHiVie8qDJbJh8hxvNl+jskFl0fCZAOULDlfD s3LaDkRSHQXDROk1C3Fofisr6g+lp/bLROuoz9z5fHr2cgtnwYTz4CXDScd7y10BOj9W +vFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741848965; x=1742453765; 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=MopfiGBM9Z8oEbwyR+l0MgHiADxFvlgYbngCIIS2QmI=; b=NS1IKiouQ1aXTxbYMFG98gI8Y+Yg9jX7t/Mg60sAtDa7g9vYOi2aFVNvjboWYsC+1U L9QKpB1QKK33TBwzp1eZ5ckrh/EkcYOIWBCMdOZ9kYSv8eKY8xCktyr9ljiAsCqSl++1 JWhT7XEksYKc6ibwnACi8+fBXdYaW3x1QsirWzkc03H4UUxt1aBkE7nS7/dYOsNv1mbt KYH14zPB/NO9QIwmIAPj8A2H12iK/aM1c8I+EaDmtCQDl6cAszEEOVbLhzW+exO5Lv7t gvZX9CXM0OjawxGSyOIGNtvWRS9SusiNPYsexPQW7wqgX9sFnAzOA55Y4+zCyE4P4pgR 52rA== X-Gm-Message-State: AOJu0Yw4FOaZEK7izrpbpvlRjQGLB+NcgR1Axjj/Oe+I0R8Bd+nWcYmV qAmxzATxONGZf2FCLJv7G+TIA9B5PXf8Ai2brPN/ZPorJV5g4M4A3O8hDYHg+q4= X-Gm-Gg: ASbGncuEkF16eOM1cuDYUFhGX/pF3hbwSTgr9G2Im6VqdUcqviGGc3OV/UBpCcoWwuc iJYpMM7oyxW7Dbhv8PtvgV69F0yGvUWTPgybkBJFHmxCE6lODtQ8g86lwwMWAd/+8PTPlr4gzGi DxeDZmhyNefOq7QcFnIwUtNwVw7BaGzsohK1bRJRXjVZonbZcBda0FeYl2uIhKhY/CeAhOsQLlc LVZO2dLhFAipkH5XfHEMuYAnfltIND4Qv9D+5SLZzKaaWA/EkVXqkHB/OSZeuJkZcPT7B0TVNJ1 VqslJKpEuwLksNusqTDimpkc55mS/gE/ax4YPOXeBFdM18kA03QJ2VMSDoY= X-Google-Smtp-Source: AGHT+IEx/lbs2ZrH4aTBsjgYxVv/7NeQ54forRfKtiD2Rt4KJWIyqWTM93rXDacqgcUORICBDbC8rw== X-Received: by 2002:a17:903:2405:b0:224:24d5:f20a with SMTP id d9443c01a7336-22428bfdba7mr436327225ad.48.1741848964926; Wed, 12 Mar 2025 23:56:04 -0700 (PDT) Received: from localhost ([157.82.205.237]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-7371167e02esm639778b3a.95.2025.03.12.23.56.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Mar 2025 23:56:04 -0700 (PDT) From: Akihiko Odaki Date: Thu, 13 Mar 2025 15:55:32 +0900 Subject: [PATCH RFC v4 06/11] virtio-net: Add hash type options MIME-Version: 1.0 Message-Id: <20250313-hash-v4-6-c75c494b495e@daynix.com> References: <20250313-hash-v4-0-c75c494b495e@daynix.com> In-Reply-To: <20250313-hash-v4-0-c75c494b495e@daynix.com> To: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , devel@daynix.com Cc: Akihiko Odaki X-Mailer: b4 0.15-dev-edae6 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x635.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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org By default, virtio-net limits the hash types that will be advertised to the guest so that all hash types are covered by the offloading capability the client provides. This change allows to override this behavior and to advertise hash types that require user-space hash calculation by specifying "on" for the corresponding properties. Signed-off-by: Akihiko Odaki --- include/hw/virtio/virtio-net.h | 1 + hw/net/virtio-net.c | 45 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index c4957c44c06e..73fdefc0dcb8 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -148,6 +148,7 @@ typedef struct VirtioNetRssData { uint32_t runtime_hash_types; uint32_t supported_hash_types; uint32_t peer_hash_types; + OnOffAutoBit64 specified_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 133317d8c358..b0f2ad78cb39 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3963,9 +3963,14 @@ static void virtio_net_device_realize(DeviceState *dev, Error **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 = true; - n->rss_data.supported_hash_types = n->rss_data.peer_hash_types; + n->rss_data.supported_hash_types = + n->rss_data.specified_hash_types.on_bits | + (n->rss_data.specified_hash_types.auto_bits & + n->rss_data.peer_hash_types); } else { - n->rss_data.supported_hash_types = VIRTIO_NET_RSS_SUPPORTED_HASHES; + n->rss_data.supported_hash_types = + n->rss_data.specified_hash_types.on_bits | + n->rss_data.specified_hash_types.auto_bits; } } @@ -4182,6 +4187,42 @@ static const Property virtio_net_properties[] = { VIRTIO_NET_F_GUEST_USO6, true), DEFINE_PROP_BIT64("host_uso", VirtIONet, host_features, VIRTIO_NET_F_HOST_USO, true), + DEFINE_PROP_ON_OFF_AUTO_BIT64("hash-ipv4", VirtIONet, + rss_data.specified_hash_types, + VIRTIO_NET_HASH_REPORT_IPv4 - 1, + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("hash-tcp4", VirtIONet, + rss_data.specified_hash_types, + VIRTIO_NET_HASH_REPORT_TCPv4 - 1, + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("hash-udp4", VirtIONet, + rss_data.specified_hash_types, + VIRTIO_NET_HASH_REPORT_UDPv4 - 1, + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("hash-ipv6", VirtIONet, + rss_data.specified_hash_types, + VIRTIO_NET_HASH_REPORT_IPv6 - 1, + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("hash-tcp6", VirtIONet, + rss_data.specified_hash_types, + VIRTIO_NET_HASH_REPORT_TCPv6 - 1, + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("hash-udp6", VirtIONet, + rss_data.specified_hash_types, + VIRTIO_NET_HASH_REPORT_UDPv6 - 1, + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("hash-ipv6ex", VirtIONet, + rss_data.specified_hash_types, + VIRTIO_NET_HASH_REPORT_IPv6_EX - 1, + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("hash-tcp6ex", VirtIONet, + rss_data.specified_hash_types, + VIRTIO_NET_HASH_REPORT_TCPv6_EX - 1, + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("hash-udp6ex", VirtIONet, + rss_data.specified_hash_types, + VIRTIO_NET_HASH_REPORT_UDPv6_EX - 1, + ON_OFF_AUTO_AUTO), }; static void virtio_net_class_init(ObjectClass *klass, void *data) From patchwork Thu Mar 13 06:55:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 14014408 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EAF03C28B28 for ; Thu, 13 Mar 2025 06:57:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tscUi-0007QQ-Qe; Thu, 13 Mar 2025 02:56:41 -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 1tscUG-0006j1-Fj for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:56:14 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tscUE-00068j-7j for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:56:12 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-219f8263ae0so11196815ad.0 for ; Wed, 12 Mar 2025 23:56:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1741848969; x=1742453769; 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=MgQDpkdeB+gab9lnEM4WvK+cxeAmq+htFO9Du/yWDvw=; b=kOrpoFFtGofTIgyByPTXmC0GwoNuI348B4on7bNVKZPPLWbsjeFchse8Xry/bJEOy/ 5wMvo8v4A5zbGXoetUTqVVdRM7p0WmUXQ3pwy1ST4z0T28877fGyM16g+cAVC9Se3UDY TcxR30TTW3A0EnSjVz9DkZlLryAY359wsIYfIE36PSjsmnfbpA8cLWDnecxd8poPWC1o wZoe8BzrLWWgviKL7RI8/MkKSjm8/CyKAokSrJmGtbHOqXxZsamylMxzHK+VbUZ22D8t IE6MYTqxdwwHl+4iRUElWRgxmsZFUUKuaHomT8Omex6ExO05L/YaYMJvtkBG0wewNVQ/ rUpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741848969; x=1742453769; 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=MgQDpkdeB+gab9lnEM4WvK+cxeAmq+htFO9Du/yWDvw=; b=N8B6pzMIOAWDvsnWJ+/fesmnL7GT+ms0OXXeWOOisTEBdQtlt8os0h7gbFxhbiSMWN C4QcEt+bzdaDjkGTIR6zO8dXjwAulmrzv+g0LFuHXdKI/kFM2jEBX9a1kIIHdj49OWNT LLhVz36DbRyrvGW6F+7gkzqjgssL0bBMr7v/GyHC9G8/66TBgQm+LaCi6d5YSB33Ib3i WiPDAWMfK5iGDWWCmxyJCjBn1WCqNfQhnZRAPb7Bml8zyia29IEYJbKR9x0DyxmDVoj/ ggkcGOWMS5U2H4G0AXL0UXz/wwdfSV4bKj3djapTQ+KC2ZlSjQuhkIXYAdIve+tXQYD0 iJvw== X-Gm-Message-State: AOJu0Yxa0XCXr0HK4LmNUFoUcciOmGD+83+d/Xsb/SRBwhjZiofVrKmT 2JfkZP5FrS4ROR8L0CkcryoFTPfUbwICIufg588RNwE70Ub+QgIp3wyUfJI+L0QAnkPLB6Jmxut T6LA= X-Gm-Gg: ASbGncvMXvuutuhdWQC0dpF/nsc+SliX2VPW3nK5B0qp2QZstnQKFm5D1Jq5+o4PEFa zUnLitg/HOtYrceoLymfivyDSShMsbbjRr/AIAhfX3Kxi9Dw23/g7MVJmTZX+cXLMd584qfDc1M rIiQF5Lwg76jfiQuVLKBw73wE5Q65NlapkEUrHNtMjgvjUdyQ7oQhuTlDSSor9R0a3FI366o4On sDVSlNvfgQ3kUpHyF9fNFlX+r1QSMWi1TtAvIgZ1B3l4t/Fcz7euZbb30iIVBN7EhqITuC2k+wZ 3bcVg4RrX9KFVkyABi9eb7Wh5ouzy6Ur5fXtN1icKxGHX2aBAgXvlYqSKZ0= X-Google-Smtp-Source: AGHT+IG6r3p8xi8Lt47DQwevXJcaIQYoVt+HaSWDhBCiHZgG4uHoEv9PVa4lkZdUjG8CLLM77yUxGQ== X-Received: by 2002:a17:902:e745:b0:223:3bf6:7e6a with SMTP id d9443c01a7336-22592e2c969mr153166385ad.12.1741848968836; Wed, 12 Mar 2025 23:56:08 -0700 (PDT) Received: from localhost ([157.82.205.237]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-225c6888675sm6542825ad.51.2025.03.12.23.56.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Mar 2025 23:56:08 -0700 (PDT) From: Akihiko Odaki Date: Thu, 13 Mar 2025 15:55:33 +0900 Subject: [PATCH RFC v4 07/11] net: Allow configuring virtio hashing MIME-Version: 1.0 Message-Id: <20250313-hash-v4-7-c75c494b495e@daynix.com> References: <20250313-hash-v4-0-c75c494b495e@daynix.com> In-Reply-To: <20250313-hash-v4-0-c75c494b495e@daynix.com> To: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , devel@daynix.com Cc: Akihiko Odaki X-Mailer: b4 0.15-dev-edae6 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x632.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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This adds set_vnet_hash() to configure virtio hashing and implements it for Linux's tap. vDPA will have an empty function as configuring virtio hashing is done with the load(). Signed-off-by: Akihiko Odaki --- include/net/net.h | 17 +++++++++++++++++ net/tap-linux.h | 1 + net/tap_int.h | 2 ++ net/net.c | 5 +++++ net/tap-bsd.c | 5 +++++ net/tap-linux.c | 5 +++++ net/tap-solaris.c | 5 +++++ net/tap-stub.c | 5 +++++ net/tap.c | 7 +++++++ net/vhost-vdpa.c | 7 +++++++ 10 files changed, 59 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 545f4339cec8..fa69e14c9829 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -35,6 +35,20 @@ typedef struct NICConf { int32_t bootindex; } NICConf; +#define NET_VNET_HASH_REPORT 1 +#define NET_VNET_HASH_RSS 2 + +typedef struct NetVnetHash { + uint16_t flags; + uint8_t pad[2]; + uint32_t types; +} NetVnetHash; + +typedef struct NetVnetHashRss { + uint16_t indirection_table_mask; + uint16_t unclassified_queue; +} NetVnetHashRss; + #define DEFINE_NIC_PROPERTIES(_state, _conf) \ DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \ DEFINE_PROP_NETDEV("netdev", _state, _conf.peers) @@ -61,6 +75,7 @@ typedef void (SetOffload)(NetClientState *, int, int, int, int, int, int, int); typedef int (GetVnetHdrLen)(NetClientState *); typedef void (SetVnetHdrLen)(NetClientState *, int); typedef bool (GetVnetHashSupportedTypes)(NetClientState *, uint32_t *); +typedef void (SetVnetHash)(NetClientState *, const NetVnetHash *); typedef int (SetVnetLE)(NetClientState *, bool); typedef int (SetVnetBE)(NetClientState *, bool); typedef struct SocketReadState SocketReadState; @@ -91,6 +106,7 @@ typedef struct NetClientInfo { SetVnetLE *set_vnet_le; SetVnetBE *set_vnet_be; GetVnetHashSupportedTypes *get_vnet_hash_supported_types; + SetVnetHash *set_vnet_hash; NetAnnounce *announce; SetSteeringEBPF *set_steering_ebpf; NetCheckPeerType *check_peer_type; @@ -192,6 +208,7 @@ void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6, int qemu_get_vnet_hdr_len(NetClientState *nc); void qemu_set_vnet_hdr_len(NetClientState *nc, int len); bool qemu_get_vnet_hash_supported_types(NetClientState *nc, uint32_t *types); +void qemu_set_vnet_hash(NetClientState *nc, const NetVnetHash *hash); int qemu_set_vnet_le(NetClientState *nc, bool is_le); int qemu_set_vnet_be(NetClientState *nc, bool is_be); void qemu_macaddr_default_if_unset(MACAddr *macaddr); diff --git a/net/tap-linux.h b/net/tap-linux.h index 9a58cecb7f47..5fac64c24f99 100644 --- a/net/tap-linux.h +++ b/net/tap-linux.h @@ -32,6 +32,7 @@ #define TUNSETVNETLE _IOW('T', 220, int) #define TUNSETVNETBE _IOW('T', 222, int) #define TUNSETSTEERINGEBPF _IOR('T', 224, int) +#define TUNSETVNETHASH _IOW('T', 229, NetVnetHash) #endif diff --git a/net/tap_int.h b/net/tap_int.h index 8857ff299d22..e1b53e343397 100644 --- a/net/tap_int.h +++ b/net/tap_int.h @@ -27,6 +27,7 @@ #define NET_TAP_INT_H #include "qapi/qapi-types-net.h" +#include "net/net.h" int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required, int mq_required, Error **errp); @@ -40,6 +41,7 @@ int tap_probe_has_uso(int fd); void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo, int uso4, int uso6); void tap_fd_set_vnet_hdr_len(int fd, int len); +void tap_fd_set_vnet_hash(int fd, const NetVnetHash *hash); int tap_fd_set_vnet_le(int fd, int vnet_is_le); int tap_fd_set_vnet_be(int fd, int vnet_is_be); int tap_fd_enable(int fd); diff --git a/net/net.c b/net/net.c index d0ae3db0d864..eaf82082137d 100644 --- a/net/net.c +++ b/net/net.c @@ -582,6 +582,11 @@ bool qemu_get_vnet_hash_supported_types(NetClientState *nc, uint32_t *types) return nc->info->get_vnet_hash_supported_types(nc, types); } +void qemu_set_vnet_hash(NetClientState *nc, const NetVnetHash *hash) +{ + nc->info->set_vnet_hash(nc, hash); +} + int qemu_set_vnet_le(NetClientState *nc, bool is_le) { #if HOST_BIG_ENDIAN diff --git a/net/tap-bsd.c b/net/tap-bsd.c index b4c84441ba8b..2eee0c0a0ec5 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -221,6 +221,11 @@ void tap_fd_set_vnet_hdr_len(int fd, int len) { } +void tap_fd_set_vnet_hash(int fd, const NetVnetHash *hash) +{ + g_assert_not_reached(); +} + int tap_fd_set_vnet_le(int fd, int is_le) { return -EINVAL; diff --git a/net/tap-linux.c b/net/tap-linux.c index 22ec2f45d2b7..c053828b056b 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -205,6 +205,11 @@ void tap_fd_set_vnet_hdr_len(int fd, int len) } } +void tap_fd_set_vnet_hash(int fd, const NetVnetHash *hash) +{ + assert(!ioctl(fd, TUNSETVNETHASH, hash)); +} + int tap_fd_set_vnet_le(int fd, int is_le) { int arg = is_le ? 1 : 0; diff --git a/net/tap-solaris.c b/net/tap-solaris.c index 51b7830bef1d..c65104b84e93 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -225,6 +225,11 @@ void tap_fd_set_vnet_hdr_len(int fd, int len) { } +void tap_fd_set_vnet_hash(int fd, const NetVnetHash *hash) +{ + g_assert_not_reached(); +} + int tap_fd_set_vnet_le(int fd, int is_le) { return -EINVAL; diff --git a/net/tap-stub.c b/net/tap-stub.c index 38673434cbd6..5bdc76216b7f 100644 --- a/net/tap-stub.c +++ b/net/tap-stub.c @@ -56,6 +56,11 @@ void tap_fd_set_vnet_hdr_len(int fd, int len) { } +void tap_fd_set_vnet_hash(int fd, const NetVnetHash *hash) +{ + g_assert_not_reached(); +} + int tap_fd_set_vnet_le(int fd, int is_le) { return -EINVAL; diff --git a/net/tap.c b/net/tap.c index ae1c7e398321..1136018c1965 100644 --- a/net/tap.c +++ b/net/tap.c @@ -248,6 +248,12 @@ static void tap_set_vnet_hdr_len(NetClientState *nc, int len) s->using_vnet_hdr = true; } +static void tap_set_vnet_hash(NetClientState *nc, const NetVnetHash *hash) +{ + TAPState *s = DO_UPCAST(TAPState, nc, nc); + return tap_fd_set_vnet_hash(s->fd, hash); +} + static int tap_set_vnet_le(NetClientState *nc, bool is_le) { TAPState *s = DO_UPCAST(TAPState, nc, nc); @@ -344,6 +350,7 @@ static NetClientInfo net_tap_info = { .has_vnet_hdr_len = tap_has_vnet_hdr_len, .set_offload = tap_set_offload, .set_vnet_hdr_len = tap_set_vnet_hdr_len, + .set_vnet_hash = tap_set_vnet_hash, .set_vnet_le = tap_set_vnet_le, .set_vnet_be = tap_set_vnet_be, .set_steering_ebpf = tap_set_steering_ebpf, diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index d35348b1e742..e5ee7cd22d4f 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -271,6 +271,11 @@ static bool vhost_vdpa_get_vnet_hash_supported_types(NetClientState *nc, return true; } +static void vhost_vdpa_set_vnet_hash(NetClientState *nc, + const NetVnetHash *hash) +{ +} + static bool vhost_vdpa_has_ufo(NetClientState *nc) { assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA); @@ -449,6 +454,7 @@ static NetClientInfo net_vhost_vdpa_info = { .cleanup = vhost_vdpa_cleanup, .has_vnet_hdr = vhost_vdpa_has_vnet_hdr, .get_vnet_hash_supported_types = vhost_vdpa_get_vnet_hash_supported_types, + .set_vnet_hash = vhost_vdpa_set_vnet_hash, .has_ufo = vhost_vdpa_has_ufo, .check_peer_type = vhost_vdpa_check_peer_type, }; @@ -1322,6 +1328,7 @@ static NetClientInfo net_vhost_vdpa_cvq_info = { .cleanup = vhost_vdpa_cleanup, .has_vnet_hdr = vhost_vdpa_has_vnet_hdr, .get_vnet_hash_supported_types = vhost_vdpa_get_vnet_hash_supported_types, + .set_vnet_hash = vhost_vdpa_set_vnet_hash, .has_ufo = vhost_vdpa_has_ufo, .check_peer_type = vhost_vdpa_check_peer_type, }; From patchwork Thu Mar 13 06:55:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 14014406 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2145EC282DE for ; Thu, 13 Mar 2025 06:57:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tscUx-0007eh-QX; Thu, 13 Mar 2025 02:56:59 -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 1tscUJ-0006pj-Iq for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:56:15 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tscUH-00069V-N1 for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:56:15 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-22398e09e39so11095875ad.3 for ; Wed, 12 Mar 2025 23:56:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1741848972; x=1742453772; 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=PsM+Cnp++8fm++9PBlCkfszQ/qYqRJZZsKVMXkCvzrE=; b=rnL9slShvI4DKQtKlA1CyRDQKK6tNtbdb5UBwTJizuJs55o0PKK6zjtsLO78ZZP1zg fFtGN0VgVvSj82P1i9L6oKGlRACh3K6/L8v5KAtaEKQjXXBDjcCurLvrGyvf95h/PYMr 49yA09EeaySdovqE/aP2swbNQkPRW+AQCTpMHSVbQmG8WrrIQdN0n7irM+30b684TwJx FHNPb+Kfau2dnHpTD4a8I91Ur8mtYDYWeXXc34J7UDVL9Ggk7y27D+HacL+lWObx/W68 BauCcG2tJyvh5IIXn0ASbch0J0rOtZzjdCAxsFyXJlhDzb5pIY/6pswIjdEko7+9lFkL rNIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741848972; x=1742453772; 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=PsM+Cnp++8fm++9PBlCkfszQ/qYqRJZZsKVMXkCvzrE=; b=g5UvsmnK1IWcsTwWe+V/4mdEmI8PeiDgVZSfpT1q0ePADPVfEG8yzN/pUQzSXabJC1 KZ4zzdtYlvLJDu0xc7wnNmdIzX+L4rAc6HSt5kPLguY+M/ibSWjIQDd6xtFNfXm9INlE aMUnQjG3p5QJOS1U9oYvyIDxyxA4uyOT167oHszBUGkmnVOedsQHTe5BBse0XFdR2v/0 CF+KyUF1TyvjyEYwxedYoxY9ijv21aLItlXfi2UvB3UVqQBUVQeENgC5x7rqO3a4OTrS eb4HNsuG4Wc1RxCHN3hIVxsHY2GREq/CVikoJ49dGAk1LcgeouAWy1ITk6MuzdRdBd8C AdIA== X-Gm-Message-State: AOJu0YypWlXwZNY3s3qjnMSB+UIHuVLZJM0CgUHTjFqf2WxTm4oxFQSv OjQmAGGAtVfcOOTXjAnDCoigV14eaecluDTxraPC+E046Ie68SK6kSz+rizsWPtnMpssObzXcT7 r5TU= X-Gm-Gg: ASbGncvEMlaeZ72sLSR5/fxpOGfgNKKSAXd1ttL+BSqrqo7Ro489qxjLkbsT8vhfJiw UGe6TTsknO8AfDci5gc/WFIEXKp4dKPzvBPcc+Hy8T0miBO941XkTPEA/lDQNTdOJKitnAtWWC3 A3GjAivXau6/Fcbz00PrxtFZgH7mCFhX8CfmIIieqEvYhk1d0KTxzPNFRoLULDAz9qYe2xJ+xEW crTtqWorLv3bXztxanRyrmiYbIpoubLkmj7jacGA4UrrNfrmF96BmLX79WLebIYTKkUq3TbO7oV B6LGPifIokB5VWPGPSMl0GY7Up4ucxiyWnkfMFoedRWwu0WZ X-Google-Smtp-Source: AGHT+IHE7AuOv9sAizGHSoQoKxjTQBVuoXPApftupIVhjBN9TJGbbM24hEQmosIt8IERG9IK93CRTQ== X-Received: by 2002:a05:6a00:4fc6:b0:736:32d2:aa82 with SMTP id d2e1a72fcca58-736aab17045mr33600845b3a.23.1741848972128; Wed, 12 Mar 2025 23:56:12 -0700 (PDT) Received: from localhost ([157.82.205.237]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-73711529531sm633744b3a.2.2025.03.12.23.56.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Mar 2025 23:56:11 -0700 (PDT) From: Akihiko Odaki Date: Thu, 13 Mar 2025 15:55:34 +0900 Subject: [PATCH RFC v4 08/11] virtio-net: Use qemu_set_vnet_hash() MIME-Version: 1.0 Message-Id: <20250313-hash-v4-8-c75c494b495e@daynix.com> References: <20250313-hash-v4-0-c75c494b495e@daynix.com> In-Reply-To: <20250313-hash-v4-0-c75c494b495e@daynix.com> To: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , devel@daynix.com Cc: Akihiko Odaki X-Mailer: b4 0.15-dev-edae6 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x634.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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This is necessary to offload hashing to tap. Signed-off-by: Akihiko Odaki --- hw/net/virtio-net.c | 77 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 13 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index b0f2ad78cb39..e125478ae834 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1212,20 +1212,65 @@ static void virtio_net_detach_ebpf_rss(VirtIONet *n) 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 = n->rss_data.populate_hash; - if (n->rss_data.populate_hash) { - virtio_net_detach_ebpf_rss(n); - } else if (!virtio_net_attach_ebpf_rss(n)) { - if (get_vhost_net(qemu_get_queue(n->nic)->peer)) { - warn_report("Can't load eBPF RSS for vhost"); + if (n->rss_data.peer_hash_available && + (n->rss_data.peer_hash_types & n->rss_data.runtime_hash_types) == + n->rss_data.runtime_hash_types) { + NetVnetHash hash = { + .flags = (n->rss_data.redirect ? NET_VNET_HASH_RSS : 0) | + (n->rss_data.populate_hash ? NET_VNET_HASH_REPORT : 0), + .types = n->rss_data.runtime_hash_types + }; + + if (n->rss_data.redirect) { + size_t indirection_table_size = + n->rss_data.indirections_len * + sizeof(*n->rss_data.indirections_table); + + size_t hash_size = sizeof(NetVnetHash) + + sizeof(NetVnetHashRss) + + indirection_table_size + + sizeof(n->rss_data.key); + + g_autofree struct { + NetVnetHash hdr; + NetVnetHashRss rss; + uint8_t footer[]; + } *rss = g_malloc(hash_size); + + rss->hdr = hash; + rss->rss.indirection_table_mask = + n->rss_data.indirections_len - 1; + rss->rss.unclassified_queue = n->rss_data.default_queue; + + memcpy(rss->footer, n->rss_data.indirections_table, + indirection_table_size); + + memcpy(rss->footer + indirection_table_size, n->rss_data.key, + sizeof(n->rss_data.key)); + + qemu_set_vnet_hash(qemu_get_queue(n->nic)->peer, &rss->hdr); } else { - warn_report("Can't load eBPF RSS - fallback to software RSS"); - n->rss_data.enabled_software_rss = true; + qemu_set_vnet_hash(qemu_get_queue(n->nic)->peer, &hash); + } + + n->rss_data.enabled_software_rss = false; + } else { + if (n->rss_data.peer_hash_available) { + NetVnetHash hash = { .flags = 0 }; + qemu_set_vnet_hash(qemu_get_queue(n->nic)->peer, &hash); + } + + n->rss_data.enabled_software_rss = n->rss_data.populate_hash; + if (n->rss_data.populate_hash) { + virtio_net_detach_ebpf_rss(n); + } else if (!virtio_net_attach_ebpf_rss(n)) { + if (get_vhost_net(qemu_get_queue(n->nic)->peer)) { + warn_report("Can't load eBPF RSS for vhost"); + } else { + warn_report("Can't load eBPF RSS - fallback to software RSS"); + n->rss_data.enabled_software_rss = true; + } } } @@ -1234,7 +1279,13 @@ static void virtio_net_commit_rss_config(VirtIONet *n) n->rss_data.indirections_len, sizeof(n->rss_data.key)); } else { - virtio_net_detach_ebpf_rss(n); + if (n->rss_data.peer_hash_available) { + NetVnetHash hash = { .flags = 0 }; + qemu_set_vnet_hash(qemu_get_queue(n->nic)->peer, &hash); + } else { + virtio_net_detach_ebpf_rss(n); + } + trace_virtio_net_rss_disable(n); } } From patchwork Thu Mar 13 06:55:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 14014410 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CAD07C28B28 for ; Thu, 13 Mar 2025 06:58:26 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tscVm-0008Te-F4; Thu, 13 Mar 2025 02:57:46 -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 1tscUN-0006tI-LL for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:56:24 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tscUL-0006A5-Dz for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:56:19 -0400 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-2ff799d99dcso1383218a91.1 for ; Wed, 12 Mar 2025 23:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1741848976; x=1742453776; 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=DukArzDg125GLBsbHFL9ykYW0pGberfM/CiWiOUc3SY=; b=fo0h1/1pArrIBJVfd6G9QgHF0p1B51Sxv7bcEOS/z1cRctml0DB/uC+ysJttmZRnZD A1iJk+mqxi32m38gatagvuJx6IPe9iBnxbOmRQB2uZdXLR9IXrCzvryRAEzgCnOLVl/v sBZUJK8oaKHbY6k3DePHZ5cMyx298oQcycK6XiSbP/yxVBItgvqf32jLowW3d1Tjk+0M Awce4WfrtvDEy22zE1nhmutQkehPYnyu6bd6s4gOznHj5PdU33gYmfn5BBr6x/IT2d2L ps3EPG79EepJQ+C5ycZ6pohe9CBCga7owM5KEXdTCpth1YTvu9w21mHwiw5U76vbyaKw 4lkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741848976; x=1742453776; 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=DukArzDg125GLBsbHFL9ykYW0pGberfM/CiWiOUc3SY=; b=brRJRVJH4P5jkzdDkRaqnp2vFqkOO+3zbdd4RX/c8GGUU5xkhbK+mdC16IpFdguzYG zSAk7qrutKzZEo3ZRfTe/XYmtQE3+GzxpYT91rm5di/rX2z5hWhEXM2poYe5WFrIGZxe a5dhRn9GWZVLOksZZN5Q0InV2IfjJCh2FefW0voBY96AZ1N4S1HLzGD+TC7YZxgoUJAb a/4aNHllsYI6A3QH411+ONSF3DKKM4RzGK9+4EWhBgtsNZoUkOZtoF/W92tg0PvmRugI N1Cks5y6vO7LwYgd03p1qatX4aKCq6pUH76yqEAhqrRx5pAvG36vEKA5f2xbo4pFBK4F YG8A== X-Gm-Message-State: AOJu0YxiiLTGb/0am8p7OSJQt+UADMH0T2wRdTtbAC4DqJa0gSPXHOdj GR8+U3q1RjlSQAyio0zWJfe+XLMwp8VWOKRr92vc5TdtqFBm+u+G4npsQvX6BEA= X-Gm-Gg: ASbGncvs8W64RrFr6h9A3u00+59Cyu5MlMx7i7IAFe6jeSVjS6ZVWb3mgVCx/t1pT6l gD7eBj266GioBD9gRbSvCJ1Jad6uoNMPTy6pvq70gwXGwWqIyTP2O3j/lMmoHgx7QpMNNlK+2O8 l8kDd7XXLRuUuEQwyMMwvvSj8fTvK2YTPpWctAgmQiK8zV7SVYzrj3RVcEPbeDxMeFccXXq5VOC XSNM11X/G9ZCygdQI3MW0Y3cX+MkF0Lb90YshOljiAvNP1nzOLNA7ixolyip2H2wvfbJIBxLfQ5 3GHX+/0Bbb2zvFvFf6vSrHdgI1XbfidjOh77Ws6Ko6oVqocw X-Google-Smtp-Source: AGHT+IFcrJ/eUUtY7TlfARDyFEIKRX3RHgJRzLwpozwrGsZnb2An8zyGlri72k5ZHz2rCfSxP7+eGQ== X-Received: by 2002:a17:90b:3887:b0:2ee:d193:f3d5 with SMTP id 98e67ed59e1d1-2ff7ce59637mr37238464a91.7.1741848975877; Wed, 12 Mar 2025 23:56:15 -0700 (PDT) Received: from localhost ([157.82.205.237]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-30138b3b483sm681970a91.4.2025.03.12.23.56.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Mar 2025 23:56:15 -0700 (PDT) From: Akihiko Odaki Date: Thu, 13 Mar 2025 15:55:35 +0900 Subject: [PATCH RFC v4 09/11] virtio-net: Offload hashing without vhost MIME-Version: 1.0 Message-Id: <20250313-hash-v4-9-c75c494b495e@daynix.com> References: <20250313-hash-v4-0-c75c494b495e@daynix.com> In-Reply-To: <20250313-hash-v4-0-c75c494b495e@daynix.com> To: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , devel@daynix.com Cc: Akihiko Odaki X-Mailer: b4 0.15-dev-edae6 Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1034.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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This is necessary to offload hashing to tap. Signed-off-by: Akihiko Odaki --- hw/net/virtio-net.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index e125478ae834..edfc76a5308e 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1712,7 +1712,11 @@ static size_t receive_header(VirtIONet *n, struct virtio_net_hdr *hdr, { size_t hdr_len = n->guest_hdr_len; - memcpy(hdr, buf, sizeof(struct virtio_net_hdr)); + memcpy(hdr, buf, + n->rss_data.populate_hash && + n->rss_data.enabled && !n->rss_data.enabled_software_rss ? + sizeof(struct virtio_net_hdr_v1_hash) : + sizeof(struct virtio_net_hdr)); *buf_offset = n->host_hdr_len; work_around_broken_dhclient(hdr, &hdr_len, buf, buf_size, buf_offset); @@ -3111,11 +3115,13 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features, } 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); + if (!use_peer_hash) { + 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; From patchwork Thu Mar 13 06:55:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 14014412 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6F505C282DE for ; Thu, 13 Mar 2025 06:58:42 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tscW9-0000iS-NR; Thu, 13 Mar 2025 02:58:10 -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 1tscUQ-00070J-Di for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:56:24 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tscUO-0006AW-CM for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:56:21 -0400 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-2235189adaeso12351285ad.0 for ; Wed, 12 Mar 2025 23:56:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1741848979; x=1742453779; 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=3l8pjiY/8aFlXCHEH1zkcj/A8CNP0bkWehdzO/Jxnbc=; b=cMssw+LtWZG1BwxNKwYAG1CEc7G3+Q+V5hTzhS+ibmNp67pzRStjOOs1Gy7cwfQ8zr JYl3xX9emC5P9kX96iQaSdyFH5ON81FQXatAwu8lPFPjejFZmrCbhBfoMnwy4NG8w31v e/J717UjT6yLyeQTtotetnxOaILVCBIOgYDiRxmkGuq+S/3YAQqx0GWBbDbuJU4NmzpL n+lEwMI6kr5/9KtKeAF17IlDajWPDpFGbLEeKFRu6xV0Zy9z2quwB5srI7Bieb5ipulQ PGk2JKkhwy7vZNvbemoXh5FIO8bC0nn9JU80qyx5VxYSmRm0aWC+4ZHVvn6Kp7XsUGIC Ttxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741848979; x=1742453779; 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=3l8pjiY/8aFlXCHEH1zkcj/A8CNP0bkWehdzO/Jxnbc=; b=TZPIkNY0mwJk86FUwsJuD7DkerRM4YzfAcnWO+LbEk1V9KYn9l3ZiE2krOufSkdtST Lqy4cgr/+BhLFj3tZRd5DCo5eWl6MgUqaJGD7vMqPM7HqEMbJucnQWzmL71cK4TSq1KO SiTL2aamSx8HeCUJ2VvRaNTJQt4cx6iTba+FoIAndLudBFlF7f6hsco/Q8q/EB/AJM0z bdCWF59KpcqIxLBdRecyok2gLnScgzXeDJgFt6FkCmcKIcmCsfC49t95OQ0cH1+dh26Q Rh5t2sbEHXoHDtMAkIvbTKk7WXup4DtYiiOKsX8KiUgqYhFAtKCQ7XEHehgCBIQCraYo aw4g== X-Gm-Message-State: AOJu0YyraG6uOC6UOJVXhOxfBFbvUNOQ9qb6IHB6aK1BYe1ctcTID25i Ev1XhlQLLUL5UeAPRLqYHeZuqO0rxr3DOSEOEIFPzLTxQCL2Wp98vu24tNA5R9iwjas/tCQ4g01 gWAQ= X-Gm-Gg: ASbGncute0MV1p/+oXMgdTUl5ohWvKpDVkfr3qQKCslMv8kjvEbz57qp9RViWq9m49/ YtP9uKqkqTMlbyJMFPpCM5Ht+VMEee15Wobv7qyOHInQ8Fw3Hix9wBVdYh9FXSSBKXkPe/HGZoB Rx7uX39JcU7BiYPHr3g7f3nX6+lhFJYevbqRFjjVEESVGkdGc04aJH2Nndw98clOFnh5NfSOlYH BcXQl/DLhh1l6Z9IlSjWnEKZj2GeNcmE28G6PXktnkVkTI4daUgbqxyY0iYXKruhNUNjTJuvitL 3yWM20VMflr+fgHgAw9AnLJeshDzkKORSmYlEW3u6MIcwLQ6 X-Google-Smtp-Source: AGHT+IFHYQLcL3jYqNXIztTlYD6SrwDfla3IzYqGPL510xDOCPaRxZ4YxSBTaGh7c2ISg3p0vCNz/A== X-Received: by 2002:a17:902:cf0a:b0:21f:53a5:19e0 with SMTP id d9443c01a7336-225c66317bfmr20723055ad.12.1741848979144; Wed, 12 Mar 2025 23:56:19 -0700 (PDT) Received: from localhost ([157.82.205.237]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-225c688d93esm6515125ad.45.2025.03.12.23.56.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Mar 2025 23:56:18 -0700 (PDT) From: Akihiko Odaki Date: Thu, 13 Mar 2025 15:55:36 +0900 Subject: [PATCH RFC v4 10/11] tap: Report virtio-net hashing support on Linux MIME-Version: 1.0 Message-Id: <20250313-hash-v4-10-c75c494b495e@daynix.com> References: <20250313-hash-v4-0-c75c494b495e@daynix.com> In-Reply-To: <20250313-hash-v4-0-c75c494b495e@daynix.com> To: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , devel@daynix.com Cc: Akihiko Odaki X-Mailer: b4 0.15-dev-edae6 Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62f.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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This allows offloading virtio-net hashing to tap on Linux. Signed-off-by: Akihiko Odaki --- net/tap-linux.h | 1 + net/tap_int.h | 1 + net/tap-bsd.c | 5 +++++ net/tap-linux.c | 13 +++++++++++++ net/tap-solaris.c | 5 +++++ net/tap-stub.c | 5 +++++ net/tap.c | 8 ++++++++ 7 files changed, 38 insertions(+) diff --git a/net/tap-linux.h b/net/tap-linux.h index 5fac64c24f99..c773609c799e 100644 --- a/net/tap-linux.h +++ b/net/tap-linux.h @@ -32,6 +32,7 @@ #define TUNSETVNETLE _IOW('T', 220, int) #define TUNSETVNETBE _IOW('T', 222, int) #define TUNSETSTEERINGEBPF _IOR('T', 224, int) +#define TUNGETVNETHASHCAP _IOR('T', 228, NetVnetHash) #define TUNSETVNETHASH _IOW('T', 229, NetVnetHash) #endif diff --git a/net/tap_int.h b/net/tap_int.h index e1b53e343397..84a88841b720 100644 --- a/net/tap_int.h +++ b/net/tap_int.h @@ -36,6 +36,7 @@ ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen); void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp); int tap_probe_vnet_hdr(int fd, Error **errp); +bool tap_probe_vnet_hash_supported_types(int fd, uint32_t *types); int tap_probe_has_ufo(int fd); int tap_probe_has_uso(int fd); void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo, diff --git a/net/tap-bsd.c b/net/tap-bsd.c index 2eee0c0a0ec5..142e1abe0420 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -217,6 +217,11 @@ int tap_probe_has_uso(int fd) return 0; } +bool tap_probe_vnet_hash_supported_types(int fd, uint32_t *types) +{ + return false; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { } diff --git a/net/tap-linux.c b/net/tap-linux.c index c053828b056b..b45039ecbbb1 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -196,6 +196,19 @@ int tap_probe_has_uso(int fd) return 1; } +bool tap_probe_vnet_hash_supported_types(int fd, uint32_t *types) +{ + NetVnetHash hash; + + if (ioctl(fd, TUNGETVNETHASHCAP, &hash)) { + return false; + } + + *types = hash.types; + + return true; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { if (ioctl(fd, TUNSETVNETHDRSZ, &len) == -1) { diff --git a/net/tap-solaris.c b/net/tap-solaris.c index c65104b84e93..00d1c850680d 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -221,6 +221,11 @@ int tap_probe_has_uso(int fd) return 0; } +bool tap_probe_vnet_hash_supported_types(int fd, uint32_t *types) +{ + return false; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { } diff --git a/net/tap-stub.c b/net/tap-stub.c index 5bdc76216b7f..a4718654fbeb 100644 --- a/net/tap-stub.c +++ b/net/tap-stub.c @@ -52,6 +52,11 @@ int tap_probe_has_uso(int fd) return 0; } +bool tap_probe_vnet_hash_supported_types(int fd, uint32_t *types) +{ + return false; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { } diff --git a/net/tap.c b/net/tap.c index 1136018c1965..98083bcd515e 100644 --- a/net/tap.c +++ b/net/tap.c @@ -248,6 +248,13 @@ static void tap_set_vnet_hdr_len(NetClientState *nc, int len) s->using_vnet_hdr = true; } +static bool tap_get_vnet_hash_supported_types(NetClientState *nc, + uint32_t *types) +{ + TAPState *s = DO_UPCAST(TAPState, nc, nc); + return tap_probe_vnet_hash_supported_types(s->fd, types); +} + static void tap_set_vnet_hash(NetClientState *nc, const NetVnetHash *hash) { TAPState *s = DO_UPCAST(TAPState, nc, nc); @@ -350,6 +357,7 @@ static NetClientInfo net_tap_info = { .has_vnet_hdr_len = tap_has_vnet_hdr_len, .set_offload = tap_set_offload, .set_vnet_hdr_len = tap_set_vnet_hdr_len, + .get_vnet_hash_supported_types = tap_get_vnet_hash_supported_types, .set_vnet_hash = tap_set_vnet_hash, .set_vnet_le = tap_set_vnet_le, .set_vnet_be = tap_set_vnet_be, From patchwork Thu Mar 13 06:55:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 14014409 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2DAB2C282DE for ; Thu, 13 Mar 2025 06:58:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tscV5-0007p1-H3; Thu, 13 Mar 2025 02:57:10 -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 1tscUU-00074I-7i for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:56:28 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tscUS-0006Az-Cs for qemu-devel@nongnu.org; Thu, 13 Mar 2025 02:56:25 -0400 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-2ff64550991so1155115a91.0 for ; Wed, 12 Mar 2025 23:56:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1741848983; x=1742453783; 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=FMIoIr6/4bz4Br49nK8n48Lj1al7ccgCjDAUACVxZ3k=; b=irmfMljIyLw2DTqs4xxgBqb7w2wFWHsnjaoXRYAkduxfKiyDPx2iTQuq+wLLOW+sik PB55zZh0UgC7RiVQGJERcQK6zKXVv8sti6PHC442jXvP6Rqhzlh/ooCz+2pXf3Ybzlhq 9pwzJCQP3I1ReDpKOAzFeEX6HMI3zeUyzrF5FELj6O65ob9jO5Y80EfNUr00vA2t69Hs eIQ59Y4BBV09j2+luUhJfrH0uK3Mfn9vT8tDKeJLnMcqAzdDE8MFWFbiyVhlYAInvMxi 4oQVS2oAIkQQzN9hh/a2yfpRNrMnq8l2X2mCSVlNi4y96gAGC1oXWjtWf4dr4imlsreg oNeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741848983; x=1742453783; 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=FMIoIr6/4bz4Br49nK8n48Lj1al7ccgCjDAUACVxZ3k=; b=qO0ZxwGZsByR52N5Z/u3t9cJncozs0ic+jNZv3I1hoSTVJ9ZFrs6IatklDdE4JtwIA EpZXo3HTPU5xojaNhdZd4z0wEhXTazejMRa2XkkR3I/bzyGdW/diPnG87xc8zADoXmuQ rMSaUnaM/ZMjupLSOe7wjc72hna652+c6YZ63Mn8kLtnDhR8P+v4CyM+ysuiTDuS4UCN DwUNNCcjTTftrIiZR7em/YuM4Fm/7IhCgl/omCM2t81gXMZz1tntUQWvPvcpK6yR2k6A S/GkrFrTw/mOZ/OcNeMJY4nhX5k8ApEnwnf7xeFfmnXzFqF7rzR9cgHg+k7dn3hTj0fO yEXQ== X-Gm-Message-State: AOJu0Yxv2uH7R42+SKb1zcdMcT3EF4UY0eT5A/Wl0m3z9aU2+X9fZEeW 485oUtWM3/iM7Poi5180cbDrmBPbov8e9g04o2Kg2F8BW/vPNCaube5w6C70rmYK9GrSkoR1rBb iWvs= X-Gm-Gg: ASbGnctDJ3yewnNjn/lkH7F/0rzvvjvh5H6PwG7tQd0btrdKW8va4vnDalc7x225dfK rh5xwqgtm6UNloz8tEYXurgcmzVbRbiW5t+qmspG6QEFBe2FjSbNlXsXN8QP/r+BBDiImsLI00r k3U+d2bCNwsBPAdCv/q8uCm8icYXmMXmvJKW2WGfa4eluHEsfaX66ONRhQMLRbpArnPgRpui2WY yGIQhvLvbgXIKzHoZkJxeaQ5AxjR/UlxUYgucTjVIJhWwMeZjD2U4zU0+ymAU/4v0strS8FMYYe rvLqpgehU9lnEV1eOlSwLViOHfTot2OG6Uw7/Wt8GU5FYOl1topJgM/0EAo= X-Google-Smtp-Source: AGHT+IHTIevd5a5psY4w5trpr7wr2G/IPwvA1BcpwguiEM1U9FOPuZDRlLJgYPGaQxP8aEEWGEXZ3A== X-Received: by 2002:a17:90b:3ecb:b0:2fe:6942:370e with SMTP id 98e67ed59e1d1-2ff7ce70a09mr36244314a91.7.1741848982934; Wed, 12 Mar 2025 23:56:22 -0700 (PDT) Received: from localhost ([157.82.205.237]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-3011821840dsm3078987a91.4.2025.03.12.23.56.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Mar 2025 23:56:22 -0700 (PDT) From: Akihiko Odaki Date: Thu, 13 Mar 2025 15:55:37 +0900 Subject: [PATCH RFC v4 11/11] docs/devel/ebpf_rss.rst: Update for peer RSS MIME-Version: 1.0 Message-Id: <20250313-hash-v4-11-c75c494b495e@daynix.com> References: <20250313-hash-v4-0-c75c494b495e@daynix.com> In-Reply-To: <20250313-hash-v4-0-c75c494b495e@daynix.com> To: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , devel@daynix.com Cc: Akihiko Odaki X-Mailer: b4 0.15-dev-edae6 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x102a.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_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org eBPF RSS virtio-net support was written in assumption that there is only one alternative RSS implementation: 'in-qemu' RSS. It is no longer true, and we now have yet another implementation; namely the peer RSS. Signed-off-by: Akihiko Odaki --- docs/devel/ebpf_rss.rst | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/docs/devel/ebpf_rss.rst b/docs/devel/ebpf_rss.rst index ed5d33767bd5..f128f0990905 100644 --- a/docs/devel/ebpf_rss.rst +++ b/docs/devel/ebpf_rss.rst @@ -7,9 +7,22 @@ eBPF RSS virtio-net support RSS(Receive Side Scaling) is used to distribute network packets to guest virtqueues by calculating packet hash. Usually every queue is processed then by a specific guest CPU core. -For now there are 2 RSS implementations in qemu: -- 'in-qemu' RSS (functions if qemu receives network packets, i.e. vhost=off) -- eBPF RSS (can function with also with vhost=on) +For now there are 3 RSS implementations in qemu: +1. Peer RSS +2. eBPF RSS +3. 'In-QEMU' RSS + +'In-QEMU' RSS is incompatible with vhost since the packets are not routed to +QEMU. eBPF RSS requires Linux 5.8+. Peer RSS requires the peer to implement RSS. +Currently QEMU can use the RSS implementation of vDPA and Linux's TUN module +with the following patch applied: +https://lore.kernel.org/r/20240915-rss-v3-0-c630015db082@daynix.com/ + +eBPF RSS does not support hash reporting. Peer RSS may support limited hash +types. + +virtio-net automatically chooses the RSS implementation to use. Peer RSS is +the most preferred, and 'in-QEMU' RSS is the least. eBPF support (CONFIG_EBPF) is enabled by 'configure' script. To enable eBPF RSS support use './configure --enable-bpf'. @@ -49,9 +62,6 @@ eBPF RSS turned on by different combinations of vhost-net, vitrio-net and tap co tap,vhost=on & virtio-net-pci,rss=on,hash=on -If CONFIG_EBPF is not set then only 'in-qemu' RSS is supported. -Also 'in-qemu' RSS, as a fallback, is used if the eBPF program failed to load or set to TUN. - RSS eBPF program ---------------- @@ -67,7 +77,6 @@ Prerequisites to recompile the eBPF program (regenerate ebpf/rss.bpf.skeleton.h) $ make -f Makefile.ebpf Current eBPF RSS implementation uses 'bounded loops' with 'backward jump instructions' which present in the last kernels. -Overall eBPF RSS works on kernels 5.8+. eBPF RSS implementation -----------------------