netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rxrpc_find_service_conn_rcu: use read_seqbegin() rather than read_seqbegin_or_lock()
@ 2023-10-27  9:58 Oleg Nesterov
  2023-10-27 10:00 ` Oleg Nesterov
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Oleg Nesterov @ 2023-10-27  9:58 UTC (permalink / raw)
  To: David Howells, Marc Dionne, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Chuck Lever, linux-afs, netdev, linux-kernel

read_seqbegin_or_lock() makes no sense unless you make "seq" odd
after the lockless access failed. See thread_group_cputime() as
an example, note that it does nextseq = 1 for the 2nd round.

So this code can use read_seqbegin() without changing the current
behaviour.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 net/rxrpc/conn_service.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/net/rxrpc/conn_service.c b/net/rxrpc/conn_service.c
index 89ac05a711a4..bfafe58681d9 100644
--- a/net/rxrpc/conn_service.c
+++ b/net/rxrpc/conn_service.c
@@ -25,7 +25,7 @@ struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *peer,
 	struct rxrpc_conn_proto k;
 	struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
 	struct rb_node *p;
-	unsigned int seq = 0;
+	unsigned int seq;
 
 	k.epoch	= sp->hdr.epoch;
 	k.cid	= sp->hdr.cid & RXRPC_CIDMASK;
@@ -35,7 +35,7 @@ struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *peer,
 		 * under just the RCU read lock, so we have to check for
 		 * changes.
 		 */
-		read_seqbegin_or_lock(&peer->service_conn_lock, &seq);
+		seq = read_seqbegin(&peer->service_conn_lock);
 
 		p = rcu_dereference_raw(peer->service_conns.rb_node);
 		while (p) {
@@ -49,9 +49,8 @@ struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *peer,
 				break;
 			conn = NULL;
 		}
-	} while (need_seqretry(&peer->service_conn_lock, seq));
+	} while (read_seqretry(&peer->service_conn_lock, seq));
 
-	done_seqretry(&peer->service_conn_lock, seq);
 	_leave(" = %d", conn ? conn->debug_id : -1);
 	return conn;
 }
-- 
2.25.1.362.g51ebf55



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

end of thread, other threads:[~2023-11-16 15:08 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-27  9:58 [PATCH] rxrpc_find_service_conn_rcu: use read_seqbegin() rather than read_seqbegin_or_lock() Oleg Nesterov
2023-10-27 10:00 ` Oleg Nesterov
2023-11-01 15:45 ` David Howells
2023-11-01 20:23   ` Oleg Nesterov
2023-11-01 20:40     ` Oleg Nesterov
2023-11-01 21:22       ` David Howells
2023-11-01 22:38         ` Oleg Nesterov
2023-11-01 20:52     ` Al Viro
2023-11-01 21:52       ` Oleg Nesterov
2023-11-01 22:48         ` Al Viro
2023-11-01 23:17           ` Oleg Nesterov
2023-11-01 21:20     ` David Howells
2023-11-01 22:15       ` Oleg Nesterov
2023-11-01 22:29         ` Oleg Nesterov
2023-11-16 13:18 ` Oleg Nesterov
2023-11-16 13:41   ` David Howells
2023-11-16 14:19     ` Oleg Nesterov
2023-11-16 15:02       ` David Howells
2023-11-16 15:06         ` Oleg Nesterov

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