[libvirt] [PATCH] news: add entries for libxl driver improvements and bug fixes

2017-02-15 Thread Jim Fehlig
Signed-off-by: Jim Fehlig 
---

Since news changes are not candidates for backport I assume it is fine
to include recent libxl improvements and bug fixes in a single commit.
I can break this up if that assumption is wrong.

 docs/news.xml | 29 +
 1 file changed, 29 insertions(+)

diff --git a/docs/news.xml b/docs/news.xml
index 5bca75ea1..22f00cc55 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -83,6 +83,16 @@
   and network.
 
   
+  
+
+  libxl: improve support for timer configurations
+
+
+  Add support for multiple timers. Extend the tsc timer to
+  support the emulate mode. Improve conversion of timer XML
+  to/from xl.cfg.
+
+  
 
 
   
@@ -116,6 +126,25 @@
   regenerate it properly.
 
   
+  
+
+  libxl: maximum memory fixes
+
+
+  Fix reporting of domain maximum memory. Fix setting dom0
+  maximum memory.
+
+  
+  
+
+  libxl: fix disk detach when driver not specified
+
+  
+  
+
+  libxl: fix dom0 autoballooning with Xen 4.8
+
+  
 
   
   
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] news: document libxl tunnelled migration support

2017-02-15 Thread Jim Fehlig

On 02/15/2017 06:35 PM, Chris Lalancette wrote:

On Wed, Feb 15, 2017 at 8:24 PM, Jim Fehlig > wrote:


Heh, as a native speaker I'm not sure which spelling is correct, but seem to
recall a prior discussion on the list proclaiming 'tunneled'. If folks
prefer I can revert the s/tunnelled/tunneled/ commit.


I think you have me to blame for "tunnelled".  At the time I initially wrote
tunnelled migration support, I did a Google search similar to what you have
done, and determined that tunnelled seemed to be slightly preferred.
Subsequently almost everyone has balked at it, but I think the horse has left
the barn on it and we should probably stick with "tunnelled".


Ok. I also failed to realize that the commit providing the news item used 
'tunnelled'. I've sent a patch to revert the spelling change, but I'll wait for 
an explicit ACK this time


https://www.redhat.com/archives/libvir-list/2017-February/msg00770.html

Regards,
Jim

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] Revert "news: fix spelling of tunneled"

2017-02-15 Thread Jim Fehlig
Use of 'tunnelled' is over 100x that of 'tunneled' throughout the
code. Also, the commit providing this news item used 'tunnelled'.

This reverts commit b5ac475f506cd13adab773cebd125a45d3f2ba8d.

Signed-off-by: Jim Fehlig 
---

Heh, so much for the trivial rule. I'll wait for an ACK on this one.

Sorry for the chatter...

 docs/news.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/docs/news.xml b/docs/news.xml
index 5bca75ea1..b0629b523 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -55,10 +55,10 @@
   
   
 
-  libxl: add tunneled migration support
+  libxl: add tunnelled migration support
 
 
-  Add tunneled migration to libxl driver, which is always capable of
+  Add tunnelled migration to libxl driver, which is always capable of
   strong encryption and doesn't require any extra network connection
   other than what's required for remote access of libvirtd.
 
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] news: document libxl tunnelled migration support

2017-02-15 Thread Chris Lalancette
On Wed, Feb 15, 2017 at 8:24 PM, Jim Fehlig  wrote:

>
> Heh, as a native speaker I'm not sure which spelling is correct, but seem
> to recall a prior discussion on the list proclaiming 'tunneled'. If folks
> prefer I can revert the s/tunnelled/tunneled/ commit.
>
>
I think you have me to blame for "tunnelled".  At the time I initially
wrote tunnelled migration support, I did a Google search similar to what
you have done, and determined that tunnelled seemed to be slightly
preferred.  Subsequently almost everyone has balked at it, but I think the
horse has left the barn on it and we should probably stick with "tunnelled".

Chris
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] news: document libxl tunnelled migration support

2017-02-15 Thread Jim Fehlig

On 02/15/2017 05:06 PM, Joao Martins wrote:

On 02/15/2017 11:41 PM, Jim Fehlig wrote:

Joao Martins wrote:

Signed-off-by: Joao Martins 
---
 docs/news.xml | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/docs/news.xml b/docs/news.xml
index b756a97..b0629b5 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -53,6 +53,16 @@
   was virtio-net.
 
   
+  
+
+  libxl: add tunnelled migration support
+
+
+  Add tunnelled migration to libxl driver, which is always capable of
+  strong encryption and doesn't require any extra network connection
+  other than what's required for remote access of libvirtd.
+
+  
 
 
   


Pushed, but only after realizing tunneled is misspelled :-(. No use perpetuating
the misspelling of tunneled, so I've pushed a trivial followup.


Interesting, I didn't know that. Greping the whole repo for "tunnelled" and you
will find a *lot* of matches:

$ git grep tunneled | wc -l
10
$ git grep tunnelled | wc -l
1242


So the incorrect spelling is used over 100x more than the correct one :-)


Hmm, but the internets aren't really clear. Some hits say tunneled vs tunnelled
being both correct.


Heh, as a native speaker I'm not sure which spelling is correct, but seem to 
recall a prior discussion on the list proclaiming 'tunneled'. If folks prefer I 
can revert the s/tunnelled/tunneled/ commit.


Regards,
Jim

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] news: document libxl tunnelled migration support

2017-02-15 Thread Joao Martins
On 02/15/2017 11:41 PM, Jim Fehlig wrote:
> Joao Martins wrote:
>> Signed-off-by: Joao Martins 
>> ---
>>  docs/news.xml | 10 ++
>>  1 file changed, 10 insertions(+)
>>
>> diff --git a/docs/news.xml b/docs/news.xml
>> index b756a97..b0629b5 100644
>> --- a/docs/news.xml
>> +++ b/docs/news.xml
>> @@ -53,6 +53,16 @@
>>was virtio-net.
>>  
>>
>> +  
>> +
>> +  libxl: add tunnelled migration support
>> +
>> +
>> +  Add tunnelled migration to libxl driver, which is always capable 
>> of
>> +  strong encryption and doesn't require any extra network connection
>> +  other than what's required for remote access of libvirtd.
>> +
>> +  
>>  
>>  
>>
> 
> Pushed, but only after realizing tunneled is misspelled :-(. No use 
> perpetuating
> the misspelling of tunneled, so I've pushed a trivial followup.

Interesting, I didn't know that. Greping the whole repo for "tunnelled" and you
will find a *lot* of matches:

$ git grep tunneled | wc -l
10
$ git grep tunnelled | wc -l
1242

Hmm, but the internets aren't really clear. Some hits say tunneled vs tunnelled
being both correct.

Joao

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v3 0/2] libxl: tunnelled migration support

2017-02-15 Thread Jim Fehlig
Joao Martins wrote:
> On 02/15/2017 10:14 PM, Joao Martins wrote:
>> On 02/15/2017 09:53 PM, Jim Fehlig wrote:
>>> Joao Martins wrote:
 Hey!

 Presented herewith is take 4 from tunnelled migration addressing all 
 previous
 comments. No functional changes from v2, only revert to v1 on the top level
 migration functions and removing unnecessary usage of virReportError.

 Thanks,
 Joao

 Bob Liu (1):
   libxl: add tunnelled migration support

 Joao Martins (1):
   libxl: refactor libxlDomainMigrationPrepare

  src/libxl/libxl_driver.c|  58 ++-
  src/libxl/libxl_migration.c | 367 
 +---
  src/libxl/libxl_migration.h |   9 ++
  3 files changed, 381 insertions(+), 53 deletions(-)

>>> ACK series. I fixed up the indentation in 2/2 before pushing.
>>>
>>> This series is newsworthy. Can you post a followup adding an entry to
>>> docs/news.xml describing this new feature? Thanks!
>> Yeap, will do.
> Just sent it over [0]. Maybe it's also worth adding news coverage to your  
> libxl
> timer improvements, and the many maxmem related fixes :)

Touche :-). I guess those are newsworthy as well. I'll send some patches in a 
bit.

Regards,
Jim

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] news: document libxl tunnelled migration support

2017-02-15 Thread Jim Fehlig
Joao Martins wrote:
> Signed-off-by: Joao Martins 
> ---
>  docs/news.xml | 10 ++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/docs/news.xml b/docs/news.xml
> index b756a97..b0629b5 100644
> --- a/docs/news.xml
> +++ b/docs/news.xml
> @@ -53,6 +53,16 @@
>was virtio-net.
>  
>
> +  
> +
> +  libxl: add tunnelled migration support
> +
> +
> +  Add tunnelled migration to libxl driver, which is always capable of
> +  strong encryption and doesn't require any extra network connection
> +  other than what's required for remote access of libvirtd.
> +
> +  
>  
>  
>

Pushed, but only after realizing tunneled is misspelled :-(. No use perpetuating
the misspelling of tunneled, so I've pushed a trivial followup.

Regards,
Jim

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] libxl: fix potential double free in libxlDriverGetDom0MaxmemConf

2017-02-15 Thread John Ferlan


On 02/15/2017 12:49 PM, Jim Fehlig wrote:
> Commit 4ab0c959 fixed a memory leak in libxlDriverGetDom0MaxmemConf
> but introduced a potential double free of mem_tokens
> 
> *** Error in `/usr/sbin/libvirtd': double free or corruption (out):
> 0x7fffc808cfd0 ***
> 
> Avoid double free by setting mem_tokens to NULL after calling
> virStringListFree.
> 
> Signed-off-by: Jim Fehlig 
> ---
>  src/libxl/libxl_conf.c | 1 +
>  1 file changed, 1 insertion(+)
> 

ACK

John (face-palm)

> diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
> index f5b788b50..4bab651b3 100644
> --- a/src/libxl/libxl_conf.c
> +++ b/src/libxl/libxl_conf.c
> @@ -1623,6 +1623,7 @@ libxlDriverGetDom0MaxmemConf(libxlDriverConfigPtr cfg,
>  }
>  }
>  virStringListFree(mem_tokens);
> +mem_tokens = NULL;
>  }
>  
>   physmem:
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] news: fix spelling of tunneled

2017-02-15 Thread Jim Fehlig
s/tunnelled/tunneled/ in news for the libxl tunneled migration feature.

Signed-off-by: Jim Fehlig 
---

Pushed under trivial rule.

 docs/news.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/docs/news.xml b/docs/news.xml
index b0629b523..5bca75ea1 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -55,10 +55,10 @@
   
   
 
-  libxl: add tunnelled migration support
+  libxl: add tunneled migration support
 
 
-  Add tunnelled migration to libxl driver, which is always capable of
+  Add tunneled migration to libxl driver, which is always capable of
   strong encryption and doesn't require any extra network connection
   other than what's required for remote access of libvirtd.
 
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v3 0/2] libxl: tunnelled migration support

2017-02-15 Thread Joao Martins
On 02/15/2017 10:14 PM, Joao Martins wrote:
> On 02/15/2017 09:53 PM, Jim Fehlig wrote:
>> Joao Martins wrote:
>>> Hey!
>>>
>>> Presented herewith is take 4 from tunnelled migration addressing all 
>>> previous
>>> comments. No functional changes from v2, only revert to v1 on the top level
>>> migration functions and removing unnecessary usage of virReportError.
>>>
>>> Thanks,
>>> Joao
>>>
>>> Bob Liu (1):
>>>   libxl: add tunnelled migration support
>>>
>>> Joao Martins (1):
>>>   libxl: refactor libxlDomainMigrationPrepare
>>>
>>>  src/libxl/libxl_driver.c|  58 ++-
>>>  src/libxl/libxl_migration.c | 367 
>>> +---
>>>  src/libxl/libxl_migration.h |   9 ++
>>>  3 files changed, 381 insertions(+), 53 deletions(-)
>>>
>>
>> ACK series. I fixed up the indentation in 2/2 before pushing.
>>
>> This series is newsworthy. Can you post a followup adding an entry to
>> docs/news.xml describing this new feature? Thanks!
> Yeap, will do.
Just sent it over [0]. Maybe it's also worth adding news coverage to your  libxl
timer improvements, and the many maxmem related fixes :)

[0] https://www.redhat.com/archives/libvir-list/2017-February/msg00761.html

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] news: document libxl tunnelled migration support

2017-02-15 Thread Joao Martins
Signed-off-by: Joao Martins 
---
 docs/news.xml | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/docs/news.xml b/docs/news.xml
index b756a97..b0629b5 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -53,6 +53,16 @@
   was virtio-net.
 
   
+  
+
+  libxl: add tunnelled migration support
+
+
+  Add tunnelled migration to libxl driver, which is always capable of
+  strong encryption and doesn't require any extra network connection
+  other than what's required for remote access of libvirtd.
+
+  
 
 
   
-- 
2.1.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [RFC PATCH v2 00/18] Introduce vGPU mdev framework to libvirt

2017-02-15 Thread Alex Williamson
Hi Erik,

On Wed, 15 Feb 2017 22:32:17 +0100
Erik Skultety  wrote:

> since v1:
> - new  attribute model introduced which tells libvirt which device 
> API
> should be considered when auto-assigning guest address
> - device_api is properly checked, thus taking the 'model' attribute only as a
> hint to assign "some" address
> - new address type 'mdev' is introduced rather than using plain  
> element,
> since the address element is more conveniently extendable.
> - the emulated mtty driver now works as well out of the box, so no HW needed 
> to
> review this series --> let's try it :)
> - fixed all the nits from v1

Yay!  Is this missing the part where the locked memory limits get
bumped for vfio devices though?  We don't know how much any given mdev
device will need to lock, but we should plan for up to the full VM
size, just like vfio devices.  Otherwise it seems like it works!
Thanks,

Alex

> Erik Skultety (18):
>   util: Introduce new module virmdev
>   conf: Introduce new hostdev device type mdev
>   conf: Introduce new address type mdev
>   conf: Update XML parser, formatter, and RNG schema to support mdev
>   conf: Introduce virDomainHostdevDefPostParse
>   conf: Add post parse code for mdevs to virDomainHostdevDefPostParse
>   security: dac: Enable labeling of vfio mediated devices
>   security: selinux: Enable labeling of vfio mediated devices
>   conf: Enable cold-plug of a mediated device
>   qemu: Assign PCI addresses for mediated devices as well
>   hostdev: Maintain a driver list of active mediated devices
>   hostdev: Introduce a reattach method for mediated devices
>   qemu: cgroup: Adjust cgroups' logic to allow mediated devices
>   qemu: namespace: Hook up the discovery of mdevs into the namespace
> code
>   qemu: Format mdevs on the qemu command line
>   test: Add some test cases for our test suite regarding the mdevs
>   docs: Document the new hostdev and address type 'mdev'
>   news: Update the NEWS.xml about the new mdev feature
> 
>  docs/formatdomain.html.in  |  48 ++-
>  docs/news.xml  |  11 +
>  docs/schemas/domaincommon.rng  |  26 ++
>  po/POTFILES.in |   1 +
>  src/Makefile.am|   1 +
>  src/conf/device_conf.h |   1 +
>  src/conf/domain_conf.c | 203 ++--
>  src/conf/domain_conf.h |   9 +
>  src/libvirt_private.syms   |  20 ++
>  src/qemu/qemu_cgroup.c |  34 ++
>  src/qemu/qemu_command.c|  49 +++
>  src/qemu/qemu_command.h|   5 +
>  src/qemu/qemu_domain.c |  12 +
>  src/qemu/qemu_domain.h |   1 +
>  src/qemu/qemu_domain_address.c |  16 +-
>  src/qemu/qemu_hostdev.c|  37 +++
>  src/qemu/qemu_hostdev.h|   8 +
>  src/qemu/qemu_hotplug.c|   2 +
>  src/security/security_apparmor.c   |   3 +
>  src/security/security_dac.c|  55 
>  src/security/security_selinux.c|  54 
>  src/util/virhostdev.c  | 229 -
>  src/util/virhostdev.h  |  16 +
>  src/util/virmdev.c | 358 
> +
>  src/util/virmdev.h |  93 ++
>  tests/domaincapsschemadata/full.xml|   1 +
>  .../qemuxml2argv-hostdev-mdev-unmanaged.args   |  25 ++
>  .../qemuxml2argv-hostdev-mdev-unmanaged.xml|  37 +++
>  tests/qemuxml2argvtest.c   |   6 +
>  .../qemuxml2xmlout-hostdev-mdev-unmanaged.xml  |  40 +++
>  tests/qemuxml2xmltest.c|   1 +
>  31 files changed, 1362 insertions(+), 40 deletions(-)
>  create mode 100644 src/util/virmdev.c
>  create mode 100644 src/util/virmdev.h
>  create mode 100644 
> tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args
>  create mode 100644 
> tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml
>  create mode 100644 
> tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v3 0/2] libxl: tunnelled migration support

2017-02-15 Thread Joao Martins
On 02/15/2017 09:53 PM, Jim Fehlig wrote:
> Joao Martins wrote:
>> Hey!
>>
>> Presented herewith is take 4 from tunnelled migration addressing all previous
>> comments. No functional changes from v2, only revert to v1 on the top level
>> migration functions and removing unnecessary usage of virReportError.
>>
>> Thanks,
>> Joao
>>
>> Bob Liu (1):
>>   libxl: add tunnelled migration support
>>
>> Joao Martins (1):
>>   libxl: refactor libxlDomainMigrationPrepare
>>
>>  src/libxl/libxl_driver.c|  58 ++-
>>  src/libxl/libxl_migration.c | 367 
>> +---
>>  src/libxl/libxl_migration.h |   9 ++
>>  3 files changed, 381 insertions(+), 53 deletions(-)
>>
> 
> ACK series. I fixed up the indentation in 2/2 before pushing.
> 
> This series is newsworthy. Can you post a followup adding an entry to
> docs/news.xml describing this new feature? Thanks!
Yeap, will do.

Thanks!
Joao

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v3 0/2] libxl: tunnelled migration support

2017-02-15 Thread Jim Fehlig
Joao Martins wrote:
> Hey!
> 
> Presented herewith is take 4 from tunnelled migration addressing all previous
> comments. No functional changes from v2, only revert to v1 on the top level
> migration functions and removing unnecessary usage of virReportError.
> 
> Thanks,
> Joao
> 
> Bob Liu (1):
>   libxl: add tunnelled migration support
> 
> Joao Martins (1):
>   libxl: refactor libxlDomainMigrationPrepare
> 
>  src/libxl/libxl_driver.c|  58 ++-
>  src/libxl/libxl_migration.c | 367 
> +---
>  src/libxl/libxl_migration.h |   9 ++
>  3 files changed, 381 insertions(+), 53 deletions(-)
> 

ACK series. I fixed up the indentation in 2/2 before pushing.

This series is newsworthy. Can you post a followup adding an entry to
docs/news.xml describing this new feature? Thanks!

Regards,
Jim

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 16/18] test: Add some test cases for our test suite regarding the mdevs

2017-02-15 Thread Erik Skultety
For now, these only cover the unmanaged, i.e. user pre-created devices.

Signed-off-by: Erik Skultety 
---
 .../qemuxml2argv-hostdev-mdev-unmanaged.args   | 25 ++
 .../qemuxml2argv-hostdev-mdev-unmanaged.xml| 37 
 tests/qemuxml2argvtest.c   |  6 
 .../qemuxml2xmlout-hostdev-mdev-unmanaged.xml  | 40 ++
 tests/qemuxml2xmltest.c|  1 +
 5 files changed, 109 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml

diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args 
b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args
new file mode 100644
index 000..fdefeb6
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args
@@ -0,0 +1,25 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu \
+-name QEMUGuest2 \
+-S \
+-M pc \
+-m 214 \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-nographic \
+-nodefconfig \
+-nodefaults \
+-monitor unix:/tmp/lib/domain--1-QEMUGuest2/monitor.sock,server,nowait \
+-no-acpi \
+-boot c \
+-usb \
+-drive file=/dev/HostVG/QEMUGuest2,format=raw,if=none,id=drive-ide0-0-0 \
+-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
+-device vfio-pci,\
+sysfsdev=/sys/bus/mdev/devices/53764d0e-85a0-42b4-af5c-2046b460b1dc,bus=pci.0,\
+addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml 
b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml
new file mode 100644
index 000..144b769
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml
@@ -0,0 +1,37 @@
+
+  QEMUGuest2
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219136
+  219136
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu
+
+  
+  
+  
+  
+
+
+
+
+
+
+
+
+
+  
+
+  
+
+
+  
+
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index faa99c6..e1173ac 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1475,6 +1475,12 @@ mymain(void)
 DO_TEST("hostdev-vfio-multidomain",
 QEMU_CAPS_NODEFCONFIG,
 QEMU_CAPS_DEVICE_VFIO_PCI, QEMU_CAPS_HOST_PCI_MULTIDOMAIN);
+DO_TEST("hostdev-mdev-unmanaged",
+QEMU_CAPS_NODEFCONFIG,
+QEMU_CAPS_DEVICE_VFIO_PCI);
+DO_TEST_PARSE_ERROR("hostdev-mdev-unmanaged-no-uuid",
+QEMU_CAPS_NODEFCONFIG,
+QEMU_CAPS_DEVICE_VFIO_PCI);
 DO_TEST_FAILURE("hostdev-vfio-multidomain",
 QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_DEVICE_VFIO_PCI);
 DO_TEST("pci-rom",
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml 
b/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml
new file mode 100644
index 000..55f19c4
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml
@@ -0,0 +1,40 @@
+
+  QEMUGuest2
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219136
+  219136
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu
+
+  
+  
+  
+  
+
+
+  
+
+
+
+  
+
+
+
+
+  
+
+  
+  
+
+
+  
+
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 0702f58..fbb5192 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -550,6 +550,7 @@ mymain(void)
 DO_TEST("hostdev-usb-address", NONE);
 DO_TEST("hostdev-pci-address", NONE);
 DO_TEST("hostdev-vfio", NONE);
+DO_TEST("hostdev-mdev-unmanaged", NONE);
 DO_TEST("pci-rom", NONE);
 DO_TEST("pci-serial-dev-chardev", NONE);
 
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 06/18] conf: Add post parse code for mdevs to virDomainHostdevDefPostParse

2017-02-15 Thread Erik Skultety
We need to make sure that if user explicitly provides a guest address
for a mdev device, the address type will be matching the device API
supported on that specific mediated device and error out with an
incorrect XML message.

Signed-off-by: Erik Skultety 
---
 src/conf/domain_conf.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 151a308..69874f0 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4239,10 +4239,26 @@ virDomainHostdevDefPostParse(virDomainHostdevDefPtr dev,
 }
 }
 break;
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+int model = dev->source.subsys.u.mdev.model;
+
+if (dev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
+return 0;
+
+if (model == VIR_MDEV_MODEL_TYPE_VFIO_PCI &&
+dev->info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+virReportError(VIR_ERR_XML_ERROR,
+   _("Unsupported address type '%s' with mediated "
+ "device model '%s'"),
+   virDomainDeviceAddressTypeToString(dev->info->type),
+   virMediatedDeviceModelTypeToString(model));
+return -1;
+}
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 break;
 }
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 04/18] conf: Update XML parser, formatter, and RNG schema to support mdev

2017-02-15 Thread Erik Skultety
To keep the domain XML as much platform agnostic as possible, do not
expose an element/attribute which would contain path directly to the
syfs filesystem which the mediated devices are build upon. Instead,
identify each mediated device by a UUID attribute as well as specifying
the device API (e.g. vfio-pci) through the 'model' attribute.

Signed-off-by: Erik Skultety 
---
 docs/schemas/domaincommon.rng | 26 ++
 src/conf/domain_conf.c| 50 +++
 2 files changed, 76 insertions(+)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index d715bff..ad8f47c 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -4014,6 +4014,7 @@
   
   
   
+  
 
   
 
@@ -4164,6 +4165,20 @@
 
   
 
+  
+
+  mdev
+
+
+  
+vfio-pci
+  
+
+
+  
+
+  
+
   
 
   storage
@@ -4322,6 +4337,11 @@
   
 
   
+  
+
+  
+
+  
   
 
   
@@ -4703,6 +4723,12 @@
   
   
 
+
+  
+mdev
+  
+  
+
   
 
   
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 053f3cb..870aec6 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6348,6 +6348,47 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr 
sourcenode,
 return ret;
 }
 
+static int
+virDomainHostdevSubsysMediatedDevDefParseXML(virDomainHostdevDefPtr def,
+ xmlXPathContextPtr ctxt)
+{
+int ret = -1;
+unsigned char uuid[VIR_UUID_BUFLEN] = {0};
+char *uuidxml = NULL;
+xmlNodePtr node = NULL;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
+
+if (mdevsrc->model == 0) {
+virReportError(VIR_ERR_XML_ERROR, "%s",
+   _("Missing 'model' attribute for element "));
+goto cleanup;
+}
+
+if (!(node = virXPathNode("./source/address", ctxt))) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("Missing  element"));
+goto cleanup;
+}
+
+if (!(uuidxml = virXMLPropString(node, "uuid"))) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("Missing 'uuid' attribute for element "));
+goto cleanup;
+}
+
+if (virUUIDParse(uuidxml, uuid) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   "%s",
+   _("Cannot parse uuid attribute of element "));
+goto cleanup;
+}
+
+virUUIDFormat(uuid, mdevsrc->uuidstr);
+ret = 0;
+ cleanup:
+VIR_FREE(uuidxml);
+return ret;
+}
 
 static int
 virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
@@ -6380,6 +6421,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 
 sgio = virXMLPropString(node, "sgio");
 rawio = virXMLPropString(node, "rawio");
+model = virXMLPropString(node, "model");
 
 /* @type is passed in from the caller rather than read from the
  * xml document, because it is specified in different places for
@@ -6494,6 +6536,8 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 goto error;
 break;
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+if (virDomainHostdevSubsysMediatedDevDefParseXML(def, ctxt) < 0)
+goto error;
 break;
 
 default:
@@ -6509,6 +6553,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 VIR_FREE(sgio);
 VIR_FREE(rawio);
 VIR_FREE(backendStr);
+VIR_FREE(model);
 return ret;
 }
 
@@ -21180,6 +21225,7 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 virDomainHostdevSubsysSCSIHostPtr scsihostsrc = >u.host;
 virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc = >u.iscsi;
 
@@ -21284,6 +21330,10 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
 break;
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
 break;
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+virBufferAsprintf(buf, "\n",
+  mdevsrc->uuidstr);
+break;
 default:
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected hostdev type %d"),
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 07/18] security: dac: Enable labeling of vfio mediated devices

2017-02-15 Thread Erik Skultety
Label the VFIO IOMMU devices under /dev/vfio/ referenced by the symlinks
in the sysfs (e.g. /sys/class/mdev_bus//iommu_group) which what
qemu actually gets formatted on the command line.

Signed-off-by: Erik Skultety 
---
 src/security/security_dac.c | 57 +++--
 1 file changed, 55 insertions(+), 2 deletions(-)

diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index ecce1d3..45bd24e 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -33,6 +33,7 @@
 #include "virfile.h"
 #include "viralloc.h"
 #include "virlog.h"
+#include "virmdev.h"
 #include "virpci.h"
 #include "virusb.h"
 #include "virscsi.h"
@@ -856,6 +857,15 @@ virSecurityDACSetHostLabel(virSCSIVHostDevicePtr dev 
ATTRIBUTE_UNUSED,
 
 
 static int
+virSecurityDACSetMediatedDevLabel(virMediatedDevicePtr dev ATTRIBUTE_UNUSED,
+  const char *file,
+  void *opaque)
+{
+return virSecurityDACSetHostdevLabelHelper(file, opaque);
+}
+
+
+static int
 virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr,
   virDomainDefPtr def,
   virDomainHostdevDefPtr dev,
@@ -867,7 +877,9 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 int ret = -1;
+virMediatedDevicePtr mdev = NULL;
 
 if (!priv->dynamicOwnership)
 return 0;
@@ -964,13 +976,26 @@ virSecurityDACSetHostdevLabel(virSecurityManagerPtr mgr,
 break;
 }
 
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+char *vfio_dev = NULL;
+if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr)))
+goto done;
+
+if (!(vfio_dev = virMediatedDeviceGetIOMMUGroupDev(mdev)))
+goto done;
+
+ret = virSecurityDACSetMediatedDevLabel(mdev, vfio_dev, );
+VIR_FREE(vfio_dev);
+break;
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 ret = 0;
 break;
 }
 
  done:
+virMediatedDeviceFree(mdev);
 return ret;
 }
 
@@ -1018,6 +1043,15 @@ virSecurityDACRestoreHostLabel(virSCSIVHostDevicePtr dev 
ATTRIBUTE_UNUSED,
 return virSecurityDACRestoreFileLabel(priv, file);
 }
 
+static int
+virSecurityDACRestoreMediatedDevLabel(virMediatedDevicePtr dev 
ATTRIBUTE_UNUSED,
+  const char *file,
+  void *opaque)
+{
+virSecurityManagerPtr mgr = opaque;
+virSecurityDACDataPtr priv = virSecurityManagerGetPrivateData(mgr);
+return virSecurityDACRestoreFileLabel(priv, file);
+}
 
 static int
 virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr mgr,
@@ -1032,6 +1066,7 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr 
mgr,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 int ret = -1;
 
 secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_DAC_NAME);
@@ -1120,7 +1155,25 @@ virSecurityDACRestoreHostdevLabel(virSecurityManagerPtr 
mgr,
 break;
 }
 
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+char *vfiodev = NULL;
+virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr);
+
+if (!mdev)
+goto done;
+
+if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
+virMediatedDeviceFree(mdev);
+goto done;
+}
+
+ret = virSecurityDACRestoreMediatedDevLabel(mdev, vfiodev, mgr);
+
+VIR_FREE(vfiodev);
+virMediatedDeviceFree(mdev);
+break;
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 ret = 0;
 break;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 10/18] qemu: Assign PCI addresses for mediated devices as well

2017-02-15 Thread Erik Skultety
So far, the official support is for x86_64 arch guests so unless a
different device API than vfio-pci is available let's only turn on
support for PCI address assignment. Once a different device API is
introduced, we can enable another address type easily.

Signed-off-by: Erik Skultety 
---
 src/qemu/qemu_domain.h |  1 +
 src/qemu/qemu_domain_address.c | 16 
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 524a672..341264b 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -34,6 +34,7 @@
 # include "qemu_agent.h"
 # include "qemu_conf.h"
 # include "qemu_capabilities.h"
+# include "virmdev.h"
 # include "virchrdev.h"
 # include "virobject.h"
 # include "logging/log_manager.h"
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 5b75044..cacd131 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -618,9 +618,11 @@ 
qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
 virPCIDeviceAddressPtr hostAddr = >source.subsys.u.pci.addr;
 
 if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
-hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI) 
{
+(hostdev->source.subsys.type !=
+ VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
+ hostdev->source.subsys.type !=
+ VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV))
 return 0;
-}
 
 if (pciFlags == pcieFlags) {
 /* This arch/qemu only supports legacy PCI, so there
@@ -642,6 +644,9 @@ 
qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
 return pcieFlags;
 }
 
+if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV)
+return pcieFlags;
+
 if (!(pciDev = virPCIDeviceNew(hostAddr->domain,
hostAddr->bus,
hostAddr->slot,
@@ -1725,12 +1730,15 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def,
 
 /* Host PCI devices */
 for (i = 0; i < def->nhostdevs; i++) {
+virDomainHostdevSubsysPtr subsys = >hostdevs[i]->source.subsys;
 if (!virDeviceInfoPCIAddressWanted(def->hostdevs[i]->info))
 continue;
 if (def->hostdevs[i]->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
 continue;
-if (def->hostdevs[i]->source.subsys.type != 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
-def->hostdevs[i]->source.subsys.type != 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST)
+if (subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
+subsys->type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST &&
+!(subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
+  subsys->u.mdev.model == VIR_MDEV_MODEL_TYPE_VFIO_PCI))
 continue;
 
 if (qemuDomainPCIAddressReserveNextAddr(addrs,
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 08/18] security: selinux: Enable labeling of vfio mediated devices

2017-02-15 Thread Erik Skultety
Label the VFIO IOMMU devices under /dev/vfio/ referenced by the symlinks
in the sysfs (e.g. /sys/class/mdev_bus//iommu_group) which what
qemu actually gets formatted on the command line.

Signed-off-by: Erik Skultety 
---
 src/security/security_selinux.c | 56 +++--
 1 file changed, 54 insertions(+), 2 deletions(-)

diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index e152c72..60bdb1c 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -36,6 +36,7 @@
 #include "virerror.h"
 #include "viralloc.h"
 #include "virlog.h"
+#include "virmdev.h"
 #include "virpci.h"
 #include "virusb.h"
 #include "virscsi.h"
@@ -1686,6 +1687,13 @@ virSecuritySELinuxSetHostLabel(virSCSIVHostDevicePtr dev 
ATTRIBUTE_UNUSED,
 }
 
 static int
+virSecuritySELinuxSetMediatedDevLabel(virMediatedDevicePtr dev 
ATTRIBUTE_UNUSED,
+  const char *file, void *opaque)
+{
+return virSecuritySELinuxSetHostdevLabelHelper(file, opaque);
+}
+
+static int
 virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
 virDomainDefPtr def,
 virDomainHostdevDefPtr dev,
@@ -1696,7 +1704,9 @@ 
virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 virSecuritySELinuxCallbackData data = {.mgr = mgr, .def = def};
+virMediatedDevicePtr mdev = NULL;
 
 int ret = -1;
 
@@ -1782,13 +1792,26 @@ 
virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManagerPtr mgr,
 break;
 }
 
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+char *vfio_dev = NULL;
+if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr)))
+goto done;
+
+if (!(vfio_dev = virMediatedDeviceGetIOMMUGroupDev(mdev)))
+goto done;
+
+ret = virSecuritySELinuxSetMediatedDevLabel(mdev, vfio_dev, );
+VIR_FREE(vfio_dev);
+break;
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 ret = 0;
 break;
 }
 
  done:
+virMediatedDeviceFree(mdev);
 return ret;
 }
 
@@ -1918,6 +1941,16 @@ virSecuritySELinuxRestoreHostLabel(virSCSIVHostDevicePtr 
dev ATTRIBUTE_UNUSED,
 }
 
 static int
+virSecuritySELinuxRestoreMediatedDevLabel(virMediatedDevicePtr dev 
ATTRIBUTE_UNUSED,
+   const char *file,
+   void *opaque)
+{
+virSecurityManagerPtr mgr = opaque;
+
+return virSecuritySELinuxRestoreFileLabel(mgr, file);
+}
+
+static int
 virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
 virDomainHostdevDefPtr dev,
 const char *vroot)
@@ -1927,6 +1960,7 @@ 
virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 int ret = -1;
 
 /* Like virSecuritySELinuxRestoreImageLabelInt() for a networked
@@ -2010,7 +2044,25 @@ 
virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManagerPtr mgr,
 break;
 }
 
-case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
+char *vfiodev = NULL;
+virMediatedDevicePtr mdev = virMediatedDeviceNew(mdevsrc->uuidstr);
+
+if (!mdev)
+goto done;
+
+if (!(vfiodev = virMediatedDeviceGetIOMMUGroupDev(mdev))) {
+virMediatedDeviceFree(mdev);
+goto done;
+}
+
+ret = virSecuritySELinuxRestoreMediatedDevLabel(mdev, vfiodev, mgr);
+
+VIR_FREE(vfiodev);
+virMediatedDeviceFree(mdev);
+break;
+}
+
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 ret = 0;
 break;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 02/18] conf: Introduce new hostdev device type mdev

2017-02-15 Thread Erik Skultety
A mediated device will be identified by a UUID of the user pre-created
mediated device. The data necessary to identify a mediated device can
be easily extended in the future, e.g. when auto-creation of mediated
devices should be enabled.

Signed-off-by: Erik Skultety 
---
 src/conf/domain_conf.c  | 36 +++-
 src/conf/domain_conf.h  |  9 +
 src/qemu/qemu_cgroup.c  |  5 +
 src/qemu/qemu_domain.c  |  1 +
 src/qemu/qemu_hotplug.c |  2 ++
 src/security/security_apparmor.c|  3 +++
 src/security/security_dac.c |  2 ++
 src/security/security_selinux.c |  2 ++
 tests/domaincapsschemadata/full.xml |  1 +
 9 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1bc72a4..4911b0b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -56,6 +56,7 @@
 #include "virstring.h"
 #include "virnetdev.h"
 #include "virhostdev.h"
+#include "virmdev.h"
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
@@ -649,7 +650,8 @@ VIR_ENUM_IMPL(virDomainHostdevSubsys, 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST,
   "usb",
   "pci",
   "scsi",
-  "scsi_host")
+  "scsi_host",
+  "mdev")
 
 VIR_ENUM_IMPL(virDomainHostdevSubsysPCIBackend,
   VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_LAST,
@@ -668,6 +670,11 @@ VIR_ENUM_IMPL(virDomainHostdevSubsysSCSIHostProtocol,
   "none",
   "vhost")
 
+VIR_ENUM_IMPL(virMediatedDeviceModel,
+  VIR_MDEV_MODEL_TYPE_LAST,
+  "default",
+  "vfio-pci")
+
 VIR_ENUM_IMPL(virDomainHostdevCaps, VIR_DOMAIN_HOSTDEV_CAPS_TYPE_LAST,
   "storage",
   "misc",
@@ -6348,10 +6355,12 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 char *sgio = NULL;
 char *rawio = NULL;
 char *backendStr = NULL;
+char *model = NULL;
 int backend;
 int ret = -1;
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 
 /* @managed can be read from the xml document - it is always an
  * attribute of the toplevel element, no matter what type of
@@ -6431,6 +6440,21 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 }
 }
 
+if (model) {
+if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV) {
+virReportError(VIR_ERR_XML_ERROR, "%s",
+   _("model is only supported with mediated devices"));
+goto error;
+}
+
+if ((mdevsrc->model = virMediatedDeviceModelTypeFromString(model)) <= 
0) {
+virReportError(VIR_ERR_XML_ERROR,
+   _("unknown hostdev model '%s'"),
+   model);
+goto error;
+}
+}
+
 switch (def->source.subsys.type) {
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
 if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, def, flags) < 0)
@@ -6463,6 +6487,8 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 if (virDomainHostdevSubsysSCSIVHostDefParseXML(sourcenode, def) < 0)
 goto error;
 break;
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+break;
 
 default:
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -13291,6 +13317,7 @@ virDomainHostdevDefParseXML(virDomainXMLOptionPtr 
xmlopt,
 }
 break;
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 break;
 }
@@ -14182,6 +14209,7 @@ virDomainHostdevMatchSubsys(virDomainHostdevDefPtr a,
 return 1;
 else
 return 0;
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 return 0;
 }
@@ -23105,6 +23133,7 @@ virDomainHostdevDefFormat(virBufferPtr buf,
 {
 const char *mode = virDomainHostdevModeTypeToString(def->mode);
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 const char *type;
 
 if (!mode) {
@@ -23154,6 +23183,11 @@ virDomainHostdevDefFormat(virBufferPtr buf,
 virBufferAsprintf(buf, " rawio='%s'",
   virTristateBoolTypeToString(scsisrc->rawio));
 }
+
+if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
+mdevsrc->model)
+virBufferAsprintf(buf, " model='%s'",
+  
virMediatedDeviceModelTypeToString(mdevsrc->model));
 }
 virBufferAddLit(buf, ">\n");
 virBufferAdjustIndent(buf, 2);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 

[libvirt] [RFC PATCH v2 12/18] hostdev: Introduce a reattach method for mediated devices

2017-02-15 Thread Erik Skultety
The name "reattach" does not really reflect the truth behind mediated
devices, since these are purely software devices that do not need to be
plugged back into the host in any way, however this patch pushes for
naming consistency for methods where the logic behind the underlying
operation stays the same except that in case of mdevs the operation
itself is effectively a NO-OP.

Signed-off-by: Erik Skultety 
---
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_hostdev.c  | 15 ++
 src/qemu/qemu_hostdev.h  |  4 
 src/util/virhostdev.c| 53 
 src/util/virhostdev.h|  7 +++
 5 files changed, 80 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 97f81ee..52aa7eb 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1715,6 +1715,7 @@ virHostdevPrepareSCSIDevices;
 virHostdevPrepareSCSIVHostDevices;
 virHostdevPrepareUSBDevices;
 virHostdevReAttachDomainDevices;
+virHostdevReAttachMediatedDevices;
 virHostdevReAttachPCIDevices;
 virHostdevReAttachSCSIDevices;
 virHostdevReAttachSCSIVHostDevices;
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 45b731c..6a7232f 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -419,6 +419,18 @@ qemuHostdevReAttachSCSIVHostDevices(virQEMUDriverPtr 
driver,
 }
 
 void
+qemuHostdevReAttachMediatedDevices(virQEMUDriverPtr driver,
+   const char *name,
+   virDomainHostdevDefPtr *hostdevs,
+   int nhostdevs)
+{
+virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
+
+virHostdevReAttachMediatedDevices(hostdev_mgr, QEMU_DRIVER_NAME,
+  name, hostdevs, nhostdevs);
+}
+
+void
 qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver,
  virDomainDefPtr def)
 {
@@ -436,4 +448,7 @@ qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver,
 
 qemuHostdevReAttachSCSIVHostDevices(driver, def->name, def->hostdevs,
 def->nhostdevs);
+
+qemuHostdevReAttachMediatedDevices(driver, def->name, def->hostdevs,
+   def->nhostdevs);
 }
diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h
index 9399241..0096497 100644
--- a/src/qemu/qemu_hostdev.h
+++ b/src/qemu/qemu_hostdev.h
@@ -84,6 +84,10 @@ void qemuHostdevReAttachSCSIVHostDevices(virQEMUDriverPtr 
driver,
  const char *name,
  virDomainHostdevDefPtr *hostdevs,
  int nhostdevs);
+void qemuHostdevReAttachMediatedDevices(virQEMUDriverPtr driver,
+const char *name,
+virDomainHostdevDefPtr *hostdevs,
+int nhostdevs);
 void qemuHostdevReAttachDomainDevices(virQEMUDriverPtr driver,
   virDomainDefPtr def);
 
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 681f720..2a43b4d 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1963,6 +1963,59 @@ virHostdevReAttachSCSIVHostDevices(virHostdevManagerPtr 
mgr,
 virObjectUnlock(mgr->activeSCSIVHostHostdevs);
 }
 
+void
+virHostdevReAttachMediatedDevices(virHostdevManagerPtr mgr,
+  const char *drv_name,
+  const char *dom_name,
+  virDomainHostdevDefPtr *hostdevs,
+  int nhostdevs)
+{
+const char *used_by_drvname = NULL;
+const char *used_by_domname = NULL;
+virDomainHostdevDefPtr hostdev = NULL;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = NULL;
+size_t i;
+
+if (nhostdevs == 0)
+return;
+
+virObjectLock(mgr->activeMediatedHostdevs);
+for (i = 0; i < nhostdevs; i++) {
+virMediatedDevicePtr mdev, tmp;
+
+hostdev = hostdevs[i];
+mdevsrc = >source.subsys.u.mdev;
+
+if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
+hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV)
+continue;
+
+if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr))) {
+VIR_WARN("Failed to reattach mediated device %s attached to "
+ "domain %s", mdevsrc->uuidstr, dom_name);
+continue;
+}
+
+/* Remove from the list only mdevs assigned to @drv_name/@dom_name */
+
+tmp = virMediatedDeviceListFind(mgr->activeMediatedHostdevs, mdev);
+virMediatedDeviceFree(mdev);
+
+/* skip inactive devices */
+if (!tmp)
+continue;
+
+virMediatedDeviceGetUsedBy(tmp, _by_drvname, _by_domname);
+if (STREQ_NULLABLE(drv_name, used_by_drvname) &&
+

[libvirt] [RFC PATCH v2 00/18] Introduce vGPU mdev framework to libvirt

2017-02-15 Thread Erik Skultety
since v1:
- new  attribute model introduced which tells libvirt which device API
should be considered when auto-assigning guest address
- device_api is properly checked, thus taking the 'model' attribute only as a
hint to assign "some" address
- new address type 'mdev' is introduced rather than using plain  element,
since the address element is more conveniently extendable.
- the emulated mtty driver now works as well out of the box, so no HW needed to
review this series --> let's try it :)
- fixed all the nits from v1

Erik Skultety (18):
  util: Introduce new module virmdev
  conf: Introduce new hostdev device type mdev
  conf: Introduce new address type mdev
  conf: Update XML parser, formatter, and RNG schema to support mdev
  conf: Introduce virDomainHostdevDefPostParse
  conf: Add post parse code for mdevs to virDomainHostdevDefPostParse
  security: dac: Enable labeling of vfio mediated devices
  security: selinux: Enable labeling of vfio mediated devices
  conf: Enable cold-plug of a mediated device
  qemu: Assign PCI addresses for mediated devices as well
  hostdev: Maintain a driver list of active mediated devices
  hostdev: Introduce a reattach method for mediated devices
  qemu: cgroup: Adjust cgroups' logic to allow mediated devices
  qemu: namespace: Hook up the discovery of mdevs into the namespace
code
  qemu: Format mdevs on the qemu command line
  test: Add some test cases for our test suite regarding the mdevs
  docs: Document the new hostdev and address type 'mdev'
  news: Update the NEWS.xml about the new mdev feature

 docs/formatdomain.html.in  |  48 ++-
 docs/news.xml  |  11 +
 docs/schemas/domaincommon.rng  |  26 ++
 po/POTFILES.in |   1 +
 src/Makefile.am|   1 +
 src/conf/device_conf.h |   1 +
 src/conf/domain_conf.c | 203 ++--
 src/conf/domain_conf.h |   9 +
 src/libvirt_private.syms   |  20 ++
 src/qemu/qemu_cgroup.c |  34 ++
 src/qemu/qemu_command.c|  49 +++
 src/qemu/qemu_command.h|   5 +
 src/qemu/qemu_domain.c |  12 +
 src/qemu/qemu_domain.h |   1 +
 src/qemu/qemu_domain_address.c |  16 +-
 src/qemu/qemu_hostdev.c|  37 +++
 src/qemu/qemu_hostdev.h|   8 +
 src/qemu/qemu_hotplug.c|   2 +
 src/security/security_apparmor.c   |   3 +
 src/security/security_dac.c|  55 
 src/security/security_selinux.c|  54 
 src/util/virhostdev.c  | 229 -
 src/util/virhostdev.h  |  16 +
 src/util/virmdev.c | 358 +
 src/util/virmdev.h |  93 ++
 tests/domaincapsschemadata/full.xml|   1 +
 .../qemuxml2argv-hostdev-mdev-unmanaged.args   |  25 ++
 .../qemuxml2argv-hostdev-mdev-unmanaged.xml|  37 +++
 tests/qemuxml2argvtest.c   |   6 +
 .../qemuxml2xmlout-hostdev-mdev-unmanaged.xml  |  40 +++
 tests/qemuxml2xmltest.c|   1 +
 31 files changed, 1362 insertions(+), 40 deletions(-)
 create mode 100644 src/util/virmdev.c
 create mode 100644 src/util/virmdev.h
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.args
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-hostdev-mdev-unmanaged.xml
 create mode 100644 
tests/qemuxml2xmloutdata/qemuxml2xmlout-hostdev-mdev-unmanaged.xml

-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 15/18] qemu: Format mdevs on the qemu command line

2017-02-15 Thread Erik Skultety
Format the mediated devices on the qemu command line as
-device vfio-pci,sysfsdev='/path/to/device/in/syfs'.

Signed-off-by: Erik Skultety 
---
 src/qemu/qemu_command.c | 49 +
 src/qemu/qemu_command.h |  5 +
 2 files changed, 54 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index c00a47a..9c12c21 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -57,6 +57,7 @@
 #include "virscsi.h"
 #include "virnuma.h"
 #include "virgic.h"
+#include "virmdev.h"
 #if defined(__linux__)
 # include 
 #endif
@@ -5161,6 +5162,35 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager,
 return ret;
 }
 
+char *
+qemuBuildHostdevMediatedDevStr(const virDomainDef *def,
+   virDomainHostdevDefPtr dev,
+   virQEMUCapsPtr qemuCaps)
+{
+virBuffer buf = VIR_BUFFER_INITIALIZER;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
+virMediatedDevicePtr mdev = NULL;
+char *ret = NULL;
+
+if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr)))
+goto cleanup;
+
+virBufferAddLit(, "vfio-pci");
+virBufferAsprintf(, ",sysfsdev=%s", virMediatedDeviceGetPath(mdev));
+
+if (qemuBuildDeviceAddressStr(, def, dev->info, qemuCaps) < 0)
+goto cleanup;
+
+if (virBufferCheckError() < 0)
+goto cleanup;
+
+ret = virBufferContentAndReset();
+
+ cleanup:
+virBufferFreeAndReset();
+virMediatedDeviceFree(mdev);
+return ret;
+}
 
 static int
 qemuBuildHostdevCommandLine(virCommandPtr cmd,
@@ -5349,6 +5379,25 @@ qemuBuildHostdevCommandLine(virCommandPtr cmd,
 VIR_FREE(devstr);
 }
 }
+
+/* MDEV */
+if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+subsys->type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV) {
+
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("VFIO PCI device assignment is not "
+ "supported by this version of qemu"));
+return -1;
+}
+
+virCommandAddArg(cmd, "-device");
+if (!(devstr =
+  qemuBuildHostdevMediatedDevStr(def, hostdev, qemuCaps)))
+return -1;
+virCommandAddArg(cmd, devstr);
+VIR_FREE(devstr);
+}
 }
 
 return 0;
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 69fe846..b263b87 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -171,6 +171,11 @@ qemuBuildSCSIVHostHostdevDevStr(const virDomainDef *def,
 virQEMUCapsPtr qemuCaps,
 char *vhostfdName);
 
+char *
+qemuBuildHostdevMediatedDevStr(const virDomainDef *def,
+   virDomainHostdevDefPtr dev,
+   virQEMUCapsPtr qemuCaps);
+
 char *qemuBuildRedirdevDevStr(const virDomainDef *def,
   virDomainRedirdevDefPtr dev,
   virQEMUCapsPtr qemuCaps);
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 14/18] qemu: namespace: Hook up the discovery of mdevs into the namespace code

2017-02-15 Thread Erik Skultety
Again, as for all the other hostdev device types, make sure that the
/dev/vfio/ device will be added to the qemu namespace.

Signed-off-by: Erik Skultety 
---
 src/qemu/qemu_domain.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c4d7a47..eb86385 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6852,10 +6852,12 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 virPCIDevicePtr pci = NULL;
 virUSBDevicePtr usb = NULL;
 virSCSIDevicePtr scsi = NULL;
 virSCSIVHostDevicePtr host = NULL;
+virMediatedDevicePtr mdev = NULL;
 char *tmpPath = NULL;
 bool freeTmpPath = false;
 
@@ -6930,6 +6932,14 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev,
 }
 
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr)))
+goto cleanup;
+
+if (!(tmpPath = virMediatedDeviceGetIOMMUGroupDev(mdev)))
+goto cleanup;
+
+freeTmpPath = true;
+break;
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 break;
 }
@@ -6950,6 +6960,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev,
 virUSBDeviceFree(usb);
 virSCSIDeviceFree(scsi);
 virSCSIVHostDeviceFree(host);
+virMediatedDeviceFree(mdev);
 if (freeTmpPath)
 VIR_FREE(tmpPath);
 return ret;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 03/18] conf: Introduce new address type mdev

2017-02-15 Thread Erik Skultety
Since the address element is much easier extendible by attributes adding
more and more elements, starting with , to the  element
once we find out we need more data to identify a mediated device. By
introducing a new address type rather than using plain elements, we also
remain consistent with all other devices that can make use of the
address element.

Signed-off-by: Erik Skultety 
---
 src/conf/device_conf.h |  1 +
 src/conf/domain_conf.c | 11 +--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index f435fb5..8b67208 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -47,6 +47,7 @@ typedef enum {
 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO,
 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA,
 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM,
+VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV,
 
 VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST
 } virDomainDeviceAddressType;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 4911b0b..053f3cb 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -259,7 +259,8 @@ VIR_ENUM_IMPL(virDomainDeviceAddress, 
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST,
   "ccw",
   "virtio-mmio",
   "isa",
-  "dimm")
+  "dimm",
+  "mdev")
 
 VIR_ENUM_IMPL(virDomainDiskDevice, VIR_DOMAIN_DISK_DEVICE_LAST,
   "disk",
@@ -3289,6 +3290,7 @@ int virDomainDeviceAddressIsValid(virDomainDeviceInfoPtr 
info,
 return virDomainDeviceCCWAddressIsValid(>addr.ccw);
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV:
 return 1;
 }
 
@@ -3381,6 +3383,7 @@ virDomainDeviceInfoAddressIsEqual(const 
virDomainDeviceInfo *a,
 /* address types below don't have any specific data */
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV:
 break;
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
@@ -5129,7 +5132,8 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
 }
 
 if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE ||
-info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390)
+info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390 ||
+info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV)
 return 0;
 
 /* We'll be in domain/devices/[device type]/ so 3 level indent */
@@ -5212,6 +5216,7 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
 break;
 
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
 break;
@@ -5773,6 +5778,7 @@ virDomainDeviceInfoParseXML(xmlNodePtr node,
 goto cleanup;
 break;
 
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
 break;
@@ -18540,6 +18546,7 @@ 
virDomainDeviceInfoCheckABIStability(virDomainDeviceInfoPtr src,
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO:
+case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_MDEV:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE:
 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST:
 break;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 05/18] conf: Introduce virDomainHostdevDefPostParse

2017-02-15 Thread Erik Skultety
Just to make the code a bit cleaner, move hostdev specific post parse
code to its own function just in case it grows in the future.

Signed-off-by: Erik Skultety 
---
 src/conf/domain_conf.c | 76 +++---
 1 file changed, 48 insertions(+), 28 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 870aec6..151a308 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4207,6 +4207,51 @@ virDomainHostdevAssignAddress(virDomainXMLOptionPtr 
xmlopt,
 
 
 static int
+virDomainHostdevDefPostParse(virDomainHostdevDefPtr dev,
+ const virDomainDef *def,
+ virDomainXMLOptionPtr xmlopt)
+{
+if (dev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
+return 0;
+
+switch (dev->source.subsys.type) {
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
+if (dev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+virDomainHostdevAssignAddress(xmlopt, def, dev) < 0) {
+virReportError(VIR_ERR_XML_ERROR, "%s",
+   _("Cannot assign SCSI host device address"));
+return -1;
+} else {
+/* Ensure provided address doesn't conflict with existing
+ * scsi disk drive address
+ */
+virDomainDeviceDriveAddressPtr addr = >info->addr.drive;
+if (virDomainDriveAddressIsUsedByDisk(def,
+  VIR_DOMAIN_DISK_BUS_SCSI,
+  addr)) {
+virReportError(VIR_ERR_XML_ERROR,
+   _("SCSI host address controller='%u' "
+ "bus='%u' target='%u' unit='%u' in "
+ "use by a SCSI disk"),
+   addr->controller, addr->bus,
+   addr->target, addr->unit);
+return -1;
+}
+}
+break;
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
+break;
+}
+
+return 0;
+}
+
+
+static int
 virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev,
 const virDomainDef *def,
 virCapsPtr caps ATTRIBUTE_UNUSED,
@@ -4287,34 +4332,9 @@ 
virDomainDeviceDefPostParseInternal(virDomainDeviceDefPtr dev,
 video->vram = VIR_ROUND_UP_POWER_OF_TWO(video->vram);
 }
 
-if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
-virDomainHostdevDefPtr hdev = dev->data.hostdev;
-
-if (virHostdevIsSCSIDevice(hdev)) {
-if (hdev->info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
-virDomainHostdevAssignAddress(xmlopt, def, hdev) < 0) {
-virReportError(VIR_ERR_XML_ERROR, "%s",
-   _("Cannot assign SCSI host device address"));
-return -1;
-} else {
-/* Ensure provided address doesn't conflict with existing
- * scsi disk drive address
- */
-virDomainDeviceDriveAddressPtr addr = >info->addr.drive;
-if (virDomainDriveAddressIsUsedByDisk(def,
-  VIR_DOMAIN_DISK_BUS_SCSI,
-  addr)) {
-virReportError(VIR_ERR_XML_ERROR,
-   _("SCSI host address controller='%u' "
- "bus='%u' target='%u' unit='%u' in "
- "use by a SCSI disk"),
-   addr->controller, addr->bus,
-   addr->target, addr->unit);
-return -1;
-}
-}
-}
-}
+if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV &&
+virDomainHostdevDefPostParse(dev->data.hostdev, def, xmlopt) < 0)
+return -1;
 
 if (dev->type == VIR_DOMAIN_DEVICE_CONTROLLER) {
 virDomainControllerDefPtr cdev = dev->data.controller;
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 13/18] qemu: cgroup: Adjust cgroups' logic to allow mediated devices

2017-02-15 Thread Erik Skultety
As goes for all the other hostdev device types, grant the qemu process
access to /dev/vfio/.

Signed-off-by: Erik Skultety 
---
 src/qemu/qemu_cgroup.c | 29 +
 1 file changed, 29 insertions(+)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 0902624..bcd10db 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -318,6 +318,23 @@ qemuSetupHostSCSIVHostDeviceCgroup(virSCSIVHostDevicePtr 
dev ATTRIBUTE_UNUSED,
 return ret;
 }
 
+static int
+qemuSetupHostMediatedDeviceCgroup(virMediatedDevicePtr dev ATTRIBUTE_UNUSED,
+  const char *path,
+  void *opaque)
+{
+virDomainObjPtr vm = opaque;
+qemuDomainObjPrivatePtr priv = vm->privateData;
+int ret = -1;
+
+VIR_DEBUG("Process path '%s' for mediated device", path);
+ret = virCgroupAllowDevicePath(priv->cgroup, path,
+   VIR_CGROUP_DEVICE_RW, false);
+virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path, "rw", ret == 0);
+
+return ret;
+}
+
 int
 qemuSetupHostdevCgroup(virDomainObjPtr vm,
virDomainHostdevDefPtr dev)
@@ -328,10 +345,12 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
 virDomainHostdevSubsysPCIPtr pcisrc = >source.subsys.u.pci;
 virDomainHostdevSubsysSCSIPtr scsisrc = >source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr hostsrc = 
>source.subsys.u.scsi_host;
+virDomainHostdevSubsysMediatedDevPtr mdevsrc = >source.subsys.u.mdev;
 virPCIDevicePtr pci = NULL;
 virUSBDevicePtr usb = NULL;
 virSCSIDevicePtr scsi = NULL;
 virSCSIVHostDevicePtr host = NULL;
+virMediatedDevicePtr mdev = NULL;
 char *path = NULL;
 
 /* currently this only does something for PCI devices using vfio
@@ -434,6 +453,15 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
 }
 
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+if (!(mdev = virMediatedDeviceNew(mdevsrc->uuidstr)))
+goto cleanup;
+
+if (!(path = virMediatedDeviceGetIOMMUGroupDev(mdev)))
+goto cleanup;
+
+if (qemuSetupHostMediatedDeviceCgroup(mdev, path, vm) < 0)
+goto cleanup;
+
 break;
 
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
@@ -447,6 +475,7 @@ qemuSetupHostdevCgroup(virDomainObjPtr vm,
 virUSBDeviceFree(usb);
 virSCSIDeviceFree(scsi);
 virSCSIVHostDeviceFree(host);
+virMediatedDeviceFree(mdev);
 VIR_FREE(path);
 return ret;
 }
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 09/18] conf: Enable cold-plug of a mediated device

2017-02-15 Thread Erik Skultety
This merely introduces virDomainHostdevMatchSubsysMediatedDev method that
is supposed to check whether device being cold-plugged does not already
exist in the domain configuration.

Signed-off-by: Erik Skultety 
---
 src/conf/domain_conf.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 69874f0..0fcf9f8 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -14267,6 +14267,19 @@ 
virDomainHostdevMatchSubsysSCSIiSCSI(virDomainHostdevDefPtr first,
 }
 
 static int
+virDomainHostdevMatchSubsysMediatedDev(virDomainHostdevDefPtr a,
+   virDomainHostdevDefPtr b)
+{
+virDomainHostdevSubsysMediatedDevPtr src_a = >source.subsys.u.mdev;
+virDomainHostdevSubsysMediatedDevPtr src_b = >source.subsys.u.mdev;
+
+if (STREQ(src_a->uuidstr, src_b->uuidstr))
+return 1;
+
+return 0;
+}
+
+static int
 virDomainHostdevMatchSubsys(virDomainHostdevDefPtr a,
 virDomainHostdevDefPtr b)
 {
@@ -14297,6 +14310,7 @@ virDomainHostdevMatchSubsys(virDomainHostdevDefPtr a,
 else
 return 0;
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
+return virDomainHostdevMatchSubsysMediatedDev(a, b);
 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
 return 0;
 }
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 11/18] hostdev: Maintain a driver list of active mediated devices

2017-02-15 Thread Erik Skultety
Keep track of the assigned mediated devices the same way we do it for
the rest of hostdevs.

Signed-off-by: Erik Skultety 
---
 src/libvirt_private.syms |   1 +
 src/qemu/qemu_hostdev.c  |  22 ++
 src/qemu/qemu_hostdev.h  |   4 ++
 src/util/virhostdev.c| 176 ++-
 src/util/virhostdev.h|   9 +++
 5 files changed, 211 insertions(+), 1 deletion(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 48c86a2..97f81ee 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1709,6 +1709,7 @@ virHostdevPCINodeDeviceDetach;
 virHostdevPCINodeDeviceReAttach;
 virHostdevPCINodeDeviceReset;
 virHostdevPrepareDomainDevices;
+virHostdevPrepareMediatedDevices;
 virHostdevPreparePCIDevices;
 virHostdevPrepareSCSIDevices;
 virHostdevPrepareSCSIVHostDevices;
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 7cd49e4..45b731c 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -305,6 +305,24 @@ qemuHostdevPrepareSCSIVHostDevices(virQEMUDriverPtr driver,
 }
 
 int
+qemuHostdevPrepareMediatedDevices(virQEMUDriverPtr driver,
+  const char *name,
+  virDomainHostdevDefPtr *hostdevs,
+  int nhostdevs)
+{
+virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
+
+if (!qemuHostdevHostSupportsPassthroughVFIO()) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("host doesn't support VFIO PCI interface"));
+return -1;
+}
+
+return virHostdevPrepareMediatedDevices(hostdev_mgr, QEMU_DRIVER_NAME,
+name, hostdevs, nhostdevs);
+}
+
+int
 qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driver,
 virDomainDefPtr def,
 virQEMUCapsPtr qemuCaps,
@@ -330,6 +348,10 @@ qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driver,
def->hostdevs, def->nhostdevs) < 0)
 return -1;
 
+if (qemuHostdevPrepareMediatedDevices(driver, def->name,
+  def->hostdevs, def->nhostdevs) < 0)
+return -1;
+
 return 0;
 }
 
diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h
index 74a7d4f..9399241 100644
--- a/src/qemu/qemu_hostdev.h
+++ b/src/qemu/qemu_hostdev.h
@@ -59,6 +59,10 @@ int qemuHostdevPrepareSCSIVHostDevices(virQEMUDriverPtr 
driver,
const char *name,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs);
+int qemuHostdevPrepareMediatedDevices(virQEMUDriverPtr driver,
+  const char *name,
+  virDomainHostdevDefPtr *hostdevs,
+  int nhostdevs);
 int qemuHostdevPrepareDomainDevices(virQEMUDriverPtr driver,
 virDomainDefPtr def,
 virQEMUCapsPtr qemuCaps,
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 86ca8e0..681f720 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1,6 +1,6 @@
 /* virhostdev.c: hostdev management
  *
- * Copyright (C) 2006-2007, 2009-2016 Red Hat, Inc.
+ * Copyright (C) 2006-2007, 2009-2017 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  * Copyright (C) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
  *
@@ -147,6 +147,7 @@ virHostdevManagerDispose(void *obj)
 virObjectUnref(hostdevMgr->activeUSBHostdevs);
 virObjectUnref(hostdevMgr->activeSCSIHostdevs);
 virObjectUnref(hostdevMgr->activeSCSIVHostHostdevs);
+virObjectUnref(hostdevMgr->activeMediatedHostdevs);
 VIR_FREE(hostdevMgr->stateDir);
 }
 
@@ -174,6 +175,9 @@ virHostdevManagerNew(void)
 if (!(hostdevMgr->activeSCSIVHostHostdevs = virSCSIVHostDeviceListNew()))
 goto error;
 
+if (!(hostdevMgr->activeMediatedHostdevs = virMediatedDeviceListNew()))
+goto error;
+
 if (privileged) {
 if (VIR_STRDUP(hostdevMgr->stateDir, HOSTDEV_STATE_DIR) < 0)
 goto error;
@@ -1595,6 +1599,176 @@ virHostdevPrepareSCSIVHostDevices(virHostdevManagerPtr 
mgr,
 return -1;
 }
 
+
+static bool
+virHostdevMediatedDeviceIsUsed(virMediatedDevicePtr dev,
+   virMediatedDeviceListPtr list)
+{
+const char *drvname, *domname;
+virMediatedDevicePtr tmp = NULL;
+
+virObjectLock(list);
+
+if ((tmp = virMediatedDeviceListFind(list, dev))) {
+virMediatedDeviceGetUsedBy(tmp, , );
+virReportError(VIR_ERR_OPERATION_INVALID,
+   _("Mediated device %s is in use by "
+ "driver %s, domain %s"),
+   virMediatedDeviceGetPath(tmp),
+   drvname, domname);
+}
+
+   

[libvirt] [RFC PATCH v2 18/18] news: Update the NEWS.xml about the new mdev feature

2017-02-15 Thread Erik Skultety
Signed-off-by: Erik Skultety 
---
 docs/news.xml | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/docs/news.xml b/docs/news.xml
index b756a97..55fa5ed 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -53,6 +53,17 @@
   was virtio-net.
 
   
+  
+
+  qemu: add mediated devices framework support
+
+
+  With the upcomming kernel changes which introduce the new mediated
+  device framework, provide an initial support of this framework into
+  libvirt, mainly introduce new device type as well as an address type
+  in the XML.
+
+  
 
 
   
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC PATCH v2 01/18] util: Introduce new module virmdev

2017-02-15 Thread Erik Skultety
Beside creation, disposal, getter, and setter methods the module exports
methods to work with lists of mediated devices.

Signed-off-by: Erik Skultety 
---
 po/POTFILES.in   |   1 +
 src/Makefile.am  |   1 +
 src/libvirt_private.syms |  18 +++
 src/util/virmdev.c   | 358 +++
 src/util/virmdev.h   |  93 
 5 files changed, 471 insertions(+)
 create mode 100644 src/util/virmdev.c
 create mode 100644 src/util/virmdev.h

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 365ea66..53c674e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -218,6 +218,7 @@ src/util/virlease.c
 src/util/virlockspace.c
 src/util/virlog.c
 src/util/virmacmap.c
+src/util/virmdev.c
 src/util/virnetdev.c
 src/util/virnetdevbandwidth.c
 src/util/virnetdevbridge.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 2f32d41..6510e1d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -186,6 +186,7 @@ UTIL_SOURCES =  
\
util/viruuid.c util/viruuid.h   \
util/virxdrdefs.h   \
util/virxml.c util/virxml.h \
+   util/virmdev.c util/virmdev.h   \
$(NULL)
 
 EXTRA_DIST += $(srcdir)/util/keymaps.csv $(srcdir)/util/virkeycode-mapgen.py
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6bbb36b..48c86a2 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1962,6 +1962,24 @@ virMacMapNew;
 virMacMapRemove;
 virMacMapWriteFile;
 
+# util/virmdev.h
+virMediatedDeviceFree;
+virMediatedDeviceGetDeviceAPI;
+virMediatedDeviceGetIOMMUGroupDev;
+virMediatedDeviceGetPath;
+virMediatedDeviceGetUsedBy;
+virMediatedDeviceListAdd;
+virMediatedDeviceListCount;
+virMediatedDeviceListDel;
+virMediatedDeviceListFind;
+virMediatedDeviceListGet;
+virMediatedDeviceListNew;
+virMediatedDeviceListSteal;
+virMediatedDeviceListStealIndex;
+virMediatedDeviceNew;
+virMediatedDeviceSetUsedBy;
+
+
 
 # util/virnetdev.h
 virNetDevAddMulti;
diff --git a/src/util/virmdev.c b/src/util/virmdev.c
new file mode 100644
index 000..9c80647
--- /dev/null
+++ b/src/util/virmdev.c
@@ -0,0 +1,358 @@
+/*
+ * virmdev.c: helper APIs for managing host MDEV devices
+ *
+ * Copyright (C) 2017-2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "virmdev.h"
+#include "dirname.h"
+#include "virlog.h"
+#include "viralloc.h"
+#include "vircommand.h"
+#include "virerror.h"
+#include "virfile.h"
+#include "virkmod.h"
+#include "virstring.h"
+#include "virutil.h"
+#include "viruuid.h"
+#include "virhostdev.h"
+
+VIR_LOG_INIT("util.mdev");
+
+struct _virMediatedDevice {
+char *path; /* sysfs path */
+
+char *used_by_drvname;
+char *used_by_domname;
+};
+
+struct _virMediatedDeviceList {
+virObjectLockable parent;
+
+size_t count;
+virMediatedDevicePtr *devs;
+};
+
+
+/* For virReportOOMError()  and virReportSystemError() */
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+static virClassPtr virMediatedDeviceListClass;
+
+static void virMediatedDeviceListDispose(void *obj);
+
+static int virMediatedOnceInit(void)
+{
+if (!(virMediatedDeviceListClass = virClassNew(virClassForObjectLockable(),
+   "virMediatedDeviceList",
+   
sizeof(virMediatedDeviceList),
+   
virMediatedDeviceListDispose)))
+return -1;
+
+return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virMediated)
+
+#ifdef __linux__
+# define MDEV_SYSFS_DEVICES "/sys/bus/mdev/devices/"
+
+virMediatedDevicePtr
+virMediatedDeviceNew(const char *uuidstr)
+{
+virMediatedDevicePtr dev = NULL, ret = NULL;
+
+if (VIR_ALLOC(dev) < 0)
+return NULL;
+
+if (virAsprintf(>path, MDEV_SYSFS_DEVICES "%s", uuidstr) < 0)
+   goto cleanup;
+
+ret = dev;
+dev = NULL;
+
+ cleanup:
+virMediatedDeviceFree(dev);
+return ret;
+}
+
+#else
+
+virMediatedDevicePtr
+virMediatedDeviceNew(virPCIDeviceAddressPtr pciaddr 

[libvirt] [RFC PATCH v2 17/18] docs: Document the new hostdev and address type 'mdev'

2017-02-15 Thread Erik Skultety
Signed-off-by: Erik Skultety 
---
 docs/formatdomain.html.in | 48 +++
 1 file changed, 44 insertions(+), 4 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 0a115f5..8f21436 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3277,8 +3277,20 @@
 attributes: iobase and irq.
 Since 1.2.1
   
+  mdev
+  Mediated devices' addresses have so far only one mandatory attribute
+uuid (since 3.1.0) which
+uniquely identifies a mediated device under the syfs file system.
+  
 
 
+
+Note: Due to nature of mediated devices, being only software devices
+defining an allocation of resources on the physical parent device, the
+address type mdev is supposed to be used to identify a
+device on the host only, rather than identifying it in the guest.
+
+
 Controllers
 
 
@@ -3774,6 +3786,19 @@
   /devices
   ...
 
+or:
+
+
+  ...
+  devices
+hostdev mode='subsystem' type='mdev' model='vfio-pci'
+source
+  address type='mdev' uuid='c2177883-f1bb-47f0-914d-32a22e3a8804'
+/source
+/hostdev
+  /devices
+  ...
+
 
   hostdev
   The hostdev element is the main container for describing
@@ -3818,12 +3843,23 @@
 type passes all LUNs presented by a single HBA to
 the guest.
   
+  mdev
+  For mediated devices (Since 3.1.0)
+  the model attribute specifies the device API which
+  determines how the host's vfio driver will expose the device to the
+  guest. Currently, only vfio-pci model is supported.
+  The model also has implications on the guest's address type, i.e.
+  for vfio-pci device API any address type other than PCI
+  will result in an error.
+  
 
 
-  Note: The managed attribute is only used with PCI 
devices
-  and is ignored by all the other device types, thus setting
-  managed explicitly with other than PCI device has the 
same
-  effect as omitting it.
+  Note: The managed attribute is only used with PCI and is
+  ignored by all the other device types, thus setting
+  managed explicitly with other than a PCI device has the
+  same effect as omitting it. Similarly, model attribute 
is
+  only supported by mediated devices and ignored by all other device
+  types.
 
   
   source
@@ -3888,6 +3924,10 @@
 is the vhost_scsi wwpn (16 hexadecimal digits with a prefix of
 "naa.") established in the host configfs.
   
+  mdev
+  Mediated devices (Since 3.1.0) are
+  described by the address element.
+  
 
   
   vendor, product
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [v6 09/10] Resctrl: concurrence support

2017-02-15 Thread Marcelo Tosatti
On Wed, Feb 15, 2017 at 01:41:52PM +0800, Eli Qiao wrote:
> The internal struct list domainall is a list which are resctral domain
> status shared by all VMs, especiall the default domain, each VM should
> access it concomitantly. Ues a mutex to control it.
> 
> Each bank's cache_left field is also a global shared resource we need
> to be care, add a mutex for each bank.
> 
> We need also to add lock to access /sys/fs/resctrl, use flock.
> 
> Signed-off-by: Eli Qiao 

Hi Eli Qiao,

I don't think this is correct: the lock must be held across entire
operations, for example:

+4) Locking between applications
+
+Certain operations on the resctrl filesystem, composed of
+read / writes to multiple files, must be atomic.
+
+As an example, the allocation of an exclusive reservation
+of L3 cache involves:
+
+1. read list of cbmmasks for each directory
+2. find a contiguous set of bits in the global CBM bitmask
+   that is clear in any of the directory cbmmasks
+3. create a new directory
+4. set the bits found in step 2 to the new directory "schemata"
+   file

The lock must be held across steps 1 through 4, and not taken
and released in between these steps (which is what this patchset
has now).

Two libvirt examples:

VM INITIALIZATION:

1) Lock filesystem lock (LOCK_EX).
2) Scan directories. 
3) Find free space.
4) Create new directory.
5) Write schemata files in new directory.
6) Write tasks file with vcpus pid.
7) Write default schemata to exclude space used by new
directory.
8) Unlock filesystem lock.

GET FREE SPACE API CALL:

1) Lock filesystem lock (LOCK_SH).
2) Scan directories. 
3) Unlock filesystem lock.
4) return data to libvirt user.

Can you please fix this? 

Other than this, and testing of v6 relative to usage of other apps
(which i plan to do tomorrow), patchset looks good to me.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH] libxl: fix potential double free in libxlDriverGetDom0MaxmemConf

2017-02-15 Thread Jim Fehlig
Commit 4ab0c959 fixed a memory leak in libxlDriverGetDom0MaxmemConf
but introduced a potential double free of mem_tokens

*** Error in `/usr/sbin/libvirtd': double free or corruption (out):
0x7fffc808cfd0 ***

Avoid double free by setting mem_tokens to NULL after calling
virStringListFree.

Signed-off-by: Jim Fehlig 
---
 src/libxl/libxl_conf.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index f5b788b50..4bab651b3 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1623,6 +1623,7 @@ libxlDriverGetDom0MaxmemConf(libxlDriverConfigPtr cfg,
 }
 }
 virStringListFree(mem_tokens);
+mem_tokens = NULL;
 }
 
  physmem:
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Introduce vGPU mdev framework to libvirt

2017-02-15 Thread Alex Williamson
On Wed, 15 Feb 2017 14:43:22 +0100
Erik Skultety  wrote:

> On Wed, Feb 15, 2017 at 09:50:03AM +0100, Martin Polednik wrote:
> > On 14/02/17 09:58 -0700, Alex Williamson wrote:  
> > > On Tue, 14 Feb 2017 16:50:14 +0100
> > > Martin Polednik  wrote:
> > >   
> > > > On 07/02/17 12:29 -0700, Alex Williamson wrote:  
> > > > >On Tue, 7 Feb 2017 17:26:51 +0100
> > > > >Erik Skultety  wrote:
> > > > >  
> > > > >> On Mon, Feb 06, 2017 at 09:33:14AM -0700, Alex Williamson wrote:  
> > > > >> > On Mon,  6 Feb 2017 13:19:42 +0100
> > > > >> > Erik Skultety  wrote:
> > > > >> >  
> > > > >> > > Finally. It's here. This is the initial suggestion on how 
> > > > >> > > libvirt might
> > > > >> > > interract with the mdev framework, currently only focussing on 
> > > > >> > > the non-managed
> > > > >> > > devices, i.e. those pre-created by the user, since that will be 
> > > > >> > > revisited once
> > > > >> > > we all settled on how the XML should look like, given we might 
> > > > >> > > not want to use
> > > > >> > > the sysfs path directly as an attribute in the domain XML. My 
> > > > >> > > proposal on the
> > > > >> > > XML is the following:
> > > > >> > >
> > > > >> > > 
> > > > >> > > 
> > > > >> > > 
> > > > >> > >  > > > >> > > function='0x00'>
> > > > >> > > vGPU_UUID
> > > > >> > > 
> > > > >> > > 
> > > > >> > > 
> > > > >> > >
> > > > >> > > So the mediated device is identified by the physical parent 
> > > > >> > > device visible on
> > > > >> > > the host and a UUID which allows us to construct the sysfs path 
> > > > >> > > by ourselves,
> > > > >> > > which we then put on the QEMU's command line.  
> > > > >> >
> > > > >> > Based on your test code, I think you're creating something like 
> > > > >> > this:
> > > > >> >
> > > > >> > -device 
> > > > >> > vfio-pci,sysfsdev=/sys/class/mdev_bus/:00:03.0/53764d0e-85a0-42b4-af5c-2046b460b1dc
> > > > >> >
> > > > >> > That would explain the need for the parent device address, but 
> > > > >> > that's
> > > > >> > an entirely self inflicted requirement.  For a managed="no" 
> > > > >> > scenarios,
> > > > >> > we shouldn't need the parent, we can get to the mdev device
> > > > >> > via /sys/bus/mdev/devices/53764d0e-85a0-42b4-af5c-2046b460b1dc.  
> > > > >> > So it  
> > > > >>
> > > > >> True, for managed="no" would this path be a nice optimization.
> > > > >>  
> > > > >> > seems that the UUID should be the only required source element for
> > > > >> > managed="no".
> > > > >> >
> > > > >> > For managed="yes", it seems like the parent device is still an 
> > > > >> > optional  
> > > > >>
> > > > >> The reason I went with the parent address element (and purposely 
> > > > >> neglecting the
> > > > >> sample mtty driver) was that I assumed any modern mdev capable HW 
> > > > >> would be
> > > > >> accessible through the PCI bus on the host. Also I wanted to 
> > > > >> explicitly hint
> > > > >> libvirt as much as possible which parent device a vGPU device 
> > > > >> instance should
> > > > >> be created on in case there are more than one of them, rather then 
> > > > >> scanning
> > > > >> sysfs for a suitable parent which actually supports the given vGPU 
> > > > >> type.
> > > > >>  
> > > > >> > field.  The most important thing that libvirt needs to know when
> > > > >> > creating a mdev device for a VM is the mdev type name.  The parent
> > > > >> > device should be an optional field to help higher level management
> > > > >> > tools deal with placement of the device for locality or load 
> > > > >> > balancing.
> > > > >> > Also, we can't assume that the parent device is a PCI device, the
> > > > >> > sample mtty driver already breaks this assumption.  
> > > > >>
> > > > >> Since we need to assume non-PCI devices and we still need to enable 
> > > > >> management
> > > > >> to hint libvirt about the parent to utilize load balancing and 
> > > > >> stuff, I've come
> > > > >> up with the following adjustments/ideas on how to reflect that in 
> > > > >> the XML:
> > > > >> - still use the address element but use it with the 'type' attribute 
> > > > >> [1] (still
> > > > >>   breaks the sample mtty driver though) while making the element 
> > > > >> truly optional
> > > > >>   if I'm going to be outvoted in favor of scanning the directory for 
> > > > >> a suitable
> > > > >>   parent device on our own, rather than requiring the user to 
> > > > >> provide that
> > > > >>
> > > > >> - providing either an attribute or a standalone element for the 
> > > > >> parent device
> > > > >>   name, like a string version of the PCI address or whatever form 
> > > > >> the parent
> > > > >>   device comes in (doesn't break the mtty driver but I don't quite 
> > > > >> like this)
> > > > >>
> > > > >> - providing a path element/attribute to sysfs pointing to the parent 
> > > > >> device
> > > > >>   which I'm afraid is what Daniel is 

[libvirt] [PATCH v2 25/33] qemu: Make virQEMUCapsInitCPUModel testable

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_capabilities.c | 19 ++-
 src/qemu/qemu_capspriv.h | 10 ++
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index a77e300b7..3163bba8a 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3204,7 +3204,7 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
  *  1 when the caller should fall back to using virCapsPtr->host.cpu,
  * -1 on error.
  */
-static int
+int
 virQEMUCapsInitCPUModel(virQEMUCapsPtr qemuCaps,
 virDomainVirtType type,
 virCPUDefPtr cpu)
@@ -3268,6 +3268,18 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
 }
 
 
+void
+virQEMUCapsSetCPUModelInfo(virQEMUCapsPtr qemuCaps,
+   virDomainVirtType type,
+   qemuMonitorCPUModelInfoPtr modelInfo)
+{
+if (type == VIR_DOMAIN_VIRT_KVM)
+qemuCaps->kvmCPUModelInfo = modelInfo;
+else
+qemuCaps->tcgCPUModelInfo = modelInfo;
+}
+
+
 static int
 virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
 xmlXPathContextPtr ctxt,
@@ -3354,10 +3366,7 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
 }
 }
 
-if (type == VIR_DOMAIN_VIRT_KVM)
-qemuCaps->kvmCPUModelInfo = hostCPU;
-else
-qemuCaps->tcgCPUModelInfo = hostCPU;
+virQEMUCapsSetCPUModelInfo(qemuCaps, type, hostCPU);
 hostCPU = NULL;
 ret = 0;
 
diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h
index 75499d462..d4f13a2d2 100644
--- a/src/qemu/qemu_capspriv.h
+++ b/src/qemu/qemu_capspriv.h
@@ -73,4 +73,14 @@ void
 virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
 virCapsPtr caps,
 virDomainVirtType type);
+
+int
+virQEMUCapsInitCPUModel(virQEMUCapsPtr qemuCaps,
+virDomainVirtType type,
+virCPUDefPtr cpu);
+
+void
+virQEMUCapsSetCPUModelInfo(virQEMUCapsPtr qemuCaps,
+   virDomainVirtType type,
+   qemuMonitorCPUModelInfoPtr modelInfo);
 #endif
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 29/33] cputest: Convert all json data files to query-cpu-model-expansion

2017-02-15 Thread Jiri Denemark
Converted by running the following command, renaming the files as
*.new, and committing only the *.new files.

(cd tests/cputestdata; ./cpu-convert.py *.json)

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- reconverted to contain "vendor" properties

 tests/cputestdata/x86_64-cpuid-A10-5800K.json.new  | 203 +
 .../cputestdata/x86_64-cpuid-Core-i5-2500.json.new | 203 +
 .../x86_64-cpuid-Core-i5-2540M.json.new| 203 +
 .../x86_64-cpuid-Core-i5-4670T.json.new| 203 +
 .../cputestdata/x86_64-cpuid-Core-i5-6600.json.new | 203 +
 .../cputestdata/x86_64-cpuid-Core-i7-2600.json.new | 203 +
 .../x86_64-cpuid-Core-i7-3740QM.json.new   | 203 +
 .../cputestdata/x86_64-cpuid-Core-i7-3770.json.new | 203 +
 .../x86_64-cpuid-Core-i7-4600U.json.new| 203 +
 .../x86_64-cpuid-Core-i7-5600U.json.new| 203 +
 .../cputestdata/x86_64-cpuid-Core2-E6850.json.new  | 203 +
 .../cputestdata/x86_64-cpuid-Opteron-2350.json.new | 203 +
 .../cputestdata/x86_64-cpuid-Opteron-6234.json.new | 203 +
 tests/cputestdata/x86_64-cpuid-Phenom-B95.json.new | 203 +
 .../cputestdata/x86_64-cpuid-Xeon-E3-1245.json.new | 203 +
 .../cputestdata/x86_64-cpuid-Xeon-E5-2630.json.new | 203 +
 .../cputestdata/x86_64-cpuid-Xeon-E5-2650.json.new | 203 +
 .../cputestdata/x86_64-cpuid-Xeon-E7-4820.json.new | 203 +
 tests/cputestdata/x86_64-cpuid-Xeon-W3520.json.new | 203 +
 19 files changed, 3857 insertions(+)
 create mode 100644 tests/cputestdata/x86_64-cpuid-A10-5800K.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i5-2500.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i5-2540M.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i5-4670T.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i5-6600.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-2600.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-3740QM.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-3770.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-4600U.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-5600U.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core2-E6850.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Opteron-2350.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Opteron-6234.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Phenom-B95.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-E3-1245.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-E5-2630.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-E5-2650.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-E7-4820.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-W3520.json.new

diff --git a/tests/cputestdata/x86_64-cpuid-A10-5800K.json.new 
b/tests/cputestdata/x86_64-cpuid-A10-5800K.json.new
new file mode 100644
index 0..132ed249b
--- /dev/null
+++ b/tests/cputestdata/x86_64-cpuid-A10-5800K.json.new
@@ -0,0 +1,203 @@
+{
+  "return": {
+"model": {
+  "name": "base",
+  "props": {
+"pfthreshold": false,
+"pku": false,
+"rtm": false,
+"tsc_adjust": true,
+"tsc-deadline": false,
+"xstore-en": false,
+"tsc-scale": false,
+"sse": true,
+"smap": false,
+"stepping": 1,
+"tce": false,
+"kvm_steal_time": true,
+"smep": false,
+"rdpid": false,
+"xcrypt": false,
+"sse4_2": true,
+"monitor": false,
+"sse4_1": true,
+"kvm-mmu": false,
+"flushbyasid": false,
+"kvm-steal-time": true,
+"lm": true,
+"tsc": true,
+"adx": false,
+"fxsr": true,
+"sha-ni": false,
+"tm": false,
+"pclmuldq": true,
+"xgetbv1": false,
+"xstore": false,
+"vmcb_clean": false,
+"vme": true,
+"vendor": "AuthenticAMD",
+"arat": false,
+"ffxsr": true,
+"de": true,
+"avx512f": false,
+"pse": true,
+"ds-cpl": false,
+"tbm": true,
+"ia64": false,
+"phe-en": false,
+"f16c": true,
+"ds": false,
+"mpx": false,
+"tsc-adjust": true,
+"aes": true,
+"avx2": false,
+"pbe": false,
+"cx16": true,
+"ds_cpl": false,
+"movbe": false,
+"perfctr-nb": false,
+"nrip_save": true,
+"kvm_mmu": false,
+"ospke": false,

[libvirt] [PATCH v2 07/33] qemu: Fix CPU model fallback in domain capabilities

2017-02-15 Thread Jiri Denemark
Our documentation of the domain capabilities XML says that the fallback
attribute of a CPU model is used to indicate whether the CPU model was
detected by libvirt itself (fallback="allow") or by asking the
hypervisor (fallback="forbid"). We need to properly set
fallback="forbid" when CPU model comes from QEMU to match the
documentation.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_capabilities.c| 3 +++
 tests/domaincapsschemadata/qemu_2.8.0.s390x.xml | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 0be2301cb..c511248bd 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3103,6 +3103,9 @@ virQEMUCapsInitCPUModel(virQEMUCapsPtr qemuCaps,
 if (ARCH_IS_S390(qemuCaps->arch))
 ret = virQEMUCapsInitCPUModelS390(qemuCaps, cpu);
 
+if (ret == 0)
+cpu->fallback = VIR_CPU_FALLBACK_FORBID;
+
 return ret;
 }
 
diff --git a/tests/domaincapsschemadata/qemu_2.8.0.s390x.xml 
b/tests/domaincapsschemadata/qemu_2.8.0.s390x.xml
index efe345962..0b8135bc5 100644
--- a/tests/domaincapsschemadata/qemu_2.8.0.s390x.xml
+++ b/tests/domaincapsschemadata/qemu_2.8.0.s390x.xml
@@ -21,7 +21,7 @@
   
 
 
-  zEC12.2-base
+  zEC12.2-base
   
   
   
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 26/33] cputest: Rename x86 data files

2017-02-15 Thread Jiri Denemark
While "x86" is a CPU sub driver name, it is not a recognized name of any
architecture known to libvirt. Let's use "x86_64" prefix which can be
used with virArch APIs.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- fix file names created by cpu-parse.sh

 tests/cputest.c| 204 ++---
 tests/cputestdata/cpu-parse.sh |   2 +-
 ...ack.xml => x86_64-Haswell-noTSX-nofallback.xml} |   0
 ...-Haswell-noTSX.xml => x86_64-Haswell-noTSX.xml} |   0
 .../{x86-Haswell.xml => x86_64-Haswell.xml}|   0
 ...e-1-result.xml => x86_64-baseline-1-result.xml} |   0
 .../{x86-baseline-1.xml => x86_64-baseline-1.xml}  |   0
 ...e-2-result.xml => x86_64-baseline-2-result.xml} |   0
 .../{x86-baseline-2.xml => x86_64-baseline-2.xml}  |   0
 ...expanded.xml => x86_64-baseline-3-expanded.xml} |   0
 ...e-3-result.xml => x86_64-baseline-3-result.xml} |   0
 .../{x86-baseline-3.xml => x86_64-baseline-3.xml}  |   0
 ...expanded.xml => x86_64-baseline-4-expanded.xml} |   0
 ...e-4-result.xml => x86_64-baseline-4-result.xml} |   0
 .../{x86-baseline-4.xml => x86_64-baseline-4.xml}  |   0
 ...expanded.xml => x86_64-baseline-5-expanded.xml} |   0
 ...e-5-result.xml => x86_64-baseline-5-result.xml} |   0
 .../{x86-baseline-5.xml => x86_64-baseline-5.xml}  |   0
 ...atable.xml => x86_64-baseline-6-migratable.xml} |   0
 ...e-6-result.xml => x86_64-baseline-6-result.xml} |   0
 .../{x86-baseline-6.xml => x86_64-baseline-6.xml}  |   0
 ...e-7-result.xml => x86_64-baseline-7-result.xml} |   0
 .../{x86-baseline-7.xml => x86_64-baseline-7.xml}  |   0
 ...e-8-result.xml => x86_64-baseline-8-result.xml} |   0
 .../{x86-baseline-8.xml => x86_64-baseline-8.xml}  |   0
 ...ml => x86_64-baseline-incompatible-vendors.xml} |   0
 ...lt.xml => x86_64-baseline-no-vendor-result.xml} |   0
 ...no-vendor.xml => x86_64-baseline-no-vendor.xml} |   0
 ...xml => x86_64-baseline-some-vendors-result.xml} |   0
 ...endors.xml => x86_64-baseline-some-vendors.xml} |   0
 ...-bogus-feature.xml => x86_64-bogus-feature.xml} |   0
 ...{x86-bogus-model.xml => x86_64-bogus-model.xml} |   0
 ...86-bogus-vendor.xml => x86_64-bogus-vendor.xml} |   0
 ...-guest.xml => x86_64-cpuid-A10-5800K-guest.xml} |   0
 ...0K-host.xml => x86_64-cpuid-A10-5800K-host.xml} |   0
 ...0K-json.xml => x86_64-cpuid-A10-5800K-json.xml} |   0
 ...-A10-5800K.json => x86_64-cpuid-A10-5800K.json} |   0
 ...id-A10-5800K.xml => x86_64-cpuid-A10-5800K.xml} |   0
 ...-guest.xml => x86_64-cpuid-Atom-D510-guest.xml} |   0
 ...10-host.xml => x86_64-cpuid-Atom-D510-host.xml} |   0
 ...id-Atom-D510.xml => x86_64-cpuid-Atom-D510.xml} |   0
 ...-guest.xml => x86_64-cpuid-Atom-N450-guest.xml} |   0
 ...50-host.xml => x86_64-cpuid-Atom-N450-host.xml} |   0
 ...id-Atom-N450.xml => x86_64-cpuid-Atom-N450.xml} |   0
 ...est.xml => x86_64-cpuid-Core-i5-2500-guest.xml} |   0
 ...host.xml => x86_64-cpuid-Core-i5-2500-host.xml} |   0
 ...json.xml => x86_64-cpuid-Core-i5-2500-json.xml} |   0
 ...i5-2500.json => x86_64-cpuid-Core-i5-2500.json} |   0
 ...e-i5-2500.xml => x86_64-cpuid-Core-i5-2500.xml} |   0
 ...st.xml => x86_64-cpuid-Core-i5-2540M-guest.xml} |   0
 ...ost.xml => x86_64-cpuid-Core-i5-2540M-host.xml} |   0
 ...son.xml => x86_64-cpuid-Core-i5-2540M-json.xml} |   0
 ...-2540M.json => x86_64-cpuid-Core-i5-2540M.json} |   0
 ...i5-2540M.xml => x86_64-cpuid-Core-i5-2540M.xml} |   0
 ...st.xml => x86_64-cpuid-Core-i5-4670T-guest.xml} |   0
 ...ost.xml => x86_64-cpuid-Core-i5-4670T-host.xml} |   0
 ...son.xml => x86_64-cpuid-Core-i5-4670T-json.xml} |   0
 ...-4670T.json => x86_64-cpuid-Core-i5-4670T.json} |   0
 ...i5-4670T.xml => x86_64-cpuid-Core-i5-4670T.xml} |   0
 ...est.xml => x86_64-cpuid-Core-i5-6600-guest.xml} |   0
 ...host.xml => x86_64-cpuid-Core-i5-6600-host.xml} |   0
 ...json.xml => x86_64-cpuid-Core-i5-6600-json.xml} |   0
 ...i5-6600.json => x86_64-cpuid-Core-i5-6600.json} |   0
 ...e-i5-6600.xml => x86_64-cpuid-Core-i5-6600.xml} |   0
 ...est.xml => x86_64-cpuid-Core-i7-2600-guest.xml} |   0
 ...host.xml => x86_64-cpuid-Core-i7-2600-host.xml} |   0
 ...json.xml => x86_64-cpuid-Core-i7-2600-json.xml} |   0
 ...i7-2600.json => x86_64-cpuid-Core-i7-2600.json} |   0
 ...e-i7-2600.xml => x86_64-cpuid-Core-i7-2600.xml} |   0
 ...st.xml => x86_64-cpuid-Core-i7-3520M-guest.xml} |   0
 ...ost.xml => x86_64-cpuid-Core-i7-3520M-host.xml} |   0
 ...i7-3520M.xml => x86_64-cpuid-Core-i7-3520M.xml} |   0
 ...t.xml => x86_64-cpuid-Core-i7-3740QM-guest.xml} |   0
 ...st.xml => x86_64-cpuid-Core-i7-3740QM-host.xml} |   0
 ...on.xml => x86_64-cpuid-Core-i7-3740QM-json.xml} |   0
 ...740QM.json => x86_64-cpuid-Core-i7-3740QM.json} |   0
 ...-3740QM.xml => x86_64-cpuid-Core-i7-3740QM.xml} |   0
 ...est.xml => x86_64-cpuid-Core-i7-3770-guest.xml} |   0
 ...host.xml => x86_64-cpuid-Core-i7-3770-host.xml} |   0
 ...json.xml => x86_64-cpuid-Core-i7-3770-json.xml} |   0
 ...i7-3770.json => 

[libvirt] [PATCH v2 18/33] cpu_x86: Introduce virCPUx86DataSetSignature

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/cpu/cpu_x86.c| 11 +++
 src/cpu/cpu_x86.h|  4 
 src/libvirt_private.syms |  1 +
 src/qemu/qemu_capabilities.c |  1 +
 4 files changed, 17 insertions(+)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 029a7d475..e3f860bc6 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -2720,6 +2720,17 @@ virCPUx86DataAddCPUID(virCPUDataPtr cpuData,
 }
 
 
+int
+virCPUx86DataSetSignature(virCPUDataPtr cpuData,
+  unsigned int family,
+  unsigned int model)
+{
+uint32_t signature = x86MakeSignature(family, model);
+
+return x86DataAddSignature(>data.x86, signature);
+}
+
+
 struct cpuArchDriver cpuDriverX86 = {
 .name = "x86",
 .arch = archs,
diff --git a/src/cpu/cpu_x86.h b/src/cpu/cpu_x86.h
index 79e78a007..ffbd064b4 100644
--- a/src/cpu/cpu_x86.h
+++ b/src/cpu/cpu_x86.h
@@ -32,4 +32,8 @@ extern struct cpuArchDriver cpuDriverX86;
 int virCPUx86DataAddCPUID(virCPUDataPtr cpuData,
   const virCPUx86CPUID *cpuid);
 
+int virCPUx86DataSetSignature(virCPUDataPtr cpuData,
+  unsigned int family,
+  unsigned int model);
+
 #endif /* __VIR_CPU_X86_H__ */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 56db100b5..6b2dddc95 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1006,6 +1006,7 @@ virCPUUpdate;
 
 # cpu/cpu_x86.h
 virCPUx86DataAddCPUID;
+virCPUx86DataSetSignature;
 
 
 # datatypes.h
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 6ca6ea702..f115f1e23 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -33,6 +33,7 @@
 #include "virprocess.h"
 #include "nodeinfo.h"
 #include "cpu/cpu.h"
+#include "cpu/cpu_x86.h"
 #include "domain_conf.h"
 #include "vircommand.h"
 #include "virbitmap.h"
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 32/33] cputest: Drop .new suffix from CPU test data files

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 tests/cputest.c | 2 +-
 .../{x86_64-cpuid-A10-5800K.json.new => x86_64-cpuid-A10-5800K.json}| 0
 ...86_64-cpuid-Core-i5-2500.json.new => x86_64-cpuid-Core-i5-2500.json} | 0
 ..._64-cpuid-Core-i5-2540M.json.new => x86_64-cpuid-Core-i5-2540M.json} | 0
 ..._64-cpuid-Core-i5-4670T.json.new => x86_64-cpuid-Core-i5-4670T.json} | 0
 ...86_64-cpuid-Core-i5-6600.json.new => x86_64-cpuid-Core-i5-6600.json} | 0
 ...86_64-cpuid-Core-i7-2600.json.new => x86_64-cpuid-Core-i7-2600.json} | 0
 ...4-cpuid-Core-i7-3740QM.json.new => x86_64-cpuid-Core-i7-3740QM.json} | 0
 ...86_64-cpuid-Core-i7-3770.json.new => x86_64-cpuid-Core-i7-3770.json} | 0
 ..._64-cpuid-Core-i7-4600U.json.new => x86_64-cpuid-Core-i7-4600U.json} | 0
 ..._64-cpuid-Core-i7-5600U.json.new => x86_64-cpuid-Core-i7-5600U.json} | 0
 ...{x86_64-cpuid-Core2-E6850.json.new => x86_64-cpuid-Core2-E6850.json} | 0
 ...86_64-cpuid-Opteron-2350.json.new => x86_64-cpuid-Opteron-2350.json} | 0
 ...86_64-cpuid-Opteron-6234.json.new => x86_64-cpuid-Opteron-6234.json} | 0
 .../{x86_64-cpuid-Phenom-B95.json.new => x86_64-cpuid-Phenom-B95.json}  | 0
 ...86_64-cpuid-Xeon-E3-1245.json.new => x86_64-cpuid-Xeon-E3-1245.json} | 0
 ...86_64-cpuid-Xeon-E5-2630.json.new => x86_64-cpuid-Xeon-E5-2630.json} | 0
 ...86_64-cpuid-Xeon-E5-2650.json.new => x86_64-cpuid-Xeon-E5-2650.json} | 0
 ...86_64-cpuid-Xeon-E7-4820.json.new => x86_64-cpuid-Xeon-E7-4820.json} | 0
 .../{x86_64-cpuid-Xeon-W3520.json.new => x86_64-cpuid-Xeon-W3520.json}  | 0
 20 files changed, 1 insertion(+), 1 deletion(-)
 rename tests/cputestdata/{x86_64-cpuid-A10-5800K.json.new => 
x86_64-cpuid-A10-5800K.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i5-2500.json.new => 
x86_64-cpuid-Core-i5-2500.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i5-2540M.json.new => 
x86_64-cpuid-Core-i5-2540M.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i5-4670T.json.new => 
x86_64-cpuid-Core-i5-4670T.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i5-6600.json.new => 
x86_64-cpuid-Core-i5-6600.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i7-2600.json.new => 
x86_64-cpuid-Core-i7-2600.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i7-3740QM.json.new => 
x86_64-cpuid-Core-i7-3740QM.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i7-3770.json.new => 
x86_64-cpuid-Core-i7-3770.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i7-4600U.json.new => 
x86_64-cpuid-Core-i7-4600U.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i7-5600U.json.new => 
x86_64-cpuid-Core-i7-5600U.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core2-E6850.json.new => 
x86_64-cpuid-Core2-E6850.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Opteron-2350.json.new => 
x86_64-cpuid-Opteron-2350.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Opteron-6234.json.new => 
x86_64-cpuid-Opteron-6234.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Phenom-B95.json.new => 
x86_64-cpuid-Phenom-B95.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Xeon-E3-1245.json.new => 
x86_64-cpuid-Xeon-E3-1245.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Xeon-E5-2630.json.new => 
x86_64-cpuid-Xeon-E5-2630.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Xeon-E5-2650.json.new => 
x86_64-cpuid-Xeon-E5-2650.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Xeon-E7-4820.json.new => 
x86_64-cpuid-Xeon-E7-4820.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Xeon-W3520.json.new => 
x86_64-cpuid-Xeon-W3520.json} (100%)

diff --git a/tests/cputest.c b/tests/cputest.c
index 8c16fb95c..b7dd95d84 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -527,7 +527,7 @@ cpuTestJSONCPUID(const void *arg)
 char *result = NULL;
 int ret = -1;
 
-if (virAsprintf(, "%s/cputestdata/%s-cpuid-%s.json.new",
+if (virAsprintf(, "%s/cputestdata/%s-cpuid-%s.json",
 abs_srcdir, virArchToString(data->arch), data->host) < 0 ||
 virAsprintf(, "cpuid-%s-json", data->host) < 0)
 goto cleanup;
diff --git a/tests/cputestdata/x86_64-cpuid-A10-5800K.json.new 
b/tests/cputestdata/x86_64-cpuid-A10-5800K.json
similarity index 100%
rename from tests/cputestdata/x86_64-cpuid-A10-5800K.json.new
rename to tests/cputestdata/x86_64-cpuid-A10-5800K.json
diff --git a/tests/cputestdata/x86_64-cpuid-Core-i5-2500.json.new 
b/tests/cputestdata/x86_64-cpuid-Core-i5-2500.json
similarity index 100%
rename from tests/cputestdata/x86_64-cpuid-Core-i5-2500.json.new
rename to tests/cputestdata/x86_64-cpuid-Core-i5-2500.json
diff --git a/tests/cputestdata/x86_64-cpuid-Core-i5-2540M.json.new 
b/tests/cputestdata/x86_64-cpuid-Core-i5-2540M.json
similarity index 100%
rename from tests/cputestdata/x86_64-cpuid-Core-i5-2540M.json.new
rename to tests/cputestdata/x86_64-cpuid-Core-i5-2540M.json
diff --git 

[libvirt] [PATCH v2 20/33] cpu_x86: Introduce virCPUx86DataAddFeature

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/cpu/cpu_x86.c| 22 ++
 src/cpu/cpu_x86.h|  3 +++
 src/libvirt_private.syms |  1 +
 3 files changed, 26 insertions(+)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index ab5e5257d..b3bccd176 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -2756,6 +2756,28 @@ virCPUx86DataSetVendor(virCPUDataPtr cpuData,
 }
 
 
+int
+virCPUx86DataAddFeature(virCPUDataPtr cpuData,
+const char *name)
+{
+virCPUx86FeaturePtr feature;
+virCPUx86MapPtr map;
+
+if (!(map = virCPUx86GetMap()))
+return -1;
+
+/* ignore unknown features */
+if (!(feature = x86FeatureFind(map, name)) &&
+!(feature = x86FeatureFindInternal(name)))
+return 0;
+
+if (x86DataAdd(>data.x86, >data) < 0)
+return -1;
+
+return 0;
+}
+
+
 struct cpuArchDriver cpuDriverX86 = {
 .name = "x86",
 .arch = archs,
diff --git a/src/cpu/cpu_x86.h b/src/cpu/cpu_x86.h
index ab5394914..91ec43fea 100644
--- a/src/cpu/cpu_x86.h
+++ b/src/cpu/cpu_x86.h
@@ -39,4 +39,7 @@ int virCPUx86DataSetSignature(virCPUDataPtr cpuData,
 int virCPUx86DataSetVendor(virCPUDataPtr cpuData,
const char *vendor);
 
+int virCPUx86DataAddFeature(virCPUDataPtr cpuData,
+const char *name);
+
 #endif /* __VIR_CPU_X86_H__ */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 7338c31e7..1c071091d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1006,6 +1006,7 @@ virCPUUpdate;
 
 # cpu/cpu_x86.h
 virCPUx86DataAddCPUID;
+virCPUx86DataAddFeature;
 virCPUx86DataSetSignature;
 virCPUx86DataSetVendor;
 
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 31/33] cputest: Drop obsolete CPU test data files

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 tests/cputestdata/x86_64-cpuid-A10-5800K.json  | 77 ---
 tests/cputestdata/x86_64-cpuid-Core-i5-2500.json   | 88 --
 tests/cputestdata/x86_64-cpuid-Core-i5-2540M.json  | 82 
 tests/cputestdata/x86_64-cpuid-Core-i5-4670T.json  | 77 ---
 tests/cputestdata/x86_64-cpuid-Core-i5-6600.json   | 82 
 tests/cputestdata/x86_64-cpuid-Core-i7-2600.json   | 77 ---
 tests/cputestdata/x86_64-cpuid-Core-i7-3740QM.json | 77 ---
 tests/cputestdata/x86_64-cpuid-Core-i7-3770.json   | 77 ---
 tests/cputestdata/x86_64-cpuid-Core-i7-4600U.json  | 82 
 tests/cputestdata/x86_64-cpuid-Core-i7-5600U.json  | 88 --
 tests/cputestdata/x86_64-cpuid-Core2-E6850.json| 77 ---
 tests/cputestdata/x86_64-cpuid-Opteron-2350.json   | 71 -
 tests/cputestdata/x86_64-cpuid-Opteron-6234.json   | 88 --
 tests/cputestdata/x86_64-cpuid-Phenom-B95.json | 77 ---
 tests/cputestdata/x86_64-cpuid-Xeon-E3-1245.json   | 88 --
 tests/cputestdata/x86_64-cpuid-Xeon-E5-2630.json   | 77 ---
 tests/cputestdata/x86_64-cpuid-Xeon-E5-2650.json   | 71 -
 tests/cputestdata/x86_64-cpuid-Xeon-E7-4820.json   | 77 ---
 tests/cputestdata/x86_64-cpuid-Xeon-W3520.json | 77 ---
 19 files changed, 1510 deletions(-)
 delete mode 100644 tests/cputestdata/x86_64-cpuid-A10-5800K.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i5-2500.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i5-2540M.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i5-4670T.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i5-6600.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-2600.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-3740QM.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-3770.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-4600U.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-5600U.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core2-E6850.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Opteron-2350.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Opteron-6234.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Phenom-B95.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-E3-1245.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-E5-2630.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-E5-2650.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-E7-4820.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-W3520.json

diff --git a/tests/cputestdata/x86_64-cpuid-A10-5800K.json 
b/tests/cputestdata/x86_64-cpuid-A10-5800K.json
deleted file mode 100644
index 53b39ad03..0
--- a/tests/cputestdata/x86_64-cpuid-A10-5800K.json
+++ /dev/null
@@ -1,77 +0,0 @@
-{
-  "return": [
-{
-  "cpuid-register": "EAX",
-  "cpuid-input-ecx": 1,
-  "cpuid-input-eax": 13,
-  "features": 0
-},
-{
-  "cpuid-register": "EDX",
-  "cpuid-input-eax": 2147483658,
-  "features": 9
-},
-{
-  "cpuid-register": "EAX",
-  "cpuid-input-eax": 1073741825,
-  "features": 16777467
-},
-{
-  "cpuid-register": "EDX",
-  "cpuid-input-eax": 3221225473,
-  "features": 0
-},
-{
-  "cpuid-register": "EDX",
-  "cpuid-input-eax": 2147483655,
-  "features": 0
-},
-{
-  "cpuid-register": "ECX",
-  "cpuid-input-eax": 2147483649,
-  "features": 2165747
-},
-{
-  "cpuid-register": "EDX",
-  "cpuid-input-eax": 2147483649,
-  "features": 642779136
-},
-{
-  "cpuid-register": "EBX",
-  "cpuid-input-ecx": 0,
-  "cpuid-input-eax": 7,
-  "features": 10
-},
-{
-  "cpuid-register": "ECX",
-  "cpuid-input-eax": 1,
-  "features": 3065524739
-},
-{
-  "cpuid-register": "EDX",
-  "cpuid-input-eax": 1,
-  "features": 126614527
-}
-  ],
-  "id": "feature-words"
-}
-
-{
-  "return": 21,
-  "id": "family"
-}
-
-{
-  "return": 16,
-  "id": "model"
-}
-
-{
-  "return": 1,
-  "id": "stepping"
-}
-
-{
-  "return": "AMD A10-5800K APU with Radeon(tm) HD Graphics  ",
-  "id": "model-id"
-}
diff --git a/tests/cputestdata/x86_64-cpuid-Core-i5-2500.json 
b/tests/cputestdata/x86_64-cpuid-Core-i5-2500.json
deleted file mode 100644
index 156b77248..0
--- a/tests/cputestdata/x86_64-cpuid-Core-i5-2500.json
+++ /dev/null
@@ -1,88 +0,0 @@
-{
-  "return": [
-{
-  "cpuid-register": "EAX",
-  "cpuid-input-eax": 6,
-  "features": 4
-},
-{
-  "cpuid-register": "EAX",
-  "cpuid-input-ecx": 1,
-  

[libvirt] [PATCH v2 11/33] qemu: Store more types in qemuMonitorCPUModelInfo

2017-02-15 Thread Jiri Denemark
While query-cpu-model-expansion returns only boolean features on s390,
but x86_64 reports some integer and string properties which we are
interested in.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_capabilities.c | 84 
 src/qemu/qemu_monitor.c  | 22 ++-
 src/qemu/qemu_monitor.h  | 23 +--
 src/qemu/qemu_monitor_json.c | 37 ---
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml |  7 ++
 5 files changed, 133 insertions(+), 40 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index aab336954..466852d13 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3074,14 +3074,16 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps,
 cpu->nfeatures = 0;
 
 for (i = 0; i < modelInfo->nprops; i++) {
-if (VIR_STRDUP(cpu->features[i].name, modelInfo->props[i].name) < 0)
+virCPUFeatureDefPtr feature = cpu->features + cpu->nfeatures;
+qemuMonitorCPUPropertyPtr prop = modelInfo->props + i;
+
+if (prop->type != QEMU_MONITOR_CPU_PROPERTY_BOOLEAN)
+continue;
+
+if (VIR_STRDUP(feature->name, prop->name) < 0)
 return -1;
-
-if (modelInfo->props[i].supported)
-cpu->features[i].policy = VIR_CPU_FEATURE_REQUIRE;
-else
-cpu->features[i].policy = VIR_CPU_FEATURE_DISABLE;
-
+feature->policy = prop->value.boolean ? VIR_CPU_FEATURE_REQUIRE
+  : VIR_CPU_FEATURE_DISABLE;
 cpu->nfeatures++;
 }
 
@@ -3154,7 +3156,6 @@ static int
 virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
 xmlXPathContextPtr ctxt)
 {
-char *str = NULL;
 xmlNodePtr hostCPUNode;
 xmlNodePtr *featureNodes = NULL;
 xmlNodePtr oldnode = ctxt->node;
@@ -3187,30 +3188,47 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
 hostCPU->nprops = n;
 
 for (i = 0; i < n; i++) {
-hostCPU->props[i].name = virXMLPropString(featureNodes[i], "name");
-if (!hostCPU->props[i].name) {
+qemuMonitorCPUPropertyPtr prop = hostCPU->props + i;
+ctxt->node = featureNodes[i];
+
+if (!(prop->name = virXMLPropString(ctxt->node, "name"))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing 'name' attribute for a host CPU"
  " model property in QEMU capabilities 
cache"));
 goto cleanup;
 }
 
-if (!(str = virXMLPropString(featureNodes[i], "boolean"))) {
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("missing 'boolean' attribute for a host CPU"
- " model property in QEMU capabilities 
cache"));
-goto cleanup;
-}
-if (STREQ(str, "yes")) {
-hostCPU->props[i].supported = true;
-} else if (STREQ(str, "no")) {
-hostCPU->props[i].supported = false;
+if (virXPathBoolean("boolean(./@boolean)", ctxt)) {
+if (virXPathBoolean("./@boolean='yes'", ctxt))
+prop->value.boolean = true;
+prop->type = QEMU_MONITOR_CPU_PROPERTY_BOOLEAN;
+} else if (virXPathBoolean("boolean(./@string)", ctxt)) {
+prop->value.string = virXMLPropString(ctxt->node, "string");
+if (!prop->value.string) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("invalid string value for '%s' host CPU "
+ "model property in QEMU capabilities 
cache"),
+   prop->name);
+goto cleanup;
+}
+prop->type = QEMU_MONITOR_CPU_PROPERTY_STRING;
+} else if (virXPathBoolean("boolean(./@ull)", ctxt)) {
+if (virXPathULongLong("string(./@ull)", ctxt,
+  >value.ull) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("invalid integer value for '%s' host CPU "
+ "model property in QEMU capabilities 
cache"),
+   prop->name);
+goto cleanup;
+}
+prop->type = QEMU_MONITOR_CPU_PROPERTY_ULL;
 } else {
 virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("invalid boolean value: '%s'"), str);
+   _("missing value for '%s' host CPU model "
+ "property in QEMU capabilities cache"),
+   

[libvirt] [PATCH v2 30/33] cputest: Test virQEMUCapsInitCPUModel

2017-02-15 Thread Jiri Denemark
The original test didn't use family/model numbers to make better
decisions about the CPU model and thus mis-detected the model in the two
cases which are modified in this commit. The detected CPU models now
match those obtained from raw CPUID data.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- updated test results to include vendors

 tests/cputest.c| 28 +++---
 tests/cputestdata/x86_64-cpuid-A10-5800K-json.xml  |  1 +
 .../cputestdata/x86_64-cpuid-Core-i5-2500-json.xml |  1 +
 .../x86_64-cpuid-Core-i5-2540M-json.xml|  1 +
 .../x86_64-cpuid-Core-i5-4670T-json.xml|  1 +
 .../cputestdata/x86_64-cpuid-Core-i5-6600-json.xml |  1 +
 .../cputestdata/x86_64-cpuid-Core-i7-2600-json.xml |  1 +
 .../x86_64-cpuid-Core-i7-3740QM-json.xml   |  1 +
 .../cputestdata/x86_64-cpuid-Core-i7-3770-json.xml |  1 +
 .../x86_64-cpuid-Core-i7-4600U-json.xml|  1 +
 .../x86_64-cpuid-Core-i7-5600U-json.xml| 12 ++
 .../cputestdata/x86_64-cpuid-Core2-E6850-json.xml  |  5 ++--
 .../cputestdata/x86_64-cpuid-Opteron-2350-json.xml |  1 +
 .../cputestdata/x86_64-cpuid-Opteron-6234-json.xml |  1 +
 tests/cputestdata/x86_64-cpuid-Phenom-B95-json.xml |  1 +
 .../cputestdata/x86_64-cpuid-Xeon-E3-1245-json.xml |  1 +
 .../cputestdata/x86_64-cpuid-Xeon-E5-2630-json.xml |  1 +
 .../cputestdata/x86_64-cpuid-Xeon-E5-2650-json.xml |  1 +
 .../cputestdata/x86_64-cpuid-Xeon-E7-4820-json.xml |  1 +
 tests/cputestdata/x86_64-cpuid-Xeon-W3520-json.xml |  1 +
 20 files changed, 48 insertions(+), 14 deletions(-)

diff --git a/tests/cputest.c b/tests/cputest.c
index c0a816b60..8c16fb95c 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -43,7 +43,9 @@
 #if WITH_QEMU && WITH_YAJL
 # include "testutilsqemu.h"
 # include "qemumonitortestutils.h"
-# include "qemu/qemu_monitor_json.h"
+# define __QEMU_CAPSRIV_H_ALLOW__
+# include "qemu/qemu_capspriv.h"
+# undef __QEMU_CAPSRIV_H_ALLOW__
 #endif
 
 #define VIR_FROM_THIS VIR_FROM_CPU
@@ -517,14 +519,15 @@ static int
 cpuTestJSONCPUID(const void *arg)
 {
 const struct data *data = arg;
-virCPUDataPtr cpuData = NULL;
+qemuMonitorCPUModelInfoPtr model = NULL;
+virQEMUCapsPtr qemuCaps = NULL;
 virCPUDefPtr cpu = NULL;
 qemuMonitorTestPtr testMon = NULL;
 char *json = NULL;
 char *result = NULL;
 int ret = -1;
 
-if (virAsprintf(, "%s/cputestdata/%s-cpuid-%s.json",
+if (virAsprintf(, "%s/cputestdata/%s-cpuid-%s.json.new",
 abs_srcdir, virArchToString(data->arch), data->host) < 0 ||
 virAsprintf(, "cpuid-%s-json", data->host) < 0)
 goto cleanup;
@@ -532,26 +535,35 @@ cpuTestJSONCPUID(const void *arg)
 if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true)))
 goto cleanup;
 
-if (qemuMonitorJSONGetCPUx86Data(qemuMonitorTestGetMonitor(testMon),
- "feature-words", ) < 0)
+if (qemuMonitorGetCPUModelExpansion(qemuMonitorTestGetMonitor(testMon),
+
QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC,
+"host", ) < 0)
 goto cleanup;
 
+if (!(qemuCaps = virQEMUCapsNew()))
+goto cleanup;
+
+virQEMUCapsSetArch(qemuCaps, data->arch);
+virQEMUCapsSetCPUModelInfo(qemuCaps, VIR_DOMAIN_VIRT_KVM, model);
+model = NULL;
+
 if (VIR_ALLOC(cpu) < 0)
 goto cleanup;
 
-cpu->arch = cpuData->arch;
+cpu->arch = data->arch;
 cpu->type = VIR_CPU_TYPE_GUEST;
 cpu->match = VIR_CPU_MATCH_EXACT;
 cpu->fallback = VIR_CPU_FALLBACK_FORBID;
 
-if (cpuDecode(cpu, cpuData, NULL, 0, NULL) < 0)
+if (virQEMUCapsInitCPUModel(qemuCaps, VIR_DOMAIN_VIRT_KVM, cpu) != 0)
 goto cleanup;
 
 ret = cpuTestCompareXML(data->arch, cpu, result, false);
 
  cleanup:
+qemuMonitorCPUModelInfoFree(model);
+virObjectUnref(qemuCaps);
 qemuMonitorTestFree(testMon);
-virCPUDataFree(cpuData);
 virCPUDefFree(cpu);
 VIR_FREE(result);
 VIR_FREE(json);
diff --git a/tests/cputestdata/x86_64-cpuid-A10-5800K-json.xml 
b/tests/cputestdata/x86_64-cpuid-A10-5800K-json.xml
index 7a38f0fd4..c021fcddf 100644
--- a/tests/cputestdata/x86_64-cpuid-A10-5800K-json.xml
+++ b/tests/cputestdata/x86_64-cpuid-A10-5800K-json.xml
@@ -1,6 +1,7 @@
 
   x86_64
   Opteron_G5
+  AMD
   
   
   
diff --git a/tests/cputestdata/x86_64-cpuid-Core-i5-2500-json.xml 
b/tests/cputestdata/x86_64-cpuid-Core-i5-2500-json.xml
index 980cf74a0..2e2430e78 100644
--- a/tests/cputestdata/x86_64-cpuid-Core-i5-2500-json.xml
+++ b/tests/cputestdata/x86_64-cpuid-Core-i5-2500-json.xml
@@ -1,6 +1,7 @@
 
   x86_64
   SandyBridge
+  Intel
   
   
   
diff --git a/tests/cputestdata/x86_64-cpuid-Core-i5-2540M-json.xml 
b/tests/cputestdata/x86_64-cpuid-Core-i5-2540M-json.xml
index 980cf74a0..2e2430e78 100644
--- 

[libvirt] [PATCH v2 02/33] docs: Fix since statement in host-model documentation

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 docs/formatdomain.html.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index bc125ed63..294d3c467 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1282,7 +1282,7 @@
   it's a good idea to avoid using host-model and use
   custom mode with just the CPU model from host
   capabilities XML.
-  (Since 1.2.11). PowerISA allows
+  Since 1.2.11 PowerISA allows
   processors to run VMs in binary compatibility mode supporting an
   older version of ISA.  Libvirt on PowerPC architecture uses the
   host-model to signify a guest mode CPU running in
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 21/33] cpu: Use virCPUData.arch in cpuDecode

2017-02-15 Thread Jiri Denemark
virCPUDef.arch is not required to be filled in for guest CPU
definitions. It doesn't make sense to artificially mandate it to be set
when cpuDecode is called especially when virCPUData.arch passed to
cpuDecode already contains the architecture.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/cpu/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index 45a17bf46..051a58040 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -240,7 +240,7 @@ cpuDecode(virCPUDefPtr cpu,
 return -1;
 }
 
-if ((driver = cpuGetSubDriver(cpu->arch)) == NULL)
+if ((driver = cpuGetSubDriver(data->arch)) == NULL)
 return -1;
 
 if (driver->decode == NULL) {
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 05/33] qemu: Refactor virQEMUCapsInitHostCPUModel

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_capabilities.c | 109 ++-
 1 file changed, 55 insertions(+), 54 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 399e31447..c5e57b4ab 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3041,37 +3041,36 @@ virQEMUCapsCPUFilterFeatures(const char *name,
 }
 
 
-static void
-virQEMUCapsCopyCPUModelFromQEMU(virQEMUCapsPtr qemuCaps)
+/**
+ * Returns  0 when host CPU model provided by QEMU was filled in qemuCaps,
+ *  1 when the caller should fall back to using virCapsPtr->host.cpu,
+ * -1 on error.
+ */
+static int
+virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps,
+virCPUDefPtr cpu)
 {
-virCPUDefPtr cpu = NULL;
-qemuMonitorCPUModelInfoPtr modelInfo = NULL;
+qemuMonitorCPUModelInfoPtr modelInfo = qemuCaps->hostCPUModelInfo;
 size_t i;
 
-if (!(modelInfo = qemuCaps->hostCPUModelInfo)) {
+if (!modelInfo) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("missing host CPU model info from QEMU capabilities"
- " for binary %s"), qemuCaps->binary);
-goto error;
+   _("missing host CPU model info from QEMU capabilities "
+ "for binary %s"),
+   qemuCaps->binary);
+return -1;
 }
 
-if (VIR_ALLOC(cpu) < 0)
-goto error;
-
 if (VIR_STRDUP(cpu->model, modelInfo->name) < 0 ||
 VIR_ALLOC_N(cpu->features, modelInfo->nprops) < 0)
-goto error;
+return -1;
 
 cpu->nfeatures_max = modelInfo->nprops;
 cpu->nfeatures = 0;
-cpu->sockets = cpu->cores = cpu->threads = 0;
-cpu->type = VIR_CPU_TYPE_GUEST;
-cpu->mode = VIR_CPU_MODE_CUSTOM;
-cpu->match = VIR_CPU_MATCH_EXACT;
 
 for (i = 0; i < modelInfo->nprops; i++) {
 if (VIR_STRDUP(cpu->features[i].name, modelInfo->props[i].name) < 0)
-goto error;
+return -1;
 
 if (modelInfo->props[i].supported)
 cpu->features[i].policy = VIR_CPU_FEATURE_REQUIRE;
@@ -3081,31 +3080,53 @@ virQEMUCapsCopyCPUModelFromQEMU(virQEMUCapsPtr qemuCaps)
 cpu->nfeatures++;
 }
 
-qemuCaps->hostCPUModel = cpu;
-return;
-
- error:
-virCPUDefFree(cpu);
-qemuCaps->hostCPUModel = NULL;
-virResetLastError();
+return 0;
 }
 
 
-static void
-virQEMUCapsCopyCPUModelFromHost(virQEMUCapsPtr qemuCaps,
-virCapsPtr caps)
+/**
+ * Returns  0 when host CPU model provided by QEMU was filled in qemuCaps,
+ *  1 when the caller should fall back to using virCapsPtr->host.cpu,
+ * -1 on error.
+ */
+static int
+virQEMUCapsInitCPUModel(virQEMUCapsPtr qemuCaps,
+virCPUDefPtr cpu)
+{
+int ret = 1;
+
+if (ARCH_IS_S390(qemuCaps->arch))
+ret = virQEMUCapsInitCPUModelS390(qemuCaps, cpu);
+
+return ret;
+}
+
+
+void
+virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
+virCapsPtr caps)
 {
 virCPUDefPtr cpu = NULL;
+int rc;
 
-if (caps->host.cpu && caps->host.cpu->model) {
-if (VIR_ALLOC(cpu) < 0)
+if (!caps || !virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch))
+return;
+
+if (VIR_ALLOC(cpu) < 0)
+goto error;
+
+cpu->type = VIR_CPU_TYPE_GUEST;
+cpu->mode = VIR_CPU_MODE_CUSTOM;
+cpu->match = VIR_CPU_MATCH_EXACT;
+cpu->fallback = VIR_CPU_FALLBACK_ALLOW;
+
+if ((rc = virQEMUCapsInitCPUModel(qemuCaps, cpu)) < 0) {
+goto error;
+} else if (rc == 1) {
+VIR_DEBUG("No host CPU model info from QEMU; using host capabilities");
+if (!caps->host.cpu || !caps->host.cpu->model)
 goto error;
 
-cpu->sockets = cpu->cores = cpu->threads = 0;
-cpu->type = VIR_CPU_TYPE_GUEST;
-cpu->mode = VIR_CPU_MODE_CUSTOM;
-cpu->match = VIR_CPU_MATCH_EXACT;
-
 if (virCPUDefCopyModelFilter(cpu, caps->host.cpu, true,
  virQEMUCapsCPUFilterFeatures, NULL) < 0)
 goto error;
@@ -3116,30 +3137,10 @@ virQEMUCapsCopyCPUModelFromHost(virQEMUCapsPtr qemuCaps,
 
  error:
 virCPUDefFree(cpu);
-qemuCaps->hostCPUModel = NULL;
 virResetLastError();
 }
 
 
-void
-virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
-virCapsPtr caps)
-{
-if (!caps || !virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch))
-return;
-
-switch (qemuCaps->arch) {
-case VIR_ARCH_S390:
-case VIR_ARCH_S390X:
-virQEMUCapsCopyCPUModelFromQEMU(qemuCaps);
-break;
-
-default:
-virQEMUCapsCopyCPUModelFromHost(qemuCaps, caps);
-}
-}
-
-
 static int
 virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
   

[libvirt] [PATCH v2 33/33] news: Detect host CPU model by asking QEMU on x86_64

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 docs/news.xml | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/docs/news.xml b/docs/news.xml
index b756a970f..798687407 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -73,6 +73,17 @@
   and network.
 
   
+  
+
+  qemu: Detect host CPU model by asking QEMU on x86_64
+
+
+  Previously, libvirt detected the host CPU model using CPUID
+  instruction, which cased libvirt to detect a lot of CPU features
+  that are not supported by QEMU/KVM. Asking QEMU makes sure we
+  don't ask for unsupported features.
+
+  
 
 
   
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 01/33] docs: Drop obsolete statement about CPU modes and migration

2017-02-15 Thread Jiri Denemark
The guest CPU definition has always been updated automatically during
migration. And currently we just transform any host-model CPU into a
custom one when a domain starts.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 docs/formatdomain.html.in | 10 --
 1 file changed, 10 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 0a115f5dc..bc125ed63 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1307,16 +1307,6 @@
   a migration is attempted then the guest may hang or crash upon
   resuming execution on the destination host.
 
-
-In both host-model and host-passthrough
-mode, the real (approximate in host-passthrough mode) CPU
-definition which would be used on current host can be determined by
-specifying VIR_DOMAIN_XML_UPDATE_CPU flag when calling
-virDomainGetXMLDesc API. When running a guest that might
-be prone to operating system reactivation when presented with
-different hardware, and which will be migrated between hosts with
-different capabilities, you can use this output to rewrite XML to the
-custom mode for more robust migration.
   
 
   model
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 00/33] qemu: Detect host CPU model by asking QEMU on x86_64

2017-02-15 Thread Jiri Denemark
Until now host-model CPU mode tried to enable all CPU features supported
by the host CPU even if QEMU/KVM did not support them. This caused a
number of issues and made host-model quite unreliable. Asking QEMU for
the CPU it can provide and the current host makes host-model much more
robust.

This series fixes the following bugs:

https://bugzilla.redhat.com/show_bug.cgi?id=1018251
https://bugzilla.redhat.com/show_bug.cgi?id=1371617
https://bugzilla.redhat.com/show_bug.cgi?id=1372581
https://bugzilla.redhat.com/show_bug.cgi?id=1404627
https://bugzilla.redhat.com/show_bug.cgi?id=870071

In addition to that, the following bug should be mostly limited to cases
when an unsupported feature is explicitly requested:

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

The series relies on features which are not in QEMU yet, but should be
hopefully close enough to be pushed in 2.9.0. In the meantime, Eduardo's
work/x86-query-cpu-expansion-full branch can be used to play with them.

Version 2:
- properly set vendor property in converted test data files
- fix cpu-parse.sh to use "x86_64" prefix for the generated files

Jiri Denemark (33):
  docs: Drop obsolete statement about CPU modes and migration
  docs: Fix since statement in host-model documentation
  qemucapstest: Add test data for QEMU 2.9.0
  domaincapstest: Add test data for QEMU 2.9.0
  qemu: Refactor virQEMUCapsInitHostCPUModel
  qemu: Skip virQEMUCapsCPUFilterFeatures on non-x86 CPUs
  qemu: Fix CPU model fallback in domain capabilities
  docs: Update description of the host-model CPU mode
  qemu: Introduce virQEMUCapsFormatHostCPUModelInfo
  qemu: Rename hostCPU/feature element in capabilities cache
  qemu: Store more types in qemuMonitorCPUModelInfo
  qemu: Probe "max" CPU model in TCG
  cpu: Introduce virCPUDataNew
  cpu_x86: Drop virCPUx86MakeData and use virCPUDataNew
  cpu_x86: Make virCPUx86DataClear static
  cpu: Rework cpuDataFree
  cpu_x86: Make virCPUx86DataAddCPUID work with virCPUDataPtr
  cpu_x86: Introduce virCPUx86DataSetSignature
  cpu_x86: Introduce virCPUx86DataSetVendor
  cpu_x86: Introduce virCPUx86DataAddFeature
  cpu: Use virCPUData.arch in cpuDecode
  qemu: Get host CPU model from QEMU on x86_64
  qemu: Use enum for CPU model expansion type
  qemu: Use full CPU model expansion on x86
  qemu: Make virQEMUCapsInitCPUModel testable
  cputest: Rename x86 data files
  cputest: Use virArch enum rather then strings
  cputest: Switch host CPU data scripts to model expansion
  cputest: Convert all json data files to query-cpu-model-expansion
  cputest: Test virQEMUCapsInitCPUModel
  cputest: Drop obsolete CPU test data files
  cputest: Drop .new suffix from CPU test data files
  news: Detect host CPU model by asking QEMU on x86_64

 docs/formatdomain.html.in  |38 +-
 docs/news.xml  |11 +
 src/bhyve/bhyve_capabilities.c | 2 +-
 src/cpu/cpu.c  |42 +-
 src/cpu/cpu.h  | 7 +-
 src/cpu/cpu_arm.c  | 7 -
 src/cpu/cpu_ppc64.c| 6 +-
 src/cpu/cpu_s390.c | 7 -
 src/cpu/cpu_x86.c  |   280 +-
 src/cpu/cpu_x86.h  |13 +-
 src/libvirt_private.syms   | 8 +-
 src/libxl/libxl_capabilities.c |18 +-
 src/qemu/qemu_capabilities.c   |   452 +-
 src/qemu/qemu_capabilities.h   | 3 +-
 src/qemu/qemu_capspriv.h   |13 +-
 src/qemu/qemu_command.c| 2 +-
 src/qemu/qemu_monitor.c|26 +-
 src/qemu/qemu_monitor.h|31 +-
 src/qemu/qemu_monitor_json.c   |   109 +-
 src/qemu/qemu_monitor_json.h   | 4 +-
 src/qemu/qemu_parse_command.c  | 2 +-
 src/qemu/qemu_process.c| 7 +-
 src/vmware/vmware_conf.c   | 2 +-
 src/vz/vz_driver.c | 2 +-
 tests/cputest.c|   324 +-
 tests/cputestdata/cpu-convert.py   |   249 +
 tests/cputestdata/cpu-gather.sh|39 +-
 tests/cputestdata/cpu-parse.sh | 5 +-
 tests/cputestdata/x86-cpuid-A10-5800K.json |77 -
 tests/cputestdata/x86-cpuid-Core-i5-2500.json  |88 -
 tests/cputestdata/x86-cpuid-Core-i5-2540M.json |82 -
 tests/cputestdata/x86-cpuid-Core-i5-4670T.json |77 -
 tests/cputestdata/x86-cpuid-Core-i5-6600.json  |82 -
 tests/cputestdata/x86-cpuid-Core-i7-2600.json  |77 -
 tests/cputestdata/x86-cpuid-Core-i7-3740QM.json|77 -
 

[libvirt] [PATCH v2 10/33] qemu: Rename hostCPU/feature element in capabilities cache

2017-02-15 Thread Jiri Denemark
The element will be generalized in the following commit.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_capabilities.c |  14 +-
 tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml  |  30 +--
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml | 322 +++
 3 files changed, 183 insertions(+), 183 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 688d19504..aab336954 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3180,7 +3180,7 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
 
 ctxt->node = hostCPUNode;
 
-if ((n = virXPathNodeSet("./feature", ctxt, )) > 0) {
+if ((n = virXPathNodeSet("./property", ctxt, )) > 0) {
 if (VIR_ALLOC_N(hostCPU->props, n) < 0)
 goto cleanup;
 
@@ -3191,14 +3191,14 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
 if (!hostCPU->props[i].name) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing 'name' attribute for a host CPU"
- " model feature in QEMU capabilities cache"));
+ " model property in QEMU capabilities 
cache"));
 goto cleanup;
 }
 
-if (!(str = virXMLPropString(featureNodes[i], "supported"))) {
+if (!(str = virXMLPropString(featureNodes[i], "boolean"))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("missing 'supported' attribute for a host CPU"
- " model feature in QEMU capabilities cache"));
+   _("missing 'boolean' attribute for a host CPU"
+ " model property in QEMU capabilities 
cache"));
 goto cleanup;
 }
 if (STREQ(str, "yes")) {
@@ -3207,7 +3207,7 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
 hostCPU->props[i].supported = false;
 } else {
 virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("invalid supported value: '%s'"), str);
+   _("invalid boolean value: '%s'"), str);
 goto cleanup;
 }
 VIR_FREE(str);
@@ -3552,7 +3552,7 @@ virQEMUCapsFormatHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
 virBufferAdjustIndent(buf, 2);
 
 for (i = 0; i < model->nprops; i++) {
-virBufferAsprintf(buf, "\n",
+virBufferAsprintf(buf, "\n",
   model->props[i].name,
   model->props[i].supported ? "yes" : "no");
 }
diff --git a/tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml 
b/tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml
index c4c9bf9d5..1f652bdc2 100644
--- a/tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml
+++ b/tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml
@@ -134,21 +134,21 @@
   
   s390x
   
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
   
   
   
diff --git a/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml 
b/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml
index ab7906175..c13e8318f 100644
--- a/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml
@@ -206,167 +206,167 @@
(v2.8.0-877-g38e4b757b4)
   x86_64
   
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

[libvirt] [PATCH v2 28/33] cputest: Switch host CPU data scripts to model expansion

2017-02-15 Thread Jiri Denemark
Instantiating "host" CPU and querying it using qom-get has been the only
way of probing host CPU via QEMU until 2.9.0 implemented
query-cpu-model-expansion for x86_64. Even though libvirt never really
used the old way its result can be easily converted into the one
produced by query-cpu-model-expansion. Thus we can reuse the original
test data and possible get new data from hosts where QEMU does not
support the new QMP command.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- cpu-convert.py: set "vendor" property according to model-id

 tests/cputestdata/cpu-convert.py | 249 +++
 tests/cputestdata/cpu-gather.sh  |  39 +-
 tests/cputestdata/cpu-parse.sh   |   3 +
 3 files changed, 285 insertions(+), 6 deletions(-)
 create mode 100755 tests/cputestdata/cpu-convert.py

diff --git a/tests/cputestdata/cpu-convert.py b/tests/cputestdata/cpu-convert.py
new file mode 100755
index 0..77bae3628
--- /dev/null
+++ b/tests/cputestdata/cpu-convert.py
@@ -0,0 +1,249 @@
+#!/usr/bin/python
+
+import sys
+import json
+
+# This is a list of x86 CPU features as of QEMU 2.8.50 and it won't need any
+# updates since in the future because query-cpu-model-expansion will be used
+# with newer QEMU.
+cpuidMap = [
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0001, 
"edx": 0, "names": ["pni", "sse3"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0002, 
"edx": 0, "names": ["pclmulqdq", "pclmuldq"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0004, 
"edx": 0, "names": ["dtes64"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0008, 
"edx": 0, "names": ["monitor"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0010, 
"edx": 0, "names": ["ds-cpl", "ds_cpl"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0020, 
"edx": 0, "names": ["vmx"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0040, 
"edx": 0, "names": ["smx"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0080, 
"edx": 0, "names": ["est"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0100, 
"edx": 0, "names": ["tm2"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0200, 
"edx": 0, "names": ["ssse3"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0400, 
"edx": 0, "names": ["cid"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x1000, 
"edx": 0, "names": ["fma"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x2000, 
"edx": 0, "names": ["cx16"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x4000, 
"edx": 0, "names": ["xtpr"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x8000, 
"edx": 0, "names": ["pdcm"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0002, 
"edx": 0, "names": ["pcid"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0004, 
"edx": 0, "names": ["dca"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0008, 
"edx": 0, "names": ["sse4.1", "sse4-1", "sse4_1"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0010, 
"edx": 0, "names": ["sse4.2", "sse4-2", "sse4_2"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0020, 
"edx": 0, "names": ["x2apic"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0040, 
"edx": 0, "names": ["movbe"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0080, 
"edx": 0, "names": ["popcnt"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0100, 
"edx": 0, "names": ["tsc-deadline"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0200, 
"edx": 0, "names": ["aes"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0400, 
"edx": 0, "names": ["xsave"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0800, 
"edx": 0, "names": ["osxsave"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x1000, 
"edx": 0, "names": ["avx"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x2000, 
"edx": 0, "names": ["f16c"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x4000, 
"edx": 0, "names": ["rdrand"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x8000, 
"edx": 0, "names": ["hypervisor"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0, "edx": 
0x0001, "names": ["fpu"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0, "edx": 
0x0002, "names": ["vme"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, 

[libvirt] [PATCH v2 06/33] qemu: Skip virQEMUCapsCPUFilterFeatures on non-x86 CPUs

2017-02-15 Thread Jiri Denemark
All features the function is currently supposed to filter out are
specific to x86_64. We should avoid removing them on other
architectures. It seems to be quite unlikely other achitectures would
use the same names, but one can never be sure.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_capabilities.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index c5e57b4ab..0be2301cb 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3030,8 +3030,13 @@ virQEMUCapsProbeQMPGICCapabilities(virQEMUCapsPtr 
qemuCaps,
 
 static bool
 virQEMUCapsCPUFilterFeatures(const char *name,
- void *opaque ATTRIBUTE_UNUSED)
+ void *opaque)
 {
+virQEMUCapsPtr qemuCaps = opaque;
+
+if (!ARCH_IS_X86(qemuCaps->arch))
+return true;
+
 if (STREQ(name, "cmt") ||
 STREQ(name, "mbm_total") ||
 STREQ(name, "mbm_local"))
@@ -3128,7 +3133,8 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
 goto error;
 
 if (virCPUDefCopyModelFilter(cpu, caps->host.cpu, true,
- virQEMUCapsCPUFilterFeatures, NULL) < 0)
+ virQEMUCapsCPUFilterFeatures,
+ qemuCaps) < 0)
 goto error;
 }
 
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 14/33] cpu_x86: Drop virCPUx86MakeData and use virCPUDataNew

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/cpu/cpu_x86.c  | 147 ++---
 src/cpu/cpu_x86.h  |   3 -
 src/libvirt_private.syms   |   1 -
 src/libxl/libxl_capabilities.c |  18 ++---
 src/qemu/qemu_monitor_json.c   |  33 -
 5 files changed, 92 insertions(+), 110 deletions(-)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index d9764a260..ccd68b681 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -303,22 +303,6 @@ virCPUx86DataClear(virCPUx86Data *data)
 }
 
 
-virCPUDataPtr
-virCPUx86MakeData(virArch arch, virCPUx86Data *data)
-{
-virCPUDataPtr cpuData;
-
-if (VIR_ALLOC(cpuData) < 0)
-return NULL;
-
-cpuData->arch = arch;
-cpuData->data.x86 = *data;
-data->len = 0;
-data->data = NULL;
-
-return cpuData;
-}
-
 static void
 x86FreeCPUData(virCPUDataPtr data)
 {
@@ -1441,7 +1425,6 @@ virCPUx86DataParse(xmlXPathContextPtr ctxt)
 {
 xmlNodePtr *nodes = NULL;
 virCPUDataPtr cpuData = NULL;
-virCPUx86Data data = VIR_CPU_X86_DATA_INIT;
 virCPUx86CPUID cpuid;
 size_t i;
 int n;
@@ -1450,26 +1433,31 @@ virCPUx86DataParse(xmlXPathContextPtr ctxt)
 if (n <= 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("no x86 CPU data found"));
-goto cleanup;
+goto error;
 }
 
+if (!(cpuData = virCPUDataNew(VIR_ARCH_X86_64)))
+goto error;
+
 for (i = 0; i < n; i++) {
 ctxt->node = nodes[i];
 if (x86ParseCPUID(ctxt, ) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse cpuid[%zu]"), i);
-goto cleanup;
+goto error;
 }
-if (virCPUx86DataAddCPUID(, ) < 0)
-goto cleanup;
+if (virCPUx86DataAddCPUID(>data.x86, ) < 0)
+goto error;
 }
 
-cpuData = virCPUx86MakeData(VIR_ARCH_X86_64, );
-
  cleanup:
 VIR_FREE(nodes);
-virCPUx86DataClear();
 return cpuData;
+
+ error:
+x86FreeCPUData(cpuData);
+cpuData = NULL;
+goto cleanup;
 }
 
 
@@ -1514,7 +1502,7 @@ x86Compute(virCPUDefPtr host,
 virCPUx86ModelPtr cpu_forbid = NULL;
 virCPUx86ModelPtr diff = NULL;
 virCPUx86ModelPtr guest_model = NULL;
-virCPUx86Data guestData = VIR_CPU_X86_DATA_INIT;
+virCPUDataPtr guestData = NULL;
 virCPUCompareResult ret;
 virCPUx86CompareResult result;
 virArch arch;
@@ -1633,9 +1621,11 @@ x86Compute(virCPUDefPtr host,
 
 x86DataSubtract(_model->data, _disable->data);
 
-if (x86DataCopy(, _model->data) < 0 ||
-!(*guest = virCPUx86MakeData(arch, )))
+if (!(guestData = virCPUDataNew(arch)) ||
+x86DataCopy(>data.x86, _model->data) < 0)
 goto error;
+
+*guest = guestData;
 }
 
  cleanup:
@@ -1647,11 +1637,11 @@ x86Compute(virCPUDefPtr host,
 x86ModelFree(cpu_disable);
 x86ModelFree(cpu_forbid);
 x86ModelFree(guest_model);
-virCPUx86DataClear();
 
 return ret;
 
  error:
+x86FreeCPUData(guestData);
 ret = VIR_CPU_COMPARE_ERROR;
 goto cleanup;
 }
@@ -1958,12 +1948,12 @@ x86Encode(virArch arch,
   virCPUDataPtr *vendor)
 {
 virCPUx86MapPtr map = NULL;
-virCPUx86Data data_forced = VIR_CPU_X86_DATA_INIT;
-virCPUx86Data data_required = VIR_CPU_X86_DATA_INIT;
-virCPUx86Data data_optional = VIR_CPU_X86_DATA_INIT;
-virCPUx86Data data_disabled = VIR_CPU_X86_DATA_INIT;
-virCPUx86Data data_forbidden = VIR_CPU_X86_DATA_INIT;
-virCPUx86Data data_vendor = VIR_CPU_X86_DATA_INIT;
+virCPUDataPtr data_forced = NULL;
+virCPUDataPtr data_required = NULL;
+virCPUDataPtr data_optional = NULL;
+virCPUDataPtr data_disabled = NULL;
+virCPUDataPtr data_forbidden = NULL;
+virCPUDataPtr data_vendor = NULL;
 
 if (forced)
 *forced = NULL;
@@ -1982,23 +1972,33 @@ x86Encode(virArch arch,
 goto error;
 
 if (forced &&
-x86EncodePolicy(_forced, cpu, map, VIR_CPU_FEATURE_FORCE) < 0)
+(!(data_forced = virCPUDataNew(arch)) ||
+ x86EncodePolicy(_forced->data.x86, cpu, map,
+ VIR_CPU_FEATURE_FORCE) < 0))
 goto error;
 
 if (required &&
-x86EncodePolicy(_required, cpu, map, VIR_CPU_FEATURE_REQUIRE) < 0)
+(!(data_required = virCPUDataNew(arch)) ||
+ x86EncodePolicy(_required->data.x86, cpu, map,
+ VIR_CPU_FEATURE_REQUIRE) < 0))
 goto error;
 
 if (optional &&
-x86EncodePolicy(_optional, cpu, map, VIR_CPU_FEATURE_OPTIONAL) < 
0)
+(!(data_optional = virCPUDataNew(arch)) ||
+ x86EncodePolicy(_optional->data.x86, cpu, map,
+ VIR_CPU_FEATURE_OPTIONAL) < 0))
 goto error;
 
 if (disabled &&
-x86EncodePolicy(_disabled, cpu, map, VIR_CPU_FEATURE_DISABLE) < 0)
+

[libvirt] [PATCH v2 09/33] qemu: Introduce virQEMUCapsFormatHostCPUModelInfo

2017-02-15 Thread Jiri Denemark
The CPU model info formating code in virQEMUCapsFormatCache will get
more complicated soon. Separating the code in
virQEMUCapsFormatHostCPUModelInfo will make the result easier to read.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_capabilities.c | 36 +++-
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index c511248bd..688d19504 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3542,6 +3542,27 @@ virQEMUCapsLoadCache(virCapsPtr caps,
 
 
 static void
+virQEMUCapsFormatHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
+  virBufferPtr buf)
+{
+qemuMonitorCPUModelInfoPtr model = qemuCaps->hostCPUModelInfo;
+size_t i;
+
+virBufferAsprintf(buf, "\n", model->name);
+virBufferAdjustIndent(buf, 2);
+
+for (i = 0; i < model->nprops; i++) {
+virBufferAsprintf(buf, "\n",
+  model->props[i].name,
+  model->props[i].supported ? "yes" : "no");
+}
+
+virBufferAdjustIndent(buf, -2);
+virBufferAddLit(buf, "\n");
+}
+
+
+static void
 virQEMUCapsFormatCPUModels(virQEMUCapsPtr qemuCaps,
virBufferPtr buf,
virDomainVirtType type)
@@ -3617,19 +3638,8 @@ virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps,
 virBufferAsprintf(, "%s\n",
   virArchToString(qemuCaps->arch));
 
-if (qemuCaps->hostCPUModelInfo) {
-virBufferAsprintf(, "\n",
-  qemuCaps->hostCPUModelInfo->name);
-virBufferAdjustIndent(, 2);
-for (i = 0; i < qemuCaps->hostCPUModelInfo->nprops; i++) {
-virBufferAsprintf(, "\n",
-  qemuCaps->hostCPUModelInfo->props[i].name,
-  qemuCaps->hostCPUModelInfo->props[i].supported ?
-  "yes" : "no");
-}
-virBufferAdjustIndent(, -2);
-virBufferAddLit(, "\n");
-}
+if (qemuCaps->hostCPUModelInfo)
+virQEMUCapsFormatHostCPUModelInfo(qemuCaps, );
 
 virQEMUCapsFormatCPUModels(qemuCaps, , VIR_DOMAIN_VIRT_KVM);
 virQEMUCapsFormatCPUModels(qemuCaps, , VIR_DOMAIN_VIRT_QEMU);
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 17/33] cpu_x86: Make virCPUx86DataAddCPUID work with virCPUDataPtr

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/cpu/cpu_x86.c  | 57 --
 src/cpu/cpu_x86.h  |  2 +-
 src/libxl/libxl_capabilities.c |  2 +-
 src/qemu/qemu_monitor_json.c   |  2 +-
 4 files changed, 36 insertions(+), 27 deletions(-)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 3b540f99c..029a7d475 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -330,9 +330,9 @@ x86DataCopy(virCPUx86Data *dst, const virCPUx86Data *src)
 }
 
 
-int
-virCPUx86DataAddCPUID(virCPUx86Data *data,
-  const virCPUx86CPUID *cpuid)
+static int
+virCPUx86DataAddCPUIDInt(virCPUx86Data *data,
+ const virCPUx86CPUID *cpuid)
 {
 virCPUx86CPUID *existing;
 
@@ -365,7 +365,7 @@ x86DataAdd(virCPUx86Data *data1,
 if (cpuid1) {
 x86cpuidSetBits(cpuid1, cpuid2);
 } else {
-if (virCPUx86DataAddCPUID(data1, cpuid2) < 0)
+if (virCPUx86DataAddCPUIDInt(data1, cpuid2) < 0)
 return -1;
 }
 }
@@ -549,7 +549,7 @@ x86DataAddSignature(virCPUx86Data *data,
 {
 virCPUx86CPUID cpuid = { .eax_in = 0x1, .eax = signature };
 
-return virCPUx86DataAddCPUID(data, );
+return virCPUx86DataAddCPUIDInt(data, );
 }
 
 
@@ -892,7 +892,7 @@ x86FeatureParse(xmlXPathContextPtr ctxt,
i, feature->name);
 goto error;
 }
-if (virCPUx86DataAddCPUID(>data, ))
+if (virCPUx86DataAddCPUIDInt(>data, ))
 goto error;
 }
 
@@ -1446,7 +1446,7 @@ virCPUx86DataParse(xmlXPathContextPtr ctxt)
_("failed to parse cpuid[%zu]"), i);
 goto error;
 }
-if (virCPUx86DataAddCPUID(>data.x86, ) < 0)
+if (virCPUx86DataAddCPUID(cpuData, ) < 0)
 goto error;
 }
 
@@ -1605,8 +1605,8 @@ x86Compute(virCPUDefPtr host,
 goto error;
 
 if (cpu->vendor && host_model->vendor &&
-virCPUx86DataAddCPUID(_model->data,
-  _model->vendor->cpuid) < 0)
+virCPUx86DataAddCPUIDInt(_model->data,
+ _model->vendor->cpuid) < 0)
 goto error;
 
 if (x86DataAddSignature(_model->data, host_model->signature) < 0)
@@ -2013,7 +2013,7 @@ x86Encode(virArch arch,
 if (!(data_vendor = virCPUDataNew(arch)))
 goto error;
 
-if (v && virCPUx86DataAddCPUID(_vendor->data.x86, >cpuid) < 0)
+if (v && virCPUx86DataAddCPUID(data_vendor, >cpuid) < 0)
 goto error;
 }
 
@@ -2083,7 +2083,7 @@ cpuidCall(virCPUx86CPUID *cpuid)
  * Sub leaf n+1 is invalid if eax[4:0] in sub leaf n equals 0.
  */
 static int
-cpuidSetLeaf4(virCPUx86Data *data,
+cpuidSetLeaf4(virCPUDataPtr data,
   virCPUx86CPUID *subLeaf0)
 {
 virCPUx86CPUID cpuid = *subLeaf0;
@@ -2106,7 +2106,7 @@ cpuidSetLeaf4(virCPUx86Data *data,
  * Sub leaf n is invalid if n > eax in sub leaf 0.
  */
 static int
-cpuidSetLeaf7(virCPUx86Data *data,
+cpuidSetLeaf7(virCPUDataPtr data,
   virCPUx86CPUID *subLeaf0)
 {
 virCPUx86CPUID cpuid = { .eax_in = 0x7 };
@@ -2133,7 +2133,7 @@ cpuidSetLeaf7(virCPUx86Data *data,
  * meaningful data even if it was (theoretically) considered invalid.
  */
 static int
-cpuidSetLeafB(virCPUx86Data *data,
+cpuidSetLeafB(virCPUDataPtr data,
   virCPUx86CPUID *subLeaf0)
 {
 virCPUx86CPUID cpuid = *subLeaf0;
@@ -2157,7 +2157,7 @@ cpuidSetLeafB(virCPUx86Data *data,
  * and edx[n-32] from sub leaf 1 is not set.
  */
 static int
-cpuidSetLeafD(virCPUx86Data *data,
+cpuidSetLeafD(virCPUDataPtr data,
   virCPUx86CPUID *subLeaf0)
 {
 virCPUx86CPUID cpuid = { .eax_in = 0xd };
@@ -2204,7 +2204,7 @@ cpuidSetLeafD(virCPUx86Data *data,
  * 0x10: Sub leaf n is valid if ebx[n] (= res[ResID]) from sub leaf 0 is set.
  */
 static int
-cpuidSetLeafResID(virCPUx86Data *data,
+cpuidSetLeafResID(virCPUDataPtr data,
   virCPUx86CPUID *subLeaf0,
   uint32_t res)
 {
@@ -2232,13 +2232,13 @@ cpuidSetLeafResID(virCPUx86Data *data,
  * Sub leaves n >= 2 are valid as long as eax[3:0] != 0.
  */
 static int
-cpuidSetLeaf12(virCPUx86Data *data,
+cpuidSetLeaf12(virCPUDataPtr data,
virCPUx86CPUID *subLeaf0)
 {
 virCPUx86CPUID cpuid = { .eax_in = 0x7 };
 virCPUx86CPUID *cpuid7;
 
-if (!(cpuid7 = x86DataCpuid(data, )) ||
+if (!(cpuid7 = x86DataCpuid(>data.x86, )) ||
 !(cpuid7->ebx & (1 << 2)))
 return 0;
 
@@ -2268,7 +2268,7 @@ cpuidSetLeaf12(virCPUx86Data *data,
  * Sub leaf 0 reports the maximum supported sub leaf in eax.
  */
 static int
-cpuidSetLeaf14(virCPUx86Data *data,
+cpuidSetLeaf14(virCPUDataPtr data,
virCPUx86CPUID *subLeaf0)
 {
 virCPUx86CPUID cpuid = { .eax_in = 0x14 };
@@ -2293,7 +2293,7 @@ cpuidSetLeaf14(virCPUx86Data 

[libvirt] [PATCH v2 04/33] domaincapstest: Add test data for QEMU 2.9.0

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 .../domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml | 116 +
 tests/domaincapsschemadata/qemu_2.9.0.x86_64.xml   | 116 +
 tests/domaincapstest.c |   8 ++
 3 files changed, 240 insertions(+)
 create mode 100644 tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml
 create mode 100644 tests/domaincapsschemadata/qemu_2.9.0.x86_64.xml

diff --git a/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml 
b/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml
new file mode 100644
index 0..9b9dfec09
--- /dev/null
+++ b/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml
@@ -0,0 +1,116 @@
+
+  /usr/bin/qemu-system-x86_64
+  qemu
+  pc-i440fx-2.9
+  x86_64
+  
+  
+
+  /usr/share/AAVMF/AAVMF_CODE.fd
+  /usr/share/OVMF/OVMF_CODE.fd
+  
+rom
+pflash
+  
+  
+yes
+no
+  
+
+  
+  
+
+
+  Broadwell
+
+
+  qemu64
+  qemu32
+  phenom
+  pentium3
+  pentium2
+  pentium
+  n270
+  kvm64
+  kvm32
+  coreduo
+  core2duo
+  athlon
+  Westmere
+  Skylake-Client
+  SandyBridge
+  Penryn
+  Opteron_G5
+  Opteron_G4
+  Opteron_G3
+  Opteron_G2
+  Opteron_G1
+  Nehalem
+  IvyBridge
+  Haswell
+  Haswell-noTSX
+  Conroe
+  Broadwell
+  Broadwell-noTSX
+  486
+
+  
+  
+
+  
+disk
+cdrom
+floppy
+lun
+  
+  
+ide
+fdc
+scsi
+virtio
+usb
+  
+
+
+  
+sdl
+vnc
+spice
+  
+
+
+  
+vga
+cirrus
+vmvga
+qxl
+virtio
+  
+
+
+  
+subsystem
+  
+  
+default
+mandatory
+requisite
+optional
+  
+  
+usb
+pci
+scsi
+  
+  
+  
+default
+kvm
+vfio
+  
+
+  
+  
+
+  
+
diff --git a/tests/domaincapsschemadata/qemu_2.9.0.x86_64.xml 
b/tests/domaincapsschemadata/qemu_2.9.0.x86_64.xml
new file mode 100644
index 0..49722f91f
--- /dev/null
+++ b/tests/domaincapsschemadata/qemu_2.9.0.x86_64.xml
@@ -0,0 +1,116 @@
+
+  /usr/bin/qemu-system-x86_64
+  kvm
+  pc-i440fx-2.9
+  x86_64
+  
+  
+
+  /usr/share/AAVMF/AAVMF_CODE.fd
+  /usr/share/OVMF/OVMF_CODE.fd
+  
+rom
+pflash
+  
+  
+yes
+no
+  
+
+  
+  
+
+
+  Broadwell
+
+
+  qemu64
+  qemu32
+  phenom
+  pentium3
+  pentium2
+  pentium
+  n270
+  kvm64
+  kvm32
+  coreduo
+  core2duo
+  athlon
+  Westmere
+  Skylake-Client
+  SandyBridge
+  Penryn
+  Opteron_G5
+  Opteron_G4
+  Opteron_G3
+  Opteron_G2
+  Opteron_G1
+  Nehalem
+  IvyBridge
+  Haswell
+  Haswell-noTSX
+  Conroe
+  Broadwell
+  Broadwell-noTSX
+  486
+
+  
+  
+
+  
+disk
+cdrom
+floppy
+lun
+  
+  
+ide
+fdc
+scsi
+virtio
+usb
+  
+
+
+  
+sdl
+vnc
+spice
+  
+
+
+  
+vga
+cirrus
+vmvga
+qxl
+virtio
+  
+
+
+  
+subsystem
+  
+  
+default
+mandatory
+requisite
+optional
+  
+  
+usb
+pci
+scsi
+  
+  
+  
+default
+kvm
+vfio
+  
+
+  
+  
+
+  
+
diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c
index 28d8609ac..9b64f2c18 100644
--- a/tests/domaincapstest.c
+++ b/tests/domaincapstest.c
@@ -453,6 +453,14 @@ mymain(void)
  "/usr/bin/qemu-system-x86_64", NULL,
  "x86_64", VIR_DOMAIN_VIRT_QEMU);
 
+DO_TEST_QEMU("2.9.0", "caps_2.9.0",
+ "/usr/bin/qemu-system-x86_64", NULL,
+ "x86_64", VIR_DOMAIN_VIRT_KVM);
+
+DO_TEST_QEMU("2.9.0-tcg", "caps_2.9.0",
+ "/usr/bin/qemu-system-x86_64", NULL,
+ "x86_64", VIR_DOMAIN_VIRT_QEMU);
+
 DO_TEST_QEMU("2.7.0", "caps_2.7.0",
  "/usr/bin/qemu-system-s390x", NULL,
  "s390x", VIR_DOMAIN_VIRT_KVM);
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 22/33] qemu: Get host CPU model from QEMU on x86_64

2017-02-15 Thread Jiri Denemark
Until now host-model CPU mode tried to enable all CPU features supported
by the host CPU even if QEMU/KVM did not support them. This caused a
number of issues and made host-model quite unreliable. Asking QEMU for
the CPU it can provide and the current host makes host-model much more
robust.

This commit fixes the following bugs:

https://bugzilla.redhat.com/show_bug.cgi?id=1018251
https://bugzilla.redhat.com/show_bug.cgi?id=1371617
https://bugzilla.redhat.com/show_bug.cgi?id=1372581
https://bugzilla.redhat.com/show_bug.cgi?id=1404627
https://bugzilla.redhat.com/show_bug.cgi?id=870071

In addition to that, the following bug should be mostly limited to cases
when an unsupported feature is explicitly requested:

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

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_capabilities.c   | 73 ++
 .../domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml | 33 +-
 tests/domaincapsschemadata/qemu_2.9.0.x86_64.xml   | 11 +++-
 3 files changed, 115 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index f115f1e23..bcfb6b694 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3128,6 +3128,77 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps,
  * -1 on error.
  */
 static int
+virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
+   virDomainVirtType type,
+   virCPUDefPtr cpu)
+{
+qemuMonitorCPUModelInfoPtr model;
+virCPUDataPtr data = NULL;
+unsigned long long sigFamily = 0;
+unsigned long long sigModel = 0;
+size_t nmodels = 0;
+char **models = NULL;
+int ret = -1;
+size_t i;
+
+if (type == VIR_DOMAIN_VIRT_KVM)
+model = qemuCaps->kvmCPUModelInfo;
+else
+model = qemuCaps->tcgCPUModelInfo;
+
+if (!model)
+return 1;
+
+if (!(data = virCPUDataNew(VIR_ARCH_X86_64)))
+goto cleanup;
+
+for (i = 0; i < model->nprops; i++) {
+qemuMonitorCPUPropertyPtr prop = model->props + i;
+
+switch (prop->type) {
+case QEMU_MONITOR_CPU_PROPERTY_BOOLEAN:
+if (prop->value.boolean &&
+virCPUx86DataAddFeature(data, prop->name) < 0)
+goto cleanup;
+break;
+
+case QEMU_MONITOR_CPU_PROPERTY_STRING:
+if (STREQ(prop->name, "vendor") &&
+virCPUx86DataSetVendor(data, prop->value.string) < 0)
+goto cleanup;
+break;
+
+case QEMU_MONITOR_CPU_PROPERTY_ULL:
+if (STREQ(prop->name, "family"))
+sigFamily = prop->value.ull;
+else if (STREQ(prop->name, "model"))
+sigModel = prop->value.ull;
+break;
+}
+}
+
+if (virCPUx86DataSetSignature(data, sigFamily, sigModel) < 0)
+goto cleanup;
+
+if (virQEMUCapsGetCPUDefinitions(qemuCaps, type, , ) < 0 ||
+cpuDecode(cpu, data, (const char **) models, nmodels, NULL) < 0)
+goto cleanup;
+
+ret = 0;
+
+ cleanup:
+virCPUDataFree(data);
+virStringListFreeCount(models, nmodels);
+return ret;
+}
+
+
+/**
+ * Returns  0 when host CPU model provided by QEMU was filled in qemuCaps,
+ *  1 when the caller should fall back to using virCapsPtr->host.cpu,
+ * -1 on error.
+ */
+static int
 virQEMUCapsInitCPUModel(virQEMUCapsPtr qemuCaps,
 virDomainVirtType type,
 virCPUDefPtr cpu)
@@ -3136,6 +3207,8 @@ virQEMUCapsInitCPUModel(virQEMUCapsPtr qemuCaps,
 
 if (ARCH_IS_S390(qemuCaps->arch))
 ret = virQEMUCapsInitCPUModelS390(qemuCaps, type, cpu);
+else if (ARCH_IS_X86(qemuCaps->arch))
+ret = virQEMUCapsInitCPUModelX86(qemuCaps, type, cpu);
 
 if (ret == 0)
 cpu->fallback = VIR_CPU_FALLBACK_FORBID;
diff --git a/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml 
b/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml
index 9b9dfec09..1827b1d6f 100644
--- a/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml
+++ b/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml
@@ -21,7 +21,38 @@
   
 
 
-  Broadwell
+  Opteron_G4
+  AMD
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
 
 
   qemu64
diff --git a/tests/domaincapsschemadata/qemu_2.9.0.x86_64.xml 
b/tests/domaincapsschemadata/qemu_2.9.0.x86_64.xml
index 49722f91f..a7a2ecdea 100644
--- a/tests/domaincapsschemadata/qemu_2.9.0.x86_64.xml
+++ b/tests/domaincapsschemadata/qemu_2.9.0.x86_64.xml
@@ -21,7 +21,16 @@
   
 
 
-  Broadwell
+  Skylake-Client
+  Intel
+  
+  
+  
+

[libvirt] [PATCH v2 13/33] cpu: Introduce virCPUDataNew

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/cpu/cpu.c| 19 +++
 src/cpu/cpu.h|  3 +++
 src/libvirt_private.syms |  1 +
 3 files changed, 23 insertions(+)

diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index 64419eee3..3063f00eb 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -312,6 +312,25 @@ cpuEncode(virArch arch,
 
 
 /**
+ * virCPUDataNew:
+ *
+ * Returns an allocated memory for virCPUData or NULL on error.
+ */
+virCPUDataPtr
+virCPUDataNew(virArch arch)
+{
+virCPUDataPtr data;
+
+if (VIR_ALLOC(data) < 0)
+return NULL;
+
+data->arch = arch;
+
+return data;
+}
+
+
+/**
  * cpuDataFree:
  *
  * @data: CPU data structure to be freed
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index 69c17e72a..ceb1e7256 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -162,6 +162,9 @@ cpuEncode   (virArch arch,
  virCPUDataPtr *vendor)
 ATTRIBUTE_NONNULL(2);
 
+virCPUDataPtr
+virCPUDataNew(virArch arch);
+
 void
 cpuDataFree (virCPUDataPtr data);
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6bbb36b4e..a2bcc6241 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -997,6 +997,7 @@ virCPUCompareXML;
 virCPUConvertLegacy;
 virCPUDataCheckFeature;
 virCPUDataFormat;
+virCPUDataNew;
 virCPUDataParse;
 virCPUGetModels;
 virCPUTranslate;
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 27/33] cputest: Use virArch enum rather then strings

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 tests/cputest.c | 294 
 1 file changed, 148 insertions(+), 146 deletions(-)

diff --git a/tests/cputest.c b/tests/cputest.c
index 406b40dfe..c0a816b60 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -56,7 +56,7 @@ enum cpuTestBoolWithError {
 
 
 struct data {
-const char *arch;
+virArch arch;
 const char *host;
 const char *name;
 const char **models;
@@ -72,14 +72,15 @@ static virQEMUDriver driver;
 
 
 static virCPUDefPtr
-cpuTestLoadXML(const char *arch, const char *name)
+cpuTestLoadXML(virArch arch, const char *name)
 {
 char *xml = NULL;
 xmlDocPtr doc = NULL;
 xmlXPathContextPtr ctxt = NULL;
 virCPUDefPtr cpu = NULL;
 
-if (virAsprintf(, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) 
< 0)
+if (virAsprintf(, "%s/cputestdata/%s-%s.xml",
+abs_srcdir, virArchToString(arch), name) < 0)
 goto cleanup;
 
 if (!(doc = virXMLParseFileCtxt(xml, )))
@@ -96,7 +97,7 @@ cpuTestLoadXML(const char *arch, const char *name)
 
 
 static virCPUDefPtr *
-cpuTestLoadMultiXML(const char *arch,
+cpuTestLoadMultiXML(virArch arch,
 const char *name,
 unsigned int *count)
 {
@@ -108,7 +109,8 @@ cpuTestLoadMultiXML(const char *arch,
 int n;
 size_t i;
 
-if (virAsprintf(, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) 
< 0)
+if (virAsprintf(, "%s/cputestdata/%s-%s.xml",
+abs_srcdir, virArchToString(arch), name) < 0)
 goto cleanup;
 
 if (!(doc = virXMLParseFileCtxt(xml, )))
@@ -145,7 +147,7 @@ cpuTestLoadMultiXML(const char *arch,
 
 
 static int
-cpuTestCompareXML(const char *arch,
+cpuTestCompareXML(virArch arch,
   virCPUDef *cpu,
   const char *name,
   bool updateCPU)
@@ -155,7 +157,7 @@ cpuTestCompareXML(const char *arch,
 int ret = -1;
 
 if (virAsprintf(, "%s/cputestdata/%s-%s.xml",
-abs_srcdir, arch, name) < 0)
+abs_srcdir, virArchToString(arch), name) < 0)
 goto cleanup;
 
 if (!(actual = virCPUDefFormat(cpu, NULL, updateCPU)))
@@ -457,7 +459,7 @@ cpuTestCPUID(bool guest, const void *arg)
 char *result = NULL;
 
 if (virAsprintf(, "%s/cputestdata/%s-cpuid-%s.xml",
-abs_srcdir, data->arch, data->host) < 0)
+abs_srcdir, virArchToString(data->arch), data->host) < 0)
 goto cleanup;
 
 if (virTestLoadFile(hostFile, ) < 0 ||
@@ -523,7 +525,7 @@ cpuTestJSONCPUID(const void *arg)
 int ret = -1;
 
 if (virAsprintf(, "%s/cputestdata/%s-cpuid-%s.json",
-abs_srcdir, data->arch, data->host) < 0 ||
+abs_srcdir, virArchToString(data->arch), data->host) < 0 ||
 virAsprintf(, "cpuid-%s-json", data->host) < 0)
 goto cleanup;
 
@@ -591,7 +593,7 @@ mymain(void)
 VIR_FREE(tmp);  \
 \
 if (virAsprintf(, "%s(%s): %s",   \
-#api, arch, name) < 0) {\
+#api, virArchToString(arch), name) < 0) {   \
 ret = -1;   \
 break;  \
 }   \
@@ -677,159 +679,159 @@ mymain(void)
 } while (0)
 
 /* host to host comparison */
-DO_TEST_COMPARE("x86_64", "host", "host", VIR_CPU_COMPARE_IDENTICAL);
-DO_TEST_COMPARE("x86_64", "host", "host-better", 
VIR_CPU_COMPARE_INCOMPATIBLE);
-DO_TEST_COMPARE("x86_64", "host", "host-worse", VIR_CPU_COMPARE_SUPERSET);
-DO_TEST_COMPARE("x86_64", "host", "host-amd-fake", 
VIR_CPU_COMPARE_INCOMPATIBLE);
-DO_TEST_COMPARE("x86_64", "host", "host-incomp-arch", 
VIR_CPU_COMPARE_INCOMPATIBLE);
-DO_TEST_COMPARE("x86_64", "host", "host-no-vendor", 
VIR_CPU_COMPARE_IDENTICAL);
-DO_TEST_COMPARE("x86_64", "host-no-vendor", "host", 
VIR_CPU_COMPARE_INCOMPATIBLE);
+DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host", 
VIR_CPU_COMPARE_IDENTICAL);
+DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host-better", 
VIR_CPU_COMPARE_INCOMPATIBLE);
+DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host-worse", 
VIR_CPU_COMPARE_SUPERSET);
+DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host-amd-fake", 
VIR_CPU_COMPARE_INCOMPATIBLE);
+DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host-incomp-arch", 
VIR_CPU_COMPARE_INCOMPATIBLE);
+DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host-no-vendor", 
VIR_CPU_COMPARE_IDENTICAL);
+DO_TEST_COMPARE(VIR_ARCH_X86_64, "host-no-vendor", "host", 
VIR_CPU_COMPARE_INCOMPATIBLE);
 
-DO_TEST_COMPARE("ppc64", 

[libvirt] [PATCH v2 24/33] qemu: Use full CPU model expansion on x86

2017-02-15 Thread Jiri Denemark
The static CPU model expansion is designed to return only canonical
names of all CPU properties. TO maintain backward compatibility libvirt
is stuck with different spelling of some of the features, which is only
returned by the full expansion. But in addition to returned all spelling
variants for all properties the full expansion will contain properties
which are not guaranteed to be migration compatible. We need to combine
both expansions. First we need to call the static expansion to limit the
result to migratable properties. Then we can use the result of the
static expansion as an input to the full expansion to get both canonical
names and their aliases.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_capabilities.c   |  10 +-
 src/qemu/qemu_monitor.h|   2 +
 src/qemu/qemu_monitor_json.c   |  28 +-
 .../domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml |   2 -
 tests/domaincapsschemadata/qemu_2.9.0.x86_64.xml   |   3 +-
 .../qemucapabilitiesdata/caps_2.9.0.x86_64.replies | 476 +
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   | 178 ++--
 7 files changed, 657 insertions(+), 42 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 20aaaf8f0..a77e300b7 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2844,6 +2844,7 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
 {
 qemuMonitorCPUModelInfoPtr *modelInfo;
 const char *model;
+qemuMonitorCPUModelExpansionType type;
 
 if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION))
 return 0;
@@ -2856,9 +2857,12 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
 model = "host";
 }
 
-return qemuMonitorGetCPUModelExpansion(mon,
-   
QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC,
-   model, modelInfo);
+if (ARCH_IS_X86(qemuCaps->arch))
+type = QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL;
+else
+type = QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC;
+
+return qemuMonitorGetCPUModelExpansion(mon, type, model, modelInfo);
 }
 
 struct tpmTypeToCaps {
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index b61f1cf54..6407a309f 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -950,6 +950,8 @@ struct _qemuMonitorCPUModelInfo {
 
 typedef enum {
 QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC,
+QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL,
+QEMU_MONITOR_CPU_MODEL_EXPANSION_FULL,
 } qemuMonitorCPUModelExpansionType;
 
 int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index dd7907482..0454571c1 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5026,7 +5026,7 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
 qemuMonitorCPUModelInfoPtr *model_info)
 {
 int ret = -1;
-virJSONValuePtr model;
+virJSONValuePtr model = NULL;
 virJSONValuePtr cmd = NULL;
 virJSONValuePtr reply = NULL;
 virJSONValuePtr data;
@@ -5038,16 +5038,24 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
 
 *model_info = NULL;
 
-if (!(model = virJSONValueNewObject()))
-goto cleanup;
+ retry:
+if (!model) {
+if (!(model = virJSONValueNewObject()))
+goto cleanup;
 
-if (virJSONValueObjectAppendString(model, "name", model_name) < 0)
-goto cleanup;
+if (virJSONValueObjectAppendString(model, "name", model_name) < 0)
+goto cleanup;
+}
 
 switch (type) {
 case QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC:
+case QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL:
 typeStr = "static";
 break;
+
+case QEMU_MONITOR_CPU_MODEL_EXPANSION_FULL:
+typeStr = "full";
+break;
 }
 
 if (!(cmd = qemuMonitorJSONMakeCommand("query-cpu-model-expansion",
@@ -5084,6 +5092,16 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
 goto cleanup;
 }
 
+if (type == QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL) {
+if (!(model = virJSONValueCopy(cpu_model)))
+goto cleanup;
+
+virJSONValueFree(cmd);
+virJSONValueFree(reply);
+type = QEMU_MONITOR_CPU_MODEL_EXPANSION_FULL;
+goto retry;
+}
+
 if (!(cpu_name = virJSONValueObjectGetString(cpu_model, "name"))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-cpu-model-expansion reply data was missing 
'name'"));
diff --git a/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml 
b/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml
index 1827b1d6f..573eb4bb6 100644
--- a/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml
+++ 

[libvirt] [PATCH v2 15/33] cpu_x86: Make virCPUx86DataClear static

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/cpu/cpu_x86.c| 2 +-
 src/cpu/cpu_x86.h| 2 --
 src/libvirt_private.syms | 1 -
 3 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index ccd68b681..0058abef7 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -293,7 +293,7 @@ x86DataCpuid(const virCPUx86Data *data,
 return NULL;
 }
 
-void
+static void
 virCPUx86DataClear(virCPUx86Data *data)
 {
 if (!data)
diff --git a/src/cpu/cpu_x86.h b/src/cpu/cpu_x86.h
index 8c8c6ed4f..bcda0da95 100644
--- a/src/cpu/cpu_x86.h
+++ b/src/cpu/cpu_x86.h
@@ -32,6 +32,4 @@ extern struct cpuArchDriver cpuDriverX86;
 int virCPUx86DataAddCPUID(virCPUx86Data *data,
   const virCPUx86CPUID *cpuid);
 
-void virCPUx86DataClear(virCPUx86Data *data);
-
 #endif /* __VIR_CPU_X86_H__ */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b4f61c87e..cc5be84ea 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1006,7 +1006,6 @@ virCPUUpdate;
 
 # cpu/cpu_x86.h
 virCPUx86DataAddCPUID;
-virCPUx86DataClear;
 
 
 # datatypes.h
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 16/33] cpu: Rework cpuDataFree

2017-02-15 Thread Jiri Denemark
The new API is called virCPUDataFree. Individual CPU drivers are no
longer required to implement their own freeing function unless they need
to free architecture specific data from virCPUData.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/bhyve/bhyve_capabilities.c |  2 +-
 src/cpu/cpu.c  | 21 +++--
 src/cpu/cpu.h  |  4 ++--
 src/cpu/cpu_arm.c  |  7 ---
 src/cpu/cpu_ppc64.c|  6 +++---
 src/cpu/cpu_s390.c |  7 ---
 src/cpu/cpu_x86.c  | 22 +++---
 src/libvirt_private.syms   |  2 +-
 src/libxl/libxl_capabilities.c |  4 ++--
 src/qemu/qemu_capabilities.c   |  2 +-
 src/qemu/qemu_monitor_json.c   |  2 +-
 src/qemu/qemu_parse_command.c  |  2 +-
 src/qemu/qemu_process.c|  2 +-
 src/vmware/vmware_conf.c   |  2 +-
 src/vz/vz_driver.c |  2 +-
 tests/cputest.c|  6 +++---
 tests/qemumonitorjsontest.c|  4 ++--
 17 files changed, 38 insertions(+), 59 deletions(-)

diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c
index 1dc0593af..52d6ca782 100644
--- a/src/bhyve/bhyve_capabilities.c
+++ b/src/bhyve/bhyve_capabilities.c
@@ -68,7 +68,7 @@ virBhyveCapsInitCPU(virCapsPtr caps,
 ret = 0;
 
  cleanup:
-cpuDataFree(data);
+virCPUDataFree(data);
 
 return ret;
 
diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index 3063f00eb..45a17bf46 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -331,7 +331,7 @@ virCPUDataNew(virArch arch)
 
 
 /**
- * cpuDataFree:
+ * virCPUDataFree:
  *
  * @data: CPU data structure to be freed
  *
@@ -340,26 +340,19 @@ virCPUDataNew(virArch arch)
  * Returns nothing.
  */
 void
-cpuDataFree(virCPUDataPtr data)
+virCPUDataFree(virCPUDataPtr data)
 {
 struct cpuArchDriver *driver;
 
 VIR_DEBUG("data=%p", data);
 
-if (data == NULL)
+if (!data)
 return;
 
-if ((driver = cpuGetSubDriver(data->arch)) == NULL)
-return;
-
-if (driver->free == NULL) {
-virReportError(VIR_ERR_NO_SUPPORT,
-   _("cannot free CPU data for %s architecture"),
-   virArchToString(data->arch));
-return;
-}
-
-(driver->free)(data);
+if ((driver = cpuGetSubDriver(data->arch)) && driver->dataFree)
+driver->dataFree(data);
+else
+VIR_FREE(data);
 }
 
 
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index ceb1e7256..0324284b9 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -116,7 +116,7 @@ struct cpuArchDriver {
 virCPUArchCompare   compare;
 cpuArchDecode   decode;
 cpuArchEncode   encode;
-cpuArchDataFree free;
+cpuArchDataFree dataFree;
 cpuArchNodeData nodeData;
 cpuArchBaseline baseline;
 virCPUArchUpdateupdate;
@@ -166,7 +166,7 @@ virCPUDataPtr
 virCPUDataNew(virArch arch);
 
 void
-cpuDataFree (virCPUDataPtr data);
+virCPUDataFree(virCPUDataPtr data);
 
 virCPUDataPtr
 cpuNodeData (virArch arch);
diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c
index 653b06b2f..3a0ee2b14 100644
--- a/src/cpu/cpu_arm.c
+++ b/src/cpu/cpu_arm.c
@@ -37,12 +37,6 @@ static const virArch archs[] = {
 VIR_ARCH_AARCH64,
 };
 
-static void
-armDataFree(virCPUDataPtr data)
-{
-VIR_FREE(data);
-}
-
 
 static int
 virCPUarmUpdate(virCPUDefPtr guest,
@@ -117,7 +111,6 @@ struct cpuArchDriver cpuDriverArm = {
 .compare = virCPUarmCompare,
 .decode = NULL,
 .encode = NULL,
-.free = armDataFree,
 .nodeData = NULL,
 .baseline = armBaseline,
 .update = virCPUarmUpdate,
diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c
index 180ad87d1..a7c8545db 100644
--- a/src/cpu/cpu_ppc64.c
+++ b/src/cpu/cpu_ppc64.c
@@ -705,7 +705,7 @@ ppc64DriverDecode(virCPUDefPtr cpu,
 }
 
 static void
-ppc64DriverFree(virCPUDataPtr data)
+virCPUppc64DataFree(virCPUDataPtr data)
 {
 if (!data)
 return;
@@ -741,7 +741,7 @@ ppc64DriverNodeData(virArch arch)
 return nodeData;
 
  error:
-ppc64DriverFree(nodeData);
+virCPUppc64DataFree(nodeData);
 return NULL;
 }
 
@@ -901,7 +901,7 @@ struct cpuArchDriver cpuDriverPPC64 = {
 .compare= virCPUppc64Compare,
 .decode = ppc64DriverDecode,
 .encode = NULL,
-.free   = ppc64DriverFree,
+.dataFree   = virCPUppc64DataFree,
 .nodeData   = ppc64DriverNodeData,
 .baseline   = ppc64DriverBaseline,
 .update = virCPUppc64Update,
diff --git a/src/cpu/cpu_s390.c b/src/cpu/cpu_s390.c
index 0248328db..9503e8e2b 100644
--- a/src/cpu/cpu_s390.c
+++ b/src/cpu/cpu_s390.c
@@ -33,12 +33,6 @@
 
 static const virArch archs[] = { VIR_ARCH_S390, VIR_ARCH_S390X };
 
-static void
-s390DataFree(virCPUDataPtr data)
-{
-VIR_FREE(data);
-}
-
 static virCPUCompareResult
 virCPUs390Compare(virCPUDefPtr host ATTRIBUTE_UNUSED,
   virCPUDefPtr cpu ATTRIBUTE_UNUSED,
@@ -115,7 +109,6 @@ struct cpuArchDriver 

[libvirt] [PATCH v2 12/33] qemu: Probe "max" CPU model in TCG

2017-02-15 Thread Jiri Denemark
Querying "host" CPU model expansion only makes sense for KVM. QEMU 2.9.0
introduces a new "max" CPU model which can be used to ask QEMU what the
best CPU it can provide to a TCG domain is.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_capabilities.c   | 151 -
 src/qemu/qemu_capabilities.h   |   3 +-
 src/qemu/qemu_capspriv.h   |   3 +-
 src/qemu/qemu_command.c|   2 +-
 src/qemu/qemu_process.c|   5 +-
 .../qemucapabilitiesdata/caps_2.8.0.s390x.replies  |   8 +
 tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml|   2 +-
 .../qemucapabilitiesdata/caps_2.9.0.x86_64.replies | 179 +
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   | 172 +++-
 tests/qemuxml2argvtest.c   |   3 +-
 10 files changed, 480 insertions(+), 48 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 466852d13..2ba82456e 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -400,13 +400,15 @@ struct _virQEMUCaps {
 size_t ngicCapabilities;
 virGICCapability *gicCapabilities;
 
-qemuMonitorCPUModelInfoPtr hostCPUModelInfo;
+qemuMonitorCPUModelInfoPtr kvmCPUModelInfo;
+qemuMonitorCPUModelInfoPtr tcgCPUModelInfo;
 
 /* Anything below is not stored in the cache since the values are
  * re-computed from the other fields or external data sources every
  * time we probe QEMU or load the results from the cache.
  */
-virCPUDefPtr hostCPUModel;
+virCPUDefPtr kvmCPUModel;
+virCPUDefPtr tcgCPUModel;
 };
 
 struct virQEMUCapsSearchData {
@@ -2163,12 +2165,20 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr 
qemuCaps)
 goto error;
 }
 
-if (qemuCaps->hostCPUModel &&
-!(ret->hostCPUModel = virCPUDefCopy(qemuCaps->hostCPUModel)))
+if (qemuCaps->kvmCPUModel &&
+!(ret->kvmCPUModel = virCPUDefCopy(qemuCaps->kvmCPUModel)))
 goto error;
 
-if (qemuCaps->hostCPUModelInfo &&
-!(ret->hostCPUModelInfo = 
qemuMonitorCPUModelInfoCopy(qemuCaps->hostCPUModelInfo)))
+if (qemuCaps->tcgCPUModel &&
+!(ret->tcgCPUModel = virCPUDefCopy(qemuCaps->tcgCPUModel)))
+goto error;
+
+if (qemuCaps->kvmCPUModelInfo &&
+!(ret->kvmCPUModelInfo = 
qemuMonitorCPUModelInfoCopy(qemuCaps->kvmCPUModelInfo)))
+goto error;
+
+if (qemuCaps->tcgCPUModelInfo &&
+!(ret->tcgCPUModelInfo = 
qemuMonitorCPUModelInfoCopy(qemuCaps->tcgCPUModelInfo)))
 goto error;
 
 if (VIR_ALLOC_N(ret->machineTypes, qemuCaps->nmachineTypes) < 0)
@@ -2217,8 +2227,10 @@ void virQEMUCapsDispose(void *obj)
 
 VIR_FREE(qemuCaps->gicCapabilities);
 
-qemuMonitorCPUModelInfoFree(qemuCaps->hostCPUModelInfo);
-virCPUDefFree(qemuCaps->hostCPUModel);
+qemuMonitorCPUModelInfoFree(qemuCaps->kvmCPUModelInfo);
+qemuMonitorCPUModelInfoFree(qemuCaps->tcgCPUModelInfo);
+virCPUDefFree(qemuCaps->kvmCPUModel);
+virCPUDefFree(qemuCaps->tcgCPUModel);
 }
 
 void
@@ -2435,9 +2447,13 @@ virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
 
 
 virCPUDefPtr
-virQEMUCapsGetHostModel(virQEMUCapsPtr qemuCaps)
+virQEMUCapsGetHostModel(virQEMUCapsPtr qemuCaps,
+virDomainVirtType type)
 {
-return qemuCaps->hostCPUModel;
+if (type == VIR_DOMAIN_VIRT_KVM)
+return qemuCaps->kvmCPUModel;
+else
+return qemuCaps->tcgCPUModel;
 }
 
 
@@ -2455,7 +2471,7 @@ virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch);
 
 case VIR_CPU_MODE_HOST_MODEL:
-return !!qemuCaps->hostCPUModel;
+return !!virQEMUCapsGetHostModel(qemuCaps, type);
 
 case VIR_CPU_MODE_CUSTOM:
 if (type == VIR_DOMAIN_VIRT_KVM)
@@ -2822,14 +2838,24 @@ virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr 
qemuCaps,
 
 static int
 virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
-   qemuMonitorPtr mon)
+   qemuMonitorPtr mon,
+   bool tcg)
 {
-if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION) ||
-!virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
+qemuMonitorCPUModelInfoPtr *modelInfo;
+const char *model;
+
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION))
 return 0;
 
-return qemuMonitorGetCPUModelExpansion(mon, "static", "host",
-   >hostCPUModelInfo);
+if (tcg || !virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) {
+modelInfo = >tcgCPUModelInfo;
+model = "max";
+} else {
+modelInfo = >kvmCPUModelInfo;
+model = "host";
+}
+
+return qemuMonitorGetCPUModelExpansion(mon, "static", model, modelInfo);
 }
 
 struct 

[libvirt] [PATCH v2 08/33] docs: Update description of the host-model CPU mode

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 docs/formatdomain.html.in | 28 ++--
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 294d3c467..9e7f7804e 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1272,16 +1272,15 @@
   model even if the destination host contains more capable CPUs for
   the running instance of the guest; but shutting down and restarting
   the guest may present different hardware to the guest according to
-  the capabilities of the new host. Beware, due to the
-  way libvirt detects host CPU and due to the fact libvirt does not
-  talk to QEMU/KVM when creating the CPU model, CPU configuration
-  created using host-model may not work as expected. The
-  guest CPU may differ from the configuration and it may also confuse
-  guest OS by using a combination of CPU features and other parameters
-  (such as CPUID level) that don't work. Until these issues are fixed,
-  it's a good idea to avoid using host-model and use
-  custom mode with just the CPU model from host
-  capabilities XML.
+  the capabilities of the new host. Libvirt older than 3.1.0 or QEMU
+  older than 2.9.0 do not support detection of the host CPU model via
+  QEMU and thus the CPU configuration created using
+  host-model may not work as expected.
+  3.1.0 and QEMU 2.9.0 this mode works the
+  way it was designed and it is indicated by the fallback
+  attribute set to forbid in the host-model CPU
+  definition advertised in domain capabilities XML.
   Since 1.2.11 PowerISA allows
   processors to run VMs in binary compatibility mode supporting an
   older version of ISA.  Libvirt on PowerPC architecture uses the
@@ -1307,6 +1306,15 @@
   a migration is attempted then the guest may hang or crash upon
   resuming execution on the destination host.
 
+
+Both host-model and host-passthrough modes
+make sense when a domain can run directly on the host CPUs without
+(for example, domains with type kvm). The actual host CPU
+is irrelevant for domains with emulated virtual CPUs (such as domains
+with type qemu). However, for backward compatibility
+host-model may be implemented even for domains running on
+emulated CPUs in which case the best CPU the hypervisor is able to
+emulate may be used rather then trying to mimic the host CPU model.
   
 
   model
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 19/33] cpu_x86: Introduce virCPUx86DataSetVendor

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/cpu/cpu_x86.c| 45 +++--
 src/cpu/cpu_x86.h|  3 +++
 src/libvirt_private.syms |  1 +
 3 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index e3f860bc6..ab5e5257d 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -478,6 +478,26 @@ x86DataToVendor(const virCPUx86Data *data,
 }
 
 
+static int
+virCPUx86VendorToCPUID(const char *vendor,
+   virCPUx86CPUID *cpuid)
+{
+if (strlen(vendor) != VENDOR_STRING_LENGTH) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("Invalid CPU vendor string '%s'"), vendor);
+return -1;
+}
+
+cpuid->eax_in = 0;
+cpuid->ecx_in = 0;
+cpuid->ebx = virReadBufInt32LE(vendor);
+cpuid->edx = virReadBufInt32LE(vendor + 4);
+cpuid->ecx = virReadBufInt32LE(vendor + 8);
+
+return 0;
+}
+
+
 static uint32_t
 x86MakeSignature(unsigned int family,
  unsigned int model)
@@ -651,17 +671,9 @@ x86VendorParse(xmlXPathContextPtr ctxt,
vendor->name);
 goto error;
 }
-if (strlen(string) != VENDOR_STRING_LENGTH) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("Invalid CPU vendor string '%s'"), string);
-goto error;
-}
 
-vendor->cpuid.eax_in = 0;
-vendor->cpuid.ecx_in = 0;
-vendor->cpuid.ebx = virReadBufInt32LE(string);
-vendor->cpuid.edx = virReadBufInt32LE(string + 4);
-vendor->cpuid.ecx = virReadBufInt32LE(string + 8);
+if (virCPUx86VendorToCPUID(string, >cpuid) < 0)
+goto error;
 
  cleanup:
 VIR_FREE(string);
@@ -2731,6 +2743,19 @@ virCPUx86DataSetSignature(virCPUDataPtr cpuData,
 }
 
 
+int
+virCPUx86DataSetVendor(virCPUDataPtr cpuData,
+   const char *vendor)
+{
+virCPUx86CPUID cpuid = { 0 };
+
+if (virCPUx86VendorToCPUID(vendor, ) < 0)
+return -1;
+
+return virCPUx86DataAddCPUID(cpuData, );
+}
+
+
 struct cpuArchDriver cpuDriverX86 = {
 .name = "x86",
 .arch = archs,
diff --git a/src/cpu/cpu_x86.h b/src/cpu/cpu_x86.h
index ffbd064b4..ab5394914 100644
--- a/src/cpu/cpu_x86.h
+++ b/src/cpu/cpu_x86.h
@@ -36,4 +36,7 @@ int virCPUx86DataSetSignature(virCPUDataPtr cpuData,
   unsigned int family,
   unsigned int model);
 
+int virCPUx86DataSetVendor(virCPUDataPtr cpuData,
+   const char *vendor);
+
 #endif /* __VIR_CPU_X86_H__ */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6b2dddc95..7338c31e7 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1007,6 +1007,7 @@ virCPUUpdate;
 # cpu/cpu_x86.h
 virCPUx86DataAddCPUID;
 virCPUx86DataSetSignature;
+virCPUx86DataSetVendor;
 
 
 # datatypes.h
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 23/33] qemu: Use enum for CPU model expansion type

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_capabilities.c |  4 +++-
 src/qemu/qemu_monitor.c  |  4 ++--
 src/qemu/qemu_monitor.h  |  6 +-
 src/qemu/qemu_monitor_json.c | 11 +--
 src/qemu/qemu_monitor_json.h |  4 ++--
 5 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index bcfb6b694..20aaaf8f0 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2856,7 +2856,9 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
 model = "host";
 }
 
-return qemuMonitorGetCPUModelExpansion(mon, "static", model, modelInfo);
+return qemuMonitorGetCPUModelExpansion(mon,
+   
QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC,
+   model, modelInfo);
 }
 
 struct tpmTypeToCaps {
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index a434b234b..a987e107e 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3641,11 +3641,11 @@ qemuMonitorCPUDefInfoFree(qemuMonitorCPUDefInfoPtr cpu)
 
 int
 qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
-const char *type,
+qemuMonitorCPUModelExpansionType type,
 const char *model_name,
 qemuMonitorCPUModelInfoPtr *model_info)
 {
-VIR_DEBUG("type=%s model_name=%s", type, model_name);
+VIR_DEBUG("type=%d model_name=%s", type, model_name);
 
 QEMU_CHECK_MONITOR_JSON(mon);
 
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 112f041f1..b61f1cf54 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -948,8 +948,12 @@ struct _qemuMonitorCPUModelInfo {
 qemuMonitorCPUPropertyPtr props;
 };
 
+typedef enum {
+QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC,
+} qemuMonitorCPUModelExpansionType;
+
 int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
-const char *type,
+qemuMonitorCPUModelExpansionType type,
 const char *model_name,
 qemuMonitorCPUModelInfoPtr *model_info);
 
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index d89dfb88d..dd7907482 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5021,7 +5021,7 @@ qemuMonitorJSONParseCPUModelProperty(const char *key,
 
 int
 qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
-const char *type,
+qemuMonitorCPUModelExpansionType type,
 const char *model_name,
 qemuMonitorCPUModelInfoPtr *model_info)
 {
@@ -5034,6 +5034,7 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
 virJSONValuePtr cpu_props;
 qemuMonitorCPUModelInfoPtr machine_model = NULL;
 char const *cpu_name;
+const char *typeStr = "";
 
 *model_info = NULL;
 
@@ -5043,8 +5044,14 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
 if (virJSONValueObjectAppendString(model, "name", model_name) < 0)
 goto cleanup;
 
+switch (type) {
+case QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC:
+typeStr = "static";
+break;
+}
+
 if (!(cmd = qemuMonitorJSONMakeCommand("query-cpu-model-expansion",
-   "s:type", type,
+   "s:type", typeStr,
"a:model", model,
NULL)))
 goto cleanup;
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 79688c82f..59d9f098c 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -354,10 +354,10 @@ int qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
 ATTRIBUTE_NONNULL(2);
 
 int qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
-const char *type,
+qemuMonitorCPUModelExpansionType type,
 const char *model_name,
 qemuMonitorCPUModelInfoPtr *model_info)
-ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
+ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
 
 int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
char ***commands)
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 2/2] apparmor: don't fail on non-apparmor

2017-02-15 Thread Jim Fehlig
Michal Privoznik wrote:
> On 02/03/2017 06:32 PM, Jim Fehlig wrote:
>> If the apparmor security driver is loaded/enabled and domain config
>> contains a  element whose type attribute is not 'apparmor',
>> starting the domain fails when attempting to label resources such
>> as tap FDs.
>>
>> Many of the apparmor driver entry points attempt to retrieve the
>> apparmor security label from the domain def, returning failure if
>> not found. Functions such as AppArmorSetFDLabel fail even though
>> domain config contains an explicit 'none' secuirty driver, e.g.
>>
>>   
>>
>> Change the entry points to succeed if the domain config 
>> is not apparmor. This matches the behavior of the selinux driver.
>>
>> Signed-off-by: Jim Fehlig 
>> ---
>>  src/security/security_apparmor.c | 58 
>> 
>>  1 file changed, 17 insertions(+), 41 deletions(-)
> 
> ACK

Thanks. Forgot to mention it, but I pushed these patches yesterday after
receiving your ACK.

Regards,
Jim


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 00/33] qemu: Detect host CPU model by asking QEMU on x86_64

2017-02-15 Thread Jiri Denemark
Self-NACK. While working on an additional fix, I noticed the
cpu-convert.py script does not set "vendor" property. Since no review
has started yet, I'll send a v2 of this series with required changes to
several patches.

Jirka

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Introduce vGPU mdev framework to libvirt

2017-02-15 Thread Erik Skultety
On Wed, Feb 15, 2017 at 09:50:03AM +0100, Martin Polednik wrote:
> On 14/02/17 09:58 -0700, Alex Williamson wrote:
> > On Tue, 14 Feb 2017 16:50:14 +0100
> > Martin Polednik  wrote:
> > 
> > > On 07/02/17 12:29 -0700, Alex Williamson wrote:
> > > >On Tue, 7 Feb 2017 17:26:51 +0100
> > > >Erik Skultety  wrote:
> > > >
> > > >> On Mon, Feb 06, 2017 at 09:33:14AM -0700, Alex Williamson wrote:
> > > >> > On Mon,  6 Feb 2017 13:19:42 +0100
> > > >> > Erik Skultety  wrote:
> > > >> >
> > > >> > > Finally. It's here. This is the initial suggestion on how libvirt 
> > > >> > > might
> > > >> > > interract with the mdev framework, currently only focussing on the 
> > > >> > > non-managed
> > > >> > > devices, i.e. those pre-created by the user, since that will be 
> > > >> > > revisited once
> > > >> > > we all settled on how the XML should look like, given we might not 
> > > >> > > want to use
> > > >> > > the sysfs path directly as an attribute in the domain XML. My 
> > > >> > > proposal on the
> > > >> > > XML is the following:
> > > >> > >
> > > >> > > 
> > > >> > > 
> > > >> > > 
> > > >> > >  > > >> > > function='0x00'>
> > > >> > > vGPU_UUID
> > > >> > > 
> > > >> > > 
> > > >> > > 
> > > >> > >
> > > >> > > So the mediated device is identified by the physical parent device 
> > > >> > > visible on
> > > >> > > the host and a UUID which allows us to construct the sysfs path by 
> > > >> > > ourselves,
> > > >> > > which we then put on the QEMU's command line.
> > > >> >
> > > >> > Based on your test code, I think you're creating something like this:
> > > >> >
> > > >> > -device 
> > > >> > vfio-pci,sysfsdev=/sys/class/mdev_bus/:00:03.0/53764d0e-85a0-42b4-af5c-2046b460b1dc
> > > >> >
> > > >> > That would explain the need for the parent device address, but that's
> > > >> > an entirely self inflicted requirement.  For a managed="no" 
> > > >> > scenarios,
> > > >> > we shouldn't need the parent, we can get to the mdev device
> > > >> > via /sys/bus/mdev/devices/53764d0e-85a0-42b4-af5c-2046b460b1dc.  So 
> > > >> > it
> > > >>
> > > >> True, for managed="no" would this path be a nice optimization.
> > > >>
> > > >> > seems that the UUID should be the only required source element for
> > > >> > managed="no".
> > > >> >
> > > >> > For managed="yes", it seems like the parent device is still an 
> > > >> > optional
> > > >>
> > > >> The reason I went with the parent address element (and purposely 
> > > >> neglecting the
> > > >> sample mtty driver) was that I assumed any modern mdev capable HW 
> > > >> would be
> > > >> accessible through the PCI bus on the host. Also I wanted to 
> > > >> explicitly hint
> > > >> libvirt as much as possible which parent device a vGPU device instance 
> > > >> should
> > > >> be created on in case there are more than one of them, rather then 
> > > >> scanning
> > > >> sysfs for a suitable parent which actually supports the given vGPU 
> > > >> type.
> > > >>
> > > >> > field.  The most important thing that libvirt needs to know when
> > > >> > creating a mdev device for a VM is the mdev type name.  The parent
> > > >> > device should be an optional field to help higher level management
> > > >> > tools deal with placement of the device for locality or load 
> > > >> > balancing.
> > > >> > Also, we can't assume that the parent device is a PCI device, the
> > > >> > sample mtty driver already breaks this assumption.
> > > >>
> > > >> Since we need to assume non-PCI devices and we still need to enable 
> > > >> management
> > > >> to hint libvirt about the parent to utilize load balancing and stuff, 
> > > >> I've come
> > > >> up with the following adjustments/ideas on how to reflect that in the 
> > > >> XML:
> > > >> - still use the address element but use it with the 'type' attribute 
> > > >> [1] (still
> > > >>   breaks the sample mtty driver though) while making the element truly 
> > > >> optional
> > > >>   if I'm going to be outvoted in favor of scanning the directory for a 
> > > >> suitable
> > > >>   parent device on our own, rather than requiring the user to provide 
> > > >> that
> > > >>
> > > >> - providing either an attribute or a standalone element for the parent 
> > > >> device
> > > >>   name, like a string version of the PCI address or whatever form the 
> > > >> parent
> > > >>   device comes in (doesn't break the mtty driver but I don't quite 
> > > >> like this)
> > > >>
> > > >> - providing a path element/attribute to sysfs pointing to the parent 
> > > >> device
> > > >>   which I'm afraid is what Daniel is not in favor of libvirt doing
> > > >>
> > > >> So, this is what I've so far come up with in terms of hinting libvirt 
> > > >> about the
> > > >> parent device, do you have any input on this, maybe some more ideas on 
> > > >> how we
> > > >> should identify the parent device?
> > > >
> > > >IMO, if we cannot account for the mtty sample 

Re: [libvirt] [v6 00/10] Support cache tune in libvirt

2017-02-15 Thread Martin Kletzander

On Wed, Feb 15, 2017 at 01:41:43PM +0800, Eli Qiao wrote:

Addressed comment from v6 -> v5

Marcelo:
  * Support other APPs to operate /sys/fs/resctrl at same time

Libvirt will scan /sys/fs/resctrl again before doing cache allocation.
patch 10 will address this.

Addressed comment from v4 -> v5:

Marcelo:
  * Several typos
  * Use flock instead of virFileLock

Addressed comment from v3 -> v4:

Daniel & Marcelo:
  * Added concurrence support

Addressed comment from v2 -> v3:

Daniel:
 * Fixed coding style, passed `make check` and `make syntax-check`

 * Variables renaming and move from header file to c file.

 * For locking/mutex support, no progress.

 There are some discussion from mailing list, but I can not find a better
 way to add locking support without performance impact.

 I'll explain the process and please help to advice what shoud we do.

 VM create:
 1) Get the cache left value on each bank of the host. This should be
shared amount all VMs.
 2) Calculate the schemata on the bank based on all created resctrl
domain's schemata
 3) Calculate the default schemata by scaning all domain's schemata.
 4) Flush default schemata to /sys/fs/resctrl/schemata

 VM destroy:
 1) Remove the resctrl domain of that VM
 2) Recalculate default schemata
 3) Flush default schemata to /sys/fs/resctrl/schemata

 The key point is that all VMs shares /sys/fs/resctrl/schemata, and
 when a VM create a resctrl domain, the schemata of that VM depends on
 the default schemata and all other exsited schematas. So a global
 mutex is reqired.

 Before calculate a schemata or update default schemata, libvirt
 should gain this global mutex.

 I will try to think more about how to support this gracefully in next
 patch set.

Marcelo:
 * Added vcpu support for cachetune, this will allow user to define which
   vcpu using which cache allocation bank.

   

   vcpus is a cpumap, the vcpu pids will be added to tasks file

 * Added cdp compatible, user can specify l3 cache even host enable cdp.
   See patch 8.
   On a cdp enabled host, specify l3code/l3data by

   

   This will create a schemata like:
   L3data:0=0xff00;...
   L3code:0=0xff00;...

 * Would you please help to test if the functions work.

Martin:
 * Xml test case, I have no time to work on this yet, would you please
   show me an example, would like to amend it later.



look at tests/qemuxml2xmltest, it is called 'qemu...', but it actually
just parses XML and then formats it back and checks the result (that
there is no information lost.  Input XMLs are in tests/qemuxml2argvdata/
and the desired outputs are in tests/qemuxml2xmloutdata/.  For XMLs that
should not change, the output XML is a symlink to the input one.  For
negative tests, there doesn't have to be any output XML (of course).


This series patches are for supportting CAT featues, which also
called cache tune in libvirt.

First to expose cache information which could be tuned in capabilites XML.
Then add new domain xml element support to add cacahe bank which will apply
on this libvirt domain.

This series patches add a util file `resctrl.c/h`, an interface to talk with
linux kernel's system fs.

There are still one TODO left:
   1. Expose a new public interface to get free cache information.
   2. Expose a new public interface to set cachetune lively.

Some discussion about this feature support can be found from:
https://www.redhat.com/archives/libvir-list/2017-January/msg00644.html


Eli Qiao (10):
 Resctrl: Add some utils functions
 Resctrl: expose cache information to capabilities
 Resctrl: Add new xml element to support cache tune
 Resctrl: Add private interface to set cachebanks
 Qemu: Set cache banks
 Resctrl: enable l3code/l3data
 Resctrl: Make sure l3data/l3code are pairs
 Resctrl: Compatible mode for cdp enabled
 Resctrl: concurrence support
 Resctrl: Scan resctrl before doing cache allocation

docs/schemas/domaincommon.rng |   46 ++
include/libvirt/virterror.h   |1 +
po/POTFILES.in|1 +
src/Makefile.am   |1 +
src/conf/capabilities.c   |   56 ++
src/conf/capabilities.h   |   23 +
src/conf/domain_conf.c|  182 +++
src/conf/domain_conf.h|   19 +
src/libvirt_private.syms  |   11 +
src/nodeinfo.c|   64 +++
src/nodeinfo.h|1 +
src/qemu/qemu_capabilities.c  |8 +
src/qemu/qemu_driver.c|6 +
src/qemu/qemu_process.c   |   53 ++
src/util/virerror.c   |1 +
src/util/virresctrl.c | 1208 +
src/util/virresctrl.h |   88 +++
17 files changed, 1769 insertions(+)
create mode 100644 src/util/virresctrl.c
create mode 100644 src/util/virresctrl.h

--
1.9.1



signature.asc
Description: Digital signature
--
libvir-list mailing list

Re: [libvirt] [PATCH 2/2] util: storage: add JSON backing volume parser 'raw' block driver

2017-02-15 Thread Richard W.M. Jones
On Wed, Feb 15, 2017 at 12:53:39PM +0100, Tomáš Golembiovský wrote:
> On Wed, 15 Feb 2017 10:55:24 +
> "Richard W.M. Jones"  wrote:
> 
> > On Tue, Feb 14, 2017 at 10:03:54PM +0100, Tomáš Golembiovský wrote:
> > > Hi,
> > > 
> > > On Tue, 14 Feb 2017 15:58:45 +
> > > "Richard W.M. Jones"  wrote:
> > >   
> > > > The patches compile.
> > > > 
> > > > I looked at both commits and they at least superficially seem
> > > > sensible.  I'm not intimately familiar enough with the original code
> > > > to review this fully.
> > > > 
> > > > However I want to try to test this using libguestfs.  I believe the
> > > > following test case should be sufficient:
> > > > 
> > > >   $ cd /var/tmp
> > > >   $ truncate -s 1M backing.img
> > > >   $ qemu-img create \
> > > >   -b 'json:{"driver":"raw", 
> > > > "file":{"filename":"/var/tmp/backing.img"}}' \  
> > > 
> > > The problem lies in the JSON here. Libvirt lacks the driver probing
> > > mechanism QEMU has (which makes sense). That means one has to be
> > > explicit about the drivers. Try with the following backing definition:
> > > 
> > > json:{"driver":"raw", "file":{ "driver":"file", 
> > > "filename":"/var/tmp/backing.img"}}  
> > 
> > OK, that works.  However it also works with the unpatched version of
> > libvirt, so it's not proof that these patches fix any problem.
> 
> Ah, sorry. I didn't notice your JSON was bad from the start and I just
> blindly extended it. The correct JSON should look like this:
> 
> json: {
> "file": {
> "driver":"raw",
> "file": {
> "driver":"file",
> "filename":"/var/tmp/backing.img"
> }
> }
> }

Ok that does now demonstrate the fix.

For reference, here is the full test:

  $ cd /var/tmp
  $ rm -f backing.img
  $ truncate -s 10M backing.img
  $ qemu-img create -b 'json:{"file":{"driver":"raw", "file":{"driver":"file", 
"filename":"/var/tmp/backing.img"}}}' -f qcow2 overlay.qcow2

With old libvirt:

  $ guestfish -a /var/tmp/overlay.qcow2 run
  libguestfs: error: could not create appliance through libvirt.
  
  Try running qemu directly without libvirt using this environment variable:
  export LIBGUESTFS_BACKEND=direct
  
  Original error from libvirt: internal error: missing parser implementation 
for JSON backing volume driver 'raw' [code=1 int1=-1]

With patched libvirt:

  $ killall libvirtd
  $ ~/d/libvirt/run guestfish -a /var/tmp/overlay.qcow2 run
  [no errors printed]

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 2/2] util: storage: add JSON backing volume parser 'raw' block driver

2017-02-15 Thread Tomáš Golembiovský
On Wed, 15 Feb 2017 10:55:24 +
"Richard W.M. Jones"  wrote:

> On Tue, Feb 14, 2017 at 10:03:54PM +0100, Tomáš Golembiovský wrote:
> > Hi,
> > 
> > On Tue, 14 Feb 2017 15:58:45 +
> > "Richard W.M. Jones"  wrote:
> >   
> > > The patches compile.
> > > 
> > > I looked at both commits and they at least superficially seem
> > > sensible.  I'm not intimately familiar enough with the original code
> > > to review this fully.
> > > 
> > > However I want to try to test this using libguestfs.  I believe the
> > > following test case should be sufficient:
> > > 
> > >   $ cd /var/tmp
> > >   $ truncate -s 1M backing.img
> > >   $ qemu-img create \
> > >   -b 'json:{"driver":"raw", 
> > > "file":{"filename":"/var/tmp/backing.img"}}' \  
> > 
> > The problem lies in the JSON here. Libvirt lacks the driver probing
> > mechanism QEMU has (which makes sense). That means one has to be
> > explicit about the drivers. Try with the following backing definition:
> > 
> > json:{"driver":"raw", "file":{ "driver":"file", 
> > "filename":"/var/tmp/backing.img"}}  
> 
> OK, that works.  However it also works with the unpatched version of
> libvirt, so it's not proof that these patches fix any problem.

Ah, sorry. I didn't notice your JSON was bad from the start and I just
blindly extended it. The correct JSON should look like this:

json: {
"file": {
"driver":"raw",
"file": {
"driver":"file",
"filename":"/var/tmp/backing.img"
}
}
}


Tomas

> 
> Rich.
> 
> -- 
> Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
> Read my programming and virtualization blog: http://rwmj.wordpress.com
> virt-df lists disk usage of guests without needing to install any
> software inside the virtual machine.  Supports Linux and Windows.
> http://people.redhat.com/~rjones/virt-df/


-- 
Tomáš Golembiovský 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v3 2/2] libxl: add tunnelled migration support

2017-02-15 Thread Joao Martins


On 02/15/2017 11:17 AM, Joao Martins wrote:
> From: Bob Liu 
> 
> Tunnelled migration doesn't require any extra network connections
> beside the libvirt daemon.  It's capable of strong encryption and the
> default option of openstack-nova.
> 
> This patch adds the tunnelled migration(Tunnel3params) support to
> libxl.  On the source side, the data flow is:
> 
>  * libxlDoMigrateSend() -> pipe libxlTunnel3MigrationFunc() polls pipe
>  * out and then write to dest stream.
> 
> While on the destination side:
>  * Stream -> pipe -> 'recvfd of libxlDomainStartRestore'
> 
> The usage is the same as p2p migration, execpt adding one extra
> '--tunnelled' to the libvirt p2p migration command.
> 
> Signed-off-by: Bob Liu 
> Signed-off-by: Joao Martins 
> ---
> v3:
>  * virStream{Send,Finish} and VIR_ALLOC_N already report errors,
>  hence removing the virReportError calls from its error paths.
>  * Revert top-level migration APIs to initial v1 approach.
> v2:
>  ( Comments from Jim )
>  * Adjust common preparetunnel function reflecting v1 suggestions
>- Using common top-level Prepare function by adding is_tunnel variable
>- Using libxl_migration PrepareAny added in patch 1
>- virHook support in PrepareTunnel3
>  * Move virThreadPtr from libxlTunnelMigrationThread into libxlTunnelControl
>  * Rename function local variable from tmThreadPtr to arg
>  * Remove redundant assignment "tmThreadPtr = >tmThread;" always being not
>  null.
>  * Adjust debug message to "poll returned 0" as opposed to "poll got
>  timeout" as the latter might not always be the case.
> ---
>  src/libxl/libxl_driver.c|  58 +-
>  src/libxl/libxl_migration.c | 275 
> +---
>  src/libxl/libxl_migration.h |   9 ++
>  3 files changed, 325 insertions(+), 17 deletions(-)
> 
> diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
> index 74cb05a..e5b8f48 100644
> --- a/src/libxl/libxl_driver.c
> +++ b/src/libxl/libxl_driver.c
> @@ -5934,6 +5934,61 @@ libxlDomainMigrateBegin3Params(virDomainPtr domain,
>  }
>  
>  static int
> +libxlDomainMigratePrepareTunnel3Params(virConnectPtr dconn,
> +   virStreamPtr st,
> +   virTypedParameterPtr params,
> +   int nparams,
> +   const char *cookiein,
> +   int cookieinlen,
> +   char **cookieout ATTRIBUTE_UNUSED,
> +   int *cookieoutlen ATTRIBUTE_UNUSED,
> +   unsigned int flags)
> +{
> +libxlDriverPrivatePtr driver = dconn->privateData;
> +virDomainDefPtr def = NULL;
> +const char *dom_xml = NULL;
> +const char *dname = NULL;
> +const char *uri_in = NULL;
> +
> +#ifdef LIBXL_HAVE_NO_SUSPEND_RESUME
> +virReportUnsupportedError();
> +return -1;
> +#endif
> +
> +virCheckFlags(LIBXL_MIGRATION_FLAGS, -1);
> +if (virTypedParamsValidate(params, nparams, LIBXL_MIGRATION_PARAMETERS) 
> < 0)
> +goto error;
> +
> +if (virTypedParamsGetString(params, nparams,
> +VIR_MIGRATE_PARAM_DEST_XML,
> +_xml) < 0 ||
> +virTypedParamsGetString(params, nparams,
> +VIR_MIGRATE_PARAM_DEST_NAME,
> +) < 0 ||
> +virTypedParamsGetString(params, nparams,
> +VIR_MIGRATE_PARAM_URI,
> +_in) < 0)
> +
> +goto error;
> +
> +if (!(def = libxlDomainMigrationPrepareDef(driver, dom_xml, dname)))
> +goto error;
> +
> +if (virDomainMigratePrepareTunnel3ParamsEnsureACL(dconn, def) < 0)
> +goto error;
> +
> +if (libxlDomainMigrationPrepareTunnel3(dconn, st, , cookiein,
> +   cookieinlen, flags) < 0)
> +goto error;
> +
> +return 0;
> +
> + error:
> +virDomainDefFree(def);
> +return -1;
> +}
> +
> +static int
>  libxlDomainMigratePrepare3Params(virConnectPtr dconn,
>   virTypedParameterPtr params,
>   int nparams,
> @@ -6033,7 +6088,7 @@ libxlDomainMigratePerform3Params(virDomainPtr dom,
>  if (virDomainMigratePerform3ParamsEnsureACL(dom->conn, vm->def) < 0)
>  goto cleanup;
>  
> -if (flags & VIR_MIGRATE_PEER2PEER) {
> +if ((flags & (VIR_MIGRATE_TUNNELLED | VIR_MIGRATE_PEER2PEER))) {
>  if (libxlDomainMigrationPerformP2P(driver, vm, dom->conn, dom_xml,
> dconnuri, uri, dname, flags) < 0)
>  goto cleanup;
> @@ -6518,6 +6573,7 @@ static virHypervisorDriver libxlHypervisorDriver = {
>  .nodeDeviceReset = libxlNodeDeviceReset, /* 1.2.3 */
>  

[libvirt] [PATCH v3 2/2] libxl: add tunnelled migration support

2017-02-15 Thread Joao Martins
From: Bob Liu 

Tunnelled migration doesn't require any extra network connections
beside the libvirt daemon.  It's capable of strong encryption and the
default option of openstack-nova.

This patch adds the tunnelled migration(Tunnel3params) support to
libxl.  On the source side, the data flow is:

 * libxlDoMigrateSend() -> pipe libxlTunnel3MigrationFunc() polls pipe
 * out and then write to dest stream.

While on the destination side:
 * Stream -> pipe -> 'recvfd of libxlDomainStartRestore'

The usage is the same as p2p migration, execpt adding one extra
'--tunnelled' to the libvirt p2p migration command.

Signed-off-by: Bob Liu 
Signed-off-by: Joao Martins 
---
v3:
 * virStream{Send,Finish} and VIR_ALLOC_N already report errors,
 hence removing the virReportError calls from its error paths.
 * Revert top-level migration APIs to initial v1 approach.
v2:
 ( Comments from Jim )
 * Adjust common preparetunnel function reflecting v1 suggestions
   - Using common top-level Prepare function by adding is_tunnel variable
   - Using libxl_migration PrepareAny added in patch 1
   - virHook support in PrepareTunnel3
 * Move virThreadPtr from libxlTunnelMigrationThread into libxlTunnelControl
 * Rename function local variable from tmThreadPtr to arg
 * Remove redundant assignment "tmThreadPtr = >tmThread;" always being not
 null.
 * Adjust debug message to "poll returned 0" as opposed to "poll got
 timeout" as the latter might not always be the case.
---
 src/libxl/libxl_driver.c|  58 +-
 src/libxl/libxl_migration.c | 275 +---
 src/libxl/libxl_migration.h |   9 ++
 3 files changed, 325 insertions(+), 17 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 74cb05a..e5b8f48 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -5934,6 +5934,61 @@ libxlDomainMigrateBegin3Params(virDomainPtr domain,
 }
 
 static int
+libxlDomainMigratePrepareTunnel3Params(virConnectPtr dconn,
+   virStreamPtr st,
+   virTypedParameterPtr params,
+   int nparams,
+   const char *cookiein,
+   int cookieinlen,
+   char **cookieout ATTRIBUTE_UNUSED,
+   int *cookieoutlen ATTRIBUTE_UNUSED,
+   unsigned int flags)
+{
+libxlDriverPrivatePtr driver = dconn->privateData;
+virDomainDefPtr def = NULL;
+const char *dom_xml = NULL;
+const char *dname = NULL;
+const char *uri_in = NULL;
+
+#ifdef LIBXL_HAVE_NO_SUSPEND_RESUME
+virReportUnsupportedError();
+return -1;
+#endif
+
+virCheckFlags(LIBXL_MIGRATION_FLAGS, -1);
+if (virTypedParamsValidate(params, nparams, LIBXL_MIGRATION_PARAMETERS) < 
0)
+goto error;
+
+if (virTypedParamsGetString(params, nparams,
+VIR_MIGRATE_PARAM_DEST_XML,
+_xml) < 0 ||
+virTypedParamsGetString(params, nparams,
+VIR_MIGRATE_PARAM_DEST_NAME,
+) < 0 ||
+virTypedParamsGetString(params, nparams,
+VIR_MIGRATE_PARAM_URI,
+_in) < 0)
+
+goto error;
+
+if (!(def = libxlDomainMigrationPrepareDef(driver, dom_xml, dname)))
+goto error;
+
+if (virDomainMigratePrepareTunnel3ParamsEnsureACL(dconn, def) < 0)
+goto error;
+
+if (libxlDomainMigrationPrepareTunnel3(dconn, st, , cookiein,
+   cookieinlen, flags) < 0)
+goto error;
+
+return 0;
+
+ error:
+virDomainDefFree(def);
+return -1;
+}
+
+static int
 libxlDomainMigratePrepare3Params(virConnectPtr dconn,
  virTypedParameterPtr params,
  int nparams,
@@ -6033,7 +6088,7 @@ libxlDomainMigratePerform3Params(virDomainPtr dom,
 if (virDomainMigratePerform3ParamsEnsureACL(dom->conn, vm->def) < 0)
 goto cleanup;
 
-if (flags & VIR_MIGRATE_PEER2PEER) {
+if ((flags & (VIR_MIGRATE_TUNNELLED | VIR_MIGRATE_PEER2PEER))) {
 if (libxlDomainMigrationPerformP2P(driver, vm, dom->conn, dom_xml,
dconnuri, uri, dname, flags) < 0)
 goto cleanup;
@@ -6518,6 +6573,7 @@ static virHypervisorDriver libxlHypervisorDriver = {
 .nodeDeviceReset = libxlNodeDeviceReset, /* 1.2.3 */
 .domainMigrateBegin3Params = libxlDomainMigrateBegin3Params, /* 1.2.6 */
 .domainMigratePrepare3Params = libxlDomainMigratePrepare3Params, /* 1.2.6 
*/
+.domainMigratePrepareTunnel3Params = 
libxlDomainMigratePrepareTunnel3Params, /* 3.1.0 */
 .domainMigratePerform3Params = 

[libvirt] [PATCH v3 0/2] libxl: tunnelled migration support

2017-02-15 Thread Joao Martins
Hey!

Presented herewith is take 4 from tunnelled migration addressing all previous
comments. No functional changes from v2, only revert to v1 on the top level
migration functions and removing unnecessary usage of virReportError.

Thanks,
Joao

Bob Liu (1):
  libxl: add tunnelled migration support

Joao Martins (1):
  libxl: refactor libxlDomainMigrationPrepare

 src/libxl/libxl_driver.c|  58 ++-
 src/libxl/libxl_migration.c | 367 +---
 src/libxl/libxl_migration.h |   9 ++
 3 files changed, 381 insertions(+), 53 deletions(-)

-- 
2.1.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2] Ensure disk names follow the disk name regex

2017-02-15 Thread Nitesh Konkar
Currently disk names do not follow the
(regex) /^[fhv]d[a-z]+[0-9]*$/ completely
and hence one can assign disk names like
vd2 etc. This patch ensures that the
disk names follow the regex mentioned.
This patch also adds a testcase.

Signed-off-by: Nitesh Konkar 
---
 src/util/virutil.c | 2 +-
 tests/utiltest.c   | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/util/virutil.c b/src/util/virutil.c
index 91178d1..2796671 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -563,7 +563,7 @@ int virDiskNameParse(const char *name, int *disk, int 
*partition)
 }
 }
 
-if (!ptr)
+if (!ptr || !c_islower(*ptr))
 return -1;
 
 for (i = 0; *ptr; i++) {
diff --git a/tests/utiltest.c b/tests/utiltest.c
index 9b7a4a3..bd55d44 100644
--- a/tests/utiltest.c
+++ b/tests/utiltest.c
@@ -37,7 +37,8 @@ static struct testDiskName diskNamesPart[] = {
 };
 
 static const char* diskNamesInvalid[] = {
-"sda00", "sda01", "sdb-1"
+"sda00", "sda01", "sdb-1",
+"vd2"
 };
 
 static int
-- 
1.9.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 1/2] libxl: refactor libxlDomainMigrationPrepare

2017-02-15 Thread Joao Martins
The newly introduced function libxlDomainMigrationPrepareAny
will be shared between P2P and tunnelled variations.

Signed-off-by: Joao Martins 
---
 src/libxl/libxl_migration.c | 92 +++--
 1 file changed, 56 insertions(+), 36 deletions(-)

diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c
index a471d2a..7beabd2 100644
--- a/src/libxl/libxl_migration.c
+++ b/src/libxl/libxl_migration.c
@@ -483,41 +483,26 @@ libxlDomainMigrationPrepareDef(libxlDriverPrivatePtr 
driver,
 return def;
 }
 
-int
-libxlDomainMigrationPrepare(virConnectPtr dconn,
-virDomainDefPtr *def,
-const char *uri_in,
-char **uri_out,
-const char *cookiein,
-int cookieinlen,
-unsigned int flags)
+static int
+libxlDomainMigrationPrepareAny(virConnectPtr dconn,
+   virDomainDefPtr *def,
+   const char *cookiein,
+   int cookieinlen,
+   libxlMigrationCookiePtr *mig,
+   char **xmlout,
+   bool *taint_hook)
 {
 libxlDriverPrivatePtr driver = dconn->privateData;
 libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
-libxlMigrationCookiePtr mig = NULL;
-virDomainObjPtr vm = NULL;
-char *hostname = NULL;
-char *xmlout = NULL;
-unsigned short port;
-char portstr[100];
-virURIPtr uri = NULL;
-virNetSocketPtr *socks = NULL;
-size_t nsocks = 0;
-int nsocks_listen = 0;
-libxlMigrationDstArgs *args = NULL;
-bool taint_hook = false;
-libxlDomainObjPrivatePtr priv = NULL;
-size_t i;
-int ret = -1;
 
-if (libxlMigrationEatCookie(cookiein, cookieinlen, ) < 0)
-goto error;
+if (libxlMigrationEatCookie(cookiein, cookieinlen, mig) < 0)
+return -1;
 
-if (mig->xenMigStreamVer > LIBXL_SAVE_VERSION) {
+if ((*mig)->xenMigStreamVer > LIBXL_SAVE_VERSION) {
 virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("Xen migration stream version '%d' is not supported 
on this host"),
-   mig->xenMigStreamVer);
-goto error;
+   (*mig)->xenMigStreamVer);
+return -1;
 }
 
 /* Let migration hook filter domain XML */
@@ -528,29 +513,29 @@ libxlDomainMigrationPrepare(virConnectPtr dconn,
 if (!(xml = virDomainDefFormat(*def, cfg->caps,
VIR_DOMAIN_XML_SECURE |
VIR_DOMAIN_XML_MIGRATABLE)))
-goto error;
+return -1;
 
 hookret = virHookCall(VIR_HOOK_DRIVER_LIBXL, (*def)->name,
   VIR_HOOK_LIBXL_OP_MIGRATE, VIR_HOOK_SUBOP_BEGIN,
-  NULL, xml, );
+  NULL, xml, xmlout);
 VIR_FREE(xml);
 
 if (hookret < 0) {
-goto error;
+return -1;
 } else if (hookret == 0) {
-if (virStringIsEmpty(xmlout)) {
+if (virStringIsEmpty(*xmlout)) {
 VIR_DEBUG("Migrate hook filter returned nothing; using the"
   " original XML");
 } else {
 virDomainDefPtr newdef;
 
-VIR_DEBUG("Using hook-filtered domain XML: %s", xmlout);
-newdef = virDomainDefParseString(xmlout, cfg->caps, 
driver->xmlopt,
+VIR_DEBUG("Using hook-filtered domain XML: %s", *xmlout);
+newdef = virDomainDefParseString(*xmlout, cfg->caps, 
driver->xmlopt,
  NULL,
  VIR_DOMAIN_DEF_PARSE_INACTIVE 
|
  
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE);
 if (!newdef)
-goto error;
+return -1;
 
 /* TODO At some stage we will want to have some check of what 
the user
  * did in the hook. */
@@ -560,17 +545,52 @@ libxlDomainMigrationPrepare(virConnectPtr dconn,
 /* We should taint the domain here. However, @vm and therefore
  * privateData too are still NULL, so just notice the fact and
  * taint it later. */
-taint_hook = true;
+*taint_hook = true;
 }
 }
 }
 
+return 0;
+}
+
+int
+libxlDomainMigrationPrepare(virConnectPtr dconn,
+virDomainDefPtr *def,
+const char *uri_in,
+char **uri_out,
+const char *cookiein,
+int cookieinlen,
+unsigned int flags)
+{
+   

Re: [libvirt] [PATCH 2/2] util: storage: add JSON backing volume parser 'raw' block driver

2017-02-15 Thread Richard W.M. Jones
On Tue, Feb 14, 2017 at 10:03:54PM +0100, Tomáš Golembiovský wrote:
> Hi,
> 
> On Tue, 14 Feb 2017 15:58:45 +
> "Richard W.M. Jones"  wrote:
> 
> > The patches compile.
> > 
> > I looked at both commits and they at least superficially seem
> > sensible.  I'm not intimately familiar enough with the original code
> > to review this fully.
> > 
> > However I want to try to test this using libguestfs.  I believe the
> > following test case should be sufficient:
> > 
> >   $ cd /var/tmp
> >   $ truncate -s 1M backing.img
> >   $ qemu-img create \
> >   -b 'json:{"driver":"raw", 
> > "file":{"filename":"/var/tmp/backing.img"}}' \
> 
> The problem lies in the JSON here. Libvirt lacks the driver probing
> mechanism QEMU has (which makes sense). That means one has to be
> explicit about the drivers. Try with the following backing definition:
> 
> json:{"driver":"raw", "file":{ "driver":"file", 
> "filename":"/var/tmp/backing.img"}}

OK, that works.  However it also works with the unpatched version of
libvirt, so it's not proof that these patches fix any problem.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] qemu_conf: Check for namespaces availability more wisely

2017-02-15 Thread Daniel P. Berrange
On Wed, Feb 15, 2017 at 11:19:24AM +0100, Michal Privoznik wrote:
> On 02/15/2017 10:43 AM, Daniel P. Berrange wrote:
> > On Wed, Feb 15, 2017 at 10:20:27AM +0100, Michal Privoznik wrote:
> >> The bare fact that mnt namespace is available is not enough for
> >> us to allow/enable qemu namespaces feature. There are other
> >> requirements: we must copy all the ACL & SELinux labels otherwise
> >> we might grant access that is administratively forbidden or vice
> >> versa.
> >> At the same time, the check for namespace prerequisites is moved
> >> from domain startup time to qemu.conf parser as it doesn't make
> >> much sense to allow users to start misconfigured libvirt just to
> >> find out they can't start a single domain.
> >>
> >> Signed-off-by: Michal Privoznik 
> >> ---
> >>  src/qemu/qemu_conf.c   | 20 
> >>  src/qemu/qemu_conf.h   |  3 ++-
> >>  src/qemu/qemu_domain.c | 43 ---
> >>  src/qemu/qemu_domain.h |  2 ++
> >>  src/qemu/qemu_driver.c |  2 +-
> >>  5 files changed, 49 insertions(+), 21 deletions(-)
> >>
> 
> 
> >> +bool
> >> +qemuDomainNamespaceAvailable(qemuDomainNamespace ns)
> >> +{
> >> +
> >> +switch (ns) {
> >> +case QEMU_DOMAIN_NS_MOUNT:
> >> +#if !defined(__linux__)
> >> +/* Namespaces are Linux specific. */
> >> +return false;
> >> +#endif
> >> +#if !defined(HAVE_SYS_ACL_H) || !defined(WITH_SELINUX)
> >> +/* We can't create the exact copy of paths if either of
> >> + * these is not available. */
> >> +return false;
> >> +#endif
> > 
> > Pretty sure this will cause the compiler to complain about
> > unreachable code paths because you'll get
> > 
> > return false;
> > return false;
> > if (virProcessNamespaceAvailable()
> 
> Ah. Obviously. What about this?
> 
> +bool
> +qemuDomainNamespaceAvailable(qemuDomainNamespace ns ATTRIBUTE_UNUSED)
> +{
> +#if !defined(__linux__)
> +/* Namespaces are Linux specific. */
> +return false;
> +
> +#else /* defined(__linux__) */
> +
> +switch (ns) {
> +case QEMU_DOMAIN_NS_MOUNT:
> +# if !defined(HAVE_SYS_ACL_H) || !defined(WITH_SELINUX)
> +/* We can't create the exact copy of paths if either of
> + * these is not available. */
> +return false;
> +# else
> +if (virProcessNamespaceAvailable(VIR_PROCESS_NAMESPACE_MNT) < 0)
> +return false;
> +# endif
> +break;
> +case QEMU_DOMAIN_NS_LAST:
> +break;
> +}
> +
> +return true;
> +#endif /* defined(__linux__) */
> +}
> +

ACK that looks fine.

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://entangle-photo.org   -o-http://search.cpan.org/~danberr/ :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] qemu_conf: Check for namespaces availability more wisely

2017-02-15 Thread Michal Privoznik
On 02/15/2017 10:43 AM, Daniel P. Berrange wrote:
> On Wed, Feb 15, 2017 at 10:20:27AM +0100, Michal Privoznik wrote:
>> The bare fact that mnt namespace is available is not enough for
>> us to allow/enable qemu namespaces feature. There are other
>> requirements: we must copy all the ACL & SELinux labels otherwise
>> we might grant access that is administratively forbidden or vice
>> versa.
>> At the same time, the check for namespace prerequisites is moved
>> from domain startup time to qemu.conf parser as it doesn't make
>> much sense to allow users to start misconfigured libvirt just to
>> find out they can't start a single domain.
>>
>> Signed-off-by: Michal Privoznik 
>> ---
>>  src/qemu/qemu_conf.c   | 20 
>>  src/qemu/qemu_conf.h   |  3 ++-
>>  src/qemu/qemu_domain.c | 43 ---
>>  src/qemu/qemu_domain.h |  2 ++
>>  src/qemu/qemu_driver.c |  2 +-
>>  5 files changed, 49 insertions(+), 21 deletions(-)
>>


>> +bool
>> +qemuDomainNamespaceAvailable(qemuDomainNamespace ns)
>> +{
>> +
>> +switch (ns) {
>> +case QEMU_DOMAIN_NS_MOUNT:
>> +#if !defined(__linux__)
>> +/* Namespaces are Linux specific. */
>> +return false;
>> +#endif
>> +#if !defined(HAVE_SYS_ACL_H) || !defined(WITH_SELINUX)
>> +/* We can't create the exact copy of paths if either of
>> + * these is not available. */
>> +return false;
>> +#endif
> 
> Pretty sure this will cause the compiler to complain about
> unreachable code paths because you'll get
> 
> return false;
> return false;
> if (virProcessNamespaceAvailable()

Ah. Obviously. What about this?

+bool
+qemuDomainNamespaceAvailable(qemuDomainNamespace ns ATTRIBUTE_UNUSED)
+{
+#if !defined(__linux__)
+/* Namespaces are Linux specific. */
+return false;
+
+#else /* defined(__linux__) */
+
+switch (ns) {
+case QEMU_DOMAIN_NS_MOUNT:
+# if !defined(HAVE_SYS_ACL_H) || !defined(WITH_SELINUX)
+/* We can't create the exact copy of paths if either of
+ * these is not available. */
+return false;
+# else
+if (virProcessNamespaceAvailable(VIR_PROCESS_NAMESPACE_MNT) < 0)
+return false;
+# endif
+break;
+case QEMU_DOMAIN_NS_LAST:
+break;
+}
+
+return true;
+#endif /* defined(__linux__) */
+}
+
+

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 26/33] cputest: Rename x86 data files

2017-02-15 Thread Jiri Denemark
While "x86" is a CPU sub driver name, it is not a recognized name of any
architecture known to libvirt. Let's use "x86_64" prefix which can be
used with virArch APIs.

Signed-off-by: Jiri Denemark 
---
 tests/cputest.c| 204 ++---
 ...ack.xml => x86_64-Haswell-noTSX-nofallback.xml} |   0
 ...-Haswell-noTSX.xml => x86_64-Haswell-noTSX.xml} |   0
 .../{x86-Haswell.xml => x86_64-Haswell.xml}|   0
 ...e-1-result.xml => x86_64-baseline-1-result.xml} |   0
 .../{x86-baseline-1.xml => x86_64-baseline-1.xml}  |   0
 ...e-2-result.xml => x86_64-baseline-2-result.xml} |   0
 .../{x86-baseline-2.xml => x86_64-baseline-2.xml}  |   0
 ...expanded.xml => x86_64-baseline-3-expanded.xml} |   0
 ...e-3-result.xml => x86_64-baseline-3-result.xml} |   0
 .../{x86-baseline-3.xml => x86_64-baseline-3.xml}  |   0
 ...expanded.xml => x86_64-baseline-4-expanded.xml} |   0
 ...e-4-result.xml => x86_64-baseline-4-result.xml} |   0
 .../{x86-baseline-4.xml => x86_64-baseline-4.xml}  |   0
 ...expanded.xml => x86_64-baseline-5-expanded.xml} |   0
 ...e-5-result.xml => x86_64-baseline-5-result.xml} |   0
 .../{x86-baseline-5.xml => x86_64-baseline-5.xml}  |   0
 ...atable.xml => x86_64-baseline-6-migratable.xml} |   0
 ...e-6-result.xml => x86_64-baseline-6-result.xml} |   0
 .../{x86-baseline-6.xml => x86_64-baseline-6.xml}  |   0
 ...e-7-result.xml => x86_64-baseline-7-result.xml} |   0
 .../{x86-baseline-7.xml => x86_64-baseline-7.xml}  |   0
 ...e-8-result.xml => x86_64-baseline-8-result.xml} |   0
 .../{x86-baseline-8.xml => x86_64-baseline-8.xml}  |   0
 ...ml => x86_64-baseline-incompatible-vendors.xml} |   0
 ...lt.xml => x86_64-baseline-no-vendor-result.xml} |   0
 ...no-vendor.xml => x86_64-baseline-no-vendor.xml} |   0
 ...xml => x86_64-baseline-some-vendors-result.xml} |   0
 ...endors.xml => x86_64-baseline-some-vendors.xml} |   0
 ...-bogus-feature.xml => x86_64-bogus-feature.xml} |   0
 ...{x86-bogus-model.xml => x86_64-bogus-model.xml} |   0
 ...86-bogus-vendor.xml => x86_64-bogus-vendor.xml} |   0
 ...-guest.xml => x86_64-cpuid-A10-5800K-guest.xml} |   0
 ...0K-host.xml => x86_64-cpuid-A10-5800K-host.xml} |   0
 ...0K-json.xml => x86_64-cpuid-A10-5800K-json.xml} |   0
 ...-A10-5800K.json => x86_64-cpuid-A10-5800K.json} |   0
 ...id-A10-5800K.xml => x86_64-cpuid-A10-5800K.xml} |   0
 ...-guest.xml => x86_64-cpuid-Atom-D510-guest.xml} |   0
 ...10-host.xml => x86_64-cpuid-Atom-D510-host.xml} |   0
 ...id-Atom-D510.xml => x86_64-cpuid-Atom-D510.xml} |   0
 ...-guest.xml => x86_64-cpuid-Atom-N450-guest.xml} |   0
 ...50-host.xml => x86_64-cpuid-Atom-N450-host.xml} |   0
 ...id-Atom-N450.xml => x86_64-cpuid-Atom-N450.xml} |   0
 ...est.xml => x86_64-cpuid-Core-i5-2500-guest.xml} |   0
 ...host.xml => x86_64-cpuid-Core-i5-2500-host.xml} |   0
 ...json.xml => x86_64-cpuid-Core-i5-2500-json.xml} |   0
 ...i5-2500.json => x86_64-cpuid-Core-i5-2500.json} |   0
 ...e-i5-2500.xml => x86_64-cpuid-Core-i5-2500.xml} |   0
 ...st.xml => x86_64-cpuid-Core-i5-2540M-guest.xml} |   0
 ...ost.xml => x86_64-cpuid-Core-i5-2540M-host.xml} |   0
 ...son.xml => x86_64-cpuid-Core-i5-2540M-json.xml} |   0
 ...-2540M.json => x86_64-cpuid-Core-i5-2540M.json} |   0
 ...i5-2540M.xml => x86_64-cpuid-Core-i5-2540M.xml} |   0
 ...st.xml => x86_64-cpuid-Core-i5-4670T-guest.xml} |   0
 ...ost.xml => x86_64-cpuid-Core-i5-4670T-host.xml} |   0
 ...son.xml => x86_64-cpuid-Core-i5-4670T-json.xml} |   0
 ...-4670T.json => x86_64-cpuid-Core-i5-4670T.json} |   0
 ...i5-4670T.xml => x86_64-cpuid-Core-i5-4670T.xml} |   0
 ...est.xml => x86_64-cpuid-Core-i5-6600-guest.xml} |   0
 ...host.xml => x86_64-cpuid-Core-i5-6600-host.xml} |   0
 ...json.xml => x86_64-cpuid-Core-i5-6600-json.xml} |   0
 ...i5-6600.json => x86_64-cpuid-Core-i5-6600.json} |   0
 ...e-i5-6600.xml => x86_64-cpuid-Core-i5-6600.xml} |   0
 ...est.xml => x86_64-cpuid-Core-i7-2600-guest.xml} |   0
 ...host.xml => x86_64-cpuid-Core-i7-2600-host.xml} |   0
 ...json.xml => x86_64-cpuid-Core-i7-2600-json.xml} |   0
 ...i7-2600.json => x86_64-cpuid-Core-i7-2600.json} |   0
 ...e-i7-2600.xml => x86_64-cpuid-Core-i7-2600.xml} |   0
 ...st.xml => x86_64-cpuid-Core-i7-3520M-guest.xml} |   0
 ...ost.xml => x86_64-cpuid-Core-i7-3520M-host.xml} |   0
 ...i7-3520M.xml => x86_64-cpuid-Core-i7-3520M.xml} |   0
 ...t.xml => x86_64-cpuid-Core-i7-3740QM-guest.xml} |   0
 ...st.xml => x86_64-cpuid-Core-i7-3740QM-host.xml} |   0
 ...on.xml => x86_64-cpuid-Core-i7-3740QM-json.xml} |   0
 ...740QM.json => x86_64-cpuid-Core-i7-3740QM.json} |   0
 ...-3740QM.xml => x86_64-cpuid-Core-i7-3740QM.xml} |   0
 ...est.xml => x86_64-cpuid-Core-i7-3770-guest.xml} |   0
 ...host.xml => x86_64-cpuid-Core-i7-3770-host.xml} |   0
 ...json.xml => x86_64-cpuid-Core-i7-3770-json.xml} |   0
 ...i7-3770.json => x86_64-cpuid-Core-i7-3770.json} |   0
 ...e-i7-3770.xml => x86_64-cpuid-Core-i7-3770.xml} |   0
 ...st.xml => x86_64-cpuid-Core-i7-4600U-guest.xml} |   

[libvirt] [PATCH 23/33] qemu: Use enum for CPU model expansion type

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_capabilities.c |  4 +++-
 src/qemu/qemu_monitor.c  |  4 ++--
 src/qemu/qemu_monitor.h  |  6 +-
 src/qemu/qemu_monitor_json.c | 11 +--
 src/qemu/qemu_monitor_json.h |  4 ++--
 5 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index bcfb6b694..20aaaf8f0 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2856,7 +2856,9 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
 model = "host";
 }
 
-return qemuMonitorGetCPUModelExpansion(mon, "static", model, modelInfo);
+return qemuMonitorGetCPUModelExpansion(mon,
+   
QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC,
+   model, modelInfo);
 }
 
 struct tpmTypeToCaps {
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index a434b234b..a987e107e 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3641,11 +3641,11 @@ qemuMonitorCPUDefInfoFree(qemuMonitorCPUDefInfoPtr cpu)
 
 int
 qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
-const char *type,
+qemuMonitorCPUModelExpansionType type,
 const char *model_name,
 qemuMonitorCPUModelInfoPtr *model_info)
 {
-VIR_DEBUG("type=%s model_name=%s", type, model_name);
+VIR_DEBUG("type=%d model_name=%s", type, model_name);
 
 QEMU_CHECK_MONITOR_JSON(mon);
 
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 112f041f1..b61f1cf54 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -948,8 +948,12 @@ struct _qemuMonitorCPUModelInfo {
 qemuMonitorCPUPropertyPtr props;
 };
 
+typedef enum {
+QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC,
+} qemuMonitorCPUModelExpansionType;
+
 int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
-const char *type,
+qemuMonitorCPUModelExpansionType type,
 const char *model_name,
 qemuMonitorCPUModelInfoPtr *model_info);
 
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index d89dfb88d..dd7907482 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5021,7 +5021,7 @@ qemuMonitorJSONParseCPUModelProperty(const char *key,
 
 int
 qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
-const char *type,
+qemuMonitorCPUModelExpansionType type,
 const char *model_name,
 qemuMonitorCPUModelInfoPtr *model_info)
 {
@@ -5034,6 +5034,7 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
 virJSONValuePtr cpu_props;
 qemuMonitorCPUModelInfoPtr machine_model = NULL;
 char const *cpu_name;
+const char *typeStr = "";
 
 *model_info = NULL;
 
@@ -5043,8 +5044,14 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
 if (virJSONValueObjectAppendString(model, "name", model_name) < 0)
 goto cleanup;
 
+switch (type) {
+case QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC:
+typeStr = "static";
+break;
+}
+
 if (!(cmd = qemuMonitorJSONMakeCommand("query-cpu-model-expansion",
-   "s:type", type,
+   "s:type", typeStr,
"a:model", model,
NULL)))
 goto cleanup;
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 79688c82f..59d9f098c 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -354,10 +354,10 @@ int qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
 ATTRIBUTE_NONNULL(2);
 
 int qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
-const char *type,
+qemuMonitorCPUModelExpansionType type,
 const char *model_name,
 qemuMonitorCPUModelInfoPtr *model_info)
-ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
+ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
 
 int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
char ***commands)
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 25/33] qemu: Make virQEMUCapsInitCPUModel testable

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_capabilities.c | 19 ++-
 src/qemu/qemu_capspriv.h | 10 ++
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index a77e300b7..3163bba8a 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3204,7 +3204,7 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
  *  1 when the caller should fall back to using virCapsPtr->host.cpu,
  * -1 on error.
  */
-static int
+int
 virQEMUCapsInitCPUModel(virQEMUCapsPtr qemuCaps,
 virDomainVirtType type,
 virCPUDefPtr cpu)
@@ -3268,6 +3268,18 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
 }
 
 
+void
+virQEMUCapsSetCPUModelInfo(virQEMUCapsPtr qemuCaps,
+   virDomainVirtType type,
+   qemuMonitorCPUModelInfoPtr modelInfo)
+{
+if (type == VIR_DOMAIN_VIRT_KVM)
+qemuCaps->kvmCPUModelInfo = modelInfo;
+else
+qemuCaps->tcgCPUModelInfo = modelInfo;
+}
+
+
 static int
 virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
 xmlXPathContextPtr ctxt,
@@ -3354,10 +3366,7 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
 }
 }
 
-if (type == VIR_DOMAIN_VIRT_KVM)
-qemuCaps->kvmCPUModelInfo = hostCPU;
-else
-qemuCaps->tcgCPUModelInfo = hostCPU;
+virQEMUCapsSetCPUModelInfo(qemuCaps, type, hostCPU);
 hostCPU = NULL;
 ret = 0;
 
diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h
index 75499d462..d4f13a2d2 100644
--- a/src/qemu/qemu_capspriv.h
+++ b/src/qemu/qemu_capspriv.h
@@ -73,4 +73,14 @@ void
 virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
 virCapsPtr caps,
 virDomainVirtType type);
+
+int
+virQEMUCapsInitCPUModel(virQEMUCapsPtr qemuCaps,
+virDomainVirtType type,
+virCPUDefPtr cpu);
+
+void
+virQEMUCapsSetCPUModelInfo(virQEMUCapsPtr qemuCaps,
+   virDomainVirtType type,
+   qemuMonitorCPUModelInfoPtr modelInfo);
 #endif
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 30/33] cputest: Test virQEMUCapsInitCPUModel

2017-02-15 Thread Jiri Denemark
The original test didn't use family/model numbers to make better
decisions about the CPU model and thus mis-detected the model in the two
cases which are modified in this commit. The detected CPU models now
match those obtained from raw CPUID data.

Signed-off-by: Jiri Denemark 
---
 tests/cputest.c| 28 +++---
 .../x86_64-cpuid-Core-i7-5600U-json.xml| 11 +
 .../cputestdata/x86_64-cpuid-Core2-E6850-json.xml  |  4 ++--
 3 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/tests/cputest.c b/tests/cputest.c
index c0a816b60..8c16fb95c 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -43,7 +43,9 @@
 #if WITH_QEMU && WITH_YAJL
 # include "testutilsqemu.h"
 # include "qemumonitortestutils.h"
-# include "qemu/qemu_monitor_json.h"
+# define __QEMU_CAPSRIV_H_ALLOW__
+# include "qemu/qemu_capspriv.h"
+# undef __QEMU_CAPSRIV_H_ALLOW__
 #endif
 
 #define VIR_FROM_THIS VIR_FROM_CPU
@@ -517,14 +519,15 @@ static int
 cpuTestJSONCPUID(const void *arg)
 {
 const struct data *data = arg;
-virCPUDataPtr cpuData = NULL;
+qemuMonitorCPUModelInfoPtr model = NULL;
+virQEMUCapsPtr qemuCaps = NULL;
 virCPUDefPtr cpu = NULL;
 qemuMonitorTestPtr testMon = NULL;
 char *json = NULL;
 char *result = NULL;
 int ret = -1;
 
-if (virAsprintf(, "%s/cputestdata/%s-cpuid-%s.json",
+if (virAsprintf(, "%s/cputestdata/%s-cpuid-%s.json.new",
 abs_srcdir, virArchToString(data->arch), data->host) < 0 ||
 virAsprintf(, "cpuid-%s-json", data->host) < 0)
 goto cleanup;
@@ -532,26 +535,35 @@ cpuTestJSONCPUID(const void *arg)
 if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true)))
 goto cleanup;
 
-if (qemuMonitorJSONGetCPUx86Data(qemuMonitorTestGetMonitor(testMon),
- "feature-words", ) < 0)
+if (qemuMonitorGetCPUModelExpansion(qemuMonitorTestGetMonitor(testMon),
+
QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC,
+"host", ) < 0)
 goto cleanup;
 
+if (!(qemuCaps = virQEMUCapsNew()))
+goto cleanup;
+
+virQEMUCapsSetArch(qemuCaps, data->arch);
+virQEMUCapsSetCPUModelInfo(qemuCaps, VIR_DOMAIN_VIRT_KVM, model);
+model = NULL;
+
 if (VIR_ALLOC(cpu) < 0)
 goto cleanup;
 
-cpu->arch = cpuData->arch;
+cpu->arch = data->arch;
 cpu->type = VIR_CPU_TYPE_GUEST;
 cpu->match = VIR_CPU_MATCH_EXACT;
 cpu->fallback = VIR_CPU_FALLBACK_FORBID;
 
-if (cpuDecode(cpu, cpuData, NULL, 0, NULL) < 0)
+if (virQEMUCapsInitCPUModel(qemuCaps, VIR_DOMAIN_VIRT_KVM, cpu) != 0)
 goto cleanup;
 
 ret = cpuTestCompareXML(data->arch, cpu, result, false);
 
  cleanup:
+qemuMonitorCPUModelInfoFree(model);
+virObjectUnref(qemuCaps);
 qemuMonitorTestFree(testMon);
-virCPUDataFree(cpuData);
 virCPUDefFree(cpu);
 VIR_FREE(result);
 VIR_FREE(json);
diff --git a/tests/cputestdata/x86_64-cpuid-Core-i7-5600U-json.xml 
b/tests/cputestdata/x86_64-cpuid-Core-i7-5600U-json.xml
index 159797178..8a6b8283f 100644
--- a/tests/cputestdata/x86_64-cpuid-Core-i7-5600U-json.xml
+++ b/tests/cputestdata/x86_64-cpuid-Core-i7-5600U-json.xml
@@ -1,12 +1,15 @@
 
   x86_64
-  Skylake-Client
+  Broadwell
+  
   
   
+  
+  
   
+  
   
+  
   
-  
-  
-  
+  
 
diff --git a/tests/cputestdata/x86_64-cpuid-Core2-E6850-json.xml 
b/tests/cputestdata/x86_64-cpuid-Core2-E6850-json.xml
index ddd730735..e93e0a321 100644
--- a/tests/cputestdata/x86_64-cpuid-Core2-E6850-json.xml
+++ b/tests/cputestdata/x86_64-cpuid-Core2-E6850-json.xml
@@ -1,11 +1,11 @@
 
   x86_64
-  Penryn
+  Conroe
   
   
+  
   
   
   
   
-  
 
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 09/33] qemu: Introduce virQEMUCapsFormatHostCPUModelInfo

2017-02-15 Thread Jiri Denemark
The CPU model info formating code in virQEMUCapsFormatCache will get
more complicated soon. Separating the code in
virQEMUCapsFormatHostCPUModelInfo will make the result easier to read.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_capabilities.c | 36 +++-
 1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index c511248bd..688d19504 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3542,6 +3542,27 @@ virQEMUCapsLoadCache(virCapsPtr caps,
 
 
 static void
+virQEMUCapsFormatHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
+  virBufferPtr buf)
+{
+qemuMonitorCPUModelInfoPtr model = qemuCaps->hostCPUModelInfo;
+size_t i;
+
+virBufferAsprintf(buf, "\n", model->name);
+virBufferAdjustIndent(buf, 2);
+
+for (i = 0; i < model->nprops; i++) {
+virBufferAsprintf(buf, "\n",
+  model->props[i].name,
+  model->props[i].supported ? "yes" : "no");
+}
+
+virBufferAdjustIndent(buf, -2);
+virBufferAddLit(buf, "\n");
+}
+
+
+static void
 virQEMUCapsFormatCPUModels(virQEMUCapsPtr qemuCaps,
virBufferPtr buf,
virDomainVirtType type)
@@ -3617,19 +3638,8 @@ virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps,
 virBufferAsprintf(, "%s\n",
   virArchToString(qemuCaps->arch));
 
-if (qemuCaps->hostCPUModelInfo) {
-virBufferAsprintf(, "\n",
-  qemuCaps->hostCPUModelInfo->name);
-virBufferAdjustIndent(, 2);
-for (i = 0; i < qemuCaps->hostCPUModelInfo->nprops; i++) {
-virBufferAsprintf(, "\n",
-  qemuCaps->hostCPUModelInfo->props[i].name,
-  qemuCaps->hostCPUModelInfo->props[i].supported ?
-  "yes" : "no");
-}
-virBufferAdjustIndent(, -2);
-virBufferAddLit(, "\n");
-}
+if (qemuCaps->hostCPUModelInfo)
+virQEMUCapsFormatHostCPUModelInfo(qemuCaps, );
 
 virQEMUCapsFormatCPUModels(qemuCaps, , VIR_DOMAIN_VIRT_KVM);
 virQEMUCapsFormatCPUModels(qemuCaps, , VIR_DOMAIN_VIRT_QEMU);
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 32/33] cputest: Drop .new suffix from CPU test data files

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 tests/cputest.c | 2 +-
 .../{x86_64-cpuid-A10-5800K.json.new => x86_64-cpuid-A10-5800K.json}| 0
 ...86_64-cpuid-Core-i5-2500.json.new => x86_64-cpuid-Core-i5-2500.json} | 0
 ..._64-cpuid-Core-i5-2540M.json.new => x86_64-cpuid-Core-i5-2540M.json} | 0
 ..._64-cpuid-Core-i5-4670T.json.new => x86_64-cpuid-Core-i5-4670T.json} | 0
 ...86_64-cpuid-Core-i5-6600.json.new => x86_64-cpuid-Core-i5-6600.json} | 0
 ...86_64-cpuid-Core-i7-2600.json.new => x86_64-cpuid-Core-i7-2600.json} | 0
 ...4-cpuid-Core-i7-3740QM.json.new => x86_64-cpuid-Core-i7-3740QM.json} | 0
 ...86_64-cpuid-Core-i7-3770.json.new => x86_64-cpuid-Core-i7-3770.json} | 0
 ..._64-cpuid-Core-i7-4600U.json.new => x86_64-cpuid-Core-i7-4600U.json} | 0
 ..._64-cpuid-Core-i7-5600U.json.new => x86_64-cpuid-Core-i7-5600U.json} | 0
 ...{x86_64-cpuid-Core2-E6850.json.new => x86_64-cpuid-Core2-E6850.json} | 0
 ...86_64-cpuid-Opteron-2350.json.new => x86_64-cpuid-Opteron-2350.json} | 0
 ...86_64-cpuid-Opteron-6234.json.new => x86_64-cpuid-Opteron-6234.json} | 0
 .../{x86_64-cpuid-Phenom-B95.json.new => x86_64-cpuid-Phenom-B95.json}  | 0
 ...86_64-cpuid-Xeon-E3-1245.json.new => x86_64-cpuid-Xeon-E3-1245.json} | 0
 ...86_64-cpuid-Xeon-E5-2630.json.new => x86_64-cpuid-Xeon-E5-2630.json} | 0
 ...86_64-cpuid-Xeon-E5-2650.json.new => x86_64-cpuid-Xeon-E5-2650.json} | 0
 ...86_64-cpuid-Xeon-E7-4820.json.new => x86_64-cpuid-Xeon-E7-4820.json} | 0
 .../{x86_64-cpuid-Xeon-W3520.json.new => x86_64-cpuid-Xeon-W3520.json}  | 0
 20 files changed, 1 insertion(+), 1 deletion(-)
 rename tests/cputestdata/{x86_64-cpuid-A10-5800K.json.new => 
x86_64-cpuid-A10-5800K.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i5-2500.json.new => 
x86_64-cpuid-Core-i5-2500.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i5-2540M.json.new => 
x86_64-cpuid-Core-i5-2540M.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i5-4670T.json.new => 
x86_64-cpuid-Core-i5-4670T.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i5-6600.json.new => 
x86_64-cpuid-Core-i5-6600.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i7-2600.json.new => 
x86_64-cpuid-Core-i7-2600.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i7-3740QM.json.new => 
x86_64-cpuid-Core-i7-3740QM.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i7-3770.json.new => 
x86_64-cpuid-Core-i7-3770.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i7-4600U.json.new => 
x86_64-cpuid-Core-i7-4600U.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core-i7-5600U.json.new => 
x86_64-cpuid-Core-i7-5600U.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Core2-E6850.json.new => 
x86_64-cpuid-Core2-E6850.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Opteron-2350.json.new => 
x86_64-cpuid-Opteron-2350.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Opteron-6234.json.new => 
x86_64-cpuid-Opteron-6234.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Phenom-B95.json.new => 
x86_64-cpuid-Phenom-B95.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Xeon-E3-1245.json.new => 
x86_64-cpuid-Xeon-E3-1245.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Xeon-E5-2630.json.new => 
x86_64-cpuid-Xeon-E5-2630.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Xeon-E5-2650.json.new => 
x86_64-cpuid-Xeon-E5-2650.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Xeon-E7-4820.json.new => 
x86_64-cpuid-Xeon-E7-4820.json} (100%)
 rename tests/cputestdata/{x86_64-cpuid-Xeon-W3520.json.new => 
x86_64-cpuid-Xeon-W3520.json} (100%)

diff --git a/tests/cputest.c b/tests/cputest.c
index 8c16fb95c..b7dd95d84 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -527,7 +527,7 @@ cpuTestJSONCPUID(const void *arg)
 char *result = NULL;
 int ret = -1;
 
-if (virAsprintf(, "%s/cputestdata/%s-cpuid-%s.json.new",
+if (virAsprintf(, "%s/cputestdata/%s-cpuid-%s.json",
 abs_srcdir, virArchToString(data->arch), data->host) < 0 ||
 virAsprintf(, "cpuid-%s-json", data->host) < 0)
 goto cleanup;
diff --git a/tests/cputestdata/x86_64-cpuid-A10-5800K.json.new 
b/tests/cputestdata/x86_64-cpuid-A10-5800K.json
similarity index 100%
rename from tests/cputestdata/x86_64-cpuid-A10-5800K.json.new
rename to tests/cputestdata/x86_64-cpuid-A10-5800K.json
diff --git a/tests/cputestdata/x86_64-cpuid-Core-i5-2500.json.new 
b/tests/cputestdata/x86_64-cpuid-Core-i5-2500.json
similarity index 100%
rename from tests/cputestdata/x86_64-cpuid-Core-i5-2500.json.new
rename to tests/cputestdata/x86_64-cpuid-Core-i5-2500.json
diff --git a/tests/cputestdata/x86_64-cpuid-Core-i5-2540M.json.new 
b/tests/cputestdata/x86_64-cpuid-Core-i5-2540M.json
similarity index 100%
rename from tests/cputestdata/x86_64-cpuid-Core-i5-2540M.json.new
rename to tests/cputestdata/x86_64-cpuid-Core-i5-2540M.json
diff --git a/tests/cputestdata/x86_64-cpuid-Core-i5-4670T.json.new 

[libvirt] [PATCH 27/33] cputest: Use virArch enum rather then strings

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 tests/cputest.c | 294 
 1 file changed, 148 insertions(+), 146 deletions(-)

diff --git a/tests/cputest.c b/tests/cputest.c
index 406b40dfe..c0a816b60 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -56,7 +56,7 @@ enum cpuTestBoolWithError {
 
 
 struct data {
-const char *arch;
+virArch arch;
 const char *host;
 const char *name;
 const char **models;
@@ -72,14 +72,15 @@ static virQEMUDriver driver;
 
 
 static virCPUDefPtr
-cpuTestLoadXML(const char *arch, const char *name)
+cpuTestLoadXML(virArch arch, const char *name)
 {
 char *xml = NULL;
 xmlDocPtr doc = NULL;
 xmlXPathContextPtr ctxt = NULL;
 virCPUDefPtr cpu = NULL;
 
-if (virAsprintf(, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) 
< 0)
+if (virAsprintf(, "%s/cputestdata/%s-%s.xml",
+abs_srcdir, virArchToString(arch), name) < 0)
 goto cleanup;
 
 if (!(doc = virXMLParseFileCtxt(xml, )))
@@ -96,7 +97,7 @@ cpuTestLoadXML(const char *arch, const char *name)
 
 
 static virCPUDefPtr *
-cpuTestLoadMultiXML(const char *arch,
+cpuTestLoadMultiXML(virArch arch,
 const char *name,
 unsigned int *count)
 {
@@ -108,7 +109,8 @@ cpuTestLoadMultiXML(const char *arch,
 int n;
 size_t i;
 
-if (virAsprintf(, "%s/cputestdata/%s-%s.xml", abs_srcdir, arch, name) 
< 0)
+if (virAsprintf(, "%s/cputestdata/%s-%s.xml",
+abs_srcdir, virArchToString(arch), name) < 0)
 goto cleanup;
 
 if (!(doc = virXMLParseFileCtxt(xml, )))
@@ -145,7 +147,7 @@ cpuTestLoadMultiXML(const char *arch,
 
 
 static int
-cpuTestCompareXML(const char *arch,
+cpuTestCompareXML(virArch arch,
   virCPUDef *cpu,
   const char *name,
   bool updateCPU)
@@ -155,7 +157,7 @@ cpuTestCompareXML(const char *arch,
 int ret = -1;
 
 if (virAsprintf(, "%s/cputestdata/%s-%s.xml",
-abs_srcdir, arch, name) < 0)
+abs_srcdir, virArchToString(arch), name) < 0)
 goto cleanup;
 
 if (!(actual = virCPUDefFormat(cpu, NULL, updateCPU)))
@@ -457,7 +459,7 @@ cpuTestCPUID(bool guest, const void *arg)
 char *result = NULL;
 
 if (virAsprintf(, "%s/cputestdata/%s-cpuid-%s.xml",
-abs_srcdir, data->arch, data->host) < 0)
+abs_srcdir, virArchToString(data->arch), data->host) < 0)
 goto cleanup;
 
 if (virTestLoadFile(hostFile, ) < 0 ||
@@ -523,7 +525,7 @@ cpuTestJSONCPUID(const void *arg)
 int ret = -1;
 
 if (virAsprintf(, "%s/cputestdata/%s-cpuid-%s.json",
-abs_srcdir, data->arch, data->host) < 0 ||
+abs_srcdir, virArchToString(data->arch), data->host) < 0 ||
 virAsprintf(, "cpuid-%s-json", data->host) < 0)
 goto cleanup;
 
@@ -591,7 +593,7 @@ mymain(void)
 VIR_FREE(tmp);  \
 \
 if (virAsprintf(, "%s(%s): %s",   \
-#api, arch, name) < 0) {\
+#api, virArchToString(arch), name) < 0) {   \
 ret = -1;   \
 break;  \
 }   \
@@ -677,159 +679,159 @@ mymain(void)
 } while (0)
 
 /* host to host comparison */
-DO_TEST_COMPARE("x86_64", "host", "host", VIR_CPU_COMPARE_IDENTICAL);
-DO_TEST_COMPARE("x86_64", "host", "host-better", 
VIR_CPU_COMPARE_INCOMPATIBLE);
-DO_TEST_COMPARE("x86_64", "host", "host-worse", VIR_CPU_COMPARE_SUPERSET);
-DO_TEST_COMPARE("x86_64", "host", "host-amd-fake", 
VIR_CPU_COMPARE_INCOMPATIBLE);
-DO_TEST_COMPARE("x86_64", "host", "host-incomp-arch", 
VIR_CPU_COMPARE_INCOMPATIBLE);
-DO_TEST_COMPARE("x86_64", "host", "host-no-vendor", 
VIR_CPU_COMPARE_IDENTICAL);
-DO_TEST_COMPARE("x86_64", "host-no-vendor", "host", 
VIR_CPU_COMPARE_INCOMPATIBLE);
+DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host", 
VIR_CPU_COMPARE_IDENTICAL);
+DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host-better", 
VIR_CPU_COMPARE_INCOMPATIBLE);
+DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host-worse", 
VIR_CPU_COMPARE_SUPERSET);
+DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host-amd-fake", 
VIR_CPU_COMPARE_INCOMPATIBLE);
+DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host-incomp-arch", 
VIR_CPU_COMPARE_INCOMPATIBLE);
+DO_TEST_COMPARE(VIR_ARCH_X86_64, "host", "host-no-vendor", 
VIR_CPU_COMPARE_IDENTICAL);
+DO_TEST_COMPARE(VIR_ARCH_X86_64, "host-no-vendor", "host", 
VIR_CPU_COMPARE_INCOMPATIBLE);
 
-DO_TEST_COMPARE("ppc64", "host", "host", VIR_CPU_COMPARE_IDENTICAL);

[libvirt] [PATCH 31/33] cputest: Drop obsolete CPU test data files

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 tests/cputestdata/x86_64-cpuid-A10-5800K.json  | 77 ---
 tests/cputestdata/x86_64-cpuid-Core-i5-2500.json   | 88 --
 tests/cputestdata/x86_64-cpuid-Core-i5-2540M.json  | 82 
 tests/cputestdata/x86_64-cpuid-Core-i5-4670T.json  | 77 ---
 tests/cputestdata/x86_64-cpuid-Core-i5-6600.json   | 82 
 tests/cputestdata/x86_64-cpuid-Core-i7-2600.json   | 77 ---
 tests/cputestdata/x86_64-cpuid-Core-i7-3740QM.json | 77 ---
 tests/cputestdata/x86_64-cpuid-Core-i7-3770.json   | 77 ---
 tests/cputestdata/x86_64-cpuid-Core-i7-4600U.json  | 82 
 tests/cputestdata/x86_64-cpuid-Core-i7-5600U.json  | 88 --
 tests/cputestdata/x86_64-cpuid-Core2-E6850.json| 77 ---
 tests/cputestdata/x86_64-cpuid-Opteron-2350.json   | 71 -
 tests/cputestdata/x86_64-cpuid-Opteron-6234.json   | 88 --
 tests/cputestdata/x86_64-cpuid-Phenom-B95.json | 77 ---
 tests/cputestdata/x86_64-cpuid-Xeon-E3-1245.json   | 88 --
 tests/cputestdata/x86_64-cpuid-Xeon-E5-2630.json   | 77 ---
 tests/cputestdata/x86_64-cpuid-Xeon-E5-2650.json   | 71 -
 tests/cputestdata/x86_64-cpuid-Xeon-E7-4820.json   | 77 ---
 tests/cputestdata/x86_64-cpuid-Xeon-W3520.json | 77 ---
 19 files changed, 1510 deletions(-)
 delete mode 100644 tests/cputestdata/x86_64-cpuid-A10-5800K.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i5-2500.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i5-2540M.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i5-4670T.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i5-6600.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-2600.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-3740QM.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-3770.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-4600U.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-5600U.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Core2-E6850.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Opteron-2350.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Opteron-6234.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Phenom-B95.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-E3-1245.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-E5-2630.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-E5-2650.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-E7-4820.json
 delete mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-W3520.json

diff --git a/tests/cputestdata/x86_64-cpuid-A10-5800K.json 
b/tests/cputestdata/x86_64-cpuid-A10-5800K.json
deleted file mode 100644
index 53b39ad03..0
--- a/tests/cputestdata/x86_64-cpuid-A10-5800K.json
+++ /dev/null
@@ -1,77 +0,0 @@
-{
-  "return": [
-{
-  "cpuid-register": "EAX",
-  "cpuid-input-ecx": 1,
-  "cpuid-input-eax": 13,
-  "features": 0
-},
-{
-  "cpuid-register": "EDX",
-  "cpuid-input-eax": 2147483658,
-  "features": 9
-},
-{
-  "cpuid-register": "EAX",
-  "cpuid-input-eax": 1073741825,
-  "features": 16777467
-},
-{
-  "cpuid-register": "EDX",
-  "cpuid-input-eax": 3221225473,
-  "features": 0
-},
-{
-  "cpuid-register": "EDX",
-  "cpuid-input-eax": 2147483655,
-  "features": 0
-},
-{
-  "cpuid-register": "ECX",
-  "cpuid-input-eax": 2147483649,
-  "features": 2165747
-},
-{
-  "cpuid-register": "EDX",
-  "cpuid-input-eax": 2147483649,
-  "features": 642779136
-},
-{
-  "cpuid-register": "EBX",
-  "cpuid-input-ecx": 0,
-  "cpuid-input-eax": 7,
-  "features": 10
-},
-{
-  "cpuid-register": "ECX",
-  "cpuid-input-eax": 1,
-  "features": 3065524739
-},
-{
-  "cpuid-register": "EDX",
-  "cpuid-input-eax": 1,
-  "features": 126614527
-}
-  ],
-  "id": "feature-words"
-}
-
-{
-  "return": 21,
-  "id": "family"
-}
-
-{
-  "return": 16,
-  "id": "model"
-}
-
-{
-  "return": 1,
-  "id": "stepping"
-}
-
-{
-  "return": "AMD A10-5800K APU with Radeon(tm) HD Graphics  ",
-  "id": "model-id"
-}
diff --git a/tests/cputestdata/x86_64-cpuid-Core-i5-2500.json 
b/tests/cputestdata/x86_64-cpuid-Core-i5-2500.json
deleted file mode 100644
index 156b77248..0
--- a/tests/cputestdata/x86_64-cpuid-Core-i5-2500.json
+++ /dev/null
@@ -1,88 +0,0 @@
-{
-  "return": [
-{
-  "cpuid-register": "EAX",
-  "cpuid-input-eax": 6,
-  "features": 4
-},
-{
-  "cpuid-register": "EAX",
-  "cpuid-input-ecx": 1,
-  "cpuid-input-eax": 13,
-  "features": 1

[libvirt] [PATCH 11/33] qemu: Store more types in qemuMonitorCPUModelInfo

2017-02-15 Thread Jiri Denemark
While query-cpu-model-expansion returns only boolean features on s390,
but x86_64 reports some integer and string properties which we are
interested in.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_capabilities.c | 84 
 src/qemu/qemu_monitor.c  | 22 ++-
 src/qemu/qemu_monitor.h  | 23 +--
 src/qemu/qemu_monitor_json.c | 37 ---
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml |  7 ++
 5 files changed, 133 insertions(+), 40 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index aab336954..466852d13 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3074,14 +3074,16 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps,
 cpu->nfeatures = 0;
 
 for (i = 0; i < modelInfo->nprops; i++) {
-if (VIR_STRDUP(cpu->features[i].name, modelInfo->props[i].name) < 0)
+virCPUFeatureDefPtr feature = cpu->features + cpu->nfeatures;
+qemuMonitorCPUPropertyPtr prop = modelInfo->props + i;
+
+if (prop->type != QEMU_MONITOR_CPU_PROPERTY_BOOLEAN)
+continue;
+
+if (VIR_STRDUP(feature->name, prop->name) < 0)
 return -1;
-
-if (modelInfo->props[i].supported)
-cpu->features[i].policy = VIR_CPU_FEATURE_REQUIRE;
-else
-cpu->features[i].policy = VIR_CPU_FEATURE_DISABLE;
-
+feature->policy = prop->value.boolean ? VIR_CPU_FEATURE_REQUIRE
+  : VIR_CPU_FEATURE_DISABLE;
 cpu->nfeatures++;
 }
 
@@ -3154,7 +3156,6 @@ static int
 virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
 xmlXPathContextPtr ctxt)
 {
-char *str = NULL;
 xmlNodePtr hostCPUNode;
 xmlNodePtr *featureNodes = NULL;
 xmlNodePtr oldnode = ctxt->node;
@@ -3187,30 +3188,47 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
 hostCPU->nprops = n;
 
 for (i = 0; i < n; i++) {
-hostCPU->props[i].name = virXMLPropString(featureNodes[i], "name");
-if (!hostCPU->props[i].name) {
+qemuMonitorCPUPropertyPtr prop = hostCPU->props + i;
+ctxt->node = featureNodes[i];
+
+if (!(prop->name = virXMLPropString(ctxt->node, "name"))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing 'name' attribute for a host CPU"
  " model property in QEMU capabilities 
cache"));
 goto cleanup;
 }
 
-if (!(str = virXMLPropString(featureNodes[i], "boolean"))) {
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("missing 'boolean' attribute for a host CPU"
- " model property in QEMU capabilities 
cache"));
-goto cleanup;
-}
-if (STREQ(str, "yes")) {
-hostCPU->props[i].supported = true;
-} else if (STREQ(str, "no")) {
-hostCPU->props[i].supported = false;
+if (virXPathBoolean("boolean(./@boolean)", ctxt)) {
+if (virXPathBoolean("./@boolean='yes'", ctxt))
+prop->value.boolean = true;
+prop->type = QEMU_MONITOR_CPU_PROPERTY_BOOLEAN;
+} else if (virXPathBoolean("boolean(./@string)", ctxt)) {
+prop->value.string = virXMLPropString(ctxt->node, "string");
+if (!prop->value.string) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("invalid string value for '%s' host CPU "
+ "model property in QEMU capabilities 
cache"),
+   prop->name);
+goto cleanup;
+}
+prop->type = QEMU_MONITOR_CPU_PROPERTY_STRING;
+} else if (virXPathBoolean("boolean(./@ull)", ctxt)) {
+if (virXPathULongLong("string(./@ull)", ctxt,
+  >value.ull) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("invalid integer value for '%s' host CPU "
+ "model property in QEMU capabilities 
cache"),
+   prop->name);
+goto cleanup;
+}
+prop->type = QEMU_MONITOR_CPU_PROPERTY_ULL;
 } else {
 virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("invalid boolean value: '%s'"), str);
+   _("missing value for '%s' host CPU model "
+ "property in QEMU capabilities cache"),
+   prop->name);
 goto cleanup;
 

[libvirt] [PATCH 24/33] qemu: Use full CPU model expansion on x86

2017-02-15 Thread Jiri Denemark
The static CPU model expansion is designed to return only canonical
names of all CPU properties. TO maintain backward compatibility libvirt
is stuck with different spelling of some of the features, which is only
returned by the full expansion. But in addition to returned all spelling
variants for all properties the full expansion will contain properties
which are not guaranteed to be migration compatible. We need to combine
both expansions. First we need to call the static expansion to limit the
result to migratable properties. Then we can use the result of the
static expansion as an input to the full expansion to get both canonical
names and their aliases.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_capabilities.c   |  10 +-
 src/qemu/qemu_monitor.h|   2 +
 src/qemu/qemu_monitor_json.c   |  28 +-
 .../domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml |   2 -
 tests/domaincapsschemadata/qemu_2.9.0.x86_64.xml   |   3 +-
 .../qemucapabilitiesdata/caps_2.9.0.x86_64.replies | 476 +
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   | 178 ++--
 7 files changed, 657 insertions(+), 42 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 20aaaf8f0..a77e300b7 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2844,6 +2844,7 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
 {
 qemuMonitorCPUModelInfoPtr *modelInfo;
 const char *model;
+qemuMonitorCPUModelExpansionType type;
 
 if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION))
 return 0;
@@ -2856,9 +2857,12 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
 model = "host";
 }
 
-return qemuMonitorGetCPUModelExpansion(mon,
-   
QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC,
-   model, modelInfo);
+if (ARCH_IS_X86(qemuCaps->arch))
+type = QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL;
+else
+type = QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC;
+
+return qemuMonitorGetCPUModelExpansion(mon, type, model, modelInfo);
 }
 
 struct tpmTypeToCaps {
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index b61f1cf54..6407a309f 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -950,6 +950,8 @@ struct _qemuMonitorCPUModelInfo {
 
 typedef enum {
 QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC,
+QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL,
+QEMU_MONITOR_CPU_MODEL_EXPANSION_FULL,
 } qemuMonitorCPUModelExpansionType;
 
 int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index dd7907482..0454571c1 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5026,7 +5026,7 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
 qemuMonitorCPUModelInfoPtr *model_info)
 {
 int ret = -1;
-virJSONValuePtr model;
+virJSONValuePtr model = NULL;
 virJSONValuePtr cmd = NULL;
 virJSONValuePtr reply = NULL;
 virJSONValuePtr data;
@@ -5038,16 +5038,24 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
 
 *model_info = NULL;
 
-if (!(model = virJSONValueNewObject()))
-goto cleanup;
+ retry:
+if (!model) {
+if (!(model = virJSONValueNewObject()))
+goto cleanup;
 
-if (virJSONValueObjectAppendString(model, "name", model_name) < 0)
-goto cleanup;
+if (virJSONValueObjectAppendString(model, "name", model_name) < 0)
+goto cleanup;
+}
 
 switch (type) {
 case QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC:
+case QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL:
 typeStr = "static";
 break;
+
+case QEMU_MONITOR_CPU_MODEL_EXPANSION_FULL:
+typeStr = "full";
+break;
 }
 
 if (!(cmd = qemuMonitorJSONMakeCommand("query-cpu-model-expansion",
@@ -5084,6 +5092,16 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
 goto cleanup;
 }
 
+if (type == QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL) {
+if (!(model = virJSONValueCopy(cpu_model)))
+goto cleanup;
+
+virJSONValueFree(cmd);
+virJSONValueFree(reply);
+type = QEMU_MONITOR_CPU_MODEL_EXPANSION_FULL;
+goto retry;
+}
+
 if (!(cpu_name = virJSONValueObjectGetString(cpu_model, "name"))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("query-cpu-model-expansion reply data was missing 
'name'"));
diff --git a/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml 
b/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml
index 1827b1d6f..573eb4bb6 100644
--- a/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml
+++ b/tests/domaincapsschemadata/qemu_2.9.0-tcg.x86_64.xml
@@ -46,9 +46,7 @@
 

[libvirt] [PATCH 29/33] cputest: Convert all json data files to query-cpu-model-expansion

2017-02-15 Thread Jiri Denemark
Converted by running the following command, renaming the files as
*.new, and committing only the *.new files.

(cd tests/cputestdata; ./cpu-convert.py *.json)

Signed-off-by: Jiri Denemark 
---
 tests/cputestdata/x86_64-cpuid-A10-5800K.json.new  | 202 +
 .../cputestdata/x86_64-cpuid-Core-i5-2500.json.new | 202 +
 .../x86_64-cpuid-Core-i5-2540M.json.new| 202 +
 .../x86_64-cpuid-Core-i5-4670T.json.new| 202 +
 .../cputestdata/x86_64-cpuid-Core-i5-6600.json.new | 202 +
 .../cputestdata/x86_64-cpuid-Core-i7-2600.json.new | 202 +
 .../x86_64-cpuid-Core-i7-3740QM.json.new   | 202 +
 .../cputestdata/x86_64-cpuid-Core-i7-3770.json.new | 202 +
 .../x86_64-cpuid-Core-i7-4600U.json.new| 202 +
 .../x86_64-cpuid-Core-i7-5600U.json.new| 202 +
 .../cputestdata/x86_64-cpuid-Core2-E6850.json.new  | 202 +
 .../cputestdata/x86_64-cpuid-Opteron-2350.json.new | 202 +
 .../cputestdata/x86_64-cpuid-Opteron-6234.json.new | 202 +
 tests/cputestdata/x86_64-cpuid-Phenom-B95.json.new | 202 +
 .../cputestdata/x86_64-cpuid-Xeon-E3-1245.json.new | 202 +
 .../cputestdata/x86_64-cpuid-Xeon-E5-2630.json.new | 202 +
 .../cputestdata/x86_64-cpuid-Xeon-E5-2650.json.new | 202 +
 .../cputestdata/x86_64-cpuid-Xeon-E7-4820.json.new | 202 +
 tests/cputestdata/x86_64-cpuid-Xeon-W3520.json.new | 202 +
 19 files changed, 3838 insertions(+)
 create mode 100644 tests/cputestdata/x86_64-cpuid-A10-5800K.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i5-2500.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i5-2540M.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i5-4670T.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i5-6600.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-2600.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-3740QM.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-3770.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-4600U.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core-i7-5600U.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Core2-E6850.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Opteron-2350.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Opteron-6234.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Phenom-B95.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-E3-1245.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-E5-2630.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-E5-2650.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-E7-4820.json.new
 create mode 100644 tests/cputestdata/x86_64-cpuid-Xeon-W3520.json.new

diff --git a/tests/cputestdata/x86_64-cpuid-A10-5800K.json.new 
b/tests/cputestdata/x86_64-cpuid-A10-5800K.json.new
new file mode 100644
index 0..1aa997279
--- /dev/null
+++ b/tests/cputestdata/x86_64-cpuid-A10-5800K.json.new
@@ -0,0 +1,202 @@
+{
+  "return": {
+"model": {
+  "name": "base",
+  "props": {
+"pfthreshold": false,
+"pku": false,
+"rtm": false,
+"tsc_adjust": true,
+"tsc-deadline": false,
+"xstore-en": false,
+"tsc-scale": false,
+"sse": true,
+"smap": false,
+"stepping": 1,
+"tce": false,
+"kvm_steal_time": true,
+"smep": false,
+"rdpid": false,
+"xcrypt": false,
+"sse4_2": true,
+"monitor": false,
+"sse4_1": true,
+"kvm-mmu": false,
+"flushbyasid": false,
+"kvm-steal-time": true,
+"lm": true,
+"tsc": true,
+"adx": false,
+"fxsr": true,
+"sha-ni": false,
+"tm": false,
+"pclmuldq": true,
+"xgetbv1": false,
+"xstore": false,
+"vmcb_clean": false,
+"vme": true,
+"arat": false,
+"ffxsr": true,
+"de": true,
+"avx512f": false,
+"pse": true,
+"ds-cpl": false,
+"tbm": true,
+"ia64": false,
+"phe-en": false,
+"f16c": true,
+"ds": false,
+"mpx": false,
+"tsc-adjust": true,
+"aes": true,
+"avx2": false,
+"pbe": false,
+"cx16": true,
+"ds_cpl": false,
+"movbe": false,
+"perfctr-nb": false,
+"nrip_save": true,
+"kvm_mmu": false,
+"ospke": false,
+"avx512ifma": false,
+"vmx": false,
+"sep": true,
+"xsaveopt": false,
+ 

[libvirt] [PATCH 33/33] news: Detect host CPU model by asking QEMU on x86_64

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 docs/news.xml | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/docs/news.xml b/docs/news.xml
index b756a970f..798687407 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -73,6 +73,17 @@
   and network.
 
   
+  
+
+  qemu: Detect host CPU model by asking QEMU on x86_64
+
+
+  Previously, libvirt detected the host CPU model using CPUID
+  instruction, which cased libvirt to detect a lot of CPU features
+  that are not supported by QEMU/KVM. Asking QEMU makes sure we
+  don't ask for unsupported features.
+
+  
 
 
   
-- 
2.11.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 12/33] qemu: Probe "max" CPU model in TCG

2017-02-15 Thread Jiri Denemark
Querying "host" CPU model expansion only makes sense for KVM. QEMU 2.9.0
introduces a new "max" CPU model which can be used to ask QEMU what the
best CPU it can provide to a TCG domain is.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_capabilities.c   | 151 -
 src/qemu/qemu_capabilities.h   |   3 +-
 src/qemu/qemu_capspriv.h   |   3 +-
 src/qemu/qemu_command.c|   2 +-
 src/qemu/qemu_process.c|   5 +-
 .../qemucapabilitiesdata/caps_2.8.0.s390x.replies  |   8 +
 tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml|   2 +-
 .../qemucapabilitiesdata/caps_2.9.0.x86_64.replies | 179 +
 tests/qemucapabilitiesdata/caps_2.9.0.x86_64.xml   | 172 +++-
 tests/qemuxml2argvtest.c   |   3 +-
 10 files changed, 480 insertions(+), 48 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 466852d13..2ba82456e 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -400,13 +400,15 @@ struct _virQEMUCaps {
 size_t ngicCapabilities;
 virGICCapability *gicCapabilities;
 
-qemuMonitorCPUModelInfoPtr hostCPUModelInfo;
+qemuMonitorCPUModelInfoPtr kvmCPUModelInfo;
+qemuMonitorCPUModelInfoPtr tcgCPUModelInfo;
 
 /* Anything below is not stored in the cache since the values are
  * re-computed from the other fields or external data sources every
  * time we probe QEMU or load the results from the cache.
  */
-virCPUDefPtr hostCPUModel;
+virCPUDefPtr kvmCPUModel;
+virCPUDefPtr tcgCPUModel;
 };
 
 struct virQEMUCapsSearchData {
@@ -2163,12 +2165,20 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr 
qemuCaps)
 goto error;
 }
 
-if (qemuCaps->hostCPUModel &&
-!(ret->hostCPUModel = virCPUDefCopy(qemuCaps->hostCPUModel)))
+if (qemuCaps->kvmCPUModel &&
+!(ret->kvmCPUModel = virCPUDefCopy(qemuCaps->kvmCPUModel)))
 goto error;
 
-if (qemuCaps->hostCPUModelInfo &&
-!(ret->hostCPUModelInfo = 
qemuMonitorCPUModelInfoCopy(qemuCaps->hostCPUModelInfo)))
+if (qemuCaps->tcgCPUModel &&
+!(ret->tcgCPUModel = virCPUDefCopy(qemuCaps->tcgCPUModel)))
+goto error;
+
+if (qemuCaps->kvmCPUModelInfo &&
+!(ret->kvmCPUModelInfo = 
qemuMonitorCPUModelInfoCopy(qemuCaps->kvmCPUModelInfo)))
+goto error;
+
+if (qemuCaps->tcgCPUModelInfo &&
+!(ret->tcgCPUModelInfo = 
qemuMonitorCPUModelInfoCopy(qemuCaps->tcgCPUModelInfo)))
 goto error;
 
 if (VIR_ALLOC_N(ret->machineTypes, qemuCaps->nmachineTypes) < 0)
@@ -2217,8 +2227,10 @@ void virQEMUCapsDispose(void *obj)
 
 VIR_FREE(qemuCaps->gicCapabilities);
 
-qemuMonitorCPUModelInfoFree(qemuCaps->hostCPUModelInfo);
-virCPUDefFree(qemuCaps->hostCPUModel);
+qemuMonitorCPUModelInfoFree(qemuCaps->kvmCPUModelInfo);
+qemuMonitorCPUModelInfoFree(qemuCaps->tcgCPUModelInfo);
+virCPUDefFree(qemuCaps->kvmCPUModel);
+virCPUDefFree(qemuCaps->tcgCPUModel);
 }
 
 void
@@ -2435,9 +2447,13 @@ virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
 
 
 virCPUDefPtr
-virQEMUCapsGetHostModel(virQEMUCapsPtr qemuCaps)
+virQEMUCapsGetHostModel(virQEMUCapsPtr qemuCaps,
+virDomainVirtType type)
 {
-return qemuCaps->hostCPUModel;
+if (type == VIR_DOMAIN_VIRT_KVM)
+return qemuCaps->kvmCPUModel;
+else
+return qemuCaps->tcgCPUModel;
 }
 
 
@@ -2455,7 +2471,7 @@ virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch);
 
 case VIR_CPU_MODE_HOST_MODEL:
-return !!qemuCaps->hostCPUModel;
+return !!virQEMUCapsGetHostModel(qemuCaps, type);
 
 case VIR_CPU_MODE_CUSTOM:
 if (type == VIR_DOMAIN_VIRT_KVM)
@@ -2822,14 +2838,24 @@ virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr 
qemuCaps,
 
 static int
 virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
-   qemuMonitorPtr mon)
+   qemuMonitorPtr mon,
+   bool tcg)
 {
-if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION) ||
-!virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
+qemuMonitorCPUModelInfoPtr *modelInfo;
+const char *model;
+
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION))
 return 0;
 
-return qemuMonitorGetCPUModelExpansion(mon, "static", "host",
-   >hostCPUModelInfo);
+if (tcg || !virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) {
+modelInfo = >tcgCPUModelInfo;
+model = "max";
+} else {
+modelInfo = >kvmCPUModelInfo;
+model = "host";
+}
+
+return qemuMonitorGetCPUModelExpansion(mon, "static", model, modelInfo);
 }
 
 struct tpmTypeToCaps {
@@ -3053,12 +3079,16 @@ 

[libvirt] [PATCH 28/33] cputest: Switch host CPU data scripts to model expansion

2017-02-15 Thread Jiri Denemark
Instantiating "host" CPU and querying it using qom-get has been the only
way of probing host CPU via QEMU until 2.9.0 implemented
query-cpu-model-expansion for x86_64. Even though libvirt never really
used the old way its result can be easily converted into the one
produced by query-cpu-model-expansion. Thus we can reuse the original
test data and possible get new data from hosts where QEMU does not
support the new QMP command.

Signed-off-by: Jiri Denemark 
---
 tests/cputestdata/cpu-convert.py | 244 +++
 tests/cputestdata/cpu-gather.sh  |  39 ++-
 tests/cputestdata/cpu-parse.sh   |   3 +
 3 files changed, 280 insertions(+), 6 deletions(-)
 create mode 100755 tests/cputestdata/cpu-convert.py

diff --git a/tests/cputestdata/cpu-convert.py b/tests/cputestdata/cpu-convert.py
new file mode 100755
index 0..5d0876854
--- /dev/null
+++ b/tests/cputestdata/cpu-convert.py
@@ -0,0 +1,244 @@
+#!/usr/bin/python
+
+import sys
+import json
+
+# This is a list of x86 CPU features as of QEMU 2.8.50 and it won't need any
+# updates since in the future because query-cpu-model-expansion will be used
+# with newer QEMU.
+cpuidMap = [
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0001, 
"edx": 0, "names": ["pni", "sse3"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0002, 
"edx": 0, "names": ["pclmulqdq", "pclmuldq"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0004, 
"edx": 0, "names": ["dtes64"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0008, 
"edx": 0, "names": ["monitor"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0010, 
"edx": 0, "names": ["ds-cpl", "ds_cpl"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0020, 
"edx": 0, "names": ["vmx"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0040, 
"edx": 0, "names": ["smx"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0080, 
"edx": 0, "names": ["est"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0100, 
"edx": 0, "names": ["tm2"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0200, 
"edx": 0, "names": ["ssse3"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0400, 
"edx": 0, "names": ["cid"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x1000, 
"edx": 0, "names": ["fma"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x2000, 
"edx": 0, "names": ["cx16"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x4000, 
"edx": 0, "names": ["xtpr"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x8000, 
"edx": 0, "names": ["pdcm"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0002, 
"edx": 0, "names": ["pcid"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0004, 
"edx": 0, "names": ["dca"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0008, 
"edx": 0, "names": ["sse4.1", "sse4-1", "sse4_1"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0010, 
"edx": 0, "names": ["sse4.2", "sse4-2", "sse4_2"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0020, 
"edx": 0, "names": ["x2apic"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0040, 
"edx": 0, "names": ["movbe"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0080, 
"edx": 0, "names": ["popcnt"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0100, 
"edx": 0, "names": ["tsc-deadline"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0200, 
"edx": 0, "names": ["aes"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0400, 
"edx": 0, "names": ["xsave"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x0800, 
"edx": 0, "names": ["osxsave"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x1000, 
"edx": 0, "names": ["avx"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x2000, 
"edx": 0, "names": ["f16c"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x4000, 
"edx": 0, "names": ["rdrand"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0x8000, 
"edx": 0, "names": ["hypervisor"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0, "edx": 
0x0001, "names": ["fpu"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0, "edx": 
0x0002, "names": ["vme"]},
+{"in_eax": 0x0001, "in_ecx": 0, "eax": 0, "ebx": 0, "ecx": 0, "edx": 
0x0004, "names": ["de"]},
+{"in_eax": 0x0001, 

[libvirt] [PATCH 05/33] qemu: Refactor virQEMUCapsInitHostCPUModel

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_capabilities.c | 109 ++-
 1 file changed, 55 insertions(+), 54 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 399e31447..c5e57b4ab 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3041,37 +3041,36 @@ virQEMUCapsCPUFilterFeatures(const char *name,
 }
 
 
-static void
-virQEMUCapsCopyCPUModelFromQEMU(virQEMUCapsPtr qemuCaps)
+/**
+ * Returns  0 when host CPU model provided by QEMU was filled in qemuCaps,
+ *  1 when the caller should fall back to using virCapsPtr->host.cpu,
+ * -1 on error.
+ */
+static int
+virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps,
+virCPUDefPtr cpu)
 {
-virCPUDefPtr cpu = NULL;
-qemuMonitorCPUModelInfoPtr modelInfo = NULL;
+qemuMonitorCPUModelInfoPtr modelInfo = qemuCaps->hostCPUModelInfo;
 size_t i;
 
-if (!(modelInfo = qemuCaps->hostCPUModelInfo)) {
+if (!modelInfo) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("missing host CPU model info from QEMU capabilities"
- " for binary %s"), qemuCaps->binary);
-goto error;
+   _("missing host CPU model info from QEMU capabilities "
+ "for binary %s"),
+   qemuCaps->binary);
+return -1;
 }
 
-if (VIR_ALLOC(cpu) < 0)
-goto error;
-
 if (VIR_STRDUP(cpu->model, modelInfo->name) < 0 ||
 VIR_ALLOC_N(cpu->features, modelInfo->nprops) < 0)
-goto error;
+return -1;
 
 cpu->nfeatures_max = modelInfo->nprops;
 cpu->nfeatures = 0;
-cpu->sockets = cpu->cores = cpu->threads = 0;
-cpu->type = VIR_CPU_TYPE_GUEST;
-cpu->mode = VIR_CPU_MODE_CUSTOM;
-cpu->match = VIR_CPU_MATCH_EXACT;
 
 for (i = 0; i < modelInfo->nprops; i++) {
 if (VIR_STRDUP(cpu->features[i].name, modelInfo->props[i].name) < 0)
-goto error;
+return -1;
 
 if (modelInfo->props[i].supported)
 cpu->features[i].policy = VIR_CPU_FEATURE_REQUIRE;
@@ -3081,31 +3080,53 @@ virQEMUCapsCopyCPUModelFromQEMU(virQEMUCapsPtr qemuCaps)
 cpu->nfeatures++;
 }
 
-qemuCaps->hostCPUModel = cpu;
-return;
-
- error:
-virCPUDefFree(cpu);
-qemuCaps->hostCPUModel = NULL;
-virResetLastError();
+return 0;
 }
 
 
-static void
-virQEMUCapsCopyCPUModelFromHost(virQEMUCapsPtr qemuCaps,
-virCapsPtr caps)
+/**
+ * Returns  0 when host CPU model provided by QEMU was filled in qemuCaps,
+ *  1 when the caller should fall back to using virCapsPtr->host.cpu,
+ * -1 on error.
+ */
+static int
+virQEMUCapsInitCPUModel(virQEMUCapsPtr qemuCaps,
+virCPUDefPtr cpu)
+{
+int ret = 1;
+
+if (ARCH_IS_S390(qemuCaps->arch))
+ret = virQEMUCapsInitCPUModelS390(qemuCaps, cpu);
+
+return ret;
+}
+
+
+void
+virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
+virCapsPtr caps)
 {
 virCPUDefPtr cpu = NULL;
+int rc;
 
-if (caps->host.cpu && caps->host.cpu->model) {
-if (VIR_ALLOC(cpu) < 0)
+if (!caps || !virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch))
+return;
+
+if (VIR_ALLOC(cpu) < 0)
+goto error;
+
+cpu->type = VIR_CPU_TYPE_GUEST;
+cpu->mode = VIR_CPU_MODE_CUSTOM;
+cpu->match = VIR_CPU_MATCH_EXACT;
+cpu->fallback = VIR_CPU_FALLBACK_ALLOW;
+
+if ((rc = virQEMUCapsInitCPUModel(qemuCaps, cpu)) < 0) {
+goto error;
+} else if (rc == 1) {
+VIR_DEBUG("No host CPU model info from QEMU; using host capabilities");
+if (!caps->host.cpu || !caps->host.cpu->model)
 goto error;
 
-cpu->sockets = cpu->cores = cpu->threads = 0;
-cpu->type = VIR_CPU_TYPE_GUEST;
-cpu->mode = VIR_CPU_MODE_CUSTOM;
-cpu->match = VIR_CPU_MATCH_EXACT;
-
 if (virCPUDefCopyModelFilter(cpu, caps->host.cpu, true,
  virQEMUCapsCPUFilterFeatures, NULL) < 0)
 goto error;
@@ -3116,30 +3137,10 @@ virQEMUCapsCopyCPUModelFromHost(virQEMUCapsPtr qemuCaps,
 
  error:
 virCPUDefFree(cpu);
-qemuCaps->hostCPUModel = NULL;
 virResetLastError();
 }
 
 
-void
-virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
-virCapsPtr caps)
-{
-if (!caps || !virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch))
-return;
-
-switch (qemuCaps->arch) {
-case VIR_ARCH_S390:
-case VIR_ARCH_S390X:
-virQEMUCapsCopyCPUModelFromQEMU(qemuCaps);
-break;
-
-default:
-virQEMUCapsCopyCPUModelFromHost(qemuCaps, caps);
-}
-}
-
-
 static int
 virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
 xmlXPathContextPtr ctxt)
-- 
2.11.1


[libvirt] [PATCH 14/33] cpu_x86: Drop virCPUx86MakeData and use virCPUDataNew

2017-02-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 src/cpu/cpu_x86.c  | 147 ++---
 src/cpu/cpu_x86.h  |   3 -
 src/libvirt_private.syms   |   1 -
 src/libxl/libxl_capabilities.c |  18 ++---
 src/qemu/qemu_monitor_json.c   |  33 -
 5 files changed, 92 insertions(+), 110 deletions(-)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index d9764a260..ccd68b681 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -303,22 +303,6 @@ virCPUx86DataClear(virCPUx86Data *data)
 }
 
 
-virCPUDataPtr
-virCPUx86MakeData(virArch arch, virCPUx86Data *data)
-{
-virCPUDataPtr cpuData;
-
-if (VIR_ALLOC(cpuData) < 0)
-return NULL;
-
-cpuData->arch = arch;
-cpuData->data.x86 = *data;
-data->len = 0;
-data->data = NULL;
-
-return cpuData;
-}
-
 static void
 x86FreeCPUData(virCPUDataPtr data)
 {
@@ -1441,7 +1425,6 @@ virCPUx86DataParse(xmlXPathContextPtr ctxt)
 {
 xmlNodePtr *nodes = NULL;
 virCPUDataPtr cpuData = NULL;
-virCPUx86Data data = VIR_CPU_X86_DATA_INIT;
 virCPUx86CPUID cpuid;
 size_t i;
 int n;
@@ -1450,26 +1433,31 @@ virCPUx86DataParse(xmlXPathContextPtr ctxt)
 if (n <= 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("no x86 CPU data found"));
-goto cleanup;
+goto error;
 }
 
+if (!(cpuData = virCPUDataNew(VIR_ARCH_X86_64)))
+goto error;
+
 for (i = 0; i < n; i++) {
 ctxt->node = nodes[i];
 if (x86ParseCPUID(ctxt, ) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse cpuid[%zu]"), i);
-goto cleanup;
+goto error;
 }
-if (virCPUx86DataAddCPUID(, ) < 0)
-goto cleanup;
+if (virCPUx86DataAddCPUID(>data.x86, ) < 0)
+goto error;
 }
 
-cpuData = virCPUx86MakeData(VIR_ARCH_X86_64, );
-
  cleanup:
 VIR_FREE(nodes);
-virCPUx86DataClear();
 return cpuData;
+
+ error:
+x86FreeCPUData(cpuData);
+cpuData = NULL;
+goto cleanup;
 }
 
 
@@ -1514,7 +1502,7 @@ x86Compute(virCPUDefPtr host,
 virCPUx86ModelPtr cpu_forbid = NULL;
 virCPUx86ModelPtr diff = NULL;
 virCPUx86ModelPtr guest_model = NULL;
-virCPUx86Data guestData = VIR_CPU_X86_DATA_INIT;
+virCPUDataPtr guestData = NULL;
 virCPUCompareResult ret;
 virCPUx86CompareResult result;
 virArch arch;
@@ -1633,9 +1621,11 @@ x86Compute(virCPUDefPtr host,
 
 x86DataSubtract(_model->data, _disable->data);
 
-if (x86DataCopy(, _model->data) < 0 ||
-!(*guest = virCPUx86MakeData(arch, )))
+if (!(guestData = virCPUDataNew(arch)) ||
+x86DataCopy(>data.x86, _model->data) < 0)
 goto error;
+
+*guest = guestData;
 }
 
  cleanup:
@@ -1647,11 +1637,11 @@ x86Compute(virCPUDefPtr host,
 x86ModelFree(cpu_disable);
 x86ModelFree(cpu_forbid);
 x86ModelFree(guest_model);
-virCPUx86DataClear();
 
 return ret;
 
  error:
+x86FreeCPUData(guestData);
 ret = VIR_CPU_COMPARE_ERROR;
 goto cleanup;
 }
@@ -1958,12 +1948,12 @@ x86Encode(virArch arch,
   virCPUDataPtr *vendor)
 {
 virCPUx86MapPtr map = NULL;
-virCPUx86Data data_forced = VIR_CPU_X86_DATA_INIT;
-virCPUx86Data data_required = VIR_CPU_X86_DATA_INIT;
-virCPUx86Data data_optional = VIR_CPU_X86_DATA_INIT;
-virCPUx86Data data_disabled = VIR_CPU_X86_DATA_INIT;
-virCPUx86Data data_forbidden = VIR_CPU_X86_DATA_INIT;
-virCPUx86Data data_vendor = VIR_CPU_X86_DATA_INIT;
+virCPUDataPtr data_forced = NULL;
+virCPUDataPtr data_required = NULL;
+virCPUDataPtr data_optional = NULL;
+virCPUDataPtr data_disabled = NULL;
+virCPUDataPtr data_forbidden = NULL;
+virCPUDataPtr data_vendor = NULL;
 
 if (forced)
 *forced = NULL;
@@ -1982,23 +1972,33 @@ x86Encode(virArch arch,
 goto error;
 
 if (forced &&
-x86EncodePolicy(_forced, cpu, map, VIR_CPU_FEATURE_FORCE) < 0)
+(!(data_forced = virCPUDataNew(arch)) ||
+ x86EncodePolicy(_forced->data.x86, cpu, map,
+ VIR_CPU_FEATURE_FORCE) < 0))
 goto error;
 
 if (required &&
-x86EncodePolicy(_required, cpu, map, VIR_CPU_FEATURE_REQUIRE) < 0)
+(!(data_required = virCPUDataNew(arch)) ||
+ x86EncodePolicy(_required->data.x86, cpu, map,
+ VIR_CPU_FEATURE_REQUIRE) < 0))
 goto error;
 
 if (optional &&
-x86EncodePolicy(_optional, cpu, map, VIR_CPU_FEATURE_OPTIONAL) < 
0)
+(!(data_optional = virCPUDataNew(arch)) ||
+ x86EncodePolicy(_optional->data.x86, cpu, map,
+ VIR_CPU_FEATURE_OPTIONAL) < 0))
 goto error;
 
 if (disabled &&
-x86EncodePolicy(_disabled, cpu, map, VIR_CPU_FEATURE_DISABLE) < 0)
+(!(data_disabled = virCPUDataNew(arch)) ||
+

  1   2   >