From patchwork Mon Oct 30 05:12:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1856821 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=FvzbR0zc; 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 4SJhLN6CTLz1yQf for ; Mon, 30 Oct 2023 16:15:40 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxKbz-00028u-Tz; Mon, 30 Oct 2023 01:14:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qxKby-00027t-8S for qemu-devel@nongnu.org; Mon, 30 Oct 2023 01:14:51 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qxKbw-0001m2-Da for qemu-devel@nongnu.org; Mon, 30 Oct 2023 01:14:49 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6b709048d8eso3409575b3a.2 for ; Sun, 29 Oct 2023 22:14:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1698642887; x=1699247687; 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=uvtq8wxoZ+JQD0l6Dj+NVPchCqfUbKogsdJs/Cye2zM=; b=FvzbR0zc6jD0NGejfEGbXeyTeCJcld+j1lbG1TmL5R81swkwaweOKcG8k+tFfrC/7q jUEKXBJpOIeSUq88v1+vqADtbTxO3BFx603bteWQuHj1lDDn/MYJjnBZ6qLOI8HJIueS L2/7OF0F8mZ1UnBjLs4DHq3Mv2VrqCDYMu88B1sT1oUi09NOmVVRhZZQgsGtZawI3HNH 8QsufiQHfzroZoAZr2MrbJxt9c0ut4JWIDuVsa+fm0FKY1ETr/vnQVbSPTnA0B4ok4kw R70/wQbvfE4gZA2uYeQmmo+/6ZYVKEHaD/837pXdV3ngUIHAxsKAUNgTTb8Tt8xUgATg 8DGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698642887; x=1699247687; 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=uvtq8wxoZ+JQD0l6Dj+NVPchCqfUbKogsdJs/Cye2zM=; b=Lc/93d7UaIqyRJ7ZO/O9gTkwzM5Jig2M1wRopXUO7mp1t0ZcKBZF6zyMF447hgRdH5 ru1y4Z8TEgiht+cVtvGUMK5v8a10WyUnyUpWIYmG/JOFKkyEv5dH/UezBg3lP/2EP/a7 8hZGrNgD3zJi3szzWMwkdshmsL9I/SM7FViQZMsBfeBVWcZBI27E+/J5LUI3CCY8il4z t63ZNUNi3PmDZHkOo9abC1M8cFYoDmXzXx2Pb+oecf5PGBzBCnkLNwOw9NlJLTncb2Gz onLQ8cT6aJdwES8u1o9n6W0xUgGnsfNXtgfHwQEbErEet3pKTXV1UYpmAVJSy9j+KIhz N/hw== X-Gm-Message-State: AOJu0YximIYCtMazBQF3KiEJCARQYfNZB2/lHgADpPjo7cbf7QJBJzP+ pAw5/hch/mqlZUhMhk+eNNaItc0rz/4ppijwwZeIxg== X-Google-Smtp-Source: AGHT+IEH6z+kH2Z+SO6bBVHH0MWvKFNpy3/u7Mqo7krRA9v8Uf0p5tvHWaevPXuQcdnjNHRHR/BwRg== X-Received: by 2002:a05:6a21:4849:b0:15d:721e:44d5 with SMTP id au9-20020a056a21484900b0015d721e44d5mr5991196pzc.49.1698642887049; Sun, 29 Oct 2023 22:14:47 -0700 (PDT) Received: from localhost ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with UTF8SMTPSA id b13-20020a170902650d00b001c736b0037fsm5486926plk.231.2023.10.29.22.14.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 Oct 2023 22:14: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 v6 10/21] virtio-net: Unify the logic to update NIC state for RSS Date: Mon, 30 Oct 2023 14:12:31 +0900 Message-ID: <20231030051356.33123-11-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231030051356.33123-1-akihiko.odaki@daynix.com> References: <20231030051356.33123-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::42c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42c.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 4c528baad9..5d4afd12b2 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1231,18 +1231,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); @@ -1290,6 +1278,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 load eBPF RSS for vhost"); + } else { + warn_report("Can't 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 { + 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)) { @@ -1418,28 +1440,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); @@ -3035,26 +3036,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; }