Skip to content

Commit

Permalink
chore: make sure hexadecimal numbers are prefixed by '0x'
Browse files Browse the repository at this point in the history
I got an error message saying 'Start microvm error: Internal error while
starting microVM: Vm error: Missing KVM capabilities: aa', which just
looked like KVM was screaming.

Thus, look through where we print hex numbers, and make sure they are
prefixed using '0x', and do so uniformly by using Rust's `:#x` format
modifier [1]

[1]: https://doc.rust-lang.org/std/fmt/#sign0

Signed-off-by: Patrick Roy <[email protected]>
  • Loading branch information
roypat committed Nov 25, 2024
1 parent cabeb7e commit 350bfb3
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/vmm/src/devices/virtio/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub trait VirtioDevice: AsAny + Send {
let avail_features = self.avail_features();
let unrequested_features = v & !avail_features;
if unrequested_features != 0 {
warn!("Received acknowledge request for unknown feature: {:x}", v);
warn!("Received acknowledge request for unknown feature: {:#x}", v);
// Don't count these features as acked.
v &= !unrequested_features;
}
Expand Down
22 changes: 7 additions & 15 deletions src/vmm/src/devices/virtio/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl MmioTransport {
self.with_queue_mut(f);
} else {
warn!(
"update virtio queue in invalid state 0x{:x}",
"update virtio queue in invalid state {:#x}",
self.device_status
);
}
Expand Down Expand Up @@ -227,7 +227,7 @@ impl MmioTransport {
}
_ => {
warn!(
"invalid virtio driver status transition: 0x{:x} -> 0x{:x}",
"invalid virtio driver status transition: {:#x} -> {:#x}",
self.device_status, status
);
}
Expand Down Expand Up @@ -282,19 +282,15 @@ impl MmioTransport {
0x70 => self.device_status,
0xfc => self.config_generation,
_ => {
warn!("unknown virtio mmio register read: 0x{:x}", offset);
warn!("unknown virtio mmio register read: {:#x}", offset);
return;
}
};
byte_order::write_le_u32(data, v);
}
0x100..=0xfff => self.locked_device().read_config(offset - 0x100, data),
_ => {
warn!(
"invalid virtio mmio read: 0x{:x}:0x{:x}",
offset,
data.len()
);
warn!("invalid virtio mmio read: {:#x}:{:#x}", offset, data.len());
}
};
}
Expand Down Expand Up @@ -324,7 +320,7 @@ impl MmioTransport {
.ack_features_by_page(self.acked_features_select, v);
} else {
warn!(
"ack virtio features in invalid state 0x{:x}",
"ack virtio features in invalid state {:#x}",
self.device_status
);
}
Expand All @@ -346,7 +342,7 @@ impl MmioTransport {
0xa0 => self.update_queue_field(|q| lo(&mut q.used_ring_address, v)),
0xa4 => self.update_queue_field(|q| hi(&mut q.used_ring_address, v)),
_ => {
warn!("unknown virtio mmio register write: 0x{:x}", offset);
warn!("unknown virtio mmio register write: {:#x}", offset);
}
}
}
Expand All @@ -361,11 +357,7 @@ impl MmioTransport {
}
}
_ => {
warn!(
"invalid virtio mmio write: 0x{:x}:0x{:x}",
offset,
data.len()
);
warn!("invalid virtio mmio write: {:#x}:{:#x}", offset, data.len());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/devices/virtio/vsock/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ where
fn write_config(&mut self, offset: u64, data: &[u8]) {
METRICS.cfg_fails.inc();
warn!(
"vsock: guest driver attempted to write device config (offset={:x}, len={:x})",
"vsock: guest driver attempted to write device config (offset={:#x}, len={:#x})",
offset,
data.len()
);
Expand Down
6 changes: 3 additions & 3 deletions src/vmm/src/gdb/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ impl MultiThreadBase for FirecrackerTarget {

while !data.is_empty() {
let gpa = arch::translate_gva(&vcpu_state.vcpu_fd, gva, &vmm).map_err(|e| {
error!("Error {e:?} translating gva on read address: {gva:X}");
error!("Error {e:?} translating gva on read address: {gva:#X}");
})?;

// Compute the amount space left in the page after the gpa
Expand Down Expand Up @@ -424,7 +424,7 @@ impl MultiThreadBase for FirecrackerTarget {

while !data.is_empty() {
let gpa = arch::translate_gva(&vcpu_state.vcpu_fd, gva, &vmm).map_err(|e| {
error!("Error {e:?} translating gva on read address: {gva:X}");
error!("Error {e:?} translating gva on read address: {gva:#X}");
})?;

// Compute the amount space left in the page after the gpa
Expand All @@ -436,7 +436,7 @@ impl MultiThreadBase for FirecrackerTarget {
vmm.guest_memory()
.write(&data[..write_len], GuestAddress(gpa))
.map_err(|e| {
error!("Error {e:?} writing memory at {gpa:X}");
error!("Error {e:?} writing memory at {gpa:#X}");
})?;

data = &data[write_len..];
Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/vstate/vcpu/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub enum KvmVcpuError {
VcpuGetLapic(kvm_ioctls::Error),
/// Failed to get KVM vcpu mp state: {0}
VcpuGetMpState(kvm_ioctls::Error),
/// Failed to get KVM vcpu msr: 0x{0:x}
/// Failed to get KVM vcpu msr: {0:#x}
VcpuGetMsr(u32),
/// Failed to get KVM vcpu msrs: {0}
VcpuGetMsrs(kvm_ioctls::Error),
Expand Down Expand Up @@ -321,7 +321,7 @@ impl KvmVcpu {
.filter(|msr| msr.index == MSR_IA32_TSC_DEADLINE && msr.data == 0)
.for_each(|msr| {
warn!(
"MSR_IA32_TSC_DEADLINE is 0, replacing with {:x}.",
"MSR_IA32_TSC_DEADLINE is 0, replacing with {:#x}.",
tsc_value
);
msr.data = tsc_value;
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/vstate/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::vstate::memory::{Address, GuestMemory, GuestMemoryMmap, GuestMemoryRe
pub enum VmError {
/// The host kernel reports an invalid KVM API version: {0}
ApiVersion(i32),
/// Missing KVM capabilities: {0:x?}
/// Missing KVM capabilities: {0:#x?}
Capabilities(u32),
/** Error creating KVM object: {0} Make sure the user launching the firecracker process is \
configured on the /dev/kvm file's ACL. */
Expand Down

0 comments on commit 350bfb3

Please sign in to comment.