From nobody Wed Nov 27 06:34:49 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=1700299663; cv=none; d=zohomail.com; s=zohoarc; b=TyltSXamGJqalusGvJT9ShUvNOMZdBYrytXiX2VIMe1spI3lfoABcMnlYiuQ0q0G4nOYR3Z8ZawsLHNsJfWbsOmIP5lZek/+UWGE9x8bRWNzBGCQPT4J8ANptKI60ErmnF7gOj/qLGKUCrM4gQdTmA52Uu5I6lFZdPsu4QRuTiI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700299663; h=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:Message-Id:Reply-To:To; bh=gXy0qDSkpZb6a3h5ithRIhT7ks0qYmAY1GAjXTFln94=; b=Mk3SxKOajDSDA+MQH4AXQWXQWLGS7Yl2B8Nl8yOWstDBc5jjV4ZziF4ohSnhpNVXcRo6Yyz5kCwmmg5vo2v5xpgo+5ntr0EvCOD0hMuUqiFehBlK+9Efe/GLCtrImErnarYxubRjgNbc6VMgqLoOMfZzspUCMgUa/DHyV15yZrU= 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 1700299663666765.2311961522298; Sat, 18 Nov 2023 01:27:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r4HbI-0006Zy-Vz; Sat, 18 Nov 2023 04:26:53 -0500 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 1r4HbF-0006Z1-K8 for qemu-devel@nongnu.org; Sat, 18 Nov 2023 04:26:50 -0500 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r4HbD-0003je-Vs for qemu-devel@nongnu.org; Sat, 18 Nov 2023 04:26:49 -0500 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6b709048f32so2523726b3a.0 for ; Sat, 18 Nov 2023 01:26:47 -0800 (PST) Received: from localhost ([157.82.205.15]) by smtp.gmail.com with UTF8SMTPSA id y21-20020a170902ed5500b001cc3b988fd6sm2632352plb.265.2023.11.18.01.26.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 18 Nov 2023 01:26:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1700299606; x=1700904406; 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=gXy0qDSkpZb6a3h5ithRIhT7ks0qYmAY1GAjXTFln94=; b=OvdzZXcxi12aRSvG2EiCjh78YQusqZ97C9jwcJMyIHq7iM+cR0310/pvemm0awWcT2 3tMI5QFF2jrZSxHKrdxrOtKlU761By0d5NndiPZ++7LTXoX1bhoooGc4Yjl9WGrZ5NgU wSdHbxZDvLPMmS6ZnnYkF0Sdz+9zS92GTVNNmrWXZbJhxXaGsX4qi2DRUmILlEwARJAW gOJscKsGXZ9bKK3cByAz6YA3DH++WuQR+3LgLH7u+JX8v7R0GX5Q/UF3T02yaor3aBHB M3dwNHSBFohawKIFQ1siVRPAqP2aa9pktnufF/04GS5vekr++mWSzk/29nb0lEfu6to9 ipog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700299606; x=1700904406; 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=gXy0qDSkpZb6a3h5ithRIhT7ks0qYmAY1GAjXTFln94=; b=bDEAD9mxs86zHT6Eu940oYPtqXaTH5T0/WNICZDJrLHGXNDxgTGshtbIBhRd7EctkF 4KUUPEgydv7Je3ZyAuzAfqgcMX6nQQiwiFNWNlAdocyBfNuG8SPMMM3EZfraNEg3+rxZ G7Y063NkHvSDotFBo5t+pIfORAplGDrMDitlirnpDIQ3Ir8b1wAR6Ad+zUmogz6muUE1 1eld+dod1Acz4rtg2G3wvoeFL+/ZxmpJzq1vYAF8Z9lRftzNdwl1Zp0QwujytkZNyNR/ KWWAMTVw8GOdf0V6tI4Zwg1pvgu/gWyta3qhNdfc/Auv3cJaJhy0UvcSr53PEu6kE7jE 3YIw== X-Gm-Message-State: AOJu0Ywvw1AJmGBk57P4sL7y7fjUELoIsl1cba+hdfbHzo5DASpbeKEt c914WWBt18wpvPq1bfMtTQhfZ1bgd9FoqJeyK/k= X-Google-Smtp-Source: AGHT+IH1MA8pR8DrZkiZ5DFuR0GkmCp6NxBKiKjIkDWi8thgwrF5Ufa05pr3tQSwdiGZPSZKaAeO4w== X-Received: by 2002:a05:6a20:4308:b0:163:5bfd:ae5b with SMTP id h8-20020a056a20430800b001635bfdae5bmr1561150pzk.15.1700299606687; Sat, 18 Nov 2023 01:26:46 -0800 (PST) From: Akihiko Odaki To: Cc: qemu-devel@nongnu.org, Yuri Benditovich , Andrew Melnychenko , "Michael S . Tsirkin" , Jason Wang , "Zhang, Chen" , Akihiko Odaki Subject: [PATCH RESEND v7 09/19] virtio-net: Unify the logic to update NIC state for RSS Date: Sat, 18 Nov 2023 18:25:49 +0900 Message-ID: <20231118092601.7132-10-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20231118092601.7132-1-akihiko.odaki@daynix.com> References: <20231118092601.7132-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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::433; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x433.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1700299665732100007 Content-Type: text/plain; charset="utf-8" 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, } } =20 -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 =3D false; - - virtio_net_detach_epbf_rss(n); -} - static bool virtio_net_attach_ebpf_to_backend(NICState *nic, int prog_fd) { NetClientState *nc =3D 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); } =20 +static void virtio_net_commit_rss_config(VirtIONet *n) +{ + 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"); + } else { + warn_report("Can't load eBPF RSS - fallback to software RS= S"); + n->rss_data.enabled_software_rss =3D 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 =3D 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 =3D 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 =3D 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 =3D 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) } } =20 - if (n->rss_data.enabled) { - n->rss_data.enabled_software_rss =3D 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 =3D 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; } =20 --=20 2.42.1