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 076AC368297; Wed, 28 Jan 2026 15:27:57 +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=1769614079; cv=none; b=utvZMIbBlHUkLBUnyq0snTseO/41P3Y5N/OfgecG1kDD5J5EftDW9I5HYfazX6t1DXCW78IeRPsujmUWzJ+CtRSWtLV0wVQaJsO1BLiQKOtwLyTp2yytkuxPx/4d+qzRbiumXUFYevZQVmreHaEAh6sQHF9Ji61YnSdX8fHbUK8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769614079; c=relaxed/simple; bh=BrLi4j57QgtV8qhnorxfv6TzhYgRMR8tNVsB4M/sVnI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t35ppWfTQBfmFqyheXrw9ZA+dfSrpLGWsjt7JfgcMOOjyke2i3XJ4Jz+ZzbKli/UjDdjJF9LWy+Bn0pDEd1Rr8MQZZZK/f9L+XFquvVBFv2pIA3oB8Qi7lcrCu321nqMNRCN4xpVlDI3a4IR8vCE70gN64q9OwbV0uPMe0GdevM= 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=MwD7lLIU; 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="MwD7lLIU" 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=tSPZVX9Sxv7o1Tr96dGuUXSLqIyOoHyYNr+LZJx+lOo=; b=MwD7lLIU6/rUUrEHGNpqZ9umNA lpgRgL+S1vpJQufKu9GAAB2g8Ojv35OiGT+YmA4wedWHSMF2n1Y/rhyZnrbNfVl70VGZXspjiLLnV +o3NfvM/RQZOEOFezwS/8nDY7uSN+TLlI+XRZzcD5ZShwKwldT3iqum9391YH12z8AQO9FbSkq1KZ qmjoReg/RciG2ATTWL4JQCJTo8n11x0mUOJz88h/fqtpD2wWF9DGopUMfoXvzzp4uZgOUSipC7oiL V5rY8tdKJtTunqX9WoOHwWQLIEOGG7uY84w2MtI0DONfjVOj/LlK9RjypqAyJ27xhzLZ3iP8AyDE7 YhquhrKA==; 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 1vl7SV-0000000GHYC-3ulz; Wed, 28 Jan 2026 15:27:56 +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 11/15] fs: consolidate fsverity_info lookup in buffer.c Date: Wed, 28 Jan 2026 16:26:23 +0100 Message-ID: <20260128152630.627409-12-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 end_buffer_async_read_io, and then pass it along to the I/O completion workqueue in struct postprocess_bh_ctx. This amortizes the lookup better once it becomes less efficient. Signed-off-by: Christoph Hellwig Reviewed-by: "Darrick J. Wong" --- fs/buffer.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 3982253b6805..f4b3297ef1b1 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -302,6 +302,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate) struct postprocess_bh_ctx { struct work_struct work; struct buffer_head *bh; + struct fsverity_info *vi; }; static void verify_bh(struct work_struct *work) @@ -309,25 +310,14 @@ static void verify_bh(struct work_struct *work) struct postprocess_bh_ctx *ctx = container_of(work, struct postprocess_bh_ctx, work); struct buffer_head *bh = ctx->bh; - struct inode *inode = bh->b_folio->mapping->host; bool valid; - valid = fsverity_verify_blocks(*fsverity_info_addr(inode), bh->b_folio, - bh->b_size, bh_offset(bh)); + valid = fsverity_verify_blocks(ctx->vi, bh->b_folio, bh->b_size, + bh_offset(bh)); end_buffer_async_read(bh, valid); kfree(ctx); } -static bool need_fsverity(struct buffer_head *bh) -{ - struct folio *folio = bh->b_folio; - struct inode *inode = folio->mapping->host; - - return fsverity_active(inode) && - /* needed by ext4 */ - folio->index < DIV_ROUND_UP(inode->i_size, PAGE_SIZE); -} - static void decrypt_bh(struct work_struct *work) { struct postprocess_bh_ctx *ctx = @@ -337,7 +327,7 @@ static void decrypt_bh(struct work_struct *work) err = fscrypt_decrypt_pagecache_blocks(bh->b_folio, bh->b_size, bh_offset(bh)); - if (err == 0 && need_fsverity(bh)) { + if (err == 0 && ctx->vi) { /* * We use different work queues for decryption and for verity * because verity may require reading metadata pages that need @@ -359,15 +349,20 @@ static void end_buffer_async_read_io(struct buffer_head *bh, int uptodate) { struct inode *inode = bh->b_folio->mapping->host; bool decrypt = fscrypt_inode_uses_fs_layer_crypto(inode); - bool verify = need_fsverity(bh); + struct fsverity_info *vi = NULL; + + /* needed by ext4 */ + if (bh->b_folio->index < DIV_ROUND_UP(inode->i_size, PAGE_SIZE)) + vi = fsverity_get_info(inode); /* Decrypt (with fscrypt) and/or verify (with fsverity) if needed. */ - if (uptodate && (decrypt || verify)) { + if (uptodate && (decrypt || vi)) { struct postprocess_bh_ctx *ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC); if (ctx) { ctx->bh = bh; + ctx->vi = vi; if (decrypt) { INIT_WORK(&ctx->work, decrypt_bh); fscrypt_enqueue_decrypt_work(&ctx->work); -- 2.47.3