Skip to content

Commit

Permalink
fix naming for boot code
Browse files Browse the repository at this point in the history
Signed-off-by: Jake Correnti <[email protected]>
  • Loading branch information
jakecorrenti committed Aug 12, 2024
1 parent 16cb204 commit f28a432
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions tests/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,16 @@ fn launch() {
// ==============
// setup boot code on guest
// ==============
let firmware_userspace = ram_mmap(firmware_code.len() as u64);
let boot_userspace = ram_mmap(firmware_code.len() as u64);
let guest_addr = 0x1000;

let address_space: &mut [u8] = unsafe {
std::slice::from_raw_parts_mut(firmware_userspace as *mut u8, firmware_code.len())
};
address_space[..firmware_code.len()].copy_from_slice(&BOOT_CODE[..]);
let firmware_userspace = address_space as *const [u8] as *const u8 as u64;
let address_space: &mut [u8] =
unsafe { std::slice::from_raw_parts_mut(boot_userspace as *mut u8, BOOT_CODE.len()) };
address_space[..BOOT_CODE.len()].copy_from_slice(&BOOT_CODE[..]);
let boot_userspace = address_space as *const [u8] as *const u8 as u64;

let gmem = kvm_bindings::kvm_create_guest_memfd {
size: firmware_code.len() as u64,
size: BOOT_CODE.len() as u64,
flags: 0,
reserved: [0; 6],
};
Expand All @@ -138,8 +137,8 @@ fn launch() {
// KVM_MEM_GUEST_MEMFD
flags: 1 << 2,
guest_phys_addr: guest_addr,
memory_size: firmware_code.len() as u64,
userspace_addr: firmware_userspace,
memory_size: BOOT_CODE.len() as u64,
userspace_addr: boot_userspace,
guest_memfd_offset: 0,
guest_memfd: gmem as u32,
pad1: 0,
Expand All @@ -151,15 +150,15 @@ fn launch() {

let attr = kvm_bindings::kvm_memory_attributes {
address: guest_addr,
size: firmware_code.len() as u64,
size: BOOT_CODE.len() as u64,
// KVM_MEMORY_ATTRIBUTE_PRIVATE
attributes: 1 << 3,
flags: 0,
};
tdx_vm.fd.set_memory_attributes(attr).unwrap();

tdx_vm
.init_mem_region_raw(guest_addr, 1, 1, firmware_userspace)
.init_mem_region_raw(guest_addr, 1, 1, boot_userspace)
.unwrap();

// if check_extension(KVM_CAP_MEMORY_MAPPING) {
Expand Down

0 comments on commit f28a432

Please sign in to comment.