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
101 return 0;101 return 0;
102}102}
103 103
104static void
105kdb_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
104int125int
105kdb_bt(int argc, const char **argv)126kdb_bt(int argc, const char **argv)
106{127{
@@ -161,7 +182,6 @@ kdb_bt(int argc, const char **argv) · 54 unmodified lines
161 } else if (strcmp(argv[0], "btc") == 0) {182 } else if (strcmp(argv[0], "btc") == 0) {
162 unsigned long cpu = ~0;183 unsigned long cpu = ~0;
163 struct task_struct *save_current_task = kdb_current_task;184 struct task_struct *save_current_task = kdb_current_task;
164 char buf[80];
165 if (argc > 1)185 if (argc > 1)
166 return KDB_ARGCOUNT;186 return KDB_ARGCOUNT;
167 if (argc == 1) {187 if (argc == 1) {
@@ -169,35 +189,22 @@ kdb_bt(int argc, const char **argv) · 1 unmodified line
169 if (diag)189 if (diag)
170 return diag;190 return diag;
171 }191 }
172 /* Recursive use of kdb_parse, do not use argv after
173 * this point */
174 argv = NULL;
175 if (cpu != ~0) {192 if (cpu != ~0) {
176 if (cpu >= num_possible_cpus() || !cpu_online(cpu)) {193 kdb_bt_cpu(cpu);
177 kdb_printf("no process for cpu %ld\n", cpu);194 } else {
178 return 0;195 /*
179 }196 * Recursive use of kdb_parse, do not use argv after
180 sprintf(buf, "btt 0x%px\n", KDB_TSK(cpu));197 * this point.
181 kdb_parse(buf);198 */
182 return 0;199 argv = NULL;
183 }200 kdb_printf("btc: cpu status: ");
184 kdb_printf("btc: cpu status: ");201 kdb_parse("cpu\n");
185 kdb_parse("cpu\n");202 for_each_online_cpu(cpu) {
186 for_each_online_cpu(cpu) {203 kdb_bt_cpu(cpu);
187 void *kdb_tsk = KDB_TSK(cpu);204 touch_nmi_watchdog();
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;
194 }205 }
195 206 kdb_set_current_task(save_current_task);
196 sprintf(buf, "btt 0x%px\n", kdb_tsk);
197 kdb_parse(buf);
198 touch_nmi_watchdog();
199 }207 }
200 kdb_set_current_task(save_current_task);
201 return 0;208 return 0;
202 } else {209 } else {
203 if (argc) {210 if (argc) {