Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5488040F8C2 for ; Thu, 22 Jan 2026 06:22:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769062926; cv=none; b=QXTThmIZy7WzfhbCddKNiDM45yEfu+VwpdU9kZTFpAg1rvkLJ3vMOzQCP+9NYvnZeRA2RcbHgHGhVQ0a6FSnvUVVWpLt0JNPbKVpVVPBfuV8OO/t1F25rF9KNE4W4wlQ8lsE5ZeYvGCNxK4PU+CWxs7diG2qfJp1JX+Kcsymj0c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769062926; c=relaxed/simple; bh=BuhcUeagOrblC0D3FauRt9BUA47GTN59GTabgWaIwD0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=O9kWQ6lUUcpY0axdrMgK4LzwFBSzjEi67Kari0oZpfRa19NKJj07dKTht3yALn235nJakRPE2MuCEH4KCOJWpuv7kdkGRyoLfUUtpPoBE4jqilOrGxUVdlp6PiLCcPx8dL8sSPqqeqtNjXymfhGWlD+R1L1ToXWJNUCPOpQbdxA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=dPtRDG3Q; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="dPtRDG3Q" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=E9+heVjOiPN4xLku4leMU1/TgIt/0iviGGXi0cpAQ7g=; b=dPtRDG3Qk40K+II92TfrLGhLFb hEEuy4bA6ZBeBqW7EupDUS4gw0v9mCd+5oqBIBqA2K8+jCFV5/pgt5ZTMlzae54XS0kn9oTL4CShi JqhoACfK14pnsTwNAJ5I7pjyrH6X1EmHDG/pLLJ06kIYdS9KIJ88IIAWAF+Q9Quk8MpNEJTFEzKl9 dShncJ7k1ueEakvMn/hqFs8SSBF4CDSd5ib/9TNUHC+hWrbWhzeQJXYMFrUFAl8DO/hN9L2NOAjqo 2kB/pyVQXvll4/nFhE402XY0ShmHOky9j6sqJxSa4J4PGivyuxa1EniRhgrlJlOzn6Yt1q91tnfOL 2r3PQlyA==; Received: from hch by bombadil.infradead.org with local (Exim 4.98.2 #2 (Red Hat Linux)) id 1vio4v-00000006Upk-0Es9; Thu, 22 Jan 2026 06:22:01 +0000 Date: Wed, 21 Jan 2026 22:22:01 -0800 From: Christoph Hellwig To: Joanne Koong Cc: Christoph Hellwig , brauner@kernel.org, willy@infradead.org, djwong@kernel.org, bfoster@redhat.com, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v3 1/1] iomap: fix readahead folio access after folio_end_read() Message-ID: References: <20260116200427.1016177-1-joannelkoong@gmail.com> <20260116200427.1016177-2-joannelkoong@gmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html On Wed, Jan 21, 2026 at 03:13:35PM -0800, Joanne Koong wrote: > Thanks for taking a look at this. The problem I'm trying to fix is > this readahead scenario: > * folio with no ifs gets read in by the filesystem through the > ->read_folio_range() call > * the filesystem reads in the folio and calls > iomap_finish_folio_read() which calls folio_end_read(), which unlocks > the folio > * then the page cache evicts the folio and drops the last refcount on > the folio which frees the folio and the folio gets repurposed by > another filesystem (eg btrfs) which uses folio->private > * the iomap logic accesses ctx->cur_folio still, and in the call to > iomap_read_end(), it'll detect a non-null folio->private and it'll > assume that's the ifs and it'll try to do stuff like > spin_lock_irq(&ifs->state_lock) which will crash the system. Yeah, I think I gather that from the code changes in the patch, but it helps to state this. Or in short, this: if (ctx->cur_folio && offset_in_folio(ctx->cur_folio, iter->pos) == 0) { accesses a potentially freed folio. > > > + if (unlikely(plen != folio_len)) > > > + return -EIO; > > > + } > > > > I think the sanity check here is an impossible to hit condition and > > should probably be a WARN_ON_ONCE? > > I'll be removing this check for the next version. I think it's good to have the checking, what I mean is to add a WARN_ON_ONCE to make it stick out as a debug check. > Looking at this some more, I think we'll need to use ctx->cur_folio > for non-readahead reads as well (eg passing ctx->cur_folio to > iomap_read_end() in iomap_read_folio()). As Matthew pointed out to me > in [1], we still can't access folio->private after folio_end_read() > even if we hold an active refcount on the folio. Yeah.