diff --git a/quest/m0/nightly/README.md b/quest/m0/nightly/README.md index 22bfd31dfb1..150d5e46fcd 100644 --- a/quest/m0/nightly/README.md +++ b/quest/m0/nightly/README.md @@ -31,7 +31,6 @@ Public API: none. Wire: none. ## Required -- [Log eviction passes the ARM concurrency model](/quest/m0/nightly/log-eviction.md) - the log eviction model passes on ARM and x86, with every segment access protected from reclamation - [The software renderer tests both capability paths](/quest/m0/nightly/render-capabilities.md) - the software-renderer lane verifies output selection with and without DMA-BUF import support without requiring hardware the runner lacks - [Shipping size history admits the generated C package](/quest/m0/nightly/shipping-history.md) - nightly measures the generated C shipping archives while preserving comparable existing size history and refusing missing or renamed artifacts - [The browser publisher completes its fairness sweep](/quest/m0/nightly/publisher-fairness.md) - the publisher fairness benchmark completes its backlog on the hosted ARM runner, yielding browser tasks while serving every group diff --git a/quest/m0/nightly/log-eviction.md b/quest/m0/nightly/log-eviction.md deleted file mode 100644 index a835b9cf595..00000000000 --- a/quest/m0/nightly/log-eviction.md +++ /dev/null @@ -1,24 +0,0 @@ -# [M] Log eviction passes the ARM concurrency model - -## Goal - -The log eviction model passes on ARM and x86, with every segment access protected from reclamation. - -## Plan - -[The 2026-10-28 Loom job](https://github.com/moq-dev/moq/actions/runs/40698329026/job/122851001821) aborts in -`a_log_reader_racing_eviction_never_touches_freed_memory` with a concurrent -read/write of `UnsafeCell`. The original panic precedes the destructor panics. - -The isolated model passes on x86 (90.83 s). A scratch reproduction using the -same model and forcing crossbeam-epoch 0.9.21's non-x86 `pin` branch fails in -`kio::log::Segment::free`. The x86 branch uses a sequentially consistent CAS; -the non-x86 branch uses a relaxed store and a sequentially consistent fence. -This reproduces the failing path, not a proven production use-after-free. - -Determine whether the log's epoch/hint protocol or its model integration is -wrong, reproduce the interleaving, and fix the cause. Preserve reclamation of -evicted entries while readers are idle and protect borrowed entries while a -read is pinned. The x86 pass alone cannot validate the fix. - -Public API: none expected. Wire: none expected. diff --git a/rs/kio/src/log.rs b/rs/kio/src/log.rs index 3cd03bb16b2..e7abe6684fe 100644 --- a/rs/kio/src/log.rs +++ b/rs/kio/src/log.rs @@ -29,7 +29,7 @@ use std::{ use crossbeam_epoch as epoch; use smallvec::SmallVec; -use crate::sync::{Arc, AtomicPtr, AtomicU64, AtomicUsize, UnsafeCell}; +use crate::sync::{Arc, AtomicPtr, AtomicU64, AtomicUsize, UnsafeCell, fence}; /// Slots in the first segment: one, since many logs never hold more. const FIRST_SEGMENT: usize = 1; @@ -442,7 +442,7 @@ impl Reader { } Read { reader: self, - _guard: guard, + _guard: ReadGuard { _pin: guard }, } } } @@ -470,7 +470,29 @@ impl fmt::Debug for Reader { /// drop it before parking. pub struct Read<'a, T> { reader: &'a mut Reader, - _guard: epoch::Guard, + _guard: ReadGuard, +} + +/// The pin behind a [`Read`], released only after the read's accesses. +/// +/// A wrapper rather than a `Drop` on `Read` itself, which would hold the `Reader` borrow +/// until the end of the scope instead of the last use. +struct ReadGuard { + _pin: epoch::Guard, +} + +impl Drop for ReadGuard { + /// Order the read's accesses before whatever the thread pins next, then unpin. + /// + /// The collector frees a segment once it sees every thread unpinned or pinned anew, + /// and the free must happen after the reads it waited out. Seeing the unpin, a + /// Release store, orders them. Seeing a later pin may not: off x86, crossbeam-epoch + /// 0.9 pins with a Relaxed store, which carries nothing of the pin before it. This + /// fence makes every later store to the thread's epoch carry these reads to the + /// collector's Acquire fence. On x86 it compiles to nothing. + fn drop(&mut self) { + fence(Ordering::Release); + } } impl Read<'_, T> { diff --git a/rs/kio/src/loom.rs b/rs/kio/src/loom.rs index 3d89efb01af..a393b8d2d2b 100644 --- a/rs/kio/src/loom.rs +++ b/rs/kio/src/loom.rs @@ -427,6 +427,11 @@ fn a_log_append_wakes_a_reader_parked_on_its_channel() { /// read it isn't ordered after fails the model. The reader keeps a hint into the first /// segment from an earlier read, which the eviction may free before its next one. /// +/// Only an ARM run checks the release at the end of each read: off x86, crossbeam-epoch +/// pins with a Relaxed store, so a collector that sees the reader's second pin is +/// ordered after its first pin's reads only through that release. On x86 its SeqCst CAS +/// orders them anyway. +/// /// The collector's own atomics run under loom too (`crossbeam_loom`), which makes the /// full search intractable, so this one bounds preemptions like moq-net's models. #[test] diff --git a/rs/kio/src/sync.rs b/rs/kio/src/sync.rs index 9cbf8bbb197..37402a6a64f 100644 --- a/rs/kio/src/sync.rs +++ b/rs/kio/src/sync.rs @@ -18,13 +18,13 @@ pub(crate) use loom::{ cell::UnsafeCell, sync::{ Arc, Mutex, MutexGuard, - atomic::{AtomicBool, AtomicPtr, AtomicU64, AtomicUsize}, + atomic::{AtomicBool, AtomicPtr, AtomicU64, AtomicUsize, fence}, }, }; #[cfg(not(loom))] pub(crate) use std::sync::{ Arc, Mutex, MutexGuard, - atomic::{AtomicBool, AtomicPtr, AtomicU64, AtomicUsize}, + atomic::{AtomicBool, AtomicPtr, AtomicU64, AtomicUsize, fence}, }; /// `std::cell::UnsafeCell` behind loom's closure API, so loom can check every access.