From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A71B16AA6; Tue, 2 Jan 2024 07:44:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4T44cJ1gRPz1wrQm; Tue, 2 Jan 2024 15:44:16 +0800 (CST) Received: from dggpemm500006.china.huawei.com (unknown [7.185.36.236]) by mail.maildlp.com (Postfix) with ESMTPS id C2A061A0192; Tue, 2 Jan 2024 15:44:29 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 2 Jan 2024 15:44:29 +0800 Received: from [10.67.121.229] (10.67.121.229) by dggpemm500007.china.huawei.com (7.185.36.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 2 Jan 2024 15:44:29 +0800 Subject: Re: [PATCH iproute2-rc 1/2] rdma: Fix core dump when pretty is used To: Stephen Hemminger , Junxian Huang References: <20231229065241.554726-1-huangjunxian6@hisilicon.com> <20231229065241.554726-2-huangjunxian6@hisilicon.com> <20231229092129.25a526c4@hermes.local> CC: , , , , , , From: Chengchang Tang Message-ID: <30d8c237-953a-8794-9baa-e21b31d4d88c@huawei.com> Date: Tue, 2 Jan 2024 15:44:29 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20231229092129.25a526c4@hermes.local> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500007.china.huawei.com (7.185.36.183) On 2023/12/30 1:21, Stephen Hemminger wrote: > On Fri, 29 Dec 2023 14:52:40 +0800 > Junxian Huang wrote: > >> From: Chengchang Tang >> >> There will be a core dump when pretty is used as the JSON object >> hasn't been opened and closed properly. >> >> Before: >> $ rdma res show qp -jp -dd >> [ { >> "ifindex": 1, >> "ifname": "hns_1", >> "port": 1, >> "lqpn": 1, >> "type": "GSI", >> "state": "RTS", >> "sq-psn": 0, >> "comm": "ib_core" >> }, >> "drv_sq_wqe_cnt": 128, >> "drv_sq_max_gs": 2, >> "drv_rq_wqe_cnt": 512, >> "drv_rq_max_gs": 1, >> rdma: json_writer.c:130: jsonw_end: Assertion `self->depth > 0' failed. >> Aborted (core dumped) >> >> After: >> $ rdma res show qp -jp -dd >> [ { >> "ifindex": 2, >> "ifname": "hns_2", >> "port": 1, >> "lqpn": 1, >> "type": "GSI", >> "state": "RTS", >> "sq-psn": 0, >> "comm": "ib_core",{ >> "drv_sq_wqe_cnt": 128, >> "drv_sq_max_gs": 2, >> "drv_rq_wqe_cnt": 512, >> "drv_rq_max_gs": 1, >> "drv_ext_sge_sge_cnt": 256 >> } >> } ] >> >> Fixes: 331152752a97 ("rdma: print driver resource attributes") >> Signed-off-by: Chengchang Tang >> Signed-off-by: Junxian Huang > This code in rdma seems to be miking json and newline functionality > which creates bug traps. > > Also the json should have same effective output in pretty and non-pretty mode. > It looks like since pretty mode add extra object layer, the nesting of {} would be > different. > > The conversion to json_print() was done but it isn't using same conventions > as ip or tc. > > The correct fix needs to go deeper and hit other things. > Hi, Stephen, The root cause of this issue is that close_json_object() is being called in newline_indent(), resulting in a mismatch of {}. When fixing this problem, I was unsure why a newline() is needed in pretty mode, so I simply kept this logic and solved the issue of open_json_object() and close_json_object() not matching. However, If the output of pretty mode and not-pretty mode should be the same, then this problem can be resolved by deleting this newline_indent(). I believe the original developer may not have realized that close_json_object() is being called in newline(), which leads to this problem. To improve the code's readability, I would try to strip out close_json_obejct() from newline(). Thanks, Chengchang Tang