From: Andrey Ryabinin Date: Wed, 20 Jan 2016 23:00:48 +0000 (-0800) Subject: kernel: printk: specify alignment for struct printk_log X-Git-Tag: submit/tizen/20160810.050017~159 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a0334ef6460ac92276f0fa9c4adee5d6320ffb41;p=platform%2Fkernel%2Flinux-exynos.git kernel: printk: specify alignment for struct printk_log On architectures that have support for efficient unaligned access struct printk_log has 4-byte alignment. Specify alignment attribute in type declaration. The whole point of this patch is to fix deadlock which happening when UBSAN detects unaligned access in printk() thus UBSAN recursively calls printk() with logbuf_lock held by top printk() call. Signed-off-by: Andrey Ryabinin Cc: Peter Zijlstra Cc: Sasha Levin Cc: Randy Dunlap Cc: Rasmus Villemoes Cc: Jonathan Corbet Cc: Michal Marek Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Yury Gribov Cc: Dmitry Vyukov Cc: Konstantin Khlebnikov Cc: Kostya Serebryany Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds [Backport from mainline for UBSAN] Signed-off-by: Seung-Woo Kim Change-Id: I93d23dec2c1539faf21eb7242ccc328999950c01 --- diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 2a38f63adf43..4a6dce9a3467 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -228,7 +228,11 @@ struct printk_log { u8 facility; /* syslog facility */ u8 flags:5; /* internal record flags */ u8 level:3; /* syslog level */ -}; +} +#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS +__packed __aligned(4) +#endif +; struct log_buffer { #ifdef CONFIG_PRINTK @@ -276,11 +280,7 @@ static enum log_flags console_prev; #define KMSG_NUM_MAX 255 /* record buffer */ -#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) -#define LOG_ALIGN 4 -#else #define LOG_ALIGN __alignof__(struct printk_log) -#endif #define __LOG_BUF_K_LEN (1 << CONFIG_LOG_BUF_SHIFT) static char __log_buf_k[__LOG_BUF_K_LEN] __aligned(LOG_ALIGN);