Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5326127rdb; Wed, 13 Dec 2023 05:51:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGlk7Qz3Gml1Yo9ShCbPyg4GHCaoWiq5Tm114d2c5ga3QtAnX/FkC/PBYXPFWsGE++K1EL/ X-Received: by 2002:a17:902:e808:b0:1d1:c917:2e4f with SMTP id u8-20020a170902e80800b001d1c9172e4fmr4334370plg.107.1702475483811; Wed, 13 Dec 2023 05:51:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702475483; cv=none; d=google.com; s=arc-20160816; b=dg6bL9ZIZgiXKphXW4czIU8hlpFSeQX2xMK7aMjw7LTKqSn/usls6ntv2cRjKAx4qB Szdc5ATvFl9l9raGKpj/isxPLUmDoE8pvv5RS1n86PqYsNxUPOck5PmGDDUrfnyK46Pf VJ46oaefIibeFXnXWNrNWCvQb1I/VReMZVq2+FGS6uIez/ZDcnz2ZCZ2y0gUnY5+Pr6h y1SCBqnDXi419DTCEKoZC3Fsst7fcN1pZpsCPqSioHOLej6zkzVjDiVzAQZBdpPBDetZ MMe/z3TlpyQrG4LTFF9P+iPIDH5yuOBuAH385mjEIutwK54FEpVVwJtY+Tin1gJ/VeMx Ualw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Fp8oJm4LequRc2I331reI5U2x+5CwUONNx70HoBczl8=; fh=9eDgTo8aIuwg9MpGeudPwJT3CA93x8I1cKC8E1Wz3RU=; b=qrYk8J4vk0h1Qlvp54DmVG0A3LJYBhf52s7knh6sia5xs5Ns+u5LmroBNibNRCUqon j4HtuoNr3dy77QMbBkqSp9iVy5jlvBzaqmaYILBbhpm14+2syWaRfdkVjxJ0AkEt3Ty8 kWAngIsBvU+PsctpFsHI9P4ka9kUT3cF4diF5+gj9bHBEviUrTp94bo1YrUXwywNN0cf tEB6MAhu64olxiCik5fwaFLQ/mBElwj1La9zY+Taaww/TccxlRVjVJGFKMvZJ6SMdCZm j2DL89O/BaLVkymAHt6DCx3ppfo8Ozex4U1K3QeavPGIQRZxGeWodh905popXWRk+q0N WIzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BaUZwVQS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id ik20-20020a170902ab1400b001d3368b3dafsi2830517plb.621.2023.12.13.05.51.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 05:51:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BaUZwVQS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 6EA0280BA64E; Wed, 13 Dec 2023 05:51:09 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379150AbjLMNuS (ORCPT + 99 others); Wed, 13 Dec 2023 08:50:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379071AbjLMNuL (ORCPT ); Wed, 13 Dec 2023 08:50:11 -0500 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 A132FE3 for ; Wed, 13 Dec 2023 05:50:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702475416; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fp8oJm4LequRc2I331reI5U2x+5CwUONNx70HoBczl8=; b=BaUZwVQSF5gxpnMaw2AXd5O0FWyAjiokabcaC5UdjCtXv2GEqCKaVCEuA3TaVgtCo3ZWvr g3k7aPCPFFbhDS1C4CrgQTT1E1ERvQO4A12vMTGl9pMk9Y7J19D7dyPG4/i0ZaSCOngxoI EDzPbCsF8dU497uThuISMMOioydawiE= 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-611-1I_O80NHO8G-cTi2fnRfDQ-1; Wed, 13 Dec 2023 08:50:13 -0500 X-MC-Unique: 1I_O80NHO8G-cTi2fnRfDQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 6006B8C46C8; Wed, 13 Dec 2023 13:50:13 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76F7840C6EB9; Wed, 13 Dec 2023 13:50:12 +0000 (UTC) From: David Howells To: Marc Dionne Cc: David Howells , linux-afs@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Oleg Nesterov Subject: [PATCH v2 04/40] rxrpc_find_service_conn_rcu: fix the usage of read_seqbegin_or_lock() Date: Wed, 13 Dec 2023 13:49:26 +0000 Message-ID: <20231213135003.367397-5-dhowells@redhat.com> In-Reply-To: <20231213135003.367397-1-dhowells@redhat.com> References: <20231213135003.367397-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 13 Dec 2023 05:51:09 -0800 (PST) From: Oleg Nesterov 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 Signed-off-by: David Howells cc: Marc Dionne cc: linux-afs@lists.infradead.org Link: https://lore.kernel.org/r/20231117164846.GA10410@redhat.com/ --- 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);