From nobody Tue Nov 5 10:31:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1726363537; cv=none; d=zohomail.com; s=zohoarc; b=MCUbyYDutp6Y7V8BUTk6ajpdBHs4PriVh9gOVPkCC0nkOa/J7Gw3M2UAoLNYbNgxgK4j0JTJDTya5nwjhHYNy1PbZHPDvHWZvAMLqJRT0OQhRwixR50AiqPmE4NNXQaGWtGV6g3o+ye6Ti8NMMapfOuPoOs0gi4r85bJwT/FV/E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726363537; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yJ1Nyzv51Uzd6E3UyEnjX/5JQDEbF9GyTUtFU2+xlqI=; b=WNXjEwPRsrSlmfjoJhlsuc3YWIY9hrGEFtXObf3Ua2Jjts+Nn3nCkhAkFsLdQbIoXQYu0JK1lpuBb7LEyMYowhnvvv2G5mnMdlx41GkUMew8+hJrkcU+lxW4M7uMHfkuvfHRARqpyZ1YyJxgm4AaLKO2xmBa1nAQDX0wKRbzXdk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1726363537377409.829580861467; Sat, 14 Sep 2024 18:25:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1spe0m-0003uD-NX; Sat, 14 Sep 2024 21:25:14 -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 1spe0k-0003qa-6f for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:25:10 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1spe0i-0005db-I7 for qemu-devel@nongnu.org; Sat, 14 Sep 2024 21:25:09 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-718d8d6af8fso2307062b3a.3 for ; Sat, 14 Sep 2024 18:25:08 -0700 (PDT) Received: from localhost ([210.160.217.68]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-71944a977c6sm1518857b3a.8.2024.09.14.18.25.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 14 Sep 2024 18:25:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1726363506; x=1726968306; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=yJ1Nyzv51Uzd6E3UyEnjX/5JQDEbF9GyTUtFU2+xlqI=; b=IiITu7hQSrNuyAjCnure1VsPjTGIxJ/4l02tiX2rdSiafuXxlo5QK2fyXHC+2d5Wp8 bkRj6QYM7sRwf3UfzSgqSTwjP3TWzpdz3dx00T4VTs5BPywQ+H61xBRzkuqiH0riZKjX 2/48R7QTNJgsUvjpjQFDAZFGUfCyFXEH3oyGjhBGQw8Pt1cyyym2YbzhP8wigmSzN24n FS9QjHbhfd8K4+Xc5a3YsdhICLeom66ZAX9Bqbx3pbX60YGpYIR8U0tavNcrA7Da3tr/ /abduwmEhKrWCyhLyyBOI1NIy+JDkRusWWyjotxeDVx9m05YZLaKcC6kSlJploaWW6ng p3Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726363506; x=1726968306; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yJ1Nyzv51Uzd6E3UyEnjX/5JQDEbF9GyTUtFU2+xlqI=; b=SdtJkdpdnTwvc9Kf3EeMHtWEStubKkX5erP0pWaXnj27hmsEkPAsjoM3E8ETP09wad B+j/paoPh9Rp93qyBZYZn/BeYFDqG0gD+ucAu4/jeVUotUfyXr7ntcDK+ZoNdh0A7NFN 4zC2R8ecGOolfSpmAacAp9uYg3fZ5yeqgTItrxDGUJslE+MXIrxPg0AeMqc3nZ7MW1uj 8Tzu12rem2b6x5qoK/Q0sT83AKekKy67jGcY+IBXWQrcn9HF9RQY1mPjTbAEeb047zbt dPC4w2LfMubEnfibyaSrojnPDc4ZQxcfnfs4qkpzDebhpw9hAuF65WKF40bmgckFNB/W snXw== X-Gm-Message-State: AOJu0YzgElJ9k3RGu+YhOwDyy6FsSk/u0/7Nv9w0oymgKVOYFhoBy+nv qLmVMCMJusIIs7mU0kEaWGKxJTTMN34dfeLnjMa1xwUkJ5s28cDU8OIAmB9i86CW1/CEV8zjijt zboQ= X-Google-Smtp-Source: AGHT+IGhCVRmQ51V6FHDhjWg7uh3zggyCbHp1WXOtU6JkCd6149cHt1mevpJYXH6U9EFhkDy1w3tHw== X-Received: by 2002:a05:6a00:2392:b0:705:a13b:e740 with SMTP id d2e1a72fcca58-719261eca97mr16746022b3a.19.1726363505995; Sat, 14 Sep 2024 18:25:05 -0700 (PDT) From: Akihiko Odaki Date: Sun, 15 Sep 2024 10:23:49 +0900 Subject: [PATCH RFC v3 08/11] virtio-net: Use qemu_set_vnet_hash() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240915-hash-v3-8-79cb08d28647@daynix.com> References: <20240915-hash-v3-0-79cb08d28647@daynix.com> In-Reply-To: <20240915-hash-v3-0-79cb08d28647@daynix.com> To: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang Cc: Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::42d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1726363537852116600 This is necessary to offload hashing to tap. Signed-off-by: Akihiko Odaki --- hw/net/virtio-net.c | 77 ++++++++++++++++++++++++++++++++++++++++++++-----= ---- 1 file changed, 64 insertions(+), 13 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 38ccd706f956..be6759d1c0f4 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1209,20 +1209,65 @@ static void virtio_net_detach_epbf_rss(VirtIONet *n) =20 static void virtio_net_commit_rss_config(VirtIONet *n) { - if (n->rss_data.peer_hash_available) { - return; - } - if (n->rss_data.enabled) { - n->rss_data.enabled_software_rss =3D 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 load eBPF RSS for vhost"); + if (n->rss_data.peer_hash_available && + (n->rss_data.peer_hash_types & n->rss_data.runtime_hash_types)= =3D=3D + n->rss_data.runtime_hash_types) { + NetVnetHash hash =3D { + .flags =3D (n->rss_data.redirect ? NET_VNET_HASH_RSS : 0) | + (n->rss_data.populate_hash ? NET_VNET_HASH_REPORT= : 0), + .types =3D n->rss_data.runtime_hash_types + }; + + if (n->rss_data.redirect) { + size_t indirection_table_size =3D + n->rss_data.indirections_len * + sizeof(*n->rss_data.indirections_table); + + size_t hash_size =3D sizeof(NetVnetHash) + + sizeof(NetVnetHashRss) + + indirection_table_size + + sizeof(n->rss_data.key); + + g_autofree struct { + NetVnetHash hdr; + NetVnetHashRss rss; + uint8_t footer[]; + } *rss =3D g_malloc(hash_size); + + rss->hdr =3D hash; + rss->rss.indirection_table_mask =3D + n->rss_data.indirections_len - 1; + rss->rss.unclassified_queue =3D n->rss_data.default_queue; + + memcpy(rss->footer, n->rss_data.indirections_table, + indirection_table_size); + + memcpy(rss->footer + indirection_table_size, n->rss_data.k= ey, + sizeof(n->rss_data.key)); + + qemu_set_vnet_hash(qemu_get_queue(n->nic)->peer, &rss->hdr= ); } else { - warn_report("Can't load eBPF RSS - fallback to software RS= S"); - n->rss_data.enabled_software_rss =3D true; + qemu_set_vnet_hash(qemu_get_queue(n->nic)->peer, &hash); + } + + n->rss_data.enabled_software_rss =3D false; + } else { + if (n->rss_data.peer_hash_available) { + NetVnetHash hash =3D { .flags =3D 0 }; + qemu_set_vnet_hash(qemu_get_queue(n->nic)->peer, &hash); + } + + n->rss_data.enabled_software_rss =3D 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 load eBPF RSS for vhost"); + } else { + warn_report("Can't load eBPF RSS - fallback to softwar= e RSS"); + n->rss_data.enabled_software_rss =3D true; + } } } =20 @@ -1230,7 +1275,13 @@ static void virtio_net_commit_rss_config(VirtIONet *= n) n->rss_data.indirections_len, sizeof(n->rss_data.key)); } else { - virtio_net_detach_epbf_rss(n); + if (n->rss_data.peer_hash_available) { + NetVnetHash hash =3D { .flags =3D 0 }; + qemu_set_vnet_hash(qemu_get_queue(n->nic)->peer, &hash); + } else { + virtio_net_detach_epbf_rss(n); + } + trace_virtio_net_rss_disable(); } } --=20 2.46.0