From nobody Fri Jan 20 03:23:42 2023 X-Original-To: dev-commits-src-branches@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 4NylFq15TGz30vnX; Fri, 20 Jan 2023 03:23:43 +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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NylFp6TNqz3ns8; Fri, 20 Jan 2023 03:23:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674185022; 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=/2YeHGQMdrj8Br8+dcaw8EkLvcrZpCMiXazZBlXx0cs=; b=giBb9ikHynHvu5LcwVBLvFP6E73os3WDGdDC8IEIq5g1gPTbpoBjeNhzEXlwP6mcS9p0w4 xwC+WGUmHsxuZB8F2A9j3fMGy8Ou623SGjFdNwIpoRZEnOhAU+Zxsltugn0qxwLGyTwsu7 3Mq4IzlZHIuuGnViaeJP/K8oLL/IOpFdIVS5GeUEaO0camyIRS8fTHzNszCq2Ys9erq7MZ P2lHoRByRmzYhg5xSL4tAOB71MoV1KeSG0E3L7LeATJP7pVdUho+BGYwobMsZgafWKXhaI MFDc906yBml8sRAu6jiogEbl16HywHPadcHetzEpJosuk1HvLUshU8SDXrlL9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674185022; 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=/2YeHGQMdrj8Br8+dcaw8EkLvcrZpCMiXazZBlXx0cs=; b=ag0+e5i2qm1mwHDUi5EJmL3yL7fFKK27W3japfsPk/3xt1d8ibC52h7MKPnZZUJYi2ewdO 0J2JJqNr7uifdVVbCBsxS2fbere8EFi1LunOJrots/c63AD34aeBhU8t8KhwNKaJHh+ba/ B1dR/yjlRoM4Lbqkllm3aUDQwLd5epDfNpP3TwHkwKNtvbP3KWDQidLHGdS6RrZUGX72oK fvqhauWInvRUjCTJYIRt0/3eOYMQ3icS4MZNIlQ4VW/6YszpJ52wXpsHgmheTNyPCbmaoW wmNiFyiLUaDz5LVqXbUdC9U8EGrfekznc8CJrLtk/cthfNpm4H0U3e1E3IIhqQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674185022; a=rsa-sha256; cv=none; b=Duk2um72oQMisYXeVXEsM0wLxFNdM8xoYlslYvatrm9oPIPRE2SPKKrVfw+mKkUwKW/v70 /hiYhJy4d+Bf+fDiHawGAxWY72rkxLiZ4vEhBCc1ZLr2fKsRoUHIyzfkmE/nUXYJ63b4W3 9D1AHhFUD05s2kjUYDODYG/GDQQBr/M8ZiEafgTr/IIPmx967I/ph8uXSQNEikQGbM/YGu qgR9np9VhSpmnKQ+MVkalZZom2XvL1utxM5zpsBPI0R5N+CpjHH8CGj69BEwM2BjXieTHG WhY/2C3p5crkLew1Kold/rc6voAFHKnILyoqwaAJWzQVRuxyka3Hd4Oc6Ob3Qw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NylFp5W1SzG9L; Fri, 20 Jan 2023 03:23:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30K3NgYT042534; Fri, 20 Jan 2023 03:23:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30K3NgHW042533; Fri, 20 Jan 2023 03:23:42 GMT (envelope-from git) Date: Fri, 20 Jan 2023 03:23:42 GMT Message-Id: <202301200323.30K3NgHW042533@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: a0cfea8c38d6 - stable/13 - Add a thread debugging flag TDB_BOUNDARY List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: a0cfea8c38d64bddd114804507e5f5a05892b2ca Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=a0cfea8c38d64bddd114804507e5f5a05892b2ca commit a0cfea8c38d64bddd114804507e5f5a05892b2ca Author: Konstantin Belousov AuthorDate: 2022-12-01 00:29:35 +0000 Commit: Konstantin Belousov CommitDate: 2023-01-20 03:20:40 +0000 Add a thread debugging flag TDB_BOUNDARY Tested by: pho (cherry picked from commit f0592b3c8dd8e172f0e7165c11371108d4d8838d) --- sys/kern/subr_syscall.c | 11 ++++++++--- sys/kern/subr_trap.c | 5 ++++- sys/sys/proc.h | 3 ++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/sys/kern/subr_syscall.c b/sys/kern/subr_syscall.c index 8507c5393c01..a61003ec7203 100644 --- a/sys/kern/subr_syscall.c +++ b/sys/kern/subr_syscall.c @@ -73,6 +73,7 @@ syscallenter(struct thread *td) traced = (p->p_flag & P_TRACED) != 0; if (__predict_false(traced || td->td_dbgflags & TDB_USERWR)) { PROC_LOCK(p); + MPASS((td->td_dbgflags & TDB_BOUNDARY) == 0); td->td_dbgflags &= ~TDB_USERWR; if (traced) td->td_dbgflags |= TDB_SCE; @@ -201,7 +202,7 @@ syscallenter(struct thread *td) td->td_retval[1]); if (__predict_false(traced)) { PROC_LOCK(p); - td->td_dbgflags &= ~TDB_SCE; + td->td_dbgflags &= ~(TDB_SCE | TDB_BOUNDARY); PROC_UNLOCK(p); } (p->p_sysent->sv_set_syscall_retval)(td, error); @@ -281,9 +282,13 @@ syscallret(struct thread *td) */ if (traced && ((td->td_dbgflags & (TDB_FORK | TDB_EXEC)) != 0 || - (p->p_ptevents & PTRACE_SCX) != 0)) + (p->p_ptevents & PTRACE_SCX) != 0)) { + MPASS((td->td_dbgflags & TDB_BOUNDARY) == 0); + td->td_dbgflags |= TDB_BOUNDARY; ptracestop(td, SIGTRAP, NULL); - td->td_dbgflags &= ~(TDB_SCX | TDB_EXEC | TDB_FORK); + } + td->td_dbgflags &= ~(TDB_SCX | TDB_EXEC | TDB_FORK | + TDB_BOUNDARY); PROC_UNLOCK(p); } diff --git a/sys/kern/subr_trap.c b/sys/kern/subr_trap.c index c2c27a4d40cb..be5041fe516f 100644 --- a/sys/kern/subr_trap.c +++ b/sys/kern/subr_trap.c @@ -214,7 +214,7 @@ ast(struct trapframe *framep) { struct thread *td; struct proc *p; - int flags, sig; + int flags, old_boundary, sig; bool resched_sigs; td = curthread; @@ -330,12 +330,15 @@ ast(struct trapframe *framep) !SIGISEMPTY(p->p_siglist)) { sigfastblock_fetch(td); PROC_LOCK(p); + old_boundary = ~TDB_BOUNDARY | (td->td_dbgflags & TDB_BOUNDARY); + td->td_dbgflags |= TDB_BOUNDARY; mtx_lock(&p->p_sigacts->ps_mtx); while ((sig = cursig(td)) != 0) { KASSERT(sig >= 0, ("sig %d", sig)); postsig(sig); } mtx_unlock(&p->p_sigacts->ps_mtx); + td->td_dbgflags &= old_boundary; PROC_UNLOCK(p); resched_sigs = true; } else { diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 861f81232927..4ba7522ab5f2 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -487,7 +487,8 @@ do { \ #define TDB_FSTP 0x00001000 /* The thread is PT_ATTACH leader */ #define TDB_STEP 0x00002000 /* (x86) PSL_T set for PT_STEP */ #define TDB_SSWITCH 0x00004000 /* Suspended in ptracestop */ -#define TDB_COREDUMPREQ 0x00008000 /* Coredump request */ +#define TDB_BOUNDARY 0x00008000 /* ptracestop() at boundary */ +#define TDB_COREDUMPREQ 0x00010000 /* Coredump request */ /* * "Private" flags kept in td_pflags: