Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4451080imw; Tue, 19 Jul 2022 06:54:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sZ855DWrWUY9Q6KeJ6SvGcmRjD45qs4Ekkt9EQNf7WsS4MEkxd7u9tC7JKx6VP6WtuThAt X-Received: by 2002:a05:6402:c0b:b0:43a:25ff:ff08 with SMTP id co11-20020a0564020c0b00b0043a25ffff08mr44499000edb.148.1658238881696; Tue, 19 Jul 2022 06:54:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658238881; cv=none; d=google.com; s=arc-20160816; b=vugUHJZIgYv/nl0tB4Ju3iJN56VDSqkisbz5/X/rvr3NA64A1tDXKQGD0Rj3dIOHx5 dsfC5MMijHEiLjEsOhV4g/bYLyJjvm+vSpHfaGvf1VKuS+gHX9xLZ7GA8Gk7XB+trvJ3 88Qi0oAsG1yNi9v/YB50atn8PuAB2BJRtEDdv7Iikzwa3yuHLpS0MK6Z8Mk1OROKk0Xk PwryJq3XEPExpG5Xfs7cz0dfWQIxj/syRk9RvPmaEXL5Dr5zI8z5xHjsJtZSOJE+Uvrz JC61H4EDZlfYMVgpNLPManvnZw/OVAea2w0Q5cg3adWQ0vpA/yF4yc1BBZuyxuhq7WXV yEdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=RpkV5mcoZ7zrPk8rSX22oR+IY3gNnX4++yEhuGc6rwo=; b=b8xagJYVl40/beBUBLisyMhwK9lLahZC95gsmy2g+dSMoao7IILg2OVo0PH7z0kEJy 6SLUEcEgukxQoJ/6m9ki0p00S6FbWq79bMa00aPNzHFozixLPBAInFoKQWnwxYnfhS9+ wl7b64CvNKYD59LLYwNioJo6n2vAG9X9+Fg1oM4ZXOP7fO7nOwF1i1jonhol4y1Z9rtU CsE+YnBkJH/Dv7tJYQUjDQywcasTuhR6rBVQUrXC+g64xIXm0fQ9Z9LPqy2oifh/S5UC /70o2QILRnvlvY9BZlAN2eDSlZIrbn+v+o3puE+J/S/nnjHkpqqZHsfkqW1KaoLog4q0 9b/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=Nf7wuiJS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c5-20020a056402120500b0042ddac25209si17320043edw.92.2022.07.19.06.54.16; Tue, 19 Jul 2022 06:54:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=Nf7wuiJS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243379AbiGSNL3 (ORCPT + 99 others); Tue, 19 Jul 2022 09:11:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243223AbiGSNK2 (ORCPT ); Tue, 19 Jul 2022 09:10:28 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 122B351A1E for ; Tue, 19 Jul 2022 05:29:03 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 0F4111F97A; Tue, 19 Jul 2022 12:28:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1658233727; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=RpkV5mcoZ7zrPk8rSX22oR+IY3gNnX4++yEhuGc6rwo=; b=Nf7wuiJSo8jt+B+HDwMMDCqyySI1BsWyIoiSGY/zvIdWm+wBxTUVD5h0r4/g8jVypZOGNW yY5z06qNQI06quegVNWbgaWQrtFR8UvJHxUz07ETsZV7/SeExBDG/NjAZHxC37zUsHJ58W shTblCU0iyJsywWgKLZA+relSNGFzg0= Received: from alley.suse.cz (unknown [10.100.201.202]) by relay2.suse.de (Postfix) with ESMTP id BBD442C141; Tue, 19 Jul 2022 12:28:46 +0000 (UTC) From: Petr Mladek To: John Ogness , Jan Kiszka , Kieran Bingham Cc: Antonio Borneo , linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com Subject: [PATCH v2] scripts/gdb: fix 'lx-dmesg' on 32 bits arch Date: Tue, 19 Jul 2022 14:28:31 +0200 Message-Id: <20220719122831.19890-1-pmladek@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Antonio Borneo The type atomic_long_t can have size 4 or 8 bytes, depending on CONFIG_64BIT; it's only content, the field 'counter', is either an int or a s64 value. Current code incorrectly uses the fixed size utils.read_u64() to read the field 'counter' inside atomic_long_t. On 32 bits architectures reading the last element 'tail_id' of the struct prb_desc_ring: struct prb_desc_ring { ... atomic_long_t tail_id; }; causes the utils.read_u64() to access outside the boundary of the struct and the gdb command 'lx-dmesg' exits with error: Python Exception : index out of range Error occurred in Python: index out of range Query the really used atomic_long_t counter type size. Fixes: e60768311af8 ("scripts/gdb: update for lockless printk ringbuffer") Signed-off-by: Antonio Borneo [pmladek@suse.com: Query the really used atomic_long_t counter type size] Tested-by: Antonio Borneo Link: https://lore.kernel.org/r/20220617143758.137307-1-antonio.borneo@foss.st.com --- This has somehow fallen through the cracks. Sending as proper patch for review. Changes against v1: + Query the really used atomic_long_t counter type size scripts/gdb/linux/dmesg.py | 9 +++------ scripts/gdb/linux/utils.py | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/scripts/gdb/linux/dmesg.py b/scripts/gdb/linux/dmesg.py index d5983cf3db7d..c771831eb077 100644 --- a/scripts/gdb/linux/dmesg.py +++ b/scripts/gdb/linux/dmesg.py @@ -22,7 +22,6 @@ prb_desc_type = utils.CachedType("struct prb_desc") prb_desc_ring_type = utils.CachedType("struct prb_desc_ring") prb_data_ring_type = utils.CachedType("struct prb_data_ring") printk_ringbuffer_type = utils.CachedType("struct printk_ringbuffer") -atomic_long_type = utils.CachedType("atomic_long_t") class LxDmesg(gdb.Command): """Print Linux kernel log buffer.""" @@ -68,8 +67,6 @@ class LxDmesg(gdb.Command): off = prb_data_ring_type.get_type()['data'].bitpos // 8 text_data_addr = utils.read_ulong(text_data_ring, off) - counter_off = atomic_long_type.get_type()['counter'].bitpos // 8 - sv_off = prb_desc_type.get_type()['state_var'].bitpos // 8 off = prb_desc_type.get_type()['text_blk_lpos'].bitpos // 8 @@ -89,9 +86,9 @@ class LxDmesg(gdb.Command): # read in tail and head descriptor ids off = prb_desc_ring_type.get_type()['tail_id'].bitpos // 8 - tail_id = utils.read_u64(desc_ring, off + counter_off) + tail_id = utils.read_atomic_long(desc_ring, off) off = prb_desc_ring_type.get_type()['head_id'].bitpos // 8 - head_id = utils.read_u64(desc_ring, off + counter_off) + head_id = utils.read_atomic_long(desc_ring, off) did = tail_id while True: @@ -102,7 +99,7 @@ class LxDmesg(gdb.Command): desc = utils.read_memoryview(inf, desc_addr + desc_off, desc_sz).tobytes() # skip non-committed record - state = 3 & (utils.read_u64(desc, sv_off + counter_off) >> desc_flags_shift) + state = 3 & (utils.read_atomic_long(desc, sv_off) >> desc_flags_shift) if state != desc_committed and state != desc_finalized: if did == head_id: break diff --git a/scripts/gdb/linux/utils.py b/scripts/gdb/linux/utils.py index ff7c1799d588..1553f68716cc 100644 --- a/scripts/gdb/linux/utils.py +++ b/scripts/gdb/linux/utils.py @@ -35,13 +35,12 @@ class CachedType: long_type = CachedType("long") - +atomic_long_type = CachedType("atomic_long_t") def get_long_type(): global long_type return long_type.get_type() - def offset_of(typeobj, field): element = gdb.Value(0).cast(typeobj) return int(str(element[field].address).split()[0], 16) @@ -129,6 +128,17 @@ def read_ulong(buffer, offset): else: return read_u32(buffer, offset) +atomic_long_counter_offset = atomic_long_type.get_type()['counter'].bitpos +atomic_long_counter_sizeof = atomic_long_type.get_type()['counter'].type.sizeof + +def read_atomic_long(buffer, offset): + global atomic_long_counter_offset + global atomic_long_counter_sizeof + + if atomic_long_counter_sizeof == 8: + return read_u64(buffer, offset + atomic_long_counter_offset) + else: + return read_u32(buffer, offset + atomic_long_counter_offset) target_arch = None -- 2.35.3