Patrick Rudolph has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/85855?usp=email )
Change subject: commonlib/include/commonlib: Add barrier in write_at_ble8() ......................................................................
commonlib/include/commonlib: Add barrier in write_at_ble8()
With the introduction of the stack canary breakpoint QEMU uncovered a different bug within coreboot. Currently the compiler optimizes over aggressively inline functions and memory stores.
That also affects write_at_ble8(), which is supposed to store a single byte at time. The compiler however optimizes multiple byte stores into a single wider (and possibly unaligned) store operation.
Make sure that the compiler does not optimize multiple calls to write_at_ble8() by adding a memory barrier.
Fixes a strange bug in QEMU where it triggers the DEBUG INT handler on unaligned 16-bit stores in the first 4KiB of memory. Aligned stores and store outside of the first 4KiB do not dispatch the DEBUG INT handler.
Change-Id: Ibbc661235a38c7f7540b656a67f067c3e51105d1 Signed-off-by: Patrick Rudolph patrick.rudolph@9elements.com --- M src/commonlib/include/commonlib/endian.h 1 file changed, 5 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/55/85855/1
diff --git a/src/commonlib/include/commonlib/endian.h b/src/commonlib/include/commonlib/endian.h index 84c90b4..d0280b1 100644 --- a/src/commonlib/include/commonlib/endian.h +++ b/src/commonlib/include/commonlib/endian.h @@ -25,6 +25,11 @@ static inline void write_ble8(void *dest, uint8_t val) { *(uint8_t *)dest = val; + /* + * Prevent compilers from optimizing multiple write_ble8() into + * a single unaligned store operation by adding a memory barrier. + */ + __asm__ __volatile__("" : : : "memory"); }
static inline void write_at_ble8(void *dest, uint8_t val, size_t offset)