Received: by 2002:a19:6b17:0:0:0:0:0 with SMTP id d23csp4733579lfa; Tue, 20 Oct 2020 05:19:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRJHirNRzYOGdNhOBkikd6WDQikwqxIAYzXgTvqrmFaqhaha6SLMSwytavYG7D2PiezxS6 X-Received: by 2002:a25:24c7:: with SMTP id k190mr3783422ybk.483.1603196393391; Tue, 20 Oct 2020 05:19:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603196393; cv=none; d=google.com; s=arc-20160816; b=TzCYXlTz5DCRkO5bIJX+O+EUwPiSrHQS7u3duYfzEYlU9dJADsLioAynQbLzXqxP5n AhNK4cBCDu68ND8TR/2h5aeZ7u6Env1IuUc6YU6oSsvx4c5l//w/Rhgds9Wcv4F7jl1G CfkuqLrj8d4w7Joh0sH9kRM7xmUxP/Us+fBu6PfrNxppwi4r8uVwq0ACHzGOU7YYUphW hEI6ssT6scv2/u6JcVN2VuLkDuZN/M/eUOg8W0UCbDls67RsuiwafXu5YCiVrgy4wlqi UfDMsBqJDbt32OF8MNZVw7UMvK8sQq6ZkwNHXKrWIqxv0FqlZlo9Pu1INnkDGUieo/Hn BqRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject; bh=K/Nm8tt7m/fK/XdT/m9JKyo5aqnf1KoGNVj9IDHL8EQ=; b=iEZ5YXptjwolw5DbzJtiQEBP3SKG1IuPN7iE61msPUuQDpkUeq9hFCMAK0bYAhT1bp CQ4eRdRcuZlHKPtSKP6f8VkxWjgsHDTgUMbxTWal/p150GlNWtLr0X4ci0FtR6gjiYZe VCnjCjaj/lrOg3MiqdbgEWSAHgSmIe8MkvhJj1kKIVIZ/MzNTwN+xf219otoFqTxam73 qUqTY15V9zDtiZ2dVxvkjzdP4xkvdO05LzPkH/FaydQ+uxlL5VFajauP1CRKSWG++e7n rH1p6KeJ8fvTXvFI7BzY1F6kSTba86TztptA68GNSP4JA50l18LcqHDBJYuRWx2fOnjj PctQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x77si2054282ybe.215.2020.10.20.05.19.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Oct 2020 05:19:53 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Received: from localhost ([::1]:58938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kUqcK-0000Es-OV for alex.bennee@linaro.org; Tue, 20 Oct 2020 08:19:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37372) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUqc9-0000DW-2Z; Tue, 20 Oct 2020 08:19:41 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:33530 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUqc6-0008Hx-Nh; Tue, 20 Oct 2020 08:19:40 -0400 Received: from DGGEMM405-HUB.china.huawei.com (unknown [172.30.72.57]) by Forcepoint Email with ESMTP id C2F9EDAD1F637220E8CB; Tue, 20 Oct 2020 20:19:29 +0800 (CST) Received: from dggema765-chm.china.huawei.com (10.1.198.207) by DGGEMM405-HUB.china.huawei.com (10.3.20.213) with Microsoft SMTP Server (TLS) id 14.3.487.0; Tue, 20 Oct 2020 20:19:29 +0800 Received: from [10.174.185.187] (10.174.185.187) by dggema765-chm.china.huawei.com (10.1.198.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1913.5; Tue, 20 Oct 2020 20:19:29 +0800 Subject: Re: [PATCH] microbit_i2c: Fix coredump when dump-vmstate To: Peter Maydell References: <20201019093401.2993833-1-liangpeng10@huawei.com> <786deb83-b6f4-d778-d5ed-19f3901ad211@redhat.com> <0c174303-50bc-128a-26ab-c062f98cd6cd@huawei.com> From: Peng Liang Message-ID: <8670055b-e7b6-1bfa-22c9-b9e1e0fe473c@huawei.com> Date: Tue, 20 Oct 2020 20:19:28 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.2.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.185.187] X-ClientProxiedBy: dggeme717-chm.china.huawei.com (10.1.199.113) To dggema765-chm.china.huawei.com (10.1.198.207) X-CFilter-Loop: Reflected Received-SPF: pass client-ip=45.249.212.255; envelope-from=liangpeng10@huawei.com; helo=huawei.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/20 08:19:30 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhanghailiang , QEMU Developers , Xiangyou Xie , qemu-arm , Joel Stanley , =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: zFew6RCHLDK1 On 10/20/2020 7:27 PM, Peter Maydell wrote: > On Tue, 20 Oct 2020 at 12:17, Peng Liang wrote: >> >> On 10/19/2020 6:35 PM, Philippe Mathieu-Daudé wrote: >>> On 10/19/20 11:34 AM, Peng Liang wrote: >>>> VMStateDescription.fields should be end with VMSTATE_END_OF_LIST(). >>>> However, microbit_i2c_vmstate doesn't follow it. Let's change it. >>> >>> It might be easy to add a Coccinelle script to avoid future errors. >>> >>> Reviewed-by: Philippe Mathieu-Daudé >>> >> >> I tried to add a Coccinelle script to add VMSTATE_END_OF_LIST() to the >> end of VMStateDescription.fields. For those who are not defined as >> compound literals, it works well. However, I cannot make it work for >> those defined as compound literals. And Julia doesn't think compound >> literals are supported currently[1]. So maybe currently it's hard to >> check the error using Coccinelle :( > > I think we could probably significantly increase the chances that > people find "missing terminator" errors in the course of normal > debugging of their device if we made the terminator be something > other than "is field->name NULL". That condition is quite likely > to be satisfied by accident shortly after the real end-of-data > (because zeroes are easy to find in memory), whereas if the condition > is "field->flags is a magic number", for instance, then the chances of > it being satisfied by accident are very low, and so a simple "loop > through the field array until we find the end" is pretty likely to > hang/crash. (If we don't already have such a loop we might need to > add one in debug mode when a vmstate is registered.) > > (This is why the REGINFO_SENTINEL used for Arm cpreg arrays is > not a simple all-zeroes value, incidentally.) > > thanks > -- PMM > . > I found that field->flags is a bit-or field, so maybe all 0xf or other magic number is still meaningful? Can we use field->version_id or field->struct_version_id as the condition? I found they are all int type but used as non-negative, so can we use field->version_id/field->struct_version_id == magic number (for example, -1) as a sentinel? -- Thanks, Peng