[PATCH] nfs: don't hold rcu_read_lock over xs_swapper call

From: Jeff Layton
Date: Thu May 28 2015 - 07:39:39 EST


Jerome reported seeing a WARN_ON pop up when enabling a swapfile on NFS.
The xs_swapper call can sleep so we do not want to hold the
rcu_read_lock when calling it. Fix this by taking a reference to the
xprt in the critical section, calling xs_swapper outside it and then
putting that reference.

Reported-by: Jerome Marchand <jmarchan@xxxxxxxxxx>
Cc: Mel Gorman <mgorman@xxxxxxx>
Signed-off-by: Jeff Layton <jeff.layton@xxxxxxxxxxxxxxx>
---
fs/nfs/file.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 8b8d83a526ce..3ee08460c4cf 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -561,12 +561,18 @@ static int nfs_swap_activate(struct swap_info_struct *sis, struct file *file,
{
int ret;
struct rpc_clnt *clnt = NFS_CLIENT(file->f_mapping->host);
+ struct rpc_xprt *xprt;

*span = sis->pages;

rcu_read_lock();
- ret = xs_swapper(rcu_dereference(clnt->cl_xprt), 1);
+ xprt = xprt_get(rcu_dereference(clnt->cl_xprt));
rcu_read_unlock();
+ if (!xprt)
+ return -EINVAL;
+
+ ret = xs_swapper(xprt, 1);
+ xprt_put(xprt);

return ret;
}
@@ -574,10 +580,16 @@ static int nfs_swap_activate(struct swap_info_struct *sis, struct file *file,
static void nfs_swap_deactivate(struct file *file)
{
struct rpc_clnt *clnt = NFS_CLIENT(file->f_mapping->host);
+ struct rpc_xprt *xprt;

rcu_read_lock();
- xs_swapper(rcu_dereference(clnt->cl_xprt), 0);
+ xprt = xprt_get(rcu_dereference(clnt->cl_xprt));
rcu_read_unlock();
+ if (!xprt)
+ return;
+
+ xs_swapper(xprt, 0);
+ xprt_put(xprt);
}
#endif

--
2.4.1


--MP_/VPZ066Oa6ok3CTMlO2eJBgV--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/