(
&mut self,
sections: &[TdvfSection],
guid_found: bool,
)
| 2531 | |
| 2532 | #[cfg(feature = "tdx")] |
| 2533 | fn populate_tdx_sections( |
| 2534 | &mut self, |
| 2535 | sections: &[TdvfSection], |
| 2536 | guid_found: bool, |
| 2537 | ) -> Result<Option<u64>> { |
| 2538 | use arch::x86_64::tdx::*; |
| 2539 | // Get the memory end *before* we start adding TDVF ram regions |
| 2540 | let boot_guest_memory = self |
| 2541 | .memory_manager |
| 2542 | .lock() |
| 2543 | .as_ref() |
| 2544 | .unwrap() |
| 2545 | .boot_guest_memory(); |
| 2546 | for section in sections { |
| 2547 | // No need to allocate if the section falls within guest RAM ranges |
| 2548 | if boot_guest_memory.address_in_range(GuestAddress(section.address)) { |
| 2549 | info!( |
| 2550 | "Not allocating TDVF Section: {section:x?} since it is already part of guest RAM" |
| 2551 | ); |
| 2552 | continue; |
| 2553 | } |
| 2554 | |
| 2555 | info!("Allocating TDVF Section: {section:x?}"); |
| 2556 | self.memory_manager |
| 2557 | .lock() |
| 2558 | .unwrap() |
| 2559 | .add_ram_region(GuestAddress(section.address), section.size as usize) |
| 2560 | .map_err(Error::AllocatingTdvfMemory)?; |
| 2561 | } |
| 2562 | |
| 2563 | // The TDVF file contains a table of section as well as code |
| 2564 | let firmware_path = self |
| 2565 | .config |
| 2566 | .lock() |
| 2567 | .unwrap() |
| 2568 | .payload |
| 2569 | .as_ref() |
| 2570 | .unwrap() |
| 2571 | .firmware |
| 2572 | .clone() |
| 2573 | .ok_or(Error::TdxFirmwareMissing)?; |
| 2574 | let mut firmware_file = File::open(firmware_path).map_err(Error::LoadTdvf)?; |
| 2575 | |
| 2576 | // The guest memory at this point now has all the required regions so it |
| 2577 | // is safe to copy from the TDVF file into it. |
| 2578 | let guest_memory = self.memory_manager.lock().as_ref().unwrap().guest_memory(); |
| 2579 | let mem = guest_memory.memory(); |
| 2580 | let mut payload_info = None; |
| 2581 | let mut hob_offset = None; |
| 2582 | for section in sections { |
| 2583 | info!("Populating TDVF Section: {section:x?}"); |
| 2584 | match section.r#type { |
| 2585 | TdvfSectionType::Bfv | TdvfSectionType::Cfv => { |
| 2586 | info!("Copying section to guest memory"); |
| 2587 | firmware_file |
| 2588 | .seek(SeekFrom::Start(section.data_offset as u64)) |
| 2589 | .map_err(Error::LoadTdvf)?; |
| 2590 | mem.read_volatile_from( |
no test coverage detected