From nobody Tue Oct 22 23:27:31 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=1729572681; cv=none; d=zohomail.com; s=zohoarc; b=TSFppyHvTgDJgOhKXfaDEh6MPfbtxl+scSTV2dJCsdJUG9Y3V0fMa851C3xgjRA+fBMXOdIkvUjRUJwIwwipiGJoW6W5cTQK3oQOc7L4dFISukzPK9dl+h2dw0oz69+vwYNcYz+DK1AC98U5iQp5Bzf77NY2+sn0cyQs48shdGs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729572681; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vf5mc+JebpfS8OAvWe8RuE/C+y1x64JofpC/2Ctgm78=; b=RuDTQjnGIBCSkCrrRPnIrHPNzr9Psp7YFs01iDN6CvTiPzHUj+8vIwXKgAOvqY6JdNt9r21kD/uTz4ctePcEQxy8Q86Nn/tU3TVWBS01POlcnpuwWzmZhcAMZkQhJUtU/pEZX8i8ziV2wEduO+6GGlBVOsJi0PXXLiAuyk4eBnQ= 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 1729572681170716.7472637987433; Mon, 21 Oct 2024 21:51:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t36rI-00024q-6y; Tue, 22 Oct 2024 00:51:05 -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 1t36r9-000234-MH for qemu-devel@nongnu.org; Tue, 22 Oct 2024 00:50:56 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t36r8-0008R0-0n for qemu-devel@nongnu.org; Tue, 22 Oct 2024 00:50:55 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-20cb7139d9dso46825645ad.1 for ; Mon, 21 Oct 2024 21:50:53 -0700 (PDT) Received: from localhost ([157.82.202.230]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-20e7f0f6d1bsm34158575ad.292.2024.10.21.21.50.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Oct 2024 21:50:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1729572652; x=1730177452; 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=vf5mc+JebpfS8OAvWe8RuE/C+y1x64JofpC/2Ctgm78=; b=lO3DdG69Rp0QgQPmV4El6N6B7NmWhpRwUYQurIaBhYMYNDgg61Q7RcyEhBMBauBsBa H1UaF0yf+19i3iVrf0D4uHj2QdTLeavUqSaZ2Uq4SHj2vdsAUsNmGtIzz3l5Ui3nubC/ b58QUdVYV9GgeJ/wLgz2Dwn8gjgQoxdueFE21KOWcAxWQ0ruwL2WWBt3/5pwyhvYwF6q G4Syk5XucAqIru5HmhPUrgi58PIwD4Ofkw3LVqzcxozXC/0eivKX5dM8Qd/dItEHEDUB NQuHm5DGTEEE0pFrpfMXs85moCKoe/rRjuT7gcPZ/ljPOZ9lPO9uGe9YSze0SdK+AR21 Wy+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729572652; x=1730177452; 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=vf5mc+JebpfS8OAvWe8RuE/C+y1x64JofpC/2Ctgm78=; b=HIWn07gzLTntfPFP6A/TMlz+ogt/y3W0/qF7RfClM6eNkJS/ZMkcvQh0YoiXGHoa4c WCGhz8XUOC6hELF3ijDlUzVPrcTIrkvhjmbQe9X+HeOJ3hDGgPw2JBIl1RQoSRm1agp4 eTB1cg9hw8ncVeKn+ed+KNGpGlw3Xw0Yx/OPsAgBTefOXBaE4d9iRKrZxG07/CuTPYF2 nux/XpS/qEfQSo7ELurhLaZoAQh2dG/CKBIeYEoi25B/C4FR5Ki1n1bYripZMg0ZHr/I Smx0YWyRUgEvzE/sTUgDva7Axzm/ZFWvpmkc6ca02ayD2zYzdT1qhtyJZsh6HwOH7NJ/ Rvbw== X-Gm-Message-State: AOJu0Yw1ExhSHgtjmkuiWfbKLkGvjiz8zebQZYBf5YGlnMhbb0k/v9Q1 oXKWPnYILbZRGhNix+nthcjTkCFiDeiZlhLa9QgvLWdFQgThgB0UiCRCYhkad8E= X-Google-Smtp-Source: AGHT+IHHW5QHFZLwhGcyEWmIyiMIsQIYxScquDd4gvYSnJsfatXfWJifgfYy3uxfvdrKQL/urprhpg== X-Received: by 2002:a17:902:ce89:b0:20c:f648:e3a7 with SMTP id d9443c01a7336-20e5a91b7a7mr177011575ad.50.1729572652658; Mon, 21 Oct 2024 21:50:52 -0700 (PDT) From: Akihiko Odaki Date: Tue, 22 Oct 2024 13:50:38 +0900 Subject: [PATCH v2 1/3] qdev-properties: Accept bool for OnOffAuto MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241022-virtio-v2-1-b2394236e053@daynix.com> References: <20241022-virtio-v2-0-b2394236e053@daynix.com> In-Reply-To: <20241022-virtio-v2-0-b2394236e053@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: 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::633; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x633.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729572683407116600 Accept bool literals for OnOffAuto properties for consistency with bool properties. This enables users to set the "on" or "off" value in a uniform syntax without knowing whether the "auto" value is accepted. This behavior is especially useful when converting an existing bool property to OnOffAuto or vice versa. 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 =3D { .set =3D set_string, }; =20 +static void set_on_off_auto(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + Property *prop =3D opaque; + int *ptr =3D object_field_prop_ptr(obj, prop); + bool value; + + if (visit_type_bool(v, name, &value, NULL)) { + *ptr =3D value ? ON_OFF_AUTO_ON : ON_OFF_AUTO_OFF; + return; + } + + qdev_propinfo_set_enum(obj, v, name, opaque, errp); +} + /* --- on/off/auto --- */ =20 const PropertyInfo qdev_prop_on_off_auto =3D { @@ -498,7 +513,7 @@ const PropertyInfo qdev_prop_on_off_auto =3D { .description =3D "on/off/auto", .enum_table =3D &OnOffAuto_lookup, .get =3D qdev_propinfo_get_enum, - .set =3D qdev_propinfo_set_enum, + .set =3D set_on_off_auto, .set_default_value =3D qdev_propinfo_set_default_value_enum, }; =20 --=20 2.47.0 From nobody Tue Oct 22 23:27:31 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=1729572732; cv=none; d=zohomail.com; s=zohoarc; b=Yrz+VXWjcTuBqxexlO02FiXVeXqmhO7IK5nOtTIGRhmLTJoFVBatYmW1wSHY4WmHc5Kk+5OuMUwfZrqvuq0CV0ZVoYiMJGyb7MxdQ1DjfDFNGyhyHKQLP4vsPzBChApDeioim5tHdFhMsW3ebeX2PLxVgveedAhx3oD/trrK0WU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729572732; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=V2/uTnhQm3uWPtccTag7eHWITcu21fyM4nMyI465zyg=; b=Q2IuUYtkoM0w2/DdeeSoZZ4N/+06fx3LQTWcPpSf1pNpX+NjMPfRij8+5SJ6H9/hUMmEYZd9j5sFsqg4gis+R+vs3zsez+j8lInjxXuRvYTdEyZnC8Bd7EAw8uJv/BG7BFqKGE+brEWjd0+UVRyd26MOjuLhO2yK++fk0Jujab4= 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 1729572732378897.6388466853292; Mon, 21 Oct 2024 21:52:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t36rP-00028p-Dv; Tue, 22 Oct 2024 00:51:12 -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 1t36rF-00024J-6d for qemu-devel@nongnu.org; Tue, 22 Oct 2024 00:51:02 -0400 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t36rC-0008RN-PL for qemu-devel@nongnu.org; Tue, 22 Oct 2024 00:51:00 -0400 Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-83ac4dacaf9so96716439f.2 for ; Mon, 21 Oct 2024 21:50:58 -0700 (PDT) Received: from localhost ([157.82.202.230]) by smtp.gmail.com with UTF8SMTPSA id 41be03b00d2f7-7eaeaafbba8sm4007307a12.18.2024.10.21.21.50.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Oct 2024 21:50:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1729572657; x=1730177457; 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=V2/uTnhQm3uWPtccTag7eHWITcu21fyM4nMyI465zyg=; b=20ZkUuaAIlHPV7BSQatwsnPuyyfCDiNQ2nzfEIRIx5HSuuVY0ikBCfcdcjK2Gm8Hd6 63bUQPDXOZ0EBrHw5gx/VcwMZ1zTVHvpez+7LNU9g3vb9cXwb0WTUSkjafwhkP2uKHQK vd9fxsZvF3dOXVItaq9480A+rD9zGgXs5tpJpsGpd46kSXOu3B2VZ6GQ5CP3tPAaXGc4 kGdkNhRGpBV+wzZWo3sexQ7RLHBT4v0wZHEf3SSiNfqe1fudYkt4SP6gbDXtx6qQaKAK 17HanQW0x5Y9mnnVb2aImU/XrGkqkLxXeKQOJVr0kVqbd3259ih26dThy9n0rfEEu8DH JGMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729572657; x=1730177457; 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=V2/uTnhQm3uWPtccTag7eHWITcu21fyM4nMyI465zyg=; b=OpIYjHJUk/vIvMERRRqRlHXcNuIDbMMhF20zI5vlNHiAMFbTLl6STaSEw8+xm1a/HL THsN+ci++bQeOxv7fygw7I4FKVtEEBl2i+O+9q8QyRGOnhob0JYX75rHqyCb66u2xZFJ ZJLRlT/r94GTcHVPH7wd3YxoCTS5CKkvOneZwJxMcZQWKbykSBjqsXq5W5UsWEJniuNq dNHOfXJwmSK3/CTYB2Zp0t3yFT8yITp7KHJM2Mw3trzuwMj+UGmsO1Tw34KfOG7AwCCN VJ87QzUo3NPbaBCZbNm9Gy6FsuOSAfIiH2xCPOMVUQsh52oBA1iAV7O0YwGdewFoTbor 7xdA== X-Gm-Message-State: AOJu0YxBQURT+dYFpYc/SAh5VdNoUbSZv6VG4vdtTgBY1fQzzDsucH3U 3urEULgwS1ai1vqc1Oc7hItRWNwtaQm4Sy8W5VU3DGOuglf8fZhvjKqYLCTsWY4= X-Google-Smtp-Source: AGHT+IF/GnH2QgDmw59wK+MV58orwGTHjDwuVN31SvZk0So7QwH+kyVEsr3tWZ9XQOL8vTjXgvCRSQ== X-Received: by 2002:a05:6e02:1d04:b0:3a0:926a:8d31 with SMTP id e9e14a558f8ab-3a4cd7ebeb1mr12712545ab.16.1729572657066; Mon, 21 Oct 2024 21:50:57 -0700 (PDT) From: Akihiko Odaki Date: Tue, 22 Oct 2024 13:50:39 +0900 Subject: [PATCH v2 2/3] qdev-properties: Add DEFINE_PROP_ON_OFF_AUTO_BIT64() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241022-virtio-v2-2-b2394236e053@daynix.com> References: <20241022-virtio-v2-0-b2394236e053@daynix.com> In-Reply-To: <20241022-virtio-v2-0-b2394236e053@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: 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::d2d; envelope-from=akihiko.odaki@daynix.com; helo=mail-io1-xd2d.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729572733472116600 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; }; =20 +/** + * 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; + =20 /*** qdev-properties.c ***/ =20 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 =3D true, \ .defval.u =3D (bool)_defval) =20 +#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 =3D (_bit), = \ + .set_default =3D true, = \ + .defval.i =3D (OnOffAuto)_defval) + #define DEFINE_PROP_BOOL(_name, _state, _field, _defval) \ DEFINE_PROP(_name, _state, _field, qdev_prop_bool, bool, \ .set_default =3D 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 =3D { =20 static uint64_t qdev_get_prop_mask64(Property *prop) { - assert(prop->info =3D=3D &qdev_prop_bit64); + assert(prop->info =3D=3D &qdev_prop_bit64 || + prop->info =3D=3D &qdev_prop_on_off_auto_bit64); return 0x1ull << prop->bitnr; } =20 @@ -232,6 +233,69 @@ const PropertyInfo qdev_prop_bit64 =3D { .set_default_value =3D set_default_value_bool, }; =20 +static void prop_get_on_off_auto_bit64(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + Property *prop =3D opaque; + OnOffAutoBit64 *p =3D object_field_prop_ptr(obj, prop); + int value; + uint64_t mask =3D qdev_get_prop_mask64(prop); + + if (p->auto_bits & mask) { + value =3D ON_OFF_AUTO_AUTO; + } else if (p->on_bits & mask) { + value =3D ON_OFF_AUTO_ON; + } else { + value =3D 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 =3D opaque; + OnOffAutoBit64 *p =3D object_field_prop_ptr(obj, prop); + bool bool_value; + int value; + uint64_t mask =3D qdev_get_prop_mask64(prop); + + if (visit_type_bool(v, name, &bool_value, NULL)) { + value =3D 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 &=3D ~mask; + p->auto_bits |=3D mask; + break; + + case ON_OFF_AUTO_ON: + p->on_bits |=3D mask; + p->auto_bits &=3D ~mask; + break; + + case ON_OFF_AUTO_OFF: + p->on_bits &=3D ~mask; + p->auto_bits &=3D ~mask; + break; + } +} + +const PropertyInfo qdev_prop_on_off_auto_bit64 =3D { + .name =3D "OnOffAuto", + .description =3D "on/off/auto", + .enum_table =3D &OnOffAuto_lookup, + .get =3D prop_get_on_off_auto_bit64, + .set =3D prop_set_on_off_auto_bit64, + .set_default_value =3D qdev_propinfo_set_default_value_enum, +}; + /* --- bool --- */ =20 static void get_bool(Object *obj, Visitor *v, const char *name, void *opaq= ue, --=20 2.47.0 From nobody Tue Oct 22 23:27:31 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=1729572699; cv=none; d=zohomail.com; s=zohoarc; b=WSTudq7LyQc44WTVZRdkEpdun/VRmHSlQSaOXpaNQMqgJDKFRwBro0HFnRVUTN5k/gk9qMCSVeMUMU9rZHJYIn3wwBaRsMERS8aoBG3WDRuSwbwNefJAk5mVlp0StuSRwmJs7CCY+fYiIYrYK5K7BKIqfjaxChKv4wSOX3c4DKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729572699; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=q/GNOYUKbHrVkW8DjI8/OPo0jygVL2ZBNtJGkOtaWHo=; b=hDYUeNY1Hfo4TffuKcr1eMOjn1PFEEliEMV4xIIGgzAGTtF8XEI9FxIeptqavsw4JG5THYigUgBfKZHEJmvt8h5B2YTKaFiTK5WuOOiidU5LZrPAPR9+sCIvEgZOU/tu5MW1IZeCCvyZGhxTuEh+/8/TdeYyLgSAkdPaAv+hsg8= 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 1729572699398309.47695133147204; Mon, 21 Oct 2024 21:51:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t36rX-0002Dl-7M; Tue, 22 Oct 2024 00:51:19 -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 1t36rJ-00027v-Ab for qemu-devel@nongnu.org; Tue, 22 Oct 2024 00:51:06 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t36rH-0008Rb-C7 for qemu-devel@nongnu.org; Tue, 22 Oct 2024 00:51:04 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-20cf3e36a76so50540715ad.0 for ; Mon, 21 Oct 2024 21:51:03 -0700 (PDT) Received: from localhost ([157.82.202.230]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-20e7f0e1ba7sm34502545ad.238.2024.10.21.21.50.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Oct 2024 21:51:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1729572662; x=1730177462; 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=q/GNOYUKbHrVkW8DjI8/OPo0jygVL2ZBNtJGkOtaWHo=; b=sU2xrFfhWW6oPiQ45oKcZVy/1mdkWqff1yij25hzCD9hCDFFC7vxXYVe0ELeIclBSf O/AdZZu+Gt5cotCbpsXQ3m3m1MEmp/bBoAJVOvWf2PMND59U6+4FY5GxXKNQQtnZCAHG 9cJjm52v1dMk76271isYGvgfIDEoZMz1ndYL6+zixBthVUIWwgCAqIY/NtU5/3i2Z/Wp oNYMg/KWxriTjEyjNhBe9ODOr5/Nf4ht9u0yCk/dxAC6+CJNB9tLkIeuhdrFwMJDERsW /Up7tWVs3M5FEUbmBPy2hJ38EqtRPbSHHCcxBee+BCn+aMMQ8pc0OH4MgvnXi/M57/5e PjDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729572662; x=1730177462; 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=q/GNOYUKbHrVkW8DjI8/OPo0jygVL2ZBNtJGkOtaWHo=; b=rQX9qAVXCJto2pI57/NedApdoVbMjExUjlCafNktccCLTXHJAEGiAIbVZJBlNkc4ph ucyECKFpp06Xh/rBCXGSdLuZ6khdRBJy8GWkGrNpiKUvcxbEKbBQJUqd5R73uzrIDcVV 7PEeXkaB2FcVF7qWC9X+2qMTt+Xt+6V7jD4mBgunHR2VrbW4nsKwD25/Zdn/ejN3gzoz 5vMvIWWrokS7wOIZLcrWCfFv8vdsZj4EaSetrPhhFsPBqVfopSXc6MRRpZ5fibnLZIwB dsdr0jac1bWwJ+zrR10aH75dNQDjTzxpiTUlGEP4znDkYYYIBqHFgc6bzNHCwNAKFvSx VXgw== X-Gm-Message-State: AOJu0Yy/Mf7+P96/TGaIbAvQcHBu+LhqcR1P+ecx8AN0fEMjo0EqZEVt jPeucHauPSRJ4173HPQbK6AL9rSv4J7OqoZjBxrEJP+uP4wQDt95gXvyMymBnGo= X-Google-Smtp-Source: AGHT+IGqI10LdHIAupBeVIo+yRLJYmd9Uzza4t/E1j/f4FOFkgwrBbWpBIoIlwnryVlCdBYoc4JAPw== X-Received: by 2002:a17:902:e54f:b0:20d:f55:8a17 with SMTP id d9443c01a7336-20e98453283mr19519985ad.6.1729572661982; Mon, 21 Oct 2024 21:51:01 -0700 (PDT) From: Akihiko Odaki Date: Tue, 22 Oct 2024 13:50:40 +0900 Subject: [PATCH v2 3/3] virtio: Convert feature properties to OnOffAuto MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241022-virtio-v2-3-b2394236e053@daynix.com> References: <20241022-virtio-v2-0-b2394236e053@daynix.com> In-Reply-To: <20241022-virtio-v2-0-b2394236e053@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: 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::62b; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1729572701488116600 Some features are not always available with vhost. Legacy features are not available with vp_vdpa in particular. virtio devices used to disable them when not available even if the corresponding properties were explicitly set to "on". QEMU already has OnOffAuto type, which includes the "auto" value to let it automatically decide the effective value. Convert feature properties to OnOffAuto and set them "auto" by default to utilize it. This allows QEMU to report an error if they are set "on" and the corresponding features are not available. Signed-off-by: Akihiko Odaki --- include/hw/virtio/virtio.h | 38 +++++++++++++++++++++----------------- hw/core/machine.c | 4 +++- hw/virtio/virtio-bus.c | 14 ++++++++++++-- hw/virtio/virtio.c | 4 +++- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index f526ecc8fcc0..b4cb5642ddd0 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -113,7 +113,8 @@ struct VirtIODevice uint16_t queue_sel; /** * These fields represent a set of VirtIO features at various - * levels of the stack. @host_features indicates the complete + * levels of the stack. @requested_features indicates the feature + * set the user requested. @host_features indicates the complete * feature set the VirtIO device can offer to the driver. * @guest_features indicates which features the VirtIO driver has * selected by writing to the feature register. Finally @@ -121,6 +122,7 @@ struct VirtIODevice * backend (e.g. vhost) and could potentially be a subset of the * total feature set offered by QEMU. */ + OnOffAutoBit64 requested_features; uint64_t host_features; uint64_t guest_features; uint64_t backend_features; @@ -149,6 +151,7 @@ struct VirtIODevice bool started; bool start_on_kick; /* when virtio 1.0 feature has not been negotiated= */ bool disable_legacy_check; + bool force_features_auto; bool vhost_started; VMChangeStateEntry *vmstate; char *bus_name; @@ -374,22 +377,23 @@ typedef struct VirtIOSCSIConf VirtIOSCSIConf; typedef struct VirtIORNGConf VirtIORNGConf; =20 #define DEFINE_VIRTIO_COMMON_FEATURES(_state, _field) \ - DEFINE_PROP_BIT64("indirect_desc", _state, _field, \ - VIRTIO_RING_F_INDIRECT_DESC, true), \ - DEFINE_PROP_BIT64("event_idx", _state, _field, \ - VIRTIO_RING_F_EVENT_IDX, true), \ - DEFINE_PROP_BIT64("notify_on_empty", _state, _field, \ - VIRTIO_F_NOTIFY_ON_EMPTY, true), \ - DEFINE_PROP_BIT64("any_layout", _state, _field, \ - VIRTIO_F_ANY_LAYOUT, true), \ - DEFINE_PROP_BIT64("iommu_platform", _state, _field, \ - VIRTIO_F_IOMMU_PLATFORM, false), \ - DEFINE_PROP_BIT64("packed", _state, _field, \ - VIRTIO_F_RING_PACKED, false), \ - DEFINE_PROP_BIT64("queue_reset", _state, _field, \ - VIRTIO_F_RING_RESET, true), \ - DEFINE_PROP_BIT64("in_order", _state, _field, \ - VIRTIO_F_IN_ORDER, false) + DEFINE_PROP_ON_OFF_AUTO_BIT64("indirect_desc", _state, _field, \ + VIRTIO_RING_F_INDIRECT_DESC, \ + ON_OFF_AUTO_AUTO), \ + DEFINE_PROP_ON_OFF_AUTO_BIT64("event_idx", _state, _field, \ + VIRTIO_RING_F_EVENT_IDX, ON_OFF_AUTO_AUT= O), \ + DEFINE_PROP_ON_OFF_AUTO_BIT64("notify_on_empty", _state, _field, \ + VIRTIO_F_NOTIFY_ON_EMPTY, ON_OFF_AUTO_AU= TO), \ + DEFINE_PROP_ON_OFF_AUTO_BIT64("any_layout", _state, _field, \ + VIRTIO_F_ANY_LAYOUT, ON_OFF_AUTO_AUTO), \ + DEFINE_PROP_ON_OFF_AUTO_BIT64("iommu_platform", _state, _field, \ + VIRTIO_F_IOMMU_PLATFORM, ON_OFF_AUTO_OFF= ), \ + DEFINE_PROP_ON_OFF_AUTO_BIT64("packed", _state, _field, \ + VIRTIO_F_RING_PACKED, ON_OFF_AUTO_OFF), \ + DEFINE_PROP_ON_OFF_AUTO_BIT64("queue_reset", _state, _field, \ + VIRTIO_F_RING_RESET, ON_OFF_AUTO_AUTO), \ + DEFINE_PROP_ON_OFF_AUTO_BIT64("in_order", _state, _field, \ + VIRTIO_F_IN_ORDER, ON_OFF_AUTO_OFF) =20 hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n); bool virtio_queue_enabled_legacy(VirtIODevice *vdev, int n); diff --git a/hw/core/machine.c b/hw/core/machine.c index adaba17ebac1..3021d42fca12 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -34,7 +34,9 @@ #include "hw/virtio/virtio-iommu.h" #include "audio/audio.h" =20 -GlobalProperty hw_compat_9_1[] =3D {}; +GlobalProperty hw_compat_9_1[] =3D { + { TYPE_VIRTIO_DEVICE, "x-force-features-auto", "on" }, +}; const size_t hw_compat_9_1_len =3D G_N_ELEMENTS(hw_compat_9_1); =20 GlobalProperty hw_compat_9_0[] =3D { diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c index 896feb37a1ca..75d433b252d5 100644 --- a/hw/virtio/virtio-bus.c +++ b/hw/virtio/virtio-bus.c @@ -50,6 +50,7 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error = **errp) bool has_iommu =3D virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFO= RM); bool vdev_has_iommu; Error *local_err =3D NULL; + uint64_t features; =20 DPRINTF("%s: plug device.\n", qbus->name); =20 @@ -63,13 +64,22 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Erro= r **errp) =20 /* Get the features of the plugged device. */ assert(vdc->get_features !=3D NULL); - vdev->host_features =3D vdc->get_features(vdev, vdev->host_features, - &local_err); + features =3D vdev->host_features | vdev->requested_features.auto_bits | + vdev->requested_features.on_bits; + features =3D vdc->get_features(vdev, features, &local_err); if (local_err) { error_propagate(errp, local_err); return; } =20 + if (!vdev->force_features_auto && + (features & vdev->requested_features.on_bits) !=3D vdev->requested= _features.on_bits) { + error_setg(errp, "A requested feature is not supported by the devi= ce"); + return; + } + + vdev->host_features =3D features; + if (klass->device_plugged !=3D NULL) { klass->device_plugged(qbus->parent, &local_err); } diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index a26f18908ea5..44ad58de33c8 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -4006,11 +4006,13 @@ static void virtio_device_instance_finalize(Object = *obj) } =20 static Property virtio_properties[] =3D { - DEFINE_VIRTIO_COMMON_FEATURES(VirtIODevice, host_features), + DEFINE_VIRTIO_COMMON_FEATURES(VirtIODevice, requested_features), DEFINE_PROP_BOOL("use-started", VirtIODevice, use_started, true), DEFINE_PROP_BOOL("use-disabled-flag", VirtIODevice, use_disabled_flag,= true), DEFINE_PROP_BOOL("x-disable-legacy-check", VirtIODevice, disable_legacy_check, false), + DEFINE_PROP_BOOL("x-force-features-auto", VirtIODevice, + force_features_auto, false), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.47.0