Skip to content

Commit

Permalink
abi: parse PlatformInfo form v3 report
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Meyer <katexochen0@gmail.com>
  • Loading branch information
katexochen committed Dec 16, 2024
1 parent ef2fcc0 commit d30defa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
16 changes: 13 additions & 3 deletions abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const (
policyDebugBit = 19
policySingleSocketBit = 20

maxPlatformInfoBit = 1
maxPlatformInfoBit = 4

signatureOffset = 0x2A0
ecdsaRSsize = 72 // From the ECDSA-P384-SHA384 format in SEV SNP API specification.
Expand Down Expand Up @@ -186,6 +186,13 @@ type SnpPlatformInfo struct {
// TSMEEnabled represents if the platform that produced the attestation report has transparent
// secure memory encryption (TSME) enabled.
TSMEEnabled bool
// ECCEnabled indicates that the platform is using error correcting codes for memory.
// Present when EccMemReporting feature bit is set.
ECCEnabled bool
// RAPLDisabled indicates that the RAPL is disabled.
RAPLDisabled bool
// CiphertextHidingDRAMEnabled indicates cypher text hiding is enabled for DRAM.
CiphertextHidingDRAMEnabled bool
}

// SnpPolicy represents the bitmask guest policy that governs the VM's behavior from launch.
Expand Down Expand Up @@ -244,8 +251,11 @@ func SnpPolicyToBytes(policy SnpPolicy) uint64 {
// unrecognized bits.
func ParseSnpPlatformInfo(platformInfo uint64) (SnpPlatformInfo, error) {
result := SnpPlatformInfo{
SMTEnabled: (platformInfo & (1 << 0)) != 0,
TSMEEnabled: (platformInfo & (1 << 1)) != 0,
SMTEnabled: (platformInfo & (1 << 0)) != 0,
TSMEEnabled: (platformInfo & (1 << 1)) != 0,
ECCEnabled: (platformInfo & (1 << 2)) != 0,
RAPLDisabled: (platformInfo & (1 << 3)) != 0,
CiphertextHidingDRAMEnabled: (platformInfo & (1 << 4)) != 0,
}
reserved := platformInfo & ^uint64((1<<(maxPlatformInfoBit+1))-1)
if reserved != 0 {
Expand Down
12 changes: 10 additions & 2 deletions abi/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,16 @@ func TestSnpPlatformInfo(t *testing.T) {
want: SnpPlatformInfo{TSMEEnabled: true, SMTEnabled: true},
},
{
input: 4,
wantErr: "unrecognized platform info bit(s): 0x4",
input: 21,
want: SnpPlatformInfo{
SMTEnabled: true,
ECCEnabled: true,
CiphertextHidingDRAMEnabled: true,
},
},
{
input: 32,
wantErr: "unrecognized platform info bit(s): 0x20",
},
}
for _, tc := range tests {
Expand Down

0 comments on commit d30defa

Please sign in to comment.