Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to zerocopy 0.8 #454

Merged
merged 3 commits into from
Oct 15, 2024
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
39 changes: 31 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ log = "0.4.17"
p384 = { version = "0.13.0" }
uuid = "1.6.1"
# Add the derive feature by default because all crates use it.
zerocopy = { version = "0.7.32", features = ["derive"] }
zerocopy = { version = "0.8.2", features = ["alloc", "derive"] }

# other repos
packit = { git = "https://github.com/coconut-svsm/packit", version = "0.1.1" }
Expand Down
12 changes: 6 additions & 6 deletions bootlib/src/igvm_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
//! This crate provides definitions of IGVM parameters to be parsed by
//! COCONUT-SVSM to determine its configuration.

use zerocopy::AsBytes;
use zerocopy::{Immutable, IntoBytes};

/// The IGVM parameter page is an unmeasured page containing individual
/// parameters that are provided by the host loader.
#[repr(C, packed)]
#[derive(AsBytes, Clone, Copy, Debug, Default)]
#[derive(IntoBytes, Clone, Copy, Debug, Default)]
pub struct IgvmParamPage {
/// The number of vCPUs that are configured for the guest VM.
pub cpu_count: u32,
Expand All @@ -26,7 +26,7 @@ pub struct IgvmParamPage {
/// An entry that represents an area of pre-validated memory defined by the
/// firmware in the IGVM file.
#[repr(C, packed)]
#[derive(AsBytes, Clone, Copy, Debug, Default)]
#[derive(IntoBytes, Immutable, Clone, Copy, Debug, Default)]
pub struct IgvmParamBlockFwMem {
/// The base physical address of the prevalidated memory region.
pub base: u32,
Expand All @@ -38,7 +38,7 @@ pub struct IgvmParamBlockFwMem {
/// The portion of the IGVM parameter block that describes metadata about
/// the firmware image embedded in the IGVM file.
#[repr(C, packed)]
#[derive(AsBytes, Clone, Copy, Debug, Default)]
#[derive(IntoBytes, Immutable, Clone, Copy, Debug, Default)]
pub struct IgvmParamBlockFwInfo {
/// The guest physical address of the start of the guest firmware. The
/// permissions on the pages in the firmware range are adjusted to the guest
Expand Down Expand Up @@ -88,7 +88,7 @@ pub struct IgvmParamBlockFwInfo {
/// builder which describes where the additional IGVM parameter information
/// has been placed into the guest address space.
#[repr(C, packed)]
#[derive(AsBytes, Clone, Copy, Debug, Default)]
#[derive(IntoBytes, Immutable, Clone, Copy, Debug, Default)]
pub struct IgvmParamBlock {
/// The total size of the parameter area, beginning with the parameter
/// block itself and including any additional parameter pages which follow.
Expand Down Expand Up @@ -145,7 +145,7 @@ pub struct IgvmParamBlock {
/// The IGVM context page is a measured page that is used to specify the start
/// context for the guest VMPL. If present, it overrides the processor state
/// initialized at reset.
#[derive(AsBytes, Copy, Debug, Clone, Default)]
#[derive(IntoBytes, Immutable, Copy, Debug, Clone, Default)]
#[repr(C, packed)]
pub struct IgvmGuestContext {
pub cr0: u64,
Expand Down
4 changes: 2 additions & 2 deletions bootlib/src/kernel_launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use crate::platform::SvsmPlatformType;

use zerocopy::AsBytes;
use zerocopy::{Immutable, IntoBytes};

#[derive(Copy, Clone, Debug)]
#[repr(C)]
Expand Down Expand Up @@ -46,7 +46,7 @@ impl KernelLaunchInfo {
// Stage 2 launch info from stage1
// The layout has to match the order in which the parts are pushed to the stack
// in stage1/stage1.S
#[derive(AsBytes, Default, Debug, Clone, Copy)]
#[derive(IntoBytes, Immutable, Default, Debug, Clone, Copy)]
#[repr(C, packed)]
pub struct Stage2LaunchInfo {
// VTOM must be the first field.
Expand Down
1 change: 1 addition & 0 deletions cpuarch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"

[dependencies]
bitfield-struct.workspace = true
zerocopy.workspace = true

[lints]
workspace = true
14 changes: 10 additions & 4 deletions cpuarch/src/vmsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
//
// Author: Joerg Roedel <[email protected]>

#![allow(non_camel_case_types)]

use bitfield_struct::bitfield;
use zerocopy::FromZeros;

// AE Exitcodes
// Table 15-35, AMD64 Architecture Programmer’s Manual, Vol. 2
#[repr(u64)]
#[derive(Clone, Copy, Default, Debug)]
#[allow(dead_code, non_camel_case_types)]
#[derive(Clone, Copy, Default, Debug, FromZeros)]
#[allow(dead_code)]
pub enum GuestVMExit {
CR0_READ = 0,
MC = 0x52,
INTR = 0x60,
NMI = 0x61,
Expand Down Expand Up @@ -46,6 +50,7 @@ pub enum GuestVMExit {
}

#[bitfield(u64)]
#[derive(FromZeros)]
pub struct VIntrCtrl {
pub v_tpr: u8,
pub v_irq: bool,
Expand Down Expand Up @@ -92,6 +97,7 @@ impl VmsaEventType {
}

#[bitfield(u64)]
#[derive(FromZeros)]
pub struct VmsaEventInject {
pub vector: u8,
#[bits(3)]
Expand All @@ -104,7 +110,7 @@ pub struct VmsaEventInject {
}

#[repr(C, packed)]
#[derive(Debug, Default, Clone, Copy)]
#[derive(Debug, Default, Clone, Copy, FromZeros)]
pub struct VMSASegment {
pub selector: u16,
pub flags: u16,
Expand All @@ -113,7 +119,7 @@ pub struct VMSASegment {
}

#[repr(C, packed)]
#[derive(Debug)]
#[derive(Debug, FromZeros)]
pub struct VMSA {
pub es: VMSASegment,
pub cs: VMSASegment,
Expand Down
1 change: 1 addition & 0 deletions igvmbuilder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ igvm_defs.workspace = true
igvm.workspace = true
uuid.workspace = true
zerocopy.workspace = true
zerocopy07 = { package = "zerocopy", version = "0.7" }

[lints]
workspace = true
6 changes: 3 additions & 3 deletions igvmbuilder/src/cpuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use std::mem::size_of;

use igvm::IgvmDirectiveHeader;
use igvm_defs::{IgvmPageDataFlags, IgvmPageDataType, PAGE_SIZE_4K};
use zerocopy::AsBytes;
use zerocopy::{Immutable, IntoBytes};

#[repr(C, packed(1))]
#[derive(AsBytes, Copy, Clone, Default)]
#[derive(IntoBytes, Immutable, Copy, Clone, Default)]
struct SnpCpuidLeaf {
eax_in: u32,
ecx_in: u32,
Expand Down Expand Up @@ -56,7 +56,7 @@ impl SnpCpuidLeaf {
}

#[repr(C, packed(1))]
#[derive(AsBytes)]
#[derive(IntoBytes, Immutable)]
pub struct SnpCpuidPage {
count: u32,
reserved: [u32; 3],
Expand Down
2 changes: 1 addition & 1 deletion igvmbuilder/src/igvm_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use igvm_defs::{
IgvmNativeVpContextX64, IgvmPageDataFlags, IgvmPageDataType, IgvmPlatformType,
IGVM_VHS_PARAMETER, IGVM_VHS_PARAMETER_INSERT, IGVM_VHS_SUPPORTED_PLATFORM, PAGE_SIZE_4K,
};
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

use crate::cmd_options::{CmdOptions, Hypervisor};
use crate::cpuid::SnpCpuidPage;
Expand Down
2 changes: 1 addition & 1 deletion igvmbuilder/src/igvm_firmware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use igvm_defs::{
IgvmPageDataType, IgvmVariableHeaderType, IGVM_VHS_PARAMETER, IGVM_VHS_PARAMETER_INSERT,
PAGE_SIZE_4K,
};
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

use crate::firmware::Firmware;

Expand Down
2 changes: 1 addition & 1 deletion igvmbuilder/src/stage2_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use bootlib::kernel_launch::Stage2LaunchInfo;
use bootlib::platform::SvsmPlatformType;
use igvm::IgvmDirectiveHeader;
use igvm_defs::{IgvmPageDataFlags, IgvmPageDataType, PAGE_SIZE_4K};
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

use crate::gpa_map::GpaMap;
use crate::igvm_builder::{
Expand Down
2 changes: 1 addition & 1 deletion igvmbuilder/src/vmsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use igvm::snp_defs::{SevFeatures, SevVmsa};
use igvm::IgvmDirectiveHeader;
use igvm_defs::IgvmNativeVpContextX64;
use zerocopy::FromZeroes;
use zerocopy07::FromZeroes;

use crate::cmd_options::SevExtraFeatures;

Expand Down
2 changes: 2 additions & 0 deletions igvmmeasure/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ igvm.workspace = true
igvm_defs.workspace = true
p384.workspace = true
zerocopy.workspace = true
# igvm_defs still uses 0.7, so we need to import the zerocopy 0.7 traits to use them.
zerocopy07 = { package = "zerocopy", version = "0.7" }

[lints]
workspace = true
5 changes: 3 additions & 2 deletions igvmmeasure/src/id_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ use p384::ecdsa::signature::Signer;
use p384::ecdsa::{Signature, SigningKey};
use p384::elliptic_curve::bigint::ArrayEncoding;
use p384::{EncodedPoint, SecretKey};
use zerocopy::{AsBytes, FromZeroes};
use zerocopy::{Immutable, IntoBytes};
use zerocopy07::FromZeroes;

use crate::igvm_measure::IgvmMeasure;
use crate::utils::{get_compatibility_mask, get_policy};

#[repr(C, packed)]
#[derive(AsBytes, Clone, Copy, Debug)]
#[derive(IntoBytes, Immutable, Clone, Copy, Debug)]
pub struct SevIdBlock {
pub ld: [u8; 48],
pub family_id: [u8; 16],
Expand Down
2 changes: 1 addition & 1 deletion igvmmeasure/src/igvm_measure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use igvm::snp_defs::SevVmsa;
use igvm::{IgvmDirectiveHeader, IgvmFile};
use igvm_defs::{IgvmPageDataFlags, IgvmPageDataType, IgvmPlatformType, PAGE_SIZE_4K};
use sha2::{Digest, Sha256};
use zerocopy::AsBytes;
use zerocopy07::AsBytes;

use crate::page_info::PageInfo;

Expand Down
2 changes: 1 addition & 1 deletion igvmmeasure/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use igvm::IgvmFile;
use igvm_defs::IgvmPlatformType;
use igvm_measure::IgvmMeasure;
use utils::get_compatibility_mask;
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

use crate::id_block::SevIdBlockBuilder;

Expand Down
6 changes: 3 additions & 3 deletions igvmmeasure/src/page_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// Author: Roy Hopkins <[email protected]>

use sha2::{Digest, Sha384};
use zerocopy::AsBytes;
use zerocopy::{Immutable, IntoBytes};

#[repr(u8)]
#[derive(AsBytes, Debug, Copy, Clone)]
#[derive(IntoBytes, Immutable, Debug, Copy, Clone)]
pub enum PageType {
Normal = 1,
Vmsa = 2,
Expand All @@ -19,7 +19,7 @@ pub enum PageType {
}

#[repr(C, packed)]
#[derive(AsBytes, Debug, Copy, Clone)]
#[derive(IntoBytes, Immutable, Debug, Copy, Clone)]
pub struct PageInfo {
digest_cur: [u8; 48],
contents: [u8; 48],
Expand Down
Loading
Loading