linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Song Liu <songliubraving@fb.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, ast@kernel.org,
	daniel@iogearbox.net, kernel-team@fb.com,
	john.fastabend@gmail.com, kpsingh@chromium.org
Subject: Re: [PATCH v2 bpf-next 1/4] perf: export get/put_chain_entry()
Date: Fri, 26 Jun 2020 13:00:46 +0200	[thread overview]
Message-ID: <20200626110046.GB4817@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20200626001332.1554603-2-songliubraving@fb.com>

On Thu, Jun 25, 2020 at 05:13:29PM -0700, Song Liu wrote:
> This would be used by bpf stack mapo.

Would it make sense to sanitize the API a little before exposing it?

diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c
index 334d48b16c36..016894b0d2c2 100644
--- a/kernel/events/callchain.c
+++ b/kernel/events/callchain.c
@@ -159,8 +159,10 @@ static struct perf_callchain_entry *get_callchain_entry(int *rctx)
 		return NULL;
 
 	entries = rcu_dereference(callchain_cpus_entries);
-	if (!entries)
+	if (!entries) {
+		put_recursion_context(this_cpu_ptr(callchain_recursion), rctx);
 		return NULL;
+	}
 
 	cpu = smp_processor_id();
 
@@ -183,12 +185,9 @@ get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
 	int rctx;
 
 	entry = get_callchain_entry(&rctx);
-	if (rctx == -1)
+	if (!entry || rctx == -1)
 		return NULL;
 
-	if (!entry)
-		goto exit_put;
-
 	ctx.entry     = entry;
 	ctx.max_stack = max_stack;
 	ctx.nr	      = entry->nr = init_nr;

  reply	other threads:[~2020-06-26 11:01 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-26  0:13 [PATCH v2 bpf-next 0/4] bpf: introduce bpf_get_task_stack() Song Liu
2020-06-26  0:13 ` [PATCH v2 bpf-next 1/4] perf: export get/put_chain_entry() Song Liu
2020-06-26 11:00   ` Peter Zijlstra [this message]
2020-06-26 20:06     ` Andrii Nakryiko
2020-06-26 21:38       ` Song Liu
2020-06-26 21:29     ` Song Liu
2020-06-26  0:13 ` [PATCH v2 bpf-next 2/4] bpf: introduce helper bpf_get_task_stak() Song Liu
2020-06-26 15:40   ` Yonghong Song
2020-06-26 22:37     ` Song Liu
2020-06-26 20:17   ` Andrii Nakryiko
2020-06-26 20:22     ` Andrii Nakryiko
2020-06-26 22:45     ` Song Liu
2020-06-26 22:51       ` Andrii Nakryiko
2020-06-26 23:47         ` Song Liu
2020-06-27  0:06           ` Andrii Nakryiko
2020-06-26  0:13 ` [PATCH v2 bpf-next 3/4] bpf: allow %pB in bpf_seq_printf() and bpf_trace_printk() Song Liu
2020-06-26 15:44   ` [Potential Spoof] " Yonghong Song
2020-06-26  0:13 ` [PATCH v2 bpf-next 4/4] selftests/bpf: add bpf_iter test with bpf_get_task_stack() Song Liu
2020-06-26 15:52   ` Yonghong Song
2020-06-26 20:21   ` Andrii Nakryiko
2020-06-26 23:05     ` Song Liu
2020-06-26 23:11       ` Andrii Nakryiko
2020-06-26 23:40         ` Song Liu

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=20200626110046.GB4817@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=kernel-team@fb.com \
    --cc=kpsingh@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    /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;
as well as URLs for NNTP newsgroup(s).