Skip to contentSkip to conversation

linux-next: manual merge of the rust tree with the driver-core tree

DISCUSSION Stephen Rothwell 2 participants 3 messages Jan 14, 2025 – Jan 23, 2025 Linux-next tree

lore
Share & tools
lore
#0 lore raw

Hi all,

Today's linux-next merge of the rust tree got a conflict in:

rust/kernel/miscdevice.rs

between commit:

88441d5c6d17 ("rust: miscdevice: access the struct miscdevice from fops->open()")

from the driver-core tree and commit:

14686571a914 ("rust: kernel: change ForeignOwnable pointer to mut")

from the rust tree.

I fixed it up (see below) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts.

Signature · 86 lines
Cheers,
Stephen Rothwell

diff --cc rust/kernel/miscdevice.rs
index dfb363630c70,b3a6cc50b240..000000000000
--- a/rust/kernel/miscdevice.rs
+++ b/rust/kernel/miscdevice.rs
@@@ -10,11 -10,9 +10,12 @@@
  
  use crate::{
      bindings,
 +    device::Device,
      error::{to_result, Error, Result, VTABLE_DEFAULT_ERROR},
+     ffi::{c_int, c_long, c_uint, c_ulong},
 +    fs::File,
      prelude::*,
 +    seq_file::SeqFile,
      str::CStr,
      types::{ForeignOwnable, Opaque},
  };
@@@ -151,17 -132,8 +147,17 @@@ pub trait MiscDevice: Sized 
          _cmd: u32,
          _arg: usize,
      ) -> Result<isize> {
-         kernel::build_error!(VTABLE_DEFAULT_ERROR)
+         build_error!(VTABLE_DEFAULT_ERROR)
      }
 +
 +    /// Show info for this fd.
 +    fn show_fdinfo(
 +        _device: <Self::Ptr as ForeignOwnable>::Borrowed<'_>,
 +        _m: &SeqFile,
 +        _file: &File,
 +    ) {
-         kernel::build_error!(VTABLE_DEFAULT_ERROR)
++        build_error!(VTABLE_DEFAULT_ERROR)
 +    }
  }
  
  const fn create_vtable<T: MiscDevice>() -> &'static bindings::file_operations {
@@@ -230,12 -188,8 +226,12 @@@ unsafe extern "C" fn fops_open<T: MiscD
          Err(err) => return err.to_errno(),
      };
  
 -    // SAFETY: The open call of a file owns the private data.
 -    unsafe { (*file).private_data = ptr.into_foreign() };
 +    // This overwrites the private data with the value specified by the user, changing the type of
 +    // this file's private data. All future accesses to the private data is performed by other
 +    // fops_* methods in this file, which all correctly cast the private data to the new type.
 +    //
 +    // SAFETY: The open call of a file can access the private data.
-     unsafe { (*raw_file).private_data = ptr.into_foreign().cast_mut() };
++    unsafe { (*raw_file).private_data = ptr.into_foreign() };
  
      0
  }
@@@ -274,12 -225,7 +270,12 @@@ unsafe extern "C" fn fops_ioctl<T: Misc
      // SAFETY: Ioctl calls can borrow the private data of the file.
      let device = unsafe { <T::Ptr as ForeignOwnable>::borrow(private) };
  
 -    match T::ioctl(device, cmd, arg) {
 +    // SAFETY:
 +    // * The file is valid for the duration of this call.
 +    // * There is no active fdget_pos region on the file on this thread.
 +    let file = unsafe { File::from_raw_file(file) };
 +
-     match T::ioctl(device, file, cmd, arg as usize) {
++    match T::ioctl(device, file, cmd, arg) {
          Ok(ret) => ret as c_long,
          Err(err) => err.to_errno() as c_long,
      }
@@@ -299,12 -245,7 +295,12 @@@ unsafe extern "C" fn fops_compat_ioctl<
      // SAFETY: Ioctl calls can borrow the private data of the file.
      let device = unsafe { <T::Ptr as ForeignOwnable>::borrow(private) };
  
 -    match T::compat_ioctl(device, cmd, arg) {
 +    // SAFETY:
 +    // * The file is valid for the duration of this call.
 +    // * There is no active fdget_pos region on the file on this thread.
 +    let file = unsafe { File::from_raw_file(file) };
 +
-     match T::compat_ioctl(device, file, cmd, arg as usize) {
++    match T::compat_ioctl(device, file, cmd, arg) {
          Ok(ret) => ret as c_long,
          Err(err) => err.to_errno() as c_long,
      }
#1 lore raw
Quoted 9 lines · Stephen Rothwell

Today's linux-next merge of the rust tree got a conflict in:

rust/kernel/miscdevice.rs

between commit:

88441d5c6d17 ("rust: miscdevice: access the struct miscdevice from fops->open()")

Quoted 7 lines

from the driver-core tree and commit:

14686571a914 ("rust: kernel: change ForeignOwnable pointer to mut")

from the rust tree.

I fixed it up (see below) and can carry the fix as necessary. This

Looks good to me as well, thanks!

Cheers,
Miguel

#2 lore raw
In reply to Stephen Rothwell

Hi all,

Quoted 95 lines · On Tue, 14 Jan 2025 15:46:23 +1100 Stephen Rothwell <[email protected]>…

Today's linux-next merge of the rust tree got a conflict in:

rust/kernel/miscdevice.rs

between commit:

88441d5c6d17 ("rust: miscdevice: access the struct miscdevice from fops->open()")

from the driver-core tree and commit:

14686571a914 ("rust: kernel: change ForeignOwnable pointer to mut")

from the rust tree.

I fixed it up (see below) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts.

rust/kernel/miscdevice.rs +5 -4
diff --cc rust/kernel/miscdevice.rs
index dfb363630c70,b3a6cc50b240..000000000000
@@@ -10,11 -10,9 +10,12 @@@
 
  use crate::{
      bindings,
 +    device::Device,
      error::{to_result, Error, Result, VTABLE_DEFAULT_ERROR},
+     ffi::{c_int, c_long, c_uint, c_ulong},
 +    fs::File,
      prelude::*,
 +    seq_file::SeqFile,
      str::CStr,
      types::{ForeignOwnable, Opaque},
  };
@@@ -151,17 -132,8 +147,17 @@@ pub trait MiscDevice: Sized 
          _cmd: u32,
          _arg: usize,
      ) -> Result<isize> {
-         kernel::build_error!(VTABLE_DEFAULT_ERROR)
+         build_error!(VTABLE_DEFAULT_ERROR)
      }
 +
 +    /// Show info for this fd.
 +    fn show_fdinfo(
 +        _device: <Self::Ptr as ForeignOwnable>::Borrowed<'_>,
 +        _m: &SeqFile,
 +        _file: &File,
 +    ) {
-         kernel::build_error!(VTABLE_DEFAULT_ERROR)
++        build_error!(VTABLE_DEFAULT_ERROR)
 +    }
  }
 
  const fn create_vtable<T: MiscDevice>() -> &'static bindings::file_operations {
@@@ -230,12 -188,8 +226,12 @@@ unsafe extern "C" fn fops_open<T: MiscD
          Err(err) => return err.to_errno(),
      };
 
 -    // SAFETY: The open call of a file owns the private data.
 -    unsafe { (*file).private_data = ptr.into_foreign() };
 +    // This overwrites the private data with the value specified by the user, changing the type of
 +    // this file's private data. All future accesses to the private data is performed by other
 +    // fops_* methods in this file, which all correctly cast the private data to the new type.
 +    //
 +    // SAFETY: The open call of a file can access the private data.
-     unsafe { (*raw_file).private_data = ptr.into_foreign().cast_mut() };
++    unsafe { (*raw_file).private_data = ptr.into_foreign() };
 
      0
  }
@@@ -274,12 -225,7 +270,12 @@@ unsafe extern "C" fn fops_ioctl<T: Misc
      // SAFETY: Ioctl calls can borrow the private data of the file.
      let device = unsafe { <T::Ptr as ForeignOwnable>::borrow(private) };
 
 -    match T::ioctl(device, cmd, arg) {
 +    // SAFETY:
 +    // * The file is valid for the duration of this call.
 +    // * There is no active fdget_pos region on the file on this thread.
 +    let file = unsafe { File::from_raw_file(file) };
 +
-     match T::ioctl(device, file, cmd, arg as usize) {
++    match T::ioctl(device, file, cmd, arg) {
          Ok(ret) => ret as c_long,
          Err(err) => err.to_errno() as c_long,
      }
@@@ -299,12 -245,7 +295,12 @@@ unsafe extern "C" fn fops_compat_ioctl<
      // SAFETY: Ioctl calls can borrow the private data of the file.
      let device = unsafe { <T::Ptr as ForeignOwnable>::borrow(private) };
 
 -    match T::compat_ioctl(device, cmd, arg) {

rust/kernel/miscdevice.rs

Quoted 10 lines
rust/kernel/miscdevice.rs +1 -1
 +    // SAFETY:
 +    // * The file is valid for the duration of this call.
 +    // * There is no active fdget_pos region on the file on this thread.
 +    let file = unsafe { File::from_raw_file(file) };
 +
-     match T::compat_ioctl(device, file, cmd, arg as usize) {
++    match T::compat_ioctl(device, file, cmd, arg) {
          Ok(ret) => ret as c_long,
          Err(err) => err.to_errno() as c_long,
      }

This is now a conflict between the driver-core tree and Linus' tree.

Signature · 2 lines
Cheers,
Stephen Rothwell