Rust for Linux List
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Breno Rodrigues Alves <breno3011alves@gmail.com>
Cc: alexander.deucher@amd.com, ojeda@kernel.org,
	christian.koenig@amd.com, arnd@arndb.de,
	rust-for-linux@vger.kernel.org, amd-gfx@lists.freedesktop.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] rust: core: implement rx580 state optimization engine and c-to-rust char dev
Date: Wed, 1 Jul 2026 12:32:57 +0200	[thread overview]
Message-ID: <2026070136-unbent-mothball-49ba@gregkh> (raw)
In-Reply-To: <20260630210445.23103-1-breno3011alves@gmail.com>

On Tue, Jun 30, 2026 at 06:04:45PM -0300, Breno Rodrigues Alves wrote:
> This patch introduces an automated indexed state mechanism to optimize
> VRAM latency and command loops for the Radeon RX 580 architecture.
> Additionally, it provides a converted C-to-Rust sample char driver.
> 
> Signed-off-by: Breno Rodrigues Alves <breno3011alves@gmail.com>
> ---
>  Documentation/rust/alves_guidelines.rst  |  3 ++
>  drivers/char/Kconfig                     |  7 +++++
>  drivers/char/alves_char_dev.rs           | 31 +++++++++++++++++++
>  drivers/gpu/drm/amd/amdgpu/Makefile      |  1 +
>  drivers/gpu/drm/amd/amdgpu/alves_core.rs | 38 ++++++++++++++++++++++++
>  5 files changed, 80 insertions(+)
>  create mode 100644 Documentation/rust/alves_guidelines.rst
>  create mode 100644 drivers/char/alves_char_dev.rs
>  create mode 100644 drivers/gpu/drm/amd/amdgpu/alves_core.rs
> 
> diff --git a/Documentation/rust/alves_guidelines.rst b/Documentation/rust/alves_guidelines.rst
> new file mode 100644
> index 000000000..f6afa63de
> --- /dev/null
> +++ b/Documentation/rust/alves_guidelines.rst
> @@ -0,0 +1,3 @@
> +# Rust for Linux - Core Guidelines
> +- Style: Linear, pragmatic, flat, Linus Torvalds style.
> +- Constraints: Zero-cost abstractions, strict RAII, no binary bloat.
> diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
> index 9865227af..ace4df826 100644
> --- a/drivers/char/Kconfig
> +++ b/drivers/char/Kconfig
> @@ -372,3 +372,10 @@ config ADI
>  	  driver include crash and makedumpfile.
>  
>  endmenu
> +config ALVES_CHAR_DEV
> +	tristate "Alves C-to-Rust Character Device Driver"
> +	depends on RUST
> +	help
> +	  This is a character device driver migrated from C to Rust.
> +	  It acts as a core showcase of 2% module conversions.
> +	  Say Y or M here if you want to test the Rust infrastructure.
> diff --git a/drivers/char/alves_char_dev.rs b/drivers/char/alves_char_dev.rs
> new file mode 100644
> index 000000000..5ccb80ea4
> --- /dev/null
> +++ b/drivers/char/alves_char_dev.rs
> @@ -0,0 +1,31 @@
> +// SPDX-License-Identifier: GPL-2.0 OR MIT
> +//! Simple Character Device converted from legacy C to Rust using core Miscdev API.

Where is the original C code?

And what is going to interact with this in userspace?  And how?

> +
> +use kernel::prelude::*;
> +use kernel::miscdev;
> +
> +module! {
> +    type: AlvesCharDevice,
> +    name: "alves_char_dev",
> +    author: "Breno Rodrigues Alves",
> +    description: "Pragmatic C-to-Rust converted character device driver",
> +    license: "GPL OR MIT",
> +}
> +
> +struct AlvesCharDevice {
> +    _dev: miscdev::Registration<AlvesCharDevice>,
> +}
> +
> +#[vtable]
> +impl miscdev::Options for AlvesCharDevice {
> +    const NAME: \&"static CStr = c_str!("alves_char_dev");
> +}
> +
> +impl kernel::Module for AlvesCharDevice {
> +    fn init(module: \&"static ThisModule) -> Result<Self> {
> +        pr_info!("Alves C-to-Rust module initialized successfully
> +");
> +        let dev = miscdev::Registration::new_reg(module)?;
> +        Ok(AlvesCharDevice { _dev: dev })
> +    }
> +}

This code doesn't actually do anything at all, how was it tested?


> diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile b/drivers/gpu/drm/amd/amdgpu/Makefile
> index ba80542ea..b9f98c3e4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> @@ -349,3 +349,4 @@ include $(AMD_GPU_RAS_FULL_PATH)/Makefile
>  amdgpu-y += $(AMD_GPU_RAS_FILES)
>  
>  obj-$(CONFIG_DRM_AMDGPU)+= amdgpu.o
> +amdgpu-y += alves_core.o
> diff --git a/drivers/gpu/drm/amd/amdgpu/alves_core.rs b/drivers/gpu/drm/amd/amdgpu/alves_core.rs
> new file mode 100644
> index 000000000..aa436763e
> --- /dev/null
> +++ b/drivers/gpu/drm/amd/amdgpu/alves_core.rs
> @@ -0,0 +1,38 @@
> +// SPDX-License-Identifier: GPL-2.0 OR MIT
> +//! AMDGPU RX 580 State Optimization Engine (Turing-inspired state machine)
> +//!
> +//! Copyright (C) 2026 Breno Rodrigues Alves.
> +
> +use kernel::prelude::*;
> +
> +#[derive(Copy, Clone, PartialEq, Eq)]
> +#[repr(u8)]
> +enum GpuState {
> +    Idling = 0,
> +    LowPower = 1,
> +    ComputeActive = 2,
> +    VramMaxPerf = 3,
> +}
> +
> +struct Rx580Engine {
> +    current_state: GpuState,
> +}
> +
> +impl Rx580Engine {
> +    fn transition(&mut self, symbol: u8) {
> +        self.current_state = match (self.current_state, symbol) {
> +            (GpuState::Idling, 0x01) => GpuState::LowPower,
> +            (GpuState::LowPower, 0x02) => GpuState::ComputeActive,
> +            (GpuState::ComputeActive, 0x03) => GpuState::VramMaxPerf,
> +            (GpuState::VramMaxPerf, 0x00) => GpuState::Idling,
> +            (state, _) => state,
> +        };
> +    }
> +}
> +
> +#[no_mangle]
> +pub extern "C" fn amdgpu_rust_rx580_optimize(register_sample: u32) {
> +    let mut engine = Rx580Engine { current_state: GpuState::Idling };
> +    let symbol = (register_sample \& 0xFF) as u8;
> +    engine.transition(symbol);
> +}

Same here, this code doesn't do anything that I can tell.  How was it
tested?

confused,

greg k-h

  parent reply	other threads:[~2026-07-01 10:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30 21:04 [PATCH v3] rust: core: implement rx580 state optimization engine and c-to-rust char dev Breno Rodrigues Alves
2026-06-30 21:10 ` Miguel Ojeda
2026-07-01 10:32 ` Greg KH [this message]
2026-07-02 18:50 ` Julian Braha

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=2026070136-unbent-mothball-49ba@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=arnd@arndb.de \
    --cc=breno3011alves@gmail.com \
    --cc=christian.koenig@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.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