Skip to content

Commit

Permalink
netvm: check PCI device before start microvm-pci-devices
Browse files Browse the repository at this point in the history
Wait up to 60 seconds for ethernet PCI to get enumerated before start the
microvm-pci-devices@net-vm service. The pront start of this service was
failing if the ethernet PCI was not yet enumerated.

Fix microvm-pci-devices@net-vm service start error:
microvm-pci-devices@net-vm[836]: /var/lib/microvms/net-vm/current/bin/pci-setup: line 4:
cd: /sys/bus/pci/devices/0008:01:00.0: No such file or directory

Signed-off-by: Juan Pablo Ruiz <[email protected]>
  • Loading branch information
jpruiz84 authored and brianmcgillion committed Feb 9, 2025
1 parent 26a8033 commit 25d1690
Showing 1 changed file with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{ lib, config, ... }:
{
pkgs,
lib,
config,
...
}:
let
cfg = config.ghaf.hardware.nvidia.orin.nx;
ethPciDevice = "0008:01:00.0";
in
{
options.ghaf.hardware.nvidia.orin.nx.enableNetvmEthernetPCIPassthrough =
Expand All @@ -11,16 +17,31 @@ in
# Orin NX Ethernet card PCI Passthrough
ghaf.hardware.nvidia.orin.enablePCIPassthroughCommon = true;

# Wait up to 60 seconds for ethernet PCI to get enumerated
systemd.services."microvm-pci-devices@net-vm".serviceConfig.ExecStartPre = ''
${pkgs.bash}/bin/bash -c ' \
TIMEOUT=60; \
ELAPSED=0; \
while [ ! -e /sys/bus/pci/devices/${ethPciDevice} ]; do \
if [ $ELAPSED -ge $TIMEOUT ]; then \
echo "Timeout reached: PCI device ${ethPciDevice} did not appear after $TIMEOUT seconds."; \
exit 1; \
fi; \
echo "Waiting for PCI device ${ethPciDevice}... $ELAPSED/$TIMEOUT seconds"; \
sleep 1; \
ELAPSED=$((ELAPSED + 1)); \
done; \
echo "PCI device ${ethPciDevice} is present."'
'';

ghaf.virtualization.microvm.netvm.extraModules = [
{
microvm.devices = [
{
bus = "pci";
path = "0008:01:00.0";
path = ethPciDevice;
}
];
# Add 8 seconds delay to wait for PCI devices to get full enumerated
microvm.preStart = "/bin/sh -c 'sleep 8'";
}
];

Expand Down

0 comments on commit 25d1690

Please sign in to comment.