Commit 5c9cf8af authored by Andrey Ryabinin's avatar Andrey Ryabinin Committed by Linus Torvalds
Browse files

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

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: default avatarAndrey 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: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 41662f5c
......@@ -233,7 +233,11 @@ struct printk_log {
u8 facility; /* syslog facility */
u8 flags:5; /* internal record flags */
u8 level:3; /* syslog level */
__packed __aligned(4)
* The logbuf_lock protects kmsg buffer, indices, counters. This can be taken
......@@ -274,11 +278,7 @@ static u32 clear_idx;
#define LOG_FACILITY(v) ((v) >> 3 & 0xff)
/* record buffer */
#define LOG_ALIGN 4
#define LOG_ALIGN __alignof__(struct printk_log)
static char __log_buf[__LOG_BUF_LEN] __aligned(LOG_ALIGN);
static char *log_buf = __log_buf;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment