rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] docs: rust: extend abstraction and binding documentation
@ 2024-02-06  6:54 Dirk Behme
  2024-02-06  8:28 ` Valentin Obst
  2024-02-06 19:35 ` Miguel Ojeda
  0 siblings, 2 replies; 5+ messages in thread
From: Dirk Behme @ 2024-02-06  6:54 UTC (permalink / raw)
  To: rust-for-linux; +Cc: Dirk Behme, Miguel Ojeda

Add some basics explained by Miguel in [1] to the documentation.
And connect it with some hints where this is implemented in the
kernel.

[1] https://www.linuxfoundation.org/webinars/rust-for-linux-writing-abstractions-and-drivers

CC: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
---
 Documentation/rust/general-information.rst | 56 ++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/Documentation/rust/general-information.rst b/Documentation/rust/general-information.rst
index 081397827a7ea..616e2f2c09220 100644
--- a/Documentation/rust/general-information.rst
+++ b/Documentation/rust/general-information.rst
@@ -64,6 +64,62 @@ but it is intended that coverage is expanded as time goes on. "Leaf" modules
 (e.g. drivers) should not use the C bindings directly. Instead, subsystems
 should provide as-safe-as-possible abstractions as needed.
 
+.. code-block::
+
+	                                                rust/bindings/
+                                                       (rust/helpers.c)
+
+                                                          include/ -----+ <-+
+                                                                        |   |
+         drivers/              rust/kernel/              +----------+ <-+   |
+           fs/                                           | bindgen  |       |
+          .../            +-------------------+          +----------+ --+   |
+                          |    Abstractions   |                         |   |
+       +---------+        | +------+ +------+ |          +----------+   |   |
+       | my_foo  | -----> | | foo  | | bar  | | -------> | Bindings | <-+   |
+       | driver  |  Safe  | | sub- | | sub- | |  Unsafe  |          |       |
+       +---------+        | |system| |system| |          | bindings | <-----+
+            |             | +------+ +------+ |          |  crate   |       |
+            |             |   kernel crate    |          +----------+       |
+            |             +-------------------+                             |
+            |                                                               |
+            +------------------# FORBIDDEN #--------------------------------+
+
+The main idea is to encapsulate all ``unsafe()`` handling in the abstractions reviewed
+and documented carefully. These are considered to be sound then. With this model
+it is assumed that users of the abstractions ("my_foo driver") can't do anything
+unsound if
+
+#. the abstractions are sound
+#. they don't use ``unsafe()``
+
+Bindings
+~~~~~~~~
+
+By including a C header from ``include/`` into ``rust/bindings/bindings_helper.h``
+the ``bindgen`` tool will auto-generate the bindings for the included subsystem.
+See the ``*_generated.rs`` output files in the ``rust/bindings/`` directory.
+
+For parts of the C header ``bindgen`` doesn't auto generate, e.g. C ``inline``
+functions, there is the option to add a small wrapper function to ``rust/helpers.c``
+to make it available for the Rust side as well.
+
+Abstractions
+~~~~~~~~~~~~
+
+Abstractions are the glue layer between the bindings and the in-kernel users. E.g.
+the drivers or file systems written in Rust. They are located in ``rust/kernel/``
+and are supposed to make the ``unsafe()`` access to the bindings as-safe-as-possible
+for their users.
+
+Tutorial
+~~~~~~~~
+
+The webinar `Rust For Linux: Writing Safe Abstractions & Drivers`
+
+	https://www.linuxfoundation.org/webinars/rust-for-linux-writing-abstractions-and-drivers
+
+has an introduction to this topic.
 
 Conditional compilation
 -----------------------
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-02-08 10:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-06  6:54 [PATCH] docs: rust: extend abstraction and binding documentation Dirk Behme
2024-02-06  8:28 ` Valentin Obst
2024-02-06 19:35 ` Miguel Ojeda
2024-02-07  5:32   ` Behme Dirk (CM/ESO2)
2024-02-08 10:36     ` Benno Lossin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).