Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2849664pxb; Mon, 18 Apr 2022 09:30:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzI2yFz/F8toe+6Llp1Ch8HYbc6OkFpc0xVNjwGn/Ki/22WdsXTuPI1guOOgeNF8kZ6Qf8N X-Received: by 2002:a17:902:868b:b0:156:7afb:2ce2 with SMTP id g11-20020a170902868b00b001567afb2ce2mr11446126plo.27.1650299433847; Mon, 18 Apr 2022 09:30:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650299433; cv=none; d=google.com; s=arc-20160816; b=r9FC+mxQuq3gEtLnExffHSUTK7Wcv5HY0F4q3vbCcaBDWfwS1NwcD27pyPslbDg6bO WQ8DZ9/ar1Yuk4zb5qDG0RiFIlvvBX2Mj5IOhCNCOTYSCUhTmaToJQ+4VGcXemIM3gxy ibA4rBVIzQgZZ8oBlTeZII4htohq3gCV1j1jGKuxl9XhboqGZqk7UuPVpRqZ2Qd0lcGU GCuZrbqbHAsSxrnwFVX+92aSWdY39J0fTlHnvu5/qSvQsJoY2bnRKORosLOzOBsBLuBk aGzUM9gO4cBNZu1TnVNMTsXRhWizmXE08ODkLCi6uJ3f/pYPr0HFz17YehVggFWH4I6p cynA== 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=8jeJkyGMrhDNgDo38E8gFtm+VI4qhnfmVV8pMpQnZk4=; b=WCMKHWP2VJ9xhks0P6VE+Ta020yJnAQFFIDYczaAD2weKYsRW5qd7yXcgDYXj9ZfES x3gqOZaOFYxHinoArPOwngD4JExRWAJjse8aCz+sO41kr2KYg0swt+ba4EYdxvQ+TRFW cY8CKLUNxzhEJ+VlfX1JpHFLCghwFOAvqCdlk0UnEQiUR8iLWTbJmf/lW1NRULXrdl38 EWxR1QXQvj3SPKNHxwqSRjvGHUIF4TNUyWhiB9ZP8RcC4W50yhT7345HCPyzP4pklPiI YO7qksYksPJytZJWbFHY3iOzeB66KQBXWOdIj0uM1qaDdTcnfSaJNUsM1WGu6g4rREKj 2c1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kcNssifE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s1-20020a63b401000000b003993a5ee24bsi9379271pgf.693.2022.04.18.09.30.17; Mon, 18 Apr 2022 09:30:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=kcNssifE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244980AbiDROBA (ORCPT + 99 others); Mon, 18 Apr 2022 10:01:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242882AbiDRNjS (ORCPT ); Mon, 18 Apr 2022 09:39:18 -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 C0F192E9F7; Mon, 18 Apr 2022 05:59:06 -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 103E4B80E44; Mon, 18 Apr 2022 12:59:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 812ABC385A7; Mon, 18 Apr 2022 12:59:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286743; bh=rRlt5YjS0rY80hz1WJvBhQP5UFivNB/6ay1N+lfJJF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kcNssifEQ12x+BjG8o+TEHU/JL15qYxGHL6PZDb0C/iALPFzrz5PGZWAGRPWDtVlO 6L0ut57NVBXsO20peCAHYA6qNkRidcifZC/yWc7Mjk/v7lnIeerOblFCdUj4+GlqIr TnvsR95KnmJ0Ej/IXLDvMvvQEFE6NXFANezop88M= 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 4.14 231/284] NFS: swap-out must always use STABLE writes. Date: Mon, 18 Apr 2022 14:13:32 +0200 Message-Id: <20220418121218.283445909@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@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=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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-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 ef30215d5b3a..8acff8f6678e 100644 --- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c @@ -888,7 +888,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; @@ -896,7 +896,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); @@ -1042,11 +1042,13 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter, dreq->iocb = iocb; 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