public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Yauheni Kaliuta <ykaliuta@redhat.com>
To: bpf@vger.kernel.org
Cc: andrii@kernel.org, ast@kernel.org, yonghong.song@linux.dev,
	Yauheni Kaliuta <ykaliuta@redhat.com>
Subject: [PATCH bpf-next v3] tracing: perf_call_bpf: use struct trace_entry in struct syscall_tp_t
Date: Tue,  1 Aug 2023 10:52:22 +0300	[thread overview]
Message-ID: <20230801075222.7717-1-ykaliuta@redhat.com> (raw)
In-Reply-To: <20230728142740.483431-1-ykaliuta@redhat.com>

bpf tracepoint program uses struct trace_event_raw_sys_enter as
argument where trace_entry is the first field. Use the same instead
of unsigned long long since if it's amended (for example by RT
patch) it accesses data with wrong offset.

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>

---

v3:
- Fixed comment

v2:
- remove extra BUILD_BUG_ON
- add structure alignement

---
 kernel/trace/trace_syscalls.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
index 942ddbdace4a..de753403cdaf 100644
--- a/kernel/trace/trace_syscalls.c
+++ b/kernel/trace/trace_syscalls.c
@@ -555,12 +555,15 @@ static int perf_call_bpf_enter(struct trace_event_call *call, struct pt_regs *re
 			       struct syscall_trace_enter *rec)
 {
 	struct syscall_tp_t {
-		unsigned long long regs;
+		struct trace_entry ent;
 		unsigned long syscall_nr;
 		unsigned long args[SYSCALL_DEFINE_MAXARGS];
-	} param;
+	} __aligned(8) param;
 	int i;
 
+	BUILD_BUG_ON(sizeof(param.ent) < sizeof(void *));
+
+	/* bpf prog requires 'regs' to be the first member in the ctx (a.k.a. &param) */
 	*(struct pt_regs **)&param = regs;
 	param.syscall_nr = rec->nr;
 	for (i = 0; i < sys_data->nb_args; i++)
@@ -657,11 +660,12 @@ static int perf_call_bpf_exit(struct trace_event_call *call, struct pt_regs *reg
 			      struct syscall_trace_exit *rec)
 {
 	struct syscall_tp_t {
-		unsigned long long regs;
+		struct trace_entry ent;
 		unsigned long syscall_nr;
 		unsigned long ret;
-	} param;
+	} __aligned(8) param;
 
+	/* bpf prog requires 'regs' to be the first member in the ctx (a.k.a. &param) */
 	*(struct pt_regs **)&param = regs;
 	param.syscall_nr = rec->nr;
 	param.ret = rec->ret;
-- 
2.41.0


  parent reply	other threads:[~2023-08-01  7:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-27 15:06 [PATCH bpf-next] tracing: perf_call_bpf: use struct trace_entry in struct syscall_tp_t Yauheni Kaliuta
2023-07-27 17:37 ` Yonghong Song
2023-07-28 10:02   ` Yauheni Kaliuta
2023-07-28 14:27   ` [PATCH bpf-next v2] " Yauheni Kaliuta
2023-07-28 16:44     ` Yonghong Song
2023-07-31  8:07       ` Yauheni Kaliuta
2023-07-31 18:20         ` Yonghong Song
2023-08-01  7:49           ` Yauheni Kaliuta
2023-08-01  7:52     ` Yauheni Kaliuta [this message]
2023-08-01 14:31       ` [PATCH bpf-next v3] " Yonghong Song
2023-08-01 18:00       ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230801075222.7717-1-ykaliuta@redhat.com \
    --to=ykaliuta@redhat.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox