From 6255598baaa4fd8f4c78a1f4f421869192d3bfe2 Mon Sep 17 00:00:00 2001 From: tiif Date: Sat, 16 Nov 2024 00:29:11 +0800 Subject: [PATCH 1/2] docs: update miri test command in CONTRIBUTING.md (#6976) --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 681b1c288c3..e2e377b295f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -201,7 +201,7 @@ run loom tests that test unstable features. You can run miri tests with ``` MIRIFLAGS="-Zmiri-disable-isolation -Zmiri-strict-provenance -Zmiri-retag-fields" \ - cargo +nightly miri test --features full --lib + cargo +nightly miri test --features full --lib --tests ``` ### Performing spellcheck on tokio codebase From 2f899144ed0fb3701bf0996578803ae9df80ebda Mon Sep 17 00:00:00 2001 From: tiif Date: Sat, 16 Nov 2024 18:16:09 +0800 Subject: [PATCH 2/2] io: avoid ptr->ref->ptr roundtrip in `RegistrationSet` (#6929) --- tokio/src/runtime/io/registration_set.rs | 11 ++++++---- tokio/tests/io_async_fd.rs | 26 +++++++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/tokio/src/runtime/io/registration_set.rs b/tokio/src/runtime/io/registration_set.rs index 9b2f3f13c43..9b23732d96a 100644 --- a/tokio/src/runtime/io/registration_set.rs +++ b/tokio/src/runtime/io/registration_set.rs @@ -106,7 +106,7 @@ impl RegistrationSet { for io in pending { // safety: the registration is part of our list - unsafe { self.remove(synced, io.as_ref()) } + unsafe { self.remove(synced, &io) } } self.num_pending_release.store(0, Release); @@ -114,9 +114,12 @@ impl RegistrationSet { // This function is marked as unsafe, because the caller must make sure that // `io` is part of the registration set. - pub(super) unsafe fn remove(&self, synced: &mut Synced, io: &ScheduledIo) { - super::EXPOSE_IO.unexpose_provenance(io); - let _ = synced.registrations.remove(io.into()); + pub(super) unsafe fn remove(&self, synced: &mut Synced, io: &Arc) { + // SAFETY: Pointers into an Arc are never null. + let io = unsafe { NonNull::new_unchecked(Arc::as_ptr(io).cast_mut()) }; + + super::EXPOSE_IO.unexpose_provenance(io.as_ptr()); + let _ = synced.registrations.remove(io); } } diff --git a/tokio/tests/io_async_fd.rs b/tokio/tests/io_async_fd.rs index 469d2a4acbe..fc243eb729a 100644 --- a/tokio/tests/io_async_fd.rs +++ b/tokio/tests/io_async_fd.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(unix, feature = "full", not(miri)))] +#![cfg(all(unix, feature = "full"))] use std::os::unix::io::{AsRawFd, RawFd}; use std::sync::{ @@ -148,6 +148,7 @@ fn drain(mut fd: &FileDescriptor, mut amt: usize) { } #[tokio::test] +#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri. async fn initially_writable() { let (a, b) = socketpair(); @@ -166,6 +167,7 @@ async fn initially_writable() { } #[tokio::test] +#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri. async fn reset_readable() { let (a, mut b) = socketpair(); @@ -210,6 +212,7 @@ async fn reset_readable() { } #[tokio::test] +#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri. async fn reset_writable() { let (a, b) = socketpair(); @@ -247,6 +250,7 @@ impl AsRawFd for ArcFd { } #[tokio::test] +#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri. async fn drop_closes() { let (a, mut b) = socketpair(); @@ -287,6 +291,7 @@ async fn drop_closes() { } #[tokio::test] +#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri. async fn reregister() { let (a, _b) = socketpair(); @@ -296,6 +301,7 @@ async fn reregister() { } #[tokio::test] +#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri. async fn try_io() { let (a, mut b) = socketpair(); @@ -331,6 +337,7 @@ async fn try_io() { } #[tokio::test] +#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri. async fn multiple_waiters() { let (a, mut b) = socketpair(); let afd_a = Arc::new(AsyncFd::new(a).unwrap()); @@ -379,6 +386,7 @@ async fn multiple_waiters() { } #[tokio::test] +#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri. async fn poll_fns() { let (a, b) = socketpair(); let afd_a = Arc::new(AsyncFd::new(a).unwrap()); @@ -472,6 +480,7 @@ fn rt() -> tokio::runtime::Runtime { } #[test] +#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri. fn driver_shutdown_wakes_currently_pending() { let rt = rt(); @@ -493,6 +502,7 @@ fn driver_shutdown_wakes_currently_pending() { } #[test] +#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri. fn driver_shutdown_wakes_future_pending() { let rt = rt(); @@ -508,6 +518,7 @@ fn driver_shutdown_wakes_future_pending() { } #[test] +#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri. fn driver_shutdown_wakes_pending_race() { // TODO: make this a loom test for _ in 0..100 { @@ -538,6 +549,7 @@ async fn poll_writable(fd: &AsyncFd) -> std::io::Result(stream: &S, data: &[u8]) -> io::Result { } #[tokio::test] -#[cfg_attr(miri, ignore)] +#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri. async fn clear_ready_matching_clears_ready() { use tokio::io::{Interest, Ready}; @@ -679,7 +695,7 @@ async fn clear_ready_matching_clears_ready() { } #[tokio::test] -#[cfg_attr(miri, ignore)] +#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri. async fn clear_ready_matching_clears_ready_mut() { use tokio::io::{Interest, Ready}; @@ -703,8 +719,8 @@ async fn clear_ready_matching_clears_ready_mut() { } #[tokio::test] +#[cfg_attr(miri, ignore)] // No socket in miri. #[cfg(target_os = "linux")] -#[cfg_attr(miri, ignore)] async fn await_error_readiness_timestamping() { use std::net::{Ipv4Addr, SocketAddr}; @@ -760,8 +776,8 @@ fn configure_timestamping_socket(udp_socket: &std::net::UdpSocket) -> std::io::R } #[tokio::test] +#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri. #[cfg(target_os = "linux")] -#[cfg_attr(miri, ignore)] async fn await_error_readiness_invalid_address() { use std::net::{Ipv4Addr, SocketAddr}; use tokio::io::{Interest, Ready};