Skip to content

Add hardware information service for host-to-guest data passing#1380

Merged
brianmcgillion merged 4 commits intotiiuae:mainfrom
juliuskoskela:hwinfo-integration
Sep 15, 2025
Merged

Add hardware information service for host-to-guest data passing#1380
brianmcgillion merged 4 commits intotiiuae:mainfrom
juliuskoskela:hwinfo-integration

Conversation

@juliuskoskela
Copy link
Copy Markdown
Contributor

@juliuskoskela juliuskoskela commented Sep 5, 2025

Description of Changes

Introduces a service for passing hardware information from host systems to guest VMs using QEMU's fw_cfg interface. Detects NVMe serial numbers and MAC addresses on the host and makes them available to guest VMs.

The implementation is cross-platform and integrates with Ghaf's microvm infrastructure.

Implementation Details

  • Adds ghaf.services.hwinfo module for host systems that automatically detects and exports hardware information
  • Adds ghaf.services.hwinfo-guest module for guest VMs to read the hardware information
  • Uses QEMU's fw_cfg mechanism which is supported across all architectures (x86_64, ARM)
  • Hardware information is passed as JSON via the -fw_cfg QEMU argument
  • Currently enabled only for net-vm on the Jetson AGX target
  • Qemu documentation for fw_cfg mechanism

Technical Considerations

Initially attempted to use ACPI table injection via -acpitable for this feature, but discovered it is not supported on ARM architectures in QEMU. The error "Option not supported for this target" occurs even with ACPI enabled on the virt machine. Implementing ACPI table injection for ARM would require upstream changes to both QEMU and potentially the microvm framework. The fw_cfg approach was chosen as it provides a clean, cross-platform solution that works on all supported architectures.

Type of Change

  • New Feature
  • Bug Fix
  • Improvement / Refactor

Related Issues / Tickets

None

Checklist

  • Clear summary in PR description
  • Detailed and meaningful commit message(s)
  • Commits are logically organized and squashed if appropriate
  • Contribution guidelines followed
  • Ghaf documentation updated with the commit - https://tiiuae.github.io/ghaf/
  • Author has run make-checks and it passes
  • All automatic GitHub Action checks pass - see actions
  • Author has added reviewers and removed PR draft status

Testing Instructions

Applicable Targets

  • Orin AGX aarch64
  • Orin NX aarch64
  • Lenovo X1 x86_64
  • Dell Latitude x86_64
  • System 76 x86_64

Installation Method

  • Requires full re-installation
  • Can be updated with nixos-rebuild ... switch
  • Other:

Test Steps To Verify:

  1. Build and flash the Orin AGX target with this change
  2. Boot the device and SSH into it
  3. Verify hardware info generation on host:
    sudo systemctl status ghaf-hwinfo-generate
    ls -la /var/lib/ghaf-hwinfo/
    cat /var/lib/ghaf-hwinfo/hwinfo.json
  4. Check that net-vm is running:
    systemctl status microvm@net-vm.service
  5. Access net-vm and verify hardware information is available:
    # In net-vm
    sudo read-hwinfo
  6. Expected output should show NVMe serial, MAC address, hostname, and timestamp

Notes

  • Hostname detection requires the service to run after network initialization
  • Timestamp accuracy depends on system time synchronization
  • The fw_cfg kernel module (qemu_fw_cfg) must be loaded in the guest
  • Currently only enabled for net-vm on Jetson AGX target

Enabling for Other Targets and VMs

To enable this service on other targets or guest VMs:

  1. Enable host service in the target hardware configuration:

    ghaf.services.hwinfo = {
      enable = true;
      outputDir = "/var/lib/ghaf-hwinfo";
    };
  2. For each guest VM, add to the VM's extraModules:

    {
      imports = [ <path-to>/modules/common/services/hwinfo ];
      ghaf.services.hwinfo-guest.enable = true;
    }
    {
      # Ensure hwinfo is generated before VM starts
      systemd.services."microvm@<vm-name>" = {
        wants = [ "ghaf-hwinfo-generate.service" ];
        after = [ "ghaf-hwinfo-generate.service" ];
      };
    }
    {
      # Pass hardware info via fw_cfg
      microvm.qemu.extraArgs = [
        "-fw_cfg" "name=opt/com.ghaf.hwinfo,file=/var/lib/ghaf-hwinfo/hwinfo.json"
      ];
    }

This approach works identically on both ARM and x86_64 targets.

Introduces a service for passing hardware information from host systems
to guest VMs using QEMU's fw_cfg interface. Detects NVMe serial numbers
and MAC addresses on the host and makes them available to guest VMs.

The implementation is cross-platform and integrates with Ghaf's microvm
infrastructure.

Signed-off-by: Julius Koskela <julius.koskela@unikie.com>
Signed-off-by: juliuskoskela <julius@koskela.email>
Copy link
Copy Markdown
Contributor

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 introduces a hardware information service that enables passing hardware data from host systems to guest VMs using QEMU's fw_cfg interface. The service collects NVMe serial numbers and MAC addresses on the host and makes them accessible to guest VMs through a cross-platform mechanism.

Key changes:

  • Implements host-side hardware detection service that generates JSON files with system information
  • Adds guest-side service for reading hardware information via QEMU fw_cfg interface
  • Enables the service specifically for the net-vm on Jetson AGX target

Reviewed Changes

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

Show a summary per file
File Description
modules/reference/hardware/jetpack/agx/orin-agx.nix Enables hwinfo service on host and configures net-vm to receive hardware data via fw_cfg
modules/common/services/hwinfo/host.nix Host service that detects NVMe serial, MAC address, hostname and generates JSON output
modules/common/services/hwinfo/guest.nix Guest service providing tools to read hardware information from fw_cfg interface
modules/common/services/hwinfo/default.nix Module entry point importing both host and guest services
modules/common/services/default.nix Adds hwinfo module to common services imports

@brianmcgillion
Copy link
Copy Markdown
Collaborator

I have not had a chance to review this patch yet, but it reminded me of a feature we are following.

https://lists.gnu.org/archive/html/qemu-devel/2025-08/msg04138.html

This improved version of the patch set will replace the patches that we currently carry. https://github.com/tiiuae/ghaf/blob/main/overlays/custom-packages/qemu/acpi-devices-passthrough-qemu-8.1.patch

Interesting how these hw events and statuses are shared in the new qemu API. More of a discussion point for later

Apply the same hardware info service configuration already present in AGX
to both AGX64 and NX platforms for consistency.

Signed-off-by: juliuskoskela <julius.koskela@unikie.com>
Copy link
Copy Markdown
Contributor

@emrahbillur emrahbillur left a comment

Choose a reason for hiding this comment

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

There was agx64 and nx targets missing where it is now added. I tested all agx, nx and agx64 targets with this PR and now it works.

@vunnyso
Copy link
Copy Markdown
Collaborator

vunnyso commented Sep 8, 2025

If this pull request is not urgent, I recommend enabling givc support on aarch64 and extracting hardware information using the givc methods. We already have the logic to extract the Mac Address through givc, and now we need to add logic for nvme_serial extraction.

@juliuskoskela
Copy link
Copy Markdown
Contributor Author

I have not had a chance to review this patch yet, but it reminded me of a feature we are following.

https://lists.gnu.org/archive/html/qemu-devel/2025-08/msg04138.html

This improved version of the patch set will replace the patches that we currently carry. https://github.com/tiiuae/ghaf/blob/main/overlays/custom-packages/qemu/acpi-devices-passthrough-qemu-8.1.patch

Interesting how these hw events and statuses are shared in the new qemu API. More of a discussion point for later

Some extra considerations.

  • ACPI is the standard way of representing hardware on x86, but not on ARM. It is also hypervisor agnostic.
  • We can enable ACPI compatibility on ARM with -machine virt,acpi=on but this requires changes in microvm upstream. On Qemu this compatibility mechanism would use fw_cfg under the hood.
  • fw_cfg is Qemu spesific generic transport channel between Qemu and guest firmware. It can do ACPI as well as Device Tree and other things. It works on both ARM and x86.

@juliuskoskela
Copy link
Copy Markdown
Contributor Author

If this pull request is not urgent, I recommend enabling givc support on aarch64 and extracting hardware information using the givc methods. We already have the logic to extract the Mac Address through givc, and now we need to add logic for nvme_serial extraction.

I think fog-ghaf needs this relatively urgently. What's the state of givc on Jetson? Last time I checked it wasn't ready, but that's some months ago.

@vunnyso
Copy link
Copy Markdown
Collaborator

vunnyso commented Sep 8, 2025

If this pull request is not urgent, I recommend enabling givc support on aarch64 and extracting hardware information using the givc methods. We already have the logic to extract the Mac Address through givc, and now we need to add logic for nvme_serial extraction.

I think fog-ghaf needs this relatively urgently. What's the state of givc on Jetson? Last time I checked it wasn't ready, but that's some months ago.

AFAIK, there are still some cross compilation issues when enabling givc .

@juliuskoskela juliuskoskela requested a review from mbssrc September 9, 2025 10:51
@juliuskoskela
Copy link
Copy Markdown
Contributor Author

A note on doing this with givc instead of fw_cfg, the main implication is that with fw_cfg the information is available at the earliest stages of the boot chain. If this is importat for the users, then we should probably stick to fw_cfg solution.

@vunnyso
Copy link
Copy Markdown
Collaborator

vunnyso commented Sep 11, 2025

Please rebase and address Copilot review comments if relevant.

- Replace writeScriptBin with writeShellApplication for better dependency management
- Use lib.getExe for systemd service scripts
- Replace string concatenation with jq for JSON generation
- Fix shellcheck warnings (useless cat, ls usage)
- Add proper runtime inputs for all dependencies

These changes address review feedback and improve code quality.

Signed-off-by: Julius Koskela <julius.koskela@unikie.com>
@juliuskoskela
Copy link
Copy Markdown
Contributor Author

Review comments have been taken into account and branch has been rebased.

@juliuskoskela
Copy link
Copy Markdown
Contributor Author

Something failed in the pipeline, investigating.

@milva-unikie
Copy link
Copy Markdown

Something failed in the pipeline, investigating.

Orin-AGX test devices were offline on Friday afternoon for some reason. All tests passed on rerun.

@brianmcgillion brianmcgillion merged commit 22594ad into tiiuae:main Sep 15, 2025
28 checks passed
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.

7 participants