mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: Fix various clippy issues
Assisted-by: Claude:Opus-4.7 Signed-off-by: Bo Chen <bchen@crusoe.ai>
This commit is contained in:
+40
-50
@@ -641,17 +641,16 @@ pub fn generate_common_cpuid(
|
|||||||
|
|
||||||
// Update some existing CPUID
|
// Update some existing CPUID
|
||||||
for entry in cpuid.as_mut_slice().iter_mut() {
|
for entry in cpuid.as_mut_slice().iter_mut() {
|
||||||
|
#[allow(unused_unsafe)]
|
||||||
match entry.function {
|
match entry.function {
|
||||||
// Clear AMX related bits if the AMX feature is not enabled
|
// Clear AMX related bits if the AMX feature is not enabled
|
||||||
0x7 => {
|
0x7 if !config.amx => {
|
||||||
if !config.amx {
|
if entry.index == 0 {
|
||||||
if entry.index == 0 {
|
entry.edx &= !((1 << AMX_BF16) | (1 << AMX_TILE) | (1 << AMX_INT8));
|
||||||
entry.edx &= !((1 << AMX_BF16) | (1 << AMX_TILE) | (1 << AMX_INT8));
|
}
|
||||||
}
|
if entry.index == 1 {
|
||||||
if entry.index == 1 {
|
entry.eax &= !(1 << AMX_FP16);
|
||||||
entry.eax &= !(1 << AMX_FP16);
|
entry.edx &= !(1 << AMX_COMPLEX);
|
||||||
entry.edx &= !(1 << AMX_COMPLEX);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
0xd =>
|
0xd =>
|
||||||
@@ -673,55 +672,46 @@ pub fn generate_common_cpuid(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
0x1d => {
|
// Tile Information (purely AMX related).
|
||||||
// Tile Information (purely AMX related).
|
0x1d if !config.amx => {
|
||||||
if !config.amx {
|
entry.eax = 0;
|
||||||
entry.eax = 0;
|
entry.ebx = 0;
|
||||||
entry.ebx = 0;
|
entry.ecx = 0;
|
||||||
entry.ecx = 0;
|
entry.edx = 0;
|
||||||
entry.edx = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
0x1e => {
|
// TMUL information (purely AMX related)
|
||||||
// TMUL information (purely AMX related)
|
0x1e if !config.amx => {
|
||||||
if !config.amx {
|
entry.eax = 0;
|
||||||
entry.eax = 0;
|
entry.ebx = 0;
|
||||||
entry.ebx = 0;
|
entry.ecx = 0;
|
||||||
entry.ecx = 0;
|
entry.edx = 0;
|
||||||
entry.edx = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy host L1 cache details if not populated by KVM
|
// Copy host L1 cache details if not populated by KVM
|
||||||
0x8000_0005 => {
|
0x8000_0005
|
||||||
if entry.eax == 0 && entry.ebx == 0 && entry.ecx == 0 && entry.edx == 0 {
|
if entry.eax == 0 && entry.ebx == 0 && entry.ecx == 0 && entry.edx == 0
|
||||||
#[allow(unused_unsafe)]
|
|
||||||
// SAFETY: cpuid called with valid leaves
|
// SAFETY: cpuid called with valid leaves
|
||||||
if unsafe { std::arch::x86_64::__cpuid(0x8000_0000).eax } >= 0x8000_0005 {
|
&& 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) };
|
// SAFETY: cpuid called with valid leaves
|
||||||
entry.eax = leaf.eax;
|
let leaf = unsafe { std::arch::x86_64::__cpuid(0x8000_0005) };
|
||||||
entry.ebx = leaf.ebx;
|
entry.eax = leaf.eax;
|
||||||
entry.ecx = leaf.ecx;
|
entry.ebx = leaf.ebx;
|
||||||
entry.edx = leaf.edx;
|
entry.ecx = leaf.ecx;
|
||||||
}
|
entry.edx = leaf.edx;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Copy host L2 cache details if not populated by KVM
|
// Copy host L2 cache details if not populated by KVM
|
||||||
0x8000_0006 => {
|
0x8000_0006
|
||||||
if entry.eax == 0 && entry.ebx == 0 && entry.ecx == 0 && entry.edx == 0 {
|
if entry.eax == 0 && entry.ebx == 0 && entry.ecx == 0 && entry.edx == 0
|
||||||
#[allow(unused_unsafe)]
|
|
||||||
// SAFETY: cpuid called with valid leaves
|
// SAFETY: cpuid called with valid leaves
|
||||||
if unsafe { std::arch::x86_64::__cpuid(0x8000_0000).eax } >= 0x8000_0006 {
|
&& unsafe { std::arch::x86_64::__cpuid(0x8000_0000).eax } >= 0x8000_0006 =>
|
||||||
#[allow(unused_unsafe)]
|
{
|
||||||
// SAFETY: cpuid called with valid leaves
|
// SAFETY: cpuid called with valid leaves
|
||||||
let leaf = unsafe { std::arch::x86_64::__cpuid(0x8000_0006) };
|
let leaf = unsafe { std::arch::x86_64::__cpuid(0x8000_0006) };
|
||||||
entry.eax = leaf.eax;
|
entry.eax = leaf.eax;
|
||||||
entry.ebx = leaf.ebx;
|
entry.ebx = leaf.ebx;
|
||||||
entry.ecx = leaf.ecx;
|
entry.ecx = leaf.ecx;
|
||||||
entry.edx = leaf.edx;
|
entry.edx = leaf.edx;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Set CPU physical bits
|
// Set CPU physical bits
|
||||||
0x8000_0008 => {
|
0x8000_0008 => {
|
||||||
|
|||||||
@@ -407,9 +407,11 @@ impl VsockMuxer {
|
|||||||
Some(EpollListener::HostSock) => {
|
Some(EpollListener::HostSock) => {
|
||||||
if self.conn_map.len() == defs::MAX_CONNECTIONS {
|
if self.conn_map.len() == defs::MAX_CONNECTIONS {
|
||||||
// If we're already maxed-out on connections, we'll just accept and
|
// 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");
|
warn!("vsock: connection limit reached; refusing new host connection");
|
||||||
self.host_sock.accept().map(|_| 0).unwrap_or(0);
|
let _ = self.host_sock.accept();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.host_sock
|
self.host_sock
|
||||||
|
|||||||
@@ -110,6 +110,10 @@ impl MuxerKillQ {
|
|||||||
/// This will succeed and return a connection key, only if the connection at the front of
|
/// This will succeed and return a connection key, only if the connection at the front of
|
||||||
/// the queue has expired. Otherwise, `None` is returned.
|
/// 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> {
|
pub fn pop(&mut self) -> Option<ConnMapKey> {
|
||||||
if let Some(item) = self.q.front()
|
if let Some(item) = self.q.front()
|
||||||
&& Instant::now() > item.kill_time
|
&& Instant::now() > item.kill_time
|
||||||
|
|||||||
+1
-1
@@ -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
|
let byte = conn
|
||||||
.read()
|
.read()
|
||||||
.map_err(run_blocking::WaitForStopReasonError::Connection)?;
|
.map_err(run_blocking::WaitForStopReasonError::Connection)?;
|
||||||
|
|||||||
@@ -433,7 +433,7 @@ pub fn load_igvm(
|
|||||||
let mut now = Instant::now();
|
let mut now = Instant::now();
|
||||||
|
|
||||||
// Sort the gpas to group them by the page type
|
// 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
|
let gpas_grouped = gpas
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
+12
-14
@@ -735,22 +735,20 @@ impl Vmm {
|
|||||||
|
|
||||||
for signal in signals.forever() {
|
for signal in signals.forever() {
|
||||||
match signal {
|
match signal {
|
||||||
SIGTERM | SIGINT => {
|
SIGTERM | SIGINT if exit_evt.write(1).is_err() => {
|
||||||
if exit_evt.write(1).is_err() {
|
// Resetting the terminal is usually done as the VMM exits
|
||||||
// Resetting the terminal is usually done as the VMM exits
|
if let Ok(lock) = original_termios_opt.lock() {
|
||||||
if let Ok(lock) = original_termios_opt.lock() {
|
if let Some(termios) = *lock {
|
||||||
if let Some(termios) = *lock {
|
// SAFETY: FFI call
|
||||||
// SAFETY: FFI call
|
let _ = unsafe {
|
||||||
let _ = unsafe {
|
tcsetattr(stdout().lock().as_raw_fd(), TCSANOW, &termios)
|
||||||
tcsetattr(stdout().lock().as_raw_fd(), TCSANOW, &termios)
|
};
|
||||||
};
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
warn!("Failed to lock original termios");
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
std::process::exit(1);
|
warn!("Failed to lock original termios");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-26
@@ -132,33 +132,29 @@ impl SerialManager {
|
|||||||
|
|
||||||
let in_fd = match output {
|
let in_fd = match output {
|
||||||
ConsoleOutput::Pty(ref fd) => fd.as_raw_fd(),
|
ConsoleOutput::Pty(ref fd) => fd.as_raw_fd(),
|
||||||
ConsoleOutput::Tty(_) => {
|
// If running on an interactive TTY then accept input.
|
||||||
// If running on an interactive TTY then accept input
|
// SAFETY: trivially safe
|
||||||
// SAFETY: trivially safe
|
ConsoleOutput::Tty(_) if unsafe { libc::isatty(libc::STDIN_FILENO) == 1 } => {
|
||||||
if unsafe { libc::isatty(libc::STDIN_FILENO) == 1 } {
|
// SAFETY: STDIN_FILENO is a valid fd
|
||||||
// SAFETY: STDIN_FILENO is a valid fd
|
let fd = unsafe { libc::dup(libc::STDIN_FILENO) };
|
||||||
let fd = unsafe { libc::dup(libc::STDIN_FILENO) };
|
if fd == -1 {
|
||||||
if fd == -1 {
|
return Err(Error::DupFd(std::io::Error::last_os_error()));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
// 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) => {
|
ConsoleOutput::Socket(ref fd) => {
|
||||||
if let Some(path_in_socket) = socket {
|
if let Some(path_in_socket) = socket {
|
||||||
|
|||||||
Reference in New Issue
Block a user