.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | | - * This program is free software; you can redistribute it and/or modify it |
---|
3 | | - * under the terms of the GNU General Public License as published by the |
---|
4 | | - * Free Software Foundation; either version 2, or (at your option) any |
---|
5 | | - * later version. |
---|
6 | | - * |
---|
7 | | - * This program is distributed in the hope that it will be useful, but |
---|
8 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
9 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
10 | | - * General Public License for more details. |
---|
11 | | - * |
---|
12 | 3 | */ |
---|
13 | 4 | |
---|
14 | 5 | /* |
---|
.. | .. |
---|
127 | 118 | |
---|
128 | 119 | #ifdef CONFIG_X86_32 |
---|
129 | 120 | switch (regno) { |
---|
130 | | - case GDB_SS: |
---|
131 | | - if (!user_mode(regs)) |
---|
132 | | - *(unsigned long *)mem = __KERNEL_DS; |
---|
133 | | - break; |
---|
134 | | - case GDB_SP: |
---|
135 | | - if (!user_mode(regs)) |
---|
136 | | - *(unsigned long *)mem = kernel_stack_pointer(regs); |
---|
137 | | - break; |
---|
138 | 121 | case GDB_GS: |
---|
139 | 122 | case GDB_FS: |
---|
140 | 123 | *(unsigned long *)mem = 0xFFFF; |
---|
.. | .. |
---|
422 | 405 | #ifdef CONFIG_SMP |
---|
423 | 406 | /** |
---|
424 | 407 | * kgdb_roundup_cpus - Get other CPUs into a holding pattern |
---|
425 | | - * @flags: Current IRQ state |
---|
426 | 408 | * |
---|
427 | 409 | * On SMP systems, we need to get the attention of the other CPUs |
---|
428 | 410 | * and get them be in a known state. This should do what is needed |
---|
429 | 411 | * to get the other CPUs to call kgdb_wait(). Note that on some arches, |
---|
430 | 412 | * the NMI approach is not used for rounding up all the CPUs. For example, |
---|
431 | | - * in case of MIPS, smp_call_function() is used to roundup CPUs. In |
---|
432 | | - * this case, we have to make sure that interrupts are enabled before |
---|
433 | | - * calling smp_call_function(). The argument to this function is |
---|
434 | | - * the flags that will be used when restoring the interrupts. There is |
---|
435 | | - * local_irq_save() call before kgdb_roundup_cpus(). |
---|
| 413 | + * in case of MIPS, smp_call_function() is used to roundup CPUs. |
---|
436 | 414 | * |
---|
437 | 415 | * On non-SMP systems, this is not called. |
---|
438 | 416 | */ |
---|
439 | | -void kgdb_roundup_cpus(unsigned long flags) |
---|
| 417 | +void kgdb_roundup_cpus(void) |
---|
440 | 418 | { |
---|
441 | | - apic->send_IPI_allbutself(NMI_VECTOR); |
---|
| 419 | + apic_send_IPI_allbutself(NMI_VECTOR); |
---|
442 | 420 | } |
---|
443 | 421 | #endif |
---|
444 | 422 | |
---|
.. | .. |
---|
472 | 450 | ptr = &remcomInBuffer[1]; |
---|
473 | 451 | if (kgdb_hex2long(&ptr, &addr)) |
---|
474 | 452 | linux_regs->ip = addr; |
---|
| 453 | + fallthrough; |
---|
475 | 454 | case 'D': |
---|
476 | 455 | case 'k': |
---|
477 | 456 | /* clear the trace bit */ |
---|
.. | .. |
---|
560 | 539 | * a system call which should be ignored |
---|
561 | 540 | */ |
---|
562 | 541 | return NOTIFY_DONE; |
---|
563 | | - /* fall through */ |
---|
| 542 | + fallthrough; |
---|
564 | 543 | default: |
---|
565 | 544 | if (user_mode(regs)) |
---|
566 | 545 | return NOTIFY_DONE; |
---|
.. | .. |
---|
650 | 629 | struct task_struct *tsk = current; |
---|
651 | 630 | int i; |
---|
652 | 631 | |
---|
653 | | - for (i = 0; i < 4; i++) |
---|
| 632 | + for (i = 0; i < 4; i++) { |
---|
654 | 633 | if (breakinfo[i].enabled) |
---|
655 | | - tsk->thread.debugreg6 |= (DR_TRAP0 << i); |
---|
| 634 | + tsk->thread.virtual_dr6 |= (DR_TRAP0 << i); |
---|
| 635 | + } |
---|
656 | 636 | } |
---|
657 | 637 | |
---|
658 | 638 | void kgdb_arch_late(void) |
---|
.. | .. |
---|
751 | 731 | int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt) |
---|
752 | 732 | { |
---|
753 | 733 | int err; |
---|
754 | | - char opc[BREAK_INSTR_SIZE]; |
---|
755 | 734 | |
---|
756 | 735 | bpt->type = BP_BREAKPOINT; |
---|
757 | | - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr, |
---|
| 736 | + err = copy_from_kernel_nofault(bpt->saved_instr, (char *)bpt->bpt_addr, |
---|
758 | 737 | BREAK_INSTR_SIZE); |
---|
759 | 738 | if (err) |
---|
760 | 739 | return err; |
---|
761 | | - err = probe_kernel_write((char *)bpt->bpt_addr, |
---|
| 740 | + err = copy_to_kernel_nofault((char *)bpt->bpt_addr, |
---|
762 | 741 | arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE); |
---|
763 | 742 | if (!err) |
---|
764 | 743 | return err; |
---|
765 | 744 | /* |
---|
766 | | - * It is safe to call text_poke() because normal kernel execution |
---|
| 745 | + * It is safe to call text_poke_kgdb() because normal kernel execution |
---|
767 | 746 | * is stopped on all cores, so long as the text_mutex is not locked. |
---|
768 | 747 | */ |
---|
769 | 748 | if (mutex_is_locked(&text_mutex)) |
---|
770 | 749 | return -EBUSY; |
---|
771 | | - text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr, |
---|
772 | | - BREAK_INSTR_SIZE); |
---|
773 | | - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE); |
---|
774 | | - if (err) |
---|
775 | | - return err; |
---|
776 | | - if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE)) |
---|
777 | | - return -EINVAL; |
---|
| 750 | + text_poke_kgdb((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr, |
---|
| 751 | + BREAK_INSTR_SIZE); |
---|
778 | 752 | bpt->type = BP_POKE_BREAKPOINT; |
---|
779 | 753 | |
---|
780 | | - return err; |
---|
| 754 | + return 0; |
---|
781 | 755 | } |
---|
782 | 756 | |
---|
783 | 757 | int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt) |
---|
784 | 758 | { |
---|
785 | | - int err; |
---|
786 | | - char opc[BREAK_INSTR_SIZE]; |
---|
787 | | - |
---|
788 | 759 | if (bpt->type != BP_POKE_BREAKPOINT) |
---|
789 | 760 | goto knl_write; |
---|
790 | 761 | /* |
---|
791 | | - * It is safe to call text_poke() because normal kernel execution |
---|
| 762 | + * It is safe to call text_poke_kgdb() because normal kernel execution |
---|
792 | 763 | * is stopped on all cores, so long as the text_mutex is not locked. |
---|
793 | 764 | */ |
---|
794 | 765 | if (mutex_is_locked(&text_mutex)) |
---|
795 | 766 | goto knl_write; |
---|
796 | | - text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE); |
---|
797 | | - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE); |
---|
798 | | - if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE)) |
---|
799 | | - goto knl_write; |
---|
800 | | - return err; |
---|
| 767 | + text_poke_kgdb((void *)bpt->bpt_addr, bpt->saved_instr, |
---|
| 768 | + BREAK_INSTR_SIZE); |
---|
| 769 | + return 0; |
---|
801 | 770 | |
---|
802 | 771 | knl_write: |
---|
803 | | - return probe_kernel_write((char *)bpt->bpt_addr, |
---|
| 772 | + return copy_to_kernel_nofault((char *)bpt->bpt_addr, |
---|
804 | 773 | (char *)bpt->saved_instr, BREAK_INSTR_SIZE); |
---|
805 | 774 | } |
---|
806 | 775 | |
---|
807 | | -struct kgdb_arch arch_kgdb_ops = { |
---|
| 776 | +const struct kgdb_arch arch_kgdb_ops = { |
---|
808 | 777 | /* Breakpoint instruction: */ |
---|
809 | 778 | .gdb_bpt_instr = { 0xcc }, |
---|
810 | 779 | .flags = KGDB_HW_BREAKPOINT, |
---|