From nobody Mon Oct 21 12:24:26 2024 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 4XXDyL2jfPz5YwYY; Mon, 21 Oct 2024 12:24:26 +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 4XXDyL1HZfz4Dkc; Mon, 21 Oct 2024 12:24:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729513466; 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=j7tCLBqT+RWzIxBLjlTqY8BGj61E5l0K2dF4eEHjwu0=; b=Z+a7YwK0w4grsFRAz75poYx11Syb4KUzEU5KDtsYehN6jrLFhoLuRiK5gcgJl1653yt96n ZDBF3oR6v1coM48uk19RDc8Mgsx6B7BUnQpYkvYIJMdyqxTOplK+rLshCBec61G4ak7wVa HS7L2pWQRWImVUNSjwBGgbC/J2aV+3CCKdIOht8aQkRpqTnoRDSTI1Ou2NJYwoHtlFZGaV 5ZgPGi7Q2mXXiX62j/U/QCtOjML+9F+mHX1AILGPRypqozzyWYcz/wTdqQYgGmOtiFk7Zp yParJ0sF3TnScWuanoXwjjIM63Wi+nKrXVwgzBdUUYcqQW5jYcqsWUEUjkt3mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729513466; 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=j7tCLBqT+RWzIxBLjlTqY8BGj61E5l0K2dF4eEHjwu0=; b=m5JkqwJ77cM6YWRwXRftFhBCsF6hR9AJrrtH4YT8GTQoecXA1o4qdsNQOoogga0fLClkft 4TrLxtG1dRWWcLX2vrNGhpszSJx0Sogb/80N2jPaESsHmBtl0JhqllqN5fCylxto7UpNbc l5tZD28fvMHoECExEEAHl4FhR13XXDSjRuaOPo+sESMvRkUexKZF4nBe4H7X2yxGCmYtS2 xgGTjkym7Rwui3e+Ez0VJU7lj+6DGyyG3H7JbXvhW4m21dfJRnr4RgVlxK9r1+xpqHFzNd HD0xqL8DOqv0e1pzsCzjJJkSQlMMVaGlOHTsR3q2+JaLkFp/RKHe7zmGcKaHkQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729513466; a=rsa-sha256; cv=none; b=iQix7daoF7/WMSguHjYQUDIzUxE3uY/+8+SeTTXQEkkyidnShhCe2ExOrEDw8UQi0lAS92 6VSFewN/5u+gK3anY4trYp7rtStRHnIUvQJdMQBNIQ911SkdwxaT9WyxdPjoJ/ZReRBoNE 6z54KgEUF4stXdJuyrjlu9yNuIqR+TY62c1qwKukRfpblxjwT1/ljN/dD2zYYSqjq7qoUZ Ww4s9clCC45KXKEAyNA2GSskKxBStF/YT9VHu5FoKFw1BbSX4rWhu+egG8VmWM/sVMgCbZ INgKMn7bgmmyNZyX91Yqf/Pd6+MUgQpgCwF5skk6MScNr6o8IpMDKLGPqq6mwg== 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 4XXDyL0v00zVsj; Mon, 21 Oct 2024 12:24:26 +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 49LCOQSp049390; Mon, 21 Oct 2024 12:24:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49LCOQqQ049387; Mon, 21 Oct 2024 12:24:26 GMT (envelope-from git) Date: Mon, 21 Oct 2024 12:24:26 GMT Message-Id: <202410211224.49LCOQqQ049387@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: 3bd4724794a5 - main - arm64: write PID in CONTEXTIDR_EL1 on ctx switch 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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: 3bd4724794a5e5838f09420a615227416d6b2903 Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=3bd4724794a5e5838f09420a615227416d6b2903 commit 3bd4724794a5e5838f09420a615227416d6b2903 Author: Zachary Leaf AuthorDate: 2024-07-31 08:23:24 +0000 Commit: Andrew Turner CommitDate: 2024-10-21 12:23:16 +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; Sponsored by: Arm Ltd --- sys/arm64/arm64/genassym.c | 2 ++ sys/arm64/arm64/swtch.S | 21 +++++++++++++++++++++ sys/arm64/arm64/sys_machdep.c | 6 ++++++ 3 files changed, 29 insertions(+) diff --git a/sys/arm64/arm64/genassym.c b/sys/arm64/arm64/genassym.c index a4db825e976c..8cbafba45a7d 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(P_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 c683a7e25314..7b6010a5f51f 100644 --- a/sys/arm64/arm64/swtch.S +++ b/sys/arm64/arm64/swtch.S @@ -55,6 +55,21 @@ 999: .endm +/* + * Lower 32 bits of CONTEXTIDR_EL1 are PID + * Upper 32 bits are reserved for future use e.g. TID + */ +.macro pid_in_context_idr + adrp x9, arm64_pid_in_contextidr + ldrb w10, [x9, :lo12:arm64_pid_in_contextidr] + cbz w10, 998f + ldr x9, [x1, #TD_PROC] + /* PID is always 0 or positive, do not sign extend */ + ldr w10, [x9, #P_PID] + msr contextidr_el1, x10 +998: +.endm + /* * void cpu_throw(struct thread *old, struct thread *new) */ @@ -66,7 +81,10 @@ 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 #ifdef VFP /* Backup the new thread pointer around a call to C code */ @@ -147,6 +165,9 @@ ENTRY(cpu_switch) mov x20, x1 mov x21, x2 + /* debug/trace: set CONTEXTIDR_EL1 to current PID, if enabled */ + pid_in_context_idr + #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 efe2931e6b8a..33000b6c223b 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 @@ -92,3 +93,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");