From nobody Mon Feb 9 15:06:57 2026 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 9D6C220102C for ; Sun, 23 Mar 2025 05:08:55 +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=1742706535; cv=none; b=dAacPqn0FUrOM+m5Kqo/huDa2DY68iN6bCchUouEsAh6oTZ/GR1zc/2dUuyZ1+YCvb+X10tKKhGFX2AoFEQtakeEH8TglWRiQlHTwi1BT/OBtRgt9yJNl0rcO5mFJBFmCdSU3FXVXFSRgyTReIWzuHO6zHdmpcFNpwJRJcirMB0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742706535; c=relaxed/simple; bh=bD8t0AIpqh8YqpWgl6s1KSM/pPLnaCgmd1WcfZa1bYc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=apeRTaSItBxfS5s3Mvt3BX8WnLZYrBj+vyjc7po0Qm1AxLscMpvifH3OUShQaoYR4hLRsDomPJzK8OnuaxJqLTFDvPKSyb5BSCLEnwPND+5fPaj4i9lD/dj+NPm2SMQPvVliEOcFYfPLBpfnjLbiKw3HodzaBHP04+Rc2tSFx2c= 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 3B892C4CEF1; Sun, 23 Mar 2025 05:08:55 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1twDaX-00000001x0a-3rTT; Sun, 23 Mar 2025 01:09:33 -0400 Message-ID: <20250323050933.770518233@goodmis.org> User-Agent: quilt/0.68 Date: Sun, 23 Mar 2025 01:09:17 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [for-next][PATCH 3/4] tracing: Skip update_last_data() if cleared and remove active check for save_mod() References: <20250323050914.459621318@goodmis.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: "Masami Hiramatsu (Google)" If the last boot data is already cleared, there is no reason to update it again. Skip if the TRACE_ARRAY_FL_LAST_BOOT is cleared. Also, for calling save_mod() when module loading, we don't need to check the trace is active or not because any module address can be on the stacktrace. Cc: Mark Rutland Cc: Mathieu Desnoyers Link: https://lore.kernel.org/174165660328.1173316.15529357882704817499.stg= it@devnote2 Signed-off-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index be97465485b3..0be048fecc89 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -6040,6 +6040,12 @@ static void update_last_data(struct trace_array *tr) if (!(tr->flags & TRACE_ARRAY_FL_BOOT)) return; =20 + if (!(tr->flags & TRACE_ARRAY_FL_LAST_BOOT)) + return; + + /* Only if the buffer has previous boot data clear and update it. */ + tr->flags &=3D ~TRACE_ARRAY_FL_LAST_BOOT; + /* Reset the module list and reload them */ if (tr->scratch) { struct trace_scratch *tscratch =3D tr->scratch; @@ -6052,9 +6058,6 @@ static void update_last_data(struct trace_array *tr) module_for_each_mod(save_mod, tr); } =20 - if (!(tr->flags & TRACE_ARRAY_FL_LAST_BOOT)) - return; - /* * Need to clear all CPU buffers as there cannot be events * from the previous boot mixed with events with this boot @@ -6077,7 +6080,6 @@ static void update_last_data(struct trace_array *tr) #else tscratch->kaslr_addr =3D 0; #endif - tr->flags &=3D ~TRACE_ARRAY_FL_LAST_BOOT; } =20 /** @@ -10099,15 +10101,6 @@ static void trace_module_remove_evals(struct modul= e *mod) static inline void trace_module_remove_evals(struct module *mod) { } #endif /* CONFIG_TRACE_EVAL_MAP_FILE */ =20 -static bool trace_array_active(struct trace_array *tr) -{ - if (tr->current_trace !=3D &nop_trace) - return true; - - /* 0 is no events, 1 is all disabled */ - return trace_events_enabled(tr, NULL) > 1; -} - static void trace_module_record(struct module *mod) { struct trace_array *tr; @@ -10116,11 +10109,8 @@ static void trace_module_record(struct module *mod) /* Update any persistent trace array that has already been started */ if ((tr->flags & (TRACE_ARRAY_FL_BOOT | TRACE_ARRAY_FL_LAST_BOOT)) =3D= =3D TRACE_ARRAY_FL_BOOT) { - /* Only update if the trace array is active */ - if (trace_array_active(tr)) { - guard(mutex)(&scratch_mutex); - save_mod(mod, tr); - } + guard(mutex)(&scratch_mutex); + save_mod(mod, tr); } } } --=20 2.47.2