From nobody Wed Mar 22 13:17:23 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 4PhTXg4dVXz40q6g; Wed, 22 Mar 2023 13:17:23 +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 4PhTXg441Yz4W0Y; Wed, 22 Mar 2023 13:17:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679491043; 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=1SYIVjr7NdqAKBxodIoUXiHpK7Nk8UaP+OLWFStUVDw=; b=bcOvDrROyp21zVw5pe3fUEXcRR295rjf0CawAoc8CarW2+u434y/xu1bTPOAlOUh/CDME4 5u/q+nQqvfTf+azWnJ3V0YoLcBGbbvK57GN5QpCM3rtm9Hhucm8MirpUHDN1Sf70rnDGkB Ph7EDub0FM3x1YBzHsn7kp8MvyxhBdAwEXzvskV81tWhGT1lFEpMGOqUoqCqBgxk8h6s58 xnWyL5txt1VShVozTNXKJJHBwpX0xT58L8snvA42qU8q1IRw3rdRHoRpxu8/Tp4/LZw89h oEGyhDjAabksTSRD4uS5LehjZWwbh7ZEfUYafwl29IqiiOpfa9U4N3IGJqPHNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679491043; 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=1SYIVjr7NdqAKBxodIoUXiHpK7Nk8UaP+OLWFStUVDw=; b=r2otdb2XF+sV5lHfnaVbDXvUIUmjUXJrGzF2FJtqQymGLlncGIfLHym68u5xYHagj2TJv+ GlxTOzAUVDrwBUJnyEkfUs+TJl4qAEIC0wh3Mcj92YTkr/Bmey1AAF5V32fqdDViAvyxAS goc3dYZi8nnZqwAxtdCVROVceLnbrk9rq+S6fiHSDPy3H0M+1o3dON7inwoHZmwoYCAA9v Nn9ezTqs75LBzYT0/IPWfXdt+QJCKX5TKk3nX79KErA2cljQuZtUz2uROk6Tfg8WHm2S5k 6MUgSTb8mMyU3q6Bl8Sn+Gr2z/cHOcwfV1o22xDKxn+e3sSfc1942ksgywp0GA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679491043; a=rsa-sha256; cv=none; b=PcJszz0MNulyI6qX7qZ1Zg439doSmn3QXdA2iNTxWxvXZ8JeG7SfIqwaTRe0GZtmbKhjB2 F5mPWrCX4QqqnnXeWYJHXEJouozYpbxBr/64+vocz1/NQEOYy7TJ7zdAAHN6mm6wxnviEk Zrf+M0sVUGo6jAviXOYssfOvEbpWKuKDMxUWtJFgHmGD9HgTdTkSWLH+MOTLpfG4+5Hy0w HU4lirSckAW2w7Sqk6cBf6Mjrp1ucBSkXC1lIyjTIThx0boRiqyOjErs/cptNZMuMvCYJS qta9NTw5rIF8JPbQ253j2CsTGikqU/Dpn7DlYt/kqansFpyQseT4nK1YLIZN8w== 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 4PhTXg36fgzvdh; Wed, 22 Mar 2023 13:17:23 +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 32MDHNRl096640; Wed, 22 Mar 2023 13:17:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32MDHN8n096639; Wed, 22 Mar 2023 13:17:23 GMT (envelope-from git) Date: Wed, 22 Mar 2023 13:17:23 GMT Message-Id: <202303221317.32MDHN8n096639@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 2310894c1021 - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 2310894c1021f49b6c3003ba215ca978eee2be75 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=2310894c1021f49b6c3003ba215ca978eee2be75 commit 2310894c1021f49b6c3003ba215ca978eee2be75 Author: Mark Johnston AuthorDate: 2023-03-20 18:16:00 +0000 Commit: Mark Johnston CommitDate: 2023-03-22 13:04:19 +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 (cherry picked from commit c3179891f897d840f578a5139839fcacb587c96d) --- 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 ee6faa222206..cf9411420304 100644 --- a/sys/kern/kern_shutdown.c +++ b/sys/kern/kern_shutdown.c @@ -239,8 +239,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 = { @@ -381,17 +381,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 9f60dcaf62fa..b75af5a7705f 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -361,7 +361,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,