misc: Fix various clippy issues

Assisted-by: Claude:Opus-4.7
Signed-off-by: Bo Chen <bchen@crusoe.ai>
This commit is contained in:
Bo Chen
2026-05-14 20:16:49 +00:00
committed by Bo Chen
parent e2cd6ff8c9
commit 3453eb6e86
7 changed files with 84 additions and 94 deletions

View File

@@ -641,17 +641,16 @@ pub fn generate_common_cpuid(
// Update some existing CPUID
for entry in cpuid.as_mut_slice().iter_mut() {
#[allow(unused_unsafe)]
match entry.function {
// Clear AMX related bits if the AMX feature is not enabled
0x7 => {
if !config.amx {
if entry.index == 0 {
entry.edx &= !((1 << AMX_BF16) | (1 << AMX_TILE) | (1 << AMX_INT8));
}
if entry.index == 1 {
entry.eax &= !(1 << AMX_FP16);
entry.edx &= !(1 << AMX_COMPLEX);
}
0x7 if !config.amx => {
if entry.index == 0 {
entry.edx &= !((1 << AMX_BF16) | (1 << AMX_TILE) | (1 << AMX_INT8));
}
if entry.index == 1 {
entry.eax &= !(1 << AMX_FP16);
entry.edx &= !(1 << AMX_COMPLEX);
}
}
0xd =>
@@ -673,55 +672,46 @@ pub fn generate_common_cpuid(
}
}
}
0x1d => {
// Tile Information (purely AMX related).
if !config.amx {
entry.eax = 0;
entry.ebx = 0;
entry.ecx = 0;
entry.edx = 0;
}
// Tile Information (purely AMX related).
0x1d if !config.amx => {
entry.eax = 0;
entry.ebx = 0;
entry.ecx = 0;
entry.edx = 0;
}
0x1e => {
// TMUL information (purely AMX related)
if !config.amx {
entry.eax = 0;
entry.ebx = 0;
entry.ecx = 0;
entry.edx = 0;
}
// TMUL information (purely AMX related)
0x1e if !config.amx => {
entry.eax = 0;
entry.ebx = 0;
entry.ecx = 0;
entry.edx = 0;
}
// Copy host L1 cache details if not populated by KVM
0x8000_0005 => {
if entry.eax == 0 && entry.ebx == 0 && entry.ecx == 0 && entry.edx == 0 {
#[allow(unused_unsafe)]
0x8000_0005
if entry.eax == 0 && entry.ebx == 0 && entry.ecx == 0 && entry.edx == 0
// SAFETY: cpuid called with valid leaves
if unsafe { std::arch::x86_64::__cpuid(0x8000_0000).eax } >= 0x8000_0005 {
// SAFETY: cpuid called with valid leaves
let leaf = unsafe { std::arch::x86_64::__cpuid(0x8000_0005) };
entry.eax = leaf.eax;
entry.ebx = leaf.ebx;
entry.ecx = leaf.ecx;
entry.edx = leaf.edx;
}
}
&& unsafe { std::arch::x86_64::__cpuid(0x8000_0000).eax } >= 0x8000_0005 =>
{
// SAFETY: cpuid called with valid leaves
let leaf = unsafe { std::arch::x86_64::__cpuid(0x8000_0005) };
entry.eax = leaf.eax;
entry.ebx = leaf.ebx;
entry.ecx = leaf.ecx;
entry.edx = leaf.edx;
}
// Copy host L2 cache details if not populated by KVM
0x8000_0006 => {
if entry.eax == 0 && entry.ebx == 0 && entry.ecx == 0 && entry.edx == 0 {
#[allow(unused_unsafe)]
0x8000_0006
if entry.eax == 0 && entry.ebx == 0 && entry.ecx == 0 && entry.edx == 0
// SAFETY: cpuid called with valid leaves
if unsafe { std::arch::x86_64::__cpuid(0x8000_0000).eax } >= 0x8000_0006 {
#[allow(unused_unsafe)]
// SAFETY: cpuid called with valid leaves
let leaf = unsafe { std::arch::x86_64::__cpuid(0x8000_0006) };
entry.eax = leaf.eax;
entry.ebx = leaf.ebx;
entry.ecx = leaf.ecx;
entry.edx = leaf.edx;
}
}
&& unsafe { std::arch::x86_64::__cpuid(0x8000_0000).eax } >= 0x8000_0006 =>
{
// SAFETY: cpuid called with valid leaves
let leaf = unsafe { std::arch::x86_64::__cpuid(0x8000_0006) };
entry.eax = leaf.eax;
entry.ebx = leaf.ebx;
entry.ecx = leaf.ecx;
entry.edx = leaf.edx;
}
// Set CPU physical bits
0x8000_0008 => {

View File

@@ -407,9 +407,11 @@ impl VsockMuxer {
Some(EpollListener::HostSock) => {
if self.conn_map.len() == defs::MAX_CONNECTIONS {
// If we're already maxed-out on connections, we'll just accept and
// immediately discard this potentially new one.
// immediately discard this potentially new one. Dropping the returned
// `UnixStream` closes the new connection; we don't care if `accept()`
// itself failed.
warn!("vsock: connection limit reached; refusing new host connection");
self.host_sock.accept().map(|_| 0).unwrap_or(0);
let _ = self.host_sock.accept();
return;
}
self.host_sock

View File

@@ -110,6 +110,10 @@ impl MuxerKillQ {
/// This will succeed and return a connection key, only if the connection at the front of
/// the queue has expired. Otherwise, `None` is returned.
///
// `VecDeque::pop_front_if` is unstable on the project MSRV; allow the
// beta clippy lint that asks for it. `unknown_lints` is needed because
// the lint does not exist on stable clippy.
#[allow(unknown_lints, clippy::manual_pop_if)]
pub fn pop(&mut self) -> Option<ConnMapKey> {
if let Some(item) = self.q.front()
&& Instant::now() > item.kill_time

View File

@@ -484,7 +484,7 @@ impl run_blocking::BlockingEventLoop for GdbEventLoop {
}
}
if conn.peek().map(|b| b.is_some()).unwrap_or(true) {
if conn.peek().map_or(true, |b| b.is_some()) {
let byte = conn
.read()
.map_err(run_blocking::WaitForStopReasonError::Connection)?;

View File

@@ -433,7 +433,7 @@ pub fn load_igvm(
let mut now = Instant::now();
// Sort the gpas to group them by the page type
gpas.sort_by(|a, b| a.gpa.cmp(&b.gpa));
gpas.sort_by_key(|a| a.gpa);
let gpas_grouped = gpas
.iter()

View File

@@ -735,22 +735,20 @@ impl Vmm {
for signal in signals.forever() {
match signal {
SIGTERM | SIGINT => {
if exit_evt.write(1).is_err() {
// Resetting the terminal is usually done as the VMM exits
if let Ok(lock) = original_termios_opt.lock() {
if let Some(termios) = *lock {
// SAFETY: FFI call
let _ = unsafe {
tcsetattr(stdout().lock().as_raw_fd(), TCSANOW, &termios)
};
}
} else {
warn!("Failed to lock original termios");
SIGTERM | SIGINT if exit_evt.write(1).is_err() => {
// Resetting the terminal is usually done as the VMM exits
if let Ok(lock) = original_termios_opt.lock() {
if let Some(termios) = *lock {
// SAFETY: FFI call
let _ = unsafe {
tcsetattr(stdout().lock().as_raw_fd(), TCSANOW, &termios)
};
}
std::process::exit(1);
} else {
warn!("Failed to lock original termios");
}
std::process::exit(1);
}
_ => (),
}

View File

@@ -132,33 +132,29 @@ impl SerialManager {
let in_fd = match output {
ConsoleOutput::Pty(ref fd) => fd.as_raw_fd(),
ConsoleOutput::Tty(_) => {
// If running on an interactive TTY then accept input
// SAFETY: trivially safe
if unsafe { libc::isatty(libc::STDIN_FILENO) == 1 } {
// SAFETY: STDIN_FILENO is a valid fd
let fd = unsafe { libc::dup(libc::STDIN_FILENO) };
if fd == -1 {
return Err(Error::DupFd(std::io::Error::last_os_error()));
}
// SAFETY: fd is valid and owned by us
let stdin_clone = unsafe { File::from_raw_fd(fd) };
// SAFETY: FFI calls with correct arguments
let ret = unsafe {
let mut flags = libc::fcntl(stdin_clone.as_raw_fd(), libc::F_GETFL);
flags |= libc::O_NONBLOCK;
libc::fcntl(stdin_clone.as_raw_fd(), libc::F_SETFL, flags)
};
if ret < 0 {
return Err(Error::SetNonBlocking(std::io::Error::last_os_error()));
}
output = ConsoleOutput::Tty(Arc::new(stdin_clone));
fd
} else {
return Ok(None);
// If running on an interactive TTY then accept input.
// SAFETY: trivially safe
ConsoleOutput::Tty(_) if unsafe { libc::isatty(libc::STDIN_FILENO) == 1 } => {
// SAFETY: STDIN_FILENO is a valid fd
let fd = unsafe { libc::dup(libc::STDIN_FILENO) };
if fd == -1 {
return Err(Error::DupFd(std::io::Error::last_os_error()));
}
// SAFETY: fd is valid and owned by us
let stdin_clone = unsafe { File::from_raw_fd(fd) };
// SAFETY: FFI calls with correct arguments
let ret = unsafe {
let mut flags = libc::fcntl(stdin_clone.as_raw_fd(), libc::F_GETFL);
flags |= libc::O_NONBLOCK;
libc::fcntl(stdin_clone.as_raw_fd(), libc::F_SETFL, flags)
};
if ret < 0 {
return Err(Error::SetNonBlocking(std::io::Error::last_os_error()));
}
output = ConsoleOutput::Tty(Arc::new(stdin_clone));
fd
}
ConsoleOutput::Socket(ref fd) => {
if let Some(path_in_socket) = socket {