From patchwork Mon Jul 8 07:38:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13726252 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3F8BDC3271E for ; Mon, 8 Jul 2024 07:39:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQixH-00021a-Nj; Mon, 08 Jul 2024 03:38:35 -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 1sQixF-0001zh-Np for qemu-devel@nongnu.org; Mon, 08 Jul 2024 03:38:33 -0400 Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sQixE-000230-2I for qemu-devel@nongnu.org; Mon, 08 Jul 2024 03:38:33 -0400 Received: by mail-il1-x134.google.com with SMTP id e9e14a558f8ab-37613975e20so16113755ab.2 for ; Mon, 08 Jul 2024 00:38:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1720424310; x=1721029110; 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=9R1xK/Vv8RXEdLfe48vF+VubVq7j3GH38byRAI52eII=; b=C8/PavmP68VyMwMKPVzq/X/lTYEqTTJjYEg3TdD8jjgrnDzJ85Ivzy/lJSkQP6xUtH P8q5OgVMqE+baW7oBKluvRgFanKJBnZp6UaqchpbqfJMhNFtypjjnK9KMHr/W/1eDt7D 009hCROyCXzUxmPGS/RtNLaVaEbMoDpPoQGGUKJJWo2uYLG5nq+BxJmcTEGlvTd+38RL WWgAfPcLorvBb7DaZsklw9cvEPE0rcv2t0FNuY+pTTzXwKVzRacMfs8C3C7FDGXAIwpS TJCP4zngYoSxSbMmRuw1ge3zEqqMZgiVa+3DtOi5LhVmt3csxt6tTCSZYPvRTzIBnfel LPuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720424310; x=1721029110; 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=9R1xK/Vv8RXEdLfe48vF+VubVq7j3GH38byRAI52eII=; b=wZaJOnDVQXo6hZsYFDu7xYEJGRGtMUnf2CMIrv45y8R15zcZQcBUIpj/8ItqGApPB6 PcQuc629QEmEH3Iu+lAiKsBqVWQWo5gdnTeRxpAvQ/lh5Etk9H1efW2x+AF6ndM5TsPH D4JEMzHhhJiZBFK2980fERLBhX0AMPBjEDr+UmnuFnhSKB0VilZXocJv5Qzw9O65DT8R IoVadzIRf0L9xvNBo/FInSgoBWxtc9gSeQ5MWYdqciPNl0SpKJaIOjxufpUlBG3fj5dD vkAgw8vcbbcUQ02iAiYhwZGPeoxCEk2DEdRlLAS6hsqdIMZ+vIuiiB1vdYOBelWNGEuY 9Pfg== X-Gm-Message-State: AOJu0YwHTNCa0NFHQS11UvekTjXNWqPrgrvI9xZO1LkQs76De4r64MN8 M0/lt55PDPpF1aTsDv7EqEgkSWnKfF0VU85ma/POQxrLHgM0CMHS9AMbiauVmAo= X-Google-Smtp-Source: AGHT+IGb6KTgmx9a8ZtnfhZ2wXxCTY+PSNTcFgdvv9uJBe7qP/O4Uwhl+0BwS5q5CExRGQuTIwzV6A== X-Received: by 2002:a05:6e02:194b:b0:375:c296:bf90 with SMTP id e9e14a558f8ab-38398430c33mr166618745ab.7.1720424309918; Mon, 08 Jul 2024 00:38:29 -0700 (PDT) Received: from localhost ([157.82.204.135]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-70afa1ee180sm7931831b3a.7.2024.07.08.00.38.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Jul 2024 00:38:29 -0700 (PDT) From: Akihiko Odaki Date: Mon, 08 Jul 2024 16:38:06 +0900 Subject: [PATCH v2 1/4] qdev-properties: Add DEFINE_PROP_ON_OFF_AUTO_BIT64() MIME-Version: 1.0 Message-Id: <20240708-auto-v2-1-f4908b953f05@daynix.com> References: <20240708-auto-v2-0-f4908b953f05@daynix.com> In-Reply-To: <20240708-auto-v2-0-f4908b953f05@daynix.com> To: Jason Wang , Dmitry Fleytman , Sriram Yagnaraman , "Michael S. Tsirkin" , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Andrew Melnychenko , Yuri Benditovich , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 Received-SPF: none client-ip=2607:f8b0:4864:20::134; envelope-from=akihiko.odaki@daynix.com; helo=mail-il1-x134.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org DEFINE_PROP_ON_OFF_AUTO_BIT64() corresponds to DEFINE_PROP_ON_OFF_AUTO() as DEFINE_PROP_BIT64() corresponds to DEFINE_PROP_BOOL(). The difference is that DEFINE_PROP_ON_OFF_AUTO_BIT64() exposes OnOffAuto instead of bool. Signed-off-by: Akihiko Odaki --- include/hw/qdev-properties.h | 18 ++++++++++++ hw/core/qdev-properties.c | 65 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h index 09aa04ca1e27..afec53a48470 100644 --- a/include/hw/qdev-properties.h +++ b/include/hw/qdev-properties.h @@ -43,11 +43,22 @@ struct PropertyInfo { ObjectPropertyRelease *release; }; +/** + * struct OnOffAutoBit64 - OnOffAuto storage with 64 elements. + * @on_bits: Bitmap of elements with "on". + * @auto_bits: Bitmap of elements with "auto". + */ +typedef struct OnOffAutoBit64 { + uint64_t on_bits; + uint64_t auto_bits; +} OnOffAutoBit64; + /*** qdev-properties.c ***/ extern const PropertyInfo qdev_prop_bit; extern const PropertyInfo qdev_prop_bit64; +extern const PropertyInfo qdev_prop_on_off_auto_bit64; extern const PropertyInfo qdev_prop_bool; extern const PropertyInfo qdev_prop_enum; extern const PropertyInfo qdev_prop_uint8; @@ -100,6 +111,13 @@ extern const PropertyInfo qdev_prop_link; .set_default = true, \ .defval.u = (bool)_defval) +#define DEFINE_PROP_ON_OFF_AUTO_BIT64(_name, _state, _field, _bit, _defval) \ + DEFINE_PROP(_name, _state, _field, qdev_prop_on_off_auto_bit64, \ + OnOffAutoBit64, \ + .bitnr = (_bit), \ + .set_default = true, \ + .defval.i = (OnOffAuto)_defval) + #define DEFINE_PROP_BOOL(_name, _state, _field, _defval) \ DEFINE_PROP(_name, _state, _field, qdev_prop_bool, bool, \ .set_default = true, \ diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 86a583574dd0..e1c336435e05 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -187,7 +187,8 @@ const PropertyInfo qdev_prop_bit = { static uint64_t qdev_get_prop_mask64(Property *prop) { - assert(prop->info == &qdev_prop_bit64); + assert(prop->info == &qdev_prop_bit64 || + prop->info == &qdev_prop_on_off_auto_bit64); return 0x1ull << prop->bitnr; } @@ -232,6 +233,68 @@ const PropertyInfo qdev_prop_bit64 = { .set_default_value = set_default_value_bool, }; +static void prop_get_on_off_auto_bit64(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + Property *prop = opaque; + OnOffAutoBit64 *p = object_field_prop_ptr(obj, prop); + int value; + uint64_t mask = qdev_get_prop_mask64(prop); + + if (p->auto_bits & mask) { + value = ON_OFF_AUTO_AUTO; + } else if (p->on_bits & mask) { + value = ON_OFF_AUTO_ON; + } else { + value = ON_OFF_AUTO_OFF; + } + + visit_type_enum(v, name, &value, &OnOffAuto_lookup, errp); +} + +static void prop_set_on_off_auto_bit64(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + Property *prop = opaque; + OnOffAutoBit64 *p = object_field_prop_ptr(obj, prop); + int value; + uint64_t mask = qdev_get_prop_mask64(prop); + + if (!visit_type_enum(v, name, &value, &OnOffAuto_lookup, errp)) { + return; + } + + switch (value) { + case ON_OFF_AUTO_AUTO: + p->on_bits &= ~mask; + p->auto_bits |= mask; + break; + + case ON_OFF_AUTO_ON: + p->on_bits |= mask; + p->auto_bits &= ~mask; + break; + + case ON_OFF_AUTO_OFF: + p->on_bits &= ~mask; + p->auto_bits &= ~mask; + break; + } +} + +const PropertyInfo qdev_prop_on_off_auto_bit64 = { + .name = "OnOffAuto", + .description = "on/off/auto", + .enum_table = &OnOffAuto_lookup, + .get = qdev_propinfo_get_enum, + .set = qdev_propinfo_set_enum, + .get = prop_get_on_off_auto_bit64, + .set = prop_set_on_off_auto_bit64, + .set_default_value = qdev_propinfo_set_default_value_enum, +}; + /* --- bool --- */ static void get_bool(Object *obj, Visitor *v, const char *name, void *opaque, From patchwork Mon Jul 8 07:38:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13726255 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B5ECDC3DA45 for ; Mon, 8 Jul 2024 07:39:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQixN-0002F2-9E; Mon, 08 Jul 2024 03:38:41 -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 1sQixL-0002DI-1D for qemu-devel@nongnu.org; Mon, 08 Jul 2024 03:38:39 -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 1sQixI-00023a-Hn for qemu-devel@nongnu.org; Mon, 08 Jul 2024 03:38:38 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-70b0013cf33so2259398b3a.2 for ; Mon, 08 Jul 2024 00:38:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1720424315; x=1721029115; 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=lPZRIoBatCKfQlpKyAIr9YZsJwzc8VLAyqblnVRpsKs=; b=jEzPGejIBy6DVMW9bVNJEKpxchaujbPKa1njUmOZ6yZmYsySYIUTF9+OUF5/6QIjfO yANfghb4aSCBb28EhCZZMjBr82Vqtu9HOq2L895GwjhhXcFfVPH9WuAIqf4L/ON2fOos KtBqlX9+HYPHlyOpRFtFa+dld24oS6FAtdkSVGbCs8WKM/4cyLJ5uK3cvVMuUbdp9Q/2 ukv2HYF93YsZwJ0OB7gH0PkR26qRdCTlX75C8t9yWKTV6I3hTEujhCVlaaSQNEsLkyJ1 hBSfB8lRwwwHcfkW+uIGbavoCU0jtTRYF7lkUtBZFFhN+AUzefEaU6Y7eB111opjF5cv lk1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720424315; x=1721029115; 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=lPZRIoBatCKfQlpKyAIr9YZsJwzc8VLAyqblnVRpsKs=; b=F/czTc4pMyBfTWVO4fVZ/ZdOEtJbV5DtteioXq9bIHbdYs48TL0twh8cq0fOvSd9tS RKvLdwXx1ohl7MoHcAxmPlQ0H2NasWimPfqPfR+SHmz1TPeekHoAgXU1netxCx5zBs/4 5MZUrOJiejlanOL9QwTLkuf24GUTQHM3K9swsejv1fKBwXilTprRNRmX+e5lu1ZdNLA4 dh9dWbrE3cxPVuxc9E0ps51q9shSODj77Ex4WVV74hHiVonQ74loEPLi6NnToCD7aRSI XI3AgDiOEqna/ikwTugGAxv4V3wZG+1bQhjn3MFve7DHfTl6qClubvoH6GrlL5mNqBva u5gw== X-Gm-Message-State: AOJu0YyjOkGJ1v2a4a5QGvYu1nGu2TDRwpY4jkcH+6ls5ArlC4KJu6/s Avi4wV2v1NKjPO1x70LVDoFWl/OxQ/p6oASQsv+QDO93j9AD8Jnr+XmEpIccAdo= X-Google-Smtp-Source: AGHT+IEyKxDLII/TpyBU0Bnr+wtZHXSGAOtiFy0JAG2lBh8iUzN2k/ZXSIBnx7B526HPRTIeKs2Hrw== X-Received: by 2002:a05:6a00:13a7:b0:70a:f65e:b143 with SMTP id d2e1a72fcca58-70b00ad0f54mr9165893b3a.31.1720424314970; Mon, 08 Jul 2024 00:38:34 -0700 (PDT) Received: from localhost ([157.82.204.135]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-70b09ea7c63sm6271998b3a.168.2024.07.08.00.38.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Jul 2024 00:38:34 -0700 (PDT) From: Akihiko Odaki Date: Mon, 08 Jul 2024 16:38:07 +0900 Subject: [PATCH v2 2/4] virtio-net: Convert feature properties to OnOffAuto MIME-Version: 1.0 Message-Id: <20240708-auto-v2-2-f4908b953f05@daynix.com> References: <20240708-auto-v2-0-f4908b953f05@daynix.com> In-Reply-To: <20240708-auto-v2-0-f4908b953f05@daynix.com> To: Jason Wang , Dmitry Fleytman , Sriram Yagnaraman , "Michael S. Tsirkin" , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Andrew Melnychenko , Yuri Benditovich , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Some features are not always available, and virtio-net used to disable them when not available even if the corresponding properties were explicitly set to "on". Convert feature properties to OnOffAuto so that the user can explicitly tell QEMU to automatically select the value by setting them "auto". QEMU will give an error if they are set "on". Convert "on" to "auto" when using an old machine for compatbility. Signed-off-by: Akihiko Odaki --- include/hw/virtio/virtio-net.h | 3 +- hw/core/machine.c | 1 + hw/net/virtio-net.c | 254 +++++++++++++++++++++++++---------------- 3 files changed, 161 insertions(+), 97 deletions(-) diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 060c23c04d2d..cfa87f739248 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -178,7 +178,7 @@ struct VirtIONet { uint32_t has_vnet_hdr; size_t host_hdr_len; size_t guest_hdr_len; - uint64_t host_features; + OnOffAutoBit64 host_features; uint32_t rsc_timeout; uint8_t rsc4_enabled; uint8_t rsc6_enabled; @@ -218,6 +218,7 @@ struct VirtIONet { /* primary failover device is hidden*/ bool failover_primary_hidden; bool failover; + bool force_features_auto; DeviceListener primary_listener; QDict *primary_opts; bool primary_opts_from_json; diff --git a/hw/core/machine.c b/hw/core/machine.c index f4cba6496c84..783d3e5695d8 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -39,6 +39,7 @@ GlobalProperty hw_compat_9_0[] = { {"scsi-disk-base", "migrate-emulated-scsi-request", "false" }, {"vfio-pci", "skip-vsc-check", "false" }, { "virtio-pci", "x-pcie-pm-no-soft-reset", "off" }, + { TYPE_VIRTIO_NET, "x-force-features-auto", "on" }, }; const size_t hw_compat_9_0_len = G_N_ELEMENTS(hw_compat_9_0); diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 8f3097270869..bd285921d507 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -750,58 +750,101 @@ static void virtio_net_set_queue_pairs(VirtIONet *n) static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue); +static bool virtio_net_clear_features(OnOffAutoBit64 *features, + uint64_t clear_bits, + const char *reason, Error **errp) +{ + if (features->on_bits & clear_bits) { + error_setg(errp, "%s", reason); + return false; + } + + features->auto_bits &= ~clear_bits; + + return true; +} + static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features, Error **errp) { VirtIONet *n = VIRTIO_NET(vdev); NetClientState *nc = qemu_get_queue(n->nic); - - /* Firstly sync all virtio-net possible supported features */ - features |= n->host_features; - - virtio_add_feature(&features, VIRTIO_NET_F_MAC); - - if (!peer_has_vnet_hdr(n)) { - virtio_clear_feature(&features, VIRTIO_NET_F_CSUM); - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_TSO4); - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_TSO6); - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_ECN); - - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_CSUM); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_TSO4); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_TSO6); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_ECN); - - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_USO); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO4); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO6); - - virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT); - } - - if (!peer_has_vnet_hdr(n) || !peer_has_ufo(n)) { - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_UFO); - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_UFO); - } - - if (!peer_has_uso(n)) { - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_USO); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO4); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO6); + OnOffAutoBit64 on_off_auto_features = n->host_features; + + if (n->force_features_auto) { + on_off_auto_features.auto_bits |= on_off_auto_features.on_bits; + on_off_auto_features.on_bits = 0; + } + + on_off_auto_features.on_bits |= features; + virtio_add_feature(&on_off_auto_features.auto_bits, VIRTIO_NET_F_MAC); + + if (!((peer_has_vnet_hdr(n) || + virtio_net_clear_features(&on_off_auto_features, + BIT_ULL(VIRTIO_NET_F_CSUM) | + BIT_ULL(VIRTIO_NET_F_HOST_TSO4) | + BIT_ULL(VIRTIO_NET_F_HOST_TSO6) | + BIT_ULL(VIRTIO_NET_F_HOST_ECN) | + BIT_ULL(VIRTIO_NET_F_GUEST_UFO) | + BIT_ULL(VIRTIO_NET_F_GUEST_CSUM) | + BIT_ULL(VIRTIO_NET_F_GUEST_TSO4) | + BIT_ULL(VIRTIO_NET_F_GUEST_TSO6) | + BIT_ULL(VIRTIO_NET_F_GUEST_ECN) | + BIT_ULL(VIRTIO_NET_F_HOST_UFO) | + BIT_ULL(VIRTIO_NET_F_HOST_USO) | + BIT_ULL(VIRTIO_NET_F_GUEST_USO4) | + BIT_ULL(VIRTIO_NET_F_GUEST_USO6) | + BIT_ULL(VIRTIO_NET_F_HASH_REPORT), + "A requested feature requires the peer to support virtio-net headers.", + errp)) && + (peer_has_ufo(n) || + virtio_net_clear_features(&on_off_auto_features, + BIT_ULL(VIRTIO_NET_F_GUEST_UFO) | + BIT_ULL(VIRTIO_NET_F_HOST_UFO), + "UFO is on but the peer does not support it.", + errp)) && + (peer_has_uso(n) || + virtio_net_clear_features(&on_off_auto_features, + BIT_ULL(VIRTIO_NET_F_HOST_USO) | + BIT_ULL(VIRTIO_NET_F_GUEST_USO4) | + BIT_ULL(VIRTIO_NET_F_GUEST_USO6), + "USO is on but the peer does not support it.", + errp)) && + (virtio_has_feature(on_off_auto_features.on_bits | + on_off_auto_features.auto_bits, + VIRTIO_NET_F_CTRL_VQ) || + virtio_net_clear_features(&on_off_auto_features, + BIT_ULL(VIRTIO_NET_F_GUEST_ANNOUNCE), + "guest_announce is on but ctrl_vq is off.", + errp)))) { + return 0; } if (!get_vhost_net(nc->peer)) { - return features; + if (!ebpf_rss_is_loaded(&n->ebpf_rss)) { + virtio_clear_feature(&on_off_auto_features.auto_bits, + VIRTIO_NET_F_RSS); + } + + return on_off_auto_features.on_bits | on_off_auto_features.auto_bits; } - if (!ebpf_rss_is_loaded(&n->ebpf_rss)) { - virtio_clear_feature(&features, VIRTIO_NET_F_RSS); + if (!ebpf_rss_is_loaded(&n->ebpf_rss) && + !virtio_net_clear_features(&on_off_auto_features, + BIT_ULL(VIRTIO_NET_F_RSS), + "Both RSS and vhost are on but eBPF is unavailable; fix eBPF or disable RSS.", + errp)) { + return 0; } - features = vhost_net_get_features(get_vhost_net(nc->peer), features); + features = vhost_net_get_features(get_vhost_net(nc->peer), + on_off_auto_features.on_bits | + on_off_auto_features.auto_bits); vdev->backend_features = features; if (n->mtu_bypass_backend && - (n->host_features & 1ULL << VIRTIO_NET_F_MTU)) { + virtio_has_feature(on_off_auto_features.on_bits | + on_off_auto_features.auto_bits, + VIRTIO_NET_F_MTU)) { features |= (1ULL << VIRTIO_NET_F_MTU); } @@ -820,6 +863,12 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features, virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_ANNOUNCE); } + if ((features & on_off_auto_features.on_bits) != + on_off_auto_features.on_bits) { + error_setg(errp, "A requested feature is incompatible with vhost."); + return 0; + } + return features; } @@ -3592,7 +3641,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) int i; if (n->net_conf.mtu) { - n->host_features |= (1ULL << VIRTIO_NET_F_MTU); + n->host_features.on_bits |= (1ULL << VIRTIO_NET_F_MTU); } if (n->net_conf.duplex_str) { @@ -3604,7 +3653,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) error_setg(errp, "'duplex' must be 'half' or 'full'"); return; } - n->host_features |= (1ULL << VIRTIO_NET_F_SPEED_DUPLEX); + n->host_features.on_bits |= (1ULL << VIRTIO_NET_F_SPEED_DUPLEX); } else { n->net_conf.duplex = DUPLEX_UNKNOWN; } @@ -3614,7 +3663,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) return; } if (n->net_conf.speed >= 0) { - n->host_features |= (1ULL << VIRTIO_NET_F_SPEED_DUPLEX); + n->host_features.on_bits |= (1ULL << VIRTIO_NET_F_SPEED_DUPLEX); } if (n->failover) { @@ -3623,10 +3672,12 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) device_listener_register(&n->primary_listener); migration_add_notifier(&n->migration_state, virtio_net_migration_state_notifier); - n->host_features |= (1ULL << VIRTIO_NET_F_STANDBY); + n->host_features.on_bits |= (1ULL << VIRTIO_NET_F_STANDBY); } - virtio_net_set_config_size(n, n->host_features); + virtio_net_set_config_size(n, + n->host_features.on_bits | + n->host_features.auto_bits); virtio_init(vdev, VIRTIO_ID_NET, n->config_size); /* @@ -3753,7 +3804,9 @@ 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)) { + if (virtio_has_feature(n->host_features.on_bits | + n->host_features.auto_bits, + VIRTIO_NET_F_RSS)) { virtio_net_load_ebpf(n); } } @@ -3764,7 +3817,9 @@ static void virtio_net_device_unrealize(DeviceState *dev) VirtIONet *n = VIRTIO_NET(dev); int i, max_queue_pairs; - if (virtio_has_feature(n->host_features, VIRTIO_NET_F_RSS)) { + if (virtio_has_feature(n->host_features.on_bits | + n->host_features.auto_bits, + VIRTIO_NET_F_RSS)) { virtio_net_unload_ebpf(n); } @@ -3908,53 +3963,58 @@ static const VMStateDescription vmstate_virtio_net = { }; static Property virtio_net_properties[] = { - DEFINE_PROP_BIT64("csum", VirtIONet, host_features, - VIRTIO_NET_F_CSUM, true), - DEFINE_PROP_BIT64("guest_csum", VirtIONet, host_features, - VIRTIO_NET_F_GUEST_CSUM, true), - DEFINE_PROP_BIT64("gso", VirtIONet, host_features, VIRTIO_NET_F_GSO, true), - DEFINE_PROP_BIT64("guest_tso4", VirtIONet, host_features, - VIRTIO_NET_F_GUEST_TSO4, true), - DEFINE_PROP_BIT64("guest_tso6", VirtIONet, host_features, - VIRTIO_NET_F_GUEST_TSO6, true), - DEFINE_PROP_BIT64("guest_ecn", VirtIONet, host_features, - VIRTIO_NET_F_GUEST_ECN, true), - DEFINE_PROP_BIT64("guest_ufo", VirtIONet, host_features, - VIRTIO_NET_F_GUEST_UFO, true), - DEFINE_PROP_BIT64("guest_announce", VirtIONet, host_features, - VIRTIO_NET_F_GUEST_ANNOUNCE, true), - DEFINE_PROP_BIT64("host_tso4", VirtIONet, host_features, - VIRTIO_NET_F_HOST_TSO4, true), - DEFINE_PROP_BIT64("host_tso6", VirtIONet, host_features, - VIRTIO_NET_F_HOST_TSO6, true), - DEFINE_PROP_BIT64("host_ecn", VirtIONet, host_features, - VIRTIO_NET_F_HOST_ECN, true), - DEFINE_PROP_BIT64("host_ufo", VirtIONet, host_features, - VIRTIO_NET_F_HOST_UFO, true), - DEFINE_PROP_BIT64("mrg_rxbuf", VirtIONet, host_features, - VIRTIO_NET_F_MRG_RXBUF, true), - DEFINE_PROP_BIT64("status", VirtIONet, host_features, - VIRTIO_NET_F_STATUS, true), - DEFINE_PROP_BIT64("ctrl_vq", VirtIONet, host_features, - VIRTIO_NET_F_CTRL_VQ, true), - DEFINE_PROP_BIT64("ctrl_rx", VirtIONet, host_features, - VIRTIO_NET_F_CTRL_RX, true), - DEFINE_PROP_BIT64("ctrl_vlan", VirtIONet, host_features, - VIRTIO_NET_F_CTRL_VLAN, true), - DEFINE_PROP_BIT64("ctrl_rx_extra", VirtIONet, host_features, - VIRTIO_NET_F_CTRL_RX_EXTRA, true), - DEFINE_PROP_BIT64("ctrl_mac_addr", VirtIONet, host_features, - VIRTIO_NET_F_CTRL_MAC_ADDR, true), - DEFINE_PROP_BIT64("ctrl_guest_offloads", VirtIONet, host_features, - VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, true), - DEFINE_PROP_BIT64("mq", VirtIONet, host_features, VIRTIO_NET_F_MQ, false), - DEFINE_PROP_BIT64("rss", VirtIONet, host_features, - VIRTIO_NET_F_RSS, false), - DEFINE_PROP_BIT64("hash", VirtIONet, host_features, - VIRTIO_NET_F_HASH_REPORT, false), + DEFINE_PROP_ON_OFF_AUTO_BIT64("csum", VirtIONet, host_features, + VIRTIO_NET_F_CSUM, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("guest_csum", VirtIONet, host_features, + VIRTIO_NET_F_GUEST_CSUM, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("gso", VirtIONet, host_features, + VIRTIO_NET_F_GSO, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("guest_tso4", VirtIONet, host_features, + VIRTIO_NET_F_GUEST_TSO4, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("guest_tso6", VirtIONet, host_features, + VIRTIO_NET_F_GUEST_TSO6, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("guest_ecn", VirtIONet, host_features, + VIRTIO_NET_F_GUEST_ECN, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("guest_ufo", VirtIONet, host_features, + VIRTIO_NET_F_GUEST_UFO, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("guest_announce", VirtIONet, host_features, + VIRTIO_NET_F_GUEST_ANNOUNCE, + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("host_tso4", VirtIONet, host_features, + VIRTIO_NET_F_HOST_TSO4, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("host_tso6", VirtIONet, host_features, + VIRTIO_NET_F_HOST_TSO6, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("host_ecn", VirtIONet, host_features, + VIRTIO_NET_F_HOST_ECN, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("host_ufo", VirtIONet, host_features, + VIRTIO_NET_F_HOST_UFO, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("mrg_rxbuf", VirtIONet, host_features, + VIRTIO_NET_F_MRG_RXBUF, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("status", VirtIONet, host_features, + VIRTIO_NET_F_STATUS, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("ctrl_vq", VirtIONet, host_features, + VIRTIO_NET_F_CTRL_VQ, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("ctrl_rx", VirtIONet, host_features, + VIRTIO_NET_F_CTRL_RX, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("ctrl_vlan", VirtIONet, host_features, + VIRTIO_NET_F_CTRL_VLAN, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("ctrl_rx_extra", VirtIONet, host_features, + VIRTIO_NET_F_CTRL_RX_EXTRA, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("ctrl_mac_addr", VirtIONet, host_features, + VIRTIO_NET_F_CTRL_MAC_ADDR, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("ctrl_guest_offloads", VirtIONet, + host_features, + VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, + ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("mq", VirtIONet, host_features, + VIRTIO_NET_F_MQ, ON_OFF_AUTO_OFF), + DEFINE_PROP_ON_OFF_AUTO_BIT64("rss", VirtIONet, host_features, + VIRTIO_NET_F_RSS, ON_OFF_AUTO_OFF), + DEFINE_PROP_ON_OFF_AUTO_BIT64("hash", VirtIONet, host_features, + VIRTIO_NET_F_HASH_REPORT, ON_OFF_AUTO_OFF), DEFINE_PROP_ARRAY("ebpf-rss-fds", VirtIONet, nr_ebpf_rss_fds, ebpf_rss_fds, qdev_prop_string, char*), - DEFINE_PROP_BIT64("guest_rsc_ext", VirtIONet, host_features, + DEFINE_PROP_BIT64("guest_rsc_ext", VirtIONet, host_features.on_bits, VIRTIO_NET_F_RSC_EXT, false), DEFINE_PROP_UINT32("rsc_interval", VirtIONet, rsc_timeout, VIRTIO_NET_RSC_DEFAULT_INTERVAL), @@ -3973,12 +4033,14 @@ static Property virtio_net_properties[] = { DEFINE_PROP_INT32("speed", VirtIONet, net_conf.speed, SPEED_UNKNOWN), DEFINE_PROP_STRING("duplex", VirtIONet, net_conf.duplex_str), DEFINE_PROP_BOOL("failover", VirtIONet, failover, false), - DEFINE_PROP_BIT64("guest_uso4", VirtIONet, host_features, - VIRTIO_NET_F_GUEST_USO4, true), - DEFINE_PROP_BIT64("guest_uso6", VirtIONet, host_features, - VIRTIO_NET_F_GUEST_USO6, true), - DEFINE_PROP_BIT64("host_uso", VirtIONet, host_features, - VIRTIO_NET_F_HOST_USO, true), + DEFINE_PROP_BOOL("x-force-features-auto", VirtIONet, force_features_auto, + false), + DEFINE_PROP_ON_OFF_AUTO_BIT64("guest_uso4", VirtIONet, host_features, + VIRTIO_NET_F_GUEST_USO4, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("guest_uso6", VirtIONet, host_features, + VIRTIO_NET_F_GUEST_USO6, ON_OFF_AUTO_AUTO), + DEFINE_PROP_ON_OFF_AUTO_BIT64("host_uso", VirtIONet, host_features, + VIRTIO_NET_F_HOST_USO, ON_OFF_AUTO_AUTO), DEFINE_PROP_END_OF_LIST(), }; From patchwork Mon Jul 8 07:38:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13726254 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 27531C3271E for ; Mon, 8 Jul 2024 07:39:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQixQ-0002Oi-KL; Mon, 08 Jul 2024 03:38:44 -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 1sQixO-0002HU-6J for qemu-devel@nongnu.org; Mon, 08 Jul 2024 03:38:42 -0400 Received: from mail-il1-x12b.google.com ([2607:f8b0:4864:20::12b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sQixM-00024G-N9 for qemu-devel@nongnu.org; Mon, 08 Jul 2024 03:38:41 -0400 Received: by mail-il1-x12b.google.com with SMTP id e9e14a558f8ab-389ccd2f0abso88225ab.2 for ; Mon, 08 Jul 2024 00:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1720424319; x=1721029119; 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=iMISOcooxhdq/M4EEkPrjF33VD9e2Se2tW19e/nqD5A=; b=01OcDC/GH56aVsbwQoTZXOeMp7rHRFh5tp48FEsBiyniNDkSM1+8niFAJFT/JN9Mp/ i037rbq4H15ID9viF9UpEavOBWvvHk0jl4s6Dq8lzYywpvRKGoCDeQ4j8MNFhJKtMZnB WTXWdpiJEKtE5PuWtR47kesZPVU/5GPukHKpGYoCRwU5nQmsk8W3M1ydpbiMnAVM+oqf f5T27N/y+VqKYPfxm5ivltZZJs4wbtHmGtzFvTTFPEcnX903AmfQLxzE7C9WtCjpKNzh DGjRnk5taiGTjGfD5DeWrl6kabiHHM+Vt3SPnQ5s8gkQ1zW0+RVY2EzvLm3yXlCX+J/G j14A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720424319; x=1721029119; 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=iMISOcooxhdq/M4EEkPrjF33VD9e2Se2tW19e/nqD5A=; b=O1VHhADxZX8QvrnK7ijdllkytN3SScm33F0rOS8nssFPvKmUuaBFMKTacw8KbbefVU vr6WAaA67kwJhuoZqnBpQFHpcCbzCunOvMUx+BFO/7y6Gee5S9/Vz0rTV2rVsRGdJj1t 1FwufQPw33itkdnjodwcb8c/pqlDv1dovdya7A7hVanmsR7dBD9yBIvx4ln6mCwu1EeZ SCYkdvDeLqwTffYwzGjomPoiXWN4PTlXcAD0N7BS/c2nWEDH4LIhP5J6UW2LXrJac6+h By9fo+iL76xO3xC7kHhTxe64GERDTg01eLlm7qREXQ5jwYOlp6qASCVmjDNzP/rxGbKJ xlLQ== X-Gm-Message-State: AOJu0YzDRXVA8shifaeaK0YLc+YyX8GA7xiL6S4czadKqykx86CKk9jK 6pzSJomgSzY3cWLl4489hUUvGYR9i0mbOLh61Rsoz6HywyHsmuQBGANzrfskRVo= X-Google-Smtp-Source: AGHT+IFm7NBhoNtqECj27U/6vBgOkLLfRC9sG3hc5gnG/V00uVQhzlpJdXd71UwM1sBZH4V6kjLudw== X-Received: by 2002:a05:6e02:1d10:b0:382:b82b:6e48 with SMTP id e9e14a558f8ab-38398b02802mr131355105ab.9.1720424319664; Mon, 08 Jul 2024 00:38:39 -0700 (PDT) Received: from localhost ([157.82.204.135]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-766adeb08c9sm3739492a12.64.2024.07.08.00.38.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Jul 2024 00:38:39 -0700 (PDT) From: Akihiko Odaki Date: Mon, 08 Jul 2024 16:38:08 +0900 Subject: [PATCH v2 3/4] virtio-net: Report RSS warning at device realization MIME-Version: 1.0 Message-Id: <20240708-auto-v2-3-f4908b953f05@daynix.com> References: <20240708-auto-v2-0-f4908b953f05@daynix.com> In-Reply-To: <20240708-auto-v2-0-f4908b953f05@daynix.com> To: Jason Wang , Dmitry Fleytman , Sriram Yagnaraman , "Michael S. Tsirkin" , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Andrew Melnychenko , Yuri Benditovich , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 Received-SPF: none client-ip=2607:f8b0:4864:20::12b; envelope-from=akihiko.odaki@daynix.com; helo=mail-il1-x12b.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Warning about RSS fallback at device realization allows the user to notice the configuration problem early. Signed-off-by: Akihiko Odaki --- hw/net/virtio-net.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index bd285921d507..e779ba2df428 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -822,6 +822,10 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features, if (!get_vhost_net(nc->peer)) { if (!ebpf_rss_is_loaded(&n->ebpf_rss)) { + if (on_off_auto_features.on_bits & VIRTIO_NET_F_RSS) { + warn_report("Can't load eBPF RSS - fallback to software RSS"); + } + virtio_clear_feature(&on_off_auto_features.auto_bits, VIRTIO_NET_F_RSS); } @@ -1332,16 +1336,10 @@ static void virtio_net_detach_epbf_rss(VirtIONet *n) 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; + n->rss_data.enabled_software_rss = n->rss_data.populate_hash || + !virtio_net_attach_epbf_rss(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 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, From patchwork Mon Jul 8 07:38:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13726253 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EDE83C3DA42 for ; Mon, 8 Jul 2024 07:39:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQixY-0002Yp-9r; Mon, 08 Jul 2024 03:38: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 1sQixU-0002US-Hd for qemu-devel@nongnu.org; Mon, 08 Jul 2024 03:38:49 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sQixR-00024j-H3 for qemu-devel@nongnu.org; Mon, 08 Jul 2024 03:38:46 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1faad2f1967so30926705ad.0 for ; Mon, 08 Jul 2024 00:38:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1720424324; x=1721029124; 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=9K8hP6K+GS49iC8TK1k5qVM0FxyjSx6s74AXBMFGPSk=; b=LQgyoSZ0x1Pcl/OBRrsLg2I1HICdYfK2N0vNJCjbmk5RDmnbDPBKHjpr5P7s3EdfRL bAzyYd9m5AFAIytdQSaHN4PEpQ3pAjDYwTiEAIbWwnL75smn3sLw9snSW/rZQdAb0H9V RG7pL6OiQzq+CBE1ohKzldELf17b5GtdQAWuGEXWYxTap2HRrLLKvYUFsZVZOTqn7uXX rwm9JwVUT4BQVtnIi6/VwQ7RFepWVNmVaxa2bF956i/a2sgyU1LChD+E8PItDJgQkNkE b8e5eaLW9aAiYWKa62bC66XykDk3KK+bPDAwZ53RyXNL1gtIPMtUZ0SJy3wB86gfRcDi rZSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720424324; x=1721029124; 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=9K8hP6K+GS49iC8TK1k5qVM0FxyjSx6s74AXBMFGPSk=; b=a8/xutBNMPDgf+eOxEhbUjScD3CTCu2JQ2jG+AFE112ArCwKaBZdZAFPKXRfW6GU85 YYjr9ZtI9wBxpKiI20XtaNzbt7bb7IMiTrfUladqgMKlhEYwGfJXZa7j1PdprKPfUqor Et8HNkJMnBScwmyLKpU+VHTelhz682VO2U6+bnMZBj+5X9wWfwF7PvBpLnZs3VZaf+Qd +nzkb3oOjQikVjResAKUaWakWS244P35PZVe8pFVZPpFTloz28uSaGJTqKZ7eXApX2uJ 9+c5n9Ud92+Fu+Bkn6JwJRlPH79bbOxPTDgE/T+tt1Pz95HZ01ESRc5TrnWVJqHyKJuG d3QA== X-Gm-Message-State: AOJu0YxZmCxneEVLUr/jmZBt50s38hK2kjan9SeE6NOX9yYvt8CwvARk pfL0DlK9C+eUfM70iecqOsJzv2T/PoL1jMq5ZcuRpiWfP53uQ02KILP7ZlttKdA= X-Google-Smtp-Source: AGHT+IHHodxy70yX/X4yIg+q4E7xiYuu2R0cRm6EhFPHT5v2EIpIT9J4Z8+lWDBPcu9xPgcfDmKQHQ== X-Received: by 2002:a17:903:110c:b0:1f9:a69d:4e05 with SMTP id d9443c01a7336-1fb370562a6mr159128765ad.19.1720424324096; Mon, 08 Jul 2024 00:38:44 -0700 (PDT) Received: from localhost ([157.82.204.135]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-1fb526a67ecsm50805975ad.150.2024.07.08.00.38.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Jul 2024 00:38:43 -0700 (PDT) From: Akihiko Odaki Date: Mon, 08 Jul 2024 16:38:09 +0900 Subject: [PATCH v2 4/4] virtio-net: Remove fallback from ebpf-rss-fds MIME-Version: 1.0 Message-Id: <20240708-auto-v2-4-f4908b953f05@daynix.com> References: <20240708-auto-v2-0-f4908b953f05@daynix.com> In-Reply-To: <20240708-auto-v2-0-f4908b953f05@daynix.com> To: Jason Wang , Dmitry Fleytman , Sriram Yagnaraman , "Michael S. Tsirkin" , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Andrew Melnychenko , Yuri Benditovich , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Eduardo Habkost Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 Received-SPF: none client-ip=2607:f8b0:4864:20::636; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x636.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org If ebpf-rss-fds is specified but we fail to use, we should not fall back to loading eBPF programs by ourselves as such makes the situation complicated. Suggested-by: Daniel P. Berrangé Signed-off-by: Akihiko Odaki --- hw/net/virtio-net.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index e779ba2df428..075c91f037d1 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1396,15 +1396,9 @@ exit: static bool virtio_net_load_ebpf(VirtIONet *n) { - bool ret = false; - - if (virtio_net_attach_ebpf_to_backend(n->nic, -1)) { - if (!(n->ebpf_rss_fds && virtio_net_load_ebpf_fds(n))) { - ret = ebpf_rss_load(&n->ebpf_rss); - } - } - - return ret; + return virtio_net_attach_ebpf_to_backend(n->nic, -1) && + (n->ebpf_rss_fds ? virtio_net_load_ebpf_fds(n) : + ebpf_rss_load(&n->ebpf_rss)); } static void virtio_net_unload_ebpf(VirtIONet *n)