Rust-for-Linux / linux

Adding support for the Rust language to the Linux kernel.
https://rust-for-linux.com
Other
3.83k stars 399 forks source link

Does key `params` unavailable in `macros::module` now? #1042

Closed zhouhaoan closed 7 months ago

zhouhaoan commented 7 months ago

I just copy the sample code from The document of macros::module. Writting a Kbuild file and a Makefile, trying to compile it as an out-of-tree module. When I execute make LLVM=1, the compiler raised an error of Unknown key "params". Here's the detail:

zhou@zhou-Virtual-Machine:~/proj/graduate_paper/rhhouse$ make LLVM=1
make -C /lib/modules/`uname -r`/build M=$PWD
make[1]: Entering directory '/home/zhou/proj/rust-for-linux/linux'
  RUSTC [M] /home/zhou/proj/graduate_paper/rhhouse/sample.o
error: proc macro panicked
  --> /home/zhou/proj/graduate_paper/rhhouse/sample.rs:3:1
   |
3  | / module!{
4  | |     type: MyModule,
5  | |     name: "my_kernel_module",
6  | |     author: "Rust for Linux Contributors",
...  |
20 | |    },
21 | | }
   | |_^
   |
   = help: message: Unknown key "params". Valid keys are: ["type", "name", "author", "description", "license", "alias"].

error[E0425]: cannot find value `THIS_MODULE` in this scope
  --> /home/zhou/proj/graduate_paper/rhhouse/sample.rs:30:24
   |
30 |             let lock = THIS_MODULE.kernel_param_lock();
   |                        ^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `writeable_i32` in this scope
  --> /home/zhou/proj/graduate_paper/rhhouse/sample.rs:31:45
   |
31 |             pr_info!("i32 param is:  {}\n", writeable_i32.read(&lock));
   |                                             ^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value `__LOG_PREFIX` in the crate root
  --> /home/zhou/proj/graduate_paper/rhhouse/sample.rs:31:13
   |
31 |             pr_info!("i32 param is:  {}\n", writeable_i32.read(&lock));
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in the crate root
   |
   = note: this error originates in the macro `$crate::print_macro` which comes from the expansion of the macro `pr_info` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0425]: cannot find value `my_i32` in this scope
  --> /home/zhou/proj/graduate_paper/rhhouse/sample.rs:35:41
   |
35 |         pr_info!("i32 param is:  {}\n", my_i32.read());
   |                                         ^^^^^^ not found in this scope

error[E0425]: cannot find value `__LOG_PREFIX` in the crate root
  --> /home/zhou/proj/graduate_paper/rhhouse/sample.rs:35:9
   |
35 |         pr_info!("i32 param is:  {}\n", my_i32.read());
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in the crate root
   |
   = note: this error originates in the macro `$crate::print_macro` which comes from the expansion of the macro `pr_info` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0050]: method `init` has 0 parameters but the declaration in trait `kernel::Module::init` has 1
  --> /home/zhou/proj/graduate_paper/rhhouse/sample.rs:26:5
   |
26 |     fn init() -> Result<Self> {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 parameter, found 0
   |
   = note: `init` from trait: `fn(&'static ThisModule) -> core::result::Result<Self, kernel::error::Error>`

error: aborting due to 7 previous errors

Some errors have detailed explanations: E0050, E0425.
For more information about an error, try `rustc --explain E0050`.
make[3]: *** [scripts/Makefile.build:292: /home/zhou/proj/graduate_paper/rhhouse/sample.o] Error 1
make[2]: *** [/home/zhou/proj/rust-for-linux/linux/Makefile:1913: /home/zhou/proj/graduate_paper/rhhouse] Error 2
make[1]: *** [Makefile:234: __sub-make] Error 2
make[1]: Leaving directory '/home/zhou/proj/rust-for-linux/linux'
make: *** [Makefile:6: default] Error 2

And here's my config file: Kbuild:

# SPDX-License-Identifier: GPL-2.0

obj-m := sample.o

Makefile:

# SPDX-License-Identifier: GPL-2.0

KDIR ?= /lib/modules/`uname -r`/build

default:
    $(MAKE) -C $(KDIR) M=$$PWD

modules_install: default
    $(MAKE) -C $(KDIR) M=$$PWD modules_install

I have two question now:

  1. Does params key unavailable now?
  2. How can I pass parameters to an out-of-tree kernle module now?
ojeda commented 7 months ago

Params are not supported in mainline yet (the example in the docs should not have had the params there yet). I think @adamrk plans to submit what we had in the rust branch to the mailing list soon.

zhouhaoan commented 7 months ago

Got it, thanks

mikemykhaylov commented 5 months ago

Any luck with getting it into mainline? Just started taking the OS course at uni, would love to do assignments in Rust but they need params passing