Skip to content

Add missing #[inline] markers to trivial wrappers around C functions #1145

Description

@Darksonn

When writing abstractions around core C apis, we often have Rust functions that do nothing other than call a C function. In those cases, we don't want the generated code to have a trivial Rust wrapper around the C function — Rust should inline it and generate a direct call into C.

However, in some cases that requires an #[inline] marker. Many methods in the kernel is missing it, and so this issue tracks such additions.

A few cases where I know that this is happening:

  • rust/kernel/task.rs
  • rust/kernel/page.rs
  • rust/kernel/sync/condvar.rs
  • rust/kernel/fs.rs specifically FileDescriptorReservation
  • rust/kernel/seq_file.rs
  • rust/kernel/uaccess.rs

To find these, you can inspect the Rust symbols yourself by building the kernel and running this command:

nm vmlinux | grep ' _R' | rustfilt

Examples of good patches that make this kind of change:

If you submit a patch that makes this kind of change, please make sure to have a good commit message (see the examples above).


This requires submitting a proper patch to the LKML and the Rust for Linux mailing list. Please recall to test your changes (including generating the documentation if changed, running the Rust doctests if changed, etc.), to use a proper title for the commit, to sign your commit under the Developer's Certificate of Origin and to add a Suggested-by: tag and a Link: tag to this issue. Please see https://docs.kernel.org/process/submitting-patches.html and https://rust-for-linux.com/contributing for details.

Please take this issue only if you are new to the kernel development process and you would like to use it as a test to submit your first patch to the kernel. Please do not take it if you do not plan to make other contributions to the kernel.

Activity

  1. panosfol commented on Mar 5, 2025

    @panosfol

    Hello! I would like to tackle this issue

  2. ojeda commented on Mar 5, 2025

    @ojeda
    Member

    Thanks, please go ahead!

  3. Darksonn commented on Mar 6, 2025

    @Darksonn
    MemberAuthor

    I recommend that you don't try to tackle every single method in one go. Start with one or two files and send a patch just for those, like the example patches did.

  4. panosfol commented on Mar 6, 2025

    @panosfol

    Sounds good!

  5. ethancedwards8 commented on Mar 10, 2025

    @ethancedwards8
  6. ojeda commented on Mar 10, 2025

    @ojeda
    Member

    Thanks both for the patches!

    By the way, please prefer lore.kernel.org for links, e.g. @ethancedwards8's patch is: https://lore.kernel.org/rust-for-linux/20250309-faux-inline-v1-1-c1b692862433@ethancedwards.com/

  7. ethancedwards8 commented on Mar 11, 2025

    @ethancedwards8

    Thanks both for the patches!

    By the way, please prefer lore.kernel.org for links, e.g. @ethancedwards8's patch is: https://lore.kernel.org/rust-for-linux/20250309-faux-inline-v1-1-c1b692862433@ethancedwards.com/

    Yeah, I typically use lore.kernel.org, but last night when I was sending the patch lore.kernel.org was having some issues (I was getting 504 errors), so I used lkml.org instead. I will use lore.kernel.org exclusively in the future, however

  8. KunWuChan commented on Mar 11, 2025

    @KunWuChan

    When writing abstractions around core C apis, we often have Rust functions that do nothing other than call a C function. In those cases, we don't want the generated code to have a trivial Rust wrapper around the C function — Rust should inline it and generate a direct call into C.在围绕核心 C API 编写抽象时,我们经常会有 Rust 函数,它们除了调用 C 函数之外什么都不做。在这些情况下,我们不希望生成的代码在 C 函数周围有一个简单的 Rust 包装器——Rust 应该内联它并生成对 C 的直接调用。

    However, in some cases that requires an #[inline] marker. Many methods in the kernel is missing it, and so this issue tracks such additions.但是,在某些情况下,这需要 #[inline] 标记。内核中的许多方法都缺少它,因此 issue 跟踪此类添加。

    A few cases where I know that this is happening:我知道这种情况正在发生的一些情况:

    • rust/kernel/task.rs``rust/内核/task.rs
    • rust/kernel/page.rs
    • rust/kernel/sync/condvar.rs
    • rust/kernel/fs.rs specifically FileDescriptorReservation``rust/kernel/fs.rs,特别是 FileDescriptorReservation
    • rust/kernel/seq_file.rs``rust/内核/seq_file.rs
    • rust/kernel/uaccess.rs``rust/内核/uaccess.rs

    To find these, you can inspect the Rust symbols yourself by building the kernel and running this command:要找到这些,您可以通过构建内核并运行以下命令来自己检查 Rust 符号:

    nm vmlinux | grep ' _R' | rustfilt
    

    Examples of good patches that make this kind of change:进行此类更改的良好补丁示例:

    If you submit a patch that makes this kind of change, please make sure to have a good commit message (see the examples above).如果您提交的补丁进行了此类更改,请确保有一个好的提交消息(请参阅上面的示例)。

    This requires submitting a proper patch to the LKML and the Rust for Linux mailing list. Please recall to test your changes (including generating the documentation if changed, running the Rust doctests if changed, etc.), to use a proper title for the commit, to sign your commit under the Developer's Certificate of Origin and to add a Suggested-by: tag and a Link: tag to this issue. Please see https://docs.kernel.org/process/submitting-patches.html and https://rust-for-linux.com/contributing for details.这需要向 LKML 和 Rust for Linux 邮件列表提交适当的补丁。请回想测试您的更改(包括更改后生成文档,如果更改则运行 Rust 文档测试等),为提交使用适当的标题,在开发者的原产地证书下签署您的提交,并为此问题添加 Suggested-by: 标签和 Link: 标签。有关详细信息,请参阅 https://docs.kernel.org/process/submitting-patches.html 和 https://rust-for-linux.com/contributing。

    Please take this issue only if you are new to the kernel development process and you would like to use it as a test to submit your first patch to the kernel. Please do not take it if you do not plan to make other contributions to the kernel.仅当您不熟悉内核开发过程,并且希望将其用作测试以向内核提交您的第一个补丁时,才请关注此问题。如果您不打算对内核做出其他贡献,请不要接受它。

    When writing abstractions around core C apis, we often have Rust functions that do nothing other than call a C function. In those cases, we don't want the generated code to have a trivial Rust wrapper around the C function — Rust should inline it and generate a direct call into C.

    However, in some cases that requires an #[inline] marker. Many methods in the kernel is missing it, and so this issue tracks such additions.

    A few cases where I know that this is happening:

    • rust/kernel/task.rs
    • rust/kernel/page.rs
    • rust/kernel/sync/condvar.rs
    • rust/kernel/fs.rs specifically FileDescriptorReservation
    • rust/kernel/seq_file.rs
    • rust/kernel/uaccess.rs

    To find these, you can inspect the Rust symbols yourself by building the kernel and running this command:

    nm vmlinux | grep ' _R' | rustfilt
    

    Examples of good patches that make this kind of change:

    If you submit a patch that makes this kind of change, please make sure to have a good commit message (see the examples above).

    This requires submitting a proper patch to the LKML and the Rust for Linux mailing list. Please recall to test your changes (including generating the documentation if changed, running the Rust doctests if changed, etc.), to use a proper title for the commit, to sign your commit under the Developer's Certificate of Origin and to add a Suggested-by: tag and a Link: tag to this issue. Please see https://docs.kernel.org/process/submitting-patches.html and https://rust-for-linux.com/contributing for details.

    Please take this issue only if you are new to the kernel development process and you would like to use it as a test to submit your first patch to the kernel. Please do not take it if you do not plan to make other contributions to the kernel.

    Thanks for the hint, I'll submit for the unfinished part, allow me to add a Suggested-by tag.

  9. charmitro commented on Mar 11, 2025

    @charmitro

    Thanks for the hint, I'll submit for the unfinished part, allow me to add a Suggested-by tag.

    Hi @KunWuChan, please note the following regarding issues labeled as "good-first-issue":

    Please take this issue only if you are new to the kernel development process and you would like to use it as a test to submit your first patch to the kernel.

  10. 39 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    easyExpected to be an easy issue to resolve.good first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions