From nobody Mon Oct 6 22:46:37 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0E9EA1F9EC0; Thu, 17 Jul 2025 01:29:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752715757; cv=none; b=FyygsA1Q23BmxpXhkHBMxlbsBSc1PC3B71l2qSDWD/zXc9yXA/H/OUWnNlu/v3t/WrYki8PmFfarNpyeNGroIRE7WnjiQ5woZLVw2EKXkC/9QawZNS8DKN7cOMZkOz+iwd1BsNGwR4shQbuYvM77jp/H9Q1n8AYI7t6BixZ/gLs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752715757; c=relaxed/simple; bh=+1dKUkXeGNCMo2SsOx0RVb/skigBKBZOQ6KCmMD4/Gk=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=n0gM+oprTAVS3ioKlLf1wYWRr8oZcR5m4ClZmAdOpWEnDMxDIpSeakZbMxWAaPOUgU6hqe4In5QEc6nL3q5UFv3qIfC1ByNMg4li8swa7n8dV23CE+Vx9k4C5pEsM2VpUdQ0iRPS6Pes/YVlKSDMcXjsSsH36gjHCkr8PVCPeXY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bzMz0suk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bzMz0suk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1555C4CEE7; Thu, 17 Jul 2025 01:29:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752715756; bh=+1dKUkXeGNCMo2SsOx0RVb/skigBKBZOQ6KCmMD4/Gk=; h=Date:From:To:Cc:Subject:References:From; b=bzMz0sukJnw69h0+SyY7TduFbN5V1FRFLGhcFhIc/cznN3HLwTtCH3X7OLFzVWWpR lUFR+hMKkLeJ3b4mSOkCwl/qpgNtmGpJwbuQrB8SvykhOJ6UZ02VIlgEPWT7s21ovR 5noM95WCmWgfl3FaKSfjvNi/ClQ5VuSw0Pelrzfjn7pxH1T9gAH6ufzcLOZvgbv3oE 681J/H/KAecRsWBljjmqlBMhKSAonABMNTcsIoMQnHXCIfL4/wk1Yztr7+55Kk+Wu0 a8m9Er69nS8buG3CJHd4H+lwuhJwfaJfqLMH2vPoX9OnLUaAk/Nf75ANffCvIVQXBt NAroXjKMNzsFw== Received: from rostedt by gandalf with local (Exim 4.98.2) (envelope-from ) id 1ucDRJ-000000068yi-1AIK; Wed, 16 Jul 2025 21:29:37 -0400 Message-ID: <20250717012937.129268020@kernel.org> User-Agent: quilt/0.68 Date: Wed, 16 Jul 2025 21:28:57 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org, x86@kernel.org Cc: Masami Hiramatsu , Mathieu Desnoyers , Josh Poimboeuf , Peter Zijlstra , Ingo Molnar , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Andrii Nakryiko , Indu Bhagat , "Jose E. Marchesi" , Beau Belgrave , Jens Remus , Linus Torvalds , Andrew Morton , Jens Axboe , Florian Weimer , Sam James Subject: [PATCH v9 09/11] unwind_user/sframe: Show file name in debug output References: <20250717012848.927473176@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Josh Poimboeuf When debugging sframe issues, the error messages aren't all that helpful without knowing what file a corresponding .sframe section belongs to. Prefix debug output strings with the file name. Signed-off-by: Josh Poimboeuf Signed-off-by: Steven Rostedt (Google) --- include/linux/sframe.h | 4 +++- kernel/unwind/sframe.c | 23 ++++++++++-------- kernel/unwind/sframe_debug.h | 45 +++++++++++++++++++++++++++++++----- 3 files changed, 56 insertions(+), 16 deletions(-) diff --git a/include/linux/sframe.h b/include/linux/sframe.h index 9a72209696f9..b79c5ec09229 100644 --- a/include/linux/sframe.h +++ b/include/linux/sframe.h @@ -10,7 +10,9 @@ =20 struct sframe_section { struct rcu_head rcu; - +#ifdef CONFIG_DYNAMIC_DEBUG + const char *filename; +#endif unsigned long sframe_start; unsigned long sframe_end; unsigned long text_start; diff --git a/kernel/unwind/sframe.c b/kernel/unwind/sframe.c index f246ead6c2a0..66d3ba3c8389 100644 --- a/kernel/unwind/sframe.c +++ b/kernel/unwind/sframe.c @@ -311,14 +311,17 @@ int sframe_find(unsigned long ip, struct unwind_user_= frame *frame) end: user_read_access_end(); =20 - if (ret =3D=3D -EFAULT) + if (ret =3D=3D -EFAULT) { + dbg_sec("removing bad .sframe section\n"); WARN_ON_ONCE(sframe_remove_section(sec->sframe_start)); + } =20 return ret; } =20 static void free_section(struct sframe_section *sec) { + dbg_free(sec); kfree(sec); } =20 @@ -329,7 +332,7 @@ static int sframe_read_header(struct sframe_section *se= c) unsigned int num_fdes; =20 if (copy_from_user(&shdr, (void __user *)sec->sframe_start, sizeof(shdr))= ) { - dbg("header usercopy failed\n"); + dbg_sec("header usercopy failed\n"); return -EFAULT; } =20 @@ -337,18 +340,18 @@ static int sframe_read_header(struct sframe_section *= sec) shdr.preamble.version !=3D SFRAME_VERSION_2 || !(shdr.preamble.flags & SFRAME_F_FDE_SORTED) || shdr.auxhdr_len) { - dbg("bad/unsupported sframe header\n"); + dbg_sec("bad/unsupported sframe header\n"); return -EINVAL; } =20 if (!shdr.num_fdes || !shdr.num_fres) { - dbg("no fde/fre entries\n"); + dbg_sec("no fde/fre entries\n"); return -EINVAL; } =20 header_end =3D sec->sframe_start + SFRAME_HEADER_SIZE(shdr); if (header_end >=3D sec->sframe_end) { - dbg("header doesn't fit in section\n"); + dbg_sec("header doesn't fit in section\n"); return -EINVAL; } =20 @@ -360,7 +363,7 @@ static int sframe_read_header(struct sframe_section *se= c) fres_end =3D fres_start + shdr.fre_len; =20 if (fres_start < fdes_end || fres_end > sec->sframe_end) { - dbg("inconsistent fde/fre offsets\n"); + dbg_sec("inconsistent fde/fre offsets\n"); return -EINVAL; } =20 @@ -416,6 +419,8 @@ int sframe_add_section(unsigned long sframe_start, unsi= gned long sframe_end, sec->text_start =3D text_start; sec->text_end =3D text_end; =20 + dbg_init(sec); + ret =3D sframe_read_header(sec); if (ret) { dbg_print_header(sec); @@ -424,8 +429,8 @@ int sframe_add_section(unsigned long sframe_start, unsi= gned long sframe_end, =20 ret =3D mtree_insert_range(sframe_mt, sec->text_start, sec->text_end, sec= , GFP_KERNEL); if (ret) { - dbg("mtree_insert_range failed: text=3D%lx-%lx\n", - sec->text_start, sec->text_end); + dbg_sec("mtree_insert_range failed: text=3D%lx-%lx\n", + sec->text_start, sec->text_end); goto err_free; } =20 @@ -447,7 +452,7 @@ static int __sframe_remove_section(struct mm_struct *mm, struct sframe_section *sec) { if (!mtree_erase(&mm->sframe_mt, sec->text_start)) { - dbg("mtree_erase failed: text=3D%lx\n", sec->text_start); + dbg_sec("mtree_erase failed: text=3D%lx\n", sec->text_start); return -EINVAL; } =20 diff --git a/kernel/unwind/sframe_debug.h b/kernel/unwind/sframe_debug.h index 055c8c8fae24..7794bf0bd78c 100644 --- a/kernel/unwind/sframe_debug.h +++ b/kernel/unwind/sframe_debug.h @@ -10,26 +10,59 @@ #define dbg(fmt, ...) \ pr_debug("%s (%d): " fmt, current->comm, current->pid, ##__VA_ARGS__) =20 +#define dbg_sec(fmt, ...) \ + dbg("%s: " fmt, sec->filename, ##__VA_ARGS__) + static __always_inline void dbg_print_header(struct sframe_section *sec) { unsigned long fdes_end; =20 fdes_end =3D sec->fdes_start + (sec->num_fdes * sizeof(struct sframe_fde)= ); =20 - dbg("SEC: sframe:0x%lx-0x%lx text:0x%lx-0x%lx " - "fdes:0x%lx-0x%lx fres:0x%lx-0x%lx " - "ra_off:%d fp_off:%d\n", - sec->sframe_start, sec->sframe_end, sec->text_start, sec->text_end, - sec->fdes_start, fdes_end, sec->fres_start, sec->fres_end, - sec->ra_off, sec->fp_off); + dbg_sec("SEC: sframe:0x%lx-0x%lx text:0x%lx-0x%lx " + "fdes:0x%lx-0x%lx fres:0x%lx-0x%lx " + "ra_off:%d fp_off:%d\n", + sec->sframe_start, sec->sframe_end, sec->text_start, sec->text_end, + sec->fdes_start, fdes_end, sec->fres_start, sec->fres_end, + sec->ra_off, sec->fp_off); +} + +static inline void dbg_init(struct sframe_section *sec) +{ + struct mm_struct *mm =3D current->mm; + struct vm_area_struct *vma; + + guard(mmap_read_lock)(mm); + vma =3D vma_lookup(mm, sec->sframe_start); + if (!vma) + sec->filename =3D kstrdup("(vma gone???)", GFP_KERNEL); + else if (vma->vm_file) + sec->filename =3D kstrdup_quotable_file(vma->vm_file, GFP_KERNEL); + else if (vma->vm_ops && vma->vm_ops->name) + sec->filename =3D kstrdup(vma->vm_ops->name(vma), GFP_KERNEL); + else if (arch_vma_name(vma)) + sec->filename =3D kstrdup(arch_vma_name(vma), GFP_KERNEL); + else if (!vma->vm_mm) + sec->filename =3D kstrdup("(vdso)", GFP_KERNEL); + else + sec->filename =3D kstrdup("(anonymous)", GFP_KERNEL); +} + +static inline void dbg_free(struct sframe_section *sec) +{ + kfree(sec->filename); } =20 #else /* !CONFIG_DYNAMIC_DEBUG */ =20 #define dbg(args...) no_printk(args) +#define dbg_sec(args... ) no_printk(args) =20 static inline void dbg_print_header(struct sframe_section *sec) {} =20 +static inline void dbg_init(struct sframe_section *sec) {} +static inline void dbg_free(struct sframe_section *sec) {} + #endif /* !CONFIG_DYNAMIC_DEBUG */ =20 #endif /* _SFRAME_DEBUG_H */ --=20 2.47.2