Skip to content

Commit 1021d87

Browse files
committed
Add guestFeatures as arg for public functions
This implements the changes from upstream: virtee/sev-snp-measure#32 Signed-off-by: Otto Bittner <[email protected]>
1 parent ebec3e0 commit 1021d87

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

.github/workflows/upstream-equivalence.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
6363
with:
6464
repository: edgelesssys/sev-snp-measure-go.git
65-
ref: main
65+
ref: ${{ github.ref_name }}
6666
path: sev-snp-measure-go
6767

6868
- name: Run sev-snp-measure

e2e/upstream_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ func TestCompatibility(t *testing.T) {
5353
ovmfHash, err := guest.OVMFHash(ovmfObj)
5454
require.NoError(err, "calculating OVMF hash: %s", err)
5555

56-
digest, err := guest.LaunchDigestFromOVMF(ovmfObj, entry.vcpus, ovmfHash)
56+
// Documentation for guestFeatures value: https://github.com/virtee/sev-snp-measure/pull/32/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R126.
57+
digest, err := guest.LaunchDigestFromOVMF(ovmfObj, 0x21, entry.vcpus, ovmfHash)
5758
require.NoError(err, "calculating launch digest: %s", err)
5859

5960
assert.True(bytes.Equal(digest, entry.measurement), "expected hash %x, got %x", entry.measurement, digest)

guest/guest.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ import (
1818
)
1919

2020
// LaunchDigestFromOVMF calculates a launch digest from a MetadataWrapper object.
21-
func LaunchDigestFromMetadataWrapper(wrapper ovmf.MetadataWrapper, vcpuCount int) ([]byte, error) {
22-
return launchDigest(wrapper.MetadataItems, wrapper.ResetEIP, vcpuCount, wrapper.OVMFHash)
21+
func LaunchDigestFromMetadataWrapper(wrapper ovmf.MetadataWrapper, guestFeatures uint64, vcpuCount int) ([]byte, error) {
22+
return launchDigest(wrapper.MetadataItems, wrapper.ResetEIP, guestFeatures, vcpuCount, wrapper.OVMFHash)
2323
}
2424

2525
// LaunchDigestFromOVMF calculates a launch digest from an OVMF object and an ovmfHash.
26-
func LaunchDigestFromOVMF(ovmfObj ovmf.OVMF, vcpuCount int, ovmfHash []byte) ([]byte, error) {
26+
func LaunchDigestFromOVMF(ovmfObj ovmf.OVMF, guestFeatures uint64, vcpuCount int, ovmfHash []byte) ([]byte, error) {
2727
resetEIP, err := ovmfObj.SevESResetEIP()
2828
if err != nil {
2929
return nil, fmt.Errorf("getting reset EIP: %w", err)
3030
}
31-
return launchDigest(ovmfObj.MetadataItems(), resetEIP, vcpuCount, ovmfHash)
31+
return launchDigest(ovmfObj.MetadataItems(), resetEIP, guestFeatures, vcpuCount, ovmfHash)
3232
}
3333

3434
func OVMFHash(ovmfObj ovmf.OVMF) ([]byte, error) {
@@ -40,7 +40,7 @@ func OVMFHash(ovmfObj ovmf.OVMF) ([]byte, error) {
4040
}
4141

4242
// launchDigest calculates the launch digest from metadata and ovmfHash for a SNP guest.
43-
func launchDigest(metadata []ovmf.MetadataSection, resetEIP uint32, vcpuCount int, ovmfHash []byte) ([]byte, error) {
43+
func launchDigest(metadata []ovmf.MetadataSection, resetEIP uint32, guestFeatures uint64, vcpuCount int, ovmfHash []byte) ([]byte, error) {
4444
guestCtx := gctx.New(ovmfHash)
4545

4646
if err := snpUpdateMetadataPages(guestCtx, metadata, vmmtypes.EC2); err != nil {
@@ -49,7 +49,7 @@ func launchDigest(metadata []ovmf.MetadataSection, resetEIP uint32, vcpuCount in
4949

5050
// Add support for flags {vcpus_family, vcpu_sig, vcpu_type} here, if relevant.
5151
// Use cpuid pkg.
52-
vmsaObj, err := vmsa.New(resetEIP, 0, vmmtypes.EC2)
52+
vmsaObj, err := vmsa.New(resetEIP, guestFeatures, 0, vmmtypes.EC2)
5353
if err != nil {
5454
return nil, fmt.Errorf("creating VMSA: %w", err)
5555
}

guest/guest_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestLaunchDigestFromOVMF(t *testing.T) {
5757
ovmfObj, err := ovmf.New(tc.ovmfPath)
5858
require.NoError(err)
5959

60-
launchDigest, err := LaunchDigestFromOVMF(ovmfObj, tc.vcpuCount, hash)
60+
launchDigest, err := LaunchDigestFromOVMF(ovmfObj, 0x1, tc.vcpuCount, hash)
6161
if tc.wantErr {
6262
assert.Error(err)
6363
} else {
@@ -101,7 +101,7 @@ func TestLaunchDigestFromMetadataWrapper(t *testing.T) {
101101
err = json.Unmarshal(data, &apiObject)
102102
require.NoError(err)
103103

104-
launchDigest, err := LaunchDigestFromMetadataWrapper(apiObject, tc.vcpuCount)
104+
launchDigest, err := LaunchDigestFromMetadataWrapper(apiObject, 0x1, tc.vcpuCount)
105105
if tc.wantErr {
106106
assert.Error(err)
107107
} else {

vmsa/vmsa.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ type SevEsSaveArea struct {
145145
Unused [2448]uint8
146146
}
147147

148-
func BuildSaveArea(eip uint32, vcpuSig uint64, vmmType vmmtypes.VMMType) (SevEsSaveArea, error) {
148+
func BuildSaveArea(eip uint32, guestFeatures uint64, vcpuSig uint64, vmmType vmmtypes.VMMType) (SevEsSaveArea, error) {
149149
var csFlags, ssFlags, trFlags uint16
150150
var rdx uint64
151151
switch vmmType {
@@ -185,7 +185,7 @@ func BuildSaveArea(eip uint32, vcpuSig uint64, vmmType vmmtypes.VMMType) (SevEsS
185185
Rip: uint64(eip & 0xffff),
186186
GPat: 0x7040600070406, // PAT MSR: See AMD APM Vol 2, Section A.3.
187187
Rdx: rdx,
188-
SevFeatures: 0x1, // Make this configurable if we want to support other modes than SEV-SNP.
188+
SevFeatures: guestFeatures, // Documentation: https://github.com/virtee/sev-snp-measure/pull/32/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R125.
189189
Xcr0: 0x1,
190190
}, nil
191191
}
@@ -195,14 +195,14 @@ type VMSA struct {
195195
ApSaveArea SevEsSaveArea
196196
}
197197

198-
func New(apEip uint32, vcpuSig uint64, vmmType vmmtypes.VMMType) (VMSA, error) {
199-
bspSaveArea, err := BuildSaveArea(BspEIP, vcpuSig, vmmType)
198+
func New(apEip uint32, guestFeatures uint64, vcpuSig uint64, vmmType vmmtypes.VMMType) (VMSA, error) {
199+
bspSaveArea, err := BuildSaveArea(BspEIP, guestFeatures, vcpuSig, vmmType)
200200
if err != nil {
201201
return VMSA{}, err
202202
}
203203
var apSaveArea SevEsSaveArea
204204
if apEip != 0 {
205-
apSaveArea, err = BuildSaveArea(apEip, vcpuSig, vmmType)
205+
apSaveArea, err = BuildSaveArea(apEip, guestFeatures, vcpuSig, vmmType)
206206
if err != nil {
207207
return VMSA{}, err
208208
}

0 commit comments

Comments
 (0)