Module Name: src
Committed By: bouyer
Date: Sun Jun 12 11:36:43 UTC 2022
Modified Files:
src/sys/arch/amd64/amd64: genassym.cf locore.S
src/sys/arch/i386/i386: genassym.cf locore.S
Log Message:
XenPV: in cpu_switchto(), reset ci_xen_clockf_usermode/ci_xen_clockf_pc,
in case a clock interrupt is deffered while we're switching lwp.
Fix a (rare) panic:
panic: kernel diagnostic assertion "p != NULL" failed: file
"/usr/src/sys/kern/kern_clock.c", line 438
seen when xen_timer_handler() is called from the splx() at the end of
mi_switch()
To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/sys/arch/amd64/amd64/genassym.cf
cvs rdiff -u -r1.212 -r1.213 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.123 -r1.124 src/sys/arch/i386/i386/genassym.cf
cvs rdiff -u -r1.188 -r1.189 src/sys/arch/i386/i386/locore.S
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/amd64/amd64/genassym.cf
diff -u src/sys/arch/amd64/amd64/genassym.cf:1.86 src/sys/arch/amd64/amd64/genassym.cf:1.87
--- src/sys/arch/amd64/amd64/genassym.cf:1.86 Tue May 24 15:55:19 2022
+++ src/sys/arch/amd64/amd64/genassym.cf Sun Jun 12 11:36:42 2022
@@ -1,4 +1,4 @@
-# $NetBSD: genassym.cf,v 1.86 2022/05/24 15:55:19 bouyer Exp $
+# $NetBSD: genassym.cf,v 1.87 2022/06/12 11:36:42 bouyer Exp $
#
# Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -376,6 +376,8 @@ ifdef XENPV
define XEN_PT_BASE offsetof(struct start_info, pt_base)
define XEN_NR_PT_FRAMES offsetof(struct start_info, nr_pt_frames)
define __HYPERVISOR_iret __HYPERVISOR_iret
+define CPU_INFO_XEN_CLOCKF_USERMODE offsetof(struct cpu_info, ci_xen_clockf_usermode)
+define CPU_INFO_XEN_CLOCKF_PC offsetof(struct cpu_info, ci_xen_clockf_pc)
endif /* XENPV */
endif /* XEN */
Index: src/sys/arch/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.212 src/sys/arch/amd64/amd64/locore.S:1.213
--- src/sys/arch/amd64/amd64/locore.S:1.212 Wed Nov 10 15:59:07 2021
+++ src/sys/arch/amd64/amd64/locore.S Sun Jun 12 11:36:42 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.S,v 1.212 2021/11/10 15:59:07 msaitoh Exp $ */
+/* $NetBSD: locore.S,v 1.213 2022/06/12 11:36:42 bouyer Exp $ */
/*
* Copyright-o-rama!
@@ -1183,6 +1183,16 @@ ENTRY(cpu_switchto)
movq %r12,%rcx
xchgq %rcx,CPUVAR(CURLWP)
+#ifdef XENPV
+ /* if we are there, we're obviously not in user context.
+ * reset ci_xen_clockf_* in case the splx() at the end of mi_switch()
+ * triggers a deffered call do xen_timer_handler()
+ */
+ movb $0, CPUVAR(XEN_CLOCKF_USERMODE)
+ movq $_C_LABEL(cpu_switchto), CPUVAR(XEN_CLOCKF_PC)
+#endif
+
+
/* Skip the rest if returning to a pinned LWP. */
testb %dl,%dl /* returning = true ? */
jnz .Lswitch_return
Index: src/sys/arch/i386/i386/genassym.cf
diff -u src/sys/arch/i386/i386/genassym.cf:1.123 src/sys/arch/i386/i386/genassym.cf:1.124
--- src/sys/arch/i386/i386/genassym.cf:1.123 Tue May 24 15:55:19 2022
+++ src/sys/arch/i386/i386/genassym.cf Sun Jun 12 11:36:42 2022
@@ -1,4 +1,4 @@
-# $NetBSD: genassym.cf,v 1.123 2022/05/24 15:55:19 bouyer Exp $
+# $NetBSD: genassym.cf,v 1.124 2022/06/12 11:36:42 bouyer Exp $
#
# Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -392,3 +392,8 @@ define EVTCHN_UPCALL_MASK offsetof(struc
define HYPERVISOR_sched_op __HYPERVISOR_sched_op
define SCHEDOP_yield SCHEDOP_yield
endif /* XEN */
+
+ifdef XENPV
+define CPU_INFO_XEN_CLOCKF_USERMODE offsetof(struct cpu_info, ci_xen_clockf_usermode)
+define CPU_INFO_XEN_CLOCKF_PC offsetof(struct cpu_info, ci_xen_clockf_pc)
+endif /* XENPV */
Index: src/sys/arch/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.188 src/sys/arch/i386/i386/locore.S:1.189
--- src/sys/arch/i386/i386/locore.S:1.188 Tue May 31 18:04:11 2022
+++ src/sys/arch/i386/i386/locore.S Sun Jun 12 11:36:42 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.S,v 1.188 2022/05/31 18:04:11 bouyer Exp $ */
+/* $NetBSD: locore.S,v 1.189 2022/06/12 11:36:42 bouyer Exp $ */
/*
* Copyright-o-rama!
@@ -128,7 +128,7 @@
*/
#include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.188 2022/05/31 18:04:11 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.189 2022/06/12 11:36:42 bouyer Exp $");
#include "opt_copy_symtab.h"
#include "opt_ddb.h"
@@ -1407,6 +1407,15 @@ ENTRY(cpu_switchto)
movl %edi,%ecx
xchgl %ecx,CPUVAR(CURLWP)
+#ifdef XENPV
+ /* if we are there, we're obviously not in user context.
+ * reset ci_xen_clockf_* in case the splx() at the end of mi_switch()
+ * triggers a deffered call do xen_timer_handler()
+ */
+ movb $0, CPUVAR(XEN_CLOCKF_USERMODE)
+ movl $_C_LABEL(cpu_switchto), CPUVAR(XEN_CLOCKF_PC)
+#endif
+
/* Skip the rest if returning to a pinned LWP. */
testl %edx,%edx
jnz switch_return