Skip to content

Commit a123ecd

Browse files
urezkiBrian Maly
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]> Orabug: 35383105 (cherry picked from commit 7e3f926) cherry-pick-repo=kernel/git/torvalds/linux.git unmodified-from-upstream: 7e3f926 Signed-off-by: Mikhael Goikhman <[email protected]> Signed-off-by: Qing Huang <[email protected]> Reviewed-by: Devesh Sharma <[email protected]> Signed-off-by: Brian Maly <[email protected]>
1 parent ddd445a commit a123ecd

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
@@ -924,9 +924,8 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
924924

925925
/**
926926
* kfree_rcu() - kfree an object after a grace period.
927-
* @ptr: pointer to kfree for both single- and double-argument invocations.
928-
* @rhf: the name of the struct rcu_head within the type of @ptr,
929-
* but only for double-argument invocations.
927+
* @ptr: pointer to kfree for double-argument invocations.
928+
* @rhf: the name of the struct rcu_head within the type of @ptr.
930929
*
931930
* Many rcu callbacks functions just call kfree() on the base structure.
932931
* These functions are trivial, but their size adds up, and furthermore
@@ -949,26 +948,18 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
949948
* The BUILD_BUG_ON check must not involve any function calls, hence the
950949
* checks are done in macros here.
951950
*/
952-
#define kfree_rcu(ptr, rhf...) kvfree_rcu(ptr, ## rhf)
951+
#define kfree_rcu(ptr, rhf) kvfree_rcu_arg_2(ptr, rhf)
952+
#define kvfree_rcu(ptr, rhf) kvfree_rcu_arg_2(ptr, rhf)
953953

954954
/**
955-
* kvfree_rcu() - kvfree an object after a grace period.
956-
*
957-
* This macro consists of one or two arguments and it is
958-
* based on whether an object is head-less or not. If it
959-
* has a head then a semantic stays the same as it used
960-
* to be before:
961-
*
962-
* kvfree_rcu(ptr, rhf);
963-
*
964-
* where @ptr is a pointer to kvfree(), @rhf is the name
965-
* of the rcu_head structure within the type of @ptr.
955+
* kfree_rcu_mightsleep() - kfree an object after a grace period.
956+
* @ptr: pointer to kfree for single-argument invocations.
966957
*
967958
* When it comes to head-less variant, only one argument
968959
* is passed and that is just a pointer which has to be
969960
* freed after a grace period. Therefore the semantic is
970961
*
971-
* kvfree_rcu(ptr);
962+
* kfree_rcu_mightsleep(ptr);
972963
*
973964
* where @ptr is the pointer to be freed by kvfree().
974965
*
@@ -977,13 +968,9 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
977968
* annotation. Otherwise, please switch and embed the
978969
* rcu_head structure within the type of @ptr.
979970
*/
980-
#define kvfree_rcu(...) KVFREE_GET_MACRO(__VA_ARGS__, \
981-
kvfree_rcu_arg_2, kvfree_rcu_arg_1)(__VA_ARGS__)
982-
971+
#define kfree_rcu_mightsleep(ptr) kvfree_rcu_arg_1(ptr)
983972
#define kvfree_rcu_mightsleep(ptr) kvfree_rcu_arg_1(ptr)
984-
#define kfree_rcu_mightsleep(ptr) kvfree_rcu_mightsleep(ptr)
985973

986-
#define KVFREE_GET_MACRO(_1, _2, NAME, ...) NAME
987974
#define kvfree_rcu_arg_2(ptr, rhf) \
988975
do { \
989976
typeof (ptr) ___p = (ptr); \

0 commit comments

Comments
 (0)