Track the implicit state machines in `src/` and the defects they hide

オープン
#525 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
リファクタリング
明瞭さ
おおむね明確
活発さ
活発
技術スタック
c

調査の方向性

Start by reading the cited lifecycle and defect locations in src/runtime/thread.c, src/runtime/forkipc.c, src/syscall/signal.c, src/core/guest.c, src/syscall/inotify.c, src/syscall/usbdev.c, and src/debug/gdbstub.c. The issue says the survey was not built or run, so verify a cited defect with a focused probe or test before filing it as a separate issue and linking it here. Done means the defects are individually tracked and the proposed lifecycle changes have a defined scope.

索引モデルが issue の本文から書いたものです。

説明

enhancement

Problem

Most object lifecycles in elfuse have no named state. The state lives in a combination of bools, a sentinel value (-1, 0, NULL), a refcount plus a flag, an atomic changed by CAS, the position inside a protocol, or the X7/X8/X9-X11 registers on the HVC return path. Each transition is a write at its own call site, so nothing checks that a transition is legal from the current state, and a missing or skipped transition shows up only as a bug.

A read of src/ at 0c499d7 found 101 such lifecycles with three or more states, or two states and an ordering rule. Nothing was built or run for this survey; the defects below were found by reading the cited lines.

Only five enums in src/ name a lifecycle, and their transitions are still spread out:

  • exec_handoff_state_t (src/syscall/exec.c): one setter, exec_handoff_set_state, with no from-state check; a successful exec writes EMPTY twice.
  • urb_state_t (src/syscall/usbdev.c): three flags (discarding, orphaned, handback) carry the rest of the lifecycle, so COMPLETED also covers records IOKit still owns.
  • posix_timer_notification_t (src/syscall/signal.c): written at 6 sites in 5 functions; armed (expiry_ns != 0) and SIGEV_NONE (signum == 0) stay implicit.
  • tlbi_kind_t (src/core/guest.h): a one-way widening accumulator changed in 3 functions.
  • the anonymous hist_mode enum (src/debug/syscall-hist.c).
Area Count Examples
Signals, timers, SysV IPC, memory (signal.c, time.c, sysvipc.c, asyncio.c, sys.c, mem.c) 25 shared-set signal claims, SROP cookie stack, on_altstack, pending_fault, itimers, shmat table, RLIMIT_CPU sampler, MAP_FIXED replace transaction, brk tracker
Path and network (path.c, casefold-walk.c, chown-overlay.c, net*.c, netlink.c) 15 path_translate_at pipeline, RESOLVE_NO_XDEV walker, chown overlay entry, SCM_RIGHTS install and rollback, abstract AF_UNIX entry, netlink reply buffer and dump framing
Core (guest.c, shim.S, bootstrap.c, rosetta.c, vdso.c, shim-globals.c) 11 W^X page flip (HVC #9), post-HVC X8 protocol, stage-1 descriptor lifecycle, region tracker stale latch, attention bitmask and its vvar mirror, Rosetta placement and re-entry
Fork, exec, process, GDB (forkipc.c, fork-state.c, exec.c, proc*.c, gdbstub*.c) 11 fork IPC handshake, proc_entry_t, lifecycle registry row, ptrace tracee, pidfd entry, execve point of no return, GDB stop and continue, RSP parser
FUSE, PTY, procfs, fs.c 11 FUSE session, request, mount and file slots; PTY keepalive row and hangup accounting; union directory stream; memfd seals
fd table, special fds, poll, I/O (fdtable.c, fd.c, poll.c, inotify.c, io.c) 10 fd slot, fd_lifetime pin, timerfd, eventfd dup binding, signalfd byte count, epoll registration, io_xfer loop
USB (usbdev.c, usbdev-fixture.c, usb-sysfs.c) 10 endpoint start gate, disconnect state, ready_token, device handle ladder, interface claim
Threads and futexes (thread.c, futex.c, the run loop in proc.c) 8 thread slot, fork quiesce barrier, stop predicate, futex waiter, PI futex word

Four shapes repeat across these areas:

  1. Side tables keyed by the guest fd number: eventfd, timerfd, signalfd, inotify, netlink, abstract sockets, the socket-option cache. The state belongs to the open file description, so dup, close-then-reuse and fork break the lookup. #411 and #412 cover the cleanup and dup halves.
  2. A pipe byte that stands for a level: inotify, eventfd, signalfd, netlink, ready_token in usbdev, the wakeup pipe. Every transition site keeps "pipe readable iff X" by hand.
  3. Flags that some exit path never clears: on_altstack, noreserve, backing_drained, rlimit_cpu_killing.
  4. Slot lifecycles built from several bools, where the deactivate paths each clean up differently. Three code paths set thread_entry_t.active = 0, and only thread_deactivate also releases signal claims and the fork-barrier count.

Defects caused by a missing transition (found by reading the cited lines, not yet filed):

  • Pattern 4. thread_quiesce_siblings (src/runtime/thread.c) counts every active slot. A vm-clone child that exited but was not reaped stays active and never reaches the barrier. Its exit path in vm_clone_thread_run (src/runtime/forkipc.c) skips the step that hands the count back, which the bring-up failure path does take. Every fork therefore waits the full 100 ms timeout while such a child exists.
  • Pattern 3. Only rt_sigreturn and exec clear on_altstack (src/syscall/signal.c). When a handler on the alternate stack leaves through siglongjmp, nothing clears the flag, and sigaltstack() returns EPERM for the rest of the thread's life.
  • Pattern 3. guest_region_t.noreserve (src/core/guest.c) is set at map time and never cleared after guest_materialize_lazy has filled the block, so a later translation fault in the same block runs the materialization, and its zero fill, again.
  • Pattern 2. The host fd behind an inotify fd is the read end of its self-pipe, and only inotify_read writes to that pipe (src/syscall/inotify.c). The kqueue event never raises the pipe level, so poll and epoll_wait never report a file event before the first read. tests/test-inotify.c passes when poll times out.
  • The disconnect state in src/syscall/usbdev.c is set at each completion site. usbdev_async_cb marks the device disconnected when the main transfer result says the device is gone, but when the zero-length-packet write after it returns kIOReturnNoDevice, that result goes through usbdev_urb_status only and the transition is skipped.
  • The GDB stop state is held in one flag. gdb_stub_handle_stop (src/debug/gdbstub.c) clears stop_requested before thread_interrupt_all kicks the siblings, and the run loop's only stop check (gdb_stub_stop_requested in src/syscall/proc.c) reads that flag alone, so the kicked threads resume guest code during a GDB stop.

Proposal

  1. File each defect above as its own issue, with a probe, and link it here.
  2. For the lifecycles that already caused a defect (fd-number side tables, the FUSE request and session, the thread slot, the inotify and signalfd readiness pipes), give the state a named enum and one transition function that checks the from-state, so a skipped transition fails loudly instead of leaving a stale flag.
  3. Key the fd side tables by open file description or by generation, as usbdev and the pidfd sweep already do (#411).

Alternatives

Fix each defect where it is, with no change to how the state is held. That is smaller per change, but it leaves the next missing transition to be found the same way.

Origin

Related: #411, #412, #511, #479, #384.

主要言語
C
スター
287
フォーク
33
平均マージ
2日 17時間
マージ済み PR(30日)
18

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

sysprog21/elfuse のほかの issue

sysprog21/elfuse の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。