From patchwork Tue Oct 10 02:59: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: 1845567 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=Ht5HMHFL; 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 4S4LHy0LvBz23jb for ; Tue, 10 Oct 2023 14:00:45 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qq2yF-00045O-TL; Mon, 09 Oct 2023 22:59:43 -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 1qq2yE-000459-5d for qemu-devel@nongnu.org; Mon, 09 Oct 2023 22:59:42 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qq2yC-0007wY-Mj for qemu-devel@nongnu.org; Mon, 09 Oct 2023 22:59:41 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-692c70bc440so3940924b3a.3 for ; Mon, 09 Oct 2023 19:59:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696906779; x=1697511579; 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=Ht5HMHFLs0yX3Vd3qZX2qd5WckIwDoqtFRzsMF0iYZiMVWIdSSUzHAPNE/wCHPzKTQ Dl8ovsggt+M6aWoLUoGkb2OeM79DBTD4Aaj4XfHH2HszdwUWLdcGO2PKKSkyjTl/oLb7 hYvCy17UA4ajM98MiKonNWa6xzmav32oLbkR/DvftGmh3++R0geTF1WqA1J7V6ypDlBz L47ItmyvKFg4edPoOxiGQVF+iFqsxu+vGusFHsVrwpFH34xevMYWGQJGAPIidLSGq7R8 YxDc4zfLWLjXJOR0F+f/dor9SjUfwkLOTFLwZGDHhG5gUNF00mR/4xoz/PSKPSvKGnD9 9xPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696906779; x=1697511579; 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=LhwTAZZ4UxCH1hRXkqOfNSa8PBVjEeha4Wuu1rpGQLYdYGP0Gh2CzvJ/ntXDrFc6Gq RcIFNHvXucCabaPAI+pBfAIDvIEcifgXR+ag/TgCFr0j1dl9OyMftj8hvBN+RVv61INT RyOnJsmwKUDyIWzzu6Ag/1yiBzEWN+QU4i9r/LmPqrnAxufFbItEWWOw+7zCoBs8Phgu iFDT0wLuCLpRRO/cEiMyH0AmE299AR32FSRRuE81SqHBhTFud/TAxWKVi24JydzxwSAA xgbceYWjTe6qskzIlH8eE+oxdqEV96Vu5hQWnJ3YMoH2ysrjtzQD0GMUYpeuso6n8JNC Zogw== X-Gm-Message-State: AOJu0YyLEYWTGjz0ot1Xt7QczlkYhOGvkD66DbYhVptQVbsqHTIv9Hin Vd+jbOaMLQUc2qKf999d0NodR7hTQdNEGCBhHmlCoA== X-Google-Smtp-Source: AGHT+IHjUo0lRD1RIlmM9QDq7lG1mmX6gbJnotAhDAK2Xf04QKyU/vc9ezNhJqyC1ReCkX+SOY3Zlg== X-Received: by 2002:a05:6a20:7d9c:b0:129:3bb4:77f1 with SMTP id v28-20020a056a207d9c00b001293bb477f1mr18006757pzj.0.1696906779164; Mon, 09 Oct 2023 19:59:39 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id ja14-20020a170902efce00b001bd62419744sm10396813plb.147.2023.10.09.19.59.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Oct 2023 19:59:38 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S. Tsirkin" , Jason Wang , Akihiko Odaki Subject: [PATCH v2 1/7] tap: Fix virtio-net header buffer size Date: Tue, 10 Oct 2023 11:59:15 +0900 Message-ID: <20231010025924.14593-2-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010025924.14593-1-akihiko.odaki@daynix.com> References: <20231010025924.14593-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::42a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42a.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 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 Tue Oct 10 02:59:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1845566 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=mgIMM00A; 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 4S4LHy07jwz1yq7 for ; Tue, 10 Oct 2023 14:00:45 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qq2yJ-000463-Ca; Mon, 09 Oct 2023 22:59:47 -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 1qq2yH-00045i-Mu for qemu-devel@nongnu.org; Mon, 09 Oct 2023 22:59:45 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qq2yG-0007wu-1E for qemu-devel@nongnu.org; Mon, 09 Oct 2023 22:59:45 -0400 Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-578e33b6fb7so3315594a12.3 for ; Mon, 09 Oct 2023 19:59:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696906782; x=1697511582; 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=mgIMM00AAj6C2WUbwxZ6nsgXhmWFW8D8mTJymtbg40EN5J2OmOIT4GCDyqrj5O0gBr fRJ7SOtl5q5/rUrlCnLXYGsjqRuGxbhK6gxczwbX0DdabwnZzE9JrbBew3Ka87gCVwTt vS9udkO3yMd/fGB7vGeCxYygcVdM4kIsWQDMtmGov8Ei9H5O1zhS6HFw4qvdzDuv4ziY VFb+oNYsnjejfI55oxRhpnDlIu1hvlsCeAgMzquXK0U3tofz8G1Ds3oTzbrOqV+BIxo6 P/KVJQfMn7hH7YWTg6zQHnwKakBHl43jErDmNRQdWGGv4WubDx1JmdyiTYYDgsVtgEuW WydQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696906782; x=1697511582; 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=lPctGJaqf4YaNsr/cmDxX8zrq38i9keIbcro8K591X4gvqmiPiIGY70b+2t9dZ4W9k yFQHpJRHrc5KnZqeA5/kkfzVr0soO/yrN7VWph5VhyIHL9HApxVHpPXdZv4xqnwpF+lY 6uDZaMKtyx0iL1MD6lPy15clU6sHEjNI0KQG1kOTQKjRmmCFvwnIyQjcumh13B0JDaG4 So70/k/Ft8uOCLXJ8/HMrmKEvCBnQWeQojL5FVuPtClV1BE5Vi1ExDjtSC1YeALfRiDX KwNj+kI0Y5F/8/FccPstyCz2RKXkJSE/kryLiaJU3OSe/p56hoauSxdOQEWGyjE7S+cF HYvA== X-Gm-Message-State: AOJu0Yw27YIlnpEYntserLbZA63kj9h1QLoaGc5E49GHVPaWg4M5FhFW sxfrV8GDdWtwzVV7fAAHhKxks95Kn6luhvqCPFKV0w== X-Google-Smtp-Source: AGHT+IGHLBxX5BJfYMzV9XIc4U/l7iYjUsRp+JjGbINNW5tqLc+pnWDXFtKvu5AhBTLWCratQJFJMg== X-Received: by 2002:a17:90a:dc18:b0:26d:11ff:1832 with SMTP id i24-20020a17090adc1800b0026d11ff1832mr12752904pjv.27.1696906782592; Mon, 09 Oct 2023 19:59:42 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id k9-20020a170902694900b001c73eace0fesm10391294plt.157.2023.10.09.19.59.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Oct 2023 19:59:42 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S. Tsirkin" , Jason Wang , Akihiko Odaki Subject: [PATCH v2 2/7] virtio-net: Copy header only when necessary Date: Tue, 10 Oct 2023 11:59:16 +0900 Message-ID: <20231010025924.14593-3-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010025924.14593-1-akihiko.odaki@daynix.com> References: <20231010025924.14593-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::532; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x532.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 Tue Oct 10 02:59:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1845571 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=iETMrO6O; 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 4S4LJf6BBnz1yq7 for ; Tue, 10 Oct 2023 14:01:22 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qq2yL-00046T-Q2; Mon, 09 Oct 2023 22:59:49 -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 1qq2yL-00046K-22 for qemu-devel@nongnu.org; Mon, 09 Oct 2023 22:59:49 -0400 Received: from mail-qk1-x730.google.com ([2607:f8b0:4864:20::730]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qq2yJ-0007x6-HQ for qemu-devel@nongnu.org; Mon, 09 Oct 2023 22:59:48 -0400 Received: by mail-qk1-x730.google.com with SMTP id af79cd13be357-7742da399a2so345510585a.0 for ; Mon, 09 Oct 2023 19:59:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696906786; x=1697511586; 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=iETMrO6OtuharinXARWol1ICpjrt4AfNn4PrKpBoD4ZXlYYw/mlvNl4TroeXftxjw9 UZjb9uk1AFeK94qM90w4TA2VcYeTC3/CB4CvHDCPwJOCxGRxfvg8O3knR7b/wT0EjVuN 6dszMe5b82fy36eKWdAjZ/MbZw8Pz7sGBDLPPf8UM4LToSB9KnktBgI1UvJp2j8vVmxw BUemVgD+56lPiW6DIWw85KT+Tu/hPsdEgt0QC/ENXku+wHEui/fKBIAaauRILMi6lQlx 9yTi3nL1XIS1BJQ+cJZ5GcV1GeI09xf6z8s0Z7BArNpPoZdii5OX5mZPjUpiCoI7ROd2 FfwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696906786; x=1697511586; 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=cWjZ8U+ObSg0bW+jnPIXYlSH/BYLGL7LKhlS9TqWb/SwHkg7rhXvMOKPAZyMroYesh HIOYaR4RFNb/iTcHcsstf7wohOMZVuYGt2/0XttHdedZUG/frUJ3BXJjGWgBZnUhmE+6 SgkAHxsW9beAhR0dzxUfW2zTjHacHcGJd5SkA/RCoPxdR9UwHu0dUzYTiQkZ6bY2d2yb dLmHAqjAQ2J2gW7UkK7pUSdwtwcQX+PV6by/EyQn6EclWGcbQ8MxindjaVJr5+2V5KHb AeAStuSeIJzgMOGfKju6GsRU8eYY9KcNFDXbHmJM0Cm8Nkqtm2AAKZ5rEn91oCW9Hrj+ RS7g== X-Gm-Message-State: AOJu0YwZZmf5MdB5qXO/Y0Yz2h2nMir+1N336MVzNvtH3ogcClIn7IP9 W6FSNze3/Mr7fdSzXt/WtH84fGHvX4/AHZbKjXj+EA== X-Google-Smtp-Source: AGHT+IFPbYsWqiYKWyiq+e2YVqM+T3vqQ3jSj+JF2aNVRLpO/eRLBLxIpdKKFM4MOtlchn0YRhjyvA== X-Received: by 2002:a05:620a:4513:b0:777:2723:ea77 with SMTP id t19-20020a05620a451300b007772723ea77mr787861qkp.65.1696906786586; Mon, 09 Oct 2023 19:59:46 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id n20-20020a638f14000000b00563e1ef0491sm9155105pgd.8.2023.10.09.19.59.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Oct 2023 19:59:46 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S. Tsirkin" , Jason Wang , Akihiko Odaki Subject: [PATCH v2 3/7] virtio-net: Disable RSS on reset Date: Tue, 10 Oct 2023 11:59:17 +0900 Message-ID: <20231010025924.14593-4-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010025924.14593-1-akihiko.odaki@daynix.com> References: <20231010025924.14593-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::730; envelope-from=akihiko.odaki@daynix.com; helo=mail-qk1-x730.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 Reviewed-by: Michael Tokarev --- 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 Tue Oct 10 02:59:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1845568 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=Hi2dnA9R; 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 4S4LHy0S7zz23jj for ; Tue, 10 Oct 2023 14:00:45 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qq2yS-00047K-Da; Mon, 09 Oct 2023 22:59:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qq2yR-00047B-Ii for qemu-devel@nongnu.org; Mon, 09 Oct 2023 22:59:55 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qq2yP-0007xV-Ti for qemu-devel@nongnu.org; Mon, 09 Oct 2023 22:59:55 -0400 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-53fa455cd94so3417756a12.2 for ; Mon, 09 Oct 2023 19:59:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696906790; x=1697511590; 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=Hi2dnA9Rxac+V6aOA2LZJfo2Bw9BPVZ1p9LerejojDbqlCRCotrt59Sp/l2YC8uye9 Ikq25YhKBKR/EuNgnb+UpG8XKTWpru7Y8zob2XnOzLRMyIFjUR93tIVuXeD+Wx5tXDkj fSDvU0k4eyMGOR7JikYn9pFcxHjCkfYbDVuXw/Njv5It9yB/H5JotrGSj26CHjWRtrzn VqpX3W8n9SwcmLFAHNSFnyvliokXVRQAQIHpVXDW4dms+//x06fEwD35snJEjXwrzARD p1oSDje0ugycplRfbpU63foyhjIX14SNZa74vzPADRIBMFHPdp4Hwu82C8yTSDQq0/wA 3Upg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696906790; x=1697511590; 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=XUilT81eYh4SembP94LuHGLLpYXGFcChSq5mfAgNjXfwYqim/HU5cO5II5CZ9N7XKb EeaH7/FycOTkoytQiKtl8+M6I/HH5TT4WrRQhWG57MgQJ3VTXV216oQh0+fAZX0N1lLg z38V5B4O4HzENlMhtMMqNB8flJc42C0OkY5hM2NOA7IpX8ILgURFttoBQykNMuKjXjuI WljI2y/0b7l4YyF77Bs2JX5ah3SNSiFSCdhUcTZBwzhPqdqlwVo3zwZSDjhoJiNM4yJe 4zRLZeDRlunX6weaQhfEXqRXUH1cXnIOx/GBkXrypN1yHRwPCZVm+yHPSwHNgdCpCpaz TjKw== X-Gm-Message-State: AOJu0YzIRyyHSYVoGLfTCtywluR4P8f+mX/XK3GYegoROQfxtZqBBXuk eH4WQtqlQqPG/lNV2yIv+fnpAtpnvL/aNV0AIUY7KA== X-Google-Smtp-Source: AGHT+IFj9YpDwORIIyD6S1U3P6SQ/pUZaY3jmWsxp6SLSoo4QnikbQLi7jgkQroVaqLtWRhbaAl0tA== X-Received: by 2002:a05:6a20:3d1e:b0:16b:80d3:7f10 with SMTP id y30-20020a056a203d1e00b0016b80d37f10mr10105130pzi.34.1696906790539; Mon, 09 Oct 2023 19:59:50 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id y5-20020a170902ed4500b001b86dd825e7sm10433955plb.108.2023.10.09.19.59.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Oct 2023 19:59:50 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S. Tsirkin" , Jason Wang , Akihiko Odaki Subject: [PATCH v2 4/7] virtio-net: Unify the logic to update NIC state for RSS Date: Tue, 10 Oct 2023 11:59:18 +0900 Message-ID: <20231010025924.14593-5-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010025924.14593-1-akihiko.odaki@daynix.com> References: <20231010025924.14593-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::52f; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x52f.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 Tue Oct 10 02:59:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1845573 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=L0CIZQq2; 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 4S4LJh6McTz1yq7 for ; Tue, 10 Oct 2023 14:01:24 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qq2yW-00048I-Id; Mon, 09 Oct 2023 23:00:00 -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 1qq2yU-000487-PK for qemu-devel@nongnu.org; Mon, 09 Oct 2023 22:59:58 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qq2yS-0007xk-Qo for qemu-devel@nongnu.org; Mon, 09 Oct 2023 22:59:58 -0400 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-694f3444f94so4228786b3a.2 for ; Mon, 09 Oct 2023 19:59:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696906794; x=1697511594; 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=L0CIZQq2r7Lp+BuFHKAjFl9onZEqyhOcnhZ2xBq2y7icYfaz/FYhMoqaHbwmq1KLqV sCXcTkSx177Gw0epFzzg2jcDr7V9F+DnIMYm6dLC0hhPj0lbjUqfUk7sH4calivjabmS SRiBUQVUp1MBeXZrX4+QB0b14wWw8Z0BDIa6jZG4VVKJxmK4/nu+zSVwS337vcN/IcYV 8WzJGqtLgTlVPEt8T/iD/lO+lbNsFjYD5zYPw57nSrZwFOoLspzdhwZH2vi0MJjKiQjG Ei2MMjDsZVWKO4PwiR5AYv2rpqhXbfwOmZ5DnDlRRGJ8nfzeGgrBxvSufhsL8rcsCCZu m7ZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696906794; x=1697511594; 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=iVj7ySZTPYC4QyaotuxWXW65kw760fApNXJNsuy7Lf5Fd1SjdG6DYQicS4Zdi1TCyZ tu6OPgRbj2pDOTKFIFV6Nc+62mch2IRPAq0Yef2W9QVFFL2CEN2QCAf2IIqSSkaC+Qpy DxDtHhjqaiOf6L10LV6jkG3EIWeuRGckfpkoSea3wpSUV5P4YKyNXU4Mwoc9NI1dmB4e +0gOZsF8CgMrghT+rgVWxESNAJn+fTkplHIHHU6A5Rr3IfWhyqt/d0U39GOD2om8LEjY +w0tacqupiBTAEQD7VBQ4oO7qoZRliZaRlQp3tvyjhbT7/wLW8k5KzURNuiKb4kwv8Rp opYQ== X-Gm-Message-State: AOJu0Yy0lzVIFhXWX8POhKV/Jm1PqUjejBO9tBhuShcF/9inqwukTNhS q5oy1BceRx1wBx2Deys+VLtOxhQEPb9gWlFeVV41cw== X-Google-Smtp-Source: AGHT+IE/e8Quw+bu62M+zr6jOJRBT3f9lNxd2XLx7P5f9AylOht/r9+1DkKQr+rkfvnAWdavwRfdCw== X-Received: by 2002:a05:6a20:3d11:b0:171:48a1:a85a with SMTP id y17-20020a056a203d1100b0017148a1a85amr2080492pzi.23.1696906794238; Mon, 09 Oct 2023 19:59:54 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id j20-20020a62b614000000b0068fe5a5a566sm7263733pff.142.2023.10.09.19.59.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Oct 2023 19:59:53 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S. Tsirkin" , Jason Wang , Akihiko Odaki Subject: [PATCH v2 5/7] virtio-net: Return an error when vhost cannot enable RSS Date: Tue, 10 Oct 2023 11:59:19 +0900 Message-ID: <20231010025924.14593-6-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010025924.14593-1-akihiko.odaki@daynix.com> References: <20231010025924.14593-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::430; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x430.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 Tue Oct 10 02:59:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1845569 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=3d2CPZAc; 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 4S4LJQ0qVzz1yq7 for ; Tue, 10 Oct 2023 14:01:10 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qq2yY-00049W-5L; Mon, 09 Oct 2023 23:00: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 1qq2yX-00048a-8C for qemu-devel@nongnu.org; Mon, 09 Oct 2023 23:00:01 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qq2yV-0007z1-P0 for qemu-devel@nongnu.org; Mon, 09 Oct 2023 23:00:01 -0400 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-27ce00abfc3so365879a91.3 for ; Mon, 09 Oct 2023 19:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696906798; x=1697511598; 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=3d2CPZAcpPxbU96ujux7D/YJVrESLVwYy99w8HBdTt8/zIROkYLizvEY3IZCNqZe3g h507B4e/8x20HJ6clFyZ1C2OvFCz3IFTopYFwxszjvLvD7DeqO6lvxW0gZK8MSdkLfZG F4bk5s83EwEhKoiWGYe9rbY0tEUA6l+5T7UOoMW9dYCryPi0WycIOYEpoOplyLJRjNtO N+a/BGL7/GjJx63srXqyTnI4L3/P1jI6XSJfIrj1njjc7WPHYGh/z7jupB4v57FNiDmP Eb3JnKbL5HR//vGVxFSUCTAiNm+yRq7v1NOeRP1beyvk3GYKA7vF3i1T2hu11TrgFdA0 0etA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696906798; x=1697511598; 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=sELvDbvVS8snRru6yA4d/v29lwrm2QKYG8/k5kQ2r1ia+qt4UMMFrNWl90FWpaRHaW T+vcxKUajIhpnQ3JEasOJ9ZXXkuiOYq5QUjYef73IDkVN2htCLkdQJwMYQx25jinN85e 9Dwr2OlpQBBgpp8GUlj4KzrinkoeOiI2PtNTHJj6DHzT+YnOgA+79BICWIMfWTwuhEWa 6KOzcp7RVicxfmorjWv1YxZbqnz1YTS+r8tyAWhNwmz5Aj2yXN+wwbIeEnSZ8xQKjq3r UcyciGWyM/HEIRwH8ySf7Z7dZnwUcgSSzT5Kgr0mEV6nZsjCltFat/b9kAUMXuMpG1y1 CVFQ== X-Gm-Message-State: AOJu0YyAIxpz+CZG3w/eKnVtqk9n6B7NycGtsGdhv12yb02FeZDTSsk+ 1DiVtJF79KnIrB+sJuguJbuhXD9qXguI6g25Qdw6Sw== X-Google-Smtp-Source: AGHT+IEsFO9EqmcyGkhltgMMMeG8XXm1UDTTZLOV4ADeUseqAuRsNx05QLhQQeqgmuwepoTAHeXIzA== X-Received: by 2002:a17:90b:3e8c:b0:276:ae8f:2456 with SMTP id rj12-20020a17090b3e8c00b00276ae8f2456mr12835210pjb.3.1696906797919; Mon, 09 Oct 2023 19:59:57 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id o12-20020a17090a3d4c00b0027782f611d1sm11915111pjf.36.2023.10.09.19.59.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Oct 2023 19:59: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 v2 6/7] virtio-net: Do not clear VIRTIO_NET_F_RSS Date: Tue, 10 Oct 2023 11:59:20 +0900 Message-ID: <20231010025924.14593-7-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010025924.14593-1-akihiko.odaki@daynix.com> References: <20231010025924.14593-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::1029; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1029.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; From patchwork Tue Oct 10 02:59:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1845570 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=G79BdpKG; 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 4S4LJV64Fyz1yq7 for ; Tue, 10 Oct 2023 14:01:14 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qq2yc-0004AB-0n; Mon, 09 Oct 2023 23:00:06 -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 1qq2ya-00049z-Ih for qemu-devel@nongnu.org; Mon, 09 Oct 2023 23:00:04 -0400 Received: from mail-vs1-xe2d.google.com ([2607:f8b0:4864:20::e2d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qq2yZ-00080a-1d for qemu-devel@nongnu.org; Mon, 09 Oct 2023 23:00:04 -0400 Received: by mail-vs1-xe2d.google.com with SMTP id ada2fe7eead31-4577c1259c6so547399137.3 for ; Mon, 09 Oct 2023 20:00:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1696906801; x=1697511601; 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=G79BdpKGMPEYHjUdIo5weQw+XT6/1n7o9JVWyF7Ol0j06uOXdiTZ9wh26PPSh5kybs eTeQ6aOwE3g2RdL8ZxaGcrGra3DVUpEho9sJD78A3iYTLtEmWz781VLwG/VdL8f9PUuJ CRPG0r7O03F3barAjhRpYJyCmsZj+rOuqBJmo/tFgJaJqOpFlE5MmppuI061PzgaAWBD skPRRZLyq85vU2yCsJuyf3nPKXftN6zffYRnx91Fsxh3xAP6KIR1bcnFeDFLCS7EaMx+ R8AFp/ZmKrzqme8hnQ7CAtp41aiGYbb/SdwpsVJpQfT8XsIlF+SIXZPVsA682eFgOWjc fjsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696906801; x=1697511601; 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=ftZ0AsjPSssFkck6Nsz9167ubO24s7A+vT+IJhTYYrq37L6xiExmOr9nJmh1RlETX+ dpt3Rd+Qj7PKGmIH+k7QWhlWmoyzbH41Kh8pcWXjdA/gLF/ZU/ySL9St0KobrX46KHAO kI9dZHiiK67lAoHWOkhkHLzIsNtSqKDU2AG7GkTuiuz4Rx9DDR2+DOG06YGVZODasq+L WrYECuDc1TzSDT0uC5ocIS1XRnzjnkA4UZscgZ7+iQ5NvzFiO8VlPegYFT6s0Rmje8/t LSMeeO8tOHJIcJjMcAMlDzx2JgeJR9LszdEq0hi2sX7L5v1UABsbaLijk1KJ/N7lkQz2 hTGQ== X-Gm-Message-State: AOJu0YybQxOoax0j30UVn+Z9Sgunjz2Dseb691KL7828XbwFUOJxpAOB UwRNpQWdBj9vq/vBR0m60aaxwRPqskmLzVYscRX0gQ== X-Google-Smtp-Source: AGHT+IGSYnq8H3XKdBvjmkkoPqB1eD1gHs+0e8bonWJNjg0WJkiR//Q0muxSow6K/rLddQ6o41Opow== X-Received: by 2002:a05:6102:34f1:b0:44e:8353:e86a with SMTP id bi17-20020a05610234f100b0044e8353e86amr11109398vsb.24.1696906801356; Mon, 09 Oct 2023 20:00:01 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id s6-20020a63b406000000b0058dc763f449sm4291467pgf.1.2023.10.09.19.59.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Oct 2023 20:00:01 -0700 (PDT) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S. Tsirkin" , Jason Wang , Akihiko Odaki Subject: [PATCH v2 7/7] ebpf: Fix RSS error handling Date: Tue, 10 Oct 2023 11:59:21 +0900 Message-ID: <20231010025924.14593-8-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231010025924.14593-1-akihiko.odaki@daynix.com> References: <20231010025924.14593-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::e2d; envelope-from=akihiko.odaki@daynix.com; helo=mail-vs1-xe2d.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;