From nobody Tue Sep 22 14:01:27 2026 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 4hq1wl6djQz6tjwP for ; Tue, 22 Sep 2026 14:01:27 +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 "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hq1wl5xNhz4XXG for ; Tue, 22 Sep 2026 14:01:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1790085687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=P3MHHxX5yf5b9SqyZbjD7NJG16luIFJl2OpEok78mdk=; b=FwY1U46MAtKR6KDvrQ1hKDZe6ObHSzxQDW+Nql6/vrmxyxjAin1D8d0hJmr8zcybe9y2Vf xiYnC15HqtQ3ihXjsl0HcRmsjnU+K5aIF6E0gOrlpQQfPbM8U24iz5+eY21iZReAcATGDx SLst6ajS920eR5m1mTmqvRPl7tHegx4H1qBdtoIXxte8bL+eM8DjXPvYhd0s/pZ7abu1m2 sQUXSqJ6pSLCDBKkfv6LAAUB1/2DgNw/b/ZRnzany9VxUd7Hzs9wBUF9vJ4Fd5WrN8DoPi 07vr8GGcNhEH/Z6sw3SXNUty39OgfY/49ff9MAanTASXdjmWWNgpjkFBGfmcKg== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1790085687; b=nYQv4BAX1NpFxXB1jtxONdMyuCabzGI3WVXJ0bUkh4ihXq+VsB7jQ1aaJeDp1pkanbFhLT raHyNWrm3tYzPXKfoAyX2Ia3gkNyTBw/3xr052cNd9H7oBiKNQbkALPxLzpcMuAqGyWYsV 5kc6i/x0DjqZ1gFQAa3y+3RH3PAcMuY3Bac3Cfl/KvWGvs0WOjXI8FvgaUrfM3s9eOndmL n5pGLvOrWDDjFLfZmlEBt9k6ccB4VCOLzvEIu6JbF0BvzKVHV5k/Fqy1PeWWII12TLgZ29 gdn9aZ7lLpDez1Pw5qj9VikvPixydNA/oezzhbj279ckr7LgSGCwQ4W+Uq35qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1790085687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=P3MHHxX5yf5b9SqyZbjD7NJG16luIFJl2OpEok78mdk=; b=MeezyOJNXDHtiTBydN8ixp+NVUZyk9tms9GfHgSmOmaBgPPQnPMDZl9W4CVGj2Ug+12Ps4 QDOKjgmYmWTC1ipitvwgayqBiduelw2WmtzpsUCu1CF7IwA9cTfbn1RxsMx7ANfsfFJNKX ycMm/TRW+3BNsAJ/K69hvdf+7xW5S85c6cpZbdeG+C0BkXIUJWHaNA3rX1hpx2qDbgKN46 pjjXRFD+OctZccfmKEperdOJJ4okc62gq0Flh2KdM3JDhsT0qw7jehgp20ZkGttqramEl8 mgRsXJZ08cF3yzWD5YOqGo1EkmWUyJTPq2WIOO1M+frS9bqlFmttL0kuHFEEsw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hq1wl4k3mz18Df for ; Tue, 22 Sep 2026 14:01:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 21fc6 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 22 Sep 2026 14:01:27 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Paulo Fragoso From: Mitchell Horne Subject: git: 6d9f435739e5 - main - hwpmc: fix leak of IBS per-CPU array on unload 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6d9f435739e5fb604f452d03ad7f2eb280bfc968 Auto-Submitted: auto-generated Date: Tue, 22 Sep 2026 14:01:27 +0000 Message-Id: <6ab28a37.21fc6.263d6012@gitrepo.freebsd.org> The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=6d9f435739e5fb604f452d03ad7f2eb280bfc968 commit 6d9f435739e5fb604f452d03ad7f2eb280bfc968 Author: Paulo Fragoso AuthorDate: 2026-09-22 14:00:31 +0000 Commit: Mitchell Horne CommitDate: 2026-09-22 14:01:24 +0000 hwpmc: fix leak of IBS per-CPU array on unload pmc_ibs_initialize() allocates the ibs_pcpu[] pointer array, and pmc_ibs_finalize() exists to free it, but pmc_ibs_finalize() is never called. Every hwpmc unload on a CPU with IBS therefore leaks one pmc_cpu_max()-sized pointer array. Call pmc_ibs_finalize() from pmc_amd_finalize(), alongside the RAPL, TSC and perf classes. IBS is only initialized on CPUs that support it, so make pmc_ibs_finalize() return early when ibs_pcpu is NULL, making it safe to call when the class was skipped at initialize time, as pmc_rapl_finalize() already is. Tested on an AMD Ryzen 5 5600X (Zen 3, 12 threads) with INVARIANTS. Before the change, each kldload/kldunload cycle leaked one 96-byte M_PMC allocation, and DTrace showed the ibs_pcpu[] allocation from pmc_ibs_initialize() as the only one never freed. After the change, 50 load/unload cycles leave M_PMC InUse and MemUse unchanged, and every allocation made at load is freed at unload. Reviewed by: mhorne Fixes: e51ef8ae490f ("hwpmc: Initial support for AMD IBS") Sponsored by: NLINK (https://nlink.com.br), Recife, Brazil Differential Revision: https://reviews.freebsd.org/D59881 --- sys/dev/hwpmc/hwpmc_amd.c | 2 ++ sys/dev/hwpmc/hwpmc_ibs.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/sys/dev/hwpmc/hwpmc_amd.c b/sys/dev/hwpmc/hwpmc_amd.c index 232c59aea3bf..77d4a4230e49 100644 --- a/sys/dev/hwpmc/hwpmc_amd.c +++ b/sys/dev/hwpmc/hwpmc_amd.c @@ -1270,6 +1270,8 @@ pmc_amd_finalize(struct pmc_mdep *md) pmc_perf_finalize(md); + pmc_ibs_finalize(md); + for (int i = 0; i < pmc_cpu_max(); i++) KASSERT(amd_pcpu[i] == NULL, ("[amd,%d] non-null pcpu cpu %d", __LINE__, i)); diff --git a/sys/dev/hwpmc/hwpmc_ibs.c b/sys/dev/hwpmc/hwpmc_ibs.c index ce9e038e5d0b..17c3495f6a79 100644 --- a/sys/dev/hwpmc/hwpmc_ibs.c +++ b/sys/dev/hwpmc/hwpmc_ibs.c @@ -918,6 +918,10 @@ pmc_ibs_finalize(struct pmc_mdep *md) { PMCDBG0(MDP, INI, 1, "ibs-finalize"); + /* Safe even if the IBS class was skipped at initialize time. */ + if (ibs_pcpu == NULL) + return; + for (int i = 0; i < pmc_cpu_max(); i++) KASSERT(ibs_pcpu[i] == NULL, ("[ibs,%d] non-null pcpu cpu %d", __LINE__, i));