[RFC PATCH 0/2] rust: block: add a borrowed blk-mq timeout callback

From: Wenzhao Liao

Date: Fri Apr 10 2026 - 13:04:54 EST


This small RFC series fills a missing blk-mq callback in the Rust block
layer. Today, Rust block drivers cannot participate in request timeout
handling because the Rust blk-mq vtable hardcodes `timeout: None`.

Patch 1 adds a typed `TimeoutReturn` wrapper for
`enum blk_eh_timer_return` and extends `mq::Operations` with an
optional `timeout(&Request<Self>) -> TimeoutReturn` callback.

The key design choice is to model timeout as a shared borrow of
`Request`, not as `ARef<Request<_>>`. In this tree, blk-mq invokes
`timeout(struct request *)` synchronously while the block layer retains
ownership of the request. The timeout path is therefore a notification
over a request whose lifetime is guaranteed for the duration of the
call, not an ownership handoff to the driver.

Representing the callback as `&Request` keeps that contract explicit in
the type system, avoids fabricating a fresh `ARef`, and avoids touching
the request wrapper refcount from the timeout path entirely. It also
prevents the Rust API from implying that drivers may persist or take
ownership of the request from this callback.

For compatibility, the vtable only installs the timeout callback when
`#[vtable]` generates `HAS_TIMEOUT`; drivers that do not implement the
method continue to expose `timeout: None`, preserving existing behavior.

Patch 2 wires the new abstraction into `rnull` as a minimal reference
user. `rnull` implements the callback and returns
`TimeoutReturn::ResetTimer`, which keeps behavior close to the current
default timeout handling while proving that the Rust abstraction wires
cleanly into a real driver.

This tree uses the `timeout(struct request *)` blk-mq ABI, so the RFC is
intentionally scoped to that signature and does not model the newer
`reserved` parameter variant.

Build-tested with:

make -C /home/lwz/rfl-dev/worktrees/rnull-upstream-contribution \
O=/tmp/c2saferust-rnull-upstream-build LLVM=-15 defconfig
make -C /home/lwz/rfl-dev/worktrees/rnull-upstream-contribution \
O=/tmp/c2saferust-rnull-upstream-build LLVM=-15 rustavailable
make -C /home/lwz/rfl-dev/worktrees/rnull-upstream-contribution \
O=/tmp/c2saferust-rnull-upstream-build LLVM=-15 vmlinux
make -C /home/lwz/rfl-dev/worktrees/rnull-upstream-contribution \
O=/tmp/c2saferust-rnull-upstream-build LLVM=-15 \
drivers/block/rnull/rnull_mod.ko

with `CONFIG_RUST=y`, `CONFIG_CONFIGFS_FS=y`, and
`CONFIG_BLK_DEV_RUST_NULL=m` enabled in the out-of-tree build.

Comments are especially welcome on whether `&Request<Self>` is the right
long-term Rust surface for blk-mq timeout handling.

Wenzhao Liao (2):
rust: block: mq: safely abstract the timeout callback
block: rnull: implement dummy timeout callback

drivers/block/rnull/rnull.rs | 4 +++
rust/kernel/block/mq.rs | 2 +-
rust/kernel/block/mq/operations.rs | 40 +++++++++++++++++++++++++++++-
3 files changed, 44 insertions(+), 2 deletions(-)

--
2.34.1