From patchwork Sun Oct 8 05:29:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1844855 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=JxCbcNDe; 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 4S39kj6pLBz1yqD for ; Sun, 8 Oct 2023 16:31:25 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpMMs-0004Fc-EY; Sun, 08 Oct 2023 01:30:18 -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 1qpMMR-00045f-KH for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:29:52 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qpMMC-00074b-At for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:29:49 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1c77449a6daso30249115ad.0 for ; Sat, 07 Oct 2023 22:29:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696742974; x=1697347774; 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=2/drKQsw3H/n//rOXbeBtEedeUYZ8/NjLqaNPEt5EN8=; b=JxCbcNDehM3OMMOuJLrwVWgqJqCS5mGDiXX140iGa7JSuMsaEq6DHV1SRrxM5d+r+D xLRvoJxRbNGy2HB1r7fr9TZATlIDztYwIoWoxzlh/yjWLtz+4pjKw79dHooDYT8n7dXK uFTZePqD1n9SuntmNHDS2q0SP1FaNKP0PrnCvgRHMEh2YeOi/GDk3Msfks//6LNbvx3e tHe0Zf4I+KXtFMFZojIvQhJKcAV7XUAUeFU/ZVPCtwBaWvHbTiEoBNkrqQj0c+4DIFmM 6YmRjo2eH0PuILhAad29s59qES4+nOCVAxTcUps/FPqrV97keOxSvlLCTtp7xsLe1EJl Cqjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696742974; x=1697347774; 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=2/drKQsw3H/n//rOXbeBtEedeUYZ8/NjLqaNPEt5EN8=; b=Z0G8cjvv5jp1LhmPjnnQ+jkf504igYqY34s0MctycNT/Eu8Jl/wAM+fdmrc5Hq3T1Z yneuZPGib6vkYA9Hs/wzjdPUdtew2/yY/66S5jAkKX2Qy0YKM0U+xrcp25eguhIsaWRr ss0pq9M3iThC6qq2h2cm/+QQOH/qjqS7Lxm5pU5Y889zTwqOM2otmEDloBz555H/vJ2J NnHFKqTKOKRW6Rj3sEb3xkEBXcwNMRnf6hGpEMkNNifbdgxW4GTyQJ4Z4Fgci1wmp9wJ H73wwZvMayIMp3qye8UbYsqvH8PS7JHn12xho43lWGXSc/et8z3m7W7mGtIr6FE49k3H GCMg== X-Gm-Message-State: AOJu0YyBJWl9x2oPKeZzlxqK86ZiP2ZTZFN+6reahww2nHDzZGHQLq6F szFkfg7BelpqBTk1WPzCGHE+V+E1HOBKEkpo00b2nA== X-Google-Smtp-Source: AGHT+IEQxdetCTUBD1OJuZnJ72hzCK3+yX+anzmZsNun0PZBLFZtRl9woAb4WtId43dE2PEIyE7viA== X-Received: by 2002:a17:902:eb4c:b0:1bd:bbc3:c87b with SMTP id i12-20020a170902eb4c00b001bdbbc3c87bmr11225303pli.41.1696742974688; Sat, 07 Oct 2023 22:29:34 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id p17-20020a170902ead100b001c7373769basm6889383pld.88.2023.10.07.22.29.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 07 Oct 2023 22:29:34 -0700 (PDT) From: Akihiko Odaki To: Cc: Akihiko Odaki , Jason Wang , qemu-devel@nongnu.org (open list:All patches CC here) Subject: [PATCH 1/6] tap: Fix virtio-net header buffer size Date: Sun, 8 Oct 2023 14:29:10 +0900 Message-ID: <20231008052917.145245-2-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231008052917.145245-1-akihiko.odaki@daynix.com> References: <20231008052917.145245-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::633; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x633.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, 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 largest possible virtio-net header is struct virtio_net_hdr_v1_hash. Fixes: fbbdbddec0 ("tap: allow extended virtio header with hash info") Signed-off-by: Akihiko Odaki --- net/tap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/tap.c b/net/tap.c index c6639d9f20..ea46feeaa8 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_v1_hash hdr = { }; if (s->host_vnet_hdr_len && !s->using_vnet_hdr) { iov_copy[0].iov_base = &hdr; @@ -136,7 +136,7 @@ static ssize_t tap_receive_raw(NetClientState *nc, const uint8_t *buf, size_t si TAPState *s = DO_UPCAST(TAPState, nc, nc); struct iovec iov[2]; int iovcnt = 0; - struct virtio_net_hdr_mrg_rxbuf hdr = { }; + struct virtio_net_hdr_v1_hash hdr = { }; if (s->host_vnet_hdr_len) { iov[iovcnt].iov_base = &hdr; From patchwork Sun Oct 8 05:29:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1844850 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=AV194/uw; 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 4S39jJ59svz1yqD for ; Sun, 8 Oct 2023 16:30:12 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpMMQ-00044x-BX; Sun, 08 Oct 2023 01:29:52 -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 1qpMMG-000445-3H for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:29:40 -0400 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qpMME-00075G-LJ for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:29:39 -0400 Received: by mail-il1-x12d.google.com with SMTP id e9e14a558f8ab-352308c0799so14096845ab.2 for ; Sat, 07 Oct 2023 22:29:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696742977; x=1697347777; 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=jkAG/GLZoDDPnb66RkDvFFcKEopH6dS+RNqnDn3VPwM=; b=AV194/uwDW0IWU02ht9oApza0IYnRLHtjuhEZi0HdimFk6ZG/X5fJHcKQtVCCEafIF kooNbNdizrZ/uVD/D1wgjDy1p7wJv+O8unZR+IWCRLSFv0qXI+EV3ho6ajzD11h2IO65 9abrvJndECqHdt895sp2k/PP90FZYjGz6w+6PL4p1AohatpP9djKqzsojZ0A/WFxymDV OWnNA7BRzc/5bfyFK74pO01TQmVRgNJqR8tBRw/+AiP/V2kwLayHp6vElTglXLcjUfaR qojiM6ubo8AreqiakbmMZhwvYkRKcmvU94IhwSciCNLFKhYm+LP15QPLgB3vLSfSgOhQ SyAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696742977; x=1697347777; 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=jkAG/GLZoDDPnb66RkDvFFcKEopH6dS+RNqnDn3VPwM=; b=gvdSHlqvSnw3ONpPfCpw8Lz2n6FEf4VF/MMPUXet52LGKlZGxcdv4Pto0ZZZI0+e7/ rGuKgQNEzMYnuFkZafp8/0p+TUFMqIyf73NzB7hqslD+PVJ7AKz8rLUfb81tIbMPbAFh lll+E/G82Z2gMhYZd2dA9sb73IgJIcivGUzBs5LESGTBd3sI0dRwOLnQ3f1dWMXHj3Ag IZVozHvoDfVSxCuxRltuDZW0JAaXVqwE5MX/iRsPP8V28yb/R2KG4VRluCr/XlZYhxIY RS/ZT3alO9MGypk/tkSqk1qH/n3tbw+Fpv5OAKahBi6vHZdlNV1kvYn0ihqVDrGFydGr usWA== X-Gm-Message-State: AOJu0YzeuG7WDmPKtRb5RlBzloQxVzC2khLuzZ7qED06ItkBfcXFIo2a u8f68FzrQDYyyAkkAJcK5gCWdQ== X-Google-Smtp-Source: AGHT+IGJzeHi33A8j3ljCqADFs65vAMtzFp4XP82t3pOBzrqzg3cEEyj+6kb7iBAecDD8EgAfWZ+ig== X-Received: by 2002:a05:6e02:1a0a:b0:34f:fe3c:fd8 with SMTP id s10-20020a056e021a0a00b0034ffe3c0fd8mr16389967ild.15.1696742977677; Sat, 07 Oct 2023 22:29:37 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id c12-20020aa78e0c000000b006933866fd21sm3984617pfr.117.2023.10.07.22.29.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 07 Oct 2023 22:29:37 -0700 (PDT) From: Akihiko Odaki To: Cc: Akihiko Odaki , "Michael S. Tsirkin" , Jason Wang , qemu-devel@nongnu.org (open list:All patches CC here) Subject: [PATCH 2/6] virtio-net: Copy header only when necessary Date: Sun, 8 Oct 2023 14:29:11 +0900 Message-ID: <20231008052917.145245-3-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231008052917.145245-1-akihiko.odaki@daynix.com> References: <20231008052917.145245-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::12d; envelope-from=akihiko.odaki@daynix.com; helo=mail-il1-x12d.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 9a93a2df01..1ba748c964 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 Sun Oct 8 05:29:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1844851 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=ZM/YScjl; 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 4S39jT4CJKz1yqD for ; Sun, 8 Oct 2023 16:30:21 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpMMi-0004AD-Qu; Sun, 08 Oct 2023 01:30:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qpMMR-00045e-Jl for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:29:52 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qpMMI-000762-9B for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:29:48 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-690b7cb71aeso2602259b3a.0 for ; Sat, 07 Oct 2023 22:29:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696742980; x=1697347780; 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=4rLJUvKzJ/knH6vUIH+0Ji9GBhazQKzSi6QIe6BIJBk=; b=ZM/YScjleyvOdIgzY9/rYmRpzHhVatQ8UKpyS127e3Uh+tiNqcX86PggawsdhOgmUZ sEYKQ5IBYMg0RDRSbJgJX29eY2/euL8TWXp2ndITJU4RCB0uv6qxeWNM/+FtAmO45LmL DR/4A3IrS9rCkFD94bvGB9APMhVa9uVZGnxcpBsRWHZVP7KWlOOgwuXCNCkjBne4qsiQ 4PWD4W4jfPnu9+OgRgpK/MEOon1pjyhwcS4rwd1YK9XLjsa/P9GpHUQhpTkMy3dshRVm cXEww819I6CsniMtA2JslyVRld7gboxuNbggz6yC4CPuVVeS7X5OCoeWZokj6WOknim8 wYKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696742980; x=1697347780; 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=4rLJUvKzJ/knH6vUIH+0Ji9GBhazQKzSi6QIe6BIJBk=; b=Fik8X2hoNJkNmOBNdWVk8vzSqxXDEueyP7TDyTt6aQpUmtQ9zdx0A40vpnZMzE0dtQ PkJzxe1JfjB0GD5JTIoPzr606u/lyVlvUScrZ3X8xct3/hM+nYe0leXNUxqAPKkeb8sB nQipp7QDW4Zxg6weEzVaN/aEwVkT2jPYK9TKh/qfuFvXk7r2qdQvZXonOOjhZnOOFuFC VUKIGi52zE30YrpkPHnKxMoxjRQPuAgfBABJrcjmk+icGRBh1UB7gOm55Mq8ZjDjMqdX M2kcG0q7hvGgMe3djiJDYTisGku3UlFidR1K9DOzAFS7OgY4s4c27+MgTk+ZTjcPad4w icEg== X-Gm-Message-State: AOJu0YzpGB31NFUJpUHkc4b50QclGkCgKsxg2pqoX23n81rt8u22e544 7iu80bAJjE5HHes+7+6S4lKTb/+4CkicYZKSIjRsww== X-Google-Smtp-Source: AGHT+IFAV7Cam6xAhrO4/67oGzA7t8ZxlMAdkF51bUt6ub+T9YUOUF3WgqsUU8kIUyiz82VkioxDzA== X-Received: by 2002:a05:6a20:7f8f:b0:158:143d:e215 with SMTP id d15-20020a056a207f8f00b00158143de215mr14793633pzj.1.1696742980676; Sat, 07 Oct 2023 22:29:40 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id n9-20020aa79049000000b0068fe7c4148fsm3943646pfo.57.2023.10.07.22.29.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 07 Oct 2023 22:29:40 -0700 (PDT) From: Akihiko Odaki To: Cc: Akihiko Odaki , "Michael S. Tsirkin" , Jason Wang , qemu-devel@nongnu.org (open list:All patches CC here) Subject: [PATCH 3/6] virtio-net: Disable RSS on reset Date: Sun, 8 Oct 2023 14:29:12 +0900 Message-ID: <20231008052917.145245-4-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231008052917.145245-1-akihiko.odaki@daynix.com> References: <20231008052917.145245-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::436; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x436.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 1ba748c964..83bac9a98a 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); @@ -3789,6 +3755,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 Sun Oct 8 05:29:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1844853 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=fCy8X0GK; 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 4S39k81rFsz1yqD for ; Sun, 8 Oct 2023 16:30:56 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpMNM-0004eO-Bj; Sun, 08 Oct 2023 01:30:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qpMMd-00049A-01 for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:30:04 -0400 Received: from mail-oa1-x2a.google.com ([2001:4860:4864:20::2a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qpMMO-00076e-D0 for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:30:02 -0400 Received: by mail-oa1-x2a.google.com with SMTP id 586e51a60fabf-1e5602c12e5so2068532fac.3 for ; Sat, 07 Oct 2023 22:29:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696742984; x=1697347784; 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=r9XCCtGoA5l5bdW6uetTj/eGIjTzGN0RtdgyGLy36eM=; b=fCy8X0GKd9iLwB14pp3PVcAjkYy7FzhSZlNgzY9Ug61fuB3R2Di61GIn90kDyqk6jN 3RDBzD5jpAnvJS2D0sYWkhs59DlJrqLEEpONJQdbjwlwZH8yo2KYoekneC9uEtSP2/Ab fQRo8p194T6ETJrNAVGitSwl2WGKnuniWvcsyuxGamOuj7VoQbSxYF3pPR0h7nM5bmcJ fIR/ZOuGJCJJsUj72xcsr+gbzilD9EYaFCDVTTNGDVogxxHkw+ZcuEjIyRs0R1dqMsjX ZgsPwFgKjfmLpsYuLWwswfHTxBEqjo8VwQvBl5ByqGS1uYwqSHiVYp6P8Y/HtZofVX9p Rv6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696742984; x=1697347784; 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=r9XCCtGoA5l5bdW6uetTj/eGIjTzGN0RtdgyGLy36eM=; b=neRz+4X6JMtH3cdK1zrH94aGzTGXpSsa6M+6caW2iHVvHVogM4qeDZzuBDdGz6nCrf Ye858zaGHSFRcsGRJ4RFxwX0tQPeE6rBYjO3uGO6h51In5ur1Q9Y2pgtqs35mNbgbZHA B2dIPSu+SaF/8MMv5W4rxqNdAlSbCxXOkzJOeQ9tD0klnb+ns872ZcigKeGcoFgs8RuH a37kpLmiVgUxC6e/YytJVtYYsP0pgt4d6uZ5XXPG7BlBnoL8Kl12aW0OMPwPfE9dxTga 9U20KtF9wtZWrOeb6FTq+5T0Sv8lctHUe/2sQhjgC374kDGTITzqlLSAN+Q80mBeyQIw 3N3A== X-Gm-Message-State: AOJu0YzddEbHKYnB254eO1XEJRndxRY9nelx3Y5sVJ5JbngUMCK7YttC f00JDr4TNlve2Kcs6hE6n57XTg== X-Google-Smtp-Source: AGHT+IEEVMJAgf7VNGrGOvK7X1hhXjRFJJbOzLkuf4bxYIgT8Ine6m7/o/URewOBJFbA1lHhTYLMpA== X-Received: by 2002:a05:6870:14c1:b0:1b0:89e0:114f with SMTP id l1-20020a05687014c100b001b089e0114fmr14578333oab.31.1696742983833; Sat, 07 Oct 2023 22:29:43 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id ji2-20020a170903324200b001b8b2b95068sm6795601plb.204.2023.10.07.22.29.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 07 Oct 2023 22:29:43 -0700 (PDT) From: Akihiko Odaki To: Cc: Akihiko Odaki , "Michael S. Tsirkin" , Jason Wang , qemu-devel@nongnu.org (open list:All patches CC here) Subject: [PATCH 4/6] virtio-net: Unify the logic to update NIC state for RSS Date: Sun, 8 Oct 2023 14:29:13 +0900 Message-ID: <20231008052917.145245-5-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231008052917.145245-1-akihiko.odaki@daynix.com> References: <20231008052917.145245-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2001:4860:4864:20::2a; envelope-from=akihiko.odaki@daynix.com; helo=mail-oa1-x2a.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 83bac9a98a..3c3440ab72 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 Sun Oct 8 05:29:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1844854 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=JkTEiW8j; 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 4S39kC2SVSz1yqD for ; Sun, 8 Oct 2023 16:30:59 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpMNI-0004Ju-Gi; Sun, 08 Oct 2023 01:30: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 1qpMMZ-00048J-3c for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:30:01 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qpMMR-00077L-CM for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:29:57 -0400 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-578e33b6fb7so2267094a12.3 for ; Sat, 07 Oct 2023 22:29:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696742987; x=1697347787; 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=ynwsXo8IPpR9kTYC+gQRvJ4ScmqBJUKwmKxlFEEjPM4=; b=JkTEiW8j5Mi+7jBNW658dlG1BYnsyEhDhnyThQ/hdoUS20Ge58L0QNsjnyk05b4EZK TR5Lw04JST5VYp1zv0/ur0DvvttC7B00v+4HrOy+5jj8wrUUBYY7685p702FKNy3fleT YhXxzttLidK5qPKbkO6iGsvtksSh/u8K/aCvlus2Bw5mvPu0yADo0lQ6FsT0tGU8t4P0 Eh75iadTcdScOEc6cnf9ybQHEeMWHWD4RhLiqLJZvKaxTHaML2vV+OfMbXUzedG1q9fT 0djr3qDm8rzH16XCjWZmRgYXhbzfWB6cs8/xOAORovwqBGsqR+zxDBrIvry1VXoVOk3F QBqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696742987; x=1697347787; 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=ynwsXo8IPpR9kTYC+gQRvJ4ScmqBJUKwmKxlFEEjPM4=; b=Mx28A8vBUD/HUbUPYZCtVYXxSOq8b7Z5lDw/pqEh3a5lruwOjG+cYNa03cRmtYGkm9 UPWLZ8UATSo/zO8C3E8cZ2wZQs/w3iknT99z2jvy+gKIIjVh1Fy0kD9Qe+KUrtT2AjAn JJ1vrizmzOI3Go0Q/u0Crdl/cLFr3OW7H7/L4gkD+8FZYzPJE1pv8CCpBQ6WZevouupE sewzaBLosPpxHCmoyZ5pGUjMYwNy1MOgCMvh5B7x1HYMUNRIqzBi67pIWEcSJahMV1pz IzepjTcnFkGyZGjengeooI7L1LUUSuenJYX35gsubwzhni27tS6ZX0XGI8TOFc2tNqBE pk4A== X-Gm-Message-State: AOJu0YyaWE8KdJOvBg8oYpd7ttX5UEXmbw4Dir7pP13QIHKa3wmua0UX Hd2bVp8bSwYduwgWRBiRxVWI3Q== X-Google-Smtp-Source: AGHT+IGsuS0YQhajxn1FGqOdcqIwxg4nAAW0AIolGol/kpXkuqk6zDn6gtKpimYwJR8VEeYQq09TBw== X-Received: by 2002:a17:902:ef96:b0:1c6:c41:af37 with SMTP id iz22-20020a170902ef9600b001c60c41af37mr8429090plb.68.1696742987292; Sat, 07 Oct 2023 22:29:47 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id c12-20020a170902c1cc00b001c60a548331sm6777468plc.304.2023.10.07.22.29.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 07 Oct 2023 22:29:46 -0700 (PDT) From: Akihiko Odaki To: Cc: Akihiko Odaki , Jason Wang , Andrew Melnychenko , Yuri Benditovich , "Michael S. Tsirkin" , qemu-devel@nongnu.org (open list:All patches CC here) Subject: [PATCH 5/6] virtio-net: Return an error when vhost cannot enable RSS Date: Sun, 8 Oct 2023 14:29:14 +0900 Message-ID: <20231008052917.145245-6-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231008052917.145245-1-akihiko.odaki@daynix.com> References: <20231008052917.145245-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::529; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x529.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 3c3440ab72..05f9abdbcd 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); @@ -3688,53 +3723,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 Sun Oct 8 05:29:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1844852 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=zcFZei04; 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 4S39k548YQz1yqD for ; Sun, 8 Oct 2023 16:30:53 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpMMq-0004ED-6H; Sun, 08 Oct 2023 01:30:16 -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 1qpMMY-00048I-IX for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:30:01 -0400 Received: from mail-oa1-x34.google.com ([2001:4860:4864:20::34]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qpMMS-00077o-2w for qemu-devel@nongnu.org; Sun, 08 Oct 2023 01:29:55 -0400 Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-1dcf357deedso2285448fac.0 for ; Sat, 07 Oct 2023 22:29:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696742990; x=1697347790; 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=CZJMBYYnCWEwvRg2gfLk3cTIM7Y+WdKEHdFL7B88ioM=; b=zcFZei04EXtfNX/Mm0SLChHQoTTpkpTGe3wa30tY6TdcPBBeNYFzLrD8FtM1cPyNIa 0cMBu+GATQJeFQICaaUWB9PaZ6RwozPE1YKns3xr7j60j9GE0J/rddwJitxYXZGpu8j4 hkaBbsFREPrpyD5soYhDsBij4IAr3TmabXaQJXFo4szV4VHsnkHtikjo3YwdHXGR5nVa tgvszcFVENhUhbV5oW3FrepCBegZQVPI8DCSjajYiSnITzA6iq/NyPIn1dl5L+6OZpEn XLP/K++/kLGa+vzH/rBsCm0J7eYvp+kYpbZ8AsQzQ8LPz/+aj07p9h/2ag9291xnFjVU 4pmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696742990; x=1697347790; 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=CZJMBYYnCWEwvRg2gfLk3cTIM7Y+WdKEHdFL7B88ioM=; b=hAGxuQlZpCbG5ny/lyMzfPoiZ8qh5de4HmMQbCCwOFm2itOA1wMCNUtEBehBNB+saU QBH+dfiixJTWr8JbYmxy8ddaRbOjcAhGLhrDvIenb2hrFILEXCAk7FH5/feo9lZcNkUY KeT3lSsOuEAvVvrXSb5RfpOt0Fd+/3+xcPVudrX+eorRmtsRy9XRidyzDALwtvhkwP19 2PwW2+4SRnJOkfTKHVTpPna+qRTNB4X1iNLXEfUfGabQSOMVwBt0Idog/GjDdxyVdQUb ki+gGuS1CxJuilpzeUfuqanNtGfbeJYWYpqrBlP1QW06N1eg+wlhRKaTrPihR9MF8USy vN4A== X-Gm-Message-State: AOJu0YwhYwWKJuzROv5WuTol7wRJWgHk3Q8IIE0MrwpikbqEpo+/XY2b Nb1iXoXAzXIVLllzbrYfKIjMGsoqtkVYxLW/FPxf9A== X-Google-Smtp-Source: AGHT+IHC1ftcxJO1ZVUEbpvBRHQLq0YwGEq7dFJefUBY6BlbiHYGrFVcCB24zQJZBgYj6VE8cOadJw== X-Received: by 2002:a05:6870:6709:b0:1e5:525a:88a1 with SMTP id gb9-20020a056870670900b001e5525a88a1mr10964768oab.56.1696742990301; Sat, 07 Oct 2023 22:29:50 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id iw7-20020a170903044700b001c5f62a639asm6762241plb.196.2023.10.07.22.29.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 07 Oct 2023 22:29:49 -0700 (PDT) From: Akihiko Odaki To: Cc: Akihiko Odaki , "Michael S. Tsirkin" , Jason Wang , qemu-devel@nongnu.org (open list:All patches CC here) Subject: [PATCH 6/6] virtio-net: Do not clear VIRTIO_NET_F_RSS Date: Sun, 8 Oct 2023 14:29:15 +0900 Message-ID: <20231008052917.145245-7-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231008052917.145245-1-akihiko.odaki@daynix.com> References: <20231008052917.145245-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2001:4860:4864:20::34; envelope-from=akihiko.odaki@daynix.com; helo=mail-oa1-x34.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 05f9abdbcd..3bb4bf136d 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;