Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2742214rda; Wed, 25 Oct 2023 10:57:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCk2rrxXW9uS/CuPDi0rkI+OaKSGJDsNw+IRxym227kXt3O/vOwzOMa82DVRZX1bgDRZJU X-Received: by 2002:a25:3d5:0:b0:d9b:81a2:b83e with SMTP id 204-20020a2503d5000000b00d9b81a2b83emr13573735ybd.46.1698256621436; Wed, 25 Oct 2023 10:57:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698256621; cv=none; d=google.com; s=arc-20160816; b=0l9DWx9TNEsInDLSjI2gpV7xrAVW6aDL5PhNNwKDAzicproz1zhd/3/39u0Sm+kZQ6 faXrKwx9i0K6zUvGddnKNf3vZ9Lmw2Xq6aL8f9ZjMuL1MvFU1se+G4PcV/pRQ/ehzZqd GDQkxoFWzmtffOkeiJYlwXc1n3Bf+eNVLTHTLxUqqdD3hNjcoWRmQYowzlExqtWisZiR MfJlbVomPiL9uLNMci3CQYRuHaDX0xvtIX6gTdDDUl+SNNy9rMqG1k8Jj4KoNQ8hRtb3 ANc3DnjJ8RQ01dy6hmplv4I2RnOyAce3NSY5LBjCbIOAWx5RFvh8BBqtQ7DCaBurqDEF iUcA== 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=bIO20jbXgSOplV2THMhTgaUzTr5RKxotR9SQLHD8dEQ=; fh=4PV+5Ng5rFMfFCXvEgStSaE3qZJmirZzcVKxhhh25Tw=; b=UZChtn7oFb1nj5wLbPW1UWs2r+ex2PzWt2kRm6KH8Vv3XzLCI7beRWyHCf4QgWfsFn w8F+Lk+rMNr/uNgJhiH9LJaW0bMu4t50NPhbNbQFDlPnsucRfV4FMfUiusO8h7zzYfLg mYApUV/nWwrJFTfxfL7IXNkotOmsFa5NnoYxxmoGXS7Xok5NsxH0bPxqsy/Gyh7JG+WB v+ycaVZget0bGxpgweSNIU0DhrtBFDPH5LkRNgiWwW+96GaHIK47H4UxyvZnvsfXzedt MqydSP5DZNbke2HzlV4kb60LlLVF3bx8rdEmZHRYGIRlJaB9BbWqs+dBW0rqvVMkeCPP Gffg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WFWe8HHH; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-nfs-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 n205-20020a25dad6000000b00d9ac304bb76si12083509ybf.449.2023.10.25.10.57.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 10:57:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-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=WFWe8HHH; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-nfs-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 7B69F80708A8; Wed, 25 Oct 2023 10:56:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234488AbjJYR4f (ORCPT + 99 others); Wed, 25 Oct 2023 13:56:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233980AbjJYR4f (ORCPT ); Wed, 25 Oct 2023 13:56:35 -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 9789813D for ; Wed, 25 Oct 2023 10:55:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698256546; 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=bIO20jbXgSOplV2THMhTgaUzTr5RKxotR9SQLHD8dEQ=; b=WFWe8HHHUfF89QzEwthouoVPE3goPNdL82v57o1Uu7/6EuvsATPXaEdij+nHkrWtmy9HWY GVEjGEoEuFIjJ1RafFDWUt/O6OEeTXTd17rPDcsgBoxP5KbPBQRfTp5sUx6bFmQNyHrAQQ ZhX4mZL8+z0Rp3z1YeSeLz3Rl/blndo= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-549-lk94h8FOMO-3VJ9NB-6cXA-1; Wed, 25 Oct 2023 13:55:40 -0400 X-MC-Unique: lk94h8FOMO-3VJ9NB-6cXA-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 8038729ABA0F; Wed, 25 Oct 2023 17:55:39 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.21]) by smtp.corp.redhat.com (Postfix) with SMTP id 73480C1596D; Wed, 25 Oct 2023 17:55:37 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Wed, 25 Oct 2023 19:54:38 +0200 (CEST) Date: Wed, 25 Oct 2023 19:54:36 +0200 From: Oleg Nesterov To: Chuck Lever Cc: Jeff Layton , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Ingo Molnar , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: nfsd_copy_write_verifier: wrong usage of read_seqbegin_or_lock() Message-ID: <20231025175435.GC29779@redhat.com> References: <20231025163006.GA8279@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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=-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 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-nfs@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, 25 Oct 2023 10:56:58 -0700 (PDT) On 10/25, Chuck Lever wrote: > > > Another question is why we can't simply turn nn->writeverf into seqcount_t. > > I guess we can't because nfsd_reset_write_verifier() needs spin_lock() to > > serialise with itself, right? > > "reset" is supposed to be very rare operation. Using a lock in that > case is probably quite acceptable, as long as reading the verifier > is wait-free and guaranteed to be untorn. > > But a seqcount_t is only 32 bits. Again, I don't understand you. Once again, we can turn writeverf into seqcount_t, see the patch below. But this way nfsd_reset_write_verifier() can race with itself, no? Oleg --- diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h index ec49b200b797..3e2adf3eb15f 100644 --- a/fs/nfsd/netns.h +++ b/fs/nfsd/netns.h @@ -110,7 +110,7 @@ struct nfsd_net { bool nfsd_net_up; bool lockd_up; - seqlock_t writeverf_lock; + seqcount_t writeverf_lock; unsigned char writeverf[8]; /* diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index 7ed02fb88a36..6320491018f8 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -1523,7 +1523,7 @@ static __net_init int nfsd_net_init(struct net *net) nn->nfsd4_minorversions = NULL; nfsd4_init_leases_net(nn); get_random_bytes(&nn->siphash_key, sizeof(nn->siphash_key)); - seqlock_init(&nn->writeverf_lock); + seqcount_init(&nn->writeverf_lock); return 0; diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c index c7af1095f6b5..fc4e31411508 100644 --- a/fs/nfsd/nfssvc.c +++ b/fs/nfsd/nfssvc.c @@ -359,13 +359,12 @@ static bool nfsd_needs_lockd(struct nfsd_net *nn) */ void nfsd_copy_write_verifier(__be32 verf[2], struct nfsd_net *nn) { - int seq = 0; + int seq; do { - read_seqbegin_or_lock(&nn->writeverf_lock, &seq); + seq = read_seqcount_begin(&nn->writeverf_lock); memcpy(verf, nn->writeverf, sizeof(nn->writeverf)); - } while (need_seqretry(&nn->writeverf_lock, seq)); - done_seqretry(&nn->writeverf_lock, seq); + } while (read_seqcount_retry(&nn->writeverf_lock, seq)); } static void nfsd_reset_write_verifier_locked(struct nfsd_net *nn) @@ -397,9 +396,9 @@ static void nfsd_reset_write_verifier_locked(struct nfsd_net *nn) */ void nfsd_reset_write_verifier(struct nfsd_net *nn) { - write_seqlock(&nn->writeverf_lock); + write_seqcount_begin(&nn->writeverf_lock); nfsd_reset_write_verifier_locked(nn); - write_sequnlock(&nn->writeverf_lock); + write_seqcount_end(&nn->writeverf_lock); } /*