SMP: secondary cores read RUNNING_THREADS without synchronization (READY_CORES is incremented with Relaxed)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 74/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- rust
- Ambito
- operating-systems
Direzione di ricerca
Leggi scheduler/mod.rs intorno a wait_and_then_start_schedule e al READY_CORES.fetch_add in schedule; segui la scrittura del thread idle in scheduler/idle.rs per capire cosa pubblica il contatore. L’issue segnala che il controllo KMiri passa dopo aver modificato l’incremento in Release; esegui il test unitario KMiri con due hart su qemu_riscv64 e conferma che questa race è scomparsa. Il pattern SmpStagedInit menzionato separatamente e la race successiva di RUNNING_THREADS non rientrano nella correzione indicata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
On SMP boards, the secondary cores read RUNNING_THREADS without a happens-before edge to core 0's write of it. Core 0 publishes "the scheduler is ready" with a Relaxed increment, so the secondary core's Acquire load synchronizes with nothing. Under the Rust memory model this is a data race on a non-atomic location, which is undefined behavior. On weakly ordered hardware (RVWMO, Arm) a secondary core may see the counter before it sees the idle thread that core 0 stored.
Where (main, e0b476f2d)
Core 0, in boot::init (boot.rs:84):
scheduler::init()(boot.rs:128) →idle::init_idle_threads()→scheduler/idle.rs:66stores every core's idle thread with a plain write:RUNNING_THREADS[i].write(arc.clone());arch::start_schedule(scheduler::schedule)(boot.rs:145).scheduler/mod.rs:469, inschedule():READY_CORES.fetch_add(1, Ordering::Relaxed);
Secondary cores, after board init (e.g. boards/qemu_riscv64/mod.rs:72), run wait_and_then_start_schedule (scheduler/mod.rs:460):
while READY_CORES.load(Ordering::Acquire) == 0 {
core::hint::spin_loop();
}
arch::start_schedule(schedule);
start_schedule calls current_thread_ref(), which reads RUNNING_THREADS[my_id] (scheduler/mod.rs:490).
An Acquire load only synchronizes with a Release (or stronger) store. fetch_add(1, Relaxed) is not one, so nothing orders the write at idle.rs:66 before the read at mod.rs:490.
Fix
Make the increment release the writes before it:
READY_CORES.fetch_add(1, Ordering::Release);
SmpStagedInit::run (support.rs:379 and support.rs:392) uses the same pattern: core 0 finishes a stage, then self.stage.fetch_add(1, Ordering::Relaxed), and the other cores wait with load(Acquire). Any state from init_runtime or init_heap that a secondary core reads afterwards has the same problem. I have not shown a concrete racing access there, so I only flag it.
How it was found
We ran the qemu_riscv64 unit-test kernel with two harts in KMiri, a Miri-based interpreter for kernels that checks for language-level UB, including data races. All harts start at the reset entry, as on QEMU. The run stops right after boot:
error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `main`
and (2) non-atomic read on thread `unnamed-1`
(2) core::ptr::NonNull::as_ref <- TinyArc::deref <- scheduler::current_thread_ref (scheduler/mod.rs:490)
<- arch::start_schedule <- scheduler::wait_and_then_start_schedule <- board init (hart 1)
(1) scheduler/idle.rs:66 RUNNING_THREADS[i].write(arc.clone()) (hart 0)
With only mod.rs:469 changed to Ordering::Release, this race is no longer reported.
The run then reaches the race that the FIXME above is_idle_core (scheduler/mod.rs:525) already mentions: notify_idle_cores reads another core's RUNNING_THREADS[id] while that core replaces it in set_current_thread. I mention it only because it is the next thing an SMP run hits.
- Lingua principale
- Rust
- Stelle
- 1.3k
- Fork
- 95
- Merge medio
- 2g 12h
- PR unite (30g)
- 29
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di vivoblueos/kernel
-
CONFIG_ALLOCATOR_LLFF does not compile: unsafe calls without unsafe blocks in allocator/llff/heap.rsAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
vivoblueos/kernel#590 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
vivoblueos/kernel#589 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
vivoblueos/kernel#523 ·
I maintainer di solito rispondono entro 1 giorno
-
Support CMSIS on qemu_mps3_an547Forse di nuovo libera @yhay81 l’ha presa 137 giorni fa e non c’è nessuna pull request aperta. Apertaenhancement good first issue help wanted priority: medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
vivoblueos/kernel#201 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
vivoblueos/kernel#583 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di vivoblueos/kernel
Issue simili
-
marketing
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
CATboardBETA/carr#18 ·
-
[Suggestion]: AgentermAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
collabnix/awesome-mcp-lists#490 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
wardian-app/Wardian#1841 ·
I maintainer di solito rispondono entro 1 giorno
-
area:infra help wanted type:ci
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
JoeyHammoth/semiconductor-bandgap-belvedere#62 ·
I maintainer di solito rispondono entro 1 giorno