All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Joel Fernandes (Google)" <joel@joelfernandes.org>
To: "Paul E. McKenney" <paulmck@kernel.org>,
	Frederic Weisbecker <frederic@kernel.org>,
	Neeraj Upadhyay <quic_neeraju@quicinc.com>,
	Josh Triplett <josh@joshtriplett.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Lai Jiangshan <jiangshanlai@gmail.com>,
	Joel Fernandes <joel@joelfernandes.org>
Cc: "Uladzislau Rezki (Sony)" <urezki@gmail.com>,
	rcu@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 11/14] rcu/kvfree: Eliminate k[v]free_rcu() single argument macro
Date: Wed, 15 Mar 2023 18:18:58 +0000	[thread overview]
Message-ID: <20230315181902.4177819-11-joel@joelfernandes.org> (raw)
In-Reply-To: <20230315181902.4177819-1-joel@joelfernandes.org>

From: "Uladzislau Rezki (Sony)" <urezki@gmail.com>

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) <urezki@gmail.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
---
 include/linux/rcupdate.h | 29 ++++++++---------------------
 1 file changed, 8 insertions(+), 21 deletions(-)

diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 094321c17e48..7571dbfecb18 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -957,9 +957,8 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
 
 /**
  * kfree_rcu() - kfree an object after a grace period.
- * @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.
+ * @ptr: pointer to kfree for double-argument invocations.
+ * @rhf: the name of the struct rcu_head within the type of @ptr.
  *
  * Many rcu callbacks functions just call kfree() on the base structure.
  * These functions are trivial, but their size adds up, and furthermore
@@ -982,26 +981,18 @@ 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...) kvfree_rcu(ptr, ## rhf)
+#define kfree_rcu(ptr, rhf) kvfree_rcu_arg_2(ptr, rhf)
+#define kvfree_rcu(ptr, rhf) kvfree_rcu_arg_2(ptr, rhf)
 
 /**
- * kvfree_rcu() - kvfree an object after a grace period.
- *
- * This macro consists of one or two arguments and it is
- * based on whether an object is head-less or not. If it
- * has a head then a semantic stays the same as it used
- * to be before:
- *
- *     kvfree_rcu(ptr, rhf);
- *
- * where @ptr is a pointer to kvfree(), @rhf is the name
- * of the rcu_head structure within the type of @ptr.
+ * kfree_rcu_mightsleep() - kfree an object after a grace period.
+ * @ptr: pointer to kfree for single-argument invocations.
  *
  * When it comes to head-less variant, only one argument
  * is passed and that is just a pointer which has to be
  * freed after a grace period. Therefore the semantic is
  *
- *     kvfree_rcu(ptr);
+ *     kfree_rcu_mightsleep(ptr);
  *
  * where @ptr is the pointer to be freed by kvfree().
  *
@@ -1010,13 +1001,9 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
  * annotation. Otherwise, please switch and embed the
  * rcu_head structure within the type of @ptr.
  */
-#define kvfree_rcu(...) KVFREE_GET_MACRO(__VA_ARGS__,		\
-	kvfree_rcu_arg_2, kvfree_rcu_arg_1)(__VA_ARGS__)
-
+#define kfree_rcu_mightsleep(ptr) kvfree_rcu_arg_1(ptr)
 #define kvfree_rcu_mightsleep(ptr) kvfree_rcu_arg_1(ptr)
-#define kfree_rcu_mightsleep(ptr) kvfree_rcu_mightsleep(ptr)
 
-#define KVFREE_GET_MACRO(_1, _2, NAME, ...) NAME
 #define kvfree_rcu_arg_2(ptr, rhf)					\
 do {									\
 	typeof (ptr) ___p = (ptr);					\
-- 
2.40.0.rc1.284.g88254d51c5-goog


  parent reply	other threads:[~2023-03-15 18:20 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-15 18:18 [PATCH v2 01/14] drbd: Rename kvfree_rcu() to kvfree_rcu_mightsleep() Joel Fernandes (Google)
2023-03-15 18:18 ` [PATCH v2 02/14] misc: vmw_vmci: " Joel Fernandes (Google)
2023-03-16  6:50   ` Greg Kroah-Hartman
2023-03-16 15:21     ` Joel Fernandes
2023-03-15 18:18 ` [PATCH v2 03/14] tracing: " Joel Fernandes (Google)
2023-03-16  7:38   ` Daniel Bristot de Oliveira
2023-03-16 15:11     ` Joel Fernandes
2023-03-15 18:18 ` [PATCH v2 04/14] lib/test_vmalloc.c: " Joel Fernandes (Google)
2023-03-15 18:18 ` [PATCH v2 05/14] net/sysctl: " Joel Fernandes (Google)
2023-03-26 12:28   ` Joel Fernandes
2023-03-27 17:14     ` Jakub Kicinski
2023-03-30 15:43       ` Joel Fernandes
2023-03-15 18:18 ` [PATCH v2 06/14] net/mlx5: Rename kfree_rcu() to kfree_rcu_mightsleep() Joel Fernandes (Google)
2023-03-26 12:34   ` Joel Fernandes
2023-03-27 15:09     ` Saeed Mahameed
2023-03-15 18:18 ` [PATCH v2 07/14] ext4/super: " Joel Fernandes (Google)
2023-03-15 19:07   ` Theodore Ts'o
2023-03-16 15:23     ` Joel Fernandes
2023-03-15 18:18 ` [PATCH v2 08/14] rcuscale: " Joel Fernandes (Google)
2023-03-15 18:18 ` [PATCH v2 09/14] torture: Enable clocksource watchdog with "tsc=watchdog" Joel Fernandes (Google)
2023-03-15 18:18 ` [PATCH v2 10/14] rcutorture: Create nocb kthreads only when testing rcu in CONFIG_RCU_NOCB_CPU=y kernels Joel Fernandes (Google)
2023-03-15 18:18 ` Joel Fernandes (Google) [this message]
2023-03-15 18:18 ` [PATCH v2 12/14] mac802154: Rename kfree_rcu() to kvfree_rcu_mightsleep() Joel Fernandes (Google)
2023-03-16 16:41   ` Stefan Schmidt
2023-03-16 18:06     ` Joel Fernandes
2023-03-15 18:19 ` [PATCH v2 13/14] RDMA/rxe: " Joel Fernandes (Google)
2023-03-15 18:38   ` Bob Pearson
2023-03-15 18:41     ` Joel Fernandes
2023-03-15 19:05       ` Bob Pearson
2023-03-15 19:59         ` Joel Fernandes
2023-03-15 18:19 ` [PATCH v2 14/14] checkpatch: Error out if deprecated RCU API used Joel Fernandes (Google)
2023-03-16  3:49   ` Paul E. McKenney
2023-03-26 12:27 ` [PATCH v2 01/14] drbd: Rename kvfree_rcu() to kvfree_rcu_mightsleep() Joel Fernandes
2023-03-27 19:26   ` Jens Axboe
2023-03-30 15:38     ` Joel Fernandes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230315181902.4177819-11-joel@joelfernandes.org \
    --to=joel@joelfernandes.org \
    --cc=frederic@kernel.org \
    --cc=jiangshanlai@gmail.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=paulmck@kernel.org \
    --cc=quic_neeraju@quicinc.com \
    --cc=rcu@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=urezki@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.