[PATCH 2/7] uaccess: Add scope guard for bare kernel nofault regions

From: Muhammad Usama Anjum

Date: Mon Aug 24 2026 - 12:10:38 EST


A batched nofault region must run its end hook on every exit. Pairing the
hooks by hand makes early returns and error paths easy to get wrong.

Add a scope guard that starts the region on entry and ends it when the
scope is left. Callers can keep their natural control flow while the
architecture state remains balanced on success and failure.

No functional change until a caller uses the guard.

Signed-off-by: Muhammad Usama Anjum <usama.anjum@xxxxxxx>
---
include/linux/uaccess.h | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
index 7ae1854673471..b25e778ddc38a 100644
--- a/include/linux/uaccess.h
+++ b/include/linux/uaccess.h
@@ -653,6 +653,10 @@ do { \
#define __end_kernel_nofault_bare() do {} while (0)
#endif

+DEFINE_LOCK_GUARD_0(__kernel_nofault_bare,
+ __begin_kernel_nofault_bare(),
+ __end_kernel_nofault_bare())
+
/**
* get_kernel_nofault(): safely attempt to read from a location
* @val: read into this variable
--
2.47.3