From 06c34b59f10552070ea1727a8596933aecaccf28 Mon Sep 17 00:00:00 2001 From: Trond Myklebust Date: Tue, 8 Jun 2021 21:22:52 +0800 Subject: [PATCH] NFS: Ensure NFS writeback allocations don't recurse back into NFS. mainline inclusion from mainline-v5.0-rc1 commit 875bc3fbf2724134234ddb3069c8e9862b0b19b3 category: bugfix bugzilla: NA CVE: NA -------------------------------- All the allocations that we can hit in the NFS layer and sunrpc layers themselves are already marked as GFP_NOFS, but we need to ensure that any calls to generic kernel functionality do the right thing as well. Signed-off-by: Trond Myklebust Signed-off-by: Zhang Xiaoxu Reviewed-by: Zhang Yi Signed-off-by: Yang Yingliang --- fs/nfs/write.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/nfs/write.c b/fs/nfs/write.c index d419d89b91f7..5ae98c0cde04 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c @@ -26,6 +26,7 @@ #include #include +#include #include "delegation.h" #include "internal.h" @@ -727,11 +728,13 @@ int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc) { struct inode *inode = mapping->host; struct nfs_pageio_descriptor pgio; - struct nfs_io_completion *ioc = nfs_io_completion_alloc(GFP_NOFS); + struct nfs_io_completion *ioc; + unsigned int pflags = memalloc_nofs_save(); int err; nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGES); + ioc = nfs_io_completion_alloc(GFP_NOFS); if (ioc) nfs_io_completion_init(ioc, nfs_io_completion_commit, inode); @@ -742,6 +745,8 @@ int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc) nfs_pageio_complete(&pgio); nfs_io_completion_put(ioc); + memalloc_nofs_restore(pflags); + if (err < 0) goto out_err; err = pgio.pg_error; -- GitLab