From patchwork Wed Jan 8 06:17:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13930159 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 72F06E77188 for ; Wed, 8 Jan 2025 06:18:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tVPOP-0000hi-HD; Wed, 08 Jan 2025 01:18:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tVPON-0000h6-GZ for qemu-devel@nongnu.org; Wed, 08 Jan 2025 01:18:11 -0500 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 1tVPOL-0000GL-EI for qemu-devel@nongnu.org; Wed, 08 Jan 2025 01:18:11 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-216281bc30fso25418205ad.0 for ; Tue, 07 Jan 2025 22:18:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1736317088; x=1736921888; 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=EN+qqbOe1sSXYPmH2HeJgFF7KPD7SBBT9uZwyt+R3fE=; b=FqVpzpX/YWN/Ht8pwpwOxaQYWUcuF7Oam8iO+XNYkKHnfXhNJo64zulCMNI8SNJM6x RyhwwIy7/dpJkSL2s8RdgNPO14gDWtcvpUU8GjxNh3fOnJbl1G6XwDMi+nWtVj0d1Mdg Um62BbIFJC73i6995DhsOra0dH5NEUtGFTYygk5kM5MA2aAEf3mAsInx8oUM5eo4AEAo rUjmFe5oNO5qqKp+Gti2LlWj9LziHQGXzSQm/ZzcI/0ft+YRHKFAOh2cINd3xwyQlDsQ r5S5SBnIWcov3w2FJUaMdPCM5UUP2DCPSpINgG2SlPxVH639yCo1jDk3sodvumeltzsl vo+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736317088; x=1736921888; 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=EN+qqbOe1sSXYPmH2HeJgFF7KPD7SBBT9uZwyt+R3fE=; b=QnUsSJYgvA0+IXC16XyZgNS3jFHPqzPIN/HfthACH6GPD43xOY1bQcQlG/FVXnlBIC BklcuhQHTsXQmK0Jcmu8wVjDtUjEGuBDJASzN1FomjeEUDhlHYTs+JzjOy2H1n686mUe yQJei9HIde+vSzHpsoO8WuGq98pBrqhwhq0kEHpITt9x+q2OVOIRC8fxYmnjgLgvD6F5 Gs1BNRiRbFl8+jWtrEJjR/XBcF0SLo9LfUX8xCP634L2mRaJEv9Jb+fksS79smVf5MH6 iqlLsxHEmG6Dpvi6uegN+OQyZJFNdgUTSLYIHdSnU4fdZUm9J1jHGRrUmAw6Y45atH8y 96VQ== X-Gm-Message-State: AOJu0Yxq/UGN93t5IzubYdlQRKW1xZzpJDnjv/byTH8sCUZCfYV9voqz 2fjTBl5acccRRgr/Ep6wVaXRtPI3RFz4bGZRSp76ReA4V4EejEhvZOiGDrxbL3Y= X-Gm-Gg: ASbGnctGQFBFI8hBt9jVPOweH2NAgsojAh5l94anFYNqsN2fq/QVVgGF98zNvho87zO BHlbYHtA4EeXQAevdAIQXBBvcomg6TQWclOHRX3xORxgvUpNIpsUizDpClT9uQMj9rywy1SEP6o YZNnpkBG8bpf6t+2NZGzM7eyJFp/br1eezO0GPpmam70c665HWRPuxNZoV284mnfJuE3ZqLMPia UeZV29Zb3qLyK95R62V9KCLwDQ/e5uUPKgBa55/H1K8ac4B0oLWoiT7Ouo= X-Google-Smtp-Source: AGHT+IEXlTmSqS2zl3C7FY9J+SGnB9yCDQen3MxQhKGoeW7uEYosnBkh43sAfeWomrPlhjnb2soM4g== X-Received: by 2002:a17:903:1d0:b0:216:2474:3c9f with SMTP id d9443c01a7336-21a83fe2fb0mr24918145ad.52.1736317087851; Tue, 07 Jan 2025 22:18:07 -0800 (PST) Received: from localhost ([157.82.203.37]) by smtp.gmail.com with UTF8SMTPSA id d9443c01a7336-219dc9f4406sm320111165ad.170.2025.01.07.22.18.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 Jan 2025 22:18:07 -0800 (PST) From: Akihiko Odaki Date: Wed, 08 Jan 2025 15:17:50 +0900 Subject: [PATCH v4 1/4] qapi: Do not consume a value if failed MIME-Version: 1.0 Message-Id: <20250108-virtio-v4-1-cbf0aa04c9f9@daynix.com> References: <20250108-virtio-v4-0-cbf0aa04c9f9@daynix.com> In-Reply-To: <20250108-virtio-v4-0-cbf0aa04c9f9@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 , Markus Armbruster , Michael Roth , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Yanan Wang , Zhao Liu , Lei Yang Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 Received-SPF: pass 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_PASS=-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 Do not consume a value if interpreting one failed so that we can reinterpret the value with a different type. Signed-off-by: Akihiko Odaki --- qapi/qobject-input-visitor.c | 103 +++++++++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 34 deletions(-) diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index f110a804b2ae..799c1c9bd6bd 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -116,9 +116,8 @@ static const char *full_name(QObjectInputVisitor *qiv, const char *name) return full_name_nth(qiv, name, 0); } -static QObject *qobject_input_try_get_object(QObjectInputVisitor *qiv, - const char *name, - bool consume) +static QObject *qobject_input_try_get_object(const QObjectInputVisitor *qiv, + const char *name) { StackObject *tos; QObject *qobj; @@ -138,34 +137,19 @@ static QObject *qobject_input_try_get_object(QObjectInputVisitor *qiv, if (qobject_type(qobj) == QTYPE_QDICT) { assert(name); ret = qdict_get(qobject_to(QDict, qobj), name); - if (tos->h && consume && ret) { - bool removed = g_hash_table_remove(tos->h, name); - assert(removed); - } } else { assert(qobject_type(qobj) == QTYPE_QLIST); assert(!name); - if (tos->entry) { - ret = qlist_entry_obj(tos->entry); - if (consume) { - tos->entry = qlist_next(tos->entry); - } - } else { - ret = NULL; - } - if (consume) { - tos->index++; - } + ret = tos->entry ? qlist_entry_obj(tos->entry) : NULL; } return ret; } static QObject *qobject_input_get_object(QObjectInputVisitor *qiv, - const char *name, - bool consume, Error **errp) + const char *name, Error **errp) { - QObject *obj = qobject_input_try_get_object(qiv, name, consume); + QObject *obj = qobject_input_try_get_object(qiv, name); if (!obj) { error_setg(errp, QERR_MISSING_PARAMETER, full_name(qiv, name)); @@ -173,6 +157,38 @@ static QObject *qobject_input_get_object(QObjectInputVisitor *qiv, return obj; } +static void qobject_input_consume_object(QObjectInputVisitor *qiv, + const char *name) +{ + StackObject *tos; + QObject *qobj; + + if (QSLIST_EMPTY(&qiv->stack)) { + /* Starting at root, name is ignored. */ + return; + } + + /* We are in a container; find the next element. */ + tos = QSLIST_FIRST(&qiv->stack); + qobj = tos->obj; + assert(qobj); + + if (qobject_type(qobj) == QTYPE_QDICT) { + assert(name); + if (tos->h) { + bool removed = g_hash_table_remove(tos->h, name); + assert(removed); + } + } else { + assert(qobject_type(qobj) == QTYPE_QLIST); + assert(!name); + if (tos->entry) { + tos->entry = qlist_next(tos->entry); + } + tos->index++; + } +} + static const char *qobject_input_get_keyval(QObjectInputVisitor *qiv, const char *name, Error **errp) @@ -180,7 +196,7 @@ static const char *qobject_input_get_keyval(QObjectInputVisitor *qiv, QObject *qobj; QString *qstr; - qobj = qobject_input_get_object(qiv, name, true, errp); + qobj = qobject_input_get_object(qiv, name, errp); if (!qobj) { return NULL; } @@ -233,6 +249,7 @@ static const QListEntry *qobject_input_push(QObjectInputVisitor *qiv, tos->index = -1; } + qobject_input_consume_object(qiv, name); QSLIST_INSERT_HEAD(&qiv->stack, tos, node); return tos->entry; } @@ -279,7 +296,7 @@ static bool qobject_input_start_struct(Visitor *v, const char *name, void **obj, size_t size, Error **errp) { QObjectInputVisitor *qiv = to_qiv(v); - QObject *qobj = qobject_input_get_object(qiv, name, true, errp); + QObject *qobj = qobject_input_get_object(qiv, name, errp); if (obj) { *obj = NULL; @@ -316,7 +333,7 @@ static bool qobject_input_start_list(Visitor *v, const char *name, Error **errp) { QObjectInputVisitor *qiv = to_qiv(v); - QObject *qobj = qobject_input_get_object(qiv, name, true, errp); + QObject *qobj = qobject_input_get_object(qiv, name, errp); const QListEntry *entry; if (list) { @@ -382,7 +399,7 @@ static bool qobject_input_start_alternate(Visitor *v, const char *name, Error **errp) { QObjectInputVisitor *qiv = to_qiv(v); - QObject *qobj = qobject_input_get_object(qiv, name, false, errp); + QObject *qobj = qobject_input_get_object(qiv, name, errp); if (!qobj) { *obj = NULL; @@ -397,7 +414,7 @@ static bool qobject_input_type_int64(Visitor *v, const char *name, int64_t *obj, Error **errp) { QObjectInputVisitor *qiv = to_qiv(v); - QObject *qobj = qobject_input_get_object(qiv, name, true, errp); + QObject *qobj = qobject_input_get_object(qiv, name, errp); QNum *qnum; if (!qobj) { @@ -409,6 +426,7 @@ static bool qobject_input_type_int64(Visitor *v, const char *name, int64_t *obj, full_name(qiv, name)); return false; } + qobject_input_consume_object(qiv, name); return true; } @@ -428,6 +446,7 @@ static bool qobject_input_type_int64_keyval(Visitor *v, const char *name, full_name(qiv, name), "integer"); return false; } + qobject_input_consume_object(qiv, name); return true; } @@ -435,7 +454,7 @@ static bool qobject_input_type_uint64(Visitor *v, const char *name, uint64_t *obj, Error **errp) { QObjectInputVisitor *qiv = to_qiv(v); - QObject *qobj = qobject_input_get_object(qiv, name, true, errp); + QObject *qobj = qobject_input_get_object(qiv, name, errp); QNum *qnum; int64_t val; @@ -448,12 +467,14 @@ static bool qobject_input_type_uint64(Visitor *v, const char *name, } if (qnum_get_try_uint(qnum, obj)) { + qobject_input_consume_object(qiv, name); return true; } /* Need to accept negative values for backward compatibility */ if (qnum_get_try_int(qnum, &val)) { *obj = val; + qobject_input_consume_object(qiv, name); return true; } @@ -479,6 +500,7 @@ static bool qobject_input_type_uint64_keyval(Visitor *v, const char *name, full_name(qiv, name), "integer"); return false; } + qobject_input_consume_object(qiv, name); return true; } @@ -486,7 +508,7 @@ static bool qobject_input_type_bool(Visitor *v, const char *name, bool *obj, Error **errp) { QObjectInputVisitor *qiv = to_qiv(v); - QObject *qobj = qobject_input_get_object(qiv, name, true, errp); + QObject *qobj = qobject_input_get_object(qiv, name, errp); QBool *qbool; if (!qobj) { @@ -500,6 +522,7 @@ static bool qobject_input_type_bool(Visitor *v, const char *name, bool *obj, } *obj = qbool_get_bool(qbool); + qobject_input_consume_object(qiv, name); return true; } @@ -518,6 +541,7 @@ static bool qobject_input_type_bool_keyval(Visitor *v, const char *name, full_name(qiv, name), "'on' or 'off'"); return false; } + qobject_input_consume_object(qiv, name); return true; } @@ -525,7 +549,7 @@ static bool qobject_input_type_str(Visitor *v, const char *name, char **obj, Error **errp) { QObjectInputVisitor *qiv = to_qiv(v); - QObject *qobj = qobject_input_get_object(qiv, name, true, errp); + QObject *qobj = qobject_input_get_object(qiv, name, errp); QString *qstr; *obj = NULL; @@ -540,6 +564,7 @@ static bool qobject_input_type_str(Visitor *v, const char *name, char **obj, } *obj = g_strdup(qstring_get_str(qstr)); + qobject_input_consume_object(qiv, name); return true; } @@ -549,15 +574,20 @@ static bool qobject_input_type_str_keyval(Visitor *v, const char *name, QObjectInputVisitor *qiv = to_qiv(v); const char *str = qobject_input_get_keyval(qiv, name, errp); + if (!str) { + return false; + } + *obj = g_strdup(str); - return !!str; + qobject_input_consume_object(qiv, name); + return true; } static bool qobject_input_type_number(Visitor *v, const char *name, double *obj, Error **errp) { QObjectInputVisitor *qiv = to_qiv(v); - QObject *qobj = qobject_input_get_object(qiv, name, true, errp); + QObject *qobj = qobject_input_get_object(qiv, name, errp); QNum *qnum; if (!qobj) { @@ -571,6 +601,7 @@ static bool qobject_input_type_number(Visitor *v, const char *name, double *obj, } *obj = qnum_get_double(qnum); + qobject_input_consume_object(qiv, name); return true; } @@ -593,6 +624,7 @@ static bool qobject_input_type_number_keyval(Visitor *v, const char *name, } *obj = val; + qobject_input_consume_object(qiv, name); return true; } @@ -600,7 +632,7 @@ static bool qobject_input_type_any(Visitor *v, const char *name, QObject **obj, Error **errp) { QObjectInputVisitor *qiv = to_qiv(v); - QObject *qobj = qobject_input_get_object(qiv, name, true, errp); + QObject *qobj = qobject_input_get_object(qiv, name, errp); *obj = NULL; if (!qobj) { @@ -608,6 +640,7 @@ static bool qobject_input_type_any(Visitor *v, const char *name, QObject **obj, } *obj = qobject_ref(qobj); + qobject_input_consume_object(qiv, name); return true; } @@ -615,7 +648,7 @@ static bool qobject_input_type_null(Visitor *v, const char *name, QNull **obj, Error **errp) { QObjectInputVisitor *qiv = to_qiv(v); - QObject *qobj = qobject_input_get_object(qiv, name, true, errp); + QObject *qobj = qobject_input_get_object(qiv, name, errp); *obj = NULL; if (!qobj) { @@ -628,6 +661,7 @@ static bool qobject_input_type_null(Visitor *v, const char *name, return false; } *obj = qnull(); + qobject_input_consume_object(qiv, name); return true; } @@ -647,13 +681,14 @@ static bool qobject_input_type_size_keyval(Visitor *v, const char *name, full_name(qiv, name), "size"); return false; } + qobject_input_consume_object(qiv, name); return true; } static void qobject_input_optional(Visitor *v, const char *name, bool *present) { QObjectInputVisitor *qiv = to_qiv(v); - QObject *qobj = qobject_input_try_get_object(qiv, name, false); + QObject *qobj = qobject_input_try_get_object(qiv, name); if (!qobj) { *present = false; From patchwork Wed Jan 8 06:17:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13930161 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 1F205E77188 for ; Wed, 8 Jan 2025 06:19:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tVPP2-0001AS-Ft; Wed, 08 Jan 2025 01:18:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tVPOV-0000n2-9u for qemu-devel@nongnu.org; Wed, 08 Jan 2025 01:18:20 -0500 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tVPOT-0000HE-Q5 for qemu-devel@nongnu.org; Wed, 08 Jan 2025 01:18:19 -0500 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-2165448243fso45921895ad.1 for ; Tue, 07 Jan 2025 22:18:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1736317096; x=1736921896; 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=nUQUJaOUPrhv5bXHlKSaYOoVtPTOlAhSIbbKfSqWyrU=; b=PCqzNLpzHqWwnNWJ038FTh3JOTEouvj+esCMUMjLIC1JHOJjFGLGe+4abQVK+oX5qY F7MNy/oI4nvN0C1COFRPKgOjyRAh9Pj3eMrX1Ucl+GJj/KkTgZedOl44iGmYUM/a3sk2 iZJD1Czg63PwZUwZXspM4oaiqnrNS+zH1XmEYZiwNZJBPbZOn6M0gz/YDvFCtghnVVTr jxvrs4vAfoWM/MZDA+zFjYzLwBoplUBtNZb1nD38B4ROq25w3QCOD9X6MvsO9ljWN8RA iOnGiSUe4/jQ/KSvqCs1GHqBqGD4Q0RO10fyi6ITTzbe5/81WWXEeLB//EVw7/xob/aX lmDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736317096; x=1736921896; 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=nUQUJaOUPrhv5bXHlKSaYOoVtPTOlAhSIbbKfSqWyrU=; b=dQRY9GHQPhyXgrmvEWE4ExLsT1gChmL2YIcwVPA9AoxqkImfFRZfVJa51Sn+Wy9T6h cjF/fuLP3vsIOME4ekQa1kHfCRMuPkkhauHryXpGhCZXJOeLbNnps3rdC7NzTHqoDi8D JWzqhkbY7QX470rHUIRau/jpIL0FiCqlYAmV8VyDxbbbTInx72vCm3usXv5HfWXAMQQm wtFYH2HLgYXS1mZPQrrnPBtuHPZuZPQ23VMa5xz85w0fzGqd04kq07cJUXoCeFOXv+yZ cd0qDdW6UyQsLe1YR5Ej8PbsY4G1wLGtCyFmNN1GLs2OXujpng22Rfxd3cMOjW92x/b6 SrAA== X-Gm-Message-State: AOJu0YzEodhg0vC0Gl6nnZe96dOzCRjAHtUBzyGU1/nXs3SeO3I/To4X SBNojgXc+4vLw7GOokbBvX2549D0mrqdHa95/fTiTrjy9l3zYV+03dT9gzQyOP0= X-Gm-Gg: ASbGncun0hF+mBO1nuakOX9RMW0TAmQosl08jYRRJpk5FK0bj+kOGHpRqG7y/W1sn6U t7C3YkUicyb91L/1qMejWWM7dhJ00HIGwm0NysHtAi69/Du6RQWzkFPAXFxiO+tdElCyLRkzL9J /cq94km6MZllFQ6pyw6wvL0iiN8OdGavFWS1JmBGTlPsWCLBow3TZbprEEG59u9LU4CAFbGI4/i 0/7sp6qXy4FXTjFvMvd3ZT5tzNTacS5/0IMzxu/IA44wW5S1SAkM89EofQ= X-Google-Smtp-Source: AGHT+IGCFCfnIQoMVlRzZZOMz/25mJgmLOpJPyL8iO6RmWq3L+oo3yjy/spVycNhbZTm8l7+14ZJfQ== X-Received: by 2002:a05:6a20:7fa7:b0:1e0:d575:8d4f with SMTP id adf61e73a8af0-1e88d39c828mr3360172637.37.1736317096456; Tue, 07 Jan 2025 22:18:16 -0800 (PST) Received: from localhost ([157.82.203.37]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-72aad8344desm34346090b3a.54.2025.01.07.22.18.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 Jan 2025 22:18:16 -0800 (PST) From: Akihiko Odaki Date: Wed, 08 Jan 2025 15:17:51 +0900 Subject: [PATCH v4 2/4] qdev-properties: Accept bool for OnOffAuto MIME-Version: 1.0 Message-Id: <20250108-virtio-v4-2-cbf0aa04c9f9@daynix.com> References: <20250108-virtio-v4-0-cbf0aa04c9f9@daynix.com> In-Reply-To: <20250108-virtio-v4-0-cbf0aa04c9f9@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 , Markus Armbruster , Michael Roth , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Yanan Wang , Zhao Liu , Lei Yang Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62a.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_PASS=-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. 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 434a76f5036e..0081d79f9b7b 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 Wed Jan 8 06:17:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13930162 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 C7D3AE7719A for ; Wed, 8 Jan 2025 06:19:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tVPP2-0001AR-F1; Wed, 08 Jan 2025 01:18:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tVPOe-0000zz-Ah for qemu-devel@nongnu.org; Wed, 08 Jan 2025 01:18:32 -0500 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tVPOc-0000Hl-Lg for qemu-devel@nongnu.org; Wed, 08 Jan 2025 01:18:28 -0500 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-2eeb4d643a5so24475502a91.3 for ; Tue, 07 Jan 2025 22:18:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1736317105; x=1736921905; 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=ZNqJPsf/cYD6P0aHHAr+PPuSee4lD92uJoGO6q9V8Jc=; b=08brniaNgWP8W2khvplHwpOUxIhlD00Z8PN7U1s6Y4mLes+LhBvO3G7UyVpyX/GOnf n0ThX1OGKsUhONYv2GicpCO895lMLXXtUuwrcB7vIxp4u4fRmoZLGSKu0glvlEDa+K6f n1flO9wVDml2asOJ4/c8ja+jCWe+P2LS4O0m8/gxZ0EkUz9b+nXlSx20sHh2RCoXPPZa qAtotZOJIVbrRKHTX5WOlNwCLCxkT2AQ2I5JeFufh8n7Ijs7gfgr4m7KE66n1DbzidmA 4HGQ53c1EUAKwO5CmCXyap0fTAlxwGd7WG/muG27ENdfuTJ1b1rCVTer6TDq+tyDfVUd l5IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736317105; x=1736921905; 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=ZNqJPsf/cYD6P0aHHAr+PPuSee4lD92uJoGO6q9V8Jc=; b=A6EOX2FowGMheLANV2Nip95acSlKdtkDtIlllFAUTO9JL2SctAjDhnV+kOXttQaihk 1/Yv72LP0lhP+T73UimnqL+6VeLVskSTRlaXSBxbq19JQM0jeBwn2MT05nn7YaOLiDmr fA1EBxdiegZREYsnm2PGPJApHBHNFhM+eiRrESqYaXzqbeUSNVbLhdsqRkZC8qcAPOmR 10Ze0vLwtzZwKrxe2QfTDxGWUc08bkkOGpqMQ/6EFsDUCQczJW74e0UDXvjv5uj3nknP z2fehbOLdm1s3ZpGt+KpHtnK7KBYfkkrXpX87baAWljyDB8y2SCPNdZW1FFzWiepZNex NxDQ== X-Gm-Message-State: AOJu0YwCRwh/bAhI6h2eTbKSC/2pN+ZUw1Q/PdDYpnypXlWTlK9XtGyB gthMMYUNk0nNiDFH0KYwK5Sj4DMFLipa8Uhd2tNYclUbc2w+gsgjespROO9z3W8= X-Gm-Gg: ASbGnct0/Ng6/VZbZP+qFT0fpoi21rfdSjUGsbH+sRPTsM6MFY0jjTC7mMKCuSbW7ma 7QvKLhW13GhYLIa8GmrRsEyJgis2F3br0JtDYhZAVEjjP7I6u4Dcxd2ke51MR1olQf+dSy1CJ8T AxWqLJP6BLFH7dFVLziBrUsqnZqPvdKDXaKPTIoX9aaDjP1VwN4vPkGfEuo2HY+0HYzJPx/Mn+F 563bsc1tJprEPstSRZ4u8zqJZAwVLflmvNk4VlMHRPbTCtngg2/FI/GhZo= X-Google-Smtp-Source: AGHT+IE/atNcga0bIkcIZ1KtzTm0oh3OxUFeqxoMk9E+3YiaYRU4c44ufP64zkKSjMTvl1QYNXWLKg== X-Received: by 2002:a05:6a00:418e:b0:727:3b77:4174 with SMTP id d2e1a72fcca58-72d22032685mr2848404b3a.23.1736317105090; Tue, 07 Jan 2025 22:18:25 -0800 (PST) Received: from localhost ([157.82.203.37]) by smtp.gmail.com with UTF8SMTPSA id d2e1a72fcca58-72aad90b949sm34327434b3a.176.2025.01.07.22.18.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 Jan 2025 22:18:24 -0800 (PST) From: Akihiko Odaki Date: Wed, 08 Jan 2025 15:17:52 +0900 Subject: [PATCH v4 3/4] qdev-properties: Add DEFINE_PROP_ON_OFF_AUTO_BIT64() MIME-Version: 1.0 Message-Id: <20250108-virtio-v4-3-cbf0aa04c9f9@daynix.com> References: <20250108-virtio-v4-0-cbf0aa04c9f9@daynix.com> In-Reply-To: <20250108-virtio-v4-0-cbf0aa04c9f9@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 , Markus Armbruster , Michael Roth , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Yanan Wang , Zhao Liu , Lei Yang Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1030.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_PASS=-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 bf27375a3ccd..0d161325e8dc 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 0081d79f9b7b..9be85cc6b7d6 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(const 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 Wed Jan 8 06:17:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 13930160 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 7E8E3E77188 for ; Wed, 8 Jan 2025 06:19:05 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tVPP3-0001Ne-W4; Wed, 08 Jan 2025 01:18:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tVPOn-00014d-Fu for qemu-devel@nongnu.org; Wed, 08 Jan 2025 01:18:39 -0500 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tVPOl-0000Hz-Gn for qemu-devel@nongnu.org; Wed, 08 Jan 2025 01:18:37 -0500 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-2eec9b3a1bbso19036675a91.3 for ; Tue, 07 Jan 2025 22:18:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1736317114; x=1736921914; 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=2WfOdMFhpM56iLiHN39KodrUfzohEYj4wntvgr2yc0s=; b=t1bIMh1HbQAJbHvENp29dHt/V279atF1P9w/6PCXQoKP84ofVsVOjtPuxZA89geiGS LASky3P+6VnUFroKZ1MlWzHbn0+NIrtU8QKMFgXSwujwq7za31/V912RGNslLqByv1cs OVU2wLHGzblJoMZEFhcVk7HB/KBvwVpXaYoESSL5exYVRfARsCqh3WEQl/XfAqPWJPcV YfFASFOV5y1NNCna7fkE1LLPHhle67KynOXa0hkb+DaSqjAU/wXqWSYivd64ZT0bW99X j3SX/bUAT9kqXp+Nt6hsdKSJdNnQ3K1SDINghV1u/UlyyimBiWIszeO/VdltXZgjlBPt gOzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736317114; x=1736921914; 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=2WfOdMFhpM56iLiHN39KodrUfzohEYj4wntvgr2yc0s=; b=lVryJb5Z0lt47OsQih1DO7hIdTYFJg7mwK1LBrW1URwnTqY3uTd1bDj5Ear25xO8vD TxymWAdR5rGMPOxFh01nCU/K2Zqoy5Obw8ybpQWtlyjrwOtH9XHxbF6Qnp0Mzrfjxc9e dQn8xHDJoBEIiK/+YDvR5/JfBxlPIUddvy5WdyYb+jhY8vwCW0v7VEPsjpO7wbp7P/oJ KquzRf+xaP/T7v/ADzqw6YtXZieGMkufkyJRnu0FQLaxA1wSgGtKpCaA/bNdoGhPQkhv NbnQ/adFMEYzOXOtQvlgXNnGU8ew0kIkRJE76xNITdJkK8XJOGdlsyXFeYgoVjHWfPHf 3JJQ== X-Gm-Message-State: AOJu0YwDPIWFMIZFyV+AZny5oo5RVzR/S5Jflan81n+KRTbpsKaWIqMS 4GU9570njWHjvlvp9ikQklRxzrgdrhTu5uMY9zy/LLGBG4RZkYKCDJ5LxEztp4A= X-Gm-Gg: ASbGncsqUR+5Aez7Hddpjl5z1ju+aW6nBfUKVV0swpfQFO3ql67oLEV2NgwoXJh9mgh uGJCJyvb0vQm6QGlZQnzJAW0UFJBlS/bJKQ2rOVzM/msLKV6x36J8wXYTejySTrF1AXVi7GTmuo 5q9/VNmWzfpRhYcQNyaho/0+wBt8e3c/RfH71s37CkPowdYzthLbhLW4eGCdYcb59YiZzPqesfE nN7OfLD8TLj0jWpx367e6kVrf67ZtE29pjA2s1UALMlsVUlx8BktlW3fgE= X-Google-Smtp-Source: AGHT+IE5Xte10lFwmZivfpV0OamABLydqvhHBdChutv75IqdB1WNBgiyHq9JpUhWtAb99ZRY7xfzKg== X-Received: by 2002:a17:90b:534b:b0:2ea:7329:43 with SMTP id 98e67ed59e1d1-2f548e9a5c2mr2411296a91.6.1736317113747; Tue, 07 Jan 2025 22:18:33 -0800 (PST) Received: from localhost ([157.82.203.37]) by smtp.gmail.com with UTF8SMTPSA id 98e67ed59e1d1-2f54a2ad2c5sm602841a91.26.2025.01.07.22.18.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 Jan 2025 22:18:33 -0800 (PST) From: Akihiko Odaki Date: Wed, 08 Jan 2025 15:17:53 +0900 Subject: [PATCH v4 4/4] virtio: Convert feature properties to OnOffAuto MIME-Version: 1.0 Message-Id: <20250108-virtio-v4-4-cbf0aa04c9f9@daynix.com> References: <20250108-virtio-v4-0-cbf0aa04c9f9@daynix.com> In-Reply-To: <20250108-virtio-v4-0-cbf0aa04c9f9@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 , Markus Armbruster , Michael Roth , Marcel Apfelbaum , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Yanan Wang , Zhao Liu , Lei Yang Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.14-dev-fd6e3 Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1034.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_PASS=-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 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 Tested-by: Lei Yang --- 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 638691028050..b854c2cb1d04 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; @@ -376,22 +379,23 @@ typedef struct VirtIOSCSIConf VirtIOSCSIConf; typedef struct VirtIORNGConf VirtIORNGConf; #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_AUTO), \ + DEFINE_PROP_ON_OFF_AUTO_BIT64("notify_on_empty", _state, _field, \ + VIRTIO_F_NOTIFY_ON_EMPTY, ON_OFF_AUTO_AUTO), \ + 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) 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 c949af97668d..bff26b95dd74 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -36,7 +36,9 @@ #include "hw/virtio/virtio-iommu.h" #include "audio/audio.h" -GlobalProperty hw_compat_9_2[] = {}; +GlobalProperty hw_compat_9_2[] = { + { TYPE_VIRTIO_DEVICE, "x-force-features-auto", "on" }, +}; const size_t hw_compat_9_2_len = G_N_ELEMENTS(hw_compat_9_2); GlobalProperty hw_compat_9_1[] = { 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 = virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM); bool vdev_has_iommu; Error *local_err = NULL; + uint64_t features; DPRINTF("%s: plug device.\n", qbus->name); @@ -63,13 +64,22 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp) /* Get the features of the plugged device. */ assert(vdc->get_features != NULL); - vdev->host_features = vdc->get_features(vdev, vdev->host_features, - &local_err); + features = vdev->host_features | vdev->requested_features.auto_bits | + vdev->requested_features.on_bits; + features = vdc->get_features(vdev, features, &local_err); if (local_err) { error_propagate(errp, local_err); return; } + if (!vdev->force_features_auto && + (features & vdev->requested_features.on_bits) != vdev->requested_features.on_bits) { + error_setg(errp, "A requested feature is not supported by the device"); + return; + } + + vdev->host_features = features; + if (klass->device_plugged != NULL) { klass->device_plugged(qbus->parent, &local_err); } diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 85110bce3744..83f803fc703d 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -4013,11 +4013,13 @@ static void virtio_device_instance_finalize(Object *obj) } static const Property virtio_properties[] = { - 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), }; static int virtio_device_start_ioeventfd_impl(VirtIODevice *vdev)