printk: Fix alignment of buf causing crash on ARM EABI
PATCH 1/1 printk: Fix alignment of buf causing crash on ARM EABI
Commit 7ff9554bb578ba02166071d2d487b7fc7d860d62, printk: convert byte-buffer to variable-length record buffer, causes systems using EABI to crash very early in the boot cycle. The first entry in struct log is a u64, which for EABI must be 8 byte aligned.
Make use of __alignof__() so the compiler to decide the alignment, but allow it to be overridden using CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS, for systems which can perform unaligned access and want to save a few bytes of space.
Tested on Orion5x and Kirkwood.
--- kernel/printk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/printk.c +2 -2
@@ -227,10 +227,10 @@ static u32 clear_idx;#define LOG_LINE_MAX 1024/* record buffer */ -#if !defined(CONFIG_64BIT ) || defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS ) +#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS )#define LOG_ALIGN 4#else -#define LOG_ALIGN 8 +#define LOG_ALIGN __alignof__(struct log)#endif #define __LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT)static char __log_buf[__LOG_BUF_LEN]__aligned(LOG_ALIGN) ;
Signature · 1 line
1.7.10
PATCH 1/1 printk: Fix alignment of buf causing crash on ARM EABI
Quoted 10 lines · Andrew Lunn
Commit
7ff9554bb578ba02166071d2d487b7fc7d860d62, printk: convert byte-buffer to variable-length record buffer, causes systems using EABI to crash very early in the boot cycle. The first entry in struct log is a u64, which for EABI must be 8 byte aligned.Make use of
__alignof__()so the compiler to decide the alignment, but allow it to be overridden usingCONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS, for systems which can perform unaligned access and want to save a few bytes of space.
Quoted 6 lines
Tested on Orion5x and Kirkwood.
Signed-off-by Andrew Lunn <[email protected]>--- kernel/printk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Thanks, I think I have a patch in my to-apply queue that fixes this in a bit different way. I'll dig that up and compare them in the next few days as I work my way through my pending patch queue.
greg k-h
PATCH 1/1 printk: Fix alignment of buf causing crash on ARM EABI
Quoted 13 lines · Greg KH
Quoted 12 lines · Andrew Lunn
Commit
7ff9554bb578ba02166071d2d487b7fc7d860d62, printk: convert byte-buffer to variable-length record buffer, causes systems using EABI to crash very early in the boot cycle. The first entry in struct log is a u64, which for EABI must be 8 byte aligned.Make use of
__alignof__()so the compiler to decide the alignment, but allow it to be overridden usingCONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS, for systems which can perform unaligned access and want to save a few bytes of space.Tested on Orion5x and Kirkwood.
Quoted 8 lines
Quoted 4 lines
Signed-off-by Andrew Lunn <[email protected]>---
?kernel/printk.c | ? ?4 ++--
?1 file changed, 2 insertions(+), 2 deletions(-)Thanks, I think I have a patch in my to-apply queue that fixes this in a bit different way. ?I'll dig that up and compare them in the next few days as I work my way through my pending patch queue.
This patch looks good to me.
Thanks,
Kay
PATCH 1/1 printk: Fix alignment of buf causing crash on ARM EABI
In reply to Andrew LunnQuoted 5 lines · Andrew Lunn
Commit
7ff9554bb578ba02166071d2d487b7fc7d860d62, printk: convert byte-buffer to variable-length record buffer, causes systems using EABI to crash very early in the boot cycle. The first entry in struct log is a u64, which for EABI must be 8 byte aligned.
Quoted 8 lines
Make use of
__alignof__()so the compiler to decide the alignment, but allow it to be overridden usingCONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS, for systems which can perform unaligned access and want to save a few bytes of space.Tested on Orion5x and Kirkwood.
Signed-off-by Andrew Lunn <[email protected]>
Indeed, using alignof is a good idea.