From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385817; b=1cfR5uz9tom8nzU4RUlTgZy+7jMgt4VZiqrQRzxjiaMcyKKbyRX9TIA5Huc3yfQZ2wkE SANkdLZnCl6g94JR3tWbhUJU1lUqIEqiEr8YclKrvfWvIsuXxM6AQsccCbG61DkgyGrKw pIrCnsk4QUeDURxAVrpO/RW7exorozWthZ7aX25u5+pC/XqY31TfeJ/FV2uDXEDZqVYcU 8F2jXux/fzdaIPBy2Z4GsJ3czAXOPhF8A4GbTgF47wpm+tp137KkNvLSbToBzRb+3+hSx iVE99msUyeHMXWH2hSJsDiFro4k3TArKrTHS0JovEuO2Zf07GD+VjkgRJmIalTWhBOg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385817; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=SyiQtHOSOD6dqKgiPdHAnwz93zXWX4jSSwl2KbjS2SQ=; b=gXPyLKTk7MkFDsoJB19hbeSksJzuy/jhCUaBjZhcm7X6ycHCcHR/q7zJxM3p1Z3gdRTb +1L+Ce47ULfeV042K/nL6/3L7eTkO83xPVFFBqr3lYe0zmg6uUrLttpKQ17kS3sVfCOIk WtXnciycWjFrDJNtBWVOt3SzsrH/9DyMSnvpD7hmRK8SYV5DB4wKK+58VptJs8HJgxsQa h2l+CHON7IC/e+EeJQJvslfj9TzVf8phNswOpAA0nfgnEtQC9qxVAScO/9bhihjNkDA/h 3FGJIN7JuoPWifqNP1OEEaWDII+g1nJaNFbVXVYKll7evRnosXwhaXDw5a3SYLWAU9Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=O+NYVHo1; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28539606A330; Fri, 4 Dec 2026 12:03:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=O+NYVHo1 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E966B1F0092C; Fri, 4 Dec 2026 12:03:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385816; bh=SyiQtHOSOD6dqKgiPdHAnwz93zXWX4jSSwl2KbjS2SQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=O+NYVHo19aepmYyfEFQlFeti7g5aB2U9q/CknHwP69wV//BexnpF4QL35iiIgJDXY 9pWGH3txwL27OykgRpFinklhN7U0j0ih5p9IdmHvIrB5UHrp4NWLKOxDRsiZBGZVUV 6dKspARurhHh5sCZ8ezEKol8in/CBrowMiVYJ6UE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sandipan Das , "Peter Zijlstra (Intel)" Subject: [PATCH 6.6 0703/1167] perf/x86/amd/uncore: Avoid PMU registration if counters are unavailable Date: Fri, 4 Dec 2026 19:02:10 +0900 Message-ID: <20261204100720.381043220@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sandipan Das commit f997e208b6c96858a2f6c0855debfbdb9b52f131 upstream. X86_FEATURE_PERFCTR_NB and X86_FEATURE_PERFCTR_LLC are derived from CPUID leaf 0x80000001 ECX bits 24 and 28 respectively and denote the availability of DF and L3 counters. When these bits are not set, the corresponding PMUs have no counters and hence, should not be registered. Fixes: 07888daa056e ("perf/x86/amd/uncore: Move discovery and registration") Signed-off-by: Sandipan Das Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20240626074404.1044230-1-sandipan.das@amd.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/events/amd/uncore.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) --- a/arch/x86/events/amd/uncore.c +++ b/arch/x86/events/amd/uncore.c @@ -634,17 +634,20 @@ int amd_uncore_df_ctx_init(struct amd_un { struct attribute **df_attr = amd_uncore_df_format_attr; struct amd_uncore_pmu *pmu; + int num_counters; /* Run just once */ if (uncore->init_done) return amd_uncore_ctx_init(uncore, cpu); + num_counters = amd_uncore_ctx_num_pmcs(uncore, cpu); + if (!num_counters) + goto done; + /* No grouping, single instance for a system */ uncore->pmus = kzalloc(sizeof(*uncore->pmus), GFP_KERNEL); - if (!uncore->pmus) { - uncore->num_pmus = 0; + if (!uncore->pmus) goto done; - } /* * For Family 17h and above, the Northbridge counters are repurposed @@ -654,7 +657,7 @@ int amd_uncore_df_ctx_init(struct amd_un pmu = &uncore->pmus[0]; strscpy(pmu->name, boot_cpu_data.x86 >= 0x17 ? "amd_df" : "amd_nb", sizeof(pmu->name)); - pmu->num_counters = amd_uncore_ctx_num_pmcs(uncore, cpu); + pmu->num_counters = num_counters; pmu->msr_base = MSR_F15H_NB_PERF_CTL; pmu->rdpmc_base = RDPMC_BASE_NB; @@ -763,17 +766,20 @@ int amd_uncore_l3_ctx_init(struct amd_un { struct attribute **l3_attr = amd_uncore_l3_format_attr; struct amd_uncore_pmu *pmu; + int num_counters; /* Run just once */ if (uncore->init_done) return amd_uncore_ctx_init(uncore, cpu); + num_counters = amd_uncore_ctx_num_pmcs(uncore, cpu); + if (!num_counters) + goto done; + /* No grouping, single instance for a system */ uncore->pmus = kzalloc(sizeof(*uncore->pmus), GFP_KERNEL); - if (!uncore->pmus) { - uncore->num_pmus = 0; + if (!uncore->pmus) goto done; - } /* * For Family 17h and above, L3 cache counters are available instead @@ -783,7 +789,7 @@ int amd_uncore_l3_ctx_init(struct amd_un pmu = &uncore->pmus[0]; strscpy(pmu->name, boot_cpu_data.x86 >= 0x17 ? "amd_l3" : "amd_l2", sizeof(pmu->name)); - pmu->num_counters = amd_uncore_ctx_num_pmcs(uncore, cpu); + pmu->num_counters = num_counters; pmu->msr_base = MSR_F16H_L2I_PERF_CTL; pmu->rdpmc_base = RDPMC_BASE_LLC;