Received: by 10.223.176.46 with SMTP id f43csp913117wra; Wed, 24 Jan 2018 07:47:52 -0800 (PST) X-Google-Smtp-Source: AH8x224QtZu9r8TBOEw+2xypG65LZqM7pAgGXlZ6xoFQArYlbpF6YvYgsbpxgdii7rC/mh1tuboO X-Received: by 2002:a17:902:125:: with SMTP id 34-v6mr8735013plb.54.1516808872451; Wed, 24 Jan 2018 07:47:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516808872; cv=none; d=google.com; s=arc-20160816; b=N5h+CmKxEIXaxEPCfDJoeFhBXWhoEU5w+/eIyMiV/CmQuRQ1yIssT+sr/k0Igt/7ou mE71Xzd+iY7EDBi/QBV5xK7Au7bo4Kf89F6xaVoiI9ZyHy6zRcMNG/LUmMpJMzufFyv3 0XpWw64leXv8l6VR+TfoTkl5AJlWl5GOvs++Rx23VqJ2UV4YQSnKqoVgJlKzc7rsttVe OBsqOBMNwGXk7Gvw9BQqNfKwCx0yJ5N6ETqP+fEH3MCvl8mQox27pJVP5Z8daa9OKso4 SwKSDmPJJQEXwd7dO6UKV7+7/1Ly0iq1XYSa1YTEhXp3jq8lxgQm9u9M58/04ZWHBuMQ +C6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=RYBMKoAZcLT/h7mpkXKR8Q4Qaliu8adEN2DFstDb4gc=; b=eJgh6SQGY0/xoSIEU4/jV47Ktl5sQ1CClSICoW1zVlu1L349i1PPx97Gvnv8SqSBTF kn3pNXLxJVLcfEfNvOqC5l0PsPp92MjYpUyn/0scEEsH3fD7sKckGXkXp7/iRXDiUhFL PqEYIG1TKIzN4ENN76dvW3t0QKEH+O4RI7kaqqdoAIK90EqMyR7W7AVJB66/fyojaZgE 77MD2xj1DxN6KGKi0Riz5oBMhPaHJL7l5ExrgWgot6T/Ywtc4ti5KRYrPfnBy9GMl5TA TxAKMfvZPGJrkPhmjU8xtTC5Q1CABqhj54KTuNxE7PptNax7DGRJIz21R4TmGD+4Vi01 JuLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b4-v6si362091plr.799.2018.01.24.07.47.38; Wed, 24 Jan 2018 07:47:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934275AbeAXPrN (ORCPT + 99 others); Wed, 24 Jan 2018 10:47:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:12383 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934121AbeAXPrL (ORCPT ); Wed, 24 Jan 2018 10:47:11 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 50778D715B; Wed, 24 Jan 2018 15:47:11 +0000 (UTC) Received: from parsley.fieldses.org (ovpn-117-83.phx2.redhat.com [10.3.117.83]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24D5A1713A; Wed, 24 Jan 2018 15:47:11 +0000 (UTC) Received: by parsley.fieldses.org (Postfix, from userid 2815) id 069331827F1; Wed, 24 Jan 2018 10:47:09 -0500 (EST) Date: Wed, 24 Jan 2018 10:47:09 -0500 From: "J. Bruce Fields" To: Sasha Levin Cc: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" , Trond Myklebust Subject: Re: [PATCH AUTOSEL for 4.14 057/100] nfsd: Ensure we don't recognise lock stateids after freeing them Message-ID: <20180124154709.GB31619@parsley.fieldses.org> References: <20180124041414.32065-1-alexander.levin@microsoft.com> <20180124041414.32065-57-alexander.levin@microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180124041414.32065-57-alexander.levin@microsoft.com> User-Agent: Mutt/1.9.1 (2017-09-22) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 24 Jan 2018 15:47:11 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Chuck Lever found this caused a regression, and Trond's fix hasn't hit Linus's tree yet. --b. On Wed, Jan 24, 2018 at 04:14:53AM +0000, Sasha Levin wrote: > From: Trond Myklebust > > [ Upstream commit 659aefb68eca28ba9aa482a9fc64de107332e256 ] > > In order to deal with lookup races, nfsd4_free_lock_stateid() needs > to be able to signal to other stateful functions that the lock stateid > is no longer valid. Right now, nfsd_lock() will check whether or not an > existing stateid is still hashed, but only in the "new lock" path. > > To ensure the stateid invalidation is also recognised by the "existing lock" > path, and also by a second call to nfsd4_free_lock_stateid() itself, we can > change the type to NFS4_CLOSED_STID under the stp->st_mutex. > > Signed-off-by: Trond Myklebust > Signed-off-by: J. Bruce Fields > Signed-off-by: Sasha Levin > --- > fs/nfsd/nfs4state.c | 19 ++++++++----------- > 1 file changed, 8 insertions(+), 11 deletions(-) > > diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c > index 61f38346ce9d..5ec0ca5cbc1e 100644 > --- a/fs/nfsd/nfs4state.c > +++ b/fs/nfsd/nfs4state.c > @@ -5099,7 +5099,9 @@ nfsd4_free_lock_stateid(stateid_t *stateid, struct nfs4_stid *s) > struct nfs4_ol_stateid *stp = openlockstateid(s); > __be32 ret; > > - mutex_lock(&stp->st_mutex); > + ret = nfsd4_lock_ol_stateid(stp); > + if (ret) > + goto out_put_stid; > > ret = check_stateid_generation(stateid, &s->sc_stateid, 1); > if (ret) > @@ -5110,11 +5112,13 @@ nfsd4_free_lock_stateid(stateid_t *stateid, struct nfs4_stid *s) > lockowner(stp->st_stateowner))) > goto out; > > + stp->st_stid.sc_type = NFS4_CLOSED_STID; > release_lock_stateid(stp); > ret = nfs_ok; > > out: > mutex_unlock(&stp->st_mutex); > +out_put_stid: > nfs4_put_stid(s); > return ret; > } > @@ -5683,6 +5687,8 @@ find_lock_stateid(struct nfs4_lockowner *lo, struct nfs4_file *fp) > lockdep_assert_held(&clp->cl_lock); > > list_for_each_entry(lst, &lo->lo_owner.so_stateids, st_perstateowner) { > + if (lst->st_stid.sc_type != NFS4_LOCK_STID) > + continue; > if (lst->st_stid.sc_file == fp) { > atomic_inc(&lst->st_stid.sc_count); > return lst; > @@ -5757,7 +5763,6 @@ lookup_or_create_lock_state(struct nfsd4_compound_state *cstate, > struct nfs4_lockowner *lo; > struct nfs4_ol_stateid *lst; > unsigned int strhashval; > - bool hashed; > > lo = find_lockowner_str(cl, &lock->lk_new_owner); > if (!lo) { > @@ -5780,15 +5785,7 @@ retry: > goto out; > } > > - mutex_lock(&lst->st_mutex); > - > - /* See if it's still hashed to avoid race with FREE_STATEID */ > - spin_lock(&cl->cl_lock); > - hashed = !list_empty(&lst->st_perfile); > - spin_unlock(&cl->cl_lock); > - > - if (!hashed) { > - mutex_unlock(&lst->st_mutex); > + if (nfsd4_lock_ol_stateid(lst) != nfs_ok) { > nfs4_put_stid(&lst->st_stid); > goto retry; > } > -- > 2.11.0