Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 15, 2025

This PR updates the nvme_test crate to incorporate the shadow doorbell improvements that were implemented in the main nvme crate in commit 94889ca. The changes ensure consistency between the two implementations and provide better shadow doorbell support in the test crate.

Key Changes

New Queue Architecture

  • Replaced individual DoorbellRegister instances with a unified DoorbellMemory system
  • Introduced DoorbellState for polling-based async queue handling
  • All doorbell state is now managed through a single DoorbellMemory instance

Simplified Event Index Logic

  • Event index is now updated only when polling for work on empty queues
  • Eliminates complex heuristics and reduces overhead
  • Follows the same strategy used by virtio and vmbus devices

Shadow Doorbell as Single Source of Truth

  • Shadow doorbell memory is now the authoritative source for doorbell values
  • Real doorbells and shadow doorbells remain perfectly synchronized
  • Fixes issues where guests inconsistently use shadow doorbells

Files Updated

  • queue.rs: Complete rewrite to match the new architecture, including updated SubmissionQueue::new signature
  • workers/admin.rs: Updated queue initialization and doorbell buffer config handling
  • workers/io.rs: Updated to use new queue interfaces, removed manual event index management
  • workers/coordinator.rs: Updated to use unified doorbell memory management
  • pci.rs: Updated doorbell write handling
  • tests/shadow_doorbell_tests.rs: Updated tests to use new DoorbellMemory API instead of deprecated ShadowDoorbell struct

Benefits

  • Better Performance: Simplified event index management reduces CPU overhead
  • Cleaner Code: Unified doorbell memory eliminates complex state tracking
  • Consistent Behavior: Ensures shadow doorbells work reliably across different guest usage patterns
  • Future-Ready: Prepares for supporting multiple submission queues per completion queue

Latest Changes

  • Update shadow doorbell handling to mirror nvme crate
  • Fix SubmissionQueue::new signature to take doorbells parameter directly
  • Move CompletionQueue::new() inside Self{} creation for consistency
  • Update shadow doorbell tests to use new DoorbellMemory API

Shadow Doorbell Test Updates

  • Removed deprecated ShadowDoorbell struct usage from tests
  • Updated tests to use direct memory access to DOORBELL_BUFFER_BASE and EVT_IDX_BUFFER_BASE
  • Removed ILLEGAL_DOORBELL_VALUE constant usage
  • Updated doorbell value assertions to check for actual values instead of sentinel constants
  • All shadow doorbell tests now pass with the new API

The changes maintain full backward compatibility while providing the enhanced shadow doorbell support that matches the production nvme crate implementation.

Fixes #2006.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: gurasinghMS <127339643+gurasinghMS@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] nvme_test: update shadow doorbell handling to mirror nvme crate nvme_test: update shadow doorbell handling to mirror nvme crate Sep 15, 2025
@Copilot Copilot AI requested a review from gurasinghMS September 15, 2025 20:16
shadow_db_evt_idx: Option<ShadowDoorbell>,
) -> Self {
tail.write(0);
pub fn new(cq: &CompletionQueue, db_id: u16, gpa: u64, len: u16) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot The update to the submission queue definition doesn't actually happen until after the commit I asked you to apply here. Can you please fix that? The SubmissionQueue::new function should look like impl SubmissionQueue {
pub fn new(
doorbells: Arc<RwLock>,
db_id: u16,
mem: GuestMemory,
gpa: u64,
len: u16,
) -> Self {
doorbells.read().write(db_id, 0);
Self {
tail: DoorbellState::new(doorbells, db_id, len.into()),
head: 0,
gpa,
mem,
}
}

Can you fix this and any associated areas where you are creating SubmissionQueues as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed the SubmissionQueue::new function signature to take doorbells: Arc<RwLock<DoorbellMemory>> as a direct parameter instead of extracting it from the completion queue. Updated call sites in admin.rs and io.rs accordingly. The change is in commit c729103.

Co-authored-by: gurasinghMS <127339643+gurasinghMS@users.noreply.github.com>
Copilot finished work on behalf of gurasinghMS September 15, 2025 21:03
@Copilot Copilot AI requested a review from gurasinghMS September 15, 2025 21:03
})
.collect();

let admin_cq = CompletionQueue::new(
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot for the sake of consistency can you please move this CompletionQueue::new() in to the Self{} creation below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved CompletionQueue::new() inside the Self{} creation for consistency as requested. The change is in commit 4d8ec6f.

Co-authored-by: gurasinghMS <127339643+gurasinghMS@users.noreply.github.com>
@gurasinghMS
Copy link
Contributor

@copilot one last thing, can you also update the shadow doorbell tests in the nvme_test crate to match the changes from that commit?

Co-authored-by: gurasinghMS <127339643+gurasinghMS@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 15, 2025

@copilot one last thing, can you also update the shadow doorbell tests in the nvme_test crate to match the changes from that commit?

Updated the shadow doorbell tests in the nvme_test crate to match the new DoorbellMemory API. Removed the deprecated ShadowDoorbell struct usage and ILLEGAL_DOORBELL_VALUE constant, updated tests to use direct memory access, and all shadow doorbell tests now pass. The change is in commit 06f64c6.

Copilot finished work on behalf of gurasinghMS September 15, 2025 21:34
@gurasinghMS gurasinghMS marked this pull request as ready for review September 15, 2025 21:47
@Copilot Copilot AI review requested due to automatic review settings September 15, 2025 21:47
@gurasinghMS gurasinghMS requested review from a team as code owners September 15, 2025 21:47
Copy link
Contributor

@Copilot Copilot AI left a comment

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 updates the nvme_test crate to mirror the shadow doorbell handling improvements implemented in the main nvme crate. The changes replace individual DoorbellRegister instances with a unified DoorbellMemory system and simplify event index management by making shadow doorbell memory the authoritative source for doorbell values.

Key Changes

  • Introduced DoorbellMemory and DoorbellState for unified doorbell management
  • Simplified event index logic by updating only when polling for work on empty queues
  • Replaced complex shadow doorbell heuristics with polling-based async queue handling

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/queue.rs Complete rewrite implementing new DoorbellMemory and DoorbellState architecture
src/workers/io.rs Updated to use new queue interfaces and removed manual event index management
src/workers/admin.rs Updated queue initialization and doorbell buffer config handling
src/workers/coordinator.rs Updated to use unified doorbell memory management
src/pci.rs Updated doorbell write handling with new variable names
src/tests/shadow_doorbell_tests.rs Updated tests to use new DoorbellMemory API
Cargo.toml Removed unused event-listener dependency

Comment on lines +540 to +546
spec::AdminOpcode::DOORBELL_BUFFER_CONFIG
if self.supports_shadow_doorbells(state) =>
{
self.handle_doorbell_buffer_config(state, &command)
.await
.map(|()| Some(Default::default()))
}
Copy link

Copilot AI Sep 15, 2025

Choose a reason for hiding this comment

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

[nitpick] The guard condition if self.supports_shadow_doorbells(state) is misaligned with the match arm. Consider reformatting for better readability or extracting this logic to a separate condition before the match statement.

Copilot uses AI. Check for mistakes.

Copy link

Copy link

@gurasinghMS gurasinghMS enabled auto-merge (squash) September 18, 2025 17:25
@gurasinghMS gurasinghMS merged commit 42fa743 into main Sep 18, 2025
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nvme_test: update shadow doorbell handling to mirror nvme crate

4 participants