From nobody Tue Jul 05 17:10:24 2022 X-Original-To: dev-commits-src-all@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 A15661D15AC5; Tue, 5 Jul 2022 17:10:24 +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 4Lcq1X3hMCz4llF; Tue, 5 Jul 2022 17:10:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657041024; 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=pYYBRWaSH/tYqsFSdhMVl+bbyvtioXRVHwOJAuoB3/A=; b=FnbW5d15K0QIZe9K7/3iiHuZk/OPpuSV5vj1wJJfoUStCr8W0xiuGO9DocVdVw6oCaS2yF GwKknq01u196FsxwPYDvXEAKjx3rK0Mr7qiMnTxoddUdgKo0OkQGLVo868pyicrCxw6vNK Bfrm1h6R+IItTJehn4eKbJDZJRt7YXvMc7zrsqrtjmPcJUnUi+FzkPudjapZfmPYed+/Kv RTmZ4bD/IfVj04RXOnMsOYBnyE2uSvO4m9FAgYwRS3oy9QrUWd8KZujYwXMLnjrLPssFn+ Xgcmsfuagfxxp2tT8kKNRPkPaJaArG+3JGeRyNLHD24api+sZ9F8sNyLgxPRkA== 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 5D3FE174B; Tue, 5 Jul 2022 17:10:24 +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 265HAOBh042185; Tue, 5 Jul 2022 17:10:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 265HAOgv042184; Tue, 5 Jul 2022 17:10:24 GMT (envelope-from git) Date: Tue, 5 Jul 2022 17:10:24 GMT Message-Id: <202207051710.265HAOgv042184@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 1e8f338d7f22 - stable/13 - hwpmc: consistently validate PMC class in allocation method List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 1e8f338d7f227fc9e1cace1280fe89ab11bfc33b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657041024; 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=pYYBRWaSH/tYqsFSdhMVl+bbyvtioXRVHwOJAuoB3/A=; b=WNGAAmoCGrbm8JZHTSClNxMTAXkepVvTt2Bf3Ndu2/yqbwcR7MEunY16ac1ku0CLC9UKgr DxCU3Q4B5Gs0fgsmaivC4J0D93cnMQL5i9EdnhWox/HYFABzgauc1+lS91C2iRrG0FF7Ad 1GY3QzfLwfMZuKl47T0mO8p9aXADMKO72e+sXzY9pZHl85T6fUK6CF1dUVJ6bvjdcwAZR1 4QsxTljSdhv4kJoj/7vXuYiYHX8BDEESfyfIo9Zhv+/pOLxbzCn4hgHlySlGCIGzGcUOl/ SKhBNocrqtu+bYxlxjoihbUzt+NGbF1xHgcPTyqx8Ec9TpWYsTR46Q5rIsUugw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657041024; a=rsa-sha256; cv=none; b=ntz1kC0QAIDMzjJcCY8jSLWOB4VM3FsMfxWktltA/mZyMHbYHR+xtURU/mQzo6vHoQ6B/T r3egJ8V9CFgJwWnXXolMNdI92y2mTd2sSTyxIu4ZOPM2VWrApcVN5zt41v/pWisoSORy5V YdFJ+/RXjKe0TruIla9j8HFxEzWLW9goOskaba/mVsSemPxRtEjaamf51KveLbidH3Y6ET /xBhw9UUAEuKvJGpzO9L+oC7KafqWPHmaKBdZXLStVbjv1GTKO21VKVc3Ylh17LEgSTQU+ BHp6beT+U2tfeab29IkbQWVNbOLUIjfMX6SaYpL0fWfijcqD+f6piGoHvLe2+Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=1e8f338d7f227fc9e1cace1280fe89ab11bfc33b commit 1e8f338d7f227fc9e1cace1280fe89ab11bfc33b Author: Mitchell Horne AuthorDate: 2021-08-30 17:02:23 +0000 Commit: Alexander Motin CommitDate: 2022-07-05 16:38:52 +0000 hwpmc: consistently validate PMC class in allocation method It is always a good idea. In one case, attempting to allocate N+1 PMCs from a class with N hardware counters would incorrectly attempt to allocate from the next class in the list. Without this validation, this can lead to all kinds of strange behaviour. Since powerpc_allocate_pmc() is used by both the mpc7xxx and ppc970 classes, add a new global to track which is active (it will never be both). Reviewed by: luporl, ray MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D31387 (cherry picked from commit 315cd55dba61416495a847f0eed6e522421e2347) --- sys/dev/hwpmc/hwpmc_core.c | 3 +++ sys/dev/hwpmc/hwpmc_e500.c | 3 +++ sys/dev/hwpmc/hwpmc_mpc7xxx.c | 1 + sys/dev/hwpmc/hwpmc_powerpc.c | 4 ++++ sys/dev/hwpmc/hwpmc_powerpc.h | 1 + sys/dev/hwpmc/hwpmc_ppc970.c | 1 + sys/dev/hwpmc/hwpmc_uncore.c | 3 +++ 7 files changed, 16 insertions(+) diff --git a/sys/dev/hwpmc/hwpmc_core.c b/sys/dev/hwpmc/hwpmc_core.c index 692d7fcd52d9..c9a040f44ffd 100644 --- a/sys/dev/hwpmc/hwpmc_core.c +++ b/sys/dev/hwpmc/hwpmc_core.c @@ -744,6 +744,9 @@ iap_allocate_pmc(int cpu, int ri, struct pmc *pm, KASSERT(ri >= 0 && ri < core_iap_npmc, ("[core,%d] illegal row-index value %d", __LINE__, ri)); + if (a->pm_class != PMC_CLASS_IAP) + return (EINVAL); + /* check requested capabilities */ caps = a->pm_caps; if ((IAP_PMC_CAPS & caps) != caps) diff --git a/sys/dev/hwpmc/hwpmc_e500.c b/sys/dev/hwpmc/hwpmc_e500.c index 72c0868f08b5..b82bada95fe3 100644 --- a/sys/dev/hwpmc/hwpmc_e500.c +++ b/sys/dev/hwpmc/hwpmc_e500.c @@ -376,6 +376,9 @@ e500_allocate_pmc(int cpu, int ri, struct pmc *pm, KASSERT(ri >= 0 && ri < E500_MAX_PMCS, ("[powerpc,%d] illegal row index %d", __LINE__, ri)); + if (a->pm_class != PMC_CLASS_E500) + return (EINVAL); + caps = a->pm_caps; pe = a->pm_ev; diff --git a/sys/dev/hwpmc/hwpmc_mpc7xxx.c b/sys/dev/hwpmc/hwpmc_mpc7xxx.c index 987480e89efd..c62c0791af01 100644 --- a/sys/dev/hwpmc/hwpmc_mpc7xxx.c +++ b/sys/dev/hwpmc/hwpmc_mpc7xxx.c @@ -471,6 +471,7 @@ pmc_mpc7xxx_initialize(struct pmc_mdep *pmc_mdep) ppc_event_first = PMC_EV_PPC7450_FIRST; ppc_event_last = PMC_EV_PPC7450_LAST; ppc_max_pmcs = MPC7XXX_MAX_PMCS; + ppc_class = pcd->pcd_class; powerpc_set_pmc = mpc7xxx_set_pmc; powerpc_pmcn_read = mpc7xxx_pmcn_read; diff --git a/sys/dev/hwpmc/hwpmc_powerpc.c b/sys/dev/hwpmc/hwpmc_powerpc.c index 537e263d4c15..aa18d2659d7d 100644 --- a/sys/dev/hwpmc/hwpmc_powerpc.c +++ b/sys/dev/hwpmc/hwpmc_powerpc.c @@ -59,6 +59,7 @@ size_t ppc_event_codes_size; int ppc_event_first; int ppc_event_last; int ppc_max_pmcs; +enum pmc_class ppc_class; void (*powerpc_set_pmc)(int cpu, int ri, int config); pmc_value_t (*powerpc_pmcn_read)(unsigned int pmc); @@ -209,6 +210,9 @@ powerpc_allocate_pmc(int cpu, int ri, struct pmc *pm, KASSERT(ri >= 0 && ri < ppc_max_pmcs, ("[powerpc,%d] illegal row index %d", __LINE__, ri)); + if (a->pm_class != ppc_class) + return (EINVAL); + caps = a->pm_caps; pe = a->pm_ev; diff --git a/sys/dev/hwpmc/hwpmc_powerpc.h b/sys/dev/hwpmc/hwpmc_powerpc.h index 551f59b60528..25b041327b84 100644 --- a/sys/dev/hwpmc/hwpmc_powerpc.h +++ b/sys/dev/hwpmc/hwpmc_powerpc.h @@ -82,6 +82,7 @@ extern size_t ppc_event_codes_size; extern int ppc_event_first; extern int ppc_event_last; extern int ppc_max_pmcs; +extern enum pmc_class ppc_class; extern void (*powerpc_set_pmc)(int cpu, int ri, int config); extern pmc_value_t (*powerpc_pmcn_read)(unsigned int pmc); diff --git a/sys/dev/hwpmc/hwpmc_ppc970.c b/sys/dev/hwpmc/hwpmc_ppc970.c index 39dc4efb290a..3e92c4dc6aa2 100644 --- a/sys/dev/hwpmc/hwpmc_ppc970.c +++ b/sys/dev/hwpmc/hwpmc_ppc970.c @@ -380,6 +380,7 @@ pmc_ppc970_initialize(struct pmc_mdep *pmc_mdep) ppc_event_first = PMC_EV_PPC970_FIRST; ppc_event_last = PMC_EV_PPC970_LAST; ppc_max_pmcs = PPC970_MAX_PMCS; + ppc_class = pcd->pcd_class; powerpc_set_pmc = ppc970_set_pmc; powerpc_pmcn_read = powerpc_pmcn_read_default; diff --git a/sys/dev/hwpmc/hwpmc_uncore.c b/sys/dev/hwpmc/hwpmc_uncore.c index f87b36616d18..85ef0f441b5c 100644 --- a/sys/dev/hwpmc/hwpmc_uncore.c +++ b/sys/dev/hwpmc/hwpmc_uncore.c @@ -526,6 +526,9 @@ ucp_allocate_pmc(int cpu, int ri, struct pmc *pm, KASSERT(ri >= 0 && ri < uncore_ucp_npmc, ("[uncore,%d] illegal row-index value %d", __LINE__, ri)); + if (a->pm_class != PMC_CLASS_UCP) + return (EINVAL); + /* check requested capabilities */ caps = a->pm_caps; if ((UCP_PMC_CAPS & caps) != caps)