[PATCH v4 35/40] uprobes: optimize xol_take_insn_slot()

Yury Norov
2024-06-20T17:58:48Z

The function opencodes atomic find_bit() operation. Switch to using
a dedicated function.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
kernel/events/uprobes.c | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 2c83ba776fc7..30654c41f0b2 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -9,6 +9,7 @@
* Copyright (C) 2011-2012 Red Hat, Inc., Peter Zijlstra
*/

+#include <linux/find_atomic.h>
#include <linux/kernel.h>
#include <linux/highmem.h>
#include <linux/pagemap.h> /* read_mapping_page */
@@ -1581,17 +1582,13 @@ static unsigned long xol_take_insn_slot(struct xol_area *area)
unsigned long slot_addr;
int slot_nr;

- do {
- 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;
+ while (1) {
+ slot_nr = find_and_set_bit(area->bitmap, UINSNS_PER_PAGE);
+ if (slot_nr < UINSNS_PER_PAGE)
+ 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);
--
2.43.0