From patchwork Thu Apr 7 18:45:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12805614 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 206E2C4332F for ; Thu, 7 Apr 2022 18:52:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347005AbiDGSy3 (ORCPT ); Thu, 7 Apr 2022 14:54:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347004AbiDGSy2 (ORCPT ); Thu, 7 Apr 2022 14:54:28 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B84141834C7 for ; Thu, 7 Apr 2022 11:52:27 -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 ams.source.kernel.org (Postfix) with ESMTPS id 7A4C4B82607 for ; Thu, 7 Apr 2022 18:52:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17760C385A4 for ; Thu, 7 Apr 2022 18:52:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649357545; bh=/0aHu6lQWcAuZqBeYBDiYAEFbo9Ggxhgm5iutTtf7Hk=; h=From:To:Subject:Date:From; b=SDcnVMfLbr+aSEPwFqg7aZkAFSZbnz6k82XQ+CLcrblWe6zIMFCAA0smiFNDjx88K tZt6Kg/YaY+86TfVbAEyuWeMHGvQlPaZgV8dzFUED9iIinKZmb82BmSuxv8AWiNSmZ Vu8ko4R7oCgGQO7MyJuWCPloZGYNzGjkl9kyVmFduOyrXOOm2kTSbJk8PVDQZMFBnk 6SoqjDuqREqysIRsbKBXV2eFXNszEC6cLYBBvY4LoPyKU7SEvHSo1R6rTWY2FtIaTv Te439vwdBRl82URiJXrLV3fYNor/BIQPmRsheWK5HNelHiIzo6cTjLNJ6aSRU/ikzB BkewS50iFPfsg== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v2 1/8] NFSv4.2: Fix missing removal of SLAB_ACCOUNT on kmem_cache allocation Date: Thu, 7 Apr 2022 14:45:54 -0400 Message-Id: <20220407184601.1064640-1-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Muchun Song The commit 5c60e89e71f8 ("NFSv4.2: Fix up an invalid combination of memory allocation flags") has stripped GFP_KERNEL_ACCOUNT down to GFP_KERNEL, however, it forgot to remove SLAB_ACCOUNT from kmem_cache allocation. It means that memory is still limited by kmemcg. This patch also fix a NULL pointer reference issue [1] reported by NeilBrown. Link: https://lore.kernel.org/all/164870069595.25542.17292003658915487357@noble.neil.brown.name/ [1] Fixes: 5c60e89e71f8 ("NFSv4.2: Fix up an invalid combination of memory allocation flags") Fixes: 5abc1e37afa0 ("mm: list_lru: allocate list_lru_one only when needed") Reported-by: NeilBrown Signed-off-by: Muchun Song Signed-off-by: Trond Myklebust --- fs/nfs/nfs42xattr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/nfs/nfs42xattr.c b/fs/nfs/nfs42xattr.c index ad3405c64b9e..e7b34f7e0614 100644 --- a/fs/nfs/nfs42xattr.c +++ b/fs/nfs/nfs42xattr.c @@ -997,7 +997,7 @@ int __init nfs4_xattr_cache_init(void) nfs4_xattr_cache_cachep = kmem_cache_create("nfs4_xattr_cache_cache", sizeof(struct nfs4_xattr_cache), 0, - (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_ACCOUNT), + (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD), nfs4_xattr_cache_init_once); if (nfs4_xattr_cache_cachep == NULL) return -ENOMEM; From patchwork Thu Apr 7 18:45:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12805616 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B803C433F5 for ; Thu, 7 Apr 2022 18:52:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347008AbiDGSyb (ORCPT ); Thu, 7 Apr 2022 14:54:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347007AbiDGSy3 (ORCPT ); Thu, 7 Apr 2022 14:54:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79C0E195318 for ; Thu, 7 Apr 2022 11:52:28 -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 ams.source.kernel.org (Postfix) with ESMTPS id ED924B82964 for ; Thu, 7 Apr 2022 18:52:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8195DC385A6 for ; Thu, 7 Apr 2022 18:52:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649357545; bh=EnGFPXwFmV30OHTUGDdJOtNW6uPHvBWYnfRHsJMk4s0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iDg8bn6ApcHl9RD+xRX6JzkCx1OLEUY/d5NyON/AYtZ9rb0V2qyrRAL5gfhPtIPRI Lf9Ig9vSVSs7kzg/MCF1Y/WB5alarC5A8rkzDcQP8MMA4G627C1R2plpsnPplb8gCF fXQ6OfwuGIcm8h77cAxNbwCUWvydc/C7l1eIh0mvOzgoxVJseF3Z9VKX4SuzXV02i6 Lb2gt78jJ+oRK/5nyX7v5ZKvGsCyBqj63lt0xT2pcb3iJPvf/b5U8j+KdUwe2209fU OJESiAmP2HbJb4wttKW2EhgcPPUxMHVns5QIMoYtJSXzrnvsB3nqVzum5GJQPsEThm T0HFhM+z+bIlQ== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v2 2/8] SUNRPC: Handle ENOMEM in call_transmit_status() Date: Thu, 7 Apr 2022 14:45:55 -0400 Message-Id: <20220407184601.1064640-2-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407184601.1064640-1-trondmy@kernel.org> References: <20220407184601.1064640-1-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust Both call_transmit() and call_bc_transmit() can now return ENOMEM, so let's make sure that we handle the errors gracefully. Fixes: 0472e4766049 ("SUNRPC: Convert socket page send code to use iov_iter()") Signed-off-by: Trond Myklebust --- net/sunrpc/clnt.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index 3c7407104d54..07328f1d3885 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c @@ -2200,6 +2200,7 @@ call_transmit_status(struct rpc_task *task) * socket just returned a connection error, * then hold onto the transport lock. */ + case -ENOMEM: case -ENOBUFS: rpc_delay(task, HZ>>2); fallthrough; @@ -2283,6 +2284,7 @@ call_bc_transmit_status(struct rpc_task *task) case -ENOTCONN: case -EPIPE: break; + case -ENOMEM: case -ENOBUFS: rpc_delay(task, HZ>>2); fallthrough; From patchwork Thu Apr 7 18:45:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12805612 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 872FBC433F5 for ; Thu, 7 Apr 2022 18:52:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233488AbiDGSy2 (ORCPT ); Thu, 7 Apr 2022 14:54:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347003AbiDGSy1 (ORCPT ); Thu, 7 Apr 2022 14:54: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 2C007194832 for ; Thu, 7 Apr 2022 11:52:27 -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 B404961DD2 for ; Thu, 7 Apr 2022 18:52:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E83D2C385A0 for ; Thu, 7 Apr 2022 18:52:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649357546; bh=v1GKfdZJkhBCnWe0zT+yWOMIjvsz805Rs3wLq8CE51M=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Oz6nSMkcqvTFaSYb0Z9iE+P4QtRGDKRlMuUQs7Xn8gma4h7ECbGPz3GR9yif5nxMQ 6YnMd37wZmRdXlZmZY9AnkPtmVrJoJStxSiVc7ATCr8q/PbqbUyqwlS8e/NSQQoJJm +weJSVZBLxx5oeGg6THNYcHVUaJfB6HmLSBoM6/L+aBx1kQHKHzlkc5WBt88vbVFug aINYlfn5GIpkPbGDImr7L01I5w0FchHikuBJwYN9BpfnG8beKrfpWwDyosS3LTeeKW S3b5jIDbqfQimsTo6Xr+HROiNNjVoNzdJbSUdnxetfSONvC4iM4bGpxnVDkzVC522S wH5MUcVQniygg== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v2 3/8] SUNRPC: Handle low memory situations in call_status() Date: Thu, 7 Apr 2022 14:45:56 -0400 Message-Id: <20220407184601.1064640-3-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407184601.1064640-2-trondmy@kernel.org> References: <20220407184601.1064640-1-trondmy@kernel.org> <20220407184601.1064640-2-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust We need to handle ENFILE, ENOBUFS, and ENOMEM, because xprt_wake_pending_tasks() can be called with any one of these due to socket creation failures. Fixes: b61d59fffd3e ("SUNRPC: xs_tcp_connect_worker{4,6}: merge common code") Signed-off-by: Trond Myklebust --- net/sunrpc/clnt.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index 07328f1d3885..6757b0fa5367 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c @@ -2367,6 +2367,11 @@ call_status(struct rpc_task *task) case -EPIPE: case -EAGAIN: break; + case -ENFILE: + case -ENOBUFS: + case -ENOMEM: + rpc_delay(task, HZ>>2); + break; case -EIO: /* shutdown or soft timeout */ goto out_exit; From patchwork Thu Apr 7 18:45:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12805617 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0545C433EF for ; Thu, 7 Apr 2022 18:52:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347007AbiDGSyc (ORCPT ); Thu, 7 Apr 2022 14:54:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347010AbiDGSya (ORCPT ); Thu, 7 Apr 2022 14:54:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0975F194FD8 for ; Thu, 7 Apr 2022 11:52:29 -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 ams.source.kernel.org (Postfix) with ESMTPS id B975FB8260C for ; Thu, 7 Apr 2022 18:52:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CD49C385AA for ; Thu, 7 Apr 2022 18:52:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649357546; bh=67FHcUEJDcE6LZMJdrQMRSXw8wfeTRKDUHlK2IpEf2M=; h=From:To:Subject:Date:In-Reply-To:References:From; b=IusFPMdpAO84X90SCqwixdwBRFZrikfL21+WvJWNGXGoSIP+FTaos9aKG3GjpS3Ps Zvn1jHRTmevBPq2SXqLonSIF2u1tjtFxtLRITqH+Nr/DXM2PV3Vu8w0fBB44UIzVd6 cgxqEWbF0+FfUeOLyKJLFnhkOo1KnCyStreUc5Fo3NxUobFoACy1zCYAuhfIVAMpy0 re9YI0fCwCT3Wbfjx5B5L+L5LntsUP+Zj9IUOdgvozKWaUu+jL+qzPw8SMLI/nLFFS Qec9NbKFfXp048nYKKweJLZs01wVZL27RceRUQ9LyWY7+IDHTtvTJUp2DhRuIkfkL4 fbgXdd2qYBfvg== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v2 4/8] NFSv4/pnfs: Handle RPC allocation errors in nfs4_proc_layoutget Date: Thu, 7 Apr 2022 14:45:57 -0400 Message-Id: <20220407184601.1064640-4-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407184601.1064640-3-trondmy@kernel.org> References: <20220407184601.1064640-1-trondmy@kernel.org> <20220407184601.1064640-2-trondmy@kernel.org> <20220407184601.1064640-3-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust If rpc_run_task() fails due to an allocation error, then bail out early. Fixes: 910ad38697d9 ("NFS: Fix memory allocation in rpc_alloc_task()") Signed-off-by: Trond Myklebust --- fs/nfs/nfs4proc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index e3f5b380cefe..16106f805ffa 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -9615,6 +9615,8 @@ nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout) nfs4_init_sequence(&lgp->args.seq_args, &lgp->res.seq_res, 0, 0); task = rpc_run_task(&task_setup_data); + if (IS_ERR(task)) + return ERR_CAST(task); status = rpc_wait_for_completion_task(task); if (status != 0) From patchwork Thu Apr 7 18:45:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12805613 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69B8DC433EF for ; Thu, 7 Apr 2022 18:52:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347003AbiDGSy2 (ORCPT ); Thu, 7 Apr 2022 14:54:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347005AbiDGSy2 (ORCPT ); Thu, 7 Apr 2022 14:54:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5C24194FD8 for ; Thu, 7 Apr 2022 11:52:27 -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 7F69761DD8 for ; Thu, 7 Apr 2022 18:52:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2999C385A4 for ; Thu, 7 Apr 2022 18:52:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649357546; bh=Zscj20Ax5HbRGyhailQq0xwvJA8LRNJg/hclC6BAr+w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=prNq6Kyp0nk5e60FaFI1VU79hobISgr+5ob4JKrWBytBpFTCEmRsNlT0woKIUbKzy n74s82AdoshbMlWiGMGo8/CeLtLy0QXzE+aT30UttDBkshz6FqghqOQOlBQoY5TFnG GshykJa7l60Gl22PonFKEEVQBs1oZMQFQClhBxJxRAfS//eq3UDficZNzvAqo85PCN 79Umqek+CwNtHOouOmKIq0w5IAsFALcU49ZuFcsrkYGZDRms7SoaOaQL7TKDeehXhI iEKy5OL88pw5UZDLDw9OhlhvXo2a4fPez03Sa8JmduwfzDZ/nQpkmqRapZ7iZAsDEM dMZzTAcIEiKsQ== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v2 5/8] NFS: Ensure rpc_run_task() cannot fail in nfs_async_rename() Date: Thu, 7 Apr 2022 14:45:58 -0400 Message-Id: <20220407184601.1064640-5-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407184601.1064640-4-trondmy@kernel.org> References: <20220407184601.1064640-1-trondmy@kernel.org> <20220407184601.1064640-2-trondmy@kernel.org> <20220407184601.1064640-3-trondmy@kernel.org> <20220407184601.1064640-4-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust Ensure the call to rpc_run_task() cannot fail by preallocating the rpc_task. Fixes: 910ad38697d9 ("NFS: Fix memory allocation in rpc_alloc_task()") Signed-off-by: Trond Myklebust --- fs/nfs/unlink.c | 1 + include/linux/nfs_xdr.h | 1 + 2 files changed, 2 insertions(+) diff --git a/fs/nfs/unlink.c b/fs/nfs/unlink.c index 5fa11e1aca4c..6f325e10056c 100644 --- a/fs/nfs/unlink.c +++ b/fs/nfs/unlink.c @@ -347,6 +347,7 @@ nfs_async_rename(struct inode *old_dir, struct inode *new_dir, data = kzalloc(sizeof(*data), GFP_KERNEL); if (data == NULL) return ERR_PTR(-ENOMEM); + task_setup_data.task = &data->task; task_setup_data.callback_data = data; data->cred = get_current_cred(); diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h index 49ba486aea5f..2863e5a69c6a 100644 --- a/include/linux/nfs_xdr.h +++ b/include/linux/nfs_xdr.h @@ -1694,6 +1694,7 @@ struct nfs_unlinkdata { struct nfs_renamedata { struct nfs_renameargs args; struct nfs_renameres res; + struct rpc_task task; const struct cred *cred; struct inode *old_dir; struct dentry *old_dentry; From patchwork Thu Apr 7 18:45:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12805619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDE4FC4332F for ; Thu, 7 Apr 2022 18:52:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230229AbiDGSye (ORCPT ); Thu, 7 Apr 2022 14:54:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347013AbiDGSya (ORCPT ); Thu, 7 Apr 2022 14:54:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6508196096 for ; Thu, 7 Apr 2022 11:52:29 -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 ams.source.kernel.org (Postfix) with ESMTPS id 98BF6B82970 for ; Thu, 7 Apr 2022 18:52:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37D88C385A0 for ; Thu, 7 Apr 2022 18:52:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649357547; bh=xdv+jPjcRgWYaV6oupqdJ5g63CNqVsQ8fEK8trdMFHM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=D/jJiIFeMF8394isyd5lVsivHmKxUHO8IqBH2Ly+zJNlyut+Ji2bKZtabz18tTdSE jhpEnbFbl6EFevmRwZvAiZLyGtYV+kqcs2VwnLLSCQ2EChvEzuUgdQptKlTR5cog2m uY3n2Zot9Q1GVH2z0cYU7zBB0DcNgVuBVCORbvPs7oKyir4BFfn+e1fYf1dnBiUZV7 9FMS52KKfJrGMALMzsvu3+sDfWO2EycVu0vKSss+KWkM0GQcY1F2ed4GBTBP2pVjfj ldYV5fVjgSnL7B2Kc151rtFeHSvSI+HVP1X8Iy9ZYVCX8b5IVOA5kGB4BNzxHHf6LC gvTlo7I0ZuaGw== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v2 6/8] SUNRPC: Handle allocation failure in rpc_new_task() Date: Thu, 7 Apr 2022 14:45:59 -0400 Message-Id: <20220407184601.1064640-6-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407184601.1064640-5-trondmy@kernel.org> References: <20220407184601.1064640-1-trondmy@kernel.org> <20220407184601.1064640-2-trondmy@kernel.org> <20220407184601.1064640-3-trondmy@kernel.org> <20220407184601.1064640-4-trondmy@kernel.org> <20220407184601.1064640-5-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust If the call to rpc_alloc_task() fails, then ensure that the calldata is released, and that rpc_run_task() and rpc_run_bc_task() bail out early. Reported-by: NeilBrown Fixes: 910ad38697d9 ("NFS: Fix memory allocation in rpc_alloc_task()") Signed-off-by: Trond Myklebust --- net/sunrpc/clnt.c | 7 +++++++ net/sunrpc/sched.c | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c index 6757b0fa5367..af0174d7ce5a 100644 --- a/net/sunrpc/clnt.c +++ b/net/sunrpc/clnt.c @@ -1127,6 +1127,8 @@ struct rpc_task *rpc_run_task(const struct rpc_task_setup *task_setup_data) struct rpc_task *task; task = rpc_new_task(task_setup_data); + if (IS_ERR(task)) + return task; if (!RPC_IS_ASYNC(task)) task->tk_flags |= RPC_TASK_CRED_NOREF; @@ -1227,6 +1229,11 @@ struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req) * Create an rpc_task to send the data */ task = rpc_new_task(&task_setup_data); + if (IS_ERR(task)) { + xprt_free_bc_request(req); + return task; + } + xprt_init_bc_request(req, task); task->tk_action = call_bc_encode; diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c index b258b87a3ec2..7f70c1e608b7 100644 --- a/net/sunrpc/sched.c +++ b/net/sunrpc/sched.c @@ -1128,6 +1128,11 @@ struct rpc_task *rpc_new_task(const struct rpc_task_setup *setup_data) if (task == NULL) { task = rpc_alloc_task(); + if (task == NULL) { + rpc_release_calldata(setup_data->callback_ops, + setup_data->callback_data); + return ERR_PTR(-ENOMEM); + } flags = RPC_TASK_DYNAMIC; } From patchwork Thu Apr 7 18:46:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12805615 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E73EFC433EF for ; Thu, 7 Apr 2022 18:52:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347014AbiDGSya (ORCPT ); Thu, 7 Apr 2022 14:54:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347008AbiDGSy3 (ORCPT ); Thu, 7 Apr 2022 14:54:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79CF2195338 for ; Thu, 7 Apr 2022 11:52:28 -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 F0BC661DA5 for ; Thu, 7 Apr 2022 18:52:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4280C385A4 for ; Thu, 7 Apr 2022 18:52:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649357547; bh=GaFjUOZTSMhrtwTWxNX8cUUnv05zT8jAdmJkkZCIX7o=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gDj5D4ciUGGhsspMMBkszbDw54keCWacuY0m4bDwkDyUHwWIMxJfGpR2DF2DTps/F zbWhaErPlxMeeIQS2kOpiTeQGCnhLNmv1eaGYlFQnLgDgNA07ILMOjnK8erHjOYJYE PVXjXcfb7QO2Dg4jVx6j7iGALdD//nkNWxRDo5zY2KPUl5UT51AxyATDGvL70JOKEZ +Hy41DO1SZthS09g2bVsSbi4YHMtRfXuDTcIDVYvaagrrtlIKyaecPxW0gOrOWgd+C PURGfqSuSARcZu7SQOIsTRA8EzlaTTo8iLZf5zCiJyQ4T+LvaoFtdB1K9uf2BKN8eO p5hQ/Ism70LTQ== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v2 7/8] SUNRPC: svc_tcp_sendmsg() should handle errors from xdr_alloc_bvec() Date: Thu, 7 Apr 2022 14:46:00 -0400 Message-Id: <20220407184601.1064640-7-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407184601.1064640-6-trondmy@kernel.org> References: <20220407184601.1064640-1-trondmy@kernel.org> <20220407184601.1064640-2-trondmy@kernel.org> <20220407184601.1064640-3-trondmy@kernel.org> <20220407184601.1064640-4-trondmy@kernel.org> <20220407184601.1064640-5-trondmy@kernel.org> <20220407184601.1064640-6-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust The allocation is done with GFP_KERNEL, but it could still fail in a low memory situation. Fixes: 4a85a6a3320b ("SUNRPC: Handle TCP socket sends with kernel_sendpage() again") Signed-off-by: Trond Myklebust --- net/sunrpc/svcsock.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c index 478f857cdaed..6ea3d87e1147 100644 --- a/net/sunrpc/svcsock.c +++ b/net/sunrpc/svcsock.c @@ -1096,7 +1096,9 @@ static int svc_tcp_sendmsg(struct socket *sock, struct xdr_buf *xdr, int ret; *sentp = 0; - xdr_alloc_bvec(xdr, GFP_KERNEL); + ret = xdr_alloc_bvec(xdr, GFP_KERNEL); + if (ret < 0) + return ret; ret = kernel_sendmsg(sock, &msg, &rm, 1, rm.iov_len); if (ret < 0) From patchwork Thu Apr 7 18:46:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12805618 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB965C433FE for ; Thu, 7 Apr 2022 18:52:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347004AbiDGSyd (ORCPT ); Thu, 7 Apr 2022 14:54:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347009AbiDGSya (ORCPT ); Thu, 7 Apr 2022 14:54:30 -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 C98C61834C7 for ; Thu, 7 Apr 2022 11:52:28 -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 5610A61DE8 for ; Thu, 7 Apr 2022 18:52:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0811BC385A6 for ; Thu, 7 Apr 2022 18:52:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649357548; bh=EqdUAZd8WBm9afbdm9YM2jUQej1o7enVtbJ6jOPJwhE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=BgT3OmIbKxEGABxDycMia1+AtsR2HUsetM0RTVUegyU90CpcKyplMLaRhRxJyVCMq ScvA0Jqq2x3CJuk/spupdri+3LGtWqzAR29naFfKB0ruda1PlGquTxjtAxgBOsEE95 xYra0tsmSXVhFyen0KqMqHcMGRTDzmRcdfw6TVu3Mf3n/oPyXa7l4g9VPxWOIDVWze 5xjFD6iBh4luCbeNeVe+M8BhZAlZRVLk2L6wAMm9FF2hNL5KahnxC6UnzbqUFSKvha Re4lUoGkjdK7fnLVUHQtLu9jDEFF1Bq3mqegBLUimkVAlu63qDzEm942jsPa4RiHpr +xCMCE+8MMd5A== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH v2 8/8] SUNRPC: Move the call to xprt_send_pagedata() out of xprt_sock_sendmsg() Date: Thu, 7 Apr 2022 14:46:01 -0400 Message-Id: <20220407184601.1064640-8-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407184601.1064640-7-trondmy@kernel.org> References: <20220407184601.1064640-1-trondmy@kernel.org> <20220407184601.1064640-2-trondmy@kernel.org> <20220407184601.1064640-3-trondmy@kernel.org> <20220407184601.1064640-4-trondmy@kernel.org> <20220407184601.1064640-5-trondmy@kernel.org> <20220407184601.1064640-6-trondmy@kernel.org> <20220407184601.1064640-7-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust The client and server have different requirements for their memory allocation, so move the allocation of the send buffer out of the socket send code that is common to both. Reported-by: NeilBrown Fixes: b2648015d452 ("SUNRPC: Make the rpciod and xprtiod slab allocation modes consistent") Signed-off-by: Trond Myklebust --- net/sunrpc/socklib.c | 6 ------ net/sunrpc/svcsock.c | 9 ++++++--- net/sunrpc/xprtsock.c | 15 +++++++++++++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/net/sunrpc/socklib.c b/net/sunrpc/socklib.c index 05b38bf68316..71ba4cf513bc 100644 --- a/net/sunrpc/socklib.c +++ b/net/sunrpc/socklib.c @@ -221,12 +221,6 @@ static int xprt_send_kvec(struct socket *sock, struct msghdr *msg, static int xprt_send_pagedata(struct socket *sock, struct msghdr *msg, struct xdr_buf *xdr, size_t base) { - int err; - - err = xdr_alloc_bvec(xdr, rpc_task_gfp_mask()); - if (err < 0) - return err; - iov_iter_bvec(&msg->msg_iter, WRITE, xdr->bvec, xdr_buf_pagecount(xdr), xdr->page_len + xdr->page_base); return xprt_sendmsg(sock, msg, base + xdr->page_base); diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c index 6ea3d87e1147..cc35ec433400 100644 --- a/net/sunrpc/svcsock.c +++ b/net/sunrpc/svcsock.c @@ -579,15 +579,18 @@ static int svc_udp_sendto(struct svc_rqst *rqstp) if (svc_xprt_is_dead(xprt)) goto out_notconn; + err = xdr_alloc_bvec(xdr, GFP_KERNEL); + if (err < 0) + goto out_unlock; + err = xprt_sock_sendmsg(svsk->sk_sock, &msg, xdr, 0, 0, &sent); - xdr_free_bvec(xdr); if (err == -ECONNREFUSED) { /* ICMP error on earlier request. */ err = xprt_sock_sendmsg(svsk->sk_sock, &msg, xdr, 0, 0, &sent); - xdr_free_bvec(xdr); } + xdr_free_bvec(xdr); trace_svcsock_udp_send(xprt, err); - +out_unlock: mutex_unlock(&xprt->xpt_mutex); if (err < 0) return err; diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index a34a15750122..e16568f9a82d 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -825,9 +825,14 @@ static int xs_stream_nospace(struct rpc_rqst *req, bool vm_wait) static int xs_stream_prepare_request(struct rpc_rqst *req) { + gfp_t gfp = rpc_task_gfp_mask(); + int ret; + + ret = xdr_alloc_bvec(&req->rq_snd_buf, gfp); + if (ret < 0) + return ret; xdr_free_bvec(&req->rq_rcv_buf); - return xdr_alloc_bvec( - &req->rq_rcv_buf, GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN); + return xdr_alloc_bvec(&req->rq_rcv_buf, gfp); } /* @@ -956,6 +961,9 @@ static int xs_udp_send_request(struct rpc_rqst *req) if (!xprt_request_get_cong(xprt, req)) return -EBADSLT; + status = xdr_alloc_bvec(xdr, rpc_task_gfp_mask()); + if (status < 0) + return status; req->rq_xtime = ktime_get(); status = xprt_sock_sendmsg(transport->sock, &msg, xdr, 0, 0, &sent); @@ -2557,6 +2565,9 @@ static int bc_sendto(struct rpc_rqst *req) int err; req->rq_xtime = ktime_get(); + err = xdr_alloc_bvec(xdr, rpc_task_gfp_mask()); + if (err < 0) + return err; err = xprt_sock_sendmsg(transport->sock, &msg, xdr, 0, marker, &sent); xdr_free_bvec(xdr); if (err < 0 || sent != (xdr->len + sizeof(marker)))