From owner-svn-src-all@freebsd.org Sun Mar 17 20:30:28 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 96FB115494F0; Sun, 17 Mar 2019 20:30:28 +0000 (UTC) (envelope-from markj@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 3AA918F528; Sun, 17 Mar 2019 20:30:28 +0000 (UTC) (envelope-from markj@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 2AACCF113; Sun, 17 Mar 2019 20:30:28 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x2HKUS0K097150; Sun, 17 Mar 2019 20:30:28 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x2HKUREK097147; Sun, 17 Mar 2019 20:30:27 GMT (envelope-from markj@FreeBSD.org) Message-Id: <201903172030.x2HKUREK097147@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Sun, 17 Mar 2019 20:30:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r345247 - in stable/12/sys: cddl/contrib/opensolaris/uts/common/dtrace cddl/contrib/opensolaris/uts/intel/dtrace cddl/dev/dtrace modules/dtrace X-SVN-Group: stable-12 X-SVN-Commit-Author: markj X-SVN-Commit-Paths: in stable/12/sys: cddl/contrib/opensolaris/uts/common/dtrace cddl/contrib/opensolaris/uts/intel/dtrace cddl/dev/dtrace modules/dtrace X-SVN-Commit-Revision: 345247 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 3AA918F528 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; NEURAL_HAM_SHORT(-0.97)[-0.972,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 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: Sun, 17 Mar 2019 20:30:29 -0000 Author: markj Date: Sun Mar 17 20:30:27 2019 New Revision: 345247 URL: https://svnweb.freebsd.org/changeset/base/345247 Log: MFC r344450, r344452, r344453: Fix a tracepoint lookup race in fasttrap_pid_probe(). Modified: stable/12/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c stable/12/sys/cddl/contrib/opensolaris/uts/intel/dtrace/fasttrap_isa.c stable/12/sys/cddl/dev/dtrace/dtrace_cddl.h stable/12/sys/modules/dtrace/Makefile Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c ============================================================================== --- stable/12/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c Sun Mar 17 18:31:48 2019 (r345246) +++ stable/12/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c Sun Mar 17 20:30:27 2019 (r345247) @@ -1089,6 +1089,8 @@ fasttrap_tracepoint_disable(proc_t *p, fasttrap_probe_ ASSERT(p->p_proc_flag & P_PR_LOCK); #endif p->p_dtrace_count--; + + atomic_add_rel_64(&p->p_fasttrap_tp_gen, 1); } /* Modified: stable/12/sys/cddl/contrib/opensolaris/uts/intel/dtrace/fasttrap_isa.c ============================================================================== --- stable/12/sys/cddl/contrib/opensolaris/uts/intel/dtrace/fasttrap_isa.c Sun Mar 17 18:31:48 2019 (r345246) +++ stable/12/sys/cddl/contrib/opensolaris/uts/intel/dtrace/fasttrap_isa.c Sun Mar 17 20:30:27 2019 (r345247) @@ -967,6 +967,7 @@ fasttrap_pid_probe(struct trapframe *tf) struct reg reg, *rp; proc_t *p = curproc, *pp; struct rm_priotracker tracker; + uint64_t gen; uintptr_t pc; uintptr_t new_pc = 0; fasttrap_bucket_t *bucket; @@ -1026,8 +1027,22 @@ fasttrap_pid_probe(struct trapframe *tf) while (pp->p_vmspace == pp->p_pptr->p_vmspace) pp = pp->p_pptr; pid = pp->p_pid; + if (pp != p) { + PROC_LOCK(pp); + if ((pp->p_flag & P_WEXIT) != 0) { + /* + * This can happen if the child was created with + * rfork(2). Userspace tracing cannot work reliably in + * such a scenario, but we can at least try. + */ + PROC_UNLOCK(pp); + sx_sunlock(&proctree_lock); + return (-1); + } + _PHOLD_LITE(pp); + PROC_UNLOCK(pp); + } sx_sunlock(&proctree_lock); - pp = NULL; rm_rlock(&fasttrap_tp_lock, &tracker); #endif @@ -1051,11 +1066,32 @@ fasttrap_pid_probe(struct trapframe *tf) if (tp == NULL) { #ifdef illumos mutex_exit(pid_mtx); + return (-1); #else rm_runlock(&fasttrap_tp_lock, &tracker); + gen = atomic_load_acq_64(&pp->p_fasttrap_tp_gen); + if (pp != p) + PRELE(pp); + if (curthread->t_fasttrap_tp_gen != gen) { + /* + * At least one tracepoint associated with this PID has + * been removed from the table since #BP was raised. + * Speculate that we hit a tracepoint that has since + * been removed, and retry the instruction. + */ + curthread->t_fasttrap_tp_gen = gen; +#ifdef __amd64 + tf->tf_rip = pc; +#else + tf->tf_eip = pc; #endif + return (0); + } return (-1); +#endif } + if (pp != p) + PRELE(pp); /* * Set the program counter to the address of the traced instruction Modified: stable/12/sys/cddl/dev/dtrace/dtrace_cddl.h ============================================================================== --- stable/12/sys/cddl/dev/dtrace/dtrace_cddl.h Sun Mar 17 18:31:48 2019 (r345246) +++ stable/12/sys/cddl/dev/dtrace/dtrace_cddl.h Sun Mar 17 20:30:27 2019 (r345247) @@ -37,7 +37,7 @@ typedef struct kdtrace_proc { u_int64_t p_dtrace_count; /* Number of DTrace tracepoints */ void *p_dtrace_helpers; /* DTrace helpers, if any */ int p_dtrace_model; - + uint64_t p_fasttrap_tp_gen; /* Tracepoint hash table gen */ } kdtrace_proc_t; /* @@ -86,6 +86,7 @@ typedef struct kdtrace_thread { u_int64_t td_hrtime; /* Last time on cpu. */ void *td_dtrace_sscr; /* Saved scratch space location. */ void *td_systrace_args; /* syscall probe arguments. */ + uint64_t td_fasttrap_tp_gen; /* Tracepoint hash table gen. */ } kdtrace_thread_t; /* @@ -113,10 +114,12 @@ typedef struct kdtrace_thread { #define t_dtrace_regv td_dtrace->td_dtrace_regv #define t_dtrace_sscr td_dtrace->td_dtrace_sscr #define t_dtrace_systrace_args td_dtrace->td_systrace_args +#define t_fasttrap_tp_gen td_dtrace->td_fasttrap_tp_gen #define p_dtrace_helpers p_dtrace->p_dtrace_helpers #define p_dtrace_count p_dtrace->p_dtrace_count #define p_dtrace_probes p_dtrace->p_dtrace_probes #define p_model p_dtrace->p_dtrace_model +#define p_fasttrap_tp_gen p_dtrace->p_fasttrap_tp_gen #define DATAMODEL_NATIVE 0 #ifdef __amd64__ Modified: stable/12/sys/modules/dtrace/Makefile ============================================================================== --- stable/12/sys/modules/dtrace/Makefile Sun Mar 17 18:31:48 2019 (r345246) +++ stable/12/sys/modules/dtrace/Makefile Sun Mar 17 20:30:27 2019 (r345247) @@ -19,9 +19,6 @@ SUBDIR+= fasttrap fbt systrace_linux .if ${MACHINE_CPUARCH} == "amd64" SUBDIR+= systrace_linux32 .endif -.if ${MACHINE_CPUARCH} == "powerpc" -SUBDIR+= fbt fasttrap -.endif .if ${MACHINE_CPUARCH} == "amd64" || \ ${MACHINE_CPUARCH} == "aarch64" || \ ${MACHINE_ARCH} == "mips64" || \ @@ -31,7 +28,9 @@ SUBDIR+= systrace_freebsd32 .if ${MACHINE_CPUARCH} == "aarch64" || \ ${MACHINE_CPUARCH} == "arm" || \ ${MACHINE_CPUARCH} == "mips" || \ + ${MACHINE_CPUARCH} == "powerpc" || \ ${MACHINE_CPUARCH} == "riscv" SUBDIR+= fbt .endif + .include