Skip to content

Commit 852a8b2

Browse files
committed
SUNRPC: Fix memory reclaim deadlocks in rpciod
Junxiao Bi reports seeing the following deadlock: @ crash> bt 1539 @ PID: 1539 TASK: ffff88178f64a040 CPU: 1 COMMAND: "rpciod/1" @ #0 [ffff88178f64d2c0] schedule at ffffffff8145833a @ #1 [ffff88178f64d348] io_schedule at ffffffff8145842c @ #2 [ffff88178f64d368] sync_page at ffffffff810d8161 @ #3 [ffff88178f64d378] __wait_on_bit at ffffffff8145895b @ #4 [ffff88178f64d3b8] wait_on_page_bit at ffffffff810d82fe @ #5 [ffff88178f64d418] wait_on_page_writeback at ffffffff810e2a1a @ torvalds#6 [ffff88178f64d438] shrink_page_list at ffffffff810e34e1 @ torvalds#7 [ffff88178f64d588] shrink_list at ffffffff810e3dbe @ torvalds#8 [ffff88178f64d6f8] shrink_zone at ffffffff810e425e @ torvalds#9 [ffff88178f64d7b8] do_try_to_free_pages at ffffffff810e4978 @ torvalds#10 [ffff88178f64d828] try_to_free_pages at ffffffff810e4c31 @ torvalds#11 [ffff88178f64d8c8] __alloc_pages_nodemask at ffffffff810de370 @ torvalds#12 [ffff88178f64d978] kmem_getpages at ffffffff8110e18b @ torvalds#13 [ffff88178f64d9a8] fallback_alloc at ffffffff8110e35e @ torvalds#14 [ffff88178f64da08] ____cache_alloc_node at ffffffff8110e51f @ torvalds#15 [ffff88178f64da48] __kmalloc at ffffffff8110efba @ torvalds#16 [ffff88178f64da98] xs_setup_xprt at ffffffffa00a563f [sunrpc] @ torvalds#17 [ffff88178f64dad8] xs_setup_tcp at ffffffffa00a7648 [sunrpc] @ torvalds#18 [ffff88178f64daf8] xprt_create_transport at ffffffffa00a478f [sunrpc] @ torvalds#19 [ffff88178f64db18] rpc_create at ffffffffa00a2d7a [sunrpc] @ torvalds#20 [ffff88178f64dbf8] rpcb_create at ffffffffa00b026b [sunrpc] @ torvalds#21 [ffff88178f64dc98] rpcb_getport_async at ffffffffa00b0c94 [sunrpc] @ torvalds#22 [ffff88178f64ddf8] call_bind at ffffffffa00a11f8 [sunrpc] @ torvalds#23 [ffff88178f64de18] __rpc_execute at ffffffffa00a88ef [sunrpc] @ torvalds#24 [ffff88178f64de58] rpc_async_schedule at ffffffffa00a9187 [sunrpc] @ torvalds#25 [ffff88178f64de78] worker_thread at ffffffff81072ed2 @ torvalds#26 [ffff88178f64dee8] kthread at ffffffff81076df3 @ torvalds#27 [ffff88178f64df48] kernel_thread at ffffffff81012e2a @ crash> Junxiao notes that the problem is not limited to the rpcbind client. In fact we can trigger the exact same problem when trying to reconnect to the server, and we find ourselves calling sock_alloc(). The following solution should work for all kernels that support the PF_MEMALLOC_NOIO flag (i.e. Linux 3.9 and newer). Link: http://lkml.kernel.org/r/53F6F772.6020708@oracle.com Reported-by: Junxiao Bi <junxiao.bi@oracle.com> Cc: stable@vger.kernel.org # 3.9+ Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
1 parent 92a5655 commit 852a8b2

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

net/sunrpc/sched.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/spinlock.h>
2020
#include <linux/mutex.h>
2121
#include <linux/freezer.h>
22+
#include <linux/sched.h>
2223

2324
#include <linux/sunrpc/clnt.h>
2425

@@ -821,9 +822,9 @@ void rpc_execute(struct rpc_task *task)
821822

822823
static void rpc_async_schedule(struct work_struct *work)
823824
{
824-
current->flags |= PF_FSTRANS;
825+
current->flags |= PF_FSTRANS | PF_MEMALLOC_NOIO;
825826
__rpc_execute(container_of(work, struct rpc_task, u.tk_work));
826-
current->flags &= ~PF_FSTRANS;
827+
current->flags &= ~(PF_FSTRANS | PF_MEMALLOC_NOIO);
827828
}
828829

829830
/**

net/sunrpc/xprtsock.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <linux/sunrpc/svcsock.h>
3939
#include <linux/sunrpc/xprtsock.h>
4040
#include <linux/file.h>
41+
#include <linux/sched.h>
4142
#ifdef CONFIG_SUNRPC_BACKCHANNEL
4243
#include <linux/sunrpc/bc_xprt.h>
4344
#endif
@@ -1927,7 +1928,7 @@ static int xs_local_setup_socket(struct sock_xprt *transport)
19271928
struct socket *sock;
19281929
int status = -EIO;
19291930

1930-
current->flags |= PF_FSTRANS;
1931+
current->flags |= PF_FSTRANS | PF_MEMALLOC_NOIO;
19311932

19321933
clear_bit(XPRT_CONNECTION_ABORT, &xprt->state);
19331934
status = __sock_create(xprt->xprt_net, AF_LOCAL,
@@ -1968,7 +1969,7 @@ static int xs_local_setup_socket(struct sock_xprt *transport)
19681969
out:
19691970
xprt_clear_connecting(xprt);
19701971
xprt_wake_pending_tasks(xprt, status);
1971-
current->flags &= ~PF_FSTRANS;
1972+
current->flags &= ~(PF_FSTRANS | PF_MEMALLOC_NOIO);
19721973
return status;
19731974
}
19741975

@@ -2071,7 +2072,7 @@ static void xs_udp_setup_socket(struct work_struct *work)
20712072
struct socket *sock = transport->sock;
20722073
int status = -EIO;
20732074

2074-
current->flags |= PF_FSTRANS;
2075+
current->flags |= PF_FSTRANS | PF_MEMALLOC_NOIO;
20752076

20762077
/* Start by resetting any existing state */
20772078
xs_reset_transport(transport);
@@ -2092,7 +2093,7 @@ static void xs_udp_setup_socket(struct work_struct *work)
20922093
out:
20932094
xprt_clear_connecting(xprt);
20942095
xprt_wake_pending_tasks(xprt, status);
2095-
current->flags &= ~PF_FSTRANS;
2096+
current->flags &= ~(PF_FSTRANS | PF_MEMALLOC_NOIO);
20962097
}
20972098

20982099
/*
@@ -2229,7 +2230,7 @@ static void xs_tcp_setup_socket(struct work_struct *work)
22292230
struct rpc_xprt *xprt = &transport->xprt;
22302231
int status = -EIO;
22312232

2232-
current->flags |= PF_FSTRANS;
2233+
current->flags |= PF_FSTRANS | PF_MEMALLOC_NOIO;
22332234

22342235
if (!sock) {
22352236
clear_bit(XPRT_CONNECTION_ABORT, &xprt->state);
@@ -2276,7 +2277,7 @@ static void xs_tcp_setup_socket(struct work_struct *work)
22762277
case -EINPROGRESS:
22772278
case -EALREADY:
22782279
xprt_clear_connecting(xprt);
2279-
current->flags &= ~PF_FSTRANS;
2280+
current->flags &= ~(PF_FSTRANS | PF_MEMALLOC_NOIO);
22802281
return;
22812282
case -EINVAL:
22822283
/* Happens, for instance, if the user specified a link
@@ -2294,7 +2295,7 @@ static void xs_tcp_setup_socket(struct work_struct *work)
22942295
out:
22952296
xprt_clear_connecting(xprt);
22962297
xprt_wake_pending_tasks(xprt, status);
2297-
current->flags &= ~PF_FSTRANS;
2298+
current->flags &= ~(PF_FSTRANS | PF_MEMALLOC_NOIO);
22982299
}
22992300

23002301
/**

0 commit comments

Comments
 (0)