rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Enable initial Rust support
@ 2024-01-06  6:59 WANG Rui
  2024-01-07  1:06 ` kernel test robot
  2024-01-07 14:29 ` Miguel Ojeda
  0 siblings, 2 replies; 7+ messages in thread
From: WANG Rui @ 2024-01-06  6:59 UTC (permalink / raw)
  To: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Huacai Chen,
	Jonathan Corbet
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, WANG Xuerui, rust-for-linux,
	linux-kernel, loongarch, linux-doc, loongson-kernel, WANG Rui

Add initial Rust support for LoongArch.

Signed-off-by: WANG Rui <wangrui@loongson.cn>
---
 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 b91e9ef4d0c2..e89c8b2efbff 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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] LoongArch: Enable initial Rust support
  2024-01-06  6:59 [PATCH] LoongArch: Enable initial Rust support WANG Rui
@ 2024-01-07  1:06 ` kernel test robot
  2024-01-07  2:28   ` Huacai Chen
  2024-01-07 14:29 ` Miguel Ojeda
  1 sibling, 1 reply; 7+ messages in thread
From: kernel test robot @ 2024-01-07  1:06 UTC (permalink / raw)
  To: WANG Rui, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
	Huacai Chen, Jonathan Corbet
  Cc: oe-kbuild-all, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, WANG Xuerui,
	rust-for-linux, linux-kernel, loongarch, linux-doc,
	loongson-kernel, WANG Rui

Hi WANG,

kernel test robot noticed the following build warnings:

[auto build test WARNING on rust/rust-next]
[also build test WARNING on linus/master v6.7-rc8 next-20240105]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/WANG-Rui/LoongArch-Enable-initial-Rust-support/20240106-150902
base:   https://github.com/Rust-for-Linux/linux rust-next
patch link:    https://lore.kernel.org/r/20240106065941.180796-1-wangrui%40loongson.cn
patch subject: [PATCH] LoongArch: Enable initial Rust support
reproduce: (https://download.01.org/0day-ci/archive/20240107/202401070815.6tdJWFme-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202401070815.6tdJWFme-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> Documentation/rust/arch-support.rst:18: WARNING: Malformed table.

vim +18 Documentation/rust/arch-support.rst

    14	
    15	============  ================  ==============================================
    16	Architecture  Level of support  Constraints
    17	============  ================  ==============================================
  > 18	``loongarch`` Maintained

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] LoongArch: Enable initial Rust support
  2024-01-07  1:06 ` kernel test robot
@ 2024-01-07  2:28   ` Huacai Chen
  0 siblings, 0 replies; 7+ messages in thread
From: Huacai Chen @ 2024-01-07  2:28 UTC (permalink / raw)
  To: kernel test robot
  Cc: WANG Rui, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
	Jonathan Corbet, oe-kbuild-all, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	WANG Xuerui, rust-for-linux, linux-kernel, loongarch, linux-doc,
	loongson-kernel

On Sun, Jan 7, 2024 at 9:06 AM kernel test robot <lkp@intel.com> wrote:
>
> Hi WANG,
>
> kernel test robot noticed the following build warnings:
>
> [auto build test WARNING on rust/rust-next]
> [also build test WARNING on linus/master v6.7-rc8 next-20240105]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url:    https://github.com/intel-lab-lkp/linux/commits/WANG-Rui/LoongArch-Enable-initial-Rust-support/20240106-150902
> base:   https://github.com/Rust-for-Linux/linux rust-next
> patch link:    https://lore.kernel.org/r/20240106065941.180796-1-wangrui%40loongson.cn
> patch subject: [PATCH] LoongArch: Enable initial Rust support
> reproduce: (https://download.01.org/0day-ci/archive/20240107/202401070815.6tdJWFme-lkp@intel.com/reproduce)
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202401070815.6tdJWFme-lkp@intel.com/
>
> All warnings (new ones prefixed by >>):
>
> >> Documentation/rust/arch-support.rst:18: WARNING: Malformed table.
>
> vim +18 Documentation/rust/arch-support.rst
>
>     14
>     15  ============  ================  ==============================================
>     16  Architecture  Level of support  Constraints
>     17  ============  ================  ==============================================
>   > 18  ``loongarch`` Maintained
I think we can put a "none." or just a "-" below "Constraints" to fix
the warning.

Huacai
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] LoongArch: Enable initial Rust support
  2024-01-06  6:59 [PATCH] LoongArch: Enable initial Rust support WANG Rui
  2024-01-07  1:06 ` kernel test robot
@ 2024-01-07 14:29 ` Miguel Ojeda
  2024-01-08  3:21   ` WANG Rui
  1 sibling, 1 reply; 7+ messages in thread
From: Miguel Ojeda @ 2024-01-07 14:29 UTC (permalink / raw)
  To: WANG Rui
  Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Huacai Chen,
	Jonathan Corbet, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, WANG Xuerui,
	rust-for-linux, linux-kernel, loongarch, linux-doc,
	loongson-kernel

On Sat, Jan 6, 2024 at 8:04 AM WANG Rui <wangrui@loongson.cn> wrote:
>
>  ============  ================  ==============================================
>  Architecture  Level of support  Constraints
>  ============  ================  ==============================================
> +``loongarch`` Maintained

On top of what Huacai said, it would be nice to add another character
and realign the table so that `loongarch` it doesn't overflow (perhaps
best done in an additional, previous patch).

> +    } else if cfg.has("LOONGARCH") {

Would it be possible to do it without a custom target in
`scripts/generate_rust_target.rs`? If it is not possible (e.g. there
is something that you cannot tweak otherwise on top of a built-in
target via the CLI flags), it is fine to use a custom target for the
moment.

For instance, this is how ARM is doing it:
https://lore.kernel.org/rust-for-linux/20231020155056.3495121-1-Jamie.Cunliffe@arm.com/

Thanks!

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] LoongArch: Enable initial Rust support
  2024-01-07 14:29 ` Miguel Ojeda
@ 2024-01-08  3:21   ` WANG Rui
  2024-01-10 11:20     ` Miguel Ojeda
  0 siblings, 1 reply; 7+ messages in thread
From: WANG Rui @ 2024-01-08  3:21 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Huacai Chen,
	Jonathan Corbet, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, WANG Xuerui,
	rust-for-linux, linux-kernel, loongarch, linux-doc,
	loongson-kernel

Hello,

On Sun, Jan 7, 2024 at 10:29 PM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Sat, Jan 6, 2024 at 8:04 AM WANG Rui <wangrui@loongson.cn> wrote:
> >
> >  ============  ================  ==============================================
> >  Architecture  Level of support  Constraints
> >  ============  ================  ==============================================
> > +``loongarch`` Maintained
>
> On top of what Huacai said, it would be nice to add another character
> and realign the table so that `loongarch` it doesn't overflow (perhaps
> best done in an additional, previous patch).

Thanks Huacai, Miguel.

>
> > +    } else if cfg.has("LOONGARCH") {
>
> Would it be possible to do it without a custom target in
> `scripts/generate_rust_target.rs`? If it is not possible (e.g. there
> is something that you cannot tweak otherwise on top of a built-in
> target via the CLI flags), it is fine to use a custom target for the
> moment.
>
> For instance, this is how ARM is doing it:
> https://lore.kernel.org/rust-for-linux/20231020155056.3495121-1-Jamie.Cunliffe@arm.com/
>

Thanks for your comments. I noticed that the refactoring of the build
system to support the use of Rust built-in targets is still ongoing.
Could this take some time? In the meantime, let's proceed with the
generation method.

> Thanks!
>
> Cheers,
> Miguel
>

-- 
Rui


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] LoongArch: Enable initial Rust support
  2024-01-08  3:21   ` WANG Rui
@ 2024-01-10 11:20     ` Miguel Ojeda
  2024-01-11  3:17       ` WANG Rui
  0 siblings, 1 reply; 7+ messages in thread
From: Miguel Ojeda @ 2024-01-10 11:20 UTC (permalink / raw)
  To: WANG Rui
  Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Huacai Chen,
	Jonathan Corbet, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, WANG Xuerui,
	rust-for-linux, linux-kernel, loongarch, linux-doc,
	loongson-kernel

On Mon, Jan 8, 2024 at 4:22 AM WANG Rui <wangrui@loongson.cn> wrote:
>
> Thanks for your comments. I noticed that the refactoring of the build
> system to support the use of Rust built-in targets is still ongoing.
> Could this take some time? In the meantime, let's proceed with the
> generation method.

My pleasure! If you mean the first patch of the arm64 series I linked,
we have been waiting for a while for that to get merged (hopefully
6.9?). So, yeah, as you say, it is probably best to continue with this
and then you can change it later after the arm64 series lands. Thanks!

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] LoongArch: Enable initial Rust support
  2024-01-10 11:20     ` Miguel Ojeda
@ 2024-01-11  3:17       ` WANG Rui
  0 siblings, 0 replies; 7+ messages in thread
From: WANG Rui @ 2024-01-11  3:17 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Huacai Chen,
	Jonathan Corbet, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, WANG Xuerui,
	rust-for-linux, linux-kernel, loongarch, linux-doc,
	loongson-kernel

On Wed, Jan 10, 2024 at 7:21 PM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Mon, Jan 8, 2024 at 4:22 AM WANG Rui <wangrui@loongson.cn> wrote:
> >
> > Thanks for your comments. I noticed that the refactoring of the build
> > system to support the use of Rust built-in targets is still ongoing.
> > Could this take some time? In the meantime, let's proceed with the
> > generation method.
>
> My pleasure! If you mean the first patch of the arm64 series I linked,
> we have been waiting for a while for that to get merged (hopefully
> 6.9?). So, yeah, as you say, it is probably best to continue with this
> and then you can change it later after the arm64 series lands. Thanks!

Thanks. I'll do it.

Regards,
Rui

>
> Cheers,
> Miguel
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-01-11  3:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-06  6:59 [PATCH] LoongArch: Enable initial Rust support WANG Rui
2024-01-07  1:06 ` kernel test robot
2024-01-07  2:28   ` Huacai Chen
2024-01-07 14:29 ` Miguel Ojeda
2024-01-08  3:21   ` WANG Rui
2024-01-10 11:20     ` Miguel Ojeda
2024-01-11  3:17       ` WANG Rui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).