rust: support for shadow call stack sanitizer
Alice Ryhl
reviewerPATCH v5 1/1 rust: support for shadow call stack sanitizer
This patch adds all of the flags that are needed to support the shadow call stack (SCS) sanitizer with Rust, and updates Kconfig to allow configurations that work.
The -Zfixed-x18 flag is required to use SCS on arm64, and requires rustc version 1.80.0 or greater. This restriction is reflected in Kconfig.
When CONFIG_DYNAMIC_SCS is enabled, the build will be configured to include unwind tables in the build artifacts. Dynamic SCS uses the unwind tables at boot to find all places that need to be patched. The -Cforce-unwind-tables=y flag ensures that unwind tables are available for Rust code.
In non-dynamic mode, the -Zsanitizer=shadow-call-stack flag is what enables the SCS sanitizer.
At the time of writing, all released rustc versions up to and including 1.81 incorrectly think that the Rust targets aarch64-unknown-none and riscv64-unknown-none-elf don't support -Zsanitizer=shadow-call-stack, so the build will fail if you enable shadow call stack in non-dynamic mode. See [1] for the relevant feature request. To avoid this compilation failure, Kconfig is set up to reject such configurations.
Note that because these configurations are rejected, this patch only allows SCS to be used with arm64 and not on riscv. However, once [1] is implemented, I will submit a follow-up patch that allows configurations without UNWIND_PATCH_PAC_INTO_SCS on sufficiently new compilers. That patch will implicitly allow SCS to be enabled on riscv, but this is okay because unlike arm64, riscv does not need any flags for rustc beyond -Zsanitizer=shadow-call-stack.
It is possible to avoid the requirement of rustc 1.80.0 by using -Ctarget-feature=+reserve-x18 instead of -Zfixed-x18. However, this flag emits a warning during the build, so this patch does not add support for using it and instead requires 1.80.0 or greater.
The depends on clause is placed on config RUST to avoid a situation where enabling Rust silently turns off the sanitizer. Instead, turning on the sanitizer results in Rust being disabled. We generally do not want changes to CONFIG_RUST to result in any mitigations being changed or turned off.
---
This patch depends on the next version of [1], which Miguel will send soon.
---
Changes in v5:
- Rebase series on v6.11-rc2.
- The first patch is no longer included as it was merged in v6.11-rc2.
- The commit message is rewritten from scratch.
- Link to v4: https://lore.kernel.org/r/[email protected]
Changes in v4:
- Move depends on to CONFIG_RUST.
- Rewrite commit messages to include more context.
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Use -Zfixed-x18.
- Add logic to reject unsupported rustc versions.
- Also include a fix to be backported.
- Link to v2: https://lore.kernel.org/rust-for-linux/[email protected]/
Changes in v2:
- Add -Cforce-unwind-tables flag.
- Link to v1: https://lore.kernel.org/rust-for-linux/[email protected]/
--- Makefile | 1 + arch/arm64/Makefile | 3 +++ init/Kconfig | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-)
Makefile +1 -0
@@ -927,6 +927,7 @@ ifdef CONFIG_SHADOW_CALL_STACK ifndef CONFIG_DYNAMIC_SCS CC_FLAGS_SCS := -fsanitize=shadow-call-stack KBUILD_CFLAGS += $(CC_FLAGS_SCS) +KBUILD_RUSTFLAGS += -Zsanitizer=shadow-call-stack endif export CC_FLAGS_SCS endif
arch/arm64/Makefile +3 -0
@@ -57,9 +57,11 @@ KBUILD_AFLAGS += $(call cc-option,-mabi=lp64) ifneq ($(CONFIG_UNWIND_TABLES),y) KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables KBUILD_AFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables +KBUILD_RUSTFLAGS += -Cforce-unwind-tables=n else KBUILD_CFLAGS += -fasynchronous-unwind-tables KBUILD_AFLAGS += -fasynchronous-unwind-tables +KBUILD_RUSTFLAGS += -Cforce-unwind-tables=y -Zuse-sync-unwind=n endif ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)
@@ -114,6 +116,7 @@ endif ifeq ($(CONFIG_SHADOW_CALL_STACK), y) KBUILD_CFLAGS += -ffixed-x18 +KBUILD_RUSTFLAGS += -Zfixed-x18 endif ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
init/Kconfig +1 -1
@@ -1909,7 +1909,7 @@ config RUST depends on !MODVERSIONS depends on !GCC_PLUGINS depends on !RANDSTRUCT - depends on !SHADOW_CALL_STACK + depends on !SHADOW_CALL_STACK || RUSTC_VERSION >= 108000 && UNWIND_PATCH_PAC_INTO_SCS depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE help Enables Rust support in the kernel.
---
base-commit: 5953fd808fca8116a91678ee5fac00fc198ad93d
change-id: 20240304-shadow-call-stack-9c197a4361d9
Best regards,
Signature · 1 line
Alice Ryhl <[email protected]>
Quoted 36 lines · Alice Ryhl
This patch adds all of the flags that are needed to support the shadow call stack (SCS) sanitizer with Rust, and updates
Kconfigto allow configurations that work.The -Zfixed-x18 flag is required to use SCS on arm64, and requires rustc version 1.80.0 or greater. This restriction is reflected in
Kconfig.When
CONFIG_DYNAMIC_SCSis enabled, the build will be configured to include unwind tables in the build artifacts. Dynamic SCS uses the unwind tables at boot to find all places that need to be patched. The -Cforce-unwind-tables=y flag ensures that unwind tables are available for Rust code.In non-dynamic mode, the -Zsanitizer=shadow-call-stack flag is what enables the SCS sanitizer.
At the time of writing, all released rustc versions up to and including 1.81 incorrectly think that the Rust targets aarch64-unknown-none and riscv64-unknown-none-elf don't support -Zsanitizer=shadow-call-stack, so the build will fail if you enable shadow call stack in non-dynamic mode. See [1] for the relevant feature request. To avoid this compilation failure,
Kconfigis set up to reject such configurations.Note that because these configurations are rejected, this patch only allows SCS to be used with arm64 and not on riscv. However, once [1] is implemented, I will submit a follow-up patch that allows configurations without
UNWIND_PATCH_PAC_INTO_SCSon sufficiently new compilers. That patch will implicitly allow SCS to be enabled on riscv, but this is okay because unlike arm64, riscv does not need any flags for rustc beyond -Zsanitizer=shadow-call-stack.It is possible to avoid the requirement of rustc 1.80.0 by using -Ctarget-feature=+reserve-x18 instead of -Zfixed-x18. However, this flag emits a warning during the build, so this patch does not add support for using it and instead requires 1.80.0 or greater.
Quoted 8 lines
The
depends onclause is placed onconfig RUSTto avoid a situation where enabling Rust silently turns off the sanitizer. Instead, turning on the sanitizer results in Rust being disabled. We generally do not want changes toCONFIG_RUSTto result in any mitigations being changed or turned off.Signed-off-by Alice Ryhl <[email protected]>
I'd like to make sure Ard is happy with this, but from what I can see it looks correct. Thanks!
Signature · 1 line
Kees Cook
Quoted 36 lines · Alice Ryhl
This patch adds all of the flags that are needed to support the shadow call stack (SCS) sanitizer with Rust, and updates
Kconfigto allow configurations that work.The -Zfixed-x18 flag is required to use SCS on arm64, and requires rustc version 1.80.0 or greater. This restriction is reflected in
Kconfig.When
CONFIG_DYNAMIC_SCSis enabled, the build will be configured to include unwind tables in the build artifacts. Dynamic SCS uses the unwind tables at boot to find all places that need to be patched. The -Cforce-unwind-tables=y flag ensures that unwind tables are available for Rust code.In non-dynamic mode, the -Zsanitizer=shadow-call-stack flag is what enables the SCS sanitizer.
At the time of writing, all released rustc versions up to and including 1.81 incorrectly think that the Rust targets aarch64-unknown-none and riscv64-unknown-none-elf don't support -Zsanitizer=shadow-call-stack, so the build will fail if you enable shadow call stack in non-dynamic mode. See [1] for the relevant feature request. To avoid this compilation failure,
Kconfigis set up to reject such configurations.Note that because these configurations are rejected, this patch only allows SCS to be used with arm64 and not on riscv. However, once [1] is implemented, I will submit a follow-up patch that allows configurations without
UNWIND_PATCH_PAC_INTO_SCSon sufficiently new compilers. That patch will implicitly allow SCS to be enabled on riscv, but this is okay because unlike arm64, riscv does not need any flags for rustc beyond -Zsanitizer=shadow-call-stack.It is possible to avoid the requirement of rustc 1.80.0 by using -Ctarget-feature=+reserve-x18 instead of -Zfixed-x18. However, this flag emits a warning during the build, so this patch does not add support for using it and instead requires 1.80.0 or greater.
Quoted 8 lines
The
depends onclause is placed onconfig RUSTto avoid a situation where enabling Rust silently turns off the sanitizer. Instead, turning on the sanitizer results in Rust being disabled. We generally do not want changes toCONFIG_RUSTto result in any mitigations being changed or turned off.Signed-off-by Alice Ryhl <[email protected]>
Looks good to me, thanks!
Sami
Will Deacon
maintainerQuoted 3 lines · Alice Ryhl
This patch adds all of the flags that are needed to support the shadow call stack (SCS) sanitizer with Rust, and updates
Kconfigto allow configurations that work.
Minor nit, but some folks have allergic reactions to "This patch". See:
https://docs.kernel.org/process/submitting-patches.html#describe-your-changes
I think the commit message is much better now, though, so thank you for adding so much more detail for v5. If you end up respinning anyway, you could move this all to the imperative.
Quoted 46 lines
Makefile | 1 + arch/arm64/Makefile | 3 +++ init/Kconfig | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-)Makefile +1
-0@@ -927,6 +927,7 @@ ifdef CONFIG_SHADOW_CALL_STACK ifndef CONFIG_DYNAMIC_SCS CC_FLAGS_SCS := -fsanitize=shadow-call-stack KBUILD_CFLAGS += $(CC_FLAGS_SCS) +KBUILD_RUSTFLAGS += -Zsanitizer=shadow-call-stack endif export CC_FLAGS_SCS endifarch/arm64/Makefile +3
-0@@ -57,9 +57,11 @@ KBUILD_AFLAGS += $(call cc-option,-mabi=lp64) ifneq ($(CONFIG_UNWIND_TABLES),y) KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables KBUILD_AFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables +KBUILD_RUSTFLAGS += -Cforce-unwind-tables=n else KBUILD_CFLAGS += -fasynchronous-unwind-tables KBUILD_AFLAGS += -fasynchronous-unwind-tables +KBUILD_RUSTFLAGS += -Cforce-unwind-tables=y -Zuse-sync-unwind=n endif ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)@@ -114,6 +116,7 @@ endif ifeq ($(CONFIG_SHADOW_CALL_STACK), y) KBUILD_CFLAGS += -ffixed-x18 +KBUILD_RUSTFLAGS += -Zfixed-x18 endif ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)init/Kconfig +0
-0
init/Kconfig config RUST · line 1912
Quoted 5 lines
init/Kconfig +1
-1@@ -1909,7 +1909,7 @@ config RUST depends on !MODVERSIONS depends on !GCC_PLUGINS depends on !RANDSTRUCT - depends on !SHADOW_CALL_STACK + depends on !SHADOW_CALL_STACK || RUSTC_VERSION >= 108000 && UNWIND_PATCH_PAC_INTO_SCS
Sorry, I didn't spot this in v4, but since UNWIND_PATCH_PAC_INTO_SCS is specific to arm64 and the only other architecture selecting ARCH_SUPPORTS_SHADOW_CALL_STACK is riscv, I can't help but feel it would be cleaner to move this logic into the arch code selecting HAVE_RUST.
That is, it's up to the architecture to make sure that it has whatever it needs for SCS to work with Rust if it claims to support Rust.
What do you think?
Will
Alice Ryhl
reviewerQuoted 6 lines · Will Deacon
Quoted 3 lines · Alice Ryhl
This patch adds all of the flags that are needed to support the shadow call stack (SCS) sanitizer with Rust, and updates
Kconfigto allow configurations that work.
Quoted 8 lines
Minor nit, but some folks have allergic reactions to "This patch". See:
https://docs.kernel.org/process/submitting-patches.html#describe-your-changes
I think the commit message is much better now, though, so thank you for adding so much more detail for v5. If you end up respinning anyway, you could move this all to the imperative.
Ah, yeah, I keep forgetting about this. I'll change it to imperative if I send another version.
Quoted 57 lines
Quoted 46 lines
Makefile | 1 + arch/arm64/Makefile | 3 +++ init/Kconfig | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-)Makefile +1
-0@@ -927,6 +927,7 @@ ifdef CONFIG_SHADOW_CALL_STACK ifndef CONFIG_DYNAMIC_SCS CC_FLAGS_SCS := -fsanitize=shadow-call-stack KBUILD_CFLAGS += $(CC_FLAGS_SCS) +KBUILD_RUSTFLAGS += -Zsanitizer=shadow-call-stack endif export CC_FLAGS_SCS endifarch/arm64/Makefile +3
-0@@ -57,9 +57,11 @@ KBUILD_AFLAGS += $(call cc-option,-mabi=lp64) ifneq ($(CONFIG_UNWIND_TABLES),y) KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables KBUILD_AFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables +KBUILD_RUSTFLAGS += -Cforce-unwind-tables=n else KBUILD_CFLAGS += -fasynchronous-unwind-tables KBUILD_AFLAGS += -fasynchronous-unwind-tables +KBUILD_RUSTFLAGS += -Cforce-unwind-tables=y -Zuse-sync-unwind=n endif ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y)@@ -114,6 +116,7 @@ endif ifeq ($(CONFIG_SHADOW_CALL_STACK), y) KBUILD_CFLAGS += -ffixed-x18 +KBUILD_RUSTFLAGS += -Zfixed-x18 endif ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)init/Kconfig +0
-0init/Kconfig config RUST · line 1912
Quoted 5 lines
init/Kconfig +1
-1@@ -1909,7 +1909,7 @@ config RUST depends on !MODVERSIONS depends on !GCC_PLUGINS depends on !RANDSTRUCT - depends on !SHADOW_CALL_STACK + depends on !SHADOW_CALL_STACK || RUSTC_VERSION >= 108000 && UNWIND_PATCH_PAC_INTO_SCSSorry, I didn't spot this in v4, but since
UNWIND_PATCH_PAC_INTO_SCSis specific to arm64 and the only other architecture selectingARCH_SUPPORTS_SHADOW_CALL_STACKis riscv, I can't help but feel it would be cleaner to move this logic into the arch code selectingHAVE_RUST.
Quoted 4 lines
That is, it's up to the architecture to make sure that it has whatever it needs for SCS to work with Rust if it claims to support Rust.
What do you think?
The select RUST if ... is going to get really complicated if we apply that rule in general. Having options here allows us to split them across several depends on clauses. I'm not sure it will even work, I had issues with cyclic Kconfig errors previously. I also don't think it's unreasonable for the architecture to say it supports both options when it really does support both; they are just mutually exclusive. I also think there is value in having all of the options that Rust doesn't work with in one place.
So I'd like to keep it as-is.
Alice
Will Deacon
maintainerQuoted 23 lines · Alice Ryhl
Quoted 17 lines · Will Deacon
init/Kconfig config RUST · line 1912
Quoted 10 lines · Alice Ryhl
init/Kconfig +1
-1@@ -1909,7 +1909,7 @@ config RUST depends on !MODVERSIONS depends on !GCC_PLUGINS depends on !RANDSTRUCT - depends on !SHADOW_CALL_STACK + depends on !SHADOW_CALL_STACK || RUSTC_VERSION >= 108000 && UNWIND_PATCH_PAC_INTO_SCSSorry, I didn't spot this in v4, but since
UNWIND_PATCH_PAC_INTO_SCSis specific to arm64 and the only other architecture selectingARCH_SUPPORTS_SHADOW_CALL_STACKis riscv, I can't help but feel it would be cleaner to move this logic into the arch code selectingHAVE_RUST.Quoted 4 lines
That is, it's up to the architecture to make sure that it has whatever it needs for SCS to work with Rust if it claims to support Rust.
What do you think?
Quoted 8 lines
The
select RUST if ...is going to get really complicated if we apply that rule in general. Having options here allows us to split them across severaldepends onclauses. I'm not sure it will even work, I had issues with cyclicKconfigerrors previously. I also don't think it's unreasonable for the architecture to say it supports both options when it really does support both; they are just mutually exclusive. I also think there is value in having all of the options that Rust doesn't work with in one place.
I'm not sure I follow why this will get really complicated. Isn't it as straightforward as the diff below, or did I miss something?
Will
--->8
arch/arm64/Kconfig +6 -1
@@ -231,7 +231,7 @@ config ARM64 select HAVE_FUNCTION_ARG_ACCESS_API select MMU_GATHER_RCU_TABLE_FREE select HAVE_RSEQ - select HAVE_RUST if CPU_LITTLE_ENDIAN + select HAVE_RUST if RUSTC_SUPPORTS_ARM64 select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS select HAVE_KPROBES
@@ -265,6 +265,11 @@ config ARM64 help ARM 64-bit (AArch64) Linux support. +config RUSTC_SUPPORTS_ARM64 + bool + depends on CPU_LITTLE_ENDIAN + depends on !SHADOW_CALL_STACK || RUSTC_VERSION >= 108000 && UNWIND_PATCH_PAC_INTO_SC + config CLANG_SUPPORTS_DYNAMIC_FTRACE_WITH_ARGS def_bool CC_IS_CLANG # https://github.com/ClangBuiltLinux/linux/issues/1507
arch/riscv/Kconfig +1 -1
@@ -172,7 +172,7 @@ config RISCV select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RETHOOK if !XIP_KERNEL select HAVE_RSEQ - select HAVE_RUST if 64BIT + select HAVE_RUST if 64BIT && !SHADOW_CALL_STACK select HAVE_SAMPLE_FTRACE_DIRECT select HAVE_SAMPLE_FTRACE_DIRECT_MULTI select HAVE_STACKPROTECTOR
init/Kconfig +0 -1
@@ -1902,7 +1902,6 @@ config RUST depends on !MODVERSIONS depends on !GCC_PLUGINS depends on !RANDSTRUCT - depends on !SHADOW_CALL_STACK depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE help Enables Rust support in the kernel.
Alice Ryhl
reviewerQuoted 34 lines · Will Deacon
Quoted 23 lines · Alice Ryhl
Quoted 17 lines · Will Deacon
init/Kconfig config RUST · line 1912
Quoted 10 lines · Alice Ryhl
init/Kconfig +1
-1@@ -1909,7 +1909,7 @@ config RUST depends on !MODVERSIONS depends on !GCC_PLUGINS depends on !RANDSTRUCT - depends on !SHADOW_CALL_STACK + depends on !SHADOW_CALL_STACK || RUSTC_VERSION >= 108000 && UNWIND_PATCH_PAC_INTO_SCSSorry, I didn't spot this in v4, but since
UNWIND_PATCH_PAC_INTO_SCSis specific to arm64 and the only other architecture selectingARCH_SUPPORTS_SHADOW_CALL_STACKis riscv, I can't help but feel it would be cleaner to move this logic into the arch code selectingHAVE_RUST.Quoted 4 lines
That is, it's up to the architecture to make sure that it has whatever it needs for SCS to work with Rust if it claims to support Rust.
What do you think?
Quoted 8 lines
The
select RUST if ...is going to get really complicated if we apply that rule in general. Having options here allows us to split them across severaldepends onclauses. I'm not sure it will even work, I had issues with cyclicKconfigerrors previously. I also don't think it's unreasonable for the architecture to say it supports both options when it really does support both; they are just mutually exclusive. I also think there is value in having all of the options that Rust doesn't work with in one place.
Quoted 2 lines
I'm not sure I follow why this will get really complicated. Isn't it as straightforward as the diff below, or did I miss something?
Hmm. I tried this but I wasn't able to enable Rust with this setup. Even though the deps of RUSTC_SUPPORTS_ARM64 are ok, it doesn't seem to be enabled and I can't find it in menuconfig. I think we need to have a select RUSTC_SUPPORTS_ARM64 somewhere.
Alice
Quoted 53 lines
--->8
arch/arm64/Kconfig +6
-1@@ -231,7 +231,7 @@ config ARM64 select HAVE_FUNCTION_ARG_ACCESS_API select MMU_GATHER_RCU_TABLE_FREE select HAVE_RSEQ - select HAVE_RUST if CPU_LITTLE_ENDIAN + select HAVE_RUST if RUSTC_SUPPORTS_ARM64 select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS select HAVE_KPROBES@@ -265,6 +265,11 @@ config ARM64 help ARM 64-bit (AArch64) Linux support. +config RUSTC_SUPPORTS_ARM64 + bool + depends on CPU_LITTLE_ENDIAN + depends on !SHADOW_CALL_STACK || RUSTC_VERSION >= 108000 && UNWIND_PATCH_PAC_INTO_SC + config CLANG_SUPPORTS_DYNAMIC_FTRACE_WITH_ARGS def_bool CC_IS_CLANG # https://github.com/ClangBuiltLinux/linux/issues/1507arch/riscv/Kconfig +1
-1@@ -172,7 +172,7 @@ config RISCV select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RETHOOK if !XIP_KERNEL select HAVE_RSEQ - select HAVE_RUST if 64BIT + select HAVE_RUST if 64BIT && !SHADOW_CALL_STACK select HAVE_SAMPLE_FTRACE_DIRECT select HAVE_SAMPLE_FTRACE_DIRECT_MULTI select HAVE_STACKPROTECTORinit/Kconfig +0
-1@@ -1902,7 +1902,6 @@ config RUST depends on !MODVERSIONS depends on !GCC_PLUGINS depends on !RANDSTRUCT - depends on !SHADOW_CALL_STACK depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE help Enables Rust support in the kernel.
Will Deacon
maintainerQuoted 35 lines · Alice Ryhl
Quoted 34 lines · Will Deacon
Quoted 31 lines · Alice Ryhl
Quoted 17 lines · Will Deacon
init/Kconfig config RUST · line 1912
Quoted 10 lines · Alice Ryhl
init/Kconfig +1
-1@@ -1909,7 +1909,7 @@ config RUST depends on !MODVERSIONS depends on !GCC_PLUGINS depends on !RANDSTRUCT - depends on !SHADOW_CALL_STACK + depends on !SHADOW_CALL_STACK || RUSTC_VERSION >= 108000 && UNWIND_PATCH_PAC_INTO_SCSSorry, I didn't spot this in v4, but since
UNWIND_PATCH_PAC_INTO_SCSis specific to arm64 and the only other architecture selectingARCH_SUPPORTS_SHADOW_CALL_STACKis riscv, I can't help but feel it would be cleaner to move this logic into the arch code selectingHAVE_RUST.Quoted 4 lines
That is, it's up to the architecture to make sure that it has whatever it needs for SCS to work with Rust if it claims to support Rust.
What do you think?
The
select RUST if ...is going to get really complicated if we apply that rule in general. Having options here allows us to split them across severaldepends onclauses. I'm not sure it will even work, I had issues with cyclicKconfigerrors previously. I also don't think it's unreasonable for the architecture to say it supports both options when it really does support both; they are just mutually exclusive. I also think there is value in having all of the options that Rust doesn't work with in one place.
Quoted 7 lines
Quoted 2 lines
I'm not sure I follow why this will get really complicated. Isn't it as straightforward as the diff below, or did I miss something?
Hmm. I tried this but I wasn't able to enable Rust with this setup. Even though the deps of
RUSTC_SUPPORTS_ARM64are ok, it doesn't seem to be enabled and I can't find it in menuconfig. I think we need to have aselect RUSTC_SUPPORTS_ARM64somewhere.
Sorry, yes, my diff was a little half-arsed:
Quoted 17 lines
Quoted 17 lines
arch/arm64/Kconfig +1
-1@@ -231,7 +231,7 @@ config ARM64 select HAVE_FUNCTION_ARG_ACCESS_API select MMU_GATHER_RCU_TABLE_FREE select HAVE_RSEQ - select HAVE_RUST if CPU_LITTLE_ENDIAN + select HAVE_RUST if RUSTC_SUPPORTS_ARM64 select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS select HAVE_KPROBES@@ -265,6 +265,11 @@ config ARM64 help ARM 64-bit (AArch64) Linux support.
Quoted 2 lines
arch/arm64/Kconfig config ARM64 · line 269
Quoted 2 lines
arch/arm64/Kconfig +2
-0+config RUSTC_SUPPORTS_ARM64 + bool
This line ^^^ should be 'def_bool y'.
Will
Alice Ryhl
reviewerQuoted 64 lines · Will Deacon
Quoted 35 lines · Alice Ryhl
Quoted 34 lines · Will Deacon
Quoted 31 lines · Alice Ryhl
Quoted 17 lines · Will Deacon
init/Kconfig config RUST · line 1912
Quoted 10 lines · Alice Ryhl
init/Kconfig +1
-1@@ -1909,7 +1909,7 @@ config RUST depends on !MODVERSIONS depends on !GCC_PLUGINS depends on !RANDSTRUCT - depends on !SHADOW_CALL_STACK + depends on !SHADOW_CALL_STACK || RUSTC_VERSION >= 108000 && UNWIND_PATCH_PAC_INTO_SCSSorry, I didn't spot this in v4, but since
UNWIND_PATCH_PAC_INTO_SCSis specific to arm64 and the only other architecture selectingARCH_SUPPORTS_SHADOW_CALL_STACKis riscv, I can't help but feel it would be cleaner to move this logic into the arch code selectingHAVE_RUST.Quoted 4 lines
That is, it's up to the architecture to make sure that it has whatever it needs for SCS to work with Rust if it claims to support Rust.
What do you think?
The
select RUST if ...is going to get really complicated if we apply that rule in general. Having options here allows us to split them across severaldepends onclauses. I'm not sure it will even work, I had issues with cyclicKconfigerrors previously. I also don't think it's unreasonable for the architecture to say it supports both options when it really does support both; they are just mutually exclusive. I also think there is value in having all of the options that Rust doesn't work with in one place.Quoted 7 lines
Quoted 2 lines
I'm not sure I follow why this will get really complicated. Isn't it as straightforward as the diff below, or did I miss something?
Hmm. I tried this but I wasn't able to enable Rust with this setup. Even though the deps of
RUSTC_SUPPORTS_ARM64are ok, it doesn't seem to be enabled and I can't find it in menuconfig. I think we need to have aselect RUSTC_SUPPORTS_ARM64somewhere.Sorry, yes, my diff was a little half-arsed:
Quoted 17 lines
Quoted 17 lines
arch/arm64/Kconfig +1
-1@@ -231,7 +231,7 @@ config ARM64 select HAVE_FUNCTION_ARG_ACCESS_API select MMU_GATHER_RCU_TABLE_FREE select HAVE_RSEQ - select HAVE_RUST if CPU_LITTLE_ENDIAN + select HAVE_RUST if RUSTC_SUPPORTS_ARM64 select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS select HAVE_KPROBES@@ -265,6 +265,11 @@ config ARM64 help ARM 64-bit (AArch64) Linux support.
Quoted 4 lines
Quoted 2 lines
arch/arm64/Kconfig config ARM64 · line 269
Quoted 2 lines
arch/arm64/Kconfig +2
-0+config RUSTC_SUPPORTS_ARM64 + boolThis line ^^^ should be '
def_booly'.
Ah, I see, I guess I learned something today. It also seems to work if I add default y.
I can change it if you think this is better. I still think there's some value in having everything in one place, but it's not a big deal. Either way, it should be temporary for a few kernel releases as we'll eventually only support compiler versions where this works.
Alice
Will Deacon
maintainerQuoted 70 lines · Alice Ryhl
Quoted 64 lines · Will Deacon
Quoted 35 lines · Alice Ryhl
Quoted 34 lines · Will Deacon
Quoted 31 lines · Alice Ryhl
Quoted 17 lines · Will Deacon
init/Kconfig config RUST · line 1912
Quoted 10 lines · Alice Ryhl
init/Kconfig +1
-1@@ -1909,7 +1909,7 @@ config RUST depends on !MODVERSIONS depends on !GCC_PLUGINS depends on !RANDSTRUCT - depends on !SHADOW_CALL_STACK + depends on !SHADOW_CALL_STACK || RUSTC_VERSION >= 108000 && UNWIND_PATCH_PAC_INTO_SCSSorry, I didn't spot this in v4, but since
UNWIND_PATCH_PAC_INTO_SCSis specific to arm64 and the only other architecture selectingARCH_SUPPORTS_SHADOW_CALL_STACKis riscv, I can't help but feel it would be cleaner to move this logic into the arch code selectingHAVE_RUST.Quoted 4 lines
That is, it's up to the architecture to make sure that it has whatever it needs for SCS to work with Rust if it claims to support Rust.
What do you think?
The
select RUST if ...is going to get really complicated if we apply that rule in general. Having options here allows us to split them across severaldepends onclauses. I'm not sure it will even work, I had issues with cyclicKconfigerrors previously. I also don't think it's unreasonable for the architecture to say it supports both options when it really does support both; they are just mutually exclusive. I also think there is value in having all of the options that Rust doesn't work with in one place.Quoted 7 lines
Quoted 2 lines
I'm not sure I follow why this will get really complicated. Isn't it as straightforward as the diff below, or did I miss something?
Hmm. I tried this but I wasn't able to enable Rust with this setup. Even though the deps of
RUSTC_SUPPORTS_ARM64are ok, it doesn't seem to be enabled and I can't find it in menuconfig. I think we need to have aselect RUSTC_SUPPORTS_ARM64somewhere.Sorry, yes, my diff was a little half-arsed:
Quoted 17 lines
Quoted 17 lines
arch/arm64/Kconfig +1
-1@@ -231,7 +231,7 @@ config ARM64 select HAVE_FUNCTION_ARG_ACCESS_API select MMU_GATHER_RCU_TABLE_FREE select HAVE_RSEQ - select HAVE_RUST if CPU_LITTLE_ENDIAN + select HAVE_RUST if RUSTC_SUPPORTS_ARM64 select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS select HAVE_KPROBES@@ -265,6 +265,11 @@ config ARM64 help ARM 64-bit (AArch64) Linux support.Quoted 4 lines
Quoted 2 lines
arch/arm64/Kconfig config ARM64 · line 269
Quoted 2 lines
arch/arm64/Kconfig +2
-0+config RUSTC_SUPPORTS_ARM64 + boolThis line ^^^ should be '
def_booly'.
Quoted 7 lines
Ah, I see, I guess I learned something today. It also seems to work if I add
default y.I can change it if you think this is better. I still think there's some value in having everything in one place, but it's not a big deal. Either way, it should be temporary for a few kernel releases as we'll eventually only support compiler versions where this works.
I do like moving the reference to UNWIND_PATCH_PAC_INTO_SCS into the arch code, so if you could respin along these lines then that would be great.
Thanks,
Will
Alice Ryhl
reviewerQuoted 75 lines · Will Deacon
Quoted 73 lines · Alice Ryhl
Quoted 64 lines · Will Deacon
Quoted 35 lines · Alice Ryhl
Quoted 34 lines · Will Deacon
Quoted 31 lines · Alice Ryhl
Quoted 17 lines · Will Deacon
init/Kconfig config RUST · line 1912
Quoted 10 lines · Alice Ryhl
init/Kconfig +1
-1@@ -1909,7 +1909,7 @@ config RUST depends on !MODVERSIONS depends on !GCC_PLUGINS depends on !RANDSTRUCT - depends on !SHADOW_CALL_STACK + depends on !SHADOW_CALL_STACK || RUSTC_VERSION >= 108000 && UNWIND_PATCH_PAC_INTO_SCSSorry, I didn't spot this in v4, but since
UNWIND_PATCH_PAC_INTO_SCSis specific to arm64 and the only other architecture selectingARCH_SUPPORTS_SHADOW_CALL_STACKis riscv, I can't help but feel it would be cleaner to move this logic into the arch code selectingHAVE_RUST.Quoted 4 lines
That is, it's up to the architecture to make sure that it has whatever it needs for SCS to work with Rust if it claims to support Rust.
What do you think?
The
select RUST if ...is going to get really complicated if we apply that rule in general. Having options here allows us to split them across severaldepends onclauses. I'm not sure it will even work, I had issues with cyclicKconfigerrors previously. I also don't think it's unreasonable for the architecture to say it supports both options when it really does support both; they are just mutually exclusive. I also think there is value in having all of the options that Rust doesn't work with in one place.Quoted 7 lines
Quoted 2 lines
I'm not sure I follow why this will get really complicated. Isn't it as straightforward as the diff below, or did I miss something?
Hmm. I tried this but I wasn't able to enable Rust with this setup. Even though the deps of
RUSTC_SUPPORTS_ARM64are ok, it doesn't seem to be enabled and I can't find it in menuconfig. I think we need to have aselect RUSTC_SUPPORTS_ARM64somewhere.Sorry, yes, my diff was a little half-arsed:
Quoted 17 lines
Quoted 17 lines
arch/arm64/Kconfig +1
-1@@ -231,7 +231,7 @@ config ARM64 select HAVE_FUNCTION_ARG_ACCESS_API select MMU_GATHER_RCU_TABLE_FREE select HAVE_RSEQ - select HAVE_RUST if CPU_LITTLE_ENDIAN + select HAVE_RUST if RUSTC_SUPPORTS_ARM64 select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS select HAVE_KPROBES@@ -265,6 +265,11 @@ config ARM64 help ARM 64-bit (AArch64) Linux support.Quoted 4 lines
Quoted 2 lines
arch/arm64/Kconfig config ARM64 · line 269
Quoted 2 lines
arch/arm64/Kconfig +2
-0+config RUSTC_SUPPORTS_ARM64 + boolThis line ^^^ should be '
def_booly'.Ah, I see, I guess I learned something today. It also seems to work if I add
default y.
Quoted 8 lines
Quoted 4 lines
I can change it if you think this is better. I still think there's some value in having everything in one place, but it's not a big deal. Either way, it should be temporary for a few kernel releases as we'll eventually only support compiler versions where this works.
I do like moving the reference to
UNWIND_PATCH_PAC_INTO_SCSinto the arch code, so if you could respin along these lines then that would be great.
Done, see:
https://lore.kernel.org/all/[email protected]/
I took the opportunity to incorporate new developments in rustc changes into the Kconfig rules.
Alice