Skip to contentSkip to conversation

Rust block device driver API and null block driver

PATCH Superseded Andreas Hindborg 5 participants 10 messages May 12, 2024 – May 14, 2024

Subsystems (4)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover Rust block device driver API and null block driver

From: Andreas Hindborg <[email protected]>

Hi All!

I am happy to finally send the first _non_ RFC patches for the Rust block device API.

This series provides an initial Rust block layer device driver API, and a very minimal null block driver to exercise the API. The driver has only one mode of operation and cannot be configured.

These patches are an updated and trimmed down version of the v2 RFC [1]. One of the requests for the v2 RFC was to split the abstractions into smaller pieces that are easier to review. This is the first part of the split patches.

A notable change in this patch set is that they no longer use the ref field of the C struct request to manage lifetime of the request structure.

The removed features will be sent later, as their dependencies land upstream.

As mentioned before, I will gladly maintain this code if required.

Canges from RFC v2:

- Change request state tracking method
- Use a slice rather than a raw pointer for RawWriter
- Use typestate patttern for GenDisk to prevent mutation of non synchronized fields
- Remove per gendisk private data support
- Remove per tag_set private data support
- Remove per hwctx private data support
- Remove per request private data support
- Remove use of ARef::into_raw
- Remove use of Opaque::try_ffi_init
- Remove map_queues support
- Remove bio iteration support
- Remove methods to fail requests
- Remove request introspection methods
- Remove module configuration via module parameters
- Remove timer completion support for Rust null block driver
- Remove memory backing support for Rust null block driver
- Remove soft-irq completion support for Rust null block driver

Thanks for all the feedback and comments on the earlier versions!

Best regards,
Andreas Hindborg

Andreas Hindborg (3):
rust: block: introduce kernel::block::mq module
rust: block: add rnull, Rust null_blk implementation
MAINTAINERS: add entry for Rust block device driver API

 MAINTAINERS                        |  14 ++
 drivers/block/Kconfig              |   9 ++
 drivers/block/Makefile             |   3 +
 drivers/block/rnull.rs             |  82 ++++++++++
 rust/bindings/bindings_helper.h    |   2 +
 rust/helpers.c                     |  16 ++
 rust/kernel/block.rs               |   5 +
 rust/kernel/block/mq.rs            | 109 +++++++++++++
 rust/kernel/block/mq/gen_disk.rs   | 205 ++++++++++++++++++++++++
 rust/kernel/block/mq/operations.rs | 245 +++++++++++++++++++++++++++++
 rust/kernel/block/mq/raw_writer.rs |  55 +++++++
 rust/kernel/block/mq/request.rs    | 227 ++++++++++++++++++++++++++
 rust/kernel/block/mq/tag_set.rs    |  93 +++++++++++
 rust/kernel/error.rs               |   5 +
 rust/kernel/lib.rs                 |   2 +
 scripts/Makefile.build             |   2 +-
 16 files changed, 1073 insertions(+), 1 deletion(-)
 create mode 100644 drivers/block/rnull.rs
 create mode 100644 rust/kernel/block.rs
 create mode 100644 rust/kernel/block/mq.rs
 create mode 100644 rust/kernel/block/mq/gen_disk.rs
 create mode 100644 rust/kernel/block/mq/operations.rs
 create mode 100644 rust/kernel/block/mq/raw_writer.rs
 create mode 100644 rust/kernel/block/mq/request.rs
 create mode 100644 rust/kernel/block/mq/tag_set.rs

base-commit: fec50db7033ea478773b159e0e2efb135270e3b7

Signature · 1 line
2.44.0
#1 lore raw

PATCH 1/3 rust: block: introduce `kernel::block::mq` module

From: Andreas Hindborg <[email protected]>

Add initial abstractions for working with blk-mq.

This patch is a maintained, refactored subset of code originally published by Wedson Almeida Filho <[email protected]> [1].

[1] https://github.com/wedsonaf/linux/tree/f2cfd2fe0e2ca4e90994f96afe268bbd4382a891/rust/kernel/blk/mq.rs

Cc Wedson Almeida Filho <[email protected]>
---
 rust/bindings/bindings_helper.h    |   2 +
 rust/helpers.c                     |  16 ++
 rust/kernel/block.rs               |   5 +
 rust/kernel/block/mq.rs            | 109 +++++++++++++
 rust/kernel/block/mq/gen_disk.rs   | 205 ++++++++++++++++++++++++
 rust/kernel/block/mq/operations.rs | 245 +++++++++++++++++++++++++++++
 rust/kernel/block/mq/raw_writer.rs |  55 +++++++
 rust/kernel/block/mq/request.rs    | 227 ++++++++++++++++++++++++++
 rust/kernel/block/mq/tag_set.rs    |  93 +++++++++++
 rust/kernel/error.rs               |   5 +
 rust/kernel/lib.rs                 |   2 +
 11 files changed, 964 insertions(+)
 create mode 100644 rust/kernel/block.rs
 create mode 100644 rust/kernel/block/mq.rs
 create mode 100644 rust/kernel/block/mq/gen_disk.rs
 create mode 100644 rust/kernel/block/mq/operations.rs
 create mode 100644 rust/kernel/block/mq/raw_writer.rs
 create mode 100644 rust/kernel/block/mq/request.rs
 create mode 100644 rust/kernel/block/mq/tag_set.rs
rust/bindings/bindings_helper.h +2 -0
index 65b98831b975..b45000342be3 100644
@@ -7,6 +7,8 @@
  */
 
 #include <kunit/test.h>
+#include <linux/blk_types.h>
+#include <linux/blk-mq.h>
 #include <linux/errname.h>
 #include <linux/ethtool.h>
 #include <linux/jiffies.h>
rust/helpers.c +16 -0
index 70e59efd92bc..f151d6b3fdfb 100644
@@ -178,3 +178,19 @@ static_assert(
 	__alignof__(size_t) == __alignof__(uintptr_t),
 	"Rust code expects C `size_t` to match Rust `usize`"
 );
+
+// This will soon be moved to a separate file, so no need to merge with above.
+#include <linux/blk-mq.h>
+#include <linux/blkdev.h>
+
+void *rust_helper_blk_mq_rq_to_pdu(struct request *rq)
+{
+	return blk_mq_rq_to_pdu(rq);
+}
+EXPORT_SYMBOL_GPL(rust_helper_blk_mq_rq_to_pdu);
+
+struct request *rust_helper_blk_mq_rq_from_pdu(void *pdu)
+{
+	return blk_mq_rq_from_pdu(pdu);
+}
+EXPORT_SYMBOL_GPL(rust_helper_blk_mq_rq_from_pdu);
rust/kernel/block.rs new file +5 -0
new file mode 100644
index 000000000000..150f710efe5b
@@ -0,0 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0
+
+//! Types for working with the block layer.
+
+pub mod mq;
rust/kernel/block/mq.rs new file +109 -0

109 lines not on this page · raw message

rust/kernel/block/mq/gen_disk.rs new file +205 -0

205 lines not on this page · raw message

rust/kernel/block/mq/operations.rs new file +245 -0

245 lines not on this page · raw message

rust/kernel/block/mq/raw_writer.rs new file +55 -0

55 lines not on this page · raw message

rust/kernel/block/mq/request.rs new file +227 -0

227 lines not on this page · raw message

rust/kernel/block/mq/tag_set.rs new file +93 -0

93 lines not on this page · raw message

rust/kernel/error.rs +5 -0
index 4786d3ee1e92..469b591cf5c7 100644
@@ -130,6 +130,11 @@ pub fn to_errno(self) -> core::ffi::c_int {
         self.0
     }
 
+    pub(crate) fn to_blk_status(self) -> bindings::blk_status_t {
+        // SAFETY: `self.0` is a valid error due to its invariant.
+        unsafe { bindings::errno_to_blk_status(self.0) }
+    }
+
     /// Returns the error encoded as a pointer.
     #[allow(dead_code)]
     pub(crate) fn to_ptr<T>(self) -> *mut T {
rust/kernel/lib.rs +2 -0
index be68d5e567b1..beede6017bc1 100644
@@ -31,6 +31,8 @@
 #[cfg(not(test))]
 #[cfg(not(testlib))]
 mod allocator;
+#[cfg(CONFIG_BLOCK)]
+pub mod block;
 mod build_assert;
 pub mod error;
 pub mod init;
Signature · 1 line
2.44.0
#2 lore raw

Re: [PATCH 1/3] rust: block: introduce `kernel::block::mq` module

kernel test robot noticed the following build warnings:

Hi Andreas,

kernel test robot noticed the following build warnings:

[auto build test WARNING on fec50db7033ea478773b159e0e2efb135270e3b7]

url:    https://github.com/intel-lab-lkp/linux/commits/Andreas-Hindborg/rust-block-introduce-kernel-block-mq-module/20240513-024107
base:   fec50db7033ea478773b159e0e2efb135270e3b7
patch link:    https://lore.kernel.org/r/20240512183950.1982353-2-nmi%40metaspace.dk
patch subject: [PATCH 1/3] rust: block: introduce `kernel::block::mq` module
config: x86_64-rhel-8.3-rust (https://download.01.org/0day-ci/archive/20240513/[email protected]/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240513/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> warning: unresolved link to `GenDisk`

--> rust/kernel/block/mq.rs:10:18
|
10 | //! - Create a [GenDisk<T>], passing in the TagSet reference
| ^^^^^^^^^^ no item named GenDisk in scope
|
= help: to escape [ and ] characters, add '' before them like [ or ] = note: #[warn(rustdoc::broken_intra_doc_links)] on by default
--

>> warning: unresolved link to `GenDisk::add`

--> rust/kernel/block/mq.rs:11:47
|
11 | //! - Add the disk to the system by calling [GenDisk::add]
| ^^^^^^^^^^^^ no item named GenDisk in scope
--

>> warning: unresolved link to `Operations::RequestData`

--> rust/kernel/block/mq.rs:22:45
|
22 | //! associated types in Operations, see [Operations::RequestData] for an
| ^^^^^^^^^^^^^^^^^^^^^^^ the trait Operations has no associated item named RequestData
--

>> warning: unresolved link to `Request::start`

--> rust/kernel/block/mq.rs:30:51
|
30 | //! mark start of request processing by calling [Request::start] and end of
| ^^^^^^^^^^^^^^ the struct Request has no field or associated item named start
--

>> warning: unresolved link to `Request::end`

--> rust/kernel/block/mq.rs:31:40
|
31 | //! processing by calling one of the [Request::end], methods. Failure to do so
| ^^^^^^^^^^^^ the struct Request has no field or associated item named end

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw

Re: [PATCH 1/3] rust: block: introduce `kernel::block::mq` module

In reply to Andreas Hindborg

rust/kernel/block/mq/gen_disk.rs line 94

Quoted 4 lines · Andreas Hindborg
rust/kernel/block/mq/gen_disk.rs new file +4 -0
+    /// Set the logical block size of the device.
+    ///
+    /// This is the smallest unit the storage device can address. It is
+    /// typically 512 bytes.

Hmm ... all block devices that I have encountered recently have a logical block size of 4096 bytes. Isn't this the preferred logical block size for SSDs and for SMR hard disks?

rust/kernel/block/mq/gen_disk.rs line 106

Quoted 6 lines
rust/kernel/block/mq/gen_disk.rs new file +6 -0
+    /// Set the physical block size of the device.
+    ///
+    /// This is the smallest unit a physical storage device can write
+    /// atomically. It is usually the same as the logical block size but may be
+    /// bigger. One example is SATA drives with 4KB sectors that expose a
+    /// 512-byte logical block size to the operating system.

Please be consistent and change "4 KB sectors" into "4 KB physical block size".

I think that the physical block size can also be smaller than the logical block size. From the SCSI SBC standard:

Table 91 — LOGICAL BLOCKS PER PHYSICAL BLOCK EXPONENT field

-----  ------------------------------------------------------------
Code   Description
-----  ------------------------------------------------------------
0      One or more physical blocks per logical block (the number of

physical blocks per logical block is not reported).
n > 0 2**n logical blocks per physical block
----- ------------------------------------------------------------

rust/kernel/block/mq/gen_disk.rs line 115

Quoted 2 lines
rust/kernel/block/mq/gen_disk.rs new file +2 -0
+impl<T: Operations, S: GenDiskState> GenDisk<T, S> {
+    /// Call to tell the block layer the capacity of the device in sectors (512B).

Why to use any other unit than bytes in Rust block::mq APIs? sector_t
was introduced before 64-bit CPUs became available to reduce the number
of bytes required to represent offsets. I don't think that this is still
a concern today. Hence my proposal to be consistent in the Rust block::mq API and to use bytes as the unit in all APIs.

Thanks,

Bart.

#4 lore raw

Re: [PATCH 1/3] rust: block: introduce `kernel::block::mq` module

Hi Bart,

Quoted 9 lines · Bart Van Assche

rust/kernel/block/mq/gen_disk.rs line 94

Quoted 4 lines · Andreas Hindborg
rust/kernel/block/mq/gen_disk.rs new file +4 -0
+    /// Set the logical block size of the device.
+    ///
+    /// This is the smallest unit the storage device can address. It is
+    /// typically 512 bytes.

Hmm ... all block devices that I have encountered recently have a logical block size of 4096 bytes. Isn't this the preferred logical block size for SSDs and for SMR hard disks?

Yes, that is probably true. This text was lifted from the entry on the sysfs attribute in Documentation/ABI/stable/sysfs-block, but maybe that needs to be updated as well.

Quoted 10 lines

rust/kernel/block/mq/gen_disk.rs line 106

Quoted 7 lines
rust/kernel/block/mq/gen_disk.rs new file +6 -0
+    /// Set the physical block size of the device.
+    ///
+    /// This is the smallest unit a physical storage device can write
+    /// atomically. It is usually the same as the logical block size but may be
+    /// bigger. One example is SATA drives with 4KB sectors that expose a
+    /// 512-byte logical block size to the operating system.

Please be consistent and change "4 KB sectors" into "4 KB physical block size".

OK, I will. I can CC the changes to
Documentation/ABI/stable/sysfs-block then'

Quoted 4 lines

I think that the physical block size can also be smaller than the logical block size. From the SCSI SBC standard:

Quoted 8 lines

Table 91 — LOGICAL BLOCKS PER PHYSICAL BLOCK EXPONENT field

-----  ------------------------------------------------------------
Code   Description
-----  ------------------------------------------------------------
0      One or more physical blocks per logical block (the number of

physical blocks per logical block is not reported).
n > 0 2**n logical blocks per physical block
----- ------------------------------------------------------------

How does that work? Would the drive do a read/modify/write internally? Would that not make the physical block size as seen from the OS equal to the smaller logical block size?

Quoted 9 lines

rust/kernel/block/mq/gen_disk.rs line 115

Quoted 3 lines
rust/kernel/block/mq/gen_disk.rs new file +2 -0
+impl<T: Operations, S: GenDiskState> GenDisk<T, S> {
+    /// Call to tell the block layer the capacity of the device in sectors (512B).

Why to use any other unit than bytes in Rust block::mq APIs? sector_t was introduced before 64-bit CPUs became available to reduce the number of bytes required to represent offsets. I don't think that this is still a concern today. Hence my proposal to be consistent in the Rust block::mq API and to use bytes as the unit in all APIs.

I think that is very good idea. How do others feel about this?

BR Andreas

#5 lore raw

Re: [PATCH 1/3] rust: block: introduce `kernel::block::mq` module

Quoted 27 lines · Andreas Hindborg

Hi Bart,

Quoted 9 lines · Bart Van Assche

rust/kernel/block/mq/gen_disk.rs line 94

Quoted 4 lines · Andreas Hindborg
rust/kernel/block/mq/gen_disk.rs new file +4 -0
+    /// Set the logical block size of the device.
+    ///
+    /// This is the smallest unit the storage device can address. It is
+    /// typically 512 bytes.

Hmm ... all block devices that I have encountered recently have a logical block size of 4096 bytes. Isn't this the preferred logical block size for SSDs and for SMR hard disks?

Yes, that is probably true. This text was lifted from the entry on the sysfs attribute in Documentation/ABI/stable/sysfs-block, but maybe that needs to be updated as well.

Quoted 8 lines
Quoted 7 lines
rust/kernel/block/mq/gen_disk.rs new file +6 -0
+    /// Set the physical block size of the device.
+    ///
+    /// This is the smallest unit a physical storage device can write
+    /// atomically. It is usually the same as the logical block size but may be
+    /// bigger. One example is SATA drives with 4KB sectors that expose a
+    /// 512-byte logical block size to the operating system.
Quoted 18 lines
Quoted 2 lines

Please be consistent and change "4 KB sectors" into "4 KB physical block size".

OK, I will. I can CC the changes to
Documentation/ABI/stable/sysfs-block then'

Quoted 12 lines

I think that the physical block size can also be smaller than the logical block size. From the SCSI SBC standard:

Table 91 — LOGICAL BLOCKS PER PHYSICAL BLOCK EXPONENT field

-----  ------------------------------------------------------------
Code   Description
-----  ------------------------------------------------------------
0      One or more physical blocks per logical block (the number of

physical blocks per logical block is not reported).
n > 0 2**n logical blocks per physical block
----- ------------------------------------------------------------

That text is bad. 0 really means physical == logical. Otherwise, there is no way to know how to access the drive because the logical size is the unit for accessing the drive. In practice, the logical block size is always smaller or equal to the physical block size. The physical block size is always a power of 2 number of logical blocks.

Quoted 1 line

How does that work? Would the drive do a read/modify/write internally?

Yes.

Quoted 2 lines

Would that not make the physical block size as seen from the OS equal to the smaller logical block size?

Not necessarily. There are a lot of 512e drives out there: 4K physical, 512B logical. So applications/hosts can still do 512B accesses for compatibility but performance may be bad. For such drive, the user should really do 4K aligned accesses.

Quoted 16 lines
Quoted 10 lines

rust/kernel/block/mq/gen_disk.rs line 115

Quoted 4 lines
rust/kernel/block/mq/gen_disk.rs new file +2 -0
+impl<T: Operations, S: GenDiskState> GenDisk<T, S> {
+    /// Call to tell the block layer the capacity of the device in sectors (512B).

Why to use any other unit than bytes in Rust block::mq APIs? sector_t was introduced before 64-bit CPUs became available to reduce the number of bytes required to represent offsets. I don't think that this is still a concern today. Hence my proposal to be consistent in the Rust block::mq API and to use bytes as the unit in all APIs.

I think that is very good idea. How do others feel about this?

BR Andreas

Signature · 2 lines
Damien Le Moal
Western Digital Research
#6 lore raw

Re: [PATCH 1/3] rust: block: introduce `kernel::block::mq` module

In reply to Andreas Hindborg
kernel test robot noticed the following build warnings:

Hi Andreas,

kernel test robot noticed the following build warnings:

[auto build test WARNING on fec50db7033ea478773b159e0e2efb135270e3b7]

url:    https://github.com/intel-lab-lkp/linux/commits/Andreas-Hindborg/rust-block-introduce-kernel-block-mq-module/20240513-024107
base:   fec50db7033ea478773b159e0e2efb135270e3b7
patch link:    https://lore.kernel.org/r/20240512183950.1982353-2-nmi%40metaspace.dk
patch subject: [PATCH 1/3] rust: block: introduce `kernel::block::mq` module
config: x86_64-buildonly-randconfig-004-20240514 (https://download.01.org/0day-ci/archive/20240514/[email protected]/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240514/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> warning: method `to_blk_status` is never used

--> rust/kernel/error.rs:133:19
|
97 | impl Error {
| ---------- method in this implementation
...
133 | pub(crate) fn to_blk_status(self) -> bindings::blk_status_t {
| ^^^^^^^^^^^^^
|
= note: #[warn(dead_code)] on by default

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#7 lore raw

PATCH 2/3 rust: block: add rnull, Rust null_blk implementation

In reply to Andreas Hindborg

From: Andreas Hindborg <[email protected]>

This patch adds an initial version of the Rust null block driver.

---
 drivers/block/Kconfig  |  9 +++++
 drivers/block/Makefile |  3 ++
 drivers/block/rnull.rs | 82 ++++++++++++++++++++++++++++++++++++++++++
 scripts/Makefile.build |  2 +-
 4 files changed, 95 insertions(+), 1 deletion(-)
 create mode 100644 drivers/block/rnull.rs
drivers/block/Kconfig +9 -0
index 5b9d4aaebb81..ed209f4f2798 100644
@@ -354,6 +354,15 @@ config VIRTIO_BLK
 	  This is the virtual block driver for virtio.  It can be used with
           QEMU based VMMs (like KVM or Xen).  Say Y or M.
 
+config BLK_DEV_RUST_NULL
+	tristate "Rust null block driver (Experimental)"
+	depends on RUST
+	help
+	  This is the Rust implementation of the null block driver. For now it
+	  is only a minimal stub.
+
+	  If unsure, say N.
+
 config BLK_DEV_RBD
 	tristate "Rados block device (RBD)"
 	depends on INET && BLOCK
drivers/block/Makefile +3 -0
index 101612cba303..1105a2d4fdcb 100644
@@ -9,6 +9,9 @@
 # needed for trace events
 ccflags-y				+= -I$(src)
 
+obj-$(CONFIG_BLK_DEV_RUST_NULL) += rnull_mod.o
+rnull_mod-y := rnull.o
+
 obj-$(CONFIG_MAC_FLOPPY)	+= swim3.o
 obj-$(CONFIG_BLK_DEV_SWIM)	+= swim_mod.o
 obj-$(CONFIG_BLK_DEV_FD)	+= floppy.o
drivers/block/rnull.rs new file +82 -0

82 lines not on this page · raw message

scripts/Makefile.build +1 -1
index baf86c0880b6..603dee4b66c4 100644
@@ -263,7 +263,7 @@ $(obj)/%.lst: $(src)/%.c FORCE
 # Compile Rust sources (.rs)
 # ---------------------------------------------------------------------------
 
-rust_allowed_features := new_uninit,offset_of
+rust_allowed_features := new_uninit,offset_of,allocator_api
 
 # `--out-dir` is required to avoid temporaries being created by `rustc` in the
 # current working directory, which may be not accessible in the out-of-tree
Signature · 1 line
2.44.0
#8 lore raw

PATCH 3/3 MAINTAINERS: add entry for Rust block device driver API

In reply to Andreas Hindborg

From: Andreas Hindborg <[email protected]>

Add an entry for the Rust block device driver abstractions.

---
 MAINTAINERS | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
MAINTAINERS +14 -0
index aea47e04c3a5..eec752f09d43 100644
@@ -3657,6 +3657,20 @@ F:	include/linux/blk*
 F:	kernel/trace/blktrace.c
 F:	lib/sbitmap.c
 
+BLOCK LAYER DEVICE DRIVER API [RUST]
+M:	Andreas Hindborg <[email protected]>
+R:	Boqun Feng <[email protected]>
+L:	[email protected]
+L:	[email protected]
+S:	Supported
+W:	https://rust-for-linux.com
+B:	https://github.com/Rust-for-Linux/linux/issues
+C:	https://rust-for-linux.zulipchat.com/#narrow/stream/Block
+T:	git https://github.com/Rust-for-Linux/linux.git rust-block-next
+F:	drivers/block/rnull.rs
+F:	rust/kernel/block.rs
+F:	rust/kernel/block/
+
 BLOCK2MTD DRIVER
 M:	Joern Engel <[email protected]>
 L:	[email protected]
Signature · 1 line
2.44.0
maintainer
#9 lore raw
In reply to Andreas Hindborg
Quoted 16 lines · Andreas Hindborg

From: Andreas Hindborg <[email protected]>

Hi All!

I am happy to finally send the first _non_ RFC patches for the Rust block device API.

This series provides an initial Rust block layer device driver API, and a very minimal null block driver to exercise the API. The driver has only one mode of operation and cannot be configured.

These patches are an updated and trimmed down version of the v2 RFC [1]. One of the requests for the v2 RFC was to split the abstractions into smaller pieces that are easier to review. This is the first part of the split patches.

Quoted 8 lines

A notable change in this patch set is that they no longer use the ref field of the C struct request to manage lifetime of the request structure.

The removed features will be sent later, as their dependencies land upstream.

As mentioned before, I will gladly maintain this code if required.

With the following stipulations (and the kernel test bot issues sorted), I think we should give this a go. We already covered this today at LSFMM, but for the sake of others, here's how I see the rust support for the block side of things:

I see rust support for the block layer as a two stage kind of thing. Stage 1 would be including this patchset. In stage 1, all fallout from block layer changes fall upon Andreas and group to fix. Under no circumstance will changes from other contributors be held up, or contributors be held accountable, for breakages of the block rust code. Should contributors wish to sort out these issues themselves, then they are of course free to do so, but it won't be something that gatekeeps other changes.

This leaves existing contributors free to go about their usual business. Kernels that don't enable rust (which won't happen unless you're setup for it anyway) won't even see build breakages. We will see some noise from the kernel test bot on the list, which does worry me a little bit. Not because it'll mark the rust side as being broken, but because it'll cause more noise which may make us miss breakages that are ultimately more important. I don't think this is a big risk, just highlighting that it is indeed a risk and will cause some potential annoyances.

In stage 1, block rust is just there to enable people to experiment and play with it, and continue to develop it. Right now Andreas has a very (VERY) basic null_blk driver, I think we should move towards a fully fledged implementation of that so we at least have _something_ to test. We really need to full API to be used and exposed, this is generic kernel requirement - we just don't merge code that has no users, ever. Since a more complete rust null blk driver does exist out of tree, perhaps we can get something more complete for v2 of this patchset? I would highly recommend that.

We may never exit stage 1, and I think during this particular stage, if things don't work out for whatever reason, the code can be removed again. As we have no critical drivers being rust exclusive at that point, it won't cause any issues yanking the code again. Moving into a stage 2 for block rust would mean that the rest of the kernel has fully adopted rust anyway, and being able (and willing) to write rust is just another part of the developer arsenal.

I'd love to see the rust code moved to eg block/rust/, as I would greatly prefer to have it closer to the actual block code rather than sitting off in rust/kernel/block instead. I see this as a similar problem to having documentation away fro the actual code, it inevitably causes a drift between them. I understand from Andreas that this is actually something that is being worked on, and we can probably expect to see that in a cycle or two.

tldr - as long as this doesn't encumer existing contributors, then I see absolutely no reason not to enable a rust playground for block drivers.

Signature · 1 line
Jens Axboe