Skip to content

nvme: report a fixed maximum namespace ID in Identify Controller#3740

Open
jstarks wants to merge 2 commits into
microsoft:mainfrom
jstarks:nn
Open

nvme: report a fixed maximum namespace ID in Identify Controller#3740
jstarks wants to merge 2 commits into
microsoft:mainfrom
jstarks:nn

Conversation

@jstarks

@jstarks jstarks commented Jun 13, 2026

Copy link
Copy Markdown
Member

The NN field of Identify Controller specifies the maximum valid namespace ID for the NVM subsystem, a fixed property of the subsystem that a host reads once to bound its NSID scans. The emulator was instead deriving NN from the highest currently-present namespace ID, which is wrong on three counts: it changes as namespaces are added and removed, it reports zero when no namespaces are present (telling the host there are no valid NSIDs at all), and it can differ between the PF and its VFs even though they share one subsystem.

Replace the dynamic value with a fixed MAX_NSID constant (1024), reported identically by every controller. Since NN now defines a hard bound on valid namespace IDs, also validate add_namespace against it and reject out-of-range or zero IDs rather than accepting a namespace the guest could never address. The NsidConflict error becomes an AddNamespaceError enum covering both the existing conflict case and the new range check.

The NN field of Identify Controller specifies the maximum valid namespace
ID for the NVM subsystem, a fixed property of the subsystem that a host
reads once to bound its NSID scans. The emulator was instead deriving NN
from the highest currently-present namespace ID, which is wrong on three
counts: it changes as namespaces are added and removed, it reports zero
when no namespaces are present (telling the host there are no valid NSIDs
at all), and it can differ between the PF and its VFs even though they
share one subsystem.

Replace the dynamic value with a fixed MAX_NSID constant (1024), reported
identically by every controller. Since NN now defines a hard bound on
valid namespace IDs, also validate add_namespace against it and reject
out-of-range or zero IDs rather than accepting a namespace the guest
could never address. The NsidConflict error becomes an AddNamespaceError
enum covering both the existing conflict case and the new range check.
Copilot AI review requested due to automatic review settings June 13, 2026 20:16
@jstarks jstarks requested review from a team as code owners June 13, 2026 20:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR corrects NVMe Identify Controller reporting by making the NN field (maximum valid NSID for the subsystem) a fixed constant rather than deriving it from currently-present namespaces, and tightens namespace hot-add validation accordingly.

Changes:

  • Introduces a fixed MAX_NSID (1024) and reports it via Identify Controller NN for all controllers.
  • Validates add_namespace NSIDs against 1..=MAX_NSID and replaces NsidConflict with a richer AddNamespaceError.
  • Adds unit tests covering NSID validation and fixed NN behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
vm/devices/storage/nvme/src/workers/coordinator.rs Updates client/request plumbing to return AddNamespaceError from namespace hot-add.
vm/devices/storage/nvme/src/workers/admin.rs Implements AddNamespaceError, enforces NSID range, and reports nn = MAX_NSID.
vm/devices/storage/nvme/src/workers.rs Re-exports AddNamespaceError instead of NsidConflict.
vm/devices/storage/nvme/src/tests/controller_tests.rs Adds tests for NSID validation and fixed Identify Controller NN.
vm/devices/storage/nvme/src/resolver.rs Updates resolver error handling to wrap AddNamespaceError.
vm/devices/storage/nvme/src/lib.rs Adds MAX_NSID constant and re-exports AddNamespaceError.

Comment thread vm/devices/storage/nvme/src/workers/admin.rs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Comment thread vm/devices/storage/nvme_test/src/lib.rs
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.

2 participants