Skip to content

id-allocator: fix double-alloc and add is_allocated public fn#120

Merged
andreeaflorescu merged 3 commits into
rust-vmm:mainfrom
JamesC1305:id-alloc-is-allocated
Jun 1, 2026
Merged

id-allocator: fix double-alloc and add is_allocated public fn#120
andreeaflorescu merged 3 commits into
rust-vmm:mainfrom
JamesC1305:id-alloc-is-allocated

Conversation

@JamesC1305
Copy link
Copy Markdown
Contributor

  • Fix an off-by-one error in free_id that could allow for ids to be double allocated
  • Add new is_allocated method, so that implementing programs can query whether an id is currently allocated or not
  • Update changelog accordingly

Requirements

Before submitting your PR, please make sure you addressed the following
requirements:

  • All commits in this PR have Signed-Off-By trailers (with
    git commit -s), and the commit message has max 60 characters for the
    summary and max 75 characters for each description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

Comment thread src/id_allocator.rs
next_id points to the next *free* id. The implementation of free_id
previously would allow id == next_id to be 'freed', despite never being
allocated. The implication of this is that a GSI could be double
allocated, first by popping `id` from the freed list (next_id remains
the same), then a second by incrementing next id.

Signed-off-by: James Curtis <jxcurtis@amazon.co.uk>
@JamesC1305 JamesC1305 force-pushed the id-alloc-is-allocated branch 2 times, most recently from 745d837 to 2d3dd75 Compare May 29, 2026 16:02
Introduce a new public function, `is_allocated` to the IdAllocator. This
allows a program to validate whether ID has already been allocated. An
interrupt ID (`id`) is determined to be currently allocated iff:

1. It is within `[range_base, range_end]` and
2. `id < next_id` or `next_id == None` and
3. It is not currently in `freed_ids`

Signed-off-by: James Curtis <jxcurtis@amazon.co.uk>
Update CHANGELOG.md to have changes made in this PR.

Signed-off-by: James Curtis <jxcurtis@amazon.co.uk>
@JamesC1305 JamesC1305 force-pushed the id-alloc-is-allocated branch from 2d3dd75 to bbcd621 Compare May 29, 2026 16:09
@andreeaflorescu andreeaflorescu merged commit 10bee9b into rust-vmm:main Jun 1, 2026
2 checks passed
@JamesC1305 JamesC1305 mentioned this pull request Jun 3, 2026
4 tasks
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.

3 participants