From nobody Wed May 27 14:59:30 2026 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 4gQXpC1T0Dz6f98S for ; Wed, 27 May 2026 14:59:31 +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 "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gQXpB6jC9z3HN1 for ; Wed, 27 May 2026 14:59:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1779893971; 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=CbtDeE5XlzLnVJ3wVM3Oxr+MztxJu0WkCBJPV3Ex3mI=; b=DyLWi/zqYhnNUyztYP/Gyp6+5vHsPu/Ug8V6B4aXLw/ooSs063Jrjt4SAy8udNCFKQ7WwM kwNx19YEgVi609y77dTtPaAbMCkf708gxQNPhvw43RYrTNmy66QJsOjx+UDE84dlywjkF0 oLi+uwrvnhxGgHfxlPH//X5HSLgEXSxPC9CaKOii9so3hb6yRqAs38buHDhfFjB+sj1U1G lvTthcbrMYi9v2cH4sS0szamcn4GOpP+lIYPqmO2UBKkW1TlS917oPKQAI4tO6XVEj9wVM WH/+BBWwreL5BwmxD9xj/b2bsr/livu8mnrYCz1DQTSGok1vz0sRNJBI8SJl1w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1779893971; a=rsa-sha256; cv=none; b=P/ET3HiWJdkeHT09n9l88byCYaOPC4PamCzcIn3pZVV/STxxeaPf5c+GqnlFfpuhR7K6xS W1nq2bHQ/4Xzx+99+nKHIseDYWwdA8EPzwLd5K8iOY3mflzTeZJl9UAYp9EIpfMHEnDBbQ x5m496fZffOvqBpNQxjQ5vK6QSl1tFw1xxVEAz4cTaPEoQbpZIiGRXa8ehsGD2Q9v/q5mk b0BpufNtWNiLVSA2t+5KgkMMmecBny2b2eNAv9cH+wLML/2sGg9FxiLUyK/OXKQvxHp9eq OJrO6lBmrcCV6Xpo0519eICfMnJ0lytud2yMS2NQ0UbvTmpBj9InKiV11EEmWg== 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=1779893971; 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=CbtDeE5XlzLnVJ3wVM3Oxr+MztxJu0WkCBJPV3Ex3mI=; b=RtkvkKBfYKXnMF6XmRm8xAH/kNvmKj74ea0wsIecalV92nf1j2WbUfhWEQ5L9bZXQq1t+O +fJtM/9a4PgXDa78+444on9T9SXte5qCqBFChh5+54lTztm94Mbw1TWh6srxTDHWDDUBG+ RXpAXkPktKKbgGWFrvf10kJgEHefpOirHygrxAJyg9LhrEbH0xtu6qVkOU8Rg2VPljPr+g xumDhOg9Uia2yUDQHgSS7Y2Y04oDwVCZPhiSqUftQGQTg1gVg7q95qwyVezrIpAs+L9apK 4NxXy5NmVY+ElEklmem0HDPVN+5E2DTIeV9+7CEE5WJJ2/m6cVq+gpARK3WN2A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gQXpB63v6z1465 for ; Wed, 27 May 2026 14:59:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 22b35 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 27 May 2026 14:59:30 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: John Baldwin Subject: git: 4f876cec30af - main - riscv64: Move pcb out of kstack into a new UMA zone 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 List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4f876cec30afca1a32d0187fc81d6c3ffd1abc30 Auto-Submitted: auto-generated Date: Wed, 27 May 2026 14:59:30 +0000 Message-Id: <6a1706d2.22b35.2d945453@gitrepo.freebsd.org> The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=4f876cec30afca1a32d0187fc81d6c3ffd1abc30 commit 4f876cec30afca1a32d0187fc81d6c3ffd1abc30 Author: John Baldwin AuthorDate: 2026-03-28 15:19:53 +0000 Commit: John Baldwin CommitDate: 2026-05-27 13:45:26 +0000 riscv64: Move pcb out of kstack into a new UMA zone Similar to arm64, riscv's pcb embeds a copy of the floating point registers and is too large to store directly in struct mdthread as is done on amd64. Instead, use a separate UMA zone for pcbs. riscv's floating point state is not as large as arm64's, so its pcb is also somewhat smaller and a single 4k page can hold 6 pcbs. Reviewed by: kib, jrtc27 Sponsored by: AFRL, DARPA Pull Request: https://ron-dev.freebsd.org/FreeBSD/src/pulls/23 --- sys/riscv/include/stack.h | 6 ++---- sys/riscv/riscv/genassym.c | 1 - sys/riscv/riscv/locore.S | 4 ++-- sys/riscv/riscv/machdep.c | 3 ++- sys/riscv/riscv/vm_machdep.c | 20 +++++++++++++++----- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/sys/riscv/include/stack.h b/sys/riscv/include/stack.h index 5669dcda6c67..fac8d4f317b6 100644 --- a/sys/riscv/include/stack.h +++ b/sys/riscv/include/stack.h @@ -48,12 +48,10 @@ bool unwind_frame(struct thread *, struct unwind_state *); #ifdef _SYS_PROC_H_ -#include - /* Get the current kernel thread stack usage. */ #define GET_STACK_USAGE(total, used) do { \ struct thread *td = curthread; \ - (total) = ptoa(td->td_kstack_pages) - sizeof(struct pcb); \ + (total) = ptoa(td->td_kstack_pages); \ (used) = td->td_kstack + (total) - (char *)&td; \ } while (0) @@ -61,7 +59,7 @@ static __inline bool kstack_contains(struct thread *td, vm_offset_t va, size_t len) { return (va >= (vm_offset_t)td->td_kstack && va + len >= va && - va + len <= (vm_offset_t)td_kstack_top(td) - sizeof(struct pcb)); + va + len <= (vm_offset_t)td_kstack_top(td)); } #endif /* _SYS_PROC_H_ */ diff --git a/sys/riscv/riscv/genassym.c b/sys/riscv/riscv/genassym.c index c216c686db9a..998183e92db6 100644 --- a/sys/riscv/riscv/genassym.c +++ b/sys/riscv/riscv/genassym.c @@ -63,7 +63,6 @@ ASSYM(PMAP_MAPDEV_EARLY_SIZE, PMAP_MAPDEV_EARLY_SIZE); ASSYM(PM_SATP, offsetof(struct pmap, pm_satp)); ASSYM(PCB_ONFAULT, offsetof(struct pcb, pcb_onfault)); -ASSYM(PCB_SIZE, sizeof(struct pcb)); ASSYM(PCB_RA, offsetof(struct pcb, pcb_ra)); ASSYM(PCB_SP, offsetof(struct pcb, pcb_sp)); ASSYM(PCB_GP, offsetof(struct pcb, pcb_gp)); diff --git a/sys/riscv/riscv/locore.S b/sys/riscv/riscv/locore.S index 305ed8d79f10..e2126af5cad2 100644 --- a/sys/riscv/riscv/locore.S +++ b/sys/riscv/riscv/locore.S @@ -241,8 +241,8 @@ va: /* Clear frame pointer */ mv s0, zero - /* Allocate space for thread0 PCB and riscv_bootparams */ - addi sp, sp, -(PCB_SIZE + RISCV_BOOTPARAMS_SIZE) & ~STACKALIGNBYTES + /* Allocate space for riscv_bootparams */ + addi sp, sp, -RISCV_BOOTPARAMS_SIZE & ~STACKALIGNBYTES /* Clear BSS */ la t0, _C_LABEL(__bss_start) diff --git a/sys/riscv/riscv/machdep.c b/sys/riscv/riscv/machdep.c index 47d9636492db..f5479c479109 100644 --- a/sys/riscv/riscv/machdep.c +++ b/sys/riscv/riscv/machdep.c @@ -105,6 +105,7 @@ struct pcpu __pcpu[MAXCPU]; static struct trapframe proc0_tf; +static struct pcb pcb0; int early_boot = 1; int cold = 1; @@ -296,7 +297,7 @@ init_proc0(void *kstack) proc_linkup0(&proc0, &thread0); thread0.td_kstack = kstack; thread0.td_kstack_pages = KSTACK_PAGES; - thread0.td_pcb = (struct pcb *)td_kstack_top(&thread0) - 1; + thread0.td_pcb = &pcb0; thread0.td_pcb->pcb_fpflags = 0; thread0.td_frame = &proc0_tf; pcpup->pc_curpcb = thread0.td_pcb; diff --git a/sys/riscv/riscv/vm_machdep.c b/sys/riscv/riscv/vm_machdep.c index 1810fe88283c..e538921c9f60 100644 --- a/sys/riscv/riscv/vm_machdep.c +++ b/sys/riscv/riscv/vm_machdep.c @@ -32,8 +32,8 @@ * SUCH DAMAGE. */ -#include #include +#include #include #include #include @@ -58,23 +58,23 @@ #define TP_OFFSET 16 /* sizeof(struct tcb) */ #endif +static uma_zone_t pcb_zone; + void cpu_thread_new_kstack(struct thread *td) { - td->td_pcb = (struct pcb *)td_kstack_top(td) - 1; - /* * td->td_frame + TF_SIZE will be the saved kernel stack pointer whilst * in userspace, so keep it aligned so it's also aligned when we * subtract TF_SIZE in the trap handler (and here for the initial stack * pointer). This also keeps the struct kernframe just afterwards - * aligned no matter what's in it or struct pcb. + * aligned no matter what's in it. * * NB: TF_SIZE not sizeof(struct trapframe) as we need the rounded * value to match the trap handler. */ td->td_frame = (struct trapframe *)(STACKALIGN( - (char *)td->td_pcb - sizeof(struct kernframe)) - TF_SIZE); + td_kstack_top(td) - sizeof(struct kernframe)) - TF_SIZE); } /* @@ -227,11 +227,13 @@ cpu_thread_exit(struct thread *td) void cpu_thread_alloc(struct thread *td) { + td->td_pcb = uma_zalloc(pcb_zone, M_WAITOK); } void cpu_thread_free(struct thread *td) { + uma_zfree(pcb_zone, td->td_pcb); } void @@ -285,3 +287,11 @@ cpu_sync_core(void) { fence_i(); } + +static void +pcbinit(void *dummy __unused) +{ + pcb_zone = uma_zcreate("pcb", sizeof(struct pcb), NULL, NULL, NULL, + NULL, UMA_ALIGNOF(struct pcb), 0); +} +SYSINIT(pcbinit, SI_SUB_INTRINSIC, SI_ORDER_ANY, pcbinit, NULL);