Thanks to visit codestin.com
Credit goes to github.com

Skip to content

KVM SEV-SNP kernel hashes and ID block support - #8123

Merged
rbradford merged 7 commits into
cloud-hypervisor:mainfrom
rhakobyan:sev-snp-kernel-hashes
May 1, 2026
Merged

rbradford merged 7 commits into
cloud-hypervisor:mainfrom
rhakobyan:sev-snp-kernel-hashes

Conversation

@rhakobyan

@rhakobyan rhakobyan commented May 1, 2026

Copy link
Copy Markdown
Member

This PR adds measured boot support for AMD SEV-SNP confidential VMs launched via Cloud Hypervisor with IGVM, bringing parity with QEMU's SEV-SNP launch flow.

The core goal is to ensure the guest's launch measurement accurately reflects the kernel, command line, and initrd provided by the VMM — and to pass a signed SNP ID block so the guest (or a remote attestor) can verify the launch against a known identity.

The kernel hashes patches are taken from #8084, and cleaned up. The ID Block patches largely follow the same principles in QEMU.

Testing

Step 1: Build Stage0 Firmware

Stage0 is built from the Project Oak stage0_bin.

Step 2: Create a Signed SNP ID Block

2a. Compute the launch measurement

sev-snp-measure --vcpus 4 --vcpu-sig <sig> \
  --ovmf stage0_bin \
  --kernel vmlinuz \
  --append "console=ttyS0 root=/dev/vda1 rw" \
  --mode snp

53c4f97b9e994ac6a93176aca0b8e85017bae981276d636dff7129834ccfcfac4b3383e9ecdd90b38ebf471ebb4c6fb7
  • --vcpu-sig: CPU signature from CPUID leaf 1 EAX
  • --ovmf: the raw stage0_bin
  • --append: must exactly match --cmdline passed to cloud-hypervisor later

2b. Generate keys (example):

openssl ... -out idkey.pem
openssl ... -out authorkey.pem

2c. Generate the ID block

MEASUREMENT_HEX="<paste hex from 2a>"
MEASUREMENT_B64=$(python3 -c "import base64; print(base64.b64encode(bytes.fromhex('${MEASUREMENT_HEX}')).decode())")

python3 sev-snp-measure/snp-create-id-block.py \
  --measurement "$MEASUREMENT_B64" \
  --idkey idkey.pem \
  --authorkey authorkey.pem \
  --igvm --policy <policy> \
  > snp-id-block.bin

Step 3: Build the IGVM File

buildigvm sev-snp \
...

Step 4: Launch Cloud-Hypervisor

4a. Build

cargo build --release --no-default-features --features "kvm,igvm,sev_snp,fw_cfg"

4b. Run

sudo ./target/release/cloud-hypervisor -vv \
  --platform sev_snp=on \
  --igvm stage0.igvm \
  --kernel vmlinuz \
  --cpus boot=4 \
  --memory size=2G,shared=on \
  --disk path=guest.qcow2,image_type=qcow2 \
  --cmdline "console=ttyS0 root=/dev/vda1 rw" \
  --serial tty \
  --console off

4c. Verify attestation (from inside the guest)

# Get attestation report from AMD PSP
snpguest report /tmp/report.bin /tmp/request.bin --random

snpguest display report /tmp/report.bin

Attestation Report (1184 bytes):
Version:                      5
Guest SVN:                    0

    Guest Policy (0x230000):
    ABI Major:     0
    ABI Minor:     0
    SMT Allowed:   1
    Migrate MA:    0
    Debug Allowed: 0
    Single Socket: 0

...
Measurement:                  
53 c4 f9 7b 9e 99 4a c6 a9 31 76 ac a0 b8 e8 50 
17 ba e9 81 27 6d 63 6d ff 71 29 83 4c cf cf ac 
4b 33 83 e9 ec dd 90 b3 8e bf 47 1e bb 4c 6f b7 

Measurement matches 2a.

@rhakobyan
rhakobyan force-pushed the sev-snp-kernel-hashes branch 2 times, most recently from 80c3d6f to 6974ccd Compare May 1, 2026 03:32
@rhakobyan
rhakobyan marked this pull request as ready for review May 1, 2026 07:59
@rhakobyan
rhakobyan requested a review from a team as a code owner May 1, 2026 07:59
@rhakobyan
rhakobyan force-pushed the sev-snp-kernel-hashes branch 3 times, most recently from 1096def to 5063720 Compare May 1, 2026 15:14
rhakobyan and others added 2 commits May 1, 2026 09:32
For KVM SEV-SNP guests, the VMM should not modify the kernel
boot header before sending it via fw_cfg. The guest firmware is expected
to set fields like type_of_loader itself.

For upcoming measured boot logic for SEV-SNP, modifying `type_of_loader`
causes the kernel hash computed by the VMM to diverge from the hash that
`sev-snp-measure` (and the guest firmware) compute, resulting in a
launch measurement mismatch.

This matches QEMU's behavior, which skips kernel header modifications
for confidential guests so the data sent via fw_cfg matches the
original kernel file provided by the user.

Signed-off-by: Ruben Hakobyan <[email protected]>
This introduces the kernel hashes measured boot table into
cloud hypervisor if a cmdline and kernel is passed into an
SEV-SNP CVM, incorporating a kernel/cmdline/optional initrd
into a memory page that is measured into the launch digest
of a SEV-SNP CVM. If both --kernel and --cmdline are not
provided, we do not insert this data page

Signed-off-by: Kevin Hui <[email protected]>
@rhakobyan
rhakobyan force-pushed the sev-snp-kernel-hashes branch from 5063720 to eec17a2 Compare May 1, 2026 16:33
Verify the SEV hash table layout, GUID placement, kernel/initrd/cmdline
digest values, and the setup_sects > boot_params size branch. These
guard against silent regressions in the launch digest computation.

Signed-off-by: Kevin Hui <[email protected]>
Introduce the KVM_SNP_PAGE_TYPE_ZERO page type for ZERO
pages. AMD SEV SNP can accept ZERO pages as a page in which
the page memory is functionally just zeroes

Signed-off-by: Kevin Hui <[email protected]>
@rhakobyan
rhakobyan force-pushed the sev-snp-kernel-hashes branch from eec17a2 to 46de765 Compare May 1, 2026 16:36
CookieComputing and others added 3 commits May 1, 2026 09:39
Preserve the original IGVM import order for KVM SNP launch updates.
The launch digest is order-sensitive, so only coalesce adjacent pages
that already share the same page type and size. MSHV continues to
sort by GPA for hypercall batching.

Signed-off-by: Kevin Hui <[email protected]>
Extract the SNP guest policy from IGVM initialization headers when
available, falling back to the default policy. This matches QEMU's
behaviour where only a non-zero IGVM policy overrides the default.

Signed-off-by: Ruben Hakobyan <[email protected]>
Add KvmSevSnpIdBlock and KvmSevSnpIdAuth structs matching the AMD
SEV-SNP Firmware ABI Spec (Rev 1.58), and build them from the IGVM
SNP ID block directive during launch finish. This properly populates
id_block_uaddr/id_auth_uaddr in KVM_SEV_SNP_LAUNCH_FINISH and derives
auth_key_en from the assembled author key, matching QEMU's behavior.

Thread the guest policy from sev_snp_init to launch_finish via an
atomic on KvmVm so the ID block gets the correct policy value.

Also track has_snp_id_block in IgvmLoadedInfo to enable the ID block
based on whether the IGVM file actually contains one, rather than
hardcoding it for KVM.

Signed-off-by: Ruben Hakobyan <[email protected]>
@rhakobyan
rhakobyan force-pushed the sev-snp-kernel-hashes branch from 46de765 to 5c6642d Compare May 1, 2026 16:39
@rbradford
rbradford added this pull request to the merge queue May 1, 2026
Merged via the queue into cloud-hypervisor:main with commit c97d635 May 1, 2026
77 of 79 checks passed
@github-project-automation github-project-automation Bot moved this from 🆕 New to ✅ Done in Cloud Hypervisor Roadmap May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

4 participants