From patchwork Tue Jan 28 15:37:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 13952658 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 C2C6C1CEAC3; Tue, 28 Jan 2025 15:37:10 +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=1738078631; cv=none; b=spKxj/irf/v3Wrh23GUzwo6PvlZmdQkivd9KSyDvYYjdwxh3hlARcn58GvpVJhiMrpZYkodXkL2sHKDbiaKrbRTInvnHHQE2PaArTdJcPwtYrKjuDGyj3zV7UOynP+6Tt2o936DEl3LuJ3Tb9A20rhVvkp9KB6CdTF4QjXWJd8Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738078631; c=relaxed/simple; bh=gBCuCf3DrjmvjehQDKAvnh/dqTCGqU4f0+ykGJSM5Ug=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TWCAaoYPh1/wHcfaNzTEQ/Blse594M5htQgtdKDtN0v+pxC8DTWzgrpTeWmUEcjvvkaZEI4w2jLY5HYKbVxtANHcpV+nB9qurrNfg9xdCtWrDGD5NdFLspLOCrLdvROcuhaHTSJFu862Rfuu2mVHfGTbzrZX1x/i0feXDIVx8KI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kzPbybVO; 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="kzPbybVO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54655C4CEDF; Tue, 28 Jan 2025 15:37:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738078630; bh=gBCuCf3DrjmvjehQDKAvnh/dqTCGqU4f0+ykGJSM5Ug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kzPbybVOjTrmOiaVYAog9dNQf7mq/btHKHNeEVi5/Tg8iuqkQT8AHRgQX/ariMydD UFiGAxHOyIbOPEYZ9MizQNg909q+1HVCgWz+hQgBdVNZeNv8T7UsFcOmp+6ueZx+fI D0LJH5a422KYPsUQj64ihfwGJTpuv37esajqSyL3Sn0tKGXrLlPd0DfoswunLFrRS3 4Y1eX987Q/L04AI6ge+C4LKhBmZMunRhgCpiTiIMs9VC2OG1axsG6a/Bu/3R3wQjJB mZaGgUu0CWZn/ydlpkmn4INC6mAnKt5DqRfRuct5exiwckPiloeHsKTlnjk+qALy/G CaKjmFUFDFCWQ== From: "Masami Hiramatsu (Google)" To: Steven Rostedt Cc: Masami Hiramatsu , Mathieu Desnoyers , Luis Chamberlain , Petr Pavlu , Sami Tolvanen , Daniel Gomez , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-modules@vger.kernel.org Subject: [RFC PATCH 1/3] tracing: Record stacktrace as the offset from _stext Date: Wed, 29 Jan 2025 00:37:06 +0900 Message-ID: <173807862643.1525539.5494079998018402469.stgit@mhiramat.roam.corp.google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog In-Reply-To: <173807861687.1525539.15082309716909038251.stgit@mhiramat.roam.corp.google.com> References: <173807861687.1525539.15082309716909038251.stgit@mhiramat.roam.corp.google.com> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Masami Hiramatsu (Google) Record kernel stacktrace as the offset from _stext so that it does not affected by KASLR. For the persistent ring buffer, decoding the stacktrace entries requires kallsyms in the previous boot because the kernel symbols will have random offset for each boot by KASLR. But this is not useful because we always need to save the kallsyms. Alternatively, we can record the stacktrace entries as the offset value from _stext. In this case, we can use System.map or nm for the vmlinux to decode the entries. Signed-off-by: Masami Hiramatsu (Google) --- kernel/trace/trace.c | 6 ++++++ kernel/trace/trace_output.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 1496a5ac33ae..8e86a43b368c 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -2973,8 +2973,14 @@ static void __ftrace_trace_stack(struct trace_array *tr, for (int i = 0; i < nr_entries; i++) { if (calls[i] >= tramp_start && calls[i] < tramp_end) calls[i] = FTRACE_TRAMPOLINE_MARKER; + else + calls[i] -= (unsigned long)_stext; } } +#else + /* Adjsut entries as the offset from _stext, instead of raw address. */ + for (int i = 0; i < nr_entries; i++) + fstack->calls[i] -= (unsigned long)_stext; #endif event = __trace_buffer_lock_reserve(buffer, TRACE_STACK, diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index 03d56f711ad1..497872df48f6 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -1248,7 +1248,7 @@ static enum print_line_t trace_stack_print(struct trace_iterator *iter, struct trace_seq *s = &iter->seq; unsigned long *p; unsigned long *end; - long delta = iter->tr->text_delta; + long delta = (unsigned long)_stext + iter->tr->text_delta; trace_assign_type(field, iter->ent); end = (unsigned long *)((long)iter->ent + iter->ent_size); From patchwork Tue Jan 28 15:37:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 13952659 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 4C7C41CEAD3; Tue, 28 Jan 2025 15:37:19 +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=1738078640; cv=none; b=CWePe1Uz8t59IhuWQXVY/2Akqq0qWsr4ksbqwq8BhdjBHr9gDwcZnlbVKZfEw+EjxumIQaz3YTG8HXTt0dvxDNnJVYHc9ITD6H+2ZRuJUnkv+N+GHcXB63Iabo0mmhWvzgAh+ZhU52v3r7dk5GGvPjP9rJiyQSjrs5ectfXxdtM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738078640; c=relaxed/simple; bh=HxL2+rxyJD0yjUQFxXAQiu1fzSMY1ftF2DKBxP+5nxw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=F/yevKwyDvpbzTEyIUDERKYhbPVcWhaZAV8hw3IsjeS0TVKahbyHfhdp5HTiACv060pWsPyuhdbqt4pcnod5c0oAjEke3B8USZA9omsw9iuY/Jd5p4l2MidLHpQYaXsjO5KOYzGnsbbtkekN/G0i+dG7+mhpjoPsWhS6gqDJ0vY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OslkblKG; 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="OslkblKG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D47F6C4CED3; Tue, 28 Jan 2025 15:37:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738078639; bh=HxL2+rxyJD0yjUQFxXAQiu1fzSMY1ftF2DKBxP+5nxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OslkblKGvalxeQXmDP2nhKDI/AaSG5uB6ZR7CC0kaZU5rrMnRZrZt2xmhdsG9pcIY zEKE+Oz+DL8+eUkKFC8B52VEOWdVLzsN/dGxcHW5g66zwjaq0dpEwolt/67Zlf2iNb 14StPhcCm98r7YfVQXvAtXd6C7XXfUQx4Entb0NOPKPz0t5YuDcDD3YEedSGFitn+I 5f2Lp9hPS0vWTCp6n4bERTjxwGz0wBl/N/1XEVpEtthRw3O5NtJFt+ta7jqPh1LnDb PP0kayQhhoekeLLu3akZAWDirnLfN9HpyH1oA334zWYIgajsrmekAAbUNndyQT7FzH M1qykBfelP3UA== From: "Masami Hiramatsu (Google)" To: Steven Rostedt Cc: Masami Hiramatsu , Mathieu Desnoyers , Luis Chamberlain , Petr Pavlu , Sami Tolvanen , Daniel Gomez , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-modules@vger.kernel.org Subject: [RFC PATCH 2/3] tracing: Introduce "rel_stack" option Date: Wed, 29 Jan 2025 00:37:15 +0900 Message-ID: <173807863557.1525539.14465198884840039000.stgit@mhiramat.roam.corp.google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog In-Reply-To: <173807861687.1525539.15082309716909038251.stgit@mhiramat.roam.corp.google.com> References: <173807861687.1525539.15082309716909038251.stgit@mhiramat.roam.corp.google.com> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Masami Hiramatsu (Google) Since the relative offset stacktrace requires a special module loading events to decode binary, it should be an optional for normal use case. User can enable this feature via `options/relative-stacktrace`. Signed-off-by: Masami Hiramatsu (Google) --- kernel/trace/trace.c | 13 ++++++++----- kernel/trace/trace.h | 2 ++ kernel/trace/trace_entries.h | 22 ++++++++++++++++++++++ kernel/trace/trace_output.c | 37 ++++++++++++++++++++++++++++++++----- 4 files changed, 64 insertions(+), 10 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 8e86a43b368c..b4da5e29957f 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -2926,6 +2926,7 @@ static void __ftrace_trace_stack(struct trace_array *tr, struct ftrace_stack *fstack; struct stack_entry *entry; int stackidx; + int type; /* * Add one, for this function and the call to save_stack_trace() @@ -2937,6 +2938,7 @@ static void __ftrace_trace_stack(struct trace_array *tr, #endif preempt_disable_notrace(); + type = (tr->trace_flags & TRACE_ITER_REL_STACK_BIT) ? TRACE_REL_STACK : TRACE_STACK; stackidx = __this_cpu_inc_return(ftrace_stack_reserve) - 1; @@ -2973,17 +2975,18 @@ static void __ftrace_trace_stack(struct trace_array *tr, for (int i = 0; i < nr_entries; i++) { if (calls[i] >= tramp_start && calls[i] < tramp_end) calls[i] = FTRACE_TRAMPOLINE_MARKER; - else + else if (type == TRACE_REL_STACK) calls[i] -= (unsigned long)_stext; } } #else - /* Adjsut entries as the offset from _stext, instead of raw address. */ - for (int i = 0; i < nr_entries; i++) - fstack->calls[i] -= (unsigned long)_stext; + if (type == TRACE_REL_STACK) + /* Adjsut entries as the offset from _stext, instead of raw address. */ + for (int i = 0; i < nr_entries; i++) + fstack->calls[i] -= (unsigned long)_stext; #endif - event = __trace_buffer_lock_reserve(buffer, TRACE_STACK, + event = __trace_buffer_lock_reserve(buffer, type, struct_size(entry, caller, nr_entries), trace_ctx); if (!event) diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 9c21ba45b7af..602aea0ec69a 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -55,6 +55,7 @@ enum trace_type { TRACE_TIMERLAT, TRACE_RAW_DATA, TRACE_FUNC_REPEATS, + TRACE_REL_STACK, __TRACE_LAST_TYPE, }; @@ -1350,6 +1351,7 @@ extern int trace_get_user(struct trace_parser *parser, const char __user *ubuf, C(TRACE_PRINTK, "trace_printk_dest"), \ C(PAUSE_ON_TRACE, "pause-on-trace"), \ C(HASH_PTR, "hash-ptr"), /* Print hashed pointer */ \ + C(REL_STACK, "relative-stacktrace"), \ FUNCTION_FLAGS \ FGRAPH_FLAGS \ STACK_FLAGS \ diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h index fbfb396905a6..7769f95b70fe 100644 --- a/kernel/trace/trace_entries.h +++ b/kernel/trace/trace_entries.h @@ -229,6 +229,28 @@ FTRACE_ENTRY(kernel_stack, stack_entry, (void *)__entry->caller[6], (void *)__entry->caller[7]) ); +FTRACE_ENTRY_DUP(kernel_rel_stack, stack_entry, + + TRACE_REL_STACK, + + F_STRUCT( + __field( int, size ) + __stack_array( unsigned long, caller, FTRACE_STACK_ENTRIES, size) + ), + + F_printk("\t=> %ps\n\t=> %ps\n\t=> %ps\n" + "\t=> %ps\n\t=> %ps\n\t=> %ps\n" + "\t=> %ps\n\t=> %ps\n", + (void *)__entry->caller[0] + (unsigned long)_stext, + (void *)__entry->caller[1] + (unsigned long)_stext, + (void *)__entry->caller[2] + (unsigned long)_stext, + (void *)__entry->caller[3] + (unsigned long)_stext, + (void *)__entry->caller[4] + (unsigned long)_stext, + (void *)__entry->caller[5] + (unsigned long)_stext, + (void *)__entry->caller[6] + (unsigned long)_stext, + (void *)__entry->caller[7] + (unsigned long)_stext) +); + FTRACE_ENTRY(user_stack, userstack_entry, TRACE_USER_STACK, diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c index 497872df48f6..47e4ab549e81 100644 --- a/kernel/trace/trace_output.c +++ b/kernel/trace/trace_output.c @@ -1239,16 +1239,17 @@ static struct trace_event trace_wake_event = { .funcs = &trace_wake_funcs, }; -/* TRACE_STACK */ - -static enum print_line_t trace_stack_print(struct trace_iterator *iter, - int flags, struct trace_event *event) +static enum print_line_t trace_kernel_stack_print(struct trace_iterator *iter, + int flags, struct trace_event *event, bool relative) { struct stack_entry *field; struct trace_seq *s = &iter->seq; unsigned long *p; unsigned long *end; - long delta = (unsigned long)_stext + iter->tr->text_delta; + long delta = iter->tr->text_delta; + + if (relative) + delta += (unsigned long)_stext; trace_assign_type(field, iter->ent); end = (unsigned long *)((long)iter->ent + iter->ent_size); @@ -1272,6 +1273,14 @@ static enum print_line_t trace_stack_print(struct trace_iterator *iter, return trace_handle_return(s); } +/* TRACE_STACK */ + +static enum print_line_t trace_stack_print(struct trace_iterator *iter, + int flags, struct trace_event *event) +{ + return trace_kernel_stack_print(iter, flags, event, false); +} + static struct trace_event_functions trace_stack_funcs = { .trace = trace_stack_print, }; @@ -1281,6 +1290,23 @@ static struct trace_event trace_stack_event = { .funcs = &trace_stack_funcs, }; +/* TRACE_REL_STACK */ + +static enum print_line_t trace_rel_stack_print(struct trace_iterator *iter, + int flags, struct trace_event *event) +{ + return trace_kernel_stack_print(iter, flags, event, true); +} + +static struct trace_event_functions trace_rel_stack_funcs = { + .trace = trace_rel_stack_print, +}; + +static struct trace_event trace_rel_stack_event = { + .type = TRACE_REL_STACK, + .funcs = &trace_rel_stack_funcs, +}; + /* TRACE_USER_STACK */ static enum print_line_t trace_user_stack_print(struct trace_iterator *iter, int flags, struct trace_event *event) @@ -1724,6 +1750,7 @@ static struct trace_event *events[] __initdata = { &trace_ctx_event, &trace_wake_event, &trace_stack_event, + &trace_rel_stack_event, &trace_user_stack_event, &trace_bputs_event, &trace_bprint_event, From patchwork Tue Jan 28 15:37:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 13952660 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 23CDBF9F8; Tue, 28 Jan 2025 15:37:29 +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=1738078650; cv=none; b=Ea8SCvsjCCU4qg5TQSeYvhA50P+CUIvLghoHYXZA0RPxswzPcBNVddL9DaTdJPz5AMLV3hBPG1tp/kTbyBNJ/9OTp2fI9TwK4WNIDITJkxj0NKqn3UcK/0Aa1q9M6OHp5yVPemAzlQHZI9X38iyVyvZ7M0pKLNEL0EFeVhzoqoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738078650; c=relaxed/simple; bh=bpTuAHnmxxYJi8aMzZEmI5QzeBf7azj2pbNnpxLLXXc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mAEpyaGF43kGkj8UuXIYhe/flaU8496YhDteiceAx6NBsBkx92m3Ay2WoJTjxrE0jHTVMBSRtvX3F6jPgxxpdR/5/tCKBireVKZL0tWI/a2/VKtUH8I+5a/Fos6Vj5B13GZKggzQKDI2+iIKwMfIdInUtZieuMKi9gARb7a2I0w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kREJGJlo; 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="kREJGJlo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F1C2C4CED3; Tue, 28 Jan 2025 15:37:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1738078649; bh=bpTuAHnmxxYJi8aMzZEmI5QzeBf7azj2pbNnpxLLXXc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kREJGJlouXAym197/2wwbyFQfmdwyrPAH2jgYX8Oucqg/Z/qZWu+c3WEpehVhSO2b ilpoN+tHplJHvHjfja9OLWfhjuXC1xL2BmF0rSaLA/3ZBoU27tCkCAg7ee0uAaERVR 7dMS/nwrQI+CQ4jGcg/6yDtLTqd7RmxMQPQRuUcgqWlIht7w3vdCd9WYh08eiRfniP lTjqZ1NjZ3qx9V1jq05Zg4KgQb4/uGqTet1WDaOXYQyDtU6gvUYqV1WNviW9vlXl0D voTpHsq+uwA374fbVarimhXCnLPQNk/o5i5E7hAvGCkWu21wawygN8eckSu+SwJIth s+4auv03+igqg== From: "Masami Hiramatsu (Google)" To: Steven Rostedt Cc: Masami Hiramatsu , Mathieu Desnoyers , Luis Chamberlain , Petr Pavlu , Sami Tolvanen , Daniel Gomez , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-modules@vger.kernel.org Subject: [RFC PATCH 3/3] modules: tracing: Add module_text_offsets event Date: Wed, 29 Jan 2025 00:37:25 +0900 Message-ID: <173807864506.1525539.5749974707383492634.stgit@mhiramat.roam.corp.google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog In-Reply-To: <173807861687.1525539.15082309716909038251.stgit@mhiramat.roam.corp.google.com> References: <173807861687.1525539.15082309716909038251.stgit@mhiramat.roam.corp.google.com> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Masami Hiramatsu (Google) Add new module_text_offsets event which records the offset of module text and init_text section address and size. This information is required for decoding the relative stacktrace entries for modules. Signed-off-by: Masami Hiramatsu (Google) --- include/trace/events/module.h | 40 ++++++++++++++++++++++++++++++++++++++++ kernel/module/main.c | 1 + 2 files changed, 41 insertions(+) diff --git a/include/trace/events/module.h b/include/trace/events/module.h index e5a006be9dc6..1e5c84cc8d15 100644 --- a/include/trace/events/module.h +++ b/include/trace/events/module.h @@ -47,6 +47,46 @@ TRACE_EVENT(module_load, TP_printk("%s %s", __get_str(name), show_module_flags(__entry->taints)) ); +/* Module address offset from _stext */ +TRACE_EVENT(module_text_offsets, + + TP_PROTO(struct module *mod), + + TP_ARGS(mod), + + TP_STRUCT__entry( + __string( name, mod->name ) + __field( unsigned long, text_offset ) + __field( unsigned int, text_size ) + __field( unsigned long, init_offset ) + __field( unsigned int, init_size ) + ), + + TP_fast_assign( + if (mod->mem[MOD_TEXT].size) { + __entry->text_offset = (unsigned long)mod->mem[MOD_TEXT].base + - (unsigned long)_stext; + __entry->text_size = mod->mem[MOD_TEXT].size; + } else { + __entry->text_offset = 0; + __entry->text_size = 0; + } + if (mod->mem[MOD_INIT_TEXT].size) { + __entry->init_offset = (unsigned long)mod->mem[MOD_INIT_TEXT].base + - (unsigned long)_stext; + __entry->init_size = mod->mem[MOD_INIT_TEXT].size; + } else { + __entry->init_offset = 0; + __entry->init_size = 0; + } + __assign_str(name); + ), + + TP_printk("%s text_offset=0x%lx text_size=%d init_offset=0x%lx init_size=%d", + __get_str(name), __entry->text_offset, __entry->text_size, + __entry->init_offset, __entry->init_size) +); + TRACE_EVENT(module_free, TP_PROTO(struct module *mod), diff --git a/kernel/module/main.c b/kernel/module/main.c index 5399c182b3cb..9f1ca8730a71 100644 --- a/kernel/module/main.c +++ b/kernel/module/main.c @@ -3372,6 +3372,7 @@ static int load_module(struct load_info *info, const char __user *uargs, /* Done! */ trace_module_load(mod); + trace_module_text_offsets(mod); return do_init_module(mod);