Skip to content

Commit

Permalink
Apply clippy suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Jiaqi Gao <[email protected]>
  • Loading branch information
gaojiaqi7 committed Mar 5, 2025
1 parent 9034e09 commit e4ea97b
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 1,027 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

14 changes: 7 additions & 7 deletions src/crypto/src/x509.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl<'a> Decode<'a> for Version<'a> {
}
}

impl<'a> Encode for Version<'a> {
impl Encode for Version<'_> {
fn encoded_len(&self) -> der::Result<der::Length> {
let len = self.0.encoded_len()?;
let explicit = Header::new(
Expand All @@ -234,7 +234,7 @@ impl<'a> Encode for Version<'a> {
}
}

impl<'a> Tagged for Version<'a> {
impl Tagged for Version<'_> {
fn tag(&self) -> Tag {
Tag::ContextSpecific {
constructed: true,
Expand Down Expand Up @@ -265,7 +265,7 @@ pub struct DistinguishedName<'a> {
value: AnyRef<'a>,
}

impl<'a> DerOrd for DistinguishedName<'a> {
impl DerOrd for DistinguishedName<'_> {
fn der_cmp(&self, other: &Self) -> der::Result<core::cmp::Ordering> {
Ok(self.attribute_type.cmp(&other.attribute_type))
}
Expand Down Expand Up @@ -317,7 +317,7 @@ impl<'a, const N: u8> Decode<'a> for UniqueIdentifier<'a, N> {
}
}

impl<'a, const N: u8> Encode for UniqueIdentifier<'a, N> {
impl<const N: u8> Encode for UniqueIdentifier<'_, N> {
fn encoded_len(&self) -> der::Result<der::Length> {
let len = self.0.encoded_len()?;
let explicit = Header::new(
Expand All @@ -344,7 +344,7 @@ impl<'a, const N: u8> Encode for UniqueIdentifier<'a, N> {
}
}

impl<'a, const N: u8> Tagged for UniqueIdentifier<'a, N> {
impl<const N: u8> Tagged for UniqueIdentifier<'_, N> {
fn tag(&self) -> Tag {
Tag::ContextSpecific {
constructed: true,
Expand Down Expand Up @@ -380,7 +380,7 @@ impl<'a> Decode<'a> for Extensions<'a> {
}
}

impl<'a> Encode for Extensions<'a> {
impl Encode for Extensions<'_> {
fn encoded_len(&self) -> der::Result<der::Length> {
let len = self.0.encoded_len()?;
let explicit = Header::new(
Expand All @@ -407,7 +407,7 @@ impl<'a> Encode for Extensions<'a> {
}
}

impl<'a> Tagged for Extensions<'a> {
impl Tagged for Extensions<'_> {
fn tag(&self) -> Tag {
Tag::ContextSpecific {
constructed: true,
Expand Down
1 change: 0 additions & 1 deletion src/devices/pci/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ pub fn find_device(vendor_id: u16, device_id: u16) -> Option<(u8, u8, u8)> {
}

/// Configure Space Access Mechanism #1
/// 32-bit I/O locations CONFIG_ADDRESS (0xCF8)
/// 0-7 register offset
/// 8-10 funtion number
Expand Down
3 changes: 1 addition & 2 deletions src/devices/virtio_serial/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,8 @@ impl VirtioSerial {
}
}

self.pop_used_rx(port_id).map_err(|e| {
self.pop_used_rx(port_id).inspect(|_| {
self.timer.reset_timeout();
e
})?;
if let Some(data) = Self::port_queue_pop(port_id) {
self.timer.reset_timeout();
Expand Down
1 change: 0 additions & 1 deletion src/devices/vsock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"
[dependencies]
atomic_refcell = "0.1.7"
byteorder = { version = "1.0", default-features = false }
cfg-if = "1.0"
conquer-once = { version = "0.3.2", default-features = false }
pci = { path = "../pci" }
virtio = { path = "../virtio", default-features = false }
Expand Down
18 changes: 8 additions & 10 deletions src/devices/vsock/src/transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: BSD-2-Clause-Patent

use cfg_if::cfg_if;
use core::fmt::{self, Display};
use rust_std_stub::error;
#[cfg(feature = "vmcall-vsock")]
Expand All @@ -11,15 +10,14 @@ use tdx_tdcall::TdVmcallError;
use virtio::VirtioError;

mod event;
cfg_if! {
if #[cfg(feature = "vmcall-vsock")] {
mod vmcall;
pub use vmcall::*;
} else if #[cfg(feature = "virtio-vsock")] {
mod virtio_pci;
pub use virtio_pci::*;
}
}
#[cfg(feature = "vmcall-vsock")]
mod vmcall;
#[cfg(feature = "vmcall-vsock")]
pub use vmcall::*;
#[cfg(feature = "virtio-vsock")]
mod virtio_pci;
#[cfg(feature = "virtio-vsock")]
pub use virtio_pci::*;

type Result<T> = core::result::Result<T, VsockTransportError>;

Expand Down
10 changes: 4 additions & 6 deletions src/devices/vsock/src/transport/vmcall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl VmcallVsock {

self.timer.set_timeout(timeout);
tdx::tdvmcall_service(command, response, VMCALL_VECTOR as u64, timeout)
.map_err(|e| VsockTransportError::Vmcall(e))?;
.map_err(VsockTransportError::Vmcall)?;

if !wait_for_event(&VMCALL_FLAG, self.timer.as_ref()) {
return Err(VsockTransportError::Timeout);
Expand Down Expand Up @@ -171,7 +171,7 @@ impl VmcallVsock {

self.timer.set_timeout(timeout);
tdx::tdvmcall_service(command, response, VMCALL_VECTOR as u64, timeout)
.map_err(|e| VsockTransportError::Vmcall(e))?;
.map_err(VsockTransportError::Vmcall)?;

// TO DO:
// Refactor the waiting logic
Expand Down Expand Up @@ -270,10 +270,9 @@ impl VsockTransport for VmcallVsock {

// Request sending out the message
self.vmcall_service_migtd_send(command, response, hdr, buf, timeout)
.map(|res| {
.inspect(|_| {
self.free_dma(command);
self.free_dma(response);
res
})
}

Expand All @@ -292,10 +291,9 @@ impl VsockTransport for VmcallVsock {
};

self.vmcall_service_migtd_receive(command, response, &stream.addr(), timeout)
.map(|res| {
.inspect(|_| {
self.free_dma(command);
self.free_dma(response);
res
})
}

Expand Down
36 changes: 21 additions & 15 deletions src/migtd/src/bin/migtd/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use migtd::{config, event_log, migration};

const MIGTD_VERSION: &str = env!("CARGO_PKG_VERSION");

// Event IDs that will be used to tag the event log
const TAGGED_EVENT_ID_POLICY: u32 = 0x1;
const TAGGED_EVENT_ID_ROOT_CA: u32 = 0x2;
#[cfg(feature = "test_disable_ra_and_accept_all")]
const TAGGED_EVENT_ID_TEST: u32 = 0x32;

#[no_mangle]
Expand All @@ -33,29 +33,33 @@ pub fn runtime_main() {
// Dump basic information of MigTD
basic_info();

// Measure the input data
do_measurements();

// Handle the migration request from VMM
handle_pre_mig();
}

fn basic_info() {
info!("MigTD Version - {}\n", MIGTD_VERSION);
}

fn do_measurements() {
// Get the event log recorded by firmware
let event_log = event_log::get_event_log_mut().expect("Failed to get the event log");

#[cfg(feature = "test_disable_ra_and_accept_all")]
measure_test_feature(event_log);
if cfg!(feature = "test_disable_ra_and_accept_all") {
measure_test_feature(event_log);
return;
}

// Get migration td policy from CFV and measure it into RMTR
#[cfg(not(feature = "test_disable_ra_and_accept_all"))]
get_policy_and_measure(event_log);

// Get root certificate from CFV and measure it into RMTR
#[cfg(not(feature = "test_disable_ra_and_accept_all"))]
get_ca_and_measure(event_log);

// Handle the migration request from VMM
handle_pre_mig();
}

fn basic_info() {
info!("MigTD Version - {}\n", MIGTD_VERSION);
}

#[cfg(feature = "test_disable_ra_and_accept_all")]
fn measure_test_feature(event_log: &mut [u8]) {
// Measure and extend the migtd test feature to RTMR
event_log::write_tagged_event_log(
Expand Down Expand Up @@ -111,6 +115,10 @@ fn handle_pre_mig() {
.map(|_| MigrationResult::Success)
.unwrap_or_else(|e| e);
let _ = session.report_status(status as u8);

#[cfg(any(feature = "test_stack_size", feature = "test_heap_size"))]
test_memory();

#[cfg(all(feature = "coverage", feature = "tdx"))]
{
const MAX_COVERAGE_DATA_PAGE_COUNT: usize = 0x200;
Expand All @@ -129,8 +137,6 @@ fn handle_pre_mig() {

loop {}
}
#[cfg(any(feature = "test_stack_size", feature = "test_heap_size"))]
test_memory()
};
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/migtd/src/driver/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use core::sync::atomic::{AtomicBool, Ordering};
use td_payload::arch::apic::*;
use td_payload::arch::idt::{register_interrupt_callback, InterruptCallback, InterruptStack};

/// A simple apic timer notification handler used to handle the
/// time out events
// A simple apic timer notification handler used to handle the
// time out events
static TIMEOUT_FLAG: AtomicBool = AtomicBool::new(false);

const TIMEOUT_VECTOR: u8 = 33;
Expand Down
1 change: 1 addition & 0 deletions src/migtd/src/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

pub mod data;
pub mod event;
#[cfg(feature = "main")]
pub mod session;

use crate::ratls::RatlsError;
Expand Down
2 changes: 0 additions & 2 deletions src/migtd/src/migration/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ impl MigrationSession {
}
}

#[cfg(feature = "main")]
pub fn op(&mut self) -> Result<()> {
match &self.state {
MigrationState::Operate(operation) => match operation {
Expand Down Expand Up @@ -324,7 +323,6 @@ impl MigrationSession {
Ok(())
}

#[cfg(feature = "main")]
fn migrate(info: &MigrationInformation) -> Result<()> {
let mut msk = MigrationSessionKey::new();

Expand Down
Loading

0 comments on commit e4ea97b

Please sign in to comment.