Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1644022pxp; Sun, 6 Mar 2022 22:03:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJxn4jWOyu1kZkMl0YRN87n+mdAF9UV4R/e+1j/47Qdt96lfFG5+9/PNSwiy0zmTJmCAf6BK X-Received: by 2002:a17:902:9a02:b0:14f:2d93:92f4 with SMTP id v2-20020a1709029a0200b0014f2d9392f4mr11188504plp.160.1646633007007; Sun, 06 Mar 2022 22:03:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646633007; cv=none; d=google.com; s=arc-20160816; b=RxSToibw4qJ/cEi7w/nn/6ulE1SorUIs6G8qDyhCkjAIj8pmySqU5WX/Rl4KXps99S kYeNyXDwVdMQ6E6yEZAH0Dw6GblyKgXoOyJQakcsovoqBjQ/IVXNbkRS49LVA2hStcTw 5ss+de1tPqdd+2EiiF35uJZ5dJzw3qsWYIoXw+F9jCZzyGmhUmJ4hquoDz82tz+OoHDw 9pK6CFRCzchSPJSx2lZwLjOwSD3scaWUM8UMBzJslYeR2EG5EEtGqPYCuyu+4bxRf866 989FO1AXUAM4DB+XGJ4/sIsbPnZRnhtoVC8BmDLOg48X9RQSXU3g2MojSukB9Upz/s4r AvsA== 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=P8Ex1C2tLGBY3G4iAkuioFe1tiAu7Sw2IQj0bqqMkqA=; b=Nsfw4RHx6ZAz98IiQeMLionHh46VSKi6Fw+CyKi2WjDCxRNw0oLSSV+PjtPc8utI3C vvjycszdW66FpR8Pwh0rVT96568DCtivd0yWoCCko6z2ARWYAH/d6+X3mmYi2hr5i5q0 txDCO3R+VZ4Q9VvRGAjzQdju0XOHKe6FIUnmB0do6r+qer1qqxLnVms+8GtTMvI25dLr 1vFZTDK2eftVsXBt1pl8oDiXPvicKm0qM9FdTBnORlifh0qkmK0OUFmwVUoEYf8D4PJq zM7rLhtIWsHsBfsnnIgyLsrSNPuQwfnVEsQm9Ap+z0Rf+EjKYJ/FeXZWQt52uczb1yjm srgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=I4NADb68; 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 d7-20020a170902aa8700b00151da975a90si4076255plr.210.2022.03.06.22.03.01; Sun, 06 Mar 2022 22:03:26 -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=I4NADb68; 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 S234465AbiCFXoR (ORCPT + 99 others); Sun, 6 Mar 2022 18:44:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234472AbiCFXoQ (ORCPT ); Sun, 6 Mar 2022 18:44:16 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCA2D403D1 for ; Sun, 6 Mar 2022 15:43:22 -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-out2.suse.de (Postfix) with ESMTPS id 9E2101F37D; Sun, 6 Mar 2022 23:43:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1646610201; 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=P8Ex1C2tLGBY3G4iAkuioFe1tiAu7Sw2IQj0bqqMkqA=; b=I4NADb68BZnf7lUhlzMYISm227LyvRz/3ItYXuq1oatCTkc33NLqGZJ60uEB8loTchguuZ 6basXbVyL1PjbzOdIIY7FZ4Pj9xnuRhBCH+7s624uaJpYEi4byX+tDDartE+OV554VQLQe gJD1hnQQD6wHF09fO2YftsccHMK0ODM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1646610201; 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=P8Ex1C2tLGBY3G4iAkuioFe1tiAu7Sw2IQj0bqqMkqA=; b=2+1XboxeUYaPpfliJDdsioP5qzOfv7gyRcPt6JCBhvDRVIDhmWqIPp2H52nMj6DDtUFLiu GiCnSD90fbfyScCA== 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 91F3E134CD; Sun, 6 Mar 2022 23:43:20 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gMI7FBhHJWJJWAAAMHmgww (envelope-from ); Sun, 06 Mar 2022 23:43:20 +0000 Subject: [PATCH 10/11] NFS: swap-out must always use STABLE writes. From: NeilBrown To: Trond Myklebust , Anna Schumaker Cc: linux-nfs@vger.kernel.org Date: Mon, 07 Mar 2022 10:41:44 +1100 Message-ID: <164661010499.31054.4815913983715248940.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 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 --- 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 04aaf39a05cb..11c566d8769f 100644 --- a/fs/nfs/direct.c +++ b/fs/nfs/direct.c @@ -794,7 +794,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; @@ -802,7 +802,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); @@ -948,11 +948,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,