From patchwork Mon Sep 26 18:41:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 12989279 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 E392DC07E9D for ; Mon, 26 Sep 2022 18:42:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231234AbiIZSmr (ORCPT ); Mon, 26 Sep 2022 14:42:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231266AbiIZSlv (ORCPT ); Mon, 26 Sep 2022 14:41:51 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB0C017E1F for ; Mon, 26 Sep 2022 11:41:05 -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 974BA61132 for ; Mon, 26 Sep 2022 18:41:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1C76C43150; Mon, 26 Sep 2022 18:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664217664; bh=Zcjvh+pca4laB4jRvvwNRyy6FVS05eQSPP4HekWceA8=; h=From:To:Cc:Subject:Date:From; b=tQV1FgwEArVMsRNgIAZgendSN32FuUi71OmKCzRkReING2BIbbLzO0qh7QhlV/705 us+e8P1KbEgYW0VLXtQsjsY319zjFcGTPPNFeWnBnOO3iRqkFF2174W6kxM5VT/kAV wy/nscT00LRLRat2JR2/PXK8gXhRnfaKlykdiw1/BRuez1NMbDSbgpbWbx7cRjp8Kh tRPw402CZ73ha4xNJ5YmTkt6xxU2e08LvAaKOuRKQBPaXCg6zk+bAI9aCXWF2bGYjY 7+ZlBbxLCsyQuzUro3p0kV+CB+85LA6xdYrafnExM9XldOht81m02MRObC/7Z2JMGx Y88+N0i3fcebw== From: Jeff Layton To: chuck.lever@oracle.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 1/2] nfsd: make nfsd4_run_cb a bool return function Date: Mon, 26 Sep 2022 14:41:01 -0400 Message-Id: <20220926184102.57254-1-jlayton@kernel.org> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org queue_work can return false and not queue anything, if the work is already queued. If that happens in the case of a CB_RECALL, we'll have taken an extra reference to the stid that will never be put. Ensure we throw a warning in that case. 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..c4ee4a820a62 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 + * on a queue, 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 e116f50afcf2..c78c3223161e 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4859,14 +4859,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; @@ -4892,7 +4891,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 18:41:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 12989280 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 5E56BC6FA8E for ; Mon, 26 Sep 2022 18:42:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231262AbiIZSms (ORCPT ); Mon, 26 Sep 2022 14:42:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229824AbiIZSlw (ORCPT ); Mon, 26 Sep 2022 14:41:52 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3BF6765B for ; Mon, 26 Sep 2022 11:41:07 -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 D7066B80D6A for ; Mon, 26 Sep 2022 18:41:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43A55C43152; Mon, 26 Sep 2022 18:41:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664217664; bh=xpEap7HOqRKMq5Q/QJesxgmIWMtl4RumIJX0YUJgL40=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QuUI56IKYuKTu+VioYH4xhBJGoRfuM+3cgEWHZlyCIZrWrtg3hwc0KRWGEN4oXYQ9 klFFTVLWW8T3v4NUmMx7w5VZDNOyiOB8VEZnyXtypeJ6xpmCB1VfKmfZhAwMoarKQG rWlgg3oDk8gA8/S0uihwQbBHiUOXO1ZaJJV+H3n38uVSsDEc8ZtuLdxBdcb/YcUOuo 1Ovxw45lsN1O273TwdFMkhxetx6AQ1Q52BVKGqBnow6PINVa2prdxJ/mN+VqpTnFEy g4J+mpRPO61EHalfy7/k1lkH87QU2Y/Yu1kkN6eoFNdLfn/AJvYgo2QQiGtDbuDhoE VtUfPuX79glYw== From: Jeff Layton To: chuck.lever@oracle.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 2/2] nfsd: extra checks when freeing delegation stateids Date: Mon, 26 Sep 2022 14:41:02 -0400 Message-Id: <20220926184102.57254-2-jlayton@kernel.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926184102.57254-1-jlayton@kernel.org> References: <20220926184102.57254-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, 6 insertions(+), 1 deletion(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index c78c3223161e..198d7abf34e4 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1060,7 +1060,12 @@ static struct nfs4_ol_stateid * nfs4_alloc_open_stateid(struct nfs4_client *clp) static void nfs4_free_deleg(struct nfs4_stid *stid) { - WARN_ON(!list_empty(&stid->sc_cp_list)); + struct nfs4_delegation *dp = delegstateid(stid); + + 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); }