Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp264228ybv; Tue, 18 Feb 2020 22:40:57 -0800 (PST) X-Google-Smtp-Source: APXvYqznfptYyUKedQLyZgL130yWSdoHm0Y6L125JOlq56o50gnxLaoO0OuV0FjXxMJATJZ5unIQ X-Received: by 2002:a9d:4e93:: with SMTP id v19mr16522911otk.200.1582094457792; Tue, 18 Feb 2020 22:40:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582094457; cv=none; d=google.com; s=arc-20160816; b=b+EDyR7NyhVOlhC00I6Ro+D09hUQ84VesnEg6w4p53iZoqlFKKcowp1kK+9C3479W4 aqtnvmPRK/AnE8ETpJ2kgfahFo+DitYfyCZHZYKdg4QuVgyvWOi+d0LMNSqe9ts+CMjF AkB9lMJ4nvmGL/J0oDyvzyA3jvUnUUc4cb/JNjx+5TByyG8WudfKMweAlIIAV0a304Iq KP3MPE+6oiHKPANGoKG4e9I7BrG4TkWz5Dv6cxArcrai0BcQd9GCNvwGDa5coCnxdUOG 8DS0WNXfxTSuASOG5h0LH4o/1fLiWYAB6Hyg6pgFwDbg28sKkUplO/zi9p0LN+TTFSRA oWHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=xatMJOOjyBdqk824oT38MRhU43KfJLtiqRw6ZkMpY3c=; b=UWpaKCK7+Dc3d49QvGJXXuxTe5fYzz6xGaEevqGp534BNtDvxmWGCQasuRpnzUXP3j 1mPykki9utp+VQDoS/kcrS6h2n6g7KOIeU53p2I5QthFCvezKCqPWZ2wqrcxwsUqs0Ab yqvwnnEFkOmzzQWdDkZ5FdfXMC2pV8hRMMl7njGwQr5eh9k3CpkpeDZod48HkNMpEmH3 5v5LXWcVdYeZCxVrnMz7+0sM7f3Xyr9ZIXzHoi/4l/kAh7wrs13hjyUonrnij+kx4wrb K8Orx6ltJ1R7PX90mm8Ni4EduKrh4h174819Ceb6PWtUBFBD5pTa2+3N4LjvUqJ+b4ai a0tA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u5si683121otg.66.2020.02.18.22.40.42; Tue, 18 Feb 2020 22:40:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726335AbgBSGkM (ORCPT + 99 others); Wed, 19 Feb 2020 01:40:12 -0500 Received: from mail105.syd.optusnet.com.au ([211.29.132.249]:48643 "EHLO mail105.syd.optusnet.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726156AbgBSGkL (ORCPT ); Wed, 19 Feb 2020 01:40:11 -0500 Received: from dread.disaster.area (pa49-179-138-28.pa.nsw.optusnet.com.au [49.179.138.28]) by mail105.syd.optusnet.com.au (Postfix) with ESMTPS id 93B223A38C1; Wed, 19 Feb 2020 17:40:06 +1100 (AEDT) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1j4J1h-0006cP-MZ; Wed, 19 Feb 2020 17:40:05 +1100 Date: Wed, 19 Feb 2020 17:40:05 +1100 From: Dave Chinner To: Matthew Wilcox Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, ocfs2-devel@oss.oracle.com, linux-xfs@vger.kernel.org Subject: Re: [PATCH v6 17/19] iomap: Restructure iomap_readpages_actor Message-ID: <20200219064005.GL10776@dread.disaster.area> References: <20200217184613.19668-1-willy@infradead.org> <20200217184613.19668-31-willy@infradead.org> <20200219032900.GE10776@dread.disaster.area> <20200219060415.GO24185@bombadil.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200219060415.GO24185@bombadil.infradead.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.3 cv=W5xGqiek c=1 sm=1 tr=0 a=zAxSp4fFY/GQY8/esVNjqw==:117 a=zAxSp4fFY/GQY8/esVNjqw==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=kj9zAlcOel0A:10 a=l697ptgUJYAA:10 a=7-415B0cAAAA:8 a=r7nCFNou5KQKI5VhP1MA:9 a=-52OSV3k6aGjHW0a:21 a=qFaRso0K34Rwt0Du:21 a=CjuIK1q_8ugA:10 a=biEYGPWJfzWAr4FL6Ov7:22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 18, 2020 at 10:04:15PM -0800, Matthew Wilcox wrote: > On Wed, Feb 19, 2020 at 02:29:00PM +1100, Dave Chinner wrote: > > On Mon, Feb 17, 2020 at 10:46:11AM -0800, Matthew Wilcox wrote: > > > @@ -418,6 +412,15 @@ iomap_readpages_actor(struct inode *inode, loff_t pos, loff_t length, > > > } > > > ret = iomap_readpage_actor(inode, pos + done, length - done, > > > ctx, iomap, srcmap); > > > + if (WARN_ON(ret == 0)) > > > + break; > > > > This error case now leaks ctx->cur_page.... > > Yes ... and I see the consequence. I mean, this is a "shouldn't happen", > so do we want to put effort into cleanup here ... Well, the normal thing for XFS is that a production kernel cleans up and handles the error gracefully with a WARN_ON_ONCE, while a debug kernel build will chuck a tanty and burn the house down so to make the developers aware that there is a "should not happen" situation occurring.... > > > @@ -451,11 +454,7 @@ iomap_readpages(struct address_space *mapping, struct list_head *pages, > > > done: > > > if (ctx.bio) > > > submit_bio(ctx.bio); > > > - if (ctx.cur_page) { > > > - if (!ctx.cur_page_in_bio) > > > - unlock_page(ctx.cur_page); > > > - put_page(ctx.cur_page); > > > - } > > > + BUG_ON(ctx.cur_page); > > > > And so will now trigger both a warn and a bug.... > > ... or do we just want to run slap bang into this bug? > > Option 1: Remove the check for 'ret == 0' altogether, as we had it before. > That puts us into endless loop territory for a failure mode, and it's not > parallel with iomap_readpage(). > > Option 2: Remove the WARN_ON from the check. Then we just hit the BUG_ON, > but we don't know why we did it. > > Option 3: Set cur_page to NULL. We'll hit the WARN_ON, avoid the BUG_ON, > might end up with a page in the page cache which is never unlocked. None of these are appealing. > Option 4: Do the unlock/put page dance before setting the cur_page to NULL. > We might double-unlock the page. why would we double unlock the page? Oh, the readahead cursor doesn't handle the case of partial page submission, which would result in IO completion unlocking the page. Ok, that's what the ctx.cur_page_in_bio check is used to detect i.e. if we've got a page that the readahead cursor points at, and we haven't actually added it to a bio, then we can leave it to the read_pages() to unlock and clean up. If it's in a bio, then IO completion will unlock it and so we only have to drop the submission reference and move the readahead cursor forwards so read_pages() doesn't try to unlock this page. i.e: /* clean up partial page submission failures */ if (ctx.cur_page && ctx.cur_page_in_bio) { put_page(ctx.cur_page); readahead_next(rac); } looks to me like it will handle the case of "ret == 0" in the actor function just fine. Cheers, Dave. -- Dave Chinner david@fromorbit.com