summaryrefslogtreecommitdiffstats
path: root/block/bio-integrity-fs.c
diff options
context:
space:
mode:
authorMiguel Ojeda <ojeda@kernel.org>2026-08-16 15:32:33 +0200
committerMiguel Ojeda <ojeda@kernel.org>2026-08-23 21:27:17 +0200
commit5febf432df1cfa5b25d99b54c32103fafbdd0eb9 (patch)
tree93a1ed1d337bc53adf1e572c2586d347703b286e /block/bio-integrity-fs.c
downloadlinux-stable-5febf432df1cfa5b25d99b54c32103fafbdd0eb9.tar.gz
linux-stable-5febf432df1cfa5b25d99b54c32103fafbdd0eb9.zip
kbuild: rust: keep Rust objects out of Clang LTO with inline helpersgrafted
Under `CONFIG_LTO_CLANG` + `CONFIG_RUST_INLINE_HELPERS`, one may hit `objtool` errors such as: vmlinux.o: error: objtool: _R..._3Gsp4boot+0xd6a: can't find jump dest instruction at .text._R..._3Gsp4boot+0x1dfd The reason is that in such builds, the Clang invocation that compiles the combined Rust plus helpers bitcode emits LLVM bitcode (again) -- the final code generation happens in the linker's LTO step, which the `-mllvm` trap options passed to Clang do not reach. This, in turn, means that unreachable traps are missing, and the impossible paths do not merely fallthrough to the next symbol, but past the end of their own section, since LTO builds place each function in its own section. Thus filter `CC_FLAGS_LTO` out of the Clang invocation, so that it always emits machine code directly, with the traps in place. Assisted-by: LLM Cc: Gary Guo <gary@garyguo.net> Cc: Boqun Feng <boqun@kernel.org> Cc: Alice Ryhl <aliceryhl@google.com> Cc: Matthew Maurer <mmaurer@google.com> Cc: Josh Poimboeuf <jpoimboe@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: stable@vger.kernel.org Fixes: 3a2486cc1da5 ("kbuild: rust: provide an option to inline C helpers into Rust") Acked-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260816133233.197500-2-ojeda@kernel.org Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'block/bio-integrity-fs.c')
-rw-r--r--block/bio-integrity-fs.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/block/bio-integrity-fs.c b/block/bio-integrity-fs.c
new file mode 100644
index 000000000..9c5fe5fa8
--- /dev/null
+++ b/block/bio-integrity-fs.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2025 Christoph Hellwig.
+ */
+#include <linux/blk-integrity.h>
+#include <linux/bio-integrity.h>
+#include "blk.h"
+
+struct fs_bio_integrity_buf {
+ struct bio_integrity_payload bip;
+ struct bio_vec bvec;
+};
+
+static struct kmem_cache *fs_bio_integrity_cache;
+static mempool_t fs_bio_integrity_pool;
+
+unsigned int fs_bio_integrity_alloc(struct bio *bio)
+{
+ struct fs_bio_integrity_buf *iib;
+ unsigned int action;
+
+ action = bio_integrity_action(bio);
+ if (!action)
+ return 0;
+
+ iib = mempool_alloc(&fs_bio_integrity_pool, GFP_NOFS);
+ bio_integrity_init(bio, &iib->bip, &iib->bvec, 1);
+
+ bio_integrity_alloc_buf(bio, GFP_NOFS, action & BI_ACT_ZERO);
+ if (action & BI_ACT_CHECK)
+ bio_integrity_setup_default(bio);
+ return action;
+}
+
+void fs_bio_integrity_free(struct bio *bio)
+{
+ struct bio_integrity_payload *bip = bio_integrity(bio);
+
+ bio_integrity_free_buf(bip);
+ mempool_free(container_of(bip, struct fs_bio_integrity_buf, bip),
+ &fs_bio_integrity_pool);
+
+ bio->bi_integrity = NULL;
+ bio->bi_opf &= ~REQ_INTEGRITY;
+}
+
+void fs_bio_integrity_generate(struct bio *bio)
+{
+ if (fs_bio_integrity_alloc(bio))
+ bio_integrity_generate(bio);
+}
+EXPORT_SYMBOL_GPL(fs_bio_integrity_generate);
+
+int fs_bio_integrity_verify(struct bio *bio, sector_t sector, unsigned int size)
+{
+ struct blk_integrity *bi = blk_get_integrity(bio->bi_bdev->bd_disk);
+ struct bio_integrity_payload *bip = bio_integrity(bio);
+ struct bvec_iter data_iter = {
+ .bi_sector = sector,
+ .bi_size = size,
+ };
+
+ /*
+ * Reinitialize bip->bip_iter.
+ *
+ * This is for use in the submitter after the driver is done with the
+ * bio. Requires the submitter to remember the sector and the size.
+ */
+ memset(&bip->bip_iter, 0, sizeof(bip->bip_iter));
+ bip->bip_iter.bi_sector = sector;
+ bip->bip_iter.bi_size = bio_integrity_bytes(bi, size >> SECTOR_SHIFT);
+ return blk_status_to_errno(bio_integrity_verify(bio, &data_iter));
+}
+
+static int __init fs_bio_integrity_init(void)
+{
+ fs_bio_integrity_cache = kmem_cache_create("fs_bio_integrity",
+ sizeof(struct fs_bio_integrity_buf), 0,
+ SLAB_HWCACHE_ALIGN | SLAB_PANIC, NULL);
+ if (mempool_init_slab_pool(&fs_bio_integrity_pool, BIO_POOL_SIZE,
+ fs_bio_integrity_cache))
+ panic("fs_bio_integrity: can't create pool\n");
+ return 0;
+}
+fs_initcall(fs_bio_integrity_init);