From patchwork Mon Sep 26 16:38:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 12989134 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E714C6FA8E for ; Mon, 26 Sep 2022 17:24:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230462AbiIZRYH (ORCPT ); Mon, 26 Sep 2022 13:24:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231165AbiIZRXq (ORCPT ); Mon, 26 Sep 2022 13:23:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CFE1151DC8 for ; Mon, 26 Sep 2022 09:38:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 744ABB80B3C for ; Mon, 26 Sep 2022 16:38:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA798C433D6; Mon, 26 Sep 2022 16:38:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664210330; bh=salnlSZJRx/RgcK7N9RcDD7zm9apNgS7pq0wnLA5zxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d/twETVyQcAs+GmxLVkl2EMRxzqDxfPlwkgf5OvxR04N0eSsPftrc3cKDC44BTo/k 4/q2ERDvhTiGIqoOBAahTeJ2bQkE8doZJw54Ln4/PxegELUQobmDUwxrTNADCeSChq pN1gOXVQSrweAC9fwYxsTZ10iuO0Uq0WI6YYmHAG2rLUXi3EdfX3KG7YSnib4Bsa42 oIDpJ/7PcdfwG6ivdxKT6iDiNSmNG7mBzYPfQ8S94nXwh+zo6TJjsk8Vf4QumMzbJK SL/czEcF6OslvYWjcTvEQslJq8NOZ+5YdoQv9hdURgopHFaeywicN6jVY3Dzic6VDZ k+eiCG06scNpw== From: Jeff Layton To: chuck.lever@oracle.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH 1/4] nfsd: only fill out return pointer on success in nfsd4_lookup_stateid Date: Mon, 26 Sep 2022 12:38:44 -0400 Message-Id: <20220926163847.47558-2-jlayton@kernel.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926163847.47558-1-jlayton@kernel.org> References: <20220926163847.47558-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org In the case of a revoked delegation, we still fill out the pointer even when returning an error, which is bad form. Only overwrite the pointer on success. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index d5a8f3d7cbe8..273ed890562c 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -6268,6 +6268,7 @@ nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate, struct nfs4_stid **s, struct nfsd_net *nn) { __be32 status; + struct nfs4_stid *stid; bool return_revoked = false; /* @@ -6290,15 +6291,16 @@ nfsd4_lookup_stateid(struct nfsd4_compound_state *cstate, } if (status) return status; - *s = find_stateid_by_type(cstate->clp, stateid, typemask); - if (!*s) + stid = find_stateid_by_type(cstate->clp, stateid, typemask); + if (!stid) return nfserr_bad_stateid; - if (((*s)->sc_type == NFS4_REVOKED_DELEG_STID) && !return_revoked) { - nfs4_put_stid(*s); + if ((stid->sc_type == NFS4_REVOKED_DELEG_STID) && !return_revoked) { + nfs4_put_stid(stid); if (cstate->minorversion) return nfserr_deleg_revoked; return nfserr_bad_stateid; } + *s = stid; return nfs_ok; } From patchwork Mon Sep 26 16:38:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 12989132 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5911C6FA82 for ; Mon, 26 Sep 2022 17:24:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230455AbiIZRYG (ORCPT ); Mon, 26 Sep 2022 13:24:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231163AbiIZRXp (ORCPT ); Mon, 26 Sep 2022 13:23:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C242C151DCB for ; Mon, 26 Sep 2022 09:38:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 09215B80B40 for ; Mon, 26 Sep 2022 16:38:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A7BAC433D7; Mon, 26 Sep 2022 16:38:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664210330; bh=R/s/21M6ZNBdHTLFlT1qvJRkgxilLGAnNqbcANIwQao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zs+wFtj5pSXjwk+jycY4FwDwny0WgN8Dovbe3EuU4AZpsbGHr026Hb46Tzyjsv+rp V0XT3Wfi3VAYQRZUmSb+w1loep2yzPblzr5M8olrSo5+5Re6aD+A0YoessOdB1zn9U GsJbV01WGJlfDvTjL/6ddhzHn7YsXqqIXHDoprJVC2zm7WJyR159tr9mmyEv1BfMkT PM/oR7CdCKiVjkv6+pC2TqKCA40a5gc2BbKYz12LqKa4+dxyUG9IghEUpgv14XxUpw sYUhlcIYaElqQCN2B3WjZiMVb2r3UVmyPz4ogLmp1nVScsFmqwVcwGLCiamcAYhLz+ JfkeguYrnA2Bw== From: Jeff Layton To: chuck.lever@oracle.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH 2/4] nfsd: fix comments about spinlock handling with delegations Date: Mon, 26 Sep 2022 12:38:45 -0400 Message-Id: <20220926163847.47558-3-jlayton@kernel.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926163847.47558-1-jlayton@kernel.org> References: <20220926163847.47558-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 273ed890562c..211f1af1cfb3 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4857,14 +4857,14 @@ static void nfsd_break_one_deleg(struct nfs4_delegation *dp) * We're assuming the state code never drops its reference * without first removing the lease. Since we're in this lease * callback (and since the lease code is serialized by the - * i_lock) we know the server hasn't removed the lease yet, and + * flc_lock) we know the server hasn't removed the lease yet, and * we know it's safe to take a reference. */ refcount_inc(&dp->dl_stid.sc_count); nfsd4_run_cb(&dp->dl_recall); } -/* Called from break_lease() with i_lock held. */ +/* Called from break_lease() with flc_lock held. */ static bool nfsd_break_deleg_cb(struct file_lock *fl) { From patchwork Mon Sep 26 16:38:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 12989131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 113D9C32771 for ; Mon, 26 Sep 2022 17:24:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230448AbiIZRYG (ORCPT ); Mon, 26 Sep 2022 13:24:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231156AbiIZRXp (ORCPT ); Mon, 26 Sep 2022 13:23:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C56BF151B3E for ; Mon, 26 Sep 2022 09:38:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DB6AF60FE6 for ; Mon, 26 Sep 2022 16:38:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EECF2C433B5; Mon, 26 Sep 2022 16:38:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664210331; bh=RpHxrgYpxq35FjRPQqazIiOeT+xlQVivUxI1IvXfHig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qnz7+1rmskL9OqUZ9fNzuQ3/ZL0shEVTKZDsoSOyNn1mJo9Xlh3PCO2X17PpIX8PH Eu+jHuXxQNTkME/R1eoEicb5EhFi+I6svCThh/qailDgt7u/FgD9EPNXLIjQ2Za6nF /Bzyy0uO4gDGg03QLz+6aulq1a7FV62hOVfW+TpuYPKVPmjPirYGWutzn0sDrxVf6A bs7jPzeewWkT5KI7mM5hD/H/6M81gdRkf2bvN0uEXB1YiuL7K7RiJXR0oDis4DjLPN dWnA2SQFawyPmSCVtKthHjZEg5rDwwYRTWL0p6MjlU64hbAT2b3GYl+17HJuEHxCsB H9WafQx3BIfHw== From: Jeff Layton To: chuck.lever@oracle.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH 3/4] nfsd: make nfsd4_run_cb a bool return function Date: Mon, 26 Sep 2022 12:38:46 -0400 Message-Id: <20220926163847.47558-4-jlayton@kernel.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926163847.47558-1-jlayton@kernel.org> References: <20220926163847.47558-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org ...and mirror the semantics of queue_work. Also, queueing a delegation recall should always succeed when queueing, so WARN if one ever doesn't. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4callback.c | 14 ++++++++++++-- fs/nfsd/nfs4state.c | 5 ++--- fs/nfsd/state.h | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c index 4ce328209f61..ba904614ebf5 100644 --- a/fs/nfsd/nfs4callback.c +++ b/fs/nfsd/nfs4callback.c @@ -1371,11 +1371,21 @@ void nfsd4_init_cb(struct nfsd4_callback *cb, struct nfs4_client *clp, cb->cb_holds_slot = false; } -void nfsd4_run_cb(struct nfsd4_callback *cb) +/** + * nfsd4_run_cb - queue up a callback job to run + * @cb: callback to queue + * + * Kick off a callback to do its thing. Returns false if it was already + * queued or running, true otherwise. + */ +bool nfsd4_run_cb(struct nfsd4_callback *cb) { + bool queued; struct nfs4_client *clp = cb->cb_clp; nfsd41_cb_inflight_begin(clp); - if (!nfsd4_queue_cb(cb)) + queued = nfsd4_queue_cb(cb); + if (!queued) nfsd41_cb_inflight_end(clp); + return queued; } diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 211f1af1cfb3..90533f43fea9 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4861,14 +4861,13 @@ static void nfsd_break_one_deleg(struct nfs4_delegation *dp) * we know it's safe to take a reference. */ refcount_inc(&dp->dl_stid.sc_count); - nfsd4_run_cb(&dp->dl_recall); + WARN_ON_ONCE(!nfsd4_run_cb(&dp->dl_recall)); } /* Called from break_lease() with flc_lock held. */ static bool nfsd_break_deleg_cb(struct file_lock *fl) { - bool ret = false; struct nfs4_delegation *dp = (struct nfs4_delegation *)fl->fl_owner; struct nfs4_file *fp = dp->dl_stid.sc_file; struct nfs4_client *clp = dp->dl_stid.sc_client; @@ -4894,7 +4893,7 @@ nfsd_break_deleg_cb(struct file_lock *fl) fp->fi_had_conflict = true; nfsd_break_one_deleg(dp); spin_unlock(&fp->fi_lock); - return ret; + return false; } /** diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h index b3477087a9fc..e2daef3cc003 100644 --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -692,7 +692,7 @@ extern void nfsd4_probe_callback_sync(struct nfs4_client *clp); extern void nfsd4_change_callback(struct nfs4_client *clp, struct nfs4_cb_conn *); extern void nfsd4_init_cb(struct nfsd4_callback *cb, struct nfs4_client *clp, const struct nfsd4_callback_ops *ops, enum nfsd4_cb_op op); -extern void nfsd4_run_cb(struct nfsd4_callback *cb); +extern bool nfsd4_run_cb(struct nfsd4_callback *cb); extern int nfsd4_create_callback_queue(void); extern void nfsd4_destroy_callback_queue(void); extern void nfsd4_shutdown_callback(struct nfs4_client *); From patchwork Mon Sep 26 16:38:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 12989130 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9EE2C07E9D for ; Mon, 26 Sep 2022 17:24:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230436AbiIZRYF (ORCPT ); Mon, 26 Sep 2022 13:24:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231158AbiIZRXp (ORCPT ); Mon, 26 Sep 2022 13:23:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CC91151DC6 for ; Mon, 26 Sep 2022 09:38:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 642D161029 for ; Mon, 26 Sep 2022 16:38:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E651C43470; Mon, 26 Sep 2022 16:38:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664210331; bh=4aQTxyFHk1yHlT+oR3aAscCn1o/8MjoCJ22b8O8VS0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OYHIVw3MMdQXk9mxmpKIXKFofAjkTYzOwIwFNHeb05WCP4LTtxmt/l+z7urZTC5c1 4z65Q12NST1zZB0tmMfI9LM8VUWF8n0OSWaYNpEnkJwd646qd545H8YXVkkITX/wM2 mUeXVLlASX4IELpTGMTNAsjqXfWQOvCuP5sS1vlG6vzRxeLNgvQk/+bOeZQG1TxkC9 LsGqeyGN9Wae9Bqc2/S7I6LR7S635KngVIHktsqA1T4J7RYXj05QlPSzq+UeAe8Vv7 XH9y6PRe1Zs4xUJHqTYyIMv7cNCfi09P7kxoKg+sIODBPH7ssuQESb2YjS9Z8svj9c 3mcaYJwdWu4XA== From: Jeff Layton To: chuck.lever@oracle.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH 4/4] nfsd: extra checks when freeing delegation stateids Date: Mon, 26 Sep 2022 12:38:47 -0400 Message-Id: <20220926163847.47558-5-jlayton@kernel.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926163847.47558-1-jlayton@kernel.org> References: <20220926163847.47558-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org We've had some reports of problems in the refcounting for delegation stateids that we've yet to track down. Add some extra checks to ensure that we've removed the object from various lists before freeing it. Link: https://bugzilla.redhat.com/show_bug.cgi?id=2127067 Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) This one may need adjustment after Dai fixes the use of openlockstateid here. diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 90533f43fea9..490092a10285 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1060,9 +1060,12 @@ static struct nfs4_ol_stateid * nfs4_alloc_open_stateid(struct nfs4_client *clp) static void nfs4_free_deleg(struct nfs4_stid *stid) { - struct nfs4_ol_stateid *stp = openlockstateid(stid); + struct nfs4_delegation *dp = delegstateid(stid); - WARN_ON(!list_empty(&stp->st_stid.sc_cp_list)); + WARN_ON_ONCE(!list_empty(&stid->sc_cp_list)); + WARN_ON_ONCE(!list_empty(&dp->dl_perfile)); + WARN_ON_ONCE(!list_empty(&dp->dl_perclnt)); + WARN_ON_ONCE(!list_empty(&dp->dl_recall_lru)); kmem_cache_free(deleg_slab, stid); atomic_long_dec(&num_delegations); }