Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5858459rdb; Sun, 17 Sep 2023 16:12:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3cJK1tt1cFTYUg0c6y0y/7uSpY+1EWoFSZet8ubb3ksiy3TEUVCw4dp4Itt2SWsHzziZo X-Received: by 2002:a05:6a00:21cd:b0:690:3a0f:4164 with SMTP id t13-20020a056a0021cd00b006903a0f4164mr7935944pfj.19.1694992358956; Sun, 17 Sep 2023 16:12:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694992358; cv=none; d=google.com; s=arc-20160816; b=QsGbdJotkTfDyzrg/9OrfQbef3ZsgBEE19wua3H+ZKYFwnnoRc41AGDQknoRadqNxX VsD2wr/FM3Rw6aQn02vOFf3UuEN2NbAyD+aHtDnHD4AbOBpH3cXoynm0508DfAsbhfe/ ZTtOnOxhyMduwwI9A6UaDGmmmqgy62573VW2kmCubhpKMbLUkEOdWEDjSYVw+Qkg4/is wur4URsO6Hbxkltyrn8LRp1ve1CmFawXRo/uXJ5nhWrPzYK0M0tx2M0g4dUY6objjcyw zWGeyJSbRscbyHxgqxhshAbt+a8xFg4tou478kDWscOxiDQ69SMgQFWmZk+VVE4Lv2yk E1lQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=oC45UHAZ9jF2rlDJMSQnZ84OHnSWk1hyvBFSNWnuOj8=; fh=sG9b8sIRwnMx357dAEVjdzLttEK3RTv7pmgywyQXOZs=; b=YvrYtGPPPwgPx2WcOKdp1/AVEaUMG0Ktlyvt/ZznYVsV7pjnIaGFgnn/aswjLQIQB6 3mWkOcRsKB3qxgtpsnH99TmWdNOBu4iNVGCsHTeYUDK90sE1LOZmBf18jjX6yu4lr+7f YIOIYkeG8upGCpXoO45wcKPg/NKzGRBmgQcCJ2hcPvFif//K68GwIPiXJCLsR/BbUm0p nZjgHSAYy3SlFhyMqu1XffmHhc3XJ8K01i/gYvm7vIw0PBm5GNqyxaBQzx3owxdDSDkD V5CL1XF1AAuDavqXEzbtLNIOcWNv4ITOyV9NkMA4bOMJBOQvSHKJpzX+OuQGlkVxE+6S +0ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CJ1ix7o2; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id u190-20020a6385c7000000b00565d9520544si7154692pgd.844.2023.09.17.16.12.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Sep 2023 16:12:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CJ1ix7o2; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 396EC819166C; Sun, 17 Sep 2023 16:12:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231551AbjIQXMH (ORCPT + 99 others); Sun, 17 Sep 2023 19:12:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238437AbjIQXME (ORCPT ); Sun, 17 Sep 2023 19:12:04 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3750120 for ; Sun, 17 Sep 2023 16:11:58 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA7E0C433C7; Sun, 17 Sep 2023 23:11:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694992318; bh=3erpsaEK2+lUc6zmfC9K5oPLp01NQD9LuTDVFXKXZaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CJ1ix7o2aLGj00n2up9ZdXANmIahSZ0ryLL2Mdr63nBEZArs8unCTVqhy6+9/lgUc zydCLPNU5ci4ToV+TSk7TDynVYwaPSmi47FLMnVTqNxgR++Pd5mi711QGGvN8A4p00 fDNG6sZMZFY4W7V3NnNVaYNlzf+FBX+ImGjDU5PAfw3nlAARy2e5+Y4SK1yX4KkbxJ hZ07V+gjBx7GvUJsbTf1yONqUeykUdQz6gyEUBMs6QbRq3FQQnLgzRubIqGhSi+Rx/ C/+ePGHIlJTQEQmhstKPJWBA4DSnZTjQM5DPJee5UH+WB5BOuXdEadBz82BcN6kmZ9 ZjO4JBavwpb1Q== From: trondmy@kernel.org To: Anna Schumaker Cc: linux-nfs@vger.kernel.org, Neil Brown Subject: [PATCH 2/2] NFSv4: Fix a state manager thread deadlock regression Date: Sun, 17 Sep 2023 19:05:51 -0400 Message-ID: <20230917230551.30483-2-trondmy@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230917230551.30483-1-trondmy@kernel.org> References: <20230917230551.30483-1-trondmy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Sun, 17 Sep 2023 16:12:35 -0700 (PDT) From: Trond Myklebust Commit 4dc73c679114 reintroduces the deadlock that was fixed by commit aeabb3c96186 ("NFSv4: Fix a NFSv4 state manager deadlock") because it prevents the setup of new threads to handle reboot recovery, while the older recovery thread is stuck returning delegations. Fixes: 4dc73c679114 ("NFSv4: keep state manager thread active if swap is enabled") Cc: stable@vger.kernel.org Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 4 +++- fs/nfs/nfs4state.c | 38 ++++++++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 5deeaea8026e..a19e809cad16 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -10652,7 +10652,9 @@ static void nfs4_disable_swap(struct inode *inode) */ struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; - nfs4_schedule_state_manager(clp); + set_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state); + clear_bit(NFS4CLNT_MANAGER_AVAILABLE, &clp->cl_state); + wake_up_var(&clp->cl_state); } static const struct inode_operations nfs4_dir_inode_operations = { diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c index 0bc160fbabec..5751a6886da4 100644 --- a/fs/nfs/nfs4state.c +++ b/fs/nfs/nfs4state.c @@ -1209,16 +1209,26 @@ void nfs4_schedule_state_manager(struct nfs_client *clp) { struct task_struct *task; char buf[INET6_ADDRSTRLEN + sizeof("-manager") + 1]; + struct rpc_clnt *clnt = clp->cl_rpcclient; + bool swapon = false; - if (clp->cl_rpcclient->cl_shutdown) + if (clnt->cl_shutdown) return; set_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state); - if (test_and_set_bit(NFS4CLNT_MANAGER_AVAILABLE, &clp->cl_state) != 0) { - wake_up_var(&clp->cl_state); - return; + + if (atomic_read(&clnt->cl_swapper)) { + swapon = !test_and_set_bit(NFS4CLNT_MANAGER_AVAILABLE, + &clp->cl_state); + if (!swapon) { + wake_up_var(&clp->cl_state); + return; + } } - set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state); + + if (test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state) != 0) + return; + __module_get(THIS_MODULE); refcount_inc(&clp->cl_count); @@ -1235,8 +1245,9 @@ void nfs4_schedule_state_manager(struct nfs_client *clp) __func__, PTR_ERR(task)); if (!nfs_client_init_is_complete(clp)) nfs_mark_client_ready(clp, PTR_ERR(task)); + if (swapon) + clear_bit(NFS4CLNT_MANAGER_AVAILABLE, &clp->cl_state); nfs4_clear_state_manager_bit(clp); - clear_bit(NFS4CLNT_MANAGER_AVAILABLE, &clp->cl_state); nfs_put_client(clp); module_put(THIS_MODULE); } @@ -2748,22 +2759,25 @@ static int nfs4_run_state_manager(void *ptr) allow_signal(SIGKILL); again: - set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state); nfs4_state_manager(clp); - if (atomic_read(&cl->cl_swapper)) { + + if (test_bit(NFS4CLNT_MANAGER_AVAILABLE, &clp->cl_state) && + !test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state)) { wait_var_event_interruptible(&clp->cl_state, test_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state)); - if (atomic_read(&cl->cl_swapper) && - test_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state)) + if (!atomic_read(&cl->cl_swapper)) + clear_bit(NFS4CLNT_MANAGER_AVAILABLE, &clp->cl_state); + if (refcount_read(&clp->cl_count) > 1 && !signalled()) goto again; /* Either no longer a swapper, or were signalled */ + clear_bit(NFS4CLNT_MANAGER_AVAILABLE, &clp->cl_state); + nfs4_clear_state_manager_bit(clp); } - clear_bit(NFS4CLNT_MANAGER_AVAILABLE, &clp->cl_state); if (refcount_read(&clp->cl_count) > 1 && !signalled() && test_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state) && - !test_and_set_bit(NFS4CLNT_MANAGER_AVAILABLE, &clp->cl_state)) + !test_and_set_bit(NFS4CLNT_MANAGER_RUNNING, &clp->cl_state)) goto again; nfs_put_client(clp); -- 2.41.0