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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["Changyuan Lyu <changyuan.lv@gmail.com>"]
license = "Apache-2.0"
repository = "https://github.com/google/alioth"
version = "0.6.0"
edition = "2021"
edition = "2024"

[workspace.dependencies]
parking_lot = { version = "0.12", features = ["hardware-lock-elision"] }
Expand Down
8 changes: 5 additions & 3 deletions alioth-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::path::PathBuf;
use alioth::board::BoardConfig;
#[cfg(target_arch = "x86_64")]
use alioth::device::fw_cfg::FwCfgItemParam;
use alioth::errors::{trace_error, DebugTrace};
use alioth::errors::{DebugTrace, trace_error};
use alioth::hv::Coco;
#[cfg(target_os = "macos")]
use alioth::hv::Hvf;
Expand All @@ -45,7 +45,7 @@ use alioth::vm::Machine;
use clap::{Args, Parser, Subcommand};
use flexi_logger::{FileSpec, Logger};
use serde::Deserialize;
use serde_aco::{help_text, Help};
use serde_aco::{Help, help_text};
use snafu::{ResultExt, Snafu};

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -387,7 +387,9 @@ fn main_run(args: RunArgs) -> Result<(), Error> {
let param = match serde_aco::from_args(&blk, &objects) {
Ok(param) => param,
Err(serde_aco::Error::ExpectedMapEq) => {
eprintln!("Please update the cmd line to --blk path={blk}, see https://github.com/google/alioth/pull/72 for details");
eprintln!(
"Please update the cmd line to --blk path={blk}, see https://github.com/google/alioth/pull/72 for details"
);
BlockParam {
path: blk.into(),
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/arch/aarch64/reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub enum Reg {
}

pub const fn encode(op0: u16, op1: u16, crn: u16, crm: u16, op2: u16) -> u16 {
op0 << 14 | op1 << 11 | crn << 7 | crm << 3 | op2
(op0 << 14) | (op1 << 11) | (crn << 7) | (crm << 3) | op2
}

c_enum! {
Expand Down
4 changes: 2 additions & 2 deletions alioth/src/board/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::arch::layout::{
RAM_32_START,
};
use crate::arch::reg::SReg;
use crate::board::{Board, BoardConfig, Result, VcpuGuard, PCIE_MMIO_64_SIZE};
use crate::board::{Board, BoardConfig, PCIE_MMIO_64_SIZE, Result, VcpuGuard};
use crate::firmware::dt::{DeviceTree, Node, PropVal};
use crate::hv::{GicV2, GicV3, Hypervisor, Its, Vcpu, Vm};
use crate::loader::{ExecType, InitState};
Expand Down Expand Up @@ -293,7 +293,7 @@ where
Gic::V3 { .. } => 0,
};
for pin in irq_pins {
interrupts.extend([ppi, pin, cpu_mask << 8 | level_trigger]);
interrupts.extend([ppi, pin, (cpu_mask << 8) | level_trigger]);
}
let node = Node {
props: HashMap::from([
Expand Down
8 changes: 4 additions & 4 deletions alioth/src/board/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ mod x86_64;
#[cfg(target_os = "linux")]
use std::collections::HashMap;
use std::ffi::CStr;
use std::sync::mpsc::{Receiver, Sender};
use std::sync::Arc;
use std::sync::mpsc::{Receiver, Sender};
use std::thread::JoinHandle;

use libc::{MAP_PRIVATE, MAP_SHARED};
Expand All @@ -37,16 +37,16 @@ use crate::arch::layout::{
};
#[cfg(target_arch = "x86_64")]
use crate::device::fw_cfg::FwCfg;
use crate::errors::{trace_error, DebugTrace};
use crate::errors::{DebugTrace, trace_error};
use crate::hv::{Coco, Vcpu, Vm, VmEntry, VmExit};
#[cfg(target_arch = "x86_64")]
use crate::loader::xen;
use crate::loader::{firmware, linux, ExecType, InitState, Payload};
use crate::loader::{ExecType, InitState, Payload, firmware, linux};
use crate::mem::emulated::Mmio;
use crate::mem::mapped::ArcMemPages;
use crate::mem::{MemBackend, MemConfig, MemRegion, MemRegionType, Memory};
use crate::pci::bus::PciBus;
use crate::pci::Bdf;
use crate::pci::bus::PciBus;
#[cfg(target_os = "linux")]
use crate::vfio::container::Container;
#[cfg(target_os = "linux")]
Expand Down
10 changes: 5 additions & 5 deletions alioth/src/board/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::arch::x86_64::{CpuidResult, __cpuid};
use std::arch::x86_64::{__cpuid, CpuidResult};
use std::collections::HashMap;
use std::iter::zip;
use std::marker::PhantomData;
use std::mem::{offset_of, size_of, size_of_val};
use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::Arc;
use std::sync::atomic::{AtomicU32, Ordering};

use parking_lot::Mutex;
use snafu::ResultExt;
Expand All @@ -29,16 +29,16 @@ use crate::arch::layout::{
BIOS_DATA_END, EBDA_END, EBDA_START, MEM_64_START, PORT_ACPI_RESET, PORT_ACPI_SLEEP_CONTROL,
RAM_32_SIZE,
};
use crate::arch::msr::{MiscEnable, IA32_MISC_ENABLE};
use crate::arch::msr::{IA32_MISC_ENABLE, MiscEnable};
use crate::arch::reg::{Reg, SegAccess, SegReg, SegRegVal};
use crate::arch::sev::SnpPageType;
use crate::board::{error, Board, BoardConfig, Result, VcpuGuard, PCIE_MMIO_64_SIZE};
use crate::board::{Board, BoardConfig, PCIE_MMIO_64_SIZE, Result, VcpuGuard, error};
use crate::firmware::acpi::bindings::{
AcpiTableFadt, AcpiTableHeader, AcpiTableRsdp, AcpiTableXsdt3,
};
use crate::firmware::acpi::reg::{FadtReset, FadtSleepControl};
use crate::firmware::acpi::{
create_fadt, create_madt, create_mcfg, create_rsdp, create_xsdt, AcpiTable,
AcpiTable, create_fadt, create_madt, create_mcfg, create_rsdp, create_xsdt,
};
use crate::hv::{Coco, Hypervisor, Vcpu, Vm};
use crate::loader::InitState;
Expand Down
4 changes: 2 additions & 2 deletions alioth/src/device/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use std::sync::Arc;
use std::thread::JoinHandle;

use libc::{
cfmakeraw, fcntl, tcgetattr, tcsetattr, termios, F_GETFL, F_SETFL, OPOST, O_NONBLOCK,
STDIN_FILENO, STDOUT_FILENO, TCSANOW,
F_GETFL, F_SETFL, O_NONBLOCK, OPOST, STDIN_FILENO, STDOUT_FILENO, TCSANOW, cfmakeraw, fcntl,
tcgetattr, tcsetattr, termios,
};
use mio::unix::SourceFd;
use mio::{Events, Interest, Poll, Token, Waker};
Expand Down
4 changes: 2 additions & 2 deletions alioth/src/device/fw_cfg/acpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use std::mem::{offset_of, size_of};

use zerocopy::{Immutable, IntoBytes};

use crate::device::fw_cfg::{create_file_name, FwCfgContent, FwCfgItem, FILE_NAME_SIZE};
use crate::firmware::acpi::bindings::{AcpiTableHeader, AcpiTableRsdp};
use crate::device::fw_cfg::{FILE_NAME_SIZE, FwCfgContent, FwCfgItem, create_file_name};
use crate::firmware::acpi::AcpiTable;
use crate::firmware::acpi::bindings::{AcpiTableHeader, AcpiTableRsdp};

pub const COMMAND_ALLOCATE: u32 = 0x1;
pub const COMMAND_ADD_POINTER: u32 = 0x2;
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/device/pvpanic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::mem::emulated::{Action, Mmio};
use crate::mem::{self, MemRegion};
use crate::pci::cap::PciCapList;
use crate::pci::config::{
CommonHeader, DeviceHeader, EmulatedConfig, HeaderType, PciConfig, BAR_MEM64, BAR_PREFETCHABLE,
BAR_MEM64, BAR_PREFETCHABLE, CommonHeader, DeviceHeader, EmulatedConfig, HeaderType, PciConfig,
};
use crate::pci::{self, Pci, PciBar};

Expand Down
2 changes: 1 addition & 1 deletion alioth/src/device/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ where
reg.divisor = (reg.divisor & 0xff00) | byte as u16;
}
DIVISOR_LATCH_MSB if reg.line_control.divisor_latch_access() => {
reg.divisor = (reg.divisor & 0x00ff) | (byte as u16) << 8;
reg.divisor = (reg.divisor & 0x00ff) | ((byte as u16) << 8);
}
TX_HOLDING_REGISTER => {
if reg.modem_control.loop_back() {
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use std::error::Error;
use std::fmt;

pub use macros::{trace_error, DebugTrace};
pub use macros::{DebugTrace, trace_error};

pub trait DebugTrace: Error {
fn debug_trace(&self, f: &mut fmt::Formatter) -> Result<u32, fmt::Error>;
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/firmware/acpi/acpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub mod reg;

use std::mem::{offset_of, size_of};

use zerocopy::{transmute, FromBytes, IntoBytes};
use zerocopy::{FromBytes, IntoBytes, transmute};

use crate::arch::layout::PCIE_CONFIG_START;
#[cfg(target_arch = "x86_64")]
Expand Down
4 changes: 3 additions & 1 deletion alioth/src/firmware/acpi/reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// limitations under the License.

use crate::firmware::acpi::bindings::FadtSleepControlReg;
use crate::mem::emulated::{Action, Mmio};
use crate::mem::Result;
use crate::mem::emulated::{Action, Mmio};

pub const FADT_RESET_VAL: u8 = b'r';

Expand All @@ -25,9 +25,11 @@ impl Mmio for FadtReset {
fn size(&self) -> u64 {
1
}

fn read(&self, _offset: u64, _size: u8) -> Result<u64> {
Ok(0)
}

fn write(&self, _offset: u64, _size: u8, val: u64) -> Result<Action> {
if val as u8 == FADT_RESET_VAL {
Ok(Action::Reset)
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/hv/hv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use crate::arch::reg::{DtReg, DtRegVal, SegReg, SegRegVal};
use crate::arch::reg::{Reg, SReg};
#[cfg(target_arch = "x86_64")]
use crate::arch::sev::{SevPolicy, SnpPageType, SnpPolicy};
use crate::errors::{trace_error, DebugTrace};
use crate::errors::{DebugTrace, trace_error};

#[cfg(target_os = "macos")]
pub use self::hvf::Hvf;
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/hv/hvf/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bitflags! {
}

#[link(name = "Hypervisor", kind = "framework")]
extern "C" {
unsafe extern "C" {
pub fn hv_vm_create(config: *mut i32) -> i32;
pub fn hv_vm_destroy() -> i32;
pub fn hv_vcpu_create(vcpu: &mut u64, exit: &mut *mut HvVcpuExit, config: *mut c_void) -> i32;
Expand Down
3 changes: 2 additions & 1 deletion alioth/src/hv/hvf/hvf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::ptr::null_mut;
use parking_lot::Mutex;
use snafu::ResultExt;

use crate::hv::{error, Hypervisor, Result, VmConfig};
use crate::hv::{Hypervisor, Result, VmConfig, error};

use self::bindings::hv_vm_create;
use self::vm::HvfVm;
Expand Down Expand Up @@ -60,6 +60,7 @@ pub struct Hvf {}

impl Hypervisor for Hvf {
type Vm = HvfVm;

fn create_vm(&self, _config: &VmConfig) -> Result<Self::Vm> {
let ret = unsafe { hv_vm_create(null_mut()) };
check_ret(ret).context(error::CreateVm)?;
Expand Down
8 changes: 4 additions & 4 deletions alioth/src/hv/hvf/vcpu/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ use snafu::ResultExt;

use crate::arch::reg::{Reg, SReg};
use crate::hv::hvf::bindings::{
hv_vcpu_destroy, hv_vcpu_get_reg, hv_vcpu_get_sys_reg, hv_vcpu_run, hv_vcpu_set_reg,
hv_vcpu_set_sys_reg, HvExitReason, HvReg, HvVcpuExit,
HvExitReason, HvReg, HvVcpuExit, hv_vcpu_destroy, hv_vcpu_get_reg, hv_vcpu_get_sys_reg,
hv_vcpu_run, hv_vcpu_set_reg, hv_vcpu_set_sys_reg,
};
use crate::hv::hvf::check_ret;
use crate::hv::{error, Result, Vcpu, VmEntry, VmExit};
use crate::hv::{Result, Vcpu, VmEntry, VmExit, error};

#[derive(Debug)]
pub struct HvfVcpu {
Expand Down Expand Up @@ -165,7 +165,7 @@ mod test {
use std::ptr::null_mut;

use assert_matches::assert_matches;
use libc::{mmap, MAP_ANONYMOUS, MAP_FAILED, MAP_PRIVATE, PROT_READ, PROT_WRITE};
use libc::{MAP_ANONYMOUS, MAP_FAILED, MAP_PRIVATE, PROT_READ, PROT_WRITE, mmap};

use crate::arch::reg::Reg;
use crate::ffi;
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/hv/hvf/vcpu/vmentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::hv::VmExit;
use crate::hv::hvf::bindings::hv_vcpu_set_reg;
use crate::hv::hvf::check_ret;
use crate::hv::hvf::vcpu::HvfVcpu;
use crate::hv::VmExit;

impl HvfVcpu {
pub fn entry_mmio(&mut self, data: u64) {
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/hv/hvf/vcpu/vmexit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

use crate::arch::reg::{EsrEl2DataAbort, EsrEl2Ec, Reg};
use crate::hv::hvf::bindings::{hv_vcpu_get_reg, HvReg, HvVcpuExitException};
use crate::hv::hvf::bindings::{HvReg, HvVcpuExitException, hv_vcpu_get_reg};
use crate::hv::hvf::check_ret;
use crate::hv::hvf::vcpu::HvfVcpu;
use crate::hv::{Vcpu, VmExit};
Expand Down
Loading