Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1470296rdh; Fri, 27 Oct 2023 15:52:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHmWWNztuMZ/ShOxzM8m169LYuWfVTUoemy1vzH78tLx0+QwCBxdNWm6Wr/NVvovvUmuuYl X-Received: by 2002:a17:90a:2a4b:b0:262:f449:4497 with SMTP id d11-20020a17090a2a4b00b00262f4494497mr4111334pjg.2.1698447156238; Fri, 27 Oct 2023 15:52:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698447156; cv=none; d=google.com; s=arc-20160816; b=lvJmYNjJPa4aMsBjfelkED406D7AYMoikXwyzNU+c9Spc0XG5KVQzC/O4jff9LC8TS sEsDJWGWcoqbLXwSPB6G/HtejvlsG5hrSkOAN8MftX63DZWsTABDt1srav/5YLNt3w1W dPJPzj+08+bV9tzmRN8fro7PaN0yh7lR5ymc4g9Gw3xqBtd59vYWD/bf9UGXHo4XhRNQ SrI9rh3jsDZyV11BcU0mTZitEuDb3sQF5YDpQa79pLP8u85kyo8+/rCi159cH1HUAbWs Tiic9Etv9ADbkUT4mlKLy++kvhEeC/D1u7+oRuJHnlAz2UWMRi6VtqQabN7O8iH4hGFL AipQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:references:in-reply-to:subject :cc:to:from:mime-version:content-transfer-encoding:dkim-signature :dkim-signature; bh=omRuHwL6dEn0kqkZMYcSf7jMW/KbFdLyh/lKeGTZ3o4=; fh=yIA6T42IFzdJPEePRdsmJCXFsvGIGHHVG+/pfhTxCX4=; b=mMyU13J8OjtvaQbdJioadMBTJPLzAC2ovFrzLiXzkCTWkMpnTRo3lxPaoi9FrvIttF 3pvoEU5WSHjXPbqFYisNIa5rX0tFIfyQnBWVZZczSMqK01lQaZxzdBngnHmrOFjOT4rW RjH2Msv4YXrUSUTwuAemlb40+semYkOcWrH5VRa0yDpJEd8DP5SUAeHB4wXHT/JCoyTj bsbBWoX5BLsjyLcd8+DEArgv3NthopMOilR18MHBU1ZZ8hqqRlQi44W31LAhHGCvsxIE 57ebcpm87Dbvp4MsfHYxPP0ZqMbsClBwVaoAqpaUQAE3yL5LU63fkykcXD2nM/g94GrS 10Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=E7jUejb+; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=fq7O0bXM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id p15-20020a17090a0e4f00b0027b15e572c2si3510048pja.21.2023.10.27.15.52.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 15:52:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=E7jUejb+; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=fq7O0bXM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id BE86A849FA71; Fri, 27 Oct 2023 15:52:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235153AbjJ0WwW (ORCPT + 99 others); Fri, 27 Oct 2023 18:52:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232770AbjJ0WwU (ORCPT ); Fri, 27 Oct 2023 18:52:20 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70A8A1B6; Fri, 27 Oct 2023 15:52:13 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 0E2601FEF5; Fri, 27 Oct 2023 22:52:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1698447132; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=omRuHwL6dEn0kqkZMYcSf7jMW/KbFdLyh/lKeGTZ3o4=; b=E7jUejb+HWyZmM4Qf5L/9K9ECtYnwhEpFWbRxJFPx5lj7ixXmk+PEzQHuhx4k962PuBXna xjMn1KaclsVYh4kIS9lvl2NmJYoVFYN0s8LaLMkWraKGPyTGmOwyl9xMKm2G1V0nzDi5eE TeJH0X+53FJM0fYI0U4Xp4pyC96rwV0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1698447132; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=omRuHwL6dEn0kqkZMYcSf7jMW/KbFdLyh/lKeGTZ3o4=; b=fq7O0bXM9HXoMJ2jvAl9yGNwLPxGpkmKuF2riOEoimI80+JokjMUoX7PzUORwHMiGgos0B MkZwiglixLuRK2BA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D8F0613524; Fri, 27 Oct 2023 22:52:08 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id fKd0Ihg/PGWPRgAAMHmgww (envelope-from ); Fri, 27 Oct 2023 22:52:08 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 From: "NeilBrown" To: "Oleg Nesterov" Cc: "Chuck Lever" , "Jeff Layton" , "Olga Kornievskaia" , "Dai Ngo" , "Tom Talpey" , "Ingo Molnar" , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] nfsd_copy_write_verifier: use read_seqbegin() rather than read_seqbegin_or_lock() In-reply-to: <20231026145018.GA19598@redhat.com> References: <20231025163006.GA8279@redhat.com>, <20231026145018.GA19598@redhat.com> Date: Sat, 28 Oct 2023 09:52:05 +1100 Message-id: <169844712523.20306.8210786436807794776@noble.neil.brown.name> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Fri, 27 Oct 2023 15:52:33 -0700 (PDT) On Fri, 27 Oct 2023, Oleg Nesterov wrote: > 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. Wow! read_seqbegin_or_lock() has never locked since Commit: 88a411c07b6f ("seqlock: livelock fix") in Linux v2.6.26 (2008). That's rather embarrassing. I agree we don't need the lock on the read-side for nfsd. Reviewed-by: NeilBrown NeilBrown > > Signed-off-by: Oleg Nesterov > --- > 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) > -- > 2.25.1.362.g51ebf55 > > >