walnux/arch
Kerogit a3f8b55143 drivers/serial/serial: prevent race conditions on 8-bit architectures
Some code paths in drivers/serial/serial.c load head and tail values
of receive and transmit circular buffers with interrupts enabled,
making it possible that the interrupt handler changes the value.
As noted in the code, this is safe as long as the load itself is atomic.

That is not true for 8bit architectures which fetch the 16-bit values
using two load instructions. If interrupt handler runs between those
two instructions and changes the value, the read returns corrupted data.

This patch introduces CONFIG_ARCH_LDST_16BIT_NOT_ATOMIC configuration
option which is automatically selected for AVR architecture. Based
on this option, head and tail values are reduced to 8-bit length
so the read remains atomic.

Patch was tested by building on rv-virt:nsh - disassembly of functions
from serial.c showed no difference which is correct as Risc-V does
not need to protect reads of these values. There should be no impact
for architectures that do not set the new configuration option.

It was also tested by by custom echo application running on AVR128DA28.

Signed-off-by: Kerogit <kr.git@kerogit.eu>
2025-06-19 10:01:24 -03:00
..
arm [Kconfig] Fix Kconfig style 2025-06-18 18:56:39 +02:00
arm64 imx9/lpuart: Fix SMP deadlock with imx9_txint 2025-06-12 15:28:18 -03:00
avr drivers/serial/serial: prevent race conditions on 8-bit architectures 2025-06-19 10:01:24 -03:00
ceva Revert "Reduce the size of tcb by four bytes." 2025-05-27 16:30:35 +08:00
dummy
hc style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
mips arch: unify Private Types banners 2025-05-28 10:17:15 +08:00
misoc Revert "Reduce the size of tcb by four bytes." 2025-05-27 16:30:35 +08:00
or1k Revert "Reduce the size of tcb by four bytes." 2025-05-27 16:30:35 +08:00
renesas Revert "Reduce the size of tcb by four bytes." 2025-05-27 16:30:35 +08:00
risc-v arch/risc-v: decouple common source for Espressif's MCUBoot port 2025-06-14 17:11:58 +08:00
sim arch: unify Private Types banners 2025-05-28 10:17:15 +08:00
sparc Revert "Reduce the size of tcb by four bytes." 2025-05-27 16:30:35 +08:00
tricore Revert "Reduce the size of tcb by four bytes." 2025-05-27 16:30:35 +08:00
x86 Revert "Reduce the size of tcb by four bytes." 2025-05-27 16:30:35 +08:00
x86_64 arch: Flag all definitions of up_perf_* functions with CONFIG_ARCH_HAVE_PERF_EVENTS 2025-06-06 17:31:10 +08:00
xtensa arch/xtensa: decouple common source for Espressif's MCUBoot port 2025-06-14 17:11:58 +08:00
z16 Revert "Reduce the size of tcb by four bytes." 2025-05-27 16:30:35 +08:00
z80 Revert "Reduce the size of tcb by four bytes." 2025-05-27 16:30:35 +08:00
CMakeLists.txt arch/z80: migrate to SPDX identifier 2024-12-02 17:23:25 +08:00
Kconfig drivers/serial/serial: prevent race conditions on 8-bit architectures 2025-06-19 10:01:24 -03:00