From patchwork Wed Oct 11 15:39:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1846831 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=RVVDah2a; 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 4S5H6C02V3z23jj for ; Thu, 12 Oct 2023 02:40:34 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqbK1-0002Vk-2P; Wed, 11 Oct 2023 11:40:30 -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 1qqbJZ-00028Y-40 for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:05 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qqbJW-0001ug-Vn for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:00 -0400 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1c9bf22fe05so14668135ad.2 for ; Wed, 11 Oct 2023 08:39:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1697038797; x=1697643597; 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=njs58QgxYwpM/JzmhO86oL0rnvQrRdx5+AMikdQqFyg=; b=RVVDah2acW5xxclKeWEz/GQIndKaoOYZ1qwKVXilsBJtD5PYHYAonWizLz5qeqNfkA qpFpaHTtP98BNa4iFNrW7/sWOJR5yxqvcxWod34IhaUc77ZIPy5oeWxZS/k90vjtjPvn dZrf3LPK0fKnVm03C/3yqI+SJrIq382m9inWHNIyhesBq798uha162vV9pHS2hfuLMfy eADnsbrYDYhv3QONI/Dtv1fD8F0OQDIJqyVxW7D2wHNwJZlF4Eg/Pb4VYIM/Deljns1W D0IsQNmmhW2JodFagea01D1J8du03rSI7yw1gof26GLBmgoB2RqEf+0k6OvKVKycubny 9Npg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697038797; x=1697643597; 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=njs58QgxYwpM/JzmhO86oL0rnvQrRdx5+AMikdQqFyg=; b=xPnNjcmp0v6WeeM6kLQfqopWQJ/f6cs3MA5rDqVilMT/qlx3sY1m9RImhpBelCaiz5 5VCI2jurV5VXlbkkaGNf7/Y+nG/V6aiUOGgt0NAhfKbyGumNbfe0dW0VNr28zu5FXQ5D Wm1ARM88r6y0yk9o4K8j8ppB4rdxAHZs9l1T9w9pciIschnInO9M16vB1eH5VUt9zbX+ QqVYcg+3yDt+SZMEm3JTzjL4g7W2cmwWB8JO3R7emxuOigQ+9ZDrY7BmaeNlF7hGD74u b+ksX+l4zOWnWjQQb5l+FW6YAizOy+3m9mH7a/stf4do393Olh+2SquHB0hxmKL9j3Gu UAVA== X-Gm-Message-State: AOJu0YykoHmx/X3/oHLIWb1tYeJEJW/6k2XlZSmiFKEMgCmN9rtrR+xU mXkKLT0HMe3lJatoGKnKJuCn1lPdrdcIXrBRqYQcIQ== X-Google-Smtp-Source: AGHT+IH7caDhvE4ztgB+4GGgWhqtXaA/cnocMMBSrfol8hq0Dl49wtJLR/Y8VjNTPq7pkOS4MBfNmg== X-Received: by 2002:a17:903:110f:b0:1c5:d0ba:429 with SMTP id n15-20020a170903110f00b001c5d0ba0429mr23704605plh.4.1697038797270; Wed, 11 Oct 2023 08:39:57 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id b16-20020a170902b61000b001c728609574sm14073656pls.6.2023.10.11.08.39.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Oct 2023 08:39:57 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , Akihiko Odaki Subject: [PATCH v3 01/11] tap: Remove tap_probe_vnet_hdr_len() Date: Thu, 12 Oct 2023 00:39:32 +0900 Message-ID: <20231011153944.39572-2-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011153944.39572-1-akihiko.odaki@daynix.com> References: <20231011153944.39572-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::62c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62c.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 It was necessary since an Linux older than 2.6.35 may implement the virtio-net header but may not allow to change its length. Remove it since such an old Linux is no longer supported. Signed-off-by: Akihiko Odaki Acked-by: Michael S. Tsirkin --- net/tap_int.h | 1 - net/tap-bsd.c | 5 ----- net/tap-linux.c | 20 -------------------- net/tap-solaris.c | 5 ----- net/tap-stub.c | 5 ----- net/tap.c | 10 ++-------- 6 files changed, 2 insertions(+), 44 deletions(-) diff --git a/net/tap_int.h b/net/tap_int.h index 547f8a5a28..ff7ab23ad7 100644 --- a/net/tap_int.h +++ b/net/tap_int.h @@ -35,7 +35,6 @@ 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); 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); diff --git a/net/tap-bsd.c b/net/tap-bsd.c index 4c98fdd337..bcd9e894a8 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -212,11 +212,6 @@ int tap_probe_has_ufo(int fd) return 0; } -int tap_probe_vnet_hdr_len(int fd, int len) -{ - return 0; -} - void tap_fd_set_vnet_hdr_len(int fd, int len) { } diff --git a/net/tap-linux.c b/net/tap-linux.c index f54f308d35..985287816e 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -173,26 +173,6 @@ int tap_probe_has_ufo(int fd) return 1; } -/* Verify that we can assign given length */ -int tap_probe_vnet_hdr_len(int fd, int len) -{ - int orig; - if (ioctl(fd, TUNGETVNETHDRSZ, &orig) == -1) { - return 0; - } - if (ioctl(fd, TUNSETVNETHDRSZ, &len) == -1) { - return 0; - } - /* Restore original length: we can't handle failure. */ - if (ioctl(fd, TUNSETVNETHDRSZ, &orig) == -1) { - fprintf(stderr, "TUNGETVNETHDRSZ ioctl() failed: %s. Exiting.\n", - strerror(errno)); - abort(); - return -errno; - } - return 1; -} - 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 38e15028bf..6ad79fecad 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -216,11 +216,6 @@ int tap_probe_has_ufo(int fd) return 0; } -int tap_probe_vnet_hdr_len(int fd, int len) -{ - return 0; -} - void tap_fd_set_vnet_hdr_len(int fd, int len) { } diff --git a/net/tap-stub.c b/net/tap-stub.c index a0fa25804b..422257668c 100644 --- a/net/tap-stub.c +++ b/net/tap-stub.c @@ -47,11 +47,6 @@ int tap_probe_has_ufo(int fd) return 0; } -int tap_probe_vnet_hdr_len(int fd, int len) -{ - return 0; -} - void tap_fd_set_vnet_hdr_len(int fd, int len) { } diff --git a/net/tap.c b/net/tap.c index c6639d9f20..0403729739 100644 --- a/net/tap.c +++ b/net/tap.c @@ -248,11 +248,7 @@ static bool tap_has_vnet_hdr(NetClientState *nc) static bool tap_has_vnet_hdr_len(NetClientState *nc, int len) { - TAPState *s = DO_UPCAST(TAPState, nc, nc); - - assert(nc->info->type == NET_CLIENT_DRIVER_TAP); - - return !!tap_probe_vnet_hdr_len(s->fd, len); + return tap_has_vnet_hdr(nc); } static int tap_get_vnet_hdr_len(NetClientState *nc) @@ -419,9 +415,7 @@ static TAPState *net_tap_fd_init(NetClientState *peer, * Make sure host header length is set correctly in tap: * it might have been modified by another instance of qemu. */ - if (tap_probe_vnet_hdr_len(s->fd, s->host_vnet_hdr_len)) { - tap_fd_set_vnet_hdr_len(s->fd, s->host_vnet_hdr_len); - } + tap_fd_set_vnet_hdr_len(s->fd, s->host_vnet_hdr_len); tap_read_poll(s, true); s->vhost_net = NULL; From patchwork Wed Oct 11 15:39:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1846833 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=ZN7O+sVX; 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 4S5H6w3lcCz23jd for ; Thu, 12 Oct 2023 02:41:12 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqbK9-0002v2-Sb; Wed, 11 Oct 2023 11:40: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 1qqbJd-0002Ei-Oz for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:09 -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 1qqbJb-0001vI-Pq for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:05 -0400 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1c9b70b9656so14545915ad.1 for ; Wed, 11 Oct 2023 08:40:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1697038802; x=1697643602; 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=g9DyJgfsNaywwdF+X+Mlrm7UwaxUF7X0EYzGFK3vXhg=; b=ZN7O+sVXntf6TGnBMz5Ql/TtilLgG1P4ewFLLJQyfjXJQrsyFtLrf3FOIH9ySOT9Fr gca88tiRpToYn3FQxXaYFCPKFJ8WPcarxRynqo/5Uvs/fx2v/99QhPABLkGtjMQ5Mbqj O3u9w1QAWabSM2yYp1c+j2ogfFP9soP2k+K5OXoR4RMX2GkeKm1D4JynF5oa4hIKUvGA ivT/mFaoWW+eHDnQMs9ydJ8ky4QEo6dazgRSxvi68tVZjUw3ChNvBptITI5Y32BTfZIY yaRc/V1pekFB2NvMitL/raTEQS7Jv9ib1diHMvE7C15L1kBGtq2MY8+6MuKWmWa6/Nta dxtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697038802; x=1697643602; 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=g9DyJgfsNaywwdF+X+Mlrm7UwaxUF7X0EYzGFK3vXhg=; b=pTT9HxOkAj5Uf0zl31CYXfBm1FoZNkBdJWfQ6mGsj3tRzOPJ36sTT5RYkcnthLIYxb y2iaVG+sDFSn0wXS/j0Kh/ZAlFFF5mpOPfwKirwMlVAnOYAvjL9gMEEHubOq5l55Ffjk OsSD6R3UpZ1lv7Xginhv5El5IfPDEmE8KaH0jmE2HLqOwRG0dwwxreGSQ1wpP4Wn9IM0 FxALOalIMKQ0j+t4ppkKCBDkrG07y2GjmkPalWtUXHNJMXowhnvi4Ra2WeRpy4QRjYbl odmFIPd/SRxEwiWGijIVu8QLv6SC6Bzpfhp8/mhId4PeCvYfAVRm0AfpvqCDjMqD5BOl t0Gg== X-Gm-Message-State: AOJu0YwEilCbrJ+2xTqPl/WxBNrQS+pYT5XbTVx+T/z4V3j6jbVzmaxN UPzAxIjQ1jQ9XiFq5qah5T0co7PX5BGay4cgaGY9rw== X-Google-Smtp-Source: AGHT+IE/hREEPHY+UQtTIOqyEAEW3XF3Tn0TcLrgJL3YwVY8LUHKb1hrOSPzZ3YvjV/tW7kqBYsbvw== X-Received: by 2002:a17:902:c947:b0:1c9:c920:6df3 with SMTP id i7-20020a170902c94700b001c9c9206df3mr3169887pla.53.1697038801607; Wed, 11 Oct 2023 08:40:01 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id p20-20020a170902ead400b001c3e732b8dbsm14189434pld.168.2023.10.11.08.39.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Oct 2023 08:40:01 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , Akihiko Odaki , Dmitry Fleytman , Sriram Yagnaraman , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione Subject: [PATCH v3 02/11] tap: Remove qemu_using_vnet_hdr() Date: Thu, 12 Oct 2023 00:39:33 +0900 Message-ID: <20231011153944.39572-3-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011153944.39572-1-akihiko.odaki@daynix.com> References: <20231011153944.39572-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none 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_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 Since qemu_set_vnet_hdr_len() is always called when qemu_using_vnet_hdr() is called, we can merge them and save some code. For consistency, express that the virtio-net header is not in use by returning 0 with qemu_get_vnet_hdr_len() instead of having a dedicated function, qemu_get_using_vnet_hdr(). Signed-off-by: Akihiko Odaki --- include/net/net.h | 6 ------ hw/net/e1000e.c | 1 - hw/net/igb.c | 1 - hw/net/net_tx_pkt.c | 4 ++-- hw/net/virtio-net.c | 3 --- hw/net/vmxnet3.c | 2 -- net/dump.c | 4 +--- net/net.c | 18 ------------------ net/netmap.c | 5 ----- net/tap.c | 22 ++-------------------- 10 files changed, 5 insertions(+), 61 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index 685ec58318..011031ef77 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -56,8 +56,6 @@ typedef RxFilterInfo *(QueryRxFilter)(NetClientState *); typedef bool (HasUfo)(NetClientState *); typedef bool (HasVnetHdr)(NetClientState *); typedef bool (HasVnetHdrLen)(NetClientState *, int); -typedef bool (GetUsingVnetHdr)(NetClientState *); -typedef void (UsingVnetHdr)(NetClientState *, bool); typedef void (SetOffload)(NetClientState *, int, int, int, int, int); typedef int (GetVnetHdrLen)(NetClientState *); typedef void (SetVnetHdrLen)(NetClientState *, int); @@ -86,8 +84,6 @@ typedef struct NetClientInfo { HasUfo *has_ufo; HasVnetHdr *has_vnet_hdr; HasVnetHdrLen *has_vnet_hdr_len; - GetUsingVnetHdr *get_using_vnet_hdr; - UsingVnetHdr *using_vnet_hdr; SetOffload *set_offload; GetVnetHdrLen *get_vnet_hdr_len; SetVnetHdrLen *set_vnet_hdr_len; @@ -191,8 +187,6 @@ void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]); bool qemu_has_ufo(NetClientState *nc); bool qemu_has_vnet_hdr(NetClientState *nc); bool qemu_has_vnet_hdr_len(NetClientState *nc, int len); -bool qemu_get_using_vnet_hdr(NetClientState *nc); -void qemu_using_vnet_hdr(NetClientState *nc, bool enable); void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6, int ecn, int ufo); int qemu_get_vnet_hdr_len(NetClientState *nc); diff --git a/hw/net/e1000e.c b/hw/net/e1000e.c index e41a6c1038..4edb58858e 100644 --- a/hw/net/e1000e.c +++ b/hw/net/e1000e.c @@ -352,7 +352,6 @@ e1000e_init_net_peer(E1000EState *s, PCIDevice *pci_dev, uint8_t *macaddr) for (i = 0; i < s->conf.peers.queues; i++) { nc = qemu_get_subqueue(s->nic, i); qemu_set_vnet_hdr_len(nc->peer, sizeof(struct virtio_net_hdr)); - qemu_using_vnet_hdr(nc->peer, true); } } diff --git a/hw/net/igb.c b/hw/net/igb.c index 8b713843d9..cfdb148051 100644 --- a/hw/net/igb.c +++ b/hw/net/igb.c @@ -339,7 +339,6 @@ igb_init_net_peer(IGBState *s, PCIDevice *pci_dev, uint8_t *macaddr) for (i = 0; i < s->conf.peers.queues; i++) { nc = qemu_get_subqueue(s->nic, i); qemu_set_vnet_hdr_len(nc->peer, sizeof(struct virtio_net_hdr)); - qemu_using_vnet_hdr(nc->peer, true); } } diff --git a/hw/net/net_tx_pkt.c b/hw/net/net_tx_pkt.c index 2e5f58b3c9..668871f8d8 100644 --- a/hw/net/net_tx_pkt.c +++ b/hw/net/net_tx_pkt.c @@ -578,7 +578,7 @@ static void net_tx_pkt_sendv( { NetClientState *nc = opaque; - if (qemu_get_using_vnet_hdr(nc->peer)) { + if (qemu_get_vnet_hdr_len(nc->peer)) { qemu_sendv_packet(nc, virt_iov, virt_iov_cnt); } else { qemu_sendv_packet(nc, iov, iov_cnt); @@ -808,7 +808,7 @@ static bool net_tx_pkt_do_sw_fragmentation(struct NetTxPkt *pkt, bool net_tx_pkt_send(struct NetTxPkt *pkt, NetClientState *nc) { - bool offload = qemu_get_using_vnet_hdr(nc->peer); + bool offload = !!qemu_get_vnet_hdr_len(nc->peer); return net_tx_pkt_send_custom(pkt, offload, net_tx_pkt_sendv, nc); } diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 9a93a2df01..cab79f19cb 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3709,9 +3709,6 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) peer_test_vnet_hdr(n); if (peer_has_vnet_hdr(n)) { - for (i = 0; i < n->max_queue_pairs; i++) { - qemu_using_vnet_hdr(qemu_get_subqueue(n->nic, i)->peer, true); - } n->host_hdr_len = sizeof(struct virtio_net_hdr); } else { n->host_hdr_len = 0; diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c index 3df1d1b101..a9619108ca 100644 --- a/hw/net/vmxnet3.c +++ b/hw/net/vmxnet3.c @@ -2086,8 +2086,6 @@ static void vmxnet3_net_init(VMXNET3State *s) if (s->peer_has_vhdr) { qemu_set_vnet_hdr_len(qemu_get_queue(s->nic)->peer, sizeof(struct virtio_net_hdr)); - - qemu_using_vnet_hdr(qemu_get_queue(s->nic)->peer, 1); } qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); diff --git a/net/dump.c b/net/dump.c index 7d05f16ca7..d2defe4ed9 100644 --- a/net/dump.c +++ b/net/dump.c @@ -154,10 +154,8 @@ static ssize_t filter_dump_receive_iov(NetFilterState *nf, NetClientState *sndr, int iovcnt, NetPacketSent *sent_cb) { NetFilterDumpState *nfds = FILTER_DUMP(nf); - int offset = qemu_get_using_vnet_hdr(nf->netdev) ? - qemu_get_vnet_hdr_len(nf->netdev) : 0; - dump_receive_iov(&nfds->ds, iov, iovcnt, offset); + dump_receive_iov(&nfds->ds, iov, iovcnt, qemu_get_vnet_hdr_len(nf->netdev)); return 0; } diff --git a/net/net.c b/net/net.c index 3523cceafc..1bb4f33a63 100644 --- a/net/net.c +++ b/net/net.c @@ -515,24 +515,6 @@ bool qemu_has_vnet_hdr_len(NetClientState *nc, int len) return nc->info->has_vnet_hdr_len(nc, len); } -bool qemu_get_using_vnet_hdr(NetClientState *nc) -{ - if (!nc || !nc->info->get_using_vnet_hdr) { - return false; - } - - return nc->info->get_using_vnet_hdr(nc); -} - -void qemu_using_vnet_hdr(NetClientState *nc, bool enable) -{ - if (!nc || !nc->info->using_vnet_hdr) { - return; - } - - nc->info->using_vnet_hdr(nc, enable); -} - void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6, int ecn, int ufo) { diff --git a/net/netmap.c b/net/netmap.c index 9e0cec58d3..b7a669f862 100644 --- a/net/netmap.c +++ b/net/netmap.c @@ -351,10 +351,6 @@ static bool netmap_has_vnet_hdr(NetClientState *nc) return netmap_has_vnet_hdr_len(nc, sizeof(struct virtio_net_hdr)); } -static void netmap_using_vnet_hdr(NetClientState *nc, bool enable) -{ -} - static void netmap_set_vnet_hdr_len(NetClientState *nc, int len) { NetmapState *s = DO_UPCAST(NetmapState, nc, nc); @@ -393,7 +389,6 @@ static NetClientInfo net_netmap_info = { .has_ufo = netmap_has_vnet_hdr, .has_vnet_hdr = netmap_has_vnet_hdr, .has_vnet_hdr_len = netmap_has_vnet_hdr_len, - .using_vnet_hdr = netmap_using_vnet_hdr, .set_offload = netmap_set_offload, .set_vnet_hdr_len = netmap_set_vnet_hdr_len, }; diff --git a/net/tap.c b/net/tap.c index 0403729739..4667933ffe 100644 --- a/net/tap.c +++ b/net/tap.c @@ -255,7 +255,7 @@ static int tap_get_vnet_hdr_len(NetClientState *nc) { TAPState *s = DO_UPCAST(TAPState, nc, nc); - return s->host_vnet_hdr_len; + return s->using_vnet_hdr ? s->host_vnet_hdr_len : 0; } static void tap_set_vnet_hdr_len(NetClientState *nc, int len) @@ -269,23 +269,7 @@ static void tap_set_vnet_hdr_len(NetClientState *nc, int len) tap_fd_set_vnet_hdr_len(s->fd, len); s->host_vnet_hdr_len = len; -} - -static bool tap_get_using_vnet_hdr(NetClientState *nc) -{ - TAPState *s = DO_UPCAST(TAPState, nc, nc); - - return s->using_vnet_hdr; -} - -static void tap_using_vnet_hdr(NetClientState *nc, bool using_vnet_hdr) -{ - TAPState *s = DO_UPCAST(TAPState, nc, nc); - - assert(nc->info->type == NET_CLIENT_DRIVER_TAP); - assert(!!s->host_vnet_hdr_len == using_vnet_hdr); - - s->using_vnet_hdr = using_vnet_hdr; + s->using_vnet_hdr = true; } static int tap_set_vnet_le(NetClientState *nc, bool is_le) @@ -382,8 +366,6 @@ static NetClientInfo net_tap_info = { .has_ufo = tap_has_ufo, .has_vnet_hdr = tap_has_vnet_hdr, .has_vnet_hdr_len = tap_has_vnet_hdr_len, - .get_using_vnet_hdr = tap_get_using_vnet_hdr, - .using_vnet_hdr = tap_using_vnet_hdr, .set_offload = tap_set_offload, .get_vnet_hdr_len = tap_get_vnet_hdr_len, .set_vnet_hdr_len = tap_set_vnet_hdr_len, From patchwork Wed Oct 11 15:39:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1846834 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=v0aWUNR6; 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 4S5H6z3jtNz23jd for ; Thu, 12 Oct 2023 02:41:15 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqbK9-0002rK-Jn; Wed, 11 Oct 2023 11:40:38 -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 1qqbJq-0002RW-IG for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:23 -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 1qqbJe-0001wx-JF for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:18 -0400 Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-3af8b498d30so4105315b6e.0 for ; Wed, 11 Oct 2023 08:40:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1697038805; x=1697643605; 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=4JchmClXziD2vBgzcNf/LgEpJ92hmMKWZAZONhdY+WI=; b=v0aWUNR6m3dfdE6Zmn3b3MBpzZAx72lwIuPWCqgdHdi4uzpTkQ+ZQmkOdThagKrYyn WXtWai85VkD/oIECAndJ8oFBcMQX6AtdhygX36FiIS6TScFBao4MgX+WKHZ13XZfZTWy QabLEkvvjyHcwI4ZIocgDbTHWu+8YtohuYVg9/U2KZWD9R49aVVL8hp4EqvvyoCZFLHf yGdgsMKFVOMW24HL7Euu70DG7m2P1Zd0aG6wgpa6KMXdbcWKMrSyyFjITsRunWuWE15e 6S1iHLuXjRmVxJS1DQ+LKqFfORALhYiu/D7u9s9wPIbjpdQw0qofVYI89GOoNohhle6/ hAqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697038805; x=1697643605; 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=4JchmClXziD2vBgzcNf/LgEpJ92hmMKWZAZONhdY+WI=; b=IB+V98MeKHG580TTdepTQ7De1PFvIKQzV4++97biAASMwm1qbWw9l0Z7PxuVVs7xtJ FTxila9f17b96rzT2z6HVrV1D1cxjUpHz7l/6V1KaAqdl6+Nrgocttz42VSWF5emgsMw SX3QTa+OHcnCo5Xey2zy1SfrKQZtN8FvZ7qPJgAhRni+yt4QoN4SlHlUJfHpD4Fq7EzK Pezt85Ugk9iPez3RNMqBDvrPqCRgg9yiR41aePbxTkNsbwupv6x6Ml/ZkHizlJebYpj/ vBqXpX3RnhUAG+Ev3HAw912YWlSJwNlTzx7AMlaljDocELUtxfa3xKz7CZXIQYQJcESO qAlg== X-Gm-Message-State: AOJu0YxvJ6ysfGktw9Fo8MS1GJBX0v8aG3c+jEwuOdQRKR512r9hyv/r IwrQf51Mr9qQtNfD4BhXZbtsOVX26mtbIPtDmPSSHw== X-Google-Smtp-Source: AGHT+IFX73HA0SJ+h0kbvxBPddRBEvTN86PYEwykVdtGbczJTNkdv8FXUadzO3xo9NmBtE5ZSTDvuA== X-Received: by 2002:a05:6358:988d:b0:14c:704b:d19f with SMTP id q13-20020a056358988d00b0014c704bd19fmr16731836rwa.3.1697038805424; Wed, 11 Oct 2023 08:40:05 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id z9-20020aa785c9000000b006926e3dc2besm10301011pfn.108.2023.10.11.08.40.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Oct 2023 08:40:05 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , Akihiko Odaki Subject: [PATCH v3 03/11] net: Move virtio-net header length assertion Date: Thu, 12 Oct 2023 00:39:34 +0900 Message-ID: <20231011153944.39572-4-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011153944.39572-1-akihiko.odaki@daynix.com> References: <20231011153944.39572-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 The virtio-net header length assertion should happen for any clients. Signed-off-by: Akihiko Odaki --- net/net.c | 5 +++++ net/tap.c | 3 --- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/net/net.c b/net/net.c index 1bb4f33a63..6d2fa8d40f 100644 --- a/net/net.c +++ b/net/net.c @@ -56,6 +56,7 @@ #include "net/filter.h" #include "qapi/string-output-visitor.h" #include "qapi/qobject-input-visitor.h" +#include "standard-headers/linux/virtio_net.h" /* Net bridge is currently not supported for W32. */ #if !defined(_WIN32) @@ -540,6 +541,10 @@ void qemu_set_vnet_hdr_len(NetClientState *nc, int len) return; } + assert(len == sizeof(struct virtio_net_hdr_mrg_rxbuf) || + len == sizeof(struct virtio_net_hdr) || + len == sizeof(struct virtio_net_hdr_v1_hash)); + nc->vnet_hdr_len = len; nc->info->set_vnet_hdr_len(nc, len); } diff --git a/net/tap.c b/net/tap.c index 4667933ffe..57389cacc3 100644 --- a/net/tap.c +++ b/net/tap.c @@ -263,9 +263,6 @@ static void tap_set_vnet_hdr_len(NetClientState *nc, int len) TAPState *s = DO_UPCAST(TAPState, nc, nc); assert(nc->info->type == NET_CLIENT_DRIVER_TAP); - assert(len == sizeof(struct virtio_net_hdr_mrg_rxbuf) || - len == sizeof(struct virtio_net_hdr) || - len == sizeof(struct virtio_net_hdr_v1_hash)); tap_fd_set_vnet_hdr_len(s->fd, len); s->host_vnet_hdr_len = len; From patchwork Wed Oct 11 15:39:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1846841 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=ZFhqQyTR; 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 4S5H9B4jsHz23jd for ; Thu, 12 Oct 2023 02:43:10 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqbKT-0003PP-IQ; Wed, 11 Oct 2023 11:40: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 1qqbK1-0002ep-W0 for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:30 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qqbJj-0001yl-V8 for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:29 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-692eed30152so5382747b3a.1 for ; Wed, 11 Oct 2023 08:40:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1697038810; x=1697643610; 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=motSgxT4NUbVePod9AMFlemp/F4twy5b08NyOAQoZcE=; b=ZFhqQyTR3NrVWkJbYmDpbMLia7D6bZjxLg+I9lKie/d8x98DtT5TgDOzRRtTFxqapH xX5sudVAu+zQnmltF4fmDyXh+lLxnWXnJ2ObW3gRw/jVDoE83gliA70TunFO6NH+c1mn NaaMihlGJ4liXHPzP0oYBAWGTYnXyjMWnmxyoku4iuq65iJcfIV+8s5r/JQCQkaX/P5i Z4vP57ZwVJHN6ZMbZhI1PKSA0yqPe48FuZdRz5fYHY40k4VJ1ocU0Kg0nxEXYtk4xGZh OQPt/2QxEfvlfZRZhLWQGVdNyJaYPZ5T1HB7zysm50q4wT1e3g+Z2dOiG9ZVMU7sWrM6 q1CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697038810; x=1697643610; 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=motSgxT4NUbVePod9AMFlemp/F4twy5b08NyOAQoZcE=; b=GMjbVpWBdq8F09aOP9MLb+Hpe/vmHX88FSlp57791lKyPaULrXg8ul2EXr35dT4BxY 9zNce2WoJHE+Mg5DmO2QokIg1BgF5WOP0qAZRwuIkKQYzhVEoD053VO9eOzM/P1KVCKk YZh9GtjK4nrhorH70sITg4AVvnaeyWPMGb3oWXFkCe2gIJdQmmZdro2RkDcRCBIP5MDH Szk7FK+6UBUGxfuxzLvDPOtN2iwVOkVUW83GHpDl360FgsNWKfMXF8YgAMJF+qJFk2Xk vv0juVmfQM84an80u/HuUPyfB9Qh/a9NUzL070pRtwgcikONNxum5ZlQDqmzuzTYW7Je Bb2A== X-Gm-Message-State: AOJu0Yw/MoUXhy6uEvEtkK04LMmp9t7YGsM0PjniJdGv2Jr5ditcRH91 HgUTKxFbxJqhm87I6Un3Dj+ym/d0/zqyNLyG7GK+DA== X-Google-Smtp-Source: AGHT+IGMF2v5t+o3P9qCS8CaoInQTP0FuS+zhnveZX6lg1uuud+4IcklVDcGPRDI0g9H6kzJrskxFg== X-Received: by 2002:a05:6a20:3213:b0:172:913c:ba37 with SMTP id hl19-20020a056a20321300b00172913cba37mr3814895pzc.38.1697038809673; Wed, 11 Oct 2023 08:40:09 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id ci22-20020a17090afc9600b00277560ecd5dsm49070pjb.46.2023.10.11.08.40.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Oct 2023 08:40:09 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , Akihiko Odaki , Pavel Dovgalyuk , Paolo Bonzini , Zhang Chen , Li Zhijian Subject: [PATCH v3 04/11] net: Remove receive_raw() Date: Thu, 12 Oct 2023 00:39:35 +0900 Message-ID: <20231011153944.39572-5-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011153944.39572-1-akihiko.odaki@daynix.com> References: <20231011153944.39572-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::429; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x429.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, 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 While netmap implements virtio-net header, it does not implement receive_raw(). Instead of implementing receive_raw for netmap, add virtio-net headers in the common code and use receive_iov()/receive() instead. This also fixes the buffer size for the virtio-net header. Fixes: fbbdbddec0 ("tap: allow extended virtio header with hash info") Signed-off-by: Akihiko Odaki --- include/net/filter.h | 3 --- include/net/net.h | 1 - include/net/queue.h | 7 ----- include/sysemu/replay.h | 2 +- net/dump.c | 4 +-- net/filter-buffer.c | 4 +-- net/filter-mirror.c | 4 +-- net/filter-replay.c | 3 +-- net/filter-rewriter.c | 5 ++-- net/filter.c | 8 +++--- net/net.c | 60 ++++++++++++++++------------------------- net/queue.c | 30 +++++++-------------- net/tap.c | 37 ------------------------- replay/replay-net.c | 8 ++---- 14 files changed, 47 insertions(+), 129 deletions(-) diff --git a/include/net/filter.h b/include/net/filter.h index 27ffc630df..e523771e72 100644 --- a/include/net/filter.h +++ b/include/net/filter.h @@ -26,7 +26,6 @@ typedef void (FilterCleanup) (NetFilterState *nf); */ typedef ssize_t (FilterReceiveIOV)(NetFilterState *nc, NetClientState *sender, - unsigned flags, const struct iovec *iov, int iovcnt, NetPacketSent *sent_cb); @@ -65,14 +64,12 @@ struct NetFilterState { ssize_t qemu_netfilter_receive(NetFilterState *nf, NetFilterDirection direction, NetClientState *sender, - unsigned flags, const struct iovec *iov, int iovcnt, NetPacketSent *sent_cb); /* pass the packet to the next filter */ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, - unsigned flags, const struct iovec *iov, int iovcnt, void *opaque); diff --git a/include/net/net.h b/include/net/net.h index 011031ef77..971dc54897 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -71,7 +71,6 @@ typedef struct NetClientInfo { NetClientDriver type; size_t size; NetReceive *receive; - NetReceive *receive_raw; NetReceiveIOV *receive_iov; NetCanReceive *can_receive; NetStart *start; diff --git a/include/net/queue.h b/include/net/queue.h index 9f2f289d77..571f4e1436 100644 --- a/include/net/queue.h +++ b/include/net/queue.h @@ -30,16 +30,12 @@ typedef struct NetQueue NetQueue; typedef void (NetPacketSent) (NetClientState *sender, ssize_t ret); -#define QEMU_NET_PACKET_FLAG_NONE 0 -#define QEMU_NET_PACKET_FLAG_RAW (1<<0) - /* Returns: * >0 - success * 0 - queue packet for future redelivery * <0 - failure (discard packet) */ typedef ssize_t (NetQueueDeliverFunc)(NetClientState *sender, - unsigned flags, const struct iovec *iov, int iovcnt, void *opaque); @@ -48,7 +44,6 @@ NetQueue *qemu_new_net_queue(NetQueueDeliverFunc *deliver, void *opaque); void qemu_net_queue_append_iov(NetQueue *queue, NetClientState *sender, - unsigned flags, const struct iovec *iov, int iovcnt, NetPacketSent *sent_cb); @@ -65,14 +60,12 @@ ssize_t qemu_net_queue_receive_iov(NetQueue *queue, ssize_t qemu_net_queue_send(NetQueue *queue, NetClientState *sender, - unsigned flags, const uint8_t *data, size_t size, NetPacketSent *sent_cb); ssize_t qemu_net_queue_send_iov(NetQueue *queue, NetClientState *sender, - unsigned flags, const struct iovec *iov, int iovcnt, NetPacketSent *sent_cb); diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h index 08aae5869f..67b2d3ac73 100644 --- a/include/sysemu/replay.h +++ b/include/sysemu/replay.h @@ -158,7 +158,7 @@ ReplayNetState *replay_register_net(NetFilterState *nfs); /*! Unregisters replay network filter. */ void replay_unregister_net(ReplayNetState *rns); /*! Called to write network packet to the replay log. */ -void replay_net_packet_event(ReplayNetState *rns, unsigned flags, +void replay_net_packet_event(ReplayNetState *rns, const struct iovec *iov, int iovcnt); /* Audio */ diff --git a/net/dump.c b/net/dump.c index d2defe4ed9..968ac7a82a 100644 --- a/net/dump.c +++ b/net/dump.c @@ -150,8 +150,8 @@ struct NetFilterDumpState { }; static ssize_t filter_dump_receive_iov(NetFilterState *nf, NetClientState *sndr, - unsigned flags, const struct iovec *iov, - int iovcnt, NetPacketSent *sent_cb) + const struct iovec *iov, int iovcnt, + NetPacketSent *sent_cb) { NetFilterDumpState *nfds = FILTER_DUMP(nf); diff --git a/net/filter-buffer.c b/net/filter-buffer.c index 283dc9cbe6..6d8b581cd8 100644 --- a/net/filter-buffer.c +++ b/net/filter-buffer.c @@ -58,7 +58,6 @@ static void filter_buffer_release_timer(void *opaque) /* filter APIs */ static ssize_t filter_buffer_receive_iov(NetFilterState *nf, NetClientState *sender, - unsigned flags, const struct iovec *iov, int iovcnt, NetPacketSent *sent_cb) @@ -79,8 +78,7 @@ static ssize_t filter_buffer_receive_iov(NetFilterState *nf, * the packets without caring about the receiver. This is suboptimal. * May need more thoughts (e.g keeping sent_cb). */ - qemu_net_queue_append_iov(s->incoming_queue, sender, flags, - iov, iovcnt, NULL); + qemu_net_queue_append_iov(s->incoming_queue, sender, iov, iovcnt, NULL); return iov_size(iov, iovcnt); } diff --git a/net/filter-mirror.c b/net/filter-mirror.c index 34a63b5dbb..8a618f26c0 100644 --- a/net/filter-mirror.c +++ b/net/filter-mirror.c @@ -145,12 +145,12 @@ static void redirector_to_filter(NetFilterState *nf, if (nf->direction == NET_FILTER_DIRECTION_ALL || nf->direction == NET_FILTER_DIRECTION_TX) { - qemu_netfilter_pass_to_next(nf->netdev, 0, &iov, 1, nf); + qemu_netfilter_pass_to_next(nf->netdev, &iov, 1, nf); } if (nf->direction == NET_FILTER_DIRECTION_ALL || nf->direction == NET_FILTER_DIRECTION_RX) { - qemu_netfilter_pass_to_next(nf->netdev->peer, 0, &iov, 1, nf); + qemu_netfilter_pass_to_next(nf->netdev->peer, &iov, 1, nf); } } diff --git a/net/filter-replay.c b/net/filter-replay.c index 54690676ef..ab132f6f24 100644 --- a/net/filter-replay.c +++ b/net/filter-replay.c @@ -31,7 +31,6 @@ struct NetFilterReplayState { static ssize_t filter_replay_receive_iov(NetFilterState *nf, NetClientState *sndr, - unsigned flags, const struct iovec *iov, int iovcnt, NetPacketSent *sent_cb) { @@ -39,7 +38,7 @@ static ssize_t filter_replay_receive_iov(NetFilterState *nf, switch (replay_mode) { case REPLAY_MODE_RECORD: if (nf->netdev == sndr) { - replay_net_packet_event(nfrs->rns, flags, iov, iovcnt); + replay_net_packet_event(nfrs->rns, iov, iovcnt); return iov_size(iov, iovcnt); } return 0; diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c index c18c4c2019..5da0b097db 100644 --- a/net/filter-rewriter.c +++ b/net/filter-rewriter.c @@ -251,7 +251,6 @@ static int handle_secondary_tcp_pkt(RewriterState *rf, static ssize_t colo_rewriter_receive_iov(NetFilterState *nf, NetClientState *sender, - unsigned flags, const struct iovec *iov, int iovcnt, NetPacketSent *sent_cb) @@ -294,7 +293,7 @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf, if (sender == nf->netdev) { /* NET_FILTER_DIRECTION_TX */ if (!handle_primary_tcp_pkt(s, conn, pkt, &key)) { - qemu_net_queue_send(s->incoming_queue, sender, 0, + qemu_net_queue_send(s->incoming_queue, sender, (const uint8_t *)pkt->data, pkt->size, NULL); packet_destroy(pkt, NULL); pkt = NULL; @@ -307,7 +306,7 @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf, } else { /* NET_FILTER_DIRECTION_RX */ if (!handle_secondary_tcp_pkt(s, conn, pkt, &key)) { - qemu_net_queue_send(s->incoming_queue, sender, 0, + qemu_net_queue_send(s->incoming_queue, sender, (const uint8_t *)pkt->data, pkt->size, NULL); packet_destroy(pkt, NULL); pkt = NULL; diff --git a/net/filter.c b/net/filter.c index 3fe88fa43f..14dfb6fa36 100644 --- a/net/filter.c +++ b/net/filter.c @@ -28,7 +28,6 @@ static inline bool qemu_can_skip_netfilter(NetFilterState *nf) ssize_t qemu_netfilter_receive(NetFilterState *nf, NetFilterDirection direction, NetClientState *sender, - unsigned flags, const struct iovec *iov, int iovcnt, NetPacketSent *sent_cb) @@ -39,7 +38,7 @@ ssize_t qemu_netfilter_receive(NetFilterState *nf, if (nf->direction == direction || nf->direction == NET_FILTER_DIRECTION_ALL) { return NETFILTER_GET_CLASS(OBJECT(nf))->receive_iov( - nf, sender, flags, iov, iovcnt, sent_cb); + nf, sender, iov, iovcnt, sent_cb); } return 0; @@ -62,7 +61,6 @@ static NetFilterState *netfilter_next(NetFilterState *nf, } ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, - unsigned flags, const struct iovec *iov, int iovcnt, void *opaque) @@ -96,7 +94,7 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, * to the sender, so sent_cb shouldn't be called later, just * pass NULL to next. */ - ret = qemu_netfilter_receive(next, direction, sender, flags, iov, + ret = qemu_netfilter_receive(next, direction, sender, iov, iovcnt, NULL); if (ret) { return ret; @@ -111,7 +109,7 @@ ssize_t qemu_netfilter_pass_to_next(NetClientState *sender, */ if (sender && sender->peer) { qemu_net_queue_send_iov(sender->peer->incoming_queue, - sender, flags, iov, iovcnt, NULL); + sender, iov, iovcnt, NULL); } out: diff --git a/net/net.c b/net/net.c index 6d2fa8d40f..9334fd166e 100644 --- a/net/net.c +++ b/net/net.c @@ -250,7 +250,6 @@ static void qemu_net_client_destructor(NetClientState *nc) g_free(nc); } static ssize_t qemu_deliver_packet_iov(NetClientState *sender, - unsigned flags, const struct iovec *iov, int iovcnt, void *opaque); @@ -604,7 +603,6 @@ int qemu_can_send_packet(NetClientState *sender) static ssize_t filter_receive_iov(NetClientState *nc, NetFilterDirection direction, NetClientState *sender, - unsigned flags, const struct iovec *iov, int iovcnt, NetPacketSent *sent_cb) @@ -614,7 +612,7 @@ static ssize_t filter_receive_iov(NetClientState *nc, if (direction == NET_FILTER_DIRECTION_TX) { QTAILQ_FOREACH(nf, &nc->filters, next) { - ret = qemu_netfilter_receive(nf, direction, sender, flags, iov, + ret = qemu_netfilter_receive(nf, direction, sender, iov, iovcnt, sent_cb); if (ret) { return ret; @@ -622,7 +620,7 @@ static ssize_t filter_receive_iov(NetClientState *nc, } } else { QTAILQ_FOREACH_REVERSE(nf, &nc->filters, next) { - ret = qemu_netfilter_receive(nf, direction, sender, flags, iov, + ret = qemu_netfilter_receive(nf, direction, sender, iov, iovcnt, sent_cb); if (ret) { return ret; @@ -636,7 +634,6 @@ static ssize_t filter_receive_iov(NetClientState *nc, static ssize_t filter_receive(NetClientState *nc, NetFilterDirection direction, NetClientState *sender, - unsigned flags, const uint8_t *data, size_t size, NetPacketSent *sent_cb) @@ -646,7 +643,7 @@ static ssize_t filter_receive(NetClientState *nc, .iov_len = size }; - return filter_receive_iov(nc, direction, sender, flags, &iov, 1, sent_cb); + return filter_receive_iov(nc, direction, sender, &iov, 1, sent_cb); } void qemu_purge_queued_packets(NetClientState *nc) @@ -683,10 +680,9 @@ void qemu_flush_queued_packets(NetClientState *nc) qemu_flush_or_purge_queued_packets(nc, false); } -static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender, - unsigned flags, - const uint8_t *buf, int size, - NetPacketSent *sent_cb) +ssize_t qemu_send_packet_async(NetClientState *sender, + const uint8_t *buf, int size, + NetPacketSent *sent_cb) { NetQueue *queue; int ret; @@ -702,28 +698,20 @@ static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender, /* Let filters handle the packet first */ ret = filter_receive(sender, NET_FILTER_DIRECTION_TX, - sender, flags, buf, size, sent_cb); + sender, buf, size, sent_cb); if (ret) { return ret; } ret = filter_receive(sender->peer, NET_FILTER_DIRECTION_RX, - sender, flags, buf, size, sent_cb); + sender, buf, size, sent_cb); if (ret) { return ret; } queue = sender->peer->incoming_queue; - return qemu_net_queue_send(queue, sender, flags, buf, size, sent_cb); -} - -ssize_t qemu_send_packet_async(NetClientState *sender, - const uint8_t *buf, int size, - NetPacketSent *sent_cb) -{ - return qemu_send_packet_async_with_flags(sender, QEMU_NET_PACKET_FLAG_NONE, - buf, size, sent_cb); + return qemu_net_queue_send(queue, sender, buf, size, sent_cb); } ssize_t qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size) @@ -752,12 +740,17 @@ ssize_t qemu_receive_packet_iov(NetClientState *nc, const struct iovec *iov, ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size) { - return qemu_send_packet_async_with_flags(nc, QEMU_NET_PACKET_FLAG_RAW, - buf, size, NULL); + struct virtio_net_hdr_v1_hash vnet_hdr = { }; + struct iovec iov[] = { + { .iov_base = &vnet_hdr, .iov_len = nc->vnet_hdr_len }, + { .iov_base = (void *)buf, .iov_len = size } + }; + + return qemu_sendv_packet_async(nc, iov, ARRAY_SIZE(iov), NULL); } static ssize_t nc_sendv_compat(NetClientState *nc, const struct iovec *iov, - int iovcnt, unsigned flags) + int iovcnt) { uint8_t *buf = NULL; uint8_t *buffer; @@ -777,18 +770,13 @@ static ssize_t nc_sendv_compat(NetClientState *nc, const struct iovec *iov, offset = iov_to_buf(iov, iovcnt, 0, buf, offset); } - if (flags & QEMU_NET_PACKET_FLAG_RAW && nc->info->receive_raw) { - ret = nc->info->receive_raw(nc, buffer, offset); - } else { - ret = nc->info->receive(nc, buffer, offset); - } + ret = nc->info->receive(nc, buffer, offset); g_free(buf); return ret; } static ssize_t qemu_deliver_packet_iov(NetClientState *sender, - unsigned flags, const struct iovec *iov, int iovcnt, void *opaque) @@ -814,10 +802,10 @@ static ssize_t qemu_deliver_packet_iov(NetClientState *sender, owned_reentrancy_guard->engaged_in_io = true; } - if (nc->info->receive_iov && !(flags & QEMU_NET_PACKET_FLAG_RAW)) { + if (nc->info->receive_iov) { ret = nc->info->receive_iov(nc, iov, iovcnt); } else { - ret = nc_sendv_compat(nc, iov, iovcnt, flags); + ret = nc_sendv_compat(nc, iov, iovcnt); } if (owned_reentrancy_guard) { @@ -849,22 +837,20 @@ ssize_t qemu_sendv_packet_async(NetClientState *sender, /* Let filters handle the packet first */ ret = filter_receive_iov(sender, NET_FILTER_DIRECTION_TX, sender, - QEMU_NET_PACKET_FLAG_NONE, iov, iovcnt, sent_cb); + iov, iovcnt, sent_cb); if (ret) { return ret; } ret = filter_receive_iov(sender->peer, NET_FILTER_DIRECTION_RX, sender, - QEMU_NET_PACKET_FLAG_NONE, iov, iovcnt, sent_cb); + iov, iovcnt, sent_cb); if (ret) { return ret; } queue = sender->peer->incoming_queue; - return qemu_net_queue_send_iov(queue, sender, - QEMU_NET_PACKET_FLAG_NONE, - iov, iovcnt, sent_cb); + return qemu_net_queue_send_iov(queue, sender, iov, iovcnt, sent_cb); } ssize_t diff --git a/net/queue.c b/net/queue.c index c872d51df8..70d29d7ac0 100644 --- a/net/queue.c +++ b/net/queue.c @@ -43,7 +43,6 @@ struct NetPacket { QTAILQ_ENTRY(NetPacket) entry; NetClientState *sender; - unsigned flags; int size; NetPacketSent *sent_cb; uint8_t data[]; @@ -92,7 +91,6 @@ void qemu_del_net_queue(NetQueue *queue) static void qemu_net_queue_append(NetQueue *queue, NetClientState *sender, - unsigned flags, const uint8_t *buf, size_t size, NetPacketSent *sent_cb) @@ -104,7 +102,6 @@ static void qemu_net_queue_append(NetQueue *queue, } packet = g_malloc(sizeof(NetPacket) + size); packet->sender = sender; - packet->flags = flags; packet->size = size; packet->sent_cb = sent_cb; memcpy(packet->data, buf, size); @@ -115,7 +112,6 @@ static void qemu_net_queue_append(NetQueue *queue, void qemu_net_queue_append_iov(NetQueue *queue, NetClientState *sender, - unsigned flags, const struct iovec *iov, int iovcnt, NetPacketSent *sent_cb) @@ -134,7 +130,6 @@ void qemu_net_queue_append_iov(NetQueue *queue, packet = g_malloc(sizeof(NetPacket) + max_len); packet->sender = sender; packet->sent_cb = sent_cb; - packet->flags = flags; packet->size = 0; for (i = 0; i < iovcnt; i++) { @@ -150,7 +145,6 @@ void qemu_net_queue_append_iov(NetQueue *queue, static ssize_t qemu_net_queue_deliver(NetQueue *queue, NetClientState *sender, - unsigned flags, const uint8_t *data, size_t size) { @@ -161,7 +155,7 @@ static ssize_t qemu_net_queue_deliver(NetQueue *queue, }; queue->delivering = 1; - ret = queue->deliver(sender, flags, &iov, 1, queue->opaque); + ret = queue->deliver(sender, &iov, 1, queue->opaque); queue->delivering = 0; return ret; @@ -169,14 +163,13 @@ static ssize_t qemu_net_queue_deliver(NetQueue *queue, static ssize_t qemu_net_queue_deliver_iov(NetQueue *queue, NetClientState *sender, - unsigned flags, const struct iovec *iov, int iovcnt) { ssize_t ret = -1; queue->delivering = 1; - ret = queue->deliver(sender, flags, iov, iovcnt, queue->opaque); + ret = queue->deliver(sender, iov, iovcnt, queue->opaque); queue->delivering = 0; return ret; @@ -190,7 +183,7 @@ ssize_t qemu_net_queue_receive(NetQueue *queue, return 0; } - return qemu_net_queue_deliver(queue, NULL, 0, data, size); + return qemu_net_queue_deliver(queue, NULL, data, size); } ssize_t qemu_net_queue_receive_iov(NetQueue *queue, @@ -201,12 +194,11 @@ ssize_t qemu_net_queue_receive_iov(NetQueue *queue, return 0; } - return qemu_net_queue_deliver_iov(queue, NULL, 0, iov, iovcnt); + return qemu_net_queue_deliver_iov(queue, NULL, iov, iovcnt); } ssize_t qemu_net_queue_send(NetQueue *queue, NetClientState *sender, - unsigned flags, const uint8_t *data, size_t size, NetPacketSent *sent_cb) @@ -214,13 +206,13 @@ ssize_t qemu_net_queue_send(NetQueue *queue, ssize_t ret; if (queue->delivering || !qemu_can_send_packet(sender)) { - qemu_net_queue_append(queue, sender, flags, data, size, sent_cb); + qemu_net_queue_append(queue, sender, data, size, sent_cb); return 0; } - ret = qemu_net_queue_deliver(queue, sender, flags, data, size); + ret = qemu_net_queue_deliver(queue, sender, data, size); if (ret == 0) { - qemu_net_queue_append(queue, sender, flags, data, size, sent_cb); + qemu_net_queue_append(queue, sender, data, size, sent_cb); return 0; } @@ -231,7 +223,6 @@ ssize_t qemu_net_queue_send(NetQueue *queue, ssize_t qemu_net_queue_send_iov(NetQueue *queue, NetClientState *sender, - unsigned flags, const struct iovec *iov, int iovcnt, NetPacketSent *sent_cb) @@ -239,13 +230,13 @@ ssize_t qemu_net_queue_send_iov(NetQueue *queue, ssize_t ret; if (queue->delivering || !qemu_can_send_packet(sender)) { - qemu_net_queue_append_iov(queue, sender, flags, iov, iovcnt, sent_cb); + qemu_net_queue_append_iov(queue, sender, iov, iovcnt, sent_cb); return 0; } - ret = qemu_net_queue_deliver_iov(queue, sender, flags, iov, iovcnt); + ret = qemu_net_queue_deliver_iov(queue, sender, iov, iovcnt); if (ret == 0) { - qemu_net_queue_append_iov(queue, sender, flags, iov, iovcnt, sent_cb); + qemu_net_queue_append_iov(queue, sender, iov, iovcnt, sent_cb); return 0; } @@ -285,7 +276,6 @@ bool qemu_net_queue_flush(NetQueue *queue) ret = qemu_net_queue_deliver(queue, packet->sender, - packet->flags, packet->data, packet->size); if (ret == 0) { diff --git a/net/tap.c b/net/tap.c index 57389cacc3..668d69c0de 100644 --- a/net/tap.c +++ b/net/tap.c @@ -131,41 +131,6 @@ static ssize_t tap_receive_iov(NetClientState *nc, const struct iovec *iov, return tap_write_packet(s, iovp, iovcnt); } -static ssize_t tap_receive_raw(NetClientState *nc, const uint8_t *buf, size_t size) -{ - TAPState *s = DO_UPCAST(TAPState, nc, nc); - struct iovec iov[2]; - int iovcnt = 0; - struct virtio_net_hdr_mrg_rxbuf hdr = { }; - - if (s->host_vnet_hdr_len) { - iov[iovcnt].iov_base = &hdr; - iov[iovcnt].iov_len = s->host_vnet_hdr_len; - iovcnt++; - } - - iov[iovcnt].iov_base = (char *)buf; - iov[iovcnt].iov_len = size; - iovcnt++; - - return tap_write_packet(s, iov, iovcnt); -} - -static ssize_t tap_receive(NetClientState *nc, const uint8_t *buf, size_t size) -{ - TAPState *s = DO_UPCAST(TAPState, nc, nc); - struct iovec iov[1]; - - if (s->host_vnet_hdr_len && !s->using_vnet_hdr) { - return tap_receive_raw(nc, buf, size); - } - - iov[0].iov_base = (char *)buf; - iov[0].iov_len = size; - - return tap_write_packet(s, iov, 1); -} - #ifndef __sun__ ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen) { @@ -355,8 +320,6 @@ int tap_get_fd(NetClientState *nc) static NetClientInfo net_tap_info = { .type = NET_CLIENT_DRIVER_TAP, .size = sizeof(TAPState), - .receive = tap_receive, - .receive_raw = tap_receive_raw, .receive_iov = tap_receive_iov, .poll = tap_poll, .cleanup = tap_cleanup, diff --git a/replay/replay-net.c b/replay/replay-net.c index 3b70f71cf1..87e6d68f4e 100644 --- a/replay/replay-net.c +++ b/replay/replay-net.c @@ -24,7 +24,6 @@ struct ReplayNetState { typedef struct NetEvent { uint8_t id; - uint32_t flags; uint8_t *data; size_t size; } NetEvent; @@ -50,11 +49,10 @@ void replay_unregister_net(ReplayNetState *rns) g_free(rns); } -void replay_net_packet_event(ReplayNetState *rns, unsigned flags, +void replay_net_packet_event(ReplayNetState *rns, const struct iovec *iov, int iovcnt) { NetEvent *event = g_new(NetEvent, 1); - event->flags = flags; event->data = g_malloc(iov_size(iov, iovcnt)); event->size = iov_size(iov, iovcnt); event->id = rns->id; @@ -74,7 +72,7 @@ void replay_event_net_run(void *opaque) assert(event->id < network_filters_count); qemu_netfilter_pass_to_next(network_filters[event->id]->netdev, - event->flags, &iov, 1, network_filters[event->id]); + &iov, 1, network_filters[event->id]); g_free(event->data); g_free(event); @@ -85,7 +83,6 @@ void replay_event_net_save(void *opaque) NetEvent *event = opaque; replay_put_byte(event->id); - replay_put_dword(event->flags); replay_put_array(event->data, event->size); } @@ -94,7 +91,6 @@ void *replay_event_net_load(void) NetEvent *event = g_new(NetEvent, 1); event->id = replay_get_byte(); - event->flags = replay_get_dword(); replay_get_array_alloc(&event->data, &event->size); return event; From patchwork Wed Oct 11 15:39:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1846832 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=chls8Nw0; 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 4S5H6j3mLyz23jd for ; Thu, 12 Oct 2023 02:41:01 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqbKP-0003FB-UB; Wed, 11 Oct 2023 11:40:53 -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 1qqbJp-0002RG-Cx for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:23 -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 1qqbJn-0001zA-ID for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:16 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1c9daca2b85so846855ad.1 for ; Wed, 11 Oct 2023 08:40:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1697038813; x=1697643613; 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=hdRn3xY+r+zZRoAOUO1YfZyC5ZVoV18TeJ1QBbbHIlQ=; b=chls8Nw0IoY2052w8BVd40jDHoSy00n2G8JOCjnjYMShFjDkmE58WmWbJFSMGif18e iIauhk0yKruCmV3yZHk0R2D6wG6c3sTDZQJzd1nMZDKqdHXT7ZUfVAjBsNT4PAGIfIww A7fOKIF8raaWalouQErxeT3XBVwLXOkRZdR9slzfcUg5xkNqsMbtnqU6WIkRjkT4tNWt A9yOzvHScI3qF7Uo3OmY9j+96VwgRcKCAhFWTg3TamVzN3rNQcZ7+u+yshCXVEvO9rzq QBOgEj/3opeDMNOvHLr4AKpjjvF3UZ0YtnBIpVJZLUP7yEpTIh7SkbpV44HmXxcfZ5qW EWZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697038813; x=1697643613; 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=hdRn3xY+r+zZRoAOUO1YfZyC5ZVoV18TeJ1QBbbHIlQ=; b=FAI+16EZ4P0COEirzLbdCF6vyhILhodNdeRxdhHQRQMpdEcwqEcfPfStqQUksZ6GIX ua2GXbngtgftukq+douQS5DOPOfk3rf/p6ohKPgdnzL7ONCptBTuRYC7L+e/tMBD/bW6 xCKf5545isaAhQGssKNywfCkdtkO/6lao/QnC0P2HECR6vi8R3IRUKFZQJxBZZ78GKhT P0/lDCD08eiCzQQgUgoMFSOj0pXbM8tC/4HHW9rdklJtr5s6dsKQbBUqKkQ2Ao3EL99J QPQIx/UkpmXuiBZrZHbUwlWq3qe91HpdhUlAB5X6IAWPgyh0u5mkpgIlMGp/IwLB7Jp6 lJoA== X-Gm-Message-State: AOJu0YxwPIgINsFlU5D7HQLjkjdDfHy5ag2/tS/MocQop1S6GJaA5tFA PJakJ3TH5HxYh/aI4Rucm0xVzC2B12RWl8Asga5Kug== X-Google-Smtp-Source: AGHT+IH1HD4+r4MviKA0GkBBfXgKr+2WGRE/dNdg7Nd58+A26GaFikChPb/yf2S1SBc0DKzUUNRdfw== X-Received: by 2002:a17:902:d490:b0:1c6:de7:add9 with SMTP id c16-20020a170902d49000b001c60de7add9mr31722456plg.19.1697038813036; Wed, 11 Oct 2023 08:40:13 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id a12-20020a170902ee8c00b001bd28b9c3ddsm3460066pld.299.2023.10.11.08.40.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Oct 2023 08:40:12 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , Akihiko Odaki Subject: [PATCH v3 05/11] tap: Shrink zeroed virtio-net header Date: Thu, 12 Oct 2023 00:39:36 +0900 Message-ID: <20231011153944.39572-6-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011153944.39572-1-akihiko.odaki@daynix.com> References: <20231011153944.39572-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none 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_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 tap prepends a zeroed virtio-net header when writing a packet to a tap with virtio-net header enabled but not in use. This only happens when s->host_vnet_hdr_len == sizeof(struct virtio_net_hdr). Signed-off-by: Akihiko Odaki --- net/tap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/tap.c b/net/tap.c index 668d69c0de..4c1eb92076 100644 --- a/net/tap.c +++ b/net/tap.c @@ -118,7 +118,7 @@ static ssize_t tap_receive_iov(NetClientState *nc, const struct iovec *iov, TAPState *s = DO_UPCAST(TAPState, nc, nc); const struct iovec *iovp = iov; struct iovec iov_copy[iovcnt + 1]; - struct virtio_net_hdr_mrg_rxbuf hdr = { }; + struct virtio_net_hdr hdr = { }; if (s->host_vnet_hdr_len && !s->using_vnet_hdr) { iov_copy[0].iov_base = &hdr; From patchwork Wed Oct 11 15:39:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1846835 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=tcP728Ai; 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 4S5H7c2KyLz23jd for ; Thu, 12 Oct 2023 02:41:48 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqbKQ-0003Ga-6b; Wed, 11 Oct 2023 11:40:54 -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 1qqbJr-0002Rd-Bv for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:23 -0400 Received: from mail-ot1-x329.google.com ([2607:f8b0:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qqbJp-0001za-Mt for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:19 -0400 Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-6c4e30a3604so4688180a34.2 for ; Wed, 11 Oct 2023 08:40:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1697038816; x=1697643616; 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=GwJY41Y5Ssd2yodd2ldhaOgM4YyGsLPHPwk9ht/SrrY=; b=tcP728AignOeG1iD6Vk4CDxl/sYPXKOq5NFJ+30KSc0vIIm/Nv9fxW/VgcteCwWmW/ Bd+szpxKY8jjKNxEvb9s7lgBzyfE21xoxT15NI69DYys8UFkwcMma7I4/NNPbgRIdYcu MpqriGfyEOK6VP+J0peXjnhXHFKG9NfQ9LajDfBYas3uAjhLCEdtHiMFxjgXJ1WdUQh1 Icc6S03AHHqSO03xosu02QtcIbCWNinhN/QTiTyIn2UspK+JBe3pAMj04EiLDYS6qlDw qoiHtWGuC5p1tmxbDdIOR2KxPWGcRkz3p51vAbufxTbm9A9HHt5z7gxMaJqENwSVf93Y qEhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697038816; x=1697643616; 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=GwJY41Y5Ssd2yodd2ldhaOgM4YyGsLPHPwk9ht/SrrY=; b=m7xMt+OCj3eYuZj3Zaqx8m8zYMPYMywU6PHkG0ebhoVnBzcFzmRh7IfbJ1tTRg+K+M CiE73EsQVOckzS2CXN5uE2s5jO+c8hCyy7k2q3UIhm8FqR9QBLvrgMHmmV+mFWdGY6r9 iPCzBHlruE0kWYPcJN4GVD669bQmUhVKSFwzkoDcCWdKJ99B2HQvnOK5DfvTVA5goFzg YXhB/5uHfV7IOVBpSDUYiyjdYzw/y+r0wBSRGiku8pmDjJQktXvOlzx0W4iV1Re50w9z bgGtIKDzEJug06QIxgq4AwqBfwZ36jufCm5b5b6PTG6dBq0l0E31ErUYrk2ogbq7VpV/ m+CQ== X-Gm-Message-State: AOJu0YzD33EglVNz4W4e4t6HTYThMhKMc7sOpjDOGewXieQjm2WrSCOY 6gKGGVNwafdrGSzOM3X/q/pRlG0JUO4thX6AkgXcAg== X-Google-Smtp-Source: AGHT+IFvBzIOZcDTq+yc9ColzTw7lmuf6a7ZmL5XOcKRxnHrx4Wk1mW1RWJKW1oFbUKjWPgXxVcAYQ== X-Received: by 2002:a05:6830:22f2:b0:6bc:b8d9:476e with SMTP id t18-20020a05683022f200b006bcb8d9476emr23366613otc.16.1697038816499; Wed, 11 Oct 2023 08:40:16 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id x20-20020a62fb14000000b00682d79199e7sm10201209pfm.200.2023.10.11.08.40.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Oct 2023 08:40:16 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , Akihiko Odaki Subject: [PATCH v3 06/11] virtio-net: Copy header only when necessary Date: Thu, 12 Oct 2023 00:39:37 +0900 Message-ID: <20231011153944.39572-7-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011153944.39572-1-akihiko.odaki@daynix.com> References: <20231011153944.39572-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::329; envelope-from=akihiko.odaki@daynix.com; helo=mail-ot1-x329.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 It is necessary to copy the header only for byte swapping. Worse, when byte swapping is not needed, the header can be larger than the buffer due to VIRTIO_NET_F_HASH_REPORT, which results in buffer overflow. Copy the header only when byte swapping is needed. Fixes: e22f0603fb ("virtio-net: reference implementation of hash report") Signed-off-by: Akihiko Odaki --- hw/net/virtio-net.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index cab79f19cb..b1cc74881a 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -361,7 +361,8 @@ static void virtio_net_vnet_endian_status(VirtIONet *n, uint8_t status) * can't do it, we fallback onto fixing the headers in the core * virtio-net code. */ - n->needs_vnet_hdr_swap = virtio_net_set_vnet_endian(vdev, n->nic->ncs, + n->needs_vnet_hdr_swap = n->has_vnet_hdr && + virtio_net_set_vnet_endian(vdev, n->nic->ncs, queue_pairs, true); } else if (virtio_net_started(n, vdev->status)) { /* After using the device, we need to reset the network backend to @@ -2690,7 +2691,7 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q) return -EINVAL; } - if (n->has_vnet_hdr) { + if (n->needs_vnet_hdr_swap) { if (iov_to_buf(out_sg, out_num, 0, &mhdr, n->guest_hdr_len) < n->guest_hdr_len) { virtio_error(vdev, "virtio-net header incorrect"); @@ -2698,19 +2699,16 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q) g_free(elem); return -EINVAL; } - if (n->needs_vnet_hdr_swap) { - virtio_net_hdr_swap(vdev, (void *) &mhdr); - sg2[0].iov_base = &mhdr; - sg2[0].iov_len = n->guest_hdr_len; - out_num = iov_copy(&sg2[1], ARRAY_SIZE(sg2) - 1, - out_sg, out_num, - n->guest_hdr_len, -1); - if (out_num == VIRTQUEUE_MAX_SIZE) { - goto drop; - } - out_num += 1; - out_sg = sg2; + virtio_net_hdr_swap(vdev, (void *) &mhdr); + sg2[0].iov_base = &mhdr; + sg2[0].iov_len = n->guest_hdr_len; + out_num = iov_copy(&sg2[1], ARRAY_SIZE(sg2) - 1, out_sg, out_num, + n->guest_hdr_len, -1); + if (out_num == VIRTQUEUE_MAX_SIZE) { + goto drop; } + out_num += 1; + out_sg = sg2; } /* * If host wants to see the guest header as is, we can From patchwork Wed Oct 11 15:39:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1846840 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=k2xy+9mt; 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 4S5H9B6WYcz23jj for ; Thu, 12 Oct 2023 02:43:10 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqbKT-0003QA-Ip; Wed, 11 Oct 2023 11:40: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 1qqbJv-0002Si-Vz for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:25 -0400 Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qqbJu-000203-83 for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:23 -0400 Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-6c644a1845cso4732809a34.2 for ; Wed, 11 Oct 2023 08:40:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1697038820; x=1697643620; 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=aEzHr5lZ6dSfodClgg1dqSkcYC39YYxzyUu7VYPY81M=; b=k2xy+9mtfzTwMKg3hamlEsdAkxNnclSStiN0TYabgJYbPlF2enblaXYrsR9S72zcnc w8NCRE+BYsKmrBij0zwM9957xbJ2+wjyQ5G9rOyEuyYlDjfG+kk2GX5tusoGR7nkAEXf gNdldVxqg80DynwDG18oZzLdPwPpeJ1Ksyri99GjN1yWgw57BMjnXYtz+k7ew0LHdeCH qecINDe3mg5sSROUIsrqTPIyX2Of+iJYIts4cWYn5ufGNGJYvYpKYTztdtkE/1jD5ze3 wdjqpfRH82EtO4vibyBdRkVGdp166cBAdDPP99gytqsUyTJAeJse0SRz7OLHLjeCLco2 a07A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697038820; x=1697643620; 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=aEzHr5lZ6dSfodClgg1dqSkcYC39YYxzyUu7VYPY81M=; b=KdOFBZgVAcibvtfydTDqykU4Brb/Ftd240adDvChtL+8QNslrhggocFffjhNnD3OeM oJgCZmgM9pBYG9iXwgyIJynGlvk43k1ETSjZpU9xDoupKqqlV/obTayHZpezzNjdgvAR m38zohGBah7dHGqu4OCZExFTE2WS1gC3t2IMvwviI/EEfu+8dMchMLOjbYifXSXT1ox1 iS96YfG23aNwI/zbziP7f7NSUeC081kthLqSTROOIDoczKYBetrLxuL32tQdULYYVNtg KebtRcxS/PEK0tr4QevdzKUYpfnTOsAJkW3H4B7APDJlI0UuIPmKYGqIsUmSOS4fbPZ2 l1qA== X-Gm-Message-State: AOJu0Yy/Vw/EnV8Hy1qyd3ZgwUMTEp3dOl/cqMwD7UCpj0pSxdSBzi7l cGS8ekiz2FELXd7yt3QahPE77qQqMgeHZKZMU1mM3A== X-Google-Smtp-Source: AGHT+IGva1MmKtVgOy7WeW0GoZpiou68AeVj/V/Q9h7ZBd1NfCFkYC11uPZ5ulWMuLDTNoHWPfl5UQ== X-Received: by 2002:a05:6830:16:b0:6c0:abdd:a875 with SMTP id c22-20020a056830001600b006c0abdda875mr23292197otp.18.1697038819763; Wed, 11 Oct 2023 08:40:19 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id y28-20020a056a001c9c00b00690d1269691sm1378276pfw.22.2023.10.11.08.40.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Oct 2023 08:40:19 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , Akihiko Odaki Subject: [PATCH v3 07/11] virtio-net: Disable RSS on reset Date: Thu, 12 Oct 2023 00:39:38 +0900 Message-ID: <20231011153944.39572-8-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011153944.39572-1-akihiko.odaki@daynix.com> References: <20231011153944.39572-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::32d; envelope-from=akihiko.odaki@daynix.com; helo=mail-ot1-x32d.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 RSS is disabled by default. Fixes: 590790297c ("virtio-net: implement RSS configuration command") Signed-off-by: Akihiko Odaki --- hw/net/virtio-net.c | 70 +++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index b1cc74881a..cd533fb91a 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -601,40 +601,6 @@ static void virtio_net_queue_enable(VirtIODevice *vdev, uint32_t queue_index) } } -static void virtio_net_reset(VirtIODevice *vdev) -{ - VirtIONet *n = VIRTIO_NET(vdev); - int i; - - /* Reset back to compatibility mode */ - n->promisc = 1; - n->allmulti = 0; - n->alluni = 0; - n->nomulti = 0; - n->nouni = 0; - n->nobcast = 0; - /* multiqueue is disabled by default */ - n->curr_queue_pairs = 1; - timer_del(n->announce_timer.tm); - n->announce_timer.round = 0; - n->status &= ~VIRTIO_NET_S_ANNOUNCE; - - /* Flush any MAC and VLAN filter table state */ - n->mac_table.in_use = 0; - n->mac_table.first_multi = 0; - n->mac_table.multi_overflow = 0; - n->mac_table.uni_overflow = 0; - memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN); - memcpy(&n->mac[0], &n->nic->conf->macaddr, sizeof(n->mac)); - qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac); - memset(n->vlans, 0, MAX_VLAN >> 3); - - /* Flush any async TX */ - for (i = 0; i < n->max_queue_pairs; i++) { - flush_or_purge_queued_packets(qemu_get_subqueue(n->nic, i)); - } -} - static void peer_test_vnet_hdr(VirtIONet *n) { NetClientState *nc = qemu_get_queue(n->nic); @@ -3786,6 +3752,42 @@ static void virtio_net_device_unrealize(DeviceState *dev) virtio_cleanup(vdev); } +static void virtio_net_reset(VirtIODevice *vdev) +{ + VirtIONet *n = VIRTIO_NET(vdev); + int i; + + /* Reset back to compatibility mode */ + n->promisc = 1; + n->allmulti = 0; + n->alluni = 0; + n->nomulti = 0; + n->nouni = 0; + n->nobcast = 0; + /* multiqueue is disabled by default */ + n->curr_queue_pairs = 1; + timer_del(n->announce_timer.tm); + n->announce_timer.round = 0; + n->status &= ~VIRTIO_NET_S_ANNOUNCE; + + /* Flush any MAC and VLAN filter table state */ + n->mac_table.in_use = 0; + n->mac_table.first_multi = 0; + n->mac_table.multi_overflow = 0; + n->mac_table.uni_overflow = 0; + memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN); + memcpy(&n->mac[0], &n->nic->conf->macaddr, sizeof(n->mac)); + qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac); + memset(n->vlans, 0, MAX_VLAN >> 3); + + /* Flush any async TX */ + for (i = 0; i < n->max_queue_pairs; i++) { + flush_or_purge_queued_packets(qemu_get_subqueue(n->nic, i)); + } + + virtio_net_disable_rss(n); +} + static void virtio_net_instance_init(Object *obj) { VirtIONet *n = VIRTIO_NET(obj); From patchwork Wed Oct 11 15:39:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1846838 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=dzzcpD7g; 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 4S5H8n054tz23jd for ; Thu, 12 Oct 2023 02:42:49 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqbKY-0003aV-Mu; Wed, 11 Oct 2023 11:41:02 -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 1qqbJy-0002Zb-AY for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:27 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qqbJw-0002Aw-IT for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:26 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-692c02adeefso5281552b3a.3 for ; Wed, 11 Oct 2023 08:40:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1697038823; x=1697643623; 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=l+GdkLFLQD0hE2TPUW8o7BtXmdE7blAvUTaedUpx1vc=; b=dzzcpD7g44SKOj9NDkzIS2Gpi31g72N/u6Yi+FdThTpqCH76LhCQIa8Wk/AdztbUXQ ufp+5J3NfoNBGoL108sIC0/G2cFfs8OKRQ6zDJ145T2XueA0/SEuR+7n3DFcfyLDy/oi QH6WTU2TH35r7MsJPOuMTr+Gv3bb7YDpmonaXEKJy+xxjduaaH+bjUE2I9zouCmCGHi1 otVaccG8Yp1FB0oF1QcAk+3yI1GA6vG96hJNsC1F+IG2DpAzeOMMGBzkKpGUVezWEFRk raZ9FRlaYsnsZezuLFpuMmQqaaY7WQj2t0EDNRYXuT2rDpCiu/LxlteGkVrKABRMZRYT 6v4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697038823; x=1697643623; 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=l+GdkLFLQD0hE2TPUW8o7BtXmdE7blAvUTaedUpx1vc=; b=K4rfUt37PtNOkpPKv0nQdAglGg6XNaMdTIZMkEPvOttNccYOOrKJGAQnFedrHsgU8V i/B2x9eKu3ZQbjfyfpGN/6BhSWFBi+gVJ8TL8uaqw56sYVog2+/Z0jIrv9jtE92eyoBq Lkp/Snge7yAIqCu72NEfdfm6uePLer6PGyhQbjYcPjGItO62V4BL5AawPaRLyF0STXAN pZpbmIaEQ6hi7AKHC2C3zoNYkpi/FS3VItTwf5Lh+SOrszDTHexmgjrBOQtxu2MvU2lA VlhL0Kp9KWdL4joUKwamtlFIIzb9g7TebdnrQI9ml1tONgKdIvu187RBH/wj/gRzazwe 7HTA== X-Gm-Message-State: AOJu0YwfUvGZtbY+2gEle6JT8wgwTpuXJYnVIXrIjGqd4kTG8NTQVw5M ZItnHz8QeeWXUP6hLnBKM+LlIfMeKpHS44wQa49VRQ== X-Google-Smtp-Source: AGHT+IHJn/Ue/MjXlORr1qtXctUbyMZED/LYkmIzwhxFEJTNtaGRXnluzg7iwahEzTk7+IRo20UTLg== X-Received: by 2002:a05:6a21:789c:b0:15c:b7ba:e8e0 with SMTP id bf28-20020a056a21789c00b0015cb7bae8e0mr21930702pzc.51.1697038823042; Wed, 11 Oct 2023 08:40:23 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id x20-20020a170902ea9400b001c5076ae6absm13983618plb.126.2023.10.11.08.40.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Oct 2023 08:40:22 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , Akihiko Odaki Subject: [PATCH v3 08/11] virtio-net: Unify the logic to update NIC state for RSS Date: Thu, 12 Oct 2023 00:39:39 +0900 Message-ID: <20231011153944.39572-9-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011153944.39572-1-akihiko.odaki@daynix.com> References: <20231011153944.39572-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::42f; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42f.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 The code to attach or detach the eBPF program to RSS were duplicated so unify them into one function to save some code. Signed-off-by: Akihiko Odaki --- hw/net/virtio-net.c | 90 ++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 54 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index cd533fb91a..25fc06bd93 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1212,18 +1212,6 @@ static int virtio_net_handle_announce(VirtIONet *n, uint8_t cmd, } } -static void virtio_net_detach_epbf_rss(VirtIONet *n); - -static void virtio_net_disable_rss(VirtIONet *n) -{ - if (n->rss_data.enabled) { - trace_virtio_net_rss_disable(); - } - n->rss_data.enabled = false; - - virtio_net_detach_epbf_rss(n); -} - static bool virtio_net_attach_ebpf_to_backend(NICState *nic, int prog_fd) { NetClientState *nc = qemu_get_peer(qemu_get_queue(nic), 0); @@ -1271,6 +1259,40 @@ static void virtio_net_detach_epbf_rss(VirtIONet *n) virtio_net_attach_ebpf_to_backend(n->nic, -1); } +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)) { + if (get_vhost_net(qemu_get_queue(n->nic)->peer)) { + warn_report("Can't use eBPF RSS for vhost"); + } else { + warn_report("Can't use eBPF RSS - fallback to software RSS"); + n->rss_data.enabled_software_rss = true; + } + } + + trace_virtio_net_rss_enable(n->rss_data.hash_types, + n->rss_data.indirections_len, + sizeof(n->rss_data.key)); + } else { + virtio_net_detach_epbf_rss(n); + trace_virtio_net_rss_disable(); + } +} + +static void virtio_net_disable_rss(VirtIONet *n) +{ + if (!n->rss_data.enabled) { + return; + } + + n->rss_data.enabled = false; + virtio_net_commit_rss_config(n); +} + static bool virtio_net_load_ebpf(VirtIONet *n) { if (!virtio_net_attach_ebpf_to_backend(n->nic, -1)) { @@ -1399,28 +1421,7 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, goto error; } n->rss_data.enabled = true; - - if (!n->rss_data.populate_hash) { - if (!virtio_net_attach_epbf_rss(n)) { - /* EBPF must be loaded for vhost */ - if (get_vhost_net(qemu_get_queue(n->nic)->peer)) { - warn_report("Can't load eBPF RSS for vhost"); - goto error; - } - /* fallback to software RSS */ - warn_report("Can't load eBPF RSS - fallback to software RSS"); - n->rss_data.enabled_software_rss = true; - } - } else { - /* use software RSS for hash populating */ - /* and detach eBPF if was loaded before */ - virtio_net_detach_epbf_rss(n); - n->rss_data.enabled_software_rss = true; - } - - trace_virtio_net_rss_enable(n->rss_data.hash_types, - n->rss_data.indirections_len, - temp.b); + virtio_net_commit_rss_config(n); return queue_pairs; error: trace_virtio_net_rss_error(err_msg, err_value); @@ -3016,26 +3017,7 @@ static int virtio_net_post_load_device(void *opaque, int version_id) } } - if (n->rss_data.enabled) { - n->rss_data.enabled_software_rss = n->rss_data.populate_hash; - if (!n->rss_data.populate_hash) { - if (!virtio_net_attach_epbf_rss(n)) { - if (get_vhost_net(qemu_get_queue(n->nic)->peer)) { - warn_report("Can't post-load eBPF RSS for vhost"); - } else { - warn_report("Can't post-load eBPF RSS - " - "fallback to software RSS"); - n->rss_data.enabled_software_rss = true; - } - } - } - - trace_virtio_net_rss_enable(n->rss_data.hash_types, - n->rss_data.indirections_len, - sizeof(n->rss_data.key)); - } else { - trace_virtio_net_rss_disable(); - } + virtio_net_commit_rss_config(n); return 0; } From patchwork Wed Oct 11 15:39:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1846837 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=IDhtW7Fp; 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 4S5H7c2WcWz23jj for ; Thu, 12 Oct 2023 02:41:48 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqbKT-0003Ol-GC; Wed, 11 Oct 2023 11:40:57 -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 1qqbK2-0002h2-Vu for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:31 -0400 Received: from mail-oo1-xc29.google.com ([2607:f8b0:4864:20::c29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qqbJz-0002Bh-OU for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:30 -0400 Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-57b5f0d658dso4046873eaf.0 for ; Wed, 11 Oct 2023 08:40:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1697038826; x=1697643626; 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=0jYFppD2q/B6HW33loL41D2UDU5z3AZeu5hXH0ps2N0=; b=IDhtW7FpRFixdbDGaxE94SgVU4JBtcr/di11uWic5e9RSz9thAUHNtfwap4Ut7INpy t3s7qpJ71aM39pd5KXIWwPpkklJsArI1KYfqDO85uYo7XCAKlhgxZqfCuNC3TyrT8Mpn rrL0ACMIzVe3Ty7MmeryPMz9bRxGuBx9FJb2efLdqF/aafNmwGdU9fQ/WBv1QQfubj3h 278u7TA8pJ01PvPyP+7rIkQfn5Ht4LMCIT7pxAzezhFij58A+PuCYNI+qU1FRjaJhzX4 4H2BhrLfbMNPVSFYIMiklL4fXKbivsHDxYsgCP8VRIbdDvGzWoAUDqlHwwYZ15kLNmca PTeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697038826; x=1697643626; 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=0jYFppD2q/B6HW33loL41D2UDU5z3AZeu5hXH0ps2N0=; b=umiUTXks/H7kSDl1mxivv+vlYKqNcvRcytnWPXF/4H6hXXBAv0R8/kyUClGvwlCYDr 2CsCXkEZ67UPKJmLfC3DX3SyE0Gb6rnUaPRWy2kzYZNrJXh6EHJoVTqf/drZKrtvKAZs 45QGeSm3lwE9vvfbKbsCWNHPgYCfZUwpYyhhHCkjI0S5NH4Cw1uHQHE6kgmCRbSZkYvv wtfvSJQW1jNpiQJMPK5SXq4MDhCn1kCvid8YlimkSepNx/ZUwJo6tQjATIkKIvrQtYeM /Jz+J6cIM+Efx+6hVMFOHGkMVVVhU+BjmyDSBwcyLzT/d65DCl5vqEbNB1WeMpruleWm tMlA== X-Gm-Message-State: AOJu0Yx1wKDEzdqeuEmA4f8rVVr72oXccxVkXdPA1S70VZ8TovbyA7zX b9SqfJLAnY4wY5lgWb5uHjGEwKJRHG2LJqvljL43+Q== X-Google-Smtp-Source: AGHT+IEDLj+c4K4xEoJZsksYDaMZCRaC4TMvGx4W4/vbAnPneQvfswT+kdwSrNp0YA18hDdJMV1/mA== X-Received: by 2002:a05:6358:7e49:b0:142:d0dc:a3ce with SMTP id p9-20020a0563587e4900b00142d0dca3cemr23301804rwm.2.1697038826383; Wed, 11 Oct 2023 08:40:26 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id h19-20020aa786d3000000b0068ff267f092sm10160741pfo.216.2023.10.11.08.40.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Oct 2023 08:40:26 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , Akihiko Odaki Subject: [PATCH v3 09/11] virtio-net: Return an error when vhost cannot enable RSS Date: Thu, 12 Oct 2023 00:39:40 +0900 Message-ID: <20231011153944.39572-10-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011153944.39572-1-akihiko.odaki@daynix.com> References: <20231011153944.39572-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::c29; envelope-from=akihiko.odaki@daynix.com; helo=mail-oo1-xc29.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 vhost requires eBPF for RSS. Even when eBPF is not available, virtio-net reported RSS availability, and raised a warning only after the guest requested RSS, and the guest could not know that RSS is not available. Check RSS availability during device realization and return an error if RSS is requested but not available. Assert RSS availability when the guest actually requests the feature. Signed-off-by: Akihiko Odaki --- ebpf/ebpf_rss.h | 2 +- ebpf/ebpf_rss-stub.c | 4 +- ebpf/ebpf_rss.c | 68 +++++++++----------------- hw/net/virtio-net.c | 114 +++++++++++++++++++++---------------------- 4 files changed, 82 insertions(+), 106 deletions(-) diff --git a/ebpf/ebpf_rss.h b/ebpf/ebpf_rss.h index bf3f2572c7..1128173572 100644 --- a/ebpf/ebpf_rss.h +++ b/ebpf/ebpf_rss.h @@ -36,7 +36,7 @@ bool ebpf_rss_is_loaded(struct EBPFRSSContext *ctx); bool ebpf_rss_load(struct EBPFRSSContext *ctx); -bool ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *config, +void ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *config, uint16_t *indirections_table, uint8_t *toeplitz_key); void ebpf_rss_unload(struct EBPFRSSContext *ctx); diff --git a/ebpf/ebpf_rss-stub.c b/ebpf/ebpf_rss-stub.c index e71e229190..525b358597 100644 --- a/ebpf/ebpf_rss-stub.c +++ b/ebpf/ebpf_rss-stub.c @@ -28,10 +28,10 @@ bool ebpf_rss_load(struct EBPFRSSContext *ctx) return false; } -bool ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *config, +void ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *config, uint16_t *indirections_table, uint8_t *toeplitz_key) { - return false; + g_assert_not_reached(); } void ebpf_rss_unload(struct EBPFRSSContext *ctx) diff --git a/ebpf/ebpf_rss.c b/ebpf/ebpf_rss.c index cee658c158..6cdf82d059 100644 --- a/ebpf/ebpf_rss.c +++ b/ebpf/ebpf_rss.c @@ -74,42 +74,32 @@ error: return false; } -static bool ebpf_rss_set_config(struct EBPFRSSContext *ctx, +static void ebpf_rss_set_config(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *config) { uint32_t map_key = 0; - if (!ebpf_rss_is_loaded(ctx)) { - return false; - } - if (bpf_map_update_elem(ctx->map_configuration, - &map_key, config, 0) < 0) { - return false; - } - return true; + assert(ebpf_rss_is_loaded(ctx)); + assert(!bpf_map_update_elem(ctx->map_configuration, &map_key, config, 0)); } -static bool ebpf_rss_set_indirections_table(struct EBPFRSSContext *ctx, +static void ebpf_rss_set_indirections_table(struct EBPFRSSContext *ctx, uint16_t *indirections_table, size_t len) { uint32_t i = 0; - if (!ebpf_rss_is_loaded(ctx) || indirections_table == NULL || - len > VIRTIO_NET_RSS_MAX_TABLE_LEN) { - return false; - } + assert(ebpf_rss_is_loaded(ctx)); + assert(indirections_table); + assert(len <= VIRTIO_NET_RSS_MAX_TABLE_LEN); for (; i < len; ++i) { - if (bpf_map_update_elem(ctx->map_indirections_table, &i, - indirections_table + i, 0) < 0) { - return false; - } + assert(!bpf_map_update_elem(ctx->map_indirections_table, &i, + indirections_table + i, 0)); } - return true; } -static bool ebpf_rss_set_toepliz_key(struct EBPFRSSContext *ctx, +static void ebpf_rss_set_toepliz_key(struct EBPFRSSContext *ctx, uint8_t *toeplitz_key) { uint32_t map_key = 0; @@ -117,41 +107,29 @@ static bool ebpf_rss_set_toepliz_key(struct EBPFRSSContext *ctx, /* prepare toeplitz key */ uint8_t toe[VIRTIO_NET_RSS_MAX_KEY_SIZE] = {}; - if (!ebpf_rss_is_loaded(ctx) || toeplitz_key == NULL) { - return false; - } + assert(ebpf_rss_is_loaded(ctx)); + assert(toeplitz_key); + memcpy(toe, toeplitz_key, VIRTIO_NET_RSS_MAX_KEY_SIZE); *(uint32_t *)toe = ntohl(*(uint32_t *)toe); - if (bpf_map_update_elem(ctx->map_toeplitz_key, &map_key, toe, - 0) < 0) { - return false; - } - return true; + assert(!bpf_map_update_elem(ctx->map_toeplitz_key, &map_key, toe, 0)); } -bool ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *config, +void ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *config, uint16_t *indirections_table, uint8_t *toeplitz_key) { - if (!ebpf_rss_is_loaded(ctx) || config == NULL || - indirections_table == NULL || toeplitz_key == NULL) { - return false; - } - - if (!ebpf_rss_set_config(ctx, config)) { - return false; - } + assert(ebpf_rss_is_loaded(ctx)); + assert(config); + assert(indirections_table); + assert(toeplitz_key); - if (!ebpf_rss_set_indirections_table(ctx, indirections_table, - config->indirections_len)) { - return false; - } + ebpf_rss_set_config(ctx, config); - if (!ebpf_rss_set_toepliz_key(ctx, toeplitz_key)) { - return false; - } + ebpf_rss_set_indirections_table(ctx, indirections_table, + config->indirections_len); - return true; + ebpf_rss_set_toepliz_key(ctx, toeplitz_key); } void ebpf_rss_unload(struct EBPFRSSContext *ctx) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 25fc06bd93..20feb20bb1 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1242,14 +1242,10 @@ static bool virtio_net_attach_epbf_rss(VirtIONet *n) rss_data_to_rss_config(&n->rss_data, &config); - if (!ebpf_rss_set_all(&n->ebpf_rss, &config, - n->rss_data.indirections_table, n->rss_data.key)) { - return false; - } + ebpf_rss_set_all(&n->ebpf_rss, &config, + n->rss_data.indirections_table, n->rss_data.key); - if (!virtio_net_attach_ebpf_to_backend(n->nic, n->ebpf_rss.program_fd)) { - return false; - } + assert(virtio_net_attach_ebpf_to_backend(n->nic, n->ebpf_rss.program_fd)); return true; } @@ -1266,12 +1262,7 @@ static void virtio_net_commit_rss_config(VirtIONet *n) if (n->rss_data.populate_hash) { virtio_net_detach_epbf_rss(n); } else if (!virtio_net_attach_epbf_rss(n)) { - if (get_vhost_net(qemu_get_queue(n->nic)->peer)) { - warn_report("Can't use eBPF RSS for vhost"); - } else { - warn_report("Can't use eBPF RSS - fallback to software RSS"); - n->rss_data.enabled_software_rss = true; - } + n->rss_data.enabled_software_rss = true; } trace_virtio_net_rss_enable(n->rss_data.hash_types, @@ -3514,6 +3505,50 @@ static bool failover_hide_primary_device(DeviceListener *listener, return qatomic_read(&n->failover_primary_hidden); } +static void virtio_net_device_unrealize(DeviceState *dev) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VirtIONet *n = VIRTIO_NET(dev); + int i, max_queue_pairs; + + if (virtio_has_feature(n->host_features, VIRTIO_NET_F_RSS)) { + virtio_net_unload_ebpf(n); + } + + /* This will stop vhost backend if appropriate. */ + virtio_net_set_status(vdev, 0); + + g_free(n->netclient_name); + n->netclient_name = NULL; + g_free(n->netclient_type); + n->netclient_type = NULL; + + g_free(n->mac_table.macs); + g_free(n->vlans); + + if (n->failover) { + qobject_unref(n->primary_opts); + device_listener_unregister(&n->primary_listener); + remove_migration_state_change_notifier(&n->migration_state); + } else { + assert(n->primary_opts == NULL); + } + + max_queue_pairs = n->multiqueue ? n->max_queue_pairs : 1; + for (i = 0; i < max_queue_pairs; i++) { + virtio_net_del_queue(n, i); + } + /* delete also control vq */ + virtio_del_queue(vdev, max_queue_pairs * 2); + qemu_announce_timer_del(&n->announce_timer, false); + g_free(n->vqs); + qemu_del_nic(n->nic); + virtio_net_rsc_cleanup(n); + g_free(n->rss_data.indirections_table); + net_rx_pkt_uninit(n->rx_pkt); + virtio_cleanup(vdev); +} + static void virtio_net_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev); @@ -3685,53 +3720,16 @@ 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); - } -} - -static void virtio_net_device_unrealize(DeviceState *dev) -{ - VirtIODevice *vdev = VIRTIO_DEVICE(dev); - VirtIONet *n = VIRTIO_NET(dev); - int i, max_queue_pairs; - - if (virtio_has_feature(n->host_features, VIRTIO_NET_F_RSS)) { - virtio_net_unload_ebpf(n); - } - - /* This will stop vhost backend if appropriate. */ - virtio_net_set_status(vdev, 0); - - g_free(n->netclient_name); - n->netclient_name = NULL; - g_free(n->netclient_type); - n->netclient_type = NULL; - - g_free(n->mac_table.macs); - g_free(n->vlans); - - if (n->failover) { - qobject_unref(n->primary_opts); - device_listener_unregister(&n->primary_listener); - remove_migration_state_change_notifier(&n->migration_state); - } else { - assert(n->primary_opts == NULL); - } + 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; + } - max_queue_pairs = n->multiqueue ? n->max_queue_pairs : 1; - for (i = 0; i < max_queue_pairs; i++) { - virtio_net_del_queue(n, i); + warn_report_once("Can't load eBPF RSS - fallback to software RSS"); } - /* delete also control vq */ - virtio_del_queue(vdev, max_queue_pairs * 2); - qemu_announce_timer_del(&n->announce_timer, false); - g_free(n->vqs); - qemu_del_nic(n->nic); - virtio_net_rsc_cleanup(n); - g_free(n->rss_data.indirections_table); - net_rx_pkt_uninit(n->rx_pkt); - virtio_cleanup(vdev); } static void virtio_net_reset(VirtIODevice *vdev) From patchwork Wed Oct 11 15:39:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1846839 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=xK39CVGf; 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 4S5H990MbWz23jd for ; Thu, 12 Oct 2023 02:43:09 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqbKE-000308-Qw; Wed, 11 Oct 2023 11:40: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 1qqbK5-0002pc-LS for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:35 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qqbK3-0002CJ-Af for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:32 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1c9c5a1b87bso12169665ad.3 for ; Wed, 11 Oct 2023 08:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1697038829; x=1697643629; 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=NbSUUiUjCogeY0CY+1W2SS+7g039FG1VSh7/UySB0M0=; b=xK39CVGf82Gky3j9fSQhz4bqgcBxC5nMWjtqXy3YkVxj5vj/WVBDEZw6k1RO7CUtHX KsPHOaB1kUWeO3XqBI/2YcE6jtjNXNY2ayXPbLBjUZsB0tvdTJ7RwpcuUWHobUi1GBi6 zfDsv+uUKySkJXMQM/jDJxozkacEjt5ZO4/8TbCPSicsfMOKGM+ZHXGcELh5i6F0Eny/ +rCG//gMcg3zH225RNAPRjbN+y2l5PueHabiMIQsg6C0WPKzT0ioq25p3xHTyp5RomE/ Z1nWuQCtnwg+aAyRb3p7wTyg4XRrF7U9mPhSD0xJ2Dk5KOBaUBzPZUVfFwSQIm/B4hed FfTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697038829; x=1697643629; 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=NbSUUiUjCogeY0CY+1W2SS+7g039FG1VSh7/UySB0M0=; b=fPf4t6PhiYgKNAm0D04knt2WqOGTx2CoT+u7fm4WpHVGrNMCdldKKE6IzcwdcFqBAr s43kPdUO0M3sn0b3T4aYIqto557PXrwKkNveWIdSnCsCq2gzPR90Shq75oxw+qU9x4Xs xu50VNSb8ulOqYO/yYb1bJ2b2r+m2vRgQZLlpVfBnL5CUjJsx6fYRDrKe0hWdBsl0oR+ YXry3hWnCgM6FAlH5yTv9OKMqm9Krr9NTKHt6/vRHoEPNOywSl43sEk9+wbR4qryqYyg 1k1g+BSIYJj3KFzQ49BHwyx95BNP02exOGsjVurflCdbtg4oz5uL73IhIYSUUrbzl94j S6pg== X-Gm-Message-State: AOJu0YwHNFaMumf+GiF8wt86lCqgWEHiUSp2gIs7rvX1keTEClsA0UiF N7iblmiRcbRZj8PMrEdzo8YRabFh8FzeNafajxoNag== X-Google-Smtp-Source: AGHT+IEDF16AKIKJLWfp3d78E1bCTrVHRP7Jza9m7hQ4usT7vGwY7rw+SlG/m7Mgn4zye00951BtfA== X-Received: by 2002:a17:902:f54c:b0:1c7:2476:c977 with SMTP id h12-20020a170902f54c00b001c72476c977mr22713012plf.33.1697038829590; Wed, 11 Oct 2023 08:40:29 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id x20-20020a170902ea9400b001c5076ae6absm13983748plb.126.2023.10.11.08.40.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Oct 2023 08:40:29 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , Akihiko Odaki Subject: [PATCH v3 10/11] virtio-net: Do not clear VIRTIO_NET_F_RSS Date: Thu, 12 Oct 2023 00:39:41 +0900 Message-ID: <20231011153944.39572-11-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011153944.39572-1-akihiko.odaki@daynix.com> References: <20231011153944.39572-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::631; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x631.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Even if eBPF is not available, virtio-net can perform RSS on the user-space if vhost is disabled although such a configuration results in a warning. If vhost is enabled, the configuration will be rejected when realizing the device. Therefore, VIRTIO_NET_F_RSS should not be cleared even if eBPF is not loaded. Signed-off-by: Akihiko Odaki --- hw/net/virtio-net.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 20feb20bb1..31a32bdff9 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -775,9 +775,6 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features, 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; From patchwork Wed Oct 11 15:39:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1846836 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=o1BFGaFm; 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 4S5H7c5Qmbz26jS for ; Thu, 12 Oct 2023 02:41:48 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqbKa-0003e4-7Q; Wed, 11 Oct 2023 11:41: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 1qqbK8-0002s5-3e for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:37 -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 1qqbK6-0002Cp-Kr for qemu-devel@nongnu.org; Wed, 11 Oct 2023 11:40:35 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1c5ff5f858dso49424905ad.2 for ; Wed, 11 Oct 2023 08:40:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1697038833; x=1697643633; 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=4suv/BvTtFCyaarl96M7QPK/UCb253pLYJ0sJd7urgg=; b=o1BFGaFmEK/G5Zt0p2/ubx+LAAOhcDxyLBdlbDXLXntMbmNk6Q5N/o+Gb2sNh5clsK 1lxh+jb0l0iRwtqrsVxyIQN7GeUabRmokvVx1VRNatNBMfgxpbTaMavDdGpA67WJjOyw 8rhCRA1Gosf3dHWq8uqadBcL3Cjn6Dt7auAo0qDtJpQwzJoHkFYTH9bVevJSz0qEZZab 1D5Nzkufnix5eKBskNdTZc3rZCCFYNIA6mFV2bTuRVEffeQL1ZHLJyd7Lr16s57l4hQP /f3wnKtYNriGr5mj+n5BRBQIxD4szpAqrppA90GldCnlUa2LzmDDZWlvQ5mW3h95WWgw UX7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697038833; x=1697643633; 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=4suv/BvTtFCyaarl96M7QPK/UCb253pLYJ0sJd7urgg=; b=Lj02lktz+kT4ViBDaKzTRGTPteYLwMN6yMa+C55VC/wvo5970TpFc5G+6ADcHsOXNp OLFVbdz4kenMBJPqPmp9TuhAgr1VNdwAK2Gvwlsob4WYev5/Hh47DWr7qt85h71/2ZRt 5MhV5MdxEAXmzaiV6QrW51Bno9B5TpXL26Kxnu/puqO88OZeG+Ahp7aMy1/0lJKyNaf6 buE7LZF1mnIQwGo7/UTkXNvXz4HK93dehJfEFIqeesjI/D5UPW45+g8VdjZAAbaoTLuO WHfgO8RywUlzJ/U1P2T5Uxle5/9JGrau9wiplH2QsZFdus4FnhPVZredQIZZN3SW74NV GTgA== X-Gm-Message-State: AOJu0YyjtHLR461D4Ex9gvtRgp8QE02H0n0H/iSyRXkNm5lKaoImd1dW bKjTvUoXtcdaoXjyha5cHivhVCx0QL7mFAJjZNTvaw== X-Google-Smtp-Source: AGHT+IFFhRztHtozF2SynWFwmx/PiFYCETGkGfFvjInkFh9GkrnWwwPYKpYjoa9JYSqOm9sg2ZjD6Q== X-Received: by 2002:a17:903:230b:b0:1c7:3558:721a with SMTP id d11-20020a170903230b00b001c73558721amr25911677plh.58.1697038832867; Wed, 11 Oct 2023 08:40:32 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id 13-20020a170902c10d00b001bc68602e54sm14127309pli.142.2023.10.11.08.40.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 Oct 2023 08:40:32 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , Akihiko Odaki Subject: [PATCH v3 11/11] ebpf: Fix RSS error handling Date: Thu, 12 Oct 2023 00:39:42 +0900 Message-ID: <20231011153944.39572-12-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231011153944.39572-1-akihiko.odaki@daynix.com> References: <20231011153944.39572-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none 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_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 calculate_rss_hash() was using hash value 0 to tell if it calculated a hash, but the hash value may be 0 on a rare occasion. Have a distinct bool value for correctness. Fixes: f3fa412de2 ("ebpf: Added eBPF RSS program.") Signed-off-by: Akihiko Odaki --- tools/ebpf/rss.bpf.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tools/ebpf/rss.bpf.c b/tools/ebpf/rss.bpf.c index 20f227e2ac..667ea6899e 100644 --- a/tools/ebpf/rss.bpf.c +++ b/tools/ebpf/rss.bpf.c @@ -377,18 +377,19 @@ error: return err; } -static inline __u32 calculate_rss_hash(struct __sk_buff *skb, - struct rss_config_t *config, struct toeplitz_key_data_t *toe) +static inline bool calculate_rss_hash(struct __sk_buff *skb, + struct rss_config_t *config, + struct toeplitz_key_data_t *toe, + __u32 *result) { __u8 rss_input[HASH_CALCULATION_BUFFER_SIZE] = {}; size_t bytes_written = 0; - __u32 result = 0; int err = 0; struct packet_hash_info_t packet_info = {}; err = parse_packet(skb, &packet_info); if (err) { - return 0; + return false; } if (packet_info.is_ipv4) { @@ -521,11 +522,13 @@ static inline __u32 calculate_rss_hash(struct __sk_buff *skb, } } - if (bytes_written) { - net_toeplitz_add(&result, rss_input, bytes_written, toe); + if (!bytes_written) { + return false; } - return result; + net_toeplitz_add(result, rss_input, bytes_written, toe); + + return true; } SEC("tun_rss_steering") @@ -546,8 +549,7 @@ int tun_rss_steering_prog(struct __sk_buff *skb) return config->default_queue; } - hash = calculate_rss_hash(skb, config, toe); - if (hash) { + if (calculate_rss_hash(skb, config, toe, &hash)) { __u32 table_idx = hash % config->indirections_len; __u16 *queue = 0;