git: e180d4c124b5 - stable/13 - arm64: Ensure that thread0's PCB flags are initialized

From: Mark Johnston <>
Date: Tue, 11 Apr 2023 14:10:35 UTC
The branch stable/13 has been updated by markj:


commit e180d4c124b51b7f5958ff64b180a1e2cabf7fb7
Author:     Mark Johnston <>
AuthorDate: 2023-03-31 13:50:34 +0000
Commit:     Mark Johnston <>
CommitDate: 2023-04-11 14:09:45 +0000

    arm64: Ensure that thread0's PCB flags are initialized
    On arm64, the PCB is stored at the top of the thread stack.  For thread0
    this comes from the static "initstack" region, which is placed in the
    .init_pagetable section, which is not part of the BSS and thus doesn't
    get zeroed by locore.  (See the comment in ldscript.arm64.)  It is thus
    possible for the pcb_flags field to be uninitialized, which can result
    in PCB_SINGLE_STEP being set.
    Fix this by simply initializing the field.  A separate commit will move
    initstack out of the .init_pagetable section, since it has no reason to
    be there, but it is preferable to explicitly initialize PCB fields
    anyway.  In particular, regular kernel stacks are not zeroed upon
    allocation, so we should be consistent here.
    Reviewed by:    andrew
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Sponsored by:   Juniper Networks
    Differential Revision:
    (cherry picked from commit a54370f4abb6bc4e3ef25da97adb3262bacb5a4b)
 sys/arm64/arm64/machdep.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sys/arm64/arm64/machdep.c b/sys/arm64/arm64/machdep.c
index 68fcf0257232..adc627f4b085 100644
--- a/sys/arm64/arm64/machdep.c
+++ b/sys/arm64/arm64/machdep.c
@@ -371,6 +371,7 @@ init_proc0(vm_offset_t kstack)
 	thread0.td_pcb = (struct pcb *)(thread0.td_kstack +
 	    thread0.td_kstack_pages * PAGE_SIZE) - 1;
+	thread0.td_pcb->pcb_flags = 0;
 	thread0.td_pcb->pcb_fpflags = 0;
 	thread0.td_pcb->pcb_fpusaved = &thread0.td_pcb->pcb_fpustate;
 	thread0.td_pcb->pcb_vfpcpu = UINT_MAX;