Skip to contentSkip to conversation

mm/vmalloc: clarify why vmap_range_noflush() might sleep

PATCH Applied Brendan Jackman 3 participants 3 messages Dec 15, 2025 – Dec 16, 2025

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

PATCH v3 1/1 mm/vmalloc: clarify why vmap_range_noflush() might sleep

The only reason vmap_range_noflush() can sleep is because of pagetable allocations.

The actual allocation mechanism is arch-specific so might_alloc() doesn't work here (what GFP flags would be used?). Hence, just add a comment.

Also note that this might do a TLB shootdown. This is not actually sleeping but it requires IRQs on for x86, and might_sleep() incidentally serves to detect violations of that too.

---
Applies to mm-new.

Changes in v3:
- Added note about TLB shootdowns and x86.
- Since the comment no longer fit on one line anyway, also be a bit more
verbose in general.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Switched from might_alloc() to keeping might_sleep() + comment
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 mm/vmalloc.c | 5 +++++
 1 file changed, 5 insertions(+)
mm/vmalloc.c +5 -0
index 41dd01e8430c548167d6123f6ec66bf798f20eec..be4e5f2566a4490d45de29568df538b7c8515b01 100644
@@ -305,6 +305,11 @@ static int vmap_range_noflush(unsigned long addr, unsigned long end,
 	int err;
 	pgtbl_mod_mask mask = 0;
 
+	/*
+	 * Might allocate pagetables (for most archs a more precise annotation
+	 * would be might_alloc(GFP_PGTABLE_KERNEL)). Also might shootdown TLB
+	 * (requires IRQs enabled on x86).
+	 */
 	might_sleep();
 	BUG_ON(addr >= end);
 

---
base-commit: d0a24447990a9d8212bfb3a692d59efa74ce9f86
change-id: 20251208-b4-vmalloc-might_alloc-754a791e4e10

Best regards,

Signature · 1 line
Brendan Jackman <[email protected]>
maintainer Reviewed-by on v3 1/1
#1 lore raw
Quoted 49 lines · Brendan Jackman

The only reason vmap_range_noflush() can sleep is because of pagetable allocations.

The actual allocation mechanism is arch-specific so might_alloc() doesn't work here (what GFP flags would be used?). Hence, just add a comment.

Also note that this might do a TLB shootdown. This is not actually sleeping but it requires IRQs on for x86, and might_sleep() incidentally serves to detect violations of that too.

---
Applies to mm-new.

Changes in v3:
- Added note about TLB shootdowns and x86.
- Since the comment no longer fit on one line anyway, also be a bit more
verbose in general.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Switched from might_alloc() to keeping might_sleep() + comment
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 mm/vmalloc.c | 5 +++++
 1 file changed, 5 insertions(+)
mm/vmalloc.c +5 -1
index 41dd01e8430c548167d6123f6ec66bf798f20eec..be4e5f2566a4490d45de29568df538b7c8515b01 100644
@@ -305,6 +305,11 @@ static int vmap_range_noflush(unsigned long addr, unsigned long end,
 	int err;
 	pgtbl_mod_mask mask = 0;
 
+	/*
+	 * Might allocate pagetables (for most archs a more precise annotation
+	 * would be might_alloc(GFP_PGTABLE_KERNEL)). Also might shootdown TLB
+	 * (requires IRQs enabled on x86).
+	 */
 	might_sleep();
 	BUG_ON(addr >= end);
 
 
---

base-commit: d0a24447990a9d8212bfb3a692d59efa74ce9f86
change-id: 20251208-b4-vmalloc-might_alloc-754a791e4e10

Quoted 4 lines

Best regards,

Signature · 1 line
Brendan Jackman <[email protected]>

--
Uladzislau Rezki

Reviewed-by on v3 1/1
#2 lore raw
In reply to Brendan Jackman
Quoted 7 lines · Brendan Jackman

The only reason vmap_range_noflush() can sleep is because of pagetable allocations.

The actual allocation mechanism is arch-specific so might_alloc() doesn't work here (what GFP flags would be used?). Hence, just add a comment.

Quoted 5 lines

Also note that this might do a TLB shootdown. This is not actually sleeping but it requires IRQs on for x86, and might_sleep() incidentally serves to detect violations of that too.

Quoted 38 lines

---
Applies to mm-new.

Changes in v3:
- Added note about TLB shootdowns and x86.
- Since the comment no longer fit on one line anyway, also be a bit more
verbose in general.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Switched from might_alloc() to keeping might_sleep() + comment
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 mm/vmalloc.c | 5 +++++
 1 file changed, 5 insertions(+)
mm/vmalloc.c +5 -1
index 41dd01e8430c548167d6123f6ec66bf798f20eec..be4e5f2566a4490d45de29568df538b7c8515b01 100644
@@ -305,6 +305,11 @@ static int vmap_range_noflush(unsigned long addr, unsigned long end,
 	int err;
 	pgtbl_mod_mask mask = 0;
 
+	/*
+	 * Might allocate pagetables (for most archs a more precise annotation
+	 * would be might_alloc(GFP_PGTABLE_KERNEL)). Also might shootdown TLB
+	 * (requires IRQs enabled on x86).
+	 */
 	might_sleep();
 	BUG_ON(addr >= end);
 
 
---

base-commit: d0a24447990a9d8212bfb3a692d59efa74ce9f86
change-id: 20251208-b4-vmalloc-might_alloc-754a791e4e10

Best regards,