From patchwork Thu Apr 7 15:38:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12805392 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 C5D71C433EF for ; Thu, 7 Apr 2022 15:44:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241339AbiDGPqw (ORCPT ); Thu, 7 Apr 2022 11:46:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345124AbiDGPqh (ORCPT ); Thu, 7 Apr 2022 11:46:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69C00C6B62 for ; Thu, 7 Apr 2022 08:44:33 -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 3B88361B8E for ; Thu, 7 Apr 2022 15:44:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 360B0C385A4 for ; Thu, 7 Apr 2022 15:44:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649346271; bh=/0aHu6lQWcAuZqBeYBDiYAEFbo9Ggxhgm5iutTtf7Hk=; h=From:To:Subject:Date:From; b=qYKnYJanVtcfqhnzZeYHI9yooQlV4P5G8MF4Z+LvHr7ElsKVJptnFjzQvSczF7Zox GqEDKhAXLm71tu7fCsb1Y7FM73hP2IfAvGpbcFmo9HcxCYGNEwl5Q0XvHyUfWUItLq SHFLEX+1gJICoc256z78/ZV38y86O1Ve9BUKRBqO4kQPpTa/Sbksi0sxVQ1WW/POFt BLfn+pS+vuP/rsot3KnoWr+NGIIRpeWTSHmULA26u1Ow/3EdrBI8JOGo4N4VvhcYIk 4HKztlW4moxBdnt2dJJldX+bWpWKJmFKrWrDy5CzzSYBh9AXag8kMiMbsgG2cjlQ9H tong+VUSJfnCQ== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH 1/7] NFSv4.2: Fix missing removal of SLAB_ACCOUNT on kmem_cache allocation Date: Thu, 7 Apr 2022 11:38:03 -0400 Message-Id: <20220407153809.1053261-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 15:38:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12805393 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 A40B3C4332F for ; Thu, 7 Apr 2022 15:44:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345080AbiDGPqx (ORCPT ); Thu, 7 Apr 2022 11:46:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345123AbiDGPqh (ORCPT ); Thu, 7 Apr 2022 11:46:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68C18C6B54 for ; Thu, 7 Apr 2022 08:44:33 -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 9CEEE61EB6 for ; Thu, 7 Apr 2022 15:44:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E962C385B2 for ; Thu, 7 Apr 2022 15:44:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649346271; bh=JdLNTLNoccxME1ykAb6vaTCpoobIqzNPmf+4E3wWhbQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kagtjd/dZvZ/+AyyYVU6oxUubBo8nSgkDykUAzBT4yC9wrv/pRo/dEYEyKsF7DKQS 57PdCFqZQs4nJdtIdvR1m8tGZv9xe4wi3JP5hBfvR2xYyEldRA96EtNkmA1KZ3MIR8 xEFGO/UKo0+Gl42btaHgWJlLrxKdcFgYl2UEV2ajXtMsPxhP7rGhJihiFMmAdpTDJP d8AOXxJthBqWNMBPJQ2ZirrmtaZzFTTh20dJtvtCEi+C2LBiIG1V/8kCe9pnWRxleR KmktIWcvrF3yOTmKW4iQs+PPGOCquFPYTHvmu+pOU3zLNlcnDQmWYA9L9aTmqZGxwC xgy/Y4VNcNzKA== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH 2/7] SUNRPC: Handle ENOMEM in call_transmit_status() Date: Thu, 7 Apr 2022 11:38:04 -0400 Message-Id: <20220407153809.1053261-2-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407153809.1053261-1-trondmy@kernel.org> References: <20220407153809.1053261-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. 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 15:38:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12805397 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 9AEBDC433EF for ; Thu, 7 Apr 2022 15:45:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345101AbiDGPq7 (ORCPT ); Thu, 7 Apr 2022 11:46:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345135AbiDGPqr (ORCPT ); Thu, 7 Apr 2022 11:46:47 -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 7454DC6F1C for ; Thu, 7 Apr 2022 08:44:35 -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 B8734B826CB for ; Thu, 7 Apr 2022 15:44:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1328AC385BB for ; Thu, 7 Apr 2022 15:44:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649346272; bh=geHWlCNz2of9qKMfCACUjEJei7ZoXiDns4tDKdJ9Pk8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GvqorTkLiyL3RSdIdgZOd39vEcFXGf0UeKg0i0YrtPIykJBxfwPEW6NEZ7no64HLz 8PUF2Kc/tAB8/Dw6LVhqDjlJ3f0/RBPDD2SN/zuW06wuixbTEsGOIf4MmnZGR2FD6k rpEXoqcbTsmlf08Gif7Hzt6CiksfFSmpxsk+EExpwCPQ1HOCwKAToS8bdPQay0XSZ6 8eMgM8T8dLXqPdQrYcTzaklHXbTQErq/jzmXzLcqxhApeH6GmotV9H2y4Xha8pWW9Y g5f2nBPsMz2pDGA9dyanSDdAgbASvninOM2i+rembs9NAIwt4g8gvmrRevB7AyRCx9 g8oExaWDbTPzQ== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH 3/7] SUNRPC: Handle low memory situations in call_status() Date: Thu, 7 Apr 2022 11:38:05 -0400 Message-Id: <20220407153809.1053261-3-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407153809.1053261-2-trondmy@kernel.org> References: <20220407153809.1053261-1-trondmy@kernel.org> <20220407153809.1053261-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. 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 15:38:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12805398 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 DAE0DC433EF for ; Thu, 7 Apr 2022 15:45:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345025AbiDGPrV (ORCPT ); Thu, 7 Apr 2022 11:47:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345104AbiDGPqr (ORCPT ); Thu, 7 Apr 2022 11:46:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C92EC6B7A for ; Thu, 7 Apr 2022 08:44:34 -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 6927061EC5 for ; Thu, 7 Apr 2022 15:44:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82AFAC385A4 for ; Thu, 7 Apr 2022 15:44:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649346272; bh=pj6f8DlWv3kPYUyaziTO0UM8iZIeqmqtlEJMypSzRhQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jvZG9czSd403JHlkKDkOZZaTdfMUJ06XR3QXX3FbR6HHlzV6fwLJI3gidpwL81TyH iqchSy+3pdTxhIsLFgW9tB1NDaNKnLHk9QeydtrW1F2U2TNJOiAayfCQwHFOQHRwuQ DgeXmgO1qfTKJPIS0N0UjCX11ufW4ulLZ377m7/Phjdny+wQS7mwo5PSL0Ili/Gzqe APARN66cODfiD8Bx5ldbFGqN8cCe7bJDbLMKiJpEaVDwOtMf7Njg8VNoJorE9c1uBp MG0AwcJeYzDYmEWQzIsxhZOkbOJiyDlDJxbeXiMXEmz64uoJ+06BcEcx4AhdxhX07j NoeRv06KnQGqw== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH 4/7] NFSv4/pnfs: Handle RPC allocation errors in nfs4_proc_layoutget Date: Thu, 7 Apr 2022 11:38:06 -0400 Message-Id: <20220407153809.1053261-4-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407153809.1053261-3-trondmy@kernel.org> References: <20220407153809.1053261-1-trondmy@kernel.org> <20220407153809.1053261-2-trondmy@kernel.org> <20220407153809.1053261-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. 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 15:38:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12805395 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 6B186C4332F for ; Thu, 7 Apr 2022 15:45:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345188AbiDGPq5 (ORCPT ); Thu, 7 Apr 2022 11:46:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345131AbiDGPqh (ORCPT ); Thu, 7 Apr 2022 11:46:37 -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 C872AC6EEB for ; Thu, 7 Apr 2022 08:44:34 -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 D5DA761ECD for ; Thu, 7 Apr 2022 15:44:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE9BAC385A5 for ; Thu, 7 Apr 2022 15:44:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649346273; bh=w8nqzRSE2X/ijqhm1W+uvklvYb3WU3hFSLvEYTI4jWg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PlTY2Bc6kMhji+YCNY1zbyjEA9KYR4/0m7gKdJpVQkdKM69s4wLHQlCvlRdofLsDf Fk7kKqpAEFuW0C1mnDUhBA2W7oXtwSkb8KmfGz1Pwh1QxjOOWxcVMg8fL8gjcb8Hms szVyHCJAVhyxiQrLr1aeGJY3M2dbOhPZxrOicuO7FRXV04lErIj2aNIo3BsK/w1ZrF iEPz5hXkf4YC5dl1XZOa9tv9h5JlO8NavxH3uEp2srkXcOEqbd0pfPYQyqJzyvsglb 81fSGl+JbkPDJ/+YRxlN2DXsDPyf/9TAfMwkyosWM7H+LWU2u64Fh/PGDpWgUGOzbu C/xz/JeVzAodw== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH 5/7] NFS: Ensure rpc_run_task() cannot fail in nfs_async_rename() Date: Thu, 7 Apr 2022 11:38:07 -0400 Message-Id: <20220407153809.1053261-5-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407153809.1053261-4-trondmy@kernel.org> References: <20220407153809.1053261-1-trondmy@kernel.org> <20220407153809.1053261-2-trondmy@kernel.org> <20220407153809.1053261-3-trondmy@kernel.org> <20220407153809.1053261-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. 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 15:38:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12805394 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 66D97C433FE for ; Thu, 7 Apr 2022 15:44:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345182AbiDGPq5 (ORCPT ); Thu, 7 Apr 2022 11:46:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345130AbiDGPqh (ORCPT ); Thu, 7 Apr 2022 11:46:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89281C6EE8 for ; Thu, 7 Apr 2022 08:44:34 -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 CDB8761EC1 for ; Thu, 7 Apr 2022 15:44:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60A94C385A9 for ; Thu, 7 Apr 2022 15:44:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649346273; bh=BjRUl9xvDLy47XQuB0DZe/W57Oa4+dauIzR16hGbzfc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=HhOib/X3kHKzYQExPiWMCycdjhRV24omFy65rADXtDTk+tc9T3xe57qjJ4l8JwOXK VMQfcmvqD5LHP/lkJHowaJIU9Qsvx76zBLaDeNEPSadkyWCAkJa9SfUeEbLBpxkH+k rKM0Ru8x8irTgT6+7DwN8aOWNsQ0uJN07lcOUTUtWrzzvRTnCyRJuzWtSj0PqZtKaB /Qchby9aCySMd+qW2cHy1cbrDETtYoQ6OspW+Ih4FyStnuSfjysmGVjiC3okSDJdWP w25QQY9YCBqQ23kMhkCfc0h8zo63Z1Pu6IzghvGenKsFkbAH54dFXLVjHMQ/uWtA0y 8pQwZoMngzOfg== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH 6/7] SUNRPC: Handle allocation failure in rpc_new_task() Date: Thu, 7 Apr 2022 11:38:08 -0400 Message-Id: <20220407153809.1053261-6-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407153809.1053261-5-trondmy@kernel.org> References: <20220407153809.1053261-1-trondmy@kernel.org> <20220407153809.1053261-2-trondmy@kernel.org> <20220407153809.1053261-3-trondmy@kernel.org> <20220407153809.1053261-4-trondmy@kernel.org> <20220407153809.1053261-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 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 15:38:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trond Myklebust X-Patchwork-Id: 12805396 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 48678C43217 for ; Thu, 7 Apr 2022 15:45:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345196AbiDGPq6 (ORCPT ); Thu, 7 Apr 2022 11:46:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345101AbiDGPqi (ORCPT ); Thu, 7 Apr 2022 11:46:38 -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 8215EC6F21 for ; Thu, 7 Apr 2022 08:44:35 -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 D0F3461B8E for ; Thu, 7 Apr 2022 15:44:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6A51C385AA for ; Thu, 7 Apr 2022 15:44:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649346274; bh=ZBqeJfKcLA80ny5CZGoA9SnCqhrKZWAqtslhR/LejX8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=i31to0SOiZQ11/HKfhgeQXDfT51aJx+ZFR3m2bTwFH0/gJRTHuc10jMtD8XtutyF+ 1+1lP9JZU55yVplelyRqumYcDjJcL8Hs28l3Cq85Fuc+Ykt70Jodpjey5TIwb5NgWw VE6EkSTOBliRsBJfDyCjK3MRKLZlOT81SRk/UFao2w1+EpuaNd0rnZ446IeM3IprqJ zCAe92vRIb7yH5+7hZwZmsippnFCbwDKDl+59ND6PLjzaTbbiwX/RzLS57lXmXz2pD VlJ84r9gHTcrH859OASnwZaj0OBuOSeO5qVD2q9+8W7huic49q0YU2l1RHbAOX0myw 6C/3dbuqCnZLw== From: trondmy@kernel.org To: linux-nfs@vger.kernel.org Subject: [PATCH 7/7] SUNRPC: Move the call to xprt_send_pagedata() out of xprt_sock_sendmsg() Date: Thu, 7 Apr 2022 11:38:09 -0400 Message-Id: <20220407153809.1053261-7-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407153809.1053261-6-trondmy@kernel.org> References: <20220407153809.1053261-1-trondmy@kernel.org> <20220407153809.1053261-2-trondmy@kernel.org> <20220407153809.1053261-3-trondmy@kernel.org> <20220407153809.1053261-4-trondmy@kernel.org> <20220407153809.1053261-5-trondmy@kernel.org> <20220407153809.1053261-6-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 Signed-off-by: Trond Myklebust --- net/sunrpc/socklib.c | 6 ------ net/sunrpc/svcsock.c | 13 +++++++++---- net/sunrpc/xprtsock.c | 15 +++++++++++++-- 3 files changed, 22 insertions(+), 12 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 478f857cdaed..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; @@ -1096,7 +1099,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) 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)))