From patchwork Fri Nov 17 16:48:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 13459155 X-Patchwork-Delegate: kuba@kernel.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="e7xTGJqQ" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9865D56 for ; Fri, 17 Nov 2023 08:49:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700239793; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=2xHmGuoMtPQwOYwidrVH9fzqJ2yR9Z3MUz8VIv42SVo=; b=e7xTGJqQ9RiLrgf0hd62QdhwslokTC5+4WSySdL02Bp/Isa0yqfLns2Y63WEMf6DMaxV4y 01jkK7mOXMbWJBJJEPkiNs+5xkJ/qBCI0vvQxYz7htJBkTKCZ5eeiz7nK/DqY/lUI+WDfk aESTrxP9YDRr44UpNDcLfyATRhc7vro= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-549-eX82f_qrP5Kokjcude60UQ-1; Fri, 17 Nov 2023 11:49:52 -0500 X-MC-Unique: eX82f_qrP5Kokjcude60UQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4B205185A781; Fri, 17 Nov 2023 16:49:52 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.123]) by smtp.corp.redhat.com (Postfix) with SMTP id 0EE7B2166B27; Fri, 17 Nov 2023 16:49:50 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Fri, 17 Nov 2023 17:48:48 +0100 (CET) Date: Fri, 17 Nov 2023 17:48:46 +0100 From: Oleg Nesterov To: David Howells Cc: Al Viro , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] rxrpc_find_service_conn_rcu: fix the usage of read_seqbegin_or_lock() Message-ID: <20231117164846.GA10410@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Patchwork-Delegate: kuba@kernel.org rxrpc_find_service_conn_rcu() should make the "seq" counter odd on the second pass, otherwise read_seqbegin_or_lock() never takes the lock. Signed-off-by: Oleg Nesterov --- net/rxrpc/conn_service.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/rxrpc/conn_service.c b/net/rxrpc/conn_service.c index 89ac05a711a4..39c908a3ca6e 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 = 1; k.epoch = sp->hdr.epoch; k.cid = sp->hdr.cid & RXRPC_CIDMASK; @@ -35,6 +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. */ + seq++; /* 2 on the 1st/lockless path, otherwise odd */ read_seqbegin_or_lock(&peer->service_conn_lock, &seq); p = rcu_dereference_raw(peer->service_conns.rb_node);