1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

qemu: Implement builtin rng backend

Since v4.2-rc0, QEMU introduced a builtin rng backend that uses
getrandom() syscall to generate random. Add it to libvirt with the
backend model 'builtin'.

https://bugzilla.redhat.com/show_bug.cgi?id=1785091

Signed-off-by: Han Han <hhan@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Han Han 2020-01-09 16:00:08 +08:00 committed by Michal Privoznik
parent 6a6d00e168
commit bd51f89c30
14 changed files with 116 additions and 7 deletions

View File

@ -5844,6 +5844,8 @@ virQEMUCapsFillDomainDeviceRNGCaps(virQEMUCapsPtr qemuCaps,
VIR_DOMAIN_CAPS_ENUM_SET(rng->backendModel, VIR_DOMAIN_RNG_BACKEND_EGD);
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_RNG_RANDOM))
VIR_DOMAIN_CAPS_ENUM_SET(rng->backendModel, VIR_DOMAIN_RNG_BACKEND_RANDOM);
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_RNG_BUILTIN))
VIR_DOMAIN_CAPS_ENUM_SET(rng->backendModel, VIR_DOMAIN_RNG_BACKEND_BUILTIN);
}

View File

@ -5583,6 +5583,7 @@ qemuBuildRNGBackendChrdevStr(virLogManagerPtr logManager,
switch ((virDomainRNGBackend) rng->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
case VIR_DOMAIN_RNG_BACKEND_LAST:
/* no chardev backend is needed */
return 0;
@ -5595,11 +5596,6 @@ qemuBuildRNGBackendChrdevStr(virLogManagerPtr logManager,
cdevflags)))
return -1;
break;
case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
virReportUnsupportedError();
return -1;
break;
}
return 0;
@ -5651,8 +5647,18 @@ qemuBuildRNGBackendProps(virDomainRNGDefPtr rng,
break;
case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
virReportUnsupportedError();
return -1;
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_RNG_BUILTIN)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("this qemu doesn't support the rng-builtin "
"backend"));
return -1;
}
if (qemuMonitorCreateObjectProps(props, "rng-builtin", objAlias,
NULL) < 0)
return -1;
break;
case VIR_DOMAIN_RNG_BACKEND_LAST:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",

View File

@ -167,6 +167,7 @@
<enum name='backendModel'>
<value>random</value>
<value>egd</value>
<value>builtin</value>
</enum>
</rng>
</devices>

View File

@ -178,6 +178,7 @@
<enum name='backendModel'>
<value>random</value>
<value>egd</value>
<value>builtin</value>
</enum>
</rng>
</devices>

View File

@ -136,6 +136,7 @@
<enum name='backendModel'>
<value>random</value>
<value>egd</value>
<value>builtin</value>
</enum>
</rng>
</devices>

View File

@ -134,6 +134,7 @@
<enum name='backendModel'>
<value>random</value>
<value>egd</value>
<value>builtin</value>
</enum>
</rng>
</devices>

View File

@ -100,6 +100,7 @@
<enum name='backendModel'>
<value>random</value>
<value>egd</value>
<value>builtin</value>
</enum>
</rng>
</devices>

View File

@ -190,6 +190,7 @@
<enum name='backendModel'>
<value>random</value>
<value>egd</value>
<value>builtin</value>
</enum>
</rng>
</devices>

View File

@ -167,6 +167,7 @@
<enum name='backendModel'>
<value>random</value>
<value>egd</value>
<value>builtin</value>
</enum>
</rng>
</devices>

View File

@ -0,0 +1,35 @@
LC_ALL=C \
PATH=/bin \
HOME=/tmp/lib/domain--1-QEMUGuest1 \
USER=test \
LOGNAME=test \
XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
QEMU_AUDIO_DRV=none \
/usr/bin/qemu-system-x86_64 \
-name guest=QEMUGuest1,debug-threads=on \
-S \
-object secret,id=masterKey0,format=raw,\
file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
-machine pc,accel=kvm,usb=off,dump-guest-core=off \
-m 214 \
-overcommit mem-lock=off \
-smp 1,sockets=1,cores=1,threads=1 \
-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
-display none \
-no-user-config \
-nodefaults \
-chardev socket,id=charmonitor,fd=1729,server,nowait \
-mon chardev=charmonitor,id=monitor,mode=control \
-rtc base=utc \
-no-shutdown \
-no-acpi \
-boot strict=on \
-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \
-object rng-builtin,id=objrng0 \
-device virtio-rng-pci,rng=objrng0,id=rng0,bus=pci.0,addr=0x3 \
-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
resourcecontrol=deny \
-msg timestamp=on

View File

@ -0,0 +1,26 @@
<domain type='kvm'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>219100</memory>
<currentMemory unit='KiB'>219100</currentMemory>
<vcpu>1</vcpu>
<os>
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<controller type='usb' index='0'/>
<controller type='pci' index='0' model='pci-root'/>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<memballoon model='virtio'/>
<rng model='virtio'>
<backend model='builtin'/>
</rng>
</devices>
</domain>

View File

@ -2121,6 +2121,7 @@ mymain(void)
DO_TEST("virtio-rng-egd",
QEMU_CAPS_DEVICE_VIRTIO_RNG,
QEMU_CAPS_OBJECT_RNG_EGD);
DO_TEST_CAPS_LATEST("virtio-rng-builtin");
DO_TEST_CAPS_VER("virtio-rng-egd-unix", "2.5.0");
DO_TEST_CAPS_LATEST("virtio-rng-egd-unix");
DO_TEST("virtio-rng-multiple",

View File

@ -0,0 +1,31 @@
<domain type='kvm'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>219100</memory>
<currentMemory unit='KiB'>219100</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<controller type='usb' index='0' model='piix3-uhci'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</memballoon>
<rng model='virtio'>
<backend model='builtin'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</rng>
</devices>
</domain>

View File

@ -630,6 +630,7 @@ mymain(void)
QEMU_CAPS_DEVICE_VIRTIO_RNG);
DO_TEST("virtio-rng-egd",
QEMU_CAPS_DEVICE_VIRTIO_RNG);
DO_TEST_CAPS_LATEST("virtio-rng-builtin");
DO_TEST("pseries-nvram",
QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE,