Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp294323iob; Fri, 13 May 2022 01:44:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNtzwq7Na+PcEG4rdkL+8uiaeLB1ueClgOjHVpyRx+3xInoLB+JBcnPjebCE+jYi2S3Fkc X-Received: by 2002:a17:907:169f:b0:6f4:2a57:e1c4 with SMTP id hc31-20020a170907169f00b006f42a57e1c4mr3432490ejc.490.1652431449282; Fri, 13 May 2022 01:44:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652431449; cv=none; d=google.com; s=arc-20160816; b=IjlPAk4J9o5F1GKfQwAS8zNEhEpSmNIdoivBCH2w7KWpyiYpFFwaBUIp10qX3DiHRY k5iqiFePmMo9+/EMSB8cUt70jqe6MyrgnS+0T1S2LNDHpyfZ3l0/bxvWTBoc+UnoPk5X sLigq7l83vjkX8N20Mxwa4a7IQZavC1hpHFNLr7vUX8ivvlE5ZM5k3TJf8vzmyJpP535 ZIcrwSORy0y0GTRDky3pnco6frHb5HDkWjpneh25zCK+eX6soxuKEJ0+VZ2dwKbTNVGM znjBSTzsmvh/PUVcXBw9mgnMoJNMEikbpIEg8PAD2n76WsJ5OXd3LdBx/+m2OBe5NoVO aeCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=R3b33V4KBr+OrqnqliMan9aY9CziFpRIWpp3d5JkrO0=; b=K2SSkiIJzBplHGcEq8z078D/DW9M13Llij3YrKG/KoGaiFFynK9bD4UjcN9RNYJlED 2K6NY9ty7JHCzrS9wzjs+lIhAtBXRnqnsSyrx0SJYwEQV7oSU2c2qidJwvQqECI+ERee KUH9JLN7ystQ2Tu3Op1qfe4MQgMgd6q39OOVo2ftYmfGlOC4KBn14UMfrwrPcBwyUVDG M1ty9cU8CD1AxsOu7To/zI1/pcek9AZlgBfFyegRSZfps2yd7GaCLVhBVMssJwcTXAu6 yP///B1WLM2y9LDTmg53GvE82rI1zIRXE/xDOH8ESvh4SxBmzBmv0dqnMWnfJKlkOXDF vuzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZqQr0k5x; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c8-20020aa7d608000000b00418c2b5bdaesi1222830edr.144.2022.05.13.01.43.34; Fri, 13 May 2022 01:44:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZqQr0k5x; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351990AbiELKHg (ORCPT + 99 others); Thu, 12 May 2022 06:07:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345766AbiELKHf (ORCPT ); Thu, 12 May 2022 06:07:35 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5E1EF36334 for ; Thu, 12 May 2022 03:07:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652350052; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R3b33V4KBr+OrqnqliMan9aY9CziFpRIWpp3d5JkrO0=; b=ZqQr0k5xFfPh2ArYMLMOyc7d/OTB/OLEjVdjIwVcduDjrsZ9Tn+q4LrfNl1N/KavWYmILS bGXXuIC02yRqlMInkFNKtkkt0z3JdeEiFEeVeChKtit1bCgVe68QQ6+T50CDqELxm24TwA FaimbmKdxCVzDeZND3RnRJsoA5jxAdA= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-444-QH6h7q-FMzG_P2ragEjEYg-1; Thu, 12 May 2022 06:07:31 -0400 X-MC-Unique: QH6h7q-FMzG_P2ragEjEYg-1 Received: by mail-qt1-f200.google.com with SMTP id ay35-20020a05622a22a300b002f3fdcb1bb1so259081qtb.8 for ; Thu, 12 May 2022 03:07:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=R3b33V4KBr+OrqnqliMan9aY9CziFpRIWpp3d5JkrO0=; b=CQoTr5v2WG+/nHJBwg9eZyE0ECbPYejQNCwaQFPpQlVqaoZeRmhjcyPP3sOb0eI9TJ 8kksGLD3ar2ete23PpQTvQKPe4c8C6vlxYWRVuk52JaYIXPd/NJ5LHtfZIyMV4TQ5R4p xmTK4r1oujuT+gurO0PImP3PgTlGsJkZ/KMiP/Q6IZg59m5Ua7/Mpf7ppfiVmDdAnGyp qY8fE7TvZUJy46TbuujjLQjB25R3GOGnmKNnWN/hIdW4mbqvt5v2BCLl8Vte9sjZ/xF+ qfPQ6oTRMCf3S14MctnrvWI54SBECEbUm9graP5HPfjO1kk8EVeEhf0vDfOlR3eXzgFh vVoA== X-Gm-Message-State: AOAM533E8XIK7yFcpjz6pTDDcv14PlZFjp3qsXYzgnEefbPu47X/6Cqh e9cOdfxBZ9R+Fj9lsNeru0ST65z8N3Heyaoux2EYIBLnvyTAshVemJmLzZtCPkOVI/egZwofR2m FjXmHwAKjCsXJTEN6nkOo X-Received: by 2002:a05:6214:19c5:b0:45a:e0e5:d37b with SMTP id j5-20020a05621419c500b0045ae0e5d37bmr25643175qvc.100.1652350050912; Thu, 12 May 2022 03:07:30 -0700 (PDT) X-Received: by 2002:a05:6214:19c5:b0:45a:e0e5:d37b with SMTP id j5-20020a05621419c500b0045ae0e5d37bmr25643163qvc.100.1652350050694; Thu, 12 May 2022 03:07:30 -0700 (PDT) Received: from [192.168.1.3] (68-20-15-154.lightspeed.rlghnc.sbcglobal.net. [68.20.15.154]) by smtp.gmail.com with ESMTPSA id m15-20020a05620a13af00b0069fe7f77e4bsm2718991qki.33.2022.05.12.03.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 03:07:30 -0700 (PDT) Message-ID: <8e19f02252305f718c104d21ff1910c13eee437b.camel@redhat.com> Subject: Re: [PATCH RFC 1/2] NFSD: nfsd4_release_lockowner() should drop clp->cl_lock sooner From: Jeff Layton To: Chuck Lever , linux-nfs@vger.kernel.org Cc: trondmy@hammerspace.com, bfields@fieldses.org, dai.ngo@oracle.com Date: Thu, 12 May 2022 06:07:29 -0400 In-Reply-To: <165230597191.5906.5961060184718742042.stgit@klimt.1015granger.net> References: <165230584037.5906.5496655737644872339.stgit@klimt.1015granger.net> <165230597191.5906.5961060184718742042.stgit@klimt.1015granger.net> Content-Type: text/plain; charset="ISO-8859-15" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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-nfs@vger.kernel.org On Wed, 2022-05-11 at 17:52 -0400, Chuck Lever wrote: > nfsd4_release_lockowner() mustn't hold clp->cl_lock when > check_for_locks() invokes nfsd_file_put(), which can sleep. > > Reported-by: Dai Ngo > Signed-off-by: Chuck Lever > Cc: > --- > fs/nfsd/nfs4state.c | 56 +++++++++++++++++++++++---------------------------- > 1 file changed, 25 insertions(+), 31 deletions(-) > > diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c > index 234e852fcdfa..e2eb6d031643 100644 > --- a/fs/nfsd/nfs4state.c > +++ b/fs/nfsd/nfs4state.c > @@ -6611,8 +6611,8 @@ nfs4_set_lock_denied(struct file_lock *fl, struct nfsd4_lock_denied *deny) > deny->ld_type = NFS4_WRITE_LT; > } > > -static struct nfs4_lockowner * > -find_lockowner_str_locked(struct nfs4_client *clp, struct xdr_netobj *owner) > +static struct nfs4_stateowner * > +find_stateowner_str_locked(struct nfs4_client *clp, struct xdr_netobj *owner) > { > unsigned int strhashval = ownerstr_hashval(owner); > struct nfs4_stateowner *so; > @@ -6624,11 +6624,22 @@ find_lockowner_str_locked(struct nfs4_client *clp, struct xdr_netobj *owner) > if (so->so_is_open_owner) > continue; > if (same_owner_str(so, owner)) > - return lockowner(nfs4_get_stateowner(so)); > + return nfs4_get_stateowner(so); > } > return NULL; > } > > +static struct nfs4_lockowner * > +find_lockowner_str_locked(struct nfs4_client *clp, struct xdr_netobj *owner) > +{ > + struct nfs4_stateowner *so; > + > + so = find_stateowner_str_locked(clp, owner); > + if (!so) > + return NULL; > + return lockowner(so); > +} > + > static struct nfs4_lockowner * > find_lockowner_str(struct nfs4_client *clp, struct xdr_netobj *owner) > { > @@ -7305,10 +7316,8 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp, > struct nfsd4_release_lockowner *rlockowner = &u->release_lockowner; > clientid_t *clid = &rlockowner->rl_clientid; > struct nfs4_stateowner *sop; > - struct nfs4_lockowner *lo = NULL; > + struct nfs4_lockowner *lo; > struct nfs4_ol_stateid *stp; > - struct xdr_netobj *owner = &rlockowner->rl_owner; > - unsigned int hashval = ownerstr_hashval(owner); > __be32 status; > struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); > struct nfs4_client *clp; > @@ -7322,32 +7331,18 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp, > return status; > > clp = cstate->clp; > - /* Find the matching lock stateowner */ > spin_lock(&clp->cl_lock); > - list_for_each_entry(sop, &clp->cl_ownerstr_hashtbl[hashval], > - so_strhash) { > - > - if (sop->so_is_open_owner || !same_owner_str(sop, owner)) > - continue; > - > - /* see if there are still any locks associated with it */ > - lo = lockowner(sop); > - list_for_each_entry(stp, &sop->so_stateids, st_perstateowner) { > - if (check_for_locks(stp->st_stid.sc_file, lo)) { > - status = nfserr_locks_held; > - spin_unlock(&clp->cl_lock); > - return status; > - } > - } > + sop = find_stateowner_str_locked(clp, &rlockowner->rl_owner); > + spin_unlock(&clp->cl_lock); > + if (!sop) > + return nfs_ok; > > - nfs4_get_stateowner(sop); > - break; > - } > - if (!lo) { > - spin_unlock(&clp->cl_lock); > - return status; > - } > + lo = lockowner(sop); > + list_for_each_entry(stp, &sop->so_stateids, st_perstateowner) > + if (check_for_locks(stp->st_stid.sc_file, lo)) > + return nfserr_locks_held; > It has been a while since I was in this code, but is it safe to walk the above list without holding the cl_lock? > + spin_lock(&clp->cl_lock); > unhash_lockowner_locked(lo); > while (!list_empty(&lo->lo_owner.so_stateids)) { > stp = list_first_entry(&lo->lo_owner.so_stateids, > @@ -7360,8 +7355,7 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp, > free_ol_stateid_reaplist(&reaplist); > remove_blocked_locks(lo); > nfs4_put_stateowner(&lo->lo_owner); > - > - return status; > + return nfs_ok; > } > > static inline struct nfs4_client_reclaim * > > -- Jeff Layton