From patchwork Sun Oct 8 05:42:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1844856 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=Pc3nHkg8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S3B0g1c5lz1yqP for ; Sun, 8 Oct 2023 16:43:29 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpMYq-0003Qb-Oc; Sun, 08 Oct 2023 01:42:40 -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 1qpMYo-0003QD-2Z for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:42:38 -0400 Received: from mail-oi1-x22c.google.com ([2607:f8b0:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qpMYl-0002gQ-RH for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:42:37 -0400 Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-3ae2ec1a222so2418011b6e.2 for ; Sat, 07 Oct 2023 22:42:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696743754; x=1697348554; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ETPUFn0hUWgvqmftil1y1SZBUPwFETxqxmqKWKXZSNM=; b=Pc3nHkg8fyh+kDguEUAeAiAqzCOBGrALgkwn43Jm6Uaqh2w6Hy0IhreZMoXT/K45zb ixBHBPH8yuANQxBE4sy7ud2qz1k10CVN8ZBRV2OnCpPFMpwcbxLX4778cnBeaFREUvhX 7muUhKMqJo0J6Pi9clJ9bX71sV5tPhIjah/bXd0nal+Wth0jMNnovriU+3WQDTzJ+2Iy QHHATWasvdw5rFXxaH0H1+1dui86M7DbTA8ZskOpD6l5Ju9r1mBY7+Deae/fQ635z4Uk bYrNDk3SDnIl+3McM/Dq9edTSPxC/hrhGKD92iSaXjHQsEZ4A9BXcr5y8qxLumCuYtAS YAtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696743754; x=1697348554; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ETPUFn0hUWgvqmftil1y1SZBUPwFETxqxmqKWKXZSNM=; b=Dw6yMjsnMRoHbTE3Iue0vOnYDj0oGjUdBg6Ge9SEijRAdCYQICAQJQz3A5zlC1U36s kSSO01MtOPE/4UQJbHVvpjIsobqtUtu99DcsTOBerTuNxREapLLZEIc+w/Mnae2gW6ut YHcJYI+EFFc5+W7ITDPhDdKCRswclhaXwsn+qjQ/z/IQcUGCiPo7VOhvdKmA+R4CpXcM 01KI9Piu2/U75W7vGEmUenV0fZnS61WOgCRb7ewRvtLm936yNy0ud8QcAsH1P2+gvP6O /YEMd1nzgoanOb9G99cs/4PsUBnxtKWRs5DuSJ2nmS3+Inzd8chR2tTjBPcr7hT6jJyM qtHQ== X-Gm-Message-State: AOJu0YxeqkCeboJsntUl6Rvptpoh2MqZbJ53PJwgToOAPaMa8u/E1KEW fvG2cPYayXBEgxANSFRQYgtXSw== X-Google-Smtp-Source: AGHT+IEsqdJqn720MV/L1x6E8mPKOFiiM/hoPGiSbuHe6wUfwG+Q4Dhn2uzDW/Sprd+0y+nwK7S4YQ== X-Received: by 2002:a05:6808:1442:b0:3a7:6ff5:c628 with SMTP id x2-20020a056808144200b003a76ff5c628mr17012021oiv.11.1696743754520; Sat, 07 Oct 2023 22:42:34 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id it19-20020a056a00459300b0069305627494sm3983933pfb.165.2023.10.07.22.42.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 07 Oct 2023 22:42:34 -0700 (PDT) From: Akihiko Odaki To: Cc: Akihiko Odaki , Jason Wang , qemu-devel@nongnu.org (open list:All patches CC here) Subject: [RFC PATCH 1/4] net: Allow to offload virtio-net hashing Date: Sun, 8 Oct 2023 14:42:15 +0900 Message-ID: <20231008054222.146228-2-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231008054222.146228-1-akihiko.odaki@daynix.com> References: <20231008054222.146228-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::22c; envelope-from=akihiko.odaki@daynix.com; helo=mail-oi1-x22c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Offloading virtio-net hashing to the client can improve the performance since the performance can reuse the hash calculated for RSS for hash reporting as well. Signed-off-by: Akihiko Odaki --- include/net/net.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ net/tap_int.h | 3 +++ net/net.c | 14 ++++++++++++++ net/tap-bsd.c | 10 ++++++++++ net/tap-linux.c | 10 ++++++++++ net/tap-solaris.c | 10 ++++++++++ net/tap-stub.c | 10 ++++++++++ net/tap.c | 14 ++++++++++++++ 8 files changed, 118 insertions(+) diff --git a/include/net/net.h b/include/net/net.h index 685ec58318..7eafef1703 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -35,6 +35,47 @@ typedef struct NICConf { int32_t bootindex; } NICConf; +#ifdef CONFIG_LINUX +#ifndef TUNGETVNETHASHCAP +#define TUNGETVNETHASHCAP _IO('T', 228) +#define TUNSETVNETHASH _IOW('T', 229, unsigned int) + +struct tun_vnet_hash_cap { + uint16_t max_indirection_table_length; + uint32_t types; +}; + +#define TUN_VNET_HASH_RSS 0x01 +#define TUN_VNET_HASH_REPORT 0x02 +struct tun_vnet_hash { + uint8_t flags; + uint32_t types; + uint16_t indirection_table_mask; + uint16_t unclassified_queue; +}; +#endif + +typedef struct tun_vnet_hash_cap NetVnetHashCap; +typedef struct tun_vnet_hash NetVnetHash; +#define NET_VNET_HASH_RSS TUN_VNET_HASH_RSS +#define NET_VNET_HASH_REPORT TUN_VNET_HASH_REPORT +#else +#define NET_VNET_HASH_RSS 1 +#define NET_VNET_HASH_REPORT 2 + +typedef struct NetVnetHashCap { + uint16_t max_indirection_table_length; + uint32_t types; +} NetVnetHashCap; + +typedef struct NetVnetHash { + uint8_t flags; + uint32_t types; + uint16_t indirection_table_mask; + uint16_t unclassified_queue; +} NetVnetHash; +#endif + #define DEFINE_NIC_PROPERTIES(_state, _conf) \ DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \ DEFINE_PROP_NETDEV("netdev", _state, _conf.peers) @@ -61,6 +102,8 @@ typedef void (UsingVnetHdr)(NetClientState *, bool); typedef void (SetOffload)(NetClientState *, int, int, int, int, int); typedef int (GetVnetHdrLen)(NetClientState *); typedef void (SetVnetHdrLen)(NetClientState *, int); +typedef bool (GetVnetHashCap)(NetClientState *, NetVnetHashCap *); +typedef void (SetVnetHash)(NetClientState *, const void *); typedef int (SetVnetLE)(NetClientState *, bool); typedef int (SetVnetBE)(NetClientState *, bool); typedef struct SocketReadState SocketReadState; @@ -93,6 +136,8 @@ typedef struct NetClientInfo { SetVnetHdrLen *set_vnet_hdr_len; SetVnetLE *set_vnet_le; SetVnetBE *set_vnet_be; + GetVnetHashCap *get_vnet_hash_cap; + SetVnetHash *set_vnet_hash; NetAnnounce *announce; SetSteeringEBPF *set_steering_ebpf; NetCheckPeerType *check_peer_type; @@ -197,6 +242,8 @@ void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6, int ecn, int ufo); int qemu_get_vnet_hdr_len(NetClientState *nc); void qemu_set_vnet_hdr_len(NetClientState *nc, int len); +bool qemu_get_vnet_hash_cap(NetClientState *nc, NetVnetHashCap *cap); +void qemu_set_vnet_hash(NetClientState *nc, const void *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_int.h b/net/tap_int.h index 547f8a5a28..aa36615600 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); @@ -36,9 +37,11 @@ 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); int tap_probe_vnet_hdr_len(int fd, int len); +bool tap_probe_vnet_hash_cap(int fd, NetVnetHashCap *cap); int tap_probe_has_ufo(int fd); void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo); void tap_fd_set_vnet_hdr_len(int fd, int len); +void tap_fd_set_vnet_hash(int fd, const void *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 3523cceafc..53372dc6aa 100644 --- a/net/net.c +++ b/net/net.c @@ -562,6 +562,20 @@ void qemu_set_vnet_hdr_len(NetClientState *nc, int len) nc->info->set_vnet_hdr_len(nc, len); } +bool qemu_get_vnet_hash_cap(NetClientState *nc, NetVnetHashCap *cap) +{ + if (!nc || !nc->info->get_vnet_hash_cap) { + return false; + } + + return nc->info->get_vnet_hash_cap(nc, cap); +} + +void qemu_set_vnet_hash(NetClientState *nc, const void *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 4c98fdd337..503faecb67 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -217,10 +217,20 @@ int tap_probe_vnet_hdr_len(int fd, int len) return 0; } +bool tap_probe_vnet_hash_cap(int fd, NetVnetHashCap *cap) +{ + return false; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { } +void tap_fd_set_vnet_hash(int fd, const void *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 f54f308d35..0877f11df2 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -193,6 +193,11 @@ int tap_probe_vnet_hdr_len(int fd, int len) return 1; } +bool tap_probe_vnet_hash_cap(int fd, NetVnetHashCap *cap) +{ + return !ioctl(fd, TUNGETVNETHASHCAP, cap); +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { if (ioctl(fd, TUNSETVNETHDRSZ, &len) == -1) { @@ -202,6 +207,11 @@ void tap_fd_set_vnet_hdr_len(int fd, int len) } } +void tap_fd_set_vnet_hash(int fd, const void *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 38e15028bf..40e93e3a40 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -221,10 +221,20 @@ int tap_probe_vnet_hdr_len(int fd, int len) return 0; } +bool tap_probe_vnet_hash_cap(int fd, NetVnetHashCap *cap) +{ + return false; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { } +void tap_fd_set_vnet_hash(int fd, const void *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 a0fa25804b..39ce77676a 100644 --- a/net/tap-stub.c +++ b/net/tap-stub.c @@ -52,10 +52,20 @@ int tap_probe_vnet_hdr_len(int fd, int len) return 0; } +bool tap_probe_vnet_hash_cap(int fd, NetVnetHashCap *cap) +{ + return false; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { } +void tap_fd_set_vnet_hash(int fd, const void *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 ea46feeaa8..7dbcdaad14 100644 --- a/net/tap.c +++ b/net/tap.c @@ -275,6 +275,18 @@ static void tap_set_vnet_hdr_len(NetClientState *nc, int len) s->host_vnet_hdr_len = len; } +static bool tap_get_vnet_hash_cap(NetClientState *nc, NetVnetHashCap *cap) +{ + TAPState *s = DO_UPCAST(TAPState, nc, nc); + return tap_probe_vnet_hash_cap(s->fd, cap); +} + +static void tap_set_vnet_hash(NetClientState *nc, const void *hash) +{ + TAPState *s = DO_UPCAST(TAPState, nc, nc); + return tap_fd_set_vnet_hash(s->fd, hash); +} + static bool tap_get_using_vnet_hdr(NetClientState *nc) { TAPState *s = DO_UPCAST(TAPState, nc, nc); @@ -391,6 +403,8 @@ static NetClientInfo net_tap_info = { .set_offload = tap_set_offload, .get_vnet_hdr_len = tap_get_vnet_hdr_len, .set_vnet_hdr_len = tap_set_vnet_hdr_len, + .get_vnet_hash_cap = tap_get_vnet_hash_cap, + .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, From patchwork Sun Oct 8 05:42:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1844858 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=nZD1nyy5; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S3B0m43zLz1yqP for ; Sun, 8 Oct 2023 16:43:36 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpMYw-0003Qy-6n; Sun, 08 Oct 2023 01:42: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 1qpMYs-0003Qj-9O for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:42:44 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qpMYp-0002hP-Fw for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:42:41 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-69fc829d7b1so667733b3a.1 for ; Sat, 07 Oct 2023 22:42:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696743758; x=1697348558; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XIxazHACH6MI6G7hYxYW2f3e48chXpxklWeO38wFpsw=; b=nZD1nyy5/sUI61RwHUMJQCiC0kdD+fPpsehrEwRU9ZwmF/kaz0I4aUoeZRE0AOzAk2 sYZQm+6YgwE/R9Zc6R6SSV/eghEhWj2Ow1vG+NrwgxkLFZAwlIYHcejcCbUU6srleRvA J2yGOPA91MoBJCH8zYfUC0eHYUcp6QioI+3bzMdjDDnyKPXLYBXQ84eEhBemJ7Zz9nHt 6tb8s3S/9LGQdcf1Xx5kF06cZvn0brSEkRH+gTS3yHVFy5Aushb66xCXfsjKtt+dLDg+ Gwles69DS0Bus5UJOjbaaGVz3KpWLAZFy+PkzfE5J1voBe8pbtp5JO8V0r6/wwNgUSDH RF9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696743758; x=1697348558; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XIxazHACH6MI6G7hYxYW2f3e48chXpxklWeO38wFpsw=; b=fvQqLKagmhR8PS+xsYEPS0cvGEDhd++f2W8MJmoCbrLHxYMd06PRzkMl5zTvdxlhuU rGnbv9O84MboaIAPXwWy83fSso9KmADTlY+a7YZbqwItTy+ho2FvOCQUIw3EAzXsqvca a94f54CKrp7YMhWqY+JftcvGdw/A6sPwuAC/t9Hx+L1/g6i6FojSa+PdLit35CdnUzuh uzfaxhy1jpkjrujjhVsXu57qfZFOwFGv4z+g+zyTP8XzMUuOD8f4nMKuKJv0YLeEhAsB O8VyZMSzhdNn1QNgw55u/30hwGdDIqHh3Whtw6iQY6S7ictEUL60XR/gnTugW5T5zFgM rgMg== X-Gm-Message-State: AOJu0Yyfabf6poA+QyiIm4QM0w/U4C7BN+wDeEtU2RnFmW6/qHz7MZ9m H8Zz3dPzEIASn4oJp9+BwPv8ew== X-Google-Smtp-Source: AGHT+IGXUSJoZ8/OPm6LHLZQLe2MgKIb3Bo+DiYcwjjyI54n74FmQRmSEg3lbKhBIJRyQwpbbuik9g== X-Received: by 2002:a05:6a00:158c:b0:690:b7a1:ac51 with SMTP id u12-20020a056a00158c00b00690b7a1ac51mr15606992pfk.31.1696743758168; Sat, 07 Oct 2023 22:42:38 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id j19-20020aa783d3000000b00690d255b5a1sm3974566pfn.217.2023.10.07.22.42.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 07 Oct 2023 22:42:37 -0700 (PDT) From: Akihiko Odaki To: Cc: Akihiko Odaki , "Michael S. Tsirkin" , Jason Wang , qemu-devel@nongnu.org (open list:All patches CC here) Subject: [RFC PATCH 2/4] virtio-net: Offload hashing without eBPF Date: Sun, 8 Oct 2023 14:42:16 +0900 Message-ID: <20231008054222.146228-3-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231008054222.146228-1-akihiko.odaki@daynix.com> References: <20231008054222.146228-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::432; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x432.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Offloading virtio-net hashing to the client can improve the performance since the performance can reuse the hash calculated for RSS for hash reporting as well. Signed-off-by: Akihiko Odaki --- include/hw/virtio/virtio-net.h | 5 +- hw/net/virtio-net.c | 164 +++++++++++++++++++++++++++------ 2 files changed, 142 insertions(+), 27 deletions(-) diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 5f5dcb4572..deba793ec2 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -138,7 +138,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 3bb4bf136d..3bf1fec2ac 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); /* @@ -931,6 +931,10 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features) features &= ~(1ULL << VIRTIO_NET_F_MTU); } + if (!virtio_has_feature(features, VIRTIO_F_VERSION_1)) { + features &= ~(1ULL << VIRTIO_NET_F_HASH_REPORT); + } + virtio_net_set_multiqueue(n, virtio_has_feature(features, VIRTIO_NET_F_RSS) || virtio_has_feature(features, VIRTIO_NET_F_MQ)); @@ -1224,7 +1228,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; } @@ -1255,18 +1259,62 @@ static void virtio_net_detach_epbf_rss(VirtIONet *n) static void virtio_net_commit_rss_config(VirtIONet *n) { 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_epbf_rss(n); - } else if (!virtio_net_attach_epbf_rss(n)) { - n->rss_data.enabled_software_rss = true; + if (n->rss_data.peer_hash_types && + (n->rss_data.peer_hash_types & n->rss_data.runtime_hash_types) == + n->rss_data.runtime_hash_types) { + size_t indirection_table_size = + n->rss_data.indirections_len * + sizeof(*n->rss_data.indirections_table); + + size_t hash_size = sizeof(NetVnetHash) + indirection_table_size + + sizeof(n->rss_data.key); + + g_autofree struct { + NetVnetHash header; + uint8_t footer[]; + } *hash = g_malloc(hash_size); + + hash->header.flags = + (n->rss_data.redirect ? NET_VNET_HASH_RSS : 0) | + (n->rss_data.populate_hash ? NET_VNET_HASH_REPORT : 0); + hash->header.types = n->rss_data.supported_hash_types; + hash->header.indirection_table_mask = + n->rss_data.indirections_len - 1; + hash->header.unclassified_queue = n->rss_data.default_queue; + + memcpy(hash->footer, n->rss_data.indirections_table, + indirection_table_size); + + memcpy(hash->footer + indirection_table_size, n->rss_data.key, + sizeof(n->rss_data.key)); + + 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_types) { + 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_epbf_rss(n); + } else if (!virtio_net_attach_epbf_rss(n)) { + n->rss_data.enabled_software_rss = true; + } } - trace_virtio_net_rss_enable(n->rss_data.hash_types, + trace_virtio_net_rss_enable(n->rss_data.runtime_hash_types, n->rss_data.indirections_len, sizeof(n->rss_data.key)); } else { - virtio_net_detach_epbf_rss(n); + if (n->rss_data.peer_hash_types) { + NetVnetHash hash = { .flags = 0 }; + qemu_set_vnet_hash(qemu_get_queue(n->nic)->peer, &hash); + } else { + virtio_net_detach_epbf_rss(n); + } + trace_virtio_net_rss_disable(); } } @@ -1297,6 +1345,54 @@ static void virtio_net_unload_ebpf(VirtIONet *n) ebpf_rss_unload(&n->ebpf_rss); } +static bool virtio_net_commit_rss_host_config(VirtIONet *n, Error **errp) +{ + bool hash_report = virtio_has_feature(n->host_features, VIRTIO_NET_F_HASH_REPORT); + bool rss = virtio_has_feature(n->host_features, VIRTIO_NET_F_RSS); + bool peer_hash_available = n->rss_data.peer_hash_available; + uint32_t supported_hash_types = n->rss_data.supported_hash_types; + uint32_t peer_hash_types = n->rss_data.peer_hash_types; + + if (peer_hash_available && + (supported_hash_types & peer_hash_types) == supported_hash_types) { + return true; + } + + if ((!rss || ebpf_rss_is_loaded(&n->ebpf_rss) || virtio_net_load_ebpf(n)) && + !hash_report) { + return true; + } + + if (!get_vhost_net(qemu_get_queue(n->nic)->peer)) { + if (rss) { + warn_report_once("Can't offload RSS - fallback to software RSS"); + } + + return true; + } + + error_setg(errp, "vhost cannot fulfill hash feature requirements"); + return false; +} + +static bool virtio_net_configure_rss_host(VirtIONet *n, Error **errp) +{ + NetVnetHashCap cap; + + if (qemu_get_vnet_hash_cap(qemu_get_queue(n->nic)->peer, &cap) && + cap.max_indirection_table_length >= VIRTIO_NET_RSS_MAX_TABLE_LEN) { + n->rss_data.peer_hash_available = true; + n->rss_data.supported_hash_types = cap.types; + n->rss_data.peer_hash_types = cap.types; + + return true; + } + + n->rss_data.supported_hash_types = VIRTIO_NET_RSS_SUPPORTED_HASHES; + + return virtio_net_commit_rss_host_config(n, errp); +} + static uint16_t virtio_net_handle_rss(VirtIONet *n, struct iovec *iov, unsigned int iov_cnt, @@ -1328,7 +1424,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); n->rss_data.indirections_len++; @@ -1391,12 +1487,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; } @@ -1798,7 +1894,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) { virtio_set_packet_hash(buf, VIRTIO_NET_HASH_REPORT_NONE, 0); @@ -1904,7 +2000,7 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf, } receive_header(n, sg, elem->in_num, buf, size); - if (n->rss_data.populate_hash) { + if (n->rss_data.populate_hash && n->rss_data.enabled_software_rss) { offset = sizeof(mhdr); iov_from_buf(sg, elem->in_num, offset, buf + offset, n->host_hdr_len - sizeof(mhdr)); @@ -2952,6 +3048,7 @@ static int virtio_net_post_load_device(void *opaque, int version_id) int i, link_down; trace_virtio_net_post_load_device(); + virtio_net_set_mrg_rx_bufs(n, n->mergeable_rx_bufs, virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1), @@ -3183,21 +3280,43 @@ 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); + Error *err; + + if (version_id == 1) { + n->rss_data.supported_hash_types = VIRTIO_NET_RSS_SUPPORTED_HASHES; + } + + if (!virtio_net_commit_rss_host_config(n, &err)) { + error_report_err(err); + return -ENOTSUP; + } + + return 0; +} + static bool virtio_net_rss_needed(void *opaque) { - return VIRTIO_NET(opaque)->rss_data.enabled; + VirtIONet *n = VIRTIO_NET(opaque); + + return virtio_has_feature(n->host_features, VIRTIO_NET_F_RSS) || + virtio_has_feature(n->host_features, VIRTIO_NET_F_HASH_REPORT); } 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 = (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, @@ -3720,15 +3839,8 @@ 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)) { - if (get_vhost_net(nc->peer)) { - error_setg(errp, "Can't load eBPF RSS for vhost"); - virtio_net_device_unrealize(dev); - return; - } - - warn_report_once("Can't load eBPF RSS - fallback to software RSS"); + if (!virtio_net_configure_rss_host(n, errp)) { + virtio_net_device_unrealize(dev); } } From patchwork Sun Oct 8 05:42:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1844857 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=ADPg0vnz; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S3B0g1xgmz1yql for ; Sun, 8 Oct 2023 16:43:29 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpMZ0-0003RU-GT; Sun, 08 Oct 2023 01:42:50 -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 1qpMYv-0003Qr-EZ for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:42:45 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qpMYs-0002iB-VY for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:42:45 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-690d2441b95so2594491b3a.1 for ; Sat, 07 Oct 2023 22:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696743762; x=1697348562; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bktt96HaK9jSV/VfWxuKA2xiQeQu/9hYpvUZ9O8KUH0=; b=ADPg0vnzrMx3eXMM6Wip+A/h74ZwpNGGWUmSy/tQyqm24a7aA3GrxrAPDyefEswhhg xSkVEo/St1CFROgzqBCKIHaeftutx1gIo1a9/KuH7G9OdXYX4REHPwHIqyPhmlfTejxo DvWIYBCpTNevuHG/rFNMNoaLPDcHznNGM1ytOvrLvLgXl3HUpDfpy9Uu4cK/vXZj+61z 4S8EqPxAw7Olsc+jn8/emBUCAiwcBB5ZPqeEUHEtQRR736w2WrVHbiZ6pUe3CMTGuRSF NVQQv1Y7vF83YoFwlm3wqo+czNlps2bZCLkmnKZgRaaaBh2ndA5HGpIj2fzQVOaEAjU1 7O+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696743762; x=1697348562; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bktt96HaK9jSV/VfWxuKA2xiQeQu/9hYpvUZ9O8KUH0=; b=pWp5kAzGyyVymi5pOvZziogmi1sRIuOtx8sZN7NC9tQ4uPi8Op1daoX3BbgHh8PFcL 5fAsspSbp02tgfc2YRdUw9hA3KxmMNSu9vDjFog58JUtKa7xzeo8t5vQci0yv9Uyemgn d1/1+96xCJLH2mebZE+HUipASlNzQK8GGvs2mJpLFnzgqmYie6NxqefVNvQhaVJrYpZn 1XWj7jJq2Vaijy2tw/tesFh7Ys/rM5mi1x0J1n2yZ87GF9FxYjPf73PsS1gp6pqHw5Hd uFmjZX0obpqvkPwNeLeqC2zBPRDfoSoX71ajKh3nnLimVwEnSKQ9ud8I73szWSP8U60P oBcw== X-Gm-Message-State: AOJu0YzkI3mbuhPYdgcC7UussPaPMWtlotX9OveSZYLUgMhkAUys0NI3 9htHd0wXVf1YIyx0Bk+/jQuS7y+BVkwd74JN6/moCw== X-Google-Smtp-Source: AGHT+IHjiQBS/sBAdE8ugbrZv2UrXXTvj7Oxt+gCfLTg9/y/h4Y0B9USsQmMdgk9to+Ryl3JisCd+g== X-Received: by 2002:a05:6a00:1d09:b0:692:6417:728a with SMTP id a9-20020a056a001d0900b006926417728amr10083566pfx.14.1696743761720; Sat, 07 Oct 2023 22:42:41 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id g2-20020a62e302000000b0069370f32687sm4095636pfh.174.2023.10.07.22.42.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 07 Oct 2023 22:42:41 -0700 (PDT) From: Akihiko Odaki To: Cc: Akihiko Odaki , "Michael S. Tsirkin" , Jason Wang , qemu-devel@nongnu.org (open list:All patches CC here) Subject: [RFC PATCH 3/4] virtio-net: Add hash type options Date: Sun, 8 Oct 2023 14:42:17 +0900 Message-ID: <20231008054222.146228-4-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231008054222.146228-1-akihiko.odaki@daynix.com> References: <20231008054222.146228-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::436; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x436.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 | 48 +++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index deba793ec2..33857dd3c2 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -142,6 +142,7 @@ typedef struct VirtioNetRssData { uint32_t runtime_hash_types; uint32_t supported_hash_types; uint32_t peer_hash_types; + OnOffAuto specified_hash_types[8]; 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 3bf1fec2ac..9146a65aa4 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1379,16 +1379,31 @@ static bool virtio_net_configure_rss_host(VirtIONet *n, Error **errp) { NetVnetHashCap cap; + n->rss_data.supported_hash_types = VIRTIO_NET_RSS_SUPPORTED_HASHES; + if (qemu_get_vnet_hash_cap(qemu_get_queue(n->nic)->peer, &cap) && cap.max_indirection_table_length >= VIRTIO_NET_RSS_MAX_TABLE_LEN) { n->rss_data.peer_hash_available = true; - n->rss_data.supported_hash_types = cap.types; n->rss_data.peer_hash_types = cap.types; - return true; + for (size_t i = 0; ; i++) { + if (i >= ARRAY_SIZE(n->rss_data.specified_hash_types)) { + n->rss_data.supported_hash_types = cap.types; + break; + } + + if (n->rss_data.specified_hash_types[i] == ON_OFF_AUTO_ON && + !(cap.types & BIT(i + 1))) { + break; + } + } } - n->rss_data.supported_hash_types = VIRTIO_NET_RSS_SUPPORTED_HASHES; + for (size_t i = 0; i < ARRAY_SIZE(n->rss_data.specified_hash_types); i++) { + if (n->rss_data.specified_hash_types[i] == ON_OFF_AUTO_OFF) { + n->rss_data.supported_hash_types &= ~BIT(i + 1); + } + } return virtio_net_commit_rss_host_config(n, errp); } @@ -4013,6 +4028,33 @@ static Property virtio_net_properties[] = { DEFINE_PROP_INT32("speed", VirtIONet, net_conf.speed, SPEED_UNKNOWN), DEFINE_PROP_STRING("duplex", VirtIONet, net_conf.duplex_str), DEFINE_PROP_BOOL("failover", VirtIONet, failover, false), + DEFINE_PROP_ON_OFF_AUTO("hash-ipv4", VirtIONet, + rss_data.specified_hash_types[VIRTIO_NET_HASH_REPORT_IPv4 - 1], + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO("hash-tcp4", VirtIONet, + rss_data.specified_hash_types[VIRTIO_NET_HASH_REPORT_TCPv4 - 1], + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO("hash-udp4", VirtIONet, + rss_data.specified_hash_types[VIRTIO_NET_HASH_REPORT_UDPv4 - 1], + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO("hash-ipv6", VirtIONet, + rss_data.specified_hash_types[VIRTIO_NET_HASH_REPORT_IPv6 - 1], + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO("hash-tcp6", VirtIONet, + rss_data.specified_hash_types[VIRTIO_NET_HASH_REPORT_TCPv6 - 1], + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO("hash-udp6", VirtIONet, + rss_data.specified_hash_types[VIRTIO_NET_HASH_REPORT_UDPv6 - 1], + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO("hash-ipv6ex", VirtIONet, + rss_data.specified_hash_types[VIRTIO_NET_HASH_REPORT_IPv6_EX - 1], + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO("hash-tcp6ex", VirtIONet, + rss_data.specified_hash_types[VIRTIO_NET_HASH_REPORT_TCPv6_EX - 1], + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO("hash-udp6ex", VirtIONet, + rss_data.specified_hash_types[VIRTIO_NET_HASH_REPORT_UDPv6_EX - 1], + ON_OFF_AUTO_AUTO), DEFINE_PROP_END_OF_LIST(), }; From patchwork Sun Oct 8 05:42:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1844859 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=PccdtqLd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S3B185N7jz1yqP for ; Sun, 8 Oct 2023 16:43:56 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpMZ1-0003Ry-Aq; Sun, 08 Oct 2023 01:42:51 -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 1qpMYy-0003RO-UO for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:42:50 -0400 Received: from mail-qt1-x829.google.com ([2607:f8b0:4864:20::829]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qpMYv-0002ij-U3 for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:42:47 -0400 Received: by mail-qt1-x829.google.com with SMTP id d75a77b69052e-41808baf6abso22318881cf.3 for ; Sat, 07 Oct 2023 22:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696743764; x=1697348564; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=88mTmxvCCzXeF5MvCYjb+uFeI1WySt4qQFaPTNFWwqc=; b=PccdtqLdHJm0FXqDKa9IONNJ/9GuXn54yf52Thw8cBgOeEliG3R481CV7y2qekS+Tf RXE0L8gkWHVWAxP7NEUCu0UTZELWzm6l47KFggPSkbqhtljCfDSJiD7Ym24fb+eK0P1y fS905rPxzfgDlku/8ogaLWQUeAAvORI467BsR/cC6+PkT9QhKd7PilhaDq+rw/hld6jn IzYF2hfjSpSrBqRGhpDRWwDkRb82a6E5Ba+0SXkDdcgv47nJSSZNPR5rdHpAitoQSd4d X6lOxJfLIm5THE65Lt5N0AN/p4mA/+EBgC3vn1rjXBSy8teGr/j/bAfyLqQ3pD6gcP81 bvyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696743764; x=1697348564; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=88mTmxvCCzXeF5MvCYjb+uFeI1WySt4qQFaPTNFWwqc=; b=EotyNqPJzULxJS0Ni5OIDF82mjocHs4DxeKDk1VxNZ4q5kvpNG5mJmgJJqAFpXRahG kHZEto2HPceci6CNcjaLzRnX64LT1nZ/qnPVI1VD24G/zEOdglRMBJM9XxtgwChor2/0 izh7Vxio5QSMZgDBBgH7VyTzSox7QDFR0PbO0nfu8JB2uSZw1JT4lSNQz+T1cnjn5HW0 StD4R4d8+PDVEIp0wO0rmP1dk+/2VN3AX6wGzG0BxNaGoM3/0Os8HHQABFS+Y5Rhw5aR AWtPZmhD6pnE7XY7RtrzcW0CbsNjLLfMrtNYUuVCfl1lLhTHEAYAn2ZIzwBoYucUkaOA U8CQ== X-Gm-Message-State: AOJu0YxPDA43L3DvaS12dGhJIk7z/RW9iR3KomOesqWadxxvtr9Qa5hT UpAZzaOCfiYS7Ylpb7ezqa0Nhg== X-Google-Smtp-Source: AGHT+IHcgOaPoWYtJRQtrou7yojFw0dwP98UbTm635hLlu5Zj28C10TzZUPrSo+Jbxe3dEy+pENTGw== X-Received: by 2002:a05:622a:34d:b0:418:16e0:f19e with SMTP id r13-20020a05622a034d00b0041816e0f19emr14822805qtw.14.1696743764495; Sat, 07 Oct 2023 22:42:44 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id n7-20020a62e507000000b00693411c6c3csm3961357pff.39.2023.10.07.22.42.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 07 Oct 2023 22:42:44 -0700 (PDT) From: Akihiko Odaki To: Cc: Akihiko Odaki , qemu-devel@nongnu.org (open list:All patches CC here) Subject: [RFC PATCH 4/4] docs/devel/ebpf_rss.rst: Update for kernel RSS Date: Sun, 8 Oct 2023 14:42:18 +0900 Message-ID: <20231008054222.146228-5-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231008054222.146228-1-akihiko.odaki@daynix.com> References: <20231008054222.146228-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::829; envelope-from=akihiko.odaki@daynix.com; helo=mail-qt1-x829.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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 kernel RSS. Signed-off-by: Akihiko Odaki --- docs/devel/ebpf_rss.rst | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/devel/ebpf_rss.rst b/docs/devel/ebpf_rss.rst index 4a68682b31..487123006c 100644 --- a/docs/devel/ebpf_rss.rst +++ b/docs/devel/ebpf_rss.rst @@ -5,9 +5,21 @@ 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. Kernel 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+. Kernel RSS requires Linux with the following +patches: +https://lore.kernel.org/all/20231008052101.144422-1-akihiko.odaki@daynix.com/ + +eBPF RSS does not support hash reporting. The hash types and indirection +table size compatible with the kernel RSS may be limited by the kernel. + +virtio-net automatically chooses the RSS implementation to use. Kernel 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'. @@ -47,9 +59,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 ---------------- @@ -65,7 +74,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 -----------------------