]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fsverity: add tracepoints
authorAndrey Albershteyn <aalbersh@kernel.org>
Mon, 26 Jan 2026 11:56:58 +0000 (12:56 +0100)
committerChristian Brauner <brauner@kernel.org>
Thu, 29 Jan 2026 15:00:57 +0000 (16:00 +0100)
fs-verity previously had debug printk but it was removed. This patch
adds trace points to similar places, as a better alternative.

Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
[djwong: fix formatting]
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Link: https://patch.msgid.link/20260126115658.27656-3-aalbersh@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
MAINTAINERS
fs/verity/enable.c
fs/verity/fsverity_private.h
fs/verity/init.c
fs/verity/verify.c
include/trace/events/fsverity.h [new file with mode: 0644]

index 5b11839cba9de1e9e43f63787578edd8c429ca39..9761650d2ead86a1f8628d1aeab8e4ef62e0dfc5 100644 (file)
@@ -10311,6 +10311,7 @@ T:      git https://git.kernel.org/pub/scm/fs/fsverity/linux.git
 F:     Documentation/filesystems/fsverity.rst
 F:     fs/verity/
 F:     include/linux/fsverity.h
+F:     include/trace/events/fsverity.h
 F:     include/uapi/linux/fsverity.h
 
 FT260 FTDI USB-HID TO I2C BRIDGE DRIVER
index 95ec42b847972c1b9bb14c5053a3dbbb85ed651d..8718d943b428283d495eddb909be6991bc70bd6b 100644 (file)
@@ -222,6 +222,8 @@ static int enable_verity(struct file *filp,
        if (err)
                goto out;
 
+       trace_fsverity_enable(inode, &params);
+
        /*
         * Start enabling verity on this file, serialized by the inode lock.
         * Fail if verity is already enabled or is already being enabled.
@@ -264,6 +266,8 @@ static int enable_verity(struct file *filp,
                goto rollback;
        }
 
+       trace_fsverity_tree_done(inode, vi, &params);
+
        /*
         * Tell the filesystem to finish enabling verity on the file.
         * Serialized with ->begin_enable_verity() by the inode lock.
index dd20b138d452fa61db532467f925044dd627b8c7..4b7ae1748f4e07b2cd3da0698ff2efae5c0ad8d8 100644 (file)
@@ -161,4 +161,6 @@ static inline void fsverity_init_signature(void)
 
 void __init fsverity_init_workqueue(void);
 
+#include <trace/events/fsverity.h>
+
 #endif /* _FSVERITY_PRIVATE_H */
index 6e8d33b50240e088dc5c52b2e14e8c57705bcc92..d6520660858386d3b7d69b20a459dc27d8017a5f 100644 (file)
@@ -5,6 +5,7 @@
  * Copyright 2019 Google LLC
  */
 
+#define CREATE_TRACE_POINTS
 #include "fsverity_private.h"
 
 #include <linux/ratelimit.h>
index 86067c8b40cf3207d0cc274852f635b9cc90d61e..940b8b956d7e28c50b7c6918b400b5c9d8836732 100644 (file)
@@ -135,6 +135,9 @@ static bool verify_data_block(struct inode *inode, struct fsverity_info *vi,
                /* Byte offset of the wanted hash relative to @addr */
                unsigned int hoffset;
        } hblocks[FS_VERITY_MAX_LEVELS];
+
+       trace_fsverity_verify_data_block(inode, params, data_pos);
+
        /*
         * The index of the previous level's block within that level; also the
         * index of that block's hash within the current level.
@@ -214,6 +217,9 @@ static bool verify_data_block(struct inode *inode, struct fsverity_info *vi,
                        want_hash = _want_hash;
                        kunmap_local(haddr);
                        put_page(hpage);
+                       trace_fsverity_merkle_hit(inode, data_pos, hblock_idx,
+                                       level,
+                                       hoffset >> params->log_digestsize);
                        goto descend;
                }
                hblocks[level].page = hpage;
@@ -232,6 +238,9 @@ descend:
                unsigned long hblock_idx = hblocks[level - 1].index;
                unsigned int hoffset = hblocks[level - 1].hoffset;
 
+               trace_fsverity_verify_merkle_block(inode, hblock_idx,
+                               level, hoffset >> params->log_digestsize);
+
                fsverity_hash_block(params, haddr, real_hash);
                if (memcmp(want_hash, real_hash, hsize) != 0)
                        goto corrupted;
diff --git a/include/trace/events/fsverity.h b/include/trace/events/fsverity.h
new file mode 100644 (file)
index 0000000..a8c52f2
--- /dev/null
@@ -0,0 +1,146 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM fsverity
+
+#if !defined(_TRACE_FSVERITY_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_FSVERITY_H
+
+#include <linux/tracepoint.h>
+
+struct fsverity_descriptor;
+struct merkle_tree_params;
+struct fsverity_info;
+
+TRACE_EVENT(fsverity_enable,
+       TP_PROTO(const struct inode *inode,
+                const struct merkle_tree_params *params),
+       TP_ARGS(inode, params),
+       TP_STRUCT__entry(
+               __field(ino_t, ino)
+               __field(u64, data_size)
+               __field(u64, tree_size)
+               __field(unsigned int, merkle_block)
+               __field(unsigned int, num_levels)
+       ),
+       TP_fast_assign(
+               __entry->ino = inode->i_ino;
+               __entry->data_size = i_size_read(inode);
+               __entry->tree_size = params->tree_size;
+               __entry->merkle_block = params->block_size;
+               __entry->num_levels = params->num_levels;
+       ),
+       TP_printk("ino %lu data_size %llu tree_size %llu merkle_block %u levels %u",
+               (unsigned long) __entry->ino,
+               __entry->data_size,
+               __entry->tree_size,
+               __entry->merkle_block,
+               __entry->num_levels)
+);
+
+TRACE_EVENT(fsverity_tree_done,
+       TP_PROTO(const struct inode *inode, const struct fsverity_info *vi,
+                const struct merkle_tree_params *params),
+       TP_ARGS(inode, vi, params),
+       TP_STRUCT__entry(
+               __field(ino_t, ino)
+               __field(u64, data_size)
+               __field(u64, tree_size)
+               __field(unsigned int, merkle_block)
+               __field(unsigned int, levels)
+               __dynamic_array(u8, root_hash, params->digest_size)
+               __dynamic_array(u8, file_digest, params->digest_size)
+       ),
+       TP_fast_assign(
+               __entry->ino = inode->i_ino;
+               __entry->data_size = i_size_read(inode);
+               __entry->tree_size = params->tree_size;
+               __entry->merkle_block = params->block_size;
+               __entry->levels = params->num_levels;
+               memcpy(__get_dynamic_array(root_hash), vi->root_hash, __get_dynamic_array_len(root_hash));
+               memcpy(__get_dynamic_array(file_digest), vi->file_digest, __get_dynamic_array_len(file_digest));
+       ),
+       TP_printk("ino %lu data_size %llu tree_size %lld merkle_block %u levels %u root_hash %s digest %s",
+               (unsigned long) __entry->ino,
+               __entry->data_size,
+               __entry->tree_size,
+               __entry->merkle_block,
+               __entry->levels,
+               __print_hex_str(__get_dynamic_array(root_hash), __get_dynamic_array_len(root_hash)),
+               __print_hex_str(__get_dynamic_array(file_digest), __get_dynamic_array_len(file_digest)))
+);
+
+TRACE_EVENT(fsverity_verify_data_block,
+       TP_PROTO(const struct inode *inode,
+                const struct merkle_tree_params *params,
+                u64 data_pos),
+       TP_ARGS(inode, params, data_pos),
+       TP_STRUCT__entry(
+               __field(ino_t, ino)
+               __field(u64, data_pos)
+               __field(unsigned int, merkle_block)
+       ),
+       TP_fast_assign(
+               __entry->ino = inode->i_ino;
+               __entry->data_pos = data_pos;
+               __entry->merkle_block = params->block_size;
+       ),
+       TP_printk("ino %lu data_pos %llu merkle_block %u",
+               (unsigned long) __entry->ino,
+               __entry->data_pos,
+               __entry->merkle_block)
+);
+
+TRACE_EVENT(fsverity_merkle_hit,
+       TP_PROTO(const struct inode *inode, u64 data_pos,
+                unsigned long hblock_idx, unsigned int level,
+                unsigned int hidx),
+       TP_ARGS(inode, data_pos, hblock_idx, level, hidx),
+       TP_STRUCT__entry(
+               __field(ino_t, ino)
+               __field(u64, data_pos)
+               __field(unsigned long, hblock_idx)
+               __field(unsigned int, level)
+               __field(unsigned int, hidx)
+       ),
+       TP_fast_assign(
+               __entry->ino = inode->i_ino;
+               __entry->data_pos = data_pos;
+               __entry->hblock_idx = hblock_idx;
+               __entry->level = level;
+               __entry->hidx = hidx;
+       ),
+       TP_printk("ino %lu data_pos %llu hblock_idx %lu level %u hidx %u",
+               (unsigned long) __entry->ino,
+               __entry->data_pos,
+               __entry->hblock_idx,
+               __entry->level,
+               __entry->hidx)
+);
+
+TRACE_EVENT(fsverity_verify_merkle_block,
+       TP_PROTO(const struct inode *inode, unsigned long hblock_idx,
+                unsigned int level, unsigned int hidx),
+       TP_ARGS(inode, hblock_idx, level, hidx),
+       TP_STRUCT__entry(
+               __field(ino_t, ino)
+               __field(unsigned long, hblock_idx)
+               __field(unsigned int, level)
+               __field(unsigned int, hidx)
+       ),
+       TP_fast_assign(
+               __entry->ino = inode->i_ino;
+               __entry->hblock_idx = hblock_idx;
+               __entry->level = level;
+               __entry->hidx = hidx;
+       ),
+       TP_printk("ino %lu hblock_idx %lu level %u hidx %u",
+               (unsigned long) __entry->ino,
+               __entry->hblock_idx,
+               __entry->level,
+               __entry->hidx)
+);
+
+#endif /* _TRACE_FSVERITY_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>