From owner-svn-src-all@freebsd.org Wed Nov 11 08:48:44 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 161992E1A1D; Wed, 11 Nov 2020 08:48:44 +0000 (UTC) (envelope-from mjg@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CWJL409n4z4VXl; Wed, 11 Nov 2020 08:48:44 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id ED3F511CD3; Wed, 11 Nov 2020 08:48:43 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0AB8mhFP062128; Wed, 11 Nov 2020 08:48:43 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0AB8mhug062126; Wed, 11 Nov 2020 08:48:43 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <202011110848.0AB8mhug062126@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Wed, 11 Nov 2020 08:48:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367583 - in head/sys: kern sys X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: in head/sys: kern sys X-SVN-Commit-Revision: 367583 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Nov 2020 08:48:44 -0000 Author: mjg Date: Wed Nov 11 08:48:43 2020 New Revision: 367583 URL: https://svnweb.freebsd.org/changeset/base/367583 Log: thread: fix thread0 tid allocation Startup code hardcodes the value instead of allocating it. The first spawned thread would then be a duplicate. Pointy hat: mjg Modified: head/sys/kern/init_main.c head/sys/kern/kern_thread.c head/sys/sys/proc.h Modified: head/sys/kern/init_main.c ============================================================================== --- head/sys/kern/init_main.c Wed Nov 11 00:43:13 2020 (r367582) +++ head/sys/kern/init_main.c Wed Nov 11 08:48:43 2020 (r367583) @@ -496,8 +496,7 @@ proc0_init(void *dummy __unused) p->p_klist = knlist_alloc(&p->p_mtx); STAILQ_INIT(&p->p_ktr); p->p_nice = NZERO; - /* pid_max cannot be greater than PID_MAX */ - td->td_tid = PID_MAX + 1; + td->td_tid = THREAD0_TID; LIST_INSERT_HEAD(TIDHASH(td->td_tid), td, td_hash); td->td_state = TDS_RUNNING; td->td_pri_class = PRI_TIMESHARE; Modified: head/sys/kern/kern_thread.c ============================================================================== --- head/sys/kern/kern_thread.c Wed Nov 11 00:43:13 2020 (r367582) +++ head/sys/kern/kern_thread.c Wed Nov 11 08:48:43 2020 (r367583) @@ -354,6 +354,7 @@ extern int max_threads_per_proc; void threadinit(void) { + lwpid_t tid0; uint32_t flags; /* @@ -374,6 +375,9 @@ threadinit(void) mtx_init(&tid_lock, "TID lock", NULL, MTX_DEF); tid_bitmap = bit_alloc(maxthread, M_TIDHASH, M_WAITOK); + tid0 = tid_alloc(); + if (tid0 != THREAD0_TID) + panic("tid0 %d != %d\n", tid0, THREAD0_TID); flags = UMA_ZONE_NOFREE; #ifdef __aarch64__ Modified: head/sys/sys/proc.h ============================================================================== --- head/sys/sys/proc.h Wed Nov 11 00:43:13 2020 (r367582) +++ head/sys/sys/proc.h Wed Nov 11 08:48:43 2020 (r367583) @@ -855,6 +855,7 @@ MALLOC_DECLARE(M_SUBPROC); */ #define PID_MAX 99999 #define NO_PID 100000 +#define THREAD0_TID NO_PID extern pid_t pid_max; #define SESS_LEADER(p) ((p)->p_session->s_leader == (p))