Skip to content

Commit 870a6f9

Browse files
committed
fix(dstack-mr): correct UEFI disk boot RTMR[0] for 2-disk config
- Add second virtio-blk disk to ACPI table generation (data disk) - BootOrder now has 3 entries [0,1,2] matching OVMF's BDS with 2 disks - Add Boot0002 'UEFI Misc Device 2' at PCI(0x2,0x0) All RTMRs now match TDX hardware measurements exactly: MRTD ✓ RTMR[0] ✓ RTMR[1] ✓ RTMR[2] ✓
1 parent 7582aa8 commit 870a6f9

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

dstack-mr/src/acpi.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ impl Machine<'_> {
5757
&format!("file={dummy_disk},if=none,id=hd0,format=raw,readonly=on"),
5858
"-device",
5959
"virtio-blk-pci,drive=hd0",
60+
// Second disk (data disk) — separate from OS disk for RTMR stability
61+
"-drive",
62+
&format!("file={dummy_disk},if=none,id=hd1,format=raw,readonly=on"),
63+
"-device",
64+
"virtio-blk-pci,drive=hd1",
6065
"-netdev",
6166
"user,id=net0",
6267
"-device",

dstack-mr/src/tdvf.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,10 @@ impl<'a> Tdvf<'a> {
337337
let acpi_rsdp_hash = measure_sha384(&tables.rsdp);
338338
let acpi_loader_hash = measure_sha384(&tables.loader);
339339

340-
// BootOrder for UEFI disk boot: [0x0000, 0x0001] (2 boot entries).
340+
// BootOrder for UEFI disk boot: [0x0000, 0x0001, 0x0002] (3 boot entries).
341+
// Boot0000=UiApp, Boot0001=OS disk (vda), Boot0002=data disk (vdb).
341342
// Digest = SHA384(variable_data_bytes), NOT SHA384(UEFI_VARIABLE_DATA struct).
342-
let boot_order_data: [u8; 4] = [0x00, 0x00, 0x01, 0x00]; // LE u16: 0, 1
343+
let boot_order_data: [u8; 6] = [0x00, 0x00, 0x01, 0x00, 0x02, 0x00]; // LE u16: 0, 1, 2
343344
let boot_order_hash = measure_sha384(&boot_order_data);
344345

345346
// Boot0001: "UEFI Misc Device" at PciRoot(0x0)/Pci(0x1,0x0) — first virtio-blk.
@@ -383,6 +384,29 @@ impl<'a> Tdvf<'a> {
383384
};
384385
let boot0001_hash = measure_sha384(&boot0001_data);
385386

387+
// Boot0002: "UEFI Misc Device 2" at PciRoot(0x0)/Pci(0x2,0x0) — second virtio-blk (data disk).
388+
// Same structure as Boot0001 but with Device=2 and description "UEFI Misc Device 2".
389+
let boot0002_data: Vec<u8> = {
390+
let mut d = Vec::new();
391+
d.extend_from_slice(&0x00000001u32.to_le_bytes()); // LOAD_OPTION_ACTIVE
392+
d.extend_from_slice(&0x0016u16.to_le_bytes()); // FilePathListLength
393+
for c in "UEFI Misc Device 2".encode_utf16() {
394+
d.extend_from_slice(&c.to_le_bytes());
395+
}
396+
d.extend_from_slice(&[0x00, 0x00]); // null terminator
397+
d.extend_from_slice(&[0x02, 0x01, 0x0c, 0x00]); // ACPI device path
398+
d.extend_from_slice(&0x0a0341d0u32.to_le_bytes()); // PNP0A03
399+
d.extend_from_slice(&0x00000000u32.to_le_bytes()); // UID=0
400+
d.extend_from_slice(&[0x01, 0x01, 0x06, 0x00, 0x00, 0x02]); // PCI: Device=2
401+
d.extend_from_slice(&[0x7f, 0xff, 0x04, 0x00]); // End
402+
d.extend_from_slice(&[
403+
0x4e, 0xac, 0x08, 0x81, 0x11, 0x9f, 0x59, 0x4d, 0x85, 0x0e, 0xe2, 0x1a, 0x52, 0x2c,
404+
0x59, 0xb2,
405+
]); // VenMedia GUID
406+
d
407+
};
408+
let boot0002_hash = measure_sha384(&boot0002_data);
409+
386410
Ok((
387411
vec![
388412
td_hob_hash,
@@ -399,6 +423,7 @@ impl<'a> Tdvf<'a> {
399423
boot_order_hash,
400424
boot000_hash.to_vec(),
401425
boot0001_hash,
426+
boot0002_hash,
402427
],
403428
tables,
404429
))

0 commit comments

Comments
 (0)