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 F21323C199E; Thu, 22 Jan 2026 08:23:06 +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=1769070188; cv=none; b=nbY3TUQRL4KZLn+VjjdsOOYCgmoMWNJOYVf/1Ee8f+3qfd3QKFuEEmhBqxg9dUa3odNzTN+Q1/APzFEObAwMRTT3oNfXK29IrtX3xY2AhxKRfrZR0oijKUBKxOKAn0awM6h3xSs7SeKvh8O33bQyVImoie/GUQm3u7FoxZ40oas= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769070188; c=relaxed/simple; bh=Ds7nQElTciKCoBuzFNRFLEVQvdWROZXdIw9DY82rvBc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g3h5zEcfB9APcSAyo2UWWwly0aPjSaQ/NAaPoAfiBtRSs402+jz4mRipbE51wocyz11oVEBhiwBfrpnR9ILBaj/yUtpLm70YGoh7xTQ8oE3R4V/5N4qIb66mmOUGSmD8tvxiF75N495QUXX0Whsqc2yTPzYqVJt2nnh1IKSAf6o= 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=WN+gg7r8; 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="WN+gg7r8" 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=Uz7fpZnjUlMd/aGr9OL/OJaWWyGR47o6Wopw3Zb7zdM=; b=WN+gg7r8VVeZUsfkGpEY+bVNIR pPQE7vV6wEEJ91SJdSOlr31GM924930lgYaKOWoMR24hiORPnakfIYVOUSK47hbaIuWi5cu7d1aD9 850a1dCW9DRw+v8bBa8mcFLgdVJN+2hygDwW3oF2jsO5CIUtY6Ppzequej/JC+qUsT2r4TAPl8U1u rEAcKxFjpJIbqYxqcieX/UbUAbQqvGHD4AtvhN9A4kYbZZ86GK7r6JEzSo/sW5vxuMr4OVKlepJLH RZOMt/45XpxBSR94DU/b+1s4Eq8O1UC/inOYgVR0WZ1oVEcYHiiwrlHsiAV7VwD3tdvZ6TDjAI3nm qUOgUxhA==; 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 1vipy4-00000006dvK-3tHV; Thu, 22 Jan 2026 08:23:05 +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 (Oracle)" , 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 Subject: [PATCH 07/11] fs: consolidate fsverity_info lookup in buffer.c Date: Thu, 22 Jan 2026 09:22:03 +0100 Message-ID: <20260122082214.452153-8-hch@lst.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260122082214.452153-1-hch@lst.de> References: <20260122082214.452153-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 --- 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