From patchwork Sun Jul 14 05:11:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13732572 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 1F833C3DA42 for ; Sun, 14 Jul 2024 05:12:35 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSrVz-00078i-6j; Sun, 14 Jul 2024 01:11:15 -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 1sSrVy-00074f-4O for qemu-devel@nongnu.org; Sun, 14 Jul 2024 01:11:14 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sSrVw-00051R-Iy for qemu-devel@nongnu.org; Sun, 14 Jul 2024 01:11:13 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-70af5fbf0d5so2030798b3a.1 for ; Sat, 13 Jul 2024 22:11:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1720933871; x=1721538671; 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=NMhK6uTuK57+JHZcNgmphmlNuH9qRfUm5a2X1fq84kE=; b=GSydNIGoNYgC6UkhEVbRefSqx2+noEV5uh5yTGXrUxGXvZBAqUiRcAVtPyKaOs4wxC fLmmusNVYM+eRKsfN56IVCFAAAjGHCyPqt/6hxSoOMcAewVPsMeWY1rFaUex7qqVAuxv p1awfs9wU/APW4Fr17DqrGi6Ubx+FpPgbMUsUEwPCllq9hfHwkZr2lITMTsFr1DEBHGR /qAJhDaN+4NKZXG0CzA7kPQBIpFiNk+z7t8Bn9QpS5UZrnT0AtLGi60Nlla7P4fwY0E/ C8xW/0u/xIA1diO0L8FThKeqoM3DT23FDoo4QKcj0Uldiqyk8o0QI/dJijEdPGYf6xH5 kSRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720933871; x=1721538671; 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=NMhK6uTuK57+JHZcNgmphmlNuH9qRfUm5a2X1fq84kE=; b=eag8aTJfznlwYWMUt3T1vo51Ncvml8lOs9rWWEum7bQBA2nqS4mhgYBbU3CSo+iFLr 7dCNXYEsCfHuy/7ekkId/RTBQk5befbVObKQA0ji8xvVDqT7EWzX94g2hxaU7VyVresS /yhio84UswpOri40UuQe4ShiVy9XnmVAu++nNSJqoaK7UkVAL8dgoQkbIlSy999mz28O Ai1FLTfSTci+Fir92vRnagdz9Pg0ksIbYxOmmAp6NG2h1Bcxzvly6uD+QWln1QbYFls3 j32NFzLvnai3yort+zOmqVJTCrxGWWumAigZgL2TV9XuoyJ3wO8n6CQLFvlYOEp7Zxcs GAbg== X-Gm-Message-State: AOJu0YwNPkYe5+l8Wn1yEKse28jcC9EZBQaOnh+odm2suAYClOlDwQxP u9HQ7ySus6QQZxUHBimuTbnPhCqACUtiNXLyhVeG1JhI4daQxo86+tK/lUvm7jI= X-Google-Smtp-Source: AGHT+IHAo03g0sPpBc4/5So4xvFiCA2GnIm/aTyr3gHmheaswAE6OV8f6hrDjQQX3VNfH2b9gqySRw== X-Received: by 2002:a05:6a00:391e:b0:70b:5368:a212 with SMTP id d2e1a72fcca58-70b6cbb6c93mr10562067b3a.15.1720933871243; Sat, 13 Jul 2024 22:11:11 -0700 (PDT) Received: from localhost ([157.82.204.135]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-70b7eba4540sm1988789b3a.43.2024.07.13.22.11.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 13 Jul 2024 22:11:10 -0700 (PDT) From: Akihiko Odaki Date: Sun, 14 Jul 2024 14:11:01 +0900 Subject: [PATCH v3 1/5] qdev-properties: Accept bool for OnOffAuto MIME-Version: 1.0 Message-Id: <20240714-auto-v3-1-e27401aabab3@daynix.com> References: <20240714-auto-v3-0-e27401aabab3@daynix.com> In-Reply-To: <20240714-auto-v3-0-e27401aabab3@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::42b; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42b.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 Accept bool literals for OnOffAuto properties for consistency with bool properties. Signed-off-by: Akihiko Odaki --- hw/core/qdev-properties.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c index 86a583574dd0..f0a270bb4f61 100644 --- a/hw/core/qdev-properties.c +++ b/hw/core/qdev-properties.c @@ -491,6 +491,21 @@ const PropertyInfo qdev_prop_string = { .set = set_string, }; +static void set_on_off_auto(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + Property *prop = opaque; + int *ptr = object_field_prop_ptr(obj, prop); + bool value; + + if (visit_type_bool(v, name, &value, NULL)) { + *ptr = value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF; + return; + } + + qdev_propinfo_set_enum(obj, v, name, opaque, errp); +} + /* --- on/off/auto --- */ const PropertyInfo qdev_prop_on_off_auto = { @@ -498,7 +513,7 @@ const PropertyInfo qdev_prop_on_off_auto = { .description = "on/off/auto", .enum_table = &OnOffAuto_lookup, .get = qdev_propinfo_get_enum, - .set = qdev_propinfo_set_enum, + .set = set_on_off_auto, .set_default_value = qdev_propinfo_set_default_value_enum, }; From patchwork Sun Jul 14 05:11:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13732569 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 CE28FC3DA49 for ; Sun, 14 Jul 2024 05:12:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSrWE-0007LL-FA; Sun, 14 Jul 2024 01:11:31 -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 1sSrW4-0007JH-5M for qemu-devel@nongnu.org; Sun, 14 Jul 2024 01:11:21 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sSrW1-00051y-Fn for qemu-devel@nongnu.org; Sun, 14 Jul 2024 01:11:18 -0400 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1fb4a807708so29271285ad.2 for ; Sat, 13 Jul 2024 22:11:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1720933876; x=1721538676; 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=gsn8jpde5vwnK4glFB3pIQsd6ePaO9NWMI60GGv1GCU=; b=dnJ0gOhgISgSswEWWuTQHQu1Wp6/OW9RVxe5TsoJ/Vccq0et6ut19+cDI551ffKKS+ FgOGBb1thZ0rFM+flvR+Lcvjo7IlWSwzgdV76Od5cq7wlM4ek51LXSZKAaAPqM3e57/1 AaJeaVwK24gkgKtur3meyPn/0koVq2R2mZCJuMn0ugUV+eT1As/65O7qHii6lzIe50qL Hj/ycNXVZMCSGeZy4d6vwc8zFHMk3TZ8Ewlhucgwn6YsN3qTexeWbS/3KKO7qvZtvM3/ irnHmxGCQbk1/eNUT/ZkAG64r40/UoyhVsEGVO62qtTiYu5YPYsrja7kGQbIAjFh/nDJ 3plg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720933876; x=1721538676; 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=gsn8jpde5vwnK4glFB3pIQsd6ePaO9NWMI60GGv1GCU=; b=jrfpYKmilqsa8o1ioRllugqAeXcpQ7sNOLQpG1oW+wZNPGiUDL9LIZdVO1Bo9vmVNP F5YY/k/PCIcQxWljYCl21BaHJ+nEpjBmY/4M/EQe16SrwrMezts8fXkH5BYlOdf3j6Cy nDpO5ASqjdYu+nhX0/1kSCcF2saijWGQVwjjKgKOhI+lNwJrx7zMHP1g32ecyjYu4pYc Hhq2R0IG95wjhmhvFGodge2BQXADWvu5ZGUparQotf5iI6fM33NWUitWeGNMfvCF6ypp oOIaZAI9zkQkItriVj0tph6Z7y3eEb3LeJtnBdwdSXDBC33eRMqnVVblRwfNSXaCYtk5 SnBw== X-Gm-Message-State: AOJu0YxTstl3vq0GGaZGcEV5ZZbzqB/BZ5ULx8A90Jh2585lVE4Wn2JU hlrk3jrD7B7/24SsQ4mhAlY4ekF8piAlLHLrkoRvJewrSNNeaMjI5gTMdlol+i8= X-Google-Smtp-Source: AGHT+IH3EBrhk+JbKV6OPWC33Q5kJgU369sgVZV7MCI845M7gR8y5gKhkWctiuVldR06nk+OsWsSqQ== X-Received: by 2002:a17:902:d48d:b0:1fb:4fa4:d20 with SMTP id d9443c01a7336-1fbb6d59ed0mr169541645ad.38.1720933876122; Sat, 13 Jul 2024 22:11:16 -0700 (PDT) Received: from localhost ([157.82.204.135]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-1fc0bc44f5fsm17760665ad.238.2024.07.13.22.11.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 13 Jul 2024 22:11:15 -0700 (PDT) From: Akihiko Odaki Date: Sun, 14 Jul 2024 14:11:02 +0900 Subject: [PATCH v3 2/5] qdev-properties: Add DEFINE_PROP_ON_OFF_AUTO_BIT64() MIME-Version: 1.0 Message-Id: <20240714-auto-v3-2-e27401aabab3@daynix.com> References: <20240714-auto-v3-0-e27401aabab3@daynix.com> In-Reply-To: <20240714-auto-v3-0-e27401aabab3@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::630; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x630.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 | 66 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 83 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 f0a270bb4f61..cc76ff0dfae6 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,69 @@ 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); + bool bool_value; + int value; + uint64_t mask = qdev_get_prop_mask64(prop); + + if (visit_type_bool(v, name, &bool_value, NULL)) { + value = bool_value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF; + } else 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 = 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 Sun Jul 14 05:11:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13732571 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 D2687C3DA4D for ; Sun, 14 Jul 2024 05:12:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSrWJ-0007RR-8K; Sun, 14 Jul 2024 01:11:37 -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 1sSrWA-0007KF-G2 for qemu-devel@nongnu.org; Sun, 14 Jul 2024 01:11:27 -0400 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sSrW5-00052O-Np for qemu-devel@nongnu.org; Sun, 14 Jul 2024 01:11:26 -0400 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-7f684af6af1so178616639f.2 for ; Sat, 13 Jul 2024 22:11:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1720933880; x=1721538680; 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=sQexyZuINSTJ3AusHlkv3xg34rU/3qwaQ/Y93A7p2axu+wiT/sp54LjTpeHvgFquIH LyVphRxVkJWt7VV2YbT1UozJ0qFv3QqG6nRmXsVzGTwtFw4uQ7w0TzhEEp+kDI3tyood /Pwf17XDvqw0h9f5cR76Dlx7r1TxaM9SLMRyGUPJQpvNmolXP81DKZapr9Hv0WrFfn/i 8oWV+f9Dz7fgPAM6D64GEcTm+YPe+jCKOjbPI9Z4er9Xi51b39bLlGi8QWDPTq4sxX6Q mQbxApZZS7pEerwUo/a8mBRIebAOhgIu2hp0Gmr3nH/LPzBWF8CqrYtwhM5fFkZr/ePs hDpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720933880; x=1721538680; 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=w0cCXX2e0y9IXs7YP15XzdcMx9atuqgh2QNbMP8117q8yrERia0u60BGtaDcaxXim2 7xlcu5Exz+eSafCgr4iYfyDrcmLh0ze9VXCvDyEuMyvHNCylv0IkxawCXCnYuYozmpFK NSlU5wYPNXHIU2co376RpLuYVu3cklmPwPT6pQXKxb2xm2FIHb1WkJwmiuzh7uITpgMR 1WBcXTsyjDVB+KJl3GzLHepLeGc0XbLs/Mrz2GPBeWOXTi0M/Nl0kkp1RbgbkuEt/G2+ RApHzGCx32GTRnOJ7Gg+eqzYhqkMrvKF48/dnUg2RAiQUZolaMKni8aOu1I/bvenee9R RyYQ== X-Gm-Message-State: AOJu0YwmzdCNvCPKXliUvW/fvRT3+hSeBOga8cFDkycfNVwBhmhIutZL 3CS9pAjOxJDmYVd1RQKGX4fujZ7s/06whGaJ38YyvZBD4h0AZLOl5DR7qd6hqwA= X-Google-Smtp-Source: AGHT+IGPCPVJOQ5Ec5n5V10C5hBtrKucO4MLzP6djBGNnlfQ2GeqmBybmv+zG01g0/hsYPH6iri7gQ== X-Received: by 2002:a92:c54f:0:b0:375:c240:e7a6 with SMTP id e9e14a558f8ab-38a5a0798b7mr194434845ab.24.1720933880422; Sat, 13 Jul 2024 22:11:20 -0700 (PDT) Received: from localhost ([157.82.204.135]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-78e32b6ba67sm1490300a12.11.2024.07.13.22.11.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 13 Jul 2024 22:11:20 -0700 (PDT) From: Akihiko Odaki Date: Sun, 14 Jul 2024 14:11:03 +0900 Subject: [PATCH v3 3/5] virtio-net: Convert feature properties to OnOffAuto MIME-Version: 1.0 Message-Id: <20240714-auto-v3-3-e27401aabab3@daynix.com> References: <20240714-auto-v3-0-e27401aabab3@daynix.com> In-Reply-To: <20240714-auto-v3-0-e27401aabab3@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::d35; envelope-from=akihiko.odaki@daynix.com; helo=mail-io1-xd35.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 Sun Jul 14 05:11:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13732573 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 C376BC3DA49 for ; Sun, 14 Jul 2024 05:15:31 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSrWL-0007WE-B4; Sun, 14 Jul 2024 01:11:37 -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 1sSrWB-0007KN-Ax for qemu-devel@nongnu.org; Sun, 14 Jul 2024 01:11:27 -0400 Received: from mail-oi1-x22c.google.com ([2607:f8b0:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sSrW9-00053n-Pt for qemu-devel@nongnu.org; Sun, 14 Jul 2024 01:11:27 -0400 Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-3d9de9f8c8dso1959010b6e.1 for ; Sat, 13 Jul 2024 22:11:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1720933885; x=1721538685; 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=sT8dVCtaipDIYjcxHAodLV8rq0WgHgXWuPCia4ZvmEjhxdcQBiX0nVYM5oRfNrqVSf hyx7aHjjbOTqesc+BJZTGAjqqCnLQRaCGZ2JMgwAY2tg0QJz/ymuuv84cRWKeHuaC3yb fPW52ZPOcvZdYVnE/PBJUGBi+7CLnku7/574yviBqZE4HOGnitKN029/4TEsJ6Pm7C7+ grzO6riaMSwIkFL5/VfJ0wtmJ4ETBhmRQTVn8hYwaBE9uic3pcrQWcAJY+ycORhXNFiL aELVY8wsg2jIkfTjoFsF51l1n3goRl/SkZxaoPNzWPCZKQurkjm9sodqXtI25d9VvbE3 GnhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720933885; x=1721538685; 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=tio8tN9cKrDra+DxtNKy486XtkSajdJirHqlckkNiCpDZDX3llp5nA23fk1BbOIGNf 4fX66GjVbBbijbXpDJ7XHHXcz7eiyX0ELYaKB2W44sdjrh8J8LK33Q+Bcu2HRuD/YSuP Dmz11AHZ1BwlEQLly/7wtIRDI++N8JCPPdTjpQhWTXCqH8Y/5zkJubT/niAzsp0qoPMM Ed4wcLYtzSzjSORGjjSMWyNxLB12JqrK1PNWVKWqnpGz47tIwK3Cw6jQS6iZw0bfGLNA c1OkIc/GQnq56rSltOA3s3uDQN4mSa9gdqVIde72DjhD3qeZ9kbFE0TTw/Fm2Vk2zJPq Up/g== X-Gm-Message-State: AOJu0YzI/gF9w74vDUU7j8VJ08LyDktv0E7PZOaLpuV8AVvhRH1+esNo 0f4c3qTfCInUeoYrTCK6pxahq2dFgI9ujUWWkyoNWyUgbURiLv+BzhfqtXNHcrM= X-Google-Smtp-Source: AGHT+IEJj5q72576lLxdMdfvH2pVGOK+BiUff5b/yEBelDxtKAmy2Qzy61PsRrXu6N+RBJY+XjLBiA== X-Received: by 2002:a05:6808:189d:b0:3da:a032:24a6 with SMTP id 5614622812f47-3daa032397amr13335005b6e.19.1720933884777; Sat, 13 Jul 2024 22:11:24 -0700 (PDT) Received: from localhost ([157.82.204.135]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-70b7ec7d2bcsm2048768b3a.99.2024.07.13.22.11.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 13 Jul 2024 22:11:24 -0700 (PDT) From: Akihiko Odaki Date: Sun, 14 Jul 2024 14:11:04 +0900 Subject: [PATCH v3 4/5] virtio-net: Report RSS warning at device realization MIME-Version: 1.0 Message-Id: <20240714-auto-v3-4-e27401aabab3@daynix.com> References: <20240714-auto-v3-0-e27401aabab3@daynix.com> In-Reply-To: <20240714-auto-v3-0-e27401aabab3@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::22c; envelope-from=akihiko.odaki@daynix.com; helo=mail-oi1-x22c.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 Sun Jul 14 05:11:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13732570 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 30AA0C3DA50 for ; Sun, 14 Jul 2024 05:12:14 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSrWM-0007bz-11; Sun, 14 Jul 2024 01:11:38 -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 1sSrWF-0007Nm-RO for qemu-devel@nongnu.org; Sun, 14 Jul 2024 01:11:33 -0400 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sSrWE-00054Z-By for qemu-devel@nongnu.org; Sun, 14 Jul 2024 01:11:31 -0400 Received: by mail-oi1-x22f.google.com with SMTP id 5614622812f47-3d9db222782so1970458b6e.3 for ; Sat, 13 Jul 2024 22:11:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1720933889; x=1721538689; 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=4cfAZs9gcmRBQAfP5MoBvIZbiyJezK58nIuVHbTQt3E=; b=nmN01QC+i2TmW50HmFRYof4EWvWf56TlnCfXuYO7DtLXGVwkJWyoDqWuA/fIbybfav LTTZn5mB5G4+ckrfypmk1OTkiBI5miS5nkjCiip0nuO+0o+xXs6XL+qh1ERGa2N0DOP6 vxeC4eoMtcGexZsfSfxbtIyuydmdeNZPiSXOF/f1ZEi57N5/qdPnMNO8JEOgBLFML3iq 2KfixsAy0TcFbujGV6tzn8rvkACmhhzSU0yXlKibU61z9+Nqy1543+okTX3wRR1fDwI+ ZKOS7h3OGEXc4XlS3JtFKPHIdtFIMzT+KL6Y0KcEOYGjJpsE5Qd8dh1nRL+ryb2uTlBc LrnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720933889; x=1721538689; 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=4cfAZs9gcmRBQAfP5MoBvIZbiyJezK58nIuVHbTQt3E=; b=hYYI52yEK6Q3Te48THRDKKr9JCUeRO80HR3HsvLUM+1cvqGKN7VmF9vzcRNm3NeSHH AmpAl/1H8U+INuUZkZjcyh9WXF7nBAQZ1j6gQYYoTNV6ZoTkwsMJitG56F4XbwjJrnYN iZ9kTbK+5xl7VA3pPhaoXotEUO5exaCcadBt2L/ab4Yd9/g2OISr2FfSiHqHEQv+HeQz TPIlFtKeMzoTK4gCvf5LLfJ+FPp/gjRcVSGq+vUWHkWCuV5CNyzOtC8yTseBLjYd7BL+ pipD4CnCraXnw7VsLlDDA7G/ljJQLPW5AaIh9pmHx+0r2a1daQ/ZE3KDSXuij6RwbVua CyXQ== X-Gm-Message-State: AOJu0Yx+W5eeaXCRgwo41b2kIHw9Uz/Kf2/JH5zCPxAIKEeMIcrBcypC DeS+abXu6fPgeg1APLCuB1AXonqqRYZo/TkDXt/RGurRQmoZlR636Y1EG3ygyuM= X-Google-Smtp-Source: AGHT+IFkXgADrSYg1RyLJr4YABin1ixkWJpJRXbaB90TFqgaot5y98YF1Mjin56f/JHbYT/0pGjqyg== X-Received: by 2002:a05:6808:1311:b0:3d9:2562:7541 with SMTP id 5614622812f47-3d93c01f75dmr20053472b6e.24.1720933889093; Sat, 13 Jul 2024 22:11:29 -0700 (PDT) Received: from localhost ([157.82.204.135]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-70b7eca64b1sm2074373b3a.143.2024.07.13.22.11.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 13 Jul 2024 22:11:28 -0700 (PDT) From: Akihiko Odaki Date: Sun, 14 Jul 2024 14:11:05 +0900 Subject: [PATCH v3 5/5] virtio-net: Remove fallback from ebpf-rss-fds MIME-Version: 1.0 Message-Id: <20240714-auto-v3-5-e27401aabab3@daynix.com> References: <20240714-auto-v3-0-e27401aabab3@daynix.com> In-Reply-To: <20240714-auto-v3-0-e27401aabab3@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::22f; envelope-from=akihiko.odaki@daynix.com; helo=mail-oi1-x22f.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 | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index e779ba2df428..2f0a4f2aabf7 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1361,21 +1361,21 @@ static void virtio_net_disable_rss(VirtIONet *n) virtio_net_commit_rss_config(n); } -static bool virtio_net_load_ebpf_fds(VirtIONet *n) +static bool virtio_net_load_ebpf_fds(VirtIONet *n, Error **errp) { int fds[EBPF_RSS_MAX_FDS] = { [0 ... EBPF_RSS_MAX_FDS - 1] = -1}; int ret = true; int i = 0; if (n->nr_ebpf_rss_fds != EBPF_RSS_MAX_FDS) { - warn_report("Expected %d file descriptors but got %d", - EBPF_RSS_MAX_FDS, n->nr_ebpf_rss_fds); + error_setg(errp, "Expected %d file descriptors but got %d", + EBPF_RSS_MAX_FDS, n->nr_ebpf_rss_fds); return false; } for (i = 0; i < n->nr_ebpf_rss_fds; i++) { fds[i] = monitor_fd_param(monitor_cur(), n->ebpf_rss_fds[i], - &error_warn); + errp); if (fds[i] < 0) { ret = false; goto exit; @@ -1394,17 +1394,11 @@ exit: return ret; } -static bool virtio_net_load_ebpf(VirtIONet *n) +static bool virtio_net_load_ebpf(VirtIONet *n, Error **errp) { - 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, errp) : + ebpf_rss_load(&n->ebpf_rss)); } static void virtio_net_unload_ebpf(VirtIONet *n) @@ -3805,7 +3799,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) if (virtio_has_feature(n->host_features.on_bits | n->host_features.auto_bits, VIRTIO_NET_F_RSS)) { - virtio_net_load_ebpf(n); + virtio_net_load_ebpf(n, errp); } }