From nobody Tue Feb 10 05:44:11 2026 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 AEF473033C6; Fri, 9 Jan 2026 03:14:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767928499; cv=none; b=QOwLJJnxDeWoZlfMJBx8+bSjnRlznJuxgx/QY2IChyxW2dyXNgY1MMP+bANJTdttfnjop1A/9BwEX4RDpZ4lg98eHpO8H/uceF+TWlzqdjTX/J0HZ6Z5ECkcKxHNsTk2w5mg6AL3nLaRoZzEG+Wb2qFMkT3ZzIbdaav/IPkMzp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767928499; c=relaxed/simple; bh=GIG0iVEeSaYWSb9UOeG6A4TW0TzFA2hTW6WDyaPChPs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tzpHLpwDtJFVlJKgPc3a1+ZEeCNzai9AxjouvJ3oBZevspC+VKizdHc8Jcu2lZyedI2Du7E2Tixpn+ekc0NUKcoGPBkpzQbsCVyiL0I5AxcIsRnnBk5wUIPZbQ1Nw2ZqwuKTpbRt7lVlsvjkAoXAjoNUP6afO8q6dTDGdE8HEJ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=hDPirPbx; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=hDPirPbx; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="hDPirPbx"; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="hDPirPbx" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=GMiG3KxyMRrDcExhh2zKYwP+YiMVAseTuuCZp2tTRO0=; b=hDPirPbxVDQuKp01p2DNZl+buDOy3ab1lSG7hTWnEYHAoMWsq5JNoa2iAlAKSfml9SRsJQPtD SjjEEa/uVi/RJDqnk5YxToqDDuK0kq9uVDcP+i0eORJ5Abmld7TR/4kKCRQKQN74myXaNF2WDmG m7SA24qGQvEAADFb083dgV8= Received: from canpmsgout04.his.huawei.com (unknown [172.19.92.133]) by szxga01-in.huawei.com (SkyGuard) with ESMTPS id 4dnRgk4SNHz1BFrL; Fri, 9 Jan 2026 11:13:54 +0800 (CST) dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=GMiG3KxyMRrDcExhh2zKYwP+YiMVAseTuuCZp2tTRO0=; b=hDPirPbxVDQuKp01p2DNZl+buDOy3ab1lSG7hTWnEYHAoMWsq5JNoa2iAlAKSfml9SRsJQPtD SjjEEa/uVi/RJDqnk5YxToqDDuK0kq9uVDcP+i0eORJ5Abmld7TR/4kKCRQKQN74myXaNF2WDmG m7SA24qGQvEAADFb083dgV8= Received: from mail.maildlp.com (unknown [172.19.162.144]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4dnRd2055Yz1prKH; Fri, 9 Jan 2026 11:11:34 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 6788840567; Fri, 9 Jan 2026 11:14:52 +0800 (CST) Received: from huawei.com (10.67.174.162) by kwepemr500015.china.huawei.com (7.202.195.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 9 Jan 2026 11:14:51 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v13 02/10] erofs: hold read context in iomap_iter if needed Date: Fri, 9 Jan 2026 03:01:32 +0000 Message-ID: <20260109030140.594936-3-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20260109030140.594936-1-lihongbo22@huawei.com> References: <20260109030140.594936-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems100001.china.huawei.com (7.221.188.238) To kwepemr500015.china.huawei.com (7.202.195.162) Content-Type: text/plain; charset="utf-8" Introduce `struct erofs_iomap_iter_ctx` to hold both `struct page *` and `void *base`, avoiding bogus use of `kmap_to_page()` in `erofs_iomap_end()`. With this change, fiemap and bmap no longer need to read inline data. Additionally, the upcoming page cache sharing mechanism requires passing the backing inode pointer to `erofs_iomap_{begin,end}()`, as I/O accesses must apply to backing inodes rather than anon inodes. Signed-off-by: Hongbo Li Reviewed-by: Gao Xiang --- fs/erofs/data.c | 67 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index bb13c4cb8455..71e23d91123d 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -266,13 +266,20 @@ void erofs_onlinefolio_end(struct folio *folio, int e= rr, bool dirty) folio_end_read(folio, !(v & BIT(EROFS_ONLINEFOLIO_EIO))); } =20 +struct erofs_iomap_iter_ctx { + struct page *page; + void *base; +}; + static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t le= ngth, unsigned int flags, struct iomap *iomap, struct iomap *srcmap) { - int ret; + struct iomap_iter *iter =3D container_of(iomap, struct iomap_iter, iomap); + struct erofs_iomap_iter_ctx *ctx =3D iter->private; struct super_block *sb =3D inode->i_sb; struct erofs_map_blocks map; struct erofs_map_dev mdev; + int ret; =20 map.m_la =3D offset; map.m_llen =3D length; @@ -283,7 +290,6 @@ static int erofs_iomap_begin(struct inode *inode, loff_= t offset, loff_t length, iomap->offset =3D map.m_la; iomap->length =3D map.m_llen; iomap->flags =3D 0; - iomap->private =3D NULL; iomap->addr =3D IOMAP_NULL_ADDR; if (!(map.m_flags & EROFS_MAP_MAPPED)) { iomap->type =3D IOMAP_HOLE; @@ -309,16 +315,20 @@ static int erofs_iomap_begin(struct inode *inode, lof= f_t offset, loff_t length, } =20 if (map.m_flags & EROFS_MAP_META) { - void *ptr; - struct erofs_buf buf =3D __EROFS_BUF_INITIALIZER; - iomap->type =3D IOMAP_INLINE; - ptr =3D erofs_read_metabuf(&buf, sb, map.m_pa, - erofs_inode_in_metabox(inode)); - if (IS_ERR(ptr)) - return PTR_ERR(ptr); - iomap->inline_data =3D ptr; - iomap->private =3D buf.base; + /* read context should read the inlined data */ + if (ctx) { + struct erofs_buf buf =3D __EROFS_BUF_INITIALIZER; + void *ptr; + + ptr =3D erofs_read_metabuf(&buf, sb, map.m_pa, + erofs_inode_in_metabox(inode)); + if (IS_ERR(ptr)) + return PTR_ERR(ptr); + iomap->inline_data =3D ptr; + ctx->page =3D buf.page; + ctx->base =3D buf.base; + } } else { iomap->type =3D IOMAP_MAPPED; } @@ -328,18 +338,18 @@ static int erofs_iomap_begin(struct inode *inode, lof= f_t offset, loff_t length, static int erofs_iomap_end(struct inode *inode, loff_t pos, loff_t length, ssize_t written, unsigned int flags, struct iomap *iomap) { - void *ptr =3D iomap->private; + struct iomap_iter *iter =3D container_of(iomap, struct iomap_iter, iomap); + struct erofs_iomap_iter_ctx *ctx =3D iter->private; =20 - if (ptr) { + if (ctx && ctx->base) { struct erofs_buf buf =3D { - .page =3D kmap_to_page(ptr), - .base =3D ptr, + .page =3D ctx->page, + .base =3D ctx->base, }; =20 DBG_BUGON(iomap->type !=3D IOMAP_INLINE); erofs_put_metabuf(&buf); - } else { - DBG_BUGON(iomap->type =3D=3D IOMAP_INLINE); + ctx->base =3D NULL; } return written; } @@ -369,18 +379,30 @@ int erofs_fiemap(struct inode *inode, struct fiemap_e= xtent_info *fieinfo, */ static int erofs_read_folio(struct file *file, struct folio *folio) { + struct iomap_read_folio_ctx read_ctx =3D { + .ops =3D &iomap_bio_read_ops, + .cur_folio =3D folio, + }; + struct erofs_iomap_iter_ctx iter_ctx =3D {}; + trace_erofs_read_folio(folio, true); =20 - iomap_bio_read_folio(folio, &erofs_iomap_ops); + iomap_read_folio(&erofs_iomap_ops, &read_ctx, &iter_ctx); return 0; } =20 static void erofs_readahead(struct readahead_control *rac) { + struct iomap_read_folio_ctx read_ctx =3D { + .ops =3D &iomap_bio_read_ops, + .rac =3D rac, + }; + struct erofs_iomap_iter_ctx iter_ctx =3D {}; + trace_erofs_readahead(rac->mapping->host, readahead_index(rac), readahead_count(rac), true); =20 - iomap_bio_readahead(rac, &erofs_iomap_ops); + iomap_readahead(&erofs_iomap_ops, &read_ctx, &iter_ctx); } =20 static sector_t erofs_bmap(struct address_space *mapping, sector_t block) @@ -400,9 +422,12 @@ static ssize_t erofs_file_read_iter(struct kiocb *iocb= , struct iov_iter *to) if (IS_DAX(inode)) return dax_iomap_rw(iocb, to, &erofs_iomap_ops); #endif - if ((iocb->ki_flags & IOCB_DIRECT) && inode->i_sb->s_bdev) + if ((iocb->ki_flags & IOCB_DIRECT) && inode->i_sb->s_bdev) { + struct erofs_iomap_iter_ctx iter_ctx =3D {}; + return iomap_dio_rw(iocb, to, &erofs_iomap_ops, - NULL, 0, NULL, 0); + NULL, 0, &iter_ctx, 0); + } return filemap_read(iocb, to, 0); } =20 --=20 2.22.0