Data race on `LOGGER.buf_console` between `set_buf_console` and the logger
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 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 小时
- 30 天内合并 PR
- 28
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
tier4/awkernel 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 2 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
维护者通常 2 天内回复
-
难度 4/5 3-5 天 新手友好度 25/100
维护者通常 2 天内回复
-
难度 5/5 一周以上 新手友好度 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 天内回复