[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v2 04/23] x86: Don't use potentially incorrect CPUID values for topology information


  • To: Simon Gaiser <simon@xxxxxxxxxxxxxxxxxxxxxx>, Anthony Liguori <aliguori@xxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Mon, 7 Aug 2023 11:10:10 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=knZR3xja8bAEDmIUgLm4qlqxCYSBqGV8z2tSXrBwD+4=; b=AVfC7KHPg45HXRsXOrAg5JxnqO3/v52Qq5rm5DVcDhC3fhCD1mqk4sL6MQV5sKRQ7lo9TpUW3wbsQDhwrVrKE54DHelI4JGH1u3KsBd5ACKOlUzSaGnrVDtd8s6/6J/QmB8MuziPPcurHYjBwr6GXTZl/abWrdhzkoCiggfzWuNf8DvUbPNZBzbHNYW5py4ejw8VnsbL6caq1NvyzxCd9ke92KSY0PlsTZGVbIjE4CeIhZwK2rMQQ3u3ZlUAh2ZfdzSat93kVcgV6u7B0QiE973PfezEfe7PPNOg9Cp1ZoW4pMw4N5FvZREqsqjpoDL3eQ+Ct5H5JF6VxZL8cX2+Rg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MB4ot9rplJORzk290+lPZRlU2uTz3tcGzPP3CNjkmeVQ0GzTFMynOlTiD2ULMHg6Ox9mXcJSjKCdSmuJLbnJKMCeFn0ELBPL8DwZ2Gl8e+VE6DPaIbcrgafDLYQP70BE7tnph/JWAAyQ39EqFaq1rMHEc2Y748WEUFJZGZP5h9Q7Fkty391ArGfduf8Zh+gr/7peHEPHS/DGCyoNxeAsIr3ygjkFvX21C/OMSkwHPc8hXrjC1Dv5KiEmLYI7Y9aYQuBKBtxSA1xpIPpygEIF7stzWdpxsPc0nAaIJ1ueNXPuSCLKYVbZv7SmyB7tKmtJLihSlsohfGZmXDzboLSA0g==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Wei Liu <wei.liu2@xxxxxxxxxx>, KarimAllah Ahmed <karahmed@xxxxxxxxx>, Jan H. Schönherr <jschoenh@xxxxxxxxx>, Matt Wilson <msw@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 07 Aug 2023 10:10:35 +0000
  • Ironport-data: A9a23:LCZko6i36lCfX/9xb4yTKfiAX1619hEKZh0ujC45NGQN5FlHY01je htvXmrUOP2JMGChLY1/YISwp0gE6MfWyddkQAI9/io0Fykb9cadCdqndUqhZCn6wu8v7q5Ex 55HNoSfdpBcolv0/ErF3m3J9CEkvU2wbuOgTrWCYmYpHlUMpB4J0XpLg/Q+jpNjne+3CgaMv cKai8DEMRqu1iUc3lg8sspvkzsx+qyr0N8klgZmP6sT7AeAzyJ94K83fsldEVOpGuG4IcbiL wrz5OnR1n/U+R4rFuSknt7TGqHdauePVeQmoiM+t5mK2nCulARrukoIHKN0hXNsoyeIh7hMJ OBl7vRcf+uL0prkw4zxWzEAe8130DYvFLXveRBTuuTLp6HKnueFL1yDwyjaMKVBktubD12i+ tREBQgARS6tp9mc74mhZrBjmuUiB/H0adZ3VnFIlVk1DN4AaLWaGuDmwIEd2z09wMdTAfzZe swVLyJ1awjNaAFOPVFRD48imOCvhT/0dDgwRFC9/PJrpTSMilEuluGybLI5efTTLSlRtm+eq njL4CLSBRYCOcbE4TGE7mitlqnEmiaTtIc6TeTpr6U32gHKroAVID4YRGOqrqWasGSdVt5PK Fcv/wlt6pFnoSRHSfG4BXVUukWspR8ZXNx4Eusk6RqMwK7Z/waYAGcfSjdLLtchsaceTDgr2 UKOhdLBDDl9tvueTnf13qeZq3a+NDYYKUcGZDQYVk0V7t/7uoYxgxnTCNF5H8adjdTvEDH1z jyipS03lbIVy8IGv4255lvHhD+qprDASwcn4QORUm/NxgZie6asYoW67l6d5vFFRK6cR0OEt WIJmOCf6v4PFpCHkCGRQOQLE6qt7vzDOzrZ6WODBLEk/jWpvnKmI4ZZ5WgnIF8za5lYPzj0f EXUpAVdoodJO2enZrN2ZIT3DNk2ya/nFpLuUfW8gsdyX6WdvTSvpElGDXN8FUi0+KTwucnT4 aumTPs=
  • Ironport-hdrordr: A9a23:5NijJKu0jQn+k777rUAKDa5w7skCM4Mji2hC6mlwRA09TyX4rb HaoB1/73SbtN9/YhEdcK+7SdW9qB/nlKKdgrNhTotKIjOW2ldARbsKheHfKlbbak7DH4BmpM Jdm6MXMqyOMbAT5/yX3OHSeexO/DFJmprEuc7ui05ICSVWQ+VY6QF9YzzrYHGfhmN9dOQE/F 733Ls2m9JkE05nH/hTfUN1O9TrlpnwjZf7ZhxDLwc/gTP+9A+A2frBCh2F2RVbeC9OxLpKyx m5ryXJop+7tu29yFv632vehq4m/+fJ+594HcmRjcpQDCvqhh3AXvUGZ5Sy+Aotpf2p6hIRsP SkmWZZA+1Dr0nJe32zo1/W1xL+3C0I43vvoGXo+kfLkIjCXTcnDMgEuo5DaBve7CMbzatB7J 4=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 07/08/2023 9:18 am, Simon Gaiser wrote:
> Anthony Liguori:
>> From: Jan H. Schönherr <jschoenh@xxxxxxxxx>
>>
>> Intel says for CPUID leaf 0Bh:
>>
>>   "Software must not use EBX[15:0] to enumerate processor
>>    topology of the system. This value in this field
>>    (EBX[15:0]) is only intended for display/diagnostic
>>    purposes. The actual number of logical processors
>>    available to BIOS/OS/Applications may be different from
>>    the value of EBX[15:0], depending on software and platform
>>    hardware configurations."
>>
>> And yet, we're using them to derive the number cores in a package
>> and the number of siblings in a core.
>>
>> Derive the number of siblings and cores from EAX instead, which is
>> intended for that.
>>
>> Signed-off-by: Jan H. Schönherr <jschoenh@xxxxxxxxx>
>> ---
>>  xen/arch/x86/cpu/common.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c
>> index e9588b3..22f392f 100644
>> --- a/xen/arch/x86/cpu/common.c
>> +++ b/xen/arch/x86/cpu/common.c
>> @@ -479,8 +479,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c)
>>      initial_apicid = edx;
>>  
>>      /* Populate HT related information from sub-leaf level 0 */
>> -    core_level_siblings = c->x86_num_siblings = LEVEL_MAX_SIBLINGS(ebx);
>>      core_plus_mask_width = ht_mask_width = BITS_SHIFT_NEXT_LEVEL(eax);
>> +    core_level_siblings = c->x86_num_siblings = 1 << ht_mask_width;
>>  
>>      sub_index = 1;
>>      do {
>> @@ -488,8 +488,8 @@ void detect_extended_topology(struct cpuinfo_x86 *c)
>>  
>>              /* Check for the Core type in the implemented sub leaves */
>>              if ( LEAFB_SUBTYPE(ecx) == CORE_TYPE ) {
>> -                    core_level_siblings = LEVEL_MAX_SIBLINGS(ebx);
>>                      core_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax);
>> +                    core_level_siblings = 1 << core_plus_mask_width;
>
> On the i5-1135G7 (4 cores with each 2 threads) I'm currently testing on
> I noticed that this changes leads to core_level_siblings == 16 and
> therefore x86_max_cores == 8. If read from ebx like before this change
> and what Linux is still doing [1] it reads core_level_siblings == 8 (as
> expected?).
>
> What's the expected semantic here? If it's to derive the actual number
> of siblings (and therefore cores) in a package as the commit message
> suggest, the new code can't work even ignoring the example from my test
> system. It will always produce powers of 2, so can't get it right on a
> system with, say, 6 cores.
>
> [1]: 
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/x86/kernel/cpu/topology.c?h=v6.4#n126

Topology is broken in many subtle ways, including bits Xen inherited
from Linux.

As it happens, Thomas is working on the Linux side right now, and it's
been quite an effort...

https://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git/log/?h=x86/topo-full

In some copious free time I'll be ste^W borrowing this.  It comes with a
negative diffstat too.

~Andrew



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.