From patchwork Thu Oct 26 14:50:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleg Nesterov X-Patchwork-Id: 158577 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp733245vqb; Thu, 26 Oct 2023 07:52:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHyfwbHh584Folc4plFNHYkVgXp2yZpnz2cTtscQe9leclh+ObNlMirS7m9/LBRHwfhnpyu X-Received: by 2002:a25:7711:0:b0:da0:c938:c79f with SMTP id s17-20020a257711000000b00da0c938c79fmr694597ybc.38.1698331955289; Thu, 26 Oct 2023 07:52:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698331955; cv=none; d=google.com; s=arc-20160816; b=es4RtlXulwkKiksEac+M9EiXDjoooPXUjICfjR3ZuabXf6ii9JhUG/m0I6T/vi0zAp Zs/kgcUIYAQt6U2pnuV3tffaLm5EFmc1JRSxcfGTb2NC4n9CpaNZ8M8Cb/8o4u132sXB waJMLt7fl2Xa7LQB8pQ1DuoWZG0DTQs7Tl6eVXYft65f9weKsArtxDt5Loj+3naGfLiK BZweWObNdKbCfIcCgQI//9nhwT6Z0Iorojz6GL1nJWdwtlPIolqCEE+cdko0p+eW/9ai Bh3sGXcj0IayAXC25u/7JguHkYqx98ZDFbVIu/22HJ6UJq3RvsjLPZ6B7wT/bBl/lFwF XPxA== 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=4TQBD4l/5fg4IXQrIfGCOPl59M/3gquDSBE20dW3+18=; fh=l3TcJes1ZJbvn7bz6RFEf1e+z+cg6o5cTNKBJCH6J18=; b=l8EpTk3ZUQFGVQMle+HYe4MkJyApbnbJkYQCnLqFvN7hiW9FMjhxqM6ocU2XZGlzeK PxtOS7TYPFsJk76oEzxSrD6oBfK1xjIj/Fb3jG5U0E/Q6t39u0WBOIDOjZNmRkaVPgPk uMxdH4CL2A0CekCxGOEpsQavna/VxqBDtrDMjChaCNtRhub9Vhxv+sTb0S2J2/cSGp57 9HBlwlojEorn02iqOq95IMk7LovjbU5chGY3Ayjd4KnlEwJK6Y8fH+eAXzTzNr6IgGJ5 HEVsxieCm8/Czwd8AyjJW9+gOin8r1Bac4wRSOMHLstyz//wZZ0GhfrCUzDwZaVoPyk6 cD8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aYimpSlr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id i131-20020a256d89000000b00d90c8844983si13300770ybc.481.2023.10.26.07.52.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 07:52:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aYimpSlr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 46B2981CC860; Thu, 26 Oct 2023 07:52:34 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345366AbjJZOwT (ORCPT + 26 others); Thu, 26 Oct 2023 10:52:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345326AbjJZOwR (ORCPT ); Thu, 26 Oct 2023 10:52:17 -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 2801E1B1 for ; Thu, 26 Oct 2023 07:51:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698331887; 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=4TQBD4l/5fg4IXQrIfGCOPl59M/3gquDSBE20dW3+18=; b=aYimpSlrqeruibpY11plRLdWNArAhIdeW0SEcYKdRU+I1KlM0Wk7bH7NkL9v0UbYCmuMHk v3pQ1PVAMsxSS7TvABtl/V6Uv3DlQzs0hymEjt4qAdfcWe2lUnOfmmY3rCy7vtMzCAXCS6 DCdehxnkSl+Elz0ldrKRFFvhiM7pqic= 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-577-Fi9T2LYyO2aZ3E8vZX5ciw-1; Thu, 26 Oct 2023 10:51:22 -0400 X-MC-Unique: Fi9T2LYyO2aZ3E8vZX5ciw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 AF63628237D1; Thu, 26 Oct 2023 14:51:21 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.21]) by smtp.corp.redhat.com (Postfix) with SMTP id 9EF121C060AE; Thu, 26 Oct 2023 14:51:19 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 26 Oct 2023 16:50:21 +0200 (CEST) Date: Thu, 26 Oct 2023 16:50:18 +0200 From: Oleg Nesterov To: Chuck Lever , Jeff Layton , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey Cc: Ingo Molnar , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] nfsd_copy_write_verifier: use read_seqbegin() rather than read_seqbegin_or_lock() Message-ID: <20231026145018.GA19598@redhat.com> References: <20231025163006.GA8279@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20231025163006.GA8279@redhat.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Thu, 26 Oct 2023 07:52:34 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780830128398706220 X-GMAIL-MSGID: 1780830128398706220 The usage of read_seqbegin_or_lock() in nfsd_copy_write_verifier() is wrong. "seq" is always even and thus "or_lock" has no effect, this code can never take ->writeverf_lock for writing. I guess this is fine, nfsd_copy_write_verifier() just copies 8 bytes and nfsd_reset_write_verifier() is supposed to be very rare operation so we do not need the adaptive locking in this case. Yet the code looks wrong and sub-optimal, it can use read_seqbegin() without changing the behaviour. Signed-off-by: Oleg Nesterov Reviewed-by: Jeff Layton Reviewed-by: NeilBrown --- fs/nfsd/nfssvc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c index c7af1095f6b5..094b765c5397 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; + unsigned seq; do { - read_seqbegin_or_lock(&nn->writeverf_lock, &seq); + seq = read_seqbegin(&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_seqretry(&nn->writeverf_lock, seq)); } static void nfsd_reset_write_verifier_locked(struct nfsd_net *nn)