From: Aleksei Oladko <[email protected]> This patch fixes an issue where a segfault occurring inside a CT caused the kernel segfault message to be logged to the CT dmesg, while the opcode dump was printed to the host dmesg.
It also fixes a bug where the segfault message recorded in the CT dmesg used the host PID instead of the PID inside the container. And the last thing fixed is the loglevel is to be determined against the PID relative to the init pidns of the Container, not against the root pidns of the Host. https://virtuozzo.atlassian.net/browse/VSTOR-119875 Fixes: c3d2bd4b6946f ("ve: Use ve_printk() for often kernel messages about user actions") Signed-off-by: Aleksei Oladko <[email protected]> Reviewed-by: Pavel Tikhomirov <[email protected]> Feature: print: enhance logging --- v2: used task_pid_ve_nr instead task_pid_vnr v5: fix loglevel detection against CT's init pidns --- arch/x86/include/asm/stacktrace.h | 1 + arch/x86/kernel/dumpstack.c | 11 ++++++++--- arch/x86/mm/fault.c | 7 ++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h index 3881b5333eb81..09e08f36d02e4 100644 --- a/arch/x86/include/asm/stacktrace.h +++ b/arch/x86/include/asm/stacktrace.h @@ -109,6 +109,7 @@ struct stack_frame_ia32 { u32 return_address; }; +void ve_show_opcodes(struct pt_regs *regs, const char *loglvl, int dst); void show_opcodes(struct pt_regs *regs, const char *loglvl); void show_ip(struct pt_regs *regs, const char *loglvl); #endif /* _ASM_X86_STACKTRACE_H */ diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c index a7d562697e50e..b8cd4ae49e9ee 100644 --- a/arch/x86/kernel/dumpstack.c +++ b/arch/x86/kernel/dumpstack.c @@ -110,7 +110,7 @@ static int copy_code(struct pt_regs *regs, u8 *buf, unsigned long src, * Thus, the 2/3rds prologue and 64 byte OPCODE_BUFSIZE is just a random * guesstimate in attempt to achieve all of the above. */ -void show_opcodes(struct pt_regs *regs, const char *loglvl) +void ve_show_opcodes(struct pt_regs *regs, const char *loglvl, int dst) { #define PROLOGUE_SIZE 42 #define EPILOGUE_SIZE 21 @@ -120,7 +120,7 @@ void show_opcodes(struct pt_regs *regs, const char *loglvl) switch (copy_code(regs, opcodes, prologue, sizeof(opcodes))) { case 0: - printk("%sCode: %" __stringify(PROLOGUE_SIZE) "ph <%02x> %" + ve_printk(dst, "%sCode: %" __stringify(PROLOGUE_SIZE) "ph <%02x> %" __stringify(EPILOGUE_SIZE) "ph\n", loglvl, opcodes, opcodes[PROLOGUE_SIZE], opcodes + PROLOGUE_SIZE + 1); break; @@ -128,12 +128,17 @@ void show_opcodes(struct pt_regs *regs, const char *loglvl) /* No access to the user space stack of other tasks. Ignore. */ break; default: - printk("%sCode: Unable to access opcode bytes at 0x%lx.\n", + ve_printk(dst, "%sCode: Unable to access opcode bytes at 0x%lx.\n", loglvl, prologue); break; } } +void show_opcodes(struct pt_regs *regs, const char *loglvl) +{ + return ve_show_opcodes(regs, loglvl, VE0_LOG); +} + void show_ip(struct pt_regs *regs, const char *loglvl) { #ifdef CONFIG_X86_32 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index 2beac0d7924d9..65494a8ee6108 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -21,6 +21,7 @@ #include <linux/mm_types.h> #include <linux/mm.h> /* find_and_lock_vma() */ #include <linux/vmalloc.h> +#include <linux/ve.h> #include <asm/cpufeature.h> /* boot_cpu_has, ... */ #include <asm/traps.h> /* dotraplinkage, ... */ @@ -746,7 +747,7 @@ static inline void show_signal_msg(struct pt_regs *regs, unsigned long error_code, unsigned long address, struct task_struct *tsk) { - const char *loglvl = task_pid_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG; + const char *loglvl = task_pid_ve_nr(tsk) > 1 ? KERN_INFO : KERN_EMERG; /* This is a racy snapshot, but it's better than nothing. */ int cpu = raw_smp_processor_id(); @@ -757,7 +758,7 @@ show_signal_msg(struct pt_regs *regs, unsigned long error_code, return; ve_printk(VE_LOG, "%s%s[%d]: segfault at %lx ip %px sp %px error %lx", - loglvl, tsk->comm, task_pid_nr(tsk), address, + loglvl, tsk->comm, task_pid_ve_nr(tsk), address, (void *)regs->ip, (void *)regs->sp, error_code); ve_print_vma_addr(VE_LOG, KERN_CONT " in ", regs->ip); @@ -773,7 +774,7 @@ show_signal_msg(struct pt_regs *regs, unsigned long error_code, ve_printk(VE_LOG, KERN_CONT "\n"); - show_opcodes(regs, loglvl); + ve_show_opcodes(regs, loglvl, VE_LOG); } static void -- 2.43.5 _______________________________________________ Devel mailing list [email protected] https://lists.openvz.org/mailman/listinfo/devel
