Skip to content

[PW_SID:1086512] [v2] riscv: cif: reduce shadow stack size limit from 4GB to 2GB#1826

Closed
linux-riscv-bot wants to merge 3 commits into
workflow__riscv__fixesfrom
pw1086512
Closed

[PW_SID:1086512] [v2] riscv: cif: reduce shadow stack size limit from 4GB to 2GB#1826
linux-riscv-bot wants to merge 3 commits into
workflow__riscv__fixesfrom
pw1086512

Conversation

@linux-riscv-bot
Copy link
Copy Markdown

PR for series 1086512 applied to workflow__riscv__fixes

Name: [v2] riscv: cif: reduce shadow stack size limit from 4GB to 2GB
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1086512
Version: 2

nathanchance and others added 3 commits April 24, 2026 07:25
…_TYPED_FUNC_START

After commit 67bdd7b ("riscv: Split out measure_cycles() for
reuse") and commit c03ad15 ("riscv: Reuse measure_cycles() in
check_vector_unaligned_access()"), there are CFI failure when booting
kernels with CONFIG_CFI=y:

  CFI failure at measure_cycles+0x38/0xe0 (target: __riscv_copy_words_unaligned+0x0/0x50; expected type: ...)
  CFI failure at measure_cycles+0x38/0xe0 (target: __riscv_copy_vec_words_unaligned+0x0/0x24; expected type: ...)

The __riscv_copy_*_unaligned() functions are now called indirectly but
they are not defined with SYM_TYPED_FUNC_START, which is required for
assembly functions called indirectly from C to pass CFI checking. Switch
to SYM_TYPED_FUNC_START to clear up the CFI failures.

Fixes: 67bdd7b ("riscv: Split out measure_cycles() for reuse")
Fixes: c03ad15 ("riscv: Reuse measure_cycles() in check_vector_unaligned_access()")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Nam Cao <namcao@linutronix.de>
Link: https://patch.msgid.link/20260406-measure_cycles-cfi-failure-v1-1-03e0234ae02f@kernel.org
Signed-off-by: Paul Walmsley <pjw@kernel.org>
Follow the ARM64 GCS (Guarded Control Stack) implementation approach
by reducing the shadow stack size allocation from min(RLIMIT_STACK, 4GB)
to min(RLIMIT_STACK/2, 2GB). see commit '506496bcbb42 "arm64/gcs: Ensure
that new threads have a GCS")'

Rationale:

1. Shadow stacks only store return addresses (8 bytes per entry), not
   local variables, function parameters, or saved registers. A 2GB
   shadow stack is far more than sufficient for any practical
   application, even with extremely deep recursion. Using half the size
   maintains adequate while being more resource-efficient margin

2. On memory-constrained systems (e.g., platforms with only 4GB of
   physical memory, which is a common configuration), allocating 4GB
   of virtual address space for shadow stack per process/thread can
   lead to virtual memory allocation failures when the overcommit mode
   is set to OVERCOMMIT_GUESS or OVERCOMMIT_NEVER:
   Error: "__vm_enough_memory: not enough memory for the allocation"

This reduces virtual address space consumption by 50% while maintaining
more than adequate space for return address storage.

Signed-off-by: Zong Li <zong.li@sifive.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2] riscv: cif: reduce shadow stack size limit from 4GB to 2GB"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 115.46 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2] riscv: cif: reduce shadow stack size limit from 4GB to 2GB"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 951.52 seconds
Result: ERROR
Output:

Redirect to /build/tmp.NimeTSUiGV and /build/tmp.fhRlBC6d30
Tree base:
01805bc4f902e ("Adding CI files")
Building the whole tree with the patch
error:
Warning: /build/tmpj9t80y3j/drivers/pmdomain/mediatek/mtk-mfg-pmdomain.c:244 struct __packed mtk_mfg_opp_entry { __le32 freq_khz; __le32 voltage_core; __le32 voltage_sram; __le32 posdiv; __le32 voltage_margin; __le32 power_mw; }; error: Cannot parse struct or union!
ld.lld: error: relocation R_RISCV_32 cannot be used against symbol '__kcfi_typeid___riscv_copy_words_unaligned'; recompile with -fPIC
ld.lld: error: relocation R_RISCV_32 cannot be used against symbol '__kcfi_typeid___riscv_copy_bytes_unaligned'; recompile with -fPIC
ld.lld: error: relocation R_RISCV_32 cannot be used against symbol '__kcfi_typeid___riscv_copy_vec_words_unaligned'; recompile with -fPIC
ld.lld: error: relocation R_RISCV_32 cannot be used against symbol '__kcfi_typeid___riscv_copy_vec_bytes_unaligned'; recompile with -fPIC



real	15m42.894s
user	577m22.445s
sys	130m19.139s

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2] riscv: cif: reduce shadow stack size limit from 4GB to 2GB"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1362.00 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2] riscv: cif: reduce shadow stack size limit from 4GB to 2GB"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 21.12 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2] riscv: cif: reduce shadow stack size limit from 4GB to 2GB"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 20.79 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2] riscv: cif: reduce shadow stack size limit from 4GB to 2GB"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 0.62 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2] riscv: cif: reduce shadow stack size limit from 4GB to 2GB"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 74.75 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2] riscv: cif: reduce shadow stack size limit from 4GB to 2GB"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2] riscv: cif: reduce shadow stack size limit from 4GB to 2GB"
kdoc
Desc: Detects for kdoc errors
Duration: 0.71 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2] riscv: cif: reduce shadow stack size limit from 4GB to 2GB"
module-param
Desc: Detect module_param changes
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2] riscv: cif: reduce shadow stack size limit from 4GB to 2GB"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "[v2] riscv: cif: reduce shadow stack size limit from 4GB to 2GB"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.37 seconds
Result: PASS

@linux-riscv-bot linux-riscv-bot force-pushed the workflow__riscv__fixes branch 2 times, most recently from 94a07a2 to f190ec6 Compare May 1, 2026 02:14
@linux-riscv-bot linux-riscv-bot deleted the pw1086512 branch May 2, 2026 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants