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 rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# allowlisted using a toolchain that requires it, causing the A/B-test to
# always fail.
[toolchain]
channel = "1.87.0"
channel = "1.89.0"
targets = ["x86_64-unknown-linux-musl", "aarch64-unknown-linux-musl"]
profile = "minimal"

12 changes: 6 additions & 6 deletions src/firecracker/src/api_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ impl ApiServer {
let vmm_outcome = *(self.vmm_response_receiver.recv().expect("VMM disconnected"));
let response = ParsedRequest::convert_to_response(&vmm_outcome);

if vmm_outcome.is_ok() {
if let Some((metric, action)) = metric_with_action {
let elapsed_time_us =
update_metric_with_elapsed_time(metric, request_processing_start_us);
info!("'{}' API request took {} us.", action, elapsed_time_us);
}
if vmm_outcome.is_ok()
&& let Some((metric, action)) = metric_with_action
{
let elapsed_time_us =
update_metric_with_elapsed_time(metric, request_processing_start_us);
info!("'{}' API request took {} us.", action, elapsed_time_us);
}
response
}
Expand Down
10 changes: 5 additions & 5 deletions src/utils/src/arg_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'a> ArgParser<'a> {
}

/// Return a reference to `arguments` field.
pub fn arguments(&self) -> &Arguments {
pub fn arguments(&self) -> &Arguments<'_> {
&self.arguments
}

Expand Down Expand Up @@ -368,10 +368,10 @@ impl<'a> Arguments<'a> {
if argument.user_value.is_some() {
// For the arguments that require a specific argument to be also present in the list
// of arguments provided by user, search for that argument.
if let Some(arg_name) = argument.requires {
if !args.contains(&(format!("--{}", arg_name))) {
return Err(UtilsArgParserError::MissingArgument(arg_name.to_string()));
}
if let Some(arg_name) = argument.requires
&& !args.contains(&(format!("--{}", arg_name)))
{
return Err(UtilsArgParserError::MissingArgument(arg_name.to_string()));
}
// Check the user-provided list for potential forbidden arguments.
for arg_name in argument.forbids.iter() {
Expand Down
8 changes: 4 additions & 4 deletions src/vmm/src/arch/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ fn get_fdt_addr(mem: &GuestMemoryMmap) -> u64 {
// we return the start of the DRAM so that
// we allow the code to try and load the FDT.

if let Some(addr) = mem.last_addr().checked_sub(layout::FDT_MAX_SIZE as u64 - 1) {
if mem.address_in_range(addr) {
return addr.raw_value();
}
if let Some(addr) = mem.last_addr().checked_sub(layout::FDT_MAX_SIZE as u64 - 1)
&& mem.address_in_range(addr)
{
return addr.raw_value();
}

layout::DRAM_MEM_START
Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/arch/aarch64/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl Aarch64RegisterVec {
}

/// Returns an iterator over stored registers.
pub fn iter(&self) -> impl Iterator<Item = Aarch64RegisterRef> {
pub fn iter(&self) -> impl Iterator<Item = Aarch64RegisterRef<'_>> {
Aarch64RegisterVecIterator {
index: 0,
offset: 0,
Expand All @@ -253,7 +253,7 @@ impl Aarch64RegisterVec {
}

/// Returns an iterator over stored registers that allows register modifications.
pub fn iter_mut(&mut self) -> impl Iterator<Item = Aarch64RegisterRefMut> {
pub fn iter_mut(&mut self) -> impl Iterator<Item = Aarch64RegisterRefMut<'_>> {
Aarch64RegisterVecIteratorMut {
index: 0,
offset: 0,
Expand Down
16 changes: 8 additions & 8 deletions src/vmm/src/arch/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,19 @@ pub fn arch_memory_regions(size: usize) -> Vec<(GuestAddress, usize)> {
dram_size,
u64_to_usize(MMIO32_MEM_START),
u64_to_usize(MMIO32_MEM_SIZE),
) {
if let Some((start_past_64bit_gap, remaining_past_64bit_gap)) = arch_memory_regions_with_gap(
) && let Some((start_past_64bit_gap, remaining_past_64bit_gap)) =
arch_memory_regions_with_gap(
&mut regions,
start_past_32bit_gap,
remaining_past_32bit_gap,
u64_to_usize(MMIO64_MEM_START),
u64_to_usize(MMIO64_MEM_SIZE),
) {
regions.push((
GuestAddress(start_past_64bit_gap as u64),
remaining_past_64bit_gap,
));
}
)
{
regions.push((
GuestAddress(start_past_64bit_gap as u64),
remaining_past_64bit_gap,
));
}

regions
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/cpu_config/aarch64/custom_cpu_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::cpu_config::templates::{
use crate::cpu_config::templates_serde::*;

impl GetCpuTemplate for Option<CpuTemplateType> {
fn get_cpu_template(&self) -> Result<Cow<CustomCpuTemplate>, GetCpuTemplateError> {
fn get_cpu_template(&self) -> Result<Cow<'_, CustomCpuTemplate>, GetCpuTemplateError> {
match self {
Some(template_type) => match template_type {
CpuTemplateType::Custom(template) => Ok(Cow::Borrowed(template)),
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/cpu_config/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub enum GetCpuTemplateError {
/// custom CPU templates and handle static CPU template and custom CPU template in a same manner.
pub trait GetCpuTemplate {
/// Get CPU template
fn get_cpu_template(&self) -> Result<Cow<CustomCpuTemplate>, GetCpuTemplateError>;
fn get_cpu_template(&self) -> Result<Cow<'_, CustomCpuTemplate>, GetCpuTemplateError>;
}

/// Enum that represents types of cpu templates available.
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/cpu_config/x86_64/custom_cpu_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::cpu_config::x86_64::static_cpu_templates::{StaticCpuTemplate, c3, t2,
use crate::logger::warn;

impl GetCpuTemplate for Option<CpuTemplateType> {
fn get_cpu_template(&self) -> Result<Cow<CustomCpuTemplate>, GetCpuTemplateError> {
fn get_cpu_template(&self) -> Result<Cow<'_, CustomCpuTemplate>, GetCpuTemplateError> {
use GetCpuTemplateError::*;

match self {
Expand Down
9 changes: 4 additions & 5 deletions src/vmm/src/devices/legacy/i8042.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,10 @@ impl vm_device::BusDevice for I8042Device {
// Check if we still have data in the internal buffer. If so, we need to trigger
// another interrupt, to let the guest know they need to issue another read from
// port 0x60.
if (self.status & SB_OUT_DATA_AVAIL) != 0 {
if let Err(I8042Error::KbdInterruptFailure(err)) = self.trigger_kbd_interrupt()
{
warn!("Failed to trigger i8042 kbd interrupt {:?}", err);
}
if (self.status & SB_OUT_DATA_AVAIL) != 0
&& let Err(I8042Error::KbdInterruptFailure(err)) = self.trigger_kbd_interrupt()
{
warn!("Failed to trigger i8042 kbd interrupt {:?}", err);
}
}
_ => read_ok = false,
Expand Down
8 changes: 4 additions & 4 deletions src/vmm/src/devices/legacy/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ impl<I: Read + AsRawFd + Send + Debug> MutEventSubscriber
// Therefore, only try to register stdin to epoll if it is a terminal or a FIFO pipe.
// SAFETY: isatty has no invariants that need to be upheld. If serial_fd is an invalid
// argument, it will return 0 and set errno to EBADF.
if unsafe { libc::isatty(serial_fd) } == 1 || is_fifo(serial_fd) {
if let Err(err) = ops.add(Events::new(&serial_fd, EventSet::IN)) {
warn!("Failed to register serial input fd: {}", err);
}
if (unsafe { libc::isatty(serial_fd) } == 1 || is_fifo(serial_fd))
&& let Err(err) = ops.add(Events::new(&serial_fd, EventSet::IN))
{
warn!("Failed to register serial input fd: {}", err);
}
if let Err(err) = ops.add(Events::new(&buf_ready_evt, EventSet::IN)) {
warn!("Failed to register serial buffer ready event: {}", err);
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/devices/virtio/block/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Block {
VhostUserBlock::new(config).map_err(BlockError::VhostUserBackend)?,
))
} else {
return Err(BlockError::InvalidBlockConfig);
Err(BlockError::InvalidBlockConfig)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/vmm/src/devices/virtio/block/virtio/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,10 @@ impl VirtioBlock {
});
}

if let FileEngine::Async(ref mut engine) = self.disk.file_engine {
if let Err(err) = engine.kick_submission_queue() {
error!("BlockError submitting pending block requests: {:?}", err);
}
if let FileEngine::Async(ref mut engine) = self.disk.file_engine
&& let Err(err) = engine.kick_submission_queue()
{
error!("BlockError submitting pending block requests: {:?}", err);
}

if !used_any {
Expand Down
10 changes: 5 additions & 5 deletions src/vmm/src/devices/virtio/block/virtio/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ impl VirtioBlock {
)) {
error!("Failed to register ratelimiter event: {}", err);
}
if let FileEngine::Async(ref engine) = self.disk.file_engine {
if let Err(err) = ops.add(Events::with_data(
if let FileEngine::Async(ref engine) = self.disk.file_engine
&& let Err(err) = ops.add(Events::with_data(
engine.completion_evt(),
Self::PROCESS_ASYNC_COMPLETION,
EventSet::IN,
)) {
error!("Failed to register IO engine completion event: {}", err);
}
))
{
error!("Failed to register IO engine completion event: {}", err);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/vmm/src/devices/virtio/iovec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ mod tests {
])
}

fn chain(m: &GuestMemoryMmap, is_write_only: bool) -> (Queue, VirtQueue) {
fn chain(m: &GuestMemoryMmap, is_write_only: bool) -> (Queue, VirtQueue<'_>) {
let vq = VirtQueue::new(GuestAddress(0), m, 16);

let mut q = vq.create_queue();
Expand All @@ -593,14 +593,14 @@ mod tests {
(q, vq)
}

fn read_only_chain(mem: &GuestMemoryMmap) -> (Queue, VirtQueue) {
fn read_only_chain(mem: &GuestMemoryMmap) -> (Queue, VirtQueue<'_>) {
let v: Vec<u8> = (0..=255).collect();
mem.write_slice(&v, GuestAddress(0x20000)).unwrap();

chain(mem, false)
}

fn write_only_chain(mem: &GuestMemoryMmap) -> (Queue, VirtQueue) {
fn write_only_chain(mem: &GuestMemoryMmap) -> (Queue, VirtQueue<'_>) {
let v = vec![0; 256];
mem.write_slice(&v, GuestAddress(0x20000)).unwrap();

Expand Down
75 changes: 37 additions & 38 deletions src/vmm/src/devices/virtio/net/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,23 +525,23 @@ impl Net {
net_metrics.tx_malformed_frames.inc();
})?;

if let Some(ns) = mmds_ns {
if ns.is_mmds_frame(headers) {
let mut frame = vec![0u8; frame_iovec.len() as usize - vnet_hdr_len()];
// Ok to unwrap here, because we are passing a buffer that has the exact size
// of the `IoVecBuffer` minus the VNET headers.
frame_iovec
.read_exact_volatile_at(&mut frame, vnet_hdr_len())
.unwrap();
let _ = ns.detour_frame(&frame);
METRICS.mmds.rx_accepted.inc();
if let Some(ns) = mmds_ns
&& ns.is_mmds_frame(headers)
{
let mut frame = vec![0u8; frame_iovec.len() as usize - vnet_hdr_len()];
// Ok to unwrap here, because we are passing a buffer that has the exact size
// of the `IoVecBuffer` minus the VNET headers.
frame_iovec
.read_exact_volatile_at(&mut frame, vnet_hdr_len())
.unwrap();
let _ = ns.detour_frame(&frame);
METRICS.mmds.rx_accepted.inc();

// MMDS frames are not accounted by the rate limiter.
Self::rate_limiter_replenish_op(rate_limiter, u64::from(frame_iovec.len()));
// MMDS frames are not accounted by the rate limiter.
Self::rate_limiter_replenish_op(rate_limiter, u64::from(frame_iovec.len()));

// MMDS consumed the frame.
return Ok(true);
}
// MMDS consumed the frame.
return Ok(true);
}

// This frame goes to the TAP.
Expand Down Expand Up @@ -588,31 +588,30 @@ impl Net {
}
}

if let Some(ns) = self.mmds_ns.as_mut() {
if let Some(len) =
if let Some(ns) = self.mmds_ns.as_mut()
&& let Some(len) =
ns.write_next_frame(frame_bytes_from_buf_mut(&mut self.rx_frame_buf)?)
{
let len = len.get();
METRICS.mmds.tx_frames.inc();
METRICS.mmds.tx_bytes.add(len as u64);
init_vnet_hdr(&mut self.rx_frame_buf);
self.rx_buffer
.iovec
.write_all_volatile_at(&self.rx_frame_buf[..vnet_hdr_len() + len], 0)?;
// SAFETY:
// * len will never be bigger that u32::MAX because mmds is bound
// by the size of `self.rx_frame_buf` which is MAX_BUFFER_SIZE size.
let len: u32 = (vnet_hdr_len() + len).try_into().unwrap();

// SAFETY:
// * We checked that `rx_buffer` includes at least one `DescriptorChain`
// * `rx_frame_buf` has size of `MAX_BUFFER_SIZE` and all `DescriptorChain` objects
// are at least that big.
unsafe {
self.rx_buffer.mark_used(len, &mut self.queues[RX_INDEX]);
}
return Ok(Some(len));
{
let len = len.get();
METRICS.mmds.tx_frames.inc();
METRICS.mmds.tx_bytes.add(len as u64);
init_vnet_hdr(&mut self.rx_frame_buf);
self.rx_buffer
.iovec
.write_all_volatile_at(&self.rx_frame_buf[..vnet_hdr_len() + len], 0)?;
// SAFETY:
// * len will never be bigger that u32::MAX because mmds is bound
// by the size of `self.rx_frame_buf` which is MAX_BUFFER_SIZE size.
let len: u32 = (vnet_hdr_len() + len).try_into().unwrap();

// SAFETY:
// * We checked that `rx_buffer` includes at least one `DescriptorChain`
// * `rx_frame_buf` has size of `MAX_BUFFER_SIZE` and all `DescriptorChain` objects are
// at least that big.
unsafe {
self.rx_buffer.mark_used(len, &mut self.queues[RX_INDEX]);
}
return Ok(Some(len));
}

// SAFETY:
Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/devices/virtio/net/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pub fn create_socket() -> File {
}

// Returns handles to virtio queues creation/activation and manipulation.
pub fn virtqueues(mem: &GuestMemoryMmap) -> (VirtQueue, VirtQueue) {
pub fn virtqueues(mem: &GuestMemoryMmap) -> (VirtQueue<'_>, VirtQueue<'_>) {
let rxq = VirtQueue::new(GuestAddress(0), mem, 16);
let txq = VirtQueue::new(GuestAddress(0x1000), mem, 16);
assert!(rxq.end().0 < txq.start().0);
Expand Down Expand Up @@ -355,7 +355,7 @@ pub mod test {
}
}

pub fn net(&mut self) -> MutexGuard<Net> {
pub fn net(&mut self) -> MutexGuard<'_, Net> {
self.net.lock().unwrap()
}

Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/devices/virtio/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ pub(crate) mod test {
}

/// Get a (locked) reference to the device
pub fn device(&mut self) -> MutexGuard<T> {
pub fn device(&mut self) -> MutexGuard<'_, T> {
self.device.lock().unwrap()
}

Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/devices/virtio/transport/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl MmioTransport {
}

/// Gets the encapsulated locked VirtioDevice.
pub fn locked_device(&self) -> MutexGuard<dyn VirtioDevice + 'static> {
pub fn locked_device(&self) -> MutexGuard<'_, dyn VirtioDevice + 'static> {
self.device.lock().expect("Poisoned lock")
}

Expand Down
Loading