MPK: Segfault running an `Engine` on a preexisting thread
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Two reproducers are given in the issue: one segfaults when a Store (with memory_protection_keys(Enabled::Yes) and linear_memory_keep_resident) is dropped on a different thread than where it ran, the other when an Engine's memory is read from a preexisting thread. Start by reproducing both under a debugger to see where the fault happens, then trace wasmtime's MPK/PKRU handling in the pooling allocator — where per-thread key state is registered, saved/restored across threads, and cleaned up on thread exit and Store drop. Done means both snippets run to completion without a segfault, ideally with a regression test.
索引モデルが issue の本文から書いたものです。
説明
This input:
use std::sync::mpsc;
use wasmtime::*;
const WAT: &str = r#"(module
(memory (export "m") 1)
(data (i32.const 0) "hello")
(func (export "f") (i32.store (i32.const 100) (i32.const 1))))"#;
fn engine() -> Result<Engine> {
let mut pool = PoolingAllocationConfig::default();
pool.memory_protection_keys(Enabled::Yes);
pool.total_memories(32);
pool.linear_memory_keep_resident(65536);
let mut config = Config::new();
config.allocation_strategy(InstanceAllocationStrategy::Pooling(pool));
Engine::new(&config)
}
fn main() -> Result<()> {
let (tx, rx) = mpsc::channel::<Store<()>>();
let pre = std::thread::spawn(move || {
let store = rx.recv().unwrap();
eprintln!("dropping store on other thread...");
drop(store);
eprintln!("dropped");
});
let engine = engine()?;
let module = Module::new(&engine, WAT)?;
let mut store = Store::new(&engine, ());
let instance = Instance::new(&mut store, &module, &[])?;
instance
.get_typed_func::<(), ()>(&mut store, "f")?
.call(&mut store, ())?;
tx.send(store).unwrap();
pre.join().unwrap();
Ok(())
}
fails with:
$ cargo run
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/mpk-thread`
dropping store on other thread...
zsh: segmentation fault (core dumped) cargo run
and this input:
use std::sync::mpsc;
use wasmtime::*;
const WAT: &str = r#"(module
(memory (export "m") 1)
(data (i32.const 0) "hello")
(func (export "f") (i32.store (i32.const 100) (i32.const 1))))"#;
fn engine() -> Result<Engine> {
let mut pool = PoolingAllocationConfig::default();
pool.memory_protection_keys(Enabled::Yes);
pool.total_memories(32);
pool.linear_memory_keep_resident(65536);
let mut config = Config::new();
config.allocation_strategy(InstanceAllocationStrategy::Pooling(pool));
Engine::new(&config)
}
fn main() -> Result<()> {
let (tx, rx) = mpsc::channel::<Engine>();
let worker = std::thread::spawn(move || -> Result<()> {
let engine = rx.recv().unwrap();
let module = Module::new(&engine, WAT)?;
let mut store = Store::new(&engine, ());
let instance = Instance::new(&mut store, &module, &[])?;
let mem = instance.get_memory(&mut store, "m").unwrap();
eprintln!("reading memory from pre-existing thread...");
eprintln!("data = {:?}", &mem.data(&store)[..5]);
Ok(())
});
tx.send(engine()?).unwrap();
worker.join().unwrap()?;
Ok(())
}
fails with:
$ cargo run
Compiling mpk-thread v0.1.0 (/home/alex/code/wasmtime2/reports/001-mpk-pkru-preexisting-thread-segv)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.39s
Running `target/debug/mpk-thread`
reading memory from pre-existing thread...
data = [zsh: segmentation fault (core dumped) cargo run
- 主要言語
- Rust
- スター
- 18.9k
- フォーク
- 2k
- 平均マージ
- 1日 6時間
- マージ済み PR(30日)
- 238
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
bytecodealliance/wasmtime のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
bytecodealliance/wasmtime#15536 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
bytecodealliance/wasmtime#15455 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
wasi-preview1-component-adapter: fd_write does not invalidate cached InputStream, causing stale reads対応中かも @dpfens が 13 日前に担当しました。 オープンwasi
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
bytecodealliance/wasmtime#15296 ·
メンテナーはふだん 1 日以内に返信
-
bug wasm-proposal:exceptions wasmtime:debugging
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
bytecodealliance/wasmtime#14102 ·
メンテナーはふだん 1 日以内に返信
-
wasm-proposal:gc
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
bytecodealliance/wasmtime#13808 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
bytecodealliance/wasmtime の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
area: plugins bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
clipy-recorder/clipy#1039 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
valkey-io/valkey-glide#7975 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
gofractally/psibase#2379 ·
メンテナーはふだん 3 日以内に返信
-
Qwen stream parser: a chunk with "error": null is treated as a stream error対応中かも @Beehtrix が今日担当しました。 オープンarea:models bug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
brekkylab/ailoy#681 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信