Commit 3d396f7041788d392c4df3d5214a0ec6ce546069

Authored by Jason Wessel
Committed by Greg Kroah-Hartman
1 parent 5aa0f98153

kgdbts: Fix kernel oops with CONFIG_DEBUG_RODATA

commit 456ca7ff24841bf2d2a2dfd690fe7d42ef70d932 upstream.

On x86 the kgdb test suite will oops when the kernel is compiled with
CONFIG_DEBUG_RODATA and you run the tests after boot time. This is
regression has existed since 2.6.26 by commit: b33cb815 (kgdbts: Use
HW breakpoints with CONFIG_DEBUG_RODATA).

The test suite can use hw breakpoints for all the tests, but it has to
execute the hardware breakpoint specific tests first in order to
determine that the hw breakpoints actually work.  Specifically the
very first test causes an oops:

# echo V1I1 > /sys/module/kgdbts/parameters/kgdbts
kgdb: Registered I/O driver kgdbts.
kgdbts:RUN plant and detach test

Entering kdb (current=0xffff880017aa9320, pid 1078) on processor 0 due to Keyboard Entry
[0]kdb> kgdbts: ERROR PUT: end of test buffer on 'plant_and_detach_test' line 1 expected OK got $E14#aa
WARNING: at drivers/misc/kgdbts.c:730 run_simple_test+0x151/0x2c0()
[...oops clipped...]

This commit re-orders the running of the tests and puts the RODATA
check into its own function so as to correctly avoid the kernel oops
by detecting and using the hw breakpoints.

Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 28 additions and 24 deletions Side-by-side Diff

drivers/misc/kgdbts.c
... ... @@ -885,6 +885,22 @@
885 885 kgdbts_break_test();
886 886 }
887 887  
  888 +static void test_debug_rodata(void)
  889 +{
  890 +#ifdef CONFIG_DEBUG_RODATA
  891 + /* Until there is an api to write to read-only text segments, use
  892 + * HW breakpoints for the remainder of any tests, else print a
  893 + * failure message if hw breakpoints do not work.
  894 + */
  895 + if (!(arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT && hwbreaks_ok)) {
  896 + eprintk("kgdbts: HW breakpoints BROKEN, ending tests\n");
  897 + return;
  898 + }
  899 + force_hwbrks = 1;
  900 + v1printk("kgdbts:Using HW breakpoints for SW breakpoint tests\n");
  901 +#endif /* CONFIG_DEBUG_RODATA */
  902 +}
  903 +
888 904 static void kgdbts_run_tests(void)
889 905 {
890 906 char *ptr;
... ... @@ -907,6 +923,18 @@
907 923 if (ptr)
908 924 sstep_test = simple_strtol(ptr+1, NULL, 10);
909 925  
  926 + /* All HW break point tests */
  927 + if (arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT) {
  928 + hwbreaks_ok = 1;
  929 + v1printk("kgdbts:RUN hw breakpoint test\n");
  930 + run_breakpoint_test(1);
  931 + v1printk("kgdbts:RUN hw write breakpoint test\n");
  932 + run_hw_break_test(1);
  933 + v1printk("kgdbts:RUN access write breakpoint test\n");
  934 + run_hw_break_test(0);
  935 + }
  936 + test_debug_rodata();
  937 +
910 938 /* required internal KGDB tests */
911 939 v1printk("kgdbts:RUN plant and detach test\n");
912 940 run_plant_and_detach_test(0);
913 941  
... ... @@ -924,34 +952,10 @@
924 952  
925 953 /* ===Optional tests=== */
926 954  
927   - /* All HW break point tests */
928   - if (arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT) {
929   - hwbreaks_ok = 1;
930   - v1printk("kgdbts:RUN hw breakpoint test\n");
931   - run_breakpoint_test(1);
932   - v1printk("kgdbts:RUN hw write breakpoint test\n");
933   - run_hw_break_test(1);
934   - v1printk("kgdbts:RUN access write breakpoint test\n");
935   - run_hw_break_test(0);
936   - }
937   -
938 955 if (nmi_sleep) {
939 956 v1printk("kgdbts:RUN NMI sleep %i seconds test\n", nmi_sleep);
940 957 run_nmi_sleep_test(nmi_sleep);
941 958 }
942   -
943   -#ifdef CONFIG_DEBUG_RODATA
944   - /* Until there is an api to write to read-only text segments, use
945   - * HW breakpoints for the remainder of any tests, else print a
946   - * failure message if hw breakpoints do not work.
947   - */
948   - if (!(arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT && hwbreaks_ok)) {
949   - eprintk("kgdbts: HW breakpoints do not work,"
950   - "skipping remaining tests\n");
951   - return;
952   - }
953   - force_hwbrks = 1;
954   -#endif /* CONFIG_DEBUG_RODATA */
955 959  
956 960 /* If the do_fork test is run it will be the last test that is
957 961 * executed because a kernel thread will be spawned at the very