From nobody Mon Mar 20 18:16:50 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PgNH72PwVz403Wv; Mon, 20 Mar 2023 18:16:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PgNH70jT6z4Tmh; Mon, 20 Mar 2023 18:16:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679336211; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Wkycpvg8n+VCEwsoZvjRwJ1AedYz6FL3MZ3/2MC5R1s=; b=LXUj6wN88H3RPy/9AAG1QHBeruxIgQrcw8T3MjO5FTvLoUN/y814GQcH8rUbdfY9O6esIV 7qW0+4hNgwB4coh/4/v0d6PMh4wAqs0wdL0b2vmocBROv7W4HgupkeK4UaW+t6yE8zq0wm SYX2OKMBFuOZBC+pOOG6/tGlsCG9hzjvJkh7PD7elCBKgkyQP0ALV1HHn6CljdH12bIUIu AdvF/Db+IFuvSnfF2VQpqynJsE0oKvT0Xeb2T+Uu9gULRjbqAKHL1rMQtSof7dyX8JdYMS p/nIA61RsUyTAATS4nkZ1lL98It7zrGOqzIFS7Ybc9ejlsbh4k5gV/MsHhwVrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679336211; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Wkycpvg8n+VCEwsoZvjRwJ1AedYz6FL3MZ3/2MC5R1s=; b=l9lqk8lWc2ASk4vjOMhuvyMBQeVVpzY1kXTfDtJVLR8iB5lIk/uFYw65EIVOkOP+tlUX2u Oj/azY9VYtRGXMtNmKOZMguDsofAPtcIk/bBbJOelm4Xq1QNMA6TOGfKZRXGlXmRPdzW9n sMmXGsR7ScueKsXo6C17DL7+J3LcKNIU7pp5+puQeD0I1JU52ZLdIK+ZLJzIG5fSNxf7+g ftPoqj0lxhcV/Mg5yggvhRonfwSgupuYXWT+sJaGPUQ7PmD12a5Ta3OuxR3qRO5t+RigDI J4KEJKowPch/QV05RJMcG1BpN6pglxR80jUPEq9zRa/ExpZbGDgyCtpi6ZxGlw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679336211; a=rsa-sha256; cv=none; b=QkJiBLnFgOaQYHDg66Hi/4ilmlgjV69PNHe0g7BhZqKJs9xTGFhhUrbA7+o2X+J2XvNqms zqIpTkoH12xkHHoLE+1Dbdz/DFWfLANRQ0U+QM0P+qsgnXuS7EEKtTfJEjaxfkwPRf0kS8 HeOboE305qHfVU9ArFgO2nCXAPHINwM5DptFTuscyN0qcsDNPzlG1v2rXqR+gFZECALJ78 L/ob7j2+fT1vyG66Fa1SDKvCdbI9NvXMI8GGlBO/U8mUlvGPYe9QLra4eGAbg8fK0uE+Gn SnnBrkEf76naLJxhzK1huR+tkIblEOoFR3qKVJF9XNaW3X3dqYBZyo/CPacV8A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PgNH65rzXzgc7; Mon, 20 Mar 2023 18:16:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 32KIGoHA035592; Mon, 20 Mar 2023 18:16:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32KIGopb035591; Mon, 20 Mar 2023 18:16:50 GMT (envelope-from git) Date: Mon, 20 Mar 2023 18:16:50 GMT Message-Id: <202303201816.32KIGopb035591@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: c3179891f897 - main - kerneldump: Inline dump_savectx() into its callers List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c3179891f897d840f578a5139839fcacb587c96d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=c3179891f897d840f578a5139839fcacb587c96d commit c3179891f897d840f578a5139839fcacb587c96d Author: Mark Johnston AuthorDate: 2023-03-20 18:16:00 +0000 Commit: Mark Johnston CommitDate: 2023-03-20 18:16:28 +0000 kerneldump: Inline dump_savectx() into its callers The callers of dump_savectx() (i.e., doadump() and livedump_start()) subsequently call dumpsys()/minidumpsys(), which dump the calling thread's stack when writing the dump. If dump_savectx() gets its own stack frame, that frame might be clobbered when its caller later calls dumpsys()/minidumpsys(), making it difficult for debuggers to unwind the stack. Fix this by making dump_savectx() a macro, so that savectx() is always called directly by the function which subsequently calls dumpsys()/minidumpsys(). This fixes stack unwinding for the panicking thread from arm64 minidumps. The same happened to work on amd64, but kgdb reports the dump_savectx() calls as coming from dumpsys(), so in that case it appears to work by accident. Fixes: c9114f9f86f9 ("Add new vnode dumper to support live minidumps") Reviewed by: mhorne, jhb MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D39151 --- sys/kern/kern_shutdown.c | 15 ++------------- sys/kern/kern_vnodedumper.c | 1 + sys/sys/conf.h | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c index 6f912369268a..70de6b691fd3 100644 --- a/sys/kern/kern_shutdown.c +++ b/sys/kern/kern_shutdown.c @@ -244,8 +244,8 @@ MTX_SYSINIT(dumper_configs, &dumpconf_list_lk, "dumper config list", MTX_DEF); static TAILQ_HEAD(dumpconflist, dumperinfo) dumper_configs = TAILQ_HEAD_INITIALIZER(dumper_configs); -/* Context information for dump-debuggers. */ -static struct pcb dumppcb; /* Registers. */ +/* Context information for dump-debuggers, saved by the dump_savectx() macro. */ +struct pcb dumppcb; /* Registers. */ lwpid_t dumptid; /* Thread ID. */ static struct cdevsw reroot_cdevsw = { @@ -392,17 +392,6 @@ print_uptime(void) printf("%lds\n", (long)ts.tv_sec); } -/* - * Set up a context that can be extracted from the dump. - */ -void -dump_savectx(void) -{ - - savectx(&dumppcb); - dumptid = curthread->td_tid; -} - int doadump(boolean_t textdump) { diff --git a/sys/kern/kern_vnodedumper.c b/sys/kern/kern_vnodedumper.c index 26154af20372..0104369b9d67 100644 --- a/sys/kern/kern_vnodedumper.c +++ b/sys/kern/kern_vnodedumper.c @@ -44,6 +44,7 @@ #include #include +#include #include static dumper_start_t vnode_dumper_start; diff --git a/sys/sys/conf.h b/sys/sys/conf.h index ad6ffc31dc2a..f1d4df674e6c 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -360,7 +360,21 @@ struct dumperinfo { extern int dumping; /* system is dumping */ -void dump_savectx(void); +/* + * Save registers for later extraction from a kernel dump. + * + * This must be inlined into the caller, which in turn must be the function that + * calls (mini)dumpsys(). Otherwise, the saved frame pointer will reference a + * stack frame that may be clobbered by subsequent function calls. + */ +#define dump_savectx() do { \ + extern struct pcb dumppcb; \ + extern lwpid_t dumptid; \ + \ + savectx(&dumppcb); \ + dumptid = curthread->td_tid; \ +} while (0) + int doadump(boolean_t); struct diocskerneldump_arg; int dumper_create(const struct dumperinfo *di_template, const char *devname,