From nobody Fri Jun 09 19:58:08 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 4QdBhd5z5pz4cKdg; Fri, 9 Jun 2023 19:58:09 +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 4QdBhd158zz4JWM; Fri, 9 Jun 2023 19:58:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686340689; 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=QCUmINrx5cHsRXP1UJ3G+56xaIZJBZvQOqqHZoPfvjU=; b=absEjJoa0uhYM3upo8FPdzV2CL6fIBnNRhiFASgHrikEJ0LdBneEI/kbnx0NFnTIW0xFeP TL0nQbiV9V/ii/EgKpQ9x4DdrEIFm9Pznhv2x1ZNwhuwqOHrI7H7Ot6FFDY1IF6yGqnJYZ Qxe4xmXlyjMZ+U90f6PDKiVYGPMTC09gfMB/FWfccsGTYfTqad6p/hQRoxIh0t5kUBArCK qMO714EOVN0suk9j1XELVN5ZTTBw7vAPy0H4VUtZKOrcU5JdO1YQqpCv9Vl457/G5L72mc 1p8D0wlEX4qLZ5O/mGemyeBPzxsMdPbEmf8EW0LQj6nXEV4KHj4yaEmlTzlSuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686340689; 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=QCUmINrx5cHsRXP1UJ3G+56xaIZJBZvQOqqHZoPfvjU=; b=pseV4Trg2Ia3z/oFedvY6N4+h5OUxThUElWe8jJs/i5z3mRKJuROeuP0iI6Yk2tW0bb1D4 bRHb7S0Vo+QrPZjl8PDTETr9JdAvfFtKNeCw3tAHX3YYfb/jhajc8rvTZaLLV8qvYdYAzc mBdrL82DPIoQ3gtSL53UqVltKVAwgTh1g7xBqr36Pjb6m3HSZdOtO8cVJsNBYKsjTer4Vb HfjbAUvdYSjX6jx4KZc4I9ihdntAXTZeIIRXEKpnJkRAZJM80J4RXil8ekORTcP9Ndq5eW tI0ECEro2OoxshzSa+xc3FehXQmqI7Mo+0BQnq6FDSyyaz1dbyQhApd1Y+JJrQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1686340689; a=rsa-sha256; cv=none; b=DVjBRDcn1sey8YSLUtMR6+IV+3sLCKfPW4G7rQHGcKakJctlphbDgy2zn3GR7Nt+9YPLYI OYoB/bd3dR2jH4w1Kho74q5Nk8baeb1nswNVung0vO4IFB8Lz+vSMizmyBidNmfy1H1Zfb YpP94b2WiSYKWcdaF3TajDcdJhp8e0/nCaBf+nW86F7371Go1DbMUNNswCFi6/ZurbJy7J nyJ+FlpT44r8BX8xvrumPvWqwsv4wP+ufwJkMlVs9WZ/I8486bQbfnO67I6IqAiZllPIko ZvEQNKNrPZkwzj0Y6HyjCcJNfgSwFWsOaFpijKfCUxNKUUKgkpgsu+tBe/g0vQ== 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 4QdBhd0C9zzp9B; Fri, 9 Jun 2023 19:58:09 +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 359Jw8ij072176; Fri, 9 Jun 2023 19:58:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 359Jw8vl072175; Fri, 9 Jun 2023 19:58:08 GMT (envelope-from git) Date: Fri, 9 Jun 2023 19:58:08 GMT Message-Id: <202306091958.359Jw8vl072175@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 6b5db9d3af04 - stable/13 - hwpmc: simplify arm64 kernel stack unwinding 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: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 6b5db9d3af0497e4538d6fd43df2596172867568 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=6b5db9d3af0497e4538d6fd43df2596172867568 commit 6b5db9d3af0497e4538d6fd43df2596172867568 Author: Mitchell Horne AuthorDate: 2023-05-05 21:58:40 +0000 Commit: Mitchell Horne CommitDate: 2023-06-09 18:14:59 +0000 hwpmc: simplify arm64 kernel stack unwinding Use the unwind_frame() function, which properly validates the frame pointer and uses ADDR_MAKE_CANONICAL() for the pc, required when PAC is enabled. Reviewed by: andrew, markj, jkoshy MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D39934 (cherry picked from commit 5387495773e9e92441b795c0eb8c2a3ecc25708a) --- sys/dev/hwpmc/hwpmc_arm64_md.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/sys/dev/hwpmc/hwpmc_arm64_md.c b/sys/dev/hwpmc/hwpmc_arm64_md.c index 015bee227f89..996c91eea592 100644 --- a/sys/dev/hwpmc/hwpmc_arm64_md.c +++ b/sys/dev/hwpmc/hwpmc_arm64_md.c @@ -62,7 +62,8 @@ int pmc_save_kernel_callchain(uintptr_t *cc, int maxsamples, struct trapframe *tf) { - uintptr_t pc, r, stackstart, stackend, fp; + struct unwind_state frame; + uintptr_t stackstart, stackend; struct thread *td; int count; @@ -70,38 +71,26 @@ pmc_save_kernel_callchain(uintptr_t *cc, int maxsamples, __LINE__)); td = curthread; - pc = PMC_TRAPFRAME_TO_PC(tf); - *cc++ = pc; + frame.pc = PMC_TRAPFRAME_TO_PC(tf); + *cc++ = frame.pc; if (maxsamples <= 1) return (1); stackstart = (uintptr_t) td->td_kstack; stackend = (uintptr_t) td->td_kstack + td->td_kstack_pages * PAGE_SIZE; - fp = PMC_TRAPFRAME_TO_FP(tf); + frame.fp = PMC_TRAPFRAME_TO_FP(tf); - if (!PMC_IN_KERNEL(pc) || - !PMC_IN_KERNEL_STACK(fp, stackstart, stackend)) + if (!PMC_IN_KERNEL(frame.pc) || + !PMC_IN_KERNEL_STACK(frame.fp, stackstart, stackend)) return (1); for (count = 1; count < maxsamples; count++) { - /* Use saved lr as pc. */ - r = fp + sizeof(uintptr_t); - if (!PMC_IN_KERNEL_STACK(r, stackstart, stackend)) - break; - pc = *(uintptr_t *)r; - if (!PMC_IN_KERNEL(pc)) - break; - - *cc++ = pc; - - /* Switch to next frame up */ - r = fp; - if (!PMC_IN_KERNEL_STACK(r, stackstart, stackend)) + if (!unwind_frame(curthread, &frame)) break; - fp = *(uintptr_t *)r; - if (!PMC_IN_KERNEL_STACK(fp, stackstart, stackend)) + if (!PMC_IN_KERNEL(frame.pc)) break; + *cc++ = frame.pc; } return (count);