Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp3310887rdb; Thu, 16 Nov 2023 06:21:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFxMUKD4wCr8rg+kZqQCAdndbgGKYkmC2wZSkTCfEytvzH6eFexNlrevNmc7vHwKh/3ce3o X-Received: by 2002:a17:90a:a413:b0:280:a4a1:5d03 with SMTP id y19-20020a17090aa41300b00280a4a15d03mr2818260pjp.4.1700144501856; Thu, 16 Nov 2023 06:21:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700144501; cv=none; d=google.com; s=arc-20160816; b=SBmSK9sMlM4LxIfDk1Q6n3FblT5QsZ6Xx8uo2UcZKZ9Th0kzdLoUCbEJ+A3XV5Nu2w 5/EUYej1gbS0rsuNHomCMFqJehERpiUHQHgkL7/aiQP7h5u+vpfhHAL7io1UAKyXfBO+ 9NIFPv1PGJFIUa9VzGOL8MBfiwEuoTBv9C4NE2FvLz+oCVyEtaNx+WK45vTSDBqJXCVK 4frUCh20guRTh41aVSJvWjzYlHT1RopuOVX0cSh446TiFJQbBYuALX048REI930i+puK 3Qh3YGfOQ5Oi7jOx2MBGTouqlj7lhOcMR1VTx3dP964Fok9jpel5UPTEM2KHorW+3/Q5 +36w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=pxIHMy1jStSlXKk4rbe3EcR1OULcVtQOqDxTS1hZNME=; fh=D90zwDrWJJyU24uVp8gp+Akedeaevan3w+fCxixPiFs=; b=crDSh9BSnSnE95lW/ogmZ+8qVYg2HyWSok2qH1UysFE3Op4sI7mSN2lamVxktdGgRn CRF1gLw3ulOZxEmnBwgwS8MCinL5zPpZaRScwfPZGIUWiTD3dv7QO1KBWBeMcCHmZkCk /APsRgRXOhLBeVQDfr5Zp1AWF8alNsK4X7whyrXdG1BFp69EnyWFJSd2Bv/LulhaYFA+ 4C9uLXrL6aG9kJKDhEkcQUqmqtMZ7CVBad+hiQNlMJ+XCZSCRsaEuTVOI710ZgED2Wkj dWzWeApS1zDpnGhZ5Cj+PXoOYAuJEYwrG5temBagNvBKglSVyWS9o9MwajtLUCT96nZH tjcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Me+uTHYC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id i3-20020a17090acf8300b00280a4766ed4si2144058pju.135.2023.11.16.06.21.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 06:21:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Me+uTHYC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 05408803416B; Thu, 16 Nov 2023 06:21:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234300AbjKPOVI (ORCPT + 99 others); Thu, 16 Nov 2023 09:21:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231230AbjKPOVH (ORCPT ); Thu, 16 Nov 2023 09:21:07 -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 5F5B098 for ; Thu, 16 Nov 2023 06:21:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700144462; 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: in-reply-to:in-reply-to:references:references; bh=pxIHMy1jStSlXKk4rbe3EcR1OULcVtQOqDxTS1hZNME=; b=Me+uTHYCgxFhpFueKUIfISAFFGnvLJTXvOH9Wwfm8LkuoVISf3xIuzSD9Z+bc/HUtBxHBP IfsKxIlh2TjV3tzSFhddRtEuedDnT/dOLyXcSprXwdShb4P3+vxJ1F+bCfmdeAFNStVY+n Ohvl6jku6jqV06VW6LBNQw5Y4eWErIM= 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-113-DhZgHQikMbqcUie3tF82xw-1; Thu, 16 Nov 2023 09:20:59 -0500 X-MC-Unique: DhZgHQikMbqcUie3tF82xw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 828F1185A788; Thu, 16 Nov 2023 14:20:58 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.226.23]) by smtp.corp.redhat.com (Postfix) with SMTP id 3AC2BC15881; Thu, 16 Nov 2023 14:20:56 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 16 Nov 2023 15:19:54 +0100 (CET) Date: Thu, 16 Nov 2023 15:19:51 +0100 From: Oleg Nesterov To: David Howells Cc: Marc Dionne , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Al Viro , Chuck Lever , linux-afs@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] rxrpc_find_service_conn_rcu: use read_seqbegin() rather than read_seqbegin_or_lock() Message-ID: <20231116141951.GE18748@redhat.com> References: <20231116131849.GA27763@redhat.com> <20231027095842.GA30868@redhat.com> <104932.1700142106@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <104932.1700142106@warthog.procyon.org.uk> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Spam-Status: No, score=-1.0 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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 16 Nov 2023 06:21:39 -0800 (PST) On 11/16, David Howells wrote: > > Oleg Nesterov wrote: > > > So do you agree that > > > > - the usage of read_seqbegin_or_lock/need_seqretry in > > this code makes no sense because read_seqlock_excl() > > is not possible > > Not exactly. I think it should take a lock on the second pass. OK, then how about the patch below? Again, I'd prefer to change the semantics/prototype of need_seqretry() to enforce the locking on the 2nd pass "automatically", but a) this needs more discussion and b) I can't do this before I update the users which use read_seqbegin_or_lock/need_seqretry incorrectly. So lets discuss this later. Oleg. --- 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);