Skip to content

mana vf: poll for shmem ownership before use #966

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions vm/devices/net/mana_driver/src/gdma_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,29 @@ impl<T: DeviceBacking> Drop for GdmaDriver<T> {
return;
}

// Wait for ownership of the shared memory.
let max_wait_time =
std::time::Instant::now() + Duration::from_millis(HWC_POLL_TIMEOUT_IN_MS);
loop {
let data = self
.bar0
.mem
.read_u32(self.bar0.map.vf_gdma_sriov_shared_reg_start as usize + 28);
if data == u32::MAX {
tracing::error!("Device no longer present");
return;
}
let header = SmcProtoHdr::from(data);
if !header.owner_is_pf() {
break;
}
if std::time::Instant::now() > max_wait_time {
tracing::error!("MANA request timed out waiting for shared memory possession bit to clear; SMC_MSG_TYPE_DESTROY_HWC");
return;
}
std::hint::spin_loop();
}

let hdr = SmcProtoHdr::new()
.with_msg_type(SmcMessageType::SMC_MSG_TYPE_DESTROY_HWC.0)
.with_msg_version(SMC_MSG_TYPE_DESTROY_HWC_VERSION);
Expand Down Expand Up @@ -288,6 +311,27 @@ impl<T: DeviceBacking> GdmaDriver<T> {

let pages = dma_buffer.pfns();

// Wait for ownership of the shared memory.
let mut backoff = Backoff::new(driver);
let mut ctx =
mesh::CancelContext::new().with_timeout(Duration::from_millis(HWC_POLL_TIMEOUT_IN_MS));
let mut hw_failure = false;
loop {
Copy link
Member

Choose a reason for hiding this comment

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

This is copy/paste. Can we make it a function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, and will do. Each is slightly different as it was copied from the wait in each respective function where the response is waited on (one for establish hwc, one for destroy hwc, slightly different from each other though probably not for good reason). To be complete with making a function, we may want all four waits (establish/destroy before sending request, establish/destroy when waiting for response) to be commonized into a single function.

let header = SmcProtoHdr::from(
bar0_mapping.read_u32(map.vf_gdma_sriov_shared_reg_start as usize + 28),
);
if !header.owner_is_pf() {
break;
}
if hw_failure {
anyhow::bail!("MANA request timed out waiting for shared memory possession bit to clear; SMC_MSG_TYPE_ESTABLISH_HWC");
}
hw_failure = matches!(
ctx.until_cancelled(backoff.back_off()).await,
Err(mesh::CancelReason::DeadlineExceeded)
);
}

// Write the shared memory.
fn low(n: u64) -> [u8; 6] {
let n = n.to_ne_bytes();
Expand Down