From 04f9d8bf25a73092e8694a89082a22727c2149d3 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 15:03:38 -0700 Subject: [PATCH 1/3] chore(quest): claim quest/m0/nightly/log-eviction.md Quest-Claim: af0627c9a6fd9200 From 003460957f43ceea8f62d92778db8e527f7870ef Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 16:18:58 -0700 Subject: [PATCH 2/3] fix(kio): order a log read before the thread's next epoch pin Off x86, crossbeam-epoch 0.9.21 pins with a Relaxed store followed by a SeqCst fence. A collector that advances past a reader because it saw the reader's next pin is then not ordered after the reads of its previous pin, so the free of an evicted segment races those reads. Loom flags it on the ARM Nightly; on x86 the pin's SeqCst CAS hides it. End every `Read` with a Release fence so any later store to the thread's epoch carries its reads to the collector's Acquire fence. It compiles to nothing on x86. Co-Authored-By: Claude Opus 5.5 --- quest/m0/nightly/README.md | 1 - quest/m0/nightly/log-eviction.md | 24 ------------------------ rs/kio/src/log.rs | 16 +++++++++++++++- rs/kio/src/loom.rs | 5 +++++ rs/kio/src/sync.rs | 4 ++-- 5 files changed, 22 insertions(+), 28 deletions(-) delete mode 100644 quest/m0/nightly/log-eviction.md 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..0693908bf49 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; @@ -473,6 +473,20 @@ pub struct Read<'a, T> { _guard: epoch::Guard, } +impl Drop for Read<'_, T> { + /// Order this 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> { /// The committed entry at `index`, or `None` when nothing is committed there yet. /// 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. From 95d2d8abf12ce45b7f4ae3f2a6aacbfd12084990 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 22:05:50 -0700 Subject: [PATCH 3/3] fix(kio): fence in a guard wrapper so Read keeps its borrow short A Drop on the generic Read held its Reader borrow until scope end, so a second reader.read() after the first's last use stopped compiling. Co-Authored-By: Claude Opus 5.5 --- rs/kio/src/log.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/rs/kio/src/log.rs b/rs/kio/src/log.rs index 0693908bf49..e7abe6684fe 100644 --- a/rs/kio/src/log.rs +++ b/rs/kio/src/log.rs @@ -442,7 +442,7 @@ impl Reader { } Read { reader: self, - _guard: guard, + _guard: ReadGuard { _pin: guard }, } } } @@ -470,11 +470,19 @@ impl fmt::Debug for Reader { /// drop it before parking. pub struct Read<'a, T> { reader: &'a mut Reader, - _guard: epoch::Guard, + _guard: ReadGuard, } -impl Drop for Read<'_, T> { - /// Order this read's accesses before whatever the thread pins next, then unpin. +/// 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