Skip to contentSkip to conversation

linux-next: build failure after merge of the rust tree

PATCH In review Stephen Rothwell 4 participants 12 messages Jan 10, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi all,

After merging the rust tree, today's linux-next build (x86_64 allmodconfig) failed like this:

error[E0423]: expected function, found macro kernel::build_error
--> rust/kernel/miscdevice.rs:159:9

    |
159 |         kernel::build_error(VTABLE_DEFAULT_ERROR)
    |         ^^^^^^^^^^^^^^^^^^^ not a function
    |
help: use `!` to invoke the macro
    |
159 |         kernel::build_error!(VTABLE_DEFAULT_ERROR)
    |                            +
help: consider importing one of these functions instead
    |
11  + use crate::build_assert::build_error;
    |
11  + use build_error::build_error;
    |
help: if you import `build_error`, refer to it directly
    |
159 -         kernel::build_error(VTABLE_DEFAULT_ERROR)
159 +         build_error(VTABLE_DEFAULT_ERROR)
    |

error: aborting due to 1 previous error

For more information about this error, try rustc --explain E0423.

Caused by commit

614724e780f5 ("rust: kernel: move build_error hidden function to prevent mistakes")

interacting with commit

5bcc8bfe841b ("rust: miscdevice: add fops->show_fdinfo() hook")

from the driver-core tree.

I have added the following merge resolution patch.

From: Stephen Rothwell <[email protected]>
Date: Fri, 10 Jan 2025 16:02:19 +1100
Subject: [PATCH] fix up for "rust: kernel: move build_error hidden function
to prevent mistakes"

interacting with commit

5bcc8bfe841b ("rust: miscdevice: add fops->show_fdinfo() hook")

from the driver-core tree.

---
 rust/kernel/miscdevice.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/miscdevice.rs +1 -1
index 9685e50b100d..3ba018651bc0 100644
@@ -156,7 +156,7 @@ fn show_fdinfo(
         _m: &SeqFile,
         _file: &File,
     ) {
-        kernel::build_error(VTABLE_DEFAULT_ERROR)
+        build_error!(VTABLE_DEFAULT_ERROR)
     }
 }
 
Signature · 5 lines
2.45.2

-- 
Cheers,
Stephen Rothwell
reviewer
#1 lore raw
Quoted 65 lines · Stephen Rothwell

Hi all,

After merging the rust tree, today's linux-next build (x86_64 allmodconfig) failed like this:

error[E0423]: expected function, found macro kernel::build_error
--> rust/kernel/miscdevice.rs:159:9

    |
159 |         kernel::build_error(VTABLE_DEFAULT_ERROR)
    |         ^^^^^^^^^^^^^^^^^^^ not a function
    |
help: use `!` to invoke the macro
    |
159 |         kernel::build_error!(VTABLE_DEFAULT_ERROR)
    |                            +
help: consider importing one of these functions instead
    |
11  + use crate::build_assert::build_error;
    |
11  + use build_error::build_error;
    |
help: if you import `build_error`, refer to it directly
    |
159 -         kernel::build_error(VTABLE_DEFAULT_ERROR)
159 +         build_error(VTABLE_DEFAULT_ERROR)
    |

error: aborting due to 1 previous error

For more information about this error, try rustc --explain E0423.

Caused by commit

614724e780f5 ("rust: kernel: move build_error hidden function to prevent mistakes")

interacting with commit

5bcc8bfe841b ("rust: miscdevice: add fops->show_fdinfo() hook")

from the driver-core tree.

I have added the following merge resolution patch.

From: Stephen Rothwell <[email protected]>
Date: Fri, 10 Jan 2025 16:02:19 +1100
Subject: [PATCH] fix up for "rust: kernel: move build_error hidden function
to prevent mistakes"

interacting with commit

5bcc8bfe841b ("rust: miscdevice: add fops->show_fdinfo() hook")

from the driver-core tree.

---
 rust/kernel/miscdevice.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/miscdevice.rs +0 -0
index 9685e50b100d..3ba018651bc0 100644

rust/kernel/miscdevice.rs fn show_fdinfo( · line 161

Quoted 7 lines
rust/kernel/miscdevice.rs +1 -1
@@ -156,7 +156,7 @@ fn show_fdinfo(
         _m: &SeqFile,
         _file: &File,
     ) {
-        kernel::build_error(VTABLE_DEFAULT_ERROR)
+        build_error!(VTABLE_DEFAULT_ERROR)
     }
 }

Thank you, this fix is correct. Greg, can you pick this up directly, or do you want a real patch?

Alice

#2 lore raw
Quoted 61 lines · Alice Ryhl
Quoted 60 lines · Stephen Rothwell

Hi all,

After merging the rust tree, today's linux-next build (x86_64 allmodconfig) failed like this:

error[E0423]: expected function, found macro kernel::build_error
--> rust/kernel/miscdevice.rs:159:9

    |
159 |         kernel::build_error(VTABLE_DEFAULT_ERROR)
    |         ^^^^^^^^^^^^^^^^^^^ not a function
    |
help: use `!` to invoke the macro
    |
159 |         kernel::build_error!(VTABLE_DEFAULT_ERROR)
    |                            +
help: consider importing one of these functions instead
    |
11  + use crate::build_assert::build_error;
    |
11  + use build_error::build_error;
    |
help: if you import `build_error`, refer to it directly
    |
159 -         kernel::build_error(VTABLE_DEFAULT_ERROR)
159 +         build_error(VTABLE_DEFAULT_ERROR)
    |

error: aborting due to 1 previous error

For more information about this error, try rustc --explain E0423.

Caused by commit

614724e780f5 ("rust: kernel: move build_error hidden function to prevent mistakes")

interacting with commit

5bcc8bfe841b ("rust: miscdevice: add fops->show_fdinfo() hook")

from the driver-core tree.

I have added the following merge resolution patch.

From: Stephen Rothwell <[email protected]>
Date: Fri, 10 Jan 2025 16:02:19 +1100
Subject: [PATCH] fix up for "rust: kernel: move build_error hidden function
to prevent mistakes"

interacting with commit

5bcc8bfe841b ("rust: miscdevice: add fops->show_fdinfo() hook")

from the driver-core tree.

---
 rust/kernel/miscdevice.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

rust/kernel/miscdevice.rs fn show_fdinfo( · line 161

Quoted 12 lines
rust/kernel/miscdevice.rs +1 -1
index 9685e50b100d..3ba018651bc0 100644
@@ -156,7 +156,7 @@ fn show_fdinfo(
         _m: &SeqFile,
         _file: &File,
     ) {
-        kernel::build_error(VTABLE_DEFAULT_ERROR)
+        build_error!(VTABLE_DEFAULT_ERROR)
     }
 }

Thank you, this fix is correct. Greg, can you pick this up directly, or do you want a real patch?

Can I take this as a real patch for my tree? Or is this only an issue due to the trees being merged?

thanks,

greg k-h

reviewer
#3 lore raw
Quoted 79 lines · Greg Kroah-Hartman
Quoted 61 lines · Alice Ryhl
Quoted 60 lines · Stephen Rothwell

Hi all,

After merging the rust tree, today's linux-next build (x86_64 allmodconfig) failed like this:

error[E0423]: expected function, found macro kernel::build_error
--> rust/kernel/miscdevice.rs:159:9

    |
159 |         kernel::build_error(VTABLE_DEFAULT_ERROR)
    |         ^^^^^^^^^^^^^^^^^^^ not a function
    |
help: use `!` to invoke the macro
    |
159 |         kernel::build_error!(VTABLE_DEFAULT_ERROR)
    |                            +
help: consider importing one of these functions instead
    |
11  + use crate::build_assert::build_error;
    |
11  + use build_error::build_error;
    |
help: if you import `build_error`, refer to it directly
    |
159 -         kernel::build_error(VTABLE_DEFAULT_ERROR)
159 +         build_error(VTABLE_DEFAULT_ERROR)
    |

error: aborting due to 1 previous error

For more information about this error, try rustc --explain E0423.

Caused by commit

614724e780f5 ("rust: kernel: move build_error hidden function to prevent mistakes")

interacting with commit

5bcc8bfe841b ("rust: miscdevice: add fops->show_fdinfo() hook")

from the driver-core tree.

I have added the following merge resolution patch.

From: Stephen Rothwell <[email protected]>
Date: Fri, 10 Jan 2025 16:02:19 +1100
Subject: [PATCH] fix up for "rust: kernel: move build_error hidden function
to prevent mistakes"

interacting with commit

5bcc8bfe841b ("rust: miscdevice: add fops->show_fdinfo() hook")

from the driver-core tree.

---
 rust/kernel/miscdevice.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

rust/kernel/miscdevice.rs fn show_fdinfo( · line 161

Quoted 12 lines
rust/kernel/miscdevice.rs +1 -1
index 9685e50b100d..3ba018651bc0 100644
@@ -156,7 +156,7 @@ fn show_fdinfo(
         _m: &SeqFile,
         _file: &File,
     ) {
-        kernel::build_error(VTABLE_DEFAULT_ERROR)
+        build_error!(VTABLE_DEFAULT_ERROR)
     }
 }

Thank you, this fix is correct. Greg, can you pick this up directly, or do you want a real patch?

Quoted 2 lines

Can I take this as a real patch for my tree? Or is this only an issue due to the trees being merged?

You can take it as a real patch. That will make your tree compile both with and without rust-next merged.

Though I guess it would be nice to update all three instances of build_error! if we make a real patch. (The other two instances are updated in rust-next, so they don't cause the failure.)

Alice

reviewer
#4 lore raw
Quoted 85 lines · Alice Ryhl
Quoted 79 lines · Greg Kroah-Hartman
Quoted 61 lines · Alice Ryhl
Quoted 60 lines · Stephen Rothwell

Hi all,

After merging the rust tree, today's linux-next build (x86_64 allmodconfig) failed like this:

error[E0423]: expected function, found macro kernel::build_error
--> rust/kernel/miscdevice.rs:159:9

    |
159 |         kernel::build_error(VTABLE_DEFAULT_ERROR)
    |         ^^^^^^^^^^^^^^^^^^^ not a function
    |
help: use `!` to invoke the macro
    |
159 |         kernel::build_error!(VTABLE_DEFAULT_ERROR)
    |                            +
help: consider importing one of these functions instead
    |
11  + use crate::build_assert::build_error;
    |
11  + use build_error::build_error;
    |
help: if you import `build_error`, refer to it directly
    |
159 -         kernel::build_error(VTABLE_DEFAULT_ERROR)
159 +         build_error(VTABLE_DEFAULT_ERROR)
    |

error: aborting due to 1 previous error

For more information about this error, try rustc --explain E0423.

Caused by commit

614724e780f5 ("rust: kernel: move build_error hidden function to prevent mistakes")

interacting with commit

5bcc8bfe841b ("rust: miscdevice: add fops->show_fdinfo() hook")

from the driver-core tree.

I have added the following merge resolution patch.

From: Stephen Rothwell <[email protected]>
Date: Fri, 10 Jan 2025 16:02:19 +1100
Subject: [PATCH] fix up for "rust: kernel: move build_error hidden function
to prevent mistakes"

interacting with commit

5bcc8bfe841b ("rust: miscdevice: add fops->show_fdinfo() hook")

from the driver-core tree.

---
 rust/kernel/miscdevice.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines

rust/kernel/miscdevice.rs fn show_fdinfo( · line 161

Quoted 12 lines
rust/kernel/miscdevice.rs +1 -1
index 9685e50b100d..3ba018651bc0 100644
@@ -156,7 +156,7 @@ fn show_fdinfo(
         _m: &SeqFile,
         _file: &File,
     ) {
-        kernel::build_error(VTABLE_DEFAULT_ERROR)
+        build_error!(VTABLE_DEFAULT_ERROR)
     }
 }

Thank you, this fix is correct. Greg, can you pick this up directly, or do you want a real patch?

Quoted 2 lines

Can I take this as a real patch for my tree? Or is this only an issue due to the trees being merged?

Quoted 6 lines

You can take it as a real patch. That will make your tree compile both with and without rust-next merged.

Though I guess it would be nice to update all three instances of build_error! if we make a real patch. (The other two instances are updated in rust-next, so they don't cause the failure.)

Actually, it looks like I am mistaken. This patch doesn't build without
https://lore.kernel.org/all/[email protected]/

I'll send a real patch.

Alice

reviewer
#5 lore raw

PATCH 1/1 miscdevice: rust: use build_error! macro instead of function

The function called build_error is an implementation detail of the macro of the same name. Thus, update miscdevice to use the macro rather than the function. See [1] for more information on this.

This use the macro with the kernel:: prefix as it has not yet been added to the prelude.

---
 rust/kernel/miscdevice.rs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
rust/kernel/miscdevice.rs +3 -3
index ebc82e7dfc80..dfb363630c70 100644
@@ -134,7 +134,7 @@ fn ioctl(
         _cmd: u32,
         _arg: usize,
     ) -> Result<isize> {
-        kernel::build_error(VTABLE_DEFAULT_ERROR)
+        kernel::build_error!(VTABLE_DEFAULT_ERROR)
     }
 
     /// Handler for ioctls.
@@ -151,7 +151,7 @@ fn compat_ioctl(
         _cmd: u32,
         _arg: usize,
     ) -> Result<isize> {
-        kernel::build_error(VTABLE_DEFAULT_ERROR)
+        kernel::build_error!(VTABLE_DEFAULT_ERROR)
     }
 
     /// Show info for this fd.
@@ -160,7 +160,7 @@ fn show_fdinfo(
         _m: &SeqFile,
         _file: &File,
     ) {
-        kernel::build_error(VTABLE_DEFAULT_ERROR)
+        kernel::build_error!(VTABLE_DEFAULT_ERROR)
     }
 }
 

base-commit: 7687c66c18c66d4ccd9949c6f641c0e7b5773483

Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Acked-by on v1 1/1
#6 lore raw

Re: [PATCH] miscdevice: rust: use build_error! macro instead of function

Quoted 7 lines · Alice Ryhl

The function called build_error is an implementation detail of the macro of the same name. Thus, update miscdevice to use the macro rather than the function. See [1] for more information on this.

This use the macro with the kernel:: prefix as it has not yet been added to the prelude.

Typo: "These"

Thanks!

Cheers,
Miguel

maintainer
#7 lore raw

Re: [PATCH] miscdevice: rust: use build_error! macro instead of function

Quoted 6 lines · Miguel Ojeda
Quoted 5 lines · Alice Ryhl

The function called build_error is an implementation detail of the macro of the same name. Thus, update miscdevice to use the macro rather than the function. See [1] for more information on this.

Quoted 6 lines
Quoted 2 lines

This use the macro with the kernel:: prefix as it has not yet been added to the prelude.

Typo: "These"

And I'll add a Reported-by: line when I apply this in a few minutes, thanks!

greg k-h

reviewer
#8 lore raw

Re: [PATCH] miscdevice: rust: use build_error! macro instead of function

Quoted 11 lines · Greg KH
Quoted 9 lines · Miguel Ojeda
Quoted 7 lines · Alice Ryhl

The function called build_error is an implementation detail of the macro of the same name. Thus, update miscdevice to use the macro rather than the function. See [1] for more information on this.

This use the macro with the kernel:: prefix as it has not yet been added to the prelude.

Quoted 6 lines
Quoted 3 lines

Typo: "These"

And I'll add a Reported-by: line when I apply this in a few minutes, thanks!

Good call, thanks!

#9 lore raw
In reply to Alice Ryhl
Quoted 3 lines · Alice Ryhl

You can take it as a real patch. That will make your tree compile both with and without rust-next merged.

I don't think it builds without rust-next since the tree does not have build_error! imported (from the prelude).

Greg: if you want to pick it as a patch, please do instead:

- kernel::build_error(VTABLE_DEFAULT_ERROR)
+ kernel::build_error!(VTABLE_DEFAULT_ERROR).

Cheers,
Miguel

#10 lore raw
In reply to Greg Kroah-Hartman
Quoted 3 lines · Greg Kroah-Hartman

Can I take this as a real patch for my tree? Or is this only an issue due to the trees being merged?

The issue appears when the trees are merged, i.e. the code is on its own OK, though it is also true the code should be using the function but the macro (even if both work), so you could take the patch as an independent cleanup to the tree, I guess. In that case, I would clean the 3 cases (i.e. adding ! but not removing kernel::).

I can also drop a couple bits in rust-next and do the cleanup early next cycle.

Context:

15f2f9313a39 ("rust: use the build_error! macro, not the hidden function") 614724e780f5 ("rust: kernel: move build_error hidden function to
prevent mistakes")

Thanks!

Cheers,
Miguel

#11 lore raw
Quoted 3 lines · Miguel Ojeda

independent cleanup to the tree, I guess. In that case, I would clean the 3 cases (i.e. adding ! but not removing kernel::).

The patch that Alice sent for this looks good.

Stephen: I did a quick build test with a merge with rust-next using the following resolution (attached).

Cheers,
Miguel

rust/kernel/lib.rs +0 -0
diff --cc rust/kernel/lib.rs
index b11fa08de3c0,6063f4a3d9c0..2d5c3d7d2e21
@@@ -37,12 -32,10 +37,13 @@@ pub use ffi
  pub mod alloc;
  #[cfg(CONFIG_BLOCK)]
  pub mod block;
- mod build_assert;
+ #[doc(hidden)]
+ pub mod build_assert;
  pub mod cred;
  pub mod device;
 +pub mod device_id;
 +pub mod devres;
 +pub mod driver;
  pub mod error;
  #[cfg(CONFIG_RUST_FW_LOADER_ABSTRACTIONS)]
  pub mod firmware;
rust/kernel/miscdevice.rs +0 -0
diff --cc rust/kernel/miscdevice.rs
index dfb363630c70,9e1b9c0fae9d..3ba018651bc0
@@@ -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 {
@@@ -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,
      }