From nobody Mon Sep 09 16:05:33 2024 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 4X2Wrs2xJGz5Wl6r; Mon, 09 Sep 2024 16:05:33 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4X2Wrs2Gbwz4rm7; Mon, 9 Sep 2024 16:05:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725897933; 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=qQ/dL71zeYzVF0Z7Icwgd2W+BMm2rwq+SVMDzh4dfd8=; b=IbL3QL4CT/eW6jQAVOTHU1dIocVHWI0AQ69EdNG/X03nOKZpb3Ox/XUHtxS/Cs2uA00QWB I0hXtQybevyY60WbL3sgxne1HlIDPLRtg8oAjJAfwOwU9bQT5502rZidpN6msR7F5HHb7r VkdSrDMI476/1vniYuKx2MpIrtPyMJw0Ri/mU4ArqLiOizvARrDOwUBmjJKnoQNneANI3a +hoV3vY4FSCedEJe1L7u6du5A6zPPsaWi/ivVrddDBBLGCX950+DYVPeCnABQdfdERU3qc +Sof139uqZXAYH4mLSRjb0lFH/7wgktPvg15Eyb3qj/B8GmyNlD1v4mJ7CBn2g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725897933; a=rsa-sha256; cv=none; b=OSbvvEXvr0WoM2bNdt9AjNPFaN1yGct9wLypfYtD+XM1Rv6mp886uhD4x4cRYUE0TZ21Oz Vi4S44UXfaaCuTjuTk1tZ7YRmyrmfYTm87e4v6HuMOTfgaKxmLH0d+5O5czWkweuqDo6P+ oCL/ON8yxUTuDB2eBhOAgjYpNSt1CLH36VdwwkHWRqnG0bLfOvxmy3tLGnNvqYQkKxKY2m gFjH3AjjIPGYH8nmHx5Ksbxf34WW1d2GjBslrBnII1R5YZjsIHDL6GjEpzdVQz7fyNlSLX Z+Jq6ElQ1x2Uf3EvgyJP9DzM3+rqRydZZy7k7dIc6W60V3lc+mgC900nx8xuWQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725897933; 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=qQ/dL71zeYzVF0Z7Icwgd2W+BMm2rwq+SVMDzh4dfd8=; b=oc6/cJsJJdtFtajDk5mFD6U5Db4FTxPbGxHOtJNNuySHR3pvd/cIZQxiYhj84LnlrfU3M4 IaX5slzkQOmt66fu90o3Bd2/TLERlHndEmWx3p0CTehxmnMFy+K0uNCu6AC0gpp35uivBp Wgx3dl+8RSDCx5g0KnamctPz/Spf+A9C+jC1p7W1Ndc1nc8WuInuQk0hGZHNpK2uvoMUuz yKrU9Oyaai9JMjpa4LbJY53YSHTvTdMaeAe2wqqWnTxovOEtDcTYZmQdGkXr5w+Z/im++h 7SyEGek5A3dJAq54314NGz9+3Sab+Jim/2FIr6LjTjtH6YuLjhnqKA5IY4TlCg== 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 4X2Wrs1ttcz18Xl; Mon, 9 Sep 2024 16:05:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 489G5Xra041846; Mon, 9 Sep 2024 16:05:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 489G5X6W041843; Mon, 9 Sep 2024 16:05:33 GMT (envelope-from git) Date: Mon, 9 Sep 2024 16:05:33 GMT Message-Id: <202409091605.489G5X6W041843@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: f05795e3f65f - main - arm64: write PID in CONTEXTIDR_EL1 on ctx switch 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f05795e3f65f305cb770ae91d8e9c8f05d267e0d Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=f05795e3f65f305cb770ae91d8e9c8f05d267e0d commit f05795e3f65f305cb770ae91d8e9c8f05d267e0d Author: Zachary Leaf AuthorDate: 2024-07-31 08:23:24 +0000 Commit: Andrew Turner CommitDate: 2024-09-09 16:03:19 +0000 arm64: write PID in CONTEXTIDR_EL1 on ctx switch Debug and trace features such as Statistical Profiling Extension (SPE) use the CONTEXTIDR_EL1 register to get the PID of the current process. Add a sysctl switch to toggle writing the current PID into this register in the thread switcher. To make use of the feature, the following sysctl switch must be set: sysctl machdep.pid_in_contextidr=1 Kernel code can also toggle the sysctl by writing directly to the global var behind the sysctl arm64_pid_in_contextidr: extern bool arm64_pid_in_contextidr; Reviewed by: andrew Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D46192 --- sys/arm64/arm64/genassym.c | 2 ++ sys/arm64/arm64/swtch.S | 17 +++++++++++++++++ sys/arm64/arm64/sys_machdep.c | 6 ++++++ 3 files changed, 25 insertions(+) diff --git a/sys/arm64/arm64/genassym.c b/sys/arm64/arm64/genassym.c index a4db825e976c..5a20169d51c3 100644 --- a/sys/arm64/arm64/genassym.c +++ b/sys/arm64/arm64/genassym.c @@ -58,6 +58,8 @@ ASSYM(PCB_TPIDRRO, offsetof(struct pcb, pcb_tpidrro_el0)); ASSYM(PCB_ONFAULT, offsetof(struct pcb, pcb_onfault)); ASSYM(PCB_FLAGS, offsetof(struct pcb, pcb_flags)); +ASSYM(PR_PID, offsetof(struct proc, p_pid)); + ASSYM(SF_UC, offsetof(struct sigframe, sf_uc)); ASSYM(TD_PROC, offsetof(struct thread, td_proc)); diff --git a/sys/arm64/arm64/swtch.S b/sys/arm64/arm64/swtch.S index 6af70ca839a0..3a2bf2cb5a7f 100644 --- a/sys/arm64/arm64/swtch.S +++ b/sys/arm64/arm64/swtch.S @@ -55,6 +55,15 @@ 999: .endm +.macro pid_in_context_idr label + adrp x9, arm64_pid_in_contextidr + ldr x10, [x9, :lo12:arm64_pid_in_contextidr] + cbz x10, \label + ldr x9, [x1, #TD_PROC] + ldr x10, [x9, #PR_PID] + msr contextidr_el1, x10 +.endm + /* * void cpu_throw(struct thread *old, struct thread *new) */ @@ -66,8 +75,12 @@ ENTRY(cpu_throw) ldr x4, [x0, #TD_PCB] ldr w5, [x4, #PCB_FLAGS] clear_step_flag w5, x6 + 1: + /* debug/trace: set CONTEXTIDR_EL1 to current PID, if enabled */ + pid_in_context_idr 2f +2: #ifdef VFP /* Backup the new thread pointer around a call to C code */ mov x19, x1 @@ -147,6 +160,10 @@ ENTRY(cpu_switch) mov x20, x1 mov x21, x2 + /* debug/trace: set CONTEXTIDR_EL1 to current PID, if enabled */ + pid_in_context_idr 0f + +0: #ifdef VFP bl vfp_save_state_switch mov x0, x20 diff --git a/sys/arm64/arm64/sys_machdep.c b/sys/arm64/arm64/sys_machdep.c index eedc57f7c572..eedee1d27015 100644 --- a/sys/arm64/arm64/sys_machdep.c +++ b/sys/arm64/arm64/sys_machdep.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -80,3 +81,8 @@ sysarch(struct thread *td, struct sysarch_args *uap) return (error); } + +bool arm64_pid_in_contextidr = false; +SYSCTL_BOOL(_machdep, OID_AUTO, pid_in_contextidr, CTLFLAG_RW, + &arm64_pid_in_contextidr, false, + "Save PID into CONTEXTIDR_EL1 register on context switch");