From nobody Tue Nov 26 18:25:50 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=1705688201; cv=none; d=zohomail.com; s=zohoarc; b=X3QlvKQx/TubB5I3G3KtuihvjMevfRtXGdqnlndpCLznZaTudMNPvfQioMqTy0r1ieBiUNfeKgDtGaIjD6tnRhQ/OqGYqBx7J/tPvlHQL5Rqeq+C72cM1rd3dDQ8Z+eAzUUMmXzYC9pBVnXuwnYFUs2mvy48WgKH+LHtRCZ7G1Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705688201; h=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=5sC1mg7x2fL1b69hJeYewTvKHdoYdK1EgellCnZKA5s=; b=QukjfnJST+9hYU8NlmUPyTy+hkEbUUsUO3OAfGIei7qaaI1CUKCvCq/+Eh0n4hiwJZoKbCseVAuO05xHS07FqE7aDfWaCyRQ0iJB0EusayrTlTJQvjDAwuo2JiRB2fca3zdiGGw9Lp6kag9UhQq7OkOTo0jEeSbTHYyZUpV54uQ= 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 1705688201362344.95475716168426; Fri, 19 Jan 2024 10:16:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rQtNK-0001gl-66; Fri, 19 Jan 2024 13:13: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 1rQtN8-0001cw-KY for qemu-devel@nongnu.org; Fri, 19 Jan 2024 13:13:43 -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 1rQtN5-0007aG-V7 for qemu-devel@nongnu.org; Fri, 19 Jan 2024 13:13:42 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-441-DgXMf4ZdM8u35VRvKTx3Dw-1; Fri, 19 Jan 2024 13:13:35 -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 8DA003C11CDF; Fri, 19 Jan 2024 18:13:34 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2727494; Fri, 19 Jan 2024 18:13:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705688018; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5sC1mg7x2fL1b69hJeYewTvKHdoYdK1EgellCnZKA5s=; b=b9Khme8vVosBQgx2NEdlqAnml7nu47Knu1aorgxjDZCagKKrWgZwq1V3JCS1hJGoeRRhvK M0iOiRu3iPtdCU0JbI3LCj/08muXLtCZ68tiSBDejLU8Aubr6hfdv/jTaktMz3aJwVHDsc gcLVYt6oKwMq5cF5l0czAVZ21cq7hDw= X-MC-Unique: DgXMf4ZdM8u35VRvKTx3Dw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 02/14] string-output-visitor: Fix (pseudo) struct handling Date: Fri, 19 Jan 2024 19:13:15 +0100 Message-ID: <20240119181327.236745-3-kwolf@redhat.com> In-Reply-To: <20240119181327.236745-1-kwolf@redhat.com> References: <20240119181327.236745-1-kwolf@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.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -45 X-Spam_score: -4.6 X-Spam_bar: ---- X-Spam_report: (-4.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.519, 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: 1705688202218100003 Content-Type: text/plain; charset="utf-8" Commit ff32bb53 tried to get minimal struct support into the string output visitor by just making it return "". Unfortunately, it forgot that the caller will still make more visitor calls for the content of the struct. If the struct is contained in a list, such as IOThreadVirtQueueMapping, in the better case its fields show up as separate list entries. In the worse case, it contains another list, and the string output visitor doesn't support nested lists and asserts that this doesn't happen. So as soon as the optional "vqs" field in IOThreadVirtQueueMapping is specified, we get a crash. This can be reproduced with the following command line: echo "info qtree" | ./qemu-system-x86_64 \ -object iothread,id=3Dt0 \ -blockdev null-co,node-name=3Ddisk \ -device '{"driver": "virtio-blk-pci", "drive": "disk", "iothread-vq-mapping": [{"iothread": "t0", "vqs": [0]}]}' \ -monitor stdio Fix the problem by counting the nesting level of structs and ignoring any visitor calls for values (apart from start/end_struct) while we're not on the top level. Lists nested directly within lists remain unimplemented, as we don't currently have a use case for them. Fixes: ff32bb53476539d352653f4ed56372dced73a388 Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2069 Reported-by: Aihua Liang Signed-off-by: Kevin Wolf Message-ID: <20240109181717.42493-1-kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- qapi/string-output-visitor.c | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/qapi/string-output-visitor.c b/qapi/string-output-visitor.c index f0c1dea89e..5115536b15 100644 --- a/qapi/string-output-visitor.c +++ b/qapi/string-output-visitor.c @@ -65,6 +65,7 @@ struct StringOutputVisitor } range_start, range_end; GList *ranges; void *list; /* Only needed for sanity checking the caller */ + unsigned int struct_nesting; }; =20 static StringOutputVisitor *to_sov(Visitor *v) @@ -144,6 +145,10 @@ static bool print_type_int64(Visitor *v, const char *n= ame, int64_t *obj, StringOutputVisitor *sov =3D to_sov(v); GList *l; =20 + if (sov->struct_nesting) { + return true; + } + switch (sov->list_mode) { case LM_NONE: string_output_append(sov, *obj); @@ -231,6 +236,10 @@ static bool print_type_size(Visitor *v, const char *na= me, uint64_t *obj, uint64_t val; char *out, *psize; =20 + if (sov->struct_nesting) { + return true; + } + if (!sov->human) { out =3D g_strdup_printf("%"PRIu64, *obj); string_output_set(sov, out); @@ -250,6 +259,11 @@ static bool print_type_bool(Visitor *v, const char *na= me, bool *obj, Error **errp) { StringOutputVisitor *sov =3D to_sov(v); + + if (sov->struct_nesting) { + return true; + } + string_output_set(sov, g_strdup(*obj ? "true" : "false")); return true; } @@ -260,6 +274,10 @@ static bool print_type_str(Visitor *v, const char *nam= e, char **obj, StringOutputVisitor *sov =3D to_sov(v); char *out; =20 + if (sov->struct_nesting) { + return true; + } + if (sov->human) { out =3D *obj ? g_strdup_printf("\"%s\"", *obj) : g_strdup(""= ); } else { @@ -273,6 +291,11 @@ static bool print_type_number(Visitor *v, const char *= name, double *obj, Error **errp) { StringOutputVisitor *sov =3D to_sov(v); + + if (sov->struct_nesting) { + return true; + } + string_output_set(sov, g_strdup_printf("%.17g", *obj)); return true; } @@ -283,6 +306,10 @@ static bool print_type_null(Visitor *v, const char *na= me, QNull **obj, StringOutputVisitor *sov =3D to_sov(v); char *out; =20 + if (sov->struct_nesting) { + return true; + } + if (sov->human) { out =3D g_strdup(""); } else { @@ -295,6 +322,9 @@ static bool print_type_null(Visitor *v, const char *nam= e, QNull **obj, static bool start_struct(Visitor *v, const char *name, void **obj, size_t size, Error **errp) { + StringOutputVisitor *sov =3D to_sov(v); + + sov->struct_nesting++; return true; } =20 @@ -302,6 +332,10 @@ static void end_struct(Visitor *v, void **obj) { StringOutputVisitor *sov =3D to_sov(v); =20 + if (--sov->struct_nesting) { + return; + } + /* TODO actually print struct fields */ string_output_set(sov, g_strdup("")); } @@ -312,6 +346,10 @@ start_list(Visitor *v, const char *name, GenericList *= *list, size_t size, { StringOutputVisitor *sov =3D to_sov(v); =20 + if (sov->struct_nesting) { + return true; + } + /* we can't traverse a list in a list */ assert(sov->list_mode =3D=3D LM_NONE); /* We don't support visits without a list */ @@ -329,6 +367,10 @@ static GenericList *next_list(Visitor *v, GenericList = *tail, size_t size) StringOutputVisitor *sov =3D to_sov(v); GenericList *ret =3D tail->next; =20 + if (sov->struct_nesting) { + return ret; + } + if (ret && !ret->next) { sov->list_mode =3D LM_END; } @@ -339,6 +381,10 @@ static void end_list(Visitor *v, void **obj) { StringOutputVisitor *sov =3D to_sov(v); =20 + if (sov->struct_nesting) { + return; + } + assert(sov->list =3D=3D obj); assert(sov->list_mode =3D=3D LM_STARTED || sov->list_mode =3D=3D LM_END || --=20 2.43.0