Received: by 2002:a05:6512:3d0e:0:0:0:0 with SMTP id d14csp39535lfv; Tue, 12 Apr 2022 16:22:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4e9fAalgnApNqxuy0nyp3Ptx9DaW47A6CcPStAPVRx23iK1y9uTS0D8GwP4unk8ma+Lgg X-Received: by 2002:a17:902:8490:b0:156:7eb1:33c7 with SMTP id c16-20020a170902849000b001567eb133c7mr39560846plo.39.1649805769546; Tue, 12 Apr 2022 16:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649805769; cv=none; d=google.com; s=arc-20160816; b=bA6Z31pnKY9jFio824DRp1uXafsYONeocJDyo9NfEvrsO0pkRjzNXuVa0s4u9vCpKz tlJtocyf84JHmA/RgfP0hTLFS6hNzqiUT6bYcyIQASHTy2nGb1W8EHnTvuQKRFicv+AE JCsfqpDety3c7lTZIBGHNq50hYEOmCLO55GYXmfHDeNJO6oOhRLNURGafdER6FuTy/Ze wrWJraZ19f5Kx70ztKVuF0bRw/0rtkPG4E+hglBP2rYw+E6z+PS6DKE8OhctmZEUE5rj fzflw5IV8sFdK3Z7OyHXiqV5dlbaVJIIZ62nn4sTvpN7rcv0NGTwvamBIoU3BfVt9oxs Ii/w== 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:subject:cc:to :from:dkim-signature; bh=r+Las+u2e0VabDavXP5RG0c54DQiLEg1bf0Te+TqSF4=; b=ij+Qvc3h/UbxKSi6ERf7wAX999lktZM1bn4uJg9HMekv+Z+2uxPkepyaL65O2W/Y85 qCTTjAHtGyxkvxoGms4CGoT6wnc4qeiwFobcMzaeu0sIJA2MbKsdjN4vXVaE72Yg30Wx +2/vlB0wXurvVE1qmv4KLNBf48ybu50ykd9O0nAfemr7g+wkPTsuU0yqnAb3OftvAihj +Zhw8vgMkN29DEgdbvDlf5+E64/orFEXdloThz6pPn0xGe7toclZ+CeV9r8IaGTeCXVj NWn/zDRgYItAnlY/3WmAsCPmYoMcMz7WbKhdCb4NDub0Ea7wibyELulphA3IUYeS6d+2 3YEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kcLhs1zk; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id j2-20020a63ec02000000b0039864440c1esi3842107pgh.786.2022.04.12.16.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 16:22:49 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kcLhs1zk; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DF9FD19EC74; Tue, 12 Apr 2022 14:15:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350809AbiDLGuk (ORCPT + 99 others); Tue, 12 Apr 2022 02:50:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350767AbiDLGnV (ORCPT ); Tue, 12 Apr 2022 02:43:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAA4737BF5; Mon, 11 Apr 2022 23:36:45 -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 B92D161904; Tue, 12 Apr 2022 06:36:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBBBFC385A6; Tue, 12 Apr 2022 06:36:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649745404; bh=WsGVm2ifufobQw4sI2QEzE15gWhPGQlXBw2iENliwjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kcLhs1zks/XwgPvrOUBiXNMZpF2cUalK976K2HgF8a/wcrJyNqsh8xBj4dRaw4gJ/ cPZEM+3Rki1Fy9knMrVMMRehbJ2HFIda/MwgYKtfT1izsZ9V04WeGVNw/dvDJh9h6y NaPXRyZOcY72fYsT4zf+mYTU5DPWujZIdLp54RnQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, NeilBrown , Trond Myklebust , Sasha Levin Subject: [PATCH 5.10 086/171] NFS: swap-out must always use STABLE writes. Date: Tue, 12 Apr 2022 08:29:37 +0200 Message-Id: <20220412062930.376791831@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220412062927.870347203@linuxfoundation.org> References: <20220412062927.870347203@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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-kernel@vger.kernel.org From: NeilBrown [ Upstream commit c265de257f558a05c1859ee9e3fed04883b9ec0e ] The commit handling code is not safe against memory-pressure deadlocks when writing to swap. In particular, nfs_commitdata_alloc() blocks indefinitely waiting for memory, and this can consume all available workqueue threads. swap-out most likely uses STABLE writes anyway as COND_STABLE indicates that a stable write should be used if the write fits in a single request, and it normally does. However if we ever swap with a small wsize, or gather unusually large numbers of pages for a single write, this might change. For safety, make it explicit in the code that direct writes used for swap must always use FLUSH_STABLE. Signed-off-by: NeilBrown Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- fs/nfs/direct.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c index 28afc315ec0c..c220810c61d1 100644 --- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c @@ -793,7 +793,7 @@ static const struct nfs_pgio_completion_ops nfs_direct_write_completion_ops = { */ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, struct iov_iter *iter, - loff_t pos) + loff_t pos, int ioflags) { struct nfs_pageio_descriptor desc; struct inode *inode = dreq->inode; @@ -801,7 +801,7 @@ static ssize_t nfs_direct_write_schedule_iovec(struct nfs_direct_req *dreq, size_t requested_bytes = 0; size_t wsize = max_t(size_t, NFS_SERVER(inode)->wsize, PAGE_SIZE); - nfs_pageio_init_write(&desc, inode, FLUSH_COND_STABLE, false, + nfs_pageio_init_write(&desc, inode, ioflags, false, &nfs_direct_write_completion_ops); desc.pg_dreq = dreq; get_dreq(dreq); @@ -947,11 +947,13 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter, pnfs_init_ds_commit_info_ops(&dreq->ds_cinfo, inode); if (swap) { - requested = nfs_direct_write_schedule_iovec(dreq, iter, pos); + requested = nfs_direct_write_schedule_iovec(dreq, iter, pos, + FLUSH_STABLE); } else { nfs_start_io_direct(inode); - requested = nfs_direct_write_schedule_iovec(dreq, iter, pos); + requested = nfs_direct_write_schedule_iovec(dreq, iter, pos, + FLUSH_COND_STABLE); if (mapping->nrpages) { invalidate_inode_pages2_range(mapping, -- 2.35.1