From owner-svn-src-head@freebsd.org Tue Oct 29 17:19:37 2019 Return-Path: Delivered-To: svn-src-head@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 1D9F715DC38; Tue, 29 Oct 2019 17:19:37 +0000 (UTC) (envelope-from glebius@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) server-signature RSA-PSS (4096 bits) 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 472dcS752Qz3Kjc; Tue, 29 Oct 2019 17:19:36 +0000 (UTC) (envelope-from glebius@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 D28C225232; Tue, 29 Oct 2019 17:19:36 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x9THJatW006901; Tue, 29 Oct 2019 17:19:36 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x9THJaIf006900; Tue, 29 Oct 2019 17:19:36 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201910291719.x9THJaIf006900@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Tue, 29 Oct 2019 17:19:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r354147 - head/sys/sys X-SVN-Group: head X-SVN-Commit-Author: glebius X-SVN-Commit-Paths: head/sys/sys X-SVN-Commit-Revision: 354147 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Oct 2019 17:19:37 -0000 Author: glebius Date: Tue Oct 29 17:19:36 2019 New Revision: 354147 URL: https://svnweb.freebsd.org/changeset/base/354147 Log: Augment macros that manipulate td_no_sleeping with assertions to check underleak and overflow of the counter. Reviewed by: kib Modified: head/sys/sys/proc.h Modified: head/sys/sys/proc.h ============================================================================== --- head/sys/sys/proc.h Tue Oct 29 16:51:12 2019 (r354146) +++ head/sys/sys/proc.h Tue Oct 29 17:19:36 2019 (r354147) @@ -246,8 +246,7 @@ struct thread { u_char td_lend_user_pri; /* (t) Lend user pri. */ /* Cleared during fork1() */ -#define td_startzero td_epochnest - u_char td_epochnest; /* (k) Epoch nest counter. */ +#define td_startzero td_flags int td_flags; /* (t) TDF_* flags. */ int td_inhibitors; /* (t) Why can not run. */ int td_pflags; /* (k) Private thread (TDP_*) flags. */ @@ -299,7 +298,7 @@ struct thread { struct vm_map_entry *td_map_def_user; /* (k) Deferred entries. */ pid_t td_dbg_forked; /* (c) Child pid for debugger. */ u_int td_vp_reserv; /* (k) Count of reserved vnodes. */ - int td_no_sleeping; /* (k) Sleeping disabled count. */ + u_int td_no_sleeping; /* (k) Sleeping disabled count. */ void *td_su; /* (k) FFS SU private */ sbintime_t td_sleeptimo; /* (t) Sleep timeout. */ int td_rtcgen; /* (s) rtc_generation of abs. sleep */ @@ -948,9 +947,15 @@ extern pid_t pid_max; #define thread_safetoswapout(td) ((td)->td_flags & TDF_CANSWAP) /* Control whether or not it is safe for curthread to sleep. */ -#define THREAD_NO_SLEEPING() ((curthread)->td_no_sleeping++) +#define THREAD_NO_SLEEPING() do { \ + curthread->td_no_sleeping++; \ + MPASS(curthread->td_no_sleeping > 0); \ +} while (0) -#define THREAD_SLEEPING_OK() ((curthread)->td_no_sleeping--) +#define THREAD_SLEEPING_OK() do { \ + MPASS(curthread->td_no_sleeping > 0); \ + curthread->td_no_sleeping--; \ +} while (0) #define THREAD_CAN_SLEEP() ((curthread)->td_no_sleeping == 0)