From nobody Tue Nov 26 04:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709650903; cv=none; d=zohomail.com; s=zohoarc; b=MSVnb5RPtVhqbzFC5j7lh9hjC3x/HyzWaS50PoiqX5KGxe3CS0uOi3yquLNKDJXUWxNRcCjXZcn10QM6qWjQOYUREPb0WP4iw7DS6JWSO2XFI3ZUYkHoF8WRMCWtmDpyhVg92N6RUK65rnvs06xiE1tDVK1Byhl8QKJwyRRAc6U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709650903; 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=ZsObEtGO0EGPs25uj/QR+XtkNGS9sHxVtQkIWny/Iio=; b=QqwLryVVrgEzxCjtpLBUHbKHyZFvLvstJ1dpR7vPaNsxq7RU7L7EH4uWxveskJoaxvUi3flMd8Uui463zU2W4HkHxBGQ3KIvCMyTP40V4hdQApD04F/JYoN4dFARus4gMXNr20onUph4VWxfrj6AvobRxLse2McANwc+qsvEDmQ= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709650903693450.58818581161404; Tue, 5 Mar 2024 07:01:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhWGi-0003Pg-1W; Tue, 05 Mar 2024 09:59:48 -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 1rhWGb-0003J5-9N for qemu-devel@nongnu.org; Tue, 05 Mar 2024 09:59:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhWGS-0004NJ-80 for qemu-devel@nongnu.org; Tue, 05 Mar 2024 09:59:39 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-523-EEbhA8f_N2OypNhGCwrP1Q-1; Tue, 05 Mar 2024 09:59:21 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A501B80026B; Tue, 5 Mar 2024 14:59:20 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 078C51121306; Tue, 5 Mar 2024 14:59:20 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 088C021E6A28; Tue, 5 Mar 2024 15:59:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709650768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZsObEtGO0EGPs25uj/QR+XtkNGS9sHxVtQkIWny/Iio=; b=Rjzq8c2sHPjK2nODgxmWcBRwUx+1CrL1EbCi13f9OKpfF1xeyHPq0hLesMZjy/3oxLlLjX EBFeyCMop73keCNgU5zJcEkYa0TiCysdJ0WUDiPhMl8IxRgitDdW8UvGhHQAsDqy7BvKul VXDkfLbOMpXzAtclVK9E10bOWpxzzUc= X-MC-Unique: EEbhA8f_N2OypNhGCwrP1Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, pbonzini@redhat.com, gaosong@loongson.cn, palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, richard.henderson@linaro.org, david@redhat.com, iii@linux.ibm.com, thuth@redhat.com, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Subject: [PATCH 1/4] target: Simplify type checks for CpuModelInfo member @props Date: Tue, 5 Mar 2024 15:59:15 +0100 Message-ID: <20240305145919.2186971-2-armbru@redhat.com> In-Reply-To: <20240305145919.2186971-1-armbru@redhat.com> References: <20240305145919.2186971-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 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: pass client-ip=170.10.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 @redhat.com) X-ZM-MESSAGEID: 1709650905233100001 Content-Type: text/plain; charset="utf-8" CpuModelInfo member @props is semantically a mapping from name to value, and syntactically a JSON object on the wire. This translates to QDict in C. Since the QAPI schema language lacks the means to express 'object', we use 'any' instead. This is QObject in C. Commands taking a CpuModelInfo argument need to check the QObject is a QDict. For arm, riscv, and s390x, the code checks right before passing the QObject to visit_start_struct(). visit_start_struct() then checks again. Delete the first check. The error message for @props that are not an object changes slightly to the the message we get for this kind of type error in other contexts. Minor improvement. Additionally, error messages about members of @props now refer to 'props.prop-name' instead of just 'prop-name'. Another minor improvement. Both changes are visible in tests/qtest/arm-cpu-features.c. Signed-off-by: Markus Armbruster Acked-by: Daniel Henrique Barboza --- target/arm/arm-qmp-cmds.c | 15 ++++----------- target/riscv/riscv-qmp-cmds.c | 19 +++++-------------- target/s390x/cpu_models_sysemu.c | 15 ++++----------- tests/qtest/arm-cpu-features.c | 12 ++++++------ 4 files changed, 19 insertions(+), 42 deletions(-) diff --git a/target/arm/arm-qmp-cmds.c b/target/arm/arm-qmp-cmds.c index 2250cd7ddf..0167759730 100644 --- a/target/arm/arm-qmp-cmds.c +++ b/target/arm/arm-qmp-cmds.c @@ -104,7 +104,7 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(Cp= uModelExpansionType type, Error **errp) { CpuModelExpansionInfo *expansion_info; - const QDict *qdict_in =3D NULL; + const QDict *qdict_in; QDict *qdict_out; ObjectClass *oc; Object *obj; @@ -151,27 +151,20 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(= CpuModelExpansionType type, } } =20 - if (model->props) { - qdict_in =3D qobject_to(QDict, model->props); - if (!qdict_in) { - error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict"); - return NULL; - } - } - obj =3D object_new(object_class_get_name(oc)); =20 - if (qdict_in) { + if (model->props) { Visitor *visitor; Error *err =3D NULL; =20 visitor =3D qobject_input_visitor_new(model->props); - if (!visit_start_struct(visitor, NULL, NULL, 0, errp)) { + if (!visit_start_struct(visitor, "props", NULL, 0, errp)) { visit_free(visitor); object_unref(obj); return NULL; } =20 + qdict_in =3D qobject_to(QDict, model->props); i =3D 0; while ((name =3D cpu_model_advertised_features[i++]) !=3D NULL) { if (qdict_get(qdict_in, name)) { diff --git a/target/riscv/riscv-qmp-cmds.c b/target/riscv/riscv-qmp-cmds.c index c48b9cfa67..69dde0c3e7 100644 --- a/target/riscv/riscv-qmp-cmds.c +++ b/target/riscv/riscv-qmp-cmds.c @@ -129,18 +129,19 @@ static void riscv_obj_add_profiles_qdict(Object *obj,= QDict *qdict_out) } =20 static void riscv_cpuobj_validate_qdict_in(Object *obj, QObject *props, - const QDict *qdict_in, Error **errp) { + const QDict *qdict_in; const QDictEntry *qe; Visitor *visitor; Error *local_err =3D NULL; =20 visitor =3D qobject_input_visitor_new(props); - if (!visit_start_struct(visitor, NULL, NULL, 0, &local_err)) { + if (!visit_start_struct(visitor, "props", NULL, 0, &local_err)) { goto err; } =20 + qdict_in =3D qobject_to(QDict, props); for (qe =3D qdict_first(qdict_in); qe; qe =3D qdict_next(qdict_in, qe)= ) { object_property_find_err(obj, qe->key, &local_err); if (local_err) { @@ -170,7 +171,6 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(Cp= uModelExpansionType type, Error **errp) { CpuModelExpansionInfo *expansion_info; - const QDict *qdict_in =3D NULL; QDict *qdict_out; ObjectClass *oc; Object *obj; @@ -188,14 +188,6 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(C= puModelExpansionType type, return NULL; } =20 - if (model->props) { - qdict_in =3D qobject_to(QDict, model->props); - if (!qdict_in) { - error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict"); - return NULL; - } - } - obj =3D object_new(object_class_get_name(oc)); =20 riscv_check_if_cpu_available(RISCV_CPU(obj), &local_err); @@ -205,9 +197,8 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(Cp= uModelExpansionType type, return NULL; } =20 - if (qdict_in) { - riscv_cpuobj_validate_qdict_in(obj, model->props, qdict_in, - &local_err); + if (model->props) { + riscv_cpuobj_validate_qdict_in(obj, model->props, &local_err); if (local_err) { error_propagate(errp, local_err); object_unref(obj); diff --git a/target/s390x/cpu_models_sysemu.c b/target/s390x/cpu_models_sys= emu.c index 63981bf36b..ef19724888 100644 --- a/target/s390x/cpu_models_sysemu.c +++ b/target/s390x/cpu_models_sysemu.c @@ -101,21 +101,13 @@ static void cpu_model_from_info(S390CPUModel *model, = const CpuModelInfo *info, Error **errp) { Error *err =3D NULL; - const QDict *qdict =3D NULL; + const QDict *qdict; const QDictEntry *e; Visitor *visitor; ObjectClass *oc; S390CPU *cpu; Object *obj; =20 - if (info->props) { - qdict =3D qobject_to(QDict, info->props); - if (!qdict) { - error_setg(errp, QERR_INVALID_PARAMETER_TYPE, "props", "dict"); - return; - } - } - oc =3D cpu_class_by_name(TYPE_S390_CPU, info->name); if (!oc) { error_setg(errp, "The CPU definition \'%s\' is unknown.", info->na= me); @@ -135,13 +127,14 @@ static void cpu_model_from_info(S390CPUModel *model, = const CpuModelInfo *info, return; } =20 - if (qdict) { + if (info->props) { visitor =3D qobject_input_visitor_new(info->props); - if (!visit_start_struct(visitor, NULL, NULL, 0, errp)) { + if (!visit_start_struct(visitor, "props", NULL, 0, errp)) { visit_free(visitor); object_unref(obj); return; } + qdict =3D qobject_to(QDict, info->props); for (e =3D qdict_first(qdict); e; e =3D qdict_next(qdict, e)) { if (!object_property_set(obj, e->key, visitor, &err)) { break; diff --git a/tests/qtest/arm-cpu-features.c b/tests/qtest/arm-cpu-features.c index a8a4c668ad..1daceb2e31 100644 --- a/tests/qtest/arm-cpu-features.c +++ b/tests/qtest/arm-cpu-features.c @@ -79,7 +79,7 @@ static const char *resp_get_error(QDict *resp) g_assert(_resp); \ _error =3D resp_get_error(_resp); \ g_assert(_error); \ - g_assert(g_str_equal(_error, expected_error)); \ + g_assert_cmpstr(_error, =3D=3D, expected_error); = \ qobject_unref(_resp); \ }) =20 @@ -194,8 +194,8 @@ static void assert_type_full(QTestState *qts) g_assert(resp); error =3D resp_get_error(resp); g_assert(error); - g_assert(g_str_equal(error, - "The requested expansion type is not supported")); + g_assert_cmpstr(error, =3D=3D, + "The requested expansion type is not supported"); qobject_unref(resp); } =20 @@ -212,8 +212,8 @@ static void assert_bad_props(QTestState *qts, const cha= r *cpu_type) g_assert(resp); error =3D resp_get_error(resp); g_assert(error); - g_assert(g_str_equal(error, - "Invalid parameter type for 'props', expected: di= ct")); + g_assert_cmpstr(error, =3D=3D, + "Invalid parameter type for 'props', expected: object"= ); qobject_unref(resp); } =20 @@ -446,7 +446,7 @@ static void test_query_cpu_model_expansion(const void *= data) assert_bad_props(qts, "max"); assert_error(qts, "foo", "The CPU type 'foo' is not a recognized " "ARM CPU type", NULL); - assert_error(qts, "max", "Parameter 'not-a-prop' is unexpected", + assert_error(qts, "max", "Parameter 'props.not-a-prop' is unexpected", "{ 'not-a-prop': false }"); assert_error(qts, "host", "The CPU type 'host' requires KVM", NULL); =20 --=20 2.44.0 From nobody Tue Nov 26 04:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709650818; cv=none; d=zohomail.com; s=zohoarc; b=GuMqJsosHrUK7mU1qalXdmc3CQMufC5m3uIwIxU1ojBiOtz/TRrW7eZB2SoKWe0M6OOENKGWXJFb57XbkbrfMvitJ2Z5IP50p/fLp8fyX/AQ/4kVyNcbiZXw5nsBfBp4DaPvXapjNRNpBdeQGJJCghgt3d7big5sq0J/CqczKdY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709650818; 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=JN/aaiSWygVR5weABBpFTY22hwpBCOu4fYNLdy0WinE=; b=Rqs++PR5nLLskF1nMOplj7o+ovyB0nBKD8fprvm3uu0EHsWr+I7hTjpUuTgjP70LX54UPXHgvzhq3wH+FoDUx/a05zD6f80M+rxeHEg+3KVExqwa+FB4/ZwmacrKdcCF+8BXcYDWCcYeD5zkbIl11pWasVwE/PdPmRNsqs3aUfY= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170965081847577.63775689230522; Tue, 5 Mar 2024 07:00:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhWGb-0003L7-Vy; Tue, 05 Mar 2024 09:59:42 -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 1rhWGU-0003Ae-IW for qemu-devel@nongnu.org; Tue, 05 Mar 2024 09:59:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhWGM-0004Kl-Py for qemu-devel@nongnu.org; Tue, 05 Mar 2024 09:59:32 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-175-UdLYpeQLOXah_aW4kI5jFg-1; Tue, 05 Mar 2024 09:59:21 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8B71F18172C2; Tue, 5 Mar 2024 14:59:20 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 07DAD2022C24; Tue, 5 Mar 2024 14:59:20 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0C68A21E691E; Tue, 5 Mar 2024 15:59:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709650765; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JN/aaiSWygVR5weABBpFTY22hwpBCOu4fYNLdy0WinE=; b=EJh/BnA8r8JWcOm7j2HWbxvFO8ZCAaYto2Qe0zgkalxV2Yq9H+v9E6mdh/YSBTEUnp9Kow ZU4glXrRp2Xz+Cxjtd+NPYVcdgcmOQEVlqF0kaL3zeZpT4feAz7yBhk4GaV4gfOmM7XNdL kPD2jUfvuTRikcFXebLjH5nkmZDLKcQ= X-MC-Unique: UdLYpeQLOXah_aW4kI5jFg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, pbonzini@redhat.com, gaosong@loongson.cn, palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, richard.henderson@linaro.org, david@redhat.com, iii@linux.ibm.com, thuth@redhat.com, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Subject: [PATCH 2/4] target/i386: Fix query-cpu-model-expansion to reject props Date: Tue, 5 Mar 2024 15:59:16 +0100 Message-ID: <20240305145919.2186971-3-armbru@redhat.com> In-Reply-To: <20240305145919.2186971-1-armbru@redhat.com> References: <20240305145919.2186971-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 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: pass client-ip=170.10.129.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 @redhat.com) X-ZM-MESSAGEID: 1709650820663100001 Content-Type: text/plain; charset="utf-8" CpuModelInfo member @props is semantically a mapping from name to value, and syntactically a JSON object on the wire. This translates to QDict in C. Since the QAPI schema language lacks the means to express 'object', we use 'any' instead. This is QObject in C. Commands taking a CpuModelInfo argument need to check the QObject is a QDict. The i386 version of qmp_query_cpu_model_expansion() fails to check. Instead, @props is silently ignored when it's not an object. For instance, {"execute": "query-cpu-model-expansion", "arguments": {"type": "full", = "model": {"name": "qemu64", "props": null}}} succeeds. Fix by refactoring the code to match the other targets. Now the command fails as it should: {"error": {"class": "GenericError", "desc": "Invalid parameter type for= 'props', expected: object"}} Signed-off-by: Markus Armbruster --- target/i386/cpu-sysemu.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/target/i386/cpu-sysemu.c b/target/i386/cpu-sysemu.c index 7422096737..df91f97827 100644 --- a/target/i386/cpu-sysemu.c +++ b/target/i386/cpu-sysemu.c @@ -25,6 +25,7 @@ #include "qapi/error.h" #include "qapi/qapi-visit-run-state.h" #include "qapi/qmp/qdict.h" +#include "qapi/qobject-input-visitor.h" #include "qom/qom-qobject.h" #include "qapi/qapi-commands-machine-target.h" #include "hw/qdev-properties.h" @@ -129,20 +130,35 @@ static void x86_cpu_to_dict_full(X86CPU *cpu, QDict *= props) } } =20 -static void object_apply_props(Object *obj, QDict *props, Error **errp) +static void object_apply_props(Object *obj, QObject *props, Error **errp) { + Visitor *visitor; + QDict *qdict; const QDictEntry *prop; =20 - for (prop =3D qdict_first(props); prop; prop =3D qdict_next(props, pro= p)) { - if (!object_property_set_qobject(obj, qdict_entry_key(prop), - qdict_entry_value(prop), errp)) { - break; + visitor =3D qobject_input_visitor_new(props); + if (!visit_start_struct(visitor, "props", NULL, 0, errp)) { + visit_free(visitor); + return; + } + + qdict =3D qobject_to(QDict, props); + for (prop =3D qdict_first(qdict); prop; prop =3D qdict_next(qdict, pro= p)) { + if (!object_property_set(obj, qdict_entry_key(prop), + visitor, errp)) { + goto out; } } + + visit_check_struct(visitor, errp); +out: + visit_end_struct(visitor, NULL); + visit_free(visitor); } =20 /* Create X86CPU object according to model+props specification */ -static X86CPU *x86_cpu_from_model(const char *model, QDict *props, Error *= *errp) +static X86CPU *x86_cpu_from_model(const char *model, QObject *props, + Error **errp) { X86CPU *xc =3D NULL; X86CPUClass *xcc; @@ -187,8 +203,7 @@ qmp_query_cpu_model_expansion(CpuModelExpansionType typ= e, QDict *props =3D NULL; const char *base_name; =20 - xc =3D x86_cpu_from_model(model->name, qobject_to(QDict, model->props), - &err); + xc =3D x86_cpu_from_model(model->name, model->props, &err); if (err) { goto out; } --=20 2.44.0 From nobody Tue Nov 26 04:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709650860; cv=none; d=zohomail.com; s=zohoarc; b=epURtX4kseEb7pj/eBc4M/711Nxl5JVVsLmtqs0UVuSpBn2CoJJxm3vyd4iX1Qb96Zg70FoMiGQkRpsiV/S9MCgdn1U7cfRQiRvcCATn9fuuT1cAgy34+Usyw0f+v8DLje7FcyxeWud+08UMjpD1j4uD/Wh4wPYOkbPpnjIs6AU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709650860; 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=KiA1J7t/TfETNZzis3RCpaXizwbF9sMTr/y4i4JKHh4=; b=ShI94QHPUIT2aZIg26C/pcwwAp4flqKxaAOY9dS5u8hzydm+bVurq6EvxoKVi1J5agNYPe6gCrAIbgKG3++h5otHWC+zHCXs1zmBKWvcpWk0dBEbIXM8Uc/mz4C1KvTF8sDq2DD+02sPiVmZ7LkaHMieeWquMuGkGE86ARdn670= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709650860495610.5233284765197; Tue, 5 Mar 2024 07:01:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhWGe-0003NH-7m; Tue, 05 Mar 2024 09:59:44 -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 1rhWGW-0003Ci-D8 for qemu-devel@nongnu.org; Tue, 05 Mar 2024 09:59:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhWGN-0004Mk-NC for qemu-devel@nongnu.org; Tue, 05 Mar 2024 09:59:35 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-622-KufdTkPrPrSYhx4cHkvXSw-1; Tue, 05 Mar 2024 09:59:21 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A68248007AF; Tue, 5 Mar 2024 14:59:20 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2296F37FC; Tue, 5 Mar 2024 14:59:20 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0FD0D21E692E; Tue, 5 Mar 2024 15:59:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709650767; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KiA1J7t/TfETNZzis3RCpaXizwbF9sMTr/y4i4JKHh4=; b=Y6YcgU7g6yeDEA9wx2LzXvkf+VB22yHZKysU1MCs5ySBTbc4fXUoTja2f0hJ7mtCPZL1XR 7WgL1O4IjN5p9M8RI2Z9ePUTEebziEjuD/evMAt3unBfyMakLbsyrypEUfMzF+oPyCW7GH uoW4wm1cfC46Al6OLeSd2cnH+HxqgRU= X-MC-Unique: KufdTkPrPrSYhx4cHkvXSw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, pbonzini@redhat.com, gaosong@loongson.cn, palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, richard.henderson@linaro.org, david@redhat.com, iii@linux.ibm.com, thuth@redhat.com, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Subject: [PATCH 3/4] target: Improve error reporting for CpuModelInfo member @props Date: Tue, 5 Mar 2024 15:59:17 +0100 Message-ID: <20240305145919.2186971-4-armbru@redhat.com> In-Reply-To: <20240305145919.2186971-1-armbru@redhat.com> References: <20240305145919.2186971-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 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: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 @redhat.com) X-ZM-MESSAGEID: 1709650862979100003 Content-Type: text/plain; charset="utf-8" query-cpu-model-comparison, query-cpu-model-baseline, and query-cpu-model-expansion take CpuModelInfo arguments. Errors in @props members of these arguments are reported for 'props', without further context. For instance, s390x rejects {"execute": "query-cpu-model-comparison", "arguments": {"modela": {"nam= e": "z13", "props": {}}, "modelb": {"name": "z14", "props": []}}} with {"error": {"class": "GenericError", "desc": "Invalid parameter type for= 'props', expected: object"}} This is unusual; the common QAPI unmarshaling machinery would complain about 'modelb.props'. Our hand-written code to visit the @props member neglects to provide the context. Tweak it so it provides it. The command above now fails with {"error": {"class": "GenericError", "desc": "Invalid parameter type for= 'modelb.props', expected: dict"}} Signed-off-by: Markus Armbruster Acked-by: Daniel Henrique Barboza --- target/arm/arm-qmp-cmds.c | 2 +- target/i386/cpu-sysemu.c | 11 ++++++----- target/riscv/riscv-qmp-cmds.c | 6 ++++-- target/s390x/cpu_models_sysemu.c | 17 ++++++++++------- tests/qtest/arm-cpu-features.c | 5 +++-- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/target/arm/arm-qmp-cmds.c b/target/arm/arm-qmp-cmds.c index 0167759730..0efbee8af8 100644 --- a/target/arm/arm-qmp-cmds.c +++ b/target/arm/arm-qmp-cmds.c @@ -158,7 +158,7 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(Cp= uModelExpansionType type, Error *err =3D NULL; =20 visitor =3D qobject_input_visitor_new(model->props); - if (!visit_start_struct(visitor, "props", NULL, 0, errp)) { + if (!visit_start_struct(visitor, "model.props", NULL, 0, errp)) { visit_free(visitor); object_unref(obj); return NULL; diff --git a/target/i386/cpu-sysemu.c b/target/i386/cpu-sysemu.c index df91f97827..3f9093d285 100644 --- a/target/i386/cpu-sysemu.c +++ b/target/i386/cpu-sysemu.c @@ -130,14 +130,15 @@ static void x86_cpu_to_dict_full(X86CPU *cpu, QDict *= props) } } =20 -static void object_apply_props(Object *obj, QObject *props, Error **errp) +static void object_apply_props(Object *obj, QObject *props, + const char *props_arg_name, Error **errp) { Visitor *visitor; QDict *qdict; const QDictEntry *prop; =20 visitor =3D qobject_input_visitor_new(props); - if (!visit_start_struct(visitor, "props", NULL, 0, errp)) { + if (!visit_start_struct(visitor, props_arg_name, NULL, 0, errp)) { visit_free(visitor); return; } @@ -158,7 +159,7 @@ out: =20 /* Create X86CPU object according to model+props specification */ static X86CPU *x86_cpu_from_model(const char *model, QObject *props, - Error **errp) + const char *props_arg_name, Error **errp) { X86CPU *xc =3D NULL; X86CPUClass *xcc; @@ -172,7 +173,7 @@ static X86CPU *x86_cpu_from_model(const char *model, QO= bject *props, =20 xc =3D X86_CPU(object_new_with_class(OBJECT_CLASS(xcc))); if (props) { - object_apply_props(OBJECT(xc), props, &err); + object_apply_props(OBJECT(xc), props, props_arg_name, &err); if (err) { goto out; } @@ -203,7 +204,7 @@ qmp_query_cpu_model_expansion(CpuModelExpansionType typ= e, QDict *props =3D NULL; const char *base_name; =20 - xc =3D x86_cpu_from_model(model->name, model->props, &err); + xc =3D x86_cpu_from_model(model->name, model->props, "model.props", &e= rr); if (err) { goto out; } diff --git a/target/riscv/riscv-qmp-cmds.c b/target/riscv/riscv-qmp-cmds.c index 69dde0c3e7..ee7465297d 100644 --- a/target/riscv/riscv-qmp-cmds.c +++ b/target/riscv/riscv-qmp-cmds.c @@ -129,6 +129,7 @@ static void riscv_obj_add_profiles_qdict(Object *obj, Q= Dict *qdict_out) } =20 static void riscv_cpuobj_validate_qdict_in(Object *obj, QObject *props, + const char *props_arg_name, Error **errp) { const QDict *qdict_in; @@ -137,7 +138,7 @@ static void riscv_cpuobj_validate_qdict_in(Object *obj,= QObject *props, Error *local_err =3D NULL; =20 visitor =3D qobject_input_visitor_new(props); - if (!visit_start_struct(visitor, "props", NULL, 0, &local_err)) { + if (!visit_start_struct(visitor, props_arg_name, NULL, 0, &local_err))= { goto err; } =20 @@ -198,7 +199,8 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(Cp= uModelExpansionType type, } =20 if (model->props) { - riscv_cpuobj_validate_qdict_in(obj, model->props, &local_err); + riscv_cpuobj_validate_qdict_in(obj, model->props, "model.props", + &local_err); if (local_err) { error_propagate(errp, local_err); object_unref(obj); diff --git a/target/s390x/cpu_models_sysemu.c b/target/s390x/cpu_models_sys= emu.c index ef19724888..8338084d00 100644 --- a/target/s390x/cpu_models_sysemu.c +++ b/target/s390x/cpu_models_sysemu.c @@ -98,7 +98,7 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **= errp) } =20 static void cpu_model_from_info(S390CPUModel *model, const CpuModelInfo *i= nfo, - Error **errp) + const char *info_arg_name, Error **errp) { Error *err =3D NULL; const QDict *qdict; @@ -128,8 +128,11 @@ static void cpu_model_from_info(S390CPUModel *model, c= onst CpuModelInfo *info, } =20 if (info->props) { + g_autofree const char *props_name =3D g_strdup_printf("%s.props", + info_arg_name); + visitor =3D qobject_input_visitor_new(info->props); - if (!visit_start_struct(visitor, "props", NULL, 0, errp)) { + if (!visit_start_struct(visitor, props_name, NULL, 0, errp)) { visit_free(visitor); object_unref(obj); return; @@ -216,7 +219,7 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(Cp= uModelExpansionType type, bool delta_changes =3D false; =20 /* convert it to our internal representation */ - cpu_model_from_info(&s390_model, model, &err); + cpu_model_from_info(&s390_model, model, "model", &err); if (err) { error_propagate(errp, err); return NULL; @@ -254,12 +257,12 @@ CpuModelCompareInfo *qmp_query_cpu_model_comparison(C= puModelInfo *infoa, S390CPUModel modela, modelb; =20 /* convert both models to our internal representation */ - cpu_model_from_info(&modela, infoa, &err); + cpu_model_from_info(&modela, infoa, "modela", &err); if (err) { error_propagate(errp, err); return NULL; } - cpu_model_from_info(&modelb, infob, &err); + cpu_model_from_info(&modelb, infob, "modelb", &err); if (err) { error_propagate(errp, err); return NULL; @@ -331,13 +334,13 @@ CpuModelBaselineInfo *qmp_query_cpu_model_baseline(Cp= uModelInfo *infoa, uint8_t max_gen; =20 /* convert both models to our internal representation */ - cpu_model_from_info(&modela, infoa, &err); + cpu_model_from_info(&modela, infoa, "modela", &err); if (err) { error_propagate(errp, err); return NULL; } =20 - cpu_model_from_info(&modelb, infob, &err); + cpu_model_from_info(&modelb, infob, "modelb", &err); if (err) { error_propagate(errp, err); return NULL; diff --git a/tests/qtest/arm-cpu-features.c b/tests/qtest/arm-cpu-features.c index 1daceb2e31..9d6e6190d5 100644 --- a/tests/qtest/arm-cpu-features.c +++ b/tests/qtest/arm-cpu-features.c @@ -213,7 +213,8 @@ static void assert_bad_props(QTestState *qts, const cha= r *cpu_type) error =3D resp_get_error(resp); g_assert(error); g_assert_cmpstr(error, =3D=3D, - "Invalid parameter type for 'props', expected: object"= ); + "Invalid parameter type for 'model.props'," + " expected: object"); qobject_unref(resp); } =20 @@ -446,7 +447,7 @@ static void test_query_cpu_model_expansion(const void *= data) assert_bad_props(qts, "max"); assert_error(qts, "foo", "The CPU type 'foo' is not a recognized " "ARM CPU type", NULL); - assert_error(qts, "max", "Parameter 'props.not-a-prop' is unexpected", + assert_error(qts, "max", "Parameter 'model.props.not-a-prop' is unexpe= cted", "{ 'not-a-prop': false }"); assert_error(qts, "host", "The CPU type 'host' requires KVM", NULL); =20 --=20 2.44.0 From nobody Tue Nov 26 04:23:42 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1709650838; cv=none; d=zohomail.com; s=zohoarc; b=oBnjKraFyrCoDdQC7w0GDW+vqyKJ/Z1CP05+ro/6VqgTheCv9GrkuMvfJ5PgjaSsG/X2AMpX7vndAmROY2Y/JVTGJuKGqMBtp4xvca1dj51o9jwiybsdGnkSzr9aQApGLkDRTc3LkgYU8+2qYHgi3ik7IOr0QJpopGB1qBwBu1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709650838; 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=qqKaRVLtdHMKon90SaGobuzyOfD/PNTQBVyQJAnd0z4=; b=cuVSRqVd4aQzc+NaXjXzzuPJkbnoYJp6T/K0CFzDzZVhG4gsHUEx9064R4oLVwl9pnIM+58KLOp16KpWz7bj5zlt7lcHPdKue39pZohNB3qnOsOpLQgMQ5/Q9tMj65RvrpUwRAXRVgV/shGaBiQFmK1UyOFVjaS4YNN1ASvvyJM= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709650838007290.1673464695949; Tue, 5 Mar 2024 07:00:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhWGc-0003MD-Ps; Tue, 05 Mar 2024 09:59:42 -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 1rhWGU-0003Ad-Gl for qemu-devel@nongnu.org; Tue, 05 Mar 2024 09:59:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhWGM-0004Jt-Mx for qemu-devel@nongnu.org; Tue, 05 Mar 2024 09:59:32 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-632-u6r5BadhNd2AAZcgnGhvLA-1; Tue, 05 Mar 2024 09:59:21 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8894D800268; Tue, 5 Mar 2024 14:59:20 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.39.192.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2293E37F6; Tue, 5 Mar 2024 14:59:20 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 12FDA21E6939; Tue, 5 Mar 2024 15:59:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709650764; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qqKaRVLtdHMKon90SaGobuzyOfD/PNTQBVyQJAnd0z4=; b=fik72cBINmjhF2jucTMGYDhsM9q0Dg6FDZ49tUSAgU3y+S72XuEKQCyMv3gVXClzVVx7kQ 7O4symu3N/ES/BRwrGXmTkTwd7xTSZtyBAkZbdTCVUEcX5UH9v0wXQHTJqGvuRho9uRcec SgLnh4+yZ3ielx4nPg7sK2p7iRMD724= X-MC-Unique: u6r5BadhNd2AAZcgnGhvLA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, pbonzini@redhat.com, gaosong@loongson.cn, palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, liwei1518@gmail.com, dbarboza@ventanamicro.com, zhiwei_liu@linux.alibaba.com, richard.henderson@linaro.org, david@redhat.com, iii@linux.ibm.com, thuth@redhat.com, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Subject: [PATCH 4/4] target/loongarch: Fix query-cpu-model-expansion to reject props Date: Tue, 5 Mar 2024 15:59:18 +0100 Message-ID: <20240305145919.2186971-5-armbru@redhat.com> In-Reply-To: <20240305145919.2186971-1-armbru@redhat.com> References: <20240305145919.2186971-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 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: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.568, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable 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 @redhat.com) X-ZM-MESSAGEID: 1709650838685100001 Content-Type: text/plain; charset="utf-8" query-cpu-model-expansion takes a CpuModelInfo argument. The loongarch version of the command silently ignores the argument's member @props. For instance, {"execute": "query-cpu-model-expansion", "arguments": {"type": "static"= , "model": {"name": "la464", "props": null}}} and {"execute": "query-cpu-model-expansion", "arguments": {"type": "static"= , "model": {"name": "la464", "props": {"prop": null}}}} succeed. Add skeleton code for property processing that recognizes no properties. Now the two commands fail as they should: {"error": {"class": "GenericError", "desc": "Invalid parameter type for= 'model.props', expected: object"}} and {"error": {"class": "GenericError", "desc": "Parameter 'model.props.pro= p' is unexpected"}} Signed-off-by: Markus Armbruster --- target/loongarch/loongarch-qmp-cmds.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/target/loongarch/loongarch-qmp-cmds.c b/target/loongarch/loong= arch-qmp-cmds.c index ec33ce81f0..44d1f089b6 100644 --- a/target/loongarch/loongarch-qmp-cmds.c +++ b/target/loongarch/loongarch-qmp-cmds.c @@ -48,6 +48,8 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(CpuM= odelExpansionType type, CpuModelInfo *model, Error **errp) { + Visitor *visitor; + bool ok; CpuModelExpansionInfo *expansion_info; QDict *qdict_out; ObjectClass *oc; @@ -60,6 +62,21 @@ CpuModelExpansionInfo *qmp_query_cpu_model_expansion(Cpu= ModelExpansionType type, return NULL; } =20 + if (model->props) { + visitor =3D qobject_input_visitor_new(model->props); + if (!visit_start_struct(visitor, "model.props", NULL, 0, errp)) { + visit_free(visitor); + return NULL; + } + + ok =3D visit_check_struct(visitor, errp); + visit_end_struct(visitor, NULL); + visit_free(visitor); + if (!ok) { + return NULL; + } + } + oc =3D cpu_class_by_name(TYPE_LOONGARCH_CPU, model->name); if (!oc) { error_setg(errp, "The CPU type '%s' is not a recognized LoongArch = CPU type", --=20 2.44.0