From: Oleg Nesterov <oleg@redhat.com>
To: Andrii Nakryiko <andrii@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Peter Zijlstra <peterz@infradead.org>
Cc: Liao Chang <liaochang1@huawei.com>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: [PATCH 4/7] uprobes: simplify xol_take_insn_slot() and its caller
Date: Sun, 29 Sep 2024 16:42:44 +0200 [thread overview]
Message-ID: <20240929144244.GA9480@redhat.com> (raw)
In-Reply-To: <20240929144201.GA9429@redhat.com>
The do / while (slot_nr >= UINSNS_PER_PAGE) loop in xol_take_insn_slot()
makes no sense, the checked condition is always true. Change this code
to use the "for (;;)" loop, this way we do not need to change slot_nr if
test_and_set_bit() fails.
Also, kill the unnecessary xol_vaddr != NULL check in xol_get_insn_slot(),
xol_take_insn_slot() never returns NULL.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
kernel/events/uprobes.c | 17 ++++-------------
1 file changed, 4 insertions(+), 13 deletions(-)
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 4619de10772e..bfe106ecad38 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1631,25 +1631,20 @@ void uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm)
*/
static unsigned long xol_take_insn_slot(struct xol_area *area)
{
- unsigned long slot_addr;
- int slot_nr;
+ unsigned int slot_nr;
- do {
+ for (;;) {
slot_nr = find_first_zero_bit(area->bitmap, UINSNS_PER_PAGE);
if (slot_nr < UINSNS_PER_PAGE) {
if (!test_and_set_bit(slot_nr, area->bitmap))
break;
-
- slot_nr = UINSNS_PER_PAGE;
continue;
}
wait_event(area->wq, (atomic_read(&area->slot_count) < UINSNS_PER_PAGE));
- } while (slot_nr >= UINSNS_PER_PAGE);
+ }
- slot_addr = area->vaddr + (slot_nr * UPROBE_XOL_SLOT_BYTES);
atomic_inc(&area->slot_count);
-
- return slot_addr;
+ return area->vaddr + slot_nr * UPROBE_XOL_SLOT_BYTES;
}
/*
@@ -1666,12 +1661,8 @@ static unsigned long xol_get_insn_slot(struct uprobe *uprobe)
return 0;
xol_vaddr = xol_take_insn_slot(area);
- if (unlikely(!xol_vaddr))
- return 0;
-
arch_uprobe_copy_ixol(area->page, xol_vaddr,
&uprobe->arch.ixol, sizeof(uprobe->arch.ixol));
-
return xol_vaddr;
}
--
2.25.1.362.g51ebf55
next prev parent reply other threads:[~2024-09-29 14:43 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-29 14:42 [PATCH 0/7] uprobes: deuglify xol_get_insn_slot/xol_free_insn_slot paths Oleg Nesterov
2024-09-29 14:42 ` [PATCH 1/7] uprobes: don't abuse get_utask() in pre_ssout() and prepare_uretprobe() Oleg Nesterov
2024-10-08 11:05 ` [tip: perf/core] " tip-bot2 for Oleg Nesterov
2024-09-29 14:42 ` [PATCH 2/7] uprobes: sanitiize xol_free_insn_slot() Oleg Nesterov
2024-10-08 11:05 ` [tip: perf/core] " tip-bot2 for Oleg Nesterov
2024-09-29 14:42 ` [PATCH 3/7] uprobes: kill the unnecessary put_uprobe/xol_free_insn_slot in uprobe_free_utask() Oleg Nesterov
2024-10-08 11:05 ` [tip: perf/core] " tip-bot2 for Oleg Nesterov
2024-09-29 14:42 ` Oleg Nesterov [this message]
2024-10-08 11:05 ` [tip: perf/core] uprobes: simplify xol_take_insn_slot() and its caller tip-bot2 for Oleg Nesterov
2024-09-29 14:42 ` [PATCH 5/7] uprobes: move the initialization of utask->xol_vaddr from pre_ssout() to xol_get_insn_slot() Oleg Nesterov
2024-10-08 11:05 ` [tip: perf/core] " tip-bot2 for Oleg Nesterov
2024-09-29 14:42 ` [PATCH 6/7] uprobes: pass utask to xol_get_insn_slot() and xol_free_insn_slot() Oleg Nesterov
2024-10-08 11:05 ` [tip: perf/core] " tip-bot2 for Oleg Nesterov
2024-09-29 14:42 ` [PATCH 7/7] uprobes: deny mremap(xol_vma) Oleg Nesterov
2024-10-08 11:05 ` [tip: perf/core] " tip-bot2 for Oleg Nesterov
2024-09-30 8:10 ` [PATCH 0/7] uprobes: deuglify xol_get_insn_slot/xol_free_insn_slot paths Peter Zijlstra
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=20240929144244.GA9480@redhat.com \
--to=oleg@redhat.com \
--cc=andrii@kernel.org \
--cc=jolsa@kernel.org \
--cc=liaochang1@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=peterz@infradead.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