From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EF06C4338F for ; Thu, 12 Aug 2021 13:52:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D79F06104F for ; Thu, 12 Aug 2021 13:52:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D79F06104F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 03C266B006C; Thu, 12 Aug 2021 09:52:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F2E896B0071; Thu, 12 Aug 2021 09:52:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E44B28D0001; Thu, 12 Aug 2021 09:52:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0036.hostedemail.com [216.40.44.36]) by kanga.kvack.org (Postfix) with ESMTP id CE4696B006C for ; Thu, 12 Aug 2021 09:52:42 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 7C7C98249980 for ; Thu, 12 Aug 2021 13:52:42 +0000 (UTC) X-FDA: 78466568964.02.1D9F6A1 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf01.hostedemail.com (Postfix) with ESMTP id AA9AB5042A01 for ; Thu, 12 Aug 2021 13:52:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=FSEsyOd/4VgGNCa1AqMwPM0EjAO09/FKI4Y/RKgJ9oc=; b=PB5TN4rKLBFyrXRJ8+IpPQ6GFx 2HZerN1HTd63PeshnKhem+nljRBmLxaui/i1om21F1sWmP+hMjDDJS55xmhS4oxKnXpp00KnpzlE2 6tQVDF8Pd76VOg9hA0cSJAVGBbnv7LS9wdSGk8uZBVHe2WoYmsCL9EPrsjzBwNlB7m9OA+qWOBH1G DTyJpos7StYMPNb6UNL6IuKFA0DUtnHaaEuEKWdoAYnmFSKoMzx36cch7maZBd4MaeMtpzgCwzvbB 9o5RCPCZF/Z5mBKHgCxOE1L3ECk8GErwIJcu9ZXSzHn3MSgCYAsxdlO5JdfXXv/TKXFzWMqGvGsxv lm77IDCQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mEB6d-00Ed87-Bu; Thu, 12 Aug 2021 13:50:55 +0000 Date: Thu, 12 Aug 2021 14:50:47 +0100 From: Matthew Wilcox To: David Howells Cc: trond.myklebust@primarydata.com, darrick.wong@oracle.com, hch@lst.de, jlayton@kernel.org, sfrench@samba.org, torvalds@linux-foundation.org, linux-nfs@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] mm: Make swap_readpage() for SWP_FS_OPS use ->direct_IO() not ->readpage() Message-ID: References: <3088327.1628774588@warthog.procyon.org.uk> <162876946134.3068428.15475611190876694695.stgit@warthog.procyon.org.uk> <162876947840.3068428.12591293664586646085.stgit@warthog.procyon.org.uk> <3088958.1628775479@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3088958.1628775479@warthog.procyon.org.uk> X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: AA9AB5042A01 X-Stat-Signature: b1935kro6bgxuhz9gpsijfuyzqnxtyrg Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=PB5TN4rK; dmarc=none; spf=none (imf01.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-HE-Tag: 1628776361-348391 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Aug 12, 2021 at 02:37:59PM +0100, David Howells wrote: > David Howells wrote: > > > Matthew Wilcox wrote: > > > > > After submitting the IO here ... > > > > > > > + if (ret != -EIOCBQUEUED) > > > > + swapfile_read_complete(&ki->iocb, ret, 0); > > > > > > We only touch the 'ki' here ... if the caller didn't call read_complete > > > > > > > + swapfile_put_kiocb(ki); > > > > > > Except for here, which is only touched in order to put the refcount. > > > > > > So why can't swapfile_read_complete() do the work of freeing the ki? > > > > When I was doing something similar for cachefiles, I couldn't get it to work > > like that. I'll have another look at that. > > Ah, yes. generic_file_direct_write() accesses in the kiocb *after* calling > ->direct_IO(), so the kiocb *must not* go away until after > generic_file_direct_write() has returned. This is a read, not a write ... but we don't care about ki_pos being updated, so that store can be conditioned on IOCB_SWAP being clear. Or instead of storing directly to ki_pos, we take a pointer to ki_pos and then redirect that pointer somewhere harmless.