io: avoid ptr->ref->ptr roundtrip in RegistrationSet (#6929)

This commit is contained in:
tiif
2024-11-16 11:16:09 +01:00
committed by GitHub
parent 6255598baa
commit 2f899144ed
2 changed files with 28 additions and 9 deletions
+7 -4
View File
@@ -106,7 +106,7 @@ impl RegistrationSet {
for io in pending { for io in pending {
// safety: the registration is part of our list // 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); 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 // This function is marked as unsafe, because the caller must make sure that
// `io` is part of the registration set. // `io` is part of the registration set.
pub(super) unsafe fn remove(&self, synced: &mut Synced, io: &ScheduledIo) { pub(super) unsafe fn remove(&self, synced: &mut Synced, io: &Arc<ScheduledIo>) {
super::EXPOSE_IO.unexpose_provenance(io); // SAFETY: Pointers into an Arc are never null.
let _ = synced.registrations.remove(io.into()); 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);
} }
} }
+21 -5
View File
@@ -1,5 +1,5 @@
#![warn(rust_2018_idioms)] #![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::os::unix::io::{AsRawFd, RawFd};
use std::sync::{ use std::sync::{
@@ -148,6 +148,7 @@ fn drain(mut fd: &FileDescriptor, mut amt: usize) {
} }
#[tokio::test] #[tokio::test]
#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri.
async fn initially_writable() { async fn initially_writable() {
let (a, b) = socketpair(); let (a, b) = socketpair();
@@ -166,6 +167,7 @@ async fn initially_writable() {
} }
#[tokio::test] #[tokio::test]
#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri.
async fn reset_readable() { async fn reset_readable() {
let (a, mut b) = socketpair(); let (a, mut b) = socketpair();
@@ -210,6 +212,7 @@ async fn reset_readable() {
} }
#[tokio::test] #[tokio::test]
#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri.
async fn reset_writable() { async fn reset_writable() {
let (a, b) = socketpair(); let (a, b) = socketpair();
@@ -247,6 +250,7 @@ impl<T: AsRawFd> AsRawFd for ArcFd<T> {
} }
#[tokio::test] #[tokio::test]
#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri.
async fn drop_closes() { async fn drop_closes() {
let (a, mut b) = socketpair(); let (a, mut b) = socketpair();
@@ -287,6 +291,7 @@ async fn drop_closes() {
} }
#[tokio::test] #[tokio::test]
#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri.
async fn reregister() { async fn reregister() {
let (a, _b) = socketpair(); let (a, _b) = socketpair();
@@ -296,6 +301,7 @@ async fn reregister() {
} }
#[tokio::test] #[tokio::test]
#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri.
async fn try_io() { async fn try_io() {
let (a, mut b) = socketpair(); let (a, mut b) = socketpair();
@@ -331,6 +337,7 @@ async fn try_io() {
} }
#[tokio::test] #[tokio::test]
#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri.
async fn multiple_waiters() { async fn multiple_waiters() {
let (a, mut b) = socketpair(); let (a, mut b) = socketpair();
let afd_a = Arc::new(AsyncFd::new(a).unwrap()); let afd_a = Arc::new(AsyncFd::new(a).unwrap());
@@ -379,6 +386,7 @@ async fn multiple_waiters() {
} }
#[tokio::test] #[tokio::test]
#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri.
async fn poll_fns() { async fn poll_fns() {
let (a, b) = socketpair(); let (a, b) = socketpair();
let afd_a = Arc::new(AsyncFd::new(a).unwrap()); let afd_a = Arc::new(AsyncFd::new(a).unwrap());
@@ -472,6 +480,7 @@ fn rt() -> tokio::runtime::Runtime {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri.
fn driver_shutdown_wakes_currently_pending() { fn driver_shutdown_wakes_currently_pending() {
let rt = rt(); let rt = rt();
@@ -493,6 +502,7 @@ fn driver_shutdown_wakes_currently_pending() {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri.
fn driver_shutdown_wakes_future_pending() { fn driver_shutdown_wakes_future_pending() {
let rt = rt(); let rt = rt();
@@ -508,6 +518,7 @@ fn driver_shutdown_wakes_future_pending() {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri.
fn driver_shutdown_wakes_pending_race() { fn driver_shutdown_wakes_pending_race() {
// TODO: make this a loom test // TODO: make this a loom test
for _ in 0..100 { for _ in 0..100 {
@@ -538,6 +549,7 @@ async fn poll_writable<T: AsRawFd>(fd: &AsyncFd<T>) -> std::io::Result<AsyncFdRe
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri.
fn driver_shutdown_wakes_currently_pending_polls() { fn driver_shutdown_wakes_currently_pending_polls() {
let rt = rt(); let rt = rt();
@@ -560,6 +572,7 @@ fn driver_shutdown_wakes_currently_pending_polls() {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri.
fn driver_shutdown_wakes_poll() { fn driver_shutdown_wakes_poll() {
let rt = rt(); let rt = rt();
@@ -576,6 +589,7 @@ fn driver_shutdown_wakes_poll() {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri.
fn driver_shutdown_then_clear_readiness() { fn driver_shutdown_then_clear_readiness() {
let rt = rt(); let rt = rt();
@@ -593,6 +607,7 @@ fn driver_shutdown_then_clear_readiness() {
} }
#[test] #[test]
#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri.
fn driver_shutdown_wakes_poll_race() { fn driver_shutdown_wakes_poll_race() {
// TODO: make this a loom test // TODO: make this a loom test
for _ in 0..100 { for _ in 0..100 {
@@ -615,6 +630,7 @@ fn driver_shutdown_wakes_poll_race() {
} }
#[tokio::test] #[tokio::test]
#[cfg_attr(miri, ignore)] // No socket in miri.
#[cfg(any(target_os = "linux", target_os = "android"))] #[cfg(any(target_os = "linux", target_os = "android"))]
async fn priority_event_on_oob_data() { async fn priority_event_on_oob_data() {
use std::net::SocketAddr; use std::net::SocketAddr;
@@ -655,7 +671,7 @@ fn send_oob_data<S: AsRawFd>(stream: &S, data: &[u8]) -> io::Result<usize> {
} }
#[tokio::test] #[tokio::test]
#[cfg_attr(miri, ignore)] #[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri.
async fn clear_ready_matching_clears_ready() { async fn clear_ready_matching_clears_ready() {
use tokio::io::{Interest, Ready}; use tokio::io::{Interest, Ready};
@@ -679,7 +695,7 @@ async fn clear_ready_matching_clears_ready() {
} }
#[tokio::test] #[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() { async fn clear_ready_matching_clears_ready_mut() {
use tokio::io::{Interest, Ready}; use tokio::io::{Interest, Ready};
@@ -703,8 +719,8 @@ async fn clear_ready_matching_clears_ready_mut() {
} }
#[tokio::test] #[tokio::test]
#[cfg_attr(miri, ignore)] // No socket in miri.
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
#[cfg_attr(miri, ignore)]
async fn await_error_readiness_timestamping() { async fn await_error_readiness_timestamping() {
use std::net::{Ipv4Addr, SocketAddr}; use std::net::{Ipv4Addr, SocketAddr};
@@ -760,8 +776,8 @@ fn configure_timestamping_socket(udp_socket: &std::net::UdpSocket) -> std::io::R
} }
#[tokio::test] #[tokio::test]
#[cfg_attr(miri, ignore)] // No F_GETFL for fcntl in miri.
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
#[cfg_attr(miri, ignore)]
async fn await_error_readiness_invalid_address() { async fn await_error_readiness_invalid_address() {
use std::net::{Ipv4Addr, SocketAddr}; use std::net::{Ipv4Addr, SocketAddr};
use tokio::io::{Interest, Ready}; use tokio::io::{Interest, Ready};