From nobody Thu Jan 8 10:12:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1767280671; cv=none; d=zohomail.com; s=zohoarc; b=JX6BGj276vkzvroxUanwIw3fJahusECBxyxapQ4TB2f8a8h8WXV+3rWeXf00SCD2LX0I/7SVsaNtmZWuB/tq3qkY9v0eZw6dEuTpGHfNcXJ0RTDe66Uoe9dZeZrUQrFLC6fGcKiCaJejxqGHlr2V+lkDvluQWf77PMwEN1qRftg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1767280671; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=1CZyvlE6M71Rpv40UQ7biaJJF6HTSHFjZESwmeQbPaE=; b=ikj82qit+a/XWOR00/Mg9BhGAlLYxgqFUe2i65pZr2+1+JOdcPwZNIIe/SEp4DTQvQz5a6iJrd2KHAXX8PZrumC/CvXJUS0dsT6o38qJP1jqcawali8KSBeN4QWu76PFMNLOnQLfOfNYFP+aggAz9FuaSCY9wqxu82Y8sFCUdOI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1767280671411646.1685508863122; Thu, 1 Jan 2026 07:17:51 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 05B8D4185E; Thu, 1 Jan 2026 10:17:49 -0500 (EST) Received: from [172.19.199.83] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 789AB419A3; Thu, 1 Jan 2026 10:16:48 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id C2EB83FB95; Thu, 1 Jan 2026 10:13:00 -0500 (EST) Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 028D53FAF9 for ; Thu, 1 Jan 2026 10:12:56 -0500 (EST) Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-64b921d9e67so16754189a12.3 for ; Thu, 01 Jan 2026 07:12:56 -0800 (PST) Received: from tulp.my.domain (2001-1c02-1a15-3000-c218-03ff-feb5-6cc4.cable.dynamic.v6.ziggo.nl. [2001:1c02:1a15:3000:c218:3ff:feb5:6cc4]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b83b7bdb6c4sm356917966b.7.2026.01.01.07.12.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jan 2026 07:12:54 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767280375; x=1767885175; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=1CZyvlE6M71Rpv40UQ7biaJJF6HTSHFjZESwmeQbPaE=; b=cJVPkCRsWvyIv0AVIOK+wF3nQMFdzFDAp3WtRAEDe3Y9q8ZvR1ul5wRdY0vwsv5mIz 8MsDW8ZyDXoWtUj8R2hTWvBdVFebdBRwbPejqv1XSdgvL638U1P5BXLGJClCqfCY1pzT cJIgEKOyofW36wP7NofTgL9XWEvdbMTavlBnHC5AJadW+uFlnZBPdeLMb8zL+qLMRixY mdFac/qS9ecob76qgEHgfaAZtMkiE2Se3XdyV7naLcAyD5BxlLsU2cyHovaS4z4KuW5C uDs1Z6V7ae9QZQ+1NJey48h2BimUdA09vUn5mqp+Qih/rL1Z2cPCGP+J05dc6Kh+ZCVf mwrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767280375; x=1767885175; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1CZyvlE6M71Rpv40UQ7biaJJF6HTSHFjZESwmeQbPaE=; b=Gw5GtJkorzr2rippRrc1rqGBkzFHMd2i2HcHoNo8gf/vnNrFfqDaXI+Tn0wHdrWwYL 5V101PIMjVsVlBaa1yUT60RFlCJ5qbjYashot9dQK5kXApkcspMz/tKgggqs1fKOuBxg FxYXQt8GHq2C2s1gzY6sdVd1FXdzHMycQCo8Pf7l3eU9x5WUFLe1ZWlUsnf++jPBDPEI HJkQdL8tn8iDM6rDKbZXBuUJJ/DvwoJitdlS5TugXwOwQaUADJXKn25asu+mi9jU7jfv XWebKdXwyi7NsxcCj3c/rrGttZ68kyg8YnkPw69eSv7uJENT4qHMudIrXikwVZuSuCl+ k45Q== X-Gm-Message-State: AOJu0YxDgWpL6KeK5bgNiy0mVLyq23lU57LpFAaM221Y2K591oWkks2c e7nb4e60364K7AHdvSz57Et84UEVXuEgGgxyR+ByS4Ou4me0CXM+OdWEarZYNxsG X-Gm-Gg: AY/fxX5rjprWJExOVjvwjYGdnCvpEt2+tRQyG4oVstoWeakvguwUcfcvc10z95/Jqc1 30NjPGXxMAuKnq+lY3Kbgvrqc6OA1MaqBjzdsfip0/taKBuJK9Y4dCF4WiVPy+2/h38WaLzt55F obe1qj5p5gGwlhULrjYwPSJnaDCM3K9wm8qxKS0knDHIv+8XDqbio/8HGYjJNBBXTZcId/xXiS1 gG7A2UBTtUiscjUBoIFTl0OtUnoA8ZVDKyRZZNKpuYDaQN3P3N96QsiOM3m0kKqvhEnD7Z7NnJP BOUsaFhgEg3tKLaUIfppwCCd09yA1ELbm9kJlo1Xmoi+LqLU1+DqUfUKr6HGXMxPNwb1xRHs8AR +KzRnzjdr07uHtEgESZAp+W+eogV91LdlbOUy0xLeri1TRhYRtOZwuGpMa+emH43yKUDWV8XqK0 YjPWZvcBt3llhDIQiaFTdrNwDnFew2vdjpJjVcE/i/LSNyJXC9mKOzI0fJfgnopOykw6b7FYPpZ +Ymrhyx87HyZLiT49N/ibGa X-Google-Smtp-Source: AGHT+IFSO+9dDrnT7fb3RORGgUY+dZasaInlROIrCqtzoAGpcoxzH9KhI36kGTmhp9TJ++hOOSQVzQ== X-Received: by 2002:a17:907:3e08:b0:b79:f8f7:38ea with SMTP id a640c23a62f3a-b80371802f1mr3974311866b.45.1767280374789; Thu, 01 Jan 2026 07:12:54 -0800 (PST) From: Roman Bogorodskiy To: devel@lists.libvirt.org Subject: [PATCH] bhyve: rework capabilities probing Date: Thu, 1 Jan 2026 16:10:12 +0100 Message-ID: <20260101151012.20702-1-bogorodskiy@gmail.com> X-Mailer: git-send-email 2.52.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 643HG6YIYUEHO3QFFJD3SWET3UXG66IW X-Message-ID-Hash: 643HG6YIYUEHO3QFFJD3SWET3UXG66IW X-MailFrom: bogorodskiy@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Roman Bogorodskiy X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1767280674705158500 Content-Type: text/plain; charset="utf-8" Currently, to probe PCI devices, for each device libvirt calls "bhyve -s 0," and parses the error message to check if this specific device is supported. For quite some time, bhyve reports the list of devices using: bhyve -s help where it prints all supported devices, one device per line. Update the code to use this command: * It is more accurate as we don't need to rely on the error message parsing. * It's faster as we get all the devices in one run instead of running bhyve for every device type. * The code is simpler. Signed-off-by: Roman Bogorodskiy Reviewed-by: Michal Privoznik --- src/bhyve/bhyve_capabilities.c | 139 ++++++++++----------------------- 1 file changed, 40 insertions(+), 99 deletions(-) diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c index 0585fff8e9..2e5e2ae3bc 100644 --- a/src/bhyve/bhyve_capabilities.c +++ b/src/bhyve/bhyve_capabilities.c @@ -258,24 +258,51 @@ bhyveProbeCapsFromHelp(unsigned int *caps, char *bina= ry) } =20 static int -bhyveProbeCapsAHCI32Slot(unsigned int *caps, char *binary) +bhyveFillCapForDevice(unsigned int *caps, const char *device) { - return bhyveProbeCapsDeviceHelper(caps, binary, - "-s", - "0,ahci", - "pci slot 0:0: unknown device \"ahci= \"", - BHYVE_CAP_AHCI32SLOT); + if (STREQ(device, "ahci")) + *caps |=3D BHYVE_CAP_AHCI32SLOT; + else if (STREQ(device, "e1000")) + *caps |=3D BHYVE_CAP_NET_E1000; + else if (STREQ(device, "fbuf")) + *caps |=3D BHYVE_CAP_FBUF; + else if (STREQ(device, "hda")) + *caps |=3D BHYVE_CAP_SOUND_HDA; + else if (STREQ(device, "nvme")) + *caps |=3D BHYVE_CAP_NVME; + else if (STREQ(device, "virtio-9p")) + *caps |=3D BHYVE_CAP_VIRTIO_9P; + else if (STREQ(device, "virtio-rnd")) + *caps |=3D BHYVE_CAP_VIRTIO_RND; + else if (STREQ(device, "xhci")) + *caps |=3D BHYVE_CAP_XHCI; + + return 0; } =20 =20 static int -bhyveProbeCapsNetE1000(unsigned int *caps, char *binary) +bhyveProbeCapsFromSHelp(unsigned int *caps, char *binary) { - return bhyveProbeCapsDeviceHelper(caps, binary, - "-s", - "0,e1000", - "pci slot 0:0: unknown device \"e100= 0\"", - BHYVE_CAP_NET_E1000); + g_autofree char *help =3D NULL; + g_autoptr(virCommand) cmd =3D NULL; + int exit; + char *cur =3D NULL; + char *saveptr =3D NULL; + + cmd =3D virCommandNew(binary); + virCommandAddArgList(cmd, "-s", "help", NULL); + virCommandSetOutputBuffer(cmd, &help); + if (virCommandRun(cmd, &exit) < 0) + return -1; + + cur =3D strtok_r(help, "\n", &saveptr); + while (cur !=3D NULL) { + bhyveFillCapForDevice(caps, cur); + cur =3D strtok_r(NULL, "\n", &saveptr); + } + + return 0; } =20 static int @@ -289,39 +316,6 @@ bhyveProbeCapsLPC_Bootrom(unsigned int *caps, char *bi= nary) } =20 =20 -static int -bhyveProbeCapsFramebuffer(unsigned int *caps, char *binary) -{ - return bhyveProbeCapsDeviceHelper(caps, binary, - "-s", - "0,fbuf", - "pci slot 0:0: unknown device \"fbuf= \"", - BHYVE_CAP_FBUF); -} - - -static int -bhyveProbeCapsXHCIController(unsigned int *caps, char *binary) -{ - return bhyveProbeCapsDeviceHelper(caps, binary, - "-s", - "0,xhci", - "pci slot 0:0: unknown device \"xhci= \"", - BHYVE_CAP_FBUF); -} - - -static int -bhyveProbeCapsSoundHda(unsigned int *caps, char *binary) -{ - return bhyveProbeCapsDeviceHelper(caps, binary, - "-s", - "0,hda", - "pci slot 0:0: unknown device \"hda\= "", - BHYVE_CAP_SOUND_HDA); -} - - static int bhyveProbeCapsVNCPassword(unsigned int *caps, char *binary) { @@ -333,39 +327,6 @@ bhyveProbeCapsVNCPassword(unsigned int *caps, char *bi= nary) } =20 =20 -static int -bhyveProbeCapsVirtio9p(unsigned int *caps, char *binary) -{ - return bhyveProbeCapsDeviceHelper(caps, binary, - "-s", - "0,virtio-9p", - "pci slot 0:0: unknown device \"hda\= "", - BHYVE_CAP_VIRTIO_9P); -} - - -static int -bhyveProbeCapsVirtioRnd(unsigned int *caps, char *binary) -{ - return bhyveProbeCapsDeviceHelper(caps, binary, - "-s", - "0,virtio-rnd", - "pci slot 0:0: unknown device \"virt= io-rnd\"", - BHYVE_CAP_VIRTIO_RND); -} - - -static int -bhyveProbeCapsNvme(unsigned int *caps, char *binary) -{ - return bhyveProbeCapsDeviceHelper(caps, binary, - "-s", - "0,nvme", - "pci slot 0:0: unknown device \"nvme= \"", - BHYVE_CAP_NVME); -} - - int virBhyveProbeCaps(unsigned int *caps) { @@ -379,35 +340,15 @@ virBhyveProbeCaps(unsigned int *caps) if ((ret =3D bhyveProbeCapsFromHelp(caps, binary))) goto out; =20 - if ((ret =3D bhyveProbeCapsAHCI32Slot(caps, binary))) - goto out; - - if ((ret =3D bhyveProbeCapsNetE1000(caps, binary))) + if ((ret =3D bhyveProbeCapsFromSHelp(caps, binary))) goto out; =20 if ((ret =3D bhyveProbeCapsLPC_Bootrom(caps, binary))) goto out; =20 - if ((ret =3D bhyveProbeCapsFramebuffer(caps, binary))) - goto out; - - if ((ret =3D bhyveProbeCapsXHCIController(caps, binary))) - goto out; - - if ((ret =3D bhyveProbeCapsSoundHda(caps, binary))) - goto out; - if ((ret =3D bhyveProbeCapsVNCPassword(caps, binary))) goto out; =20 - if ((ret =3D bhyveProbeCapsVirtio9p(caps, binary))) - goto out; - - if ((ret =3D bhyveProbeCapsVirtioRnd(caps, binary))) - goto out; - - if ((ret =3D bhyveProbeCapsNvme(caps, binary))) - goto out; =20 out: VIR_FREE(binary); --=20 2.52.0