Skip to content

flowey: package ipmi_kcs_ffi staticlib + header via checkin pipeline#3838

Draft
marma-dev wants to merge 4 commits into
microsoft:mainfrom
marma-dev:user/marma/ipmi-kcs-ffi-flowey
Draft

flowey: package ipmi_kcs_ffi staticlib + header via checkin pipeline#3838
marma-dev wants to merge 4 commits into
microsoft:mainfrom
marma-dev:user/marma/ipmi-kcs-ffi-flowey

Conversation

@marma-dev

Copy link
Copy Markdown

Summary

Adds a build_ipmi_kcs_ffi flowey node that builds the ipmi_kcs_ffi C-ABI static library and bundles it with its C header (ipmi_kcs.h), publishing the pair as an x64-windows artifact from the check-in gates pipeline. This lets the out-of-tree C++ Legacy HCL build (OS repo) consume the shared IPMI KCS BMC emulator, instead of reimplementing the KCS state machine + SEL handling in C++.

This is PR 4 of 4 in the IPMI KCS stack (stacked on ipmi_kcs-ffi):

  • PR1 — core ipmi_kcs device + resource handle.
  • PR2 — host the device in OpenHCL/underhill with SEL forwarding.
  • PR3 — extract the no_std core + C-ABI staticlib.
  • PR4 (this) — package/publish the staticlib via the flowey pipeline.

Approach

Packaging is implemented the OpenVMM-native way — a flowey node wired into checkin_gates, not a hand-written workflow YAML — modeled directly on the existing build_and_test_vmgs_lib node (which packages the analogous vmgs_lib C-ABI library).

What's included

  • flowey/flowey_lib_hvlite/src/build_ipmi_kcs_ffi.rs — new SimpleFlowNode:
    • builds ipmi_kcs_ffi with CargoCrateType::StaticLib,
    • emits an IpmiKcsFfiOutput artifact (WindowsStaticLib { lib, header } / LinuxStaticLib { a, header }) that bundles ipmi_kcs.h alongside the .lib/.a,
    • sources the header from the repo via git_checkout_openvmm_repo.
    • No C test harness (unlike vmgs_lib, whose example C test lives in-repo) — the only consumer is the out-of-tree C++ HCL, which validates the ABI in its own build.
  • flowey/flowey_lib_hvlite/src/lib.rs — register the module.
  • flowey/flowey_hvlite/src/pipelines/checkin_gates.rs — declare the x64-windows-ipmi_kcs_ffi artifact and publish it from the windows "not for VMM tests" job. Gated to x64 only (the ipmi_kcs device is x86-only), following the existing let mut job + conditional-publish pattern used for arch-specific artifacts.
  • Regenerated CI YAML (.github/workflows/openvmm-{ci,pr,pr-release}.yaml, ci-flowey/openvmm-pr.yaml) via cargo xflowey regen.

Validation

  • cargo check -p flowey_lib_hvlite -p flowey_hvlite — clean.
  • cargo xflowey regen — succeeds; CI YAML regenerated and checked in (no pipeline drift).
  • Confirmed the generated pipelines contain the x64-windows-ipmi_kcs_ffi build + publish steps and zero aarch64 references.
  • Verified a clean regen on the parent branch produces no YAML diff, so the entire YAML delta is attributable to this artifact (no incidental drift).
  • The produced staticlib + header link cleanly into the Legacy HCL (hcl/fw) razzle build with no unresolved symbols (validated separately via the consumed artifact).

Risk

Low — additive CI/packaging plus one new flowey node. No product crate behavior changes. The artifact is gated to the x64 windows job; other jobs/arches are unaffected.

Copilot AI review requested due to automatic review settings June 29, 2026 17:18
@github-actions github-actions Bot added the unsafe Related to unsafe code label Jun 29, 2026
@github-actions

Copy link
Copy Markdown

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

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 adds Flowey-based packaging for the ipmi_kcs_ffi C-ABI static library plus its ipmi_kcs.h header, publishing the bundle as a Windows x64 artifact from the checkin_gates pipeline so out-of-tree consumers (Legacy HCL C++) can link against the shared IPMI KCS implementation.

Changes:

  • Introduces new IPMI KCS crates (ipmi_kcs_core, ipmi_kcs, ipmi_kcs_resources, ipmi_kcs_ffi) and wires the device resolver into openvmm_resources (x86_64 guest only).
  • Adds a new Flowey node (build_ipmi_kcs_ffi) and publishes an x64-windows-ipmi_kcs_ffi artifact from the Windows “not for VMM tests” job.
  • Regenerates Flowey-produced CI workflow YAMLs to include the new artifact publishing steps.

Reviewed changes

Copilot reviewed 23 out of 24 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
vm/devices/ipmi_kcs/src/resolver.rs Adds a static resource resolver for the IPMI KCS chipset device.
vm/devices/ipmi_kcs/src/lib.rs Implements the OpenVMM ChipsetDevice/PIO wrapper around the shared core plus unit tests.
vm/devices/ipmi_kcs/Cargo.toml Defines the new ipmi_kcs integration crate and dependencies.
vm/devices/ipmi_kcs_resources/src/lib.rs Adds the IpmiKcsHandle MeshPayload resource handle.
vm/devices/ipmi_kcs_resources/Cargo.toml Defines the new ipmi_kcs_resources crate dependencies.
vm/devices/ipmi_kcs_ffi/src/lib.rs Implements the C ABI wrapper over ipmi_kcs_core plus ABI-driving unit tests.
vm/devices/ipmi_kcs_ffi/ipmi_kcs.h Provides the C header for the published staticlib ABI.
vm/devices/ipmi_kcs_ffi/Cargo.toml Configures staticlib + rlib crate types for FFI + unit tests.
vm/devices/ipmi_kcs_core/src/sink.rs Adds injected SEL sink + clock traits for the no_std core.
vm/devices/ipmi_kcs_core/src/sel.rs Implements SEL storage/commands with injected dependencies.
vm/devices/ipmi_kcs_core/src/protocol.rs Defines protocol constants/enums and helpers.
vm/devices/ipmi_kcs_core/src/lib.rs Implements the KCS state machine and IPMI message handling core.
vm/devices/ipmi_kcs_core/Cargo.toml Adds features for inspect/trace and core dependencies.
openvmm/openvmm_resources/src/lib.rs Registers IpmiKcsResolver behind cfg(guest_arch = "x86_64").
openvmm/openvmm_resources/Cargo.toml Adds ipmi_kcs dependency (currently under cfg(target_arch = "x86_64")).
flowey/flowey_lib_hvlite/src/lib.rs Registers the new Flowey module.
flowey/flowey_lib_hvlite/src/build_ipmi_kcs_ffi.rs Adds Flowey node to build staticlib and bundle header into a typed artifact.
flowey/flowey_hvlite/src/pipelines/checkin_gates.rs Publishes x64-windows-ipmi_kcs_ffi artifact from the Windows job (x64 only).
ci-flowey/openvmm-pr.yaml Regenerated pipeline YAML to publish the new artifact.
.github/workflows/openvmm-pr.yaml Regenerated GitHub workflow YAML to include updated steps/artifact publish.
.github/workflows/openvmm-pr-release.yaml Regenerated GitHub workflow YAML to include updated steps/artifact publish.
.github/workflows/openvmm-ci.yaml Regenerated GitHub workflow YAML to include updated steps/artifact publish.
Cargo.toml Adds workspace members/paths for the new IPMI KCS crates.
Cargo.lock Updates lockfile entries for the new workspace crates and dependencies.

Comment on lines 108 to 111
[target.'cfg(target_arch = "x86_64")'.dependencies]
ipmi_kcs.workspace = true
serial_16550.workspace = true
serial_debugcon.workspace = true
Comment on lines +115 to +118
fn bmc_time(&self) -> u32 {
let now = self.deps.clock.now_unix_secs();
let adjusted = now.saturating_add(self.time_offset);
adjusted.max(0) as u32
Comment on lines +198 to +211
match self.kcs_state() {
KcsState::WRITE_STATE => {
self.write_buffer.push(byte);

if self.write_end_pending {
// This was the last byte. Process the complete message.
self.write_end_pending = false;
self.process_ipmi_message();
} else {
// More bytes expected. Set OBF for dummy read.
self.data_out = 0x00;
self.status |= STATUS_OBF;
}
}
Comment on lines +241 to +245
assert_eq!(wr(0xCA3, 0x61), IPMI_KCS_OK); // WRITE_START
rd(0xCA2, &mut byte);
assert_eq!(wr(0xCA2, 0x18), IPMI_KCS_OK); // NetFn/LUN
assert_eq!(wr(0xCA3, 0x62), IPMI_KCS_OK); // WRITE_END
rd(0xCA2, &mut byte);
Manish Ranjan Mahanta added 4 commits June 30, 2026 09:54
Import the IPMI KCS device crate and add production-readiness changes over the PoC:

- SelSink trait for forwarding SEL entries to a host (no-op by default); enables OpenHCL to publish guest SEL to host ETW.

- BmcClock trait to remove std::time dependency from the SEL store; SystemClock default, injectable for paravisor.

- with_deps constructors on IpmiKcsDevice/SelStore; register resolver in openvmm_resources (x86_64).

- Tests for sink egress and injected clock.
- protocol.rs: use open_enum's inner #![expect(missing_docs)] idiom instead of an outer #[allow], so it reaches the generated associated constants (protocol module is pub).

- sel.rs: SelStore::new() is only used by tests now that the lib paths construct via with_deps; move it into a #[cfg(test)] impl.

- Cargo.lock: add ipmi_kcs / ipmi_kcs_resources entries.
Split the IPMI KCS BMC into a reusable core so OpenHCL (Rust) and the Legacy HCL C++ (OS Repo) share one implementation instead of duplicating it:

- ipmi_kcs_core (new): no_std + alloc KCS state machine + SEL. protocol/sel moved here; SystemClock/std::time removed in favor of injected BmcClock; inspect and trace are optional features (off by default) so minimal consumers link neither.

- ipmi_kcs: now a thin OpenVMM integration layer wrapping ipmi_kcs_core::KcsDevice (ChipsetDevice/PortIoIntercept/InspectMut/save-restore + std SystemClock).

- ipmi_kcs_ffi (new): C ABI staticlib (+ ipmi_kcs.h) exposing new/free/io_read/io_write/reset with SEL + clock callbacks; std shim per the vmgs_lib precedent.

Tests: core 22, integration 3, ffi 2 (incl. C-ABI Get Device ID + SEL callback). 0 warnings.
Add a build_ipmi_kcs_ffi flowey node (modeled on build_and_test_vmgs_lib) that builds the ipmi_kcs_ffi C-ABI staticlib and bundles it with ipmi_kcs.h, published as an x64-windows artifact from the checkin gates pipeline. ipmi_kcs is x86-only, so the artifact is gated to the x64 job. Regenerated CI YAML. This is the upstream-shaped replacement for the fork-local ipmi-kcs-ffi.yaml workflow.
@marma-dev marma-dev force-pushed the user/marma/ipmi-kcs-ffi-flowey branch from 978d4e2 to ee8a62c Compare June 30, 2026 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants