Commit graph

6,290 commits

Author SHA1 Message Date
Daniel Leung
ee54baf126 Revert "xtensa: move MMU init functions to mmu.c"
This reverts commit 8c02dde437.

For some unknown reasons, xt-clang emits two copies of
z_xt_init_pc if xtensa_mmu_init_paging() is in the same file
as xtensa_mmu_init() and xtensa_mmu_reinit(). So had to
revert the change.

Fixes #103055

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-02-04 13:50:54 +01:00
Daniel Leung
a5a9ff4c28 xtensa: handle instruction TLB multi-hit exception
When using LLEXT, instruction TLB multi-hit becomes a reality
as the same memory space can be occupied by different modules
with different permissions. The ITLB cache may still contain
entries of the unloaded module. So we need to manually
invalidate any cached ITLB corresponding to the exception
address so the TLB associated with the newly loaded module
can be used.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-02-03 09:38:03 +01:00
Daniel Leung
9b9e9ebde7 xtensa: mmu: data TLB multi-hit only handle exception address
There is no need to invalidate the whole auto-refilled data TLB
cache when DTLB multi-hit exception is raised. Now it only
invalidates the TLB entries corresponding to the one causing
the DTLB multi-hit. This allows other non-related TLB entries
to remain in the cache so they don't need to be reloaded.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-02-03 09:38:03 +01:00
Daniel Leung
599df95875 xtensa: return back to interrupted thread for certain exceptions
For both data TLB multi-hit and load/store ring error, we should
return to the interrupted thread immediately so that it can get
past the exception generated code. It is because both of these
exceptions are the result of having cached TLB entries not
aligning to the correct access pattern. So once we have handled
the exception, go back to the interrupted thread to continue
to minimize the chance of having another incompatible TLB being
cached.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-02-03 09:38:03 +01:00
Daniel Leung
27e4802621 xtensa: remove unnecessary setting of is_fatal_error during exc
There is no need for an extra switch block to manipulate
the value of is_fatal_error, which defaults to false, and is set
according to the actual exception above. So remove that.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-02-03 09:38:03 +01:00
Nicolas Pitre
a72194c2a0 arm*: BTI requires C library built with branch protection
BTI requires that the C library be compiled with -mbranch-protection to
include BTI landing pads. Newlib from toolchains lacks this support, so
only minimal libc or picolibc built from source (PICOLIBC_USE_MODULE) can
be used with BTI.

Without this, the basic hello_world/ sample fails to execute.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-02-03 09:36:09 +01:00
Nicolas Pitre
991990946d arm*: Improve ARM_PAC_PER_THREAD RNG dependency handling
Change the random number generator requirement for per-thread PAC keys
from a hard dependency to a more flexible approach:

- Use 'select CSPRNG_NEEDED' to automatically request cryptographic
  RNG support rather than requiring specific RNG options to be
  pre-enabled
- Use 'imply TEST_RANDOM_GENERATOR' as a fallback when no real CSPRNG
  is available, enabling testing without hardware entropy

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-02-03 09:36:09 +01:00
Nicolas Pitre
a02a3f14f3 arm64: Make PACBTI Kconfig available and add compiler flag support
Enable the ARM_PACBTI Kconfig choice for ARM64 architectures (ARMV8_A
and ARMV9_A) in addition to the existing ARM32 ARMV8_1_M_MAINLINE
support. Add the corresponding -mbranch-protection compiler flags to
both GCC and Clang target files for ARM64.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-02-03 09:36:09 +01:00
Nicolas Pitre
13fe03a3b5 arm64: Add Branch Target Identification (BTI) support
Add support for ARMv8.5+ Branch Target Identification to protect against
Jump-Oriented Programming (JOP) attacks. This complements PAC to offer
complete protection against both ROP and JOP attacks, ensuring
comprehensive control flow integrity.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-02-03 09:36:09 +01:00
Nicolas Pitre
d1d439ca09 arm64: Add Pointer Authentication (PAC) support
Add support for ARMv8.3+ Pointer Authentication to protect against
Return-Oriented Programming (ROP) attacks. This implementation provides
PAC functionality with per-thread key isolation, secure key management,
and integration with Zephyr's thread model.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-02-03 09:36:09 +01:00
Grygorii Strashko
db1bea3ae2 drivers: xen: add XEN_EVENTS Kconfig option
The Xen events channel driver consume 72K of RAM, but may not be
required in all use cases.

Added a XEN_EVENTS Kconfig option so that Xen events can be gracefully
disabled if not required. Updated the relevant CMakeLists.txt and
Kconfig files to guard the inclusion of the Xen events driver and its
source files by this option.

Signed-off-by: Grygorii Strashko <grygorii_strashko@epam.com>
Signed-off-by: Svitlana Drozd <svitlana_drozd@epam.com>
2026-01-30 16:56:52 -06:00
Mathieu Choplain
761aaba6be arch: arm: cortex_m: pm_s2ram: add missing include
Functions in assembler file pm_s2ram.S are declared with the usual:
  SECTION_FUNC(TEXT, <function name>)

Note the first argument (section name) is `TEXT` in capital letters which
a define in `include/zephyr/linker/sections.h` should replace with `text`,
such that the functions are placed in section `.text.<function name>` which
matches the ".text.*" pattern in linker script. However, this file is not
included by pm_s2ram.S: as such, the substitution never happens and the
functions go in `.TEXT.<function name>` instead! This has not caused issues
thanks to a workaround in the Cortex-M linker script, which also has
".TEXT.*" as input section name pattern (unlike all other archs!), but is a
bug nonetheless.

Fix this issue by adding the missing include which ensures the functions
are placed in sections with the proper name.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-01-29 16:10:19 -06:00
Mathieu Choplain
544a96356d arch: arm: cortex_m: __aeabi_read_tp: add missing include
The eponymous function in __aeabi_read_tp.S is declared using:
  SECTION_FUNC(TEXT, __aeabi_read_tp)

Note the first argument (section name) is `TEXT` in capital letters which
a define in `include/zephyr/linker/sections.h` should replace with `text`,
such that the function is placed in section `.text.__aeabi_read_tp` which
matches the ".text.*" pattern in linker script. However, this file is not
included by __aeabi_read_tp.S: as such, the substitution never happens and
the function goes in `.TEXT.__aeabi_read_tp` instead! This has not caused
issues thanks to a workaround in the Cortex-M linker script, which also
has ".TEXT.*" as input section name pattern (unlike all other archs!), but
is a bug nonetheless.

Fix this issue by adding the missing include which ensures the function
is placed in a section with the proper name.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-01-29 16:10:19 -06:00
Firas Sammoura
faa65388d3 arch: riscv: Allow z_riscv_fatal_error to return
The Zephyr kernel's generic `z_fatal_error()` function, which is
invoked by architecture-specific fatal error handlers, is not
guaranteed to be non-returning. For instance, it can return if an
essential thread aborts itself.

The RISC-V port's `z_riscv_fatal_error` function was previously
inconsistently marked as `FUNC_NORETURN`. This commit removes this
attribute to align with the core kernel behavior, allowing the
function to return if `z_fatal_error()` returns.

Specific changes include:

-   Removed `FUNC_NORETURN` from `z_riscv_fatal_error` declarations
    in `fatal.c` and `kernel_arch_func.h`.
-   Removed `CODE_UNREACHABLE` after the call to `z_fatal_error`
    within `z_riscv_fatal_error` as it can now return.
-   In `isr.S`, changed `tail z_riscv_fatal_error` to
    `call z_riscv_fatal_error` in the exception entry, followed by
    a jump to `check_reschedule` to handle the return path.
-   Added `CODE_UNREACHABLE` at call sites of `z_riscv_fatal_error`
    (e.g., in `z_riscv_fault`, `z_check_user_fault`,
    `arch_irq_spurious`) where the context ensures the call is
    effectively terminal.

Signed-off-by: Firas Sammoura <fsammoura@google.com>
2026-01-29 13:39:45 +01:00
Amneesh Singh
713f9bfe8d arch: arm: cortex_a_r: fix cache line size calculation
Cortex-R5F Technical Reference Manual by Arm says DMINLINE is the Log2 of
the minimum number of words (one word = four bytes) in a cache line.

For instance, say DMINLINE is 3, which means the cache line size is
2^3=8 words or 32 bytes, however with the current calculation, it comes
out to be 16 bytes. Therefore, we fix this calculation by correctly
calculating the number of bytes for the cache line size.

Signed-off-by: Amneesh Singh <amneesh@ti.com>
2026-01-27 10:25:34 -06:00
Afonso Oliveira
ca062130c9 arch: riscv: call IMSIC secondary init on SMP boot
Invoke IMSIC secondary initialization during RISC-V SMP bring-up.

Signed-off-by: Afonso Oliveira <afonsoo@synopsys.com>
2026-01-26 14:16:22 +01:00
Fin Maaß
2cea7b0582 thead: riscv: use riscv,isa-extensions dt prop
use riscv,isa-extensions dt prop for riscv cpus.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-01-26 14:15:18 +01:00
Fin Maaß
e2fd8e6de7 riscv: use riscv,isa-extensions dt prop
implement and use riscv,isa-extensions
dt prop, like in linux
https://www.kernel.org/doc/Documentation/devicetree/bindings/riscv/extensions.yaml
to set the riscv extentions.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-01-26 14:15:18 +01:00
Fin Maaß
0da1b7870e arch: riscv: require "riscv" compatible
Require the "riscv" compatible for
CONFIG_RISCV.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-01-26 14:15:18 +01:00
Appana Durga Kedareswara rao
34076efa39 arm64: fpu: Clear K_FP_REGS flag in arch_float_disable()
The arch_float_disable() function was not clearing the K_FP_REGS flag
from thread->base.user_options after disabling FPU access. This caused
the float_disable test to fail as it verifies the flag is properly
cleared after FPU disable.

Signed-off-by: Appana Durga Kedareswara rao <appana.durga.kedareswara.rao@amd.com>
2026-01-26 11:56:59 +01:00
Daniel Leung
8c02dde437 xtensa: move MMU init functions to mmu.c
Since we have split source files for page table related stuff
and MMU related stuff, move the MMU initialization functions
from the page table source file into MMU source file.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-01-24 08:48:54 -06:00
Daniel Leung
ed4cec2d22 xtensa: ptables: doxygen doc
This adds doxygen doc to the page table source file as
we are missing quite a bit of documentation there.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-01-24 08:48:54 -06:00
Daniel Leung
744a7f4daf xtensa: mmu: do doxygen for functions
This changes the existing comments for functions into doxygen
style documentation for functions. Also adds missing doxygen
doc for functions.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-01-24 08:48:54 -06:00
Fin Maaß
daf90f79ee arch: riscv: add dependencies to FLOAT_HARD
1. it reguires that there are floating point registers,
so the extention f is required. (zfinx uses the int regs instead)
2. RV32E doesn't supports hardware floating-point calling convention.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-01-24 08:47:18 -06:00
Andy Lin
d807e39a2c arch: riscv: Add the support for Zbkb ISA extension
Introduce the missing flag to compile code with Zbkb extension,
which has already been supported by the GCC 12 in current SDK.

Signed-off-by: Andy Lin <andylinpersonal@gmail.com>
2026-01-23 13:51:55 +01:00
Peter Mitsis
3944b0cfc7 kernel: Extend thread user_options to 16 bits
Upgrades the thread user_options to 16 bits from an 8-bit value to
provide more space for future values.

Also, as the size of this field has changed, the values for the
existing architecture specific thread options have also shifted
from the upper end of the old 8-bit field, to the upper end of
the new 16-bit field.

Fixes #101034

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2026-01-22 08:40:17 +00:00
Daniel Leung
50e980d9a8 xtensa: mmu: halt system if not enough L2 tables during boot
If there are not enough free L2 tables to map all predefined
memory regions at boot, halt the system in case assertion is
not enabled. Without all the needed memory regions mapped,
it is very unlikely that anything will run properly.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-01-22 08:39:30 +00:00
Daniel Leung
82b7d94d45 xtensa: mmu: add debug logs on page table allocations
Adds some debug logs when we are allocating page tables.
This provides a more visible way of seeing whether
we need to have more free tables.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-01-22 08:39:30 +00:00
Daniel Leung
0777dbea02 xtensa: mmu: assert when L2 table allocation fails during dup
Add an assertions to halt the system if L2 table allocation
fails when we need to duplicate an existing L2 table, as it is
a must-have and must-success operation.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-01-22 08:39:30 +00:00
Benjamin Cabé
27120315d3 arch: arm: avoid the use of "sanity check" term
As per coding guidelines, "sanity check" must be avoided.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-01-21 20:06:35 +01:00
Benjamin Cabé
71262d0e07 arch: xtensa: avoid the use of "sanity check" term
As per coding guidelines, "sanity check" must be avoided.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-01-21 20:06:25 +01:00
Benjamin Cabé
5a9715add1 arch: x86: avoid the use of "sanity check" term
As per coding guidelines, "sanity check" must be avoided.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-01-21 20:06:15 +01:00
Benjamin Cabé
f64bb4bf1e arch: riscv: avoid the use of "sanity check" term
As per coding guidelines, "sanity check" must be avoided.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-01-21 20:06:06 +01:00
Benjamin Cabé
ff78913fa8 arch: arm: smp: Master core should be referred to as "primary"
As per Zephyr guidelines re: inclusive language, the term
"master" is replaced with "primary".

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-01-21 20:05:54 +01:00
Adrian Warecki
c1a2b3be45 xtensa: Restore the EXCCAUSE register when returning from Double Exception
Preserve EXCCAUSE and EXCVADDR values on entry to _Level1Vector.
Restore EXCCAUSE when exiting TLB miss exception handling in the double
exception handler.

During first-level exception handling, a LoadStoreTLBMissException may
occur during the initial register dump to BSA. It modifies EXCCAUSE and
EXCVADDR registers before they are saved in BSA. Therefore, these values
must be captured as early as possible.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
2026-01-21 11:22:35 +00:00
Adrian Warecki
fd8188a408 xtensa: Remove saving EXCCAUSE in BSA from _Level1Vector
Remove saving EXCCAUSE register in BSA through the _Level1Vector handler.
These value are later overwritten by the ODD_REG_SAVE macro called by
EXCINT_HANDLER, so saving it here is pointless.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
2026-01-21 11:22:35 +00:00
Jamie McCrae
3233c2915a arch: arm: core: cortex_m: timing: Remove stray comment
Removes a stray comment mentioning a Kconfig which actually has
nothing to do with the code

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-01-20 13:21:38 +00:00
Tom Hughes
a28b6f8ed7 arc: Use ARG_UNUSED instead of self-assignment to avoid clang warnings
clang warns about self assignment when -Wself-assign is enabled.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2026-01-17 14:28:18 +01:00
Sylvio Alves
b05332abee arch: riscv: pmp: add SoC-specific region support
Add infrastructure for SoCs to define additional PMP regions
that need protection beyond the standard ROM region. This uses
iterable sections to collect region definitions at link time.

The PMP_SOC_REGION_DEFINE macro allows SoCs to register memory
regions with specific permissions. These regions become global
PMP entries shared between M-mode and U-mode.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-01-13 17:26:48 +01:00
Jisheng Zhang
23dfe86f4a arch: arm64: remove ARM64_EXCEPTION_STACK_TRACE
After commit 02770ad963 ("debug: EXCEPTION_STACK_TRACE should depend
on arch Kconfigs"), the ARM64_EXCEPTION_STACK_TRACE isn't used any more,
remove it.

Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
2026-01-09 10:39:41 +01:00
Mathieu Choplain
36170c4530 arch: *: remove check for CONFIG_SOC_PER_CORE_INIT_HOOK
soc_per_core_init_hook() is usually called from arch_kernel_init() and
arch_secondary_cpu_init() which are C functions. As such, there is no need
to check for CONFIG_SOC_PER_CORE_INIT_HOOK since platform/hooks.h provides
a no-op function-like macro implementation if the Kconfig option is not
enabled.

Remove the Kconfig option check from all files.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-01-07 19:39:53 +01:00
Andy Lin
8558b935b1 coredump: arm: Callee registers for armv6-m and v8-m baseline
Ensure callee registers included in coredump.
Push callee registers onto stack for
CONFIG_ARMV6_M_ARMV8_M_BASELINE as well
when CONFIG_EXTRA_EXCEPTION_INFO enabled.

Effectively a complement to df6b8c3 by mholden.

Signed-off-by: Andy Lin <andylinpersonal@gmail.com>
2026-01-05 16:06:19 +01:00
Alberto Escolar Piedras
e90135eb0c arch: posix: cmake: Minor clarifications
Minor improvements in this cmake:
Add a comment to clarify why we set one option, and move an if
into an else with a comment of what is doing.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-01-03 10:20:34 +01:00
Alberto Escolar Piedras
6f427044dd arch: posix: cmake: Remove unnecessary line
This variable is not set to anything.
This line has always been just bogus.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-01-03 10:20:34 +01:00
Alberto Escolar Piedras
a2f45762f1 arch posix: cleanup NATIVE_APPLICATION support remnants
NO_POSIX_CHEATS was a macro used to avoid including the content of a
header (`posix_cheats.h`) which allowed building applications in the
POSIX architecture without the native simulator, avoiding collisions
between some embedded symbols and those from the host C library.

Support for this way of building, and this header and macro were
removed in e150ffb92c, but these users
were forgotten. This was harmless, but let's just clean it up now.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-01-03 10:19:34 +01:00
Guennadi Liakhovetski
8c200c0f2f xtensa: mmu: (cosmetic) clean up pointer types
Use void * cleanly: avoid needless type-casts and use void * for
generic pointers instead of uint8_t *.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2025-12-19 07:53:07 -06:00
Sylvio Alves
f8d2e00a0e includes: remove duplicated entries in zephyr-tree
Remove duplicated #include directives within the same
preprocessor scope across the Zephyr tree.

Duplicates inside different #ifdef branches are preserved
as they may be intentional.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2025-12-17 13:57:38 -05:00
Lucien Zhao
9e42f9fc34 arch: arm: mpu: Add Kconfig options for SRAM Write-Through cache policy
- CONFIG_ARM_MPU_SRAM_WRITE_THROUGH: enables Write-Through cache policy
  for SRAM regions instead of default Write-Back

Includes corresponding MPU attribute macros for ARMv7-M and ARMv8-M
architectures. Maintains backward compatibility with existing
configurations.

Signed-off-by: Lucien Zhao <lucien.zhao@nxp.com>
2025-12-17 14:35:50 +02:00
Mathieu Choplain
dc5e85a8d0 kernel/arch: remove zephyr,ccm initialization code
doc: dts: api: remove documentation of chosen `zephyr,ccm`

The `zephyr,ccm` chosen was an ST-specific property which has been replaced
by the generic `zephyr,dtcm`. Remove region initialization code from the
common arch init code (+ BSS zeroing from common XIP init code).

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2025-12-09 14:54:36 -05:00
Daniel Leung
701cbfbc23 xtensa: mmu: may need to copy entries during L2 table dup
During L2 page table duplication, there are cases where we
should copy the table over instead of restoring the PTEs.
Add the ability to copy the table over.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-12-09 09:25:33 +01:00