From 7df4672a3597e3bbcf2e375fa3b798a4208094e5 Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Thu, 7 Apr 2022 16:17:18 -0700 Subject: [PATCH] cpuid: handle CPUID(0x80000006): L2 cache information Fixes: #7341 Signed-off-by: Andrei Vagin --- pkg/cpuid/cpuid_amd64_test.go | 17 +++++++++++++++++ pkg/cpuid/native_amd64.go | 26 +++++++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/pkg/cpuid/cpuid_amd64_test.go b/pkg/cpuid/cpuid_amd64_test.go index a5bf8ada3..29f8f2ef7 100644 --- a/pkg/cpuid/cpuid_amd64_test.go +++ b/pkg/cpuid/cpuid_amd64_test.go @@ -56,6 +56,23 @@ func TestHostFeatureSet(t *testing.T) { } } +func TestFixedExtendedState(t *testing.T) { + hostFeatures := HostFeatureSet() + fixedFeatures := hostFeatures.Fixed() + for i, allowed := range allowedBasicFunctions { + if !allowed { + continue + } + in := In{Eax: uint32(i) + uint32(extendedStart)} + h := hostFeatures.Query(in) + f := fixedFeatures.Query(in) + if h != f { + t.Errorf("native: %x fixed: %x", h, f) + } + } + +} + func TestHasFeature(t *testing.T) { if !justFPU.HasFeature(X86FeatureFPU) { t.Errorf("HasFeature failed, %q should contain %v", justFPU.FlagString(), X86FeatureFPU) diff --git a/pkg/cpuid/native_amd64.go b/pkg/cpuid/native_amd64.go index d6118a7ad..b0102feee 100644 --- a/pkg/cpuid/native_amd64.go +++ b/pkg/cpuid/native_amd64.go @@ -62,10 +62,15 @@ const xSaveInfoNumLeaves = 64 // Maximum number of xSaveInfo leaves. // The "extended" functions. const ( - extendedStart cpuidFunction = 0x80000000 - extendedFunctionInfo cpuidFunction = extendedStart + 0 // Returns highest available extended function in eax. - extendedFeatures = extendedStart + 1 // Returns some extended feature bits in edx and ecx. - addressSizes = extendedStart + 8 // Physical and virtual address sizes. + extendedStart cpuidFunction = 0x80000000 + extendedFunctionInfo cpuidFunction = extendedStart + 0 // Returns highest available extended function in eax. + extendedFeatures = extendedStart + 1 // Returns some extended feature bits in edx and ecx. + processorBrandString2 = extendedStart + 2 // Processor Name String Identifier. + processorBrandString3 = extendedStart + 3 // Processor Name String Identifier. + processorBrandString4 = extendedStart + 4 // Processor Name String Identifier. + l1CacheAndTLBInfo = extendedStart + 5 // Returns L2 cache information. + l2CacheInfo = extendedStart + 6 // Returns L2 cache information. + addressSizes = extendedStart + 8 // Physical and virtual address sizes. ) var allowedBasicFunctions = [...]bool{ @@ -78,9 +83,14 @@ var allowedBasicFunctions = [...]bool{ } var allowedExtendedFunctions = [...]bool{ - extendedFunctionInfo - extendedStart: true, - extendedFeatures - extendedStart: true, - addressSizes - extendedStart: true, + extendedFunctionInfo - extendedStart: true, + extendedFeatures - extendedStart: true, + addressSizes - extendedStart: true, + processorBrandString2 - extendedStart: true, + processorBrandString3 - extendedStart: true, + processorBrandString4 - extendedStart: true, + l1CacheAndTLBInfo - extendedStart: true, + l2CacheInfo - extendedStart: true, } // Function executes a CPUID function. @@ -108,6 +118,8 @@ func (i *In) normalize() { switch cpuidFunction(i.Eax) { case vendorID, featureInfo, intelCacheDescriptors, extendedFunctionInfo, extendedFeatures: i.Ecx = 0 // Ignore. + case processorBrandString2, processorBrandString3, processorBrandString4, l1CacheAndTLBInfo, l2CacheInfo: + i.Ecx = 0 // Ignore. case intelDeterministicCacheParams, extendedFeatureInfo: // Preserve i.Ecx. }