From patchwork Wed May 10 16:28:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 13237071 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 7B0C7C77B7C for ; Wed, 10 May 2023 16:34:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229468AbjEJQec (ORCPT ); Wed, 10 May 2023 12:34:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235571AbjEJQea (ORCPT ); Wed, 10 May 2023 12:34:30 -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 2AFD87EE6 for ; Wed, 10 May 2023 09:34:28 -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 A8F1F649CF for ; Wed, 10 May 2023 16:34:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5248C433EF; Wed, 10 May 2023 16:34:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683736467; bh=m38iE512Bp6EMTVdU69benLJi4T5hYsmaBjnWPlZ/n0=; h=From:To:Cc:Subject:Date:From; b=NEcfqKgbYBDcwRom9ae6hew2ejhPxT0vdtwZGZ2u6yC7Yc9UcJwrkaW7SDPVWv52i PsnY02Qg+WJL3fXCuJpOjiv/KUG4VqNZx4auUQUJBZQczaFpmtKAUYQuZtZI4nU0Fc EGDN09S6peKuHytJP7V26CquBy8JgQ1Jh+ECSBb9Sbbyumemq3N2g29PegDscEPDKp LhHAPJLzF2wsVGQqEJ7jz/QNWB/Nl2dTwSg4PUIdEPXDMFaMApjE0oZgBOBbej0JT8 Wj540cpfr+GpY9dderPyx4MDpYggCJKZfgeER8jgfSHYy7GqwcKB4e1LDmpegVRLPI dVFQvejO8ExVQ== From: trondmy@kernel.org To: Anna Schumaker Cc: linux-nfs@vger.kernel.org Subject: [PATCH] SUNRPC: Don't change task->tk_status after the call to rpc_exit_task Date: Wed, 10 May 2023 12:28:00 -0400 Message-Id: <20230510162800.11298-1-trondmy@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust Some calls to rpc_exit_task() may deliberately change the value of task->tk_status, for instance because it gets checked by the RPC call's rpc_release() callback. That makes it wrong to reset the value to task->tk_rpc_status. In particular this causes a bug where the rpc_call_done() callback tries to fail over a set of pNFS/flexfiles writes to a different IP address, but the reset of task->tk_status causes nfs_commit_release_pages() to immediately mark the file as having a fatal error. Fixes: 39494194f93b ("SUNRPC: Fix races with rpc_killall_tasks()") Cc: stable@vger.kernel.org # 6.1.x Signed-off-by: Trond Myklebust --- net/sunrpc/sched.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c index c8321de341ee..6debf4fd42d4 100644 --- a/net/sunrpc/sched.c +++ b/net/sunrpc/sched.c @@ -927,11 +927,10 @@ static void __rpc_execute(struct rpc_task *task) */ do_action = task->tk_action; /* Tasks with an RPC error status should exit */ - if (do_action != rpc_exit_task && + if (do_action && do_action != rpc_exit_task && (status = READ_ONCE(task->tk_rpc_status)) != 0) { task->tk_status = status; - if (do_action != NULL) - do_action = rpc_exit_task; + do_action = rpc_exit_task; } /* Callbacks override all actions */ if (task->tk_callback) {