[PATCH 56/79] block: rust: add abstraction for block queue feature flags

Andreas Hindborg
2026-02-15T23:42:13Z

Add the `Feature` enum and `Features` type as Rust abstractions for the
C `blk_features_t` bitfield. These types wrap the `BLK_FEAT_*` flags
and allow drivers to describe block device capabilities such as write
cache support, FUA, rotational media, and DAX.

Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
rust/bindings/bindings_helper.h | 15 ++++++++-
rust/kernel/block/mq.rs | 2 ++
rust/kernel/block/mq/feature.rs | 73 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 89 insertions(+), 1 deletion(-)

diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h
index b8c2f3eadc730..209c53443e9cb 100644
--- a/rust/bindings/bindings_helper.h
+++ b/rust/bindings/bindings_helper.h
@@ -113,7 +113,6 @@ const gfp_t RUST_CONST_HELPER_GFP_NOWAIT = GFP_NOWAIT;
const gfp_t RUST_CONST_HELPER___GFP_ZERO = __GFP_ZERO;
const gfp_t RUST_CONST_HELPER___GFP_HIGHMEM = ___GFP_HIGHMEM;
const gfp_t RUST_CONST_HELPER___GFP_NOWARN = ___GFP_NOWARN;
-const blk_features_t RUST_CONST_HELPER_BLK_FEAT_ROTATIONAL = BLK_FEAT_ROTATIONAL;
const blk_status_t RUST_CONST_HELPER_BLK_STS_OK = BLK_STS_OK;
const blk_status_t RUST_CONST_HELPER_BLK_STS_NOTSUPP = BLK_STS_NOTSUPP;
const blk_status_t RUST_CONST_HELPER_BLK_STS_TIMEOUT = BLK_STS_TIMEOUT;
@@ -133,7 +132,21 @@ const blk_status_t RUST_CONST_HELPER_BLK_STS_ZONE_ACTIVE_RESOURCE = BLK_STS_ZONE
const blk_status_t RUST_CONST_HELPER_BLK_STS_OFFLINE = BLK_STS_OFFLINE;
const blk_status_t RUST_CONST_HELPER_BLK_STS_DURATION_LIMIT = BLK_STS_DURATION_LIMIT;
const blk_status_t RUST_CONST_HELPER_BLK_STS_INVAL = BLK_STS_INVAL;
+const blk_features_t RUST_CONST_HELPER_BLK_FEAT_WRITE_CACHE = BLK_FEAT_WRITE_CACHE;
+const blk_features_t RUST_CONST_HELPER_BLK_FEAT_FUA = BLK_FEAT_FUA;
+const blk_features_t RUST_CONST_HELPER_BLK_FEAT_ROTATIONAL = BLK_FEAT_ROTATIONAL;
+const blk_features_t RUST_CONST_HELPER_BLK_FEAT_ADD_RANDOM = BLK_FEAT_ADD_RANDOM;
+const blk_features_t RUST_CONST_HELPER_BLK_FEAT_IO_STAT = BLK_FEAT_IO_STAT;
+const blk_features_t RUST_CONST_HELPER_BLK_FEAT_STABLE_WRITES = BLK_FEAT_STABLE_WRITES;
+const blk_features_t RUST_CONST_HELPER_BLK_FEAT_SYNCHRONOUS = BLK_FEAT_SYNCHRONOUS;
+const blk_features_t RUST_CONST_HELPER_BLK_FEAT_NOWAIT = BLK_FEAT_NOWAIT;
+const blk_features_t RUST_CONST_HELPER_BLK_FEAT_DAX = BLK_FEAT_DAX;
+const blk_features_t RUST_CONST_HELPER_BLK_FEAT_POLL = BLK_FEAT_POLL;
const blk_features_t RUST_CONST_HELPER_BLK_FEAT_ZONED = BLK_FEAT_ZONED;
+const blk_features_t RUST_CONST_HELPER_BLK_FEAT_PCI_P2PDMA = BLK_FEAT_PCI_P2PDMA;
+const blk_features_t RUST_CONST_HELPER_BLK_FEAT_SKIP_TAGSET_QUIESCE = BLK_FEAT_SKIP_TAGSET_QUIESCE;
+const blk_features_t RUST_CONST_HELPER_BLK_FEAT_RAID_PARTIAL_STRIPES_EXPENSIVE = BLK_FEAT_RAID_PARTIAL_STRIPES_EXPENSIVE;
+const blk_features_t RUST_CONST_HELPER_BLK_FEAT_ATOMIC_WRITES = BLK_FEAT_ATOMIC_WRITES;
const blk_opf_t RUST_CONST_HELPER_REQ_FAILFAST_DEV = REQ_FAILFAST_DEV;
const blk_opf_t RUST_CONST_HELPER_REQ_FAILFAST_TRANSPORT = REQ_FAILFAST_TRANSPORT;
const blk_opf_t RUST_CONST_HELPER_REQ_FAILFAST_DRIVER = REQ_FAILFAST_DRIVER;
diff --git a/rust/kernel/block/mq.rs b/rust/kernel/block/mq.rs
index 5a1c8e914bb9e..b36112f7b22b9 100644
--- a/rust/kernel/block/mq.rs
+++ b/rust/kernel/block/mq.rs
@@ -125,12 +125,14 @@
//! # Ok::<(), kernel::error::Error>(())
//! ```

+mod feature;
pub mod gen_disk;
mod operations;
mod request;
mod request_queue;
pub mod tag_set;

+pub use feature::{Feature, Features};
pub use operations::IoCompletionBatch;
pub use operations::Operations;
pub use request::Command;
diff --git a/rust/kernel/block/mq/feature.rs b/rust/kernel/block/mq/feature.rs
new file mode 100644
index 0000000000000..6c9f098e10c55
--- /dev/null
+++ b/rust/kernel/block/mq/feature.rs
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Block device feature flags.
+//!
+//! This module provides Rust abstractions for the C `blk_features_t` type and
+//! the associated `BLK_FEAT_*` flags defined in `include/linux/blkdev.h`.
+
+use kernel::prelude::*;
+
+impl_flags! {
+ /// A set of block device feature flags.
+ ///
+ /// This type wraps the C `blk_features_t` bitfield and represents a
+ /// combination of zero or more [`Feature`] flags. It is used to describe
+ /// the capabilities of a block device in [`struct queue_limits`].
+ ///
+ /// [`struct queue_limits`]: srctree/include/linux/blkdev.h
+ #[derive(Debug, Clone, Default, Copy, PartialEq, Eq)]
+ pub struct Features(u32);
+
+ /// A block device feature flag.
+ ///
+ /// Each variant corresponds to a `BLK_FEAT_*` constant defined in
+ /// `include/linux/blkdev.h`. These flags describe individual capabilities
+ /// or properties of a block device.
+ #[derive(Debug, Clone, Copy, PartialEq, Eq)]
+ pub enum Feature {
+ /// Supports a volatile write cache.
+ WriteCache = bindings::BLK_FEAT_WRITE_CACHE,
+
+ /// Supports passing on the FUA bit.
+ ForcedUnitAccess = bindings::BLK_FEAT_FUA,
+
+ /// Rotational device (hard drive or floppy).
+ Rotational = bindings::BLK_FEAT_ROTATIONAL,
+
+ /// Contributes to the random number pool.
+ AddRandom = bindings::BLK_FEAT_ADD_RANDOM,
+
+ /// Enables disk/partitions I/O accounting.
+ IoStat = bindings::BLK_FEAT_IO_STAT,
+
+ /// Don't modify data until writeback is done.
+ StableWrites = bindings::BLK_FEAT_STABLE_WRITES,
+
+ /// Always completes in submit context.
+ Synchronous = bindings::BLK_FEAT_SYNCHRONOUS,
+
+ /// Supports REQ_NOWAIT.
+ Nowait = bindings::BLK_FEAT_NOWAIT,
+
+ /// Supports DAX.
+ Dax = bindings::BLK_FEAT_DAX,
+
+ /// Supports I/O polling.
+ Poll = bindings::BLK_FEAT_POLL,
+
+ /// Is a zoned device.
+ Zoned = bindings::BLK_FEAT_ZONED,
+
+ /// Supports PCI(e) p2p requests.
+ PciP2Pdma = bindings::BLK_FEAT_PCI_P2PDMA,
+
+ /// Skips this queue in `blk_mq_(un)quiesce_tagset`.
+ SkipTagsetQuiesce = bindings::BLK_FEAT_SKIP_TAGSET_QUIESCE,
+
+ /// Undocumented magic for bcache.
+ RaidPartialStripesExpensive = bindings::BLK_FEAT_RAID_PARTIAL_STRIPES_EXPENSIVE,
+
+ /// Atomic writes enabled.
+ AtomicWrites = bindings::BLK_FEAT_ATOMIC_WRITES,
+ }
+}

--
2.51.2