mirror of
https://github.com/rd-stuffs/msm-4.14.git
synced 2025-02-20 11:45:48 +08:00
-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEZH8oZUiU471FcZm+ONu9yGCSaT4FAmJfsXYACgkQONu9yGCS aT4FSg/+JNuh/FNAa4Es7pC4O3BpsaIIji6MEYjSw1sMMgqtmXCnbm+1TCsgCOee auBiVGZzNjLRNESrqOPisEA5aUs31i3fVOD0c55bHgOhqxtLxaU7HmtqIlfvnEKu a49LRtqq3AEObilBFeBHQnUrTEGO/MnI4XoUsLdR6FWJBnYsBLczDdNGYIWZ/hCX y129piS/P53nHfmPTMH0De6soOXFIx3d82437pwA0vDEANtMx8lyaW+kdPSsgZl7 03JAQFW1KRjiLzHt+9w7c78dbnyEIQd78W4wn4NFglN7Ybxi7NFEjaf0xnyerwG2 b38ofe8Gw5IqUzF6eCHliG1UgQwZD7pNBjOIKukrpxL3bIEcTOhIQeu1HCm901k0 /Y53ju6tNCrv2PbHVylYibasxPiA2gxzFwJW/JvWWTtZZ6AwkZV0fs3LXXpmDix3 7n/QBjQcz4sOAAWwFoaxneUOTaNoFseZtW/dgqbq+Ukgt2SCP15EUDMVjIXi3fDr 3z5+QvO5IbjbcsFShVfDQ6RfnALp4TWXbrPQ+RTK77BZTbMNg7wjKxBC2MmTmStI 8aiDYecKR4FOXdW930zxYHS76gx57V30hur7jlqjFz0uNYnXU/R42kKUxEqD/86G UNX+zMv9uH5INANIy4P6DNZyZoTHQgdMIuuhKvntg/G3BcQ5I7k= =zpoO -----END PGP SIGNATURE----- Merge 4.14.276 into android-4.14-stable Changes in 4.14.276 USB: serial: pl2303: add IBM device IDs USB: serial: simple: add Nokia phone driver netdevice: add the case if dev is NULL virtio_console: break out of buf poll on remove ethernet: sun: Free the coherent when failing in probing spi: Fix invalid sgs value spi: Fix erroneous sgs value with min_t() af_key: add __GFP_ZERO flag for compose_sadb_supported in function pfkey_register fuse: fix pipe buffer lifetime for direct_io tpm: fix reference counting for struct tpm_chip block: Add a helper to validate the block size virtio-blk: Use blk_validate_block_size() to validate block size USB: usb-storage: Fix use of bitfields for hardware data in ene_ub6250.c coresight: Fix TRCCONFIGR.QE sysfs interface iio: inkern: apply consumer scale on IIO_VAL_INT cases iio: inkern: apply consumer scale when no channel scale is available iio: inkern: make a best effort on offset calculation clk: uniphier: Fix fixed-rate initialization ptrace: Check PTRACE_O_SUSPEND_SECCOMP permission on PTRACE_SEIZE Documentation: add link to stable release candidate tree Documentation: update stable tree link SUNRPC: avoid race between mod_timer() and del_timer_sync() NFSD: prevent underflow in nfssvc_decode_writeargs() pinctrl: samsung: drop pin banks references on error paths can: ems_usb: ems_usb_start_xmit(): fix double dev_kfree_skb() in error path jffs2: fix use-after-free in jffs2_clear_xattr_subsystem jffs2: fix memory leak in jffs2_do_mount_fs jffs2: fix memory leak in jffs2_scan_medium mm/pages_alloc.c: don't create ZONE_MOVABLE beyond the end of a node mempolicy: mbind_range() set_policy() after vma_merge() scsi: libsas: Fix sas_ata_qc_issue() handling of NCQ NON DATA commands qed: display VF trust config qed: validate and restrict untrusted VFs vlan promisc mode Revert "Input: clear BTN_RIGHT/MIDDLE on buttonpads" ALSA: cs4236: fix an incorrect NULL check on list iterator drbd: fix potential silent data corruption ACPI: properties: Consistently return -ENOENT if there are no more references drivers: hamradio: 6pack: fix UAF bug caused by mod_timer() video: fbdev: sm712fb: Fix crash in smtcfb_read() video: fbdev: atari: Atari 2 bpp (STe) palette bugfix ARM: dts: at91: sama5d2: Fix PMERRLOC resource size ARM: dts: exynos: fix UART3 pins configuration in Exynos5250 ARM: dts: exynos: add missing HDMI supplies on SMDK5250 ARM: dts: exynos: add missing HDMI supplies on SMDK5420 carl9170: fix missing bit-wise or operator for tx_params thermal: int340x: Increase bitmap size lib/raid6/test: fix multiple definition linking error DEC: Limit PMAX memory probing to R3k systems media: davinci: vpif: fix unbalanced runtime PM get brcmfmac: firmware: Allocate space for default boardrev in nvram brcmfmac: pcie: Replace brcmf_pcie_copy_mem_todev with memcpy_toio PCI: pciehp: Clear cmd_busy bit in polling mode crypto: authenc - Fix sleep in atomic context in decrypt_tail crypto: mxs-dcp - Fix scatterlist processing spi: tegra114: Add missing IRQ check in tegra_spi_probe selftests/x86: Add validity check and allow field splitting spi: pxa2xx-pci: Balance reference count for PCI DMA device hwmon: (pmbus) Add mutex to regulator ops hwmon: (sch56xx-common) Replace WDOG_ACTIVE with WDOG_HW_RUNNING PM: hibernate: fix __setup handler error handling PM: suspend: fix return value of __setup handler hwrng: atmel - disable trng on failure path crypto: vmx - add missing dependencies ACPI: APEI: fix return value of __setup handlers crypto: ccp - ccp_dmaengine_unregister release dma channels hwmon: (pmbus) Add Vin unit off handling clocksource: acpi_pm: fix return value of __setup handler sched/debug: Remove mpol_get/put and task_lock/unlock from sched_show_numa perf/core: Fix address filter parser for multiple filters perf/x86/intel/pt: Fix address filter config for 32-bit kernel media: coda: Fix missing put_device() call in coda_get_vdoa_data video: fbdev: smscufx: Fix null-ptr-deref in ufx_usb_probe() video: fbdev: fbcvt.c: fix printing in fb_cvt_print_name() ARM: dts: qcom: ipq4019: fix sleep clock soc: ti: wkup_m3_ipc: Fix IRQ check in wkup_m3_ipc_probe media: usb: go7007: s2250-board: fix leak in probe() ASoC: ti: davinci-i2s: Add check for clk_enable() ALSA: spi: Add check for clk_enable() arm64: dts: ns2: Fix spi-cpol and spi-cpha property arm64: dts: broadcom: Fix sata nodename printk: fix return value of printk.devkmsg __setup handler ASoC: mxs-saif: Handle errors for clk_enable ASoC: atmel_ssc_dai: Handle errors for clk_enable memory: emif: Add check for setup_interrupts memory: emif: check the pointer temp in get_device_details() ALSA: firewire-lib: fix uninitialized flag for AV/C deferred transaction media: stk1160: If start stream fails, return buffers with VB2_BUF_STATE_QUEUED ASoC: atmel: Add missing of_node_put() in at91sam9g20ek_audio_probe ASoC: wm8350: Handle error for wm8350_register_irq ASoC: fsi: Add check for clk_enable video: fbdev: omapfb: Add missing of_node_put() in dvic_probe_of ASoC: dmaengine: do not use a NULL prepare_slave_config() callback ASoC: mxs: Fix error handling in mxs_sgtl5000_probe ASoC: imx-es8328: Fix error return code in imx_es8328_probe() ASoC: msm8916-wcd-digital: Fix missing clk_disable_unprepare() in msm8916_wcd_digital_probe mtd: onenand: Check for error irq drm/edid: Don't clear formats if using deep color ath9k_htc: fix uninit value bugs power: reset: gemini-poweroff: Fix IRQ check in gemini_poweroff_probe ray_cs: Check ioremap return value power: supply: ab8500: Fix memory leak in ab8500_fg_sysfs_init HID: i2c-hid: fix GET/SET_REPORT for unnumbered reports iwlwifi: Fix -EIO error code that is never returned dm crypt: fix get_key_size compiler warning if !CONFIG_KEYS scsi: pm8001: Fix command initialization in pm80XX_send_read_log() scsi: pm8001: Fix command initialization in pm8001_chip_ssp_tm_req() scsi: pm8001: Fix payload initialization in pm80xx_set_thermal_config() scsi: pm8001: Fix abort all task initialization TOMOYO: fix __setup handlers return values ext2: correct max file size computing drm/tegra: Fix reference leak in tegra_dsi_ganged_probe power: supply: bq24190_charger: Fix bq24190_vbus_is_enabled() wrong false return KVM: x86: Fix emulation in writing cr8 KVM: x86/emulator: Defer not-present segment check in __load_segment_descriptor() i2c: xiic: Make bus names unique power: supply: wm8350-power: Handle error for wm8350_register_irq power: supply: wm8350-power: Add missing free in free_charger_irq PCI: Reduce warnings on possible RW1C corruption powerpc/sysdev: fix incorrect use to determine if list is empty mfd: mc13xxx: Add check for mc13xxx_irq_request vxcan: enable local echo for sent CAN frames MIPS: RB532: fix return value of __setup handler mtd: rawnand: atmel: fix refcount issue in atmel_nand_controller_init USB: storage: ums-realtek: fix error code in rts51x_read_mem() af_netlink: Fix shift out of bounds in group mask calculation i2c: mux: demux-pinctrl: do not deactivate a master that is not active tcp: ensure PMTU updates are processed during fastopen mfd: asic3: Add missing iounmap() on error asic3_mfd_probe mxser: fix xmit_buf leak in activate when LSR == 0xff pwm: lpc18xx-sct: Initialize driver data and hardware before pwmchip_add() staging:iio:adc:ad7280a: Fix handing of device address bit reversing. serial: 8250_mid: Balance reference count for PCI DMA device serial: 8250: Fix race condition in RTS-after-send handling iio: adc: Add check for devm_request_threaded_irq clk: qcom: clk-rcg2: Update the frac table for pixel clock remoteproc: qcom_wcnss: Add missing of_node_put() in wcnss_alloc_memory_region clk: loongson1: Terminate clk_div_table with sentinel element clk: clps711x: Terminate clk_div_table with sentinel element clk: tegra: tegra124-emc: Fix missing put_device() call in emc_ensure_emc_driver NFS: remove unneeded check in decode_devicenotify_args() pinctrl: mediatek: Fix missing of_node_put() in mtk_pctrl_init pinctrl: nomadik: Add missing of_node_put() in nmk_pinctrl_probe pinctrl/rockchip: Add missing of_node_put() in rockchip_pinctrl_probe tty: hvc: fix return value of __setup handler kgdboc: fix return value of __setup handler kgdbts: fix return value of __setup handler jfs: fix divide error in dbNextAG netfilter: nf_conntrack_tcp: preserve liberal flag in tcp options xen: fix is_xen_pmu() net: phy: broadcom: Fix brcm_fet_config_init() qlcnic: dcb: default to returning -EOPNOTSUPP net/x25: Fix null-ptr-deref caused by x25_disconnect NFSv4/pNFS: Fix another issue with a list iterator pointing to the head lib/test: use after free in register_test_dev_kmod() selinux: use correct type for context length loop: use sysfs_emit() in the sysfs xxx show() Fix incorrect type in assignment of ipv6 port for audit irqchip/nvic: Release nvic_base upon failure ACPICA: Avoid walking the ACPI Namespace if it is not there ACPI/APEI: Limit printable size of BERT table data PM: core: keep irq flags in device_pm_check_callbacks() spi: tegra20: Use of_device_get_match_data() ext4: don't BUG if someone dirty pages without asking ext4 first ntfs: add sanity check on allocation size video: fbdev: nvidiafb: Use strscpy() to prevent buffer overflow video: fbdev: w100fb: Reset global state video: fbdev: cirrusfb: check pixclock to avoid divide by zero video: fbdev: omapfb: acx565akm: replace snprintf with sysfs_emit ARM: dts: qcom: fix gic_irq_domain_translate warnings for msm8960 ARM: dts: bcm2837: Add the missing L1/L2 cache information video: fbdev: omapfb: panel-dsi-cm: Use sysfs_emit() instead of snprintf() video: fbdev: omapfb: panel-tpo-td043mtea1: Use sysfs_emit() instead of snprintf() ASoC: soc-core: skip zero num_dai component in searching dai name media: cx88-mpeg: clear interrupt status register before streaming video ARM: tegra: tamonten: Fix I2C3 pad setting ARM: mmp: Fix failure to remove sram device video: fbdev: sm712fb: Fix crash in smtcfb_write() media: hdpvr: initialize dev->worker at hdpvr_register_videodev mmc: host: Return an error when ->enable_sdio_irq() ops is missing powerpc/lib/sstep: Fix 'sthcx' instruction powerpc/lib/sstep: Fix build errors with newer binutils scsi: qla2xxx: Fix warning for missing error code scsi: qla2xxx: Suppress a kernel complaint in qla_create_qpair() KVM: Prevent module exit until all VMs are freed ubifs: rename_whiteout: Fix double free for whiteout_ui->data ubifs: Add missing iput if do_tmpfile() failed in rename whiteout ubifs: setflags: Make dirtied_ino_d 8 bytes aligned ubifs: rename_whiteout: correct old_dir size computing can: mcba_usb: mcba_usb_start_xmit(): fix double dev_kfree_skb in error path can: mcba_usb: properly check endpoint type gfs2: Make sure FITRIM minlen is rounded up to fs block size pinctrl: pinconf-generic: Print arguments for bias-pull-* ubi: Fix race condition between ctrl_cdev_ioctl and ubi_cdev_ioctl ACPI: CPPC: Avoid out of bounds access when parsing _CPC data mm/mmap: return 1 from stack_guard_gap __setup() handler mm/memcontrol: return 1 from cgroup.memory __setup() handler ubi: fastmap: Return error code if memory allocation fails in add_aeb() ASoC: topology: Allow TLV control to be either read or write ARM: dts: spear1340: Update serial node properties ARM: dts: spear13xx: Update SPI dma properties openvswitch: Fixed nd target mask field in the flow dump. KVM: x86: Forbid VMM to set SYNIC/STIMER MSRs when SynIC wasn't activated ubifs: Rectify space amount budget for mkdir/tmpfile operations rtc: wm8350: Handle error for wm8350_register_irq ARM: 9187/1: JIVE: fix return value of __setup handler KVM: x86/svm: Clear reserved bits written to PerfEvtSeln MSRs ath5k: fix OOB in ath5k_eeprom_read_pcal_info_5111 ptp: replace snprintf with sysfs_emit powerpc: dts: t104xrdb: fix phy type for FMAN 4/5 scsi: mvsas: Replace snprintf() with sysfs_emit() scsi: bfa: Replace snprintf() with sysfs_emit() power: supply: axp20x_battery: properly report current when discharging powerpc: Set crashkernel offset to mid of RMA region PCI: aardvark: Fix support for MSI interrupts iommu/arm-smmu-v3: fix event handling soft lockup dm ioctl: prevent potential spectre v1 gadget scsi: pm8001: Fix pm8001_mpi_task_abort_resp() scsi: aha152x: Fix aha152x_setup() __setup handler return value net/smc: correct settings of RMB window update limit macvtap: advertise link netns via netlink bnxt_en: Eliminate unintended link toggle during FW reset MIPS: fix fortify panic when copying asm exception handlers scsi: libfc: Fix use after free in fc_exch_abts_resp() usb: dwc3: omap: fix "unbalanced disables for smps10_out1" on omap5evm xtensa: fix DTC warning unit_address_format Bluetooth: Fix use after free in hci_send_acl init/main.c: return 1 from handled __setup() functions w1: w1_therm: fixes w1_seq for ds28ea00 sensors SUNRPC/call_alloc: async tasks mustn't block waiting for memory NFS: swap IO handling is slightly different for O_DIRECT IO NFS: swap-out must always use STABLE writes. serial: samsung_tty: do not unlock port->lock for uart_write_wakeup() virtio_console: eliminate anonymous module_init & module_exit jfs: prevent NULL deref in diFree parisc: Fix CPU affinity for Lasi, WAX and Dino chips ipv6: add missing tx timestamping on IPPROTO_RAW net: add missing SOF_TIMESTAMPING_OPT_ID support mm: fix race between MADV_FREE reclaim and blkdev direct IO read drm/amdgpu: fix off by one in amdgpu_gfx_kiq_acquire() scsi: zorro7xx: Fix a resource leak in zorro7xx_remove_one() net: stmmac: Fix unset max_speed difference between DT and non-DT platforms drm/imx: Fix memory leak in imx_pd_connector_get_modes drbd: Fix five use after free bugs in get_initial_state Revert "mmc: sdhci-xenon: fix annoying 1.8V regulator warning" mmmremap.c: avoid pointless invalidate_range_start/end on mremap(old_size=0) mm/mempolicy: fix mpol_new leak in shared_policy_replace x86/pm: Save the MSR validity status at context setup x86/speculation: Restore speculation related MSRs during S3 resume btrfs: fix qgroup reserve overflow the qgroup limit arm64: patch_text: Fixup last cpu should be master perf: qcom_l2_pmu: fix an incorrect NULL check on list iterator tools build: Use $(shell ) instead of `` to get embedded libperl's ccopts dmaengine: Revert "dmaengine: shdma: Fix runtime PM imbalance on error" mm: don't skip swap entry even if zap_details specified arm64: module: remove (NOLOAD) from linker script mm/sparsemem: fix 'mem_section' will never be NULL gcc 12 warning cgroup: Use open-time credentials for process migraton perm checks cgroup: Allocate cgroup_file_ctx for kernfs_open_file->priv cgroup: Use open-time cgroup namespace for process migration perm checks xfrm: policy: match with both mark and mask on user interfaces memory: atmel-ebi: Fix missing of_node_put in atmel_ebi_probe veth: Ensure eth header is in skb's linear part gpiolib: acpi: use correct format characters mlxsw: i2c: Fix initialization error flow net: ethernet: stmmac: fix altr_tse_pcs function when using a fixed-link nfc: nci: add flush_workqueue to prevent uaf cifs: potential buffer overflow in handling symlinks drm/amd: Add USBC connector ID drm/amdkfd: Check for potential null return of kmalloc_array() Drivers: hv: vmbus: Prevent load re-ordering when reading ring buffer scsi: target: tcmu: Fix possible page UAF scsi: ibmvscsis: Increase INITIAL_SRP_LIMIT to 1024 net: micrel: fix KS8851_MLL Kconfig ata: libata-core: Disable READ LOG DMA EXT for Samsung 840 EVOs gpu: ipu-v3: Fix dev_dbg frequency output scsi: mvsas: Add PCI ID of RocketRaid 2640 drivers: net: slip: fix NPD bug in sl_tx_timeout() mm, page_alloc: fix build_zonerefs_node() mm: kmemleak: take a full lowmem check in kmemleak_*_phys() gcc-plugins: latent_entropy: use /dev/urandom ALSA: pcm: Test for "silence" field in struct "pcm_format_data" ARM: davinci: da850-evm: Avoid NULL pointer dereference smp: Fix offline cpu check in flush_smp_call_function_queue() i2c: pasemi: Wait for write xfers to finish Linux 4.14.276 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I45d8292ce654c0236758030a89b4618cf3a3d87b
1190 lines
31 KiB
C
1190 lines
31 KiB
C
/*
|
|
* kgdbts is a test suite for kgdb for the sole purpose of validating
|
|
* that key pieces of the kgdb internals are working properly such as
|
|
* HW/SW breakpoints, single stepping, and NMI.
|
|
*
|
|
* Created by: Jason Wessel <jason.wessel@windriver.com>
|
|
*
|
|
* Copyright (c) 2008 Wind River Systems, Inc.
|
|
*
|
|
* 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, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
/* Information about the kgdb test suite.
|
|
* -------------------------------------
|
|
*
|
|
* The kgdb test suite is designed as a KGDB I/O module which
|
|
* simulates the communications that a debugger would have with kgdb.
|
|
* The tests are broken up in to a line by line and referenced here as
|
|
* a "get" which is kgdb requesting input and "put" which is kgdb
|
|
* sending a response.
|
|
*
|
|
* The kgdb suite can be invoked from the kernel command line
|
|
* arguments system or executed dynamically at run time. The test
|
|
* suite uses the variable "kgdbts" to obtain the information about
|
|
* which tests to run and to configure the verbosity level. The
|
|
* following are the various characters you can use with the kgdbts=
|
|
* line:
|
|
*
|
|
* When using the "kgdbts=" you only choose one of the following core
|
|
* test types:
|
|
* A = Run all the core tests silently
|
|
* V1 = Run all the core tests with minimal output
|
|
* V2 = Run all the core tests in debug mode
|
|
*
|
|
* You can also specify optional tests:
|
|
* N## = Go to sleep with interrupts of for ## seconds
|
|
* to test the HW NMI watchdog
|
|
* F## = Break at do_fork for ## iterations
|
|
* S## = Break at sys_open for ## iterations
|
|
* I## = Run the single step test ## iterations
|
|
*
|
|
* NOTE: that the do_fork and sys_open tests are mutually exclusive.
|
|
*
|
|
* To invoke the kgdb test suite from boot you use a kernel start
|
|
* argument as follows:
|
|
* kgdbts=V1 kgdbwait
|
|
* Or if you wanted to perform the NMI test for 6 seconds and do_fork
|
|
* test for 100 forks, you could use:
|
|
* kgdbts=V1N6F100 kgdbwait
|
|
*
|
|
* The test suite can also be invoked at run time with:
|
|
* echo kgdbts=V1N6F100 > /sys/module/kgdbts/parameters/kgdbts
|
|
* Or as another example:
|
|
* echo kgdbts=V2 > /sys/module/kgdbts/parameters/kgdbts
|
|
*
|
|
* When developing a new kgdb arch specific implementation or
|
|
* using these tests for the purpose of regression testing,
|
|
* several invocations are required.
|
|
*
|
|
* 1) Boot with the test suite enabled by using the kernel arguments
|
|
* "kgdbts=V1F100 kgdbwait"
|
|
* ## If kgdb arch specific implementation has NMI use
|
|
* "kgdbts=V1N6F100
|
|
*
|
|
* 2) After the system boot run the basic test.
|
|
* echo kgdbts=V1 > /sys/module/kgdbts/parameters/kgdbts
|
|
*
|
|
* 3) Run the concurrency tests. It is best to use n+1
|
|
* while loops where n is the number of cpus you have
|
|
* in your system. The example below uses only two
|
|
* loops.
|
|
*
|
|
* ## This tests break points on sys_open
|
|
* while [ 1 ] ; do find / > /dev/null 2>&1 ; done &
|
|
* while [ 1 ] ; do find / > /dev/null 2>&1 ; done &
|
|
* echo kgdbts=V1S10000 > /sys/module/kgdbts/parameters/kgdbts
|
|
* fg # and hit control-c
|
|
* fg # and hit control-c
|
|
* ## This tests break points on do_fork
|
|
* while [ 1 ] ; do date > /dev/null ; done &
|
|
* while [ 1 ] ; do date > /dev/null ; done &
|
|
* echo kgdbts=V1F1000 > /sys/module/kgdbts/parameters/kgdbts
|
|
* fg # and hit control-c
|
|
*
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/kgdb.h>
|
|
#include <linux/ctype.h>
|
|
#include <linux/uaccess.h>
|
|
#include <linux/syscalls.h>
|
|
#include <linux/nmi.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/kthread.h>
|
|
#include <linux/module.h>
|
|
#include <linux/sched/task.h>
|
|
|
|
#include <asm/sections.h>
|
|
|
|
#define v1printk(a...) do { \
|
|
if (verbose) \
|
|
printk(KERN_INFO a); \
|
|
} while (0)
|
|
#define v2printk(a...) do { \
|
|
if (verbose > 1) { \
|
|
printk(KERN_INFO a); \
|
|
} \
|
|
touch_nmi_watchdog(); \
|
|
} while (0)
|
|
#define eprintk(a...) do { \
|
|
printk(KERN_ERR a); \
|
|
WARN_ON(1); \
|
|
} while (0)
|
|
#define MAX_CONFIG_LEN 40
|
|
|
|
static struct kgdb_io kgdbts_io_ops;
|
|
static char get_buf[BUFMAX];
|
|
static int get_buf_cnt;
|
|
static char put_buf[BUFMAX];
|
|
static int put_buf_cnt;
|
|
static char scratch_buf[BUFMAX];
|
|
static int verbose;
|
|
static int repeat_test;
|
|
static int test_complete;
|
|
static int send_ack;
|
|
static int final_ack;
|
|
static int force_hwbrks;
|
|
static int hwbreaks_ok;
|
|
static int hw_break_val;
|
|
static int hw_break_val2;
|
|
static int cont_instead_of_sstep;
|
|
static unsigned long cont_thread_id;
|
|
static unsigned long sstep_thread_id;
|
|
#if defined(CONFIG_ARM) || defined(CONFIG_MIPS) || defined(CONFIG_SPARC)
|
|
static int arch_needs_sstep_emulation = 1;
|
|
#else
|
|
static int arch_needs_sstep_emulation;
|
|
#endif
|
|
static unsigned long cont_addr;
|
|
static unsigned long sstep_addr;
|
|
static int restart_from_top_after_write;
|
|
static int sstep_state;
|
|
|
|
/* Storage for the registers, in GDB format. */
|
|
static unsigned long kgdbts_gdb_regs[(NUMREGBYTES +
|
|
sizeof(unsigned long) - 1) /
|
|
sizeof(unsigned long)];
|
|
static struct pt_regs kgdbts_regs;
|
|
|
|
/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
|
|
static int configured = -1;
|
|
|
|
#ifdef CONFIG_KGDB_TESTS_BOOT_STRING
|
|
static char config[MAX_CONFIG_LEN] = CONFIG_KGDB_TESTS_BOOT_STRING;
|
|
#else
|
|
static char config[MAX_CONFIG_LEN];
|
|
#endif
|
|
static struct kparam_string kps = {
|
|
.string = config,
|
|
.maxlen = MAX_CONFIG_LEN,
|
|
};
|
|
|
|
static void fill_get_buf(char *buf);
|
|
|
|
struct test_struct {
|
|
char *get;
|
|
char *put;
|
|
void (*get_handler)(char *);
|
|
int (*put_handler)(char *, char *);
|
|
};
|
|
|
|
struct test_state {
|
|
char *name;
|
|
struct test_struct *tst;
|
|
int idx;
|
|
int (*run_test) (int, int);
|
|
int (*validate_put) (char *);
|
|
};
|
|
|
|
static struct test_state ts;
|
|
|
|
static int kgdbts_unreg_thread(void *ptr)
|
|
{
|
|
/* Wait until the tests are complete and then ungresiter the I/O
|
|
* driver.
|
|
*/
|
|
while (!final_ack)
|
|
msleep_interruptible(1500);
|
|
/* Pause for any other threads to exit after final ack. */
|
|
msleep_interruptible(1000);
|
|
if (configured)
|
|
kgdb_unregister_io_module(&kgdbts_io_ops);
|
|
configured = 0;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* This is noinline such that it can be used for a single location to
|
|
* place a breakpoint
|
|
*/
|
|
static noinline void kgdbts_break_test(void)
|
|
{
|
|
v2printk("kgdbts: breakpoint complete\n");
|
|
}
|
|
|
|
/* Lookup symbol info in the kernel */
|
|
static unsigned long lookup_addr(char *arg)
|
|
{
|
|
unsigned long addr = 0;
|
|
|
|
if (!strcmp(arg, "kgdbts_break_test"))
|
|
addr = (unsigned long)kgdbts_break_test;
|
|
else if (!strcmp(arg, "sys_open"))
|
|
addr = (unsigned long)do_sys_open;
|
|
else if (!strcmp(arg, "do_fork"))
|
|
addr = (unsigned long)_do_fork;
|
|
else if (!strcmp(arg, "hw_break_val"))
|
|
addr = (unsigned long)&hw_break_val;
|
|
addr = (unsigned long) dereference_function_descriptor((void *)addr);
|
|
return addr;
|
|
}
|
|
|
|
static void break_helper(char *bp_type, char *arg, unsigned long vaddr)
|
|
{
|
|
unsigned long addr;
|
|
|
|
if (arg)
|
|
addr = lookup_addr(arg);
|
|
else
|
|
addr = vaddr;
|
|
|
|
sprintf(scratch_buf, "%s,%lx,%i", bp_type, addr,
|
|
BREAK_INSTR_SIZE);
|
|
fill_get_buf(scratch_buf);
|
|
}
|
|
|
|
static void sw_break(char *arg)
|
|
{
|
|
break_helper(force_hwbrks ? "Z1" : "Z0", arg, 0);
|
|
}
|
|
|
|
static void sw_rem_break(char *arg)
|
|
{
|
|
break_helper(force_hwbrks ? "z1" : "z0", arg, 0);
|
|
}
|
|
|
|
static void hw_break(char *arg)
|
|
{
|
|
break_helper("Z1", arg, 0);
|
|
}
|
|
|
|
static void hw_rem_break(char *arg)
|
|
{
|
|
break_helper("z1", arg, 0);
|
|
}
|
|
|
|
static void hw_write_break(char *arg)
|
|
{
|
|
break_helper("Z2", arg, 0);
|
|
}
|
|
|
|
static void hw_rem_write_break(char *arg)
|
|
{
|
|
break_helper("z2", arg, 0);
|
|
}
|
|
|
|
static void hw_access_break(char *arg)
|
|
{
|
|
break_helper("Z4", arg, 0);
|
|
}
|
|
|
|
static void hw_rem_access_break(char *arg)
|
|
{
|
|
break_helper("z4", arg, 0);
|
|
}
|
|
|
|
static void hw_break_val_access(void)
|
|
{
|
|
hw_break_val2 = hw_break_val;
|
|
}
|
|
|
|
static void hw_break_val_write(void)
|
|
{
|
|
hw_break_val++;
|
|
}
|
|
|
|
static int get_thread_id_continue(char *put_str, char *arg)
|
|
{
|
|
char *ptr = &put_str[11];
|
|
|
|
if (put_str[1] != 'T' || put_str[2] != '0')
|
|
return 1;
|
|
kgdb_hex2long(&ptr, &cont_thread_id);
|
|
return 0;
|
|
}
|
|
|
|
static int check_and_rewind_pc(char *put_str, char *arg)
|
|
{
|
|
unsigned long addr = lookup_addr(arg);
|
|
unsigned long ip;
|
|
int offset = 0;
|
|
|
|
kgdb_hex2mem(&put_str[1], (char *)kgdbts_gdb_regs,
|
|
NUMREGBYTES);
|
|
gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs);
|
|
ip = instruction_pointer(&kgdbts_regs);
|
|
v2printk("Stopped at IP: %lx\n", ip);
|
|
#ifdef GDB_ADJUSTS_BREAK_OFFSET
|
|
/* On some arches, a breakpoint stop requires it to be decremented */
|
|
if (addr + BREAK_INSTR_SIZE == ip)
|
|
offset = -BREAK_INSTR_SIZE;
|
|
#endif
|
|
|
|
if (arch_needs_sstep_emulation && sstep_addr &&
|
|
ip + offset == sstep_addr &&
|
|
((!strcmp(arg, "sys_open") || !strcmp(arg, "do_fork")))) {
|
|
/* This is special case for emulated single step */
|
|
v2printk("Emul: rewind hit single step bp\n");
|
|
restart_from_top_after_write = 1;
|
|
} else if (strcmp(arg, "silent") && ip + offset != addr) {
|
|
eprintk("kgdbts: BP mismatch %lx expected %lx\n",
|
|
ip + offset, addr);
|
|
return 1;
|
|
}
|
|
/* Readjust the instruction pointer if needed */
|
|
ip += offset;
|
|
cont_addr = ip;
|
|
#ifdef GDB_ADJUSTS_BREAK_OFFSET
|
|
instruction_pointer_set(&kgdbts_regs, ip);
|
|
#endif
|
|
return 0;
|
|
}
|
|
|
|
static int check_single_step(char *put_str, char *arg)
|
|
{
|
|
unsigned long addr = lookup_addr(arg);
|
|
static int matched_id;
|
|
|
|
/*
|
|
* From an arch indepent point of view the instruction pointer
|
|
* should be on a different instruction
|
|
*/
|
|
kgdb_hex2mem(&put_str[1], (char *)kgdbts_gdb_regs,
|
|
NUMREGBYTES);
|
|
gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs);
|
|
v2printk("Singlestep stopped at IP: %lx\n",
|
|
instruction_pointer(&kgdbts_regs));
|
|
|
|
if (sstep_thread_id != cont_thread_id) {
|
|
/*
|
|
* Ensure we stopped in the same thread id as before, else the
|
|
* debugger should continue until the original thread that was
|
|
* single stepped is scheduled again, emulating gdb's behavior.
|
|
*/
|
|
v2printk("ThrID does not match: %lx\n", cont_thread_id);
|
|
if (arch_needs_sstep_emulation) {
|
|
if (matched_id &&
|
|
instruction_pointer(&kgdbts_regs) != addr)
|
|
goto continue_test;
|
|
matched_id++;
|
|
ts.idx -= 2;
|
|
sstep_state = 0;
|
|
return 0;
|
|
}
|
|
cont_instead_of_sstep = 1;
|
|
ts.idx -= 4;
|
|
return 0;
|
|
}
|
|
continue_test:
|
|
matched_id = 0;
|
|
if (instruction_pointer(&kgdbts_regs) == addr) {
|
|
eprintk("kgdbts: SingleStep failed at %lx\n",
|
|
instruction_pointer(&kgdbts_regs));
|
|
return 1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void write_regs(char *arg)
|
|
{
|
|
memset(scratch_buf, 0, sizeof(scratch_buf));
|
|
scratch_buf[0] = 'G';
|
|
pt_regs_to_gdb_regs(kgdbts_gdb_regs, &kgdbts_regs);
|
|
kgdb_mem2hex((char *)kgdbts_gdb_regs, &scratch_buf[1], NUMREGBYTES);
|
|
fill_get_buf(scratch_buf);
|
|
}
|
|
|
|
static void skip_back_repeat_test(char *arg)
|
|
{
|
|
int go_back = simple_strtol(arg, NULL, 10);
|
|
|
|
repeat_test--;
|
|
if (repeat_test <= 0)
|
|
ts.idx++;
|
|
else
|
|
ts.idx -= go_back;
|
|
fill_get_buf(ts.tst[ts.idx].get);
|
|
}
|
|
|
|
static int got_break(char *put_str, char *arg)
|
|
{
|
|
test_complete = 1;
|
|
if (!strncmp(put_str+1, arg, 2)) {
|
|
if (!strncmp(arg, "T0", 2))
|
|
test_complete = 2;
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static void get_cont_catch(char *arg)
|
|
{
|
|
/* Always send detach because the test is completed at this point */
|
|
fill_get_buf("D");
|
|
}
|
|
|
|
static int put_cont_catch(char *put_str, char *arg)
|
|
{
|
|
/* This is at the end of the test and we catch any and all input */
|
|
v2printk("kgdbts: cleanup task: %lx\n", sstep_thread_id);
|
|
ts.idx--;
|
|
return 0;
|
|
}
|
|
|
|
static int emul_reset(char *put_str, char *arg)
|
|
{
|
|
if (strncmp(put_str, "$OK", 3))
|
|
return 1;
|
|
if (restart_from_top_after_write) {
|
|
restart_from_top_after_write = 0;
|
|
ts.idx = -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void emul_sstep_get(char *arg)
|
|
{
|
|
if (!arch_needs_sstep_emulation) {
|
|
if (cont_instead_of_sstep) {
|
|
cont_instead_of_sstep = 0;
|
|
fill_get_buf("c");
|
|
} else {
|
|
fill_get_buf(arg);
|
|
}
|
|
return;
|
|
}
|
|
switch (sstep_state) {
|
|
case 0:
|
|
v2printk("Emulate single step\n");
|
|
/* Start by looking at the current PC */
|
|
fill_get_buf("g");
|
|
break;
|
|
case 1:
|
|
/* set breakpoint */
|
|
break_helper("Z0", NULL, sstep_addr);
|
|
break;
|
|
case 2:
|
|
/* Continue */
|
|
fill_get_buf("c");
|
|
break;
|
|
case 3:
|
|
/* Clear breakpoint */
|
|
break_helper("z0", NULL, sstep_addr);
|
|
break;
|
|
default:
|
|
eprintk("kgdbts: ERROR failed sstep get emulation\n");
|
|
}
|
|
sstep_state++;
|
|
}
|
|
|
|
static int emul_sstep_put(char *put_str, char *arg)
|
|
{
|
|
if (!arch_needs_sstep_emulation) {
|
|
char *ptr = &put_str[11];
|
|
if (put_str[1] != 'T' || put_str[2] != '0')
|
|
return 1;
|
|
kgdb_hex2long(&ptr, &sstep_thread_id);
|
|
return 0;
|
|
}
|
|
switch (sstep_state) {
|
|
case 1:
|
|
/* validate the "g" packet to get the IP */
|
|
kgdb_hex2mem(&put_str[1], (char *)kgdbts_gdb_regs,
|
|
NUMREGBYTES);
|
|
gdb_regs_to_pt_regs(kgdbts_gdb_regs, &kgdbts_regs);
|
|
v2printk("Stopped at IP: %lx\n",
|
|
instruction_pointer(&kgdbts_regs));
|
|
/* Want to stop at IP + break instruction size by default */
|
|
sstep_addr = cont_addr + BREAK_INSTR_SIZE;
|
|
break;
|
|
case 2:
|
|
if (strncmp(put_str, "$OK", 3)) {
|
|
eprintk("kgdbts: failed sstep break set\n");
|
|
return 1;
|
|
}
|
|
break;
|
|
case 3:
|
|
if (strncmp(put_str, "$T0", 3)) {
|
|
eprintk("kgdbts: failed continue sstep\n");
|
|
return 1;
|
|
} else {
|
|
char *ptr = &put_str[11];
|
|
kgdb_hex2long(&ptr, &sstep_thread_id);
|
|
}
|
|
break;
|
|
case 4:
|
|
if (strncmp(put_str, "$OK", 3)) {
|
|
eprintk("kgdbts: failed sstep break unset\n");
|
|
return 1;
|
|
}
|
|
/* Single step is complete so continue on! */
|
|
sstep_state = 0;
|
|
return 0;
|
|
default:
|
|
eprintk("kgdbts: ERROR failed sstep put emulation\n");
|
|
}
|
|
|
|
/* Continue on the same test line until emulation is complete */
|
|
ts.idx--;
|
|
return 0;
|
|
}
|
|
|
|
static int final_ack_set(char *put_str, char *arg)
|
|
{
|
|
if (strncmp(put_str+1, arg, 2))
|
|
return 1;
|
|
final_ack = 1;
|
|
return 0;
|
|
}
|
|
/*
|
|
* Test to plant a breakpoint and detach, which should clear out the
|
|
* breakpoint and restore the original instruction.
|
|
*/
|
|
static struct test_struct plant_and_detach_test[] = {
|
|
{ "?", "S0*" }, /* Clear break points */
|
|
{ "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */
|
|
{ "D", "OK" }, /* Detach */
|
|
{ "", "" },
|
|
};
|
|
|
|
/*
|
|
* Simple test to write in a software breakpoint, check for the
|
|
* correct stop location and detach.
|
|
*/
|
|
static struct test_struct sw_breakpoint_test[] = {
|
|
{ "?", "S0*" }, /* Clear break points */
|
|
{ "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */
|
|
{ "c", "T0*", }, /* Continue */
|
|
{ "g", "kgdbts_break_test", NULL, check_and_rewind_pc },
|
|
{ "write", "OK", write_regs },
|
|
{ "kgdbts_break_test", "OK", sw_rem_break }, /*remove breakpoint */
|
|
{ "D", "OK" }, /* Detach */
|
|
{ "D", "OK", NULL, got_break }, /* On success we made it here */
|
|
{ "", "" },
|
|
};
|
|
|
|
/*
|
|
* Test a known bad memory read location to test the fault handler and
|
|
* read bytes 1-8 at the bad address
|
|
*/
|
|
static struct test_struct bad_read_test[] = {
|
|
{ "?", "S0*" }, /* Clear break points */
|
|
{ "m0,1", "E*" }, /* read 1 byte at address 1 */
|
|
{ "m0,2", "E*" }, /* read 1 byte at address 2 */
|
|
{ "m0,3", "E*" }, /* read 1 byte at address 3 */
|
|
{ "m0,4", "E*" }, /* read 1 byte at address 4 */
|
|
{ "m0,5", "E*" }, /* read 1 byte at address 5 */
|
|
{ "m0,6", "E*" }, /* read 1 byte at address 6 */
|
|
{ "m0,7", "E*" }, /* read 1 byte at address 7 */
|
|
{ "m0,8", "E*" }, /* read 1 byte at address 8 */
|
|
{ "D", "OK" }, /* Detach which removes all breakpoints and continues */
|
|
{ "", "" },
|
|
};
|
|
|
|
/*
|
|
* Test for hitting a breakpoint, remove it, single step, plant it
|
|
* again and detach.
|
|
*/
|
|
static struct test_struct singlestep_break_test[] = {
|
|
{ "?", "S0*" }, /* Clear break points */
|
|
{ "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */
|
|
{ "c", "T0*", NULL, get_thread_id_continue }, /* Continue */
|
|
{ "kgdbts_break_test", "OK", sw_rem_break }, /*remove breakpoint */
|
|
{ "g", "kgdbts_break_test", NULL, check_and_rewind_pc },
|
|
{ "write", "OK", write_regs }, /* Write registers */
|
|
{ "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */
|
|
{ "g", "kgdbts_break_test", NULL, check_single_step },
|
|
{ "kgdbts_break_test", "OK", sw_break, }, /* set sw breakpoint */
|
|
{ "c", "T0*", }, /* Continue */
|
|
{ "g", "kgdbts_break_test", NULL, check_and_rewind_pc },
|
|
{ "write", "OK", write_regs }, /* Write registers */
|
|
{ "D", "OK" }, /* Remove all breakpoints and continues */
|
|
{ "", "" },
|
|
};
|
|
|
|
/*
|
|
* Test for hitting a breakpoint at do_fork for what ever the number
|
|
* of iterations required by the variable repeat_test.
|
|
*/
|
|
static struct test_struct do_fork_test[] = {
|
|
{ "?", "S0*" }, /* Clear break points */
|
|
{ "do_fork", "OK", sw_break, }, /* set sw breakpoint */
|
|
{ "c", "T0*", NULL, get_thread_id_continue }, /* Continue */
|
|
{ "do_fork", "OK", sw_rem_break }, /*remove breakpoint */
|
|
{ "g", "do_fork", NULL, check_and_rewind_pc }, /* check location */
|
|
{ "write", "OK", write_regs, emul_reset }, /* Write registers */
|
|
{ "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */
|
|
{ "g", "do_fork", NULL, check_single_step },
|
|
{ "do_fork", "OK", sw_break, }, /* set sw breakpoint */
|
|
{ "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */
|
|
{ "D", "OK", NULL, final_ack_set }, /* detach and unregister I/O */
|
|
{ "", "", get_cont_catch, put_cont_catch },
|
|
};
|
|
|
|
/* Test for hitting a breakpoint at sys_open for what ever the number
|
|
* of iterations required by the variable repeat_test.
|
|
*/
|
|
static struct test_struct sys_open_test[] = {
|
|
{ "?", "S0*" }, /* Clear break points */
|
|
{ "sys_open", "OK", sw_break, }, /* set sw breakpoint */
|
|
{ "c", "T0*", NULL, get_thread_id_continue }, /* Continue */
|
|
{ "sys_open", "OK", sw_rem_break }, /*remove breakpoint */
|
|
{ "g", "sys_open", NULL, check_and_rewind_pc }, /* check location */
|
|
{ "write", "OK", write_regs, emul_reset }, /* Write registers */
|
|
{ "s", "T0*", emul_sstep_get, emul_sstep_put }, /* Single step */
|
|
{ "g", "sys_open", NULL, check_single_step },
|
|
{ "sys_open", "OK", sw_break, }, /* set sw breakpoint */
|
|
{ "7", "T0*", skip_back_repeat_test }, /* Loop based on repeat_test */
|
|
{ "D", "OK", NULL, final_ack_set }, /* detach and unregister I/O */
|
|
{ "", "", get_cont_catch, put_cont_catch },
|
|
};
|
|
|
|
/*
|
|
* Test for hitting a simple hw breakpoint
|
|
*/
|
|
static struct test_struct hw_breakpoint_test[] = {
|
|
{ "?", "S0*" }, /* Clear break points */
|
|
{ "kgdbts_break_test", "OK", hw_break, }, /* set hw breakpoint */
|
|
{ "c", "T0*", }, /* Continue */
|
|
{ "g", "kgdbts_break_test", NULL, check_and_rewind_pc },
|
|
{ "write", "OK", write_regs },
|
|
{ "kgdbts_break_test", "OK", hw_rem_break }, /*remove breakpoint */
|
|
{ "D", "OK" }, /* Detach */
|
|
{ "D", "OK", NULL, got_break }, /* On success we made it here */
|
|
{ "", "" },
|
|
};
|
|
|
|
/*
|
|
* Test for hitting a hw write breakpoint
|
|
*/
|
|
static struct test_struct hw_write_break_test[] = {
|
|
{ "?", "S0*" }, /* Clear break points */
|
|
{ "hw_break_val", "OK", hw_write_break, }, /* set hw breakpoint */
|
|
{ "c", "T0*", NULL, got_break }, /* Continue */
|
|
{ "g", "silent", NULL, check_and_rewind_pc },
|
|
{ "write", "OK", write_regs },
|
|
{ "hw_break_val", "OK", hw_rem_write_break }, /*remove breakpoint */
|
|
{ "D", "OK" }, /* Detach */
|
|
{ "D", "OK", NULL, got_break }, /* On success we made it here */
|
|
{ "", "" },
|
|
};
|
|
|
|
/*
|
|
* Test for hitting a hw access breakpoint
|
|
*/
|
|
static struct test_struct hw_access_break_test[] = {
|
|
{ "?", "S0*" }, /* Clear break points */
|
|
{ "hw_break_val", "OK", hw_access_break, }, /* set hw breakpoint */
|
|
{ "c", "T0*", NULL, got_break }, /* Continue */
|
|
{ "g", "silent", NULL, check_and_rewind_pc },
|
|
{ "write", "OK", write_regs },
|
|
{ "hw_break_val", "OK", hw_rem_access_break }, /*remove breakpoint */
|
|
{ "D", "OK" }, /* Detach */
|
|
{ "D", "OK", NULL, got_break }, /* On success we made it here */
|
|
{ "", "" },
|
|
};
|
|
|
|
/*
|
|
* Test for hitting a hw access breakpoint
|
|
*/
|
|
static struct test_struct nmi_sleep_test[] = {
|
|
{ "?", "S0*" }, /* Clear break points */
|
|
{ "c", "T0*", NULL, got_break }, /* Continue */
|
|
{ "D", "OK" }, /* Detach */
|
|
{ "D", "OK", NULL, got_break }, /* On success we made it here */
|
|
{ "", "" },
|
|
};
|
|
|
|
static void fill_get_buf(char *buf)
|
|
{
|
|
unsigned char checksum = 0;
|
|
int count = 0;
|
|
char ch;
|
|
|
|
strcpy(get_buf, "$");
|
|
strcat(get_buf, buf);
|
|
while ((ch = buf[count])) {
|
|
checksum += ch;
|
|
count++;
|
|
}
|
|
strcat(get_buf, "#");
|
|
get_buf[count + 2] = hex_asc_hi(checksum);
|
|
get_buf[count + 3] = hex_asc_lo(checksum);
|
|
get_buf[count + 4] = '\0';
|
|
v2printk("get%i: %s\n", ts.idx, get_buf);
|
|
}
|
|
|
|
static int validate_simple_test(char *put_str)
|
|
{
|
|
char *chk_str;
|
|
|
|
if (ts.tst[ts.idx].put_handler)
|
|
return ts.tst[ts.idx].put_handler(put_str,
|
|
ts.tst[ts.idx].put);
|
|
|
|
chk_str = ts.tst[ts.idx].put;
|
|
if (*put_str == '$')
|
|
put_str++;
|
|
|
|
while (*chk_str != '\0' && *put_str != '\0') {
|
|
/* If someone does a * to match the rest of the string, allow
|
|
* it, or stop if the received string is complete.
|
|
*/
|
|
if (*put_str == '#' || *chk_str == '*')
|
|
return 0;
|
|
if (*put_str != *chk_str)
|
|
return 1;
|
|
|
|
chk_str++;
|
|
put_str++;
|
|
}
|
|
if (*chk_str == '\0' && (*put_str == '\0' || *put_str == '#'))
|
|
return 0;
|
|
|
|
return 1;
|
|
}
|
|
|
|
static int run_simple_test(int is_get_char, int chr)
|
|
{
|
|
int ret = 0;
|
|
if (is_get_char) {
|
|
/* Send an ACK on the get if a prior put completed and set the
|
|
* send ack variable
|
|
*/
|
|
if (send_ack) {
|
|
send_ack = 0;
|
|
return '+';
|
|
}
|
|
/* On the first get char, fill the transmit buffer and then
|
|
* take from the get_string.
|
|
*/
|
|
if (get_buf_cnt == 0) {
|
|
if (ts.tst[ts.idx].get_handler)
|
|
ts.tst[ts.idx].get_handler(ts.tst[ts.idx].get);
|
|
else
|
|
fill_get_buf(ts.tst[ts.idx].get);
|
|
}
|
|
|
|
if (get_buf[get_buf_cnt] == '\0') {
|
|
eprintk("kgdbts: ERROR GET: EOB on '%s' at %i\n",
|
|
ts.name, ts.idx);
|
|
get_buf_cnt = 0;
|
|
fill_get_buf("D");
|
|
}
|
|
ret = get_buf[get_buf_cnt];
|
|
get_buf_cnt++;
|
|
return ret;
|
|
}
|
|
|
|
/* This callback is a put char which is when kgdb sends data to
|
|
* this I/O module.
|
|
*/
|
|
if (ts.tst[ts.idx].get[0] == '\0' && ts.tst[ts.idx].put[0] == '\0' &&
|
|
!ts.tst[ts.idx].get_handler) {
|
|
eprintk("kgdbts: ERROR: beyond end of test on"
|
|
" '%s' line %i\n", ts.name, ts.idx);
|
|
return 0;
|
|
}
|
|
|
|
if (put_buf_cnt >= BUFMAX) {
|
|
eprintk("kgdbts: ERROR: put buffer overflow on"
|
|
" '%s' line %i\n", ts.name, ts.idx);
|
|
put_buf_cnt = 0;
|
|
return 0;
|
|
}
|
|
/* Ignore everything until the first valid packet start '$' */
|
|
if (put_buf_cnt == 0 && chr != '$')
|
|
return 0;
|
|
|
|
put_buf[put_buf_cnt] = chr;
|
|
put_buf_cnt++;
|
|
|
|
/* End of packet == #XX so look for the '#' */
|
|
if (put_buf_cnt > 3 && put_buf[put_buf_cnt - 3] == '#') {
|
|
if (put_buf_cnt >= BUFMAX) {
|
|
eprintk("kgdbts: ERROR: put buffer overflow on"
|
|
" '%s' line %i\n", ts.name, ts.idx);
|
|
put_buf_cnt = 0;
|
|
return 0;
|
|
}
|
|
put_buf[put_buf_cnt] = '\0';
|
|
v2printk("put%i: %s\n", ts.idx, put_buf);
|
|
/* Trigger check here */
|
|
if (ts.validate_put && ts.validate_put(put_buf)) {
|
|
eprintk("kgdbts: ERROR PUT: end of test "
|
|
"buffer on '%s' line %i expected %s got %s\n",
|
|
ts.name, ts.idx, ts.tst[ts.idx].put, put_buf);
|
|
}
|
|
ts.idx++;
|
|
put_buf_cnt = 0;
|
|
get_buf_cnt = 0;
|
|
send_ack = 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void init_simple_test(void)
|
|
{
|
|
memset(&ts, 0, sizeof(ts));
|
|
ts.run_test = run_simple_test;
|
|
ts.validate_put = validate_simple_test;
|
|
}
|
|
|
|
static void run_plant_and_detach_test(int is_early)
|
|
{
|
|
char before[BREAK_INSTR_SIZE];
|
|
char after[BREAK_INSTR_SIZE];
|
|
|
|
probe_kernel_read(before, (char *)kgdbts_break_test,
|
|
BREAK_INSTR_SIZE);
|
|
init_simple_test();
|
|
ts.tst = plant_and_detach_test;
|
|
ts.name = "plant_and_detach_test";
|
|
/* Activate test with initial breakpoint */
|
|
if (!is_early)
|
|
kgdb_breakpoint();
|
|
probe_kernel_read(after, (char *)kgdbts_break_test,
|
|
BREAK_INSTR_SIZE);
|
|
if (memcmp(before, after, BREAK_INSTR_SIZE)) {
|
|
printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
|
|
panic("kgdb memory corruption");
|
|
}
|
|
|
|
/* complete the detach test */
|
|
if (!is_early)
|
|
kgdbts_break_test();
|
|
}
|
|
|
|
static void run_breakpoint_test(int is_hw_breakpoint)
|
|
{
|
|
test_complete = 0;
|
|
init_simple_test();
|
|
if (is_hw_breakpoint) {
|
|
ts.tst = hw_breakpoint_test;
|
|
ts.name = "hw_breakpoint_test";
|
|
} else {
|
|
ts.tst = sw_breakpoint_test;
|
|
ts.name = "sw_breakpoint_test";
|
|
}
|
|
/* Activate test with initial breakpoint */
|
|
kgdb_breakpoint();
|
|
/* run code with the break point in it */
|
|
kgdbts_break_test();
|
|
kgdb_breakpoint();
|
|
|
|
if (test_complete)
|
|
return;
|
|
|
|
eprintk("kgdbts: ERROR %s test failed\n", ts.name);
|
|
if (is_hw_breakpoint)
|
|
hwbreaks_ok = 0;
|
|
}
|
|
|
|
static void run_hw_break_test(int is_write_test)
|
|
{
|
|
test_complete = 0;
|
|
init_simple_test();
|
|
if (is_write_test) {
|
|
ts.tst = hw_write_break_test;
|
|
ts.name = "hw_write_break_test";
|
|
} else {
|
|
ts.tst = hw_access_break_test;
|
|
ts.name = "hw_access_break_test";
|
|
}
|
|
/* Activate test with initial breakpoint */
|
|
kgdb_breakpoint();
|
|
hw_break_val_access();
|
|
if (is_write_test) {
|
|
if (test_complete == 2) {
|
|
eprintk("kgdbts: ERROR %s broke on access\n",
|
|
ts.name);
|
|
hwbreaks_ok = 0;
|
|
}
|
|
hw_break_val_write();
|
|
}
|
|
kgdb_breakpoint();
|
|
|
|
if (test_complete == 1)
|
|
return;
|
|
|
|
eprintk("kgdbts: ERROR %s test failed\n", ts.name);
|
|
hwbreaks_ok = 0;
|
|
}
|
|
|
|
static void run_nmi_sleep_test(int nmi_sleep)
|
|
{
|
|
unsigned long flags;
|
|
|
|
init_simple_test();
|
|
ts.tst = nmi_sleep_test;
|
|
ts.name = "nmi_sleep_test";
|
|
/* Activate test with initial breakpoint */
|
|
kgdb_breakpoint();
|
|
local_irq_save(flags);
|
|
mdelay(nmi_sleep*1000);
|
|
touch_nmi_watchdog();
|
|
local_irq_restore(flags);
|
|
if (test_complete != 2)
|
|
eprintk("kgdbts: ERROR nmi_test did not hit nmi\n");
|
|
kgdb_breakpoint();
|
|
if (test_complete == 1)
|
|
return;
|
|
|
|
eprintk("kgdbts: ERROR %s test failed\n", ts.name);
|
|
}
|
|
|
|
static void run_bad_read_test(void)
|
|
{
|
|
init_simple_test();
|
|
ts.tst = bad_read_test;
|
|
ts.name = "bad_read_test";
|
|
/* Activate test with initial breakpoint */
|
|
kgdb_breakpoint();
|
|
}
|
|
|
|
static void run_do_fork_test(void)
|
|
{
|
|
init_simple_test();
|
|
ts.tst = do_fork_test;
|
|
ts.name = "do_fork_test";
|
|
/* Activate test with initial breakpoint */
|
|
kgdb_breakpoint();
|
|
}
|
|
|
|
static void run_sys_open_test(void)
|
|
{
|
|
init_simple_test();
|
|
ts.tst = sys_open_test;
|
|
ts.name = "sys_open_test";
|
|
/* Activate test with initial breakpoint */
|
|
kgdb_breakpoint();
|
|
}
|
|
|
|
static void run_singlestep_break_test(void)
|
|
{
|
|
init_simple_test();
|
|
ts.tst = singlestep_break_test;
|
|
ts.name = "singlestep_breakpoint_test";
|
|
/* Activate test with initial breakpoint */
|
|
kgdb_breakpoint();
|
|
kgdbts_break_test();
|
|
kgdbts_break_test();
|
|
}
|
|
|
|
static void kgdbts_run_tests(void)
|
|
{
|
|
char *ptr;
|
|
int fork_test = 0;
|
|
int do_sys_open_test = 0;
|
|
int sstep_test = 1000;
|
|
int nmi_sleep = 0;
|
|
int i;
|
|
|
|
verbose = 0;
|
|
if (strstr(config, "V1"))
|
|
verbose = 1;
|
|
if (strstr(config, "V2"))
|
|
verbose = 2;
|
|
|
|
ptr = strchr(config, 'F');
|
|
if (ptr)
|
|
fork_test = simple_strtol(ptr + 1, NULL, 10);
|
|
ptr = strchr(config, 'S');
|
|
if (ptr)
|
|
do_sys_open_test = simple_strtol(ptr + 1, NULL, 10);
|
|
ptr = strchr(config, 'N');
|
|
if (ptr)
|
|
nmi_sleep = simple_strtol(ptr+1, NULL, 10);
|
|
ptr = strchr(config, 'I');
|
|
if (ptr)
|
|
sstep_test = simple_strtol(ptr+1, NULL, 10);
|
|
|
|
/* All HW break point tests */
|
|
if (arch_kgdb_ops.flags & KGDB_HW_BREAKPOINT) {
|
|
hwbreaks_ok = 1;
|
|
v1printk("kgdbts:RUN hw breakpoint test\n");
|
|
run_breakpoint_test(1);
|
|
v1printk("kgdbts:RUN hw write breakpoint test\n");
|
|
run_hw_break_test(1);
|
|
v1printk("kgdbts:RUN access write breakpoint test\n");
|
|
run_hw_break_test(0);
|
|
}
|
|
|
|
/* required internal KGDB tests */
|
|
v1printk("kgdbts:RUN plant and detach test\n");
|
|
run_plant_and_detach_test(0);
|
|
v1printk("kgdbts:RUN sw breakpoint test\n");
|
|
run_breakpoint_test(0);
|
|
v1printk("kgdbts:RUN bad memory access test\n");
|
|
run_bad_read_test();
|
|
v1printk("kgdbts:RUN singlestep test %i iterations\n", sstep_test);
|
|
for (i = 0; i < sstep_test; i++) {
|
|
run_singlestep_break_test();
|
|
if (i % 100 == 0)
|
|
v1printk("kgdbts:RUN singlestep [%i/%i]\n",
|
|
i, sstep_test);
|
|
}
|
|
|
|
/* ===Optional tests=== */
|
|
|
|
if (nmi_sleep) {
|
|
v1printk("kgdbts:RUN NMI sleep %i seconds test\n", nmi_sleep);
|
|
run_nmi_sleep_test(nmi_sleep);
|
|
}
|
|
|
|
/* If the do_fork test is run it will be the last test that is
|
|
* executed because a kernel thread will be spawned at the very
|
|
* end to unregister the debug hooks.
|
|
*/
|
|
if (fork_test) {
|
|
repeat_test = fork_test;
|
|
printk(KERN_INFO "kgdbts:RUN do_fork for %i breakpoints\n",
|
|
repeat_test);
|
|
kthread_run(kgdbts_unreg_thread, NULL, "kgdbts_unreg");
|
|
run_do_fork_test();
|
|
return;
|
|
}
|
|
|
|
/* If the sys_open test is run it will be the last test that is
|
|
* executed because a kernel thread will be spawned at the very
|
|
* end to unregister the debug hooks.
|
|
*/
|
|
if (do_sys_open_test) {
|
|
repeat_test = do_sys_open_test;
|
|
printk(KERN_INFO "kgdbts:RUN sys_open for %i breakpoints\n",
|
|
repeat_test);
|
|
kthread_run(kgdbts_unreg_thread, NULL, "kgdbts_unreg");
|
|
run_sys_open_test();
|
|
return;
|
|
}
|
|
/* Shutdown and unregister */
|
|
kgdb_unregister_io_module(&kgdbts_io_ops);
|
|
configured = 0;
|
|
}
|
|
|
|
static int kgdbts_option_setup(char *opt)
|
|
{
|
|
if (strlen(opt) >= MAX_CONFIG_LEN) {
|
|
printk(KERN_ERR "kgdbts: config string too long\n");
|
|
return 1;
|
|
}
|
|
strcpy(config, opt);
|
|
return 1;
|
|
}
|
|
|
|
__setup("kgdbts=", kgdbts_option_setup);
|
|
|
|
static int configure_kgdbts(void)
|
|
{
|
|
int err = 0;
|
|
|
|
if (!strlen(config) || isspace(config[0]))
|
|
goto noconfig;
|
|
|
|
final_ack = 0;
|
|
run_plant_and_detach_test(1);
|
|
|
|
err = kgdb_register_io_module(&kgdbts_io_ops);
|
|
if (err) {
|
|
configured = 0;
|
|
return err;
|
|
}
|
|
configured = 1;
|
|
kgdbts_run_tests();
|
|
|
|
return err;
|
|
|
|
noconfig:
|
|
config[0] = 0;
|
|
configured = 0;
|
|
|
|
return err;
|
|
}
|
|
|
|
static int __init init_kgdbts(void)
|
|
{
|
|
/* Already configured? */
|
|
if (configured == 1)
|
|
return 0;
|
|
|
|
return configure_kgdbts();
|
|
}
|
|
device_initcall(init_kgdbts);
|
|
|
|
static int kgdbts_get_char(void)
|
|
{
|
|
int val = 0;
|
|
|
|
if (ts.run_test)
|
|
val = ts.run_test(1, 0);
|
|
|
|
return val;
|
|
}
|
|
|
|
static void kgdbts_put_char(u8 chr)
|
|
{
|
|
if (ts.run_test)
|
|
ts.run_test(0, chr);
|
|
}
|
|
|
|
static int param_set_kgdbts_var(const char *kmessage,
|
|
const struct kernel_param *kp)
|
|
{
|
|
size_t len = strlen(kmessage);
|
|
|
|
if (len >= MAX_CONFIG_LEN) {
|
|
printk(KERN_ERR "kgdbts: config string too long\n");
|
|
return -ENOSPC;
|
|
}
|
|
|
|
/* Only copy in the string if the init function has not run yet */
|
|
if (configured < 0) {
|
|
strcpy(config, kmessage);
|
|
return 0;
|
|
}
|
|
|
|
if (configured == 1) {
|
|
printk(KERN_ERR "kgdbts: ERROR: Already configured and running.\n");
|
|
return -EBUSY;
|
|
}
|
|
|
|
strcpy(config, kmessage);
|
|
/* Chop out \n char as a result of echo */
|
|
if (len && config[len - 1] == '\n')
|
|
config[len - 1] = '\0';
|
|
|
|
/* Go and configure with the new params. */
|
|
return configure_kgdbts();
|
|
}
|
|
|
|
static void kgdbts_pre_exp_handler(void)
|
|
{
|
|
/* Increment the module count when the debugger is active */
|
|
if (!kgdb_connected)
|
|
try_module_get(THIS_MODULE);
|
|
}
|
|
|
|
static void kgdbts_post_exp_handler(void)
|
|
{
|
|
/* decrement the module count when the debugger detaches */
|
|
if (!kgdb_connected)
|
|
module_put(THIS_MODULE);
|
|
}
|
|
|
|
static struct kgdb_io kgdbts_io_ops = {
|
|
.name = "kgdbts",
|
|
.read_char = kgdbts_get_char,
|
|
.write_char = kgdbts_put_char,
|
|
.pre_exception = kgdbts_pre_exp_handler,
|
|
.post_exception = kgdbts_post_exp_handler,
|
|
};
|
|
|
|
/*
|
|
* not really modular, but the easiest way to keep compat with existing
|
|
* bootargs behaviour is to continue using module_param here.
|
|
*/
|
|
module_param_call(kgdbts, param_set_kgdbts_var, param_get_string, &kps, 0644);
|
|
MODULE_PARM_DESC(kgdbts, "<A|V1|V2>[F#|S#][N#]");
|