Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions alioth/src/board/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#[path = "board_aarch64.rs"]
mod aarch64;
#[cfg(target_arch = "x86_64")]
#[path = "board_x86_64.rs"]
#[path = "board_x86_64/board_x86_64.rs"]
mod x86_64;

#[cfg(target_os = "linux")]
Expand Down Expand Up @@ -45,7 +45,7 @@ use crate::device::MmioDev;
#[cfg(target_arch = "x86_64")]
use crate::device::fw_cfg::FwCfg;
use crate::errors::{DebugTrace, trace_error};
use crate::hv::{Coco, Vcpu, Vm, VmEntry, VmExit};
use crate::hv::{Coco, Hypervisor, Vcpu, Vm, VmConfig, VmEntry, VmExit};
#[cfg(target_arch = "x86_64")]
use crate::loader::xen;
use crate::loader::{Executable, InitState, Payload, linux};
Expand All @@ -58,9 +58,9 @@ use crate::vfio::container::Container;
use crate::vfio::iommu::Ioas;

#[cfg(target_arch = "aarch64")]
pub(crate) use self::aarch64::ArchBoard;
use self::aarch64::ArchBoard;
#[cfg(target_arch = "x86_64")]
pub(crate) use self::x86_64::ArchBoard;
use self::x86_64::ArchBoard;

#[trace_error]
#[derive(Snafu, DebugTrace)]
Expand Down Expand Up @@ -92,7 +92,7 @@ pub enum Error {
#[snafu(display("Failed to reset PCI devices"))]
ResetPci { source: Box<crate::pci::Error> },
#[snafu(display("Failed to configure firmware"))]
Firmware { error: std::io::Error },
FwCfg { error: std::io::Error },
#[snafu(display("Missing payload"))]
MissingPayload,
#[snafu(display("Failed to notify the VMM thread"))]
Expand All @@ -104,6 +104,10 @@ pub enum Error {
#[cfg(target_arch = "x86_64")]
#[snafu(display("Missing CPUID leaf {leaf:x?}"))]
MissingCpuid { leaf: CpuidIn },
#[snafu(display("Firmware error"), context(false))]
Firmware { source: Box<crate::firmware::Error> },
#[snafu(display("Unknown firmware metadata"))]
UnknownFirmwareMetadata,
}

type Result<T, E = Error> = std::result::Result<T, E>;
Expand Down Expand Up @@ -233,10 +237,22 @@ impl<V> Board<V>
where
V: Vm,
{
pub fn new(vm: V, memory: Memory, arch: ArchBoard<V>, config: BoardConfig) -> Self {
Board {
pub fn new<H>(hv: &H, mut config: BoardConfig) -> Result<Self>
where
H: Hypervisor<Vm = V>,
{
config.config_fixup()?;

let vm_config = VmConfig {
coco: config.coco.clone(),
};
let mut vm = hv.create_vm(&vm_config)?;
let vm_memory = Arc::new(vm.create_vm_memory()?);
let arch = ArchBoard::new(hv, &vm, &config)?;

let board = Board {
vm,
memory,
memory: Memory::new(vm_memory.clone()),
arch,
config,
payload: RwLock::new(None),
Expand All @@ -257,7 +273,11 @@ where
fatal: false,
}),
cond_var: Condvar::new(),
}
};

board.coco_init(vm_memory)?;

Ok(board)
}

pub fn boot(&self) -> Result<()> {
Expand Down Expand Up @@ -294,14 +314,14 @@ where
Ok(())
}

fn load_payload(&self) -> Result<InitState, Error> {
fn load_payload(&self, vcpu: &mut V::Vcpu) -> Result<InitState, Error> {
let payload = self.payload.read();
let Some(payload) = payload.as_ref() else {
return error::MissingPayload.fail();
};

if let Some(fw) = payload.firmware.as_ref() {
return self.setup_firmware(fw, payload);
return self.setup_firmware(fw, payload, vcpu);
}

let Some(exec) = &payload.executable else {
Expand Down Expand Up @@ -414,7 +434,6 @@ where

fn boot_init_sync(&self, index: u16, vcpu: &mut V::Vcpu) -> Result<()> {
let vcpus = self.vcpus.read();
self.coco_init(index)?;
if index == 0 {
self.create_ram()?;
for (port, dev) in self.io_devs.read().iter() {
Expand All @@ -424,7 +443,7 @@ where
self.memory.add_mmio_dev(*addr, dev.clone())?;
}
self.add_pci_devs()?;
let init_state = self.load_payload()?;
let init_state = self.load_payload(vcpu)?;
self.init_boot_vcpu(vcpu, &init_state)?;
self.create_firmware_data(&init_state)?;
}
Expand Down
4 changes: 2 additions & 2 deletions alioth/src/board/board_aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ where
encode_mpidr(&self.config.cpu.topology, index).0
}

pub fn setup_firmware(&self, _: &Path, _: &Payload) -> Result<InitState> {
pub fn setup_firmware(&self, _: &Path, _: &Payload, _: &V::Vcpu) -> Result<InitState> {
unimplemented!()
}

Expand Down Expand Up @@ -154,7 +154,7 @@ where
Ok(())
}

pub fn coco_init(&self, _id: u16) -> Result<()> {
pub fn coco_init(&self, _: Arc<V::Memory>) -> Result<()> {
Ok(())
}

Expand Down
Loading