From nobody Thu Oct 22 10:31:38 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 4j9Mrq3FYfz6wjTZ for ; Thu, 22 Oct 2026 10:31:39 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4j9Mrp2mzXz4G49 for ; Thu, 22 Oct 2026 10:31:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1792665098; 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=cf0SkRVCPsw0+WyKiN2b1XXI5MrI0dlNNFt3RAU9eCA=; b=UFlIcksj7IDRkK9Xt8FdpVdDYKTM7wuumljmSpa+M4GO3g3IjYi4q57/85U42+QWq141ED jC65Z1AmdnLsgPLDNP/XKXrCoAXZn6zIj/HTpyVzLWd+pYmdT1SzyShKFDw0k5rkzxS+o8 GhW9SQBb0pbnJUDY96kgoojYSkR0CR4rHXyRsZndtUJXX8ndb/IzMRPcioFldEEJC2p7V0 yzWFf9vw6AgTjI8am/gGYacNqlq0TYrjX1bAY0pmEbCz5MEB5TAZA9lORb4/9LiS4BAo07 hq7LvHh0nEb8ENolDDy54xT7zSNSsv97oqN0bFHDIjx/oqxHlYzwCX69142V0w== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1792665098; b=ZwNJQpbg5B5Xm9Os2hgPg/MXiNtSQnGOjgPo577Zt7+ChNkZy9kqVNK0m1G4WsDuFPvayT 0GejyB+19T4Xpsls1b73k7kZheQr5WioFISFGtcRuZfNpzat+jfXRzkhBWMS4rPVJZ/M44 qq0+x/f7+soZionwBmHZ52+9G4gQFvDL4jWK7ZhGWPz+kBpBGju79XDJe4VtBzsV8noZM1 HY40NUr4F4oU7wElxprUrFvRZKl9F5SswATbGr1eP14ztH+RDS6YVwB17l6kj9MF0G/YRJ HYUmRCGs5liTjP3aDLBQiWtYmiazy5HGXjkROo4MNe7osqb4LSYJtqdGhllPTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1792665098; 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=cf0SkRVCPsw0+WyKiN2b1XXI5MrI0dlNNFt3RAU9eCA=; b=UVFmKxTH/PNNbBj+xUj6GXL/Bb8aT40ptMizL6lyrCr/p6xJTEluIPHRruUKmhOyP8RFxu Vx9e0ajhyQPRul5sxEksoErSNvA8nUDan3JDSYnvFEfS+XoTvXJtkoyHRcAMG6LfbjU5iw vX/7uoe28cYbOD1bxSzqJTehlnOJYdb9bp+DfbXDEvXVfIahj5vOOk56D+vIP3nSq+imqb h3aGpNqI+k97Mq+v1UHGPxU11v+r62jsZa6QeUv4EVrOAWX/jk4omOb2qLOpwzGQY2YbV4 BQxHVn/vnAiyN9b5KBP+jdtRXcAdDcFheWgMr3BtJIoldbhnK3s9VqnCeMdxIA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4j9Mrp1vhRzcxH for ; Thu, 22 Oct 2026 10:31:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 38e71 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 22 Oct 2026 10:31:38 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Piotr Kubaj Subject: git: 268e7c2ff7a0 - stable/15 - powerpc64: give each CPU its own KDB trap stack List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches of the src repository 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: pkubaj X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 268e7c2ff7a0485c07a2b3b6dce2c186f25799ce Auto-Submitted: auto-generated Date: Thu, 22 Oct 2026 10:31:38 +0000 Message-Id: <6ad9e60a.38e71.492637b8@gitrepo.freebsd.org> The branch stable/15 has been updated by pkubaj: URL: https://cgit.FreeBSD.org/src/commit/?id=268e7c2ff7a0485c07a2b3b6dce2c186f25799ce commit 268e7c2ff7a0485c07a2b3b6dce2c186f25799ce Author: Piotr Kubaj AuthorDate: 2026-10-15 14:27:59 +0000 Commit: Piotr Kubaj CommitDate: 2026-10-22 08:01:19 +0000 powerpc64: give each CPU its own KDB trap stack Kernel mode program, trace, breakpoint and machine check exceptions go through dbtrap, which saves the registers on trapstk and, if KDB doesn't want the trap, restores them from there and continues with the normal trap handler. There was just one trapstk for all CPUs, so when two of them trapped at the same time they overwrote each other's frame and one of them carried on with the other's registers. DTrace fbt probes are these traps, so a probe on a function that runs on several CPUs at once took the kernel down within seconds. Keep the stack in the pcpu instead. The boot CPU gets a static one, since it's set up before malloc works, the others allocate theirs in cpu_pcpu_init() like the Book-E critical interrupt stack. Approved by: jhibbits MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D60362 (cherry picked from commit eaaf838e33042ed3f282a5cdf8e1260e78d4989b) --- sys/powerpc/aim/aim_machdep.c | 27 +++++++++++++++++++++++++++ sys/powerpc/aim/locore64.S | 7 ------- sys/powerpc/aim/trap_subr64.S | 7 +++---- sys/powerpc/include/pcpu.h | 3 ++- sys/powerpc/powerpc/genassym.c | 1 + 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/sys/powerpc/aim/aim_machdep.c b/sys/powerpc/aim/aim_machdep.c index 814c679ff47e..eb815d0a8603 100644 --- a/sys/powerpc/aim/aim_machdep.c +++ b/sys/powerpc/aim/aim_machdep.c @@ -529,6 +529,20 @@ kdb_cpu_set_singlestep(void) kdb_frame->srr1 |= PSL_SE; } +#if defined(__powerpc64__) && defined(KDB) +/* Stack used by the KDB trap handler (dbtrap) on each CPU. */ +#define AIM_DBSTACK_SIZE 8192 + +/* + * Stack for the KDB trap handler on the boot CPU. It is static because the + * boot CPU is initialised long before malloc works; APs reach cpu_pcpu_init() + * at SI_SUB_CPU and allocate theirs. Sizing a MAXCPU array would reserve + * megabytes for CPUs that do not exist. + */ +static char aim_boot_dbstack[AIM_DBSTACK_SIZE] __aligned(16); +static bool aim_boot_dbstack_used; +#endif + /* * Initialise a struct pcpu. */ @@ -536,8 +550,21 @@ void cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t sz) { #ifdef __powerpc64__ +#ifdef KDB + char *dbstack; +#endif + /* Copy the SLB contents from the current CPU */ memcpy(pcpu->pc_aim.slb, PCPU_GET(aim.slb), sizeof(pcpu->pc_aim.slb)); + +#ifdef KDB + if (!aim_boot_dbstack_used) { + aim_boot_dbstack_used = true; + dbstack = aim_boot_dbstack; + } else + dbstack = malloc(AIM_DBSTACK_SIZE, M_DEVBUF, M_WAITOK); + pcpu->pc_aim.dbstack = dbstack + AIM_DBSTACK_SIZE; +#endif #endif } diff --git a/sys/powerpc/aim/locore64.S b/sys/powerpc/aim/locore64.S index 9e49b605b8b4..de6bfe6f6b08 100644 --- a/sys/powerpc/aim/locore64.S +++ b/sys/powerpc/aim/locore64.S @@ -62,13 +62,6 @@ GLOBAL(tmpstk) TOC_ENTRY(tmpstk) TOC_ENTRY(can_wakeup) -#ifdef KDB -#define TRAPSTKSZ 8192 /* 8k trap stack */ -GLOBAL(trapstk) - .space TRAPSTKSZ -TOC_ENTRY(trapstk) -#endif - /* * Entry point for bootloaders that do not fully implement ELF and start diff --git a/sys/powerpc/aim/trap_subr64.S b/sys/powerpc/aim/trap_subr64.S index 56291337dd5b..db996d26bfa4 100644 --- a/sys/powerpc/aim/trap_subr64.S +++ b/sys/powerpc/aim/trap_subr64.S @@ -920,10 +920,9 @@ dbtrap: andi. %r1,%r1,0xff00 mtsprg3 %r1 - GET_TOCBASE(%r1) /* get new SP */ - addis %r1,%r1,TOC_REF(trapstk)@ha - ld %r1,TOC_REF(trapstk)@l(%r1) - addi %r1,%r1,(TRAPSTKSZ-48) + GET_CPUINFO(%r1) /* this CPU's trap stack */ + ld %r1,PC_AIM_DBSTACK(%r1) + addi %r1,%r1,-48 FRAME_SETUP(PC_DBSAVE) /* Call C trap code: */ diff --git a/sys/powerpc/include/pcpu.h b/sys/powerpc/include/pcpu.h index 21636310218c..1e60a78bb204 100644 --- a/sys/powerpc/include/pcpu.h +++ b/sys/powerpc/include/pcpu.h @@ -68,7 +68,8 @@ struct pvo_entry; struct pvo_entry *qmap_pvo; \ struct mtx qmap_lock; \ uint64_t opal_hmi_flags; \ - char __pad[1337]; + void *dbstack; /* KDB trap stack top */ \ + char __pad[1329]; #ifdef __powerpc64__ #define PCPU_MD_AIM_FIELDS PCPU_MD_AIM64_FIELDS diff --git a/sys/powerpc/powerpc/genassym.c b/sys/powerpc/powerpc/genassym.c index bc39e086bfa0..8fdeb6cf07e1 100644 --- a/sys/powerpc/powerpc/genassym.c +++ b/sys/powerpc/powerpc/genassym.c @@ -112,6 +112,7 @@ ASSYM(PC_KERNSLB, offsetof(struct pcpu, pc_aim.slb)); ASSYM(PC_USERSLB, offsetof(struct pcpu, pc_aim.userslb)); ASSYM(PC_SLBSAVE, offsetof(struct pcpu, pc_aim.slbsave)); ASSYM(PC_SLBSTACK, offsetof(struct pcpu, pc_aim.slbstack)); +ASSYM(PC_AIM_DBSTACK, offsetof(struct pcpu, pc_aim.dbstack)); ASSYM(USER_SLB_SLOT, USER_SLB_SLOT); ASSYM(USER_SLB_SLBE, USER_SLB_SLBE); ASSYM(SEGMENT_MASK, SEGMENT_MASK);