From patchwork Mon Sep 14 13:01:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 249760 Delivered-To: patches@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1614477ilg; Mon, 14 Sep 2020 06:02:03 -0700 (PDT) X-Received: by 2002:a05:6000:124d:: with SMTP id j13mr16887725wrx.182.1600088523370; Mon, 14 Sep 2020 06:02:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600088523; cv=none; d=google.com; s=arc-20160816; b=jgbZcTdZkuJ2MDFKWr0bGA9H/nyMn5dCswijULwYQxn+hQEpqB3BApBInxCzwDP2Rc +i/f3iI1cHry3C1pVeSp1LsrBwniGUVPu8EyzPU++sgxAz/QkS53YYCCf/6eDskbileF slfkNA15rBjmkNCPbMGgKGVu0i7mf3nL7titeZqTOkySBnV+AkLNPdOXIBgVHJkUCTmV XgFU4qc0c1eLsCURUgDG+M8p58jWAB9VkIWsRDSMQtBfPLYW7xzmB+toXXQdwu7xTZVo iOwZmnTA8OKOKQ0kk2afXFQs1tK1pHJmjG4YdKbnySgs/YMWdhA/Tp7Pl9vY8L8YvBH3 Dpng== 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=o2bHvryZQLWnkv+dYNHBTXO/DsrmPeloLYjVsFFfptI=; b=C7wQaBvSPMXABWpkJZAoUQIrx/Cp/OncYxp1wJkSTvr6Y8jqDTpu5JP64ZVqLzXDG8 Cbmp9dwvgnXREh4FF6UpmfFbvKsja4fr9krqHOfYYpJpcDfefHC0i34hIbfZUVLnI2Aq 2hiTxpzAaWhQPjs2ckosR4wXefCP8CnIJ6jW1ecwPj5cCjeDoGRdrv6UwVhToyYgz4mN Ohu2guwHlmdYyUsmznPbNSlreGm12QRXTZMnfIm1moQTLSoaQHCTE6qFvPkkROnmORPm 8uBhPlBu8VRke5M6VVEYThKNgg3stdvQe9UQFV95mKHUcjgxN0TVth7tK61sqTn0Sbta LEVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pE2cCoB4; 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 y12sor4868150wrw.45.2020.09.14.06.02.03 for (Google Transport Security); Mon, 14 Sep 2020 06:02:03 -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=pE2cCoB4; 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=o2bHvryZQLWnkv+dYNHBTXO/DsrmPeloLYjVsFFfptI=; b=pE2cCoB4QzQ08cjcZxpQf2kst5TzIrF2i5trDOAzUpy2s9zeuwAQ/Nx3IFBR9z/hXZ 2kKNmcYp5d1ZihOljX+hxl3qNDCb0lc8Y8Mvobr9D5EKagkgH1aB9uVQ4CVdYdrRXoY9 zP42ixjTX6ZAvclvIg6i9jBtf+RZtIOUlXhRiQGMhIh6IQswvzUWCBLGVz5emnKjak20 xWGDPxKFgvhvznguBIIQHlgs/TWGbKxGF3WaYWx6vOR+btYNXEM835N65nlXsV2u7cKK 6jmc2/2qvjDCEsfykogJZ0sLkaEOgM775yi8SXaX/hwGEy+nY/bxXpLvhpQMUaWpAXrk KYug== 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=o2bHvryZQLWnkv+dYNHBTXO/DsrmPeloLYjVsFFfptI=; b=ueiCd61DbstxCjFqA5awJSt0e2u8DT2UVspaexk/ANytvrFlsGVqLzxXW2cleg6pcU 2duUvqADRrInWEZCfaBj+KRrwF8OUSRTOXmtgfgSP6b/SR2iJ4mEXgs7eo+6agDt+8iI oGkVu6Ok3QN7ajiPM0AQ6U52JEHozYdQOhqTsRUnhmWreP30VxVICIC5lRTVWfz3KvjY oxFCuhTsShIWw000jHW79ezI/TmCUK86InZqCu4L5h+ZcZY9zi+N22fY2JTM6gkGusaJ W8lCSVtrWOIU/ob6Y1L8xrUMt35OsddKxj/8zJ1xmtgkK/lt3WoqMp3HePDK7/pIodT3 GcwQ== X-Gm-Message-State: AOAM5337oa0favZSpggThnvg20fJOMlZ9oojrYQ9jl92mkfUDJ4x8sPO DXXAYk9K6w5k+OeBxDbF+Crrb2xy X-Google-Smtp-Source: ABdhPJxZK4XsK2KPeAGMEzC3inVIZOP5soww3+m9A+K0lTdvS3ROedJ839p6WuCHWNrJ0H7MDRhGdw== X-Received: by 2002:a05:6000:1c8:: with SMTP id t8mr15767631wrx.3.1600088522936; Mon, 14 Sep 2020 06:02:02 -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 t6sm23420983wre.30.2020.09.14.06.02.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 06:02:02 -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: Mon, 14 Sep 2020 14:01:41 +0100 Message-Id: <20200914130143.1322802-2-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200914130143.1322802-1-daniel.thompson@linaro.org> References: <20200914130143.1322802-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 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 | 14 ++++++++++++++ 4 files changed, 45 insertions(+) -- 2.25.4 Reviewed-by: Masami Hiramatsu 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..713c17fe789c 100644 --- a/lib/Kconfig.kgdb +++ b/lib/Kconfig.kgdb @@ -24,6 +24,20 @@ menuconfig KGDB if KGDB +config KGDB_HONOUR_BLOCKLIST + bool "KGDB: use kprobe blocklist to prohibit unsafe breakpoints" + depends on HAVE_KPROBES + 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 Mon Sep 14 13:01:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 249761 Delivered-To: patches@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1614495ilg; Mon, 14 Sep 2020 06:02:04 -0700 (PDT) X-Received: by 2002:adf:e3cf:: with SMTP id k15mr14941670wrm.291.1600088524421; Mon, 14 Sep 2020 06:02:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600088524; cv=none; d=google.com; s=arc-20160816; b=Gp0jRAaaUe8/5m72ofGaHo0u75cxCVAxXaj/6Ku2n9fgCUjy+7SFVkFQxvw6ctZpIa JfUgbObKSNyrb/2urnSBpQx9R9mwer9STRtHRIQq4D99Y1UHAaJTgESx/NfaXsknhD5v tq0YL2GPHf3k/aKSk9xyqh+DPAszo+xoSm1NFZnS2dLt5NS0gpVycmV+vmXWI6clJQSC nbgNlF7JbakI4oK1VHLLbBY8UUQ5GeWelMOR/U4PbjKJK4GCpu1EMF7UpzHOLevCNEYh n+EeeEVpSotxlMVI4s8cEz7WrANR3TBueMdIpML9SVG6mN0GPsciApcFJhS0H6i2KiGK C4zQ== 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=NBc+524mNMySIXGyBF0ZKFskAXcAly2eLLkxj4mn+0Q=; b=WXOa0Pwlu2n64QLbilCpWiJF+J9yxf3IPkLwGOMEFX/G7MwJ7tCH+bG7l+6AYem2XR 8sc0q7Sn3J9qHVTl5+n6b9Q7P9zxH35rfXHaCuN90cE664Pe9qePUd79cmP54NuNSTwS SOEHY7WQUraSZjuMmqqpyiORa/9DewzXpQx0wI2WAEje0ZorziYIlEmAZOzSA2cZV/M3 dnNOaEWMJVf+gFlgm9UeAXab54kHY5KzqzlAzDqHn1rJzDGeTH9jIomGFXhT2AnpIy2h jUTYQgmQAF7rmuOXCHbInChe3BVlIv6xsCE2hE92puPnrI0AlxnQnQkQVFhUaGU0ITJS 3Qnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="wW//ZSe6"; 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 c17sor5030624wre.28.2020.09.14.06.02.04 for (Google Transport Security); Mon, 14 Sep 2020 06:02:04 -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="wW//ZSe6"; 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=NBc+524mNMySIXGyBF0ZKFskAXcAly2eLLkxj4mn+0Q=; b=wW//ZSe6q99e6l33yqQ0bv9yrvassnq7qwZRgFmB3tl5KWNCuLqKteAKnwijt+a7M4 RSOJCituZMcaXRkqRQ+SRT6J4ASyMHxdQFmS0L5pfONjKlLWGM+zXRYRhQT/7Vn9Xkxw 1aIZa7RfhcW39YkRlDXTFvXugx0sEaAKqJGvaN+UVce/RUL+FahnGAm2Iyop8CYrrqZx bk8iZ5tUfH+ksOynOz+ZqTp7aa8Qm5MMTOSsq09VpPAI9wOpC0jz6sSRG45t+kGtsJCE mVNE6KEkrQTEeNSJRDmweR9U7pDvTGTCHcKTdrLTfkkmuyrlKyYey17h6QfKd1CDKBcW H4Kg== 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=NBc+524mNMySIXGyBF0ZKFskAXcAly2eLLkxj4mn+0Q=; b=toTXuxCC4zGIp72gmtFTOFqVJdhRPsqm5uUAbbkMO5ghIvxku9xGA3NyKUEr62s5sh 5dtlrU3SA77L5Wk6LdV/qE+ddh+dX3PITvKCZIZp79MXOa6EadIw3BxrPoOVniVwUSGQ gHW+CdZfSrO1BU6nDkMSvPb4zqkzTmFG07b3P22199RQWwBlvOjgavpoVQiqj+jviVym 7w1aGwYYw9TfL/7HxdlT3bhe4QGwvnUkjeNyKc+3X+ICcxS7qYKA/uQ5/931nMk9+uLl XG21JC++2yPnCQsnWwDeX/H5aVqwcR3fpfTqTu6Zd2KTgd+KKFsBB5eFs6qMwv3mo47v U5JA== X-Gm-Message-State: AOAM531uWAJsTSESED5UsVY7ZJdoXRB3TTK6z5TI/bOhPvpe17mmSutu TcPcBQvzWoGJw+UBCEu6ZH3koRz1 X-Google-Smtp-Source: ABdhPJx0l/sd/ukowq4I6JNlM0FlvEF8p/b6PwzlqUyLsn2dcKfjzKGIpoDUNVbkTK7sLhad++59xw== X-Received: by 2002:adf:9b8b:: with SMTP id d11mr8024287wrc.71.1600088524074; Mon, 14 Sep 2020 06:02:04 -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 t6sm23420983wre.30.2020.09.14.06.02.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 06:02:03 -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: Mon, 14 Sep 2020 14:01:42 +0100 Message-Id: <20200914130143.1322802-3-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200914130143.1322802-1-daniel.thompson@linaro.org> References: <20200914130143.1322802-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 | 11 +++++++++++ 1 file changed, 11 insertions(+) -- 2.25.4 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c index b1277728a835..9618c1e2faf6 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) { @@ -302,6 +304,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 +332,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 +396,7 @@ int dbg_deactivate_sw_breakpoints(void) } return ret; } +NOKPROBE_SYMBOL(dbg_deactivate_sw_breakpoints); int dbg_remove_sw_break(unsigned long addr) { @@ -560,6 +565,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 +573,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 +805,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 +850,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 +885,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 +911,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 Mon Sep 14 13:01:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 249762 Delivered-To: patches@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1614511ilg; Mon, 14 Sep 2020 06:02:05 -0700 (PDT) X-Received: by 2002:adf:c64e:: with SMTP id u14mr15374736wrg.373.1600088525612; Mon, 14 Sep 2020 06:02:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600088525; cv=none; d=google.com; s=arc-20160816; b=t5iESxuHApVV4FxxAPwERzPbZMdYEgEFyYyQzLO2I5YE7LHCyBOWczU1nZNz8JbjZn bVVhCe4SZZymm/T1ZB1hjrbRYWxJO//5Udu0UH6Clesp0KSSwLYlVUZECrIjbd3hm4VS zWQMa9AuG1GT87YC42x9oaG8Y/lY8j3e4/M7mTp5yIdTVvrzI5Wwm1YHhwTqSFFFPXH4 AFASzU7VXoDEVxqpNLh87d0K8NW4qE4WlKotl5W4rSCFGwJEVPZTU59y+cx0WgVdsq6o cTX8RfNCRrikzxz8fVuh8v8aTXqC8w90zKgyGGgYJ6q1ZpayaNA40jc1DSphlnn8VqlY 8vgQ== 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=tOLZ70bedyzf8xgXzV0MTRrdMCvy/3UOdRHKK+GhNMo=; b=d/2n44xrqwLhpAwYMlCuxTGDkrdYdgXwB6glEbt5MJve55hIoQBNHqkQ21UfjpVtGm 5D5Q4JrgYREMzgu5lHFlE3XtYFVtaQUFw1cvVCGOFtLyzOjNP3XEo56wo+wKJ44fozSw GUfZMi+v3imgkr7BCzrvIWSSL+aTsrNUDvbcbVQhl/WoFRGsurCiGlx0qJNiHEn6XfBq xNbZ7+gS3smkPTk4VqrviTGVEgHbphdERlqouam0xL7prvTuJQHkzFM2jX89e1QqbroE /+hghPhfkePb7WDe8GmaC+cw+FfZdIu6K72FVLR89lyRnmJhxKpVyabVaNspglV5h5At DDig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=POu12cEa; 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 e13sor4933832wrr.40.2020.09.14.06.02.05 for (Google Transport Security); Mon, 14 Sep 2020 06:02:05 -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=POu12cEa; 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=tOLZ70bedyzf8xgXzV0MTRrdMCvy/3UOdRHKK+GhNMo=; b=POu12cEaJFApnX2+rMx/2kxThtVNQIhVlX9u3uZHeXLJOzGppLaqXQdv+tPvj5R+xE tX780vtge+r4reu3udS1EdIs+vCSCvs8D/OznPjbRs9vgy+n5aPGJSYIbTB6XBJCv5nN Eo26ybzSJ1+gIxNxBFYRTZ8MiiuFtHMtM5t4awBHb5W7QJUXZGMexDV6XkZH+/ZibUR/ c57u3FcVLQ9yVf6Pe0gAy47AMCdKNxJpebRjlWTpU6ea9Nj/lqnkyRtHq5C2oaTmtJUN vB+yien4dbtStTvDkZj+6qjtUCyixOMzrjEZpwkgJj94aR/1IDbIEu6Lo/fqksseLJT1 Csmg== 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=tOLZ70bedyzf8xgXzV0MTRrdMCvy/3UOdRHKK+GhNMo=; b=lMLvcEkh+UNhJEFCerNmVeXvMeAnfaRWsJFrLnW7ry3eeL9o8QALoxW+CvqQfbtvwD H4+qrcQ3fXTe2+sNqZtN3MQsyZGX4l9BWnfl0jRh2p6rdeDYsHvFxQs+pgO1i8YOYI9C qRNy6IO02mha+jegWZxtoyjulaX++UUJiImnU0E/1aDh5VYR0kF/M4BsS6wrk6zAxMR9 WKOa7qRodbLT7Ru/gqTbxe5Q58hR4VSHmNlbXrVn3SVBVDhgbmUE2a2bvGR8v8Pd/RT2 lirgkq0Y55hBEiPY7dC9qaq4oCTH0McU9nHRV2uBf+0gZvER3Ob/7dDyXmg0EHELD1Wj Sd6Q== X-Gm-Message-State: AOAM531MGylijPQEDiTaLIm+sdoTtTOwfmbVcRHKqcawnweEMwSzhF65 528ctU+Tw+0i/K2zZkGwFLoA2KFX X-Google-Smtp-Source: ABdhPJxdxolEdcYMjP3ctpO3wrxCQQtg4g3aiPudfFv1rQGBGhcDTJuT8gbgF3Z/w5SfmtM8lkj34w== X-Received: by 2002:adf:f70d:: with SMTP id r13mr16395380wrp.317.1600088525276; Mon, 14 Sep 2020 06:02:05 -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 t6sm23420983wre.30.2020.09.14.06.02.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 06:02:04 -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: Mon, 14 Sep 2020 14:01:43 +0100 Message-Id: <20200914130143.1322802-4-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200914130143.1322802-1-daniel.thompson@linaro.org> References: <20200914130143.1322802-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 --- 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 Reviewed-by: Douglas Anderson diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c index 9618c1e2faf6..74d42d3f3180 100644 --- a/kernel/debug/debug_core.c +++ b/kernel/debug/debug_core.c @@ -763,6 +763,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;