Changes in 4.9.231 KVM: s390: reduce number of IO pins to 1 gpu: host1x: Detach driver on unregister spi: spidev: fix a race between spidev_release and spidev_remove spi: spidev: fix a potential use-after-free in spidev_release() s390/kasan: fix early pgm check handler execution cifs: update ctime and mtime during truncate ARM: imx6: add missing put_device() call in imx6q_suspend_init() scsi: mptscsih: Fix read sense data size net: cxgb4: fix return error value in t4_prep_fw smsc95xx: check return value of smsc95xx_reset smsc95xx: avoid memory leak in smsc95xx_bind ALSA: compress: fix partial_drain completion state arm64: kgdb: Fix single-step exception handling oops bnxt_en: fix NULL dereference in case SR-IOV configuration fails net: macb: mark device wake capable when "magic-packet" property present ALSA: opl3: fix infoleak in opl3 ALSA: hda - let hs_mic be picked ahead of hp_mic ALSA: usb-audio: add quirk for MacroSilicon MS2109 KVM: arm64: Fix definition of PAGE_HYP_DEVICE KVM: x86: bit 8 of non-leaf PDPEs is not reserved Revert "ath9k: Fix general protection fault in ath9k_hif_usb_rx_cb" btrfs: fix fatal extent_buffer readahead vs releasepage race drm/radeon: fix double free ARC: entry: fix potential EFA clobber when TIF_SYSCALL_TRACE ARC: elf: use right ELF_ARCH s390/mm: fix huge pte soft dirty copying ipv4: fill fl4_icmp_{type,code} in ping_v4_sendmsg l2tp: remove skb_dst_set() from l2tp_xmit_skb() llc: make sure applications use ARPHRD_ETHER net: Added pointer check for dst->ops->neigh_lookup in dst_neigh_lookup_skb net: usb: qmi_wwan: add support for Quectel EG95 LTE modem tcp: md5: add missing memory barriers in tcp_md5_do_add()/tcp_md5_hash_key() tcp: md5: refine tcp_md5_do_add()/tcp_md5_hash_key() barriers genetlink: remove genl_bind tcp: make sure listeners don't initialize congestion-control state tcp: md5: do not send silly options in SYNCOOKIES tcp: md5: allow changing MD5 keys in all socket states cgroup: fix cgroup_sk_alloc() for sk_clone_lock() cgroup: Fix sock_cgroup_data on big-endian. i2c: eg20t: Load module automatically if ID matches iio:magnetometer:ak8974: Fix alignment and data leak issues iio: magnetometer: ak8974: Fix runtime PM imbalance on error iio: mma8452: Add missed iio_device_unregister() call in mma8452_probe() iio: pressure: zpa2326: handle pm_runtime_get_sync failure iio:pressure:ms5611 Fix buffer element alignment iio:health:afe4403 Fix timestamp alignment and prevent data leak. spi: fix initial SPI_SR value in spi-fsl-dspi net: dsa: bcm_sf2: Fix node reference count Revert "usb/ehci-platform: Set PM runtime as active on resume" Revert "usb/xhci-plat: Set PM runtime as active on resume" Revert "usb/ohci-platform: Fix a warning when hibernating" iio:health:afe4404 Fix timestamp alignment and prevent data leak. spi: spi-sun6i: sun6i_spi_transfer_one(): fix setting of clock rate usb: gadget: udc: atmel: fix uninitialized read in debug printk staging: comedi: verify array index is correct before using it Revert "thermal: mediatek: fix register index error" ARM: dts: socfpga: Align L2 cache-controller nodename with dtschema perf stat: Zero all the 'ena' and 'run' array slot stats for interval mode mtd: rawnand: brcmnand: fix CS0 layout HID: magicmouse: do not set up autorepeat usb: core: Add a helper function to check the validity of EP type in URB ALSA: line6: Perform sanity check for each URB creation ALSA: usb-audio: Fix race against the error recovery URB submission USB: c67x00: fix use after free in c67x00_giveback_urb usb: dwc2: Fix shutdown callback in platform usb: chipidea: core: add wakeup support for extcon usb: gadget: function: fix missing spinlock in f_uac1_legacy USB: serial: iuu_phoenix: fix memory corruption USB: serial: cypress_m8: enable Simply Automated UPB PIM USB: serial: ch341: add new Product ID for CH340 USB: serial: option: add GosunCn GM500 series USB: serial: option: add Quectel EG95 LTE modem virtio: virtio_console: add missing MODULE_DEVICE_TABLE() for rproc serial fuse: Fix parameter for FS_IOC_{GET,SET}FLAGS mei: bus: don't clean driver pointer Input: i8042 - add Lenovo XiaoXin Air 12 to i8042 nomux list uio_pdrv_genirq: fix use without device tree and no interrupt timer: Fix wheel index calculation on last level MIPS: Fix build for LTS kernel caused by backporting lpj adjustment hwmon: (emc2103) fix unable to change fan pwm1_enable attribute dmaengine: fsl-edma: Fix NULL pointer exception in fsl_edma_tx_handler misc: atmel-ssc: lock with mutex instead of spinlock arm64: ptrace: Override SPSR.SS when single-stepping is enabled sched/fair: handle case of task_h_load() returning 0 irqchip/gic: Atomically update affinity x86/cpu: Move x86_cache_bits settings Linux 4.9.231 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I57b0f3c4ffcdc49231d1c48f3f25fae424daeeb9
374 lines
9.6 KiB
C
374 lines
9.6 KiB
C
/*
|
|
* AArch64 KGDB support
|
|
*
|
|
* Based on arch/arm/kernel/kgdb.c
|
|
*
|
|
* Copyright (C) 2013 Cavium Inc.
|
|
* Author: Vijaya Kumar K <vijaya.kumar@caviumnetworks.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <linux/bug.h>
|
|
#include <linux/irq.h>
|
|
#include <linux/kdebug.h>
|
|
#include <linux/kgdb.h>
|
|
#include <linux/kprobes.h>
|
|
#include <asm/debug-monitors.h>
|
|
#include <asm/insn.h>
|
|
#include <asm/traps.h>
|
|
|
|
struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = {
|
|
{ "x0", 8, offsetof(struct pt_regs, regs[0])},
|
|
{ "x1", 8, offsetof(struct pt_regs, regs[1])},
|
|
{ "x2", 8, offsetof(struct pt_regs, regs[2])},
|
|
{ "x3", 8, offsetof(struct pt_regs, regs[3])},
|
|
{ "x4", 8, offsetof(struct pt_regs, regs[4])},
|
|
{ "x5", 8, offsetof(struct pt_regs, regs[5])},
|
|
{ "x6", 8, offsetof(struct pt_regs, regs[6])},
|
|
{ "x7", 8, offsetof(struct pt_regs, regs[7])},
|
|
{ "x8", 8, offsetof(struct pt_regs, regs[8])},
|
|
{ "x9", 8, offsetof(struct pt_regs, regs[9])},
|
|
{ "x10", 8, offsetof(struct pt_regs, regs[10])},
|
|
{ "x11", 8, offsetof(struct pt_regs, regs[11])},
|
|
{ "x12", 8, offsetof(struct pt_regs, regs[12])},
|
|
{ "x13", 8, offsetof(struct pt_regs, regs[13])},
|
|
{ "x14", 8, offsetof(struct pt_regs, regs[14])},
|
|
{ "x15", 8, offsetof(struct pt_regs, regs[15])},
|
|
{ "x16", 8, offsetof(struct pt_regs, regs[16])},
|
|
{ "x17", 8, offsetof(struct pt_regs, regs[17])},
|
|
{ "x18", 8, offsetof(struct pt_regs, regs[18])},
|
|
{ "x19", 8, offsetof(struct pt_regs, regs[19])},
|
|
{ "x20", 8, offsetof(struct pt_regs, regs[20])},
|
|
{ "x21", 8, offsetof(struct pt_regs, regs[21])},
|
|
{ "x22", 8, offsetof(struct pt_regs, regs[22])},
|
|
{ "x23", 8, offsetof(struct pt_regs, regs[23])},
|
|
{ "x24", 8, offsetof(struct pt_regs, regs[24])},
|
|
{ "x25", 8, offsetof(struct pt_regs, regs[25])},
|
|
{ "x26", 8, offsetof(struct pt_regs, regs[26])},
|
|
{ "x27", 8, offsetof(struct pt_regs, regs[27])},
|
|
{ "x28", 8, offsetof(struct pt_regs, regs[28])},
|
|
{ "x29", 8, offsetof(struct pt_regs, regs[29])},
|
|
{ "x30", 8, offsetof(struct pt_regs, regs[30])},
|
|
{ "sp", 8, offsetof(struct pt_regs, sp)},
|
|
{ "pc", 8, offsetof(struct pt_regs, pc)},
|
|
/*
|
|
* struct pt_regs thinks PSTATE is 64-bits wide but gdb remote
|
|
* protocol disagrees. Therefore we must extract only the lower
|
|
* 32-bits. Look for the big comment in asm/kgdb.h for more
|
|
* detail.
|
|
*/
|
|
{ "pstate", 4, offsetof(struct pt_regs, pstate)
|
|
#ifdef CONFIG_CPU_BIG_ENDIAN
|
|
+ 4
|
|
#endif
|
|
},
|
|
{ "v0", 16, -1 },
|
|
{ "v1", 16, -1 },
|
|
{ "v2", 16, -1 },
|
|
{ "v3", 16, -1 },
|
|
{ "v4", 16, -1 },
|
|
{ "v5", 16, -1 },
|
|
{ "v6", 16, -1 },
|
|
{ "v7", 16, -1 },
|
|
{ "v8", 16, -1 },
|
|
{ "v9", 16, -1 },
|
|
{ "v10", 16, -1 },
|
|
{ "v11", 16, -1 },
|
|
{ "v12", 16, -1 },
|
|
{ "v13", 16, -1 },
|
|
{ "v14", 16, -1 },
|
|
{ "v15", 16, -1 },
|
|
{ "v16", 16, -1 },
|
|
{ "v17", 16, -1 },
|
|
{ "v18", 16, -1 },
|
|
{ "v19", 16, -1 },
|
|
{ "v20", 16, -1 },
|
|
{ "v21", 16, -1 },
|
|
{ "v22", 16, -1 },
|
|
{ "v23", 16, -1 },
|
|
{ "v24", 16, -1 },
|
|
{ "v25", 16, -1 },
|
|
{ "v26", 16, -1 },
|
|
{ "v27", 16, -1 },
|
|
{ "v28", 16, -1 },
|
|
{ "v29", 16, -1 },
|
|
{ "v30", 16, -1 },
|
|
{ "v31", 16, -1 },
|
|
{ "fpsr", 4, -1 },
|
|
{ "fpcr", 4, -1 },
|
|
};
|
|
|
|
char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
|
|
{
|
|
if (regno >= DBG_MAX_REG_NUM || regno < 0)
|
|
return NULL;
|
|
|
|
if (dbg_reg_def[regno].offset != -1)
|
|
memcpy(mem, (void *)regs + dbg_reg_def[regno].offset,
|
|
dbg_reg_def[regno].size);
|
|
else
|
|
memset(mem, 0, dbg_reg_def[regno].size);
|
|
return dbg_reg_def[regno].name;
|
|
}
|
|
|
|
int dbg_set_reg(int regno, void *mem, struct pt_regs *regs)
|
|
{
|
|
if (regno >= DBG_MAX_REG_NUM || regno < 0)
|
|
return -EINVAL;
|
|
|
|
if (dbg_reg_def[regno].offset != -1)
|
|
memcpy((void *)regs + dbg_reg_def[regno].offset, mem,
|
|
dbg_reg_def[regno].size);
|
|
return 0;
|
|
}
|
|
|
|
void
|
|
sleeping_thread_to_gdb_regs(unsigned long *gdb_regs, struct task_struct *task)
|
|
{
|
|
struct pt_regs *thread_regs;
|
|
|
|
/* Initialize to zero */
|
|
memset((char *)gdb_regs, 0, NUMREGBYTES);
|
|
thread_regs = task_pt_regs(task);
|
|
memcpy((void *)gdb_regs, (void *)thread_regs->regs, GP_REG_BYTES);
|
|
/* Special case for PSTATE (check comments in asm/kgdb.h for details) */
|
|
dbg_get_reg(33, gdb_regs + GP_REG_BYTES, thread_regs);
|
|
}
|
|
|
|
void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long pc)
|
|
{
|
|
regs->pc = pc;
|
|
}
|
|
|
|
static int compiled_break;
|
|
|
|
static void kgdb_arch_update_addr(struct pt_regs *regs,
|
|
char *remcom_in_buffer)
|
|
{
|
|
unsigned long addr;
|
|
char *ptr;
|
|
|
|
ptr = &remcom_in_buffer[1];
|
|
if (kgdb_hex2long(&ptr, &addr))
|
|
kgdb_arch_set_pc(regs, addr);
|
|
else if (compiled_break == 1)
|
|
kgdb_arch_set_pc(regs, regs->pc + 4);
|
|
|
|
compiled_break = 0;
|
|
}
|
|
|
|
int kgdb_arch_handle_exception(int exception_vector, int signo,
|
|
int err_code, char *remcom_in_buffer,
|
|
char *remcom_out_buffer,
|
|
struct pt_regs *linux_regs)
|
|
{
|
|
int err;
|
|
|
|
switch (remcom_in_buffer[0]) {
|
|
case 'D':
|
|
case 'k':
|
|
/*
|
|
* Packet D (Detach), k (kill). No special handling
|
|
* is required here. Handle same as c packet.
|
|
*/
|
|
case 'c':
|
|
/*
|
|
* Packet c (Continue) to continue executing.
|
|
* Set pc to required address.
|
|
* Try to read optional parameter and set pc.
|
|
* If this was a compiled breakpoint, we need to move
|
|
* to the next instruction else we will just breakpoint
|
|
* over and over again.
|
|
*/
|
|
kgdb_arch_update_addr(linux_regs, remcom_in_buffer);
|
|
atomic_set(&kgdb_cpu_doing_single_step, -1);
|
|
kgdb_single_step = 0;
|
|
|
|
/*
|
|
* Received continue command, disable single step
|
|
*/
|
|
if (kernel_active_single_step())
|
|
kernel_disable_single_step();
|
|
|
|
err = 0;
|
|
break;
|
|
case 's':
|
|
/*
|
|
* Update step address value with address passed
|
|
* with step packet.
|
|
* On debug exception return PC is copied to ELR
|
|
* So just update PC.
|
|
* If no step address is passed, resume from the address
|
|
* pointed by PC. Do not update PC
|
|
*/
|
|
kgdb_arch_update_addr(linux_regs, remcom_in_buffer);
|
|
atomic_set(&kgdb_cpu_doing_single_step, raw_smp_processor_id());
|
|
kgdb_single_step = 1;
|
|
|
|
/*
|
|
* Enable single step handling
|
|
*/
|
|
if (!kernel_active_single_step())
|
|
kernel_enable_single_step(linux_regs);
|
|
err = 0;
|
|
break;
|
|
default:
|
|
err = -1;
|
|
}
|
|
return err;
|
|
}
|
|
|
|
static int kgdb_brk_fn(struct pt_regs *regs, unsigned int esr)
|
|
{
|
|
if (user_mode(regs))
|
|
return DBG_HOOK_ERROR;
|
|
|
|
kgdb_handle_exception(1, SIGTRAP, 0, regs);
|
|
return DBG_HOOK_HANDLED;
|
|
}
|
|
NOKPROBE_SYMBOL(kgdb_brk_fn)
|
|
|
|
static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int esr)
|
|
{
|
|
if (user_mode(regs))
|
|
return DBG_HOOK_ERROR;
|
|
|
|
compiled_break = 1;
|
|
kgdb_handle_exception(1, SIGTRAP, 0, regs);
|
|
|
|
return DBG_HOOK_HANDLED;
|
|
}
|
|
NOKPROBE_SYMBOL(kgdb_compiled_brk_fn);
|
|
|
|
static int kgdb_step_brk_fn(struct pt_regs *regs, unsigned int esr)
|
|
{
|
|
if (user_mode(regs))
|
|
return DBG_HOOK_ERROR;
|
|
|
|
kgdb_handle_exception(0, SIGTRAP, 0, regs);
|
|
return DBG_HOOK_HANDLED;
|
|
}
|
|
NOKPROBE_SYMBOL(kgdb_step_brk_fn);
|
|
|
|
static struct break_hook kgdb_brkpt_hook = {
|
|
.esr_mask = 0xffffffff,
|
|
.esr_val = (u32)ESR_ELx_VAL_BRK64(KGDB_DYN_DBG_BRK_IMM),
|
|
.fn = kgdb_brk_fn
|
|
};
|
|
|
|
static struct break_hook kgdb_compiled_brkpt_hook = {
|
|
.esr_mask = 0xffffffff,
|
|
.esr_val = (u32)ESR_ELx_VAL_BRK64(KGDB_COMPILED_DBG_BRK_IMM),
|
|
.fn = kgdb_compiled_brk_fn
|
|
};
|
|
|
|
static struct step_hook kgdb_step_hook = {
|
|
.fn = kgdb_step_brk_fn
|
|
};
|
|
|
|
static void kgdb_call_nmi_hook(void *ignored)
|
|
{
|
|
kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs());
|
|
}
|
|
|
|
void kgdb_roundup_cpus(unsigned long flags)
|
|
{
|
|
local_irq_enable();
|
|
smp_call_function(kgdb_call_nmi_hook, NULL, 0);
|
|
local_irq_disable();
|
|
}
|
|
|
|
static int __kgdb_notify(struct die_args *args, unsigned long cmd)
|
|
{
|
|
struct pt_regs *regs = args->regs;
|
|
|
|
if (kgdb_handle_exception(1, args->signr, cmd, regs))
|
|
return NOTIFY_DONE;
|
|
return NOTIFY_STOP;
|
|
}
|
|
|
|
static int
|
|
kgdb_notify(struct notifier_block *self, unsigned long cmd, void *ptr)
|
|
{
|
|
unsigned long flags;
|
|
int ret;
|
|
|
|
local_irq_save(flags);
|
|
ret = __kgdb_notify(ptr, cmd);
|
|
local_irq_restore(flags);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static struct notifier_block kgdb_notifier = {
|
|
.notifier_call = kgdb_notify,
|
|
/*
|
|
* Want to be lowest priority
|
|
*/
|
|
.priority = -INT_MAX,
|
|
};
|
|
|
|
/*
|
|
* kgdb_arch_init - Perform any architecture specific initialization.
|
|
* This function will handle the initialization of any architecture
|
|
* specific callbacks.
|
|
*/
|
|
int kgdb_arch_init(void)
|
|
{
|
|
int ret = register_die_notifier(&kgdb_notifier);
|
|
|
|
if (ret != 0)
|
|
return ret;
|
|
|
|
register_break_hook(&kgdb_brkpt_hook);
|
|
register_break_hook(&kgdb_compiled_brkpt_hook);
|
|
register_step_hook(&kgdb_step_hook);
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* kgdb_arch_exit - Perform any architecture specific uninitalization.
|
|
* This function will handle the uninitalization of any architecture
|
|
* specific callbacks, for dynamic registration and unregistration.
|
|
*/
|
|
void kgdb_arch_exit(void)
|
|
{
|
|
unregister_break_hook(&kgdb_brkpt_hook);
|
|
unregister_break_hook(&kgdb_compiled_brkpt_hook);
|
|
unregister_step_hook(&kgdb_step_hook);
|
|
unregister_die_notifier(&kgdb_notifier);
|
|
}
|
|
|
|
struct kgdb_arch arch_kgdb_ops;
|
|
|
|
int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
|
|
{
|
|
int err;
|
|
|
|
BUILD_BUG_ON(AARCH64_INSN_SIZE != BREAK_INSTR_SIZE);
|
|
|
|
err = aarch64_insn_read((void *)bpt->bpt_addr, (u32 *)bpt->saved_instr);
|
|
if (err)
|
|
return err;
|
|
|
|
return aarch64_insn_write((void *)bpt->bpt_addr,
|
|
(u32)AARCH64_BREAK_KGDB_DYN_DBG);
|
|
}
|
|
|
|
int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
|
|
{
|
|
return aarch64_insn_write((void *)bpt->bpt_addr,
|
|
*(u32 *)bpt->saved_instr);
|
|
}
|