hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/misc/kgdbts.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * kgdbts is a test suite for kgdb for the sole purpose of validating
34 * that key pieces of the kgdb internals are working properly such as
....@@ -6,19 +7,6 @@
67 * Created by: Jason Wessel <jason.wessel@windriver.com>
78 *
89 * Copyright (c) 2008 Wind River Systems, Inc.
9
- *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License version 2 as
12
- * published by the Free Software Foundation.
13
- *
14
- * This program is distributed in the hope that it will be useful,
15
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
- * See the GNU General Public License for more details.
18
- *
19
- * You should have received a copy of the GNU General Public License
20
- * along with this program; if not, write to the Free Software
21
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2210 */
2311 /* Information about the kgdb test suite.
2412 * -------------------------------------
....@@ -45,16 +33,16 @@
4533 * You can also specify optional tests:
4634 * N## = Go to sleep with interrupts of for ## seconds
4735 * to test the HW NMI watchdog
48
- * F## = Break at do_fork for ## iterations
36
+ * F## = Break at kernel_clone for ## iterations
4937 * S## = Break at sys_open for ## iterations
5038 * I## = Run the single step test ## iterations
5139 *
52
- * NOTE: that the do_fork and sys_open tests are mutually exclusive.
40
+ * NOTE: that the kernel_clone and sys_open tests are mutually exclusive.
5341 *
5442 * To invoke the kgdb test suite from boot you use a kernel start
5543 * argument as follows:
5644 * kgdbts=V1 kgdbwait
57
- * Or if you wanted to perform the NMI test for 6 seconds and do_fork
45
+ * Or if you wanted to perform the NMI test for 6 seconds and kernel_clone
5846 * test for 100 forks, you could use:
5947 * kgdbts=V1N6F100 kgdbwait
6048 *
....@@ -86,7 +74,7 @@
8674 * echo kgdbts=V1S10000 > /sys/module/kgdbts/parameters/kgdbts
8775 * fg # and hit control-c
8876 * fg # and hit control-c
89
- * ## This tests break points on do_fork
77
+ * ## This tests break points on kernel_clone
9078 * while [ 1 ] ; do date > /dev/null ; done &
9179 * while [ 1 ] ; do date > /dev/null ; done &
9280 * echo kgdbts=V1F1000 > /sys/module/kgdbts/parameters/kgdbts
....@@ -222,8 +210,8 @@
222210 addr = (unsigned long)kgdbts_break_test;
223211 else if (!strcmp(arg, "sys_open"))
224212 addr = (unsigned long)do_sys_open;
225
- else if (!strcmp(arg, "do_fork"))
226
- addr = (unsigned long)_do_fork;
213
+ else if (!strcmp(arg, "kernel_clone"))
214
+ addr = (unsigned long)kernel_clone;
227215 else if (!strcmp(arg, "hw_break_val"))
228216 addr = (unsigned long)&hw_break_val;
229217 addr = (unsigned long) dereference_function_descriptor((void *)addr);
....@@ -323,7 +311,7 @@
323311
324312 if (arch_needs_sstep_emulation && sstep_addr &&
325313 ip + offset == sstep_addr &&
326
- ((!strcmp(arg, "sys_open") || !strcmp(arg, "do_fork")))) {
314
+ ((!strcmp(arg, "sys_open") || !strcmp(arg, "kernel_clone")))) {
327315 /* This is special case for emulated single step */
328316 v2printk("Emul: rewind hit single step bp\n");
329317 restart_from_top_after_write = 1;
....@@ -609,19 +597,19 @@
609597 };
610598
611599 /*
612
- * Test for hitting a breakpoint at do_fork for what ever the number
600
+ * Test for hitting a breakpoint at kernel_clone for what ever the number
613601 * of iterations required by the variable repeat_test.
614602 */
615
-static struct test_struct do_fork_test[] = {
603
+static struct test_struct do_kernel_clone_test[] = {
616604 { "?", "S0*" }, /* Clear break points */
617
- { "do_fork", "OK", sw_break, }, /* set sw breakpoint */
605
+ { "kernel_clone", "OK", sw_break, }, /* set sw breakpoint */
618606 { "c", "T0*", NULL, get_thread_id_continue }, /* Continue */
619
- { "do_fork", "OK", sw_rem_break }, /*remove breakpoint */
620
- { "g", "do_fork", NULL, check_and_rewind_pc }, /* check location */
607
+ { "kernel_clone", "OK", sw_rem_break }, /*remove breakpoint */
608
+ { "g", "kernel_clone", NULL, check_and_rewind_pc }, /* check location */
621609 { "write", "OK", write_regs, emul_reset }, /* Write registers */
622610 { "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */
623
- { "g", "do_fork", NULL, check_single_step },
624
- { "do_fork", "OK", sw_break, }, /* set sw breakpoint */
611
+ { "g", "kernel_clone", NULL, check_single_step },
612
+ { "kernel_clone", "OK", sw_break, }, /* set sw breakpoint */
625613 { "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */
626614 { "D", "OK", NULL, final_ack_set }, /* detach and unregister I/O */
627615 { "", "", get_cont_catch, put_cont_catch },
....@@ -841,7 +829,7 @@
841829 char before[BREAK_INSTR_SIZE];
842830 char after[BREAK_INSTR_SIZE];
843831
844
- probe_kernel_read(before, (char *)kgdbts_break_test,
832
+ copy_from_kernel_nofault(before, (char *)kgdbts_break_test,
845833 BREAK_INSTR_SIZE);
846834 init_simple_test();
847835 ts.tst = plant_and_detach_test;
....@@ -849,8 +837,8 @@
849837 /* Activate test with initial breakpoint */
850838 if (!is_early)
851839 kgdb_breakpoint();
852
- probe_kernel_read(after, (char *)kgdbts_break_test,
853
- BREAK_INSTR_SIZE);
840
+ copy_from_kernel_nofault(after, (char *)kgdbts_break_test,
841
+ BREAK_INSTR_SIZE);
854842 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
855843 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
856844 panic("kgdb memory corruption");
....@@ -948,11 +936,11 @@
948936 kgdb_breakpoint();
949937 }
950938
951
-static void run_do_fork_test(void)
939
+static void run_kernel_clone_test(void)
952940 {
953941 init_simple_test();
954
- ts.tst = do_fork_test;
955
- ts.name = "do_fork_test";
942
+ ts.tst = do_kernel_clone_test;
943
+ ts.name = "do_kernel_clone_test";
956944 /* Activate test with initial breakpoint */
957945 kgdb_breakpoint();
958946 }
....@@ -980,7 +968,7 @@
980968 static void kgdbts_run_tests(void)
981969 {
982970 char *ptr;
983
- int fork_test = 0;
971
+ int clone_test = 0;
984972 int do_sys_open_test = 0;
985973 int sstep_test = 1000;
986974 int nmi_sleep = 0;
....@@ -994,7 +982,7 @@
994982
995983 ptr = strchr(config, 'F');
996984 if (ptr)
997
- fork_test = simple_strtol(ptr + 1, NULL, 10);
985
+ clone_test = simple_strtol(ptr + 1, NULL, 10);
998986 ptr = strchr(config, 'S');
999987 if (ptr)
1000988 do_sys_open_test = simple_strtol(ptr + 1, NULL, 10);
....@@ -1038,16 +1026,16 @@
10381026 run_nmi_sleep_test(nmi_sleep);
10391027 }
10401028
1041
- /* If the do_fork test is run it will be the last test that is
1029
+ /* If the kernel_clone test is run it will be the last test that is
10421030 * executed because a kernel thread will be spawned at the very
10431031 * end to unregister the debug hooks.
10441032 */
1045
- if (fork_test) {
1046
- repeat_test = fork_test;
1047
- printk(KERN_INFO "kgdbts:RUN do_fork for %i breakpoints\n",
1033
+ if (clone_test) {
1034
+ repeat_test = clone_test;
1035
+ printk(KERN_INFO "kgdbts:RUN kernel_clone for %i breakpoints\n",
10481036 repeat_test);
10491037 kthread_run(kgdbts_unreg_thread, NULL, "kgdbts_unreg");
1050
- run_do_fork_test();
1038
+ run_kernel_clone_test();
10511039 return;
10521040 }
10531041
....@@ -1072,10 +1060,10 @@
10721060 {
10731061 if (strlen(opt) >= MAX_CONFIG_LEN) {
10741062 printk(KERN_ERR "kgdbts: config string too long\n");
1075
- return -ENOSPC;
1063
+ return 1;
10761064 }
10771065 strcpy(config, opt);
1078
- return 0;
1066
+ return 1;
10791067 }
10801068
10811069 __setup("kgdbts=", kgdbts_option_setup);