Skip to content

Count only owned children in nr_children - #1

Open
vilhelms wants to merge 1 commit into
mainfrom
vilhelm/nr-children-owned
Open

vilhelms wants to merge 1 commit into
mainfrom
vilhelm/nr-children-owned

Conversation

@vilhelms

Copy link
Copy Markdown
Collaborator

count_consistent (part of metaregion_sound_node) says nr_children counts every present PTE of a node. Upstream counts only the children a node owns:

  • create_user_page_table copies the kernel half of the top level into a new user root with write_pte and does not increment nr_children; the user root borrows those entries.
  • PageTablePageMeta::on_drop walks only TOP_LEVEL_INDEX_RANGE for a top-level node, so it never drops them.

So after create_user_page_table the new user root breaks count_consistent (256 present PTEs, nr_children == 0). Main does not notice because the function drops the new page table's owner, but anything that later needs a sound owner for that page table would fail.

Changes

  • NodeOwner::owned_range: TOP_LEVEL_INDEX_RANGE for a top-level node, all slots otherwise. count_owned counts the present PTEs in it; count_consistent is now nr_children == count_owned().
  • count_present_between and its lemmas replace the whole-array count_present helpers, which are removed. lemma_count_owned_update: writing a slot changes the count only if the node owns the slot.
  • Entry operations that can change a slot's presence (replace, alloc_if_none, replace_child, alloc_absent_child, replace_absent_with_frame) require owns_slot(idx). The cursor discharges it with the new CursorOwner::lemma_cur_slot_owned (inside its range, the current node owns the slot it points at).
  • lemma_view_rec_nr_children_zero_empty requires a node below the top level, as its one caller has.
  • create_user_page_table now proves the new user root stays count_consistent through the copy loop.

No trusted code is added and no executable code changes. cargo dv verify -p ostd: 1491 verified, 0 errors (main: 1489).

Noticed but not changed: vostd's trusted on_drop omits upstream's if nr_children == 0 { return; } early return.

🤖 Generated with Claude Code

`count_consistent` said that `nr_children` counts every present PTE of
a node. Upstream counts only the children a node owns: a user page
table's root borrows the kernel half, so `create_user_page_table`
copies those PTEs in without incrementing `nr_children`, and
`PageTablePageMeta::on_drop` walks only `TOP_LEVEL_INDEX_RANGE`. The
new user root therefore broke `count_consistent`; main did not notice
because `create_user_page_table` drops the new page table's owner.

- `NodeOwner::owned_range` is `TOP_LEVEL_INDEX_RANGE` for a top-level
  node and all slots otherwise; `count_owned` counts the present PTEs
  in it, and `count_consistent` now says `nr_children == count_owned()`.
- `count_present_between` and its lemmas replace the whole-array
  `count_present` helpers. `lemma_count_owned_update`: writing a slot
  changes the count only if the node owns the slot.
- The entry operations that can change a slot's presence (`replace`,
  `alloc_if_none`, `replace_child`, `alloc_absent_child`,
  `replace_absent_with_frame`) require the node to own the slot; the
  cursor shows it with the new `lemma_cur_slot_owned`.
- `create_user_page_table` now proves the new user root stays
  `count_consistent` while the kernel half is copied in.

No trusted code is added and no executable code changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vilhelms
vilhelms force-pushed the vilhelm/nr-children-owned branch from 05e6e52 to 920c5fd Compare November 23, 2026 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant