kfree_rcu() updates for v5.12
Paul E. McKenney
maintainercover kfree_rcu() updates for v5.12
Hello!
This series provides kfree_rcu() updates:
1. Record kvfree_call_rcu() call stack for KASAN, courtesy of Zqiang.
2. Introduce kfree_rcu() single-argument macro, courtesy of
Uladzislau Rezki.
3. Eliminate the __kvfree_rcu() macro, courtesy of Uladzislau Rezki.
Thanx, Paul
------------------------------------------------------------------------
include/linux/rcupdate.h | 40 ++++++++++++++++++---------------------- kernel/rcu/tree.c | 1 + 2 files changed, 19 insertions(+), 22 deletions(-)
[email protected]
maintainerPATCH 1/3 rcu: Record kvfree_call_rcu() call stack for KASAN
From: Zqiang <[email protected]>
This commit adds a call to kasan_record_aux_stack() in kvfree_call_rcu() in order to record the call stack of the code that caused the object to be freed. Please note that this function does not update the allocated/freed state, which is important because RCU readers might still be referencing this object.
--- kernel/rcu/tree.c | 1 + 1 file changed, 1 insertion(+)
kernel/rcu/tree.c +1 -0
@@ -3498,6 +3498,7 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) goto unlock_return; } +kasan_record_aux_stack (ptr); success =kvfree_call_rcu_add_ptr_to_bulk (krcp, ptr);if (!success) {run_page_cache_worker (krcp);
Signature · 1 line
2.9.5
[email protected]
maintainerPATCH 2/3 rcu: Introduce kfree_rcu() single-argument macro
In reply to Paul E. McKenneyFrom: "Uladzislau Rezki (Sony)" <[email protected]>
There is a kvfree_rcu() single argument macro that handles pointers returned by kvmalloc(). Even though it also handles pointer returned by kmalloc(), readability suffers.
This commit therefore updates the kfree_rcu() macro to explicitly pair with kmalloc(), thus improving readability.
--- include/linux/rcupdate.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
include/linux/rcupdate.h +12 -10
@@ -851,8 +851,9 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)/** * kfree_rcu() - kfree an object after a grace period. -* @ptr: pointer to kfree -* @rhf: the name of the struct rcu_head within the type of @ptr. +* @ptr: pointer to kfree for both single- and double-argument invocations. +* @rhf: the name of the struct rcu_head within the type of @ptr, +* but only for double-argument invocations. * * Many rcu callbacks functions just call kfree() on the base structure. * These functions are trivial, but their size adds up, and furthermore
@@ -875,13 +876,7 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)* The BUILD_BUG_ON check must not involve any function calls, hence the * checks are done in macros here. */ -#define kfree_rcu (ptr, rhf) \ -do { \ - typeof (ptr) ___p = (ptr); \ - \ - if (___p) \ - __kvfree_rcu(&((___p)->rhf), offsetof(typeof(*(ptr)), rhf)); \ -} while (0) +#define kfree_rcu kvfree_rcu/** * kvfree_rcu() - kvfree an object after a grace period.
@@ -913,7 +908,14 @@ do { \ kvfree_rcu_arg_2, kvfree_rcu_arg_1)(__VA_ARGS__)#define KVFREE_GET_MACRO (_1, _2,NAME , ...) NAME -#define kvfree_rcu_arg_2 (ptr, rhf) kfree_rcu(ptr, rhf) +#define kvfree_rcu_arg_2 (ptr, rhf) \ +do { \ + typeof (ptr) ___p = (ptr); \ + \ + if (___p) \ + __kvfree_rcu(&((___p)->rhf), offsetof(typeof(*(ptr)), rhf)); \ +} while (0) +#define kvfree_rcu_arg_1 (ptr) \ do { \ typeof(ptr) ___p = (ptr); \
Signature · 1 line
2.9.5
[email protected]
maintainerPATCH 3/3 rcu: Eliminate the __kvfree_rcu() macro
In reply to Paul E. McKenneyFrom: "Uladzislau Rezki (Sony)" <[email protected]>
This commit open-codes the __kvfree_rcu() macro, thus saving a few lines of code and improving readability.
--- include/linux/rcupdate.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
include/linux/rcupdate.h +6 -12
@@ -840,15 +840,6 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)*/ #define __is_kvfree_rcu_offset (offset) ((offset) < 4096) -/* -* Helper macro for kfree_rcu() to prevent argument-expansion eyestrain. -*/ -#define __kvfree_rcu (head, offset) \ - do { \ - BUILD_BUG_ON(!__is_kvfree_rcu_offset(offset)); \ - kvfree_call_rcu(head, (rcu_callback_t)(unsigned long)(offset)); \ - } while (0) -/** * kfree_rcu() - kfree an object after a grace period. * @ptr: pointer to kfree for both single- and double-argument invocations.
@@ -866,7 +857,7 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)* Because the functions are not allowed in the low-order 4096 bytes of * kernel virtual memory, offsets up to 4095 bytes can be accommodated. * If the offset is larger than 4095 bytes, a compile-time error will -* be generated in __kvfree_rcu(). If this error is triggered, you can +* be generated in kvfree_rcu_arg_2(). If this error is triggered, you can * either fall back to use of call_rcu() or rearrange the structure to * position the rcu_head structure into the first 4096 bytes. *
@@ -912,8 +903,11 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)do { \typeof (ptr) ___p = (ptr); \ \ -if (___p) \ -__kvfree_rcu (&((___p)->rhf), offsetof(typeof (*(ptr )), rhf)); \ +if (___p) { \ +BUILD_BUG_ON (!__is_kvfree_rcu_offset (offsetof(typeof (*(ptr )), rhf))); \ +kvfree_call_rcu (&((___p)->rhf), (rcu_callback_t )(unsigned long ) \ + (offsetof(typeof (*(ptr )), rhf))); \ + } \ } while (0)#define kvfree_rcu_arg_1 (ptr) \
Signature · 1 line
2.9.5