From patchwork Sun Sep 27 21:15:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 313601 Delivered-To: patches@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp2819476ilg; Sun, 27 Sep 2020 14:16:16 -0700 (PDT) X-Received: by 2002:a05:600c:4108:: with SMTP id j8mr8620850wmi.116.1601241375890; Sun, 27 Sep 2020 14:16:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601241375; cv=none; d=google.com; s=arc-20160816; b=Dp7WddejzqFsqImQl8j6r0H4NW4VTltglr9yd1sB3WngkwYfn+ot5f1sgFexDfdooE D/DlVkhOgy4UebaiVZaTD2b6Dmuqfy05wshDw3jIi8enkyk9+LrCS/TLMgndbnl+OBYK KrxM2YecmKsGsImn+7HZlOUywhO6/MnDlC3X1AJ4m9oILxbABewnHaAQ//FNVm+iO6GD y5BfS25DVyFOXFxOzOxJ7y3+dE9XXJPGkQAimXm+sh2DDYjyAP0rqM6NDUviXrlA3x75 4/BY4lQSFKPQX+fRM0R2BObts7ZvbfUnp0+Q1SJgGq32783637S5nK9fErBS+Ujo/A+x cXAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=dlej/lv7oVkXNfjhU3o8F709/Rsr6/sqjZB7q+Bb9kY=; b=WAdvpNUP0XL/HbYqJPyxPoY1URKziSBqo6x65KEpfZMydUMbPzO0dj/BEC3LkjFB8Y SsHVyoLD8EHKp0YyuyC0BOqQzZs78nYF6TW+sbrILbsCbgpYpW1KkpYOGGjrNWN5EVse mW2X/7mpi9YzmvesnEnpR7E3M9VDmxGCCLf/GpaxQSvtDNX4rmwkbEGrfzxFjikZOHAY 5nfgyZzgatkUt5G0ZepjsL4EtkdGcFFROEmw+7+nVdbVk6DmHysaOfbfQ3Hrl8rOoXdU uSsZ0CqoKSOUxw62EzYr24obt09qvmnumigkos/8IDoRG3pZWBgoUoywJ8iW5OfbNMod LbqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jjIs/Shx"; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id g65sor2559994wmg.18.2020.09.27.14.16.15 for (Google Transport Security); Sun, 27 Sep 2020 14:16:15 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jjIs/Shx"; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dlej/lv7oVkXNfjhU3o8F709/Rsr6/sqjZB7q+Bb9kY=; b=jjIs/ShxEUKGd7uwSXED4AjI2tzuzQz/UDxHA4VMAJF2qD1a0V0jAAB2AWYdaDBYAC I2AELKianFoU4dmp7Nun+Ui2jfnrme9WZnOviAv+3g1ucd6BpKMy2L8Y8ggKrsYa3Xlp Am8eUlB+uiZ82P9xc9wWfb2/GxLifoUXmLzwLrzFc8ch5l5c91ZPwDLBBGD0C3oUBY/Y 8CVEJKRaNTzHxbsA0mOSz4Mq9cMM7h9xZeMD7nxDMIaIc0D3FcNx1pi0p/xA40X8TnZN zQrTAH1rMR2lD9gfgU0r9I4w6Ca1CIwFgyOnB1/G8jhMrJMmRh7ptCB3PUJanTYDyQud D4Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dlej/lv7oVkXNfjhU3o8F709/Rsr6/sqjZB7q+Bb9kY=; b=J3sOdZm91yr5tT3EDvMtbj2VoNEczLgSMbhSXYg5gB24WkmFUvYLMdpaNWwu5JJkbn 8gWlQmV0A9MlmFrFEkifco2VQH+q/41ZkxguTu2mqsv7cT2OUo9xtaPtwufHEQrcBHoO 9aKg+Ccfzv67GdmDOYdvCpKzC2hyuYfCiFVoUmduPkTo5XfYydU9cPOQHXvGkAFGc+66 ItwqWmsWDl+L7VYIpnod8csWs3RoSwRjmPoCQHlCgnRHPgZxHyRDAZvrVUVB3IwPwOju yVVNJAiYe/eJSxQggrXdVPOJ4RbIT+WvuEPBznUrQZxUqWart08kkRQ4jA+iKgnfcj1E uj0w== X-Gm-Message-State: AOAM533/RnNMurUY+efY9fiX9RnPOkYSHsNB0Ut8l8K/ID3oJaNq/Ofz qFyDiGLmUy9SG0ZIHAplGam6pmTs X-Google-Smtp-Source: ABdhPJybjs2360ZXFdycpun4TnffqLBoF2b3BVpvb5RBACJB4L8AP9d14d9i8h6KCHKK5li6jLs2cA== X-Received: by 2002:a1c:4c06:: with SMTP id z6mr8202363wmf.40.1601241375471; Sun, 27 Sep 2020 14:16:15 -0700 (PDT) Return-Path: Received: from wychelm.lan (cpc141216-aztw34-2-0-cust174.18-1.cable.virginm.net. [80.7.220.175]) by smtp.gmail.com with ESMTPSA id s17sm11396676wrr.40.2020.09.27.14.16.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Sep 2020 14:16:14 -0700 (PDT) From: Daniel Thompson To: Jason Wessel , Douglas Anderson Cc: Daniel Thompson , Peter Zijlstra , sumit.garg@linaro.org, pmladek@suse.com, sergey.senozhatsky@gmail.com, will@kernel.org, Masami Hiramatsu , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v3 1/3] kgdb: Honour the kprobe blocklist when setting breakpoints Date: Sun, 27 Sep 2020 22:15:29 +0100 Message-Id: <20200927211531.1380577-2-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200927211531.1380577-1-daniel.thompson@linaro.org> References: <20200927211531.1380577-1-daniel.thompson@linaro.org> MIME-Version: 1.0 Currently kgdb has absolutely no safety rails in place to discourage or prevent a user from placing a breakpoint in dangerous places such as the debugger's own trap entry/exit and other places where it is not safe to take synchronous traps. Introduce a new config symbol KGDB_HONOUR_BLOCKLIST and modify the default implementation of kgdb_validate_break_address() so that we use the kprobe blocklist to prohibit instrumentation of critical functions if the config symbol is set. The config symbol dependencies are set to ensure that the blocklist will be enabled by default if we enable KGDB and are compiling for an architecture where we HAVE_KPROBES. Suggested-by: Peter Zijlstra Reviewed-by: Douglas Anderson Reviewed-by: Masami Hiramatsu Signed-off-by: Daniel Thompson --- include/linux/kgdb.h | 18 ++++++++++++++++++ kernel/debug/debug_core.c | 4 ++++ kernel/debug/kdb/kdb_bp.c | 9 +++++++++ lib/Kconfig.kgdb | 15 +++++++++++++++ 4 files changed, 46 insertions(+) -- 2.25.4 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h index 477b8b7c908f..0d6cf64c8bb1 100644 --- a/include/linux/kgdb.h +++ b/include/linux/kgdb.h @@ -16,6 +16,7 @@ #include #include #include +#include #ifdef CONFIG_HAVE_ARCH_KGDB #include #endif @@ -335,6 +336,23 @@ extern int kgdb_nmicallin(int cpu, int trapnr, void *regs, int err_code, atomic_t *snd_rdy); extern void gdbstub_exit(int status); +/* + * kgdb and kprobes both use the same (kprobe) blocklist (which makes sense + * given they are both typically hooked up to the same trap meaning on most + * architectures one cannot be used to debug the other) + * + * However on architectures where kprobes is not (yet) implemented we permit + * breakpoints everywhere rather than blocking everything by default. + */ +static inline bool kgdb_within_blocklist(unsigned long addr) +{ +#ifdef CONFIG_KGDB_HONOUR_BLOCKLIST + return within_kprobe_blacklist(addr); +#else + return false; +#endif +} + extern int kgdb_single_step; extern atomic_t kgdb_active; #define in_dbg_master() \ diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c index b16dbc1bf056..b1277728a835 100644 --- a/kernel/debug/debug_core.c +++ b/kernel/debug/debug_core.c @@ -188,6 +188,10 @@ int __weak kgdb_validate_break_address(unsigned long addr) { struct kgdb_bkpt tmp; int err; + + if (kgdb_within_blocklist(addr)) + return -EINVAL; + /* Validate setting the breakpoint and then removing it. If the * remove fails, the kernel needs to emit a bad message because we * are deep trouble not being able to put things back the way we diff --git a/kernel/debug/kdb/kdb_bp.c b/kernel/debug/kdb/kdb_bp.c index d7ebb2c79cb8..ec4940146612 100644 --- a/kernel/debug/kdb/kdb_bp.c +++ b/kernel/debug/kdb/kdb_bp.c @@ -306,6 +306,15 @@ static int kdb_bp(int argc, const char **argv) if (!template.bp_addr) return KDB_BADINT; + /* + * This check is redundant (since the breakpoint machinery should + * be doing the same check during kdb_bp_install) but gives the + * user immediate feedback. + */ + diag = kgdb_validate_break_address(template.bp_addr); + if (diag) + return diag; + /* * Find an empty bp structure to allocate */ diff --git a/lib/Kconfig.kgdb b/lib/Kconfig.kgdb index 256f2486f9bd..05dae05b6cc9 100644 --- a/lib/Kconfig.kgdb +++ b/lib/Kconfig.kgdb @@ -24,6 +24,21 @@ menuconfig KGDB if KGDB +config KGDB_HONOUR_BLOCKLIST + bool "KGDB: use kprobe blocklist to prohibit unsafe breakpoints" + depends on HAVE_KPROBES + depends on MODULES + select KPROBES + default y + help + If set to Y the debug core will use the kprobe blocklist to + identify symbols where it is unsafe to set breakpoints. + In particular this disallows instrumentation of functions + called during debug trap handling and thus makes it very + difficult to inadvertently provoke recursive trap handling. + + If unsure, say Y. + config KGDB_SERIAL_CONSOLE tristate "KGDB: use kgdb over the serial console" select CONSOLE_POLL From patchwork Sun Sep 27 21:15:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 313602 Delivered-To: patches@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp2819488ilg; Sun, 27 Sep 2020 14:16:17 -0700 (PDT) X-Received: by 2002:a1c:b608:: with SMTP id g8mr8765279wmf.106.1601241377099; Sun, 27 Sep 2020 14:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601241377; cv=none; d=google.com; s=arc-20160816; b=HAy9Xl6u65EzWMP+uxOpdvh3zq5DhbDRIh9cRZdi/oe6AMvGDSS6BaKuSFN/sEIoV4 9ExweQ1+4DFNeTPMkCAPSkpUDzHEsAclu67j9l2ORQMw0pt5v7a8/F0anpORk4ofhX3g vyMiMerjQB3LdlH/wVk4+mmrOHlyRA/GAmFc2jGgYwsPvAL/r1+C6HLxuJ6ZNdpDKxBB eOgoeX/8ZmB+/i5qkloC0Q1ZWvTniOyWPDzG8XjCVxP0MrpN0VQStZkdt+9DYMU1jG+3 22D2Z1+sKEBg5/FhpVPx6Qf3FAshQ6ExZQ/LJKiFpPrFOJZ+2lu151kNgF9JpHC1rp2D 2JYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=N+Ii1nMTxqQ3KB5diZSPJLBE7AzX1vOzJWQZljPq00k=; b=gUSeJ1VmvnNhotgA0FvXRFzkr0yJ78WswppE5x9CeeJNF+ag/nctKO27aQnvxKhqOD /UQa1McW7RZY4rBh3cJjY8UU92LFdtHSAm9h4f/9yFyDU21M/p52sIzVeyCliiuQLzA1 bpWtndaKwU25bPOrqEGLC4IzE8N0sYh7jz2YJ2oWyaTA4FoXYmvGM0tvv7XYRovoK5AH tGZ+MCmDVKWTf9CE2MYOlinHxIyobgqh/U+iKtcwwiNQU6TkM6EdxLu/BXXxXGa1rhhK kGNSNMAkzLhTPA9EiD2UNJ2HyIdrURs+JO5o8Cd236DzHqw1iM2qgkmcwSNre79jcAme Y0ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IzRe0iLc; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id u26sor2567718wmj.1.2020.09.27.14.16.16 for (Google Transport Security); Sun, 27 Sep 2020 14:16:17 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IzRe0iLc; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N+Ii1nMTxqQ3KB5diZSPJLBE7AzX1vOzJWQZljPq00k=; b=IzRe0iLcxGVxSWG941aMsPrFaGDAlhFd/0DWKmNS7I3+k9Rs8UszLqf+776SaffdkQ iw8OT30UVGAn4LNed6pEQ18id6nyCzVVhe0MGBnPpbUFH5LyDb6nZi6qX0Zp+XTFBv3k pTlcZFBfouoLSmyfldSWnGJIXWszAxX3W9VxhfdjwHqAiPX/NOBwgOE0ZiOBaRfRK31v JSHtqJ0NsNUS4GOCiXkcOOLuDUGEe1DSRdbhjxsD6FqoqhOHqYaX94MepxMpRD32J8Hc sew+85FHUwqbGlAnZLy59HlBvg1ci53RzlzkZvuBhtyomo+bu9hOmtIblasPwvfuMnDG r3Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N+Ii1nMTxqQ3KB5diZSPJLBE7AzX1vOzJWQZljPq00k=; b=NzBm8xYG3XBuW2cGcOz8v7iuaK+A2X1r7c8B12HQXR8XZSO1TCWl0rjNS5+RqDCb1Z cBA6sEDKR71uCopEr0/EbNiCxTKcFa8Y9aPPxAAJkb0SYTPDdVSS1g3AcZq01w26apeG TVOdkoNbFU7wD5Z977YS0ug80bGdA5reYd4SnWnk361fn9vGdvhI8TOhM/E48r8qllD5 F3CN+qqCdNPaDJJQRtSqu9poKNtjpli2XBxQ3HN+7M4I3zkBK7U/7DGFknOdripwWGwr 3jmhZ6vlA6Q5ciQzoFGV/ZMyI3GpM3L+8FNLsIrd4Ch3RwsyqNi1WPMo4C91KTiMw5J3 Z+ZA== X-Gm-Message-State: AOAM532lwv02R5Qvl1OJPVej8lcyMP3SuY0hqnREQGH2+EOH1tojw9e9 sE4udQes23hT0qD6pxsnITHJO5mo X-Google-Smtp-Source: ABdhPJwi5Uve1dX5mSII74NP7BohO0vivBIUiywg2rM9zTvrjEX3Q5fG1U53TK3YqXK9dTZdIaQk+A== X-Received: by 2002:a7b:c4d1:: with SMTP id g17mr8161345wmk.167.1601241376739; Sun, 27 Sep 2020 14:16:16 -0700 (PDT) Return-Path: Received: from wychelm.lan (cpc141216-aztw34-2-0-cust174.18-1.cable.virginm.net. [80.7.220.175]) by smtp.gmail.com with ESMTPSA id s17sm11396676wrr.40.2020.09.27.14.16.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Sep 2020 14:16:16 -0700 (PDT) From: Daniel Thompson To: Jason Wessel , Douglas Anderson Cc: Daniel Thompson , Peter Zijlstra , sumit.garg@linaro.org, pmladek@suse.com, sergey.senozhatsky@gmail.com, will@kernel.org, Masami Hiramatsu , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v3 2/3] kgdb: Add NOKPROBE labels on the trap handler functions Date: Sun, 27 Sep 2020 22:15:30 +0100 Message-Id: <20200927211531.1380577-3-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200927211531.1380577-1-daniel.thompson@linaro.org> References: <20200927211531.1380577-1-daniel.thompson@linaro.org> MIME-Version: 1.0 Currently kgdb honours the kprobe blocklist but doesn't place its own trap handling code on the list. Add labels to discourage attempting to use kgdb to debug itself. Not every functions that executes from the trap handler needs to be marked up: relatively early in the trap handler execution (just after we bring the other CPUs to a halt) all breakpoints are replaced with the original opcodes. This patch marks up code in the debug_core that executes between trap entry and the breakpoints being deactivated and, also, code that executes between breakpoint activation and trap exit. To be clear these changes are not sufficient to make recursive trapping impossible since cover all the library calls made during kgdb's entry/exit logic. However going much further whilst we are sharing the kprobe blocklist risks reducing the capabilities of kprobe and this would be a bad trade off (especially so given kgdb's users are currently conditioned to avoid recursive traps). Signed-off-by: Daniel Thompson --- kernel/debug/debug_core.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) -- 2.25.4 Reviewed-by: Douglas Anderson diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c index b1277728a835..faa1f99ce65a 100644 --- a/kernel/debug/debug_core.c +++ b/kernel/debug/debug_core.c @@ -177,12 +177,14 @@ int __weak kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt) arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE); return err; } +NOKPROBE_SYMBOL(kgdb_arch_set_breakpoint); int __weak kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt) { return copy_to_kernel_nofault((char *)bpt->bpt_addr, (char *)bpt->saved_instr, BREAK_INSTR_SIZE); } +NOKPROBE_SYMBOL(kgdb_arch_remove_breakpoint); int __weak kgdb_validate_break_address(unsigned long addr) { @@ -212,6 +214,7 @@ unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs) { return instruction_pointer(regs); } +NOKPROBE_SYMBOL(kgdb_arch_pc); int __weak kgdb_arch_init(void) { @@ -222,6 +225,7 @@ int __weak kgdb_skipexception(int exception, struct pt_regs *regs) { return 0; } +NOKPROBE_SYMBOL(kgdb_skipexception); #ifdef CONFIG_SMP @@ -243,6 +247,7 @@ void __weak kgdb_call_nmi_hook(void *ignored) */ kgdb_nmicallback(raw_smp_processor_id(), get_irq_regs()); } +NOKPROBE_SYMBOL(kgdb_call_nmi_hook); void __weak kgdb_roundup_cpus(void) { @@ -276,6 +281,7 @@ void __weak kgdb_roundup_cpus(void) kgdb_info[cpu].rounding_up = false; } } +NOKPROBE_SYMBOL(kgdb_roundup_cpus); #endif @@ -302,6 +308,7 @@ static void kgdb_flush_swbreak_addr(unsigned long addr) /* Force flush instruction cache if it was outside the mm */ flush_icache_range(addr, addr + BREAK_INSTR_SIZE); } +NOKPROBE_SYMBOL(kgdb_flush_swbreak_addr); /* * SW breakpoint management: @@ -329,6 +336,7 @@ int dbg_activate_sw_breakpoints(void) } return ret; } +NOKPROBE_SYMBOL(dbg_activate_sw_breakpoints); int dbg_set_sw_break(unsigned long addr) { @@ -392,6 +400,7 @@ int dbg_deactivate_sw_breakpoints(void) } return ret; } +NOKPROBE_SYMBOL(dbg_deactivate_sw_breakpoints); int dbg_remove_sw_break(unsigned long addr) { @@ -513,6 +522,7 @@ static int kgdb_io_ready(int print_wait) } return 1; } +NOKPROBE_SYMBOL(kgdb_io_ready); static int kgdb_reenter_check(struct kgdb_state *ks) { @@ -560,6 +570,7 @@ static int kgdb_reenter_check(struct kgdb_state *ks) return 1; } +NOKPROBE_SYMBOL(kgdb_reenter_check); static void dbg_touch_watchdogs(void) { @@ -567,6 +578,7 @@ static void dbg_touch_watchdogs(void) clocksource_touch_watchdog(); rcu_cpu_stall_reset(); } +NOKPROBE_SYMBOL(dbg_touch_watchdogs); static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs, int exception_state) @@ -798,6 +810,7 @@ static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs, return kgdb_info[cpu].ret_state; } +NOKPROBE_SYMBOL(kgdb_cpu_enter); /* * kgdb_handle_exception() - main entry point from a kernel exception @@ -842,6 +855,7 @@ kgdb_handle_exception(int evector, int signo, int ecode, struct pt_regs *regs) arch_kgdb_ops.enable_nmi(1); return ret; } +NOKPROBE_SYMBOL(kgdb_handle_exception); /* * GDB places a breakpoint at this function to know dynamically loaded objects. @@ -876,6 +890,7 @@ int kgdb_nmicallback(int cpu, void *regs) #endif return 1; } +NOKPROBE_SYMBOL(kgdb_nmicallback); int kgdb_nmicallin(int cpu, int trapnr, void *regs, int err_code, atomic_t *send_ready) @@ -901,6 +916,7 @@ int kgdb_nmicallin(int cpu, int trapnr, void *regs, int err_code, #endif return 1; } +NOKPROBE_SYMBOL(kgdb_nmicallin); static void kgdb_console_write(struct console *co, const char *s, unsigned count) From patchwork Sun Sep 27 21:15:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 313603 Delivered-To: patches@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp2819499ilg; Sun, 27 Sep 2020 14:16:18 -0700 (PDT) X-Received: by 2002:a1c:488:: with SMTP id 130mr8069701wme.164.1601241378209; Sun, 27 Sep 2020 14:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601241378; cv=none; d=google.com; s=arc-20160816; b=kf1BxFtLsq4SD4NXbOLKLzuG3s6YbgfjGoJ7JoNqBclhjFY8BRJsdkrYfgTsN5qnBC Kh9PQT3irkxdV18dWeazZjcs9U9KhouYYbdGTsfMRWi0G2KN3F1coG258YGshk5kFkU5 BbYeFQJ1dTpMrHQj3ZD5sq1JIbXktSQd3hH1qQSC1pv3mpdTeX0DMShCJPiIBEeZcobq qMw/y0SGYy4fMNgo5ZNOjLFmCYfMjJ7Kpg/CgdUApLsuEe8fGcBJdB/evHS7YeCedEK8 dW1tADppbpNEeyKIXud9ogUzqBW/GqHlTKZVr7R2ErdleA+quJmv9tk2T5GNkJcheG6K jtag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=a99k07/EyDDQHmuhibQRaLo4XWgbxK6z35bVqiMsuv8=; b=dPUStuX+Q33Jhg4ABdCrxOL6jpJYa0DsPrkFBHeni7+ti9bUtzN7SgEa+gEqbvBqv2 7SlzJE/hkAOPobwbyBr3lKydzlwSCxFK3uNekjqBtdU6sp732pMdv7ohNHMdaFHZV8HT dkd+eXQK/l9RVrEX++Dp8JDvB8smYs09EJHdnObPHQWniZFVULX4UKc1lHIRuMvRlhX1 DWnvTat6Xv21+77PJ+aat8cpUSYZQcumkjgQV0skAXKjDwiOSlTbqY7QTfr5rE1y0FMM oSsEPrqHGsOMnYB1XAsJZcPVhv6YaWQzvxIdZO0BN/M8h2kaD/C+mdbds0aPCIY8EqUk 7wRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CjFXYG9B; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id a6sor4454136wrr.58.2020.09.27.14.16.18 for (Google Transport Security); Sun, 27 Sep 2020 14:16:18 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CjFXYG9B; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a99k07/EyDDQHmuhibQRaLo4XWgbxK6z35bVqiMsuv8=; b=CjFXYG9BR8dkXSbiyxLxrUYbFRhjiOb1vcwmYg4vsW7360k60NHd/8S43UvXZA5FT5 y5VyC5QYUXGmFaaGmwntXMTbUvqNhpSq3moC26ISTM5UAC+skTj4T6PO3hrzqrT6z15R hmAIvGK4AYwwCnEQeuzshHnQDATrFWpGn/iA1WzpjEShT3FvgfRikun4C5n3kerVeLUL 1ASUSioryEuYeddzAzUwSfgNb8cD3KjYmuWABM8tEtkal6+cf2e68Low/keUuApsOV6f /6j0xr2ThzRu2LrBh/JoIfZRwmi19wGblaXZqiOMVOmiIOcQs99OXexE8U3y7loHj9U+ 9Zdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=a99k07/EyDDQHmuhibQRaLo4XWgbxK6z35bVqiMsuv8=; b=HbbP6yJbPPt15etrNwZDqvXu2Fo1ivtBf3HCcK8c8rL3u6rUC+rIZGEwY+NnDahIeI GNlDITN1l+SwaULi7tddTNQlNqHziCAq/BSD50vPHazEm5AszoLxmqkc+QdQKMZw+LVC Chha9Fkkyj8mhgR26UjpnfHw14W2HhZ9fx37d1S7pEJdUlzrjLF2pGxtsayrHnYOAJu6 e1+RmucLjyhV99sTxJmjd9MjUwmpnvZuj1LFwzQ40CwhvP1BY2qhO8C+JWW8Q2a3UlDF vxkS2yU3lD5xoSZ/w6RQTSyvHjicBSlRHiOE7Pwki4BKLYgBaKbdR34X8wn1DUL89tgA B1xg== X-Gm-Message-State: AOAM530CVQfHd4DCNOSqhldW/MRk4gGJq9Za0YQ8IBPpdzVXkdiI0GCd oXRSKU4Kf5PEUXk16GhVCzfA/tCP X-Google-Smtp-Source: ABdhPJxsis82EaVU2Ny17vWSbD6xDjUxPFjWZp3tZqcI8T/hln1YFSfFswHXGrJGbExBNQLQpInGKQ== X-Received: by 2002:a5d:51ca:: with SMTP id n10mr15438828wrv.222.1601241377872; Sun, 27 Sep 2020 14:16:17 -0700 (PDT) Return-Path: Received: from wychelm.lan (cpc141216-aztw34-2-0-cust174.18-1.cable.virginm.net. [80.7.220.175]) by smtp.gmail.com with ESMTPSA id s17sm11396676wrr.40.2020.09.27.14.16.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Sep 2020 14:16:17 -0700 (PDT) From: Daniel Thompson To: Jason Wessel , Douglas Anderson Cc: Daniel Thompson , Peter Zijlstra , sumit.garg@linaro.org, pmladek@suse.com, sergey.senozhatsky@gmail.com, will@kernel.org, Masami Hiramatsu , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v3 3/3] kernel: debug: Centralize dbg_[de]activate_sw_breakpoints Date: Sun, 27 Sep 2020 22:15:31 +0100 Message-Id: <20200927211531.1380577-4-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200927211531.1380577-1-daniel.thompson@linaro.org> References: <20200927211531.1380577-1-daniel.thompson@linaro.org> MIME-Version: 1.0 During debug trap execution we expect dbg_deactivate_sw_breakpoints() to be paired with an dbg_activate_sw_breakpoint(). Currently although the calls are paired correctly they are needlessly smeared across three different functions. Worse this also results in code to drive polled I/O being called with breakpoints activated which, in turn, needlessly increases the set of functions that will recursively trap if breakpointed. Fix this by moving the activation of breakpoints into the debug core. Signed-off-by: Daniel Thompson Reviewed-by: Douglas Anderson --- kernel/debug/debug_core.c | 2 ++ kernel/debug/gdbstub.c | 1 - kernel/debug/kdb/kdb_debugger.c | 2 -- 3 files changed, 2 insertions(+), 3 deletions(-) -- 2.25.4 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c index faa1f99ce65a..e4339fd82db0 100644 --- a/kernel/debug/debug_core.c +++ b/kernel/debug/debug_core.c @@ -768,6 +768,8 @@ static int kgdb_cpu_enter(struct kgdb_state *ks, struct pt_regs *regs, } } + dbg_activate_sw_breakpoints(); + /* Call the I/O driver's post_exception routine */ if (dbg_io_ops->post_exception) dbg_io_ops->post_exception(); diff --git a/kernel/debug/gdbstub.c b/kernel/debug/gdbstub.c index cc3c43dfec44..e9a9c3097089 100644 --- a/kernel/debug/gdbstub.c +++ b/kernel/debug/gdbstub.c @@ -1061,7 +1061,6 @@ int gdb_serial_stub(struct kgdb_state *ks) error_packet(remcom_out_buffer, -EINVAL); break; } - dbg_activate_sw_breakpoints(); fallthrough; /* to default processing */ default: default_handle: diff --git a/kernel/debug/kdb/kdb_debugger.c b/kernel/debug/kdb/kdb_debugger.c index 53a0df6e4d92..0220afda3200 100644 --- a/kernel/debug/kdb/kdb_debugger.c +++ b/kernel/debug/kdb/kdb_debugger.c @@ -147,7 +147,6 @@ int kdb_stub(struct kgdb_state *ks) return DBG_PASS_EVENT; } kdb_bp_install(ks->linux_regs); - dbg_activate_sw_breakpoints(); /* Set the exit state to a single step or a continue */ if (KDB_STATE(DOING_SS)) gdbstub_state(ks, "s"); @@ -167,7 +166,6 @@ int kdb_stub(struct kgdb_state *ks) * differently vs the gdbstub */ kgdb_single_step = 0; - dbg_deactivate_sw_breakpoints(); return DBG_SWITCH_CPU_EVENT; } return kgdb_info[ks->cpu].ret_state;