lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230625121657.3631109-4-changxian.cqs@antgroup.com>
Date:   Sun, 25 Jun 2023 20:16:52 +0800
From:   "Qingsong Chen" <changxian.cqs@...group.com>
To:     linux-kernel@...r.kernel.org
Cc:     "田洪亮" <tate.thl@...group.com>,
        "Qingsong Chen" <changxian.cqs@...group.com>,
        "Miguel Ojeda" <ojeda@...nel.org>,
        "Alex Gaynor" <alex.gaynor@...il.com>,
        "Wedson Almeida Filho" <wedsonaf@...il.com>,
        "Boqun Feng" <boqun.feng@...il.com>, "Gary Guo" <gary@...yguo.net>,
        "Björn Roy Baron" <bjorn3_gh@...tonmail.com>,
        "Benno Lossin" <benno.lossin@...ton.me>,
        <rust-for-linux@...r.kernel.org>
Subject: [RFC PATCH 3/8] rust: kernel: add some hook TargetOperations

- Add hooks when suspend or resume a target.
- Add operation to check if a target is busy.

Signed-off-by: Qingsong Chen <changxian.cqs@...group.com>
---
 rust/kernel/device_mapper.rs | 76 ++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)

diff --git a/rust/kernel/device_mapper.rs b/rust/kernel/device_mapper.rs
index 153bae3aad79..aeda12245171 100644
--- a/rust/kernel/device_mapper.rs
+++ b/rust/kernel/device_mapper.rs
@@ -64,6 +64,42 @@ fn rq_end_io(
     ) -> EndState {
         unimplemented!()
     }
+
+    /// Hook presuspend.
+    #[allow(unused)]
+    fn presuspend(t: &mut Target<Self>) {
+        unimplemented!()
+    }
+
+    /// Hook presuspend_undo.
+    #[allow(unused)]
+    fn presuspend_undo(t: &mut Target<Self>) {
+        unimplemented!()
+    }
+
+    /// Hook postsuspend.
+    #[allow(unused)]
+    fn postsuspend(t: &mut Target<Self>) {
+        unimplemented!()
+    }
+
+    /// Hook preresume.
+    #[allow(unused)]
+    fn preresume(t: &mut Target<Self>) -> Result {
+        unimplemented!()
+    }
+
+    /// Hook resume.
+    #[allow(unused)]
+    fn resume(t: &mut Target<Self>) {
+        unimplemented!()
+    }
+
+    /// Check if target is busy.
+    #[allow(unused)]
+    fn busy(t: &mut Target<Self>) -> bool {
+        unimplemented!()
+    }
 }
 
 /// Wrap the kernel struct `target_type`.
@@ -130,6 +166,12 @@ pub fn register<T: TargetOperations>(
                     ),
                     (HAS_END_IO, end_io, dm_endio_fn),
                     (HAS_RQ_END_IO, rq_end_io, dm_request_endio_fn),
+                    (HAS_PRESUSPEND, presuspend, dm_presuspend_fn),
+                    (HAS_PRESUSPEND_UNDO, presuspend_undo, dm_presuspend_undo_fn),
+                    (HAS_POSTSUSPEND, postsuspend, dm_postsuspend_fn),
+                    (HAS_PRERESUME, preresume, dm_preresume_fn),
+                    (HAS_RESUME, resume, dm_resume_fn),
+                    (HAS_BUSY, busy, dm_busy_fn),
                 );
 
                 to_result(bindings::dm_register_target(tt))
@@ -251,6 +293,40 @@ impl TargetType {
             T::rq_end_io(t, rq, map_ctx, (error as u32).into()) as _
         }
     }
+    unsafe extern "C" fn dm_presuspend_fn<T: TargetOperations>(ti: *mut bindings::dm_target) {
+        // SAFETY: the kernel should pass valid `dm_target` pointer.
+        let t = unsafe { Target::borrow_mut(ti) };
+        T::presuspend(t);
+    }
+    unsafe extern "C" fn dm_presuspend_undo_fn<T: TargetOperations>(ti: *mut bindings::dm_target) {
+        // SAFETY: the kernel should pass valid `dm_target` pointer.
+        let t = unsafe { Target::borrow_mut(ti) };
+        T::presuspend_undo(t);
+    }
+    unsafe extern "C" fn dm_postsuspend_fn<T: TargetOperations>(ti: *mut bindings::dm_target) {
+        // SAFETY: the kernel should pass valid `dm_target` pointer.
+        let t = unsafe { Target::borrow_mut(ti) };
+        T::postsuspend(t);
+    }
+    unsafe extern "C" fn dm_preresume_fn<T: TargetOperations>(
+        ti: *mut bindings::dm_target,
+    ) -> core::ffi::c_int {
+        // SAFETY: the kernel should pass valid `dm_target` pointer.
+        let t = unsafe { Target::borrow_mut(ti) };
+        T::preresume(t).map_or_else(|e| e.to_errno(), |_| 0)
+    }
+    unsafe extern "C" fn dm_resume_fn<T: TargetOperations>(ti: *mut bindings::dm_target) {
+        // SAFETY: the kernel should pass valid `dm_target` pointer.
+        let t = unsafe { Target::borrow_mut(ti) };
+        T::resume(t);
+    }
+    unsafe extern "C" fn dm_busy_fn<T: TargetOperations>(
+        ti: *mut bindings::dm_target,
+    ) -> core::ffi::c_int {
+        // SAFETY: the kernel should pass valid `dm_target` pointer.
+        let t = unsafe { Target::borrow_mut(ti) };
+        T::busy(t) as _
+    }
 }
 
 /// Wrap the kernel struct `dm_target`.
-- 
2.40.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ