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
4 changes: 2 additions & 2 deletions src/cpuid/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

#[cfg(target_arch = "x86")]
use std::arch::x86::{CpuidResult, __cpuid_count, __get_cpuid_max};
use std::arch::x86::{__cpuid_count, __get_cpuid_max, CpuidResult};
#[cfg(target_arch = "x86_64")]
use std::arch::x86_64::{CpuidResult, __cpuid_count, __get_cpuid_max};
use std::arch::x86_64::{__cpuid_count, __get_cpuid_max, CpuidResult};

use crate::cpu_leaf::*;

Expand Down
3 changes: 2 additions & 1 deletion src/devices/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ fn main() {
return;
}

let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("missing CARGO_MANIFEST_DIR"));
let manifest_dir =
PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("missing CARGO_MANIFEST_DIR"));
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("missing OUT_DIR"));
let rustc = env::var("RUSTC").unwrap_or_else(|_| "rustc".to_string());
let wrapper_src = manifest_dir.join("build").join("windows_init_wrapper.rs");
Expand Down
4 changes: 2 additions & 2 deletions src/devices/src/legacy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ mod vcpu;
#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
pub mod windows_apic_stub;
#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
pub mod windows_pic_stub;
#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
pub mod windows_pci_cfg_stub;
#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
pub mod windows_pic_stub;
#[cfg(target_arch = "x86_64")]
mod x86_64;
#[cfg(target_arch = "x86_64")]
Expand Down
12 changes: 10 additions & 2 deletions src/devices/src/legacy/windows_apic_stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ fn windows_apic_debug_log(message: impl AsRef<str>) {
if !*VALUE.get_or_init(|| {
std::env::var("LIBKRUN_WINDOWS_VERBOSE_DEBUG")
.or_else(|_| std::env::var("LIBKRUN_WINDOWS_IO_DEBUG"))
.map(|v| matches!(v.trim().to_ascii_lowercase().as_str(), "1" | "true" | "yes" | "on"))
.map(|v| {
matches!(
v.trim().to_ascii_lowercase().as_str(),
"1" | "true" | "yes" | "on"
)
})
.unwrap_or(false)
}) {
return;
}
use std::io::Write;

for path in [r"C:\Users\18770\.a3s\libkrun-whpx-io-current.log", "tmp_whpx_io.log"] {
for path in [
r"C:\Users\18770\.a3s\libkrun-whpx-io-current.log",
"tmp_whpx_io.log",
] {
if let Ok(mut file) = std::fs::OpenOptions::new()
.create(true)
.append(true)
Expand Down
2 changes: 1 addition & 1 deletion src/devices/src/legacy/windows_pci_cfg_stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl BusDevice for PciConfigIoStub {
#[cfg(test)]
mod tests {
use super::{
CONFIG_ENABLE_BIT, PCI_CLASS_HOST_BRIDGE, PCI_SUBCLASS_HOST_BRIDGE, PciConfigIoStub,
PciConfigIoStub, CONFIG_ENABLE_BIT, PCI_CLASS_HOST_BRIDGE, PCI_SUBCLASS_HOST_BRIDGE,
};
use crate::BusDevice;

Expand Down
32 changes: 19 additions & 13 deletions src/devices/src/legacy/windows_pic_stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ fn windows_pic_debug_log(message: impl AsRef<str>) {
if !*VALUE.get_or_init(|| {
std::env::var("LIBKRUN_WINDOWS_VERBOSE_DEBUG")
.or_else(|_| std::env::var("LIBKRUN_WINDOWS_IO_DEBUG"))
.map(|v| matches!(v.trim().to_ascii_lowercase().as_str(), "1" | "true" | "yes" | "on"))
.map(|v| {
matches!(
v.trim().to_ascii_lowercase().as_str(),
"1" | "true" | "yes" | "on"
)
})
.unwrap_or(false)
}) {
return;
}
use std::io::Write;

for path in [r"C:\Users\18770\.a3s\libkrun-whpx-io-current.log", "tmp_whpx_io.log"] {
for path in [
r"C:\Users\18770\.a3s\libkrun-whpx-io-current.log",
"tmp_whpx_io.log",
] {
if let Ok(mut file) = std::fs::OpenOptions::new()
.create(true)
.append(true)
Expand Down Expand Up @@ -117,7 +125,12 @@ impl PicState {
// edge becomes deliverable again.
self.clear_pending_irq_without_in_service(irq);
}
log::debug!("PIC {}: specific EOI command 0x{:02x} irq={}", name, value, irq);
log::debug!(
"PIC {}: specific EOI command 0x{:02x} irq={}",
name,
value,
irq
);
windows_pic_debug_log(format!(
"[PIC] {} eoi cmd=0x{:02x} specific=true irq={} irr=0x{:02x} in_service=0x{:02x}",
name, value, irq, self.irr, self.in_service
Expand All @@ -139,8 +152,7 @@ impl PicState {
);
windows_pic_debug_log(format!(
"[PIC] {} icw2 vector_base=0x{:02x}",
name,
self.vector_offset
name, self.vector_offset
));
}
InitState::ExpectIcw3 => {
Expand All @@ -160,9 +172,7 @@ impl PicState {
);
windows_pic_debug_log(format!(
"[PIC] {} icw4=0x{:02x} initialized auto_eoi={}",
name,
value,
self.auto_eoi
name, value, self.auto_eoi
));
}
InitState::Ready => {
Expand All @@ -173,11 +183,7 @@ impl PicState {
self.mask,
(self.mask & 0x01) != 0
);
windows_pic_debug_log(format!(
"[PIC] {} ocw1 mask=0x{:02x}",
name,
self.mask
));
windows_pic_debug_log(format!("[PIC] {} ocw1 mask=0x{:02x}", name, self.mask));
}
}
}
Expand Down
38 changes: 37 additions & 1 deletion src/devices/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,39 @@ pub enum Error {
SpuriousEvent,
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::FailedReadingQueue {
event_type,
underlying,
} => write!(f, "FailedReadingQueue({event_type}): {underlying}"),
Self::FailedReadTap => f.write_str("FailedReadTap"),
Self::FailedSignalingUsedQueue(error) => {
write!(f, "FailedSignalingUsedQueue: {error}")
}
Self::PayloadExpected => f.write_str("PayloadExpected"),
Self::IoError(error) => write!(f, "IoError: {error}"),
Self::NoAvailBuffers => f.write_str("NoAvailBuffers"),
Self::SpuriousEvent => f.write_str("SpuriousEvent"),
}
}
}

impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::FailedReadingQueue { underlying, .. }
| Self::FailedSignalingUsedQueue(underlying)
| Self::IoError(underlying) => Some(underlying),
Self::FailedReadTap
| Self::PayloadExpected
| Self::NoAvailBuffers
| Self::SpuriousEvent => None,
}
}
}

/// Types of devices that can get attached to this platform.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Copy)]
pub enum DeviceType {
Expand Down Expand Up @@ -112,7 +145,10 @@ mod tests {
event_type: "RX",
underlying: io_error,
};
assert_eq!(format!("{:?}", error), "FailedReadingQueue { event_type: \"RX\", underlying: Custom { kind: Other, error: \"\" } }");
let debug = format!("{error:?}");
assert!(debug.contains("FailedReadingQueue"));
assert!(debug.contains("event_type: \"RX\""));
assert!(debug.contains("test"));
}

#[test]
Expand Down
6 changes: 1 addition & 5 deletions src/devices/src/virtio/file_traits_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ pub trait FileReadWriteAtVolatile {
Ok(total)
}

fn write_vectored_at_volatile(
&self,
bufs: &[VolatileSlice],
mut offset: u64,
) -> Result<usize> {
fn write_vectored_at_volatile(&self, bufs: &[VolatileSlice], mut offset: u64) -> Result<usize> {
let mut total = 0usize;
for &slice in bufs {
if slice.is_empty() {
Expand Down
17 changes: 14 additions & 3 deletions src/devices/src/virtio/fs/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ fn fs_device_debug_log(message: impl AsRef<str>) {
static VALUE: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
if !*VALUE.get_or_init(|| {
std::env::var("LIBKRUN_WINDOWS_VERBOSE_DEBUG")
.map(|v| matches!(v.trim().to_ascii_lowercase().as_str(), "1" | "true" | "yes" | "on"))
.map(|v| {
matches!(
v.trim().to_ascii_lowercase().as_str(),
"1" | "true" | "yes" | "on"
)
})
.unwrap_or(false)
}) {
return;
Expand Down Expand Up @@ -87,7 +92,10 @@ impl Fs {
queues: Vec<VirtQueue>,
) -> super::Result<Fs> {
#[cfg(target_os = "windows")]
fs_device_debug_log(format!("Fs::with_queues fs_id={} shared_dir={}", fs_id, shared_dir));
fs_device_debug_log(format!(
"Fs::with_queues fs_id={} shared_dir={}",
fs_id, shared_dir
));
let mut queue_events = Vec::new();
for _ in 0..queues.len() {
queue_events
Expand Down Expand Up @@ -216,7 +224,10 @@ impl VirtioDevice for Fs {

fn activate(&mut self, mem: GuestMemoryMmap, interrupt: InterruptTransport) -> ActivateResult {
#[cfg(target_os = "windows")]
fs_device_debug_log(format!("Fs::activate tag={}", String::from_utf8_lossy(&self.config.tag)));
fs_device_debug_log(format!(
"Fs::activate tag={}",
String::from_utf8_lossy(&self.config.tag)
));
if self.worker_thread.is_some() {
panic!("virtio_fs: worker thread already exists");
}
Expand Down
7 changes: 6 additions & 1 deletion src/devices/src/virtio/fs/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ fn fs_server_debug_log(message: impl AsRef<str>) {
static VALUE: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
if !*VALUE.get_or_init(|| {
std::env::var("LIBKRUN_WINDOWS_VERBOSE_DEBUG")
.map(|v| matches!(v.trim().to_ascii_lowercase().as_str(), "1" | "true" | "yes" | "on"))
.map(|v| {
matches!(
v.trim().to_ascii_lowercase().as_str(),
"1" | "true" | "yes" | "on"
)
})
.unwrap_or(false)
}) {
return;
Expand Down
40 changes: 29 additions & 11 deletions src/devices/src/virtio/fs/windows/passthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ fn virtiofs_debug_enabled() -> bool {
static VALUE: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*VALUE.get_or_init(|| {
std::env::var("LIBKRUN_WINDOWS_VERBOSE_DEBUG")
.map(|v| matches!(v.trim().to_ascii_lowercase().as_str(), "1" | "true" | "yes" | "on"))
.map(|v| {
matches!(
v.trim().to_ascii_lowercase().as_str(),
"1" | "true" | "yes" | "on"
)
})
.unwrap_or(false)
})
}
Expand Down Expand Up @@ -159,7 +164,10 @@ pub struct PassthroughFs {
impl PassthroughFs {
pub fn new(cfg: Config) -> io::Result<PassthroughFs> {
let root_dir = PathBuf::from(&cfg.root_dir);
virtiofs_debug_log(format!("PassthroughFs::new root_dir={}", root_dir.display()));
virtiofs_debug_log(format!(
"PassthroughFs::new root_dir={}",
root_dir.display()
));

// Verify root directory exists
if !root_dir.exists() {
Expand Down Expand Up @@ -360,7 +368,10 @@ impl PassthroughFs {
if usr_lib64_loader.is_file() {
usr_lib64
} else {
self.root_dir.join("usr").join("lib").join("x86_64-linux-gnu")
self.root_dir
.join("usr")
.join("lib")
.join("x86_64-linux-gnu")
}
}
_ => return None,
Expand Down Expand Up @@ -425,11 +436,7 @@ impl PassthroughFs {
if parent_path == self.root_dir {
if let Some(name) = name_path.to_str() {
if let Some(target) = self.root_alias_target(name) {
virtiofs_debug_log(format!(
"lookup alias /{} -> {}",
name,
target.display()
));
virtiofs_debug_log(format!("lookup alias /{} -> {}", name, target.display()));
return target;
}
}
Expand Down Expand Up @@ -1454,7 +1461,10 @@ impl FileSystem for PassthroughFs {
// harmless close() into EIO for read-only executable loads.
if let Some(handle_data) = self.handles.read().unwrap().get(&handle) {
if should_trace_path(&handle_data.path) {
virtiofs_debug_log(format!("flush-ok {} handle={handle}", handle_data.path.display()));
virtiofs_debug_log(format!(
"flush-ok {} handle={handle}",
handle_data.path.display()
));
}
}
Ok(())
Expand Down Expand Up @@ -1818,7 +1828,11 @@ mod tests {
)
.expect("lookup x86_64-linux-gnu");
let soname_entry = fs
.lookup(ctx(), x86_entry.inode, &CString::new("libcrypt.so.1").unwrap())
.lookup(
ctx(),
x86_entry.inode,
&CString::new("libcrypt.so.1").unwrap(),
)
.expect("lookup libcrypt.so.1 alias");

assert_eq!(soname_entry.attr.st_size, 8);
Expand All @@ -1842,7 +1856,11 @@ mod tests {
.lookup(ctx(), usr_entry.inode, &CString::new("lib").unwrap())
.expect("lookup /usr/lib");
let soname_entry = fs
.lookup(ctx(), lib_entry.inode, &CString::new("libcrypt.so.1").unwrap())
.lookup(
ctx(),
lib_entry.inode,
&CString::new("libcrypt.so.1").unwrap(),
)
.expect("lookup /usr/lib/libcrypt.so.1 alias");

assert_eq!(soname_entry.attr.st_size, 8);
Expand Down
11 changes: 8 additions & 3 deletions src/devices/src/virtio/fs/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use utils::worker_message::WorkerMessage;

#[cfg(not(target_os = "windows"))]
use std::os::fd::AsRawFd;
#[cfg(target_os = "windows")]
use std::{fs::OpenOptions, io::Write};
use std::sync::atomic::AtomicI32;
use std::sync::Arc;
use std::thread;
#[cfg(target_os = "windows")]
use std::{fs::OpenOptions, io::Write};

use utils::epoll::{ControlOperation, Epoll, EpollEvent, EventSet};
use utils::eventfd::EventFd;
Expand All @@ -27,7 +27,12 @@ fn fs_worker_debug_log(message: impl AsRef<str>) {
static VALUE: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
if !*VALUE.get_or_init(|| {
std::env::var("LIBKRUN_WINDOWS_VERBOSE_DEBUG")
.map(|v| matches!(v.trim().to_ascii_lowercase().as_str(), "1" | "true" | "yes" | "on"))
.map(|v| {
matches!(
v.trim().to_ascii_lowercase().as_str(),
"1" | "true" | "yes" | "on"
)
})
.unwrap_or(false)
}) {
return;
Expand Down
Loading
Loading