From nobody Tue Feb 10 02:46:36 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1744129935377798.0782821814923; Tue, 8 Apr 2025 09:32:15 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 639641708; Tue, 8 Apr 2025 12:32:14 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8BE551563; Tue, 8 Apr 2025 12:31:18 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 181B0B31; Tue, 8 Apr 2025 12:31:14 -0400 (EDT) Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id EE300148D for ; Tue, 8 Apr 2025 12:31:10 -0400 (EDT) Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-aaf0f1adef8so925157266b.3 for ; Tue, 08 Apr 2025 09:31:10 -0700 (PDT) Received: from tulp.my.domain (80-115-115-199.cable.dynamic.v4.ziggo.nl. [80.115.115.199]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac7bfe5c5ffsm937295966b.23.2025.04.08.09.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Apr 2025 09:31:07 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744129869; x=1744734669; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+MPW9bNhk2K/bfgVih0f3D2gARXOzs6pHDYWG/KQH38=; b=YY9jY1KDLViNddhe2pLisYiv1qKN8/8eu/WNGG/K1LHqQP1f/pbma+HTvao2bgA0rm vD0P+KzwYFFpskYAlehxz0+NiPrElHQDAr/ZT1/xynlL0x43N958aSjzJRNrP+OPAnfy fjSDUtFekTsPYv+OPpnsJ2q+TrtMEXlow54hzAdmaA1WuBpD9bBV7nl52byuA3a3JD2K DqC8wVKiJ94EAHtqiQswpxP7LacEJG7Kvd43Qf6CD6hRf4jY8lgRH03kMfj7rmeM5U1J c5yT0XDM+bGsf2lBsJvSYgh2u+q8DdK0MCssKqTTJPtUR+YyxxwkHgtOTD8rwAineHAl vWGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744129869; x=1744734669; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+MPW9bNhk2K/bfgVih0f3D2gARXOzs6pHDYWG/KQH38=; b=xJPhvs/kVF7HwDdPS2Hn17edK5T/MGhGse9sQlmys6RkWdi1DwynYRoBr670UUdhHa rKHYLvZT/ICz1cO8FEfYVUFPqpFnB4bFioBuy0EjFI7y0JsuezTLLTJE1PF7K3D2pBLm kfc5e4AJaaVud4EJf1EQvj4QuAn4GhYaAUS4tGc7xf6FofNR6WWsZcgUoar1SKSOyO/L ORGkpTBa/+YzIKDQRv1ooDvhnuCMJMJTYH2TCtSbVusJrT0Ub8EfCbt57P+B5Jrcn0LD uVwJQpu4p+mbKgCoNVS6zNBvBNx6/sLMSzXPj0FTe31OrdmOQV/2Co6kS3wSYQXyQxMY y77w== X-Gm-Message-State: AOJu0Yw8MxhzKilzy0t5imMJYXChG7wFntf6UdeT9pyp6Z+3I4dvolMj vEKdShA6mRo15XNUXySIt5fDgE9Q434mPHC5oUq3iHcd92JbYSR1sYxVc7zdXt2v1g== X-Gm-Gg: ASbGncv4uHGJhzfyqyMh0pNexP2JGan1HnAjXBrQmuqNFpiK6IvTkPd0wBDKe1skmRY 2HxkGZBV7Zqb2fc7R4gpQU8bCcM1xbEthcH7GhOY+feS4BK2wrnRyo3R+EwTJJaMoZN/o2pKP2T SpBtIyeWwNNwytCXe8rSpxE8hD1hNHDdzLVLM//4hDbKLL/7IZnYGiIf3qnjvp8GS3Z5/3wooG6 xWDCQd7usO2sryPaplviDLymQtc7fRtIHjnDRlsj1EChoIQ3AgD8pOSIAnJp+nyj7vwrCk5BpDF 7fyFcXzjqCfZS8KJrB5eIXjqdb6u141CBcBSwnAmcC7mI+3Tw225pW3kMn0IfGllZH1BK4ah0O9 twoh8xSV0uf1mWJn1kg== X-Google-Smtp-Source: AGHT+IHPrtKcbM4Nu+yAQxrUAFDPdOfIsg77JfkVAfZNPDXYS2FzpkiUD6+cIqaMtLXstqhcqXtCRg== X-Received: by 2002:a17:907:9728:b0:ac2:87b0:e4a5 with SMTP id a640c23a62f3a-ac7d6c9e900mr1372051266b.2.1744129869167; Tue, 08 Apr 2025 09:31:09 -0700 (PDT) From: Roman Bogorodskiy To: devel@lists.libvirt.org Subject: [PATCH 1/3] bhyve: support random number generator device Date: Tue, 8 Apr 2025 18:27:28 +0200 Message-ID: <20250408162730.67891-2-bogorodskiy@gmail.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408162730.67891-1-bogorodskiy@gmail.com> References: <20250408162730.67891-1-bogorodskiy@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 2BWL2YZ4YHARRR4I3FYIWMLXIKPNXERX X-Message-ID-Hash: 2BWL2YZ4YHARRR4I3FYIWMLXIKPNXERX X-MailFrom: bogorodskiy@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Roman Bogorodskiy X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1744129939440019100 Content-Type: text/plain; charset="utf-8" Bhyve supports the Virtio RNG interface. It's always using the /dev/random device and doesn't have any configuration options. Thus, in XML it's represented as: So extend the bhyve driver to support that and add a set of tests for this feature. Signed-off-by: Roman Bogorodskiy --- src/bhyve/bhyve_capabilities.c | 15 ++++++++ src/bhyve/bhyve_capabilities.h | 2 + src/bhyve/bhyve_command.c | 23 ++++++++++++ src/bhyve/bhyve_device.c | 11 ++++++ .../bhyvexml2argv-virtio-rnd.args | 11 ++++++ .../bhyvexml2argv-virtio-rnd.ldargs | 4 ++ .../bhyvexml2argv-virtio-rnd.xml | 26 +++++++++++++ tests/bhyvexml2argvtest.c | 3 ++ .../bhyvexml2xmlout-virtio-rnd.xml | 37 +++++++++++++++++++ tests/bhyvexml2xmltest.c | 1 + 10 files changed, 133 insertions(+) create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-virtio-rnd.args create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-virtio-rnd.ldargs create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-virtio-rnd.xml create mode 100644 tests/bhyvexml2xmloutdata/bhyvexml2xmlout-virtio-rnd.xml diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c index b065256cf0..37ae5d2872 100644 --- a/src/bhyve/bhyve_capabilities.c +++ b/src/bhyve/bhyve_capabilities.c @@ -4,6 +4,7 @@ * Copyright (C) 2014 Roman Bogorodskiy * Copyright (C) 2014 Semihalf * Copyright (C) 2020 Fabian Freyer + * Copyright (C) 2025 The FreeBSD Foundation * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -327,6 +328,17 @@ bhyveProbeCapsVirtio9p(unsigned int *caps, char *binar= y) } =20 =20 +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); +} + + int virBhyveProbeCaps(unsigned int *caps) { @@ -364,6 +376,9 @@ virBhyveProbeCaps(unsigned int *caps) if ((ret =3D bhyveProbeCapsVirtio9p(caps, binary))) goto out; =20 + if ((ret =3D bhyveProbeCapsVirtioRnd(caps, binary))) + goto out; + out: VIR_FREE(binary); return ret; diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h index 582eae083d..9b24241dc1 100644 --- a/src/bhyve/bhyve_capabilities.h +++ b/src/bhyve/bhyve_capabilities.h @@ -2,6 +2,7 @@ * bhyve_capabilities.h: bhyve capabilities module * * Copyright (C) 2014 Semihalf + * Copyright (C) 2025 The FreeBSD Foundation * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -52,6 +53,7 @@ typedef enum { BHYVE_CAP_SOUND_HDA =3D 1 << 7, BHYVE_CAP_VNC_PASSWORD =3D 1 << 8, BHYVE_CAP_VIRTIO_9P =3D 1 << 9, + BHYVE_CAP_VIRTIO_RND =3D 1 << 10, } virBhyveCapsFlags; =20 int virBhyveProbeGrubCaps(virBhyveGrubCapsFlags *caps); diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index bc287307c8..50de3e1660 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -2,6 +2,7 @@ * bhyve_command.c: bhyve command generation * * Copyright (C) 2014 Roman Bogorodskiy + * Copyright (C) 2025 The FreeBSD Foundation * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -152,6 +153,24 @@ bhyveBuildConsoleArgStr(const virDomainDef *def, virCo= mmand *cmd) return 0; } =20 +static int +bhyveBuildRNGArgStr(const virDomainDef *def G_GNUC_UNUSED, + virDomainRNGDef *rng, + virCommand *cmd) +{ + if (rng->backend !=3D VIR_DOMAIN_RNG_BACKEND_RANDOM) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("RNG backend is not supported")); + return -1; + } + + virCommandAddArg(cmd, "-s"); + virCommandAddArgFormat(cmd, "%d:%d,virtio-rnd", + rng->info.addr.pci.slot, + rng->info.addr.pci.function); + return 0; +} + static int bhyveBuildAHCIControllerArgStr(const virDomainDef *def, virDomainControllerDef *controller, @@ -807,6 +826,10 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *driver= , virDomainDef *def, if (bhyveBuildConsoleArgStr(def, cmd) < 0) return NULL; =20 + for (i =3D 0; i < def->nrngs; i++) + if (bhyveBuildRNGArgStr(def, def->rngs[i], cmd) < 0) + return NULL; + if (def->namespaceData) { bhyveDomainCmdlineDef *bhyvecmd; =20 diff --git a/src/bhyve/bhyve_device.c b/src/bhyve/bhyve_device.c index e4d14c4102..68983d5bc4 100644 --- a/src/bhyve/bhyve_device.c +++ b/src/bhyve/bhyve_device.c @@ -2,6 +2,7 @@ * bhyve_device.c: bhyve device management * * Copyright (C) 2014 Roman Bogorodskiy + * Copyright (C) 2025 The FreeBSD Foundation * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -184,6 +185,16 @@ bhyveAssignDevicePCISlots(virDomainDef *def, return -1; } =20 + for (i =3D 0; i < def->nrngs; i++) { + if (!virDeviceInfoPCIAddressIsWanted(&def->rngs[i]->info)) + continue; + if (virDomainPCIAddressReserveNextAddr(addrs, + &def->rngs[i]->info, + VIR_PCI_CONNECT_TYPE_PCI_DE= VICE, + -1) < 0) + return -1; + } + return 0; } =20 diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-virtio-rnd.args b/tests/= bhyvexml2argvdata/bhyvexml2argv-virtio-rnd.args new file mode 100644 index 0000000000..849e4599f8 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-virtio-rnd.args @@ -0,0 +1,11 @@ +bhyve \ +-c 1 \ +-m 214 \ +-u \ +-H \ +-P \ +-s 0:0,hostbridge \ +-s 2:0,ahci,hd:/tmp/freebsd.img \ +-s 3:0,virtio-net,faketapdev,mac=3D52:54:00:b9:94:02 \ +-s 4:0,virtio-rnd \ +bhyve diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-virtio-rnd.ldargs b/test= s/bhyvexml2argvdata/bhyvexml2argv-virtio-rnd.ldargs new file mode 100644 index 0000000000..5905f4b3e6 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-virtio-rnd.ldargs @@ -0,0 +1,4 @@ +bhyveload \ +-m 214 \ +-d /tmp/freebsd.img \ +bhyve diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-virtio-rnd.xml b/tests/b= hyvexml2argvdata/bhyvexml2argv-virtio-rnd.xml new file mode 100644 index 0000000000..78a4e3f400 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-virtio-rnd.xml @@ -0,0 +1,26 @@ + + bhyve + df3be7e7-a104-11e3-aeb0-50e5492bd3dc + 219136 + 1 + + hvm + + + + + + +
+ + + + + +
+ + + + + + diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index cdaa32f65c..74d9ba4f70 100644 --- a/tests/bhyvexml2argvtest.c +++ b/tests/bhyvexml2argvtest.c @@ -243,6 +243,9 @@ mymain(void) DO_TEST_FAILURE("fs-9p-unsupported-accessmode"); driver.bhyvecaps &=3D ~BHYVE_CAP_VIRTIO_9P; DO_TEST_FAILURE("fs-9p"); + DO_TEST("virtio-rnd"); + driver.bhyvecaps &=3D ~BHYVE_CAP_VIRTIO_RND; + DO_TEST_FAILURE("virtio-rnd"); =20 /* Address allocation tests */ DO_TEST("addr-single-sata-disk"); diff --git a/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-virtio-rnd.xml b/tes= ts/bhyvexml2xmloutdata/bhyvexml2xmlout-virtio-rnd.xml new file mode 100644 index 0000000000..61645c719d --- /dev/null +++ b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-virtio-rnd.xml @@ -0,0 +1,37 @@ + + bhyve + df3be7e7-a104-11e3-aeb0-50e5492bd3dc + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + + + + +
+ + + +
+ + + + + +
+ + + /dev/random +
+ + + diff --git a/tests/bhyvexml2xmltest.c b/tests/bhyvexml2xmltest.c index 428f1b47bb..98006dac04 100644 --- a/tests/bhyvexml2xmltest.c +++ b/tests/bhyvexml2xmltest.c @@ -114,6 +114,7 @@ mymain(void) DO_TEST_DIFFERENT("sound"); DO_TEST_DIFFERENT("isa-controller"); DO_TEST_DIFFERENT("fs-9p"); + DO_TEST_DIFFERENT("virtio-rnd"); =20 /* Address allocation tests */ DO_TEST_DIFFERENT("addr-single-sata-disk"); --=20 2.49.0