RCU Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH tip/core/rcu 0/9] Replace rcu_swap_protected() for v5.5
@ 2019-10-03  1:41 Paul E. McKenney
  2019-10-03  1:43 ` [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace() paulmck
                   ` (10 more replies)
  0 siblings, 11 replies; 35+ messages in thread
From: Paul E. McKenney @ 2019-10-03  1:41 UTC (permalink / raw)
  To: rcu
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells,
	edumazet, fweisbec, oleg, joel

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(-)

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

* [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()
  2019-10-03  1:41 [PATCH tip/core/rcu 0/9] Replace rcu_swap_protected() for v5.5 Paul E. McKenney
@ 2019-10-03  1:43 ` paulmck
  2019-10-03 16:35   ` Mathieu Desnoyers
  2019-10-03  1:43 ` [PATCH tip/core/rcu 2/9] x86/kvm/pmu: Replace rcu_swap_protected() with rcu_replace() paulmck
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 35+ messages in thread
From: paulmck @ 2019-10-03  1:43 UTC (permalink / raw)
  To: rcu
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells,
	edumazet, fweisbec, oleg, joel, Paul E. McKenney,
	Bart Van Assche, Christoph Hellwig, Hannes Reinecke,
	Johannes Thumshirn, Shane M Seymour, Martin K . Petersen

From: "Paul E. McKenney" <paulmck@kernel.org>

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.

Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
Cc: Shane M Seymour <shane.seymour@hpe.com>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
---
 include/linux/rcupdate.h | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
index 75a2ede..3b73287 100644
--- a/include/linux/rcupdate.h
+++ b/include/linux/rcupdate.h
@@ -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


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

* [PATCH tip/core/rcu 2/9] x86/kvm/pmu: Replace rcu_swap_protected() with rcu_replace()
  2019-10-03  1:41 [PATCH tip/core/rcu 0/9] Replace rcu_swap_protected() for v5.5 Paul E. McKenney
  2019-10-03  1:43 ` [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace() paulmck
@ 2019-10-03  1:43 ` paulmck
  2019-10-03 10:14   ` Paolo Bonzini
  2019-10-03  1:43 ` [PATCH tip/core/rcu 3/9] drivers/gpu: " paulmck
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 35+ messages in thread
From: paulmck @ 2019-10-03  1:43 UTC (permalink / raw)
  To: rcu
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells,
	edumazet, fweisbec, oleg, joel, Paul E. McKenney, Paolo Bonzini,
	Radim Krčmář,
	Ingo Molnar, Borislav Petkov, H. Peter Anvin, x86, kvm

From: "Paul E. McKenney" <paulmck@kernel.org>

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

Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Radim Krčmář" <rkrcmar@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: <x86@kernel.org>
Cc: <kvm@vger.kernel.org>
---
 arch/x86/kvm/pmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
index 46875bb..4c37266 100644
--- a/arch/x86/kvm/pmu.c
+++ b/arch/x86/kvm/pmu.c
@@ -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);
-- 
2.9.5


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

* [PATCH tip/core/rcu 3/9] drivers/gpu: Replace rcu_swap_protected() with rcu_replace()
  2019-10-03  1:41 [PATCH tip/core/rcu 0/9] Replace rcu_swap_protected() for v5.5 Paul E. McKenney
  2019-10-03  1:43 ` [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace() paulmck
  2019-10-03  1:43 ` [PATCH tip/core/rcu 2/9] x86/kvm/pmu: Replace rcu_swap_protected() with rcu_replace() paulmck
@ 2019-10-03  1:43 ` " paulmck
  2019-10-03  1:43 ` [PATCH tip/core/rcu 4/9] drivers/scsi: " paulmck
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 35+ messages in thread
From: paulmck @ 2019-10-03  1:43 UTC (permalink / raw)
  To: rcu
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells,
	edumazet, fweisbec, oleg, joel, Paul E. McKenney, Jani Nikula,
	Joonas Lahtinen, Rodrigo Vivi, David Airlie, Daniel Vetter,
	Chris Wilson, Tvrtko Ursulin, intel-gfx, dri-devel

From: "Paul E. McKenney" <paulmck@kernel.org>

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

Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: David Airlie <airlied@linux.ie>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: <intel-gfx@lists.freedesktop.org>
Cc: <dri-devel@lists.freedesktop.org>
---
 drivers/gpu/drm/i915/gem/i915_gem_context.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_context.c b/drivers/gpu/drm/i915/gem/i915_gem_context.c
index 1cdfe05..c5c22c4 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_context.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_context.c
@@ -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);
-- 
2.9.5


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

* [PATCH tip/core/rcu 4/9] drivers/scsi: Replace rcu_swap_protected() with rcu_replace()
  2019-10-03  1:41 [PATCH tip/core/rcu 0/9] Replace rcu_swap_protected() for v5.5 Paul E. McKenney
                   ` (2 preceding siblings ...)
  2019-10-03  1:43 ` [PATCH tip/core/rcu 3/9] drivers/gpu: " paulmck
@ 2019-10-03  1:43 ` " paulmck
  2019-10-04  2:09   ` Martin K. Petersen
  2019-10-03  1:43 ` [PATCH tip/core/rcu 5/9] fs/afs: " paulmck
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 35+ messages in thread
From: paulmck @ 2019-10-03  1:43 UTC (permalink / raw)
  To: rcu
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells,
	edumazet, fweisbec, oleg, joel, Paul E. McKenney,
	James E.J. Bottomley, Martin K. Petersen, linux-scsi

From: "Paul E. McKenney" <paulmck@kernel.org>

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

Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: <linux-scsi@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>
---
 drivers/scsi/scsi.c       | 4 ++--
 drivers/scsi/scsi_sysfs.c | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 1f5b5c8..6a38d4a 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -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)
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 64c96c7..8d17779 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -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)
-- 
2.9.5


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

* [PATCH tip/core/rcu 5/9] fs/afs: Replace rcu_swap_protected() with rcu_replace()
  2019-10-03  1:41 [PATCH tip/core/rcu 0/9] Replace rcu_swap_protected() for v5.5 Paul E. McKenney
                   ` (3 preceding siblings ...)
  2019-10-03  1:43 ` [PATCH tip/core/rcu 4/9] drivers/scsi: " paulmck
@ 2019-10-03  1:43 ` " paulmck
  2019-10-03  1:43 ` [PATCH tip/core/rcu 6/9] bpf/cgroup: " paulmck
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 35+ messages in thread
From: paulmck @ 2019-10-03  1:43 UTC (permalink / raw)
  To: rcu
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells,
	edumazet, fweisbec, oleg, joel, Paul E. McKenney, linux-afs

From: "Paul E. McKenney" <paulmck@kernel.org>

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

Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: David Howells <dhowells@redhat.com>
Cc: <linux-afs@lists.infradead.org>
Cc: <linux-kernel@vger.kernel.org>
---
 fs/afs/vl_list.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/afs/vl_list.c b/fs/afs/vl_list.c
index 21eb0c0..e594598 100644
--- a/fs/afs/vl_list.c
+++ b/fs/afs/vl_list.c
@@ -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);
 		}
-- 
2.9.5


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

* [PATCH tip/core/rcu 6/9] bpf/cgroup: Replace rcu_swap_protected() with rcu_replace()
  2019-10-03  1:41 [PATCH tip/core/rcu 0/9] Replace rcu_swap_protected() for v5.5 Paul E. McKenney
                   ` (4 preceding siblings ...)
  2019-10-03  1:43 ` [PATCH tip/core/rcu 5/9] fs/afs: " paulmck
@ 2019-10-03  1:43 ` " paulmck
  2019-10-03 17:21   ` Andrii Nakryiko
  2019-10-03  1:43 ` [PATCH tip/core/rcu 7/9] net/core: " paulmck
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 35+ messages in thread
From: paulmck @ 2019-10-03  1:43 UTC (permalink / raw)
  To: rcu
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells,
	edumazet, fweisbec, oleg, joel, Paul E. McKenney,
	Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song, netdev, bpf

From: "Paul E. McKenney" <paulmck@kernel.org>

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

Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Yonghong Song <yhs@fb.com>
Cc: <netdev@vger.kernel.org>
Cc: <bpf@vger.kernel.org>
---
 kernel/bpf/cgroup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
index ddd8add..06a0657 100644
--- a/kernel/bpf/cgroup.c
+++ b/kernel/bpf/cgroup.c
@@ -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


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

* [PATCH tip/core/rcu 7/9] net/core: Replace rcu_swap_protected() with rcu_replace()
  2019-10-03  1:41 [PATCH tip/core/rcu 0/9] Replace rcu_swap_protected() for v5.5 Paul E. McKenney
                   ` (5 preceding siblings ...)
  2019-10-03  1:43 ` [PATCH tip/core/rcu 6/9] bpf/cgroup: " paulmck
@ 2019-10-03  1:43 ` " paulmck
  2019-10-03  1:43 ` [PATCH tip/core/rcu 8/9] net/netfilter: " paulmck
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 35+ messages in thread
From: paulmck @ 2019-10-03  1:43 UTC (permalink / raw)
  To: rcu
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells,
	edumazet, fweisbec, oleg, joel, Paul E. McKenney,
	David S. Miller, Jiri Pirko, Ido Schimmel, Petr Machata,
	Paolo Abeni, netdev

From: "Paul E. McKenney" <paulmck@kernel.org>

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

Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jiri Pirko <jiri@mellanox.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Ido Schimmel <idosch@mellanox.com>
Cc: Petr Machata <petrm@mellanox.com>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: <netdev@vger.kernel.org>
---
 net/core/dev.c            | 4 ++--
 net/core/sock_reuseport.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index bf3ed41..41f6936 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -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)
diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
index f3ceec9..805287b 100644
--- a/net/core/sock_reuseport.c
+++ b/net/core/sock_reuseport.c
@@ -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)
-- 
2.9.5


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

* [PATCH tip/core/rcu 8/9] net/netfilter: Replace rcu_swap_protected() with rcu_replace()
  2019-10-03  1:41 [PATCH tip/core/rcu 0/9] Replace rcu_swap_protected() for v5.5 Paul E. McKenney
                   ` (6 preceding siblings ...)
  2019-10-03  1:43 ` [PATCH tip/core/rcu 7/9] net/core: " paulmck
@ 2019-10-03  1:43 ` " paulmck
  2019-10-08 14:16   ` Pablo Neira Ayuso
  2019-10-03  1:43 ` [PATCH tip/core/rcu 9/9] net/sched: " paulmck
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 35+ messages in thread
From: paulmck @ 2019-10-03  1:43 UTC (permalink / raw)
  To: rcu
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells,
	edumazet, fweisbec, oleg, joel, Paul E. McKenney,
	Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal,
	David S. Miller, netfilter-devel, coreteam, netdev

From: "Paul E. McKenney" <paulmck@kernel.org>

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

Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Jozsef Kadlecsik <kadlec@netfilter.org>
Cc: Florian Westphal <fw@strlen.de>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: <netfilter-devel@vger.kernel.org>
Cc: <coreteam@netfilter.org>
Cc: <netdev@vger.kernel.org>
---
 net/netfilter/nf_tables_api.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index d481f9b..8499baf 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -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);
-- 
2.9.5


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

* [PATCH tip/core/rcu 9/9] net/sched: Replace rcu_swap_protected() with rcu_replace()
  2019-10-03  1:41 [PATCH tip/core/rcu 0/9] Replace rcu_swap_protected() for v5.5 Paul E. McKenney
                   ` (7 preceding siblings ...)
  2019-10-03  1:43 ` [PATCH tip/core/rcu 8/9] net/netfilter: " paulmck
@ 2019-10-03  1:43 ` " paulmck
  2019-10-03  8:38 ` [PATCH tip/core/rcu 5/9] fs/afs: " David Howells
  2019-10-03  8:39 ` [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace() David Howells
  10 siblings, 0 replies; 35+ messages in thread
From: paulmck @ 2019-10-03  1:43 UTC (permalink / raw)
  To: rcu
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells,
	edumazet, fweisbec, oleg, joel, Paul E. McKenney,
	Jamal Hadi Salim, Cong Wang, Jiri Pirko, David S. Miller, netdev

From: "Paul E. McKenney" <paulmck@kernel.org>

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

Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Jiri Pirko <jiri@resnulli.us>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: <netdev@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>
---
 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(-)

diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 2558f00..1ab810c 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -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);
diff --git a/net/sched/act_csum.c b/net/sched/act_csum.c
index d3cfad8..ced5fe6 100644
--- a/net/sched/act_csum.c
+++ b/net/sched/act_csum.c
@@ -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)
diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
index fcc4602..500e874 100644
--- a/net/sched/act_ct.c
+++ b/net/sched/act_ct.c
@@ -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)
diff --git a/net/sched/act_ctinfo.c b/net/sched/act_ctinfo.c
index 0dbcfd1..e6ea270 100644
--- a/net/sched/act_ctinfo.c
+++ b/net/sched/act_ctinfo.c
@@ -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)
diff --git a/net/sched/act_ife.c b/net/sched/act_ife.c
index 3a31e24..a6a60b8 100644
--- a/net/sched/act_ife.c
+++ b/net/sched/act_ife.c
@@ -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);
diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c
index 9ce073a..1ed5d7e 100644
--- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -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;
diff --git a/net/sched/act_mpls.c b/net/sched/act_mpls.c
index e168df0..cea8771 100644
--- a/net/sched/act_mpls.c
+++ b/net/sched/act_mpls.c
@@ -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)
diff --git a/net/sched/act_police.c b/net/sched/act_police.c
index 89c04c5..02a4bc9c 100644
--- a/net/sched/act_police.c
+++ b/net/sched/act_police.c
@@ -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)
diff --git a/net/sched/act_skbedit.c b/net/sched/act_skbedit.c
index 6a8d333..6c4bd47 100644
--- a/net/sched/act_skbedit.c
+++ b/net/sched/act_skbedit.c
@@ -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);
diff --git a/net/sched/act_tunnel_key.c b/net/sched/act_tunnel_key.c
index 2f83a79..7130da8 100644
--- a/net/sched/act_tunnel_key.c
+++ b/net/sched/act_tunnel_key.c
@@ -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)
diff --git a/net/sched/act_vlan.c b/net/sched/act_vlan.c
index 08aaf71..402c9ea 100644
--- a/net/sched/act_vlan.c
+++ b/net/sched/act_vlan.c
@@ -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)
-- 
2.9.5


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

* Re: [PATCH tip/core/rcu 5/9] fs/afs: Replace rcu_swap_protected() with rcu_replace()
  2019-10-03  1:41 [PATCH tip/core/rcu 0/9] Replace rcu_swap_protected() for v5.5 Paul E. McKenney
                   ` (8 preceding siblings ...)
  2019-10-03  1:43 ` [PATCH tip/core/rcu 9/9] net/sched: " paulmck
@ 2019-10-03  8:38 ` " David Howells
  2019-10-05 16:10   ` Paul E. McKenney
  2019-10-03  8:39 ` [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace() David Howells
  10 siblings, 1 reply; 35+ messages in thread
From: David Howells @ 2019-10-03  8:38 UTC (permalink / raw)
  To: paulmck
  Cc: dhowells, rcu, linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, edumazet,
	fweisbec, oleg, joel, linux-afs

paulmck@kernel.org 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!

> Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
> Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> Cc: David Howells <dhowells@redhat.com>
> Cc: <linux-afs@lists.infradead.org>
> Cc: <linux-kernel@vger.kernel.org>

Acked-by: David Howells <dhowells@redhat.com>

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

* Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()
  2019-10-03  1:41 [PATCH tip/core/rcu 0/9] Replace rcu_swap_protected() for v5.5 Paul E. McKenney
                   ` (9 preceding siblings ...)
  2019-10-03  8:38 ` [PATCH tip/core/rcu 5/9] fs/afs: " David Howells
@ 2019-10-03  8:39 ` David Howells
  2019-10-03 13:08   ` Steven Rostedt
  10 siblings, 1 reply; 35+ messages in thread
From: David Howells @ 2019-10-03  8:39 UTC (permalink / raw)
  To: paulmck
  Cc: dhowells, rcu, linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, edumazet,
	fweisbec, oleg, joel, Bart Van Assche, Christoph Hellwig,
	Hannes Reinecke, Johannes Thumshirn, Shane M Seymour,
	Martin K . Petersen

paulmck@kernel.org wrote:

> +#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

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

* Re: [PATCH tip/core/rcu 2/9] x86/kvm/pmu: Replace rcu_swap_protected() with rcu_replace()
  2019-10-03  1:43 ` [PATCH tip/core/rcu 2/9] x86/kvm/pmu: Replace rcu_swap_protected() with rcu_replace() paulmck
@ 2019-10-03 10:14   ` Paolo Bonzini
  2019-10-05 16:11     ` Paul E. McKenney
  0 siblings, 1 reply; 35+ messages in thread
From: Paolo Bonzini @ 2019-10-03 10:14 UTC (permalink / raw)
  To: paulmck, rcu
  Cc: linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells,
	edumazet, fweisbec, oleg, joel, Radim Krčmář,
	Ingo Molnar, Borislav Petkov, H. Peter Anvin, x86, kvm

On 03/10/19 03:43, paulmck@kernel.org wrote:
> From: "Paul E. McKenney" <paulmck@kernel.org>
> 
> This commit replaces the use of rcu_swap_protected() with the more
> intuitively appealing rcu_replace() as a step towards removing
> rcu_swap_protected().
> 
> Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
> Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: "Radim Krčmář" <rkrcmar@redhat.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: <x86@kernel.org>
> Cc: <kvm@vger.kernel.org>
> ---
>  arch/x86/kvm/pmu.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> index 46875bb..4c37266 100644
> --- a/arch/x86/kvm/pmu.c
> +++ b/arch/x86/kvm/pmu.c
> @@ -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

Acked-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo

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

* Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()
  2019-10-03  8:39 ` [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace() David Howells
@ 2019-10-03 13:08   ` Steven Rostedt
  2019-10-03 13:33     ` Paul E. McKenney
  2019-10-03 16:31     ` Mathieu Desnoyers
  0 siblings, 2 replies; 35+ messages in thread
From: Steven Rostedt @ 2019-10-03 13:08 UTC (permalink / raw)
  To: David Howells
  Cc: paulmck, rcu, linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, edumazet, fweisbec, oleg,
	joel, Bart Van Assche, Christoph Hellwig, Hannes Reinecke,
	Johannes Thumshirn, Shane M Seymour, Martin K . Petersen

On Thu, 03 Oct 2019 09:39:17 +0100
David Howells <dhowells@redhat.com> wrote:

> paulmck@kernel.org wrote:
> 
> > +#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


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

* Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()
  2019-10-03 13:08   ` Steven Rostedt
@ 2019-10-03 13:33     ` Paul E. McKenney
  2019-10-03 13:41       ` Peter Zijlstra
  2019-10-03 14:01       ` Joel Fernandes
  2019-10-03 16:31     ` Mathieu Desnoyers
  1 sibling, 2 replies; 35+ messages in thread
From: Paul E. McKenney @ 2019-10-03 13:33 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: David Howells, rcu, linux-kernel, mingo, jiangshanlai, dipankar,
	akpm, mathieu.desnoyers, josh, tglx, peterz, edumazet, fweisbec,
	oleg, joel, Bart Van Assche, Christoph Hellwig, Hannes Reinecke,
	Johannes Thumshirn, Shane M Seymour, Martin K . Petersen

On Thu, Oct 03, 2019 at 09:08:50AM -0400, Steven Rostedt wrote:
> On Thu, 03 Oct 2019 09:39:17 +0100
> David Howells <dhowells@redhat.com> wrote:
> 
> > paulmck@kernel.org wrote:
> > 
> > > +#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().

> 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

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

* Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()
  2019-10-03 13:33     ` Paul E. McKenney
@ 2019-10-03 13:41       ` Peter Zijlstra
  2019-10-03 13:58         ` Paul E. McKenney
  2019-10-03 14:01       ` Joel Fernandes
  1 sibling, 1 reply; 35+ messages in thread
From: Peter Zijlstra @ 2019-10-03 13:41 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: Steven Rostedt, David Howells, rcu, linux-kernel, mingo,
	jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh, tglx,
	edumazet, fweisbec, oleg, joel, Bart Van Assche,
	Christoph Hellwig, Hannes Reinecke, Johannes Thumshirn,
	Shane M Seymour, Martin K . Petersen

On Thu, Oct 03, 2019 at 06:33:15AM -0700, Paul E. McKenney wrote:
> On Thu, Oct 03, 2019 at 09:08:50AM -0400, Steven Rostedt wrote:
> > On Thu, 03 Oct 2019 09:39:17 +0100
> > David Howells <dhowells@redhat.com> wrote:
> > 
> > > paulmck@kernel.org wrote:
> > > 
> > > > +#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().

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

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

* Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()
  2019-10-03 13:41       ` Peter Zijlstra
@ 2019-10-03 13:58         ` Paul E. McKenney
  0 siblings, 0 replies; 35+ messages in thread
From: Paul E. McKenney @ 2019-10-03 13:58 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Steven Rostedt, David Howells, rcu, linux-kernel, mingo,
	jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh, tglx,
	edumazet, fweisbec, oleg, joel, Bart Van Assche,
	Christoph Hellwig, Hannes Reinecke, Johannes Thumshirn,
	Shane M Seymour, Martin K . Petersen

On Thu, Oct 03, 2019 at 03:41:31PM +0200, Peter Zijlstra wrote:
> On Thu, Oct 03, 2019 at 06:33:15AM -0700, Paul E. McKenney wrote:
> > On Thu, Oct 03, 2019 at 09:08:50AM -0400, Steven Rostedt wrote:
> > > On Thu, 03 Oct 2019 09:39:17 +0100
> > > David Howells <dhowells@redhat.com> wrote:
> > > 
> > > > paulmck@kernel.org wrote:
> > > > 
> > > > > +#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().
> 
> Nope, still the case. xchg() is an atomic op with full ordering.

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

							Thanx, Paul

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

* Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()
  2019-10-03 13:33     ` Paul E. McKenney
  2019-10-03 13:41       ` Peter Zijlstra
@ 2019-10-03 14:01       ` Joel Fernandes
  1 sibling, 0 replies; 35+ messages in thread
From: Joel Fernandes @ 2019-10-03 14:01 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: Steven Rostedt, David Howells, rcu, linux-kernel, mingo,
	jiangshanlai, dipankar, akpm, mathieu.desnoyers, josh, tglx,
	peterz, edumazet, fweisbec, oleg, Bart Van Assche,
	Christoph Hellwig, Hannes Reinecke, Johannes Thumshirn,
	Shane M Seymour, Martin K . Petersen

On Thu, Oct 03, 2019 at 06:33:15AM -0700, Paul E. McKenney wrote:
> On Thu, Oct 03, 2019 at 09:08:50AM -0400, Steven Rostedt wrote:
> > On Thu, 03 Oct 2019 09:39:17 +0100
> > David Howells <dhowells@redhat.com> wrote:
> > 
> > > paulmck@kernel.org wrote:
> > > 
> > > > +#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().

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


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

* Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()
  2019-10-03 13:08   ` Steven Rostedt
  2019-10-03 13:33     ` Paul E. McKenney
@ 2019-10-03 16:31     ` Mathieu Desnoyers
  2019-10-03 18:05       ` Peter Zijlstra
  1 sibling, 1 reply; 35+ messages in thread
From: Mathieu Desnoyers @ 2019-10-03 16:31 UTC (permalink / raw)
  To: rostedt
  Cc: David Howells, paulmck, rcu, linux-kernel, Ingo Molnar,
	Lai Jiangshan, dipankar, Andrew Morton, Josh Triplett,
	Thomas Gleixner, Peter Zijlstra, Eric Dumazet, fweisbec,
	Oleg Nesterov, Joel Fernandes, Google, Bart Van Assche,
	Christoph Hellwig, Hannes Reinecke, Johannes Thumshirn,
	Shane M Seymour, Martin K . Petersen

----- On Oct 3, 2019, at 9:08 AM, rostedt rostedt@goodmis.org wrote:

> On Thu, 03 Oct 2019 09:39:17 +0100
> David Howells <dhowells@redhat.com> wrote:
> 
>> paulmck@kernel.org wrote:
>> 
>> > +#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.

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


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

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

* Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()
  2019-10-03  1:43 ` [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace() paulmck
@ 2019-10-03 16:35   ` Mathieu Desnoyers
  2019-10-03 16:52     ` Paul E. McKenney
  0 siblings, 1 reply; 35+ messages in thread
From: Mathieu Desnoyers @ 2019-10-03 16:35 UTC (permalink / raw)
  To: paulmck
  Cc: rcu, linux-kernel, Ingo Molnar, Lai Jiangshan, dipankar,
	Andrew Morton, Josh Triplett, Thomas Gleixner, Peter Zijlstra,
	rostedt, David Howells, Eric Dumazet, fweisbec, Oleg Nesterov,
	Joel Fernandes, Google, Bart Van Assche, Christoph Hellwig,
	Hannes Reinecke, Johannes Thumshirn, Shane M Seymour, Martin

----- On Oct 2, 2019, at 9:43 PM, paulmck paulmck@kernel.org wrote:

> From: "Paul E. McKenney" <paulmck@kernel.org>
> 
> 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


> 
> Link:
> https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
> Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> Cc: Bart Van Assche <bart.vanassche@wdc.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Hannes Reinecke <hare@suse.de>
> Cc: Johannes Thumshirn <jthumshirn@suse.de>
> Cc: Shane M Seymour <shane.seymour@hpe.com>
> Cc: Martin K. Petersen <martin.petersen@oracle.com>
> ---
> include/linux/rcupdate.h | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
> 
> diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
> index 75a2ede..3b73287 100644
> --- a/include/linux/rcupdate.h
> +++ b/include/linux/rcupdate.h
> @@ -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

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

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

* Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()
  2019-10-03 16:35   ` Mathieu Desnoyers
@ 2019-10-03 16:52     ` Paul E. McKenney
  2019-10-03 17:21       ` Mathieu Desnoyers
  0 siblings, 1 reply; 35+ messages in thread
From: Paul E. McKenney @ 2019-10-03 16:52 UTC (permalink / raw)
  To: Mathieu Desnoyers
  Cc: rcu, linux-kernel, Ingo Molnar, Lai Jiangshan, dipankar,
	Andrew Morton, Josh Triplett, Thomas Gleixner, Peter Zijlstra,
	rostedt, David Howells, Eric Dumazet, fweisbec, Oleg Nesterov,
	Joel Fernandes, Google, Bart Van Assche, Christoph Hellwig,
	Hannes Reinecke, Johannes Thumshirn, Shane M Seymour, Martin

On Thu, Oct 03, 2019 at 12:35:30PM -0400, Mathieu Desnoyers wrote:
> ----- On Oct 2, 2019, at 9:43 PM, paulmck paulmck@kernel.org wrote:
> 
> > From: "Paul E. McKenney" <paulmck@kernel.org>
> > 
> > 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.

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

> Thanks,
> 
> Mathieu
> 
> 
> > 
> > Link:
> > https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
> > Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> > Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> > Cc: Bart Van Assche <bart.vanassche@wdc.com>
> > Cc: Christoph Hellwig <hch@lst.de>
> > Cc: Hannes Reinecke <hare@suse.de>
> > Cc: Johannes Thumshirn <jthumshirn@suse.de>
> > Cc: Shane M Seymour <shane.seymour@hpe.com>
> > Cc: Martin K. Petersen <martin.petersen@oracle.com>
> > ---
> > include/linux/rcupdate.h | 18 ++++++++++++++++++
> > 1 file changed, 18 insertions(+)
> > 
> > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
> > index 75a2ede..3b73287 100644
> > --- a/include/linux/rcupdate.h
> > +++ b/include/linux/rcupdate.h
> > @@ -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
> 
> -- 
> Mathieu Desnoyers
> EfficiOS Inc.
> http://www.efficios.com

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

* Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()
  2019-10-03 16:52     ` Paul E. McKenney
@ 2019-10-03 17:21       ` Mathieu Desnoyers
  2019-10-03 19:09         ` Paul E. McKenney
  0 siblings, 1 reply; 35+ messages in thread
From: Mathieu Desnoyers @ 2019-10-03 17:21 UTC (permalink / raw)
  To: paulmck
  Cc: rcu, linux-kernel, Ingo Molnar, Lai Jiangshan, dipankar,
	Andrew Morton, Josh Triplett, Thomas Gleixner, Peter Zijlstra,
	rostedt, David Howells, Eric Dumazet, fweisbec, Oleg Nesterov,
	Joel Fernandes, Google, Bart Van Assche, Christoph Hellwig,
	Hannes Reinecke, Johannes Thumshirn, Shane M Seymour, Martin

----- On Oct 3, 2019, at 12:52 PM, paulmck paulmck@kernel.org wrote:

> On Thu, Oct 03, 2019 at 12:35:30PM -0400, Mathieu Desnoyers wrote:
>> ----- On Oct 2, 2019, at 9:43 PM, paulmck paulmck@kernel.org wrote:
>> 
>> > From: "Paul E. McKenney" <paulmck@kernel.org>
>> > 
>> > 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.
> 
> 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


> 
>							Thanx, Paul
> 
>> Thanks,
>> 
>> Mathieu
>> 
>> 
>> > 
>> > Link:
>> > https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
>> > Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
>> > Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
>> > Cc: Bart Van Assche <bart.vanassche@wdc.com>
>> > Cc: Christoph Hellwig <hch@lst.de>
>> > Cc: Hannes Reinecke <hare@suse.de>
>> > Cc: Johannes Thumshirn <jthumshirn@suse.de>
>> > Cc: Shane M Seymour <shane.seymour@hpe.com>
>> > Cc: Martin K. Petersen <martin.petersen@oracle.com>
>> > ---
>> > include/linux/rcupdate.h | 18 ++++++++++++++++++
>> > 1 file changed, 18 insertions(+)
>> > 
>> > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
>> > index 75a2ede..3b73287 100644
>> > --- a/include/linux/rcupdate.h
>> > +++ b/include/linux/rcupdate.h
>> > @@ -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
>> 
>> --
>> Mathieu Desnoyers
>> EfficiOS Inc.
> > http://www.efficios.com

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

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

* Re: [PATCH tip/core/rcu 6/9] bpf/cgroup: Replace rcu_swap_protected() with rcu_replace()
  2019-10-03  1:43 ` [PATCH tip/core/rcu 6/9] bpf/cgroup: " paulmck
@ 2019-10-03 17:21   ` Andrii Nakryiko
  2019-10-03 20:58     ` Song Liu
  0 siblings, 1 reply; 35+ messages in thread
From: Andrii Nakryiko @ 2019-10-03 17:21 UTC (permalink / raw)
  To: paulmck
  Cc: rcu, open list, Ingo Molnar, jiangshanlai, dipankar,
	Andrew Morton, mathieu.desnoyers, josh, Thomas Gleixner,
	Peter Ziljstra, Steven Rostedt, dhowells, Eric Dumazet, fweisbec,
	oleg, Joel Fernandes, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Networking, bpf

On Wed, Oct 2, 2019 at 6:45 PM <paulmck@kernel.org> wrote:
>
> From: "Paul E. McKenney" <paulmck@kernel.org>
>
> This commit replaces the use of rcu_swap_protected() with the more
> intuitively appealing rcu_replace() as a step towards removing
> rcu_swap_protected().
>
> Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
> Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: Martin KaFai Lau <kafai@fb.com>
> Cc: Song Liu <songliubraving@fb.com>
> Cc: Yonghong Song <yhs@fb.com>
> Cc: <netdev@vger.kernel.org>
> Cc: <bpf@vger.kernel.org>
> ---

Acked-by: Andrii Nakryiko <andriin@fb.com>

>  kernel/bpf/cgroup.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c
> index ddd8add..06a0657 100644
> --- a/kernel/bpf/cgroup.c
> +++ b/kernel/bpf/cgroup.c
> @@ -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
>

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

* Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()
  2019-10-03 16:31     ` Mathieu Desnoyers
@ 2019-10-03 18:05       ` Peter Zijlstra
  0 siblings, 0 replies; 35+ messages in thread
From: Peter Zijlstra @ 2019-10-03 18:05 UTC (permalink / raw)
  To: Mathieu Desnoyers
  Cc: rostedt, David Howells, paulmck, rcu, linux-kernel, Ingo Molnar,
	Lai Jiangshan, dipankar, Andrew Morton, Josh Triplett,
	Thomas Gleixner, Eric Dumazet, fweisbec, Oleg Nesterov,
	Joel Fernandes, Google, Bart Van Assche, Christoph Hellwig,
	Hannes Reinecke, Johannes Thumshirn, Shane M Seymour,
	Martin K . Petersen

On Thu, Oct 03, 2019 at 12:31:38PM -0400, Mathieu Desnoyers wrote:
> 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.

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

* Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()
  2019-10-03 17:21       ` Mathieu Desnoyers
@ 2019-10-03 19:09         ` Paul E. McKenney
  2019-10-03 19:14           ` Mathieu Desnoyers
  0 siblings, 1 reply; 35+ messages in thread
From: Paul E. McKenney @ 2019-10-03 19:09 UTC (permalink / raw)
  To: Mathieu Desnoyers
  Cc: rcu, linux-kernel, Ingo Molnar, Lai Jiangshan, dipankar,
	Andrew Morton, Josh Triplett, Thomas Gleixner, Peter Zijlstra,
	rostedt, David Howells, Eric Dumazet, fweisbec, Oleg Nesterov,
	Joel Fernandes, Google, Bart Van Assche, Christoph Hellwig,
	Hannes Reinecke, Johannes Thumshirn, Shane M Seymour, Martin

On Thu, Oct 03, 2019 at 01:21:14PM -0400, Mathieu Desnoyers wrote:
> ----- On Oct 3, 2019, at 12:52 PM, paulmck paulmck@kernel.org wrote:
> 
> > On Thu, Oct 03, 2019 at 12:35:30PM -0400, Mathieu Desnoyers wrote:
> >> ----- On Oct 2, 2019, at 9:43 PM, paulmck paulmck@kernel.org wrote:
> >> 
> >> > From: "Paul E. McKenney" <paulmck@kernel.org>
> >> > 
> >> > 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.
> > 
> > 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 ?

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

> Thanks,
> 
> Mathieu
> 
> 
> > 
> >							Thanx, Paul
> > 
> >> Thanks,
> >> 
> >> Mathieu
> >> 
> >> 
> >> > 
> >> > Link:
> >> > https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
> >> > Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> >> > Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> >> > Cc: Bart Van Assche <bart.vanassche@wdc.com>
> >> > Cc: Christoph Hellwig <hch@lst.de>
> >> > Cc: Hannes Reinecke <hare@suse.de>
> >> > Cc: Johannes Thumshirn <jthumshirn@suse.de>
> >> > Cc: Shane M Seymour <shane.seymour@hpe.com>
> >> > Cc: Martin K. Petersen <martin.petersen@oracle.com>
> >> > ---
> >> > include/linux/rcupdate.h | 18 ++++++++++++++++++
> >> > 1 file changed, 18 insertions(+)
> >> > 
> >> > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
> >> > index 75a2ede..3b73287 100644
> >> > --- a/include/linux/rcupdate.h
> >> > +++ b/include/linux/rcupdate.h
> >> > @@ -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
> >> 
> >> --
> >> Mathieu Desnoyers
> >> EfficiOS Inc.
> > > http://www.efficios.com
> 
> -- 
> Mathieu Desnoyers
> EfficiOS Inc.
> http://www.efficios.com

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

* Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace()
  2019-10-03 19:09         ` Paul E. McKenney
@ 2019-10-03 19:14           ` Mathieu Desnoyers
  0 siblings, 0 replies; 35+ messages in thread
From: Mathieu Desnoyers @ 2019-10-03 19:14 UTC (permalink / raw)
  To: paulmck
  Cc: rcu, linux-kernel, Ingo Molnar, Lai Jiangshan, dipankar,
	Andrew Morton, Josh Triplett, Thomas Gleixner, Peter Zijlstra,
	rostedt, David Howells, Eric Dumazet, fweisbec, Oleg Nesterov,
	Joel Fernandes, Google, Bart Van Assche, Christoph Hellwig,
	Hannes Reinecke, Johannes Thumshirn, Shane M Seymour, Martin

----- On Oct 3, 2019, at 3:09 PM, paulmck paulmck@kernel.org wrote:

> On Thu, Oct 03, 2019 at 01:21:14PM -0400, Mathieu Desnoyers wrote:
>> ----- On Oct 3, 2019, at 12:52 PM, paulmck paulmck@kernel.org wrote:
>> 
>> > On Thu, Oct 03, 2019 at 12:35:30PM -0400, Mathieu Desnoyers wrote:
>> >> ----- On Oct 2, 2019, at 9:43 PM, paulmck paulmck@kernel.org wrote:
>> >> 
>> >> > From: "Paul E. McKenney" <paulmck@kernel.org>
>> >> > 
>> >> > 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.
>> > 
>> > 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 ?
> 
> 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

> 
>							Thanx, Paul
> 
>> Thanks,
>> 
>> Mathieu
>> 
>> 
>> > 
>> >							Thanx, Paul
>> > 
>> >> Thanks,
>> >> 
>> >> Mathieu
>> >> 
>> >> 
>> >> > 
>> >> > Link:
>> >> > https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
>> >> > Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
>> >> > Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
>> >> > Cc: Bart Van Assche <bart.vanassche@wdc.com>
>> >> > Cc: Christoph Hellwig <hch@lst.de>
>> >> > Cc: Hannes Reinecke <hare@suse.de>
>> >> > Cc: Johannes Thumshirn <jthumshirn@suse.de>
>> >> > Cc: Shane M Seymour <shane.seymour@hpe.com>
>> >> > Cc: Martin K. Petersen <martin.petersen@oracle.com>
>> >> > ---
>> >> > include/linux/rcupdate.h | 18 ++++++++++++++++++
>> >> > 1 file changed, 18 insertions(+)
>> >> > 
>> >> > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
>> >> > index 75a2ede..3b73287 100644
>> >> > --- a/include/linux/rcupdate.h
>> >> > +++ b/include/linux/rcupdate.h
>> >> > @@ -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
>> >> 
>> >> --
>> >> Mathieu Desnoyers
>> >> EfficiOS Inc.
>> > > http://www.efficios.com
>> 
>> --
>> Mathieu Desnoyers
>> EfficiOS Inc.
> > http://www.efficios.com

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

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

* Re: [PATCH tip/core/rcu 6/9] bpf/cgroup: Replace rcu_swap_protected() with rcu_replace()
  2019-10-03 17:21   ` Andrii Nakryiko
@ 2019-10-03 20:58     ` Song Liu
  2019-10-05 16:11       ` Paul E. McKenney
  0 siblings, 1 reply; 35+ messages in thread
From: Song Liu @ 2019-10-03 20:58 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: paulmck, rcu, open list, Ingo Molnar, jiangshanlai, dipankar,
	Andrew Morton, mathieu.desnoyers, josh, Thomas Gleixner,
	Peter Ziljstra, Steven Rostedt, dhowells, Eric Dumazet, fweisbec,
	Oleg Nesterov, Joel Fernandes, Alexei Starovoitov,
	Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
	Networking, bpf

On Thu, Oct 3, 2019 at 10:43 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Wed, Oct 2, 2019 at 6:45 PM <paulmck@kernel.org> wrote:
> >
> > From: "Paul E. McKenney" <paulmck@kernel.org>
> >
> > This commit replaces the use of rcu_swap_protected() with the more
> > intuitively appealing rcu_replace() as a step towards removing
> > rcu_swap_protected().
> >
> > Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
> > Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> > Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> > Cc: Alexei Starovoitov <ast@kernel.org>
> > Cc: Daniel Borkmann <daniel@iogearbox.net>
> > Cc: Martin KaFai Lau <kafai@fb.com>
> > Cc: Song Liu <songliubraving@fb.com>
> > Cc: Yonghong Song <yhs@fb.com>
> > Cc: <netdev@vger.kernel.org>
> > Cc: <bpf@vger.kernel.org>
> > ---
>
> Acked-by: Andrii Nakryiko <andriin@fb.com>

Acked-by: Song Liu <songliubraving@fb.com>

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

* Re: [PATCH tip/core/rcu 4/9] drivers/scsi: Replace rcu_swap_protected() with rcu_replace()
  2019-10-03  1:43 ` [PATCH tip/core/rcu 4/9] drivers/scsi: " paulmck
@ 2019-10-04  2:09   ` Martin K. Petersen
  2019-10-05 16:06     ` Paul E. McKenney
  0 siblings, 1 reply; 35+ messages in thread
From: Martin K. Petersen @ 2019-10-04  2:09 UTC (permalink / raw)
  To: paulmck
  Cc: rcu, linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells,
	edumazet, fweisbec, oleg, joel, James E.J. Bottomley,
	Martin K. Petersen, linux-scsi


Paul,

No objections from me.

> +	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().

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH tip/core/rcu 4/9] drivers/scsi: Replace rcu_swap_protected() with rcu_replace()
  2019-10-04  2:09   ` Martin K. Petersen
@ 2019-10-05 16:06     ` Paul E. McKenney
  2019-10-10  2:36       ` Martin K. Petersen
  0 siblings, 1 reply; 35+ messages in thread
From: Paul E. McKenney @ 2019-10-05 16:06 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: rcu, linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells,
	edumazet, fweisbec, oleg, joel, James E.J. Bottomley, linux-scsi

On Thu, Oct 03, 2019 at 10:09:31PM -0400, Martin K. Petersen wrote:
> 
> 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.

> > +	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

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

* Re: [PATCH tip/core/rcu 5/9] fs/afs: Replace rcu_swap_protected() with rcu_replace()
  2019-10-03  8:38 ` [PATCH tip/core/rcu 5/9] fs/afs: " David Howells
@ 2019-10-05 16:10   ` Paul E. McKenney
  0 siblings, 0 replies; 35+ messages in thread
From: Paul E. McKenney @ 2019-10-05 16:10 UTC (permalink / raw)
  To: David Howells
  Cc: rcu, linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, edumazet,
	fweisbec, oleg, joel, linux-afs

On Thu, Oct 03, 2019 at 09:38:14AM +0100, David Howells wrote:
> paulmck@kernel.org 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!
> 
> > Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
> > Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> > Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> > Cc: David Howells <dhowells@redhat.com>
> > Cc: <linux-afs@lists.infradead.org>
> > Cc: <linux-kernel@vger.kernel.org>
> 
> Acked-by: David Howells <dhowells@redhat.com>

Applied, thank you David!

							Thanx, Paul

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

* Re: [PATCH tip/core/rcu 2/9] x86/kvm/pmu: Replace rcu_swap_protected() with rcu_replace()
  2019-10-03 10:14   ` Paolo Bonzini
@ 2019-10-05 16:11     ` Paul E. McKenney
  0 siblings, 0 replies; 35+ messages in thread
From: Paul E. McKenney @ 2019-10-05 16:11 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: rcu, linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells,
	edumazet, fweisbec, oleg, joel, Radim Krčmář,
	Ingo Molnar, Borislav Petkov, H. Peter Anvin, x86, kvm

On Thu, Oct 03, 2019 at 12:14:32PM +0200, Paolo Bonzini wrote:
> On 03/10/19 03:43, paulmck@kernel.org wrote:
> > From: "Paul E. McKenney" <paulmck@kernel.org>
> > 
> > This commit replaces the use of rcu_swap_protected() with the more
> > intuitively appealing rcu_replace() as a step towards removing
> > rcu_swap_protected().
> > 
> > Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
> > Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> > Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> > Cc: Paolo Bonzini <pbonzini@redhat.com>
> > Cc: "Radim Krčmář" <rkrcmar@redhat.com>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: Borislav Petkov <bp@alien8.de>
> > Cc: "H. Peter Anvin" <hpa@zytor.com>
> > Cc: <x86@kernel.org>
> > Cc: <kvm@vger.kernel.org>
> > ---
> >  arch/x86/kvm/pmu.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c
> > index 46875bb..4c37266 100644
> > --- a/arch/x86/kvm/pmu.c
> > +++ b/arch/x86/kvm/pmu.c
> > @@ -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
> 
> Acked-by: Paolo Bonzini <pbonzini@redhat.com>

It never goes without saying!  ;-)

Applied, thank you!

							Thanx, Paul

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

* Re: [PATCH tip/core/rcu 6/9] bpf/cgroup: Replace rcu_swap_protected() with rcu_replace()
  2019-10-03 20:58     ` Song Liu
@ 2019-10-05 16:11       ` Paul E. McKenney
  0 siblings, 0 replies; 35+ messages in thread
From: Paul E. McKenney @ 2019-10-05 16:11 UTC (permalink / raw)
  To: Song Liu
  Cc: Andrii Nakryiko, rcu, open list, Ingo Molnar, jiangshanlai,
	dipankar, Andrew Morton, mathieu.desnoyers, josh,
	Thomas Gleixner, Peter Ziljstra, Steven Rostedt, dhowells,
	Eric Dumazet, fweisbec, Oleg Nesterov, Joel Fernandes,
	Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song, Networking, bpf

On Thu, Oct 03, 2019 at 01:58:13PM -0700, Song Liu wrote:
> On Thu, Oct 3, 2019 at 10:43 AM Andrii Nakryiko
> <andrii.nakryiko@gmail.com> wrote:
> >
> > On Wed, Oct 2, 2019 at 6:45 PM <paulmck@kernel.org> wrote:
> > >
> > > From: "Paul E. McKenney" <paulmck@kernel.org>
> > >
> > > This commit replaces the use of rcu_swap_protected() with the more
> > > intuitively appealing rcu_replace() as a step towards removing
> > > rcu_swap_protected().
> > >
> > > Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
> > > Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> > > Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> > > Cc: Alexei Starovoitov <ast@kernel.org>
> > > Cc: Daniel Borkmann <daniel@iogearbox.net>
> > > Cc: Martin KaFai Lau <kafai@fb.com>
> > > Cc: Song Liu <songliubraving@fb.com>
> > > Cc: Yonghong Song <yhs@fb.com>
> > > Cc: <netdev@vger.kernel.org>
> > > Cc: <bpf@vger.kernel.org>
> > > ---
> >
> > Acked-by: Andrii Nakryiko <andriin@fb.com>
> 
> Acked-by: Song Liu <songliubraving@fb.com>

Applied, thank you both!

							Thanx, Paul

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

* Re: [PATCH tip/core/rcu 8/9] net/netfilter: Replace rcu_swap_protected() with rcu_replace()
  2019-10-03  1:43 ` [PATCH tip/core/rcu 8/9] net/netfilter: " paulmck
@ 2019-10-08 14:16   ` Pablo Neira Ayuso
  2019-10-09 15:36     ` Paul E. McKenney
  0 siblings, 1 reply; 35+ messages in thread
From: Pablo Neira Ayuso @ 2019-10-08 14:16 UTC (permalink / raw)
  To: paulmck
  Cc: rcu, linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells,
	edumazet, fweisbec, oleg, joel, Jozsef Kadlecsik,
	Florian Westphal, David S. Miller, netfilter-devel, coreteam,
	netdev

On Wed, Oct 02, 2019 at 06:43:09PM -0700, paulmck@kernel.org wrote:
> From: "Paul E. McKenney" <paulmck@kernel.org>
> 
> This commit replaces the use of rcu_swap_protected() with the more
> intuitively appealing rcu_replace() as a step towards removing
> rcu_swap_protected().
> 
> Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
> Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> Cc: Pablo Neira Ayuso <pablo@netfilter.org>
> Cc: Jozsef Kadlecsik <kadlec@netfilter.org>
> Cc: Florian Westphal <fw@strlen.de>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: <netfilter-devel@vger.kernel.org>
> Cc: <coreteam@netfilter.org>
> Cc: <netdev@vger.kernel.org>

Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>

> ---
>  net/netfilter/nf_tables_api.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> index d481f9b..8499baf 100644
> --- a/net/netfilter/nf_tables_api.c
> +++ b/net/netfilter/nf_tables_api.c
> @@ -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);
> -- 
> 2.9.5
> 

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

* Re: [PATCH tip/core/rcu 8/9] net/netfilter: Replace rcu_swap_protected() with rcu_replace()
  2019-10-08 14:16   ` Pablo Neira Ayuso
@ 2019-10-09 15:36     ` Paul E. McKenney
  0 siblings, 0 replies; 35+ messages in thread
From: Paul E. McKenney @ 2019-10-09 15:36 UTC (permalink / raw)
  To: Pablo Neira Ayuso
  Cc: rcu, linux-kernel, mingo, jiangshanlai, dipankar, akpm,
	mathieu.desnoyers, josh, tglx, peterz, rostedt, dhowells,
	edumazet, fweisbec, oleg, joel, Jozsef Kadlecsik,
	Florian Westphal, David S. Miller, netfilter-devel, coreteam,
	netdev

On Tue, Oct 08, 2019 at 04:16:11PM +0200, Pablo Neira Ayuso wrote:
> On Wed, Oct 02, 2019 at 06:43:09PM -0700, paulmck@kernel.org wrote:
> > From: "Paul E. McKenney" <paulmck@kernel.org>
> > 
> > This commit replaces the use of rcu_swap_protected() with the more
> > intuitively appealing rcu_replace() as a step towards removing
> > rcu_swap_protected().
> > 
> > Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/
> > Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
> > Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> > Cc: Pablo Neira Ayuso <pablo@netfilter.org>
> > Cc: Jozsef Kadlecsik <kadlec@netfilter.org>
> > Cc: Florian Westphal <fw@strlen.de>
> > Cc: "David S. Miller" <davem@davemloft.net>
> > Cc: <netfilter-devel@vger.kernel.org>
> > Cc: <coreteam@netfilter.org>
> > Cc: <netdev@vger.kernel.org>
> 
> Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>

Applied, thank you!

							Thanx, Paul

> > ---
> >  net/netfilter/nf_tables_api.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
> > index d481f9b..8499baf 100644
> > --- a/net/netfilter/nf_tables_api.c
> > +++ b/net/netfilter/nf_tables_api.c
> > @@ -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);
> > -- 
> > 2.9.5
> > 

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

* Re: [PATCH tip/core/rcu 4/9] drivers/scsi: Replace rcu_swap_protected() with rcu_replace()
  2019-10-05 16:06     ` Paul E. McKenney
@ 2019-10-10  2:36       ` Martin K. Petersen
  0 siblings, 0 replies; 35+ messages in thread
From: Martin K. Petersen @ 2019-10-10  2:36 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: Martin K. Petersen, rcu, linux-kernel, mingo, jiangshanlai,
	dipankar, akpm, mathieu.desnoyers, josh, tglx, peterz, rostedt,
	dhowells, edumazet, fweisbec, oleg, joel, James E.J. Bottomley,
	linux-scsi


Paul,

> 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!

-- 
Martin K. Petersen	Oracle Linux Engineering

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

end of thread, back to index

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-03  1:41 [PATCH tip/core/rcu 0/9] Replace rcu_swap_protected() for v5.5 Paul E. McKenney
2019-10-03  1:43 ` [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace() paulmck
2019-10-03 16:35   ` Mathieu Desnoyers
2019-10-03 16:52     ` Paul E. McKenney
2019-10-03 17:21       ` Mathieu Desnoyers
2019-10-03 19:09         ` Paul E. McKenney
2019-10-03 19:14           ` Mathieu Desnoyers
2019-10-03  1:43 ` [PATCH tip/core/rcu 2/9] x86/kvm/pmu: Replace rcu_swap_protected() with rcu_replace() paulmck
2019-10-03 10:14   ` Paolo Bonzini
2019-10-05 16:11     ` Paul E. McKenney
2019-10-03  1:43 ` [PATCH tip/core/rcu 3/9] drivers/gpu: " paulmck
2019-10-03  1:43 ` [PATCH tip/core/rcu 4/9] drivers/scsi: " paulmck
2019-10-04  2:09   ` Martin K. Petersen
2019-10-05 16:06     ` Paul E. McKenney
2019-10-10  2:36       ` Martin K. Petersen
2019-10-03  1:43 ` [PATCH tip/core/rcu 5/9] fs/afs: " paulmck
2019-10-03  1:43 ` [PATCH tip/core/rcu 6/9] bpf/cgroup: " paulmck
2019-10-03 17:21   ` Andrii Nakryiko
2019-10-03 20:58     ` Song Liu
2019-10-05 16:11       ` Paul E. McKenney
2019-10-03  1:43 ` [PATCH tip/core/rcu 7/9] net/core: " paulmck
2019-10-03  1:43 ` [PATCH tip/core/rcu 8/9] net/netfilter: " paulmck
2019-10-08 14:16   ` Pablo Neira Ayuso
2019-10-09 15:36     ` Paul E. McKenney
2019-10-03  1:43 ` [PATCH tip/core/rcu 9/9] net/sched: " paulmck
2019-10-03  8:38 ` [PATCH tip/core/rcu 5/9] fs/afs: " David Howells
2019-10-05 16:10   ` Paul E. McKenney
2019-10-03  8:39 ` [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace() David Howells
2019-10-03 13:08   ` Steven Rostedt
2019-10-03 13:33     ` Paul E. McKenney
2019-10-03 13:41       ` Peter Zijlstra
2019-10-03 13:58         ` Paul E. McKenney
2019-10-03 14:01       ` Joel Fernandes
2019-10-03 16:31     ` Mathieu Desnoyers
2019-10-03 18:05       ` Peter Zijlstra

RCU Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/rcu/0 rcu/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 rcu rcu/ https://lore.kernel.org/rcu \
		rcu@vger.kernel.org rcu@archiver.kernel.org
	public-inbox-index rcu

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.rcu


AGPL code for this site: git clone https://public-inbox.org/ public-inbox