From nobody Thu Dec 18 20:38:26 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 D7DD11FA828; Wed, 18 Dec 2024 19:14:30 +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=1734549270; cv=none; b=UtYPHz2Y86bWAfZu75kPuk83ikLvKJuSV98Ny4eDbg3J1AYLIjvi21/HDLI7ekXzNASuGSGFAI/TnzjTHixnvo8mBz9EeBDWqPIoWmXbtv5x/TlZBi+KrBATS84//ZPUF9yMLYanj8LQ/FSAaQNqzwRp2US8fHPyKOYZvo3Vxc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734549270; c=relaxed/simple; bh=ZMyhXHK2aZiodnkf6+XIvqdd4GWxatTVdFuOcGTUzRo=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type; b=XHTrtpEZCZKZs2vHucuhPOoUXYvboj2wmAGCQ6iE3q7wqiMg1yKmTGtAMBfgBE9FVLttYCZuFy42sImd9KVvmI6SrviLBew1i/fkmT8ooa6qvnfuOFulG3RE1wq5Grotb3C9VQvukCb7Yk/gscwRg2Au3PuXKLXMk2OYSgNicQs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 000B7C4CED7; Wed, 18 Dec 2024 19:14:29 +0000 (UTC) Date: Wed, 18 Dec 2024 14:15:07 -0500 From: Steven Rostedt To: LKML , Linux Trace Kernel Cc: Masami Hiramatsu , Mathieu Desnoyers , Linus Torvalds Subject: [PATCH v2] trace/ring-buffer: Do not use TP_printk() formatting for boot mapped buffers Message-ID: <20241218141507.28389a1d@gandalf.local.home> X-Mailer: Claws Mail 3.20.0git84 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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: Steven Rostedt The TP_printk() of a TRACE_EVENT() is a generic printf format that any developer can create for their event. It may include pointers to strings and such. A boot mapped buffer may contain data from a previous kernel where the strings addresses are different. One solution is to copy the event content and update the pointers by the recorded delta, but a simpler solution (for now) is to just use the print_fields() function to print these events. The print_fields() function just iterates the fields and prints them according to what type they are, and ignores the TP_printk() format from the event itself. To understand the difference, when printing via TP_printk() the output looks like this: 4582.696626: kmem_cache_alloc: call_site=3Dgetname_flags+0x47/0x1f0 ptr= =3D00000000e70e10e0 bytes_req=3D4096 bytes_alloc=3D4096 gfp_flags=3DGFP_KER= NEL node=3D-1 accounted=3Dfalse 4582.696629: kmem_cache_alloc: call_site=3Dalloc_empty_file+0x6b/0x110 pt= r=3D0000000095808002 bytes_req=3D360 bytes_alloc=3D384 gfp_flags=3DGFP_KERN= EL node=3D-1 accounted=3Dfalse 4582.696630: kmem_cache_alloc: call_site=3Dsecurity_file_alloc+0x24/0x100= ptr=3D00000000576339c3 bytes_req=3D16 bytes_alloc=3D16 gfp_flags=3DGFP_KER= NEL|__GFP_ZERO node=3D-1 accounted=3Dfalse 4582.696653: kmem_cache_free: call_site=3Ddo_sys_openat2+0xa7/0xd0 ptr=3D= 00000000e70e10e0 name=3Dnames_cache But when printing via print_fields() (echo 1 > /sys/kernel/tracing/options/= fields) the same event output looks like this: 4582.696626: kmem_cache_alloc: call_site=3D0xffffffff92d10d97 (-183179325= 7) ptr=3D0xffff9e0e8571e000 (-107689771147264) bytes_req=3D0x1000 (4096) by= tes_alloc=3D0x1000 (4096) gfp_flags=3D0xcc0 (3264) node=3D0xffffffff (-1) a= ccounted=3D(0) 4582.696629: kmem_cache_alloc: call_site=3D0xffffffff92d0250b (-183185278= 9) ptr=3D0xffff9e0e8577f800 (-107689770747904) bytes_req=3D0x168 (360) byte= s_alloc=3D0x180 (384) gfp_flags=3D0xcc0 (3264) node=3D0xffffffff (-1) accou= nted=3D(0) 4582.696630: kmem_cache_alloc: call_site=3D0xffffffff92efca74 (-182977882= 8) ptr=3D0xffff9e0e8d35d3b0 (-107689640864848) bytes_req=3D0x10 (16) bytes_= alloc=3D0x10 (16) gfp_flags=3D0xdc0 (3520) node=3D0xffffffff (-1) accounted= =3D(0) 4582.696653: kmem_cache_free: call_site=3D0xffffffff92cfbea7 (-1831879001= ) ptr=3D0xffff9e0e8571e000 (-107689771147264) name=3Dnames_cache Cc: stable@vger.kernel.org Fixes: 07714b4bb3f98 ("tracing: Handle old buffer mappings for event string= s and functions") Signed-off-by: Steven Rostedt (Google) --- Changes since v1: https://lore.kernel.org/all/20241217173520.658174695@good= mis.org/ - Do not update print_field() with text_delta offset. kernel/trace/trace.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index be62f0ea1814..6581cb2bc67f 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -4353,6 +4353,15 @@ static enum print_line_t print_trace_fmt(struct trac= e_iterator *iter) if (event) { if (tr->trace_flags & TRACE_ITER_FIELDS) return print_event_fields(iter, event); + /* + * For TRACE_EVENT() events, the print_fmt is not + * safe to use if the array has delta offsets + * Force printing via the fields. + */ + if ((tr->text_delta || tr->data_delta) && + event->type > __TRACE_LAST_TYPE) + return print_event_fields(iter, event); + return event->funcs->trace(iter, sym_flags, event); } =20 --=20 2.45.2