public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Andrii Nakryiko <andrii@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	song@kernel.org, daniel@iogearbox.net, rostedt@goodmis.org,
	mhiramat@kernel.org, bpf@vger.kernel.org,
	linux-trace-kernel@vger.kernel.org
Subject: [PATCH AUTOSEL 6.8 03/15] bpf: put uprobe link's path and task in release callback
Date: Mon, 15 Apr 2024 06:02:43 -0400	[thread overview]
Message-ID: <20240415100311.3126785-3-sashal@kernel.org> (raw)
In-Reply-To: <20240415100311.3126785-1-sashal@kernel.org>

From: Andrii Nakryiko <andrii@kernel.org>

[ Upstream commit e9c856cabefb71d47b2eeb197f72c9c88e9b45b0 ]

There is no need to delay putting either path or task to deallocation
step. It can be done right after bpf_uprobe_unregister. Between release
and dealloc, there could be still some running BPF programs, but they
don't access either task or path, only data in link->uprobes, so it is
safe to do.

On the other hand, doing path_put() in dealloc callback makes this
dealloc sleepable because path_put() itself might sleep. Which is
problematic due to the need to call uprobe's dealloc through call_rcu(),
which is what is done in the next bug fix patch. So solve the problem by
releasing these resources early.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20240328052426.3042617-1-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 kernel/trace/bpf_trace.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 7ac6c52b25ebc..45de8a4923e21 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -3142,6 +3142,9 @@ static void bpf_uprobe_multi_link_release(struct bpf_link *link)
 
 	umulti_link = container_of(link, struct bpf_uprobe_multi_link, link);
 	bpf_uprobe_unregister(&umulti_link->path, umulti_link->uprobes, umulti_link->cnt);
+	if (umulti_link->task)
+		put_task_struct(umulti_link->task);
+	path_put(&umulti_link->path);
 }
 
 static void bpf_uprobe_multi_link_dealloc(struct bpf_link *link)
@@ -3149,9 +3152,6 @@ static void bpf_uprobe_multi_link_dealloc(struct bpf_link *link)
 	struct bpf_uprobe_multi_link *umulti_link;
 
 	umulti_link = container_of(link, struct bpf_uprobe_multi_link, link);
-	if (umulti_link->task)
-		put_task_struct(umulti_link->task);
-	path_put(&umulti_link->path);
 	kvfree(umulti_link->uprobes);
 	kfree(umulti_link);
 }
-- 
2.43.0


  parent reply	other threads:[~2024-04-15 12:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-15 10:02 [PATCH AUTOSEL 6.8 01/15] ASoC: SOF: Intel: hda-dsp: Skip IMR boot on ACE platforms in case of S3 suspend Sasha Levin
2024-04-15 10:02 ` [PATCH AUTOSEL 6.8 02/15] regulator: tps65132: Add of_match table Sasha Levin
2024-04-15 10:02 ` Sasha Levin [this message]
2024-04-15 10:02 ` [PATCH AUTOSEL 6.8 04/15] OSS: dmasound/paula: Mark driver struct with __refdata to prevent section mismatch Sasha Levin
2024-04-15 10:02 ` [PATCH AUTOSEL 6.8 05/15] scsi: ufs: core: WLUN suspend dev/link state error recovery Sasha Levin
2024-04-15 10:02 ` [PATCH AUTOSEL 6.8 06/15] scsi: libsas: Align SMP request allocation to ARCH_DMA_MINALIGN Sasha Levin
2024-04-15 10:02 ` [PATCH AUTOSEL 6.8 07/15] scsi: ufs: core: Fix MCQ mode dev command timeout Sasha Levin
2024-04-15 10:02 ` [PATCH AUTOSEL 6.8 08/15] ALSA: line6: Zero-initialize message buffers Sasha Levin
2024-04-15 10:02 ` [PATCH AUTOSEL 6.8 09/15] block: fix overflow in blk_ioctl_discard() Sasha Levin
2024-04-15 10:02 ` [PATCH AUTOSEL 6.8 10/15] ASoC: codecs: ES8326: Solve error interruption issue Sasha Levin
2024-04-15 10:02 ` [PATCH AUTOSEL 6.8 11/15] ASoC: codecs: ES8326: modify clock table Sasha Levin
2024-04-15 10:02 ` [PATCH AUTOSEL 6.8 12/15] net: bcmgenet: Reset RBUF on first open Sasha Levin
2024-04-15 10:02 ` [PATCH AUTOSEL 6.8 13/15] vboxsf: explicitly deny setlease attempts Sasha Levin
2024-04-15 10:02 ` [PATCH AUTOSEL 6.8 14/15] ata: sata_gemini: Check clk_enable() result Sasha Levin
2024-04-15 10:02 ` [PATCH AUTOSEL 6.8 15/15] firewire: ohci: mask bus reset interrupts between ISR and bottom half Sasha Levin

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=20240415100311.3126785-3-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=song@kernel.org \
    --cc=stable@vger.kernel.org \
    /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