Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1448359pxp; Sun, 6 Mar 2022 15:51:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+dNp7JMk4AhzvVCPaVYpSQ3FYgyvFmCMr0X2E2FZTVnvYIVb9Eu/2kmLhrzO/HVD8MfJM X-Received: by 2002:a17:906:d1c4:b0:6d5:83bb:f58a with SMTP id bs4-20020a170906d1c400b006d583bbf58amr7221920ejb.672.1646610669528; Sun, 06 Mar 2022 15:51:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646610669; cv=none; d=google.com; s=arc-20160816; b=a8Ug1OUha3ImvactvDCdK4mGa3cgExGp9rSRoJ3/UbFMOub6saHCsaeZInMly0Wh9b 0ga7lC+ksCYYzq1KAWqqwnqGpDl7PeEAOKJFSYOtUK6ijCen+yJQnATa7PGO8MmUxQI6 gsQajCQmhNezhHHjZFlUP3AUfn/CbKOouKHTp3c1W/IUvzRt+WeOJ37B97XZXoXl4ekZ cdGI2e2gWRO9n5/PhclvPSuy7fmpw62vZ9lkKE/o10qbQdD4+6uVgeJrUYnb6bpbEtkP 0vJbtBvOZzUeluMiX1oJHoVnCGR2C+bwGF6ZfVYr6pfV3UHZJe1yRIl8X+E+kUXw9TQX BWfg== 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:cc:to:from :subject:dkim-signature:dkim-signature; bh=hRVIPm23nHnrI7WtoIgjrZUWa+2YaFb1uWafdgoA9iU=; b=FJmmNgup/Iaqb5helLU6i9ziytZwWyCIezbYH5AOHogTtPSG8GIM2xOsyS7BEt9ezn HRq2iJUadXJmTzuQlHf7LVRZFyUQ2wdk8GshkwifHNV6M7Ay4fJBkH+TEATO5IFCxwwj 310WYAEmyY07XxcuQ0kbuOLy2aws2KJVwxAbcyEjeQypgwotPKvE+PpYPB97ZbB6o3VR RKFej92iy/BVVmVrfnU5eX3F1SbuuOXL3AJlkva9CQRlKs/liwYY+0OSWqh1UMhXfnTr gmr+A36egt/rn1Y+f/p3sMPQAl+pLQIJouj8dLRmJ6h+eHeVJroESw2grmbSY61b09G4 RYnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=P1khN2D5; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bi1-20020a170906a24100b006cfd19f548bsi7259195ejb.69.2022.03.06.15.50.35; Sun, 06 Mar 2022 15:51:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-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=@suse.de header.s=susede2_rsa header.b=P1khN2D5; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234471AbiCFXo2 (ORCPT + 99 others); Sun, 6 Mar 2022 18:44:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234481AbiCFXo1 (ORCPT ); Sun, 6 Mar 2022 18:44:27 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED2404198F for ; Sun, 6 Mar 2022 15:43:29 -0800 (PST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7547121111; Sun, 6 Mar 2022 23:43:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1646610208; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hRVIPm23nHnrI7WtoIgjrZUWa+2YaFb1uWafdgoA9iU=; b=P1khN2D5Si+pdXiOTkY7AffOEEGHB4eCjmyc+4gPbxnhr2n6b236zSF+2fljRAZi/svIB2 113c6SzCXxgsJIPpIlj/D2/m4jdP3EglfUsJ7inBjkO2r2wBjineTR0yN90bVzLepJLefg a05OkmS9KoM5uzoaRXjcfM23PhJNCZU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1646610208; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hRVIPm23nHnrI7WtoIgjrZUWa+2YaFb1uWafdgoA9iU=; b=RyXhAuTtzDSOo5toNnzJomClbjAPpUYc/hsBYm4iI8zItfW9AZM1H5rVEj/0+Jwnjv4vKq UHRM+e8yE98MQtCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 55E69134CD; Sun, 6 Mar 2022 23:43:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sTKUBB9HJWJRWAAAMHmgww (envelope-from ); Sun, 06 Mar 2022 23:43:27 +0000 Subject: [PATCH 11/11] SUNRPC: change locking for xs_swap_enable/disable From: NeilBrown To: Trond Myklebust , Anna Schumaker Cc: linux-nfs@vger.kernel.org Date: Mon, 07 Mar 2022 10:41:45 +1100 Message-ID: <164661010499.31054.12748930938408125464.stgit@noble.brown> In-Reply-To: <164660993703.31054.17075972410545449555.stgit@noble.brown> References: <164660993703.31054.17075972410545449555.stgit@noble.brown> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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-nfs@vger.kernel.org It is not in general safe to wait for XPRT_LOCKED to clear. A wakeup is only sent when - connection completes - sock close completes so during normal operations, this can wait indefinitely. The event we need to protect against is ->inet being set to NULL, and that happens under the recv_mutex lock. So drop the handlign of XPRT_LOCKED and use recv_mutex instead. Signed-off-by: NeilBrown --- net/sunrpc/xprtsock.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 61d3293f1d68..7e39f87cde2d 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c @@ -1936,9 +1936,9 @@ static void xs_local_connect(struct rpc_xprt *xprt, struct rpc_task *task) #if IS_ENABLED(CONFIG_SUNRPC_SWAP) /* - * Note that this should be called with XPRT_LOCKED held (or when we otherwise - * know that we have exclusive access to the socket), to guard against - * races with xs_reset_transport. + * Note that this should be called with XPRT_LOCKED held, or recv_mutex + * held, or when we otherwise know that we have exclusive access to the + * socket, to guard against races with xs_reset_transport. */ static void xs_set_memalloc(struct rpc_xprt *xprt) { @@ -1967,13 +1967,11 @@ xs_enable_swap(struct rpc_xprt *xprt) { struct sock_xprt *xs = container_of(xprt, struct sock_xprt, xprt); - if (atomic_inc_return(&xprt->swapper) != 1) - return 0; - if (wait_on_bit_lock(&xprt->state, XPRT_LOCKED, TASK_KILLABLE)) - return -ERESTARTSYS; - if (xs->inet) + mutex_lock(&xs->recv_mutex); + if (atomic_inc_return(&xprt->swapper) == 1 && + xs->inet) sk_set_memalloc(xs->inet); - xprt_release_xprt(xprt, NULL); + mutex_unlock(&xs->recv_mutex); return 0; } @@ -1989,13 +1987,11 @@ xs_disable_swap(struct rpc_xprt *xprt) { struct sock_xprt *xs = container_of(xprt, struct sock_xprt, xprt); - if (!atomic_dec_and_test(&xprt->swapper)) - return; - if (wait_on_bit_lock(&xprt->state, XPRT_LOCKED, TASK_KILLABLE)) - return; - if (xs->inet) + mutex_lock(&xs->recv_mutex); + if (atomic_dec_and_test(&xprt->swapper) && + xs->inet) sk_clear_memalloc(xs->inet); - xprt_release_xprt(xprt, NULL); + mutex_unlock(&xs->recv_mutex); } #else static void xs_set_memalloc(struct rpc_xprt *xprt)