From patchwork Sat May 14 05:34:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meena Shanmugam X-Patchwork-Id: 572797 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 50B17C433F5 for ; Sat, 14 May 2022 05:35:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229976AbiENFfJ (ORCPT ); Sat, 14 May 2022 01:35:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231565AbiENFfI (ORCPT ); Sat, 14 May 2022 01:35:08 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E61B225D1 for ; Fri, 13 May 2022 22:35:07 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id g12-20020a170902740c00b0015d243ff163so5340249pll.19 for ; Fri, 13 May 2022 22:35:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=TvbCzBBvo15VRUBc/6ak0d8mhY7uSzRxncOCYNG60n0=; b=ZpWwbDbP+X/DGCnmKcpKBBG8A2iqIMkb+/b77fjL9BDepkrB0solslY09hbxB0GCcS l0L/WqwjZwadXUkpgOSq4mS+msQt49jzK5I+BZWpHvCxpqW+cd5nY3ogCaSedG9XdB7P 9jbjTzXGh89CpFKJq2m9RH9Hnfa97ucAtz1O6TZJrUHZ+KpNQeLIu8bm8uCrbx/d7wJL j8/omK0M2mx4fBi9nmMwHUcev+5HFoYt4BepuErKq3QJU1MEeFQzDZL7MY2fxOwjOWvp NvIxzi3BzxXWbYR/ILR2IzOdwOaUZg5VUWpw/ZEoRBIMHpnBtduEbEA+7eQxA7axayyz toVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=TvbCzBBvo15VRUBc/6ak0d8mhY7uSzRxncOCYNG60n0=; b=K7pNkicuNjDfk+SC+xzXdQ37FsAekNWk6wGsUrKEXg5SDyL4G2AwlcQNUF765xCrs0 NvvVlNVpi21jTbHbyCrZlOcsWrNM6N6niYqQtTOObwAa93GMVVm+mHORTr2/6fcjvr+v Qv+5rhBpC0SdNjSDAPEYSIm0XuInJ0/a4m6OAEmGRckKS8LGdmJ7pJaXBq164O2tFPKU Pz7JIjF3d2WO14RyrdraWqAQmQrtJeMufKVsZNfHCLaXGL5n+zR4GD1p1iBlSIU8SUWF yTuI7ZaajguHal4CJ/yn0RJpqwNjAewAIlJbtcwxgzxAxvUZnU36anLFfo7KUBuxCGw2 EGXw== X-Gm-Message-State: AOAM5329zh/8e4DRHZh4f4TD+Mz02RhEXOamWCuPVxt2oCoqD2jUBHbF oc4BA7dklGSSmJhLE5lypK7NjsVzBR6Jyafj+GWsOA== X-Google-Smtp-Source: ABdhPJxV98s95KfUzPC/9JuwlR6rmZrr+YcMUKdvkxX0r0g/PpFeNz0xoasNWYCBcK/LDrrbjrfPYG03evZPpw6yZsx+OQ== X-Received: from meenashanmugamspl.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2707]) (user=meenashanmugam job=sendgmr) by 2002:a05:6a00:ad0:b0:4e1:2d96:2ab0 with SMTP id c16-20020a056a000ad000b004e12d962ab0mr7741746pfl.3.1652506507386; Fri, 13 May 2022 22:35:07 -0700 (PDT) Date: Sat, 14 May 2022 05:34:50 +0000 In-Reply-To: <20220514053453.3277330-1-meenashanmugam@google.com> Message-Id: <20220514053453.3277330-2-meenashanmugam@google.com> Mime-Version: 1.0 References: <20220514053453.3277330-1-meenashanmugam@google.com> X-Mailer: git-send-email 2.36.0.550.gb090851708-goog Subject: [PATCH 1/4] SUNRPC: Clean up scheduling of autoclose From: Meena Shanmugam To: gregkh@linuxfoundation.org Cc: enrico.scholz@sigma-chemnitz.de, meenashanmugam@google.com, stable@vger.kernel.org, trond.myklebust@hammerspace.com, Anna Schumaker Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Trond Myklebust commit e26d9972720e2484f44cdd94ca4e31cc372ed2ed upstream. Consolidate duplicated code in xprt_force_disconnect() and xprt_conditional_disconnect(). Signed-off-by: Trond Myklebust Signed-off-by: Anna Schumaker Signed-off-by: Meena Shanmugam --- net/sunrpc/xprt.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c index 6bc225d64d23..a6bb957084f7 100644 --- a/net/sunrpc/xprt.c +++ b/net/sunrpc/xprt.c @@ -731,6 +731,20 @@ void xprt_disconnect_done(struct rpc_xprt *xprt) } EXPORT_SYMBOL_GPL(xprt_disconnect_done); +/** + * xprt_schedule_autoclose_locked - Try to schedule an autoclose RPC call + * @xprt: transport to disconnect + */ +static void xprt_schedule_autoclose_locked(struct rpc_xprt *xprt) +{ + set_bit(XPRT_CLOSE_WAIT, &xprt->state); + if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0) + queue_work(xprtiod_workqueue, &xprt->task_cleanup); + else if (xprt->snd_task && !test_bit(XPRT_SND_IS_COOKIE, &xprt->state)) + rpc_wake_up_queued_task_set_status(&xprt->pending, + xprt->snd_task, -ENOTCONN); +} + /** * xprt_force_disconnect - force a transport to disconnect * @xprt: transport to disconnect @@ -742,13 +756,7 @@ void xprt_force_disconnect(struct rpc_xprt *xprt) /* Don't race with the test_bit() in xprt_clear_locked() */ spin_lock(&xprt->transport_lock); - set_bit(XPRT_CLOSE_WAIT, &xprt->state); - /* Try to schedule an autoclose RPC call */ - if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0) - queue_work(xprtiod_workqueue, &xprt->task_cleanup); - else if (xprt->snd_task && !test_bit(XPRT_SND_IS_COOKIE, &xprt->state)) - rpc_wake_up_queued_task_set_status(&xprt->pending, - xprt->snd_task, -ENOTCONN); + xprt_schedule_autoclose_locked(xprt); spin_unlock(&xprt->transport_lock); } EXPORT_SYMBOL_GPL(xprt_force_disconnect); @@ -788,11 +796,7 @@ void xprt_conditional_disconnect(struct rpc_xprt *xprt, unsigned int cookie) goto out; if (test_bit(XPRT_CLOSING, &xprt->state)) goto out; - set_bit(XPRT_CLOSE_WAIT, &xprt->state); - /* Try to schedule an autoclose RPC call */ - if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0) - queue_work(xprtiod_workqueue, &xprt->task_cleanup); - xprt_wake_pending_tasks(xprt, -EAGAIN); + xprt_schedule_autoclose_locked(xprt); out: spin_unlock(&xprt->transport_lock); } From patchwork Sat May 14 05:34:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meena Shanmugam X-Patchwork-Id: 572904 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 79AC9C433FE for ; Sat, 14 May 2022 05:35:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231829AbiENFfN (ORCPT ); Sat, 14 May 2022 01:35:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231565AbiENFfM (ORCPT ); Sat, 14 May 2022 01:35:12 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D98B510C0 for ; Fri, 13 May 2022 22:35:10 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id x190-20020a6386c7000000b003d82199c4fdso5154779pgd.16 for ; Fri, 13 May 2022 22:35:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=pQ3/2wWEXIEp31+Th9Fv52M8A6U+DB7IXsH9VispyAE=; b=h2zwPrO7yfmI1kLWQ5G5Rag/gvBZcgWFfRt1yjeRbZb+u5Y73AWdHkSIEp8e7EnMcL djfq63gEE6tWA2qKh7VYuYLgZFy+Dy4MIkxBl3g4IYgJDUK9slcuaceUeSpf6Eb1hwGz Rdvo9JtcXbEjltanGIfIWdnjgiwYrlIsosoHgDKBM1GL2iHiUwuyYNEydNmcRdzsYAFb 7qa9XcVhFqjr34W0H9wU2BAik2/Rf9tfIOpVXY6nnzdfR/cxb1eJDXERpo3S8pt2nKfJ CwJAvzNsCBfP9kJHc3rQj6I/ACdbxZewiJu2gwOERg2g72p5hXdLrrgmdsI76fWP7oqk vTJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=pQ3/2wWEXIEp31+Th9Fv52M8A6U+DB7IXsH9VispyAE=; b=JZiG4e5rYCmPB8ZtDBWTadWqOimj0uGoiTUkNqcTatsI9tjpCv3SZNHZtJdcDPJlSA 4reROiUrGnqwppbtEig+kFJsyt+0aB+SIpqJw4qWpQNe9SAIa5rCG2iabN5Xr/zkH3Zg KQSKZp/A66TrYcbwTCOHFFwncjZfFThAq6oRlumzlvW6EyrXkw4snc1yxt2LQ7Rj+SVt mhUg//AIdLn9Ol8c1yjxjO15f/fLdg34WU0fKVlGQBqgjAOTTv5wSLbAMJSaWvwwvctF LFapa7vcumBElaTCgw6R5fhVwHDRd/rOo1bra7Hjrl0wjuIpm05hP+TI3n1upwR/vG9j QfBA== X-Gm-Message-State: AOAM533EbEN8Q/uiRk2SawmzI9wP3ZMscUhEQZ5Y3u4MSoQFwzz2u3mN EpFyr0EJbhZyk1KuxjDf2h/IXITEzcEsxXfuati47Q== X-Google-Smtp-Source: ABdhPJyVXMDFbSACO7sLYmDqCGSLYkzNYvDmhZfuP332EuIl8LYPHLxwM5EGIXrEXhQu7SriApCZsCLGkEY5+e5t7XrT5g== X-Received: from meenashanmugamspl.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2707]) (user=meenashanmugam job=sendgmr) by 2002:a17:90a:e7d2:b0:1dc:e6c6:604b with SMTP id kb18-20020a17090ae7d200b001dce6c6604bmr19616414pjb.183.1652506510368; Fri, 13 May 2022 22:35:10 -0700 (PDT) Date: Sat, 14 May 2022 05:34:51 +0000 In-Reply-To: <20220514053453.3277330-1-meenashanmugam@google.com> Message-Id: <20220514053453.3277330-3-meenashanmugam@google.com> Mime-Version: 1.0 References: <20220514053453.3277330-1-meenashanmugam@google.com> X-Mailer: git-send-email 2.36.0.550.gb090851708-goog Subject: [PATCH 2/4] SUNRPC: Prevent immediate close+reconnect From: Meena Shanmugam To: gregkh@linuxfoundation.org Cc: enrico.scholz@sigma-chemnitz.de, meenashanmugam@google.com, stable@vger.kernel.org, trond.myklebust@hammerspace.com Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Trond Myklebust commit 3be232f11a3cc9b0ef0795e39fa11bdb8e422a06 upstream. If we have already set up the socket and are waiting for it to connect, then don't immediately close and retry. Signed-off-by: Trond Myklebust Signed-off-by: Meena Shanmugam --- net/sunrpc/xprt.c | 3 ++- net/sunrpc/xprtsock.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c index a6bb957084f7..af0159459c75 100644 --- a/net/sunrpc/xprt.c +++ b/net/sunrpc/xprt.c @@ -737,7 +737,8 @@ EXPORT_SYMBOL_GPL(xprt_disconnect_done); */ static void xprt_schedule_autoclose_locked(struct rpc_xprt *xprt) { - set_bit(XPRT_CLOSE_WAIT, &xprt->state); + if (test_and_set_bit(XPRT_CLOSE_WAIT, &xprt->state)) + return; if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0) queue_work(xprtiod_workqueue, &xprt->task_cleanup); else if (xprt->snd_task && !test_bit(XPRT_SND_IS_COOKIE, &xprt->state)) diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index bd123f1d0923..60c58eb9a456 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -2345,7 +2345,7 @@ static void xs_connect(struct rpc_xprt *xprt, struct rpc_task *task) WARN_ON_ONCE(!xprt_lock_connect(xprt, task, transport)); - if (transport->sock != NULL) { + if (transport->sock != NULL && !xprt_connecting(xprt)) { dprintk("RPC: xs_connect delayed xprt %p for %lu " "seconds\n", xprt, xprt->reestablish_timeout / HZ); From patchwork Sat May 14 05:34:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meena Shanmugam X-Patchwork-Id: 572796 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 EF084C433EF for ; Sat, 14 May 2022 05:35:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231565AbiENFfS (ORCPT ); Sat, 14 May 2022 01:35:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231846AbiENFfP (ORCPT ); Sat, 14 May 2022 01:35:15 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1135E10C0 for ; Fri, 13 May 2022 22:35:14 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2d11b6259adso88844977b3.19 for ; Fri, 13 May 2022 22:35:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=sY49jKBF5FM4c+1hN6yD4uq5YLeIbMZrfN/k7lkxmlg=; b=hrYqYzFLV0JPwU996yxacxXAYwwMFxaPYG4ZYVnf5fjnQqaMCJW5MXQUS1S6mbtp3B DUKDSfPfK++ypMT615KGJ/Fz7p9vxAqLZhGJXijN0Pl8cRAWov7ySC1+jxX7jQgnWNKo yH8cnft0ArQmy3H3vl5KXa8NgnTEXHVmcb3jlPivIAeFkbNTo7NwhV7SyQSRyrJTL5Dn BZvfHt6LUiwZQLWSJXAWdGmNhlfLfX7X8vONu6SofMoB2FrITGrPZX7AvnLWpqIUjgP4 MvhIuN+5Gg3p0HLFPmoh7rnxMFWULOfu0KKV8zCFO3mcJWzsFle97cIfl54eLq6jlXyW HueA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=sY49jKBF5FM4c+1hN6yD4uq5YLeIbMZrfN/k7lkxmlg=; b=0TMz3myBEIEu5l89CAFGATjoIhITbZ8KF/9gV7G1WDKicGGV0CmH13orWke7oF2/o5 MKgiGpEKXoBz3oKG2Qazgvs/15nyiAqkcHUYgeblIKYWoZM2nv1W+qTwnHTZNjpIT9Bq hRlhG4/CVlwdFnt8eGhT7Mm6uufR0jwRRIib/k/17k84KWWOZK8srT52MkfwEbHae+EP ljBhkrpSk7gU/XLvoI0e2dPBMIlTcHrOrZjORYJMU9pIWtOMdP25OSYtedSO+qVwMuKy X7Cai2XMUAFURe37a657JNUdlh/Tr/rsaCB8FHJti0xsKxHNgRdmgUpB3hGrO663v5Mv c4Zw== X-Gm-Message-State: AOAM530Cvh/q/D+Bxc8h2E1hdI1yXgeO9i5B65EBD/dcfiYMpyzW6M1O Xbl1s6/VLxevZqzV4sGn2RI89eYTZry130dafxl14A== X-Google-Smtp-Source: ABdhPJw95Jgp6QuXznuZbY36iVG2TkrvwtYyVD0eJvNGwyjX/Rd9rHUHyfFx5fvG2GDcbgLjMI3ZTsC2v8PGAUuFGQl7gw== X-Received: from meenashanmugamspl.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2707]) (user=meenashanmugam job=sendgmr) by 2002:a81:d16:0:b0:2f4:dd5d:9846 with SMTP id 22-20020a810d16000000b002f4dd5d9846mr9037146ywn.372.1652506513293; Fri, 13 May 2022 22:35:13 -0700 (PDT) Date: Sat, 14 May 2022 05:34:52 +0000 In-Reply-To: <20220514053453.3277330-1-meenashanmugam@google.com> Message-Id: <20220514053453.3277330-4-meenashanmugam@google.com> Mime-Version: 1.0 References: <20220514053453.3277330-1-meenashanmugam@google.com> X-Mailer: git-send-email 2.36.0.550.gb090851708-goog Subject: [PATCH 3/4] SUNRPC: Don't call connect() more than once on a TCP socket From: Meena Shanmugam To: gregkh@linuxfoundation.org Cc: enrico.scholz@sigma-chemnitz.de, meenashanmugam@google.com, stable@vger.kernel.org, trond.myklebust@hammerspace.com Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Trond Myklebust commit 89f42494f92f448747bd8a7ab1ae8b5d5520577d upstream. Avoid socket state races due to repeated calls to ->connect() using the same socket. If connect() returns 0 due to the connection having completed, but we are in fact in a closing state, then we may leave the XPRT_CONNECTING flag set on the transport. Reported-by: Enrico Scholz Fixes: 3be232f11a3c ("SUNRPC: Prevent immediate close+reconnect") Signed-off-by: Trond Myklebust [meenashanmugam: Backported to 5.10: Fixed merge conflict in xs_tcp_setup_socket] Signed-off-by: Meena Shanmugam --- include/linux/sunrpc/xprtsock.h | 1 + net/sunrpc/xprtsock.c | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/linux/sunrpc/xprtsock.h b/include/linux/sunrpc/xprtsock.h index 8c2a712cb242..689062afdd61 100644 --- a/include/linux/sunrpc/xprtsock.h +++ b/include/linux/sunrpc/xprtsock.h @@ -89,5 +89,6 @@ struct sock_xprt { #define XPRT_SOCK_WAKE_WRITE (5) #define XPRT_SOCK_WAKE_PENDING (6) #define XPRT_SOCK_WAKE_DISCONNECT (7) +#define XPRT_SOCK_CONNECT_SENT (8) #endif /* _LINUX_SUNRPC_XPRTSOCK_H */ diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 60c58eb9a456..33a81f9703b1 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -2260,10 +2260,14 @@ static void xs_tcp_setup_socket(struct work_struct *work) struct rpc_xprt *xprt = &transport->xprt; int status = -EIO; - if (!sock) { - sock = xs_create_sock(xprt, transport, - xs_addr(xprt)->sa_family, SOCK_STREAM, - IPPROTO_TCP, true); + if (xprt_connected(xprt)) + goto out; + if (test_and_clear_bit(XPRT_SOCK_CONNECT_SENT, + &transport->sock_state) || + !sock) { + xs_reset_transport(transport); + sock = xs_create_sock(xprt, transport, xs_addr(xprt)->sa_family, + SOCK_STREAM, IPPROTO_TCP, true); if (IS_ERR(sock)) { status = PTR_ERR(sock); goto out; @@ -2294,6 +2298,7 @@ static void xs_tcp_setup_socket(struct work_struct *work) break; case 0: case -EINPROGRESS: + set_bit(XPRT_SOCK_CONNECT_SENT, &transport->sock_state); case -EALREADY: xprt_unlock_connect(xprt, transport); return; @@ -2345,13 +2350,9 @@ static void xs_connect(struct rpc_xprt *xprt, struct rpc_task *task) WARN_ON_ONCE(!xprt_lock_connect(xprt, task, transport)); - if (transport->sock != NULL && !xprt_connecting(xprt)) { + if (transport->sock != NULL) { dprintk("RPC: xs_connect delayed xprt %p for %lu " - "seconds\n", - xprt, xprt->reestablish_timeout / HZ); - - /* Start by resetting any existing state */ - xs_reset_transport(transport); + "seconds\n", xprt, xprt->reestablish_timeout / HZ); delay = xprt_reconnect_delay(xprt); xprt_reconnect_backoff(xprt, XS_TCP_INIT_REEST_TO); From patchwork Sat May 14 05:34:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meena Shanmugam X-Patchwork-Id: 572903 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 A1579C433F5 for ; Sat, 14 May 2022 05:35:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231846AbiENFfZ (ORCPT ); Sat, 14 May 2022 01:35:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231875AbiENFfS (ORCPT ); Sat, 14 May 2022 01:35:18 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEB5E22F for ; Fri, 13 May 2022 22:35:16 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id d4-20020a17090ac24400b001dcec51802cso7197560pjx.4 for ; Fri, 13 May 2022 22:35:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=VZAZAPHvT0TKLZ9jTfeA+9ROnhqNYTAn9rPhraV02Tc=; b=guaJG6PAb7tVgS9A6ACn480wa197Nv5Ec72AmOeYWkh7IN6IPAOOj/KhkAI3GHI6YU Ev64zmLOD+triu5APRxQoH8DAXj0SrZLa/VLoSMMgpNSRJxNfkY0Gu8KHrJyre9sYYz5 fm4hDyGl6e4Wi3vjd+WSzFkbly0lIWL/4VHfHtcIu05jVuAFGnrQn+p1UtwMuacRWRlT a0QDi0nGxtviRoGlnTn+rLpZGO+Caw4Pw2U9ozvtXJBP0WQQWxHOXcTMLm4tQYui92sp PHZQcMHyvgjONC41MDWz30op4AYJXmhMA7KtY6kC0/NErfJsg+JyXsGr8YUj06REp9WX Ux4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=VZAZAPHvT0TKLZ9jTfeA+9ROnhqNYTAn9rPhraV02Tc=; b=Dn/ELrf6eKE6apD6lbUyCXsS09Z+F+F+VPd1MaaoY+vU+COS39Q7N4fHvad8VpSnSM owa0f+podhNGsuom017gtTwFO7zNlJZ98D8XoCCt1F616+rFlw2FtUk3cnTiED6tZffF O0eTayfGAn9T7yPCrBjeHkvQRJGx80w7z9sSPqtWUcsPLLY77dQPdeAXiVZFwEj7UXU1 2brcE1HT7ys0O+QjjmEnYxjyk071nDvDHvoeUS8x+ZslnMx+dRNJnnqbeF+90awAfdnL 2d3nNNpMe8/5vPrWPCmUd1H/QnUNPwBlIIfNtCHLC/K4itI0ZMj0RdLtkoireGFRWNGu o9/A== X-Gm-Message-State: AOAM530soj1GvZBDBjrwcX+xZxBr+pMkFgRddjfA5Ysg/pihNOduMMIq GvExOApteMSPT9HyXHdCvB6osVHQ9B7aeSRm7tfdNA== X-Google-Smtp-Source: ABdhPJwBwFFj3BqXVwtsliLQS73P2lABbO7cLJWYyWCWemobldNbGv0dDxtvZ/rDd9yrpGci2Suq44pd52gLJBenxwUcSA== X-Received: from meenashanmugamspl.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2707]) (user=meenashanmugam job=sendgmr) by 2002:a17:903:230b:b0:15e:bc9c:18c7 with SMTP id d11-20020a170903230b00b0015ebc9c18c7mr7655695plh.29.1652506516304; Fri, 13 May 2022 22:35:16 -0700 (PDT) Date: Sat, 14 May 2022 05:34:53 +0000 In-Reply-To: <20220514053453.3277330-1-meenashanmugam@google.com> Message-Id: <20220514053453.3277330-5-meenashanmugam@google.com> Mime-Version: 1.0 References: <20220514053453.3277330-1-meenashanmugam@google.com> X-Mailer: git-send-email 2.36.0.550.gb090851708-goog Subject: [PATCH 4/4] SUNRPC: Ensure we flush any closed sockets before xs_xprt_free() From: Meena Shanmugam To: gregkh@linuxfoundation.org Cc: enrico.scholz@sigma-chemnitz.de, meenashanmugam@google.com, stable@vger.kernel.org, trond.myklebust@hammerspace.com, Felix Fu , Al Viro Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Trond Myklebust commit f00432063db1a0db484e85193eccc6845435b80e upstream. We must ensure that all sockets are closed before we call xprt_free() and release the reference to the net namespace. The problem is that calling fput() will defer closing the socket until delayed_fput() gets called. Let's fix the situation by allowing rpciod and the transport teardown code (which runs on the system wq) to call __fput_sync(), and directly close the socket. Reported-by: Felix Fu Acked-by: Al Viro Fixes: a73881c96d73 ("SUNRPC: Fix an Oops in udp_poll()") Cc: stable@vger.kernel.org # 5.1.x: 3be232f11a3c: SUNRPC: Prevent immediate close+reconnect Cc: stable@vger.kernel.org # 5.1.x: 89f42494f92f: SUNRPC: Don't call connect() more than once on a TCP socket Cc: stable@vger.kernel.org # 5.1.x Signed-off-by: Trond Myklebust Signed-off-by: Meena Shanmugam --- fs/file_table.c | 1 + include/trace/events/sunrpc.h | 1 - net/sunrpc/xprt.c | 7 +------ net/sunrpc/xprtsock.c | 16 +++++++++++++--- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/fs/file_table.c b/fs/file_table.c index fbd45a1a0e7e..12aaa04ac5b7 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -377,6 +377,7 @@ void __fput_sync(struct file *file) } EXPORT_SYMBOL(fput); +EXPORT_SYMBOL(__fput_sync); void __init files_init(void) { diff --git a/include/trace/events/sunrpc.h b/include/trace/events/sunrpc.h index ed1bbac004d5..8220369ee610 100644 --- a/include/trace/events/sunrpc.h +++ b/include/trace/events/sunrpc.h @@ -1006,7 +1006,6 @@ DEFINE_RPC_XPRT_LIFETIME_EVENT(connect); DEFINE_RPC_XPRT_LIFETIME_EVENT(disconnect_auto); DEFINE_RPC_XPRT_LIFETIME_EVENT(disconnect_done); DEFINE_RPC_XPRT_LIFETIME_EVENT(disconnect_force); -DEFINE_RPC_XPRT_LIFETIME_EVENT(disconnect_cleanup); DEFINE_RPC_XPRT_LIFETIME_EVENT(destroy); DECLARE_EVENT_CLASS(rpc_xprt_event, diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c index af0159459c75..13d5323f8098 100644 --- a/net/sunrpc/xprt.c +++ b/net/sunrpc/xprt.c @@ -886,12 +886,7 @@ void xprt_connect(struct rpc_task *task) if (!xprt_lock_write(xprt, task)) return; - if (test_and_clear_bit(XPRT_CLOSE_WAIT, &xprt->state)) { - trace_xprt_disconnect_cleanup(xprt); - xprt->ops->close(xprt); - } - - if (!xprt_connected(xprt)) { + if (!xprt_connected(xprt) && !test_bit(XPRT_CLOSE_WAIT, &xprt->state)) { task->tk_rqstp->rq_connect_cookie = xprt->connect_cookie; rpc_sleep_on_timeout(&xprt->pending, task, NULL, xprt_request_timeout(task->tk_rqstp)); diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 33a81f9703b1..71c0ec9eaf0b 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -871,7 +871,7 @@ static int xs_local_send_request(struct rpc_rqst *req) /* Close the stream if the previous transmission was incomplete */ if (xs_send_request_was_aborted(transport, req)) { - xs_close(xprt); + xprt_force_disconnect(xprt); return -ENOTCONN; } @@ -909,7 +909,7 @@ static int xs_local_send_request(struct rpc_rqst *req) -status); fallthrough; case -EPIPE: - xs_close(xprt); + xprt_force_disconnect(xprt); status = -ENOTCONN; } @@ -1191,6 +1191,16 @@ static void xs_reset_transport(struct sock_xprt *transport) if (sk == NULL) return; + /* + * Make sure we're calling this in a context from which it is safe + * to call __fput_sync(). In practice that means rpciod and the + * system workqueue. + */ + if (!(current->flags & PF_WQ_WORKER)) { + WARN_ON_ONCE(1); + set_bit(XPRT_CLOSE_WAIT, &xprt->state); + return; + } if (atomic_read(&transport->xprt.swapper)) sk_clear_memalloc(sk); @@ -1214,7 +1224,7 @@ static void xs_reset_transport(struct sock_xprt *transport) mutex_unlock(&transport->recv_mutex); trace_rpc_socket_close(xprt, sock); - fput(filp); + __fput_sync(filp); xprt_disconnect_done(xprt); }