From nobody Sat May 06 17:49:45 2023 X-Original-To: dev-commits-src-main@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 4QDFSB0M1zz49sT6; Sat, 6 May 2023 17:49:46 +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 4QDFS96gflz3FnQ; Sat, 6 May 2023 17:49:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683395386; 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=NuE5dMddArkSVw/Uk8sdxHOEBC6ckdco0N6G8FeyrjA=; b=mWX5SErzoTCnNnAs5NJx7n9iiCwPFHiOQhGDKj5o/+QbRosGdAdVucBq7L1EgcHrLv/Eye ULyYHZL+7qMOtKQkwjay9t2RPLCPwUppNmPGAizM6cxRDEBMNZzZq5g/NkvKHQEgX2QEsL zGAIm50rfMMs8BQq1RU5pP1upD1vQc0isPTYorv9wSt80DpR9VhUl2eHVwrngmPdHKlaal TYpuA5ajLssnhL/sGnHJJd4uG9ucX+8AI84Hf1t90taVoieBrzWfIFKU+PSraqB+BbBR2S SirdPhzRkkOWYxhXi4blewjBSayi/5drbWrwYVSWsJhfxMkHn/S6OOuDrc8oyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683395386; 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=NuE5dMddArkSVw/Uk8sdxHOEBC6ckdco0N6G8FeyrjA=; b=IUaXAIM6H0LC7WNvASxGGOMEpKAU8v4VTSH0s2eRL9hoOQ5AEsodGv+3epM7jHvezsRlvU axhqoYznQ7SkRBqIhkDeN+u9UBB1u/feVgeh6cHrdoQsXr2VtWcoqSKG6dvBcX0UDZ5x/j QoM50wqSuitdGsd6ELDiP0OhA2YeUyO5MQjNESvVD8tLB6elDUhLVqswb5AYFeW4CSkhkm r7C+aneWgqz+VfegtHWh6Nh3bVzvlIRsWWuxv5ESJ+yX2pR2Pjn5HFABCh72VT9k57JQbg o0ILRSdfd7strb131383MIY90B0YPzQO48R3P8cdcTQwaxWPZwYqpNwID0gjZA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1683395386; a=rsa-sha256; cv=none; b=Hy6KLliVcniXypqocRkj3tAuOsL38qEMiMj37fE1b3JwDUIN/IrBcQR0GNywIe/88Lj448 G8zywEASo6m88/gMo22sRemvpk6FvxYq72MgJ4HddiZ0OzPFBS8W5v3nxJA4Am+KnoNcZQ riOP90WlTtAjuWnWf6bba/d7z88RDW0WlHWhgigzYp8E3g8wUqgY3R4O0AzMn1/cAZodae n9DhZ0CEgJPvG4E34iB9ij9eBL0AiLkETP8aOa2kA9fTK/KCtkGoxL8c4O0wATY2t4JMCf Re6TfEYkQ9kLQRMg3SmxKOfcNm1f3vkjsjmX5ic/rHjphvcDJRx39KcXvnbLXw== 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 4QDFS95ltczm8k; Sat, 6 May 2023 17:49:45 +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 346HnjqD017956; Sat, 6 May 2023 17:49:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 346HnjS9017955; Sat, 6 May 2023 17:49:45 GMT (envelope-from git) Date: Sat, 6 May 2023 17:49:45 GMT Message-Id: <202305061749.346HnjS9017955@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: 5387495773e9 - main - hwpmc: simplify arm64 kernel stack unwinding List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 5387495773e9e92441b795c0eb8c2a3ecc25708a Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=5387495773e9e92441b795c0eb8c2a3ecc25708a commit 5387495773e9e92441b795c0eb8c2a3ecc25708a Author: Mitchell Horne AuthorDate: 2023-05-05 21:58:40 +0000 Commit: Mitchell Horne CommitDate: 2023-05-06 17:49:19 +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 --- 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 59d33ef34d06..dd51f7bd18d5 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);