Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp1005530rdb; Wed, 1 Nov 2023 08:46:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGTqOv4LxTabQbns/vAHv7VAhMDo1FM/2m2o8A/wdbNGRA5jeM1342q+LnQtz1F9hPEO7/k X-Received: by 2002:a05:6a20:729e:b0:181:7d6d:c0fa with SMTP id o30-20020a056a20729e00b001817d6dc0famr577442pzk.49.1698853611827; Wed, 01 Nov 2023 08:46:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698853611; cv=none; d=google.com; s=arc-20160816; b=D/f6iS9HiMgXA8AeqDFx6gRj+B0S4EC1xuMMgRtkGmLEt9xeALLMRyZa0tnFmR1f67 OVbp8z3Tc235OvK/Cigx7SVgAZcpOk+8BH3dpafAdUjIrXjOCPeEBbubatqu5/ZfqMey xWfgna1qayn/bZHBaFww8zpZklysXoq+/82I0lKlu9owSAa6pXBQ1vLpb4yVQdYiF3yG 9u60uhSfKDeWSCD5fZKia9cTkuPBJORwD9E9iSG0k/t2ys64VBH8tNDTLJQlTG6ym/r5 cYV53NbpXpqszM8/KG6zcjoY0LkgXw0GL3v+HjPcQHCuD38Qp8tqK0FY4QDPwLJ7fOGE 4DkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:content-id:mime-version:subject :cc:to:references:in-reply-to:from:organization:dkim-signature; bh=sZfmnba+tHGz8pqoH154foHS+YLTOXshRrCAdJjTAkk=; fh=6/wK4j2vSDrlMD05tXIaGPUVedfhUhDyb4A2QU17fA4=; b=zujg2I8W5hvakXTMCnfLEj8mDhm7Yujw5BOI6L/csCpIYKeT3LQ5nKZPTpGR5AIHKX VPsH0sDzl4QPrJJ9t4TZ6jpBZmOQC6rIjAYp47J7TSBhHJwXDEp921DXDmiMcIos5Pl1 NOKF3wfMoxodF4NOtVFgtEVTcCyfakEiMnOdkCEO6sLMeg7WTUKarrg+2XE78/Xd00V+ 3sB5e6QxOZQObP8UxO5m8SErQubgPPph7hK5Tofibi0J8Wfz0Gq/YvzgDF6APXv7s2ox vpqodeM9RDbxmKq9XtpFRx/3nwd3yBAP/1B2q6EK+7C4y7aBsZjKLjE68EO1OowZWVmH Bszw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fyYXbe5W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id le3-20020a170902fb0300b001c5e0672f53si3116917plb.466.2023.11.01.08.46.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 08:46:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fyYXbe5W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 5019B8038D4D; Wed, 1 Nov 2023 08:46:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234388AbjKAPqS (ORCPT + 99 others); Wed, 1 Nov 2023 11:46:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234846AbjKAPqK (ORCPT ); Wed, 1 Nov 2023 11:46:10 -0400 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 70662115 for ; Wed, 1 Nov 2023 08:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698853523; 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=sZfmnba+tHGz8pqoH154foHS+YLTOXshRrCAdJjTAkk=; b=fyYXbe5WhIy7TlCvLlDqCHtj1qr1uTDdUoAEMpr4cShCVYqLq+JR6aPXaTIlqGnqfJoUt+ sWXFp9f+Dp5QiCMw80TPWbdf9KEJu/d2DxLUXzb9d/atOZNfWUeeWvfTxElBKOlEVDx7iC LXjnPU/pGEGfHAemGyo6PmRoCuhr8+Q= 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-251-rUr5MMA-OZqMoERtx8pLZQ-1; Wed, 01 Nov 2023 11:45:20 -0400 X-MC-Unique: rUr5MMA-OZqMoERtx8pLZQ-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 69EB1811E88; Wed, 1 Nov 2023 15:45:19 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCFC1C1290F; Wed, 1 Nov 2023 15:45:17 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <20231027095842.GA30868@redhat.com> References: <20231027095842.GA30868@redhat.com> To: Oleg Nesterov Cc: dhowells@redhat.com, Marc Dionne , Alexander Viro , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , 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() MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1952181.1698853516.1@warthog.procyon.org.uk> Date: Wed, 01 Nov 2023 15:45:16 +0000 Message-ID: <1952182.1698853516@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Spam-Status: No, score=-1.3 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 01 Nov 2023 08:46:49 -0700 (PDT) Oleg Nesterov wrote: > read_seqbegin_or_lock() makes no sense unless you make "seq" odd > after the lockless access failed. I think you're wrong. write_seqlock() turns it odd. For instance, if the read lock is taken first: sequence seq CPU 1 CPU 2 ======= ======= =============================== =============== 0 0 0 seq = 0 // MUST BE EVEN ACCORDING TO DOC 0 0 read_seqbegin_or_lock() [lockless] ... 1 0 write_seqlock() 1 0 need_seqretry() [seq=even; sequence!=seq: retry] 1 1 read_seqbegin_or_lock() [exclusive] -->spin_lock(lock); 2 1 write_sequnlock() <--locked ... 2 1 need_seqretry() However, if the write lock is taken first: sequence seq CPU 1 CPU 2 ======= ======= =============================== =============== 0 1 write_seqlock() 1 0 seq = 0 // MUST BE EVEN ACCORDING TO DOC 1 0 read_seqbegin_or_lock() [lockless] 1 0 __read_seqcount_begin() while (lock.sequence is odd) cpu_relax(); 2 0 write_sequnlock() 2 2 [loop end] ... 2 2 need_seqretry() [seq=even; sequence==seq; done] Note that it spins in __read_seqcount_begin() until we get an even seq, indicating that no write is currently in progress - at which point we can perform a lockless pass. > See thread_group_cputime() as an example, note that it does nextseq = 1 for > the 2nd round. That's not especially convincing. David