Module Name:    src
Committed By:   ryo
Date:           Sat Sep  7 09:27:25 UTC 2019

Modified Files:
        src/sys/arch/aarch64/aarch64: db_machdep.c

Log Message:
prevent switching to CPUs that are not responding to IPI_DDB.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/aarch64/aarch64/db_machdep.c

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/aarch64/aarch64/db_machdep.c
diff -u src/sys/arch/aarch64/aarch64/db_machdep.c:1.18 src/sys/arch/aarch64/aarch64/db_machdep.c:1.19
--- src/sys/arch/aarch64/aarch64/db_machdep.c:1.18	Sat Sep  7 09:21:17 2019
+++ src/sys/arch/aarch64/aarch64/db_machdep.c	Sat Sep  7 09:27:25 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: db_machdep.c,v 1.18 2019/09/07 09:21:17 ryo Exp $ */
+/* $NetBSD: db_machdep.c,v 1.19 2019/09/07 09:27:25 ryo Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.18 2019/09/07 09:21:17 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_machdep.c,v 1.19 2019/09/07 09:27:25 ryo Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd32.h"
@@ -868,24 +868,39 @@ db_md_watch_cmd(db_expr_t addr, bool hav
 volatile struct cpu_info *db_trigger;
 volatile struct cpu_info *db_onproc;
 volatile struct cpu_info *db_newcpu;
+volatile int db_readytoswitch[MAXCPUS];
 
 #ifdef _KERNEL
 void
 db_md_switch_cpu_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
     const char *modif)
 {
+	struct cpu_info *new_ci = NULL;
 	u_int cpuno = (u_int)addr;
+	int i;
+
+	membar_consumer();
 
-	if (!have_addr || (cpuno >= ncpu)) {
-		db_printf("cpu: 0..%d\n", ncpu - 1);
+	if (!have_addr) {
+		for (i = 0; i < ncpu; i++) {
+			if (db_readytoswitch[i] != 0)
+				db_printf("cpu%d: ready\n", i);
+			else
+				db_printf("cpu%d: not responding\n", i);
+		}
 		return;
 	}
 
-	struct cpu_info *new_ci = cpu_lookup(cpuno);
+	if (cpuno < ncpu)
+		new_ci = cpu_lookup(cpuno);
 	if (new_ci == NULL) {
 		db_printf("cpu %u does not exist", cpuno);
 		return;
 	}
+	if (db_readytoswitch[new_ci->ci_index] == 0) {
+		db_printf("cpu %u is not responding", cpuno);
+		return;
+	}
 
 	if (new_ci == curcpu())
 		return;
@@ -940,6 +955,8 @@ kdb_trap(int type, struct trapframe *tf)
 		db_trigger = ci;
 		membar_producer();
 	}
+	db_readytoswitch[ci->ci_index] = 1;
+	membar_producer();
 #endif
 
 	for (;;) {
@@ -993,6 +1010,8 @@ kdb_trap(int type, struct trapframe *tf)
 		__asm __volatile ("sev; sev; sev");
 	}
 	db_trigger = NULL;
+	db_readytoswitch[ci->ci_index] = 0;
+	membar_producer();
 #endif
 
 	return 1;

Reply via email to