From nobody Sun Dec 14 06:20:36 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98E04C00140 for ; Mon, 15 Aug 2022 19:23:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245594AbiHOTXu (ORCPT ); Mon, 15 Aug 2022 15:23:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344499AbiHOTVQ (ORCPT ); Mon, 15 Aug 2022 15:21:16 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0E58B77; Mon, 15 Aug 2022 11:40:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 30713B81082; Mon, 15 Aug 2022 18:40:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C69DC433B5; Mon, 15 Aug 2022 18:40:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588813; bh=sl4Fi1GtVI3xilBeMMiFXxAxo/7l7eg0v2oFNV/ihkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TyZ0HKj4cteyi7NuonNcqxXVZndXUp8t0E4Fa0E/G3kFhnY9AZKdaaNzKCH6bHoom njvzUnbwEyObiPjWbAEl43Hbx5h7gRAJjqPTs4GcIwteTUyJLvSlJWYm+MtKxjQWvw fyKjl17/kVPYyfd7eb0kObVqVyV3PQztSirFkPf0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Ogness , Petr Mladek , Sasha Levin Subject: [PATCH 5.15 521/779] scripts/gdb: lx-dmesg: read records individually Date: Mon, 15 Aug 2022 20:02:45 +0200 Message-Id: <20220815180359.514327692@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: John Ogness [ Upstream commit deaee2704a157dfcca77301ddaa10c62a9840952 ] For the gdb command lx-dmesg, the entire descriptor, info, and text data regions are read into memory before printing any records. For large kernel log buffers, this not only causes a huge delay before seeing any records, but it may also lead to python errors of too much memory allocation. Rather than reading in all these regions in advance, read them as needed and only read the regions for the particular record that is being printed. The gdb macro "dmesg" in Documentation/admin-guide/kdump/gdbmacros.txt already prints out the kernel log buffer like this. Signed-off-by: John Ogness Signed-off-by: Petr Mladek Link: https://lore.kernel.org/r/874k79c3a9.fsf@jogness.linutronix.de Signed-off-by: Sasha Levin --- scripts/gdb/linux/dmesg.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/scripts/gdb/linux/dmesg.py b/scripts/gdb/linux/dmesg.py index a92c55bd8de5..d5983cf3db7d 100644 --- a/scripts/gdb/linux/dmesg.py +++ b/scripts/gdb/linux/dmesg.py @@ -44,19 +44,17 @@ class LxDmesg(gdb.Command): sz =3D prb_desc_ring_type.get_type().sizeof desc_ring =3D utils.read_memoryview(inf, addr, sz).tobytes() =20 - # read in descriptor array + # read in descriptor count, size, and address off =3D prb_desc_ring_type.get_type()['count_bits'].bitpos // 8 desc_ring_count =3D 1 << utils.read_u32(desc_ring, off) desc_sz =3D prb_desc_type.get_type().sizeof off =3D prb_desc_ring_type.get_type()['descs'].bitpos // 8 - addr =3D utils.read_ulong(desc_ring, off) - descs =3D utils.read_memoryview(inf, addr, desc_sz * desc_ring_cou= nt).tobytes() + desc_addr =3D utils.read_ulong(desc_ring, off) =20 - # read in info array + # read in info size and address info_sz =3D printk_info_type.get_type().sizeof off =3D prb_desc_ring_type.get_type()['infos'].bitpos // 8 - addr =3D utils.read_ulong(desc_ring, off) - infos =3D utils.read_memoryview(inf, addr, info_sz * desc_ring_cou= nt).tobytes() + info_addr =3D utils.read_ulong(desc_ring, off) =20 # read in text data ring structure off =3D printk_ringbuffer_type.get_type()['text_data_ring'].bitpos= // 8 @@ -64,12 +62,11 @@ class LxDmesg(gdb.Command): sz =3D prb_data_ring_type.get_type().sizeof text_data_ring =3D utils.read_memoryview(inf, addr, sz).tobytes() =20 - # read in text data + # read in text data size and address off =3D prb_data_ring_type.get_type()['size_bits'].bitpos // 8 text_data_sz =3D 1 << utils.read_u32(text_data_ring, off) off =3D prb_data_ring_type.get_type()['data'].bitpos // 8 - addr =3D utils.read_ulong(text_data_ring, off) - text_data =3D utils.read_memoryview(inf, addr, text_data_sz).tobyt= es() + text_data_addr =3D utils.read_ulong(text_data_ring, off) =20 counter_off =3D atomic_long_type.get_type()['counter'].bitpos // 8 =20 @@ -102,17 +99,20 @@ class LxDmesg(gdb.Command): desc_off =3D desc_sz * ind info_off =3D info_sz * ind =20 + desc =3D utils.read_memoryview(inf, desc_addr + desc_off, desc= _sz).tobytes() + # skip non-committed record - state =3D 3 & (utils.read_u64(descs, desc_off + sv_off + - counter_off) >> desc_flags_shift) + state =3D 3 & (utils.read_u64(desc, sv_off + counter_off) >> d= esc_flags_shift) if state !=3D desc_committed and state !=3D desc_finalized: if did =3D=3D head_id: break did =3D (did + 1) & desc_id_mask continue =20 - begin =3D utils.read_ulong(descs, desc_off + begin_off) % text= _data_sz - end =3D utils.read_ulong(descs, desc_off + next_off) % text_da= ta_sz + begin =3D utils.read_ulong(desc, begin_off) % text_data_sz + end =3D utils.read_ulong(desc, next_off) % text_data_sz + + info =3D utils.read_memoryview(inf, info_addr + info_off, info= _sz).tobytes() =20 # handle data-less record if begin & 1 =3D=3D 1: @@ -125,16 +125,17 @@ class LxDmesg(gdb.Command): # skip over descriptor id text_start =3D begin + utils.get_long_type().sizeof =20 - text_len =3D utils.read_u16(infos, info_off + len_off) + text_len =3D utils.read_u16(info, len_off) =20 # handle truncated message if end - text_start < text_len: text_len =3D end - text_start =20 - text =3D text_data[text_start:text_start + text_len].decod= e( - encoding=3D'utf8', errors=3D'replace') + text_data =3D utils.read_memoryview(inf, text_data_addr + = text_start, + text_len).tobytes() + text =3D text_data[0:text_len].decode(encoding=3D'utf8', e= rrors=3D'replace') =20 - time_stamp =3D utils.read_u64(infos, info_off + ts_off) + time_stamp =3D utils.read_u64(info, ts_off) =20 for line in text.splitlines(): msg =3D u"[{time:12.6f}] {line}\n".format( --=20 2.35.1