Skip to content

Commit 7e3f926

Browse files
urezkipaulmckrcu
authored andcommitted
rcu/kvfree: Eliminate k[v]free_rcu() single argument macro
The kvfree_rcu() and kfree_rcu() APIs are hazardous in that if you forget the second argument, it works, but might sleep. This sleeping can be a correctness bug from atomic contexts, and even in non-atomic contexts it might introduce unacceptable latencies. This commit therefore removes the single-argument kvfree_rcu() and kfree_rcu() macros. Code that would have previously used these single-argument kvfree_rcu() and kfree_rcu() macros should instead use kvfree_rcu_mightsleep() or kfree_rcu_mightsleep(). [ paulmck: Apply Joel Fernandes feedback. ] Signed-off-by: Uladzislau Rezki (Sony) <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]> Signed-off-by: Joel Fernandes (Google) <[email protected]>
1 parent ac9a786 commit 7e3f926

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

include/linux/rcupdate.h

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -957,9 +957,8 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
957957

958958
/**
959959
* kfree_rcu() - kfree an object after a grace period.
960-
* @ptr: pointer to kfree for both single- and double-argument invocations.
961-
* @rhf: the name of the struct rcu_head within the type of @ptr,
962-
* but only for double-argument invocations.
960+
* @ptr: pointer to kfree for double-argument invocations.
961+
* @rhf: the name of the struct rcu_head within the type of @ptr.
963962
*
964963
* Many rcu callbacks functions just call kfree() on the base structure.
965964
* These functions are trivial, but their size adds up, and furthermore
@@ -984,26 +983,18 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
984983
* The BUILD_BUG_ON check must not involve any function calls, hence the
985984
* checks are done in macros here.
986985
*/
987-
#define kfree_rcu(ptr, rhf...) kvfree_rcu(ptr, ## rhf)
986+
#define kfree_rcu(ptr, rhf) kvfree_rcu_arg_2(ptr, rhf)
987+
#define kvfree_rcu(ptr, rhf) kvfree_rcu_arg_2(ptr, rhf)
988988

989989
/**
990-
* kvfree_rcu() - kvfree an object after a grace period.
991-
*
992-
* This macro consists of one or two arguments and it is
993-
* based on whether an object is head-less or not. If it
994-
* has a head then a semantic stays the same as it used
995-
* to be before:
996-
*
997-
* kvfree_rcu(ptr, rhf);
998-
*
999-
* where @ptr is a pointer to kvfree(), @rhf is the name
1000-
* of the rcu_head structure within the type of @ptr.
990+
* kfree_rcu_mightsleep() - kfree an object after a grace period.
991+
* @ptr: pointer to kfree for single-argument invocations.
1001992
*
1002993
* When it comes to head-less variant, only one argument
1003994
* is passed and that is just a pointer which has to be
1004995
* freed after a grace period. Therefore the semantic is
1005996
*
1006-
* kvfree_rcu(ptr);
997+
* kfree_rcu_mightsleep(ptr);
1007998
*
1008999
* where @ptr is the pointer to be freed by kvfree().
10091000
*
@@ -1012,13 +1003,9 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
10121003
* annotation. Otherwise, please switch and embed the
10131004
* rcu_head structure within the type of @ptr.
10141005
*/
1015-
#define kvfree_rcu(...) KVFREE_GET_MACRO(__VA_ARGS__, \
1016-
kvfree_rcu_arg_2, kvfree_rcu_arg_1)(__VA_ARGS__)
1017-
1006+
#define kfree_rcu_mightsleep(ptr) kvfree_rcu_arg_1(ptr)
10181007
#define kvfree_rcu_mightsleep(ptr) kvfree_rcu_arg_1(ptr)
1019-
#define kfree_rcu_mightsleep(ptr) kvfree_rcu_mightsleep(ptr)
10201008

1021-
#define KVFREE_GET_MACRO(_1, _2, NAME, ...) NAME
10221009
#define kvfree_rcu_arg_2(ptr, rhf) \
10231010
do { \
10241011
typeof (ptr) ___p = (ptr); \

0 commit comments

Comments
 (0)