linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] rcu: introduce kfree_rcu() single argument macro
@ 2020-11-20 11:49 Uladzislau Rezki (Sony)
  2020-11-20 11:49 ` [PATCH 2/2] rcu: eliminate the __kvfree_rcu() macro Uladzislau Rezki (Sony)
  0 siblings, 1 reply; 4+ messages in thread
From: Uladzislau Rezki (Sony) @ 2020-11-20 11:49 UTC (permalink / raw)
  To: LKML, RCU, Paul E . McKenney
  Cc: Andrew Morton, Frederic Weisbecker, Neeraj Upadhyay,
	Joel Fernandes, Peter Zijlstra, Michal Hocko, Thomas Gleixner,
	Theodore Y . Ts'o, Sebastian Andrzej Siewior,
	Uladzislau Rezki, Oleksiy Avramchenko

There is a kvfree_rcu() single argument macro that pairs
with kvmalloc() allocated pointer. Even though it also
deals with SLAB one, it might be confused for the users.

That is why add an extra kfree_rcu() macro that explicitly
pairs with kmalloc() pointer and its name, so it becomes
more obvious for users.

Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
---
 include/linux/rcupdate.h | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index e09c0d87b3c3..b1e75648d402 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -853,8 +853,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(both for single argument and double one)
+ * @rhf: the name of the struct rcu_head within the type of @ptr,
+ *       only for double argument.
  *
  * Many rcu callbacks functions just call kfree() on the base structure.
  * These functions are trivial, but their size adds up, and furthermore
@@ -877,13 +878,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.
@@ -915,7 +910,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);				\
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] rcu: eliminate the __kvfree_rcu() macro
  2020-11-20 11:49 [PATCH 1/2] rcu: introduce kfree_rcu() single argument macro Uladzislau Rezki (Sony)
@ 2020-11-20 11:49 ` Uladzislau Rezki (Sony)
  2020-11-24 19:55   ` Paul E. McKenney
  0 siblings, 1 reply; 4+ messages in thread
From: Uladzislau Rezki (Sony) @ 2020-11-20 11:49 UTC (permalink / raw)
  To: LKML, RCU, Paul E . McKenney
  Cc: Andrew Morton, Frederic Weisbecker, Neeraj Upadhyay,
	Joel Fernandes, Peter Zijlstra, Michal Hocko, Thomas Gleixner,
	Theodore Y . Ts'o, Sebastian Andrzej Siewior,
	Uladzislau Rezki, Oleksiy Avramchenko

Make the kvfree_rcu_arg_2() to be open-coded, so readability
and review look better from the first glance. Moreover, that
makes it clear that both kvfree_rcu_arg_1/2() use one single
interface.

Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
---
 include/linux/rcupdate.h | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index b1e75648d402..6d56dd7e6a30 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -842,15 +842,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(both for single argument and double one)
@@ -868,7 +859,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.
  *
@@ -914,8 +905,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)					\
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] rcu: eliminate the __kvfree_rcu() macro
  2020-11-20 11:49 ` [PATCH 2/2] rcu: eliminate the __kvfree_rcu() macro Uladzislau Rezki (Sony)
@ 2020-11-24 19:55   ` Paul E. McKenney
  2020-11-25 18:57     ` Uladzislau Rezki
  0 siblings, 1 reply; 4+ messages in thread
From: Paul E. McKenney @ 2020-11-24 19:55 UTC (permalink / raw)
  To: Uladzislau Rezki (Sony)
  Cc: LKML, RCU, Andrew Morton, Frederic Weisbecker, Neeraj Upadhyay,
	Joel Fernandes, Peter Zijlstra, Michal Hocko, Thomas Gleixner,
	Theodore Y . Ts'o, Sebastian Andrzej Siewior,
	Oleksiy Avramchenko

On Fri, Nov 20, 2020 at 12:49:17PM +0100, Uladzislau Rezki (Sony) wrote:
> Make the kvfree_rcu_arg_2() to be open-coded, so readability
> and review look better from the first glance. Moreover, that
> makes it clear that both kvfree_rcu_arg_1/2() use one single
> interface.
> 
> Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>

I queued both with the usual editing, thank you!

							Thanx, Paul

> ---
>  include/linux/rcupdate.h | 18 ++++++------------
>  1 file changed, 6 insertions(+), 12 deletions(-)
> 
> diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
> index b1e75648d402..6d56dd7e6a30 100644
> --- a/include/linux/rcupdate.h
> +++ b/include/linux/rcupdate.h
> @@ -842,15 +842,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(both for single argument and double one)
> @@ -868,7 +859,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.
>   *
> @@ -914,8 +905,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)					\
> -- 
> 2.20.1
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] rcu: eliminate the __kvfree_rcu() macro
  2020-11-24 19:55   ` Paul E. McKenney
@ 2020-11-25 18:57     ` Uladzislau Rezki
  0 siblings, 0 replies; 4+ messages in thread
From: Uladzislau Rezki @ 2020-11-25 18:57 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: Uladzislau Rezki (Sony),
	LKML, RCU, Andrew Morton, Frederic Weisbecker, Neeraj Upadhyay,
	Joel Fernandes, Peter Zijlstra, Michal Hocko, Thomas Gleixner,
	Theodore Y . Ts'o, Sebastian Andrzej Siewior,
	Oleksiy Avramchenko

On Tue, Nov 24, 2020 at 11:55:51AM -0800, Paul E. McKenney wrote:
> On Fri, Nov 20, 2020 at 12:49:17PM +0100, Uladzislau Rezki (Sony) wrote:
> > Make the kvfree_rcu_arg_2() to be open-coded, so readability
> > and review look better from the first glance. Moreover, that
> > makes it clear that both kvfree_rcu_arg_1/2() use one single
> > interface.
> > 
> > Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
> 
> I queued both with the usual editing, thank you!
> 
Thank you, Paul!

--
Vlad Rezki

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-25 18:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-20 11:49 [PATCH 1/2] rcu: introduce kfree_rcu() single argument macro Uladzislau Rezki (Sony)
2020-11-20 11:49 ` [PATCH 2/2] rcu: eliminate the __kvfree_rcu() macro Uladzislau Rezki (Sony)
2020-11-24 19:55   ` Paul E. McKenney
2020-11-25 18:57     ` Uladzislau Rezki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).