Data race on `LOGGER.buf_console` between `set_buf_console` and the logger
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- rust
調査の方向性
Start with awkernel_lib/src/logger.rs and trace set_buf_console alongside Logger::enabled, Logger::log, and Logger::flush; then check the buffered logger setup in applications/awkernel_services/src/buffered_logger.rs. Verify how console registration and logging can overlap across CPUs, including the set_raw_console path. Done when the shared logger state is accessed without a data race and the boot-time raw console behavior is understood.
索引モデルが issue の本文から書いたものです。
説明
Summary
awkernel_lib::logger::set_buf_console writes LOGGER.buf_console without synchronization while other CPUs read it through log::info! and the other logging macros. This is a data race, which is undefined behavior in Rust.
This was found during the review of #799.
Details
LOGGER is a static mut in awkernel_lib/src/logger.rs:
static mut LOGGER: Logger = Logger {
raw_console: None,
buf_console: None,
};
- Writer:
set_buf_consoleruns(*ptr).buf_console = Some(logger)with no lock and no atomic operation. The buffered logger task (applications/awkernel_services/src/buffered_logger.rs) calls it, so it runs after all CPUs have started to execute tasks. - Readers:
Logger::enabled,Logger::log, andLogger::flushreadself.buf_consoleon every CPU each time a logging macro is called, also with no synchronization.
Possible effect
Option<&'static dyn Log> is two words: a data pointer and a vtable pointer. The write can be two stores. A CPU that reads between them can get the new data pointer with the old vtable pointer, and log.log(record) then calls through an invalid vtable.
The window is a few instructions and the write happens once at boot, so this is unlikely to occur in practice. I have not reproduced it.
Proposed fix
buf_console is written once and never changed afterward, so a separate AtomicBool that publishes it is enough:
set_buf_consolewrites the pointer, and then sets the flag withOrdering::Release.Loggerloads the flag withOrdering::Acquire, and readsbuf_consoleonly when the flag is set.
With this, no CPU reads the pointer while it is written.
Related
set_raw_console writes raw_console in the same way. It is called from console::register_console, which appears to run during early boot before the other CPUs start. Whether it can run concurrently with logging on another CPU should be checked as part of this issue.
- 主要言語
- Rust
- スター
- 282
- フォーク
- 12
- 平均マージ
- 2日 9時間
- マージ済み PR(30日)
- 28
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
tier4/awkernel のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 2 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 2 日以内に返信
-
Deadlock in ixgbeオープン
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
メンテナーはふだん 2 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
メンテナーはふだん 2 日以内に返信
似ている issue
-
marketing
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
flashbots/panetiere#46 · コメント 1 件 ·
メンテナーはふだん 5 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
jlcodes99/cockpit-tools#3190 ·
メンテナーはふだん 4 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Feyisara2108/stellargive#1376 ·
メンテナーはふだん 1 日以内に返信
-
area:post bug effort:medium P7 source:agent
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信