Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFE: Skeleton for DMA layer #306

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

bhargavshah1988
Copy link

No description provided.

}
}

pub fn map_dma_ranges(
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand this is a draft ... could you add a doc comment so that folks know the intended contract and usage here?

}

/// Adds a new client to the list and stores its pinning threshold
fn register_client(&self, client: &Arc<DmaClient>, threshold: usize) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a need to have per-client bounce buffers?

}

// Trait for the DMA interface
pub trait DmaInterface {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you envision that this would replace other uses of bounce buffering? (for example, copying from private memory into shared memory for isolated VMs, or when the block disk bounces for arm64 guests)?

Copy link
Author

Choose a reason for hiding this comment

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

yes, i do envision that.
Policy on GlobalDmaManager can be control the behavior system wide.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. How do you envision handling the case:

  1. Have a VTL0 VM where sometimes memory needs to be pinned.
  2. This particular transaction's memory must be placed in a bounce buffer, even if pinning would otherwise succeed?

(I'm thinking about the block device driver here, where it would never want to pin memory - the kernel doesn't know about the VTL0 addresses.)

Copy link
Contributor

Choose a reason for hiding this comment

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

We discussed this offline. map_dma_ranges will take additional per-transaction parameters. For example, some clients may want all transactions to be placed into the bounce buffer.

static GLOBAL_DMA_MANAGER: OnceCell<Arc<GlobalDmaManager>> = OnceCell::new();

/// Global DMA Manager to handle resources and manage clients
pub struct GlobalDmaManager {
Copy link
Contributor

Choose a reason for hiding this comment

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

What settings will this manager have? Which of those do you expect to expose in Vtl2Settings?

let mut dma_transactions = Vec::new();
let force_bounce_buffer = options.map_or(false, |opts| opts.force_bounce_buffer);

let threshold = manager.get_client_threshold(self).ok_or(DmaError::InitializationFailed)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

This line can be moved before defining dma_transactions to fail earlier.


for range in ranges {
let use_bounce_buffer = force_bounce_buffer || range_size > threshold || !self.can_pin(range);

Copy link
Contributor

Choose a reason for hiding this comment

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

extra empty line


for transaction in dma_transactions {
if transaction.is_bounce_buffer {
// Code to release bounce buffer
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need copy out from bounce buffer here?

Copy link
Contributor

Choose a reason for hiding this comment

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

The caller may not know if it's bounce buffer or not, so I think we need handle it here. And need pass the Memory range to copy data out. Actually, I think we need know the IO direction to decide which copy is needed (including the one in map_dma_ranges).


/// Allocates a bounce buffer if available, otherwise returns an error
pub fn allocate_bounce_buffer(&self, size: usize) -> Result<usize, DmaError> {
Err(DmaError::BounceBufferFailed) // Placeholder
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need ensure the bounce buffer is page aligned?

Copy link
Author

Choose a reason for hiding this comment

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

I envision that bounce buffer management will be aligned.

Copy link
Contributor

Choose a reason for hiding this comment

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

And also note it: our current bounce buffer allocation function has infinite loop issue which we want to avoid it in the new implementation.

let result = self.issue_raw(command).await;

dma_client
.unmap_dma_ranges(&dma_transactions.transactions)
Copy link
Contributor

Choose a reason for hiding this comment

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

So we need handle the same functionality as copy_to_guest_memory in unmap_dma_ranges if opcode.transfer_controller_to_host()

let result = self.issue_raw(command).await;

dma_client
.unmap_dma_ranges(&dma_transactions.transactions)
Copy link
Contributor

Choose a reason for hiding this comment

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

To simplify usage, can we just pass dma_transactions to unmap_dma_ranges? So caller needn't know details of DmaTransactionHandler?

pub original_addr: usize,
pub dma_addr: usize,
pub size: usize,
pub is_pinned: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have comments explaining these fields? like is_pinned and is_bounce_buffer cannot be both true, why do we need keep both?

Copy link
Author

Choose a reason for hiding this comment

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

yes, i will add it.

let threshold = manager.get_client_threshold(self).ok_or(DmaError::InitializationFailed)?;

for range in ranges {
let use_bounce_buffer = force_bounce_buffer || range_size > threshold || !self.can_pin(range);
Copy link
Contributor

Choose a reason for hiding this comment

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

If can_pin returns true, would it grantee the later pin_memory succeed?
I guess not. Then what's the strategy to handle pin/bounce buffer failures?
I mean, should we fallback to bounce buffer if pin failed?
Should we try pin if bounce buffer allocation failed?

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.

4 participants