From 98b956886e3a358914a411e306056c74f3acb9a9 Mon Sep 17 00:00:00 2001 From: Alejandro Jimenez Date: Tue, 4 Feb 2020 22:07:16 -0500 Subject: [PATCH] pvh: Add definitions for PVH boot protocol support Create supporting definitions to use the hvm start info and memory map table entry struct definitions from the linux-loader crate in order to enable PVH boot protocol support Signed-off-by: Alejandro Jimenez --- arch/src/lib.rs | 10 ++++++++++ arch/src/x86_64/layout.rs | 9 +++++++++ arch/src/x86_64/mod.rs | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/arch/src/lib.rs b/arch/src/lib.rs index 75f78696f..99b785447 100644 --- a/arch/src/lib.rs +++ b/arch/src/lib.rs @@ -1,3 +1,5 @@ +// Copyright © 2020, Oracle and/or its affiliates. +// // Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 @@ -31,6 +33,14 @@ pub enum Error { ZeroPagePastRamEnd, /// Error writing the zero page of guest memory. ZeroPageSetup(vm_memory::GuestMemoryError), + /// The memory map table extends past the end of guest memory. + MemmapTablePastRamEnd, + /// Error writing memory map table to guest memory. + MemmapTableSetup, + /// The hvm_start_info structure extends past the end of guest memory. + StartInfoPastRamEnd, + /// Error writing hvm_start_info to guest memory. + StartInfoSetup, } pub type Result = result::Result; diff --git a/arch/src/x86_64/layout.rs b/arch/src/x86_64/layout.rs index 735a9eba8..488cede2a 100644 --- a/arch/src/x86_64/layout.rs +++ b/arch/src/x86_64/layout.rs @@ -1,3 +1,5 @@ +// Copyright © 2020, Oracle and/or its affiliates. +// // Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 // @@ -26,6 +28,13 @@ pub const LOW_RAM_START: GuestAddress = GuestAddress(0x0); pub const BOOT_GDT_START: GuestAddress = GuestAddress(0x500); pub const BOOT_IDT_START: GuestAddress = GuestAddress(0x520); +/// Address for the hvm_start_info struct used in PVH boot +pub const PVH_INFO_START: GuestAddress = GuestAddress(0x6000); + +/// Address of memory map table used in PVH boot. Can overlap +/// with the zero page address since they are mutually exclusive. +pub const MEMMAP_START: GuestAddress = GuestAddress(0x7000); + /// The 'zero page', a.k.a linux kernel bootparams. pub const ZERO_PAGE_START: GuestAddress = GuestAddress(0x7000); diff --git a/arch/src/x86_64/mod.rs b/arch/src/x86_64/mod.rs index a6f274718..3c11e9f5a 100644 --- a/arch/src/x86_64/mod.rs +++ b/arch/src/x86_64/mod.rs @@ -1,3 +1,5 @@ +// Copyright © 2020, Oracle and/or its affiliates. +// // Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 // @@ -13,6 +15,7 @@ pub mod regs; use crate::RegionType; use linux_loader::loader::bootparam::{boot_params, setup_header}; +use linux_loader::loader::start_info::{hvm_memmap_table_entry, hvm_start_info}; use std::mem; use vm_memory::{ Address, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryMmap, GuestUsize, @@ -21,6 +24,22 @@ use vm_memory::{ const E820_RAM: u32 = 1; const E820_RESERVED: u32 = 2; +// This is a workaround to the Rust enforcement specifying that any implementation of a foreign +// trait (in this case `DataInit`) where: +// * the type that is implementing the trait is foreign or +// * all of the parameters being passed to the trait (if there are any) are also foreign +// is prohibited. +#[derive(Copy, Clone, Default)] +struct StartInfoWrapper(hvm_start_info); + +// It is safe to initialize StartInfoWrapper which is a wrapper over `hvm_start_info` (a series of ints). +unsafe impl ByteValued for StartInfoWrapper {} + +#[derive(Copy, Clone, Default)] +struct MemmapTableEntryWrapper(hvm_memmap_table_entry); + +unsafe impl ByteValued for MemmapTableEntryWrapper {} + // This is a workaround to the Rust enforcement specifying that any implementation of a foreign // trait (in this case `DataInit`) where: // * the type that is implementing the trait is foreign or