From patchwork Thu Apr 28 15:30: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: 12830931 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 624D8C433EF for ; Thu, 28 Apr 2022 15:36:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230054AbiD1Pj0 (ORCPT ); Thu, 28 Apr 2022 11:39:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233280AbiD1PjY (ORCPT ); Thu, 28 Apr 2022 11:39:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3FB7496A3 for ; Thu, 28 Apr 2022 08:36:09 -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 2618E61EA4 for ; Thu, 28 Apr 2022 15:36:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C24BC385A9; Thu, 28 Apr 2022 15:36:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651160168; bh=2ZzLX/nSMo3VhPl7kFlY98cwt8OokcpFyhsV9jwdx+U=; h=From:To:Subject:Date:From; b=sqKLQYrsClZpzqzDM9d73/JGFuqP03+6f8PK//i5VTPjdKsaBFgmtLR4xeeReRxXC Ba/Rm7ZK7EdZ5yWfTBBgSIt8wRsxxtT8Inm8YRse4oKOTgXzv0XuS3Txp0+uAxvujf IEChhGAnr2IPwR6yn3PhUnOVHJTvwk+8tebRvAKdEylVPVQOynbul3scIP/BnAKWaS +B77rH1B8AA+1NBT0wwmQS8rUtB5jdIydW6CQtpUwaSjNqii2ZFKMGxLmMn7Ec7upQ /J31EPazz9uSj5naA7kccLDbKzkSWlttmJqVDEWS4Ef3V5UP7lZAySgfrhkw29di6B z+1bTv6ZCVbUA== From: trondmy@kernel.org To: wanghai , linux-nfs@vger.kernel.org Subject: [PATCH 1/2] SUNRPC: Don't leak sockets in xs_local_connect() Date: Thu, 28 Apr 2022 11:30:00 -0400 Message-Id: <20220428153001.9545-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: Trond Myklebust If there is still a closed socket associated with the transport, then we need to trigger an autoclose before we can set up a new connection. Reported-by: wanghai (M) Fixes: f00432063db1 ("SUNRPC: Ensure we flush any closed sockets before xs_xprt_free()") Signed-off-by: Trond Myklebust --- net/sunrpc/xprtsock.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 8ab64ea46870..f9849b297ea3 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -1950,6 +1950,9 @@ static void xs_local_connect(struct rpc_xprt *xprt, struct rpc_task *task) struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); int ret; + if (transport->file) + goto force_disconnect; + if (RPC_IS_ASYNC(task)) { /* * We want the AF_LOCAL connect to be resolved in the @@ -1962,11 +1965,17 @@ static void xs_local_connect(struct rpc_xprt *xprt, struct rpc_task *task) */ task->tk_rpc_status = -ENOTCONN; rpc_exit(task, -ENOTCONN); - return; + goto out_wake; } ret = xs_local_setup_socket(transport); if (ret && !RPC_IS_SOFTCONN(task)) msleep_interruptible(15000); + return; +force_disconnect: + xprt_force_disconnect(xprt); +out_wake: + xprt_clear_connecting(xprt); + xprt_wake_pending_tasks(xprt, -ENOTCONN); } #if IS_ENABLED(CONFIG_SUNRPC_SWAP) From patchwork Thu Apr 28 15:30: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: 12830932 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 D3CC5C433F5 for ; Thu, 28 Apr 2022 15:36:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231130AbiD1Pj0 (ORCPT ); Thu, 28 Apr 2022 11:39:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233590AbiD1PjY (ORCPT ); Thu, 28 Apr 2022 11:39:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D306496BB for ; Thu, 28 Apr 2022 08:36:10 -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 A59A961FB1 for ; Thu, 28 Apr 2022 15:36:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6526C385A0; Thu, 28 Apr 2022 15:36:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651160169; bh=CWMNOjybVKoVyuQMJdUrwvTlJYDc2t0EVuicZ/5TiZU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CrkPT7v1A3rppUVdTlzsX4oaVVg34B02usOKIAXw5DXVS5UWyKSBnZ/0xJRExJLUF b56E8BS9r4PwkPFRzcxbhe3iZ0pYZXp5EVJPvYhQAvBt2L5vRiUg5PJQQ+T9MbX6ZC plHZMwzVloYll3grpk05guBO5COIHRqVtR8hciRv7svs42c2pORXHytBdcUQstyXBN dZwE0/Y7PmD/p3lShzLZfxd6g0S/jsfwwnyn/PkR21qWE0Ds9W/SY4F6i14CDINPcB YZAuM9dxcmbvcGk+qjPi9rnyPxoEu6TAPRq/9zgX/ZCIRZgcrJjBp0tUgJhTNHLWsz nXiJyIA4cedQw== From: trondmy@kernel.org To: wanghai , linux-nfs@vger.kernel.org Subject: [PATCH 2/2] SUNRPC: Ensure timely close of disconnected AF_LOCAL sockets Date: Thu, 28 Apr 2022 11:30:01 -0400 Message-Id: <20220428153001.9545-2-trondmy@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220428153001.9545-1-trondmy@kernel.org> References: <20220428153001.9545-1-trondmy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust When the rpcbind server closes the socket, we need to ensure that the socket is closed by the kernel as soon as feasible, so add a sk_state_change callback to trigger this close. Signed-off-by: Trond Myklebust --- net/sunrpc/xprtsock.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index f9849b297ea3..cf91f7c4bdf9 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -1418,6 +1418,25 @@ static size_t xs_tcp_bc_maxpayload(struct rpc_xprt *xprt) } #endif /* CONFIG_SUNRPC_BACKCHANNEL */ +/** + * xs_local_state_change - callback to handle AF_LOCAL socket state changes + * @sk: socket whose state has changed + * + */ +static void xs_local_state_change(struct sock *sk) +{ + struct rpc_xprt *xprt; + struct sock_xprt *transport; + + if (!(xprt = xprt_from_sock(sk))) + return; + if (sk->sk_shutdown & SHUTDOWN_MASK) { + clear_bit(XPRT_CONNECTED, &xprt->state); + /* Trigger the socket release */ + xs_run_error_worker(transport, XPRT_SOCK_WAKE_DISCONNECT); + } +} + /** * xs_tcp_state_change - callback to handle TCP socket state changes * @sk: socket whose state has changed @@ -1866,6 +1885,7 @@ static int xs_local_finish_connecting(struct rpc_xprt *xprt, sk->sk_user_data = xprt; sk->sk_data_ready = xs_data_ready; sk->sk_write_space = xs_udp_write_space; + sk->sk_state_change = xs_local_state_change; sk->sk_error_report = xs_error_report; xprt_clear_connected(xprt);