Linux Trace Kernel
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Alice Ryhl <aliceryhl@google.com>
Cc: lkp@intel.com, boqun.feng@gmail.com, llvm@lists.linux.dev,
	oe-kbuild-all@lists.linux.dev, ojeda@kernel.org,
	linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND] jump_label: rust: pass a mut ptr to `static_key_count`
Date: Mon, 18 Nov 2024 18:28:18 -0500	[thread overview]
Message-ID: <20241118182818.7717993c@gandalf.local.home> (raw)
In-Reply-To: <20241118202727.73646-1-aliceryhl@google.com>

On Mon, 18 Nov 2024 20:27:26 +0000
Alice Ryhl <aliceryhl@google.com> wrote:

> When building the rust_print sample with CONFIG_JUMP_LABEL=n, the Rust
> static key support falls back to using static_key_count. This function
> accepts a mutable pointer to the `struct static_key`, but the Rust
> abstractions are incorrectly passing a const pointer.
> 
> This means that builds using CONFIG_JUMP_LABEL=n and SAMPLE_RUST_PRINT=y
> fail with the following error message:
> 
> 	error[E0308]: mismatched types
> 	  --> <root>/samples/rust/rust_print_main.rs:87:5  
> 	   |
> 	87 | /     kernel::declare_trace! {
> 	88 | |         /// # Safety
> 	89 | |         ///
> 	90 | |         /// Always safe to call.
> 	91 | |         unsafe fn rust_sample_loaded(magic: c_int);
> 	92 | |     }
> 	   | |     ^
> 	   | |     |
> 	   | |_____types differ in mutability
> 	   |       arguments to this function are incorrect
> 	   |
> 	   = note: expected raw pointer `*mut kernel::bindings::static_key`
> 	              found raw pointer `*const kernel::bindings::static_key`
> 	note: function defined here
> 	  --> <root>/rust/bindings/bindings_helpers_generated.rs:33:12  
> 	   |
> 	33 |     pub fn static_key_count(key: *mut static_key) -> c_int;
> 	   |            ^^^^^^^^^^^^^^^^
> 
> To fix this, insert a pointer cast so that the pointer is mutable.

Hi Alice,

BTW, how do you test the sample tracepoint? I see you add a tracepoint in
the module load call, but currently we can enable module tracepoints on
module load. How do you enable it when the rust_print module gets loaded?

-- Steve


> 
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202411181440.qEdcuyh6-lkp@intel.com/
> Fixes: 169484ab6677 ("rust: add arch_static_branch")
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
>  rust/kernel/jump_label.rs | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/rust/kernel/jump_label.rs b/rust/kernel/jump_label.rs
> index 2f2df03a3275..b5aff632ecc7 100644
> --- a/rust/kernel/jump_label.rs
> +++ b/rust/kernel/jump_label.rs
> @@ -26,7 +26,7 @@ macro_rules! static_branch_unlikely {
>  
>          #[cfg(not(CONFIG_JUMP_LABEL))]
>          {
> -            $crate::bindings::static_key_count(_key) > 0
> +            $crate::bindings::static_key_count(_key.cast_mut()) > 0
>          }
>  
>          #[cfg(CONFIG_JUMP_LABEL)]
> 
> base-commit: 22193c586b43ee88d66954395885742a6e4a49a9


  parent reply	other threads:[~2024-11-18 23:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <202411181440.qEdcuyh6-lkp@intel.com>
2024-11-18 20:27 ` [PATCH RESEND] jump_label: rust: pass a mut ptr to `static_key_count` Alice Ryhl
2024-11-18 20:41   ` Miguel Ojeda
2024-11-18 23:28   ` Steven Rostedt [this message]
2024-11-19  8:36     ` Alice Ryhl
2024-11-19 15:12       ` Steven Rostedt
2024-11-19 15:31         ` Alice Ryhl
2024-11-19 15:53           ` Steven Rostedt
2024-11-19 16:16             ` Alice Ryhl
2024-11-19 16:52               ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241118182818.7717993c@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=aliceryhl@google.com \
    --cc=boqun.feng@gmail.com \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=llvm@lists.linux.dev \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=ojeda@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox