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=1796388519; b=gJWi8/Gqrr7DOuMQZToZO8Mf622N/FotGsdU32rB8FIbJkdX52czkgIEXTDuux2rHlIM MPrzhnHOkHSeQEOMaw4+4FHpkgjlUWlxJF4vRjs8bqrz5tNvggrU1rVezv6rTTKnHaKNA waV6ftg6/FPYV8PVcY/JieHYhVJIhcWCVvglDgZFfE9/S147kRcdM45FMjBlxdq3xOHuD YuRY7MA4Z7ngXwS1aq5ysoMfrInUKaBsNEwBoFUIndzjyacDvTHvU9x+mU5SJPq8ZZOjK fQzR4yvmlxsgQ0YtARBc/tbo+VAYQiyWL7/btk+/m+vkX2lJP1P17P2/MaTFy/5FGUw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388519; 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=9H9EzBYKlMvkgKiPkN3RJ1XCRX4Y8HwyJ5XuMkp02Mg=; b=l9F5xMqRFND3/BpQn3rdxUa2yZfrjubVx2u7VkVqbHZ+/tNUGxw5nnZk76tO2GiicHPg S/K6x5qTMdxYeEOjS3zdynbSISDrYN36q79VZEaq457njQsQHfPdijunYd6edbU5iX3Bk usDJPHx+GwctjHDSYRkb0Oq01bI67Rt3XZIVKs4ma7KNYIs1dHgSDiTidBAFx4PwI0BE5 tSa9EBKNIadAUuG8FrgR3mbYZ88lpkIYi8aj1gfFRfOhoFeirgy5uSxN5ocQ/YWlf+rft /oFLJ+BiyLwxbIN+JYUGGxBKpMIb1eaxzlZX5b3v1Bt73Fpw9jRmGoicTSnVoRUGvAg== 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=kh5DPOsf; 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 68000606A682; Fri, 4 Dec 2026 12:48:39 +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=kh5DPOsf Received: by smtp.kernel.org (Postfix) with ESMTPSA id D18411F00897; Fri, 4 Dec 2026 12:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388519; bh=9H9EzBYKlMvkgKiPkN3RJ1XCRX4Y8HwyJ5XuMkp02Mg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kh5DPOsfIGmO8dJB0oZqOhz3Zrg6Xt4lFXEUzja2V5uzaBWVW7y5fcNOmuZ3VRpEU JK4NlWPcP7FvaaYIU3k0Pcvu20AZgBqzFbBdRIafJoy3wAxGFe2OnyD3YRIWwv/NEA ypy7JHO2ZGqDYpFE5jSWnjElwuV80K9lOlbOxLUA= 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.1 0648/1059] perf/x86/amd/uncore: Avoid PMU registration if counters are unavailable Date: Fri, 4 Dec 2026 19:02:59 +0900 Message-ID: <20261204100700.850401537@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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;