Skip to contentSkip to conversation

uprobes: Use flexible array for xol_area bitmap

PATCH In review Rosen Penev 3 participants 3 messages Nov 13

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 uprobes: Use flexible array for xol_area bitmap

The XOL slot bitmap has the same lifetime as struct xol_area, but it is currently allocated separately. That adds another allocation failure path and a matching cleanup branch without buying any extra flexibility.

Store the bitmap as a regular array and allocate it together with the xol_area. The bitmap remains zero-initialized, while the allocation and error handling become simpler.

---
v3: use normal array
v2: add Acked-by. remove Assisted-by

 kernel/events/uprobes.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
kernel/events/uprobes.c +2 -10
index caf444762a27..c5c90b53d4cc 100644
@@ -108,7 +108,6 @@ static LIST_HEAD(delayed_uprobe_list);
  */
 struct xol_area {
 	wait_queue_head_t		wq;		/* if all slots are busy */
-	unsigned long			*bitmap;	/* 0 = free slot */
 
 	struct page			*page;
 	/*
@@ -117,6 +116,7 @@ struct xol_area {
 	 * the vma go away, and we must handle that reasonably gracefully.
 	 */
 	unsigned long			vaddr;		/* Page(s) of instruction slots */
+	unsigned long			bitmap[BITS_TO_LONGS(UINSNS_PER_PAGE)];	/* 0 = free slot */
 };
 
 static void uprobe_warn(struct task_struct *t, const char *msg)
@@ -1762,14 +1762,9 @@ static struct xol_area *__create_xol_area(unsigned long vaddr)
 	if (unlikely(!area))
 		goto out;
 
-	area->bitmap = kcalloc(BITS_TO_LONGS(UINSNS_PER_PAGE), sizeof(long),
-			       GFP_KERNEL);
-	if (!area->bitmap)
-		goto free_area;
-
 	area->page = alloc_page(GFP_HIGHUSER | __GFP_ZERO);
 	if (!area->page)
-		goto free_bitmap;
+		goto free_area;
 
 	area->vaddr = vaddr;
 	init_waitqueue_head(&area->wq);
@@ -1782,8 +1777,6 @@ static struct xol_area *__create_xol_area(unsigned long vaddr)
 		return area;
 
 	__free_page(area->page);
- free_bitmap:
-	kfree(area->bitmap);
  free_area:
 	kfree(area);
  out:
@@ -1824,7 +1817,6 @@ void uprobe_clear_state(struct mm_struct *mm)
 		return;
 
 	put_page(area->page);
-	kfree(area->bitmap);
 	kfree(area);
 }
 
Signature · 1 line
2.56.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] uprobes: commit subject claims flexible array for fixed-size bitmap --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] uprobes: commit subject claims flexible array for fixed-size bitmap
--

commit 1d1d15ef8335187f18a7637def6f83ac3b705261
Author: Rosen Penev <[email protected]>

uprobes: Use flexible array for xol_area bitmap

This commit embeds the XOL slot bitmap directly into struct xol_area as a fixed-size array instead of allocating and freeing it separately.

Quoted 1 line

uprobes: Use flexible array for xol_area bitmap

[Severity: Low]
This isn't a bug, but the subject line still says "flexible array" even though struct xol_area embeds bitmap as a fixed-size array (bitmap[BITS_TO_LONGS(UINSNS_PER_PAGE)]) and the commit message body describes it as a regular array.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Acked-by on v3 1/1
#2 lore raw
In reply to Rosen Penev
Quoted 6 lines · Rosen Penev

The XOL slot bitmap has the same lifetime as struct xol_area, but it is currently allocated separately. That adds another allocation failure path and a matching cleanup branch without buying any extra flexibility.

Quoted 6 lines

Store the bitmap as a regular array and allocate it together with the xol_area. The bitmap remains zero-initialized, while the allocation and error handling become simpler.