[Devel] [PATCH vz10 v2 2/2] ve: fix inconsistent dmesg output for segfaults in CT

Aleksei Oladko aleksey.oladko at virtuozzo.com
Mon Nov 24 23:42:48 MSK 2025


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.

https://virtuozzo.atlassian.net/browse/VSTOR-119875
Fixes c3d2bd4b6946f ("ve: Use ve_printk() for often kernel messages about user actions")

v2: used task_pid_ve_nr instead  task_pid_vnr

Signed-off-by: Aleksei Oladko <aleksey.oladko at virtuozzo.com>
---
 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 3881b5333eb8..09e08f36d02e 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 a7d562697e50..b8cd4ae49e9e 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 2beac0d7924d..b109c387ef25 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, ...		*/
@@ -757,8 +758,8 @@ 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,
-		(void *)regs->ip, (void *)regs->sp, error_code);
+		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.0



More information about the Devel mailing list