From owner-svn-src-all@freebsd.org Mon Aug 24 18:57:33 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BEBF09C13DA; Mon, 24 Aug 2015 18:57:33 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 956DD17F; Mon, 24 Aug 2015 18:57:33 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t7OIvXEo078765; Mon, 24 Aug 2015 18:57:33 GMT (envelope-from bz@FreeBSD.org) Received: (from bz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t7OIvXu2078764; Mon, 24 Aug 2015 18:57:33 GMT (envelope-from bz@FreeBSD.org) Message-Id: <201508241857.t7OIvXu2078764@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bz set sender to bz@FreeBSD.org using -f From: "Bjoern A. Zeeb" Date: Mon, 24 Aug 2015 18:57:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r287115 - head/sys/dev/hwpmc X-SVN-Group: head 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.20 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: Mon, 24 Aug 2015 18:57:33 -0000 Author: bz Date: Mon Aug 24 18:57:32 2015 New Revision: 287115 URL: https://svnweb.freebsd.org/changeset/base/287115 Log: When forking a child process with PMC_F_DESCENDANTS set in pmc_attach() in the parent, we will inherit the pmcids but cannot execute any operations on them in the child. The reason for this is that pmc_find_pmc() only tries to find the current process on the owners hash list, but given the child does not own the attachment, we cannot find it. Thus, in case the initial lookup fails, try to find the pmc_process state affiliated with the child process, lookup the pmc from there using the row index, and get the owner process from that pmc. Then continue as normal and lookup the pmc context of the owner (process). This allows us to call, e.g., pmc_start() in the child process before we start the work there, but to collect the accumulated results later in the parent. Sponsored by: DARPA,AFRL Obtained from: L41 Tested by: rwatson, L41 MFC after: 4 weeks Reviewed by: gnn Differential Revision: https://reviews.freebsd.org/D2052 Modified: head/sys/dev/hwpmc/hwpmc_mod.c Modified: head/sys/dev/hwpmc/hwpmc_mod.c ============================================================================== --- head/sys/dev/hwpmc/hwpmc_mod.c Mon Aug 24 17:58:11 2015 (r287114) +++ head/sys/dev/hwpmc/hwpmc_mod.c Mon Aug 24 18:57:32 2015 (r287115) @@ -2538,13 +2538,35 @@ static int pmc_find_pmc(pmc_id_t pmcid, struct pmc **pmc) { - struct pmc *pm; + struct pmc *pm, *opm; struct pmc_owner *po; + struct pmc_process *pp; + KASSERT(PMC_ID_TO_ROWINDEX(pmcid) < md->pmd_npmc, + ("[pmc,%d] Illegal pmc index %d (max %d)", __LINE__, + PMC_ID_TO_ROWINDEX(pmcid), md->pmd_npmc)); PMCDBG1(PMC,FND,1, "find-pmc id=%d", pmcid); - if ((po = pmc_find_owner_descriptor(curthread->td_proc)) == NULL) - return ESRCH; + if ((po = pmc_find_owner_descriptor(curthread->td_proc)) == NULL) { + /* + * In case of PMC_F_DESCENDANTS child processes we will not find + * the current process in the owners hash list. Find the owner + * process first and from there lookup the po. + */ + if ((pp = pmc_find_process_descriptor(curthread->td_proc, + PMC_FLAG_NONE)) == NULL) { + return ESRCH; + } else { + opm = pp->pp_pmcs[PMC_ID_TO_ROWINDEX(pmcid)].pp_pmc; + if (opm == NULL) + return ESRCH; + if ((opm->pm_flags & (PMC_F_ATTACHED_TO_OWNER| + PMC_F_DESCENDANTS)) != (PMC_F_ATTACHED_TO_OWNER| + PMC_F_DESCENDANTS)) + return ESRCH; + po = opm->pm_owner; + } + } if ((pm = pmc_find_pmc_descriptor_in_process(po, pmcid)) == NULL) return EINVAL;