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
6 changes: 3 additions & 3 deletions alioth-cli/src/boot/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ fn create<H: Hypervisor>(hypervisor: &H, config: Config) -> Result<Machine<H>, a
#[cfg(target_os = "linux")]
NetParam::Vu(sock) => {
let param = VuFrontendParam {
id: DeviceId::Net,
id: DeviceId::NET,
socket: sock.socket,
};
vm.add_virtio_dev(format!("vu-net-{index}"), param)
Expand All @@ -391,7 +391,7 @@ fn create<H: Hypervisor>(hypervisor: &H, config: Config) -> Result<Machine<H>, a
#[cfg(target_os = "linux")]
BlkParam::Vu(s) => {
let p = VuFrontendParam {
id: DeviceId::Block,
id: DeviceId::BLOCK,
socket: s.socket,
};
vm.add_virtio_dev(format!("vu-net-{index}"), p)
Expand All @@ -415,7 +415,7 @@ fn create<H: Hypervisor>(hypervisor: &H, config: Config) -> Result<Machine<H>, a
#[cfg(target_os = "linux")]
VsockParam::Vu(s) => {
let p = VuFrontendParam {
id: DeviceId::Socket,
id: DeviceId::SOCKET,
socket: s.socket,
};
vm.add_virtio_dev("vu-vsock", p)
Expand Down
37 changes: 19 additions & 18 deletions alioth/src/arch/x86_64/sev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,25 @@ bitfield! {
pub ciphertext_hiding, set_ciphertext_hiding: 24;
}

/// AMD SEV-SNP launch update page type.
///
/// From SEV SNP Firmware ABI Specification, Revision 1.55, Table 67.
#[repr(u8)]
#[derive(Debug, Clone, Copy)]
pub enum SnpPageType {
/// A normal data page.
Normal = 1,
/// A VMSA page.
Vmsa = 2,
/// A page full of zeros.
Zero = 3,
/// A page that is encrypted but not measured.
Unmeasured = 4,
/// A page for the firmware to store secrets for the guest.
Secrets = 5,
/// A page for the hypervisor to provide CPUID function values.
Cpuid = 6,
consts! {
/// AMD SEV-SNP launch update page type.
///
/// From SEV SNP Firmware ABI Specification, Revision 1.55, Table 67.
#[derive(Default)]
pub struct SnpPageType(u8) {
/// A normal data page.
NORMAL = 1;
/// A VMSA page.
VMSA = 2;
/// A page full of zeros.
ZERO = 3;
/// A page that is encrypted but not measured.
UNMEASURED = 4;
/// A page for the firmware to store secrets for the guest.
SECRETS = 5;
/// A page for the hypervisor to provide CPUID function values.
CPUID = 6;
}
}

#[repr(C, packed)]
Expand Down
8 changes: 4 additions & 4 deletions alioth/src/board/board_x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@ where
let ram = ram_bus.lock_layout();
let (desc, _) = SevMetadataDesc::read_from_prefix(&fw_range[offset..]).unwrap();
let snp_page_type = match desc.type_ {
SevDescType::SNP_DESC_MEM => SnpPageType::Unmeasured,
SevDescType::SNP_SECRETS => SnpPageType::Secrets,
SevDescType::SNP_DESC_MEM => SnpPageType::UNMEASURED,
SevDescType::SNP_SECRETS => SnpPageType::SECRETS,
SevDescType::CPUID => {
assert!(desc.len as usize >= size_of::<SnpCpuidInfo>());
assert!(cpuid_table.entries.len() >= self.arch.cpuids.len());
cpuid_table.count = self.arch.cpuids.len() as u32;
self.fill_snp_cpuid(&mut cpuid_table.entries);
ram.write_t(desc.base as _, &cpuid_table)?;
SnpPageType::Cpuid
SnpPageType::CPUID
}
_ => unimplemented!(),
};
Expand Down Expand Up @@ -309,7 +309,7 @@ where
self.memory
.mark_private_memory(fw_gpa, fw_range.len() as _, true)?;
self.vm
.snp_launch_update(fw_range, fw_gpa, SnpPageType::Normal)
.snp_launch_update(fw_range, fw_gpa, SnpPageType::NORMAL)
.unwrap();
}
Coco::IntelTdx { attr } => todo!("Intel TDX {attr:?}"),
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/hv/kvm/vm/vm_x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl KvmVm {
uaddr: range.as_mut_ptr() as _,
len: range.len() as _,
gfn_start: gpa >> 12,
type_: type_ as _,
type_,
..Default::default()
};
self.sev_op(KvmSevCmdId::SNP_LAUNCH_UPDATE, Some(&mut update))?;
Expand Down
4 changes: 2 additions & 2 deletions alioth/src/sys/linux/sev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::arch::sev::{SevPolicy, SevStatus, SnpPolicy};
use crate::arch::sev::{SevPolicy, SevStatus, SnpPageType, SnpPolicy};
use crate::{consts, ioctl_writeread};

consts! {
Expand Down Expand Up @@ -206,7 +206,7 @@ pub struct KvmSevSnpLaunchUpdate {
pub gfn_start: u64,
pub uaddr: u64,
pub len: u64,
pub type_: u8,
pub type_: SnpPageType,
pub pad0: u8,
pub flags: u16,
pub pad1: u32,
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/virtio/dev/balloon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl Virtio for Balloon {
type Feature = BalloonFeature;

fn id(&self) -> DeviceId {
DeviceId::Balloon
DeviceId::BALLOON
}

fn name(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/virtio/dev/blk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl Virtio for Block {
type Feature = BlockFeature;

fn id(&self) -> DeviceId {
DeviceId::Block
DeviceId::BLOCK
}

fn name(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/virtio/dev/entropy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl Virtio for Entropy {
type Feature = EntropyFeature;

fn id(&self) -> DeviceId {
DeviceId::Entropy
DeviceId::ENTROPY
}

fn name(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/virtio/dev/entropy_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn entropy_test(fixture_ram_bus: RamBus, fixture_queues: Box<[QueueReg]>) {
};
let dev = param.build("entropy").unwrap();

assert_matches!(dev.id(), DeviceId::Entropy);
assert_matches!(dev.id(), DeviceId::ENTROPY);
assert_eq!(dev.name(), "entropy");
assert_eq!(dev.num_queues(), 1);
assert_matches!(*dev.config(), EntropyConfig);
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/virtio/dev/fs/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ where
type Feature = FsFeature;

fn id(&self) -> DeviceId {
DeviceId::FileSystem
DeviceId::FILE_SYSTEM
}

fn name(&self) -> &str {
Expand Down
4 changes: 2 additions & 2 deletions alioth/src/virtio/dev/fs/vu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl VuFs {
if param.tag.is_none() {
extra_features |= VuFeature::CONFIG;
}
let frontend = VuFrontend::new(name, &param.socket, DeviceId::FileSystem, extra_features)?;
let frontend = VuFrontend::new(name, &param.socket, DeviceId::FILE_SYSTEM, extra_features)?;
let config = if let Some(tag) = param.tag {
assert!(tag.len() <= 36);
assert_ne!(tag.len(), 0);
Expand Down Expand Up @@ -131,7 +131,7 @@ impl Virtio for VuFs {
type Feature = FsFeature;

fn id(&self) -> DeviceId {
DeviceId::FileSystem
DeviceId::FILE_SYSTEM
}

fn name(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/virtio/dev/net/tap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl Virtio for Net {
type Feature = NetFeature;

fn id(&self) -> DeviceId {
DeviceId::Net
DeviceId::NET
}

fn name(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/virtio/dev/net/vmnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl Virtio for Net {
type Feature = NetFeature;

fn id(&self) -> DeviceId {
DeviceId::Net
DeviceId::NET
}

fn name(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/virtio/dev/vsock/uds_vsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ impl Virtio for UdsVsock {
type Feature = VsockFeature;

fn id(&self) -> DeviceId {
DeviceId::Socket
DeviceId::SOCKET
}

fn name(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/virtio/dev/vsock/uds_vsock_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn vsock_conn_test(fixture_ram_bus: RamBus, #[with(3)] fixture_queues: Box<[Queu
};
let dev = param.build("vsock").unwrap();

assert_matches!(dev.id(), DeviceId::Socket);
assert_matches!(dev.id(), DeviceId::SOCKET);
assert_eq!(dev.name(), "vsock");
assert_eq!(dev.num_queues(), 3);
assert_eq!(dev.config().guest_cid, GUEST_CID as u32);
Expand Down
2 changes: 1 addition & 1 deletion alioth/src/virtio/dev/vsock/vhost_vsock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Virtio for VhostVsock {
type Feature = VsockFeature;

fn id(&self) -> DeviceId {
DeviceId::Socket
DeviceId::SOCKET
}

fn name(&self) -> &str {
Expand Down
46 changes: 24 additions & 22 deletions alioth/src/virtio/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use crate::utils::{get_atomic_high32, get_atomic_low32, set_atomic_high32, set_a
use crate::virtio::dev::{Register, StartParam, VirtioDevice, WakeEvent};
use crate::virtio::queue::QueueReg;
use crate::virtio::{DevStatus, DeviceId, IrqSender, Result, error};
use crate::{impl_mmio_for_zerocopy, mem};
use crate::{consts, impl_mmio_for_zerocopy, mem};

const VIRTIO_MSI_NO_VECTOR: u16 = 0xffff;

Expand Down Expand Up @@ -576,31 +576,33 @@ const VIRTIO_DEVICE_ID_BASE: u16 = 0x1040;

fn get_class(id: DeviceId) -> (u8, u8) {
match id {
DeviceId::Net => (0x02, 0x00),
DeviceId::FileSystem => (0x01, 0x80),
DeviceId::Block => (0x01, 0x00),
DeviceId::Socket => (0x02, 0x80),
DeviceId::NET => (0x02, 0x00),
DeviceId::FILE_SYSTEM => (0x01, 0x80),
DeviceId::BLOCK => (0x01, 0x00),
DeviceId::SOCKET => (0x02, 0x80),
_ => (0xff, 0x00),
}
}

#[repr(u8)]
pub enum VirtioPciCfg {
Common = 1,
Notify = 2,
Isr = 3,
Device = 4,
Pci = 5,
SharedMemory = 8,
Vendor = 9,
consts! {
#[derive(Default, FromZeros, Immutable, IntoBytes)]
pub struct VirtioPciCfg(u8) {
COMMON = 1;
NOTIFY = 2;
ISR = 3;
DEVICE = 4;
PCI = 5;
SHARED_MEMORY = 8;
VENDOR = 9;
}
}

#[repr(C, align(4))]
#[derive(Debug, Default, FromZeros, Immutable, IntoBytes)]
pub struct VirtioPciCap {
header: PciCapHdr,
cap_len: u8,
cfg_type: u8,
cfg_type: VirtioPciCfg,
bar: u8,
id: u8,
padding: [u8; 2],
Expand Down Expand Up @@ -690,14 +692,14 @@ where
let mut header = DeviceHeader {
common: CommonHeader {
vendor: VIRTIO_VENDOR_ID,
device: VIRTIO_DEVICE_ID_BASE + dev.id as u16,
device: VIRTIO_DEVICE_ID_BASE + dev.id.raw(),
revision: 0x1,
header_type: HeaderType::DEVICE,
class,
subclass,
..Default::default()
},
subsystem: VIRTIO_DEVICE_ID_BASE + dev.id as u16,
subsystem: VIRTIO_DEVICE_ID_BASE + dev.id.raw(),
..Default::default()
};
let device_config = dev.device_config.clone();
Expand Down Expand Up @@ -730,7 +732,7 @@ where
..Default::default()
},
cap_len: size_of::<VirtioPciCap>() as u8,
cfg_type: VirtioPciCfg::Common as u8,
cfg_type: VirtioPciCfg::COMMON,
bar: 0,
id: 0,
offset: (virtio_register_offset + VirtioPciRegister::OFFSET_COMMON) as u32,
Expand All @@ -743,7 +745,7 @@ where
..Default::default()
},
cap_len: size_of::<VirtioPciCap>() as u8,
cfg_type: VirtioPciCfg::Isr as u8,
cfg_type: VirtioPciCfg::ISR,
bar: 0,
id: 0,
offset: (virtio_register_offset + VirtioPciRegister::OFFSET_ISR_STATUS) as u32,
Expand All @@ -757,7 +759,7 @@ where
..Default::default()
},
cap_len: size_of::<VirtioPciNotifyCap>() as u8,
cfg_type: VirtioPciCfg::Notify as u8,
cfg_type: VirtioPciCfg::NOTIFY,
bar: 0,
id: 0,
offset: (virtio_register_offset + VirtioPciRegister::OFFSET_QUEUE_NOTIFY) as u32,
Expand All @@ -772,7 +774,7 @@ where
..Default::default()
},
cap_len: size_of::<VirtioPciCap>() as u8,
cfg_type: VirtioPciCfg::Device as u8,
cfg_type: VirtioPciCfg::DEVICE,
bar: 0,
id: 0,
offset: device_config_offset as u32,
Expand Down Expand Up @@ -814,7 +816,7 @@ where
..Default::default()
},
cap_len: size_of::<VirtioPciCap64>() as u8,
cfg_type: VirtioPciCfg::SharedMemory as u8,
cfg_type: VirtioPciCfg::SHARED_MEMORY,
bar: 2,
id: index as u8,
offset: offset as u32,
Expand Down
25 changes: 13 additions & 12 deletions alioth/src/virtio/virtio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use std::path::Path;

use snafu::Snafu;

use crate::bitflags;
use crate::errors::{DebugTrace, trace_error};
use crate::{bitflags, consts};

#[trace_error]
#[derive(Snafu, DebugTrace)]
Expand Down Expand Up @@ -99,17 +99,18 @@ const FEATURE_BUILT_IN: u128 = VirtioFeature::EVENT_IDX.bits()
| VirtioFeature::RING_PACKED.bits()
| VirtioFeature::VERSION_1.bits();

#[derive(Debug, Clone, Copy)]
pub enum DeviceId {
Net = 1,
Block = 2,
Entropy = 4,
Balloon = 5,
Socket = 19,
Iommu = 23,
Mem = 24,
FileSystem = 26,
Pmem = 27,
consts! {
pub struct DeviceId(u16) {
NET = 1;
BLOCK = 2;
ENTROPY = 4;
BALLOON = 5;
SOCKET = 19;
IOMMU = 23;
MEM = 24;
FILE_SYSTEM = 26;
PMEM = 27;
}
}

bitflags! {
Expand Down