From nobody Thu Oct 22 10:40:56 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 4j9N3X4S9hz6wkb4 for ; Thu, 22 Oct 2026 10:40:56 +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 4j9N3X1gtgz4JBL for ; Thu, 22 Oct 2026 10:40:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1792665656; 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=v/sTQcSsJGl3rtPWaW/xPkWDKZvqhiYAphywqAqUzTY=; b=mrjZozMaeFkKvBSrMMSVhWwmwWBzpm7rpZw0Wf8AdThs2FmAcFmdWgWIIogxV0I5cyZYKz PGeU7a8+yUBSU0zMBt9CwRJ01nF68i6L61od0pKTStknKrC2rMmsEg0tYawXwYCdf/4jdQ LQ+6T93EpUK3Lq07zIsoruTeErq5yYFzuINsiZYH9zVyr3F/VqJ9vi2JLe9SEpK+ORS6wX s/Xb0MscRqUZUCVEw6pHtqypUEj03mMDEcynFT/sYt1zS9klmPfSAiTD6hGH/K9FCSdsYa 656d5BgZbVt8OXNsLlXSmbWaeTMu9H5TvXxSnhL8f5efvL7NUi0AnJ9adWySfQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1792665656; b=ybljM/TxS3Vn3jj+zdr91jiHTBnxEz/54r+mMNw5R8cwOqbl+T2jtVcEx2ets+fbSeOG91 +VNitZN6cEeiDZStfJcZLxIZ8OPdGzomHX1IGOsjno+D92NZVIqZUfwGaUPJR/0SCWInmH AEta45nFzpUjtyvq1DsQ0rQTaZ0OwboC62r4+dqK7HMdeCJJ1xGbYOUbXYYZXdck+3xeCV uf/JY8GroRNOBvxN1R2eaV0yg9paBm6//Gz4cdLEiEEMekH1U4dnf7bUi6H7jM+pnDg8Ne H3LTEVv3p8MEjYxOfVueDx6ZmNZFsKaMb6h6/UnXuxC/Imau4dvGUNIjHLuhqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1792665656; 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=v/sTQcSsJGl3rtPWaW/xPkWDKZvqhiYAphywqAqUzTY=; b=ttHXqwBI8DUSd73JsoC4GfeEUW+2XRZL4c5uqEvWr8Wpiv322Q+vnEkKktd8Vm2AVeqzdu dqZT7LiWqm8g4ZfYa6/KgSikPcgTPFHYdNDQYj/maPqYcxmJ9QFNX2wDaVVCMKuBHw2tpb 0FT7SWxaB5mM6zhhceb8ZpO+8LUSMv0rAN4ipitCa65TQJh6a9AnWdvZaBJ68tDlOCZEEr 2N0IA7yOao9Qm9DxrFp99yVloqwUEExYWgO7Myf/8AwJSC10vT6sOSi1H9QAE1GHY36s9S nuh2qv25mgxa5TOV72F0pu6lKm6Lth9gsAWsk+gk7dKhdpd2Q+1WEIMnj6/WAA== 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 4j9N3X0VFQzdTf for ; Thu, 22 Oct 2026 10:40:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3a451 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 22 Oct 2026 10:40:56 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Piotr Kubaj Subject: git: a283b70a66a2 - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: a283b70a66a2a09c9cd500860e80927323486a93 Auto-Submitted: auto-generated Date: Thu, 22 Oct 2026 10:40:56 +0000 Message-Id: <6ad9e838.3a451.73e6a3ff@gitrepo.freebsd.org> The branch stable/14 has been updated by pkubaj: URL: https://cgit.FreeBSD.org/src/commit/?id=a283b70a66a2a09c9cd500860e80927323486a93 commit a283b70a66a2a09c9cd500860e80927323486a93 Author: Piotr Kubaj AuthorDate: 2026-10-15 14:27:59 +0000 Commit: Piotr Kubaj CommitDate: 2026-10-22 10:40:37 +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) (cherry picked from commit 268e7c2ff7a0485c07a2b3b6dce2c186f25799ce) --- 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 0ede455155f9..0dce4b6e0b7c 100644 --- a/sys/powerpc/powerpc/genassym.c +++ b/sys/powerpc/powerpc/genassym.c @@ -114,6 +114,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);