NetBSD Problem Report #57839

From martin@duskware.de  Fri Jan 12 18:07:24 2024
Return-Path: <martin@duskware.de>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 1B5101A9238
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 12 Jan 2024 18:07:24 +0000 (UTC)
From: martin@NetBSD.org
Reply-To: martin@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: Reproducable VAX pmap bug
X-Send-Pr-Version: 3.95

>Number:         57839
>Category:       port-vax
>Synopsis:       Reproducable VAX pmap bug
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    port-vax-maintainer
>State:          feedback
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jan 12 18:10:00 +0000 2024
>Closed-Date:    
>Last-Modified:  Wed Nov 11 18:30:03 +0000 2026
>Originator:     Martin Husemann
>Release:        NetBSD 10.99.10
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD dead-to-the-world.duskware.de 10.99.10 NetBSD 10.99.10 (DEAD) #19: Wed Jan 10 15:59:25 CET 2024 martin@seven-days-to-the-wolves.aprisoft.de:/work/src/sys/arch/vax/compile/DEAD vax
Architecture: vax
Machine: vax
>Description:

Running the atf test suite crashes the kernel:

[ 2155.0184746] panic: pmap_destroy used pmap
[ 2155.0309698] cpu0: Begin traceback...
[ 2155.0447079] panic: pmap_destroy used pmap
[ 2155.0537111] Stack traceback : 
[ 2155.0611692]          Process is executing in user space.
[ 2155.0684572] cpu0: End traceback...
Stopped in pid 337.337 (t_lwp_create) at        netbsd:vpanic+0x179:    pushl   
$0
db> bt
panic: pmap_destroy used pmap
Stack traceback :
0x8b9b8d40: vpanic+0x179(0x802116e5,0x8b9b8dd8)
0x8b9b8d60: printf_nostamp+0x0(0x802116e5)
0x8b9b8d8c: pmap_kenter_pa+0x0(0x87687d40)
0x8b9b8ddc: uvmspace_free+0x73(0x867d2900)
0x8b9b8e04: uvm_proc_exit+0x53(0x85a09530)
0x8b9b8e28: exit1+0x15b(0x877a6ac0,0,0)
0x8b9b8ed8: sys_exit+0x31(0x877a6ac0,0x8b9b8f54,0x8b9b8f4c)
0x8b9b8f18: syscall+0x126(0x8b9b8fb4)


>How-To-Repeat:

cd /usr/tests/lib/libc/sys && atf-run t_lwp_create 


>Fix:
n/a

>Release-Note:

>Audit-Trail:
From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-vax/57839
Date: Thu, 5 Nov 2026 23:45:01 +0100

 --oNku53dHTcHtLiB4
 Content-Type: text/plain; charset=utf-8
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable

 Hi,

 first of all, this issue is still reproducible with an
 DIAGNOSTIC-enabled kernel (here in SIMH; needed to upsize the miniroot
 fs from 8m to 10m):

 [ 1398.1366770] panic: pmap_destroy used pmap
 [ 1398.1366770] cpu0: Begin traceback...
 [ 1398.1466792] Stack traceback:
 [ 1398.3567255] 0xa71e9d44: vpanic+0x17c(0x8039afcf,0xa71e9ddc)
 [ 1398.5867762] 0xa71e9d64: aprint_verbose+0x0(0x8039afcf)
 [ 1398.7968225] 0xa71e9d90: pmap_kenter_pa+0x0(0x9f525740)
 [ 1399.0168710] 0xa71e9de0: uvmspace_free+0x7b(0x9fea4d80)
 [ 1399.2069129] 0xa71e9e08: uvm_proc_exit+0x53(0x9f8ca640)
 [ 1399.2869305] 0xa71e9e2c: exit1+0x170(0x9f8ae880,0,0)
 [ 1399.3669481] 0xa71e9ed8: sys_exit+0x31(0x9f8ae880,0xa71e9f54,0xa71e9f4c)
 [ 1399.5169812] 0xa71e9f18: syscall+0xec(0xa71e9fb4)
 [ 1399.5169812] cpu0: End traceback...

 [ 1399.5169812] dump to dev 9,1 not possible

 HALT instruction, PC: 80013FFC (PUSHAB 8039B207)


 =2E..while on a non-DIAG  kernel, the test just passes.



 I think there's still a pm_pcbs referencing the pmap when it is fed to
 pmap_destroy, It's always linked in through cpu_lwp_fork(), and
 cleared through pmap_deactivate() called through mi_switch(). But that
 doesn't happen if the LWP never runs (eg. through error pathes.) The
 testcase (lwp_create_bad_lid_ptr) provokes such an error path.

   Right now, I'm building a new kernel that invokes pmap_deactivate()
 in cpu_lwp_free() IFF l !=3D curlwp.  That should be enough I hope...

   Martin, ISTR that you stated something like you'd like to run ATF
 more often on VAX, but you tend to have DIAGNOSTIC enabled. I really
 hope this catches it!

 MfG, JBG

 --=20

 --oNku53dHTcHtLiB4
 Content-Type: application/pgp-signature; name="signature.asc"

 -----BEGIN PGP SIGNATURE-----

 iF0EABECAB0WIQQlDTvPcScNjKREqWEdvV51g5nhuwUCau0G6QAKCRAdvV51g5nh
 u6gsAJ4vOkf+lTixb/sCvzFZcqdWdxayHgCdFZn421agAm00YQH9f16/NE8lW14=
 =hldp
 -----END PGP SIGNATURE-----

 --oNku53dHTcHtLiB4--

From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-vax/57839
Date: Sun, 8 Nov 2026 08:44:45 +0100

 --whbJPoPwx1YUiGt1
 Content-Type: text/plain; charset=utf-8
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable

 Hi!

 With the following patch applied, I can sucessfully run this test
 case:

 vax-template# cd /usr/tests/lib/libc/sys && atf-run t_lwp_create

 Content-Type: application/X-atf-tps; version=3D"3"

 info: atf.version, Automated Testing Framework 0.20 (atf-0.20)
 info: tests.root, /usr/tests/lib/libc/sys
 info: time.start, Sun Nov 8 07:32:08 UTC 2026
 info: uname.sysname, NetBSD
 info: uname.nodename, vax-template.classiccmp
 info: uname.release, 11.99.9
 info: uname.version, NetBSD 11.99.9 (GENERIC) #0: Wed Oct 28 09:49:53 UTC 2=
 026 mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/vax/compile/GENERIC
 info: uname.machine, vax
 info: env, ENV=3D/root/.shrc
 info: env, BLOCKSIZE=3D1k
 info: env, PWD=3D/usr/tests/lib/libc/sys
 info: env, MAIL=3D/var/mail/root
 info: env, HOME=3D/root
 info: env, PATH=3D/sbin:/usr/sbin:/bin:/usr/bin:/usr/pkg/sbin:/usr/pkg/bin:=
 /usr/games:/usr/X11R7/bin:/usr/local/sbin:/usr/local/bin
 info: env, HOST=3Dvax-template.classiccmp
 info: env, SSH_CONNECTION=3D10.234.0.1 54068 10.234.2.7 22
 info: env, SSH_TTY=3D/dev/pts/0
 info: env, TERM=3Dscreen5
 info: env, OLDPWD=3D/root
 info: env, USER=3Droot
 info: env, SSH_CLIENT=3D10.234.0.1 54068 22
 info: env, PKG_PATH=3Dhttp://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/vax/=
 10.0_2022Q4/All
 info: env, LOGNAME=3Droot
 info: env, SHELL=3D/bin/sh
 tps-count: 1
 tp-start: 1794123148.564015, t_lwp_create, 6
 tc-start: 1794123148.584015, lwp_create_bad_lid_ptr
 tc-end: 1794123150.504058, lwp_create_bad_lid_ptr, passed
 tc-start: 1794123150.574059, lwp_create_generic_fail_no_uc_cpu
 tc-end: 1794123151.524081, lwp_create_generic_fail_no_uc_cpu, passed
 tc-start: 1794123151.584082, lwp_create_vax_fail_psl_0
 tc-end: 1794123152.574104, lwp_create_vax_fail_psl_0, passed
 tc-start: 1794123152.644105, lwp_create_vax_fail_psl_1
 tc-end: 1794123153.624127, lwp_create_vax_fail_psl_1, passed
 tc-start: 1794123153.694129, lwp_create_vax_fail_psl_cm
 tc-end: 1794123154.504147, lwp_create_vax_fail_psl_cm, passed
 tc-start: 1794123154.594149, lwp_create_works
 tc-end: 1794123155.574171, lwp_create_works, passed
 tp-end: 1794123155.644172, t_lwp_create
 info: time.end, Sun Nov 8 07:32:39 UTC 2026
 vax-template#=20

 =2E..without crashing, that is.

 root@VPS2264-jenkins-node1:/var/cache/git/buildhelpers/patches [master] # c=
 at generic-netbsd--jbglaw-pr57839-enable-DIAGNOSTIC.patch generic-netbsd--j=
 bglaw-pr57839-lwp-free-pcb.patch=20
 diff --git a/distrib/vax/miniroot/Makefile.inc b/distrib/vax/miniroot/Makef=
 ile.inc
 index 37fbd138a3c1..f272794ee7e0 100644
 --- a/distrib/vax/miniroot/Makefile.inc
 +++ b/distrib/vax/miniroot/Makefile.inc
 @@ -1,6 +1,6 @@
  # $NetBSD: Makefile.inc,v 1.25 2017/01/24 18:04:05 christos Exp $
 =20
 -IMAGESIZE=3D     8m
 +IMAGESIZE=3D     10m
  MAKEFS_FLAGS+=3D -o density=3D3k
  IMAGEENDIAN=3D   le
  MAKEDEVTARGETS=3D        all ipty
 diff --git a/sys/arch/vax/conf/GENERIC b/sys/arch/vax/conf/GENERIC
 index b9955a0e5f0f..04a97e03fb72 100644
 --- a/sys/arch/vax/conf/GENERIC
 +++ b/sys/arch/vax/conf/GENERIC
 @@ -51,7 +51,7 @@ makeoptions   DEBUG=3D"-g"
  options        DDB
  options        DDB_HISTORY_SIZE=3D512    # enable history editing in DDB
  options        KTRACE
 -#options       DIAGNOSTIC
 +options        DIAGNOSTIC
  #options       DEBUG
  #options       PMAPDEBUG
  #options       TRAPDEBUG
 diff --git a/sys/arch/vax/vax/vm_machdep.c b/sys/arch/vax/vax/vm_machdep.c
 index fe138a16c2f4..5c2b9855f675 100644
 --- a/sys/arch/vax/vax/vm_machdep.c
 +++ b/sys/arch/vax/vax/vm_machdep.c
 @@ -175,8 +175,15 @@ void
  cpu_lwp_free(struct lwp *l, int proc)
  {
 =20
 -       (void)l;
         (void)proc;
 +
 +       /*
 +        * Unlink the PCB here, before the u-area holding it is freed. THis=
  is
 +        * only needed for LWPs than never ran (due to errors while creating
 +        * them) as in all other cases, mi_switch() will do the job.
 +        */
 +       if (l !=3D curlwp)
 +               pmap_deactivate(l);
  }
 =20
  void



 I've stored it as two patches: One enabling DIAGNOSTIC (and sizing up
 the miniroot fs as it wouldn't fit otherwise), the second part is the
 actual fix.


 MfG, JBG

 --=20

 --whbJPoPwx1YUiGt1
 Content-Type: application/pgp-signature; name="signature.asc"

 -----BEGIN PGP SIGNATURE-----

 iF0EABECAB0WIQQlDTvPcScNjKREqWEdvV51g5nhuwUCavAoagAKCRAdvV51g5nh
 uz/WAJ4pcg6QmKqdEzKqkKu73uCm1DEMvACbBXJAgJ+Y5FQqFbxf6n5sXfRz9Cw=
 =bBdj
 -----END PGP SIGNATURE-----

 --whbJPoPwx1YUiGt1--

From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-vax/57839
Date: Tue, 10 Nov 2026 10:55:38 +0100

 --negmOx2LioZftMgl
 Content-Type: text/plain; charset=utf-8
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable

 Hi!

 I believe the patch is correct and fixes the issue. (By now, it's also
 tested by me.) Who'd review it?

 Thanks,
   Jan-Benedict

 --=20

 --negmOx2LioZftMgl
 Content-Type: application/pgp-signature; name="signature.asc"

 -----BEGIN PGP SIGNATURE-----

 iF0EABECAB0WIQQlDTvPcScNjKREqWEdvV51g5nhuwUCavLqGAAKCRAdvV51g5nh
 u1gSAJ4m59DpzTOHcnkYsrTF8uVqUxTpfACghmjG4ObgxoBG4oEB4Ew0JwopUvw=
 =q/ER
 -----END PGP SIGNATURE-----

 --negmOx2LioZftMgl--

From: Kalvis Duckmanton <kalvisd@gmail.com>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: port-vax/57839
Date: Tue, 10 Nov 2026 23:22:51 +1100

 To recap:
 The ATF test /usr/tests/lib/libc/sys/t_lwp_create:lwp_create_bad_lid_ptr 
 invokes sys__lwp_create() with a bogus lwpid_t *.

 In sys__lwp_create(), the creation of the new LWP by do_lwp_create() 
 succeeds, but the subsequent copyout() of the LWP ID fails due to the 
 bogus pointer and the newly created LWP, having never run, is then 
 destroyed by lwp_exit().

 do_lwp_create() ends up calling vax/vm_machdep.c:cpu_lwp_fork(), which 
 in turn calls pmap_activate().  pmap_activate() does a few things -- it 
 stores values for the P0 and P1 base and length registers in the new 
 LWP's PCB and links that PCB into the list of PCBs using the pmap.  
 While pmap_activate() can also load the CPU's P0 and P1 registers, it 
 doesn't at this time because the new LWP is not the one currently active.

 Later, because the LWP never ran, the matching pmap_deactivate() is 
 never called and the reference in the pmap to the PCB remains, leading 
 to a panic when the pmap is destroyed.

 After investigation, the consensus is that the call to pmap_activate() 
 in cpu_lwp_fork() is not needed; pmap_activate() (and the matching 
 pmap_deactivate()) will be called later as the LWP is scheduled.

 However, one of the side-effects of pmap_activate() is still required -- 
 the values for the P0 and P1 registers in the new LWP's PCB need to be 
 initialised, and in particular the initial AST level needs to be set to 
 AST_PCB (no ASTs pending)

 cheers
 kalvis

From: "Kalvis Duckmanton" <kalvisd@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/57839 CVS commit: src/sys/arch/vax/vax
Date: Tue, 10 Nov 2026 12:34:23 +0000

 Module Name:	src
 Committed By:	kalvisd
 Date:		Tue Nov 10 12:34:23 UTC 2026

 Modified Files:
 	src/sys/arch/vax/vax: vm_machdep.c

 Log Message:
 vax/vm_machdep.c: avoid calling pmap_activate() from cpu_lwp_fork()

 In cpu_lwp_fork(), set initial values for the P0 and P1 base and
 length registers and AST level rather than calling pmap_activate() to
 do so.  pmap_activate() will be called later when the LWP runs.

 PR port-vax/57839


 To generate a diff of this commit:
 cvs rdiff -u -r1.119 -r1.120 src/sys/arch/vax/vax/vm_machdep.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->feedback
State-Changed-By: kalvisd@NetBSD.org
State-Changed-When: Tue, 10 Nov 2026 12:42:09 +0000
State-Changed-Why:
Committed fix


From: Jan-Benedict Glaw <jbglaw@lug-owl.de>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: port-vax/57839
Date: Wed, 11 Nov 2026 19:27:01 +0100

 --7WezKbWAZ44urU7c
 Content-Type: text/plain; charset=utf-8
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable

 Build a new release (-current) with your patch included (@kalvisd) and
 it works, too:

 vax-template# cd /usr/tests/lib/libc/sys && atf-run t_lwp_create
 Content-Type: application/X-atf-tps; version=3D"3"

 info: atf.version, Automated Testing Framework 0.20 (atf-0.20)
 info: tests.root, /usr/tests/lib/libc/sys
 info: time.start, Wed Nov 11 18:22:30 UTC 2026
 info: uname.sysname, NetBSD
 info: uname.nodename, vax-template.classiccmp
 info: uname.release, 11.99.9
 info: uname.version, NetBSD 11.99.9 (GENERIC) #0: Wed Oct 28 09:49:53 UTC 2=
 026 mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/vax/compile/GENERIC
 info: uname.machine, vax
 info: env, ENV=3D/root/.shrc
 info: env, BLOCKSIZE=3D1k
 info: env, PWD=3D/usr/tests/lib/libc/sys
 info: env, MAIL=3D/var/mail/root
 info: env, HOME=3D/root
 info: env, PATH=3D/sbin:/usr/sbin:/bin:/usr/bin:/usr/pkg/sbin:/usr/pkg/bin:=
 /usr/games:/usr/X11R7/bin:/usr/local/sbin:/usr/local/bin
 info: env, HOST=3Dvax-template.classiccmp
 info: env, SSH_CONNECTION=3D10.234.0.1 42918 10.234.2.12 22
 info: env, SSH_TTY=3D/dev/pts/0
 info: env, TERM=3Dscreen5
 info: env, OLDPWD=3D/root
 info: env, USER=3Droot
 info: env, SSH_CLIENT=3D10.234.0.1 42918 22
 info: env, PKG_PATH=3Dhttp://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/vax/=
 10.0_2022Q4/All
 info: env, LOGNAME=3Droot
 info: env, SHELL=3D/bin/sh
 tps-count: 1
 tp-start: 1794421371.512482, t_lwp_create, 6
 tc-start: 1794421371.542485, lwp_create_bad_lid_ptr
 tc-end: 1794421373.752723, lwp_create_bad_lid_ptr, passed
 tc-start: 1794421373.832731, lwp_create_generic_fail_no_uc_cpu
 tc-end: 1794421374.732828, lwp_create_generic_fail_no_uc_cpu, passed
 tc-start: 1794421374.842840, lwp_create_vax_fail_psl_0
 tc-end: 1794421375.802943, lwp_create_vax_fail_psl_0, passed
 tc-start: 1794421375.992964, lwp_create_vax_fail_psl_1
 tc-end: 1794421377.13073, lwp_create_vax_fail_psl_1, passed
 tc-start: 1794421377.83081, lwp_create_vax_fail_psl_cm
 tc-end: 1794421378.93189, lwp_create_vax_fail_psl_cm, passed
 tc-start: 1794421378.163197, lwp_create_works
 tc-end: 1794421378.983285, lwp_create_works, passed
 tp-end: 1794421379.63293, t_lwp_create
 info: time.end, Wed Nov 11 18:23:03 UTC 2026


 So I guess this ticket can now be either closed directly, or prepare
 pull-ups to 9 and 10 as this is a real kernel bug that any of the
 numerous VAX users could use to crash the system.
 --=20

 --7WezKbWAZ44urU7c
 Content-Type: application/pgp-signature; name="signature.asc"

 -----BEGIN PGP SIGNATURE-----

 iF0EABECAB0WIQQlDTvPcScNjKREqWEdvV51g5nhuwUCavSzcQAKCRAdvV51g5nh
 u8j7AKCER4/YDrIY8JmnUolXi333KplqCwCfZ5y8uWG+7clqxpXkR7pWPbo/aKM=
 =toBi
 -----END PGP SIGNATURE-----

 --7WezKbWAZ44urU7c--

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.