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 E4ED0367F36; Wed, 28 Jan 2026 15:28: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=1769614085; cv=none; b=MdZLTQFZroqHTAU9dKbmpTpAY+gsMM6/+WXYOqjyY2WjHJoI8Yq5qfS4XQzYwXWzoJqHxrQRW1lWFb9uFOZLdvhuPkBvs0GDldzI62B3yIFUvFi+U77/zZTspAToKSz3GZOdh+UbusE/cxRMP5a7v7Alc8dnnKWzL+UiKPxGELQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614085; c=relaxed/simple; bh=RH4ywp0cmyWzgcoK/QUJN+cb3B+tPrcjBFmD3MkPAcI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SHs92SWh5VIFgiJq551OU6JjPaF7ZtRCJuz/vDMIW9Yr6QskUKxqnUNGm1/+kd1rClG71KV3tx78tcejvUN/1Ik1i5YpKrOmfLbIMzl/jg/2t3kOJv8dT61088hdaClDZiaTQ6VuLeyklEf0mngZ6ifXc5axvflrq732jbAwrY4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=C7mPkD4F; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=lst.de 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="C7mPkD4F" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=oRybYDIwYACfSNoZYA6Jbad4AVQunyOxpSpOn34Lydo=; b=C7mPkD4FKOxbPCGqh5e4ZNQrmX lPKeKBifP+uwBTlhG2TU3ubWwq84JQh7nsaPx9Wsoy83Ei6kPKWzoIIhJXociUVud3bXgPSFuIqKg O6NR9tFO5e435GCtINO+FFZPodK0Qr2Ve0+wONyShuae+Pes6eW7jlHhbmBLGe2l+RiMiYOFr8NT7 ZqEFyWE0AOlXRFhnX+CBC3BxHXYKWUY+9l04700vzmjldg5P3FjwNIgy06HReyaSAcErNeyohwtfy 8V9sDQ4yOOIpO/VJ5ULkNBWPoKFJJj0sIzXdcFeblK6NJb1UQtgP8fgpV8jrrUSDnTubT/CAENQh4 HPt9t5Cw==; Received: from 2a02-8389-2341-5b80-d601-7564-c2e0-491c.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:d601:7564:c2e0:491c] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vl7Sb-0000000GHYt-0LF9; Wed, 28 Jan 2026 15:28:01 +0000 From: Christoph Hellwig To: Eric Biggers Cc: Al Viro , Christian Brauner , Jan Kara , David Sterba , "Theodore Ts'o" , Jaegeuk Kim , Chao Yu , Andrey Albershteyn , Matthew Wilcox , linux-fsdevel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, fsverity@lists.linux.dev, "Darrick J. Wong" Subject: [PATCH 12/15] ext4: consolidate fsverity_info lookup Date: Wed, 28 Jan 2026 16:26:24 +0100 Message-ID: <20260128152630.627409-13-hch@lst.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260128152630.627409-1-hch@lst.de> References: <20260128152630.627409-1-hch@lst.de> Precedence: bulk X-Mailing-List: fsverity@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Look up the fsverity_info once in ext4_mpage_readpages, and then use it for the readahead, local verification of holes and pass it along to the I/O completion workqueue in struct bio_post_read_ctx. This amortizes the lookup better once it becomes less efficient. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" --- fs/ext4/readpage.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c index bf65562da9c2..17920f14e2c2 100644 --- a/fs/ext4/readpage.c +++ b/fs/ext4/readpage.c @@ -61,6 +61,7 @@ enum bio_post_read_step { struct bio_post_read_ctx { struct bio *bio; + struct fsverity_info *vi; struct work_struct work; unsigned int cur_step; unsigned int enabled_steps; @@ -96,7 +97,7 @@ static void verity_work(struct work_struct *work) struct bio_post_read_ctx *ctx = container_of(work, struct bio_post_read_ctx, work); struct bio *bio = ctx->bio; - struct inode *inode = bio_first_folio_all(bio)->mapping->host; + struct fsverity_info *vi = ctx->vi; /* * fsverity_verify_bio() may call readahead() again, and although verity @@ -109,7 +110,7 @@ static void verity_work(struct work_struct *work) mempool_free(ctx, bio_post_read_ctx_pool); bio->bi_private = NULL; - fsverity_verify_bio(*fsverity_info_addr(inode), bio); + fsverity_verify_bio(vi, bio); __read_end_io(bio); } @@ -173,22 +174,16 @@ static void mpage_end_io(struct bio *bio) __read_end_io(bio); } -static inline bool ext4_need_verity(const struct inode *inode, pgoff_t idx) -{ - return fsverity_active(inode) && - idx < DIV_ROUND_UP(inode->i_size, PAGE_SIZE); -} - static void ext4_set_bio_post_read_ctx(struct bio *bio, const struct inode *inode, - pgoff_t first_idx) + struct fsverity_info *vi) { unsigned int post_read_steps = 0; if (fscrypt_inode_uses_fs_layer_crypto(inode)) post_read_steps |= 1 << STEP_DECRYPT; - if (ext4_need_verity(inode, first_idx)) + if (vi) post_read_steps |= 1 << STEP_VERITY; if (post_read_steps) { @@ -197,6 +192,7 @@ static void ext4_set_bio_post_read_ctx(struct bio *bio, mempool_alloc(bio_post_read_ctx_pool, GFP_NOFS); ctx->bio = bio; + ctx->vi = vi; ctx->enabled_steps = post_read_steps; bio->bi_private = ctx; } @@ -224,6 +220,7 @@ int ext4_mpage_readpages(struct inode *inode, sector_t first_block; unsigned page_block; struct block_device *bdev = inode->i_sb->s_bdev; + struct fsverity_info *vi = NULL; int length; unsigned relative_block = 0; struct ext4_map_blocks map; @@ -245,9 +242,11 @@ int ext4_mpage_readpages(struct inode *inode, folio = readahead_folio(rac); if (first_folio) { - if (ext4_need_verity(inode, folio->index)) - fsverity_readahead(*fsverity_info_addr(inode), - folio, nr_pages); + if (folio->index < + DIV_ROUND_UP(inode->i_size, PAGE_SIZE)) + vi = fsverity_get_info(inode); + if (vi) + fsverity_readahead(vi, folio, nr_pages); first_folio = false; } @@ -338,10 +337,7 @@ int ext4_mpage_readpages(struct inode *inode, folio_zero_segment(folio, first_hole << blkbits, folio_size(folio)); if (first_hole == 0) { - if (ext4_need_verity(inode, folio->index) && - !fsverity_verify_folio( - *fsverity_info_addr(inode), - folio)) + if (vi && !fsverity_verify_folio(vi, folio)) goto set_error_page; folio_end_read(folio, true); continue; @@ -369,7 +365,7 @@ int ext4_mpage_readpages(struct inode *inode, REQ_OP_READ, GFP_KERNEL); fscrypt_set_bio_crypt_ctx(bio, inode, next_block, GFP_KERNEL); - ext4_set_bio_post_read_ctx(bio, inode, folio->index); + ext4_set_bio_post_read_ctx(bio, inode, vi); bio->bi_iter.bi_sector = first_block << (blkbits - 9); bio->bi_end_io = mpage_end_io; if (rac) -- 2.47.3