* [RFC RESEND 0/2] RISC-V: enable rust @ 2023-02-24 13:50 Conor Dooley 2023-02-24 13:50 ` [RFC RESEND 1/2] scripts: generate_rust_target: enable building on RISC-V Conor Dooley 2023-02-24 13:50 ` [RFC RESEND 2/2] RISC-V: enable building the 64-bit kernels with rust support Conor Dooley 0 siblings, 2 replies; 7+ messages in thread From: Conor Dooley @ 2023-02-24 13:50 UTC (permalink / raw) To: linux-riscv Cc: Conor Dooley, conor, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng, Gary Guo, Björn Roy Baron, Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Nathan Chancellor, Nick Desaulniers, Tom Rix, rust-for-linux, linux-doc, linux-kernel, llvm This is a somewhat blind (and maybe foolish) attempt at enabling Rust for RISC-V. I've tested this on Icicle, and the modules seem to work. I'd like to play around with Rust on RISC-V, but I'm not interested in using downstream kernels, so figured I should try and see what's missing... I've tagged this as RFC in case I've missed some "WAaaaa you can't do this" somewhere :) Thanks, Conor. Changes in RFC-RESEND: - fixed the asymmetrical additions in the Makefile bits - added cc-cover to my git send-email command... CC: Miguel Ojeda <ojeda@kernel.org> CC: Alex Gaynor <alex.gaynor@gmail.com> CC: Wedson Almeida Filho <wedsonaf@gmail.com> CC: Boqun Feng <boqun.feng@gmail.com> CC: Gary Guo <gary@garyguo.net> CC: Björn Roy Baron <bjorn3_gh@protonmail.com> CC: Jonathan Corbet <corbet@lwn.net> CC: Paul Walmsley <paul.walmsley@sifive.com> CC: Palmer Dabbelt <palmer@dabbelt.com> CC: Nathan Chancellor <nathan@kernel.org> CC: Nick Desaulniers <ndesaulniers@google.com> CC: Tom Rix <trix@redhat.com> CC: rust-for-linux@vger.kernel.org CC: linux-doc@vger.kernel.org CC: linux-kernel@vger.kernel.org CC: linux-riscv@lists.infradead.org CC: llvm@lists.linux.dev Miguel Ojeda (2): scripts: generate_rust_target: enable building on RISC-V RISC-V: enable building the 64-bit kernels with rust support Documentation/rust/arch-support.rst | 2 ++ arch/riscv/Kconfig | 1 + arch/riscv/Makefile | 3 ++- scripts/generate_rust_target.rs | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) -- 2.39.2 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC RESEND 1/2] scripts: generate_rust_target: enable building on RISC-V 2023-02-24 13:50 [RFC RESEND 0/2] RISC-V: enable rust Conor Dooley @ 2023-02-24 13:50 ` Conor Dooley 2023-02-24 13:50 ` [RFC RESEND 2/2] RISC-V: enable building the 64-bit kernels with rust support Conor Dooley 1 sibling, 0 replies; 7+ messages in thread From: Conor Dooley @ 2023-02-24 13:50 UTC (permalink / raw) To: linux-riscv Cc: Conor Dooley, conor, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng, Gary Guo, Björn Roy Baron, Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Nathan Chancellor, Nick Desaulniers, Tom Rix, rust-for-linux, linux-doc, linux-kernel, llvm From: Miguel Ojeda <ojeda@kernel.org> Add the required bits from rust-for-linux to enable generating a RISC-V target for rust. Signed-off-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Conor Dooley <conor.dooley@microchip.com> --- scripts/generate_rust_target.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/generate_rust_target.rs b/scripts/generate_rust_target.rs index 3c6cbe2b278d..72428fc66502 100644 --- a/scripts/generate_rust_target.rs +++ b/scripts/generate_rust_target.rs @@ -161,6 +161,25 @@ fn main() { ts.push("features", features); ts.push("llvm-target", "x86_64-linux-gnu"); ts.push("target-pointer-width", "64"); + } else if cfg.has("RISCV") { + if cfg.has("64BIT") { + ts.push("arch", "riscv64"); + ts.push("data-layout", "e-m:e-p:64:64-i64:64-i128:128-n64-S128"); + ts.push("llvm-target", "riscv64-linux-gnu"); + ts.push("target-pointer-width", "64"); + } else { + ts.push("arch", "riscv32"); + ts.push("data-layout", "e-m:e-p:32:32-i64:64-n32-S128"); + ts.push("llvm-target", "riscv32-linux-gnu"); + ts.push("target-pointer-width", "32"); + } + ts.push("code-model", "medium"); + ts.push("disable-redzone", true); + let mut features = "+m,+a".to_string(); + if cfg.has("RISCV_ISA_C") { + features += ",+c"; + } + ts.push("features", features); } else { panic!("Unsupported architecture"); } -- 2.39.2 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RFC RESEND 2/2] RISC-V: enable building the 64-bit kernels with rust support 2023-02-24 13:50 [RFC RESEND 0/2] RISC-V: enable rust Conor Dooley 2023-02-24 13:50 ` [RFC RESEND 1/2] scripts: generate_rust_target: enable building on RISC-V Conor Dooley @ 2023-02-24 13:50 ` Conor Dooley 2023-02-24 14:57 ` Nathan Chancellor 2023-02-24 20:45 ` Miguel Ojeda 1 sibling, 2 replies; 7+ messages in thread From: Conor Dooley @ 2023-02-24 13:50 UTC (permalink / raw) To: linux-riscv Cc: Conor Dooley, conor, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng, Gary Guo, Björn Roy Baron, Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Nathan Chancellor, Nick Desaulniers, Tom Rix, rust-for-linux, linux-doc, linux-kernel, llvm From: Miguel Ojeda <ojeda@kernel.org> The rust modules work on 64-bit RISC-V, with no twiddling required. Select HAS_RUST and provide the required flags to kbuild so that the modules can be used. 32-bit is broken in core rust code, so support is limited to 64-bit only: ld.lld: error: undefined symbol: __udivdi3 Signed-off-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Conor Dooley <conor.dooley@microchip.com> --- Documentation/rust/arch-support.rst | 2 ++ arch/riscv/Kconfig | 1 + arch/riscv/Makefile | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Documentation/rust/arch-support.rst b/Documentation/rust/arch-support.rst index 6982b63775da..197919158596 100644 --- a/Documentation/rust/arch-support.rst +++ b/Documentation/rust/arch-support.rst @@ -15,5 +15,7 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file. ============ ================ ============================================== Architecture Level of support Constraints ============ ================ ============================================== +``riscv`` Maintained ``rv64`` only. +============ ================ ============================================== ``x86`` Maintained ``x86_64`` only. ============ ================ ============================================== diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 81eb031887d2..73174157212d 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -115,6 +115,7 @@ config RISCV select HAVE_POSIX_CPU_TIMERS_TASK_WORK select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RSEQ + select HAVE_RUST if 64BIT select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS select IRQ_DOMAIN diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile index 76989561566b..0d6fc4e25221 100644 --- a/arch/riscv/Makefile +++ b/arch/riscv/Makefile @@ -29,8 +29,8 @@ ifeq ($(CONFIG_ARCH_RV64I),y) KBUILD_CFLAGS += -mabi=lp64 KBUILD_AFLAGS += -mabi=lp64 - KBUILD_LDFLAGS += -melf64lriscv + KBUILD_RUSTFLAGS += -Ctarget-cpu=generic-rv64 else BITS := 32 UTS_MACHINE := riscv32 @@ -38,6 +38,7 @@ else KBUILD_CFLAGS += -mabi=ilp32 KBUILD_AFLAGS += -mabi=ilp32 KBUILD_LDFLAGS += -melf32lriscv + KBUILD_RUSTFLAGS += -Ctarget-cpu=generic-rv32 endif ifeq ($(CONFIG_LD_IS_LLD),y) -- 2.39.2 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [RFC RESEND 2/2] RISC-V: enable building the 64-bit kernels with rust support 2023-02-24 13:50 ` [RFC RESEND 2/2] RISC-V: enable building the 64-bit kernels with rust support Conor Dooley @ 2023-02-24 14:57 ` Nathan Chancellor 2023-02-24 15:27 ` Conor Dooley 2023-02-24 20:45 ` Miguel Ojeda 1 sibling, 1 reply; 7+ messages in thread From: Nathan Chancellor @ 2023-02-24 14:57 UTC (permalink / raw) To: Conor Dooley Cc: linux-riscv, conor, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng, Gary Guo, Björn Roy Baron, Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Nick Desaulniers, Tom Rix, rust-for-linux, linux-doc, linux-kernel, llvm Hi Conor, On Fri, Feb 24, 2023 at 01:50:44PM +0000, Conor Dooley wrote: > From: Miguel Ojeda <ojeda@kernel.org> > > The rust modules work on 64-bit RISC-V, with no twiddling required. > Select HAS_RUST and provide the required flags to kbuild so that the > modules can be used. > 32-bit is broken in core rust code, so support is limited to 64-bit > only: ld.lld: error: undefined symbol: __udivdi3 > > Signed-off-by: Miguel Ojeda <ojeda@kernel.org> > Signed-off-by: Conor Dooley <conor.dooley@microchip.com> > --- > Documentation/rust/arch-support.rst | 2 ++ > arch/riscv/Kconfig | 1 + > arch/riscv/Makefile | 3 ++- > 3 files changed, 5 insertions(+), 1 deletion(-) > > diff --git a/Documentation/rust/arch-support.rst b/Documentation/rust/arch-support.rst > index 6982b63775da..197919158596 100644 > --- a/Documentation/rust/arch-support.rst > +++ b/Documentation/rust/arch-support.rst > @@ -15,5 +15,7 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file. > ============ ================ ============================================== > Architecture Level of support Constraints > ============ ================ ============================================== > +``riscv`` Maintained ``rv64`` only. > +============ ================ ============================================== > ``x86`` Maintained ``x86_64`` only. > ============ ================ ============================================== > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > index 81eb031887d2..73174157212d 100644 > --- a/arch/riscv/Kconfig > +++ b/arch/riscv/Kconfig > @@ -115,6 +115,7 @@ config RISCV > select HAVE_POSIX_CPU_TIMERS_TASK_WORK > select HAVE_REGS_AND_STACK_ACCESS_API > select HAVE_RSEQ > + select HAVE_RUST if 64BIT Just a small drive by comment, you have 'if 64BIT' here... > select HAVE_STACKPROTECTOR > select HAVE_SYSCALL_TRACEPOINTS > select IRQ_DOMAIN > diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile > index 76989561566b..0d6fc4e25221 100644 > --- a/arch/riscv/Makefile > +++ b/arch/riscv/Makefile > @@ -29,8 +29,8 @@ ifeq ($(CONFIG_ARCH_RV64I),y) > > KBUILD_CFLAGS += -mabi=lp64 > KBUILD_AFLAGS += -mabi=lp64 > - > KBUILD_LDFLAGS += -melf64lriscv > + KBUILD_RUSTFLAGS += -Ctarget-cpu=generic-rv64 > else > BITS := 32 > UTS_MACHINE := riscv32 > @@ -38,6 +38,7 @@ else > KBUILD_CFLAGS += -mabi=ilp32 > KBUILD_AFLAGS += -mabi=ilp32 > KBUILD_LDFLAGS += -melf32lriscv > + KBUILD_RUSTFLAGS += -Ctarget-cpu=generic-rv32 but also add KBUILD_RUSTFLAGS for the !64BIT case. Seems like one of those can be removed. > endif > > ifeq ($(CONFIG_LD_IS_LLD),y) > -- > 2.39.2 > Cheers, Nathan ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC RESEND 2/2] RISC-V: enable building the 64-bit kernels with rust support 2023-02-24 14:57 ` Nathan Chancellor @ 2023-02-24 15:27 ` Conor Dooley 0 siblings, 0 replies; 7+ messages in thread From: Conor Dooley @ 2023-02-24 15:27 UTC (permalink / raw) To: Nathan Chancellor Cc: linux-riscv, conor, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng, Gary Guo, Björn Roy Baron, Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Nick Desaulniers, Tom Rix, rust-for-linux, linux-doc, linux-kernel, llvm [-- Attachment #1: Type: text/plain, Size: 3175 bytes --] On Fri, Feb 24, 2023 at 07:57:13AM -0700, Nathan Chancellor wrote: > Hi Conor, > > On Fri, Feb 24, 2023 at 01:50:44PM +0000, Conor Dooley wrote: > > From: Miguel Ojeda <ojeda@kernel.org> > > > > The rust modules work on 64-bit RISC-V, with no twiddling required. > > Select HAS_RUST and provide the required flags to kbuild so that the > > modules can be used. > > 32-bit is broken in core rust code, so support is limited to 64-bit > > only: ld.lld: error: undefined symbol: __udivdi3 > > > > Signed-off-by: Miguel Ojeda <ojeda@kernel.org> > > Signed-off-by: Conor Dooley <conor.dooley@microchip.com> > > --- > > Documentation/rust/arch-support.rst | 2 ++ > > arch/riscv/Kconfig | 1 + > > arch/riscv/Makefile | 3 ++- > > 3 files changed, 5 insertions(+), 1 deletion(-) > > > > diff --git a/Documentation/rust/arch-support.rst b/Documentation/rust/arch-support.rst > > index 6982b63775da..197919158596 100644 > > --- a/Documentation/rust/arch-support.rst > > +++ b/Documentation/rust/arch-support.rst > > @@ -15,5 +15,7 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file. > > ============ ================ ============================================== > > Architecture Level of support Constraints > > ============ ================ ============================================== > > +``riscv`` Maintained ``rv64`` only. > > +============ ================ ============================================== > > ``x86`` Maintained ``x86_64`` only. > > ============ ================ ============================================== > > diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig > > index 81eb031887d2..73174157212d 100644 > > --- a/arch/riscv/Kconfig > > +++ b/arch/riscv/Kconfig > > @@ -115,6 +115,7 @@ config RISCV > > select HAVE_POSIX_CPU_TIMERS_TASK_WORK > > select HAVE_REGS_AND_STACK_ACCESS_API > > select HAVE_RSEQ > > + select HAVE_RUST if 64BIT > > Just a small drive by comment, you have 'if 64BIT' here... > > > select HAVE_STACKPROTECTOR > > select HAVE_SYSCALL_TRACEPOINTS > > select IRQ_DOMAIN > > diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile > > index 76989561566b..0d6fc4e25221 100644 > > --- a/arch/riscv/Makefile > > +++ b/arch/riscv/Makefile > > @@ -29,8 +29,8 @@ ifeq ($(CONFIG_ARCH_RV64I),y) > > > > KBUILD_CFLAGS += -mabi=lp64 > > KBUILD_AFLAGS += -mabi=lp64 > > - > > KBUILD_LDFLAGS += -melf64lriscv > > + KBUILD_RUSTFLAGS += -Ctarget-cpu=generic-rv64 > > else > > BITS := 32 > > UTS_MACHINE := riscv32 > > @@ -38,6 +38,7 @@ else > > KBUILD_CFLAGS += -mabi=ilp32 > > KBUILD_AFLAGS += -mabi=ilp32 > > KBUILD_LDFLAGS += -melf32lriscv > > + KBUILD_RUSTFLAGS += -Ctarget-cpu=generic-rv32 > > but also add KBUILD_RUSTFLAGS for the !64BIT case. Seems like one of > those can be removed. Yeah & it's ditto for the rv32 handling in 1/2 as well. Ideally there wouldn't be implicit 64-bit division and the "if 64BIT" could go away. I just left things as-lifted, but I'll go drop anything 32-bit related if this series looses the RFC prefix ;) [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC RESEND 2/2] RISC-V: enable building the 64-bit kernels with rust support 2023-02-24 13:50 ` [RFC RESEND 2/2] RISC-V: enable building the 64-bit kernels with rust support Conor Dooley 2023-02-24 14:57 ` Nathan Chancellor @ 2023-02-24 20:45 ` Miguel Ojeda 2023-02-24 21:03 ` Conor Dooley 1 sibling, 1 reply; 7+ messages in thread From: Miguel Ojeda @ 2023-02-24 20:45 UTC (permalink / raw) To: Conor Dooley Cc: linux-riscv, conor, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng, Gary Guo, Björn Roy Baron, Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Nathan Chancellor, Nick Desaulniers, Tom Rix, rust-for-linux, linux-doc, linux-kernel, llvm On Fri, Feb 24, 2023 at 2:51 PM Conor Dooley <conor.dooley@microchip.com> wrote: > > The rust modules work on 64-bit RISC-V, with no twiddling required. > Select HAS_RUST and provide the required flags to kbuild so that the HAS -> HAVE > diff --git a/Documentation/rust/arch-support.rst b/Documentation/rust/arch-support.rst > index 6982b63775da..197919158596 100644 > --- a/Documentation/rust/arch-support.rst > +++ b/Documentation/rust/arch-support.rst > @@ -15,5 +15,7 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file. > ============ ================ ============================================== > Architecture Level of support Constraints > ============ ================ ============================================== > +``riscv`` Maintained ``rv64`` only. > +============ ================ ============================================== > ``x86`` Maintained ``x86_64`` only. I think this separator between rows should not be here (it is not in `rust-for-linux/rust`). Please see https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#simple-tables. Cheers, Miguel ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC RESEND 2/2] RISC-V: enable building the 64-bit kernels with rust support 2023-02-24 20:45 ` Miguel Ojeda @ 2023-02-24 21:03 ` Conor Dooley 0 siblings, 0 replies; 7+ messages in thread From: Conor Dooley @ 2023-02-24 21:03 UTC (permalink / raw) To: Miguel Ojeda Cc: Conor Dooley, linux-riscv, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho, Boqun Feng, Gary Guo, Björn Roy Baron, Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Nathan Chancellor, Nick Desaulniers, Tom Rix, rust-for-linux, linux-doc, linux-kernel, llvm [-- Attachment #1: Type: text/plain, Size: 1171 bytes --] On Fri, Feb 24, 2023 at 09:45:05PM +0100, Miguel Ojeda wrote: > On Fri, Feb 24, 2023 at 2:51 PM Conor Dooley <conor.dooley@microchip.com> wrote: > > diff --git a/Documentation/rust/arch-support.rst b/Documentation/rust/arch-support.rst > > index 6982b63775da..197919158596 100644 > > --- a/Documentation/rust/arch-support.rst > > +++ b/Documentation/rust/arch-support.rst > > @@ -15,5 +15,7 @@ support corresponds to ``S`` values in the ``MAINTAINERS`` file. > > ============ ================ ============================================== > > Architecture Level of support Constraints > > ============ ================ ============================================== > > +``riscv`` Maintained ``rv64`` only. > > +============ ================ ============================================== > > ``x86`` Maintained ``x86_64`` only. > > I think this separator between rows should not be here (it is not in > `rust-for-linux/rust`). Please see > https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#simple-tables. That's what the "let the automation tell me if I messed up rst" approach gets you ;) [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-02-24 21:03 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-02-24 13:50 [RFC RESEND 0/2] RISC-V: enable rust Conor Dooley 2023-02-24 13:50 ` [RFC RESEND 1/2] scripts: generate_rust_target: enable building on RISC-V Conor Dooley 2023-02-24 13:50 ` [RFC RESEND 2/2] RISC-V: enable building the 64-bit kernels with rust support Conor Dooley 2023-02-24 14:57 ` Nathan Chancellor 2023-02-24 15:27 ` Conor Dooley 2023-02-24 20:45 ` Miguel Ojeda 2023-02-24 21:03 ` Conor Dooley
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).