>From 527e41205915d605f68c356a636dfc12b7545b7b Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Thu, 28 May 2015 07:39:39 -0400 Subject: [PATCH] nfs: don't hold rcu_read_lock over xs_swapper call 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 Cc: Mel Gorman Signed-off-by: Jeff Layton --- 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