Re: [PATCH 2/2] msix: Pull in config.h for CONFIG_KVM

2010-10-23 Thread Paolo Bonzini

On 10/23/2010 03:50 AM, Alex Williamson wrote:

Oops, memory.c isn't upstream, I'll push it down in my patch queue and
send a new one.


Neither is kvm_set_irq actually. :)  This patch is only needed for qemu-kvm.

BTW, maybe the better solution would be to move the kvm_*_irq* functions 
from qemu-kvm.c to kvm-all.c, add stubs to kvm-stub.c, and get rid of 
the #ifdef completely in msix.c


Paolo
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[no subject]

2010-10-23 Thread satimis

http://satimis.blog-discount.com
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [SeaBIOS] [PATCH] mark irq9 active high in DSDT

2010-10-23 Thread Kevin O'Connor
On Thu, Oct 21, 2010 at 12:07:17PM +0200, Avi Kivity wrote:
 How do we manage the stable series wrt this issue?
 
 qemu-kvm-0.12.5 has a regression within the stable series that this
 patch fixes.  qemu 0.12.5 does not, but only because it does not
 emulate polarity in the I/O APIC correctly.
 
 There are several paths we could take:
 
 - do nothing, bug is fixed in mainline
 - release a seabios 0.x.1 for qemu 0.13.1 with this patch
 - same, plus seabios 0.y.1 for qemu 0.12.6 with this patch
 - skip qemu (which is not truly affected), patch qemu-kvm's copy of
 seabios for both 0.12.z and 0.13.z
 
 The third option is the most correct from a release engineering
 point of view, but involves more work for everyone.

I'm okay with making tags and branches of seabios for bug fixes.  So
far qemu/kvm has just grabbed various builds of seabios - is it
worthwhile to branch off of the seabios-0.6.1 version - which would
mean qemu/kvm would pull in additional changes beyond the bug fix
above?

-Kevin
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] msix: Pull in config.h for CONFIG_KVM

2010-10-23 Thread Michael S. Tsirkin
On Fri, Oct 22, 2010 at 02:40:39PM -0600, Alex Williamson wrote:
 We need to pull in config.h or else kvm.h doesn't pull in
 linux/config.h, which we need if we ever want KVM_CAP_IRQCHIP
 defined.  This requires moving the object over to Makefile.target
 or else we can't find config-target.h
 
 Signed-off-by: Alex Williamson alex.william...@redhat.com

Why? We just moved it from .target to .objs, see
889e30cc18e21f2091b77267dca8096d7dd34f8b.

 ---
 
  Makefile.objs   |2 --
  Makefile.target |1 +
  hw/msix.c   |1 +
  3 files changed, 2 insertions(+), 2 deletions(-)
 
 diff --git a/Makefile.objs b/Makefile.objs
 index ca2d2d0..c097d25 100644
 --- a/Makefile.objs
 +++ b/Makefile.objs
 @@ -201,8 +201,6 @@ hw-obj-$(CONFIG_PIIX4) += piix4.o
  # PCI watchdog devices
  hw-obj-y += wdt_i6300esb.o
  
 -hw-obj-y += msix.o
 -
  # PCI network cards
  hw-obj-y += ne2000.o
  hw-obj-y += eepro100.o
 diff --git a/Makefile.target b/Makefile.target
 index 347ad6b..63da13b 100644
 --- a/Makefile.target
 +++ b/Makefile.target
 @@ -185,6 +185,7 @@ obj-y += rwhandler.o
  obj-$(CONFIG_KVM) += kvm.o kvm-all.o
  obj-$(CONFIG_NO_KVM) += kvm-stub.o
  obj-y += memory.o
 +obj-y += msix.o
  
  LIBS+=-lz
  
 diff --git a/hw/msix.c b/hw/msix.c
 index 4122395..23256c9 100644
 --- a/hw/msix.c
 +++ b/hw/msix.c
 @@ -11,6 +11,7 @@
   * the COPYING file in the top-level directory.
   */
  
 +#include config.h
  #include hw.h
  #include msix.h
  #include pci.h
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] msix: Allow msix_init on a device with existing MSI-X capability

2010-10-23 Thread Michael S. Tsirkin
On Fri, Oct 22, 2010 at 02:40:31PM -0600, Alex Williamson wrote:
 To enable common msix support to be used with pass through devices,
 don't attempt to change the BAR if the device already has an
 MSI-X capability.  This also means we want to pay closer attention
 to the size when we map the msix table page, as it isn't necessarily
 covering the entire end of the BAR.
 
 Signed-off-by: Alex Williamson alex.william...@redhat.com
 ---
 
  hw/msix.c |   67 
 +++--
  1 files changed, 38 insertions(+), 29 deletions(-)
 
 diff --git a/hw/msix.c b/hw/msix.c
 index 43efbd2..4122395 100644
 --- a/hw/msix.c
 +++ b/hw/msix.c
 @@ -167,35 +167,43 @@ static int msix_add_config(struct PCIDevice *pdev, 
 unsigned short nentries,
  {
  int config_offset;
  uint8_t *config;
 -uint32_t new_size;
  
 -if (nentries  1 || nentries  PCI_MSIX_FLAGS_QSIZE + 1)
 -return -EINVAL;
 -if (bar_size  0x8000)
 -return -ENOSPC;
 -
 -/* Add space for MSI-X structures */
 -if (!bar_size) {
 -new_size = MSIX_PAGE_SIZE;
 -} else if (bar_size  MSIX_PAGE_SIZE) {
 -bar_size = MSIX_PAGE_SIZE;
 -new_size = MSIX_PAGE_SIZE * 2;
 -} else {
 -new_size = bar_size * 2;
 -}
 -
 -pdev-msix_bar_size = new_size;
 -config_offset = pci_add_capability(pdev, PCI_CAP_ID_MSIX, 
 MSIX_CAP_LENGTH);
 -if (config_offset  0)
 -return config_offset;
 -config = pdev-config + config_offset;
 -
 -pci_set_word(config + PCI_MSIX_FLAGS, nentries - 1);
 -/* Table on top of BAR */
 -pci_set_long(config + MSIX_TABLE_OFFSET, bar_size | bar_nr);
 -/* Pending bits on top of that */
 -pci_set_long(config + MSIX_PBA_OFFSET, (bar_size + MSIX_PAGE_PENDING) |
 - bar_nr);
 +pdev-msix_bar_size = bar_size;
 +
 +config_offset = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
 +
 +if (!config_offset) {
 +uint32_t new_size;
 +
 +if (nentries  1 || nentries  PCI_MSIX_FLAGS_QSIZE + 1)
 +return -EINVAL;
 +if (bar_size  0x8000)
 +return -ENOSPC;
 +
 +/* Add space for MSI-X structures */
 +if (!bar_size) {
 +new_size = MSIX_PAGE_SIZE;
 +} else if (bar_size  MSIX_PAGE_SIZE) {
 +bar_size = MSIX_PAGE_SIZE;
 +new_size = MSIX_PAGE_SIZE * 2;
 +} else {
 +new_size = bar_size * 2;
 +}
 +
 +pdev-msix_bar_size = new_size;
 +config_offset = pci_add_capability(pdev, PCI_CAP_ID_MSIX,
 +   MSIX_CAP_LENGTH);
 +if (config_offset  0)
 +return config_offset;
 +config = pdev-config + config_offset;
 +
 +pci_set_word(config + PCI_MSIX_FLAGS, nentries - 1);
 +/* Table on top of BAR */
 +pci_set_long(config + MSIX_TABLE_OFFSET, bar_size | bar_nr);
 +/* Pending bits on top of that */
 +pci_set_long(config + MSIX_PBA_OFFSET, (bar_size + 
 MSIX_PAGE_PENDING) |
 + bar_nr);
 +}
  pdev-msix_cap = config_offset;
  /* Make flags bit writeable. */
  pdev-wmask[config_offset + MSIX_CONTROL_OFFSET] |= MSIX_ENABLE_MASK |
 @@ -337,7 +345,8 @@ void msix_mmio_map(PCIDevice *d, int region_num,
  return;
  if (size = offset)
  return;
 -cpu_register_physical_memory(addr + offset, size - offset,
 +cpu_register_physical_memory(addr + offset,
 + MIN(size - offset, MSIX_PAGE_SIZE),

This is wrong I think, the table might not fit in a single page.
You would need to read table size out of from device config.

   d-msix_mmio_index);
  }
  
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] msix: Pull in config.h for CONFIG_KVM

2010-10-23 Thread Alex Williamson
On Sat, 2010-10-23 at 18:16 +0200, Michael S. Tsirkin wrote:
 On Fri, Oct 22, 2010 at 02:40:39PM -0600, Alex Williamson wrote:
  We need to pull in config.h or else kvm.h doesn't pull in
  linux/config.h, which we need if we ever want KVM_CAP_IRQCHIP
  defined.  This requires moving the object over to Makefile.target
  or else we can't find config-target.h
  
  Signed-off-by: Alex Williamson alex.william...@redhat.com
 
 Why? We just moved it from .target to .objs, see
 889e30cc18e21f2091b77267dca8096d7dd34f8b.

Maybe that's why it used to work.  When building in the qemu-kvm.git
tree, I'm not getting CONFIG_KVM defined, which means I'm not getting
KVM_CAP_IRQCHIP defined, which results in msix_irq_entries not being
allocated.  Then when I call msix_vector_use, I get a seg fault.
Something is broken there.  Thanks,

Alex

  ---
  
   Makefile.objs   |2 --
   Makefile.target |1 +
   hw/msix.c   |1 +
   3 files changed, 2 insertions(+), 2 deletions(-)
  
  diff --git a/Makefile.objs b/Makefile.objs
  index ca2d2d0..c097d25 100644
  --- a/Makefile.objs
  +++ b/Makefile.objs
  @@ -201,8 +201,6 @@ hw-obj-$(CONFIG_PIIX4) += piix4.o
   # PCI watchdog devices
   hw-obj-y += wdt_i6300esb.o
   
  -hw-obj-y += msix.o
  -
   # PCI network cards
   hw-obj-y += ne2000.o
   hw-obj-y += eepro100.o
  diff --git a/Makefile.target b/Makefile.target
  index 347ad6b..63da13b 100644
  --- a/Makefile.target
  +++ b/Makefile.target
  @@ -185,6 +185,7 @@ obj-y += rwhandler.o
   obj-$(CONFIG_KVM) += kvm.o kvm-all.o
   obj-$(CONFIG_NO_KVM) += kvm-stub.o
   obj-y += memory.o
  +obj-y += msix.o
   
   LIBS+=-lz
   
  diff --git a/hw/msix.c b/hw/msix.c
  index 4122395..23256c9 100644
  --- a/hw/msix.c
  +++ b/hw/msix.c
  @@ -11,6 +11,7 @@
* the COPYING file in the top-level directory.
*/
   
  +#include config.h
   #include hw.h
   #include msix.h
   #include pci.h



--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] msix: Allow msix_init on a device with existing MSI-X capability

2010-10-23 Thread Alex Williamson
On Sat, 2010-10-23 at 18:18 +0200, Michael S. Tsirkin wrote:
 On Fri, Oct 22, 2010 at 02:40:31PM -0600, Alex Williamson wrote:
  To enable common msix support to be used with pass through devices,
  don't attempt to change the BAR if the device already has an
  MSI-X capability.  This also means we want to pay closer attention
  to the size when we map the msix table page, as it isn't necessarily
  covering the entire end of the BAR.
  
  Signed-off-by: Alex Williamson alex.william...@redhat.com
  ---
  
   hw/msix.c |   67 
  +++--
   1 files changed, 38 insertions(+), 29 deletions(-)
  
  diff --git a/hw/msix.c b/hw/msix.c
  index 43efbd2..4122395 100644
  --- a/hw/msix.c
  +++ b/hw/msix.c
  @@ -167,35 +167,43 @@ static int msix_add_config(struct PCIDevice *pdev, 
  unsigned short nentries,
   {
   int config_offset;
   uint8_t *config;
  -uint32_t new_size;
   
  -if (nentries  1 || nentries  PCI_MSIX_FLAGS_QSIZE + 1)
  -return -EINVAL;
  -if (bar_size  0x8000)
  -return -ENOSPC;
  -
  -/* Add space for MSI-X structures */
  -if (!bar_size) {
  -new_size = MSIX_PAGE_SIZE;
  -} else if (bar_size  MSIX_PAGE_SIZE) {
  -bar_size = MSIX_PAGE_SIZE;
  -new_size = MSIX_PAGE_SIZE * 2;
  -} else {
  -new_size = bar_size * 2;
  -}
  -
  -pdev-msix_bar_size = new_size;
  -config_offset = pci_add_capability(pdev, PCI_CAP_ID_MSIX, 
  MSIX_CAP_LENGTH);
  -if (config_offset  0)
  -return config_offset;
  -config = pdev-config + config_offset;
  -
  -pci_set_word(config + PCI_MSIX_FLAGS, nentries - 1);
  -/* Table on top of BAR */
  -pci_set_long(config + MSIX_TABLE_OFFSET, bar_size | bar_nr);
  -/* Pending bits on top of that */
  -pci_set_long(config + MSIX_PBA_OFFSET, (bar_size + MSIX_PAGE_PENDING) |
  - bar_nr);
  +pdev-msix_bar_size = bar_size;
  +
  +config_offset = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  +
  +if (!config_offset) {
  +uint32_t new_size;
  +
  +if (nentries  1 || nentries  PCI_MSIX_FLAGS_QSIZE + 1)
  +return -EINVAL;
  +if (bar_size  0x8000)
  +return -ENOSPC;
  +
  +/* Add space for MSI-X structures */
  +if (!bar_size) {
  +new_size = MSIX_PAGE_SIZE;
  +} else if (bar_size  MSIX_PAGE_SIZE) {
  +bar_size = MSIX_PAGE_SIZE;
  +new_size = MSIX_PAGE_SIZE * 2;
  +} else {
  +new_size = bar_size * 2;
  +}
  +
  +pdev-msix_bar_size = new_size;
  +config_offset = pci_add_capability(pdev, PCI_CAP_ID_MSIX,
  +   MSIX_CAP_LENGTH);
  +if (config_offset  0)
  +return config_offset;
  +config = pdev-config + config_offset;
  +
  +pci_set_word(config + PCI_MSIX_FLAGS, nentries - 1);
  +/* Table on top of BAR */
  +pci_set_long(config + MSIX_TABLE_OFFSET, bar_size | bar_nr);
  +/* Pending bits on top of that */
  +pci_set_long(config + MSIX_PBA_OFFSET, (bar_size + 
  MSIX_PAGE_PENDING) |
  + bar_nr);
  +}
   pdev-msix_cap = config_offset;
   /* Make flags bit writeable. */
   pdev-wmask[config_offset + MSIX_CONTROL_OFFSET] |= MSIX_ENABLE_MASK |
  @@ -337,7 +345,8 @@ void msix_mmio_map(PCIDevice *d, int region_num,
   return;
   if (size = offset)
   return;
  -cpu_register_physical_memory(addr + offset, size - offset,
  +cpu_register_physical_memory(addr + offset,
  + MIN(size - offset, MSIX_PAGE_SIZE),
 
 This is wrong I think, the table might not fit in a single page.
 You would need to read table size out of from device config.

That's true, but I was hoping to save that for later since we don't seem
to be running into that problem yet.  Current device assignment code
assumes a single page, and I haven't heard of anyone with a vector table
that exceeds that yet.  Thanks,

Alex


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] msix: Pull in config.h for CONFIG_KVM

2010-10-23 Thread Michael S. Tsirkin
On Sat, Oct 23, 2010 at 10:52:43AM -0600, Alex Williamson wrote:
 On Sat, 2010-10-23 at 18:16 +0200, Michael S. Tsirkin wrote:
  On Fri, Oct 22, 2010 at 02:40:39PM -0600, Alex Williamson wrote:
   We need to pull in config.h or else kvm.h doesn't pull in
   linux/config.h, which we need if we ever want KVM_CAP_IRQCHIP
   defined.  This requires moving the object over to Makefile.target
   or else we can't find config-target.h
   
   Signed-off-by: Alex Williamson alex.william...@redhat.com
  
  Why? We just moved it from .target to .objs, see
  889e30cc18e21f2091b77267dca8096d7dd34f8b.
 
 Maybe that's why it used to work.  When building in the qemu-kvm.git
 tree, I'm not getting CONFIG_KVM defined, which means I'm not getting
 KVM_CAP_IRQCHIP defined, which results in msix_irq_entries not being
 allocated.  Then when I call msix_vector_use, I get a seg fault.
 Something is broken there.  Thanks,
 
 Alex

This is hopefully fixed in the latest bits.
bd8b215bce453706c3951460cc7e6627ccb90314

-- 
MST
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


qemu 0.13.0: threaded vnc and boot=once are broken

2010-10-23 Thread Nix
So I've been using QEMU/KVM 0.12.5 happily to boot both various Linux
distributions and Windows XP. I upgraded to 0.13.0 (tip of stable-0.13
branch) to get virtio-serial (which recent libguestfses require).
I configured with --enable-vnc-thread because a quick perusal of relevant
list discussions suggested that it had only been disabled because of
poor Windows threading support in qemu, and that it might reduce
blocking a bit.  However, upon upgrading, I find that my normal
XP-booting command-line no longer works (and neither do my command-lines
for Fedora et al, I suspect):

/usr/bin/qemu-system-x86_64 -M pc-0.12 -cpu qemu32 -enable-kvm -m 4096 -smp 2 
-name activated-windows -vnc spindle:9 -boot once=d -drive 
file=/vm/windows/activated.img,if=ide,index=0,boot=on,cache=writeback,serial=8402:1CFE
 -cdrom /dev/cdrom -net 
nic,macaddr=52:54:00:4b:f7:7f,vlan=0,model=ne2k_pci,name=eth0 -net 
tap,vlan=0,ifname=windows,script=/sbin/qemu-windows-full.ifup,downscript=/sbin/qemu-windows-full.ifdown
 -parallel none -usb -usbdevice tablet -k en-gb -vga std -rtc base=localtime 
-soundhw ac97 -runas windows-vm -pidfile /var/run/qemu/windows.pid -serial 
mon:telnet::10404,server,nowait

yields:

,
| Starting SeaBIOS (version pre-0.6.1-20100713_085324-titi=
| 
| 
| 
| gPXE (http://etherboot.org) - 0:00.0 CD00 PCI2.10 PnP BBS pmmd...@10 CD00
| 
| Booting from CD/DVD...
| 
| 1023MB medium detected
| 
| Boot failed: Could not read from CDROM (code 0004)
| No bootable device.
`

i.e., qemu has treated my '-boot once=d' as a '-boot d', even though
that was install-time-only and it should have done a '-boot c'.

So, I take the -boot out (it's not really necessary anymore), only to
get this on qemu's stderr:

qemu: qemu_mutex_lock: Invalid argument

Running with -sdl instead of -vnc fixes this. Configuring without
--enable-vnc-thread fixes it too. So it looks like --enable-vnc-thread
may be disabled by default because it is broken, as well. One comment
suggested that commit ac71103dc6b408775ae72067790ab367912f75ec may fix
this, but this was cherry-picked for 0.13.x without solving the problem
(for me at least).


(An unjustifiably snarky aside: has anyone considered actual release
notes? It is terribly hard to figure out what effect the vast flood of
qemu changes between versions will actually have short of reading the
entire git log and mailing list archives: the ten-line qemu 0.13
'release notes' didn't even *mention* VNC threading, for instance.
What's the point of adding a feature if nobody's told it exists? qemu
already has so very many nifty features that there's not much chance of
people stumbling over new features by chance. It gives everyone a little
bit of egoboo to see their feature in lights, as well. :) )
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] msix: Pull in config.h for CONFIG_KVM

2010-10-23 Thread Alex Williamson
On Sat, 2010-10-23 at 19:29 +0200, Michael S. Tsirkin wrote:
 On Sat, Oct 23, 2010 at 10:52:43AM -0600, Alex Williamson wrote:
  On Sat, 2010-10-23 at 18:16 +0200, Michael S. Tsirkin wrote:
   On Fri, Oct 22, 2010 at 02:40:39PM -0600, Alex Williamson wrote:
We need to pull in config.h or else kvm.h doesn't pull in
linux/config.h, which we need if we ever want KVM_CAP_IRQCHIP
defined.  This requires moving the object over to Makefile.target
or else we can't find config-target.h

Signed-off-by: Alex Williamson alex.william...@redhat.com
   
   Why? We just moved it from .target to .objs, see
   889e30cc18e21f2091b77267dca8096d7dd34f8b.
  
  Maybe that's why it used to work.  When building in the qemu-kvm.git
  tree, I'm not getting CONFIG_KVM defined, which means I'm not getting
  KVM_CAP_IRQCHIP defined, which results in msix_irq_entries not being
  allocated.  Then when I call msix_vector_use, I get a seg fault.
  Something is broken there.  Thanks,
  
  Alex
 
 This is hopefully fixed in the latest bits.
 bd8b215bce453706c3951460cc7e6627ccb90314

Nope, my tree includes that.  It's not kvm_set_irq, it's kvm_msix_add,
which dereferences msix_irq_entries, which is only allocated in
msix_init if KVM_CAP_IRQCHIP is defined, which it's not.  Maybe you also
meant to remove the ifdef from msix_init?  I also note there's another
in msix_notify.  Thanks,

Alex

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] msix: Pull in config.h for CONFIG_KVM

2010-10-23 Thread Michael S. Tsirkin
On Sat, Oct 23, 2010 at 12:42:44PM -0600, Alex Williamson wrote:
 On Sat, 2010-10-23 at 19:29 +0200, Michael S. Tsirkin wrote:
  On Sat, Oct 23, 2010 at 10:52:43AM -0600, Alex Williamson wrote:
   On Sat, 2010-10-23 at 18:16 +0200, Michael S. Tsirkin wrote:
On Fri, Oct 22, 2010 at 02:40:39PM -0600, Alex Williamson wrote:
 We need to pull in config.h or else kvm.h doesn't pull in
 linux/config.h, which we need if we ever want KVM_CAP_IRQCHIP
 defined.  This requires moving the object over to Makefile.target
 or else we can't find config-target.h
 
 Signed-off-by: Alex Williamson alex.william...@redhat.com

Why? We just moved it from .target to .objs, see
889e30cc18e21f2091b77267dca8096d7dd34f8b.
   
   Maybe that's why it used to work.  When building in the qemu-kvm.git
   tree, I'm not getting CONFIG_KVM defined, which means I'm not getting
   KVM_CAP_IRQCHIP defined, which results in msix_irq_entries not being
   allocated.  Then when I call msix_vector_use, I get a seg fault.
   Something is broken there.  Thanks,
   
   Alex
  
  This is hopefully fixed in the latest bits.
  bd8b215bce453706c3951460cc7e6627ccb90314
 
 Nope, my tree includes that.  It's not kvm_set_irq, it's kvm_msix_add,
 which dereferences msix_irq_entries, which is only allocated in
 msix_init if KVM_CAP_IRQCHIP is defined, which it's not.  Maybe you also
 meant to remove the ifdef from msix_init?  I also note there's another
 in msix_notify.  Thanks,
 
 Alex

Not sure what's wrong:
$git grep KVM_CAP_IRQCHIP origin/master -- hw/msix.c
$

http://git.kernel.org/?p=virt/kvm/qemu-kvm.git;a=blob;f=hw/msix.c;hb=HEAD

also does not show any ifdefs.

-- 
MST
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] msix: Pull in config.h for CONFIG_KVM

2010-10-23 Thread Alex Williamson
On Sat, Oct 23, 2010 at 2:38 PM, Michael S. Tsirkin m...@redhat.com wrote:
 On Sat, Oct 23, 2010 at 12:42:44PM -0600, Alex Williamson wrote:
 On Sat, 2010-10-23 at 19:29 +0200, Michael S. Tsirkin wrote:
  On Sat, Oct 23, 2010 at 10:52:43AM -0600, Alex Williamson wrote:
   On Sat, 2010-10-23 at 18:16 +0200, Michael S. Tsirkin wrote:
On Fri, Oct 22, 2010 at 02:40:39PM -0600, Alex Williamson wrote:
 We need to pull in config.h or else kvm.h doesn't pull in
 linux/config.h, which we need if we ever want KVM_CAP_IRQCHIP
 defined.  This requires moving the object over to Makefile.target
 or else we can't find config-target.h

 Signed-off-by: Alex Williamson alex.william...@redhat.com
   
Why? We just moved it from .target to .objs, see
889e30cc18e21f2091b77267dca8096d7dd34f8b.
  
   Maybe that's why it used to work.  When building in the qemu-kvm.git
   tree, I'm not getting CONFIG_KVM defined, which means I'm not getting
   KVM_CAP_IRQCHIP defined, which results in msix_irq_entries not being
   allocated.  Then when I call msix_vector_use, I get a seg fault.
   Something is broken there.  Thanks,
  
   Alex
 
  This is hopefully fixed in the latest bits.
  bd8b215bce453706c3951460cc7e6627ccb90314

 Nope, my tree includes that.  It's not kvm_set_irq, it's kvm_msix_add,
 which dereferences msix_irq_entries, which is only allocated in
 msix_init if KVM_CAP_IRQCHIP is defined, which it's not.  Maybe you also
 meant to remove the ifdef from msix_init?  I also note there's another
 in msix_notify.  Thanks,

 Alex

 Not sure what's wrong:
 $git grep KVM_CAP_IRQCHIP origin/master -- hw/msix.c
 $

 http://git.kernel.org/?p=virt/kvm/qemu-kvm.git;a=blob;f=hw/msix.c;hb=HEAD

 also does not show any ifdefs.

Hmm, somehow my tree missed 763a04a920f1098e57ad6b46c91c3e531adc961d
Ignore this patch and I'll refresh again.  Sorry for the noise.

Alex
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Gests periodically stuck for ~ 10-15 seconds - what to do?

2010-10-23 Thread Hermann Himmelbauer
Am Samstag 23 Oktober 2010 22:37:41 schrieb Hermann Himmelbauer:
 Hi,
 I'm quite new to virtualization and KVM, I have a 2*4-core Intel machine
 here with 16GB RAM and Debian Lenny as host. I further installed two Debian
 Lenny guests, one with 2 CPUs, the other with one. The guests were
 installed similar to this:

 virt-install --connect qemu:///system -n MyVMName -r 1024 --vcpus=2 -f
 path/to/qcow2_file -s 12 -c ~/debian-503-amd64-netinst.iso --vnc -k
 de --noautoconsole --os-type linux --os-variant
 debianLenny --accelerate --network=bridge:br0 --hvm

Regarding a suggestion on #IRC that the above does not tell enough about the 
KVM configuration, here are the command lines for both guests:

/usr/bin/kvm -S -M pc-0.12 -enable-kvm -m 1024 -smp 
2,sockets=2,cores=1,threads=1 -name vmUranos -uuid 
8e5139ce-c561-c52f-35e1-07db9bc5045b -nodefaults -chardev 
socket,id=monitor,path=/var/lib/libvirt/qemu/vmUranos.monitor,server,nowait 
-mon 
chardev=monitor,mode=readline -rtc base=utc -boot c -drive 
if=none,media=cdrom,id=drive-ide0-1-0,readonly=on -device 
ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 -drive 
file=/dev/capella_raptor/UranosBase,if=none,id=drive-virtio-disk0,boot=on,cache=none
 -device 
virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0 
-device 
virtio-net-pci,vlan=0,id=net0,mac=54:52:00:03:f4:ca,bus=pci.0,addr=0x5 -net 
tap,fd=17,vlan=0,name=hostnet0 -chardev pty,id=serial0 -device 
isa-serial,chardev=serial0 -usb -vnc 127.0.0.1:0 -k de -vga cirrus -device 
virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3

/usr/bin/kvm -S -M pc -enable-kvm -m 1024 -smp 
1,sockets=1,cores=1,threads=1 -name galemo -uuid 
171b4536-84ea-041d-d318-16b8fb20f855 -nodefaults -chardev 
socket,id=monitor,path=/var/lib/libvirt/qemu/galemo.monitor,server,nowait -mon 
chardev=monitor,mode=readline -rtc base=utc -boot c -drive 
if=none,media=cdrom,id=drive-ide0-1-0,readonly=on -device 
ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 -drive 
file=/dev/capella_data1/galemo,if=none,id=drive-virtio-disk0,boot=on -device 
virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0 
-device 
virtio-net-pci,vlan=0,id=net0,mac=54:52:00:45:9c:d9,bus=pci.0,addr=0x5 -net 
tap,fd=18,vlan=0,name=hostnet0 -chardev pty,id=serial0 -device 
isa-serial,chardev=serial0 -usb -vnc 127.0.0.1:1 -k de -vga cirrus -device 
virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3

Best Regards,
Hermann

-- 
herm...@qwer.tk
GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch 4/5] qemu-kvm: use upstream regs save/restore code

2010-10-23 Thread Marcelo Tosatti
Signed-off-by: Marcelo Tosatti mtosa...@redhat.com

Index: qemu-kvm/qemu-kvm-x86.c
===
--- qemu-kvm.orig/qemu-kvm-x86.c
+++ qemu-kvm/qemu-kvm-x86.c
@@ -719,35 +719,12 @@ static void kvm_reset_mpstate(CPUState *
 
 void kvm_arch_load_regs(CPUState *env, int level)
 {
-struct kvm_regs regs;
 struct kvm_msr_entry msrs[100];
 int rc, n, i;
 
 assert(kvm_cpu_is_stopped(env) || env-thread_id == kvm_get_thread_id());
 
-regs.rax = env-regs[R_EAX];
-regs.rbx = env-regs[R_EBX];
-regs.rcx = env-regs[R_ECX];
-regs.rdx = env-regs[R_EDX];
-regs.rsi = env-regs[R_ESI];
-regs.rdi = env-regs[R_EDI];
-regs.rsp = env-regs[R_ESP];
-regs.rbp = env-regs[R_EBP];
-#ifdef TARGET_X86_64
-regs.r8 = env-regs[8];
-regs.r9 = env-regs[9];
-regs.r10 = env-regs[10];
-regs.r11 = env-regs[11];
-regs.r12 = env-regs[12];
-regs.r13 = env-regs[13];
-regs.r14 = env-regs[14];
-regs.r15 = env-regs[15];
-#endif
-
-regs.rflags = env-eflags;
-regs.rip = env-eip;
-
-kvm_set_regs(env, regs);
+kvm_getput_regs(env, 1);
 
 kvm_put_xsave(env);
 kvm_put_xcrs(env);
@@ -824,35 +801,12 @@ void kvm_arch_load_regs(CPUState *env, i
 
 void kvm_arch_save_regs(CPUState *env)
 {
-struct kvm_regs regs;
 struct kvm_msr_entry msrs[100];
 uint32_t i, n, rc;
 
 assert(kvm_cpu_is_stopped(env) || env-thread_id == kvm_get_thread_id());
 
-kvm_get_regs(env, regs);
-
-env-regs[R_EAX] = regs.rax;
-env-regs[R_EBX] = regs.rbx;
-env-regs[R_ECX] = regs.rcx;
-env-regs[R_EDX] = regs.rdx;
-env-regs[R_ESI] = regs.rsi;
-env-regs[R_EDI] = regs.rdi;
-env-regs[R_ESP] = regs.rsp;
-env-regs[R_EBP] = regs.rbp;
-#ifdef TARGET_X86_64
-env-regs[8] = regs.r8;
-env-regs[9] = regs.r9;
-env-regs[10] = regs.r10;
-env-regs[11] = regs.r11;
-env-regs[12] = regs.r12;
-env-regs[13] = regs.r13;
-env-regs[14] = regs.r14;
-env-regs[15] = regs.r15;
-#endif
-
-env-eflags = regs.rflags;
-env-eip = regs.rip;
+kvm_getput_regs(env, 0);
 
 kvm_get_xsave(env);
 kvm_get_xcrs(env);
Index: qemu-kvm/target-i386/kvm.c
===
--- qemu-kvm.orig/target-i386/kvm.c
+++ qemu-kvm/target-i386/kvm.c
@@ -630,7 +630,6 @@ static void get_seg(SegmentCache *lhs, c
| (rhs-avl * DESC_AVL_MASK);
 }
 
-#ifdef OBSOLETE_KVM_IMPL
 
 static void kvm_getput_reg(__u64 *kvm_reg, target_ulong *qemu_reg, int set)
 {
@@ -679,8 +678,6 @@ static int kvm_getput_regs(CPUState *env
 return ret;
 }
 
-#endif
-
 static int kvm_put_fpu(CPUState *env)
 {
 struct kvm_fpu fpu;


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch 0/5] use upstream x86 state save/restore code

2010-10-23 Thread Marcelo Tosatti



--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch 1/5] qemu-kvm: kill xsave/xcrs helpers

2010-10-23 Thread Marcelo Tosatti
Use kvm_vcpu_ioctl directly instead.

Signed-off-by: Marcelo Tosatti mtosa...@redhat.com

Index: qemu-kvm/qemu-kvm-x86.c
===
--- qemu-kvm.orig/qemu-kvm-x86.c
+++ qemu-kvm/qemu-kvm-x86.c
@@ -825,7 +825,7 @@ void kvm_arch_load_regs(CPUState *env, i
 *(uint64_t *)xsave-region[XSAVE_XSTATE_BV] = env-xstate_bv;
 memcpy(xsave-region[XSAVE_YMMH_SPACE], env-ymmh_regs,
sizeof env-ymmh_regs);
-kvm_set_xsave(env, xsave);
+kvm_vcpu_ioctl(env, KVM_SET_XSAVE, xsave);
 if (kvm_check_extension(kvm_state, KVM_CAP_XCRS)) {
 struct kvm_xcrs xcrs;
 
@@ -833,7 +833,7 @@ void kvm_arch_load_regs(CPUState *env, i
 xcrs.flags = 0;
 xcrs.xcrs[0].xcr = 0;
 xcrs.xcrs[0].value = env-xcr0;
-kvm_set_xcrs(env, xcrs);
+kvm_vcpu_ioctl(env, KVM_SET_XCRS, xcrs);
 }
 qemu_free(xsave);
 } else {
@@ -1011,7 +1011,7 @@ void kvm_arch_save_regs(CPUState *env)
 struct kvm_xsave* xsave;
 uint16_t cwd, swd, twd, fop;
 xsave = qemu_memalign(4096, sizeof(struct kvm_xsave));
-kvm_get_xsave(env, xsave);
+kvm_vcpu_ioctl(env, KVM_GET_XSAVE, xsave);
 cwd = (uint16_t)xsave-region[0];
 swd = (uint16_t)(xsave-region[0]  16);
 twd = (uint16_t)xsave-region[1];
@@ -1033,7 +1033,7 @@ void kvm_arch_save_regs(CPUState *env)
 if (kvm_check_extension(kvm_state, KVM_CAP_XCRS)) {
 struct kvm_xcrs xcrs;
 
-kvm_get_xcrs(env, xcrs);
+kvm_vcpu_ioctl(env, KVM_GET_XCRS, xcrs);
 if (xcrs.xcrs[0].xcr == 0) {
 env-xcr0 = xcrs.xcrs[0].value;
 }
Index: qemu-kvm/qemu-kvm.c
===
--- qemu-kvm.orig/qemu-kvm.c
+++ qemu-kvm/qemu-kvm.c
@@ -516,30 +516,6 @@ int kvm_set_mpstate(CPUState *env, struc
 }
 #endif
 
-#ifdef KVM_CAP_XSAVE
-int kvm_get_xsave(CPUState *env, struct kvm_xsave *xsave)
-{
-return kvm_vcpu_ioctl(env, KVM_GET_XSAVE, xsave);
-}
-
-int kvm_set_xsave(CPUState *env, struct kvm_xsave *xsave)
-{
-return kvm_vcpu_ioctl(env, KVM_SET_XSAVE, xsave);
-}
-#endif
-
-#ifdef KVM_CAP_XCRS
-int kvm_get_xcrs(CPUState *env, struct kvm_xcrs *xcrs)
-{
-return kvm_vcpu_ioctl(env, KVM_GET_XCRS, xcrs);
-}
-
-int kvm_set_xcrs(CPUState *env, struct kvm_xcrs *xcrs)
-{
-return kvm_vcpu_ioctl(env, KVM_SET_XCRS, xcrs);
-}
-#endif
-
 static int handle_mmio(CPUState *env)
 {
 unsigned long addr = env-kvm_run-mmio.phys_addr;
Index: qemu-kvm/qemu-kvm.h
===
--- qemu-kvm.orig/qemu-kvm.h
+++ qemu-kvm/qemu-kvm.h
@@ -284,34 +284,6 @@ int kvm_get_mpstate(CPUState *env, struc
 int kvm_set_mpstate(CPUState *env, struct kvm_mp_state *mp_state);
 #endif
 
-#ifdef KVM_CAP_XSAVE
-/*!
- *  * \brief Read VCPU xsave state
- *
- */
-int kvm_get_xsave(CPUState *env, struct kvm_xsave *xsave);
-
-/*!
- *  * \brief Write VCPU xsave state
- *
- */
-int kvm_set_xsave(CPUState *env, struct kvm_xsave *xsave);
-#endif
-
-#ifdef KVM_CAP_XCRS
-/*!
- *  * \brief Read VCPU XCRs
- *
- */
-int kvm_get_xcrs(CPUState *env, struct kvm_xcrs *xcrs);
-
-/*!
- *  * \brief Write VCPU XCRs
- *
- */
-int kvm_set_xcrs(CPUState *env, struct kvm_xcrs *xcrs);
-#endif
-
 /*!
  * \brief Simulate an external vectored interrupt
  *


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[patch 3/5] qemu-kvm: use upstream sregs save/restore code

2010-10-23 Thread Marcelo Tosatti
Signed-off-by: Marcelo Tosatti mtosa...@redhat.com

Index: qemu-kvm/qemu-kvm-x86.c
===
--- qemu-kvm.orig/qemu-kvm-x86.c
+++ qemu-kvm/qemu-kvm-x86.c
@@ -709,55 +709,6 @@ static void kvm_reset_mpstate(CPUState *
 #endif
 }
 
-static void set_v8086_seg(struct kvm_segment *lhs, const SegmentCache *rhs)
-{
-lhs-selector = rhs-selector;
-lhs-base = rhs-base;
-lhs-limit = rhs-limit;
-lhs-type = 3;
-lhs-present = 1;
-lhs-dpl = 3;
-lhs-db = 0;
-lhs-s = 1;
-lhs-l = 0;
-lhs-g = 0;
-lhs-avl = 0;
-lhs-unusable = 0;
-}
-
-static void set_seg(struct kvm_segment *lhs, const SegmentCache *rhs)
-{
-unsigned flags = rhs-flags;
-lhs-selector = rhs-selector;
-lhs-base = rhs-base;
-lhs-limit = rhs-limit;
-lhs-type = (flags  DESC_TYPE_SHIFT)  15;
-lhs-present = (flags  DESC_P_MASK) != 0;
-lhs-dpl = rhs-selector  3;
-lhs-db = (flags  DESC_B_SHIFT)  1;
-lhs-s = (flags  DESC_S_MASK) != 0;
-lhs-l = (flags  DESC_L_SHIFT)  1;
-lhs-g = (flags  DESC_G_MASK) != 0;
-lhs-avl = (flags  DESC_AVL_MASK) != 0;
-lhs-unusable = 0;
-}
-
-static void get_seg(SegmentCache *lhs, const struct kvm_segment *rhs)
-{
-lhs-selector = rhs-selector;
-lhs-base = rhs-base;
-lhs-limit = rhs-limit;
-lhs-flags =
-(rhs-type  DESC_TYPE_SHIFT)
-| (rhs-present * DESC_P_MASK)
-| (rhs-dpl  DESC_DPL_SHIFT)
-| (rhs-db  DESC_B_SHIFT)
-| (rhs-s * DESC_S_MASK)
-| (rhs-l  DESC_L_SHIFT)
-| (rhs-g * DESC_G_MASK)
-| (rhs-avl * DESC_AVL_MASK);
-}
-
 #define XSAVE_CWD_RIP 2
 #define XSAVE_CWD_RDP 4
 #define XSAVE_MXCSR   6
@@ -769,7 +720,6 @@ static void get_seg(SegmentCache *lhs, c
 void kvm_arch_load_regs(CPUState *env, int level)
 {
 struct kvm_regs regs;
-struct kvm_sregs sregs;
 struct kvm_msr_entry msrs[100];
 int rc, n, i;
 
@@ -802,55 +752,7 @@ void kvm_arch_load_regs(CPUState *env, i
 kvm_put_xsave(env);
 kvm_put_xcrs(env);
 
-memset(sregs.interrupt_bitmap, 0, sizeof(sregs.interrupt_bitmap));
-if (env-interrupt_injected = 0) {
-sregs.interrupt_bitmap[env-interrupt_injected / 64] |=
-(uint64_t)1  (env-interrupt_injected % 64);
-}
-
-if ((env-eflags  VM_MASK)) {
-set_v8086_seg(sregs.cs, env-segs[R_CS]);
-set_v8086_seg(sregs.ds, env-segs[R_DS]);
-set_v8086_seg(sregs.es, env-segs[R_ES]);
-set_v8086_seg(sregs.fs, env-segs[R_FS]);
-set_v8086_seg(sregs.gs, env-segs[R_GS]);
-set_v8086_seg(sregs.ss, env-segs[R_SS]);
-} else {
-set_seg(sregs.cs, env-segs[R_CS]);
-set_seg(sregs.ds, env-segs[R_DS]);
-set_seg(sregs.es, env-segs[R_ES]);
-set_seg(sregs.fs, env-segs[R_FS]);
-set_seg(sregs.gs, env-segs[R_GS]);
-set_seg(sregs.ss, env-segs[R_SS]);
-
-if (env-cr[0]  CR0_PE_MASK) {
-/* force ss cpl to cs cpl */
-sregs.ss.selector = (sregs.ss.selector  ~3) |
-(sregs.cs.selector  3);
-sregs.ss.dpl = sregs.ss.selector  3;
-}
-}
-
-set_seg(sregs.tr, env-tr);
-set_seg(sregs.ldt, env-ldt);
-
-sregs.idt.limit = env-idt.limit;
-sregs.idt.base = env-idt.base;
-sregs.gdt.limit = env-gdt.limit;
-sregs.gdt.base = env-gdt.base;
-
-sregs.cr0 = env-cr[0];
-sregs.cr2 = env-cr[2];
-sregs.cr3 = env-cr[3];
-sregs.cr4 = env-cr[4];
-
-sregs.cr8 = cpu_get_apic_tpr(env-apic_state);
-sregs.apic_base = cpu_get_apic_base(env-apic_state);
-
-sregs.efer = env-efer;
-
-kvm_set_sregs(env, sregs);
-
+kvm_put_sregs(env);
 /* msrs */
 n = 0;
 /* Remember to increase msrs size if you add new registers below */
@@ -923,10 +825,8 @@ void kvm_arch_load_regs(CPUState *env, i
 void kvm_arch_save_regs(CPUState *env)
 {
 struct kvm_regs regs;
-struct kvm_sregs sregs;
 struct kvm_msr_entry msrs[100];
-uint32_t hflags;
-uint32_t i, n, rc, bit;
+uint32_t i, n, rc;
 
 assert(kvm_cpu_is_stopped(env) || env-thread_id == kvm_get_thread_id());
 
@@ -957,81 +857,7 @@ void kvm_arch_save_regs(CPUState *env)
 kvm_get_xsave(env);
 kvm_get_xcrs(env);
 
-kvm_get_sregs(env, sregs);
-
-/* There can only be one pending IRQ set in the bitmap at a time, so try
-   to find it and save its number instead (-1 for none). */
-env-interrupt_injected = -1;
-for (i = 0; i  ARRAY_SIZE(sregs.interrupt_bitmap); i++) {
-if (sregs.interrupt_bitmap[i]) {
-bit = ctz64(sregs.interrupt_bitmap[i]);
-env-interrupt_injected = i * 64 + bit;
-break;
-}
-}
-
-get_seg(env-segs[R_CS], sregs.cs);
-get_seg(env-segs[R_DS], sregs.ds);
-get_seg(env-segs[R_ES], sregs.es);
-get_seg(env-segs[R_FS], sregs.fs);
-get_seg(env-segs[R_GS], sregs.gs);
-get_seg(env-segs[R_SS], sregs.ss);
-
-

[patch 2/5] qemu-kvm: use upstream fpu/xsave/xcrs save/restore code

2010-10-23 Thread Marcelo Tosatti
Signed-off-by: Marcelo Tosatti mtosa...@redhat.com

Index: qemu-kvm/qemu-kvm.c
===
--- qemu-kvm.orig/qemu-kvm.c
+++ qemu-kvm/qemu-kvm.c
@@ -472,16 +472,6 @@ int kvm_set_regs(CPUState *env, struct k
 return kvm_vcpu_ioctl(env, KVM_SET_REGS, regs);
 }
 
-int kvm_get_fpu(CPUState *env, struct kvm_fpu *fpu)
-{
-return kvm_vcpu_ioctl(env, KVM_GET_FPU, fpu);
-}
-
-int kvm_set_fpu(CPUState *env, struct kvm_fpu *fpu)
-{
-return kvm_vcpu_ioctl(env, KVM_SET_FPU, fpu);
-}
-
 int kvm_get_sregs(CPUState *env, struct kvm_sregs *sregs)
 {
 return kvm_vcpu_ioctl(env, KVM_GET_SREGS, sregs);
@@ -1696,6 +1686,16 @@ static int kvm_create_context(void)
 kvm_state-debugregs = kvm_check_extension(kvm_state, KVM_CAP_DEBUGREGS);
 #endif
 
+kvm_state-xsave = 0;
+#ifdef KVM_CAP_XSAVE
+kvm_state-xsave = kvm_check_extension(kvm_state, KVM_CAP_XSAVE);
+#endif
+
+kvm_state-xcrs = 0;
+#ifdef KVM_CAP_XCRS
+kvm_state-xcrs = kvm_check_extension(kvm_state, KVM_CAP_XCRS);
+#endif
+
 kvm_init_ap();
 if (kvm_irqchip) {
 if (!qemu_kvm_has_gsi_routing()) {
Index: qemu-kvm/qemu-kvm-x86.c
===
--- qemu-kvm.orig/qemu-kvm-x86.c
+++ qemu-kvm/qemu-kvm-x86.c
@@ -769,7 +769,6 @@ static void get_seg(SegmentCache *lhs, c
 void kvm_arch_load_regs(CPUState *env, int level)
 {
 struct kvm_regs regs;
-struct kvm_fpu fpu;
 struct kvm_sregs sregs;
 struct kvm_msr_entry msrs[100];
 int rc, n, i;
@@ -800,58 +799,8 @@ void kvm_arch_load_regs(CPUState *env, i
 
 kvm_set_regs(env, regs);
 
-#ifdef KVM_CAP_XSAVE
-if (kvm_check_extension(kvm_state, KVM_CAP_XSAVE)) {
-struct kvm_xsave* xsave;
-
-uint16_t cwd, swd, twd, fop;
-
-xsave = qemu_memalign(4096, sizeof(struct kvm_xsave));
-memset(xsave, 0, sizeof(struct kvm_xsave));
-cwd = swd = twd = fop = 0;
-swd = env-fpus  ~(7  11);
-swd |= (env-fpstt  7)  11;
-cwd = env-fpuc;
-for (i = 0; i  8; ++i) {
-twd |= (!env-fptags[i])  i;
-}
-xsave-region[0] = (uint32_t)(swd  16) + cwd;
-xsave-region[1] = (uint32_t)(fop  16) + twd;
-memcpy(xsave-region[XSAVE_ST_SPACE], env-fpregs,
-   sizeof env-fpregs);
-memcpy(xsave-region[XSAVE_XMM_SPACE], env-xmm_regs,
-   sizeof env-xmm_regs);
-xsave-region[XSAVE_MXCSR] = env-mxcsr;
-*(uint64_t *)xsave-region[XSAVE_XSTATE_BV] = env-xstate_bv;
-memcpy(xsave-region[XSAVE_YMMH_SPACE], env-ymmh_regs,
-   sizeof env-ymmh_regs);
-kvm_vcpu_ioctl(env, KVM_SET_XSAVE, xsave);
-if (kvm_check_extension(kvm_state, KVM_CAP_XCRS)) {
-struct kvm_xcrs xcrs;
-
-xcrs.nr_xcrs = 1;
-xcrs.flags = 0;
-xcrs.xcrs[0].xcr = 0;
-xcrs.xcrs[0].value = env-xcr0;
-kvm_vcpu_ioctl(env, KVM_SET_XCRS, xcrs);
-}
-qemu_free(xsave);
-} else {
-#endif
-memset(fpu, 0, sizeof fpu);
-fpu.fsw = env-fpus  ~(7  11);
-fpu.fsw |= (env-fpstt  7)  11;
-fpu.fcw = env-fpuc;
-for (i = 0; i  8; ++i) {
-fpu.ftwx |= (!env-fptags[i])  i;
-}
-memcpy(fpu.fpr, env-fpregs, sizeof env-fpregs);
-memcpy(fpu.xmm, env-xmm_regs, sizeof env-xmm_regs);
-fpu.mxcsr = env-mxcsr;
-kvm_set_fpu(env, fpu);
-#ifdef KVM_CAP_XSAVE
-}
-#endif
+kvm_put_xsave(env);
+kvm_put_xcrs(env);
 
 memset(sregs.interrupt_bitmap, 0, sizeof(sregs.interrupt_bitmap));
 if (env-interrupt_injected = 0) {
@@ -974,7 +923,6 @@ void kvm_arch_load_regs(CPUState *env, i
 void kvm_arch_save_regs(CPUState *env)
 {
 struct kvm_regs regs;
-struct kvm_fpu fpu;
 struct kvm_sregs sregs;
 struct kvm_msr_entry msrs[100];
 uint32_t hflags;
@@ -1006,54 +954,8 @@ void kvm_arch_save_regs(CPUState *env)
 env-eflags = regs.rflags;
 env-eip = regs.rip;
 
-#ifdef KVM_CAP_XSAVE
-if (kvm_check_extension(kvm_state, KVM_CAP_XSAVE)) {
-struct kvm_xsave* xsave;
-uint16_t cwd, swd, twd, fop;
-xsave = qemu_memalign(4096, sizeof(struct kvm_xsave));
-kvm_vcpu_ioctl(env, KVM_GET_XSAVE, xsave);
-cwd = (uint16_t)xsave-region[0];
-swd = (uint16_t)(xsave-region[0]  16);
-twd = (uint16_t)xsave-region[1];
-fop = (uint16_t)(xsave-region[1]  16);
-env-fpstt = (swd  11)  7;
-env-fpus = swd;
-env-fpuc = cwd;
-for (i = 0; i  8; ++i) {
-env-fptags[i] = !((twd  i)  1);
-}
-env-mxcsr = xsave-region[XSAVE_MXCSR];
-memcpy(env-fpregs, xsave-region[XSAVE_ST_SPACE],
-sizeof env-fpregs);
-memcpy(env-xmm_regs, xsave-region[XSAVE_XMM_SPACE],
-sizeof env-xmm_regs);
-env-xstate_bv = *(uint64_t *)xsave-region[XSAVE_XSTATE_BV];
-

[patch 5/5] qemu-kvm: use upstream msr save/restore code

2010-10-23 Thread Marcelo Tosatti
Signed-off-by: Marcelo Tosatti mtosa...@redhat.com

Index: qemu-kvm/qemu-kvm-x86.c
===
--- qemu-kvm.orig/qemu-kvm-x86.c
+++ qemu-kvm/qemu-kvm-x86.c
@@ -28,10 +28,6 @@
 
 static struct kvm_msr_list *kvm_msr_list;
 extern unsigned int kvm_shadow_memory;
-static int kvm_has_msr_star;
-static int kvm_has_vm_hsave_pa;
-
-static int _lm_capable_kernel;
 
 int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr)
 {
@@ -358,31 +354,6 @@ static struct kvm_msr_list *kvm_get_msr_
 return msrs;
 }
 
-int kvm_get_msrs(CPUState *env, struct kvm_msr_entry *msrs, int n)
-{
-struct kvm_msrs *kmsrs = qemu_malloc(sizeof *kmsrs + n * sizeof *msrs);
-int r;
-
-kmsrs-nmsrs = n;
-memcpy(kmsrs-entries, msrs, n * sizeof *msrs);
-r = kvm_vcpu_ioctl(env, KVM_GET_MSRS, kmsrs);
-memcpy(msrs, kmsrs-entries, n * sizeof *msrs);
-free(kmsrs);
-return r;
-}
-
-int kvm_set_msrs(CPUState *env, struct kvm_msr_entry *msrs, int n)
-{
-struct kvm_msrs *kmsrs = qemu_malloc(sizeof *kmsrs + n * sizeof *msrs);
-int r;
-
-kmsrs-nmsrs = n;
-memcpy(kmsrs-entries, msrs, n * sizeof *msrs);
-r = kvm_vcpu_ioctl(env, KVM_SET_MSRS, kmsrs);
-free(kmsrs);
-return r;
-}
-
 static void print_seg(FILE *file, const char *name, struct kvm_segment *seg)
 {
 fprintf(stderr,
@@ -558,11 +529,11 @@ static const VMStateDescription vmstate_
 
 int kvm_arch_qemu_create_context(void)
 {
-int i, r;
+int r;
 struct utsname utsname;
 
 uname(utsname);
-_lm_capable_kernel = strcmp(utsname.machine, x86_64) == 0;
+lm_capable_kernel = strcmp(utsname.machine, x86_64) == 0;
 
 if (kvm_shadow_memory) {
 kvm_set_shadow_pages(kvm_context, kvm_shadow_memory);
@@ -572,14 +543,6 @@ int kvm_arch_qemu_create_context(void)
 if (!kvm_msr_list) {
 return -1;
 }
-for (i = 0; i  kvm_msr_list-nmsrs; ++i) {
-if (kvm_msr_list-indices[i] == MSR_STAR) {
-kvm_has_msr_star = 1;
-}
-if (kvm_msr_list-indices[i] == MSR_VM_HSAVE_PA) {
-kvm_has_vm_hsave_pa = 1;
-}
-}
 
 #ifdef KVM_CAP_ADJUST_CLOCK
 if (kvm_check_extension(kvm_state, KVM_CAP_ADJUST_CLOCK)) {
@@ -595,70 +558,6 @@ int kvm_arch_qemu_create_context(void)
 return 0;
 }
 
-/* returns 0 on success, non-0 on failure */
-static int get_msr_entry(struct kvm_msr_entry *entry, CPUState *env)
-{
-switch (entry-index) {
-case MSR_IA32_SYSENTER_CS:
-env-sysenter_cs  = entry-data;
-break;
-case MSR_IA32_SYSENTER_ESP:
-env-sysenter_esp = entry-data;
-break;
-case MSR_IA32_SYSENTER_EIP:
-env-sysenter_eip = entry-data;
-break;
-case MSR_STAR:
-env-star = entry-data;
-break;
-#ifdef TARGET_X86_64
-case MSR_CSTAR:
-env-cstar= entry-data;
-break;
-case MSR_KERNELGSBASE:
-env-kernelgsbase = entry-data;
-break;
-case MSR_FMASK:
-env-fmask= entry-data;
-break;
-case MSR_LSTAR:
-env-lstar= entry-data;
-break;
-#endif
-case MSR_IA32_TSC:
-env-tsc  = entry-data;
-break;
-case MSR_VM_HSAVE_PA:
-env-vm_hsave = entry-data;
-break;
-case MSR_KVM_SYSTEM_TIME:
-env-system_time_msr = entry-data;
-break;
-case MSR_KVM_WALL_CLOCK:
-env-wall_clock_msr = entry-data;
-break;
-#ifdef KVM_CAP_MCE
-case MSR_MCG_STATUS:
-env-mcg_status = entry-data;
-break;
-case MSR_MCG_CTL:
-env-mcg_ctl = entry-data;
-break;
-#endif
-default:
-#ifdef KVM_CAP_MCE
-if (entry-index = MSR_MC0_CTL 
-entry-index  MSR_MC0_CTL + (env-mcg_cap  0xff) * 4) {
-env-mce_banks[entry-index - MSR_MC0_CTL] = entry-data;
-break;
-}
-#endif
-printf(Warning unknown msr index 0x%x\n, entry-index);
-return 1;
-}
-return 0;
-}
-
 static void kvm_arch_save_mpstate(CPUState *env)
 {
 #ifdef KVM_CAP_MP_STATE
@@ -719,8 +618,7 @@ static void kvm_reset_mpstate(CPUState *
 
 void kvm_arch_load_regs(CPUState *env, int level)
 {
-struct kvm_msr_entry msrs[100];
-int rc, n, i;
+int rc;
 
 assert(kvm_cpu_is_stopped(env) || env-thread_id == kvm_get_thread_id());
 
@@ -730,56 +628,10 @@ void kvm_arch_load_regs(CPUState *env, i
 kvm_put_xcrs(env);
 
 kvm_put_sregs(env);
-/* msrs */
-n = 0;
-/* Remember to increase msrs size if you add new registers below */
-kvm_msr_entry_set(msrs[n++], MSR_IA32_SYSENTER_CS,  env-sysenter_cs);
-kvm_msr_entry_set(msrs[n++], MSR_IA32_SYSENTER_ESP, env-sysenter_esp);
-kvm_msr_entry_set(msrs[n++], MSR_IA32_SYSENTER_EIP, env-sysenter_eip);
-if (kvm_has_msr_star) {
-kvm_msr_entry_set(msrs[n++], MSR_STAR,  env-star);
-}
-if (kvm_has_vm_hsave_pa) {
-