2024-01-08 03:21:53

by WANG Rui

[permalink] [raw]
Subject: [PATCH v1 0/2] Rust enablement for LoongArch

Enable Rust support for the LoongArch architecture.

Previous versions:
v0: https://lore.kernel.org/loongarch/[email protected]/

Changes in v1:
- Address htmldocs warning.

WANG Rui (2):
Documentation: rust: Add a character to the first column
LoongArch: Enable initial Rust support

Documentation/rust/arch-support.rst | 13 +++++++------
arch/loongarch/Kconfig | 1 +
arch/loongarch/Makefile | 3 +++
scripts/generate_rust_target.rs | 10 ++++++++++
4 files changed, 21 insertions(+), 6 deletions(-)

--
2.43.0



2024-01-08 03:22:24

by WANG Rui

[permalink] [raw]
Subject: [PATCH v1 1/2] Documentation: rust: Add a character to the first column

Add a character to the first table column in preparation for subsequent
'loongarch' row additions.

Signed-off-by: WANG Rui <[email protected]>
---
Documentation/rust/arch-support.rst | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/Documentation/rust/arch-support.rst b/Documentation/rust/arch-support.rst
index b91e9ef4d0c2..14875a2e073a 100644
--- a/Documentation/rust/arch-support.rst
+++ b/Documentation/rust/arch-support.rst
@@ -12,10 +12,10 @@ which uses ``libclang``.
Below is a general summary of architectures that currently work. Level of
support corresponds to ``S`` values in the ``MAINTAINERS`` file.

-============ ================ ==============================================
-Architecture Level of support Constraints
-============ ================ ==============================================
-``um`` Maintained ``x86_64`` only.
-``x86`` Maintained ``x86_64`` only.
-============ ================ ==============================================
+============= ================ ==============================================
+Architecture Level of support Constraints
+============= ================ ==============================================
+``um`` Maintained ``x86_64`` only.
+``x86`` Maintained ``x86_64`` only.
+============= ================ ==============================================

--
2.43.0


2024-01-08 03:22:28

by WANG Rui

[permalink] [raw]
Subject: [PATCH v1 2/2] LoongArch: Enable initial Rust support

Add initial Rust support for LoongArch.

Signed-off-by: WANG Rui <[email protected]>
---
Documentation/rust/arch-support.rst | 1 +
arch/loongarch/Kconfig | 1 +
arch/loongarch/Makefile | 3 +++
scripts/generate_rust_target.rs | 10 ++++++++++
4 files changed, 15 insertions(+)

diff --git a/Documentation/rust/arch-support.rst b/Documentation/rust/arch-support.rst
index 14875a2e073a..73203ba1e901 100644
--- a/Documentation/rust/arch-support.rst
+++ b/Documentation/rust/arch-support.rst
@@ -15,6 +15,7 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file.
============= ================ ==============================================
Architecture Level of support Constraints
============= ================ ==============================================
+``loongarch`` Maintained -
``um`` Maintained ``x86_64`` only.
``x86`` Maintained ``x86_64`` only.
============= ================ ==============================================
diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
index 15d05dd2b7f3..6d39ec3077da 100644
--- a/arch/loongarch/Kconfig
+++ b/arch/loongarch/Kconfig
@@ -142,6 +142,7 @@ config LOONGARCH
select HAVE_REGS_AND_STACK_ACCESS_API
select HAVE_RETHOOK
select HAVE_RSEQ
+ select HAVE_RUST
select HAVE_SAMPLE_FTRACE_DIRECT
select HAVE_SAMPLE_FTRACE_DIRECT_MULTI
select HAVE_SETUP_PER_CPU_AREA if NUMA
diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile
index 4ba8d67ddb09..ba45cb7b621c 100644
--- a/arch/loongarch/Makefile
+++ b/arch/loongarch/Makefile
@@ -81,8 +81,11 @@ KBUILD_AFLAGS_MODULE += -Wa,-mla-global-with-abs
KBUILD_CFLAGS_MODULE += -fplt -Wa,-mla-global-with-abs,-mla-local-with-abs
endif

+KBUILD_RUSTFLAGS_MODULE += -Crelocation-model=pic
+
ifeq ($(CONFIG_RELOCATABLE),y)
KBUILD_CFLAGS_KERNEL += -fPIE
+KBUILD_RUSTFLAGS_KERNEL += -Crelocation-model=pie
LDFLAGS_vmlinux += -static -pie --no-dynamic-linker -z notext $(call ld-option, --apply-dynamic-relocs)
endif

diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs
index 3c6cbe2b278d..3edda6a10dd0 100644
--- a/scripts/generate_rust_target.rs
+++ b/scripts/generate_rust_target.rs
@@ -161,6 +161,16 @@ fn main() {
ts.push("features", features);
ts.push("llvm-target", "x86_64-linux-gnu");
ts.push("target-pointer-width", "64");
+ } else if cfg.has("LOONGARCH") {
+ ts.push("arch", "loongarch64");
+ ts.push(
+ "data-layout",
+ "e-m:e-p:64:64-i64:64-i128:128-n64-S128",
+ );
+ ts.push("features", "-f,-d");
+ ts.push("llvm-target", "loongarch64-linux-gnusf");
+ ts.push("llvm-abiname", "lp64s");
+ ts.push("target-pointer-width", "64");
} else {
panic!("Unsupported architecture");
}
--
2.43.0


2024-01-08 04:23:34

by Huacai Chen

[permalink] [raw]
Subject: Re: [PATCH v1 0/2] Rust enablement for LoongArch

No need to split patches.

Huacai

On Mon, Jan 8, 2024 at 11:21 AM WANG Rui <[email protected]> wrote:
>
> Enable Rust support for the LoongArch architecture.
>
> Previous versions:
> v0: https://lore.kernel.org/loongarch/[email protected]/
>
> Changes in v1:
> - Address htmldocs warning.
>
> WANG Rui (2):
> Documentation: rust: Add a character to the first column
> LoongArch: Enable initial Rust support
>
> Documentation/rust/arch-support.rst | 13 +++++++------
> arch/loongarch/Kconfig | 1 +
> arch/loongarch/Makefile | 3 +++
> scripts/generate_rust_target.rs | 10 ++++++++++
> 4 files changed, 21 insertions(+), 6 deletions(-)
>
> --
> 2.43.0
>

2024-01-09 09:54:47

by Huacai Chen

[permalink] [raw]
Subject: Re: [PATCH v1 0/2] Rust enablement for LoongArch

Squashed and applied, thanks.

Huacai

On Mon, Jan 8, 2024 at 12:23 PM Huacai Chen <[email protected]> wrote:
>
> No need to split patches.
>
> Huacai
>
> On Mon, Jan 8, 2024 at 11:21 AM WANG Rui <[email protected]> wrote:
> >
> > Enable Rust support for the LoongArch architecture.
> >
> > Previous versions:
> > v0: https://lore.kernel.org/loongarch/[email protected]/
> >
> > Changes in v1:
> > - Address htmldocs warning.
> >
> > WANG Rui (2):
> > Documentation: rust: Add a character to the first column
> > LoongArch: Enable initial Rust support
> >
> > Documentation/rust/arch-support.rst | 13 +++++++------
> > arch/loongarch/Kconfig | 1 +
> > arch/loongarch/Makefile | 3 +++
> > scripts/generate_rust_target.rs | 10 ++++++++++
> > 4 files changed, 21 insertions(+), 6 deletions(-)
> >
> > --
> > 2.43.0
> >

2024-01-09 19:35:29

by Boqun Feng

[permalink] [raw]
Subject: Re: [PATCH v1 0/2] Rust enablement for LoongArch

Hi,

Thanks for the patch.

On Mon, Jan 08, 2024 at 11:21:15AM +0800, WANG Rui wrote:
> Enable Rust support for the LoongArch architecture.
>

Could you share how you build and test? For example, I wonder the clang
or gcc version you used and bindgen version you used. Thanks.

Regards,
Boqun

> Previous versions:
> v0: https://lore.kernel.org/loongarch/[email protected]/
>
> Changes in v1:
> - Address htmldocs warning.
>
> WANG Rui (2):
> Documentation: rust: Add a character to the first column
> LoongArch: Enable initial Rust support
>
> Documentation/rust/arch-support.rst | 13 +++++++------
> arch/loongarch/Kconfig | 1 +
> arch/loongarch/Makefile | 3 +++
> scripts/generate_rust_target.rs | 10 ++++++++++
> 4 files changed, 21 insertions(+), 6 deletions(-)
>
> --
> 2.43.0
>

2024-01-10 01:42:14

by WANG Rui

[permalink] [raw]
Subject: Re: [PATCH v1 0/2] Rust enablement for LoongArch

Hi Boqun,

On Wed, Jan 10, 2024 at 3:35 AM Boqun Feng <[email protected]> wrote:
>
> Hi,
>
> Thanks for the patch.
>
> On Mon, Jan 08, 2024 at 11:21:15AM +0800, WANG Rui wrote:
> > Enable Rust support for the LoongArch architecture.
> >
>
> Could you share how you build and test? For example, I wonder the clang
> or gcc version you used and bindgen version you used. Thanks.

You are welcome! The versions I'm using are listed in
scripts/min-tool-version.sh, and I have tested Rust samples and the
rnull block driver.

llvm: main branch (ea3c7b3397f8de8e885ea7cd1ed5138ec4a72d50)
rustc: 1.74.1
bindgen: 0.65.1

Here are the build steps:

1. Build llvm
2. Install rust, rust-src (using rustup) and bindgen
3. Build kernel

For more details, refer to Documentation/rust/quick-start.rst; there
is nothing special about it.

Regards,
Rui

>
> Regards,
> Boqun
>
> > Previous versions:
> > v0: https://lore.kernel.org/loongarch/[email protected]/
> >
> > Changes in v1:
> > - Address htmldocs warning.
> >
> > WANG Rui (2):
> > Documentation: rust: Add a character to the first column
> > LoongArch: Enable initial Rust support
> >
> > Documentation/rust/arch-support.rst | 13 +++++++------
> > arch/loongarch/Kconfig | 1 +
> > arch/loongarch/Makefile | 3 +++
> > scripts/generate_rust_target.rs | 10 ++++++++++
> > 4 files changed, 21 insertions(+), 6 deletions(-)
> >
> > --
> > 2.43.0
> >
>


2024-01-10 02:10:39

by Boqun Feng

[permalink] [raw]
Subject: Re: [PATCH v1 0/2] Rust enablement for LoongArch

On Wed, Jan 10, 2024 at 09:41:38AM +0800, WANG Rui wrote:
> Hi Boqun,
>
> On Wed, Jan 10, 2024 at 3:35 AM Boqun Feng <[email protected]> wrote:
> >
> > Hi,
> >
> > Thanks for the patch.
> >
> > On Mon, Jan 08, 2024 at 11:21:15AM +0800, WANG Rui wrote:
> > > Enable Rust support for the LoongArch architecture.
> > >
> >
> > Could you share how you build and test? For example, I wonder the clang
> > or gcc version you used and bindgen version you used. Thanks.
>
> You are welcome! The versions I'm using are listed in
> scripts/min-tool-version.sh, and I have tested Rust samples and the
> rnull block driver.
>
> llvm: main branch (ea3c7b3397f8de8e885ea7cd1ed5138ec4a72d50)

This means the LLVM support is yet to release? Or does LLVM 17 also
work?

Regards,
Boqun

> rustc: 1.74.1
> bindgen: 0.65.1
>
> Here are the build steps:
>
> 1. Build llvm
> 2. Install rust, rust-src (using rustup) and bindgen
> 3. Build kernel
>
> For more details, refer to Documentation/rust/quick-start.rst; there
> is nothing special about it.
>
> Regards,
> Rui
>
> >
> > Regards,
> > Boqun
> >
> > > Previous versions:
> > > v0: https://lore.kernel.org/loongarch/[email protected]/
> > >
> > > Changes in v1:
> > > - Address htmldocs warning.
> > >
> > > WANG Rui (2):
> > > Documentation: rust: Add a character to the first column
> > > LoongArch: Enable initial Rust support
> > >
> > > Documentation/rust/arch-support.rst | 13 +++++++------
> > > arch/loongarch/Kconfig | 1 +
> > > arch/loongarch/Makefile | 3 +++
> > > scripts/generate_rust_target.rs | 10 ++++++++++
> > > 4 files changed, 21 insertions(+), 6 deletions(-)
> > >
> > > --
> > > 2.43.0
> > >
> >
>

2024-01-10 02:50:21

by WANG Rui

[permalink] [raw]
Subject: Re: [PATCH v1 0/2] Rust enablement for LoongArch

On Wed, Jan 10, 2024 at 10:09 AM Boqun Feng <[email protected]> wrote:
>
> On Wed, Jan 10, 2024 at 09:41:38AM +0800, WANG Rui wrote:
> > Hi Boqun,
> >
> > On Wed, Jan 10, 2024 at 3:35 AM Boqun Feng <[email protected]> wrote:
> > >
> > > Hi,
> > >
> > > Thanks for the patch.
> > >
> > > On Mon, Jan 08, 2024 at 11:21:15AM +0800, WANG Rui wrote:
> > > > Enable Rust support for the LoongArch architecture.
> > > >
> > >
> > > Could you share how you build and test? For example, I wonder the clang
> > > or gcc version you used and bindgen version you used. Thanks.
> >
> > You are welcome! The versions I'm using are listed in
> > scripts/min-tool-version.sh, and I have tested Rust samples and the
> > rnull block driver.
> >
> > llvm: main branch (ea3c7b3397f8de8e885ea7cd1ed5138ec4a72d50)
>
> This means the LLVM support is yet to release? Or does LLVM 17 also
> work?

LLVM 17 doesn't work. The minimum LLVM version required for LoongArch
is 18.0.0. This is the reason why we have updated the
scripts/min-tool-version.sh. [1]

[1] https://lore.kernel.org/loongarch/[email protected]/

Regards,
Rui

>
> Regards,
> Boqun
>
> > rustc: 1.74.1
> > bindgen: 0.65.1
> >
> > Here are the build steps:
> >
> > 1. Build llvm
> > 2. Install rust, rust-src (using rustup) and bindgen
> > 3. Build kernel
> >
> > For more details, refer to Documentation/rust/quick-start.rst; there
> > is nothing special about it.
> >
> > Regards,
> > Rui
> >
> > >
> > > Regards,
> > > Boqun
> > >
> > > > Previous versions:
> > > > v0: https://lore.kernel.org/loongarch/[email protected]/
> > > >
> > > > Changes in v1:
> > > > - Address htmldocs warning.
> > > >
> > > > WANG Rui (2):
> > > > Documentation: rust: Add a character to the first column
> > > > LoongArch: Enable initial Rust support
> > > >
> > > > Documentation/rust/arch-support.rst | 13 +++++++------
> > > > arch/loongarch/Kconfig | 1 +
> > > > arch/loongarch/Makefile | 3 +++
> > > > scripts/generate_rust_target.rs | 10 ++++++++++
> > > > 4 files changed, 21 insertions(+), 6 deletions(-)
> > > >
> > > > --
> > > > 2.43.0
> > > >
> > >
> >
>


--
WANG Rui


2024-01-10 10:50:50

by Miguel Ojeda

[permalink] [raw]
Subject: Re: [PATCH v1 0/2] Rust enablement for LoongArch

On Wed, Jan 10, 2024 at 3:49 AM WANG Rui <[email protected]> wrote:
>
> LLVM 17 doesn't work. The minimum LLVM version required for LoongArch
> is 18.0.0. This is the reason why we have updated the
> scripts/min-tool-version.sh. [1]
>
> [1] https://lore.kernel.org/loongarch/[email protected]/

Thanks! Is this targeted at 6.9?

Cheers,
Miguel

2024-01-11 03:17:35

by WANG Rui

[permalink] [raw]
Subject: Re: [PATCH v1 0/2] Rust enablement for LoongArch

On Wed, Jan 10, 2024 at 6:50 PM Miguel Ojeda
<[email protected]> wrote:
>
> On Wed, Jan 10, 2024 at 3:49 AM WANG Rui <[email protected]> wrote:
> >
> > LLVM 17 doesn't work. The minimum LLVM version required for LoongArch
> > is 18.0.0. This is the reason why we have updated the
> > scripts/min-tool-version.sh. [1]
> >
> > [1] https://lore.kernel.org/loongarch/[email protected]/
>
> Thanks! Is this targeted at 6.9?

6.8

Regards,
Rui

>
> Cheers,
> Miguel
>


2024-01-14 15:44:10

by Miguel Ojeda

[permalink] [raw]
Subject: Re: [PATCH v1 0/2] Rust enablement for LoongArch

On Thu, Jan 11, 2024 at 4:16 AM WANG Rui <[email protected]> wrote:
>
> 6.8

Thanks, that is quite expedited...

Please `rustfmt` the code to avoid failing the `rustfmtcheck` target.
I see you already created the 6.8 tag but I have not seen it in
linux-next yet and you did not send the PR, so it would be ideal if
you could fix this before it goes to Linus.

diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_targetrs
index 3edda6a10..0da52b548 100644
--- a/scripts/generate_rust_target.rs
+++ b/scripts/generate_rust_target.rs
@@ -163,10 +163,7 @@ fn main() {
ts.push("target-pointer-width", "64");
} else if cfg.has("LOONGARCH") {
ts.push("arch", "loongarch64");
- ts.push(
- "data-layout",
- "e-m:e-p:64:64-i64:64-i128:128-n64-S128",
- );
+ ts.push("data-layout", "e-m:e-p:64:64-i64:64-i128:128-n64-S128");
ts.push("features", "-f,-d");
ts.push("llvm-target", "loongarch64-linux-gnusf");
ts.push("llvm-abiname", "lp64s");

Thanks!

Cheers,
Miguel

2024-01-15 03:24:05

by Huacai Chen

[permalink] [raw]
Subject: Re: [PATCH v1 0/2] Rust enablement for LoongArch

Hi, Miguel,

On Sun, Jan 14, 2024 at 11:44 PM Miguel Ojeda
<[email protected]> wrote:
>
> On Thu, Jan 11, 2024 at 4:16 AM WANG Rui <[email protected]> wrote:
> >
> > 6.8
>
> Thanks, that is quite expedited...
>
> Please `rustfmt` the code to avoid failing the `rustfmtcheck` target.
> I see you already created the 6.8 tag but I have not seen it in
> linux-next yet and you did not send the PR, so it would be ideal if
> you could fix this before it goes to Linus.
>
> diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs
> index 3edda6a10..0da52b548 100644
> --- a/scripts/generate_rust_target.rs
> +++ b/scripts/generate_rust_target.rs
> @@ -163,10 +163,7 @@ fn main() {
> ts.push("target-pointer-width", "64");
> } else if cfg.has("LOONGARCH") {
> ts.push("arch", "loongarch64");
> - ts.push(
> - "data-layout",
> - "e-m:e-p:64:64-i64:64-i128:128-n64-S128",
> - );
> + ts.push("data-layout", "e-m:e-p:64:64-i64:64-i128:128-n64-S128");
> ts.push("features", "-f,-d");
> ts.push("llvm-target", "loongarch64-linux-gnusf");
> ts.push("llvm-abiname", "lp64s");
>
> Thanks!
Thank you for your suggestion, but since this will be replaced by the
built-in target soon, and I don't want to change the tag to make Linus
unhappy. Let's leave it as is.

Huacai

>
> Cheers,
> Miguel

2024-01-15 16:09:24

by Miguel Ojeda

[permalink] [raw]
Subject: Re: [PATCH v1 0/2] Rust enablement for LoongArch

On Mon, Jan 15, 2024 at 4:23 AM Huacai Chen <[email protected]> wrote:
>
> Thank you for your suggestion, but since this will be replaced by the
> built-in target soon, and I don't want to change the tag to make Linus
> unhappy. Let's leave it as is.

The issue is not a big deal and I appreciate that you made the effort
to enable Rust for your architecture. However, please note that we do
our best to maintain a clean formatting state for Rust code (i.e.
`rustfmt` should be run) and that people may see this in tests/CIs
that use the Make target.

I don't think Linus would mind too much, and you could point him to
this email if you want (or you could put the fix on top); but if you
really want to keep the tag as-is, then we should consider it as a fix
for this cycle, i.e. we should not wait for e.g. the next cycle for
the built-in target. Could you please send it through your tree as
soon as possible?

Cheers,
Miguel

2024-01-16 09:32:01

by Huacai Chen

[permalink] [raw]
Subject: Re: [PATCH v1 0/2] Rust enablement for LoongArch

Hi, Miguel,

On Tue, Jan 16, 2024 at 12:08 AM Miguel Ojeda
<[email protected]> wrote:
>
> On Mon, Jan 15, 2024 at 4:23 AM Huacai Chen <[email protected]> wrote:
> >
> > Thank you for your suggestion, but since this will be replaced by the
> > built-in target soon, and I don't want to change the tag to make Linus
> > unhappy. Let's leave it as is.
>
> The issue is not a big deal and I appreciate that you made the effort
> to enable Rust for your architecture. However, please note that we do
> our best to maintain a clean formatting state for Rust code (i.e.
> `rustfmt` should be run) and that people may see this in tests/CIs
> that use the Make target.
>
> I don't think Linus would mind too much, and you could point him to
> this email if you want (or you could put the fix on top); but if you
> really want to keep the tag as-is, then we should consider it as a fix
> for this cycle, i.e. we should not wait for e.g. the next cycle for
> the built-in target. Could you please send it through your tree as
> soon as possible?
OK, since Linus said the merge window is paused now, I rebase and
retag my tree and the Rust commit is like this, I think this is
perfect now?

https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson.git/commit/?h=loongarch-next&id=706f9e1ab7c7a58d80ef2c87d8720131253a2256

Huacai

>
> Cheers,
> Miguel

2024-01-16 15:16:17

by Miguel Ojeda

[permalink] [raw]
Subject: Re: [PATCH v1 0/2] Rust enablement for LoongArch

On Tue, Jan 16, 2024 at 10:31 AM Huacai Chen <[email protected]> wrote:
>
> OK, since Linus said the merge window is paused now, I rebase and
> retag my tree and the Rust commit is like this, I think this is
> perfect now?
>
> https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongsongit/commit/?h=loongarch-next&id=706f9e1ab7c7a58d80ef2c87d8720131253a2256

Thanks a lot! That works, yeah.

I also took the chance to build LLVM and QEMU and I tested the tag --
it seems to work: I see the samples (built-in) printing in the kernel
log :)

So in case you end up rebasing for another reason and want to add it,
even if it is a simple check I did:

Tested-by: Miguel Ojeda <[email protected]>

Cheers,
Miguel

2024-01-17 04:34:54

by Huacai Chen

[permalink] [raw]
Subject: Re: [PATCH v1 0/2] Rust enablement for LoongArch

Hi, Miguel,

On Tue, Jan 16, 2024 at 11:16 PM Miguel Ojeda
<[email protected]> wrote:
>
> On Tue, Jan 16, 2024 at 10:31 AM Huacai Chen <[email protected]> wrote:
> >
> > OK, since Linus said the merge window is paused now, I rebase and
> > retag my tree and the Rust commit is like this, I think this is
> > perfect now?
> >
> > https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson.git/commit/?h=loongarch-next&id=706f9e1ab7c7a58d80ef2c87d8720131253a2256
>
> Thanks a lot! That works, yeah.
>
> I also took the chance to build LLVM and QEMU and I tested the tag --
> it seems to work: I see the samples (built-in) printing in the kernel
> log :)
>
> So in case you end up rebasing for another reason and want to add it,
> even if it is a simple check I did:
>
> Tested-by: Miguel Ojeda <[email protected]>
OK, if Xuerui updates this patch, then I will rebase again.
https://lore.kernel.org/loongarch/CAAhV-H7KteJvRVpj3Hz-Ui9VnmijcJq5D1Tb-KJvqTO_+jjp2Q@mail.gmail.com/T/#t

Huacai

>
> Cheers,
> Miguel