Skip to contentSkip to conversation

Replace rcu_swap_protected() for v5.5

PATCH Superseded Paul E. McKenney 12 participants 48 messages Oct 3, 2019 – Oct 28, 2019

Subsystems (16)
lore
Share & tools
lore

Paul E. McKenney

author maintainer
#0 lore raw

cover Replace rcu_swap_protected() for v5.5

Hello!

This series replaces uses of rcu_swap_protected() with rcu_replace(). A later patch will remove rcu_swap_protected().

1. Upgrade rcu_swap_protected() to rcu_replace().

2-9. Replace calls to rcu_swap_protected() with rcu_replace().

Thanx, Paul

------------------------------------------------------------------------

 arch/x86/kvm/pmu.c                          |    4 ++--
 drivers/gpu/drm/i915/gem/i915_gem_context.c |    2 +-
 drivers/scsi/scsi.c                         |    4 ++--
 drivers/scsi/scsi_sysfs.c                   |    8 ++++----
 fs/afs/vl_list.c                            |    4 ++--
 include/linux/rcupdate.h                    |   18 ++++++++++++++++++
 kernel/bpf/cgroup.c                         |    4 ++--
 net/core/dev.c                              |    4 ++--
 net/core/sock_reuseport.c                   |    4 ++--
 net/netfilter/nf_tables_api.c               |    5 +++--
 net/sched/act_api.c                         |    2 +-
 net/sched/act_csum.c                        |    4 ++--
 net/sched/act_ct.c                          |    2 +-
 net/sched/act_ctinfo.c                      |    4 ++--
 net/sched/act_ife.c                         |    2 +-
 net/sched/act_mirred.c                      |    4 ++--
 net/sched/act_mpls.c                        |    2 +-
 net/sched/act_police.c                      |    6 +++---
 net/sched/act_skbedit.c                     |    4 ++--
 net/sched/act_tunnel_key.c                  |    4 ++--
 net/sched/act_vlan.c                        |    2 +-
 21 files changed, 56 insertions(+), 37 deletions(-)
author maintainer
#1 lore raw

PATCH 1/9 rcu: Upgrade rcu_swap_protected() to rcu_replace()

From: "Paul E. McKenney" <[email protected]>

Although the rcu_swap_protected() macro follows the example of swap(), the interactions with RCU make its update of its argument somewhat counter-intuitive. This commit therefore introduces an rcu_replace() that returns the old value of the RCU pointer instead of doing the argument update. Once all the uses of rcu_swap_protected() are updated to instead use rcu_replace(), rcu_swap_protected() will be removed.

---
 include/linux/rcupdate.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
include/linux/rcupdate.h +18 -0
index 75a2ede..3b73287 100644
@@ -383,6 +383,24 @@ do {									      \
 } while (0)
 
 /**
+ * rcu_replace() - replace an RCU pointer, returning its old value
+ * @rcu_ptr: RCU pointer, whose old value is returned
+ * @ptr: regular pointer
+ * @c: the lockdep conditions under which the dereference will take place
+ *
+ * Perform a replacement, where @rcu_ptr is an RCU-annotated
+ * pointer and @c is the lockdep argument that is passed to the
+ * rcu_dereference_protected() call used to read that pointer.  The old
+ * value of @rcu_ptr is returned, and @rcu_ptr is set to @ptr.
+ */
+#define rcu_replace(rcu_ptr, ptr, c)					\
+({									\
+	typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c));	\
+	rcu_assign_pointer((rcu_ptr), (ptr));				\
+	__tmp;								\
+})
+
+/**
  * rcu_swap_protected() - swap an RCU and a regular pointer
  * @rcu_ptr: RCU pointer
  * @ptr: regular pointer
Signature · 1 line
2.9.5
maintainer
#2 lore raw

Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()

include/linux/rcupdate.h do { \ · line 401

Quoted 6 lines · [email protected] wrote:
include/linux/rcupdate.h +6 -0
+#define rcu_replace(rcu_ptr, ptr, c)					\
+({									\
+	typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c));	\
+	rcu_assign_pointer((rcu_ptr), (ptr));				\
+	__tmp;								\
+})

Does it make sense to actually use xchg() if that's supported by the arch?

David

#3 lore raw

Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()

Quoted 11 lines · On Thu, 03 Oct 2019 09:39:17 +0100 David Howells <[email protected]> wrote:

include/linux/rcupdate.h do { \ · line 401

Quoted 6 lines · [email protected] wrote:
include/linux/rcupdate.h +6 -0
+#define rcu_replace(rcu_ptr, ptr, c)					\
+({									\
+	typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c));	\
+	rcu_assign_pointer((rcu_ptr), (ptr));				\
+	__tmp;								\
+})  

Does it make sense to actually use xchg() if that's supported by the arch?

Hmm, is there really any arch that doesn't support xchg()? It would be very hard to do any kind of atomic operations without it.

cmpxchg() is the one that I understand is optional by the arch.

-- Steve

author maintainer
#4 lore raw

Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()

Quoted 5 lines · Steven Rostedt
Quoted 2 lines · On Thu, 03 Oct 2019 09:39:17 +0100 David Howells <[email protected]> wrote:

[email protected] wrote:

Quoted 8 lines
Quoted 8 lines

include/linux/rcupdate.h do { \ · line 401

Quoted 6 lines
include/linux/rcupdate.h +6 -0
+#define rcu_replace(rcu_ptr, ptr, c)					\
+({									\
+	typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c));	\
+	rcu_assign_pointer((rcu_ptr), (ptr));				\
+	__tmp;								\
+})  

Does it make sense to actually use xchg() if that's supported by the arch?

Historically, xchg() has been quite a bit slower than a pair of assignment statements, in part due to the strong memory ordering guaranteed by xchg(). Has that changed? If so, then, agreed, it might make sense to use xchg().

Quoted 4 lines

Hmm, is there really any arch that doesn't support xchg()? It would be very hard to do any kind of atomic operations without it.

cmpxchg() is the one that I understand is optional by the arch.

To your point, even the old Sequent Symmetry platforms supported xchg() back in the late 1980s and early 1990s, but only the later versions (with 80486 and later) supported cmpxchg().

Thanx, Paul

#5 lore raw

Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()

Quoted 15 lines · Paul E. McKenney
Quoted 5 lines · Steven Rostedt
Quoted 2 lines · On Thu, 03 Oct 2019 09:39:17 +0100 David Howells <[email protected]> wrote:

[email protected] wrote:

Quoted 8 lines
Quoted 8 lines

include/linux/rcupdate.h do { \ · line 401

Quoted 6 lines
include/linux/rcupdate.h +6 -0
+#define rcu_replace(rcu_ptr, ptr, c)					\
+({									\
+	typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c));	\
+	rcu_assign_pointer((rcu_ptr), (ptr));				\
+	__tmp;								\
+})  

Does it make sense to actually use xchg() if that's supported by the arch?

Quoted 4 lines

Historically, xchg() has been quite a bit slower than a pair of assignment statements, in part due to the strong memory ordering guaranteed by xchg(). Has that changed? If so, then, agreed, it might make sense to use xchg().

Nope, still the case. xchg() is an atomic op with full ordering.

author maintainer
#6 lore raw

Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()

Quoted 16 lines · Peter Zijlstra
Quoted 15 lines · Paul E. McKenney
Quoted 13 lines · Steven Rostedt
Quoted 10 lines · On Thu, 03 Oct 2019 09:39:17 +0100 David Howells <[email protected]> wrote:

include/linux/rcupdate.h do { \ · line 401

Quoted 6 lines · [email protected] wrote:
include/linux/rcupdate.h +6 -0
+#define rcu_replace(rcu_ptr, ptr, c)					\
+({									\
+	typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c));	\
+	rcu_assign_pointer((rcu_ptr), (ptr));				\
+	__tmp;								\
+})  

Does it make sense to actually use xchg() if that's supported by the arch?

Quoted 6 lines
Quoted 4 lines

Historically, xchg() has been quite a bit slower than a pair of assignment statements, in part due to the strong memory ordering guaranteed by xchg(). Has that changed? If so, then, agreed, it might make sense to use xchg().

Nope, still the case. xchg() is an atomic op with full ordering.

OK, let's stick with the pair of assignments, then. ;-)

Thanx, Paul

#7 lore raw

Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()

In reply to Paul E. McKenney
Quoted 15 lines · Paul E. McKenney
Quoted 5 lines · Steven Rostedt
Quoted 2 lines · On Thu, 03 Oct 2019 09:39:17 +0100 David Howells <[email protected]> wrote:

[email protected] wrote:

Quoted 8 lines
Quoted 8 lines

include/linux/rcupdate.h do { \ · line 401

Quoted 6 lines
include/linux/rcupdate.h +6 -0
+#define rcu_replace(rcu_ptr, ptr, c)					\
+({									\
+	typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c));	\
+	rcu_assign_pointer((rcu_ptr), (ptr));				\
+	__tmp;								\
+})  

Does it make sense to actually use xchg() if that's supported by the arch?

Quoted 4 lines

Historically, xchg() has been quite a bit slower than a pair of assignment statements, in part due to the strong memory ordering guaranteed by xchg(). Has that changed? If so, then, agreed, it might make sense to use xchg().

For the kfree_rcu() performance testing I was working on recently, replacing xchg() with a pair of assignment statements in the code being tested provided a great performance increase (on x86).

thanks,

- Joel

#8 lore raw

Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()

In reply to Steven Rostedt
Quoted 15 lines · ----- On Oct 3, 2019, at 9:08 AM, rostedt [email protected] wrote:
Quoted 11 lines · On Thu, 03 Oct 2019 09:39:17 +0100 David Howells <[email protected]> wrote:

include/linux/rcupdate.h do { \ · line 401

Quoted 6 lines · [email protected] wrote:
include/linux/rcupdate.h +6 -0
+#define rcu_replace(rcu_ptr, ptr, c)					\
+({									\
+	typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c));	\
+	rcu_assign_pointer((rcu_ptr), (ptr));				\
+	__tmp;								\
+})

Does it make sense to actually use xchg() if that's supported by the arch?

Quoted 4 lines

Hmm, is there really any arch that doesn't support xchg()? It would be very hard to do any kind of atomic operations without it.

cmpxchg() is the one that I understand is optional by the arch.

I remember going through all kernel arch headers myself and introduce irq-off-based xchg and cmpxchg generic implementations for all UP architectures lacking cmpxchg/xchg instructions.

We might want to consider simply using xchg() here.

FWIW, the API exposed by the Userspace RCU project (liburcu) for this is:

rcu_xchg_pointer()

Thanks,

Mathieu

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
#9 lore raw

Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()

Quoted 1 line · Mathieu Desnoyers

We might want to consider simply using xchg() here.

As stated elsewhere, xchg() is an atomic op with full ordering, IOW it is stupid expensive for what needs to be done.

#10 lore raw

Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()

In reply to [email protected]
Quoted 8 lines · ----- On Oct 2, 2019, at 9:43 PM, paulmck [email protected] wrote:

From: "Paul E. McKenney" <[email protected]>

Although the rcu_swap_protected() macro follows the example of swap(), the interactions with RCU make its update of its argument somewhat counter-intuitive. This commit therefore introduces an rcu_replace() that returns the old value of the RCU pointer instead of doing the argument update. Once all the uses of rcu_swap_protected() are updated to instead use rcu_replace(), rcu_swap_protected() will be removed.

We expose the rcu_xchg_pointer() API in liburcu (Userspace RCU) project. Any reason for not going that way and keep the kernel and user-space RCU APIs alike ?

It's of course fine if they diverge, but we might want to at least consider if using the same API name would be OK.

Thanks,

Mathieu

Quoted 46 lines

Link:
https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/

Cc Bart Van Assche <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
Cc Shane M Seymour <[email protected]>
Cc Martin K. Petersen <[email protected]>

---
include/linux/rcupdate.h | 18 ++++++++++++++++++

1 file changed, 18 insertions(+)
include/linux/rcupdate.h +18 -1
index 75a2ede..3b73287 100644
@@ -383,6 +383,24 @@ do {									      \
 } while (0)
 
 /**
+ * rcu_replace() - replace an RCU pointer, returning its old value
+ * @rcu_ptr: RCU pointer, whose old value is returned
+ * @ptr: regular pointer
+ * @c: the lockdep conditions under which the dereference will take place
+ *
+ * Perform a replacement, where @rcu_ptr is an RCU-annotated
+ * pointer and @c is the lockdep argument that is passed to the
+ * rcu_dereference_protected() call used to read that pointer.  The old
+ * value of @rcu_ptr is returned, and @rcu_ptr is set to @ptr.
+ */
+#define rcu_replace(rcu_ptr, ptr, c)					\
+({									\
+	typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c));	\
+	rcu_assign_pointer((rcu_ptr), (ptr));				\
+	__tmp;								\
+})
+
+/**
 * rcu_swap_protected() - swap an RCU and a regular pointer
 * @rcu_ptr: RCU pointer
 * @ptr: regular pointer
--

2.9.5

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
author maintainer
#11 lore raw

Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()

Quoted 11 lines · Mathieu Desnoyers
Quoted 8 lines · ----- On Oct 2, 2019, at 9:43 PM, paulmck [email protected] wrote:

From: "Paul E. McKenney" <[email protected]>

Although the rcu_swap_protected() macro follows the example of swap(), the interactions with RCU make its update of its argument somewhat counter-intuitive. This commit therefore introduces an rcu_replace() that returns the old value of the RCU pointer instead of doing the argument update. Once all the uses of rcu_swap_protected() are updated to instead use rcu_replace(), rcu_swap_protected() will be removed.

Quoted 6 lines

We expose the rcu_xchg_pointer() API in liburcu (Userspace RCU) project. Any reason for not going that way and keep the kernel and user-space RCU APIs alike ?

It's of course fine if they diverge, but we might want to at least consider if using the same API name would be OK.

Different semantics. An rcu_xchg_pointer() allows concurrent updates, and rcu_replace() does not.

But yes, if someone needs the concurrent updates, rcu_xchg_pointer() would certainly be my choice for the name.

Thanx, Paul

Quoted 56 lines

Thanks,

Mathieu

Quoted 46 lines

Link:
https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/

Cc Bart Van Assche <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
Cc Shane M Seymour <[email protected]>
Cc Martin K. Petersen <[email protected]>

---
include/linux/rcupdate.h | 18 ++++++++++++++++++

1 file changed, 18 insertions(+)
include/linux/rcupdate.h +18 -1
index 75a2ede..3b73287 100644
@@ -383,6 +383,24 @@ do {									      \
 } while (0)
 
 /**
+ * rcu_replace() - replace an RCU pointer, returning its old value
+ * @rcu_ptr: RCU pointer, whose old value is returned
+ * @ptr: regular pointer
+ * @c: the lockdep conditions under which the dereference will take place
+ *
+ * Perform a replacement, where @rcu_ptr is an RCU-annotated
+ * pointer and @c is the lockdep argument that is passed to the
+ * rcu_dereference_protected() call used to read that pointer.  The old
+ * value of @rcu_ptr is returned, and @rcu_ptr is set to @ptr.
+ */
+#define rcu_replace(rcu_ptr, ptr, c)					\
+({									\
+	typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c));	\
+	rcu_assign_pointer((rcu_ptr), (ptr));				\
+	__tmp;								\
+})
+
+/**
 * rcu_swap_protected() - swap an RCU and a regular pointer
 * @rcu_ptr: RCU pointer
 * @ptr: regular pointer
--

2.9.5

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
#12 lore raw

Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()

Quoted 16 lines · ----- On Oct 3, 2019, at 12:52 PM, paulmck [email protected] wrote:
Quoted 15 lines · Mathieu Desnoyers
Quoted 8 lines · ----- On Oct 2, 2019, at 9:43 PM, paulmck [email protected] wrote:

From: "Paul E. McKenney" <[email protected]>

Although the rcu_swap_protected() macro follows the example of swap(), the interactions with RCU make its update of its argument somewhat counter-intuitive. This commit therefore introduces an rcu_replace() that returns the old value of the RCU pointer instead of doing the argument update. Once all the uses of rcu_swap_protected() are updated to instead use rcu_replace(), rcu_swap_protected() will be removed.

We expose the rcu_xchg_pointer() API in liburcu (Userspace RCU) project. Any reason for not going that way and keep the kernel and user-space RCU APIs alike ?

Quoted 8 lines
Quoted 2 lines

It's of course fine if they diverge, but we might want to at least consider if using the same API name would be OK.

Different semantics. An rcu_xchg_pointer() allows concurrent updates, and rcu_replace() does not.

But yes, if someone needs the concurrent updates, rcu_xchg_pointer() would certainly be my choice for the name.

Then considering that its assignment counterpart is "rcu_assign_pointer()" (and not "rcu_assign()"), would "rcu_replace_pointer()" be less ambiguous about its intended use ?

Thanks,

Mathieu

Quoted 59 lines

Thanx, Paul

Quoted 56 lines

Thanks,

Mathieu

Quoted 45 lines

Link:
https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/

Cc Bart Van Assche <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
Cc Shane M Seymour <[email protected]>
Cc Martin K. Petersen <[email protected]>

---
include/linux/rcupdate.h | 18 ++++++++++++++++++

1 file changed, 18 insertions(+)
include/linux/rcupdate.h +18 -1
index 75a2ede..3b73287 100644
@@ -383,6 +383,24 @@ do {									      \
 } while (0)
 
 /**
+ * rcu_replace() - replace an RCU pointer, returning its old value
+ * @rcu_ptr: RCU pointer, whose old value is returned
+ * @ptr: regular pointer
+ * @c: the lockdep conditions under which the dereference will take place
+ *
+ * Perform a replacement, where @rcu_ptr is an RCU-annotated
+ * pointer and @c is the lockdep argument that is passed to the
+ * rcu_dereference_protected() call used to read that pointer.  The old
+ * value of @rcu_ptr is returned, and @rcu_ptr is set to @ptr.
+ */
+#define rcu_replace(rcu_ptr, ptr, c)					\
+({									\
+	typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c));	\
+	rcu_assign_pointer((rcu_ptr), (ptr));				\
+	__tmp;								\
+})
+
+/**
 * rcu_swap_protected() - swap an RCU and a regular pointer
 * @rcu_ptr: RCU pointer
 * @ptr: regular pointer
--
Quoted 1 line

2.9.5

--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
author maintainer
#13 lore raw

Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()

Quoted 24 lines · Mathieu Desnoyers
Quoted 22 lines · ----- On Oct 3, 2019, at 12:52 PM, paulmck [email protected] wrote:
Quoted 11 lines · Mathieu Desnoyers
Quoted 8 lines · ----- On Oct 2, 2019, at 9:43 PM, paulmck [email protected] wrote:

From: "Paul E. McKenney" <[email protected]>

Although the rcu_swap_protected() macro follows the example of swap(), the interactions with RCU make its update of its argument somewhat counter-intuitive. This commit therefore introduces an rcu_replace() that returns the old value of the RCU pointer instead of doing the argument update. Once all the uses of rcu_swap_protected() are updated to instead use rcu_replace(), rcu_swap_protected() will be removed.

Quoted 6 lines

We expose the rcu_xchg_pointer() API in liburcu (Userspace RCU) project. Any reason for not going that way and keep the kernel and user-space RCU APIs alike ?

It's of course fine if they diverge, but we might want to at least consider if using the same API name would be OK.

Different semantics. An rcu_xchg_pointer() allows concurrent updates, and rcu_replace() does not.

Quoted 6 lines
Quoted 2 lines

But yes, if someone needs the concurrent updates, rcu_xchg_pointer() would certainly be my choice for the name.

Then considering that its assignment counterpart is "rcu_assign_pointer()" (and not "rcu_assign()"), would "rcu_replace_pointer()" be less ambiguous about its intended use ?

The sequence was rcu_swap_protected() -> rcu_swap() -> rcu_replace(). Because that rcu_replace(), unlike rcu_swap_protected(), returns a value, the shorter name is valuable.

Maybe we should have used rcu_assign() instead of rcu_assign_pointer(), but there is no point in that sort of change at this late date!

Thanx, Paul

Quoted 69 lines

Thanks,

Mathieu

Quoted 59 lines

Thanx, Paul

Quoted 56 lines

Thanks,

Mathieu

Quoted 45 lines

Link:
https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/

Cc Bart Van Assche <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
Cc Shane M Seymour <[email protected]>
Cc Martin K. Petersen <[email protected]>

---
include/linux/rcupdate.h | 18 ++++++++++++++++++

1 file changed, 18 insertions(+)
include/linux/rcupdate.h +18 -1
index 75a2ede..3b73287 100644
@@ -383,6 +383,24 @@ do {									      \
 } while (0)
 
 /**
+ * rcu_replace() - replace an RCU pointer, returning its old value
+ * @rcu_ptr: RCU pointer, whose old value is returned
+ * @ptr: regular pointer
+ * @c: the lockdep conditions under which the dereference will take place
+ *
+ * Perform a replacement, where @rcu_ptr is an RCU-annotated
+ * pointer and @c is the lockdep argument that is passed to the
+ * rcu_dereference_protected() call used to read that pointer.  The old
+ * value of @rcu_ptr is returned, and @rcu_ptr is set to @ptr.
+ */
+#define rcu_replace(rcu_ptr, ptr, c)					\
+({									\
+	typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c));	\
+	rcu_assign_pointer((rcu_ptr), (ptr));				\
+	__tmp;								\
+})
+
+/**
 * rcu_swap_protected() - swap an RCU and a regular pointer
 * @rcu_ptr: RCU pointer
 * @ptr: regular pointer
--
Quoted 1 line

2.9.5

--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
#14 lore raw

Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()

Quoted 32 lines · ----- On Oct 3, 2019, at 3:09 PM, paulmck [email protected] wrote:
Quoted 24 lines · Mathieu Desnoyers
Quoted 22 lines · ----- On Oct 3, 2019, at 12:52 PM, paulmck [email protected] wrote:
Quoted 11 lines · Mathieu Desnoyers
Quoted 8 lines · ----- On Oct 2, 2019, at 9:43 PM, paulmck [email protected] wrote:

From: "Paul E. McKenney" <[email protected]>

Although the rcu_swap_protected() macro follows the example of swap(), the interactions with RCU make its update of its argument somewhat counter-intuitive. This commit therefore introduces an rcu_replace() that returns the old value of the RCU pointer instead of doing the argument update. Once all the uses of rcu_swap_protected() are updated to instead use rcu_replace(), rcu_swap_protected() will be removed.

Quoted 6 lines

We expose the rcu_xchg_pointer() API in liburcu (Userspace RCU) project. Any reason for not going that way and keep the kernel and user-space RCU APIs alike ?

It's of course fine if they diverge, but we might want to at least consider if using the same API name would be OK.

Different semantics. An rcu_xchg_pointer() allows concurrent updates, and rcu_replace() does not.

Quoted 6 lines
Quoted 2 lines

But yes, if someone needs the concurrent updates, rcu_xchg_pointer() would certainly be my choice for the name.

Then considering that its assignment counterpart is "rcu_assign_pointer()" (and not "rcu_assign()"), would "rcu_replace_pointer()" be less ambiguous about its intended use ?

Quoted 6 lines

The sequence was rcu_swap_protected() -> rcu_swap() -> rcu_replace(). Because that rcu_replace(), unlike rcu_swap_protected(), returns a value, the shorter name is valuable.

Maybe we should have used rcu_assign() instead of rcu_assign_pointer(), but there is no point in that sort of change at this late date!

I agree that having both the "rcu_" prefix and the "_pointer" suffix is somewhat redundant. Indeed it's not a worthwhile change for a pre-existing API, but it is welcome for a new API.

Thanks!

Mathieu

Quoted 72 lines

Thanx, Paul

Quoted 69 lines

Thanks,

Mathieu

Quoted 59 lines

Thanx, Paul

Quoted 56 lines

Thanks,

Mathieu

Quoted 45 lines

Link:
https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/

Cc Bart Van Assche <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
Cc Shane M Seymour <[email protected]>
Cc Martin K. Petersen <[email protected]>

---
include/linux/rcupdate.h | 18 ++++++++++++++++++

1 file changed, 18 insertions(+)
include/linux/rcupdate.h +18 -1
index 75a2ede..3b73287 100644
@@ -383,6 +383,24 @@ do {									      \
 } while (0)
 
 /**
+ * rcu_replace() - replace an RCU pointer, returning its old value
+ * @rcu_ptr: RCU pointer, whose old value is returned
+ * @ptr: regular pointer
+ * @c: the lockdep conditions under which the dereference will take place
+ *
+ * Perform a replacement, where @rcu_ptr is an RCU-annotated
+ * pointer and @c is the lockdep argument that is passed to the
+ * rcu_dereference_protected() call used to read that pointer.  The old
+ * value of @rcu_ptr is returned, and @rcu_ptr is set to @ptr.
+ */
+#define rcu_replace(rcu_ptr, ptr, c)					\
+({									\
+	typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c));	\
+	rcu_assign_pointer((rcu_ptr), (ptr));				\
+	__tmp;								\
+})
+
+/**
 * rcu_swap_protected() - swap an RCU and a regular pointer
 * @rcu_ptr: RCU pointer
 * @ptr: regular pointer
--
Quoted 1 line

2.9.5

--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
author maintainer
#15 lore raw

PATCH 2/9 x86/kvm/pmu: Replace rcu_swap_protected() with rcu_replace()

In reply to Paul E. McKenney

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

---
 arch/x86/kvm/pmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/pmu.c +2 -2
index 46875bb..4c37266 100644
@@ -416,8 +416,8 @@ int kvm_vm_ioctl_set_pmu_event_filter(struct kvm *kvm, void __user *argp)
 	*filter = tmp;
 
 	mutex_lock(&kvm->lock);
-	rcu_swap_protected(kvm->arch.pmu_event_filter, filter,
-			   mutex_is_locked(&kvm->lock));
+	filter = rcu_replace(kvm->arch.pmu_event_filter, filter,
+			     mutex_is_locked(&kvm->lock));
 	mutex_unlock(&kvm->lock);
 
 	synchronize_srcu_expedited(&kvm->srcu);
Signature · 1 line
2.9.5
maintainer Acked-by on v1 2/9
#16 lore raw

Re: [PATCH tip/core/rcu 2/9] x86/kvm/pmu: Replace rcu_swap_protected() with rcu_replace()

Quoted 27 lines · On 03/10/19 03:43, [email protected] wrote:

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

---
 arch/x86/kvm/pmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/pmu.c +0 -0
index 46875bb..4c37266 100644

arch/x86/kvm/pmu.c int kvm_vm_ioctl_set_pmu_event_filter(struct kvm *kvm, void __user *argp) · line 423

Quoted 10 lines
arch/x86/kvm/pmu.c +2 -2
@@ -416,8 +416,8 @@ int kvm_vm_ioctl_set_pmu_event_filter(struct kvm *kvm, void __user *argp)
 	*filter = tmp;
 
 	mutex_lock(&kvm->lock);
-	rcu_swap_protected(kvm->arch.pmu_event_filter, filter,
-			   mutex_is_locked(&kvm->lock));
+	filter = rcu_replace(kvm->arch.pmu_event_filter, filter,
+			     mutex_is_locked(&kvm->lock));
 	mutex_unlock(&kvm->lock);
 
 	synchronize_srcu_expedited(&kvm->srcu);

Should go without saying, but

Paolo

author maintainer Applied
#17 lore raw

Re: [PATCH tip/core/rcu 2/9] x86/kvm/pmu: Replace rcu_swap_protected() with rcu_replace()

Quoted 36 lines · Paolo Bonzini
Quoted 35 lines · On 03/10/19 03:43, [email protected] wrote:

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

---
 arch/x86/kvm/pmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/pmu.c +2 -2
index 46875bb..4c37266 100644
@@ -416,8 +416,8 @@ int kvm_vm_ioctl_set_pmu_event_filter(struct kvm *kvm, void __user *argp)
 	*filter = tmp;
 
 	mutex_lock(&kvm->lock);
-	rcu_swap_protected(kvm->arch.pmu_event_filter, filter,
-			   mutex_is_locked(&kvm->lock));
+	filter = rcu_replace(kvm->arch.pmu_event_filter, filter,
+			     mutex_is_locked(&kvm->lock));
 	mutex_unlock(&kvm->lock);
 
Quoted 6 lines

arch/x86/kvm/pmu.c int kvm_vm_ioctl_set_pmu_event_filter(struct kvm *kvm, void __user *argp) · line 423

Quoted 2 lines
arch/x86/kvm/pmu.c +0 -0
 	synchronize_srcu_expedited(&kvm->srcu);

Should go without saying, but

It never goes without saying! ;-)

Applied, thank you!

Thanx, Paul

author maintainer
#18 lore raw

PATCH 3/9 drivers/gpu: Replace rcu_swap_protected() with rcu_replace()

In reply to Paul E. McKenney

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

---
 drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +1 -1
index 1cdfe05..c5c22c4 100644
@@ -1629,7 +1629,7 @@ set_engines(struct i915_gem_context *ctx,
 		i915_gem_context_set_user_engines(ctx);
 	else
 		i915_gem_context_clear_user_engines(ctx);
-	rcu_swap_protected(ctx->engines, set.engines, 1);
+	set.engines = rcu_replace(ctx->engines, set.engines, 1);
 	mutex_unlock(&ctx->engines_mutex);
 
 	call_rcu(&set.engines->rcu, free_engines_rcu);
Signature · 1 line
2.9.5
author maintainer
#19 lore raw

PATCH 4/9 drivers/scsi: Replace rcu_swap_protected() with rcu_replace()

In reply to Paul E. McKenney

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

---
 drivers/scsi/scsi.c       | 4 ++--
 drivers/scsi/scsi_sysfs.c | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/scsi/scsi.c +2 -2
index 1f5b5c8..6a38d4a 100644
@@ -434,8 +434,8 @@ static void scsi_update_vpd_page(struct scsi_device *sdev, u8 page,
 		return;
 
 	mutex_lock(&sdev->inquiry_mutex);
-	rcu_swap_protected(*sdev_vpd_buf, vpd_buf,
-			   lockdep_is_held(&sdev->inquiry_mutex));
+	vpd_buf = rcu_replace(*sdev_vpd_buf, vpd_buf,
+			      lockdep_is_held(&sdev->inquiry_mutex));
 	mutex_unlock(&sdev->inquiry_mutex);
 
 	if (vpd_buf)
drivers/scsi/scsi_sysfs.c +4 -4
index 64c96c7..8d17779 100644
@@ -466,10 +466,10 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
 	sdev->request_queue = NULL;
 
 	mutex_lock(&sdev->inquiry_mutex);
-	rcu_swap_protected(sdev->vpd_pg80, vpd_pg80,
-			   lockdep_is_held(&sdev->inquiry_mutex));
-	rcu_swap_protected(sdev->vpd_pg83, vpd_pg83,
-			   lockdep_is_held(&sdev->inquiry_mutex));
+	vpd_pg80 = rcu_replace(sdev->vpd_pg80, vpd_pg80,
+			       lockdep_is_held(&sdev->inquiry_mutex));
+	vpd_pg83 = rcu_replace(sdev->vpd_pg83, vpd_pg83,
+			       lockdep_is_held(&sdev->inquiry_mutex));
 	mutex_unlock(&sdev->inquiry_mutex);
 
 	if (vpd_pg83)
Signature · 1 line
2.9.5
#20 lore raw

Re: [PATCH tip/core/rcu 4/9] drivers/scsi: Replace rcu_swap_protected() with rcu_replace()

Paul,

No objections from me.

drivers/scsi/scsi_sysfs.c static void scsi_device_dev_release_usercontext(struct work_struct *work) · line 472

Quoted 4 lines
drivers/scsi/scsi_sysfs.c +4 -0
+	vpd_pg80 = rcu_replace(sdev->vpd_pg80, vpd_pg80,
+			       lockdep_is_held(&sdev->inquiry_mutex));
+	vpd_pg83 = rcu_replace(sdev->vpd_pg83, vpd_pg83,
+			       lockdep_is_held(&sdev->inquiry_mutex));

Just a heads-up that we have added a couple of additional VPD pages so my 5.5 tree will need additional calls to be updated to rcu_replace().

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
author maintainer
#21 lore raw

Re: [PATCH tip/core/rcu 4/9] drivers/scsi: Replace rcu_swap_protected() with rcu_replace()

Quoted 4 lines · Martin K. Petersen

Paul,

No objections from me.

Thank you, Martin! I have applied your Acked-by, but please let me know if that over-interprets your "No objections" above.

Quoted 7 lines

drivers/scsi/scsi_sysfs.c static void scsi_device_dev_release_usercontext(struct work_struct *work) · line 472

Quoted 4 lines
drivers/scsi/scsi_sysfs.c +4 -0
+	vpd_pg80 = rcu_replace(sdev->vpd_pg80, vpd_pg80,
+			       lockdep_is_held(&sdev->inquiry_mutex));
+	vpd_pg83 = rcu_replace(sdev->vpd_pg83, vpd_pg83,
+			       lockdep_is_held(&sdev->inquiry_mutex));

Just a heads-up that we have added a couple of additional VPD pages so my 5.5 tree will need additional calls to be updated to rcu_replace().

I do not intend to actually remove rcu_swap_protected() until 5.6 for exactly this sort of thing. My plan is to take another pass through the tree after 5.5 comes out, and these will be caught at that time.

Does that work for you?

Thanx, Paul

#22 lore raw

Re: [PATCH tip/core/rcu 4/9] drivers/scsi: Replace rcu_swap_protected() with rcu_replace()

Paul,

Quoted 5 lines

I do not intend to actually remove rcu_swap_protected() until 5.6 for exactly this sort of thing. My plan is to take another pass through the tree after 5.5 comes out, and these will be caught at that time.

Does that work for you?

Yep, that's great. Thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
author maintainer
#23 lore raw

PATCH 5/9 fs/afs: Replace rcu_swap_protected() with rcu_replace()

In reply to Paul E. McKenney

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

---
 fs/afs/vl_list.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/afs/vl_list.c +2 -2
index 21eb0c0..e594598 100644
@@ -279,8 +279,8 @@ struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *cell,
 			struct afs_addr_list *old = addrs;
 
 			write_lock(&server->lock);
-			rcu_swap_protected(server->addresses, old,
-					   lockdep_is_held(&server->lock));
+			old = rcu_replace(server->addresses, old,
+					  lockdep_is_held(&server->lock));
 			write_unlock(&server->lock);
 			afs_put_addrlist(old);
 		}
Signature · 1 line
2.9.5
maintainer Acked-by on v1 5/9
#24 lore raw

Re: [PATCH tip/core/rcu 5/9] fs/afs: Replace rcu_swap_protected() with rcu_replace()

Quoted 3 lines · [email protected] wrote:

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

Yay!

Quoted 6 lines
author maintainer Applied
#25 lore raw

Re: [PATCH tip/core/rcu 5/9] fs/afs: Replace rcu_swap_protected() with rcu_replace()

Quoted 8 lines · David Howells
Quoted 3 lines · [email protected] wrote:

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

Yay!

Quoted 8 lines
Quoted 6 lines

Applied, thank you David!

Thanx, Paul

author maintainer
#26 lore raw

PATCH 6/9 bpf/cgroup: Replace rcu_swap_protected() with rcu_replace()

In reply to Paul E. McKenney

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

---
 kernel/bpf/cgroup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/bpf/cgroup.c +2 -2
index ddd8add..06a0657 100644
@@ -180,8 +180,8 @@ static void activate_effective_progs(struct cgroup *cgrp,
 				     enum bpf_attach_type type,
 				     struct bpf_prog_array *old_array)
 {
-	rcu_swap_protected(cgrp->bpf.effective[type], old_array,
-			   lockdep_is_held(&cgroup_mutex));
+	old_array = rcu_replace(cgrp->bpf.effective[type], old_array,
+				lockdep_is_held(&cgroup_mutex));
 	/* free prog array after grace period, since __cgroup_bpf_run_*()
 	 * might be still walking the array
 	 */
Signature · 1 line
2.9.5
Acked-by on v1 6/9
#27 lore raw

Re: [PATCH tip/core/rcu 6/9] bpf/cgroup: Replace rcu_swap_protected() with rcu_replace()

Quoted 17 lines · On Wed, Oct 2, 2019 at 6:45 PM <[email protected]> wrote:

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

Quoted 1 line

---

Quoted 21 lines
 kernel/bpf/cgroup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/bpf/cgroup.c +2 -3
index ddd8add..06a0657 100644
@@ -180,8 +180,8 @@ static void activate_effective_progs(struct cgroup *cgrp,
                                     enum bpf_attach_type type,
                                     struct bpf_prog_array *old_array)
 {
-       rcu_swap_protected(cgrp->bpf.effective[type], old_array,
-                          lockdep_is_held(&cgroup_mutex));
+       old_array = rcu_replace(cgrp->bpf.effective[type], old_array,
+                               lockdep_is_held(&cgroup_mutex));
        /* free prog array after grace period, since __cgroup_bpf_run_*()
         * might be still walking the array
         */
--

2.9.5

Acked-by
#28 lore raw

Re: [PATCH tip/core/rcu 6/9] bpf/cgroup: Replace rcu_swap_protected() with rcu_replace()

Quoted 21 lines · Andrii Nakryiko
Quoted 17 lines · On Wed, Oct 2, 2019 at 6:45 PM <[email protected]> wrote:

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

Quoted 1 line

---

Quoted 1 line
author maintainer Applied
#29 lore raw

Re: [PATCH tip/core/rcu 6/9] bpf/cgroup: Replace rcu_swap_protected() with rcu_replace()

Quoted 23 lines · Song Liu
Quoted 21 lines · Andrii Nakryiko
Quoted 18 lines · On Wed, Oct 2, 2019 at 6:45 PM <[email protected]> wrote:

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

---

Quoted 3 lines
Quoted 1 line

Applied, thank you both!

Thanx, Paul

author maintainer
#30 lore raw

PATCH 7/9 net/core: Replace rcu_swap_protected() with rcu_replace()

In reply to Paul E. McKenney

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

---
 net/core/dev.c            | 4 ++--
 net/core/sock_reuseport.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
net/core/dev.c +2 -2
index bf3ed41..41f6936 100644
@@ -1288,8 +1288,8 @@ int dev_set_alias(struct net_device *dev, const char *alias, size_t len)
 	}
 
 	mutex_lock(&ifalias_mutex);
-	rcu_swap_protected(dev->ifalias, new_alias,
-			   mutex_is_locked(&ifalias_mutex));
+	new_alias = rcu_replace(dev->ifalias, new_alias,
+				mutex_is_locked(&ifalias_mutex));
 	mutex_unlock(&ifalias_mutex);
 
 	if (new_alias)
net/core/sock_reuseport.c +2 -2
index f3ceec9..805287b 100644
@@ -356,8 +356,8 @@ int reuseport_detach_prog(struct sock *sk)
 	spin_lock_bh(&reuseport_lock);
 	reuse = rcu_dereference_protected(sk->sk_reuseport_cb,
 					  lockdep_is_held(&reuseport_lock));
-	rcu_swap_protected(reuse->prog, old_prog,
-			   lockdep_is_held(&reuseport_lock));
+	old_prog = rcu_replace(reuse->prog, old_prog,
+			       lockdep_is_held(&reuseport_lock));
 	spin_unlock_bh(&reuseport_lock);
 
 	if (!old_prog)
Signature · 1 line
2.9.5
author maintainer
#31 lore raw

PATCH 8/9 net/netfilter: Replace rcu_swap_protected() with rcu_replace()

In reply to Paul E. McKenney

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

---
 net/netfilter/nf_tables_api.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +3 -2
index d481f9b..8499baf 100644
@@ -1461,8 +1461,9 @@ static void nft_chain_stats_replace(struct nft_trans *trans)
 	if (!nft_trans_chain_stats(trans))
 		return;
 
-	rcu_swap_protected(chain->stats, nft_trans_chain_stats(trans),
-			   lockdep_commit_lock_is_held(trans->ctx.net));
+	nft_trans_chain_stats(trans) =
+		rcu_replace(chain->stats, nft_trans_chain_stats(trans),
+			    lockdep_commit_lock_is_held(trans->ctx.net));
 
 	if (!nft_trans_chain_stats(trans))
 		static_branch_inc(&nft_counters_enabled);
Signature · 1 line
2.9.5
maintainer Acked-by on v1 8/9
#32 lore raw

Re: [PATCH tip/core/rcu 8/9] net/netfilter: Replace rcu_swap_protected() with rcu_replace()

Quoted 6 lines · On Wed, Oct 02, 2019 at 06:43:09PM -0700, [email protected] wrote:

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

Quoted 10 lines
Quoted 23 lines
---
 net/netfilter/nf_tables_api.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +3 -2
index d481f9b..8499baf 100644
@@ -1461,8 +1461,9 @@ static void nft_chain_stats_replace(struct nft_trans *trans)
 	if (!nft_trans_chain_stats(trans))
 		return;
 
-	rcu_swap_protected(chain->stats, nft_trans_chain_stats(trans),
-			   lockdep_commit_lock_is_held(trans->ctx.net));
+	nft_trans_chain_stats(trans) =
+		rcu_replace(chain->stats, nft_trans_chain_stats(trans),
+			    lockdep_commit_lock_is_held(trans->ctx.net));
 
 	if (!nft_trans_chain_stats(trans))
 		static_branch_inc(&nft_counters_enabled);
Signature · 1 line
2.9.5
author maintainer Applied
#33 lore raw

Re: [PATCH tip/core/rcu 8/9] net/netfilter: Replace rcu_swap_protected() with rcu_replace()

Quoted 18 lines · Pablo Neira Ayuso
Quoted 6 lines · On Wed, Oct 02, 2019 at 06:43:09PM -0700, [email protected] wrote:

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

Quoted 10 lines
Quoted 1 line

Applied, thank you!

Thanx, Paul

Quoted 23 lines
Quoted 23 lines
---
 net/netfilter/nf_tables_api.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +3 -2
index d481f9b..8499baf 100644
@@ -1461,8 +1461,9 @@ static void nft_chain_stats_replace(struct nft_trans *trans)
 	if (!nft_trans_chain_stats(trans))
 		return;
 
-	rcu_swap_protected(chain->stats, nft_trans_chain_stats(trans),
-			   lockdep_commit_lock_is_held(trans->ctx.net));
+	nft_trans_chain_stats(trans) =
+		rcu_replace(chain->stats, nft_trans_chain_stats(trans),
+			    lockdep_commit_lock_is_held(trans->ctx.net));
 
 	if (!nft_trans_chain_stats(trans))
 		static_branch_inc(&nft_counters_enabled);
Signature · 1 line
2.9.5
author maintainer
#34 lore raw

PATCH 9/9 net/sched: Replace rcu_swap_protected() with rcu_replace()

In reply to Paul E. McKenney

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

---
 net/sched/act_api.c        | 2 +-
 net/sched/act_csum.c       | 4 ++--
 net/sched/act_ct.c         | 2 +-
 net/sched/act_ctinfo.c     | 4 ++--
 net/sched/act_ife.c        | 2 +-
 net/sched/act_mirred.c     | 4 ++--
 net/sched/act_mpls.c       | 2 +-
 net/sched/act_police.c     | 6 +++---
 net/sched/act_skbedit.c    | 4 ++--
 net/sched/act_tunnel_key.c | 4 ++--
 net/sched/act_vlan.c       | 2 +-
 11 files changed, 18 insertions(+), 18 deletions(-)
net/sched/act_api.c +1 -1
index 2558f00..1ab810c 100644
@@ -88,7 +88,7 @@ struct tcf_chain *tcf_action_set_ctrlact(struct tc_action *a, int action,
 					 struct tcf_chain *goto_chain)
 {
 	a->tcfa_action = action;
-	rcu_swap_protected(a->goto_chain, goto_chain, 1);
+	goto_chain = rcu_replace(a->goto_chain, goto_chain, 1);
 	return goto_chain;
 }
 EXPORT_SYMBOL(tcf_action_set_ctrlact);
net/sched/act_csum.c +2 -2
index d3cfad8..ced5fe6 100644
@@ -101,8 +101,8 @@ static int tcf_csum_init(struct net *net, struct nlattr *nla,
 
 	spin_lock_bh(&p->tcf_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
-	rcu_swap_protected(p->params, params_new,
-			   lockdep_is_held(&p->tcf_lock));
+	params_new = rcu_replace(p->params, params_new,
+				 lockdep_is_held(&p->tcf_lock));
 	spin_unlock_bh(&p->tcf_lock);
 
 	if (goto_ch)
net/sched/act_ct.c +1 -1
index fcc4602..500e874 100644
@@ -722,7 +722,7 @@ static int tcf_ct_init(struct net *net, struct nlattr *nla,
 
 	spin_lock_bh(&c->tcf_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
-	rcu_swap_protected(c->params, params, lockdep_is_held(&c->tcf_lock));
+	params = rcu_replace(c->params, params, lockdep_is_held(&c->tcf_lock));
 	spin_unlock_bh(&c->tcf_lock);
 
 	if (goto_ch)
net/sched/act_ctinfo.c +2 -2
index 0dbcfd1..e6ea270 100644
@@ -257,8 +257,8 @@ static int tcf_ctinfo_init(struct net *net, struct nlattr *nla,
 
 	spin_lock_bh(&ci->tcf_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, actparm->action, goto_ch);
-	rcu_swap_protected(ci->params, cp_new,
-			   lockdep_is_held(&ci->tcf_lock));
+	cp_new = rcu_replace(ci->params, cp_new,
+			     lockdep_is_held(&ci->tcf_lock));
 	spin_unlock_bh(&ci->tcf_lock);
 
 	if (goto_ch)
net/sched/act_ife.c +1 -1
index 3a31e24..a6a60b8 100644
@@ -594,7 +594,7 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla,
 		spin_lock_bh(&ife->tcf_lock);
 	/* protected by tcf_lock when modifying existing action */
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
-	rcu_swap_protected(ife->params, p, 1);
+	p = rcu_replace(ife->params, p, 1);
 
 	if (exists)
 		spin_unlock_bh(&ife->tcf_lock);
net/sched/act_mirred.c +2 -2
index 9ce073a..1ed5d7e 100644
@@ -178,8 +178,8 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
 			goto put_chain;
 		}
 		mac_header_xmit = dev_is_mac_header_xmit(dev);
-		rcu_swap_protected(m->tcfm_dev, dev,
-				   lockdep_is_held(&m->tcf_lock));
+		dev = rcu_replace(m->tcfm_dev, dev,
+				  lockdep_is_held(&m->tcf_lock));
 		if (dev)
 			dev_put(dev);
 		m->tcfm_mac_header_xmit = mac_header_xmit;
net/sched/act_mpls.c +1 -1
index e168df0..cea8771 100644
@@ -258,7 +258,7 @@ static int tcf_mpls_init(struct net *net, struct nlattr *nla,
 
 	spin_lock_bh(&m->tcf_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
-	rcu_swap_protected(m->mpls_p, p, lockdep_is_held(&m->tcf_lock));
+	p = rcu_replace(m->mpls_p, p, lockdep_is_held(&m->tcf_lock));
 	spin_unlock_bh(&m->tcf_lock);
 
 	if (goto_ch)
net/sched/act_police.c +3 -3
index 89c04c5..02a4bc9c 100644
@@ -191,9 +191,9 @@ static int tcf_police_init(struct net *net, struct nlattr *nla,
 		police->tcfp_ptoks = new->tcfp_mtu_ptoks;
 	spin_unlock_bh(&police->tcfp_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
-	rcu_swap_protected(police->params,
-			   new,
-			   lockdep_is_held(&police->tcf_lock));
+	new = rcu_replace(police->params,
+			  new,
+			  lockdep_is_held(&police->tcf_lock));
 	spin_unlock_bh(&police->tcf_lock);
 
 	if (goto_ch)
net/sched/act_skbedit.c +2 -2
index 6a8d333..6c4bd47 100644
@@ -206,8 +206,8 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
 
 	spin_lock_bh(&d->tcf_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
-	rcu_swap_protected(d->params, params_new,
-			   lockdep_is_held(&d->tcf_lock));
+	params_new = rcu_replace(d->params, params_new,
+				 lockdep_is_held(&d->tcf_lock));
 	spin_unlock_bh(&d->tcf_lock);
 	if (params_new)
 		kfree_rcu(params_new, rcu);
net/sched/act_tunnel_key.c +2 -2
index 2f83a79..7130da8 100644
@@ -381,8 +381,8 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
 
 	spin_lock_bh(&t->tcf_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
-	rcu_swap_protected(t->params, params_new,
-			   lockdep_is_held(&t->tcf_lock));
+	params_new = rcu_replace(t->params, params_new,
+				 lockdep_is_held(&t->tcf_lock));
 	spin_unlock_bh(&t->tcf_lock);
 	tunnel_key_release_params(params_new);
 	if (goto_ch)
net/sched/act_vlan.c +1 -1
index 08aaf71..402c9ea 100644
@@ -220,7 +220,7 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla,
 
 	spin_lock_bh(&v->tcf_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
-	rcu_swap_protected(v->vlan_p, p, lockdep_is_held(&v->tcf_lock));
+	p = rcu_replace(v->vlan_p, p, lockdep_is_held(&v->tcf_lock));
 	spin_unlock_bh(&v->tcf_lock);
 
 	if (goto_ch)
Signature · 1 line
2.9.5
author maintainer
#35 lore raw

v2 cover Replace rcu_swap_protected() for v5.5

In reply to Paul E. McKenney

Hello!

This series replaces uses of rcu_swap_protected() with rcu_replace(). A later patch will remove rcu_swap_protected().

1. Upgrade rcu_swap_protected() to rcu_replace().

2-10. Replace calls to rcu_swap_protected() with rcu_replace().

Changes from v1:

o Added security/safesetid patch.

o Changed the name from rcu_replace() to rcu_replace_pointer()
based on feedback from Ingo Molnar.

Thanx, Paul

------------------------------------------------------------------------

 arch/x86/kvm/pmu.c                          |    4 ++--
 drivers/gpu/drm/i915/gem/i915_gem_context.c |    2 +-
 drivers/scsi/scsi.c                         |    4 ++--
 drivers/scsi/scsi_sysfs.c                   |    8 ++++----
 fs/afs/vl_list.c                            |    4 ++--
 include/linux/rcupdate.h                    |   18 ++++++++++++++++++
 kernel/bpf/cgroup.c                         |    4 ++--
 net/core/dev.c                              |    4 ++--
 net/core/sock_reuseport.c                   |    4 ++--
 net/netfilter/nf_tables_api.c               |    5 +++--
 net/sched/act_api.c                         |    2 +-
 net/sched/act_csum.c                        |    4 ++--
 net/sched/act_ct.c                          |    3 ++-
 net/sched/act_ctinfo.c                      |    4 ++--
 net/sched/act_ife.c                         |    2 +-
 net/sched/act_mirred.c                      |    4 ++--
 net/sched/act_mpls.c                        |    2 +-
 net/sched/act_police.c                      |    6 +++---
 net/sched/act_sample.c                      |    4 ++--
 net/sched/act_skbedit.c                     |    4 ++--
 net/sched/act_tunnel_key.c                  |    4 ++--
 net/sched/act_vlan.c                        |    2 +-
 security/safesetid/securityfs.c             |    4 ++--
 23 files changed, 61 insertions(+), 41 deletions(-)
author maintainer
#36 lore raw

PATCH v2 1/10 rcu: Upgrade rcu_swap_protected() to rcu_replace()

From: "Paul E. McKenney" <[email protected]>

Although the rcu_swap_protected() macro follows the example of swap(), the interactions with RCU make its update of its argument somewhat counter-intuitive. This commit therefore introduces an rcu_replace() that returns the old value of the RCU pointer instead of doing the argument update. Once all the uses of rcu_swap_protected() are updated to instead use rcu_replace(), rcu_swap_protected() will be removed.

[ paulmck: From rcu_replace() to rcu_replace_pointer() per Ingo Molnar. ]
Cc Bart Van Assche <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Hannes Reinecke <[email protected]>
Cc Johannes Thumshirn <[email protected]>
Cc Shane M Seymour <[email protected]>
Cc Martin K. Petersen <[email protected]>
---
 include/linux/rcupdate.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
include/linux/rcupdate.h +18 -0
index 75a2ede..185dd97 100644
@@ -383,6 +383,24 @@ do {									      \
 } while (0)
 
 /**
+ * rcu_replace_pointer() - replace an RCU pointer, returning its old value
+ * @rcu_ptr: RCU pointer, whose old value is returned
+ * @ptr: regular pointer
+ * @c: the lockdep conditions under which the dereference will take place
+ *
+ * Perform a replacement, where @rcu_ptr is an RCU-annotated
+ * pointer and @c is the lockdep argument that is passed to the
+ * rcu_dereference_protected() call used to read that pointer.  The old
+ * value of @rcu_ptr is returned, and @rcu_ptr is set to @ptr.
+ */
+#define rcu_replace_pointer(rcu_ptr, ptr, c)				\
+({									\
+	typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c));	\
+	rcu_assign_pointer((rcu_ptr), (ptr));				\
+	__tmp;								\
+})
+
+/**
  * rcu_swap_protected() - swap an RCU and a regular pointer
  * @rcu_ptr: RCU pointer
  * @ptr: regular pointer
Signature · 1 line
2.9.5
author maintainer
#37 lore raw

PATCH v2 2/10 x86/kvm/pmu: Replace rcu_swap_protected() with rcu_replace()

In reply to Paul E. McKenney

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

[ paulmck: From rcu_replace() to rcu_replace_pointer() per Ingo Molnar. ]
Cc "Radim Krčmář" <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/kvm/pmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/pmu.c +2 -2
index 46875bb..5ddb05a 100644
@@ -416,8 +416,8 @@ int kvm_vm_ioctl_set_pmu_event_filter(struct kvm *kvm, void __user *argp)
 	*filter = tmp;
 
 	mutex_lock(&kvm->lock);
-	rcu_swap_protected(kvm->arch.pmu_event_filter, filter,
-			   mutex_is_locked(&kvm->lock));
+	filter = rcu_replace_pointer(kvm->arch.pmu_event_filter, filter,
+				     mutex_is_locked(&kvm->lock));
 	mutex_unlock(&kvm->lock);
 
 	synchronize_srcu_expedited(&kvm->srcu);
Signature · 1 line
2.9.5
author maintainer
#38 lore raw

PATCH v2 3/10 drivers/gpu: Replace rcu_swap_protected() with rcu_replace()

In reply to Paul E. McKenney

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

[ paulmck: From rcu_replace() to rcu_replace_pointer() per Ingo Molnar. ]
Cc Jani Nikula <[email protected]>
Cc Joonas Lahtinen <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Chris Wilson <[email protected]>
Cc Tvrtko Ursulin <[email protected]>
---
 drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +1 -1
index 1cdfe05..3f3e803 100644
@@ -1629,7 +1629,7 @@ set_engines(struct i915_gem_context *ctx,
 		i915_gem_context_set_user_engines(ctx);
 	else
 		i915_gem_context_clear_user_engines(ctx);
-	rcu_swap_protected(ctx->engines, set.engines, 1);
+	set.engines = rcu_replace_pointer(ctx->engines, set.engines, 1);
 	mutex_unlock(&ctx->engines_mutex);
 
 	call_rcu(&set.engines->rcu, free_engines_rcu);
Signature · 6 lines
2.9.5

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer Reviewed-by on v2 3/10
#39 lore raw

Re: [PATCH tip/core/rcu 03/10] drivers/gpu: Replace rcu_swap_protected() with rcu_replace()

Quoting [email protected] (2019-10-22 22:12:08)

Quoted 6 lines

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

Quoted 13 lines
[ paulmck: From rcu_replace() to rcu_replace_pointer() per Ingo Molnar. ]
Cc Jani Nikula <[email protected]>
Cc Joonas Lahtinen <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Chris Wilson <[email protected]>
Cc Tvrtko Ursulin <[email protected]>

"drm/i915:" preferred as the subject prefix for increased specificity.

Let me know which tree you end up merging with.

Regards, Joonas

author maintainer Applied
#40 lore raw

Re: [PATCH tip/core/rcu 03/10] drivers/gpu: Replace rcu_swap_protected() with rcu_replace()

Quoted 21 lines · Joonas Lahtinen

Quoting [email protected] (2019-10-22 22:12:08)

Quoted 6 lines

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

Quoted 13 lines
[ paulmck: From rcu_replace() to rcu_replace_pointer() per Ingo Molnar. ]
Cc Jani Nikula <[email protected]>
Cc Joonas Lahtinen <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Chris Wilson <[email protected]>
Cc Tvrtko Ursulin <[email protected]>
Quoted 1 line

"drm/i915:" preferred as the subject prefix for increased specificity.

"drm/i915" it is!

Quoted 1 line

Let me know which tree you end up merging with.

I expect to be sending a pull request for inclusion into the -tip tree in a day or three.

Quoted 1 line

Applied, thank you!

Thanx, Paul

author maintainer
#41 lore raw

PATCH v2 4/10 drivers/scsi: Replace rcu_swap_protected() with rcu_replace()

In reply to Paul E. McKenney

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

---
 drivers/scsi/scsi.c       | 4 ++--
 drivers/scsi/scsi_sysfs.c | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/scsi/scsi.c +2 -2
index 1f5b5c8..7a1b6c7 100644
@@ -434,8 +434,8 @@ static void scsi_update_vpd_page(struct scsi_device *sdev, u8 page,
 		return;
 
 	mutex_lock(&sdev->inquiry_mutex);
-	rcu_swap_protected(*sdev_vpd_buf, vpd_buf,
-			   lockdep_is_held(&sdev->inquiry_mutex));
+	vpd_buf = rcu_replace_pointer(*sdev_vpd_buf, vpd_buf,
+				      lockdep_is_held(&sdev->inquiry_mutex));
 	mutex_unlock(&sdev->inquiry_mutex);
 
 	if (vpd_buf)
drivers/scsi/scsi_sysfs.c +4 -4
index 64c96c7..5adfcab 100644
@@ -466,10 +466,10 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
 	sdev->request_queue = NULL;
 
 	mutex_lock(&sdev->inquiry_mutex);
-	rcu_swap_protected(sdev->vpd_pg80, vpd_pg80,
-			   lockdep_is_held(&sdev->inquiry_mutex));
-	rcu_swap_protected(sdev->vpd_pg83, vpd_pg83,
-			   lockdep_is_held(&sdev->inquiry_mutex));
+	vpd_pg80 = rcu_replace_pointer(sdev->vpd_pg80, vpd_pg80,
+				       lockdep_is_held(&sdev->inquiry_mutex));
+	vpd_pg83 = rcu_replace_pointer(sdev->vpd_pg83, vpd_pg83,
+				       lockdep_is_held(&sdev->inquiry_mutex));
 	mutex_unlock(&sdev->inquiry_mutex);
 
 	if (vpd_pg83)
Signature · 1 line
2.9.5
author maintainer
#42 lore raw

PATCH v2 5/10 fs/afs: Replace rcu_swap_protected() with rcu_replace()

In reply to Paul E. McKenney

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

---
 fs/afs/vl_list.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/afs/vl_list.c +2 -2
index 21eb0c0..8fea54e 100644
@@ -279,8 +279,8 @@ struct afs_vlserver_list *afs_extract_vlserver_list(struct afs_cell *cell,
 			struct afs_addr_list *old = addrs;
 
 			write_lock(&server->lock);
-			rcu_swap_protected(server->addresses, old,
-					   lockdep_is_held(&server->lock));
+			old = rcu_replace_pointer(server->addresses, old,
+						  lockdep_is_held(&server->lock));
 			write_unlock(&server->lock);
 			afs_put_addrlist(old);
 		}
Signature · 1 line
2.9.5
author maintainer
#43 lore raw

PATCH v2 6/10 bpf/cgroup: Replace rcu_swap_protected() with rcu_replace()

In reply to Paul E. McKenney

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

---
 kernel/bpf/cgroup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/bpf/cgroup.c +2 -2
index ddd8add..c684cf4 100644
@@ -180,8 +180,8 @@ static void activate_effective_progs(struct cgroup *cgrp,
 				     enum bpf_attach_type type,
 				     struct bpf_prog_array *old_array)
 {
-	rcu_swap_protected(cgrp->bpf.effective[type], old_array,
-			   lockdep_is_held(&cgroup_mutex));
+	old_array = rcu_replace_pointer(cgrp->bpf.effective[type], old_array,
+					lockdep_is_held(&cgroup_mutex));
 	/* free prog array after grace period, since __cgroup_bpf_run_*()
 	 * might be still walking the array
 	 */
Signature · 1 line
2.9.5
author maintainer
#44 lore raw

PATCH v2 7/10 net/core: Replace rcu_swap_protected() with rcu_replace()

In reply to Paul E. McKenney

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

[ paulmck: From rcu_replace() to rcu_replace_pointer() per Ingo Molnar. ]
Cc "David S. Miller" <[email protected]>
Cc Jiri Pirko <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Ido Schimmel <[email protected]>
Cc Petr Machata <[email protected]>
Cc Paolo Abeni <[email protected]>
---
 net/core/dev.c            | 4 ++--
 net/core/sock_reuseport.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
net/core/dev.c +2 -2
index bf3ed41..c5d8882 100644
@@ -1288,8 +1288,8 @@ int dev_set_alias(struct net_device *dev, const char *alias, size_t len)
 	}
 
 	mutex_lock(&ifalias_mutex);
-	rcu_swap_protected(dev->ifalias, new_alias,
-			   mutex_is_locked(&ifalias_mutex));
+	new_alias = rcu_replace_pointer(dev->ifalias, new_alias,
+					mutex_is_locked(&ifalias_mutex));
 	mutex_unlock(&ifalias_mutex);
 
 	if (new_alias)
net/core/sock_reuseport.c +2 -2
index f3ceec9..f19f179 100644
@@ -356,8 +356,8 @@ int reuseport_detach_prog(struct sock *sk)
 	spin_lock_bh(&reuseport_lock);
 	reuse = rcu_dereference_protected(sk->sk_reuseport_cb,
 					  lockdep_is_held(&reuseport_lock));
-	rcu_swap_protected(reuse->prog, old_prog,
-			   lockdep_is_held(&reuseport_lock));
+	old_prog = rcu_replace_pointer(reuse->prog, old_prog,
+				       lockdep_is_held(&reuseport_lock));
 	spin_unlock_bh(&reuseport_lock);
 
 	if (!old_prog)
Signature · 1 line
2.9.5
author maintainer
#45 lore raw

PATCH v2 8/10 net/netfilter: Replace rcu_swap_protected() with rcu_replace()

In reply to Paul E. McKenney

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

---
 net/netfilter/nf_tables_api.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +3 -2
index d481f9b..3379974 100644
@@ -1461,8 +1461,9 @@ static void nft_chain_stats_replace(struct nft_trans *trans)
 	if (!nft_trans_chain_stats(trans))
 		return;
 
-	rcu_swap_protected(chain->stats, nft_trans_chain_stats(trans),
-			   lockdep_commit_lock_is_held(trans->ctx.net));
+	nft_trans_chain_stats(trans) =
+		rcu_replace_pointer(chain->stats, nft_trans_chain_stats(trans),
+				    lockdep_commit_lock_is_held(trans->ctx.net));
 
 	if (!nft_trans_chain_stats(trans))
 		static_branch_inc(&nft_counters_enabled);
Signature · 1 line
2.9.5
author maintainer
#46 lore raw

PATCH v2 9/10 net/sched: Replace rcu_swap_protected() with rcu_replace()

In reply to Paul E. McKenney

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

[ paulmck: From rcu_replace() to rcu_replace_pointer() per Ingo Molnar. ]
Cc Jamal Hadi Salim <[email protected]>
Cc Cong Wang <[email protected]>
Cc Jiri Pirko <[email protected]>
Cc "David S. Miller" <[email protected]>
---
 net/sched/act_api.c        | 2 +-
 net/sched/act_csum.c       | 4 ++--
 net/sched/act_ct.c         | 3 ++-
 net/sched/act_ctinfo.c     | 4 ++--
 net/sched/act_ife.c        | 2 +-
 net/sched/act_mirred.c     | 4 ++--
 net/sched/act_mpls.c       | 2 +-
 net/sched/act_police.c     | 6 +++---
 net/sched/act_sample.c     | 4 ++--
 net/sched/act_skbedit.c    | 4 ++--
 net/sched/act_tunnel_key.c | 4 ++--
 net/sched/act_vlan.c       | 2 +-
 12 files changed, 21 insertions(+), 20 deletions(-)
net/sched/act_api.c +1 -1
index 2558f00..3d51573 100644
@@ -88,7 +88,7 @@ struct tcf_chain *tcf_action_set_ctrlact(struct tc_action *a, int action,
 					 struct tcf_chain *goto_chain)
 {
 	a->tcfa_action = action;
-	rcu_swap_protected(a->goto_chain, goto_chain, 1);
+	goto_chain = rcu_replace_pointer(a->goto_chain, goto_chain, 1);
 	return goto_chain;
 }
 EXPORT_SYMBOL(tcf_action_set_ctrlact);
net/sched/act_csum.c +2 -2
index d3cfad8..87dddba 100644
@@ -101,8 +101,8 @@ static int tcf_csum_init(struct net *net, struct nlattr *nla,
 
 	spin_lock_bh(&p->tcf_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
-	rcu_swap_protected(p->params, params_new,
-			   lockdep_is_held(&p->tcf_lock));
+	params_new = rcu_replace_pointer(p->params, params_new,
+					 lockdep_is_held(&p->tcf_lock));
 	spin_unlock_bh(&p->tcf_lock);
 
 	if (goto_ch)
net/sched/act_ct.c +2 -1
index fcc4602..2d5ab23 100644
@@ -722,7 +722,8 @@ static int tcf_ct_init(struct net *net, struct nlattr *nla,
 
 	spin_lock_bh(&c->tcf_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
-	rcu_swap_protected(c->params, params, lockdep_is_held(&c->tcf_lock));
+	params = rcu_replace_pointer(c->params, params,
+				     lockdep_is_held(&c->tcf_lock));
 	spin_unlock_bh(&c->tcf_lock);
 
 	if (goto_ch)
net/sched/act_ctinfo.c +2 -2
index 0dbcfd1..c599818 100644
@@ -257,8 +257,8 @@ static int tcf_ctinfo_init(struct net *net, struct nlattr *nla,
 
 	spin_lock_bh(&ci->tcf_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, actparm->action, goto_ch);
-	rcu_swap_protected(ci->params, cp_new,
-			   lockdep_is_held(&ci->tcf_lock));
+	cp_new = rcu_replace_pointer(ci->params, cp_new,
+				     lockdep_is_held(&ci->tcf_lock));
 	spin_unlock_bh(&ci->tcf_lock);
 
 	if (goto_ch)
net/sched/act_ife.c +1 -1
index 3a31e24..2ea2e16 100644
@@ -594,7 +594,7 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla,
 		spin_lock_bh(&ife->tcf_lock);
 	/* protected by tcf_lock when modifying existing action */
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
-	rcu_swap_protected(ife->params, p, 1);
+	p = rcu_replace_pointer(ife->params, p, 1);
 
 	if (exists)
 		spin_unlock_bh(&ife->tcf_lock);
net/sched/act_mirred.c +2 -2
index 9ce073a..0c2f737 100644
@@ -178,8 +178,8 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
 			goto put_chain;
 		}
 		mac_header_xmit = dev_is_mac_header_xmit(dev);
-		rcu_swap_protected(m->tcfm_dev, dev,
-				   lockdep_is_held(&m->tcf_lock));
+		dev = rcu_replace_pointer(m->tcfm_dev, dev,
+					  lockdep_is_held(&m->tcf_lock));
 		if (dev)
 			dev_put(dev);
 		m->tcfm_mac_header_xmit = mac_header_xmit;
net/sched/act_mpls.c +1 -1
index e168df0..5b3031c 100644
@@ -258,7 +258,7 @@ static int tcf_mpls_init(struct net *net, struct nlattr *nla,
 
 	spin_lock_bh(&m->tcf_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
-	rcu_swap_protected(m->mpls_p, p, lockdep_is_held(&m->tcf_lock));
+	p = rcu_replace_pointer(m->mpls_p, p, lockdep_is_held(&m->tcf_lock));
 	spin_unlock_bh(&m->tcf_lock);
 
 	if (goto_ch)
net/sched/act_police.c +3 -3
index 89c04c5..caa91cf 100644
@@ -191,9 +191,9 @@ static int tcf_police_init(struct net *net, struct nlattr *nla,
 		police->tcfp_ptoks = new->tcfp_mtu_ptoks;
 	spin_unlock_bh(&police->tcfp_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
-	rcu_swap_protected(police->params,
-			   new,
-			   lockdep_is_held(&police->tcf_lock));
+	new = rcu_replace_pointer(police->params,
+				  new,
+				  lockdep_is_held(&police->tcf_lock));
 	spin_unlock_bh(&police->tcf_lock);
 
 	if (goto_ch)
net/sched/act_sample.c +2 -2
index 514456a..4deeaf2 100644
@@ -102,8 +102,8 @@ static int tcf_sample_init(struct net *net, struct nlattr *nla,
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
 	s->rate = rate;
 	s->psample_group_num = psample_group_num;
-	rcu_swap_protected(s->psample_group, psample_group,
-			   lockdep_is_held(&s->tcf_lock));
+	psample_group = rcu_replace_pointer(s->psample_group, psample_group,
+					    lockdep_is_held(&s->tcf_lock));
 
 	if (tb[TCA_SAMPLE_TRUNC_SIZE]) {
 		s->truncate = true;
net/sched/act_skbedit.c +2 -2
index 6a8d333..c38cc39 100644
@@ -206,8 +206,8 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
 
 	spin_lock_bh(&d->tcf_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
-	rcu_swap_protected(d->params, params_new,
-			   lockdep_is_held(&d->tcf_lock));
+	params_new = rcu_replace_pointer(d->params, params_new,
+					 lockdep_is_held(&d->tcf_lock));
 	spin_unlock_bh(&d->tcf_lock);
 	if (params_new)
 		kfree_rcu(params_new, rcu);
net/sched/act_tunnel_key.c +2 -2
index 2f83a79..20d7ca4 100644
@@ -381,8 +381,8 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
 
 	spin_lock_bh(&t->tcf_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
-	rcu_swap_protected(t->params, params_new,
-			   lockdep_is_held(&t->tcf_lock));
+	params_new = rcu_replace_pointer(t->params, params_new,
+					 lockdep_is_held(&t->tcf_lock));
 	spin_unlock_bh(&t->tcf_lock);
 	tunnel_key_release_params(params_new);
 	if (goto_ch)
net/sched/act_vlan.c +1 -1
index 08aaf71..7aca1f0 100644
@@ -220,7 +220,7 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla,
 
 	spin_lock_bh(&v->tcf_lock);
 	goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
-	rcu_swap_protected(v->vlan_p, p, lockdep_is_held(&v->tcf_lock));
+	p = rcu_replace_pointer(v->vlan_p, p, lockdep_is_held(&v->tcf_lock));
 	spin_unlock_bh(&v->tcf_lock);
 
 	if (goto_ch)
Signature · 1 line
2.9.5
author maintainer
#47 lore raw

PATCH v2 10/10 security/safesetid: Replace rcu_swap_protected() with rcu_replace()

In reply to Paul E. McKenney

From: "Paul E. McKenney" <[email protected]>

This commit replaces the use of rcu_swap_protected() with the more intuitively appealing rcu_replace() as a step towards removing rcu_swap_protected().

---
 security/safesetid/securityfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
security/safesetid/securityfs.c +2 -2
index 74a13d4..f8bc574 100644
@@ -179,8 +179,8 @@ static ssize_t handle_policy_update(struct file *file,
 	 * doesn't currently exist, just use a spinlock for now.
 	 */
 	mutex_lock(&policy_update_lock);
-	rcu_swap_protected(safesetid_setuid_rules, pol,
-			   lockdep_is_held(&policy_update_lock));
+	pol = rcu_replace_pointer(safesetid_setuid_rules, pol,
+				  lockdep_is_held(&policy_update_lock));
 	mutex_unlock(&policy_update_lock);
 	err = len;
 
Signature · 1 line
2.9.5