netvsp: gdma driver report git commit#2963
Conversation
|
Tested on a lab machine. socmana log shows Built binaries with |
There was a problem hiding this comment.
Pull request overview
This PR adds build-time Git revision information to the MANA GDMA VF driver verification request so that the SoC/HWC side can log which driver build is running during triage.
Changes:
- Populate
GdmaVerifyVerReqOS/build identity strings (os_ver_str1/os_ver_str2) with a driver name andBUILD_GIT_SHA. - Add a
build.rsformana_driverto emitBUILD_GIT_SHA/BUILD_GIT_BRANCHviabuild_rs_git_info. - Log the received driver name/commit on the GDMA HWC side when handling
GDMA_VERIFY_VF_DRIVER_VERSION.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| vm/devices/net/mana_driver/src/gdma_driver.rs | Fill verify-version request fields with driver name and Git SHA to report to the SoC. |
| vm/devices/net/mana_driver/build.rs | Emit Git metadata at build time for use via option_env!. |
| vm/devices/net/mana_driver/Cargo.toml | Add build_rs_git_info as a build dependency. |
| vm/devices/net/gdma/src/hwc.rs | Parse and log the driver name/commit from the verify-version request. |
| Cargo.lock | Record the new build dependency in the lockfile. |
| #[tracing::instrument(skip(self), level = "debug", err)] | ||
| pub async fn verify_vf_driver_version(&mut self) -> anyhow::Result<()> { | ||
| let mut req = GdmaVerifyVerReq { | ||
| protocol_ver_min: 1, |
There was a problem hiding this comment.
Lets see if we can plumb in the OPENHCL_VERSION value into protocol_ver_min/max
efd6945 to
cb7c8c7
Compare
|
|
||
| /// Parse an OPENHCL_VERSION string of the form "major.minor.build.platform" | ||
| /// into four u32 components. Missing or unparseable components default to 0. | ||
| fn parse_openhcl_version(version: &str) -> (u32, u32, u32, u32) { |
There was a problem hiding this comment.
This belongs better in the build_rs_git_info crate
| let mut parts = version.splitn(4, '.'); | ||
| let major = parts.next().and_then(|s| s.parse().ok()).unwrap_or(0); | ||
| let minor = parts.next().and_then(|s| s.parse().ok()).unwrap_or(0); | ||
| let build = parts.next().and_then(|s| s.parse().ok()).unwrap_or(0); |
There was a problem hiding this comment.
@justus-camp-microsoft or @maheeraeron - Do you know in the openhcl_version="1.5.10492.0", what do the last two (i.e. 10492.0 in the above example) fields for?
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
| }; | ||
|
|
||
| // Identify the driver and build to the SOC | ||
| // str1 = OS/driver name, str2 = build identity. |
There was a problem hiding this comment.
Let's also move this to build_info crate. Rest all looks good to me.
vm/devices/net/gdma/src/hwc.rs
Outdated
| .ok() | ||
| .and_then(|c| c.to_str().ok()) | ||
| .unwrap_or("<invalid>"); | ||
| tracing::debug!(drv_name, drv_commit, "vf driver version"); |
There was a problem hiding this comment.
We can log the other fields here as well and move this to info level as this is good debug info.
| // Identify the driver and build to the SOC | ||
| // str1 = "OpenHCL", str2 = build identity. | ||
| let name = build_info::PRODUCT_NAME.as_bytes(); | ||
| req.os_ver_str1[..name.len()].copy_from_slice(name); |
There was a problem hiding this comment.
This also needs a min length check like below
| rust-version.workspace = true | ||
|
|
||
| [dependencies] | ||
| build_info.workspace = true |
There was a problem hiding this comment.
@justus-camp-microsoft @Brian-Perkins - Will this be a problem for the reproducible build stuff?
There was a problem hiding this comment.
I wouldn't think so, we already depend on build_info in other important places
| req.os_ver_str1[..len].copy_from_slice(&name.as_bytes()[..len]); | ||
|
|
||
| let revision = build_info::get().scm_revision(); | ||
| let len = revision.len().min(req.os_ver_str2.len() - 1); |
There was a problem hiding this comment.
Generally, for these you want to use saturating_sub, but its fine for now
openhcl/build_info/src/lib.rs
Outdated
|
|
||
| // Parse the OPENHCL_VERSION string of the form "major.minor.build.platform" | ||
| // into four u32 components. Missing or unparseable components default to 0. | ||
| pub fn parse_openhcl_version() -> (u32, u32, u32, u32) { |
There was a problem hiding this comment.
I don't think we should be doing this at runtime, we should do it at build time instead (either providing the ints in env vars or using const fn). That way we can also validate at build time that things match the expected format.
smalis-msft
left a comment
There was a problem hiding this comment.
Convert parsing to a build-time operation, not runtime
Is it possible to prevent runtime inclusion of the crate so that this can be prevented in future? |
|
I'm not sure what you mean by that. We have to include the crate to call the getters at runtime. I'm just opposed to doing any significant logic at runtime around this data, since it all should be available at build time. |
openhcl/build_info/src/lib.rs
Outdated
|
|
||
| static OPENHCL_VERSION: OpenHclVersion = OpenHclVersion::new(); | ||
|
|
||
| pub fn openhcl_version() -> &'static OpenHclVersion { |
There was a problem hiding this comment.
nit: I'd get rid of the function and just make the static pub
openhcl/build_info/src/lib.rs
Outdated
| } | ||
| } | ||
|
|
||
| pub fn product_name(&self) -> &'static str { |
There was a problem hiding this comment.
Make all of these getters const too
openhcl/build_info/src/lib.rs
Outdated
| } | ||
|
|
||
| impl OpenHclVersion { | ||
| const VERSION: (u32, u32, u32, u32) = const_parse_version(BuildInfo::new().openhcl_version); |
There was a problem hiding this comment.
This shouldn't be a separate const, it should get called in new
openhcl/build_info/src/lib.rs
Outdated
|
|
||
| // Parse `bytes[start..end]` as a u32. Returns 0 if the segment is empty | ||
| // or contains any non-digit character. | ||
| const fn const_parse_u32_segment(bytes: &[u8], start: usize, end: usize) -> u32 { |
There was a problem hiding this comment.
i'm surprised std doesn't provide a const way to do this, but this is fine if it doesn't.
There was a problem hiding this comment.
I looked a little harder and found u32::from_str_radix!. Doing things in const is hard. :P
openhcl/build_info/src/lib.rs
Outdated
|
|
||
| impl OpenHclVersion { | ||
| pub const fn new() -> Self { | ||
| let (major, minor, build, platform) = const_parse_version(BuildInfo::new().openhcl_version); |
There was a problem hiding this comment.
nit: You can just have this reutrn [u32;4] and then have let [major, minor, build, platform] = ... instead of going through a tuple.
openhcl/build_info/src/lib.rs
Outdated
| } | ||
| match u32::from_str_radix(s, 10) { | ||
| Ok(v) => v, | ||
| Err(_) => 0, |
There was a problem hiding this comment.
can't we panic in a const context?
Soc needs a signal for determining what features are available. During triage, soc logs will provide more information to determine which version of the Gdma driver and OpenHCL was running.