Skip to content

Commit 6ffe8c7

Browse files
oleg-nesterovPeter Zijlstra
authored andcommitted
uprobes: simplify xol_take_insn_slot() and its caller
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 <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 430af82 commit 6ffe8c7

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

kernel/events/uprobes.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,25 +1628,20 @@ void uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm)
16281628
*/
16291629
static unsigned long xol_take_insn_slot(struct xol_area *area)
16301630
{
1631-
unsigned long slot_addr;
1632-
int slot_nr;
1631+
unsigned int slot_nr;
16331632

1634-
do {
1633+
for (;;) {
16351634
slot_nr = find_first_zero_bit(area->bitmap, UINSNS_PER_PAGE);
16361635
if (slot_nr < UINSNS_PER_PAGE) {
16371636
if (!test_and_set_bit(slot_nr, area->bitmap))
16381637
break;
1639-
1640-
slot_nr = UINSNS_PER_PAGE;
16411638
continue;
16421639
}
16431640
wait_event(area->wq, (atomic_read(&area->slot_count) < UINSNS_PER_PAGE));
1644-
} while (slot_nr >= UINSNS_PER_PAGE);
1641+
}
16451642

1646-
slot_addr = area->vaddr + (slot_nr * UPROBE_XOL_SLOT_BYTES);
16471643
atomic_inc(&area->slot_count);
1648-
1649-
return slot_addr;
1644+
return area->vaddr + slot_nr * UPROBE_XOL_SLOT_BYTES;
16501645
}
16511646

16521647
/*
@@ -1663,12 +1658,8 @@ static unsigned long xol_get_insn_slot(struct uprobe *uprobe)
16631658
return 0;
16641659

16651660
xol_vaddr = xol_take_insn_slot(area);
1666-
if (unlikely(!xol_vaddr))
1667-
return 0;
1668-
16691661
arch_uprobe_copy_ixol(area->page, xol_vaddr,
16701662
&uprobe->arch.ixol, sizeof(uprobe->arch.ixol));
1671-
16721663
return xol_vaddr;
16731664
}
16741665

0 commit comments

Comments
 (0)