Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp661110pxb; Tue, 5 Apr 2022 17:44:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwM6pHKhQJNCf/PYjY8taux3Jjn2PkyxLY2Q1oDY/FzfuGXzHIaKZUE98yXKuNnPpxYbiyc X-Received: by 2002:a17:907:97cc:b0:6da:a8fb:d1db with SMTP id js12-20020a17090797cc00b006daa8fbd1dbmr6027658ejc.267.1649205881850; Tue, 05 Apr 2022 17:44:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649205881; cv=none; d=google.com; s=arc-20160816; b=WoRYf49vPXOG6NvLdAleKvO+KbpCI2kGfnZ00lAdiXXnlLZKDRJ7jCbJLrCHSjCAxF lkVDk/TS/RxgCWnyV9HmLl74IYpU3gpxATKFQWRxh/C9Nr+ac4eFDsTwe3XpQhU4ssym VSHZrpGSW9kMYIGftxoOggkR/j6VaWZnrDO54vVKJdmOBTRcOtHvP7E9ipHSqhY97AVT NYEbgcgXMTbPHGqriVhIg7/TOGmXSSRrbT+NK4B34IgrNddTJQeXKWrIqU4DIFcv80qB Xsl67UKh2l3wbY3A8ZMmw68vDBjHqAL2dSvd0SMdG/jUxF6wse0jgLdfs6nSd18NwaEC bx3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=948nfg1YJdIsgXAjv/WHadV3dro+GdF/VMsMjL2ja0g=; b=iiTz0/Cf5PCF+JovFsDsBQBrU34w/wUQwEJqlUvQ7eTICEyx+uu+lZ6qYx/cgzybBs 8qmqxF991VtsIpMMmMQbX7eVyqlkRNTdwKOPy3PcEcUuqCmPc8VjctjvQWw+oqQQfKo4 SZZfQ3qvJlvGYEDybnINR5o1k/eKAJN8n/sZar7UkywWQzVkk1ewp0hwKEsJOzf3ycPM n2mbaAsWBTE3eA7nL76JYuOTxAcM6puKTtdwMBNA5SKcYkmYECXW01cj+X4apvUWVrRM kbfptYmrEAHSJee+VCYIHNvAY8w1FviYNZYighWiVQYdChVFBP58v/zqsn3Jv5mbUxAa 4FyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y886MNh4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b9-20020a170906728900b006df76385e40si12289754ejl.736.2022.04.05.17.44.17; Tue, 05 Apr 2022 17:44:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y886MNh4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358652AbiDENJb (ORCPT + 99 others); Tue, 5 Apr 2022 09:09:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344160AbiDEJS1 (ORCPT ); Tue, 5 Apr 2022 05:18:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DDC45880F; Tue, 5 Apr 2022 02:04:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E1B0461003; Tue, 5 Apr 2022 09:04:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1D23C385A3; Tue, 5 Apr 2022 09:04:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149481; bh=V+jffPj/n1B4osgu6LsAk2faz/RWgTBC0PsfbB1yEp8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y886MNh4SIPTYmMn7492ucgrt0yfVPePSHZ6KYphYkCXQo9uHa2ZZP/dbFwKJASA5 stnGyo6Hq/XPe7pYcT7kbbY3Q0qdbyVoPqX/R5SEiMxB5tw5VIeixD2Wh0OixrjQrp cF2gssgbGHBYoeOGKduf+NC2u6G2kWug1GpNRlI8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, NeilBrown , Trond Myklebust , Sasha Levin Subject: [PATCH 5.16 0713/1017] SUNRPC/call_alloc: async tasks mustnt block waiting for memory Date: Tue, 5 Apr 2022 09:27:06 +0200 Message-Id: <20220405070415.433782641@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: NeilBrown [ Upstream commit c487216bec83b0c5a8803e5c61433d33ad7b104d ] 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: NeilBrown Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- net/sunrpc/sched.c | 4 +++- net/sunrpc/xprtrdma/transport.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c index e2c835482791..d5b6e897f5a5 100644 --- a/net/sunrpc/sched.c +++ b/net/sunrpc/sched.c @@ -1023,8 +1023,10 @@ int rpc_malloc(struct rpc_task *task) struct rpc_buffer *buf; gfp_t gfp = GFP_NOFS; + if (RPC_IS_ASYNC(task)) + gfp = GFP_NOWAIT | __GFP_NOWARN; if (RPC_IS_SWAPPER(task)) - gfp = __GFP_MEMALLOC | GFP_NOWAIT | __GFP_NOWARN; + gfp |= __GFP_MEMALLOC; size += sizeof(struct rpc_buffer); if (size <= RPC_BUFFER_MAXSIZE) diff --git a/net/sunrpc/xprtrdma/transport.c b/net/sunrpc/xprtrdma/transport.c index 16e5696314a4..a52277115500 100644 --- a/net/sunrpc/xprtrdma/transport.c +++ b/net/sunrpc/xprtrdma/transport.c @@ -574,8 +574,10 @@ xprt_rdma_allocate(struct rpc_task *task) gfp_t flags; flags = RPCRDMA_DEF_GFP; + if (RPC_IS_ASYNC(task)) + flags = GFP_NOWAIT | __GFP_NOWARN; if (RPC_IS_SWAPPER(task)) - flags = __GFP_MEMALLOC | GFP_NOWAIT | __GFP_NOWARN; + flags |= __GFP_MEMALLOC; if (!rpcrdma_check_regbuf(r_xprt, req->rl_sendbuf, rqst->rq_callsize, flags)) -- 2.34.1