From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42DF929BDB7; Tue, 12 Aug 2025 19:23:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755026597; cv=none; b=S+1PFPJcwLSAfdgYgDFb6HD5DeWhMxiDMFDxjMPqzWflwWwEd2F40D7Pd3CQf2AfUKxvj3AASwdMUCqke/VwDnNJWgDvpUSI/RMxDqw3FVitTjcHzrBAT+GR+8FvD2D4mrthCHNrExJvVLiy8hdAGqhmvajFMBcOf7+AVIeRDPk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755026597; c=relaxed/simple; bh=hsySSo7Mn+Hl5Lw6uqVTl4mOi3EdTI5HOfdrgQygLCU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e3JIgjyQ1e8kXtSQN2ppSW24SmiNtR3khK+T5BF0ABaerWxLjGoWs1KJ/BSzHr/odkGO2/2MyyqZ2mWngkVcqaRApqOQE0v6YMX2cxCp/Xf+3HqW5kuTMP+evr/21+AqasVPm4gXUefrOeF/u2h5e8B9/oA4SlA3CQ1iQipGA+E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=IOLPD30i; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="IOLPD30i" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7B1DC4CEF0; Tue, 12 Aug 2025 19:23:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1755026597; bh=hsySSo7Mn+Hl5Lw6uqVTl4mOi3EdTI5HOfdrgQygLCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IOLPD30i8NsyqJEjEkYDV2sA+3swZNIAg/h+l8S7L6UqT3DW7EQAtltdhA+P1iLjx 8pM8iDKQUgKqt2SZjZ9jSPYFqOdaeyuy5d3hC9gMuPcHLXedxzXW2QV9L0zV2dFHf1 FJYT3mT36ALDxD3iUwuoJKWfGEqQXyoos5F59WNk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Trond Myklebust , Benjamin Coddington , Laurence Oberman , Jeff Layton , Trond Myklebust , Sasha Levin Subject: [PATCH 6.15 384/480] NFS: Fixup allocation flags for nfsiods __GFP_NORETRY Date: Tue, 12 Aug 2025 19:49:52 +0200 Message-ID: <20250812174413.264868842@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250812174357.281828096@linuxfoundation.org> References: <20250812174357.281828096@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Benjamin Coddington [ Upstream commit 99765233ab42bf7a4950377ad7894dce8a5c0e60 ] If the NFS client is doing writeback from a workqueue context, avoid using __GFP_NORETRY for allocations if the task has set PF_MEMALLOC_NOIO or PF_MEMALLOC_NOFS. The combination of these flags makes memory allocation failures much more likely. We've seen those allocation failures show up when the loopback driver is doing writeback from a workqueue to a file on NFS, where memory allocation failure results in errors or corruption within the loopback device's filesystem. Suggested-by: Trond Myklebust Fixes: 0bae835b63c5 ("NFS: Avoid writeback threads getting stuck in mempool_alloc()") Signed-off-by: Benjamin Coddington Reviewed-by: Laurence Oberman Tested-by: Laurence Oberman Reviewed-by: Jeff Layton Link: https://lore.kernel.org/r/f83ac1155a4bc670f2663959a7a068571e06afd9.1752111622.git.bcodding@redhat.com Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- fs/nfs/internal.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index 69c2c10ee658..d8f768254f16 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h @@ -671,9 +671,12 @@ nfs_write_match_verf(const struct nfs_writeverf *verf, static inline gfp_t nfs_io_gfp_mask(void) { - if (current->flags & PF_WQ_WORKER) - return GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN; - return GFP_KERNEL; + gfp_t ret = current_gfp_context(GFP_KERNEL); + + /* For workers __GFP_NORETRY only with __GFP_IO or __GFP_FS */ + if ((current->flags & PF_WQ_WORKER) && ret == GFP_KERNEL) + ret |= __GFP_NORETRY | __GFP_NOWARN; + return ret; } /* -- 2.39.5