[PATCH 05/11] riscv: enable landing pad enforcement
Deepak Gupta
debug at rivosinc.com
Fri Jul 25 07:20:26 PDT 2025
On Fri, Jul 25, 2025 at 08:33:46AM +0200, Heinrich Schuchardt wrote:
>On 25.07.25 01:36, Deepak Gupta wrote:
>>Enables landing pad enforcement by invoking a SBI FWFT call.
>>
>>Signed-off-by: Deepak Gupta <debug at rivosinc.com>
>>---
>> arch/riscv/kernel/asm-offsets.c | 1 +
>> arch/riscv/kernel/head.S | 19 +++++++++++++++++++
>> 2 files changed, 20 insertions(+)
>>
>>diff --git a/arch/riscv/kernel/asm-offsets.c b/arch/riscv/kernel/asm-offsets.c
>>index e4d55126dc3e..e6a9fad86fae 100644
>>--- a/arch/riscv/kernel/asm-offsets.c
>>+++ b/arch/riscv/kernel/asm-offsets.c
>>@@ -536,6 +536,7 @@ void asm_offsets(void)
>> DEFINE(SBI_EXT_FWFT, SBI_EXT_FWFT);
>> DEFINE(SBI_EXT_FWFT_SET, SBI_EXT_FWFT_SET);
>> DEFINE(SBI_FWFT_SHADOW_STACK, SBI_FWFT_SHADOW_STACK);
>>+ DEFINE(SBI_FWFT_LANDING_PAD, SBI_FWFT_LANDING_PAD);
>> DEFINE(SBI_FWFT_SET_FLAG_LOCK, SBI_FWFT_SET_FLAG_LOCK);
>> #endif
>> }
>>diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
>>index 9c99c5ad6fe8..59af044bf85c 100644
>>--- a/arch/riscv/kernel/head.S
>>+++ b/arch/riscv/kernel/head.S
>>@@ -185,6 +185,16 @@ secondary_start_sbi:
>> 1:
>> #endif
>> scs_load_current
>>+
>>+#if defined(CONFIG_RISCV_SBI) && defined(CONFIG_RISCV_KERNEL_CFI)
>>+ li a7, SBI_EXT_FWFT
>>+ li a6, SBI_EXT_FWFT_SET
>>+ li a0, SBI_FWFT_LANDING_PAD
>>+ li a1, 1 /* enable landing pad for supervisor */
>>+ li a2, SBI_FWFT_SET_FLAG_LOCK
>>+ ecall /* check for error condition and take appropriate action */
>>+#endif
>>+
>> call smp_callin
>> #endif /* CONFIG_SMP */
>>@@ -359,6 +369,15 @@ SYM_CODE_START(_start_kernel)
>> #endif
>> scs_load_current
>>+#if defined(CONFIG_RISCV_SBI) && defined(CONFIG_RISCV_KERNEL_CFI)
>>+ li a7, SBI_EXT_FWFT
>>+ li a6, SBI_EXT_FWFT_SET
>>+ li a0, SBI_FWFT_LANDING_PAD
>>+ li a1, 1 /* enable landing pad for supervisor */
>
>The SBI specification calls BIT(0) "LOCK".
>Shouldn't we define a constant for the lock bit instead of using a
>magic value?
See below `li a2, SBI_FWFT_SET_FLAG_LOCK`.
"li a1, 1 /* enable landing pad for supervisor */>" --> this is enabling.
Had we done "li a1, 0 /* enable landing pad for supervisor */" --> this is
asking firmware to disable the feature (turn off the bit in menvcfg CSR)
>Best regards
>
>Heinrich
>
>>+ li a2, SBI_FWFT_SET_FLAG_LOCK
>>+ ecall /* check for error condition and take appropriate action */
>>+#endif
>>+
>> #ifdef CONFIG_KASAN
>> call kasan_early_init
>> #endif
>>
>
More information about the linux-riscv
mailing list