From nobody Tue Feb 10 00:57:53 2026 Received: from canpmsgout04.his.huawei.com (canpmsgout04.his.huawei.com [113.46.200.219]) (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 A577230F7E4; Fri, 14 Nov 2025 10:07:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763114825; cv=none; b=TNIEb/glSfrwLLH9plt+6jfoOxF+XHAn56MIldh2Qs8LvF1hA+vBll784T45RMfgey52wVna/HHtsZh7E1KYKmmHb1UvigckRqZqQMAkwAn1NNsZHC1Z+1VpfJECUXJAHmRKaYq06O41j9twsM0fjridGCwYS0cgCJf9vju9GQA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763114825; c=relaxed/simple; bh=60G7Og+fkL/ycDlX4lls67Wo98U0QEGGA8YMPqHQ0po=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KHisTICbq2+jwvV+dYF+KT5Dxp8d0Yy6i2BPo6wvRwjYrDuWUo+99bFjDhNVei7DxlGlCjLbYTECD64eWGvJy6ozH2J4S3XLVtLGHoexPFh/Mw3C8pzXQd8y23QMQmvCXCNdt2oMCB8Z0x8ByCpmZABCOLCkCxb+EH6t3urs4qU= 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=EV8iVJoK; arc=none smtp.client-ip=113.46.200.219 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="EV8iVJoK" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=taDPXuSohFIbjKqHNC7TAvBRm/MUsJxB6CrB2qYxkis=; b=EV8iVJoK7ecc8euILR3Ko+h8dtrSgWNrVnjY8Vcmao3+AkMEaU8pATbmZEDpmMiRkSTdu+Gsa XMaew/zvJVirMT6LwmE63XorCDRwkPo+twFwkod6zJj3F1uqtPl3HEG9Kz0Ofnj4roJDk+bxCX2 9s4ydz0TIyD24QrPdbVnaZc= Received: from mail.maildlp.com (unknown [172.19.163.174]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4d7CSB3S9cz1prLM; Fri, 14 Nov 2025 18:05:14 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id CFF9C14035E; Fri, 14 Nov 2025 18:06:55 +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, 14 Nov 2025 18:06:55 +0800 From: Hongbo Li To: , , , , , CC: , , Subject: [PATCH v8 2/9] erofs: hold read context in iomap_iter if needed Date: Fri, 14 Nov 2025 09:55:09 +0000 Message-ID: <20251114095516.207555-3-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251114095516.207555-1-lihongbo22@huawei.com> References: <20251114095516.207555-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: kwepems500001.china.huawei.com (7.221.188.70) To kwepemr500015.china.huawei.com (7.202.195.162) Content-Type: text/plain; charset="utf-8" Uncoming page cache sharing needs pass read context to iomap_iter, here we unify the way of passing the read context in EROFS. Moreover, bmap and fiemap don't need to map the inline data. Note that we keep `struct page *` in `struct erofs_iomap_iter_ctx` as well to avoid bogus kmap_to_page usage. Signed-off-by: Hongbo Li --- fs/erofs/data.c | 79 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 20 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index bb13c4cb8455..bd3d85c61341 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -266,14 +266,23 @@ 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 erofs_iomap_iter_ctx *ctx; struct super_block *sb =3D inode->i_sb; struct erofs_map_blocks map; struct erofs_map_dev mdev; + struct iomap_iter *iter; =20 + iter =3D container_of(iomap, struct iomap_iter, iomap); + ctx =3D iter->private; map.m_la =3D offset; map.m_llen =3D length; ret =3D erofs_map_blocks(inode, &map); @@ -283,7 +292,8 @@ 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; + if (ctx) + ctx->base =3D NULL; iomap->addr =3D IOMAP_NULL_ADDR; if (!(map.m_flags & EROFS_MAP_MAPPED)) { iomap->type =3D IOMAP_HOLE; @@ -309,16 +319,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) { + void *ptr; + struct erofs_buf buf =3D __EROFS_BUF_INITIALIZER; + + 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 +342,19 @@ 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 erofs_iomap_iter_ctx *ctx; + struct iomap_iter *iter; =20 - if (ptr) { + iter =3D container_of(iomap, struct iomap_iter, iomap); + ctx =3D iter->private; + 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); } return written; } @@ -369,18 +384,36 @@ 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 { + .page =3D NULL, + .base =3D NULL, + }; + 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 { + .page =3D NULL, + .base =3D NULL, + }; + 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 +433,15 @@ 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 { + .page =3D NULL, + .base =3D NULL, + }; + 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