Skip to content
Draft
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
10 changes: 1 addition & 9 deletions src/migtd/src/bin/migtd/cvmemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use alloc::vec::Vec;
use migtd;
use migtd::driver::vmcall_raw::panic_with_guest_crash_reg_report;
use migtd::migration::event;
use migtd::migration::logging::{
create_logarea, enable_logarea, init_vmm_logger, u8_to_levelfilter,
};
use migtd::migration::logging::{create_logarea, enable_logarea, init_vmm_logger};
use migtd::migration::session::{exchange_msk, report_status};
use migtd::migration::MigrationResult;

Expand Down Expand Up @@ -480,12 +478,6 @@ fn handle_pre_mig_emu() -> i32 {
.map(|_| MigrationResult::Success)
.unwrap_or_else(|e| e);

log::info!(migration_request_id = wfr_info.mig_request_id;
"Setting log level to {}\n",
wfr_info.log_max_level
);
log::set_max_level(u8_to_levelfilter(wfr_info.log_max_level));

if status == MigrationResult::Success {
log::trace!(migration_request_id = wfr_info.mig_request_id; "Successfully completed Enable LogArea\n");
} else {
Expand Down
6 changes: 0 additions & 6 deletions src/migtd/src/bin/migtd/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,12 +573,6 @@ fn handle_pre_mig() {
.map(|_| MigrationResult::Success)
.unwrap_or_else(|e| e);

log::info!( migration_request_id = wfr_info.mig_request_id;
"Setting log level to {}\n",
wfr_info.log_max_level
);
log::set_max_level(u8_to_levelfilter(wfr_info.log_max_level));

if status == MigrationResult::Success {
log::trace!(migration_request_id = wfr_info.mig_request_id; "Successfully completed Enable LogArea\n");
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/migtd/src/migration/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ pub async fn enable_logarea(log_max_level: u8, request_id: u64, data: &mut Vec<u
LOGGING_INFORMATION
.logarea_initialized
.store(true, Ordering::SeqCst);
// Keep the crate-global log gate in sync with the per-MigTD gate so
// both filters agree; only done on the validated success path.
log::set_max_level(u8_to_levelfilter(log_max_level));
#[cfg(not(test))]
log::info!( migration_request_id = request_id;
"enable_logarea: Logging has been enabled with MaxLevel: {}\n",
Expand All @@ -316,7 +319,7 @@ pub async fn enable_logarea(log_max_level: u8, request_id: u64, data: &mut Vec<u
Ok(())
} else {
log::error!( migration_request_id = request_id;
"enable_logarea: Logging has been enabled with MaxLevel: {}\n",
"enable_logarea: rejected request with invalid MaxLogLevel: {}\n",
log_max_level
);
data.extend_from_slice(
Expand Down
42 changes: 18 additions & 24 deletions src/migtd/src/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,6 @@ use r_efi::efi::Guid;
use rust_std_stub::io;
use scroll::{Pread, Pwrite};

/// Implement `read_from_bytes(data_length, payload)` for a fixed-size
/// `#[derive(Pread)]` struct. Validates `data_length == size_of::<Self>()`
/// and rejects payloads with trailing bytes.
#[cfg(feature = "vmcall-raw")]
macro_rules! impl_read_from_bytes {
($t:ty) => {
#[cfg(feature = "vmcall-raw")]
impl $t {
pub fn read_from_bytes(
data_length: u32,
payload: &[u8],
) -> core::result::Result<Self, MigrationResult> {
if data_length != core::mem::size_of::<Self>() as u32 {
return Err(MigrationResult::InvalidParameter);
}
payload
.pread(0)
.map_err(|_| MigrationResult::InvalidParameter)
}
}
};
}

/// Implement `read_from_bytes(data_length, payload)` for a struct whose layout
/// starts with `mig_request_id: u64` followed by optional data bytes.
/// Accepts either the full struct or just the `mig_request_id` (with the
Expand Down Expand Up @@ -239,7 +216,24 @@ pub struct EnableLogAreaInfo {
}

#[cfg(feature = "vmcall-raw")]
impl_read_from_bytes!(EnableLogAreaInfo);
impl EnableLogAreaInfo {
pub fn read_from_bytes(
data_length: u32,
payload: &[u8],
) -> core::result::Result<Self, MigrationResult> {
if data_length != core::mem::size_of::<Self>() as u32 {
return Err(MigrationResult::InvalidParameter);
}
let info: Self = payload
.pread(0)
.map_err(|_| MigrationResult::InvalidParameter)?;
// GHCI 1.5 v6 Table 3-50: reserved bytes MUST be zero.
if info.reserved.iter().any(|&b| b != 0) {
return Err(MigrationResult::InvalidParameter);
}
Ok(info)
}
}

#[repr(C)]
#[derive(Debug, Pread, Pwrite)]
Expand Down
Loading