提交 a2f39fc0 编写于 作者: N NeilBrown 提交者: Yongqiang Liu

SUNRPC/call_alloc: async tasks mustn't block waiting for memory

stable inclusion
from stable-4.19.238
commit 9970fca80164b3cbfd700acd735aa043d40a73ed
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5A6BA
CVE: NA

--------------------------------

[ Upstream commit c487216b ]

When memory is short, new worker threads cannot be created and we depend
on the minimum one rpciod thread to be able to handle everything.
So it must not block waiting for memory.

mempools are particularly a problem as memory can only be released back
to the mempool by an async rpc task running.  If all available
workqueue threads are waiting on the mempool, no thread is available to
return anything.

rpc_malloc() can block, and this might cause deadlocks.
So check RPC_IS_ASYNC(), rather than RPC_IS_SWAPPER() to determine if
blocking is acceptable.
Signed-off-by: NNeilBrown <neilb@suse.de>
Signed-off-by: NTrond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NYongqiang Liu <liuyongqiang13@huawei.com>
上级 67d8c495
...@@ -897,8 +897,10 @@ int rpc_malloc(struct rpc_task *task) ...@@ -897,8 +897,10 @@ int rpc_malloc(struct rpc_task *task)
struct rpc_buffer *buf; struct rpc_buffer *buf;
gfp_t gfp = GFP_NOIO | __GFP_NOWARN; gfp_t gfp = GFP_NOIO | __GFP_NOWARN;
if (RPC_IS_ASYNC(task))
gfp = GFP_NOWAIT | __GFP_NOWARN;
if (RPC_IS_SWAPPER(task)) if (RPC_IS_SWAPPER(task))
gfp = __GFP_MEMALLOC | GFP_NOWAIT | __GFP_NOWARN; gfp |= __GFP_MEMALLOC;
size += sizeof(struct rpc_buffer); size += sizeof(struct rpc_buffer);
if (size <= RPC_BUFFER_MAXSIZE) if (size <= RPC_BUFFER_MAXSIZE)
......
...@@ -647,8 +647,10 @@ xprt_rdma_allocate(struct rpc_task *task) ...@@ -647,8 +647,10 @@ xprt_rdma_allocate(struct rpc_task *task)
gfp_t flags; gfp_t flags;
flags = RPCRDMA_DEF_GFP; flags = RPCRDMA_DEF_GFP;
if (RPC_IS_ASYNC(task))
flags = GFP_NOWAIT | __GFP_NOWARN;
if (RPC_IS_SWAPPER(task)) if (RPC_IS_SWAPPER(task))
flags = __GFP_MEMALLOC | GFP_NOWAIT | __GFP_NOWARN; flags |= __GFP_MEMALLOC;
if (!rpcrdma_get_sendbuf(r_xprt, req, rqst->rq_callsize, flags)) if (!rpcrdma_get_sendbuf(r_xprt, req, rqst->rq_callsize, flags))
goto out_fail; goto out_fail;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册