History

kdb: Fix "btc <cpu>" crash if the CPU didn't round up

I noticed that when I did "btc <cpu>" and the CPU I passed in hadn't rounded up that I'd crash. I was going to copy the same fix from commit 162bc7f5afd7 ("kdb: Don't back trace on a cpu that didn't round up") into the "not all the CPUs" case, but decided it'd be better to clean things up a little bit. This consolidates the two code paths. It is _slightly_ wasteful in in that the checks for "cpu" being too small or being offline isn't really needed when we're iterating over all online CPUs, but that really shouldn't hurt. Better to have the same code path. While at it, eliminate at least one slightly ugly (and totally needless) recursive use of kdb_parse().

Douglas Anderson committed 7 years ago

Commit 55a7e231 parent 54af3e31 file · +34 −27Browse files

Showing the changes to kernel/debug (1 of 1 file). Show all

Unified · Split

kernel/debug/kdb/kdb_bt.c+34−27
@@ -101,6 +101,27 @@ kdb_bt1(struct task_struct *p, unsigned long mask, bool btaprompt) · 100 unmodified lines
101101 return 0;
102102 }
103103
104+static void
105+kdb_bt_cpu(unsigned long cpu)
106+{
107+ struct task_struct *kdb_tsk;
108+
109+ if (cpu >= num_possible_cpus() || !cpu_online(cpu)) {
110+ kdb_printf("WARNING: no process for cpu %ld\n", cpu);
111+ return;
112+ }
113+
114+ /* If a CPU failed to round up we could be here */
115+ kdb_tsk = KDB_TSK(cpu);
116+ if (!kdb_tsk) {
117+ kdb_printf("WARNING: no task for cpu %ld\n", cpu);
118+ return;
119+ }
120+
121+ kdb_set_current_task(kdb_tsk);
122+ kdb_bt1(kdb_tsk, ~0UL, false);
123+}
124+
104125 int
105126 kdb_bt(int argc, const char **argv)
106127 {
@@ -161,7 +182,6 @@ kdb_bt(int argc, const char **argv) · 54 unmodified lines
161182 } else if (strcmp(argv[0], "btc") == 0) {
162183 unsigned long cpu = ~0;
163184 struct task_struct *save_current_task = kdb_current_task;
164− char buf[80];
165185 if (argc > 1)
166186 return KDB_ARGCOUNT;
167187 if (argc == 1) {
@@ -169,35 +189,22 @@ kdb_bt(int argc, const char **argv) · 1 unmodified line
169189 if (diag)
170190 return diag;
171191 }
172− /* Recursive use of kdb_parse, do not use argv after
173− * this point */
174− argv = NULL;
175192 if (cpu != ~0) {
176− if (cpu >= num_possible_cpus() || !cpu_online(cpu)) {
177− kdb_printf("no process for cpu %ld\n", cpu);
178− return 0;
179− }
180− sprintf(buf, "btt 0x%px\n", KDB_TSK(cpu));
181− kdb_parse(buf);
182− return 0;
183− }
184− kdb_printf("btc: cpu status: ");
185− kdb_parse("cpu\n");
186− for_each_online_cpu(cpu) {
187− void *kdb_tsk = KDB_TSK(cpu);
188−
189− /* If a CPU failed to round up we could be here */
190− if (!kdb_tsk) {
191− kdb_printf("WARNING: no task for cpu %ld\n",
192− cpu);
193− continue;
193+ kdb_bt_cpu(cpu);
194+ } else {
195+ /*
196+ * Recursive use of kdb_parse, do not use argv after
197+ * this point.
198+ */
199+ argv = NULL;
200+ kdb_printf("btc: cpu status: ");
201+ kdb_parse("cpu\n");
202+ for_each_online_cpu(cpu) {
203+ kdb_bt_cpu(cpu);
204+ touch_nmi_watchdog();
194205 }
195−
196− sprintf(buf, "btt 0x%px\n", kdb_tsk);
197− kdb_parse(buf);
198− touch_nmi_watchdog();
206+ kdb_set_current_task(save_current_task);
199207 }
200− kdb_set_current_task(save_current_task);
201208 return 0;
202209 } else {
203210 if (argc) {