From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out28-4.mail.aliyun.com (out28-4.mail.aliyun.com [115.124.28.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F7F53C660C for ; Thu, 4 Jun 2026 07:02:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.28.4 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556567; cv=none; b=J4RosrUcz67OtSTH+BHElnfDCvwvVXblc5aJE5uEkamta/sNM82elN0BR8mvOXrOyZJzPB2ZuTIuROVLcNT1tE1eVD3oqAz3nkD96LCA/vZkER5udN2w6RXL97SeJzXoL54Ts0FQ6uYL+7yCtTqL1BM/tv8g7ul57SEdzXBTESA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780556567; c=relaxed/simple; bh=9JRusIlLHrJIJK03XvHCpmT2T00LxEBZEwu3JdQj/v4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ZZb/DhNjnn78Pmpx8TkQ4UlEVcdhBBg6vnrFUTEU28jJjmNksg7O+aHQYkTVnCsAYE3ubY4u6JLvRSyYkgRmxF8/FNgsDp6J7f4CoiJvrnEYldAHHSPT+dNUW7X6f61MNljiIJqAaXs5Z3eslNbDbNv9b8PPDdykZkIUergQcps= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=open-hieco.net; spf=pass smtp.mailfrom=open-hieco.net; arc=none smtp.client-ip=115.124.28.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=open-hieco.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=open-hieco.net X-Alimail-AntiSpam:AC=CONTINUE;BC=0.07437256|-1;CH=green;DM=|CONTINUE|false|;DS=CONTINUE|ham_regular_dialog|0.12145-0.000553094-0.877997;FP=5039907559379141810|0|0|0|0|-1|-1|-1;HT=maildocker-contentspam033037032089;MF=fuhao@open-hieco.net;NM=1;PH=DS;RN=7;RT=7;SR=0;TI=SMTPD_---.howBjPg_1780556237; Received: from 172.25.21.212(mailfrom:fuhao@open-hieco.net fp:SMTPD_---.howBjPg_1780556237 cluster:ay29) by smtp.aliyun-inc.com; Thu, 04 Jun 2026 14:57:18 +0800 Message-ID: Date: Thu, 4 Jun 2026 14:57:17 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/8] x86/cpu: Get LLC ID for Hygon family 18h model 4h To: Borislav Petkov Cc: tglx@kernel.org, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org References: <20260603031740.GMah-c1C26EhcgwV8C@fat_crate.local> Content-Language: en-US From: Fu Hao In-Reply-To: <20260603031740.GMah-c1C26EhcgwV8C@fat_crate.local> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 6/3/2026 11:17 AM, Borislav Petkov wrote: > On Tue, Apr 07, 2026 at 04:23:09PM +0800, Fu Hao wrote: >> Add support to calculate LLC ID from the number of threads sharing >> the cache for Hygon family 18h model 4h processor. >> >> Signed-off-by: Fu Hao >> --- >> arch/x86/kernel/cpu/cacheinfo.c | 22 +++++++++++++++++----- >> 1 file changed, 17 insertions(+), 5 deletions(-) > > If you're going to copy code at least try to share functionality which is > kinda begging to be a separate function. > > Ontop of yours and untested: > > diff --git a/arch/x86/kernel/cpu/cacheinfo.c b/arch/x86/kernel/cpu/cacheinfo.c > index 98862afc4e55..8e51226aee74 100644 > --- a/arch/x86/kernel/cpu/cacheinfo.c > +++ b/arch/x86/kernel/cpu/cacheinfo.c > @@ -305,10 +305,19 @@ static unsigned int get_cache_id(u32 apicid, const struct _cpuid4_info *id4) > return apicid >> index_msb; > } > > +/* LLC ID is calculated from the number of threads sharing the L3 cache. */ > +static void __calc_llc_id(struct cpuinfo_x86 *c) > +{ > + u32 llc_index = find_num_cache_leaves(c) - 1; > + struct _cpuid4_info id4 = {}; > + > + if (!amd_fill_cpuid4_info(llc_index, &id4)) > + c->topo.llc_id = get_cache_id(c->topo.apicid, &id4); > +} > + > /* > * AMD/Hygon CPUs may have multiple LLCs if L3 caches exist. > */ > - > void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u16 die_id) > { > if (!cpuid_amd_hygon_has_l3_cache()) > @@ -324,15 +333,7 @@ void cacheinfo_amd_init_llc_id(struct cpuinfo_x86 *c, u16 die_id) > */ > c->topo.llc_id = c->topo.apicid >> 3; > } else { > - /* > - * Newer families: LLC ID is calculated from the number > - * of threads sharing the L3 cache. > - */ > - u32 llc_index = find_num_cache_leaves(c) - 1; > - struct _cpuid4_info id4 = {}; > - > - if (!amd_fill_cpuid4_info(llc_index, &id4)) > - c->topo.llc_id = get_cache_id(c->topo.apicid, &id4); > + __calc_llc_id(c); > } > } > > @@ -342,15 +343,7 @@ void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c) > return; > > if (c->x86_model >= 0x4) { > - /* > - * From model 4h: LLC ID is calculated from the number > - * of threads sharing the L3 cache. > - */ > - u32 llc_index = find_num_cache_leaves(c) - 1; > - struct _cpuid4_info id4 = {}; > - > - if (!amd_fill_cpuid4_info(llc_index, &id4)) > - c->topo.llc_id = get_cache_id(c->topo.apicid, &id4); > + __calc_llc_id(c); > } else { > /* > * The others are similar to AMD Family 17h up to 1F models: LLC is > Hi Boris, Thanks for your guidance. The goal here was to keep the changes minimal and consistent with the existing code flow. Since Hygon reports the same CPUID leaves as AMD, it made sense to just follow AMD's current implementation rather than introduce a separate path. For Hygon processors, the LLC ID comes from fixed bit positions regardless of whether SMT is enabled or not. Therefore, perhaps I could implement it as follows: @@ -341,11 +341,18 @@ void cacheinfo_hygon_init_llc_id(struct cpuinfo_x86 *c) if (!cpuid_amd_hygon_has_l3_cache()) return; - /* - * Hygons are similar to AMD Family 17h up to 1F models: LLC is - * at the core complex level. Core complex ID is ApicId[3]. - */ - c->topo.llc_id = c->topo.apicid >> 3; + switch (c->x86_model) { + case 0x6: + c->topo.llc_id = c->topo.apicid >> 4; + break; + case 0x7: + case 0x8: + c->topo.llc_id = c->topo.apicid >> 5; + break; + default: + c->topo.llc_id = c->topo.apicid >> 3; + break; + } } Thank you again for reviewing and offering your suggestions. -- Regards, Fu Hao