]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
6 years agotests: qemucapabilities: Test commands used to query capabilities
Peter Krempa [Fri, 1 Jun 2018 08:03:01 +0000 (10:03 +0200)]
tests: qemucapabilities: Test commands used to query capabilities

Use qemuMonitorTestNewFromFileFull which allows to test commands used
along with providing replies. This has two advantages:

1) It's easier to see which command was used when looking at the files
2) We check that the used commands are actually in the correct order

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agotests: qemucapsprobemock: Prepare 'qemucapsprobe' for the new format
Peter Krempa [Thu, 3 May 2018 15:29:36 +0000 (17:29 +0200)]
tests: qemucapsprobemock: Prepare 'qemucapsprobe' for the new format

Change the output of qemucapsprobe to record the commands used for
querying. This allows to easily identify which reply belongs to which
command and also will allow to test whether we use stable queries.

This change includes changing dropping of the QMP greeting from the file
and reformatting of the query and output to stdout.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agotests: qemucapsprobemock: Fail if JSON reply from qemu can't be reformatted
Peter Krempa [Fri, 4 May 2018 13:34:41 +0000 (15:34 +0200)]
tests: qemucapsprobemock: Fail if JSON reply from qemu can't be reformatted

Rather than skipping output on failure fail loudly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agotests: qemucapsprobemock: Simplify and extract skipping of empty lines
Peter Krempa [Thu, 3 May 2018 15:34:43 +0000 (17:34 +0200)]
tests: qemucapsprobemock: Simplify and extract skipping of empty lines

The prettyfied output may sometimes contain empty lines which would
desynchonize the test monitor workers. The skipping code can be much
simplified though. Also a extract it so so that it's obvious what
it's doing and can be reused.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agotests: qemumonitor: Optimize control flow when concatenating replies
Peter Krempa [Thu, 3 May 2018 09:43:34 +0000 (11:43 +0200)]
tests: qemumonitor: Optimize control flow when concatenating replies

The test file can be broken up by newlines and is automatically
concatenated back. Fix the control flow so that the concatenation code
'continues' the loop rather than branching out.

Also add an anotation to the concatenation code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agotests: qemumonitor: Simplify handling of end of file in full file test
Peter Krempa [Thu, 3 May 2018 09:38:23 +0000 (11:38 +0200)]
tests: qemumonitor: Simplify handling of end of file in full file test

On EOF, the loop can be terminated right away since most of it is
skipped anyways and the handling of the last command is repeated after
the loop.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agotests: qemucapabilities: Reset command sequence before second probe
Peter Krempa [Mon, 4 Jun 2018 09:21:51 +0000 (11:21 +0200)]
tests: qemucapabilities: Reset command sequence before second probe

The test data for capabilities is obtained from two consecutive qemu
runs when the regular monitor object will be reset. Do the same for the
test monitor object which is not disposed between runs by calling
qemuMonitorResetCommandID.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: monitor: Add possibility to reset command sequence in tests
Peter Krempa [Fri, 4 May 2018 14:26:08 +0000 (16:26 +0200)]
qemu: monitor: Add possibility to reset command sequence in tests

qemucapabilitiestest for simplicity uses one test monitor object for
simulating work of two separate inquiries of the qemu process. To allow
better testing in the future it will be required to reset the counter
so that it accurately simulates how qemu would behave.

This patch adds a private monitor API which allows to reset the counter
which will be usable only in tests.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: fix uninitialised variable in virQEMUDriverConfigLoadFile
Julio Faracco [Mon, 11 Jun 2018 20:35:33 +0000 (17:35 -0300)]
qemu: fix uninitialised variable in virQEMUDriverConfigLoadFile

Since virConfGetValueBool() can return earlier, the parameter 'value'
might be not initialised properly inside this method. Another proof:
Valgrind is returning this error during the libvirtd daemon startup:

==16199== Conditional jump or move depends on uninitialised value(s)
==16199==    at 0x27FFFEF4: virQEMUDriverConfigLoadFile (qemu_conf.c:809)
==16199==    by 0x2807665C: qemuStateInitialize (qemu_driver.c:654)
==16199==    by 0x5535428: virStateInitialize (libvirt.c:662)
==16199==    by 0x12AED8: daemonRunStateInit (remote_daemon.c:802)
==16199==    by 0x536DE18: virThreadHelper (virthread.c:206)
==16199==    by 0x6CB36DA: start_thread (pthread_create.c:463)
==16199==    by 0x6FEC88E: clone (clone.S:95)

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Extract formatting of 'mirror' disk sub-element
Peter Krempa [Mon, 11 Jun 2018 14:51:16 +0000 (16:51 +0200)]
conf: Extract formatting of 'mirror' disk sub-element

Move the code to a separate function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Use virXMLFormatElement to format disk 'driver' element
Peter Krempa [Mon, 11 Jun 2018 13:32:05 +0000 (15:32 +0200)]
conf: Use virXMLFormatElement to format disk 'driver' element

Formatting of 'driver' already used a separate buffer but was part of
the main function. Separate it and remove bunch of unnecessary temporary
variables.

Note that some checks are removed but they are not really necessary
anyways.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Use virXMLFormatElement to format disk IO tuning
Peter Krempa [Mon, 11 Jun 2018 13:32:05 +0000 (15:32 +0200)]
conf: Use virXMLFormatElement to format disk IO tuning

Extract and refactor the code to use the new approach which allows to
delete a monster condition to check if the element needs to be
formatted.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Implement the driver backend for virDomainGetLaunchSecurityInfo
Brijesh Singh [Fri, 8 Jun 2018 14:41:01 +0000 (09:41 -0500)]
qemu: Implement the driver backend for virDomainGetLaunchSecurityInfo

This patch implements the internal driver API for launch event into
qemu driver. When SEV is enabled, execute 'query-sev-launch-measurement'
to get the measurement of memory encrypted through launch sequence.

Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoremote: Implement the remote protocol for launch security
Brijesh Singh [Fri, 8 Jun 2018 14:41:00 +0000 (09:41 -0500)]
remote: Implement the remote protocol for launch security

Add remote support for launch security info.

Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agolibvirt: Introduce virDomainGetLaunchSecurityInfo public API
Brijesh Singh [Fri, 8 Jun 2018 14:40:59 +0000 (09:40 -0500)]
libvirt: Introduce virDomainGetLaunchSecurityInfo public API

The API can be used outside the libvirt to get the launch security
information. When SEV is enabled, the API can be used to get the
measurement of the launch process.

Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoqemu: Add support to launch an SEV guest
Brijesh Singh [Fri, 8 Jun 2018 14:40:58 +0000 (09:40 -0500)]
qemu: Add support to launch an SEV guest

QEMU >= 2.12 provides 'sev-guest' object which is used to launch encrypted
VMs on AMD platform using SEV feature. The various inputs required to
launch SEV guest is provided through the <launch-security> tag. A typical
SEV guest launch command line looks like this:

  -object sev-guest,id=sev0,cbitpos=47,reduced-phys-bits=5 ...\
  -machine memory-encryption=sev0 \

Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoqemu/cgroup: Add /dev/sev in shared devices list
Brijesh Singh [Fri, 8 Jun 2018 14:40:57 +0000 (09:40 -0500)]
qemu/cgroup: Add /dev/sev in shared devices list

QEMU uses /dev/sev device while creating the SEV guest, lets add /dev/sev
in the list of devices allowed to be accessed by the QEMU.

Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoconf: Introduce launch-security element in domain
Brijesh Singh [Fri, 8 Jun 2018 14:40:56 +0000 (09:40 -0500)]
conf: Introduce launch-security element in domain

The launch-security element can be used to define the security
model to use when launching a domain. Currently we support 'sev'.

When 'sev' is used, the VM will be launched with AMD SEV feature enabled.
SEV feature supports running encrypted VM under the control of KVM.
Encrypted VMs have their pages (code and data) secured such that only the
guest itself has access to the unencrypted version. Each encrypted VM is
associated with a unique encryption key; if its data is accessed to a
different entity using a different key the encrypted guests data will be
incorrectly decrypted, leading to unintelligible data.

Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoqemu: Implement the driver backend for virNodeGetSEVInfo()
Brijesh Singh [Fri, 8 Jun 2018 14:40:55 +0000 (09:40 -0500)]
qemu: Implement the driver backend for virNodeGetSEVInfo()

Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoremote: Implement the remote protocol for virNodeGetSEVInfo()
Brijesh Singh [Fri, 8 Jun 2018 14:40:54 +0000 (09:40 -0500)]
remote: Implement the remote protocol for virNodeGetSEVInfo()

Add remote support for virNodeGetSEVInfo().

Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agolibvirt: Introduce virNodeGetSEVInfo public API
Brijesh Singh [Fri, 8 Jun 2018 14:40:53 +0000 (09:40 -0500)]
libvirt: Introduce virNodeGetSEVInfo public API

The API can be used by application to retrieve the Platform Diffie-Hellman
Key and Platform Certificate chain.

Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoconf: Expose SEV feature in domain capabilities
Brijesh Singh [Fri, 8 Jun 2018 14:40:52 +0000 (09:40 -0500)]
conf: Expose SEV feature in domain capabilities

Extend hypervisor capabilities to include sev feature. When available,
hypervisor supports launching an encrypted VM on AMD platform. The
sev feature tag provides additional details like Platform Diffie-Hellman
(PDH) key and certificate chain which can be used by the guest owner to
establish a cryptographic session with the SEV firmware to negotiate
keys used for attestation or to provide secret during launch.

Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoqemu: Provide support to query the SEV capability
Brijesh Singh [Fri, 8 Jun 2018 14:40:51 +0000 (09:40 -0500)]
qemu: Provide support to query the SEV capability

QEMU version >= 2.12 provides support for launching an encrypted VMs on
AMD x86 platform using Secure Encrypted Virtualization (SEV) feature.
This patch adds support to query the SEV capability from the qemu.

Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoevents: remove remoteEventQueue wrapper function
Anya Harter [Mon, 11 Jun 2018 19:38:19 +0000 (15:38 -0400)]
events: remove remoteEventQueue wrapper function

And replace all calls with virObjectEventStateQueue such that:

    remoteEventQueue(priv, event, callbackID);

becomes:

    virObjectEventStateQueue(priv->eventState, event, callbackID);

Signed-off-by: Anya Harter <aharter@redhat.com>
6 years agoevents: move NULL check to EventStateQueueRemote
Anya Harter [Mon, 11 Jun 2018 19:38:18 +0000 (15:38 -0400)]
events: move NULL check to EventStateQueueRemote

Remove NULL check around call to virObjectEventStateQueueRemote in
remote_driver.c.

Signed-off-by: Anya Harter <aharter@redhat.com>
6 years agoevents: add NULL check in virObjectEventStateQueue
Anya Harter [Mon, 11 Jun 2018 19:38:17 +0000 (15:38 -0400)]
events: add NULL check in virObjectEventStateQueue

And remove NULL checking from all callers.

Signed-off-by: Anya Harter <aharter@redhat.com>
6 years agoqemu: Allow no address to be defined for virtio-scsi iothread attach
John Ferlan [Thu, 7 Jun 2018 00:21:26 +0000 (20:21 -0400)]
qemu: Allow no address to be defined for virtio-scsi iothread attach

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

When attaching a virtio-scsi with IOThreads for the config of a
live domain, allow the <address> to not be defined thus allowing
post parse processing to fill in the address. This allows parsing
of an individual device to succeed for attach config.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Alter error message when IOThread address not correct
John Ferlan [Mon, 11 Jun 2018 22:44:02 +0000 (18:44 -0400)]
qemu: Alter error message when IOThread address not correct

Make the error a bit clearer that virtio-scsi IOThreads require
virtio pci or ccw controller address types.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Fix error for attach controller config for live guest
John Ferlan [Thu, 7 Jun 2018 00:21:25 +0000 (20:21 -0400)]
qemu: Fix error for attach controller config for live guest

Fix the error message to indicate what exactly is failing - that
the controller index provided matches an existing controller.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Check error from virXMLFormatElement call
John Ferlan [Fri, 8 Jun 2018 17:07:55 +0000 (13:07 -0400)]
conf: Check error from virXMLFormatElement call

Commit id 1bd5a08d added a call to virXMLFormatElement without
also checking the return status.

Found by Coverity.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Katerina Koukiou <kkoukiou@redhat.com>
6 years agotest: Check return status for libxlxml2domconfigtest
John Ferlan [Wed, 14 Feb 2018 12:12:35 +0000 (07:12 -0500)]
test: Check return status for libxlxml2domconfigtest

Commit id d8e8b63d introduced the test, but neglected to check for
error from virTestLoadFile in testCompareXMLToDomConfig.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Katerina Koukiou <kkoukiou@redhat.com>
6 years agotest: Fix resource leak in qemumonitorjsontest
John Ferlan [Wed, 18 Apr 2018 10:33:42 +0000 (06:33 -0400)]
test: Fix resource leak in qemumonitorjsontest

Introduced by commmit id 37bd4571c. Need to goto cleanup and
not return directly.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Katerina Koukiou <kkoukiou@redhat.com>
6 years agoqemu: Fix Coverity build for qemu_monitor
John Ferlan [Fri, 8 Jun 2018 10:46:32 +0000 (06:46 -0400)]
qemu: Fix Coverity build for qemu_monitor

Commit id '7ef0471bf' added a new parameter to qemuMonitorOpen,
but didn't update the ATTTRIBUTE_NONNULL for the @cb (param 5).

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Katerina Koukiou <kkoukiou@redhat.com>
6 years agovbox: Fix resource leak
John Ferlan [Tue, 5 Jun 2018 12:33:04 +0000 (08:33 -0400)]
vbox: Fix resource leak

The @disk was allocated, filled in, and consumed on the normal path,
but for error/cleanup paths it would be leaked.  Rename to newHardDisk
and manage properly.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Katerina Koukiou <kkoukiou@redhat.com>
6 years agovbox: Fix resource leak
John Ferlan [Tue, 5 Jun 2018 12:18:32 +0000 (08:18 -0400)]
vbox: Fix resource leak

Need to free the allocated hardDiskToOpen array. The contents of the
array are just pointers returned by virVBoxSnapshotConfHardDiskByLocation
and not allocated AFAICT so they don't need to also be freed as well.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Katerina Koukiou <kkoukiou@redhat.com>
6 years agovirstring: fix a typo
Chen Hanxiao [Mon, 11 Jun 2018 10:46:21 +0000 (18:46 +0800)]
virstring: fix a typo

s/glibc's_asprintf/glibc's asprintf

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agoxen_common: Split per-PCI logic from xenParsePCI()
Fabiano Fidêncio [Sun, 27 May 2018 22:28:23 +0000 (00:28 +0200)]
xen_common: Split per-PCI logic from xenParsePCI()

xenParsePCI() does a lot of stuff and, in order to make things cleaner,
let's split it in two new functions:
- xenParsePCI(): it's a new function that keeps the old name. It's
responsible for the whole per-PCI logic from the old xenParsePCI();
- xenParsePCIList(): it's basically the old xenParsePCI(), but now it
just iterates over the list of PCIs, calling xenParsePCI() per each PCI.

This patch is basically preparing the ground for the future when
typesafe virConf acessors will be used.

Signed-off-by: Fabiano Fidêncio <fabiano@fidencio.org>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agovmx: convert to typesafe virConf accessors
Fabiano Fidêncio [Sun, 27 May 2018 22:28:22 +0000 (00:28 +0200)]
vmx: convert to typesafe virConf accessors

Signed-off-by: Fabiano Fidêncio <fabiano@fidencio.org>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agoxen_vm: convert to typesafe virConf accessors
Fabiano Fidêncio [Sun, 27 May 2018 22:28:21 +0000 (00:28 +0200)]
xen_vm: convert to typesafe virConf accessors

Signed-off-by: Fabiano Fidêncio <fabiano@fidencio.org>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agoxen_xm: Split the per-disk logic from xenParseXMDisk()
Fabiano Fidêncio [Sun, 27 May 2018 22:28:20 +0000 (00:28 +0200)]
xen_xm: Split the per-disk logic from xenParseXMDisk()

xenParseXMDisk() does a lot of stuff and, in order to make things
cleaner, let's split it in two new functions:
- xenParseXMDisk(): it's a new function that keeps the old name. It's
responsible for the whole per-disk logic from the old xenParseXMDisk();
- xenParseXMDiskList(): it's basically the old xenParseXMDisk(), but
now it just iterates over the list of disks, calling xenParseXMDisk()
per each disk.

This patch is basically preparing the ground for the future when
typesafe virConf acessors will be used.

Signed-off-by: Fabiano Fidêncio <fabiano@fidencio.org>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agobhyve: tests: Add missing data files
Roman Bogorodskiy [Fri, 8 Jun 2018 17:52:17 +0000 (21:52 +0400)]
bhyve: tests: Add missing data files

Add missing data files for bhyve cpu topology tests that should have been
added in b66fda0a74.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
6 years agoqemu: Fix segmentation fault on reconnect
Marc Hartmayer [Fri, 8 Jun 2018 10:49:07 +0000 (12:49 +0200)]
qemu: Fix segmentation fault on reconnect

On start up of libvirtd the worker pool of the QEMU driver must be
initialized before trying to reconnect to all the running QEMU
instances. Otherwise segmentation faults can occur if there are QEMU
monitor events emitted.

 #0  __GI___pthread_mutex_lock
 #1  0x000003fffdba9e62 in virMutexLock
 #2  0x000003fffdbab2dc in virThreadPoolSendJob
 #3  0x000003ffd8343b70 in qemuProcessHandleSerialChanged
 #4  0x000003ffd836a776 in qemuMonitorEmitSerialChange
 #5  0x000003ffd8378e52 in qemuMonitorJSONHandleSerialChange
 #6  0x000003ffd8378930 in qemuMonitorJSONIOProcessEvent
 #7  0x000003ffd837edee in qemuMonitorJSONIOProcessLine
 #8  0x000003ffd837ef86 in qemuMonitorJSONIOProcess
 #9  0x000003ffd836757a in qemuMonitorIOProcess
 #10 0x000003ffd836863e in qemuMonitorIO
 #11 0x000003fffdb4033a in virEventPollDispatchHandles
 #12 0x000003fffdb4055e in virEventPollRunOnce
 #13 0x000003fffdb3e782 in virEventRunDefaultImpl
 #14 0x000003fffdc89400 in virNetDaemonRun
 #15 0x000000010002a816 in main

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agoutil: Remove cbm_mask from virResctrlInfoPerType
Martin Kletzander [Thu, 8 Feb 2018 15:02:04 +0000 (16:02 +0100)]
util: Remove cbm_mask from virResctrlInfoPerType

It was used just temporarily to do a calculation, no need to keep that around.
Also use virBitmap in the code instead of reimplementing two of its existing
functions.  And move the counting part next to where the value is read.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoMove virCacheKernel enum implemetation from conf/ to util/
Martin Kletzander [Thu, 8 Feb 2018 14:55:09 +0000 (15:55 +0100)]
Move virCacheKernel enum implemetation from conf/ to util/

It will be used in that file later on, plus it makes sense for all the
implementations to be in same place.  Also comment each one of them nicely and
add a comment explaining why they all need to end with the same _LAST value.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoutil: Initialize virResctrlInfo struct right away
Martin Kletzander [Thu, 8 Feb 2018 14:47:46 +0000 (15:47 +0100)]
util: Initialize virResctrlInfo struct right away

There is no need to have virResctrlGetInfo() when it must be called after
virResctrlInfoNew() anyway, otherwise it's just an unusable object.  When we
wrap the logic inside the New() function we'll save some calls later as well.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoutil: Reorder parts of virresctrl
Martin Kletzander [Thu, 8 Feb 2018 14:21:57 +0000 (15:21 +0100)]
util: Reorder parts of virresctrl

Move description of the purpose of the file before any definition.

One empty line between related enum definitions.

All typedefs before all structs.  This is exception from the usual, but not the
only one, we already have something similar for some other structs.  This way we
can move contents between structs and reorder some parts nicely without moving
all definitions of one type before another one just so it's defined.

Define all classes in one place.

Have one initialization function for all classes in the file.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoutil: Use virFileFlock() in virresctrl
Martin Kletzander [Thu, 8 Feb 2018 14:09:02 +0000 (15:09 +0100)]
util: Use virFileFlock() in virresctrl

That way we get rid of the last preprocessor conditional so the code compiles on
all platforms.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoutil: Avoid needless preprocessor conditionals in virresctrl
Martin Kletzander [Fri, 9 Feb 2018 06:32:33 +0000 (07:32 +0100)]
util: Avoid needless preprocessor conditionals in virresctrl

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoutil: Introduce virFileFlock
Martin Kletzander [Thu, 8 Feb 2018 13:53:20 +0000 (14:53 +0100)]
util: Introduce virFileFlock

We already have virFileLock(), but we are now using flock() in the code as
well (due to requirements for mutual exclusion between libvirt and other
programs using flock() as well), so let's have a function for that as well so we
don't need to have stubs for unsupported platforms in other files.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoutil: Fix typo in error message %ud -> %u
Martin Kletzander [Thu, 8 Feb 2018 13:50:42 +0000 (14:50 +0100)]
util: Fix typo in error message %ud -> %u

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoutil: Rename resctrl to alloc if it is virResctrlAllocPtr
Martin Kletzander [Thu, 1 Feb 2018 13:57:40 +0000 (14:57 +0100)]
util: Rename resctrl to alloc if it is virResctrlAllocPtr

Just to stay consistent.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agodocs: Add TSEG support info into news.xml
Martin Kletzander [Thu, 7 Jun 2018 13:57:05 +0000 (15:57 +0200)]
docs: Add TSEG support info into news.xml

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Add support for setting the TSEG size
Martin Kletzander [Thu, 10 May 2018 21:37:18 +0000 (23:37 +0200)]
qemu: Add support for setting the TSEG size

The default is stable per machine type so there should be no need to keep that.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Add capability flag for setting the extended tseg size
Martin Kletzander [Thu, 10 May 2018 21:27:57 +0000 (23:27 +0200)]
qemu: Add capability flag for setting the extended tseg size

For getting the reply I queried the newest and oldest QEMU using
test/qemucapsprobe.  From the differences I only extracted the reply to the new
QMP command and discarded the rest.  For all the versions below the one which
added support for the new option I used the output from the oldest QEMU release
and for those that support it I used the output from the newest one.

In order to make doubly sure the reply is where it is supposed to be (the
replies files are very forgiving) I added the property to all the replies files,
reran the tests again and fixed the order in replies files so that all the
versions are reporting the new capability.  Then removed that one property.

After that I used test/qemucapsfixreplies to fix the reply IDs.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf, schema, docs: Add support for TSEG size setting
Martin Kletzander [Thu, 10 May 2018 19:32:26 +0000 (21:32 +0200)]
conf, schema, docs: Add support for TSEG size setting

TSEG (Top of Memory Segment) is one of many regions that SMM (System Management
Mode) can occupy.  This one, however is special, because a) most of the SMM code
lives in TSEG nowadays and b) QEMU just (well, some time ago) added support for
so called 'extended' TSEG.  The difference to the TSEG implemented in real q35's
MCH (Memory Controller Hub) is that it can offer one extra size to the guest OS
apart from the standard TSEG's 1, 2, and 8 MiB and that size can be selected in
1 MiB increments.  Maximum may vary based on QEMU and is way too big, so we
don't need to check for the maximum here.  Similarly to the memory size we'll
leave it to the hypervisor to try satisfying that and giving us an error message
in case it is not possible.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Relax check for SMM feature
Martin Kletzander [Thu, 7 Jun 2018 21:24:45 +0000 (23:24 +0200)]
qemu: Relax check for SMM feature

One of the things that this is improving is the fact that instead of error
message (that was wrong) you get when starting a domain with SMM and i440fx we
allow the setting to go through.  SMM option exists and makes sense on i440fx as
well (basically whenever that _SMM_OPT capability is set).

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Move checks for SMM from command-line creation into validation phase
Martin Kletzander [Thu, 10 May 2018 21:28:24 +0000 (23:28 +0200)]
qemu: Move checks for SMM from command-line creation into validation phase

We are still hoping all of such checks will be moved there and this is one small
step in that direction.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: qemuxml2argv: Make tests based on DO_TEST_CAPS_LATEST stable
Peter Krempa [Mon, 4 Jun 2018 13:30:49 +0000 (15:30 +0200)]
tests: qemuxml2argv: Make tests based on DO_TEST_CAPS_LATEST stable

To avoid problems with test cases specifying an alias machine type which
would change once capabilities for a newer version are added strip all
alias machine types for the DO_TEST_CAPS_LATEST based tests.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoutil: storage: remove 'allow_probe' from virStorageFileGetMetadata
Peter Krempa [Mon, 4 Jun 2018 08:25:17 +0000 (10:25 +0200)]
util: storage: remove 'allow_probe' from virStorageFileGetMetadata

All callers pass 'false' now so it's no longer needed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: storage: Drop duplicate tests with TEST_CHAIN
Peter Krempa [Mon, 4 Jun 2018 08:16:03 +0000 (10:16 +0200)]
tests: storage: Drop duplicate tests with TEST_CHAIN

Now that all test cases with TEST_CHAIN were testing the same thing
twice drop one of them. Note that some of the cases were duplicate even
before dropping the image format probing tests.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: storage: Drop format probing from tests
Peter Krempa [Mon, 4 Jun 2018 07:39:28 +0000 (09:39 +0200)]
tests: storage: Drop format probing from tests

Storage drivers now don't allow it so there's no need to test it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: storage: Absorb ALLOW_PROBE flag into the TEST_CHAIN macro
Peter Krempa [Mon, 4 Jun 2018 07:50:13 +0000 (09:50 +0200)]
tests: storage: Absorb ALLOW_PROBE flag into the TEST_CHAIN macro

The second set of arguments for TEST_CHAIN always specifies the
'ALLOW_PROBE' flag. Make it part of the macro.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: virstoragetest: Add complementary test case for QED format
Peter Krempa [Mon, 4 Jun 2018 07:36:24 +0000 (09:36 +0200)]
tests: virstoragetest: Add complementary test case for QED format

We have a test case for QED disk image with autodetection but not with
the format explicitly specified.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agosecurity: aa-helper: Remove the -p parameter
Peter Krempa [Mon, 4 Jun 2018 07:00:47 +0000 (09:00 +0200)]
security: aa-helper: Remove the -p parameter

As the aa-helper binary is supposed to be used only with libvirt, we can
fully remove it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agosecurity: Remove VIR_SECURITY_MANAGER_ALLOW_DISK_PROBE
Peter Krempa [Mon, 4 Jun 2018 07:00:41 +0000 (09:00 +0200)]
security: Remove VIR_SECURITY_MANAGER_ALLOW_DISK_PROBE

Nothing is setting that flag now so it can be removed. Note that
removing 'mgr' from 'load_profile' in the apparmor driver would create a
lot of churn.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: driver: Remove impossible code path in qemuDomainSnapshotCreateInactiveExternal
Peter Krempa [Mon, 4 Jun 2018 07:00:37 +0000 (09:00 +0200)]
qemu: driver: Remove impossible code path in  qemuDomainSnapshotCreateInactiveExternal

Previous patch naively removed all code relevant to disk format
checking. The semantics now dictate that the format check when creating
external snapshots is now impossible as we always fill in the format for
disks in domain definition in the post-parse callback.

Remove the impossible code path.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: conf: Remove 'allow_disk_format_probing' config option
Peter Krempa [Mon, 4 Jun 2018 07:00:27 +0000 (09:00 +0200)]
qemu: conf: Remove 'allow_disk_format_probing' config option

The option is insecure and it has been long enough for users to migrate
their disk files to use explicit format. Drop the option and related
code.

The config parser still parses it and rejects statup if it's still
present in the config in enabled state.

The augeas lens is also kept so that users can disable it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: Drop tests enabling allowDiskFormatProbing
Peter Krempa [Mon, 4 Jun 2018 06:59:57 +0000 (08:59 +0200)]
tests: Drop tests enabling allowDiskFormatProbing

Format probing will be dropped so remove the tests which will become
obsolete.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoAdd Virtlyst web application to apps.html
Daniel Nicoletti [Mon, 4 Jun 2018 18:44:23 +0000 (15:44 -0300)]
Add Virtlyst web application to apps.html

Signed-off-by: Daniel Nicoletti <dantti12@gmail.com>
6 years agonwfilter: fix build error when pcap-config is not present
Brijesh Singh [Thu, 7 Jun 2018 20:46:27 +0000 (15:46 -0500)]
nwfilter: fix build error when pcap-config is not present

The compilation fails with the following error when pcap-config
is not present on the host:

nwfilter/nwfilter_learnipaddr.c:824:1: error: conflicting types for 'virNWFilterLearnIPAddress'
 virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver ATTRIBUTE_UNUSED,

 In file included from nwfilter/nwfilter_learnipaddr.c:57:0:
 nwfilter/nwfilter_learnipaddr.h:38:5: note: previous declaration of 'virNWFilterLearnIPAddress' was here
  int virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,

Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agonwfilter: directly use poll to wait for packets instead of pcap_next
Daniel P. Berrangé [Mon, 21 May 2018 11:46:00 +0000 (12:46 +0100)]
nwfilter: directly use poll to wait for packets instead of pcap_next

When a QEMU VM shuts down its TAP device gets deleted while nwfilter
IP address learning thread is still capturing packets. It is seen that
with TPACKET_V3 support in libcap, the pcap_next() call will not always
exit its poll() when the NIC is removed. This prevents the learning
thread from exiting which blocks the rest of libvirtd waiting on mutex
acquisition. By switching to do poll() in libvirt code, we can ensure
that we always exit the poll() at a time that is right for libvirt.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agonwfilter: fix IP address learning
Daniel P. Berrangé [Fri, 18 May 2018 11:54:52 +0000 (12:54 +0100)]
nwfilter: fix IP address learning

In a previous commit:

  commit d4bf8f415074759baf051644559e04fe78888f8b
  Author: Daniel P. Berrangé <berrange@redhat.com>
  Date:   Wed Feb 14 09:43:59 2018 +0000

    nwfilter: handle missing switch enum cases

    Ensure all enum cases are listed in switch statements, or cast away
    enum type in places where we don't wish to cover all cases.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
we changed a switch in the nwfilter learning thread so that it had
explict cases for all enum entries. Unfortunately the parameters in the
method had been declared with incorrect type. The "howDetect" parameter
does *not* accept "enum howDetect" values, rather it accepts a bitmask
of "enum howDetect" values, so it should have been an "int" type.

The caller always passes DETECT_STATIC|DETECT_DHCP, so essentially the
IP addressing learning was completely broken by the above change, as it
never matched any switch case, hitting the default leading to EINVAL.

Stop using a typedef for the parameter name this this is a bitmask,
not a plain enum value. Also stop using switch() since that's misleading
with bitmasks too.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agodocs: remove git snapshot download links
Daniel P. Berrangé [Thu, 7 Jun 2018 14:05:07 +0000 (15:05 +0100)]
docs: remove git snapshot download links

The process used to build the snapshots no longer works because the box
it runs on is outdated. Analysing the web logs shows the majority of
traffic to these links is from search engine bots. With those removed,
there is about 1 hit per day from (probable) humans.

Most users needing a tarball are better served by using official
releases. Those needing latest code are better served by using git
checkout. The tarball snapshots are not compelling enough to invest time
in fixing the script that produces them.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agonews: Document bhyve guest CPU topology feature
Roman Bogorodskiy [Mon, 28 May 2018 14:41:09 +0000 (18:41 +0400)]
news: Document bhyve guest CPU topology feature

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agobhyve: Add CPU topology support
Roman Bogorodskiy [Mon, 21 May 2018 14:53:36 +0000 (18:53 +0400)]
bhyve: Add CPU topology support

Recently, bhyve started supporting specifying guest CPU topology.
It looks this way:

  bhyve -c cpus=C,sockets=S,cores=C,threads=T ...

The old behaviour was bhyve -c C, where C is a number of vCPUs, is
still supported.

So if we have CPU topology in the domain XML, use the new syntax,
otherwise keep the old behaviour.

Also, document this feature in the bhyve driver page.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agobhyve: Properly name bhyve help parsing function
Roman Bogorodskiy [Thu, 7 Jun 2018 13:20:53 +0000 (17:20 +0400)]
bhyve: Properly name bhyve help parsing function

Currently there's a function called bhyveProbeCapsRTC_UTC() that
parses bhyve capabilities from the bhyve help output (bhyve -h).
Right now it only checks the '-u' flag, but as there will be more
features detectable through this help output, give it more general
name: bhyveProbeCapsFromHelp().

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoschema: remove reference to brctl
Ján Tomko [Thu, 7 Jun 2018 07:08:41 +0000 (09:08 +0200)]
schema: remove reference to brctl

ip(8) is the contemporary way of configuring bridges.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agotravis: Whitespace fixes
Andrea Bolognani [Thu, 7 Jun 2018 13:41:40 +0000 (15:41 +0200)]
travis: Whitespace fixes

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
6 years agotravis: switch to using Ubuntu 16.04 and 18.04
Daniel P. Berrangé [Tue, 5 Jun 2018 14:20:04 +0000 (15:20 +0100)]
travis: switch to using Ubuntu 16.04 and 18.04

The container images provided by Travis only support Ubuntu 14.04,
however, Travis has ability to run docker, which allows the build
script to use arbitrary OS images. This takes advantage of that to
convert the build over to Ubuntu 16.04 and 18.04

This is using the official Ubuntu provided images and installing
extra build deps required, as we previously did with Travis container
images.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agodocs: Tiny fix for the SMM description
Martin Kletzander [Thu, 10 May 2018 19:43:18 +0000 (21:43 +0200)]
docs: Tiny fix for the SMM description

The default is actually `on` when `<smm/>` is specified.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agodocs: document mandatory signoffs in governance.html
Ján Tomko [Tue, 5 Jun 2018 18:57:43 +0000 (20:57 +0200)]
docs: document mandatory signoffs in governance.html

Amend the paragraphs about no CLAs and implicit license
agreements to mention mandatory Signed-off-by tags.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agovirsh: fix help for detach-disk --print-xml
Ján Tomko [Thu, 7 Jun 2018 07:21:14 +0000 (09:21 +0200)]
virsh: fix help for detach-disk --print-xml

The help message was copied from attach-interface.
Introduced by commit <431e736>.

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu_tpm: Drop needles include of cap-ng.h
Michal Privoznik [Thu, 7 Jun 2018 06:32:11 +0000 (08:32 +0200)]
qemu_tpm: Drop needles include of cap-ng.h

qemu_tpm.c is not calling any capng_* functions. Let's drop this
include then. This also fixes a build failure without capng.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
6 years agofdstream: Report error from the I/O thread
John Ferlan [Wed, 6 Jun 2018 12:38:30 +0000 (08:38 -0400)]
fdstream: Report error from the I/O thread

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

Commit id 0fe4aa14 added the thread specific error message
reporting (or save) to virFDStreamEvent; however, as processing
goes via virStream{Send|SendHole|Recv} via calls from
daemonStreamHandle{WriteData|Hole|Read} the last error
gets reset in the main libvirt API's thus, whatever error
may have been set as last error will be cleared prior to
the error paths using it resulting in the generic error
on the client side.

For each of the paths that check threadQuit or threadErr,
check if threadErr was set and set it agian if there isn't
a last error (e.g. some other failure) set so that the
message can be provided back to the client.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agoutil: Implement and use virFileIsRegular() rather than d_type
Stefan Berger [Wed, 6 Jun 2018 16:24:12 +0000 (12:24 -0400)]
util: Implement and use virFileIsRegular() rather than d_type

The dirent's d_type field is not portable to all platforms. So we have
to use stat() to determine the type of file for the functions that need
to be cross-platform. Fix virFileChownFiles() by calling the new
virFileIsRegular() function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoDon't use enums in TPM struct fields
Daniel P. Berrangé [Wed, 6 Jun 2018 16:37:49 +0000 (17:37 +0100)]
Don't use enums in TPM struct fields

When using an enum in a struct field, the compiler is free to decide to
make it an unsigned type if it desires. This in turn leads to bugs when
code does

    if ((def->foo = virDomainFooTypeFromString(str)) < 0)
       ...

because 'def->foo' can't technically have an unsigned value from the
compiler's POV. While it is possible to add (int) casts in the code
example above, this is not desirable because it is easy to miss out
such casts. eg the code fixed here caused an error with clang builds

../../src/conf/domain_conf.c:12838:73: error: comparison of unsigned enum expression < 0 is always false [-Werror,-Wtautological-compare]
        if ((def->version = virDomainTPMVersionTypeFromString(version)) < 0) {
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agostorage: fix crash in luks encrypted volume creation
Katerina Koukiou [Wed, 6 Jun 2018 14:15:19 +0000 (16:15 +0200)]
storage: fix crash in luks encrypted volume creation

Fix the case when creating a luks encrypted volume
via an xml file without 'secret' element.
libvirtd was receiving SIGSEGV, now proper error is reported for
the missing element.

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

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com>
6 years agoconf: Use virDomainChrSourceDefClear() rather than VIR_FREE()
Stefan Berger [Thu, 24 May 2018 14:56:09 +0000 (10:56 -0400)]
conf: Use virDomainChrSourceDefClear() rather than VIR_FREE()

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Use resrc=tpm in case of TPM passthrough following docs
Stefan Berger [Thu, 24 May 2018 14:53:05 +0000 (10:53 -0400)]
conf: Use resrc=tpm in case of TPM passthrough following docs

Fix the resrc field for the TPM passthrough case to show tpm.
This fixes the code to follow the documentation.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Audit TPM emulator device at domain startup
Stefan Berger [Thu, 24 May 2018 14:51:26 +0000 (10:51 -0400)]
conf: Audit TPM emulator device at domain startup

Extend the existing auditing with auditing for the TPM emulator.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Run swtpm_setup in unprivileged mode for a TPM 2.0
Stefan Berger [Wed, 23 May 2018 20:53:09 +0000 (16:53 -0400)]
qemu: Run swtpm_setup in unprivileged mode for a TPM 2.0

swtpm_setup can be run for a TPM 2 in unprivileged mode assuming
XDG_CONFIG_HOME has been set and the necessary configuration files
have been put into that directory.

For current reference also see this link:

https://github.com/stefanberger/swtpm/pull/63

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agonews: Update news with new TPM emulator feature
Stefan Berger [Tue, 22 May 2018 14:55:32 +0000 (10:55 -0400)]
news: Update news with new TPM emulator feature

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Add swtpm to emulator cgroup
Stefan Berger [Thu, 5 Apr 2018 19:06:55 +0000 (15:06 -0400)]
qemu: Add swtpm to emulator cgroup

Add the external swtpm to the emulator cgroup so that upper limits of CPU
usage can be enforced on the emulated TPM.

To enable this we need to have the swtpm write its process id (pid) into a
file. We then read it from the file to configure the emulator cgroup.

The PID file is created in /var/run/libvirt/qemu/swtpm:

[root@localhost swtpm]# ls -lZ /var/run/libvirt/qemu/swtpm/
total 4
-rw-r--r--. 1 tss  tss  system_u:object_r:qemu_var_run_t:s0          5 Apr 10 12:26 1-testvm-swtpm.pid
srw-rw----. 1 qemu qemu system_u:object_r:svirt_image_t:s0:c597,c632 0 Apr 10 12:26 1-testvm-swtpm.sock

The swtpm command line now looks as follows:

root@localhost testvm]# ps auxZ | grep swtpm | grep socket | grep -v grep
system_u:system_r:virtd_t:s0:c597,c632 tss 18697 0.0  0.0 28172 3892 ?       Ss   16:46   0:00 /usr/bin/swtpm socket --daemon --ctrl type=unixio,path=/var/run/libvirt/qemu/swtpm/1-testvm-swtpm.sock,mode=0600 --tpmstate dir=/var/lib/libvirt/swtpm/485d0004-a48f-436a-8457-8a3b73e28568/tpm1.2/ --log file=/var/log/swtpm/libvirt/qemu/testvm-swtpm.log --pid file=/var/run/libvirt/qemu/swtpm/1-testvm-swtpm.pid

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoconf: Add support for choosing emulation of a TPM 2.0
Stefan Berger [Wed, 4 Apr 2018 18:40:17 +0000 (14:40 -0400)]
conf: Add support for choosing emulation of a TPM 2.0

This patch extends the TPM's device XML with TPM 2.0 support. This only works
for the emulator type backend and looks as follows:

    <tpm model='tpm-tis'>
      <backend type='emulator' version='2.0'/>
    </tpm>

The swtpm process now has --tpm2 as an additional parameter:

system_u:system_r:svirt_t:s0:c597,c632 tss 18477 11.8  0.0 28364  3868 ?        Rs   11:13  13:50 /usr/bin/swtpm socket --daemon --ctrl type=unixio,path=/var/run/libvirt/qemu/swtpm/testvm-swtpm.sock,mode=0660 --tpmstate dir=/var/lib/libvirt/swtpm/testvm/tpm2,mode=0640 --log file=/var/log/swtpm/libvirt/qemu/testvm-swtpm.log --tpm2 --pid file=/var/run/libvirt/qemu/swtpm/testvm-swtpm.pid

The version of the TPM can be changed and the state of the TPM is preserved.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agosecurity: Label the external swtpm with SELinux labels
Stefan Berger [Wed, 4 Apr 2018 16:40:32 +0000 (12:40 -0400)]
security: Label the external swtpm with SELinux labels

In this patch we label the swtpm process with SELinux labels. We give it the
same label as the QEMU process has. We label its state directory and files
as well. We restore the old security labels once the swtpm has terminated.

The file and process labels now look as follows:

Directory: /var/lib/libvirt/swtpm

[root@localhost swtpm]# ls -lZ
total 4
rwx------. 2 tss  tss  system_u:object_r:svirt_image_t:s0:c254,c932 4096 Apr  5 16:46 testvm

[root@localhost testvm]# ls -lZ
total 8
-rw-r--r--. 1 tss tss system_u:object_r:svirt_image_t:s0:c254,c932 3648 Apr  5 16:46 tpm-00.permall

The log in /var/log/swtpm/libvirt/qemu is labeled as follows:

-rw-r--r--. 1 tss tss system_u:object_r:svirt_image_t:s0:c254,c932 2237 Apr  5 16:46 vtpm.log

[root@localhost 485d0004-a48f-436a-8457-8a3b73e28567]# ps auxZ | grep swtpm | grep ctrl | grep -v grep
system_u:system_r:svirt_t:s0:c254,c932 tss 25664 0.0  0.0 28172  3892 ?        Ss   16:57   0:00 /usr/bin/swtpm socket --daemon --ctrl type=unixio,path=/var/run/libvirt/qemu/swtpm/testvm-swtpm.sock,mode=0660 --tpmstate dir=/var/lib/libvirt/swtpm/testvm/tpm1.2 --log file=/var/log/swtpm/libvirt/qemu/testvm-swtpm.log

[root@localhost 485d0004-a48f-436a-8457-8a3b73e28567]# ps auxZ | grep qemu | grep tpm | grep -v grep
system_u:system_r:svirt_t:s0:c254,c932 qemu 25669 99.0  0.0 3096704 48500 ?    Sl   16:57   3:28 /bin/qemu-system-x86_64 [..]

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: Add test cases for external swtpm TPM emulator
Stefan Berger [Tue, 4 Apr 2017 16:22:31 +0000 (12:22 -0400)]
tests: Add test cases for external swtpm TPM emulator

This patch adds extensions to existing test cases and specific test cases
for the tpm-emulator.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Add support for external swtpm TPM emulator
Stefan Berger [Tue, 4 Apr 2017 16:22:31 +0000 (12:22 -0400)]
qemu: Add support for external swtpm TPM emulator

This patch adds support for an external swtpm TPM emulator. The XML for
this type of TPM looks as follows:

 <tpm model='tpm-tis'>
   <backend type='emulator'/>
 </tpm>

The XML will currently only start a TPM 1.2.

Upon first start, libvirt will run `swtpm_setup`, which will simulate the
manufacturing of a TPM and create certificates for it and write them into
NVRAM locations of the emulated TPM.

After that libvirt starts the swtpm TPM emulator using the `swtpm` executable.

Once the VM terminates, libvirt uses the swtpm_ioctl executable to gracefully
shut down the `swtpm` in case it is still running (QEMU did not send shutdown)
or clean up the socket file.

The above mentioned executables must be found in the PATH.

The executables can either be run as root or started as root and switch to
the tss user. The requirement for the tss user comes through 'tcsd', which
is used for the simulation of the manufacturing. Which user is used can be
configured through qemu.conf. By default 'tss' is used.

The swtpm writes out state into files. The state is kept in /var/lib/libvirt/swtpm:

[root@localhost libvirt]# ls -lZ | grep swtpm

drwx--x--x. 7 root root unconfined_u:object_r:virt_var_lib_t:s0 4096 Apr  5 16:22 swtpm

The directory /var/lib/libvirt/swtpm maintains per-TPM state directories.
(Using the uuid of the VM for that since the name can change per VM renaming but
 we need a stable directory name.)

[root@localhost swtpm]# ls -lZ
total 4
drwx------. 2 tss  tss  system_u:object_r:virt_var_lib_t:s0          4096 Apr  5 16:46 485d0004-a48f-436a-8457-8a3b73e28568

[root@localhost 485d0004-a48f-436a-8457-8a3b73e28568]# ls -lZ
total 4
drwx------. 2 tss tss system_u:object_r:virt_var_lib_t:s0 4096 Apr 10 21:34 tpm1.2

[root@localhost tpm1.2]# ls -lZ
total 8
-rw-r--r--. 1 tss tss system_u:object_r:virt_var_lib_t:s0 3648 Apr  5 16:46 tpm-00.permall

The directory /var/run/libvirt/qemu/swtpm/ hosts the swtpm.sock that
QEMU uses to communicate with the swtpm:

root@localhost domain-1-testvm]# ls -lZ
total 0
srw-------. 1 qemu qemu system_u:object_r:svirt_image_t:s0:c597,c632  0 Apr  6 10:24 1-testvm-swtpm.sock

The logfile for the swtpm is in /var/log/swtpm/libvirt/qemu:

[root@localhost-3 qemu]# ls -lZ
total 4
-rw-------. 1 tss tss unconfined_u:object_r:var_log_t:s0 2199 Apr  6 14:01 testvm-swtpm.log

The processes are labeled as follows:

[root@localhost 485d0004-a48f-436a-8457-8a3b73e28567]# ps auxZ | grep swtpm | grep socket | grep -v grep
system_u:system_r:virtd_t:s0-s0:c0.c1023 tss 18697 0.0  0.0 28172 3892 ?       Ss   16:46   0:00 /usr/bin/swtpm socket --daemon --ctrl type=unixio,path=/var/run/libvirt/qemu/swtpm/1-testvm-swtpm.sock,mode=0600 --tpmstate dir=/var/lib/libvirt/swtpm/485d0004-a48f-436a-8457-8a3b73e28568/tpm1.2 --log file=/var/log/swtpm/libvirt/qemu/testvm-swtpm.log

[root@localhost 485d0004-a48f-436a-8457-8a3b73e28567]# ps auxZ | grep qemu | grep tpm | grep -v grep
system_u:system_r:svirt_t:s0:c413,c430 qemu 18702 2.5  0.0 3036052 48676 ?     Sl   16:46   0:08 /bin/qemu-system-x86_64 [...]

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Extend QEMU with external TPM support
Stefan Berger [Tue, 4 Apr 2017 16:22:31 +0000 (12:22 -0400)]
qemu: Extend QEMU with external TPM support

Implement functions for managing the storage of the external swtpm as well
as starting and stopping it. Also implement functions to use swtpm_setup,
which simulates the manufacturing of a TPM, which includes creation of
certificates for the device.

Further, the external TPM needs storage on the host that we need to set
up before it can be run. We can clean up the host once the domain is
undefined.

This patch also implements a small layer for external device support that
calls into the TPM device layer if a domain has an attached TPM. This is
the layer we will wire up later on.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: Extend qemu_conf with tpm-emulator support
Stefan Berger [Tue, 4 Apr 2017 16:22:31 +0000 (12:22 -0400)]
qemu: Extend qemu_conf with tpm-emulator support

Extend qemu_conf with user and group for running the tpm-emulator
and add directories to the configuration for the locations of the
log, state, and socket of the tpm-emulator.

Also add these new directories to the QEMU Makefile.inc.am and
the RPM spec file libvirt.spec.in.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
6 years agosecurity: Add DAC and SELinux security for tpm-emulator
Stefan Berger [Tue, 4 Apr 2017 16:22:31 +0000 (12:22 -0400)]
security: Add DAC and SELinux security for tpm-emulator

Extend the DAC and SELinux modules with support for the tpm-emulator.
We label the Unix socket that QEMU connects to after starting swtmp
with DAC and SELinux labels. We do not have to restore the labels in
this case since the tpm-emulator will remove the Unix socket when it
terminates.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>