Skip to content

Commit ed83c12

Browse files
committed
fix: pkg/hwapi/msr_intel.go: adapt to changes in ReadMSR
ReadMSR returns uint64 instead of an array of uint64 since #16. Previously, we read first element of the array (corresponding to core 0), now since ReadMSR only reads of MSR of core 0, we can just work with the value it returns. Signed-off-by: Michal Gorlas <michal.gorlas@9elements.com>
1 parent 17d765c commit ed83c12

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

pkg/hwapi/msr_intel.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package hwapi
22

3-
//Model specific registers
3+
// Model specific registers
44
const (
55
msrSMBase int64 = 0x9e //nolint
66
msrMTRRCap int64 = 0xfe
@@ -18,11 +18,11 @@ type IA32Debug struct {
1818
PCHStrap bool
1919
}
2020

21-
//HasSMRR returns true if the CPU supports SMRR
21+
// HasSMRR returns true if the CPU supports SMRR
2222
func HasSMRR(h LowLevelHardwareInterfaces) (bool, error) {
2323
mtrrcap := h.ReadMSR(msrMTRRCap)
2424

25-
return (mtrrcap[0]>>11)&1 != 0, nil
25+
return (mtrrcap>>11)&1 != 0, nil
2626
}
2727

2828
// SMRR for the SMM code.
@@ -40,50 +40,50 @@ func GetSMRRInfo(h LowLevelHardwareInterfaces) (SMRR, error) {
4040

4141
smrrPhysmask := h.ReadMSR(msrSMRRPhysMask)
4242

43-
ret.Active = (smrrPhysmask[0]>>11)&1 != 0
44-
ret.PhysBase = (smrrPhysbase[0] >> 12) & 0xfffff
45-
ret.PhysMask = (smrrPhysmask[0] >> 12) & 0xfffff
43+
ret.Active = (smrrPhysmask>>11)&1 != 0
44+
ret.PhysBase = (smrrPhysbase >> 12) & 0xfffff
45+
ret.PhysMask = (smrrPhysmask >> 12) & 0xfffff
4646

4747
return ret, nil
4848
}
4949

50-
//IA32FeatureControlIsLocked returns true if the IA32_FEATURE_CONTROL msr is locked
50+
// IA32FeatureControlIsLocked returns true if the IA32_FEATURE_CONTROL msr is locked
5151
func IA32FeatureControlIsLocked(h LowLevelHardwareInterfaces) (bool, error) {
5252
featCtrl := h.ReadMSR(msrFeatureControl)
5353

54-
return featCtrl[0]&1 != 0, nil
54+
return featCtrl&1 != 0, nil
5555
}
5656

57-
//IA32PlatformID returns the IA32_PLATFORM_ID msr
57+
// IA32PlatformID returns the IA32_PLATFORM_ID msr
5858
func IA32PlatformID(h LowLevelHardwareInterfaces) (uint64, error) {
5959
pltID := h.ReadMSR(msrPlatformID)
6060

61-
return pltID[0], nil
61+
return pltID, nil
6262
}
6363

64-
//AllowsVMXInSMX returns true if VMX is allowed in SMX
64+
// AllowsVMXInSMX returns true if VMX is allowed in SMX
6565
func AllowsVMXInSMX(h LowLevelHardwareInterfaces) (bool, error) {
6666
featCtrl := h.ReadMSR(msrFeatureControl)
6767

6868
var mask uint64 = (1 << 1) & (1 << 5) & (1 << 6)
69-
return (mask & featCtrl[0]) == mask, nil
69+
return (mask & featCtrl) == mask, nil
7070
}
7171

72-
//TXTLeavesAreEnabled returns true if all TXT leaves are enabled
72+
// TXTLeavesAreEnabled returns true if all TXT leaves are enabled
7373
func TXTLeavesAreEnabled(h LowLevelHardwareInterfaces) (bool, error) {
7474
featCtrl := h.ReadMSR(msrFeatureControl)
7575

76-
txtBits := (featCtrl[0] >> 8) & 0x1ff
76+
txtBits := (featCtrl >> 8) & 0x1ff
7777
return (txtBits&0xff == 0xff) || (txtBits&0x100 == 0x100), nil
7878
}
7979

80-
//IA32DebugInterfaceEnabledOrLocked returns the enabled, locked and pchStrap state of IA32_DEBUG_INTERFACE msr
80+
// IA32DebugInterfaceEnabledOrLocked returns the enabled, locked and pchStrap state of IA32_DEBUG_INTERFACE msr
8181
func IA32DebugInterfaceEnabledOrLocked(h LowLevelHardwareInterfaces) (*IA32Debug, error) {
8282
var debugMSR IA32Debug
8383
debugInterfaceCtrl := h.ReadMSR(msrIA32DebugInterface)
8484

85-
debugMSR.Enabled = (debugInterfaceCtrl[0]>>0)&1 != 0
86-
debugMSR.Locked = (debugInterfaceCtrl[0]>>30)&1 != 0
87-
debugMSR.PCHStrap = (debugInterfaceCtrl[0]>>31)&1 != 0
85+
debugMSR.Enabled = (debugInterfaceCtrl>>0)&1 != 0
86+
debugMSR.Locked = (debugInterfaceCtrl>>30)&1 != 0
87+
debugMSR.PCHStrap = (debugInterfaceCtrl>>31)&1 != 0
8888
return &debugMSR, nil
8989
}

0 commit comments

Comments
 (0)