Re: [PATCH 1/2] kvm tools: Export DISPLAY ENV as our default host ip address

2012-09-05 Thread Asias He
On Tue, Sep 4, 2012 at 9:07 PM, Avi Kivity a...@redhat.com wrote:
 On 08/24/2012 02:29 PM, Asias He wrote:
 It is useful to run a X program in guest and display it on host.

 1) Make host's x server listen to localhost:6000
host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
UNIX-CONNECT:/tmp/.X11-unix/X0

 2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
   guest_shell$ xlogo


 Note, this is insecure, don't do this with untrusted guests.

In this use case, the user on the host side should trust the guest.

Btw, any attack the untrusted guests can do with the X port which host listens?

-- 
Asias He
--
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 5/5] virtio-scsi: introduce multiqueue support

2012-09-05 Thread Paolo Bonzini
Il 04/09/2012 22:11, Nicholas A. Bellinger ha scritto:
 As tgt-tgt_lock is taken in virtscsi_queuecommand_multi() before the
 atomic_inc_return(tgt-reqs) check, it seems like using atomic_dec() w/o
 smp_mb__after_atomic_dec or tgt_lock access here is not using atomic.h
 accessors properly, no..?

 No, only a single thing is being accessed, and there is no need to
 order the decrement with respect to preceding or subsequent accesses to
 other locations.

 In other words, tgt-reqs is already synchronized with itself, and that
 is enough.

 
 However, it's still my understanding that the use of atomic_dec() in the
 completion path mean that smp_mb__after_atomic_dec() is a requirement to
 be proper portable atomic.hcode, no..?  Otherwise tgt-regs should be
 using something other than an atomic_t, right..?

Memory barriers aren't _always_ requested, only when you need to order
accesses to multiple locations.

In this case, there is no other location that the
queuecommand/completion handlers needs to synchronize against, so no
barrier is required.  You can see plenty of atomic_inc/atomic_dec in the
code without a barrier afterwards (the typical case is the opposite as
in this patch: a refcount increment needs no barrier, a refcount
decrement uses atomic_dec_return).

 virtio-scsi multiqueue has a performance benefit up to 20% (for a single
 LUN) or 40% (on overall bandwidth across multiple LUNs).  I doubt that a
 single memory barrier can have that much impact. :)

 
 I've no doubt that this series increases the large block high bandwidth
 for virtio-scsi, but historically that has always been the easier
 workload to scale.  ;)

This is with a mixed workload (random 4k-64k) and tmpfs backend on the host.

 Yes, I think Jen's new approach is providing some pretty significant
 gains for raw block drivers with extremly high packet (small block
 random I/O) workloads, esp with hw block drivers that support genuine mq
 with hw num_queues  1.

I need to look into it, to understand how the queue steering here can be
adapted to his code.

 Have you measured the host_lock to be a bottleneck in high-iops
 benchmarks, even for a modern driver that does not hold it in
 queuecommand?  (Certainly it will become more important as the
 virtio-scsi queuecommand becomes thinner and thinner).
 
 This is exactly why it would make such a good vehicle to re-architect
 SCSI core.  I'm thinking it can be the first sw LLD we attempt to get
 running on an (currently) future scsi-mq prototype.

Agreed.

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


Re: [PATCH v2 2/7] s390/kvm: Add support for machine checks.

2012-09-05 Thread Heiko Carstens
On Tue, Sep 04, 2012 at 05:13:25PM +0200, Cornelia Huck wrote:

Just some quick comments:

[...]

  int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code)
  {
   struct kvm_s390_local_interrupt *li = vcpu-arch.local_int;
 @@ -648,6 +747,12 @@ int kvm_s390_inject_vm(struct kvm *kvm,
   case KVM_S390_INT_EMERGENCY:
   kfree(inti);
   return -EINVAL;
 + case KVM_S390_MCHK:
 + VM_EVENT(kvm, 5, inject: machine check parm64:%llx,
 +  s390int-parm64);
 + inti-type = s390int-type;
 + inti-mchk.mcic = s390int-parm64;
 + break;

The kvm_s390_interrupt struct seems to be inappropriate to pass machine check
data around.
E.g. if you want to inject an uncorrectable storage error, because the host
failed to swap in a page, you must also pass a failing storage address which
doesn't fit into this structure.
Just something you should consider. ;)

 +static int handle_lpswe(struct kvm_vcpu *vcpu)
 +{
 + int base2 = vcpu-arch.sie_block-ipb  28;
 + int disp2 = ((vcpu-arch.sie_block-ipb  0x0fff)  16);

Sooner or later we need helper functions which extract the significant parts
of an instruction.
Maybay something like insn_[type]_get_base2(...) or simply structures like
struct insn_[type], which allow to easily access parts of an instruction.

 + u64 addr;
 + u64 new_psw[2];

psw_t?

 +
 + addr = disp2;
 + if (base2)
 + addr += vcpu-run-s.regs.gprs[base2];
 + 
 + if (addr  7) {
 + kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
 + goto out;
 + }
 +
 + if (copy_from_guest(vcpu, new_psw, addr, sizeof(*new_psw))) {

I assume that should be sizeof(new_psw). Did that ever work?!

 + if ((vcpu-arch.sie_block-gpsw.mask  0xb80800fe7fff) ||
 + (((vcpu-arch.sie_block-gpsw.mask  0x00011000) ==
 +   0x1000) 
 +  (vcpu-arch.sie_block-gpsw.addr  0x8000)) ||
 + (!(vcpu-arch.sie_block-gpsw.mask  0x00018000) 
 +  (vcpu-arch.sie_block-gpsw.addr  0xfff0)) ||
 + ((vcpu-arch.sie_block-gpsw.mask  0x00011000) ==
 +  0x0001)) {

This is not very readable...

Please make use of the PSW defines in ptrace.h and add new ones if needed.
Also please make use of (move) the PSW32 defines in compat.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: expanding virtual disk based on lvm

2012-09-05 Thread Avi Kivity
On 09/04/2012 09:58 PM, Ross Boylan wrote:
 On Tue, 2012-09-04 at 15:53 +0300, Avi Kivity wrote:
 On 08/28/2012 11:26 PM, Ross Boylan wrote:
  My vm launches with -hda /dev/turtle/VD0 -hdb /dev/turtle/VD1, where VD0
  and VD1 are lvm logical volumes.  I used lvextend to expand them, but
  the VM, started after the expansion, does not seem to see the extra
  space.
  
  What do I need to so that the space will be recognized?
 
 IDE (-hda) does not support rechecking the size.  Try booting with
 virtio-blk.  Additionally, you may need to request the guest to rescan
 the drive (no idea how to do that).  Nor am I sure whether qemu will
 emulate the request correctly.
 
 Thank you for the suggestion.
 
 I think the physical recognition of the new virtual disk size was
 accomplished when I restarted the VM, without any other steps.  I've had
 plenty of other problems, but I think at the VM level things are good.

Certainly restart (shutting down qemu and restarting it, not a reset)
works, I thought you wanted online resize.



-- 
error compiling committee.c: too many arguments to function
--
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 v2 1/7] s390/kvm: Support for I/O interrupts.

2012-09-05 Thread Avi Kivity
On 09/04/2012 06:13 PM, Cornelia Huck wrote:
 Add support for handling I/O interrupts (standard, subchannel-related
 ones and rudimentary adapter interrupts).
 
 The subchannel-identifying parameters are encoded into the interrupt
 type.
 
 I/O interrupts are floating, so they can't be injected on a specific
 vcpu.
 
 diff --git a/include/linux/kvm.h b/include/linux/kvm.h
 index d808694..5a36e65 100644
 --- a/include/linux/kvm.h
 +++ b/include/linux/kvm.h
 @@ -396,6 +396,12 @@ struct kvm_s390_psw {
  #define KVM_S390_INT_SERVICE 0x2401u
  #define KVM_S390_INT_EMERGENCY   0x1201u
  #define KVM_S390_INT_EXTERNAL_CALL   0x1202u
 +#define KVM_S390_INT_IO(ai,cssid,ssid,schid)   \
 + (((schid)) |   \
 +  ((ssid)  16) |  \
 +  ((cssid)  18) | \
 +  ((ai)  26))
 +
  

Documentation?


-- 
error compiling committee.c: too many arguments to function
--
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: [RFC PATCH v2 0/7] s390: virtual css host support.

2012-09-05 Thread Avi Kivity
On 09/04/2012 06:13 PM, Cornelia Huck wrote:
 Hi,
 
 here's the second revision of the virtual channel subsystem support for
 s390.
 
 I changed the representation of the channel subsystem, introducing channel
 subsystem images, which brings it closer to the actual implementation. A
 new ioctl for adding a new channel subsystem image has also been introduced.

Looks good to me, though of course I could only do a shallow review.

I'd like to see acks from an s390 maintainer on the non-kvm patches, and
will apply after the other comments are addressed.


-- 
error compiling committee.c: too many arguments to function
--
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] kvm tools: Export DISPLAY ENV as our default host ip address

2012-09-05 Thread Avi Kivity
On 09/05/2012 09:03 AM, Asias He wrote:
 On Tue, Sep 4, 2012 at 9:07 PM, Avi Kivity a...@redhat.com wrote:
 On 08/24/2012 02:29 PM, Asias He wrote:
 It is useful to run a X program in guest and display it on host.

 1) Make host's x server listen to localhost:6000
host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
UNIX-CONNECT:/tmp/.X11-unix/X0

 2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
   guest_shell$ xlogo


 Note, this is insecure, don't do this with untrusted guests.
 
 In this use case, the user on the host side should trust the guest.
 
 Btw, any attack the untrusted guests can do with the X port which host 
 listens?

Steal the entire display, record user keystrokes, present false information.

btw, how did it work?  The you need the xauth cookie for this to work,
or disable authentication.


-- 
error compiling committee.c: too many arguments to function
--
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] kvm tools: Export DISPLAY ENV as our default host ip address

2012-09-05 Thread Pekka Enberg
On 08/24/2012 02:29 PM, Asias He wrote:
 It is useful to run a X program in guest and display it on host.

 1) Make host's x server listen to localhost:6000
host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
UNIX-CONNECT:/tmp/.X11-unix/X0

 2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
   guest_shell$ xlogo

On Tue, Sep 4, 2012 at 4:07 PM, Avi Kivity a...@redhat.com wrote:
 Note, this is insecure, don't do this with untrusted guests.

Asias, can we add a command line argument that enables this? It'd be
safer to keep it disabled by default.
--
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] kvm tools: Export DISPLAY ENV as our default host ip address

2012-09-05 Thread Ingo Molnar

* Pekka Enberg penb...@kernel.org wrote:

 On 08/24/2012 02:29 PM, Asias He wrote:
  It is useful to run a X program in guest and display it on host.
 
  1) Make host's x server listen to localhost:6000
 host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
 UNIX-CONNECT:/tmp/.X11-unix/X0
 
  2) Start the guest and run X program
 host_shell$ lkvm run -k /boot/bzImage
guest_shell$ xlogo
 
 On Tue, Sep 4, 2012 at 4:07 PM, Avi Kivity a...@redhat.com wrote:
  Note, this is insecure, don't do this with untrusted guests.
 
 Asias, can we add a command line argument that enables this? 
 It'd be safer to keep it disabled by default.

It might also be prudent to name the option in a way that 
signals that the user of it understands the security 
implications:

--X11-trusted-guest 1

or so.

Thanks,

Ingo
--
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/3] KVM: Add KVM_VCPU_GET_REG_LIST/KVM_CAP_REG_LIST.

2012-09-05 Thread Rusty Russell
This is a generic interface to find out what you can use
KVM_GET_ONE_REG/KVM_SET_ONE_REG on.  Archs need to define
KVM_HAVE_REG_LIST and then kvm_arch_num_regs() and
kvm_arch_copy_reg_indices() functions.

It's inspired by KVM_GET_MSR_INDEX_LIST, except it's a per-vcpu ioctl,
and uses 64-bit indices.

Signed-off-by: Rusty Russell rusty.russ...@linaro.org
---
 Documentation/virtual/kvm/api.txt |   20 
 include/linux/kvm.h   |   12 
 include/linux/kvm_host.h  |5 -
 virt/kvm/kvm_main.c   |   20 
 4 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/Documentation/virtual/kvm/api.txt 
b/Documentation/virtual/kvm/api.txt
index b91bfd4..f30c3d0 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1985,6 +1985,26 @@ the virtualized real-mode area (VRMA) facility, the 
kernel will
 re-create the VMRA HPTEs on the next KVM_RUN of any vcpu.)
 
 
+4.76 KVM_VCPU_GET_REG_LIST
+
+Capability: KVM_CAP_REG_LIST
+Architectures: all
+Type: vcpu ioctl
+Parameters: struct kvm_reg_list (in/out)
+Returns: 0 on success; -1 on error
+Errors:
+  E2BIG: the reg index list is too big to fit in the array specified by
+ the user (the number required will be written into n).
+
+struct kvm_reg_list {
+   __u64 n; /* number of registers in reg[] */
+   __u64 reg[0];
+};
+
+This ioctl returns the guest registers that are supported for the
+KVM_GET_ONE_REG/KVM_SET_ONE_REG calls.
+
+
 5. The kvm_run structure
 
 
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 8c3760e..e839889 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -625,6 +625,7 @@ struct kvm_ppc_smmu_info {
 #ifdef __KVM_HAVE_READONLY_MEM
 #define KVM_CAP_READONLY_MEM 81
 #endif
+#define KVM_CAP_REG_LIST 82
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -913,6 +914,7 @@ struct kvm_s390_ucas_mapping {
 #define KVM_SET_ONE_REG  _IOW(KVMIO,  0xac, struct kvm_one_reg)
 /* VM is being stopped by host */
 #define KVM_KVMCLOCK_CTRL_IO(KVMIO,   0xad)
+#define KVM_VCPU_GET_REG_LIST_IOWR(KVMIO, 0xb0, struct kvm_reg_list)
 
 #define KVM_DEV_ASSIGN_ENABLE_IOMMU(1  0)
 #define KVM_DEV_ASSIGN_PCI_2_3 (1  1)
@@ -964,4 +971,9 @@ struct kvm_assigned_msix_entry {
__u16 padding[3];
 };
 
+/* For KVM_VCPU_GET_REG_LIST. */
+struct kvm_reg_list {
+   __u64 n; /* number of regs */
+   __u64 reg[0];
+};
 #endif /* __LINUX_KVM_H */
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 2277ff8..d9ee33f 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -587,7 +587,10 @@ int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu);
 int kvm_arch_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
 int kvm_arch_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg);
 #endif
-
+#ifdef KVM_HAVE_REG_LIST
+unsigned long kvm_arch_num_regs(struct kvm_vcpu *vcpu);
+int kvm_arch_copy_reg_indices(struct kvm_vcpu *vcpu, u64 __user *indices);
+#endif
 void kvm_free_physmem(struct kvm *kvm);
 
 void *kvm_kvzalloc(unsigned long size);
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 169a001..453fe93 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2082,6 +2082,23 @@ out_free2:
break;
}
 #endif
+#ifdef KVM_HAVE_REG_LIST
+   case KVM_VCPU_GET_REG_LIST: {
+   struct kvm_reg_list __user *user_list = argp;
+   struct kvm_reg_list reg_list;
+   unsigned n;
+
+   if (copy_from_user(reg_list, user_list, sizeof reg_list))
+   return -EFAULT;
+   n = reg_list.n;
+   reg_list.n = kvm_arch_num_regs(vcpu);
+   if (copy_to_user(user_list, reg_list, sizeof reg_list))
+   return -EFAULT;
+   if (n  reg_list.n)
+   return -E2BIG;
+   return kvm_arch_copy_reg_indices(vcpu, user_list-reg);
+   }
+#endif
 
default:
r = kvm_arch_vcpu_ioctl(filp, ioctl, arg);
@@ -2397,6 +2414,9 @@ static long kvm_dev_ioctl_check_extension_generic(long 
arg)
 #ifdef KVM_HAVE_ONE_REG
case KVM_CAP_ONE_REG:
 #endif
+#ifdef KVM_HAVE_REG_LIST
+   case KVM_CAP_REG_LIST:
+#endif
return 1;
 #ifdef KVM_CAP_IRQ_ROUTING
case KVM_CAP_IRQ_ROUTING:
-- 
1.7.9.5

--
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 2/3] KVM: Add KVM_REG_SIZE() helper.

2012-09-05 Thread Rusty Russell
Useful helper for getting length of register given id.

Signed-off-by: Rusty Russell rusty.russ...@linaro.org
---
 include/linux/kvm.h |2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index d808694..8c3760e 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -744,6 +744,8 @@ struct kvm_dirty_tlb {
 #define KVM_REG_SIZE_U256  0x0050ULL
 #define KVM_REG_SIZE_U512  0x0060ULL
 #define KVM_REG_SIZE_U1024 0x0070ULL
+#define KVM_REG_SIZE(id)   \
+   (1U  (((id)  KVM_REG_SIZE_MASK)  KVM_REG_SIZE_SHIFT))
 
 struct kvm_one_reg {
__u64 id;
-- 
1.7.9.5

--
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/3] KVM_VCPU_GET_REG_LIST API

2012-09-05 Thread Rusty Russell
This is the generic part of the KVM_SET_ONE_REG/KVM_GET_ONE_REG
enhancements which ARM wants, rebased onto kvm/next.

Rusty Russell (3):
  KVM: Move KVM_SET_ONE_REG/KVM_GET_ONE_REG to generic code.
  KVM: Add KVM_REG_SIZE() helper.
  KVM: Add KVM_VCPU_GET_REG_LIST/KVM_CAP_REG_LIST.

 Documentation/virtual/kvm/api.txt   |   20 ++
 arch/powerpc/include/asm/kvm_host.h |1 +
 arch/powerpc/kvm/book3s_hv.c|4 ++--
 arch/powerpc/kvm/book3s_pr.c|4 ++--
 arch/powerpc/kvm/booke.c|4 ++--
 arch/powerpc/kvm/powerpc.c  |   15 --
 arch/s390/include/asm/kvm_host.h|1 +
 arch/s390/kvm/kvm-s390.c|   19 ++
 include/linux/kvm.h |   14 +
 include/linux/kvm_host.h|9 -
 virt/kvm/kvm_main.c |   38 +++
 11 files changed, 90 insertions(+), 39 deletions(-)

-- 
1.7.9.5

--
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/3] KVM: Move KVM_SET_ONE_REG/KVM_GET_ONE_REG to generic code.

2012-09-05 Thread Rusty Russell
Avi has indicated that this is the future.  For now, make it dependent on
KVM_HAVE_ONE_REG (and define that for PPC and S/390).

Signed-off-by: Rusty Russell rusty.russ...@linaro.org
---
 arch/powerpc/include/asm/kvm_host.h |1 +
 arch/powerpc/kvm/book3s_hv.c|4 ++--
 arch/powerpc/kvm/book3s_pr.c|4 ++--
 arch/powerpc/kvm/booke.c|4 ++--
 arch/powerpc/kvm/powerpc.c  |   15 ---
 arch/s390/include/asm/kvm_host.h|1 +
 arch/s390/kvm/kvm-s390.c|   19 ++-
 include/linux/kvm_host.h|4 
 virt/kvm/kvm_main.c |   18 ++
 9 files changed, 32 insertions(+), 38 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_host.h 
b/arch/powerpc/include/asm/kvm_host.h
index 28e8f5e..a021412 100644
--- a/arch/powerpc/include/asm/kvm_host.h
+++ b/arch/powerpc/include/asm/kvm_host.h
@@ -50,6 +50,7 @@
 #include linux/mmu_notifier.h
 
 #define KVM_ARCH_WANT_MMU_NOTIFIER
+#define KVM_HAVE_ONE_REG
 
 struct kvm;
 extern int kvm_unmap_hva(struct kvm *kvm, unsigned long hva);
diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 83e929e..8c711f1 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -535,7 +535,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
return 0;
 }
 
-int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
+int kvm_arch_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 {
int r = -EINVAL;
 
@@ -550,7 +550,7 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, 
struct kvm_one_reg *reg)
return r;
 }
 
-int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
+int kvm_arch_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 {
int r = -EINVAL;
 
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index 05c28f5..add88a9 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -899,7 +899,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
return 0;
 }
 
-int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
+int kvm_arch_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 {
int r = -EINVAL;
 
@@ -915,7 +915,7 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, 
struct kvm_one_reg *reg)
return r;
 }
 
-int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
+int kvm_arch_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 {
int r = -EINVAL;
 
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index d25a097..d239e8e 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -1219,12 +1219,12 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
return kvmppc_core_set_sregs(vcpu, sregs);
 }
 
-int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
+int kvm_arch_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 {
return -EINVAL;
 }
 
-int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
+int kvm_arch_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 {
return -EINVAL;
 }
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 879b14a..21cd47b 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -228,7 +228,6 @@ int kvm_dev_ioctl_check_extension(long ext)
case KVM_CAP_PPC_UNSET_IRQ:
case KVM_CAP_PPC_IRQ_LEVEL:
case KVM_CAP_ENABLE_CAP:
-   case KVM_CAP_ONE_REG:
r = 1;
break;
 #ifndef CONFIG_KVM_BOOK3S_64_HV
@@ -708,20 +707,6 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
break;
}
 
-   case KVM_SET_ONE_REG:
-   case KVM_GET_ONE_REG:
-   {
-   struct kvm_one_reg reg;
-   r = -EFAULT;
-   if (copy_from_user(reg, argp, sizeof(reg)))
-   goto out;
-   if (ioctl == KVM_SET_ONE_REG)
-   r = kvm_vcpu_ioctl_set_one_reg(vcpu, reg);
-   else
-   r = kvm_vcpu_ioctl_get_one_reg(vcpu, reg);
-   break;
-   }
-
 #if defined(CONFIG_KVM_E500V2) || defined(CONFIG_KVM_E500MC)
case KVM_DIRTY_TLB: {
struct kvm_dirty_tlb dirty;
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index b784154..9adb19d 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -23,6 +23,7 @@
 #define KVM_MEMORY_SLOTS 32
 /* memory slots that does not exposed to userspace */
 #define KVM_PRIVATE_MEM_SLOTS 4
+#define KVM_HAVE_ONE_REG
 
 struct sca_entry {
atomic_t scn;
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index e83df7f..916cf1d 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ 

Re: [RFC 0/5] Making KVM_GET_ONE_REG/KVM_SET_ONE_REG generic.

2012-09-05 Thread Rusty Russell
Avi Kivity a...@redhat.com writes:

 On 09/03/2012 03:33 PM, Rusty Russell wrote:
 Avi Kivity a...@redhat.com writes:
 On 09/01/2012 03:35 PM, Rusty Russell wrote:
 Passing an address in a struct is pretty bad, since it involves
 compatibility wrappers.  

 Right, some s390 thing.
 
 Err, no, i386 on x86-64, or ppc32 on ppc64, or arm on arm64
 
 Any time you put a pointer in a structure which is exposed to userspace,
 you have to deal with this.

 Not is you pack the pointer in a __u64, which is what we do to preserve
 padding.  Then it is only s390 which needs extra love.

OK, yes.  Or skip pointers altogether, like I do.

 Another option is to use the size parameter from the ioctl.  It just
 sits there doing nothing.

Not nothing, it defines the head struct size.  It's redundant, but
proven a useful sanity check over the years.

Perhaps somewhere else does use these 14 bits to represent a variable
size, but it would surprise me a bit to see it.  We'd probably want some
way to tell userspace the size then, so we have a different redundancy.

We're being too clever, that's why I copied the x86 MSR discovery
interface.

Cheers,
Rusty.
--
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: [RFC 0/5] Making KVM_GET_ONE_REG/KVM_SET_ONE_REG generic.

2012-09-05 Thread Rusty Russell
Peter Maydell peter.mayd...@linaro.org writes:
 On 1 September 2012 13:28, Rusty Russell ru...@rustcorp.com.au wrote:
 Rusty Russell (8):
   KVM: ARM: Fix walk_msrs()
   KVM: Move KVM_SET_ONE_REG/KVM_GET_ONE_REG to generic code.
   KVM: Add KVM_REG_SIZE() helper.
   KVM: ARM: use KVM_SET_ONE_REG/KVM_GET_ONE_REG.
   KVM: Add KVM_VCPU_GET_REG_LIST.
   KVM: ARM: Use KVM_VCPU_GET_REG_LIST.
   KVM: ARM: Access all registers via KVM_GET_ONE_REG/KVM_SET_ONE_REG.
   KVM ARM: Update api.txt

 So I was thinking about this, and I remembered that the SET_ONE_REG/
 GET_ONE_REG API has userspace pass a pointer to the variable the
 kernel should read/write (unlike the _MSR x86 ioctls, where the
 actual data value is sent back and forth in the struct). Further,
 the kernel only writes a data value of the size of the register
 (rather than always reading/writing a uint64_t).

 This is a problem because it means userspace needs to know the
 size of each register, and the kernel doesn't provide any way
 to determine the size. This defeats the idea that userspace should
 be able to migrate kernel register state without having to know
 the semantics of all the registers involved.

It's there.  There are bits in the id which indicate the size:

#define KVM_REG_SIZE_SHIFT  52
#define KVM_REG_SIZE_MASK   0x00f0ULL
#define KVM_REG_SIZE_U8 0xULL
#define KVM_REG_SIZE_U160x0010ULL
#define KVM_REG_SIZE_U320x0020ULL
#define KVM_REG_SIZE_U640x0030ULL
#define KVM_REG_SIZE_U128   0x0040ULL
#define KVM_REG_SIZE_U256   0x0050ULL
#define KVM_REG_SIZE_U512   0x0060ULL
#define KVM_REG_SIZE_U1024  0x0070ULL

And my patches added a helper:

#define KVM_REG_SIZE(id)\
(1U  (((id)  KVM_REG_SIZE_MASK)  KVM_REG_SIZE_SHIFT))

 I could live with always read/write 64 bits. I definitely don't
 want to have to deal with matching up register widths to accesses
 in userspace, please.

I changed my mind about the old scheme when I realized we have to deal
with 128-bit FPU registers.

Cheers,
Rusty.
--
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: [RFC 5/5] KVM: ARM: Access all registers via KVM_GET_ONE_REG/KVM_SET_ONE_REG.

2012-09-05 Thread Rusty Russell
Christoffer Dall c.d...@virtualopensystems.com writes:
 that's fine, but then the #define's shouldn't be called something with
 COPROC in their names.

Sure, feel free to rename it.  I failed to come up with a concise, clear
name, so coproc stuck.

Cheers,
Rusty.

--
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 v2 1/7] s390/kvm: Support for I/O interrupts.

2012-09-05 Thread Cornelia Huck
On Wed, 05 Sep 2012 10:28:53 +0300
Avi Kivity a...@redhat.com wrote:

 On 09/04/2012 06:13 PM, Cornelia Huck wrote:
  Add support for handling I/O interrupts (standard, subchannel-related
  ones and rudimentary adapter interrupts).
  
  The subchannel-identifying parameters are encoded into the interrupt
  type.
  
  I/O interrupts are floating, so they can't be injected on a specific
  vcpu.
  
  diff --git a/include/linux/kvm.h b/include/linux/kvm.h
  index d808694..5a36e65 100644
  --- a/include/linux/kvm.h
  +++ b/include/linux/kvm.h
  @@ -396,6 +396,12 @@ struct kvm_s390_psw {
   #define KVM_S390_INT_SERVICE   0x2401u
   #define KVM_S390_INT_EMERGENCY 0x1201u
   #define KVM_S390_INT_EXTERNAL_CALL 0x1202u
  +#define KVM_S390_INT_IO(ai,cssid,ssid,schid)   \
  +   (((schid)) |   \
  +((ssid)  16) |  \
  +((cssid)  18) | \
  +((ai)  26))
  +
   
 
 Documentation?
 

KVM_S390_INTERRUPT is currently completely undocumented... I'll
probably do an extra patch and then have this and the machine check
patch add the new values.

--
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 -v3] KVM: x86: lapic: Clean up find_highest_vector() and count_vectors()

2012-09-05 Thread Takuya Yoshikawa
On Thu, 30 Aug 2012 19:49:23 +0300
Michael S. Tsirkin m...@redhat.com wrote:

 On Fri, Aug 31, 2012 at 01:09:56AM +0900, Takuya Yoshikawa wrote:
  On Thu, 30 Aug 2012 16:21:31 +0300
  Michael S. Tsirkin m...@redhat.com wrote:
   
+static u32 apic_read_reg(int reg_off, void *bitmap)
+{
+   return *((u32 *)(bitmap + reg_off));
+}
+
   
   Contrast with apic_set_reg which gets apic,
   add fact that all callers invoke REG_POS and you will
   see this is a bad API.
   
   I played with some APIs but in the end it's
   probably better to just open-code this.
  
  I don't mind open-coding this.
  
   As a bonus, open-coding will avoid the need
   for cast above, which is good: casts make code more
   fragile.
  
  But I still don't understand why we can eliminate casting:
  
u32 reg_val;
  
reg_val = *((u32 *)(bitmap + REG_POS(vec)));
if (reg_val)
return __fls(reg_val) + vec;
  
  (I'm not sure compilers are allowed to push out the value and
  do multiple references for this code as explained in
  https://lwn.net/Articles/508991/
 
 So you *were* talking about concurrency?

Yes and no, please see below.

 And you expect to solve it somehow without barriers
 explicit or implicit?

What I want to make clear is that the value we pass to
__fls() is not zero, not any more, to avoid undefined
behaviour.

So as you showed below, if the value passed to __fls() is
exactly from the register, which we did non-zero check,
that's fine.  Barriers are not related here.

But as can be seen in the last part of the article above,
that's may theoretically not be guranteed?

Anyway, I'm now thinking that we do not care about such
things here, and can just follow your advice, yes?


 
  )
  
  
  If you mean
  
u32 *reg;
  
reg = bitmap + REG_POS(vec);
if (*reg)
return __fls(*reg) + vec;
 
 yes
 
  I'm still not confident if this is a good style.
  I rarely see code doing
  
if (*p)
__fls(*p);
  
  This looks like explicite multiple references: I'm not saying
  this will actually be compiled to do multiple references.
  
  Thanks,
  Takuya
 
 It's just weird. Both versions are exactly equivalent in C.
 Adding a temporary changes *nothing* so the best readability
 wins. And IMHO, a version that does not cast wins hands down.
 I did a small test just to give you an example:

Thank you for the example.

What you showed is what I wanted to mean by
I'm not saying this will actually be compiled to ...

Thanks,
Takuya

 
 [mst@robin ~]$ cat a.c 
 
 int foo(void *bitmap)
 {
unsigned *reg;
  
reg = bitmap + 4;
if (*reg)
return *reg + 1;
 
return -1;
 }
 [mst@robin ~]$ cat b.c 
 
 int foo(void *bitmap)
 {
unsigned reg;
  
reg = *((unsigned *)(bitmap + 4));
if (reg)
return reg + 1;
 
return -1;
 }
 
 [mst@robin ~]$ gcc -O2 -c a.c
 [mst@robin ~]$ gcc -O2 -c b.c
 
 
 [mst@robin ~]$ objdump -ld a.o
 
 a.o: file format elf32-i386
 
 
 Disassembly of section .text:
 
  foo:
 foo():
0:   8b 44 24 04 mov0x4(%esp),%eax
4:   8b 50 04mov0x4(%eax),%edx
7:   b8 ff ff ff ff  mov$0x,%eax
c:   8d 4a 01lea0x1(%edx),%ecx
f:   85 d2   test   %edx,%edx
   11:   0f 45 c1cmovne %ecx,%eax
   14:   c3  ret
 [mst@robin ~]$ objdump -ld b.o
 
 b.o: file format elf32-i386
 
 
 Disassembly of section .text:
 
  foo:
 foo():
0:   8b 44 24 04 mov0x4(%esp),%eax
4:   8b 50 04mov0x4(%eax),%edx
7:   b8 ff ff ff ff  mov$0x,%eax
c:   8d 4a 01lea0x1(%edx),%ecx
f:   85 d2   test   %edx,%edx
   11:   0f 45 c1cmovne %ecx,%eax
   14:   c3  ret
--
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 00/33] Cleanups and automatic init/exit calls

2012-09-05 Thread Sasha Levin
This patch series is mostly about cleanups:

 - Clean all the global variables we have to store configuration options.
 - Remove externed config options between objects.
 - Adding several exit routines to clean up on exit.
 - Remove the global 'kvm' object.
 - Contain arch specific init/exit calls within the corresponding non-arch
 specific code instead of the global init.


This patch series also adds a method to call init/exit functions automatically
after we've finished intializing config options.

Doing so clears out a big chunk of repetetive code in our builtin-run init
function, and makes adding new modules easier since there's now no need to
link them to builtin-run.


Sasha Levin (33):
  kvm tools: introduce kvm_config to store instance-specific config
options
  kvm tools: generate command line options dynamically
  kvm tools: split struct kvm into arch specific part
  kvm tools: move kvm_config into struct kvm
  kvm tools: remove redundancy between kvm_config and kvm
  kvm tools: move ioport_debug into struct kvm_config
  kvm tools: move mmio_debug into struct kvm_config
  kvm tools: move active_console into struct kvm_config
  kvm tools: add private ptr to option parser
  kvm tools: disk image related cleanup
  kvm tools: move nrcpus into struct kvm_config
  kvm tools: move kvm_cpus into struct kvm
  kvm tools: improve framebuffer manager initialization
  kvm tools: improve term init/exit functions
  kvm tools: threadpool exit routine
  kvm tools: timer cleanup
  kvm tools: virtio-console init/exit
  kvm tools: virtio-rng init/exit
  kvm tools: virtio-bln init/exit
  kvm tools: pci-shmem init-exit
  kvm tools: virtio-net init/exit
  kvm tools: kvm-ipc cleanup
  kvm tools: kbd initialization check
  kvm tools: ui improvements
  kvm tools: kernel load/firmware cleanup
  kvm tools: ioport arch init
  kvm tools: ram init
  kvm tools: move the rest of the config initializations
  kvm tools: virtio-9p cleanup
  kvm tools: add init/exit automatic calls
  kvm tools: use init/exit where possible
  kvm tools: pass kvm ptr directly to timer injection
  kvm tools: remove global kvm object

 tools/kvm/Makefile   |3 +-
 tools/kvm/builtin-run.c  |  +-
 tools/kvm/disk/core.c|   73 +-
 tools/kvm/framebuffer.c  |9 +-
 tools/kvm/hw/i8042.c |   15 +-
 tools/kvm/hw/pci-shmem.c |  147 +++-
 tools/kvm/hw/rtc.c   |   14 +-
 tools/kvm/hw/serial.c|   24 +-
 tools/kvm/hw/vesa.c  |6 +-
 tools/kvm/include/kvm/brlock.h   |   16 +-
 tools/kvm/include/kvm/disk-image.h   |9 +-
 tools/kvm/include/kvm/framebuffer.h  |5 +-
 tools/kvm/include/kvm/i8042.h|2 +-
 tools/kvm/include/kvm/ioport.h   |7 +-
 tools/kvm/include/kvm/kvm-config.h   |   60 ++
 tools/kvm/include/kvm/kvm-cpu.h  |6 +-
 tools/kvm/include/kvm/kvm-ipc.h  |8 +-
 tools/kvm/include/kvm/kvm.h  |   38 +-
 tools/kvm/include/kvm/parse-options.h|   16 +-
 tools/kvm/include/kvm/pci-shmem.h|6 +-
 tools/kvm/include/kvm/sdl.h  |8 +-
 tools/kvm/include/kvm/term.h |   16 +-
 tools/kvm/include/kvm/threadpool.h   |3 +-
 tools/kvm/include/kvm/util-init.h|   51 ++
 tools/kvm/include/kvm/virtio-9p.h|3 +
 tools/kvm/include/kvm/virtio-balloon.h   |3 +-
 tools/kvm/include/kvm/virtio-console.h   |3 +-
 tools/kvm/include/kvm/virtio-net.h   |6 +-
 tools/kvm/include/kvm/vnc.h  |   10 +-
 tools/kvm/ioeventfd.c|2 +
 tools/kvm/ioport.c   |   23 +-
 tools/kvm/kvm-cpu.c  |   81 ++-
 tools/kvm/kvm-ipc.c  |  301 +++-
 tools/kvm/kvm.c  |  229 ++
 tools/kvm/mmio.c |   13 +-
 tools/kvm/pci.c  |   12 +-
 tools/kvm/powerpc/cpu_info.c |2 +-
 tools/kvm/powerpc/include/kvm/kvm-arch.h |   24 +-
 tools/kvm/powerpc/irq.c  |2 +-
 tools/kvm/powerpc/kvm-cpu.c  |8 +-
 tools/kvm/powerpc/kvm.c  |   42 +-
 tools/kvm/powerpc/spapr_hvcons.c |   14 +-
 tools/kvm/powerpc/spapr_pci.c|2 +-
 tools/kvm/powerpc/xics.c |   24 +-
 tools/kvm/symbol.c   |4 +-
 tools/kvm/term.c |   61 +-
 tools/kvm/ui/sdl.c   |   26 +-
 tools/kvm/ui/vnc.c   |   26 +-
 tools/kvm/util/init.c|   69 ++
 tools/kvm/util/threadpool.c  |   36 +-
 tools/kvm/virtio/9p.c|   69 ++
 tools/kvm/virtio/balloon.c   |   23 +-
 tools/kvm/virtio/blk.c   |2 +
 tools/kvm/virtio/console.c   |   26 +-
 tools/kvm/virtio/net.c 

[PATCH 01/33] kvm tools: introduce kvm_config to store instance-specific config options

2012-09-05 Thread Sasha Levin
Move all the configurable options from global static variables to a 
self-contained
structure.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c| 310 +++--
 tools/kvm/include/kvm/kvm-config.h |  53 +++
 2 files changed, 210 insertions(+), 153 deletions(-)
 create mode 100644 tools/kvm/include/kvm/kvm-config.h

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 0412e58..19260c3 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -69,37 +69,40 @@ struct kvm *kvm;
 struct kvm_cpu **kvm_cpus;
 __thread struct kvm_cpu *current_kvm_cpu;
 
-static struct disk_image_params disk_image[MAX_DISK_IMAGES];
-static u64 ram_size;
-static u8  image_count;
-static u8 num_net_devices;
-static bool virtio_rng;
-static const char *kernel_cmdline;
-static const char *kernel_filename;
-static const char *vmlinux_filename;
-static const char *initrd_filename;
-static const char *firmware_filename;
-static const char *console;
-static const char *dev;
-static const char *network;
-static const char *host_ip;
-static const char *guest_ip;
-static const char *guest_mac;
-static const char *host_mac;
-static const char *script;
-static const char *guest_name;
-static const char *sandbox;
-static const char *hugetlbfs_path;
-static const char *custom_rootfs_name = default;
-static struct virtio_net_params *net_params;
-static bool single_step;
-static bool vnc;
-static bool sdl;
-static bool balloon;
-static bool using_rootfs;
-static bool custom_rootfs;
-static bool no_net;
-static bool no_dhcp;
+struct kvm_config {
+   struct disk_image_params disk_image[MAX_DISK_IMAGES];
+   u64 ram_size;
+   u8  image_count;
+   u8 num_net_devices;
+   bool virtio_rng;
+   const char *kernel_cmdline;
+   const char *kernel_filename;
+   const char *vmlinux_filename;
+   const char *initrd_filename;
+   const char *firmware_filename;
+   const char *console;
+   const char *dev;
+   const char *network;
+   const char *host_ip;
+   const char *guest_ip;
+   const char *guest_mac;
+   const char *host_mac;
+   const char *script;
+   const char *guest_name;
+   const char *sandbox;
+   const char *hugetlbfs_path;
+   const char *custom_rootfs_name;
+   struct virtio_net_params *net_params;
+   bool single_step;
+   bool vnc;
+   bool sdl;
+   bool balloon;
+   bool using_rootfs;
+   bool custom_rootfs;
+   bool no_net;
+   bool no_dhcp;
+} cfg;
+
 extern bool ioport_debug;
 extern bool mmio_debug;
 static int  kvm_run_wrapper;
@@ -140,13 +143,13 @@ static int img_name_parser(const struct option *opt, 
const char *arg, int unset)
S_ISDIR(st.st_mode)) {
char tmp[PATH_MAX];
 
-   if (using_rootfs)
+   if (cfg.using_rootfs)
die(Please use only one rootfs directory atmost);
 
if (realpath(arg, tmp) == 0 ||
virtio_9p__register(kvm, tmp, /dev/root)  0)
die(Unable to initialize virtio 9p);
-   using_rootfs = 1;
+   cfg.using_rootfs = 1;
return 0;
}
 
@@ -156,7 +159,7 @@ static int img_name_parser(const struct option *opt, const 
char *arg, int unset)
S_ISDIR(st.st_mode)) {
char tmp[PATH_MAX];
 
-   if (using_rootfs)
+   if (cfg.using_rootfs)
die(Please use only one rootfs directory atmost);
 
if (realpath(path, tmp) == 0 ||
@@ -165,25 +168,25 @@ static int img_name_parser(const struct option *opt, 
const char *arg, int unset)
if (virtio_9p__register(kvm, /, hostfs)  0)
die(Unable to initialize virtio 9p);
kvm_setup_resolv(arg);
-   using_rootfs = custom_rootfs = 1;
-   custom_rootfs_name = arg;
+   cfg.using_rootfs = cfg.custom_rootfs = 1;
+   cfg.custom_rootfs_name = arg;
return 0;
}
 
-   if (image_count = MAX_DISK_IMAGES)
+   if (cfg.image_count = MAX_DISK_IMAGES)
die(Currently only 4 images are supported);
 
-   disk_image[image_count].filename = arg;
+   cfg.disk_image[cfg.image_count].filename = arg;
cur = arg;
 
if (strncmp(arg, scsi:, 5) == 0) {
sep = strstr(arg, :);
if (sep)
-   disk_image[image_count].wwpn = sep + 1;
+   cfg.disk_image[cfg.image_count].wwpn = sep + 1;
sep = strstr(sep + 1, :);
if (sep) {
*sep = 0;
-   disk_image[image_count].tpgt = sep + 1;
+   cfg.disk_image[cfg.image_count].tpgt = sep + 1;
}
cur = sep + 1;
}
@@ -192,15 +195,15 @@ static int 

[PATCH 02/33] kvm tools: generate command line options dynamically

2012-09-05 Thread Sasha Levin
Since we now store options in a struct, we should generate the command line 
options
dynamically. This is a pre-requisite to the following patch moving the options
into struct kvm.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c | 132 ++--
 1 file changed, 72 insertions(+), 60 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 19260c3..db5ae4b 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -455,66 +455,76 @@ static int shmem_parser(const struct option *opt, const 
char *arg, int unset)
return 0;
 }
 
-static const struct option options[] = {
-   OPT_GROUP(Basic options:),
-   OPT_STRING('\0', name, cfg.guest_name, guest name,
-   A name for the guest),
-   OPT_INTEGER('c', cpus, nrcpus, Number of CPUs),
-   OPT_U64('m', mem, cfg.ram_size, Virtual machine memory size in 
MiB.),
-   OPT_CALLBACK('\0', shmem, NULL,
-[pci:]addr:size[:handle=handle][:create],
-Share host shmem with guest via pci device,
-shmem_parser),
-   OPT_CALLBACK('d', disk, NULL, image or rootfs_dir, Disk image or 
rootfs directory, img_name_parser),
-   OPT_BOOLEAN('\0', balloon, cfg.balloon, Enable virtio balloon),
-   OPT_BOOLEAN('\0', vnc, cfg.vnc, Enable VNC framebuffer),
-   OPT_BOOLEAN('\0', sdl, cfg.sdl, Enable SDL framebuffer),
-   OPT_BOOLEAN('\0', rng, cfg.virtio_rng, Enable virtio Random Number 
Generator),
-   OPT_CALLBACK('\0', 9p, NULL, dir_to_share,tag_name,
-Enable virtio 9p to share files between host and guest, 
virtio_9p_rootdir_parser),
-   OPT_STRING('\0', console, cfg.console, serial, virtio or hv,
-   Console to use),
-   OPT_STRING('\0', dev, cfg.dev, device_file, KVM device file),
-   OPT_CALLBACK('\0', tty, NULL, tty id,
-Remap guest TTY into a pty on the host,
-tty_parser),
-   OPT_STRING('\0', sandbox, cfg.sandbox, script,
-   Run this script when booting into custom rootfs),
-   OPT_STRING('\0', hugetlbfs, cfg.hugetlbfs_path, path, Hugetlbfs 
path),
-
-   OPT_GROUP(Kernel options:),
-   OPT_STRING('k', kernel, cfg.kernel_filename, kernel,
-   Kernel to boot in virtual machine),
-   OPT_STRING('i', initrd, cfg.initrd_filename, initrd,
-   Initial RAM disk image),
-   OPT_STRING('p', params, cfg.kernel_cmdline, params,
-   Kernel command line arguments),
-   OPT_STRING('f', firmware, cfg.firmware_filename, firmware,
-   Firmware image to boot in virtual machine),
-
-   OPT_GROUP(Networking options:),
-   OPT_CALLBACK_DEFAULT('n', network, NULL, network params,
-Create a new guest NIC,
-netdev_parser, NULL),
-   OPT_BOOLEAN('\0', no-dhcp, cfg.no_dhcp, Disable kernel DHCP in 
rootfs mode),
-
-   OPT_GROUP(BIOS options:),
-   OPT_INTEGER('\0', vidmode, vidmode,
-   Video mode),
-
-   OPT_GROUP(Debug options:),
-   OPT_BOOLEAN('\0', debug, do_debug_print,
-   Enable debug messages),
-   OPT_BOOLEAN('\0', debug-single-step, cfg.single_step,
-   Enable single stepping),
-   OPT_BOOLEAN('\0', debug-ioport, ioport_debug,
-   Enable ioport debugging),
-   OPT_BOOLEAN('\0', debug-mmio, mmio_debug,
-   Enable MMIO debugging),
-   OPT_INTEGER('\0', debug-iodelay, debug_iodelay,
-   Delay IO by millisecond),
-   OPT_END()
-};
+#define BUILD_OPTIONS(name, cfg)   \
+   struct option name[] = {\
+   OPT_GROUP(Basic options:),\
+   OPT_STRING('\0', name, (cfg)-guest_name, guest name,  \
+   A name for the guest),\
+   OPT_INTEGER('c', cpus, nrcpus, Number of CPUs),\
+   OPT_U64('m', mem, (cfg)-ram_size, Virtual machine memory size\
+   in MiB.),  \
+   OPT_CALLBACK('\0', shmem, NULL,   \
+[pci:]addr:size[:handle=handle][:create],  \
+Share host shmem with guest via pci device,  \
+shmem_parser), \
+   OPT_CALLBACK('d', disk, NULL, image or rootfs_dir, Disk\
+   image or rootfs directory, img_name_parser),   \
+   OPT_BOOLEAN('\0', balloon, (cfg)-balloon, Enable virtio\
+   balloon),  \
+   OPT_BOOLEAN('\0', vnc, (cfg)-vnc, Enable VNC framebuffer),\
+   OPT_BOOLEAN('\0', sdl, 

[PATCH 03/33] kvm tools: split struct kvm into arch specific part

2012-09-05 Thread Sasha Levin
Move all the non-arch specific members into a generic struct, and the arch 
specific
members into a arch specific kvm_arch. This prevents code duplication across 
different
archs.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/include/kvm/kvm.h  | 27 
 tools/kvm/powerpc/cpu_info.c |  2 +-
 tools/kvm/powerpc/include/kvm/kvm-arch.h | 24 +-
 tools/kvm/powerpc/irq.c  |  2 +-
 tools/kvm/powerpc/kvm-cpu.c  |  6 ++---
 tools/kvm/powerpc/kvm.c  | 42 
 tools/kvm/powerpc/spapr_pci.c|  2 +-
 tools/kvm/powerpc/xics.c | 24 +-
 tools/kvm/x86/bios.c |  6 ++---
 tools/kvm/x86/boot.c |  6 ++---
 tools/kvm/x86/include/kvm/kvm-arch.h | 26 +---
 tools/kvm/x86/kvm-cpu.c  | 30 +++
 tools/kvm/x86/kvm.c  | 12 -
 13 files changed, 95 insertions(+), 114 deletions(-)

diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index 22a1b0e..50c1d10 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -31,6 +31,33 @@ struct kvm_ext {
int code;
 };
 
+struct kvm {
+   struct kvm_arch arch;
+   int sys_fd; /* For system ioctls(), i.e. 
/dev/kvm */
+   int vm_fd;  /* For VM ioctls() */
+   timer_t timerid;/* Posix timer for interrupts */
+
+   int nrcpus; /* Number of cpus to run */
+
+   u32 mem_slots;  /* for 
KVM_SET_USER_MEMORY_REGION */
+
+   u64 ram_size;
+   void*ram_start;
+   u64 ram_pagesize;
+
+   boolnmi_disabled;
+
+   boolsingle_step;
+
+   const char  *vmlinux;
+   struct disk_image   **disks;
+   int nr_disks;
+
+   char*name;
+
+   int vm_state;
+};
+
 void kvm__set_dir(const char *fmt, ...);
 const char *kvm__get_dir(void);
 
diff --git a/tools/kvm/powerpc/cpu_info.c b/tools/kvm/powerpc/cpu_info.c
index 1f440a5..11ca14e 100644
--- a/tools/kvm/powerpc/cpu_info.c
+++ b/tools/kvm/powerpc/cpu_info.c
@@ -174,7 +174,7 @@ struct cpu_info *find_cpu_info(struct kvm *kvm)
 {
struct cpu_info *info;
unsigned int i;
-   u32 pvr = kvm-pvr;
+   u32 pvr = kvm-arch.pvr;
 
for (info = NULL, i = 0; i  ARRAY_SIZE(host_pvr_info); i++) {
if ((pvr  host_pvr_info[i].pvr_mask) == host_pvr_info[i].pvr) {
diff --git a/tools/kvm/powerpc/include/kvm/kvm-arch.h 
b/tools/kvm/powerpc/include/kvm/kvm-arch.h
index 316fe79..97181c4 100644
--- a/tools/kvm/powerpc/include/kvm/kvm-arch.h
+++ b/tools/kvm/powerpc/include/kvm/kvm-arch.h
@@ -43,36 +43,14 @@
 
 struct spapr_phb;
 
-struct kvm {
-   int sys_fd; /* For system ioctls(), i.e. 
/dev/kvm */
-   int vm_fd;  /* For VM ioctls() */
-   timer_t timerid;/* Posix timer for interrupts */
-
-   int nrcpus; /* Number of cpus to run */
-
-   u32 mem_slots;  /* for 
KVM_SET_USER_MEMORY_REGION */
-
-   u64 ram_size;
-   void*ram_start;
-   u64 ram_pagesize;
-
+struct kvm_arch {
u64 sdr1;
u32 pvr;
-
-   boolnmi_disabled;
-
-   boolsingle_step;
-
-   const char  *vmlinux;
-   struct disk_image   **disks;
-   int nr_disks;
unsigned long   rtas_gra;
unsigned long   rtas_size;
unsigned long   fdt_gra;
unsigned long   initrd_gra;
unsigned long   initrd_size;
-   char*name;
-   int vm_state;
struct icp_state*icp;
struct spapr_phb*phb;
 };
diff --git a/tools/kvm/powerpc/irq.c b/tools/kvm/powerpc/irq.c
index 7da4012..6d134c5 100644
--- a/tools/kvm/powerpc/irq.c
+++ b/tools/kvm/powerpc/irq.c
@@ -59,7 +59,7 @@ int irq__init(struct kvm *kvm)
 * are numbered 0..nrcpus.  This may not really be true,
 * but it is OK currently.
 */
-   kvm-icp = xics_system_init(XICS_IRQS, kvm-nrcpus);
+   kvm-arch.icp = xics_system_init(XICS_IRQS, kvm-nrcpus);
return 0;
 }
 
diff --git a/tools/kvm/powerpc/kvm-cpu.c b/tools/kvm/powerpc/kvm-cpu.c
index 97fc759..755d11a 100644
--- a/tools/kvm/powerpc/kvm-cpu.c
+++ b/tools/kvm/powerpc/kvm-cpu.c
@@ -115,7 +115,7 @@ static void 

[PATCH 05/33] kvm tools: remove redundancy between kvm_config and kvm

2012-09-05 Thread Sasha Levin
Remove some redundant members between struct kvm_config and struct kvm
since options are now contained within struct kvm.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c | 2 --
 tools/kvm/hw/rtc.c  | 2 +-
 tools/kvm/include/kvm/kvm.h | 3 ---
 tools/kvm/kvm-cpu.c | 2 +-
 4 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index a8926dd..8221c22 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -1040,8 +1040,6 @@ static int kvm_cmd_run_init(int argc, const char **argv)
if (r)
goto fail;
 
-   kvm-single_step = kvm-cfg.single_step;
-
r = ioeventfd__init(kvm);
if (r  0) {
pr_err(ioeventfd__init() failed with error %d\n, r);
diff --git a/tools/kvm/hw/rtc.c b/tools/kvm/hw/rtc.c
index b4f9f1f..4941daf 100644
--- a/tools/kvm/hw/rtc.c
+++ b/tools/kvm/hw/rtc.c
@@ -134,4 +134,4 @@ int rtc__exit(struct kvm *kvm)
ioport__unregister(0x0071);
 
return 0;
-}
\ No newline at end of file
+}
diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index 167693e..ca4375a 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -42,15 +42,12 @@ struct kvm {
int nrcpus; /* Number of cpus to run */
 
u32 mem_slots;  /* for 
KVM_SET_USER_MEMORY_REGION */
-
u64 ram_size;
void*ram_start;
u64 ram_pagesize;
 
boolnmi_disabled;
 
-   boolsingle_step;
-
const char  *vmlinux;
struct disk_image   **disks;
int nr_disks;
diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c
index 12791dd..dbd14b7 100644
--- a/tools/kvm/kvm-cpu.c
+++ b/tools/kvm/kvm-cpu.c
@@ -92,7 +92,7 @@ int kvm_cpu__start(struct kvm_cpu *cpu)
 
kvm_cpu__reset_vcpu(cpu);
 
-   if (cpu-kvm-single_step)
+   if (cpu-kvm-cfg.single_step)
kvm_cpu__enable_singlestep(cpu);
 
while (cpu-is_running) {
-- 
1.7.12

--
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 04/33] kvm tools: move kvm_config into struct kvm

2012-09-05 Thread Sasha Levin
Contain the options within struct kvm itself. This way options are specific
to a given struct kvm and not just global.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c | 273 +++-
 tools/kvm/include/kvm/kvm.h |   7 +-
 tools/kvm/kvm.c |  37 ++
 3 files changed, 130 insertions(+), 187 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index db5ae4b..a8926dd 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -49,60 +49,14 @@
 #include ctype.h
 #include stdio.h
 
-#define DEFAULT_KVM_DEV/dev/kvm
-#define DEFAULT_CONSOLEserial
-#define DEFAULT_NETWORKuser
-#define DEFAULT_HOST_ADDR  192.168.33.1
-#define DEFAULT_GUEST_ADDR 192.168.33.15
-#define DEFAULT_GUEST_MAC  02:15:15:15:15:15
-#define DEFAULT_HOST_MAC   02:01:01:01:01:01
-#define DEFAULT_SCRIPT none
-const char *DEFAULT_SANDBOX_FILENAME = guest/sandbox.sh;
-
 #define MB_SHIFT   (20)
 #define KB_SHIFT   (10)
 #define GB_SHIFT   (30)
-#define MIN_RAM_SIZE_MB(64ULL)
-#define MIN_RAM_SIZE_BYTE  (MIN_RAM_SIZE_MB  MB_SHIFT)
 
 struct kvm *kvm;
 struct kvm_cpu **kvm_cpus;
 __thread struct kvm_cpu *current_kvm_cpu;
 
-struct kvm_config {
-   struct disk_image_params disk_image[MAX_DISK_IMAGES];
-   u64 ram_size;
-   u8  image_count;
-   u8 num_net_devices;
-   bool virtio_rng;
-   const char *kernel_cmdline;
-   const char *kernel_filename;
-   const char *vmlinux_filename;
-   const char *initrd_filename;
-   const char *firmware_filename;
-   const char *console;
-   const char *dev;
-   const char *network;
-   const char *host_ip;
-   const char *guest_ip;
-   const char *guest_mac;
-   const char *host_mac;
-   const char *script;
-   const char *guest_name;
-   const char *sandbox;
-   const char *hugetlbfs_path;
-   const char *custom_rootfs_name;
-   struct virtio_net_params *net_params;
-   bool single_step;
-   bool vnc;
-   bool sdl;
-   bool balloon;
-   bool using_rootfs;
-   bool custom_rootfs;
-   bool no_net;
-   bool no_dhcp;
-} cfg;
-
 extern bool ioport_debug;
 extern bool mmio_debug;
 static int  kvm_run_wrapper;
@@ -143,13 +97,13 @@ static int img_name_parser(const struct option *opt, const 
char *arg, int unset)
S_ISDIR(st.st_mode)) {
char tmp[PATH_MAX];
 
-   if (cfg.using_rootfs)
+   if (kvm-cfg.using_rootfs)
die(Please use only one rootfs directory atmost);
 
if (realpath(arg, tmp) == 0 ||
virtio_9p__register(kvm, tmp, /dev/root)  0)
die(Unable to initialize virtio 9p);
-   cfg.using_rootfs = 1;
+   kvm-cfg.using_rootfs = 1;
return 0;
}
 
@@ -159,7 +113,7 @@ static int img_name_parser(const struct option *opt, const 
char *arg, int unset)
S_ISDIR(st.st_mode)) {
char tmp[PATH_MAX];
 
-   if (cfg.using_rootfs)
+   if (kvm-cfg.using_rootfs)
die(Please use only one rootfs directory atmost);
 
if (realpath(path, tmp) == 0 ||
@@ -168,25 +122,25 @@ static int img_name_parser(const struct option *opt, 
const char *arg, int unset)
if (virtio_9p__register(kvm, /, hostfs)  0)
die(Unable to initialize virtio 9p);
kvm_setup_resolv(arg);
-   cfg.using_rootfs = cfg.custom_rootfs = 1;
-   cfg.custom_rootfs_name = arg;
+   kvm-cfg.using_rootfs = kvm-cfg.custom_rootfs = 1;
+   kvm-cfg.custom_rootfs_name = arg;
return 0;
}
 
-   if (cfg.image_count = MAX_DISK_IMAGES)
+   if (kvm-cfg.image_count = MAX_DISK_IMAGES)
die(Currently only 4 images are supported);
 
-   cfg.disk_image[cfg.image_count].filename = arg;
+   kvm-cfg.disk_image[kvm-cfg.image_count].filename = arg;
cur = arg;
 
if (strncmp(arg, scsi:, 5) == 0) {
sep = strstr(arg, :);
if (sep)
-   cfg.disk_image[cfg.image_count].wwpn = sep + 1;
+   kvm-cfg.disk_image[kvm-cfg.image_count].wwpn = sep + 
1;
sep = strstr(sep + 1, :);
if (sep) {
*sep = 0;
-   cfg.disk_image[cfg.image_count].tpgt = sep + 1;
+   kvm-cfg.disk_image[kvm-cfg.image_count].tpgt = sep + 
1;
}
cur = sep + 1;
}
@@ -195,15 +149,15 @@ static int img_name_parser(const struct option *opt, 
const char *arg, int unset)
sep = strstr(cur, ,);
if (sep) {
if 

[PATCH 06/33] kvm tools: move ioport_debug into struct kvm_config

2012-09-05 Thread Sasha Levin
This config option was 'extern'ed between different objects. Clean it up
and move it into struct kvm_config.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c| 3 +--
 tools/kvm/include/kvm/kvm-config.h | 1 +
 tools/kvm/ioport.c | 5 ++---
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 8221c22..4a6ff1a 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -57,7 +57,6 @@ struct kvm *kvm;
 struct kvm_cpu **kvm_cpus;
 __thread struct kvm_cpu *current_kvm_cpu;
 
-extern bool ioport_debug;
 extern bool mmio_debug;
 static int  kvm_run_wrapper;
 extern int  active_console;
@@ -471,7 +470,7 @@ static int shmem_parser(const struct option *opt, const 
char *arg, int unset)
Enable debug messages),   \
OPT_BOOLEAN('\0', debug-single-step, (cfg)-single_step, \
Enable single stepping),  \
-   OPT_BOOLEAN('\0', debug-ioport, ioport_debug,\
+   OPT_BOOLEAN('\0', debug-ioport, (cfg)-ioport_debug, \
Enable ioport debugging), \
OPT_BOOLEAN('\0', debug-mmio, mmio_debug,\
Enable MMIO debugging),   \
diff --git a/tools/kvm/include/kvm/kvm-config.h 
b/tools/kvm/include/kvm/kvm-config.h
index 3ffc2c2..f45edb0 100644
--- a/tools/kvm/include/kvm/kvm-config.h
+++ b/tools/kvm/include/kvm/kvm-config.h
@@ -48,6 +48,7 @@ struct kvm_config {
bool custom_rootfs;
bool no_net;
bool no_dhcp;
+   bool ioport_debug;
 };
 
 #endif
diff --git a/tools/kvm/ioport.c b/tools/kvm/ioport.c
index 662a78b..2208c15 100644
--- a/tools/kvm/ioport.c
+++ b/tools/kvm/ioport.c
@@ -21,7 +21,6 @@ DEFINE_MUTEX(ioport_mutex);
 static u16 free_io_port_idx; /* protected by ioport_mutex 
*/
 
 static struct rb_root  ioport_tree = RB_ROOT;
-bool   ioport_debug;
 
 static u16 ioport__find_free_port(void)
 {
@@ -177,10 +176,10 @@ bool kvm__emulate_io(struct kvm *kvm, u16 port, void 
*data, int direction, int s
 error:
br_read_unlock();
 
-   if (ioport_debug)
+   if (kvm-cfg.ioport_debug)
ioport_error(port, data, direction, size, count);
 
-   return !ioport_debug;
+   return !kvm-cfg.ioport_debug;
 }
 
 int ioport__init(struct kvm *kvm)
-- 
1.7.12

--
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 09/33] kvm tools: add private ptr to option parser

2012-09-05 Thread Sasha Levin
Support passing a private ptr to CALLBACK options. This will make it possible
assigning options into specific struct kvms by passing them directly to parsers.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c   | 13 +++--
 tools/kvm/include/kvm/parse-options.h | 16 ++--
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 2b4315b..52e0190 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -417,9 +417,10 @@ static int shmem_parser(const struct option *opt, const 
char *arg, int unset)
OPT_CALLBACK('\0', shmem, NULL,   \
 [pci:]addr:size[:handle=handle][:create],  \
 Share host shmem with guest via pci device,  \
-shmem_parser), \
-   OPT_CALLBACK('d', disk, NULL, image or rootfs_dir, Disk\
-   image or rootfs directory, img_name_parser),   \
+shmem_parser, NULL),   \
+   OPT_CALLBACK('d', disk, kvm, image or rootfs_dir, Disk \
+   image or rootfs directory, img_name_parser,\
+   NULL),  \
OPT_BOOLEAN('\0', balloon, (cfg)-balloon, Enable virtio\
balloon),  \
OPT_BOOLEAN('\0', vnc, (cfg)-vnc, Enable VNC framebuffer),\
@@ -428,14 +429,14 @@ static int shmem_parser(const struct option *opt, const 
char *arg, int unset)
Number Generator), \
OPT_CALLBACK('\0', 9p, NULL, dir_to_share,tag_name, \
 Enable virtio 9p to share files between host and  \
-guest, virtio_9p_rootdir_parser), \
+guest, virtio_9p_rootdir_parser, NULL),   \
OPT_STRING('\0', console, (cfg)-console, serial, virtio or \
hv, Console to use), \
OPT_STRING('\0', dev, (cfg)-dev, device_file, \
KVM device file), \
OPT_CALLBACK('\0', tty, NULL, tty id,   \
 Remap guest TTY into a pty on the host,  \
-tty_parser),   \
+tty_parser, NULL), \
OPT_STRING('\0', sandbox, (cfg)-sandbox, script,  \
Run this script when booting into custom   \
rootfs),   \
@@ -455,7 +456,7 @@ static int shmem_parser(const struct option *opt, const 
char *arg, int unset)
OPT_GROUP(Networking options:),   \
OPT_CALLBACK_DEFAULT('n', network, NULL, network params,\
 Create a new guest NIC,  \
-netdev_parser, NULL),  \
+netdev_parser, NULL, NULL),\
OPT_BOOLEAN('\0', no-dhcp, (cfg)-no_dhcp, Disable kernel DHCP\
in rootfs mode),   \
\
diff --git a/tools/kvm/include/kvm/parse-options.h 
b/tools/kvm/include/kvm/parse-options.h
index 7886ff7..a8a25d0 100644
--- a/tools/kvm/include/kvm/parse-options.h
+++ b/tools/kvm/include/kvm/parse-options.h
@@ -89,6 +89,7 @@ const char *long_name;
 void *value;
 const char *argh;
 const char *help;
+void *ptr;
 
 int flags;
 parse_opt_cb *callback;
@@ -150,7 +151,7 @@ intptr_t defval;
.help = (h) \
 }
 
-#define OPT_CALLBACK(s, l, v, a, h, f)  \
+#define OPT_CALLBACK(s, l, v, a, h, f, p)   \
 {  \
.type = OPTION_CALLBACK,\
.short_name = (s),  \
@@ -158,10 +159,11 @@ intptr_t defval;
.value = (v),   \
(a),\
.help = (h),\
-   .callback = (f) \
+   .callback = (f),\
+   .ptr = (p), \
 }
 
-#define OPT_CALLBACK_NOOPT(s, l, v, a, h, f) \
+#define OPT_CALLBACK_NOOPT(s, l, v, a, h, f, p) \
 {  \
.type = OPTION_CALLBACK,\
.short_name = (s),  \
@@ -170,10 +172,11 @@ intptr_t defval;
(a),\
.help = (h),\
.callback = (f),\
-   .flags = PARSE_OPT_NOARG\
+   .flags = PARSE_OPT_NOARG,   \
+  

[PATCH 08/33] kvm tools: move active_console into struct kvm_config

2012-09-05 Thread Sasha Levin
This config option was 'extern'ed between different objects. Clean it up
and move it into struct kvm_config.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c|  9 -
 tools/kvm/hw/serial.c  | 16 ++--
 tools/kvm/include/kvm/kvm-config.h |  1 +
 tools/kvm/include/kvm/term.h   | 10 +-
 tools/kvm/powerpc/spapr_hvcons.c   | 14 ++
 tools/kvm/term.c   | 28 ++--
 tools/kvm/virtio/console.c | 12 +---
 7 files changed, 45 insertions(+), 45 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 117a9de..2b4315b 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -58,7 +58,6 @@ struct kvm_cpu **kvm_cpus;
 __thread struct kvm_cpu *current_kvm_cpu;
 
 static int  kvm_run_wrapper;
-extern int  active_console;
 extern int  debug_iodelay;
 
 bool do_debug_print = false;
@@ -1000,11 +999,11 @@ static int kvm_cmd_run_init(int argc, const char **argv)
kvm-cfg.console = DEFAULT_CONSOLE;
 
if (!strncmp(kvm-cfg.console, virtio, 6))
-   active_console  = CONSOLE_VIRTIO;
+   kvm-cfg.active_console  = CONSOLE_VIRTIO;
else if (!strncmp(kvm-cfg.console, serial, 6))
-   active_console  = CONSOLE_8250;
+   kvm-cfg.active_console  = CONSOLE_8250;
else if (!strncmp(kvm-cfg.console, hv, 2))
-   active_console = CONSOLE_HV;
+   kvm-cfg.active_console = CONSOLE_HV;
else
pr_warning(No console!);
 
@@ -1182,7 +1181,7 @@ static int kvm_cmd_run_init(int argc, const char **argv)
}
 
 
-   if (active_console == CONSOLE_VIRTIO)
+   if (kvm-cfg.active_console == CONSOLE_VIRTIO)
virtio_console__init(kvm);
 
if (kvm-cfg.virtio_rng)
diff --git a/tools/kvm/hw/serial.c b/tools/kvm/hw/serial.c
index 956307c..63dedd0 100644
--- a/tools/kvm/hw/serial.c
+++ b/tools/kvm/hw/serial.c
@@ -95,12 +95,13 @@ static struct serial8250_device devices[] = {
},
 };
 
-static void serial8250_flush_tx(struct serial8250_device *dev)
+static void serial8250_flush_tx(struct kvm *kvm, struct serial8250_device *dev)
 {
dev-lsr |= UART_LSR_TEMT | UART_LSR_THRE;
 
if (dev-txcnt) {
-   term_putc(CONSOLE_8250, dev-txbuf, dev-txcnt, dev-id);
+   if (kvm-cfg.active_console == CONSOLE_8250)
+   term_putc(dev-txbuf, dev-txcnt, dev-id);
dev-txcnt = 0;
}
 }
@@ -149,7 +150,7 @@ static void serial8250_update_irq(struct kvm *kvm, struct 
serial8250_device *dev
 * here.
 */
if (!(dev-ier  UART_IER_THRI))
-   serial8250_flush_tx(dev);
+   serial8250_flush_tx(kvm, dev);
 }
 
 #define SYSRQ_PENDING_NONE 0
@@ -175,7 +176,7 @@ static void serial8250__receive(struct kvm *kvm, struct 
serial8250_device *dev,
 * should give the kernel the desired pause. That also flushes
 * the tx fifo to the terminal.
 */
-   serial8250_flush_tx(dev);
+   serial8250_flush_tx(kvm, dev);
 
if (dev-mcr  UART_MCR_LOOP)
return;
@@ -188,10 +189,13 @@ static void serial8250__receive(struct kvm *kvm, struct 
serial8250_device *dev,
return;
}
 
-   while (term_readable(CONSOLE_8250, dev-id) 
+   if (kvm-cfg.active_console != CONSOLE_8250)
+   return;
+
+   while (term_readable(dev-id) 
   dev-rxcnt  FIFO_LEN) {
 
-   c = term_getc(CONSOLE_8250, dev-id);
+   c = term_getc(dev-id);
 
if (c  0)
break;
diff --git a/tools/kvm/include/kvm/kvm-config.h 
b/tools/kvm/include/kvm/kvm-config.h
index e3edf29..fd7a5cd 100644
--- a/tools/kvm/include/kvm/kvm-config.h
+++ b/tools/kvm/include/kvm/kvm-config.h
@@ -22,6 +22,7 @@ struct kvm_config {
u8  image_count;
u8 num_net_devices;
bool virtio_rng;
+   int active_console;
const char *kernel_cmdline;
const char *kernel_filename;
const char *vmlinux_filename;
diff --git a/tools/kvm/include/kvm/term.h b/tools/kvm/include/kvm/term.h
index a6a9822..33d96ce 100644
--- a/tools/kvm/include/kvm/term.h
+++ b/tools/kvm/include/kvm/term.h
@@ -8,12 +8,12 @@
 #define CONSOLE_VIRTIO 2
 #define CONSOLE_HV 3
 
-int term_putc_iov(int who, struct iovec *iov, int iovcnt, int term);
-int term_getc_iov(int who, struct iovec *iov, int iovcnt, int term);
-int term_putc(int who, char *addr, int cnt, int term);
-int term_getc(int who, int term);
+int term_putc_iov(struct iovec *iov, int iovcnt, int term);
+int term_getc_iov(struct iovec *iov, int iovcnt, int term);
+int term_putc(char *addr, int cnt, int term);
+int term_getc(int term);
 
-bool term_readable(int who, int term);
+bool term_readable(int term);
 void term_set_tty(int term);
 void term_init(void);
 

[PATCH 07/33] kvm tools: move mmio_debug into struct kvm_config

2012-09-05 Thread Sasha Levin
This config option was 'extern'ed between different objects. Clean it up
and move it into struct kvm_config.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c| 3 +--
 tools/kvm/include/kvm/kvm-config.h | 1 +
 tools/kvm/mmio.c   | 3 +--
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 4a6ff1a..117a9de 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -57,7 +57,6 @@ struct kvm *kvm;
 struct kvm_cpu **kvm_cpus;
 __thread struct kvm_cpu *current_kvm_cpu;
 
-extern bool mmio_debug;
 static int  kvm_run_wrapper;
 extern int  active_console;
 extern int  debug_iodelay;
@@ -472,7 +471,7 @@ static int shmem_parser(const struct option *opt, const 
char *arg, int unset)
Enable single stepping),  \
OPT_BOOLEAN('\0', debug-ioport, (cfg)-ioport_debug, \
Enable ioport debugging), \
-   OPT_BOOLEAN('\0', debug-mmio, mmio_debug,\
+   OPT_BOOLEAN('\0', debug-mmio, (cfg)-mmio_debug, \
Enable MMIO debugging),   \
OPT_INTEGER('\0', debug-iodelay, debug_iodelay,  \
Delay IO by millisecond), \
diff --git a/tools/kvm/include/kvm/kvm-config.h 
b/tools/kvm/include/kvm/kvm-config.h
index f45edb0..e3edf29 100644
--- a/tools/kvm/include/kvm/kvm-config.h
+++ b/tools/kvm/include/kvm/kvm-config.h
@@ -49,6 +49,7 @@ struct kvm_config {
bool no_net;
bool no_dhcp;
bool ioport_debug;
+   bool mmio_debug;
 };
 
 #endif
diff --git a/tools/kvm/mmio.c b/tools/kvm/mmio.c
index dd28ef33..38ce117 100644
--- a/tools/kvm/mmio.c
+++ b/tools/kvm/mmio.c
@@ -21,7 +21,6 @@ struct mmio_mapping {
 };
 
 static struct rb_root mmio_tree = RB_ROOT;
-bool mmio_debug = false;
 
 static struct mmio_mapping *mmio_search(struct rb_root *root, u64 addr, u64 
len)
 {
@@ -130,7 +129,7 @@ bool kvm__emulate_mmio(struct kvm *kvm, u64 phys_addr, u8 
*data, u32 len, u8 is_
if (mmio)
mmio-mmio_fn(phys_addr, data, len, is_write, mmio-ptr);
else {
-   if (mmio_debug)
+   if (kvm-cfg.mmio_debug)
fprintf(stderr, Warning: Ignoring MMIO %s at %016llx 
(length %u)\n,
to_direction(is_write), phys_addr, len);
}
-- 
1.7.12

--
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 10/33] kvm tools: disk image related cleanup

2012-09-05 Thread Sasha Levin
Move io debug delay into kvm_config, the parser out of builtin-run into the 
disk code
and make the init/exit functions match the rest of the code in style.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c| 75 ++
 tools/kvm/disk/core.c  | 71 ++--
 tools/kvm/include/kvm/disk-image.h |  9 +++--
 tools/kvm/include/kvm/kvm-config.h |  1 +
 4 files changed, 92 insertions(+), 64 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 52e0190..cb48ead 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -58,7 +58,6 @@ struct kvm_cpu **kvm_cpus;
 __thread struct kvm_cpu *current_kvm_cpu;
 
 static int  kvm_run_wrapper;
-extern int  debug_iodelay;
 
 bool do_debug_print = false;
 
@@ -78,17 +77,11 @@ enum {
KVM_RUN_SANDBOX,
 };
 
-void kvm_run_set_wrapper_sandbox(void)
-{
-   kvm_run_wrapper = KVM_RUN_SANDBOX;
-}
-
 static int img_name_parser(const struct option *opt, const char *arg, int 
unset)
 {
char path[PATH_MAX];
-   const char *cur;
struct stat st;
-   char *sep;
+   struct kvm *kvm = opt-ptr;
 
if (stat(arg, st) == 0 
S_ISDIR(st.st_mode)) {
@@ -124,39 +117,12 @@ static int img_name_parser(const struct option *opt, 
const char *arg, int unset)
return 0;
}
 
-   if (kvm-cfg.image_count = MAX_DISK_IMAGES)
-   die(Currently only 4 images are supported);
-
-   kvm-cfg.disk_image[kvm-cfg.image_count].filename = arg;
-   cur = arg;
-
-   if (strncmp(arg, scsi:, 5) == 0) {
-   sep = strstr(arg, :);
-   if (sep)
-   kvm-cfg.disk_image[kvm-cfg.image_count].wwpn = sep + 
1;
-   sep = strstr(sep + 1, :);
-   if (sep) {
-   *sep = 0;
-   kvm-cfg.disk_image[kvm-cfg.image_count].tpgt = sep + 
1;
-   }
-   cur = sep + 1;
-   }
-
-   do {
-   sep = strstr(cur, ,);
-   if (sep) {
-   if (strncmp(sep + 1, ro, 2) == 0)
-   
kvm-cfg.disk_image[kvm-cfg.image_count].readonly = true;
-   else if (strncmp(sep + 1, direct, 6) == 0)
-   
kvm-cfg.disk_image[kvm-cfg.image_count].direct = true;
-   *sep = 0;
-   cur = sep + 1;
-   }
-   } while (sep);
-
-   kvm-cfg.image_count++;
+   return disk_img_name_parser(opt, arg, unset);
+}
 
-   return 0;
+void kvm_run_set_wrapper_sandbox(void)
+{
+   kvm_run_wrapper = KVM_RUN_SANDBOX;
 }
 
 static int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, 
int unset)
@@ -406,7 +372,7 @@ static int shmem_parser(const struct option *opt, const 
char *arg, int unset)
return 0;
 }
 
-#define BUILD_OPTIONS(name, cfg)   \
+#define BUILD_OPTIONS(name, cfg, kvm)  \
struct option name[] = {\
OPT_GROUP(Basic options:),\
OPT_STRING('\0', name, (cfg)-guest_name, guest name,  \
@@ -420,7 +386,7 @@ static int shmem_parser(const struct option *opt, const 
char *arg, int unset)
 shmem_parser, NULL),   \
OPT_CALLBACK('d', disk, kvm, image or rootfs_dir, Disk \
image or rootfs directory, img_name_parser,\
-   NULL),  \
+   kvm),   \
OPT_BOOLEAN('\0', balloon, (cfg)-balloon, Enable virtio\
balloon),  \
OPT_BOOLEAN('\0', vnc, (cfg)-vnc, Enable VNC framebuffer),\
@@ -473,7 +439,7 @@ static int shmem_parser(const struct option *opt, const 
char *arg, int unset)
Enable ioport debugging), \
OPT_BOOLEAN('\0', debug-mmio, (cfg)-mmio_debug, \
Enable MMIO debugging),   \
-   OPT_INTEGER('\0', debug-iodelay, debug_iodelay,  \
+   OPT_INTEGER('\0', debug-iodelay, (cfg)-debug_iodelay,   \
Delay IO by millisecond), \
OPT_END()   \
};
@@ -768,7 +734,7 @@ static const char *find_vmlinux(void)
 
 void kvm_run_help(void)
 {
-   BUILD_OPTIONS(options, kvm-cfg);
+   BUILD_OPTIONS(options, kvm-cfg, kvm);
usage_with_options(run_usage, options);
 }
 
@@ -927,7 +893,7 @@ static int kvm_cmd_run_init(int argc, const char **argv)
kvm-cfg.custom_rootfs_name = default;
 
while (argc != 0) {
-

[PATCH 11/33] kvm tools: move nrcpus into struct kvm_config

2012-09-05 Thread Sasha Levin
This no longer has to be a global since we now have kvm_config.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c| 31 +++
 tools/kvm/include/kvm/kvm-config.h |  1 +
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index cb48ead..df8e17c 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -61,7 +61,6 @@ static int  kvm_run_wrapper;
 
 bool do_debug_print = false;
 
-static int nrcpus;
 static int vidmode = -1;
 
 extern char _binary_guest_init_start;
@@ -377,7 +376,7 @@ static int shmem_parser(const struct option *opt, const 
char *arg, int unset)
OPT_GROUP(Basic options:),\
OPT_STRING('\0', name, (cfg)-guest_name, guest name,  \
A name for the guest),\
-   OPT_INTEGER('c', cpus, nrcpus, Number of CPUs),\
+   OPT_INTEGER('c', cpus, (cfg)-nrcpus, Number of CPUs), \
OPT_U64('m', mem, (cfg)-ram_size, Virtual machine memory size\
in MiB.),  \
OPT_CALLBACK('\0', shmem, NULL,   \
@@ -528,7 +527,7 @@ static void handle_debug(int fd, u32 type, u32 len, u8 *msg)
if (!(dbg_type  KVM_DEBUG_CMD_TYPE_DUMP))
return;
 
-   for (i = 0; i  nrcpus; i++) {
+   for (i = 0; i  kvm-nrcpus; i++) {
struct kvm_cpu *cpu = kvm_cpus[i];
 
if (!cpu)
@@ -947,11 +946,11 @@ static int kvm_cmd_run_init(int argc, const char **argv)
 
kvm-cfg.vmlinux_filename = find_vmlinux();
 
-   if (nrcpus == 0)
-   nrcpus = nr_online_cpus;
+   if (kvm-cfg.nrcpus == 0)
+   kvm-cfg.nrcpus = nr_online_cpus;
 
if (!kvm-cfg.ram_size)
-   kvm-cfg.ram_size = get_ram_size(nrcpus);
+   kvm-cfg.ram_size = get_ram_size(kvm-cfg.nrcpus);
 
if (kvm-cfg.ram_size  MIN_RAM_SIZE_MB)
die(Not enough memory specified: %lluMB (min %lluMB), 
kvm-cfg.ram_size, MIN_RAM_SIZE_MB);
@@ -1015,20 +1014,20 @@ static int kvm_cmd_run_init(int argc, const char **argv)
max_cpus = kvm__max_cpus(kvm);
recommended_cpus = kvm__recommended_cpus(kvm);
 
-   if (nrcpus  max_cpus) {
+   if (kvm-cfg.nrcpus  max_cpus) {
printf(  # Limit the number of CPUs to %d\n, max_cpus);
-   nrcpus = max_cpus;
-   } else if (nrcpus  recommended_cpus) {
+   kvm-cfg.nrcpus = max_cpus;
+   } else if (kvm-cfg.nrcpus  recommended_cpus) {
printf(  # Warning: The maximum recommended amount of VCPUs
 is %d\n, recommended_cpus);
}
 
-   kvm-nrcpus = nrcpus;
+   kvm-nrcpus = kvm-cfg.nrcpus;
 
/* Alloc one pointer too many, so array ends up 0-terminated */
-   kvm_cpus = calloc(nrcpus + 1, sizeof(void *));
+   kvm_cpus = calloc(kvm-nrcpus + 1, sizeof(void *));
if (!kvm_cpus)
-   die(Couldn't allocate array for %d CPUs, nrcpus);
+   die(Couldn't allocate array for %d CPUs, kvm-nrcpus);
 
r = irq__init(kvm);
if (r  0) {
@@ -1105,7 +1104,7 @@ static int kvm_cmd_run_init(int argc, const char **argv)
}
 
printf(  # %s run -k %s -m %Lu -c %d --name %s\n, KVM_BINARY_NAME,
-   kvm-cfg.kernel_filename, kvm-cfg.ram_size / 1024 / 1024, 
nrcpus, kvm-cfg.guest_name);
+   kvm-cfg.kernel_filename, kvm-cfg.ram_size / 1024 / 1024, 
kvm-cfg.nrcpus, kvm-cfg.guest_name);
 
if (!kvm-cfg.firmware_filename) {
if (!kvm__load_kernel(kvm, kvm-cfg.kernel_filename,
@@ -1235,7 +1234,7 @@ static int kvm_cmd_run_init(int argc, const char **argv)
}
}
 
-   for (i = 0; i  nrcpus; i++) {
+   for (i = 0; i  kvm-nrcpus; i++) {
kvm_cpus[i] = kvm_cpu__init(kvm, i);
if (!kvm_cpus[i])
die(unable to initialize KVM VCPU);
@@ -1251,7 +1250,7 @@ static int kvm_cmd_run_work(void)
int i, r = -1;
void *ret = NULL;
 
-   for (i = 0; i  nrcpus; i++) {
+   for (i = 0; i  kvm-nrcpus; i++) {
if (pthread_create(kvm_cpus[i]-thread, NULL, kvm_cpu_thread, 
kvm_cpus[i]) != 0)
die(unable to create KVM VCPU thread);
}
@@ -1263,7 +1262,7 @@ static int kvm_cmd_run_work(void)
kvm_cpu__delete(kvm_cpus[0]);
kvm_cpus[0] = NULL;
 
-   for (i = 1; i  nrcpus; i++) {
+   for (i = 1; i  kvm-nrcpus; i++) {
if (kvm_cpus[i]-is_running) {
pthread_kill(kvm_cpus[i]-thread, SIGKVMEXIT);
if (pthread_join(kvm_cpus[i]-thread, ret) != 0)
diff --git a/tools/kvm/include/kvm/kvm-config.h 
b/tools/kvm/include/kvm/kvm-config.h
index 35cde48..1f06df3 100644
--- 

[PATCH 12/33] kvm tools: move kvm_cpus into struct kvm

2012-09-05 Thread Sasha Levin
There's no reason the array of guest specific vcpus is global. Move it into
struct kvm.

Also split up arch specific vcpu init from the generic code and call it from
the kvm_cpu initializer.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/Makefile  |  2 +-
 tools/kvm/builtin-run.c | 70 +-
 tools/kvm/hw/i8042.c|  2 +-
 tools/kvm/hw/vesa.c |  1 +
 tools/kvm/include/kvm/framebuffer.h |  1 +
 tools/kvm/include/kvm/kvm-cpu.h |  6 ++-
 tools/kvm/include/kvm/kvm.h |  1 +
 tools/kvm/kvm-cpu.c | 75 ++---
 tools/kvm/kvm.c |  6 +--
 tools/kvm/powerpc/kvm-cpu.c |  2 +-
 tools/kvm/term.c|  2 +-
 tools/kvm/ui/sdl.c  |  2 +-
 tools/kvm/x86/kvm-cpu.c |  2 +-
 13 files changed, 104 insertions(+), 68 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 0e2fa66..efa3d4f 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -243,7 +243,7 @@ DEFINES += -DKVMTOOLS_VERSION='$(KVMTOOLS_VERSION)'
 DEFINES+= -DBUILD_ARCH='$(ARCH)'
 
 KVM_INCLUDE := include
-CFLAGS += $(CPPFLAGS) $(DEFINES) -I$(KVM_INCLUDE) -I$(ARCH_INCLUDE) 
-I$(KINCL_PATH)/include -I$(KINCL_PATH)/arch/$(ARCH)/include/ -O2 
-fno-strict-aliasing -g -flto
+CFLAGS += $(CPPFLAGS) $(DEFINES) -I$(KVM_INCLUDE) -I$(ARCH_INCLUDE) 
-I$(KINCL_PATH)/include -I$(KINCL_PATH)/arch/$(ARCH)/include/ -O0 
-fno-strict-aliasing -g -flto
 
 WARNINGS += -Wall
 WARNINGS += -Wcast-align
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index df8e17c..8b332c1 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -54,7 +54,6 @@
 #define GB_SHIFT   (30)
 
 struct kvm *kvm;
-struct kvm_cpu **kvm_cpus;
 __thread struct kvm_cpu *current_kvm_cpu;
 
 static int  kvm_run_wrapper;
@@ -520,15 +519,15 @@ static void handle_debug(int fd, u32 type, u32 len, u8 
*msg)
if ((int)vcpu = kvm-nrcpus)
return;
 
-   kvm_cpus[vcpu]-needs_nmi = 1;
-   pthread_kill(kvm_cpus[vcpu]-thread, SIGUSR1);
+   kvm-cpus[vcpu]-needs_nmi = 1;
+   pthread_kill(kvm-cpus[vcpu]-thread, SIGUSR1);
}
 
if (!(dbg_type  KVM_DEBUG_CMD_TYPE_DUMP))
return;
 
for (i = 0; i  kvm-nrcpus; i++) {
-   struct kvm_cpu *cpu = kvm_cpus[i];
+   struct kvm_cpu *cpu = kvm-cpus[i];
 
if (!cpu)
continue;
@@ -561,7 +560,7 @@ static void handle_stop(int fd, u32 type, u32 len, u8 *msg)
if (WARN_ON(type != KVM_IPC_STOP || len))
return;
 
-   kvm_cpu__reboot();
+   kvm_cpu__reboot(kvm);
 }
 
 static void *kvm_cpu_thread(void *arg)
@@ -873,7 +872,6 @@ static int kvm_cmd_run_init(int argc, const char **argv)
static char real_cmdline[2048], default_name[20];
struct framebuffer *fb = NULL;
unsigned int nr_online_cpus;
-   int max_cpus, recommended_cpus;
int i, r;
 
kvm = kvm__new();
@@ -1011,24 +1009,12 @@ static int kvm_cmd_run_init(int argc, const char **argv)
goto fail;
}
 
-   max_cpus = kvm__max_cpus(kvm);
-   recommended_cpus = kvm__recommended_cpus(kvm);
-
-   if (kvm-cfg.nrcpus  max_cpus) {
-   printf(  # Limit the number of CPUs to %d\n, max_cpus);
-   kvm-cfg.nrcpus = max_cpus;
-   } else if (kvm-cfg.nrcpus  recommended_cpus) {
-   printf(  # Warning: The maximum recommended amount of VCPUs
-is %d\n, recommended_cpus);
+   r = kvm_cpu__init(kvm);
+   if (r  0) {
+   pr_err(kvm_cpu__init() failed with error %d\n, r);
+   goto fail;
}
-
-   kvm-nrcpus = kvm-cfg.nrcpus;
-
-   /* Alloc one pointer too many, so array ends up 0-terminated */
-   kvm_cpus = calloc(kvm-nrcpus + 1, sizeof(void *));
-   if (!kvm_cpus)
-   die(Couldn't allocate array for %d CPUs, kvm-nrcpus);
-
+   
r = irq__init(kvm);
if (r  0) {
pr_err(irq__init() failed with error %d\n, r);
@@ -1217,7 +1203,8 @@ static int kvm_cmd_run_init(int argc, const char **argv)
goto fail;
}
 
-   /* Device init all done; firmware init must
+   /* 
+* Device init all done; firmware init must
 * come after this (it may set up device trees etc.)
 */
 
@@ -1234,12 +1221,6 @@ static int kvm_cmd_run_init(int argc, const char **argv)
}
}
 
-   for (i = 0; i  kvm-nrcpus; i++) {
-   kvm_cpus[i] = kvm_cpu__init(kvm, i);
-   if (!kvm_cpus[i])
-   die(unable to initialize KVM VCPU);
-   }
-
thread_pool__init(nr_online_cpus);
 fail:
return r;
@@ -1247,33 +1228,16 @@ fail:
 
 static int 

[PATCH 13/33] kvm tools: improve framebuffer manager initialization

2012-09-05 Thread Sasha Levin
Make the init and exit functions of the framebuffer similar to the rest
of the code.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c | 6 --
 tools/kvm/framebuffer.c | 6 --
 tools/kvm/include/kvm/framebuffer.h | 4 ++--
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 8b332c1..569c934 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -1197,7 +1197,7 @@ static int kvm_cmd_run_init(int argc, const char **argv)
}
}
 
-   r = fb__start();
+   r = fb__init(kvm);
if (r  0) {
pr_err(fb__init() failed with error %d\n, r);
goto fail;
@@ -1258,7 +1258,9 @@ static void kvm_cmd_run_exit(int guest_ret)
if (r  0)
pr_warning(irq__exit() failed with error %d\n, r);
 
-   fb__stop();
+   r = fb__exit(kvm);
+   if (r  0)
+   pr_warning(fb__exit() failed with error %d\n, r);
 
r = virtio_scsi_exit(kvm);
if (r  0)
diff --git a/tools/kvm/framebuffer.c b/tools/kvm/framebuffer.c
index e15b717..a9d6f75 100644
--- a/tools/kvm/framebuffer.c
+++ b/tools/kvm/framebuffer.c
@@ -44,7 +44,7 @@ static int start_targets(struct framebuffer *fb)
return 0;
 }
 
-int fb__start(void)
+int fb__init(struct kvm *kvm)
 {
struct framebuffer *fb;
 
@@ -59,7 +59,7 @@ int fb__start(void)
return 0;
 }
 
-void fb__stop(void)
+int fb__exit(struct kvm *kvm)
 {
struct framebuffer *fb;
 
@@ -72,4 +72,6 @@ void fb__stop(void)
 
munmap(fb-mem, fb-mem_size);
}
+
+   return 0;
 }
diff --git a/tools/kvm/include/kvm/framebuffer.h 
b/tools/kvm/include/kvm/framebuffer.h
index 64f6a26..e3200e5 100644
--- a/tools/kvm/include/kvm/framebuffer.h
+++ b/tools/kvm/include/kvm/framebuffer.h
@@ -30,7 +30,7 @@ struct framebuffer {
 
 struct framebuffer *fb__register(struct framebuffer *fb);
 int fb__attach(struct framebuffer *fb, struct fb_target_operations *ops);
-int fb__start(void);
-void fb__stop(void);
+int fb__init(struct kvm *kvm);
+int fb__exit(struct kvm *kvm);
 
 #endif /* KVM__FRAMEBUFFER_H */
-- 
1.7.12

--
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 14/33] kvm tools: improve term init/exit functions

2012-09-05 Thread Sasha Levin
Make the init and exit functions of the term code similar to the rest
of the code.

Also move in the pty parser into the term code out of builtin-run.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c  | 19 +--
 tools/kvm/include/kvm/term.h |  6 +-
 tools/kvm/term.c | 28 
 3 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 569c934..b4da06e 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -146,15 +146,6 @@ static int virtio_9p_rootdir_parser(const struct option 
*opt, const char *arg, i
return 0;
 }
 
-static int tty_parser(const struct option *opt, const char *arg, int unset)
-{
-   int tty = atoi(arg);
-
-   term_set_tty(tty);
-
-   return 0;
-}
-
 static inline void str_to_mac(const char *str, char *mac)
 {
sscanf(str, %hhx:%hhx:%hhx:%hhx:%hhx:%hhx,
@@ -988,7 +979,11 @@ static int kvm_cmd_run_init(int argc, const char **argv)
if (!kvm-cfg.script)
kvm-cfg.script = DEFAULT_SCRIPT;
 
-   term_init();
+   r = term_init(kvm);
+   if (r  0) {
+   pr_err(term_init() failed with error %d\n, r);
+   goto fail;
+   }
 
if (!kvm-cfg.guest_name) {
if (kvm-cfg.custom_rootfs) {
@@ -1302,6 +1297,10 @@ static void kvm_cmd_run_exit(int guest_ret)
if (r  0)
pr_warning(pci__exit() failed with error %d\n, r);
 
+   r = term_exit(kvm);
+   if (r  0)
+   pr_warning(pci__exit() failed with error %d\n, r);
+
r = kvm__exit(kvm);
if (r  0)
pr_warning(pci__exit() failed with error %d\n, r);
diff --git a/tools/kvm/include/kvm/term.h b/tools/kvm/include/kvm/term.h
index 33d96ce..493ce39 100644
--- a/tools/kvm/include/kvm/term.h
+++ b/tools/kvm/include/kvm/term.h
@@ -1,6 +1,8 @@
 #ifndef KVM__TERM_H
 #define KVM__TERM_H
 
+#include kvm/kvm.h
+
 #include sys/uio.h
 #include stdbool.h
 
@@ -15,6 +17,8 @@ int term_getc(int term);
 
 bool term_readable(int term);
 void term_set_tty(int term);
-void term_init(void);
+int term_init(struct kvm *kvm);
+int term_exit(struct kvm *kvm);
+int tty_parser(const struct option *opt, const char *arg, int unset);
 
 #endif /* KVM__TERM_H */
diff --git a/tools/kvm/term.c b/tools/kvm/term.c
index fb7963e..66f4804 100644
--- a/tools/kvm/term.c
+++ b/tools/kvm/term.c
@@ -127,13 +127,26 @@ void term_set_tty(int term)
term_fds[term][TERM_FD_IN] = term_fds[term][TERM_FD_OUT] = master;
 }
 
-void term_init(void)
+int tty_parser(const struct option *opt, const char *arg, int unset)
+{
+   int tty = atoi(arg);
+
+   term_set_tty(tty);
+
+   return 0;
+}
+
+int term_init(struct kvm *kvm)
 {
struct termios term;
-   int i;
+   int i, r;
+
+   r = tcgetattr(STDIN_FILENO, orig_term);
+   if (r  0) {
+   pr_warning(unable to save initial standard input settings);
+   return r;
+   }
 
-   if (tcgetattr(STDIN_FILENO, orig_term)  0)
-   die(unable to save initial standard input settings);
 
term = orig_term;
term.c_lflag = ~(ICANON | ECHO | ISIG);
@@ -147,4 +160,11 @@ void term_init(void)
 
signal(SIGTERM, term_sig_cleanup);
atexit(term_cleanup);
+
+   return 0;
+}
+
+int term_exit(struct kvm *kvm)
+{
+   return 0;
 }
-- 
1.7.12

--
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 15/33] kvm tools: threadpool exit routine

2012-09-05 Thread Sasha Levin
Add an exit function for the threadpool which will stop all running threads in 
the
pool. Also clean up the init code a bit.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c| 11 ++-
 tools/kvm/include/kvm/threadpool.h |  3 ++-
 tools/kvm/util/threadpool.c| 33 +
 3 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index b4da06e..d83917f 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -1216,7 +1216,12 @@ static int kvm_cmd_run_init(int argc, const char **argv)
}
}
 
-   thread_pool__init(nr_online_cpus);
+   r = thread_pool__init(kvm);
+   if (r  0) {
+   pr_err(thread_pool__init() failed with error %d\n, r);
+   goto fail;
+   }
+
 fail:
return r;
 }
@@ -1301,6 +1306,10 @@ static void kvm_cmd_run_exit(int guest_ret)
if (r  0)
pr_warning(pci__exit() failed with error %d\n, r);
 
+   r = thread_pool__exit(kvm);
+   if (r  0)
+   pr_warning(thread_pool__exit() failed with error %d\n, r);
+
r = kvm__exit(kvm);
if (r  0)
pr_warning(pci__exit() failed with error %d\n, r);
diff --git a/tools/kvm/include/kvm/threadpool.h 
b/tools/kvm/include/kvm/threadpool.h
index 768239f..abe46ea 100644
--- a/tools/kvm/include/kvm/threadpool.h
+++ b/tools/kvm/include/kvm/threadpool.h
@@ -30,7 +30,8 @@ static inline void thread_pool__init_job(struct 
thread_pool__job *job, struct kv
};
 }
 
-int thread_pool__init(unsigned long thread_count);
+int thread_pool__init(struct kvm *kvm);
+int thread_pool__exit(struct kvm *kvm);
 
 void thread_pool__do_job(struct thread_pool__job *job);
 
diff --git a/tools/kvm/util/threadpool.c b/tools/kvm/util/threadpool.c
index bafbcd7..6c7566d 100644
--- a/tools/kvm/util/threadpool.c
+++ b/tools/kvm/util/threadpool.c
@@ -14,6 +14,7 @@ static LIST_HEAD(head);
 
 static pthread_t   *threads;
 static longthreadcount;
+static boolrunning;
 
 static struct thread_pool__job *thread_pool__job_pop_locked(void)
 {
@@ -76,15 +77,16 @@ static void *thread_pool__threadfunc(void *param)
 {
pthread_cleanup_push(thread_pool__threadfunc_cleanup, NULL);
 
-   for (;;) {
+   while (running) {
struct thread_pool__job *curjob;
 
mutex_lock(job_mutex);
-   while ((curjob = thread_pool__job_pop_locked()) == NULL)
+   while (running  (curjob = thread_pool__job_pop_locked()) == 
NULL)
pthread_cond_wait(job_cond, job_mutex);
mutex_unlock(job_mutex);
 
-   thread_pool__handle_job(curjob);
+   if (running)
+   thread_pool__handle_job(curjob);
}
 
pthread_cleanup_pop(0);
@@ -116,9 +118,12 @@ static int thread_pool__addthread(void)
return res;
 }
 
-int thread_pool__init(unsigned long thread_count)
+int thread_pool__init(struct kvm *kvm)
 {
unsigned long i;
+   unsigned int thread_count = sysconf(_SC_NPROCESSORS_ONLN);
+
+   running = true;
 
for (i = 0; i  thread_count; i++)
if (thread_pool__addthread()  0)
@@ -127,6 +132,26 @@ int thread_pool__init(unsigned long thread_count)
return i;
 }
 
+int thread_pool__exit(struct kvm *kvm)
+{
+   int i;
+   void *NUL = NULL;
+
+   running = false;
+
+   for (i = 0; i  threadcount; i++) {
+   mutex_lock(job_mutex);
+   pthread_cond_signal(job_cond);
+   mutex_unlock(job_mutex);
+   }
+
+   for (i = 0; i  threadcount; i++) {
+   pthread_join(threads[i], NUL);
+   }
+
+   return 0;
+}
+
 void thread_pool__do_job(struct thread_pool__job *job)
 {
struct thread_pool__job *jobinfo = job;
-- 
1.7.12

--
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 16/33] kvm tools: timer cleanup

2012-09-05 Thread Sasha Levin
Make the timer init/exit follow the rest of the code, and move it out of
builtin-run.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c | 12 ++--
 tools/kvm/include/kvm/kvm.h |  4 ++--
 tools/kvm/kvm.c | 23 +++
 3 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index d83917f..f09aac8 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -1203,7 +1203,11 @@ static int kvm_cmd_run_init(int argc, const char **argv)
 * come after this (it may set up device trees etc.)
 */
 
-   kvm__start_timer(kvm);
+   r = kvm_timer__init(kvm);
+   if (r  0) {
+   pr_err(kvm_timer__init() failed with error %d\n, r);
+   goto fail;
+   }
 
if (kvm-cfg.firmware_filename) {
if (!kvm__load_firmware(kvm, kvm-cfg.firmware_filename))
@@ -1258,9 +1262,13 @@ static void kvm_cmd_run_exit(int guest_ret)
if (r  0)
pr_warning(irq__exit() failed with error %d\n, r);
 
+   r = kvm_timer__exit(kvm);
+   if (r  0)
+   pr_warning(kvm_timer__exit() failed with error %d\n, r);
+
r = fb__exit(kvm);
if (r  0)
-   pr_warning(fb__exit() failed with error %d\n, r);
+   pr_warning(kvm_timer__exit() failed with error %d\n, r);
 
r = virtio_scsi_exit(kvm);
if (r  0)
diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index d3b6dab..2cd30e4 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -68,8 +68,8 @@ int kvm__exit(struct kvm *kvm);
 bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename);
 bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename,
const char *initrd_filename, const char 
*kernel_cmdline, u16 vidmode);
-void kvm__start_timer(struct kvm *kvm);
-void kvm__stop_timer(struct kvm *kvm);
+int kvm_timer__init(struct kvm *kvm);
+int kvm_timer__exit(struct kvm *kvm);
 void kvm__irq_line(struct kvm *kvm, int irq, int level);
 void kvm__irq_trigger(struct kvm *kvm, int irq);
 bool kvm__emulate_io(struct kvm *kvm, u16 port, void *data, int direction, int 
size, u32 count);
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index eeac0f6..42a0f06 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -254,8 +254,6 @@ int kvm__enumerate_instances(int (*callback)(const char 
*name, int fd))
 
 int kvm__exit(struct kvm *kvm)
 {
-   kvm__stop_timer(kvm);
-
kvm__arch_delete_ram(kvm);
kvm_ipc__stop();
kvm__remove_socket(kvm-cfg.guest_name);
@@ -478,10 +476,11 @@ found_kernel:
  * userspace hypervisor into the guest at periodical intervals. Please note
  * that clock interrupt, for example, is not handled here.
  */
-void kvm__start_timer(struct kvm *kvm)
+int kvm_timer__init(struct kvm *kvm)
 {
struct itimerspec its;
struct sigevent sev;
+   int r;
 
memset(sev, 0, sizeof(struct sigevent));
sev.sigev_value.sival_int   = 0;
@@ -489,25 +488,33 @@ void kvm__start_timer(struct kvm *kvm)
sev.sigev_signo = SIGALRM;
sev._sigev_un._tid  = syscall(__NR_gettid);
 
-   if (timer_create(CLOCK_REALTIME, sev, kvm-timerid)  0)
-   die(timer_create());
+   r = timer_create(CLOCK_REALTIME, sev, kvm-timerid);
+   if (r  0)
+   return r;
 
its.it_value.tv_sec = TIMER_INTERVAL_NS / 10;
its.it_value.tv_nsec= TIMER_INTERVAL_NS % 10;
its.it_interval.tv_sec  = its.it_value.tv_sec;
its.it_interval.tv_nsec = its.it_value.tv_nsec;
 
-   if (timer_settime(kvm-timerid, 0, its, NULL)  0)
-   die(timer_settime());
+   r = timer_settime(kvm-timerid, 0, its, NULL);
+   if (r  0) {
+   timer_delete(kvm-timerid);
+   return r;
+   }
+
+   return 0;
 }
 
-void kvm__stop_timer(struct kvm *kvm)
+int kvm_timer__exit(struct kvm *kvm)
 {
if (kvm-timerid)
if (timer_delete(kvm-timerid)  0)
die(timer_delete());
 
kvm-timerid = 0;
+
+   return 0;
 }
 
 void kvm__dump_mem(struct kvm *kvm, unsigned long addr, unsigned long size)
-- 
1.7.12

--
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 17/33] kvm tools: virtio-console init/exit

2012-09-05 Thread Sasha Levin
Make the init/exit of virtio-console self-contained, so the global init code
won't need to check if it was selected or not.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c| 12 +---
 tools/kvm/include/kvm/virtio-console.h |  3 ++-
 tools/kvm/virtio/console.c | 12 +++-
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index f09aac8..ef539b9a 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -1124,9 +1124,11 @@ static int kvm_cmd_run_init(int argc, const char **argv)
goto fail;
}
 
-
-   if (kvm-cfg.active_console == CONSOLE_VIRTIO)
-   virtio_console__init(kvm);
+   r = virtio_console__init(kvm);
+   if (r  0) {
+   pr_err(virtio_console__init() failed with error %d\n, r);
+   goto fail;
+   }
 
if (kvm-cfg.virtio_rng)
virtio_rng__init(kvm);
@@ -1282,6 +1284,10 @@ static void kvm_cmd_run_exit(int guest_ret)
if (r  0)
pr_warning(virtio_rng__exit() failed with error %d\n, r);
 
+   r = virtio_console__exit(kvm);
+   if (r  0)
+   pr_warning(virtio_console__exit() failed with error %d\n, r);
+
r = disk_image__exit(kvm);
if (r  0)
pr_warning(disk_image__exit() failed with error %d\n, r);
diff --git a/tools/kvm/include/kvm/virtio-console.h 
b/tools/kvm/include/kvm/virtio-console.h
index 50d8653..8980920 100644
--- a/tools/kvm/include/kvm/virtio-console.h
+++ b/tools/kvm/include/kvm/virtio-console.h
@@ -3,7 +3,8 @@
 
 struct kvm;
 
-void virtio_console__init(struct kvm *kvm);
+int virtio_console__init(struct kvm *kvm);
 void virtio_console__inject_interrupt(struct kvm *kvm);
+int virtio_console__exit(struct kvm *kvm);
 
 #endif /* KVM__CONSOLE_VIRTIO_H */
diff --git a/tools/kvm/virtio/console.c b/tools/kvm/virtio/console.c
index 4a9ca9f..a1cb8f4 100644
--- a/tools/kvm/virtio/console.c
+++ b/tools/kvm/virtio/console.c
@@ -182,10 +182,20 @@ static struct virtio_ops con_dev_virtio_ops = (struct 
virtio_ops) {
.get_size_vq= get_size_vq,
 };
 
-void virtio_console__init(struct kvm *kvm)
+int virtio_console__init(struct kvm *kvm)
 {
+   if (kvm-cfg.active_console != CONSOLE_VIRTIO)
+   return 0;
+
virtio_init(kvm, cdev, cdev.vdev, con_dev_virtio_ops,
VIRTIO_PCI, PCI_DEVICE_ID_VIRTIO_CONSOLE, 
VIRTIO_ID_CONSOLE, PCI_CLASS_CONSOLE);
if (compat_id == -1)
compat_id = virtio_compat_add_message(virtio-console, 
CONFIG_VIRTIO_CONSOLE);
+
+   return 0;
+}
+
+int virtio_console__exit(struct kvm *kvm)
+{
+   return 0;
 }
-- 
1.7.12

--
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 18/33] kvm tools: virtio-rng init/exit

2012-09-05 Thread Sasha Levin
Make the init/exit of virtio-rng self-contained, so the global init code
won't need to check if it was selected or not.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c | 7 +--
 tools/kvm/virtio/rng.c  | 3 +++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index ef539b9a..ed7babc 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -1130,8 +1130,11 @@ static int kvm_cmd_run_init(int argc, const char **argv)
goto fail;
}
 
-   if (kvm-cfg.virtio_rng)
-   virtio_rng__init(kvm);
+   r = virtio_rng__init(kvm);
+   if (r  0) {
+   pr_err(virtio_rng__init() failed with error %d\n, r);
+   goto fail;
+   }
 
if (kvm-cfg.balloon)
virtio_bln__init(kvm);
diff --git a/tools/kvm/virtio/rng.c b/tools/kvm/virtio/rng.c
index 2b1ab39..91228e2 100644
--- a/tools/kvm/virtio/rng.c
+++ b/tools/kvm/virtio/rng.c
@@ -147,6 +147,9 @@ int virtio_rng__init(struct kvm *kvm)
struct rng_dev *rdev;
int r;
 
+   if (!kvm-cfg.virtio_rng)
+   return 0;
+
rdev = malloc(sizeof(*rdev));
if (rdev == NULL)
return -ENOMEM;
-- 
1.7.12

--
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 19/33] kvm tools: virtio-bln init/exit

2012-09-05 Thread Sasha Levin
Make the init/exit of virtio-balloon self-contained, so the global init code
won't need to check if it was selected or not.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c| 11 +--
 tools/kvm/include/kvm/virtio-balloon.h |  3 ++-
 tools/kvm/virtio/balloon.c | 12 +++-
 3 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index ed7babc..ec61696 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -1136,8 +1136,11 @@ static int kvm_cmd_run_init(int argc, const char **argv)
goto fail;
}
 
-   if (kvm-cfg.balloon)
-   virtio_bln__init(kvm);
+   r = virtio_bln__init(kvm);
+   if (r  0) {
+   pr_err(virtio_rng__init() failed with error %d\n, r);
+   goto fail;
+   }
 
if (!kvm-cfg.network)
kvm-cfg.network = DEFAULT_NETWORK;
@@ -1287,6 +1290,10 @@ static void kvm_cmd_run_exit(int guest_ret)
if (r  0)
pr_warning(virtio_rng__exit() failed with error %d\n, r);
 
+   r = virtio_bln__exit(kvm);
+   if (r  0)
+   pr_warning(virtio_bln__exit() failed with error %d\n, r);
+
r = virtio_console__exit(kvm);
if (r  0)
pr_warning(virtio_console__exit() failed with error %d\n, r);
diff --git a/tools/kvm/include/kvm/virtio-balloon.h 
b/tools/kvm/include/kvm/virtio-balloon.h
index eb49fd4..844a1ba 100644
--- a/tools/kvm/include/kvm/virtio-balloon.h
+++ b/tools/kvm/include/kvm/virtio-balloon.h
@@ -3,6 +3,7 @@
 
 struct kvm;
 
-void virtio_bln__init(struct kvm *kvm);
+int virtio_bln__init(struct kvm *kvm);
+int virtio_bln__exit(struct kvm *kvm);
 
 #endif /* KVM__BLN_VIRTIO_H */
diff --git a/tools/kvm/virtio/balloon.c b/tools/kvm/virtio/balloon.c
index ea64fd4..07852d7 100644
--- a/tools/kvm/virtio/balloon.c
+++ b/tools/kvm/virtio/balloon.c
@@ -243,8 +243,11 @@ struct virtio_ops bln_dev_virtio_ops = (struct virtio_ops) 
{
.get_size_vq= get_size_vq,
 };
 
-void virtio_bln__init(struct kvm *kvm)
+int virtio_bln__init(struct kvm *kvm)
 {
+   if (!kvm-cfg.balloon)
+   return 0;
+
kvm_ipc__register_handler(KVM_IPC_BALLOON, handle_mem);
kvm_ipc__register_handler(KVM_IPC_STAT, virtio_bln__print_stats);
 
@@ -256,4 +259,11 @@ void virtio_bln__init(struct kvm *kvm)
 
if (compat_id == -1)
compat_id = virtio_compat_add_message(virtio-balloon, 
CONFIG_VIRTIO_BALLOON);
+
+   return 0;
+}
+
+int virtio_bln__exit(struct kvm *kvm)
+{
+   return 0;
 }
-- 
1.7.12

--
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 21/33] kvm tools: virtio-net init/exit

2012-09-05 Thread Sasha Levin
Make the init/exit of virtio-net self-contained, so the global init code
won't need to check if it was selected or not.

This also moves the bulk of the net-specific initialization code, including
the parser, into virtio-net itself.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c| 122 +++--
 tools/kvm/include/kvm/virtio-net.h |   6 +-
 tools/kvm/virtio/net.c | 134 +++--
 3 files changed, 144 insertions(+), 118 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 9a09376..7c6fe80 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -146,97 +146,6 @@ static int virtio_9p_rootdir_parser(const struct option 
*opt, const char *arg, i
return 0;
 }
 
-static inline void str_to_mac(const char *str, char *mac)
-{
-   sscanf(str, %hhx:%hhx:%hhx:%hhx:%hhx:%hhx,
-   mac, mac+1, mac+2, mac+3, mac+4, mac+5);
-}
-static int set_net_param(struct virtio_net_params *p, const char *param,
-   const char *val)
-{
-   if (strcmp(param, guest_mac) == 0) {
-   str_to_mac(val, p-guest_mac);
-   } else if (strcmp(param, mode) == 0) {
-   if (!strncmp(val, user, 4)) {
-   int i;
-
-   for (i = 0; i  kvm-cfg.num_net_devices; i++)
-   if (kvm-cfg.net_params[i].mode == 
NET_MODE_USER)
-   die(Only one usermode network device 
allowed at a time);
-   p-mode = NET_MODE_USER;
-   } else if (!strncmp(val, tap, 3)) {
-   p-mode = NET_MODE_TAP;
-   } else if (!strncmp(val, none, 4)) {
-   kvm-cfg.no_net = 1;
-   return -1;
-   } else
-   die(Unknown network mode %s, please use user, tap or 
none, kvm-cfg.network);
-   } else if (strcmp(param, script) == 0) {
-   p-script = strdup(val);
-   } else if (strcmp(param, guest_ip) == 0) {
-   p-guest_ip = strdup(val);
-   } else if (strcmp(param, host_ip) == 0) {
-   p-host_ip = strdup(val);
-   } else if (strcmp(param, trans) == 0) {
-   p-trans = strdup(val);
-   } else if (strcmp(param, vhost) == 0) {
-   p-vhost = atoi(val);
-   } else if (strcmp(param, fd) == 0) {
-   p-fd = atoi(val);
-   } else
-   die(Unknown network parameter %s, param);
-
-   return 0;
-}
-
-static int netdev_parser(const struct option *opt, const char *arg, int unset)
-{
-   struct virtio_net_params p;
-   char *buf = NULL, *cmd = NULL, *cur = NULL;
-   bool on_cmd = true;
-
-   if (arg) {
-   buf = strdup(arg);
-   if (buf == NULL)
-   die(Failed allocating new net buffer);
-   cur = strtok(buf, ,=);
-   }
-
-   p = (struct virtio_net_params) {
-   .guest_ip   = DEFAULT_GUEST_ADDR,
-   .host_ip= DEFAULT_HOST_ADDR,
-   .script = DEFAULT_SCRIPT,
-   .mode   = NET_MODE_TAP,
-   };
-
-   str_to_mac(DEFAULT_GUEST_MAC, p.guest_mac);
-   p.guest_mac[5] += kvm-cfg.num_net_devices;
-
-   while (cur) {
-   if (on_cmd) {
-   cmd = cur;
-   } else {
-   if (set_net_param(p, cmd, cur)  0)
-   goto done;
-   }
-   on_cmd = !on_cmd;
-
-   cur = strtok(NULL, ,=);
-   };
-
-   kvm-cfg.num_net_devices++;
-
-   kvm-cfg.net_params = realloc(kvm-cfg.net_params, 
kvm-cfg.num_net_devices * sizeof(*kvm-cfg.net_params));
-   if (kvm-cfg.net_params == NULL)
-   die(Failed adding new network device);
-
-   kvm-cfg.net_params[kvm-cfg.num_net_devices - 1] = p;
-
-done:
-   free(buf);
-   return 0;
-}
-
 #define BUILD_OPTIONS(name, cfg, kvm)  \
struct option name[] = {\
OPT_GROUP(Basic options:),\
@@ -287,7 +196,7 @@ done:
OPT_GROUP(Networking options:),   \
OPT_CALLBACK_DEFAULT('n', network, NULL, network params,\
 Create a new guest NIC,  \
-netdev_parser, NULL, NULL),\
+netdev_parser, NULL, kvm), \
OPT_BOOLEAN('\0', no-dhcp, (cfg)-no_dhcp, Disable kernel DHCP\
in rootfs mode),   \
\
@@ -739,7 +648,7 @@ static int kvm_cmd_run_init(int argc, const char **argv)
static char 

[PATCH 22/33] kvm tools: kvm-ipc cleanup

2012-09-05 Thread Sasha Levin
Move all the kvm-ipc specific code into the relevant file, and modify
the ipc callback to pass a ptr to struct kvm as well.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c | 122 
 tools/kvm/include/kvm/kvm-ipc.h |   8 +-
 tools/kvm/kvm-ipc.c | 299 +---
 tools/kvm/kvm.c | 147 
 tools/kvm/virtio/balloon.c  |   4 +-
 5 files changed, 289 insertions(+), 291 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 7c6fe80..ac03b75 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -218,127 +218,11 @@ static int virtio_9p_rootdir_parser(const struct option 
*opt, const char *arg, i
OPT_END()   \
};
 
-/*
- * Serialize debug printout so that the output of multiple vcpus does not
- * get mixed up:
- */
-static int printout_done;
-
-static void handle_sigusr1(int sig)
-{
-   struct kvm_cpu *cpu = current_kvm_cpu;
-   int fd = kvm_cpu__get_debug_fd();
-
-   if (!cpu || cpu-needs_nmi)
-   return;
-
-   dprintf(fd, \n #\n # vCPU #%ld's dump:\n #\n, cpu-cpu_id);
-   kvm_cpu__show_registers(cpu);
-   kvm_cpu__show_code(cpu);
-   kvm_cpu__show_page_tables(cpu);
-   fflush(stdout);
-   printout_done = 1;
-   mb();
-}
-
-/* Pause/resume the guest using SIGUSR2 */
-static int is_paused;
-
-static void handle_pause(int fd, u32 type, u32 len, u8 *msg)
-{
-   if (WARN_ON(len))
-   return;
-
-   if (type == KVM_IPC_RESUME  is_paused) {
-   kvm-vm_state = KVM_VMSTATE_RUNNING;
-   kvm__continue();
-   } else if (type == KVM_IPC_PAUSE  !is_paused) {
-   kvm-vm_state = KVM_VMSTATE_PAUSED;
-   ioctl(kvm-vm_fd, KVM_KVMCLOCK_CTRL);
-   kvm__pause();
-   } else {
-   return;
-   }
-
-   is_paused = !is_paused;
-}
-
-static void handle_vmstate(int fd, u32 type, u32 len, u8 *msg)
-{
-   int r = 0;
-
-   if (type == KVM_IPC_VMSTATE)
-   r = write(fd, kvm-vm_state, sizeof(kvm-vm_state));
-
-   if (r  0)
-   pr_warning(Failed sending VMSTATE);
-}
-
-static void handle_debug(int fd, u32 type, u32 len, u8 *msg)
-{
-   int i;
-   struct debug_cmd_params *params;
-   u32 dbg_type;
-   u32 vcpu;
-
-   if (WARN_ON(type != KVM_IPC_DEBUG || len != sizeof(*params)))
-   return;
-
-   params = (void *)msg;
-   dbg_type = params-dbg_type;
-   vcpu = params-cpu;
-
-   if (dbg_type  KVM_DEBUG_CMD_TYPE_SYSRQ)
-   serial8250__inject_sysrq(kvm, params-sysrq);
-
-   if (dbg_type  KVM_DEBUG_CMD_TYPE_NMI) {
-   if ((int)vcpu = kvm-nrcpus)
-   return;
-
-   kvm-cpus[vcpu]-needs_nmi = 1;
-   pthread_kill(kvm-cpus[vcpu]-thread, SIGUSR1);
-   }
-
-   if (!(dbg_type  KVM_DEBUG_CMD_TYPE_DUMP))
-   return;
-
-   for (i = 0; i  kvm-nrcpus; i++) {
-   struct kvm_cpu *cpu = kvm-cpus[i];
-
-   if (!cpu)
-   continue;
-
-   printout_done = 0;
-
-   kvm_cpu__set_debug_fd(fd);
-   pthread_kill(cpu-thread, SIGUSR1);
-   /*
-* Wait for the vCPU to dump state before signalling
-* the next thread. Since this is debug code it does
-* not matter that we are burning CPU time a bit:
-*/
-   while (!printout_done)
-   mb();
-   }
-
-   close(fd);
-
-   serial8250__inject_sysrq(kvm, 'p');
-}
-
 static void handle_sigalrm(int sig)
 {
kvm__arch_periodic_poll(kvm);
 }
 
-static void handle_stop(int fd, u32 type, u32 len, u8 *msg)
-{
-   if (WARN_ON(type != KVM_IPC_STOP || len))
-   return;
-
-   kvm_cpu__reboot(kvm);
-}
-
 static void *kvm_cpu_thread(void *arg)
 {
current_kvm_cpu = arg;
@@ -655,12 +539,6 @@ static int kvm_cmd_run_init(int argc, const char **argv)
return PTR_ERR(kvm);
 
signal(SIGALRM, handle_sigalrm);
-   kvm_ipc__register_handler(KVM_IPC_DEBUG, handle_debug);
-   signal(SIGUSR1, handle_sigusr1);
-   kvm_ipc__register_handler(KVM_IPC_PAUSE, handle_pause);
-   kvm_ipc__register_handler(KVM_IPC_RESUME, handle_pause);
-   kvm_ipc__register_handler(KVM_IPC_STOP, handle_stop);
-   kvm_ipc__register_handler(KVM_IPC_VMSTATE, handle_vmstate);
 
nr_online_cpus = sysconf(_SC_NPROCESSORS_ONLN);
kvm-cfg.custom_rootfs_name = default;
diff --git a/tools/kvm/include/kvm/kvm-ipc.h b/tools/kvm/include/kvm/kvm-ipc.h
index aefffa4..ba7628c 100644
--- a/tools/kvm/include/kvm/kvm-ipc.h
+++ b/tools/kvm/include/kvm/kvm-ipc.h
@@ -2,6 +2,7 @@
 #define KVM__IPC_H_
 
 #include linux/types.h
+#include 

[PATCH 25/33] kvm tools: kernel load/firmware cleanup

2012-09-05 Thread Sasha Levin
Sort out the config initialization order so that configuration is fully 
initialized
before init functions start running, and move the firmware initialization code 
into
kvm.c.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c| 122 -
 tools/kvm/include/kvm/kvm-config.h |   1 +
 tools/kvm/kvm.c|  15 +
 3 files changed, 70 insertions(+), 68 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index c59f100..ba1cf41 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -594,6 +594,7 @@ static int kvm_cmd_run_init(int argc, const char **argv)
}
 
kvm-cfg.vmlinux_filename = find_vmlinux();
+   kvm-vmlinux = kvm-cfg.vmlinux_filename;
 
if (kvm-cfg.nrcpus == 0)
kvm-cfg.nrcpus = nr_online_cpus;
@@ -642,11 +643,14 @@ static int kvm_cmd_run_init(int argc, const char **argv)
if (!kvm-cfg.vnc  !kvm-cfg.sdl)
kvm-cfg.vidmode = -1;
 
-   r = term_init(kvm);
-   if (r  0) {
-   pr_err(term_init() failed with error %d\n, r);
-   goto fail;
-   }
+   memset(real_cmdline, 0, sizeof(real_cmdline));
+   kvm__arch_set_cmdline(real_cmdline, kvm-cfg.vnc || kvm-cfg.sdl);
+
+   if (strlen(real_cmdline)  0)
+   strcat(real_cmdline,  );
+
+   if (kvm-cfg.kernel_cmdline)
+   strlcat(real_cmdline, kvm-cfg.kernel_cmdline, 
sizeof(real_cmdline));
 
if (!kvm-cfg.guest_name) {
if (kvm-cfg.custom_rootfs) {
@@ -657,10 +661,52 @@ static int kvm_cmd_run_init(int argc, const char **argv)
}
}
 
+   if (!kvm-cfg.using_rootfs  !kvm-cfg.disk_image[0].filename  
!kvm-cfg.initrd_filename) {
+   char tmp[PATH_MAX];
+
+   kvm_setup_create_new(kvm-cfg.custom_rootfs_name);
+   kvm_setup_resolv(kvm-cfg.custom_rootfs_name);
+
+   snprintf(tmp, PATH_MAX, %s%s, kvm__get_dir(), default);
+   if (virtio_9p__register(kvm, tmp, /dev/root)  0)
+   die(Unable to initialize virtio 9p);
+   if (virtio_9p__register(kvm, /, hostfs)  0)
+   die(Unable to initialize virtio 9p);
+   kvm-cfg.using_rootfs = kvm-cfg.custom_rootfs = 1;
+   }
+
+   if (kvm-cfg.using_rootfs) {
+   strcat(real_cmdline,  root=/dev/root rw 
rootflags=rw,trans=virtio,version=9p2000.L rootfstype=9p);
+   if (kvm-cfg.custom_rootfs) {
+   kvm_run_set_sandbox();
+
+   strcat(real_cmdline,  init=/virt/init);
+
+   if (!kvm-cfg.no_dhcp)
+   strcat(real_cmdline,   ip=dhcp);
+   if (kvm_setup_guest_init())
+   die(Failed to setup init for guest.);
+   }
+   } else if (!strstr(real_cmdline, root=)) {
+   strlcat(real_cmdline,  root=/dev/vda rw , 
sizeof(real_cmdline));
+   }
+
+   kvm-cfg.real_cmdline = real_cmdline;
+
+   printf(  # %s run -k %s -m %Lu -c %d --name %s\n, KVM_BINARY_NAME,
+   kvm-cfg.kernel_filename, kvm-cfg.ram_size / 1024 / 1024, 
kvm-cfg.nrcpus, kvm-cfg.guest_name);
+
r = kvm__init(kvm);
if (r)
goto fail;
 
+   r = term_init(kvm);
+   if (r  0) {
+   pr_err(term_init() failed with error %d\n, r);
+   goto fail;
+   }
+
+
r = ioeventfd__init(kvm);
if (r  0) {
pr_err(ioeventfd__init() failed with error %d\n, r);
@@ -691,64 +737,15 @@ static int kvm_cmd_run_init(int argc, const char **argv)
goto fail;
}
 
-   memset(real_cmdline, 0, sizeof(real_cmdline));
-   kvm__arch_set_cmdline(real_cmdline, kvm-cfg.vnc || kvm-cfg.sdl);
-
-   if (strlen(real_cmdline)  0)
-   strcat(real_cmdline,  );
-
-   if (kvm-cfg.kernel_cmdline)
-   strlcat(real_cmdline, kvm-cfg.kernel_cmdline, 
sizeof(real_cmdline));
-
-   if (!kvm-cfg.using_rootfs  !kvm-cfg.disk_image[0].filename  
!kvm-cfg.initrd_filename) {
-   char tmp[PATH_MAX];
-
-   kvm_setup_create_new(kvm-cfg.custom_rootfs_name);
-   kvm_setup_resolv(kvm-cfg.custom_rootfs_name);
-
-   snprintf(tmp, PATH_MAX, %s%s, kvm__get_dir(), default);
-   if (virtio_9p__register(kvm, tmp, /dev/root)  0)
-   die(Unable to initialize virtio 9p);
-   if (virtio_9p__register(kvm, /, hostfs)  0)
-   die(Unable to initialize virtio 9p);
-   kvm-cfg.using_rootfs = kvm-cfg.custom_rootfs = 1;
-   }
-
-   if (kvm-cfg.using_rootfs) {
-   strcat(real_cmdline,  root=/dev/root rw 
rootflags=rw,trans=virtio,version=9p2000.L rootfstype=9p);
-   if (kvm-cfg.custom_rootfs) {
-  

[PATCH 27/33] kvm tools: ram init

2012-09-05 Thread Sasha Levin
RAM should be initialized as part of kvm__init, and not somewhere random in the 
global
init code.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c | 2 --
 tools/kvm/kvm.c | 2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 66bba44..f54a6c1 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -800,8 +800,6 @@ static int kvm_cmd_run_init(int argc, const char **argv)
goto fail;
}
 
-   kvm__init_ram(kvm);
-
r = kbd__init(kvm);
if (r  0) {
pr_err(kbd__init() failed with error %d\n, r);
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 7a6e15e..cca2e93 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -246,6 +246,8 @@ int kvm__init(struct kvm *kvm)
 
kvm__arch_init(kvm, kvm-cfg.hugetlbfs_path, kvm-cfg.ram_size);
 
+   kvm__init_ram(kvm);
+
if (!kvm-cfg.firmware_filename) {
if (!kvm__load_kernel(kvm, kvm-cfg.kernel_filename,
kvm-cfg.initrd_filename, 
kvm-cfg.real_cmdline, kvm-cfg.vidmode))
-- 
1.7.12

--
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 28/33] kvm tools: move the rest of the config initializations

2012-09-05 Thread Sasha Levin
These should appear before running any init calls.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index f54a6c1..6e6fbf5 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -643,6 +643,9 @@ static int kvm_cmd_run_init(int argc, const char **argv)
if (!kvm-cfg.vnc  !kvm-cfg.sdl)
kvm-cfg.vidmode = -1;
 
+   if (!kvm-cfg.network)
+kvm-cfg.network = DEFAULT_NETWORK;
+
memset(real_cmdline, 0, sizeof(real_cmdline));
kvm__arch_set_cmdline(real_cmdline, kvm-cfg.vnc || kvm-cfg.sdl);
 
@@ -789,9 +792,6 @@ static int kvm_cmd_run_init(int argc, const char **argv)
goto fail;
}
 
-   if (!kvm-cfg.network)
-   kvm-cfg.network = DEFAULT_NETWORK;
-
virtio_9p__init(kvm);
 
r = virtio_net__init(kvm);
-- 
1.7.12

--
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 29/33] kvm tools: virtio-9p cleanup

2012-09-05 Thread Sasha Levin
Sort out init/exit calls, move parser into the 9p code and make sure
rootfs config is initialized before virtio-9p (or any other init func)
is called.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c   | 67 ++
 tools/kvm/include/kvm/virtio-9p.h |  3 ++
 tools/kvm/virtio/9p.c | 68 +++
 3 files changed, 80 insertions(+), 58 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 6e6fbf5..183aa42 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -77,42 +77,12 @@ static int img_name_parser(const struct option *opt, const 
char *arg, int unset)
 {
char path[PATH_MAX];
struct stat st;
-   struct kvm *kvm = opt-ptr;
-
-   if (stat(arg, st) == 0 
-   S_ISDIR(st.st_mode)) {
-   char tmp[PATH_MAX];
-
-   if (kvm-cfg.using_rootfs)
-   die(Please use only one rootfs directory atmost);
-
-   if (realpath(arg, tmp) == 0 ||
-   virtio_9p__register(kvm, tmp, /dev/root)  0)
-   die(Unable to initialize virtio 9p);
-   kvm-cfg.using_rootfs = 1;
-   return 0;
-   }
 
snprintf(path, PATH_MAX, %s%s, kvm__get_dir(), arg);
 
-   if (stat(path, st) == 0 
-   S_ISDIR(st.st_mode)) {
-   char tmp[PATH_MAX];
-
-   if (kvm-cfg.using_rootfs)
-   die(Please use only one rootfs directory atmost);
-
-   if (realpath(path, tmp) == 0 ||
-   virtio_9p__register(kvm, tmp, /dev/root)  0)
-   die(Unable to initialize virtio 9p);
-   if (virtio_9p__register(kvm, /, hostfs)  0)
-   die(Unable to initialize virtio 9p);
-   kvm_setup_resolv(arg);
-   kvm-cfg.using_rootfs = kvm-cfg.custom_rootfs = 1;
-   kvm-cfg.custom_rootfs_name = arg;
-   return 0;
-   }
-
+   if ((stat(arg, st) == 0  S_ISDIR(st.st_mode)) ||
+  (stat(path, st) == 0  S_ISDIR(st.st_mode)))
+   return virtio_9p_img_name_parser(opt, arg, unset);
return disk_img_name_parser(opt, arg, unset);
 }
 
@@ -121,29 +91,6 @@ void kvm_run_set_wrapper_sandbox(void)
kvm_run_wrapper = KVM_RUN_SANDBOX;
 }
 
-static int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, 
int unset)
-{
-   char *tag_name;
-   char tmp[PATH_MAX];
-
-   /*
-* 9p dir can be of the form dirname,tag_name or
-* just dirname. In the later case we use the
-* default tag name
-*/
-   tag_name = strstr(arg, ,);
-   if (tag_name) {
-   *tag_name = '\0';
-   tag_name++;
-   }
-   if (realpath(arg, tmp)) {
-   if (virtio_9p__register(kvm, tmp, tag_name)  0)
-   die(Unable to initialize virtio 9p);
-   } else
-   die(Failed resolving 9p path);
-   return 0;
-}
-
 #define BUILD_OPTIONS(name, cfg, kvm)  \
struct option name[] = {\
OPT_GROUP(Basic options:),\
@@ -167,7 +114,7 @@ static int virtio_9p_rootdir_parser(const struct option 
*opt, const char *arg, i
Number Generator), \
OPT_CALLBACK('\0', 9p, NULL, dir_to_share,tag_name, \
 Enable virtio 9p to share files between host and  \
-guest, virtio_9p_rootdir_parser, NULL),   \
+guest, virtio_9p_rootdir_parser, kvm),\
OPT_STRING('\0', console, (cfg)-console, serial, virtio or \
hv, Console to use), \
OPT_STRING('\0', dev, (cfg)-dev, device_file, \
@@ -792,7 +739,11 @@ static int kvm_cmd_run_init(int argc, const char **argv)
goto fail;
}
 
-   virtio_9p__init(kvm);
+   r = virtio_9p__init(kvm);
+   if (r  0) {
+   pr_err(virtio_9p__init() failed with error %d\n, r);
+   goto fail;
+   }
 
r = virtio_net__init(kvm);
if (r  0) {
diff --git a/tools/kvm/include/kvm/virtio-9p.h 
b/tools/kvm/include/kvm/virtio-9p.h
index cb590d1..19ffe50 100644
--- a/tools/kvm/include/kvm/virtio-9p.h
+++ b/tools/kvm/include/kvm/virtio-9p.h
@@ -3,6 +3,7 @@
 #include kvm/virtio.h
 #include kvm/pci.h
 #include kvm/threadpool.h
+#include kvm/parse-options.h
 
 #include sys/types.h
 #include dirent.h
@@ -65,6 +66,8 @@ struct p9_pdu {
 
 struct kvm;
 
+int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, int 
unset);
+int virtio_9p_img_name_parser(const struct option *opt, const char *arg, int 
unset);
 int virtio_9p__register(struct kvm *kvm, const char *root, const char 

[PATCH 26/33] kvm tools: ioport arch init

2012-09-05 Thread Sasha Levin
Move ioport arch init into ioport init, which is the logical place for that 
instead of a
random place in the global init code.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c | 2 --
 tools/kvm/ioport.c  | 2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index ba1cf41..66bba44 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -747,8 +747,6 @@ static int kvm_cmd_run_init(int argc, const char **argv)
if (r  0)
pr_debug(symbol_init() failed with error %d\n, r);
 
-   ioport__setup_arch();
-
r = rtc__init(kvm);
if (r  0) {
pr_err(rtc__init() failed with error %d\n, r);
diff --git a/tools/kvm/ioport.c b/tools/kvm/ioport.c
index 2208c15..f5fb246 100644
--- a/tools/kvm/ioport.c
+++ b/tools/kvm/ioport.c
@@ -184,6 +184,8 @@ error:
 
 int ioport__init(struct kvm *kvm)
 {
+   ioport__setup_arch();
+
return 0;
 }
 
-- 
1.7.12

--
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 31/33] kvm tools: use init/exit where possible

2012-09-05 Thread Sasha Levin
Switch to using init/exit calls instead of the repeating call blocks in 
builtin-run.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/Makefile  |   1 +
 tools/kvm/builtin-run.c | 246 +---
 tools/kvm/disk/core.c   |   2 +
 tools/kvm/framebuffer.c |   3 +
 tools/kvm/hw/i8042.c|   1 +
 tools/kvm/hw/pci-shmem.c|   2 +
 tools/kvm/hw/rtc.c  |   2 +
 tools/kvm/hw/serial.c   |   2 +
 tools/kvm/include/kvm/kvm.h |   2 +
 tools/kvm/ioeventfd.c   |   2 +
 tools/kvm/ioport.c  |   2 +
 tools/kvm/kvm-cpu.c |   2 +
 tools/kvm/kvm-ipc.c |   2 +
 tools/kvm/kvm.c |   4 +
 tools/kvm/pci.c |   2 +
 tools/kvm/symbol.c  |   4 +-
 tools/kvm/term.c|   2 +
 tools/kvm/ui/sdl.c  |   7 +-
 tools/kvm/ui/vnc.c  |   7 +-
 tools/kvm/util/threadpool.c |   3 +
 tools/kvm/virtio/9p.c   |   1 +
 tools/kvm/virtio/balloon.c  |   2 +
 tools/kvm/virtio/blk.c  |   2 +
 tools/kvm/virtio/console.c  |   2 +
 tools/kvm/virtio/net.c  |   2 +
 tools/kvm/virtio/rng.c  |   2 +
 tools/kvm/virtio/scsi.c |   2 +
 tools/kvm/x86/irq.c |   2 +
 28 files changed, 66 insertions(+), 247 deletions(-)

diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index efa3d4f..862e76b 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -84,6 +84,7 @@ OBJS  += net/uip/buf.o
 OBJS   += net/uip/csum.o
 OBJS   += net/uip/dhcp.o
 OBJS   += kvm-cmd.o
+OBJS   += util/init.o
 OBJS   += util/rbtree.o
 OBJS   += util/threadpool.o
 OBJS   += util/parse-options.o
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 183aa42..bca9122 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -476,7 +476,6 @@ static int kvm_cmd_run_init(int argc, const char **argv)
 {
static char real_cmdline[2048], default_name[20];
unsigned int nr_online_cpus;
-   int r;
 
kvm = kvm__new();
if (IS_ERR(kvm))
@@ -646,160 +645,7 @@ static int kvm_cmd_run_init(int argc, const char **argv)
printf(  # %s run -k %s -m %Lu -c %d --name %s\n, KVM_BINARY_NAME,
kvm-cfg.kernel_filename, kvm-cfg.ram_size / 1024 / 1024, 
kvm-cfg.nrcpus, kvm-cfg.guest_name);
 
-   r = kvm__init(kvm);
-   if (r)
-   goto fail;
-
-   r = term_init(kvm);
-   if (r  0) {
-   pr_err(term_init() failed with error %d\n, r);
-   goto fail;
-   }
-
-
-   r = ioeventfd__init(kvm);
-   if (r  0) {
-   pr_err(ioeventfd__init() failed with error %d\n, r);
-   goto fail;
-   }
-
-   r = kvm_cpu__init(kvm);
-   if (r  0) {
-   pr_err(kvm_cpu__init() failed with error %d\n, r);
-   goto fail;
-   }
-   
-   r = irq__init(kvm);
-   if (r  0) {
-   pr_err(irq__init() failed with error %d\n, r);
-   goto fail;
-   }
-
-   r = pci__init(kvm);
-   if (r  0) {
-   pr_err(pci__init() failed with error %d\n, r);
-   goto fail;
-   }
-
-   r = ioport__init(kvm);
-   if (r  0) {
-   pr_err(ioport__init() failed with error %d\n, r);
-   goto fail;
-   }
-
-   r = disk_image__init(kvm);
-   if (r  0) {
-   pr_err(disk_image__init() failed with error %d\n, r);
-   goto fail;
-   }
-
-   r = symbol_init(kvm);
-   if (r  0)
-   pr_debug(symbol_init() failed with error %d\n, r);
-
-   r = rtc__init(kvm);
-   if (r  0) {
-   pr_err(rtc__init() failed with error %d\n, r);
-   goto fail;
-   }
-
-   r = serial8250__init(kvm);
-   if (r  0) {
-   pr_err(serial__init() failed with error %d\n, r);
-   goto fail;
-   }
-
-   r = virtio_blk__init(kvm);
-   if (r  0) {
-   pr_err(virtio_blk__init() failed with error %d\n, r);
-   goto fail;
-   }
-
-   r = virtio_scsi_init(kvm);
-   if (r  0) {
-   pr_err(virtio_scsi_init() failed with error %d\n, r);
-   goto fail;
-   }
-
-   r = virtio_console__init(kvm);
-   if (r  0) {
-   pr_err(virtio_console__init() failed with error %d\n, r);
-   goto fail;
-   }
-
-   r = virtio_rng__init(kvm);
-   if (r  0) {
-   pr_err(virtio_rng__init() failed with error %d\n, r);
-   goto fail;
-   }
-
-   r = virtio_bln__init(kvm);
-   if (r  0) {
-   pr_err(virtio_rng__init() failed with error %d\n, r);
-   goto fail;
-   }
-
-   r = virtio_9p__init(kvm);
-   if (r  0) {
-   pr_err(virtio_9p__init() failed with error %d\n, r);
-   goto fail;
-   }
-
-   r = virtio_net__init(kvm);
-   if (r  0) {
-   pr_err(virtio_net__init() failed with 

[PATCH 24/33] kvm tools: ui improvements

2012-09-05 Thread Sasha Levin
Move the vesa initialization logic into sdl__init() and vnc__init(), builtin-run
shouldn't have to know about the conditions for initializing vesa on it's own.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c| 49 ++
 tools/kvm/hw/vesa.c|  3 +++
 tools/kvm/include/kvm/kvm-config.h |  1 +
 tools/kvm/include/kvm/sdl.h|  8 +++
 tools/kvm/include/kvm/vnc.h| 10 
 tools/kvm/ui/sdl.c | 19 ---
 tools/kvm/ui/vnc.c | 21 
 7 files changed, 60 insertions(+), 51 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 96a3d70..c59f100 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -60,8 +60,6 @@ static int  kvm_run_wrapper;
 
 bool do_debug_print = false;
 
-static int vidmode = -1;
-
 extern char _binary_guest_init_start;
 extern char _binary_guest_init_size;
 
@@ -201,7 +199,7 @@ static int virtio_9p_rootdir_parser(const struct option 
*opt, const char *arg, i
in rootfs mode),   \
\
OPT_GROUP(BIOS options:), \
-   OPT_INTEGER('\0', vidmode, vidmode,  \
+   OPT_INTEGER('\0', vidmode, (cfg)-vidmode,   \
Video mode),  \
\
OPT_GROUP(Debug options:),\
@@ -530,7 +528,6 @@ static void kvm_run_write_sandbox_cmd(const char **argv, 
int argc)
 static int kvm_cmd_run_init(int argc, const char **argv)
 {
static char real_cmdline[2048], default_name[20];
-   struct framebuffer *fb = NULL;
unsigned int nr_online_cpus;
int r;
 
@@ -642,6 +639,9 @@ static int kvm_cmd_run_init(int argc, const char **argv)
if (!kvm-cfg.script)
kvm-cfg.script = DEFAULT_SCRIPT;
 
+   if (!kvm-cfg.vnc  !kvm-cfg.sdl)
+   kvm-cfg.vidmode = -1;
+
r = term_init(kvm);
if (r  0) {
pr_err(term_init() failed with error %d\n, r);
@@ -691,17 +691,6 @@ static int kvm_cmd_run_init(int argc, const char **argv)
goto fail;
}
 
-   /*
-* vidmode should be either specified
-* either set by default
-*/
-   if (kvm-cfg.vnc || kvm-cfg.sdl) {
-   if (vidmode == -1)
-   vidmode = 0x312;
-   } else {
-   vidmode = 0;
-   }
-
memset(real_cmdline, 0, sizeof(real_cmdline));
kvm__arch_set_cmdline(real_cmdline, kvm-cfg.vnc || kvm-cfg.sdl);
 
@@ -752,7 +741,7 @@ static int kvm_cmd_run_init(int argc, const char **argv)
 
if (!kvm-cfg.firmware_filename) {
if (!kvm__load_kernel(kvm, kvm-cfg.kernel_filename,
-   kvm-cfg.initrd_filename, real_cmdline, 
vidmode))
+   kvm-cfg.initrd_filename, real_cmdline, 
kvm-cfg.vidmode))
die(unable to load kernel %s, 
kvm-cfg.kernel_filename);
 
kvm-vmlinux = kvm-cfg.vmlinux_filename;
@@ -830,28 +819,16 @@ static int kvm_cmd_run_init(int argc, const char **argv)
goto fail;
}
 
-   if (kvm-cfg.vnc || kvm-cfg.sdl) {
-   fb = vesa__init(kvm);
-   if (IS_ERR(fb)) {
-   pr_err(vesa__init() failed with error %ld\n, 
PTR_ERR(fb));
-   goto fail;
-   }
-   }
-
-   if (kvm-cfg.vnc  fb) {
-   r = vnc__init(fb);
-   if (r  0) {
-   pr_err(vnc__init() failed with error %d\n, r);
-   goto fail;
-   }
+   r = vnc__init(kvm);
+   if (r  0) {
+   pr_err(vnc__init() failed with error %d\n, r);
+   goto fail;
}
 
-   if (kvm-cfg.sdl  fb) {
-   sdl__init(fb);
-   if (r  0) {
-   pr_err(sdl__init() failed with error %d\n, r);
-   goto fail;
-   }
+   r = sdl__init(kvm);
+   if (r  0) {
+   pr_err(sdl__init() failed with error %d\n, r);
+   goto fail;
}
 
r = fb__init(kvm);
diff --git a/tools/kvm/hw/vesa.c b/tools/kvm/hw/vesa.c
index 09512d5..6f2d9f4 100644
--- a/tools/kvm/hw/vesa.c
+++ b/tools/kvm/hw/vesa.c
@@ -53,6 +53,9 @@ struct framebuffer *vesa__init(struct kvm *kvm)
char *mem;
int r;
 
+   if (!kvm-cfg.vnc  !kvm-cfg.sdl)
+   return NULL;
+
r = irq__register_device(PCI_DEVICE_ID_VESA, dev, pin, line);
if (r  0)
return ERR_PTR(r);
diff --git a/tools/kvm/include/kvm/kvm-config.h 

[PATCH 32/33] kvm tools: pass kvm ptr directly to timer injection

2012-09-05 Thread Sasha Levin
This will help us get rid of the global kvm object.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c | 10 --
 tools/kvm/kvm.c |  1 +
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index bca9122..0ad49c1 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -163,8 +163,10 @@ void kvm_run_set_wrapper_sandbox(void)
OPT_END()   \
};
 
-static void handle_sigalrm(int sig)
+static void handle_sigalrm(int sig, siginfo_t *si, void *uc)
 {
+   struct kvm *kvm = uc;
+
kvm__arch_periodic_poll(kvm);
 }
 
@@ -476,12 +478,16 @@ static int kvm_cmd_run_init(int argc, const char **argv)
 {
static char real_cmdline[2048], default_name[20];
unsigned int nr_online_cpus;
+   struct sigaction sa;
 
kvm = kvm__new();
if (IS_ERR(kvm))
return PTR_ERR(kvm);
 
-   signal(SIGALRM, handle_sigalrm);
+   sa.sa_flags = SA_SIGINFO;
+   sa.sa_sigaction = handle_sigalrm;
+   sigemptyset(sa.sa_mask);
+   sigaction(SIGALRM, sa, NULL);
 
nr_online_cpus = sysconf(_SC_NPROCESSORS_ONLN);
kvm-cfg.custom_rootfs_name = default;
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 20322a3..d107931 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -358,6 +358,7 @@ int kvm_timer__init(struct kvm *kvm)
sev.sigev_value.sival_int   = 0;
sev.sigev_notify= SIGEV_THREAD_ID;
sev.sigev_signo = SIGALRM;
+   sev.sigev_value.sival_ptr   = kvm;
sev._sigev_un._tid  = syscall(__NR_gettid);
 
r = timer_create(CLOCK_REALTIME, sev, kvm-timerid);
-- 
1.7.12

--
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 33/33] kvm tools: remove global kvm object

2012-09-05 Thread Sasha Levin
This was ugly, and now we get rid of it.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c| 48 +++---
 tools/kvm/hw/i8042.c   |  4 ++--
 tools/kvm/hw/pci-shmem.c   |  2 +-
 tools/kvm/hw/rtc.c | 10 -
 tools/kvm/hw/serial.c  |  8 +++
 tools/kvm/hw/vesa.c|  2 +-
 tools/kvm/include/kvm/brlock.h | 16 +++---
 tools/kvm/include/kvm/ioport.h |  7 +++---
 tools/kvm/include/kvm/kvm.h|  4 ++--
 tools/kvm/include/kvm/term.h   |  4 ++--
 tools/kvm/ioport.c | 16 +++---
 tools/kvm/kvm-cpu.c|  2 +-
 tools/kvm/kvm-ipc.c|  4 ++--
 tools/kvm/kvm.c|  6 ++
 tools/kvm/mmio.c   | 10 -
 tools/kvm/pci.c| 10 -
 tools/kvm/term.c   |  7 +++---
 tools/kvm/virtio/balloon.c |  5 ++---
 tools/kvm/virtio/console.c |  2 +-
 tools/kvm/virtio/net.c | 12 +--
 tools/kvm/virtio/pci.c |  6 +++---
 tools/kvm/x86/ioport.c | 20 +-
 22 files changed, 102 insertions(+), 103 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 0ad49c1..85b9238 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -53,7 +53,6 @@
 #define KB_SHIFT   (10)
 #define GB_SHIFT   (30)
 
-struct kvm *kvm;
 __thread struct kvm_cpu *current_kvm_cpu;
 
 static int  kvm_run_wrapper;
@@ -339,11 +338,13 @@ static const char *find_vmlinux(void)
 
 void kvm_run_help(void)
 {
+   struct kvm *kvm = NULL;
+
BUILD_OPTIONS(options, kvm-cfg, kvm);
usage_with_options(run_usage, options);
 }
 
-static int kvm_setup_guest_init(void)
+static int kvm_setup_guest_init(struct kvm *kvm)
 {
const char *rootfs = kvm-cfg.custom_rootfs_name;
char tmp[PATH_MAX];
@@ -367,7 +368,7 @@ static int kvm_setup_guest_init(void)
return 0;
 }
 
-static int kvm_run_set_sandbox(void)
+static int kvm_run_set_sandbox(struct kvm *kvm)
 {
const char *guestfs_name = kvm-cfg.custom_rootfs_name;
char path[PATH_MAX], script[PATH_MAX], *tmp;
@@ -439,7 +440,7 @@ static void resolve_program(const char *src, char *dst, 
size_t len)
strncpy(dst, src, len);
 }
 
-static void kvm_run_write_sandbox_cmd(const char **argv, int argc)
+static void kvm_run_write_sandbox_cmd(struct kvm *kvm, const char **argv, int 
argc)
 {
const char script_hdr[] = #! /bin/bash\n\n;
char program[PATH_MAX];
@@ -474,15 +475,15 @@ static void kvm_run_write_sandbox_cmd(const char **argv, 
int argc)
close(fd);
 }
 
-static int kvm_cmd_run_init(int argc, const char **argv)
+static struct kvm *kvm_cmd_run_init(int argc, const char **argv)
 {
static char real_cmdline[2048], default_name[20];
unsigned int nr_online_cpus;
struct sigaction sa;
+   struct kvm *kvm = kvm__new();
 
-   kvm = kvm__new();
if (IS_ERR(kvm))
-   return PTR_ERR(kvm);
+   return kvm;
 
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = handle_sigalrm;
@@ -502,7 +503,7 @@ static int kvm_cmd_run_init(int argc, const char **argv)
if (strcmp(argv[0], --) == 0) {
if (kvm_run_wrapper == KVM_RUN_SANDBOX) {
kvm-cfg.sandbox = 
DEFAULT_SANDBOX_FILENAME;
-   kvm_run_write_sandbox_cmd(argv+1, 
argc-1);
+   kvm_run_write_sandbox_cmd(kvm, argv+1, 
argc-1);
break;
}
}
@@ -513,7 +514,7 @@ static int kvm_cmd_run_init(int argc, const char **argv)
%s\n, argv[0]);
usage_with_options(run_usage, options);
free(kvm);
-   return -EINVAL;
+   return ERR_PTR(-EINVAL);
}
if (kvm_run_wrapper == KVM_RUN_SANDBOX) {
/*
@@ -521,7 +522,7 @@ static int kvm_cmd_run_init(int argc, const char **argv)
 * sandbox command
 */
kvm-cfg.sandbox = DEFAULT_SANDBOX_FILENAME;
-   kvm_run_write_sandbox_cmd(argv, argc);
+   kvm_run_write_sandbox_cmd(kvm, argv, argc);
} else {
/*
 * first unhandled parameter is treated as a 
kernel
@@ -542,7 +543,7 @@ static int kvm_cmd_run_init(int argc, const char **argv)
 
if (!kvm-cfg.kernel_filename) {
kernel_usage_with_options();
-   return -EINVAL;
+   return 

[PATCH 20/33] kvm tools: pci-shmem init-exit

2012-09-05 Thread Sasha Levin
Make the init/exit of pci-shmem self-contained, so the global init code
won't need to check if it was selected or not.

Also move the parser out of builtin-run into the pci-shmem code.

Signed-off-by: Sasha Levin levinsasha...@gmail.com
---
 tools/kvm/builtin-run.c   | 134 +++
 tools/kvm/hw/pci-shmem.c  | 143 --
 tools/kvm/include/kvm/pci-shmem.h |   6 +-
 3 files changed, 153 insertions(+), 130 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index ec61696..9a09376 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -237,130 +237,6 @@ done:
return 0;
 }
 
-static int shmem_parser(const struct option *opt, const char *arg, int unset)
-{
-   const u64 default_size = SHMEM_DEFAULT_SIZE;
-   const u64 default_phys_addr = SHMEM_DEFAULT_ADDR;
-   const char *default_handle = SHMEM_DEFAULT_HANDLE;
-   struct shmem_info *si = malloc(sizeof(struct shmem_info));
-   u64 phys_addr;
-   u64 size;
-   char *handle = NULL;
-   int create = 0;
-   const char *p = arg;
-   char *next;
-   int base = 10;
-   int verbose = 0;
-
-   const int skip_pci = strlen(pci:);
-   if (verbose)
-   pr_info(shmem_parser(%p,%s,%d), opt, arg, unset);
-   /* parse out optional addr family */
-   if (strcasestr(p, pci:)) {
-   p += skip_pci;
-   } else if (strcasestr(p, mem:)) {
-   die(I can't add to E820 map yet.\n);
-   }
-   /* parse out physical addr */
-   base = 10;
-   if (strcasestr(p, 0x))
-   base = 16;
-   phys_addr = strtoll(p, next, base);
-   if (next == p  phys_addr == 0) {
-   pr_info(shmem: no physical addr specified, using default.);
-   phys_addr = default_phys_addr;
-   }
-   if (*next != ':'  *next != '\0')
-   die(shmem: unexpected chars after phys addr.\n);
-   if (*next == '\0')
-   p = next;
-   else
-   p = next + 1;
-   /* parse out size */
-   base = 10;
-   if (strcasestr(p, 0x))
-   base = 16;
-   size = strtoll(p, next, base);
-   if (next == p  size == 0) {
-   pr_info(shmem: no size specified, using default.);
-   size = default_size;
-   }
-   /* look for [KMGkmg][Bb]*  uses base 2. */
-   int skip_B = 0;
-   if (strspn(next, KMGkmg)) {   /* might have a prefix */
-   if (*(next + 1) == 'B' || *(next + 1) == 'b')
-   skip_B = 1;
-   switch (*next) {
-   case 'K':
-   case 'k':
-   size = size  KB_SHIFT;
-   break;
-   case 'M':
-   case 'm':
-   size = size  MB_SHIFT;
-   break;
-   case 'G':
-   case 'g':
-   size = size  GB_SHIFT;
-   break;
-   default:
-   die(shmem: bug in detecting size prefix.);
-   break;
-   }
-   next += 1 + skip_B;
-   }
-   if (*next != ':'  *next != '\0') {
-   die(shmem: unexpected chars after phys size. %c%c\n,
-   *next, *p);
-   }
-   if (*next == '\0')
-   p = next;
-   else
-   p = next + 1;
-   /* parse out optional shmem handle */
-   const int skip_handle = strlen(handle=);
-   next = strcasestr(p, handle=);
-   if (*p  next) {
-   if (p != next)
-   die(unexpected chars before handle\n);
-   p += skip_handle;
-   next = strchrnul(p, ':');
-   if (next - p) {
-   handle = malloc(next - p + 1);
-   strncpy(handle, p, next - p);
-   handle[next - p] = '\0';/* just in case. */
-   }
-   if (*next == '\0')
-   p = next;
-   else
-   p = next + 1;
-   }
-   /* parse optional create flag to see if we should create shm seg. */
-   if (*p  strcasestr(p, create)) {
-   create = 1;
-   p += strlen(create);
-   }
-   if (*p != '\0')
-   die(shmem: unexpected trailing chars\n);
-   if (handle == NULL) {
-   handle = malloc(strlen(default_handle) + 1);
-   strcpy(handle, default_handle);
-   }
-   if (verbose) {
-   pr_info(shmem: phys_addr = %llx, phys_addr);
-   pr_info(shmem: size  = %llx, size);
-   pr_info(shmem: handle= %s, handle);
-   pr_info(shmem: create= %d, create);
-   }
-
-   si-phys_addr = phys_addr;
-   si-size = size;
-   si-handle = handle;
-   si-create = create;
-   

Re: [PATCH v2 2/7] s390/kvm: Add support for machine checks.

2012-09-05 Thread Cornelia Huck
On Wed, 5 Sep 2012 09:22:32 +0200
Heiko Carstens heiko.carst...@de.ibm.com wrote:

 On Tue, Sep 04, 2012 at 05:13:25PM +0200, Cornelia Huck wrote:
 
 Just some quick comments:
 
 [...]
 
   int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code)
   {
  struct kvm_s390_local_interrupt *li = vcpu-arch.local_int;
  @@ -648,6 +747,12 @@ int kvm_s390_inject_vm(struct kvm *kvm,
  case KVM_S390_INT_EMERGENCY:
  kfree(inti);
  return -EINVAL;
  +   case KVM_S390_MCHK:
  +   VM_EVENT(kvm, 5, inject: machine check parm64:%llx,
  +s390int-parm64);
  +   inti-type = s390int-type;
  +   inti-mchk.mcic = s390int-parm64;
  +   break;
 
 The kvm_s390_interrupt struct seems to be inappropriate to pass machine check
 data around.
 E.g. if you want to inject an uncorrectable storage error, because the host
 failed to swap in a page, you must also pass a failing storage address which
 doesn't fit into this structure.
 Just something you should consider. ;)

Sigh, it seems we might want a KVM_S390_INTERRUPT2 taking a larger and
more complex structure later on...

kvm_s390_interrupt should be fine for our current needs, though,
expecially as machine checks are currently only injected in-kernel.

 
  +static int handle_lpswe(struct kvm_vcpu *vcpu)
  +{
  +   int base2 = vcpu-arch.sie_block-ipb  28;
  +   int disp2 = ((vcpu-arch.sie_block-ipb  0x0fff)  16);
 
 Sooner or later we need helper functions which extract the significant parts
 of an instruction.
 Maybay something like insn_[type]_get_base2(...) or simply structures like
 struct insn_[type], which allow to easily access parts of an instruction.

Agree on helper functions, not sure about the use of structures for
that. Let's see how it looks coded up.

 
  +   u64 addr;
  +   u64 new_psw[2];
 
 psw_t?
 
  +
  +   addr = disp2;
  +   if (base2)
  +   addr += vcpu-run-s.regs.gprs[base2];
  +   
  +   if (addr  7) {
  +   kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  +   goto out;
  +   }
  +
  +   if (copy_from_guest(vcpu, new_psw, addr, sizeof(*new_psw))) {
 
 I assume that should be sizeof(new_psw). Did that ever work?!

No, because the code was never hit since the code for ICTL was
incorrect... The guest kernel just does a good job at keeping machine
checks open nearly all of the time :)

 
  +   if ((vcpu-arch.sie_block-gpsw.mask  0xb80800fe7fff) ||
  +   (((vcpu-arch.sie_block-gpsw.mask  0x00011000) ==
  + 0x1000) 
  +(vcpu-arch.sie_block-gpsw.addr  0x8000)) ||
  +   (!(vcpu-arch.sie_block-gpsw.mask  0x00018000) 
  +(vcpu-arch.sie_block-gpsw.addr  0xfff0)) ||
  +   ((vcpu-arch.sie_block-gpsw.mask  0x00011000) ==
  +0x0001)) {
 
 This is not very readable...

It's straight from the PoP's discussion of invalid bits.

 
 Please make use of the PSW defines in ptrace.h and add new ones if needed.
 Also please make use of (move) the PSW32 defines in compat.h.

I'll check these.

--
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: [RFC 0/5] Making KVM_GET_ONE_REG/KVM_SET_ONE_REG generic.

2012-09-05 Thread Peter Maydell
On 5 September 2012 07:48, Rusty Russell ru...@rustcorp.com.au wrote:
 Peter Maydell peter.mayd...@linaro.org writes:

 This is a problem because it means userspace needs to know the
 size of each register, and the kernel doesn't provide any way
 to determine the size. This defeats the idea that userspace should
 be able to migrate kernel register state without having to know
 the semantics of all the registers involved.

 It's there.  There are bits in the id which indicate the size:

 And my patches added a helper:

 #define KVM_REG_SIZE(id)\
 (1U  (((id)  KVM_REG_SIZE_MASK)  KVM_REG_SIZE_SHIFT))

Ah, right, I hadn't realised that was in the exposed-to-userspace
bit of the code.

 I could live with always read/write 64 bits. I definitely don't
 want to have to deal with matching up register widths to accesses
 in userspace, please.

 I changed my mind about the old scheme when I realized we have to deal
 with 128-bit FPU registers.

Mmm, ARM might not have any awkward size registers but there's
x86 weirdisms to consider for a generic ABI I guess.

-- PMM
--
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] kvm tools: Export DISPLAY ENV as our default host ip address

2012-09-05 Thread Asias He
On Wed, Sep 5, 2012 at 4:00 PM, Pekka Enberg penb...@kernel.org wrote:
 On 08/24/2012 02:29 PM, Asias He wrote:
 It is useful to run a X program in guest and display it on host.

 1) Make host's x server listen to localhost:6000
host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
UNIX-CONNECT:/tmp/.X11-unix/X0

 2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
   guest_shell$ xlogo

 On Tue, Sep 4, 2012 at 4:07 PM, Avi Kivity a...@redhat.com wrote:
 Note, this is insecure, don't do this with untrusted guests.

 Asias, can we add a command line argument that enables this? It'd be
 safer to keep it disabled by default.

Step 1) is not started by lkvm, if user does not run the socat cmd in
host side, the remote display for guest will not work at all.

This patch only set  DISPLAY env to host IP.  if user runs the socat
cmd in host side, even if without the exporting DISPLAY env, the
untrusted guest can also do the attack.

-- 
Asias He
--
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] kvm tools: Export DISPLAY ENV as our default host ip address

2012-09-05 Thread Asias He
On Wed, Sep 5, 2012 at 4:09 PM, Ingo Molnar mi...@kernel.org wrote:

 * Pekka Enberg penb...@kernel.org wrote:

 On 08/24/2012 02:29 PM, Asias He wrote:
  It is useful to run a X program in guest and display it on host.
 
  1) Make host's x server listen to localhost:6000
 host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
 UNIX-CONNECT:/tmp/.X11-unix/X0
 
  2) Start the guest and run X program
 host_shell$ lkvm run -k /boot/bzImage
guest_shell$ xlogo

 On Tue, Sep 4, 2012 at 4:07 PM, Avi Kivity a...@redhat.com wrote:
  Note, this is insecure, don't do this with untrusted guests.

 Asias, can we add a command line argument that enables this?
 It'd be safer to keep it disabled by default.

 It might also be prudent to name the option in a way that
 signals that the user of it understands the security
 implications:

 --X11-trusted-guest 1


Yes. If we do something like the socat cmd does in step 1) above in
lkvm, we need a option to enable that explicitly.

-- 
Asias He
--
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] kvm tools: Export DISPLAY ENV as our default host ip address

2012-09-05 Thread Asias He
On Wed, Sep 5, 2012 at 3:56 PM, Avi Kivity a...@redhat.com wrote:
 On 09/05/2012 09:03 AM, Asias He wrote:
 On Tue, Sep 4, 2012 at 9:07 PM, Avi Kivity a...@redhat.com wrote:
 On 08/24/2012 02:29 PM, Asias He wrote:
 It is useful to run a X program in guest and display it on host.

 1) Make host's x server listen to localhost:6000
host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
UNIX-CONNECT:/tmp/.X11-unix/X0

 2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
   guest_shell$ xlogo


 Note, this is insecure, don't do this with untrusted guests.

 In this use case, the user on the host side should trust the guest.

 Btw, any attack the untrusted guests can do with the X port which host 
 listens?

 Steal the entire display, record user keystrokes, present false information.

OK.

 btw, how did it work?  The you need the xauth cookie for this to work,
 or disable authentication.

The trick here is just listening tcp x11 port(only on localhost) and
forwarding the tcp x11 data to local socket.
The auth sutff should be done by the host side normal X11 setup.

-- 
Asias He
--
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: expanding virtual disk based on lvm

2012-09-05 Thread Alexandre DERUMIER

Certainly restart (shutting down qemu and restarting it, not a reset) 
works, I thought you wanted online resize. 

You can resize an lvm volume online without restarting the guest.


just use lvextend to extend you lvm volume

then use qmp block_resize command with the same size. (so the guest will see 
the new size)



I have implemented this in the proxmox kvm distribution, and it's working fine.

(tested with virtio-blk and virtio-scsi)



- Mail original - 

De: Avi Kivity a...@redhat.com 
À: Ross Boylan r...@biostat.ucsf.edu 
Cc: kvm@vger.kernel.org 
Envoyé: Mercredi 5 Septembre 2012 09:25:26 
Objet: Re: expanding virtual disk based on lvm 

On 09/04/2012 09:58 PM, Ross Boylan wrote: 
 On Tue, 2012-09-04 at 15:53 +0300, Avi Kivity wrote: 
 On 08/28/2012 11:26 PM, Ross Boylan wrote: 
  My vm launches with -hda /dev/turtle/VD0 -hdb /dev/turtle/VD1, where VD0 
  and VD1 are lvm logical volumes. I used lvextend to expand them, but 
  the VM, started after the expansion, does not seem to see the extra 
  space. 
  
  What do I need to so that the space will be recognized? 
 
 IDE (-hda) does not support rechecking the size. Try booting with 
 virtio-blk. Additionally, you may need to request the guest to rescan 
 the drive (no idea how to do that). Nor am I sure whether qemu will 
 emulate the request correctly. 
 
 Thank you for the suggestion. 
 
 I think the physical recognition of the new virtual disk size was 
 accomplished when I restarted the VM, without any other steps. I've had 
 plenty of other problems, but I think at the VM level things are good. 

Certainly restart (shutting down qemu and restarting it, not a reset) 
works, I thought you wanted online resize. 



-- 
error compiling committee.c: too many arguments to function 
-- 
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 
--
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 -v3] KVM: x86: lapic: Clean up find_highest_vector() and count_vectors()

2012-09-05 Thread Michael S. Tsirkin
On Wed, Sep 05, 2012 at 05:30:31PM +0900, Takuya Yoshikawa wrote:
 On Thu, 30 Aug 2012 19:49:23 +0300
 Michael S. Tsirkin m...@redhat.com wrote:
 
  On Fri, Aug 31, 2012 at 01:09:56AM +0900, Takuya Yoshikawa wrote:
   On Thu, 30 Aug 2012 16:21:31 +0300
   Michael S. Tsirkin m...@redhat.com wrote:

 +static u32 apic_read_reg(int reg_off, void *bitmap)
 +{
 + return *((u32 *)(bitmap + reg_off));
 +}
 +

Contrast with apic_set_reg which gets apic,
add fact that all callers invoke REG_POS and you will
see this is a bad API.

I played with some APIs but in the end it's
probably better to just open-code this.
   
   I don't mind open-coding this.
   
As a bonus, open-coding will avoid the need
for cast above, which is good: casts make code more
fragile.
   
   But I still don't understand why we can eliminate casting:
   
 u32 reg_val;
   
 reg_val = *((u32 *)(bitmap + REG_POS(vec)));
 if (reg_val)
 return __fls(reg_val) + vec;
   
   (I'm not sure compilers are allowed to push out the value and
   do multiple references for this code as explained in
   https://lwn.net/Articles/508991/
  
  So you *were* talking about concurrency?
 
 Yes and no, please see below.
 
  And you expect to solve it somehow without barriers
  explicit or implicit?
 
 What I want to make clear is that the value we pass to
 __fls() is not zero, not any more, to avoid undefined
 behaviour.
 
 So as you showed below, if the value passed to __fls() is
 exactly from the register, which we did non-zero check,
 that's fine.  Barriers are not related here.
 
 But as can be seen in the last part of the article above,
 that's may theoretically not be guranteed?

It's not guaranteed if another thread can modify the bitmap.
Is this the case here? If yes we need at least ACCESS_ONCE.

 Anyway, I'm now thinking that we do not care about such
 things here, and can just follow your advice, yes?

Unless you see an issue with it ...

  
   )
   
   
   If you mean
   
 u32 *reg;
   
 reg = bitmap + REG_POS(vec);
 if (*reg)
 return __fls(*reg) + vec;
  
  yes
  
   I'm still not confident if this is a good style.
   I rarely see code doing
   
 if (*p)
 __fls(*p);
   
   This looks like explicite multiple references: I'm not saying
   this will actually be compiled to do multiple references.
   
   Thanks,
 Takuya
  
  It's just weird. Both versions are exactly equivalent in C.
  Adding a temporary changes *nothing* so the best readability
  wins. And IMHO, a version that does not cast wins hands down.
  I did a small test just to give you an example:
 
 Thank you for the example.
 
 What you showed is what I wanted to mean by
 I'm not saying this will actually be compiled to ...
 
 Thanks,
   Takuya
 
  
  [mst@robin ~]$ cat a.c 
  
  int foo(void *bitmap)
  {
 unsigned *reg;
   
 reg = bitmap + 4;
 if (*reg)
 return *reg + 1;
  
 return -1;
  }
  [mst@robin ~]$ cat b.c 
  
  int foo(void *bitmap)
  {
 unsigned reg;
   
 reg = *((unsigned *)(bitmap + 4));
 if (reg)
 return reg + 1;
  
 return -1;
  }
  
  [mst@robin ~]$ gcc -O2 -c a.c
  [mst@robin ~]$ gcc -O2 -c b.c
  
  
  [mst@robin ~]$ objdump -ld a.o
  
  a.o: file format elf32-i386
  
  
  Disassembly of section .text:
  
   foo:
  foo():
 0:   8b 44 24 04 mov0x4(%esp),%eax
 4:   8b 50 04mov0x4(%eax),%edx
 7:   b8 ff ff ff ff  mov$0x,%eax
 c:   8d 4a 01lea0x1(%edx),%ecx
 f:   85 d2   test   %edx,%edx
11:   0f 45 c1cmovne %ecx,%eax
14:   c3  ret
  [mst@robin ~]$ objdump -ld b.o
  
  b.o: file format elf32-i386
  
  
  Disassembly of section .text:
  
   foo:
  foo():
 0:   8b 44 24 04 mov0x4(%esp),%eax
 4:   8b 50 04mov0x4(%eax),%edx
 7:   b8 ff ff ff ff  mov$0x,%eax
 c:   8d 4a 01lea0x1(%edx),%ecx
 f:   85 d2   test   %edx,%edx
11:   0f 45 c1cmovne %ecx,%eax
14:   c3  ret
--
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: Error: Not supported image type twoGbMaxExtentFlat. - problems using virt-convert - SOLVED

2012-09-05 Thread Lentes, Bernd

Brian wrote:

 On Tuesday, September 04, 2012 11:26:49 AM Lentes, Bernd wrote:
  Hi,
 
  i want to convert a sles 11 sp2 64bit system (running on
 VMWare Server
  1.09) to libvirt format. Host OS is SLES 11 SP2 64bit. I tried
  virt-convert --os-variant=sles11 sles_11_vmx/ sles_11_kvm/ .
 
  This is what i got:
  Generating output in 'virt-image' format to sles_11_kvm//
  Converting disk 'tomcat_6.vmdk' to type raw...
  ERRORCouldn't convert disks: Disk conversion failed
 with exit status 1:
  VMDK: Not supported image type twoGbMaxExtentFlat.
 qemu-img: Could not
  open '/var/lib/kvm/images/sles_11_vmx/tomcat_6.vmdk': Operation not
  supported qemu-img: Could not open
  '/var/lib/kvm/images/sles_11_vmx/tomcat_6.vmdk'
 
  It seems that virt-convert does not like the 2GB files form
 VMWare Server.
 
  How can i convert my system from VMWare Server 1.09 to
 libvirt format ?

 I don't know what libvirt format is, but to get a raw file if
 it's Linux:
 vmware-vdiskmanager -r source.vmdk -t 2 dest.raw

 At least I think that should work... That might still be a
 vmdk file, but it
 should work with qemu-img. You might try -t 0 if you are
 short on space.



Hi Brian,

thanks for your tip, that worked. I did vmware-vdiskmanager -r source.vmdk -t 
2 destination.
Afterwards i changed in the vmx-file of the old VM the path of the diskimage 
(it still pointed to the old vmdk files, you have to change it to point to the 
new raw file). Then i did a virt-convert --os-variant=sles11 sles_11_vmx/ 
sles_11_kvm/. Now the new VM is booting. I still have some problems booting 
the new VM, it does not find the root partition. But that should be easy to 
solve.


Bernd

Helmholtz Zentrum München
Deutsches Forschungszentrum für Gesundheit und Umwelt (GmbH)
Ingolstädter Landstr. 1
85764 Neuherberg
www.helmholtz-muenchen.de
Aufsichtsratsvorsitzende: MinDir´in Bärbel Brumme-Bothe
Geschäftsführer: Prof. Dr. Günther Wess und Dr. Nikolaus Blum
Registergericht: Amtsgericht München HRB 6466
USt-IdNr: DE 129521671


Re: [PATCH 1/2] kvm tools: Export DISPLAY ENV as our default host ip address

2012-09-05 Thread Avi Kivity
On 09/05/2012 12:19 PM, Asias He wrote:
 On Wed, Sep 5, 2012 at 3:56 PM, Avi Kivity a...@redhat.com wrote:
 On 09/05/2012 09:03 AM, Asias He wrote:
 On Tue, Sep 4, 2012 at 9:07 PM, Avi Kivity a...@redhat.com wrote:
 On 08/24/2012 02:29 PM, Asias He wrote:
 It is useful to run a X program in guest and display it on host.

 1) Make host's x server listen to localhost:6000
host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
UNIX-CONNECT:/tmp/.X11-unix/X0

 2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
   guest_shell$ xlogo


 Note, this is insecure, don't do this with untrusted guests.

 In this use case, the user on the host side should trust the guest.

 Btw, any attack the untrusted guests can do with the X port which host 
 listens?

 Steal the entire display, record user keystrokes, present false information.
 
 OK.
 
 btw, how did it work?  The you need the xauth cookie for this to work,
 or disable authentication.
 
 The trick here is just listening tcp x11 port(only on localhost) and
 forwarding the tcp x11 data to local socket.
 The auth sutff should be done by the host side normal X11 setup.
 

Ok.  Then the socat command not only exposes the display to the guest,
but also to any local process with access to localhost:6000.


-- 
error compiling committee.c: too many arguments to function
--
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 00/33] Cleanups and automatic init/exit calls

2012-09-05 Thread Pekka Enberg
On Wed, Sep 5, 2012 at 11:31 AM, Sasha Levin levinsasha...@gmail.com wrote:
 This patch series is mostly about cleanups:

  - Clean all the global variables we have to store configuration options.
  - Remove externed config options between objects.
  - Adding several exit routines to clean up on exit.
  - Remove the global 'kvm' object.
  - Contain arch specific init/exit calls within the corresponding non-arch
  specific code instead of the global init.

 This patch series also adds a method to call init/exit functions automatically
 after we've finished intializing config options.

 Doing so clears out a big chunk of repetetive code in our builtin-run init
 function, and makes adding new modules easier since there's now no need to
 link them to builtin-run.

I'm getting an instant SIGSEGV for vm run with these patches:

  [penberg@tux kvm]$ gdb --args ./lkvm run
  GNU gdb (GDB) Fedora (7.3.50.20110722-13.fc16)
  Copyright (C) 2011 Free Software Foundation, Inc.
  License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
  This is free software: you are free to change and redistribute it.
  There is NO WARRANTY, to the extent permitted by law.  Type show copying
  and show warranty for details.
  This GDB was configured as x86_64-redhat-linux-gnu.
  For bug reporting instructions, please see:
  http://www.gnu.org/software/gdb/bugs/...
  Reading symbols from /home/penberg/linux/tools/kvm/lkvm...done.
  (gdb) r
  Starting program: /home/penberg/linux/tools/kvm/lkvm run
  [Thread debugging using libthread_db enabled]
  Using host libthread_db library /lib64/libthread_db.so.1.
# lkvm run -k ../../arch/x86/boot/bzImage -m 448 -c 4 --name guest-6703
  [New Thread 0x7fffdbfd5700 (LWP 6707)]
  [New Thread 0x7fffdb7d4700 (LWP 6708)]
  warning: Range for type (null) has invalid bounds 0..-109

  Program received signal SIGSEGV, Segmentation fault.
  0x0040fb14 in kvm__pause (kvm=0x712010) at kvm.c:419
  419   if (!kvm-cpus[0] || kvm-cpus[0]-thread == 0)
  Missing separate debuginfos, use: debuginfo-install
SDL-1.2.14-13.fc16.x86_64 glibc-2.14.90-24.fc16.7.x86_64
zlib-1.2.5-6.fc16.x86_64
  (gdb) bt
  #0  0x0040fb14 in kvm__pause (kvm=0x712010) at kvm.c:419
  #1  0x0040f898 in ioport__register (kvm=0x712010, port=3324,
ops=0x638ce0, count=4, param=0x0) at ioport.c:63
  #2  0x0040f6c4 in pci__init (kvm=0x712010) at pci.c:194
  #3  0x00414f94 in init_list__init (kvm=0x712010) at util/init.c:41
  #4  0x0041dc4e in kvm_cmd_run_init.2726 (argc=0,
argv=0x7fffe168) at builtin-run.c:655
  #5  0x00419d8e in kvm_cmd_run (argc=0, argv=0x7fffe168,
prefix=0x0) at builtin-run.c:689
  #6  0x004198ce in handle_command (command=0x6396e0, argc=1,
argv=0x7fffe160) at kvm-cmd.c:84
  #7  0x00419797 in handle_kvm_command.5445 (argc=1,
argv=0x7fffe160) at main.c:11
  #8  0x0042753e in main (argc=2, argv=0x7fffe158) at main.c:18
--
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: [Qemu-devel] [PATCH] kvm: Fix warning from static code analysis

2012-09-05 Thread Stefan Hajnoczi
On Mon, Sep 03, 2012 at 10:40:40PM +0200, Stefan Weil wrote:
 Report from smatch:
 
 kvm-all.c:1373 kvm_init(135) warn:
  variable dereferenced before check 's' (see line 1360)
 
 's' cannot by NULL (it was alloced using g_malloc0), so there is no need
 to check it here.
 
 Signed-off-by: Stefan Weil s...@weilnetz.de
 ---
  kvm-all.c |   12 +---
  1 file changed, 5 insertions(+), 7 deletions(-)

Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches

Stefan
--
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 -v3] KVM: x86: lapic: Clean up find_highest_vector() and count_vectors()

2012-09-05 Thread Takuya Yoshikawa
On Wed, 5 Sep 2012 12:26:49 +0300
Michael S. Tsirkin m...@redhat.com wrote:

 It's not guaranteed if another thread can modify the bitmap.
 Is this the case here? If yes we need at least ACCESS_ONCE.

In this patch, using the wrapper function to read out a register
value forces compilers not to do bad things.  But I agree that
it is not a good API.

I would like to use fls() rather than ACCESS_ONCE if it's
really needed.

  Anyway, I'm now thinking that we do not care about such
  things here, and can just follow your advice, yes?
 
 Unless you see an issue with it ...

Although I read the code, I'm not sure.

But this code is apparently not so critical for performance
that we can simply use fls().

If I can remove likely() and use proper macros, that's enough
for me.

Thanks,
Takuya
--
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/8] KVM: x86 emulator: use aligned variants of SSE register ops

2012-09-05 Thread Avi Kivity
On 09/04/2012 03:51 PM, Mathias Krause wrote:
 On Tue, Sep 4, 2012 at 2:13 PM, Avi Kivity a...@redhat.com wrote:
 On 09/04/2012 03:09 PM, Avi Kivity wrote:
 On 08/30/2012 02:30 AM, Mathias Krause wrote:
 As the the compiler ensures that the memory operand is always aligned
 to a 16 byte memory location,

 I'm not sure it does.  Is V4SI aligned?  Do we use alignof() to
 propagate the alignment to the vcpu allocation code?
 
 I checked that to by introducing a dummy char member in struct operand
 that would have misaligned vec_val but, indeed, the compiler ensured
 it's still 16 byte aligned.

Ok.

 

 We actually do.  But please rebase the series against next, I got some
 conflicts while applying.
 
 If next means kvm/next
 (i.e.git://git.kernel.org/pub/scm/virt/kvm/kvm.git#next) here, the
 whole series applies cleanly for me.
 HEAD in kvm/next is 9a78197 KVM: x86: remove unused variable from
 kvm_task_switch() here. Albeit the series was build against kvm/next
 at the time as a81aba1 KVM: VMX: Ignore segment G and D bits when
 considering whether we can virtualize was HEAD in this branch.
 
 Could you please retry and show me the conflicts you get?

I tried again and it applies cleanly now, so it must have been a user
error earlier.

All applied, thanks.

-- 
error compiling committee.c: too many arguments to function
--
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] kvm tools: Export DISPLAY ENV as our default host ip address

2012-09-05 Thread Asias He
On Wed, Sep 5, 2012 at 5:29 PM, Avi Kivity a...@redhat.com wrote:
 On 09/05/2012 12:19 PM, Asias He wrote:
 On Wed, Sep 5, 2012 at 3:56 PM, Avi Kivity a...@redhat.com wrote:
 On 09/05/2012 09:03 AM, Asias He wrote:
 On Tue, Sep 4, 2012 at 9:07 PM, Avi Kivity a...@redhat.com wrote:
 On 08/24/2012 02:29 PM, Asias He wrote:
 It is useful to run a X program in guest and display it on host.

 1) Make host's x server listen to localhost:6000
host_shell$ socat -d -d TCP-LISTEN:6000,fork,bind=localhost \
UNIX-CONNECT:/tmp/.X11-unix/X0

 2) Start the guest and run X program
host_shell$ lkvm run -k /boot/bzImage
   guest_shell$ xlogo


 Note, this is insecure, don't do this with untrusted guests.

 In this use case, the user on the host side should trust the guest.

 Btw, any attack the untrusted guests can do with the X port which host 
 listens?

 Steal the entire display, record user keystrokes, present false information.

 OK.

 btw, how did it work?  The you need the xauth cookie for this to work,
 or disable authentication.

 The trick here is just listening tcp x11 port(only on localhost) and
 forwarding the tcp x11 data to local socket.
 The auth sutff should be done by the host side normal X11 setup.


 Ok.  Then the socat command not only exposes the display to the guest,
 but also to any local process with access to localhost:6000.

Yes.  It is a trick for people with 'Xorg -nolisten tcp' enabled.

-- 
Asias He
--
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 -v3] KVM: x86: lapic: Clean up find_highest_vector() and count_vectors()

2012-09-05 Thread Michael S. Tsirkin
On Wed, Sep 05, 2012 at 06:40:26PM +0900, Takuya Yoshikawa wrote:
 On Wed, 5 Sep 2012 12:26:49 +0300
 Michael S. Tsirkin m...@redhat.com wrote:
 
  It's not guaranteed if another thread can modify the bitmap.
  Is this the case here? If yes we need at least ACCESS_ONCE.
 
 In this patch, using the wrapper function to read out a register
 value forces compilers not to do bad things.

It's not robust. Compiler is free to optimize it out, and it
frequently does that.

 But I agree that it is not a good API.
 
 I would like to use fls() rather than ACCESS_ONCE if it's
 really needed.

Sure, makes sense.

   Anyway, I'm now thinking that we do not care about such
   things here, and can just follow your advice, yes?
  
  Unless you see an issue with it ...
 
 Although I read the code, I'm not sure.
 
 But this code is apparently not so critical for performance
 that we can simply use fls().

Yes. I guess if it becomes critical we'll need to add a cache anyway.

 If I can remove likely() and use proper macros, that's enough
 for me.

Me too.

 Thanks,
   Takuya
--
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] kvm tools: Export DISPLAY ENV as our default host ip address

2012-09-05 Thread Avi Kivity
On 09/05/2012 12:46 PM, Asias He wrote:
 Ok.  Then the socat command not only exposes the display to the guest,
 but also to any local process with access to localhost:6000.
 
 Yes.  It is a trick for people with 'Xorg -nolisten tcp' enabled.

Which is hopefully everyone.

-- 
error compiling committee.c: too many arguments to function
--
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] kvm tools: Export DISPLAY ENV as our default host ip address

2012-09-05 Thread Asias He
On Wed, Sep 5, 2012 at 5:53 PM, Avi Kivity a...@redhat.com wrote:
 On 09/05/2012 12:46 PM, Asias He wrote:
 Ok.  Then the socat command not only exposes the display to the guest,
 but also to any local process with access to localhost:6000.

 Yes.  It is a trick for people with 'Xorg -nolisten tcp' enabled.

 Which is hopefully everyone.

Yup. That's why I want the socat trick ;-d

-- 
Asias He
--
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 -v4] KVM: x86: lapic: Clean up find_highest_vector() and count_vectors()

2012-09-05 Thread Takuya Yoshikawa
find_highest_vector() and count_vectors():
 - Instead of using magic values, define and use proper macros.

find_highest_vector():
 - Remove likely() which is there only for historical reasons and not
   doing correct branch predictions anymore.  Using such heuristics
   to optimize this function is not worth it now.  Let CPUs predict
   things instead.

 - Stop checking word[0] separately.  This was only needed for doing
   likely() optimization.

 - Use for loop, not while, to iterate over the register array to make
   the code clearer.

Note that we actually confirmed that the likely() did wrong predictions
by inserting debug code.

Signed-off-by: Takuya Yoshikawa yoshikawa.tak...@oss.ntt.co.jp
Cc: Michael S. Tsirkin m...@redhat.com
---
 arch/x86/kvm/lapic.c |   30 ++
 1 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 18d149d..8ace252 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -66,6 +66,7 @@
 #define APIC_DEST_NOSHORT  0x0
 #define APIC_DEST_MASK 0x800
 #define MAX_APIC_VECTOR256
+#define APIC_VECTORS_PER_REG   32
 
 #define VEC_POS(v) ((v)  (32 - 1))
 #define REG_POS(v) (((v)  5)  4)
@@ -208,25 +209,30 @@ static unsigned int apic_lvt_mask[APIC_LVT_NUM] = {
 
 static int find_highest_vector(void *bitmap)
 {
-   u32 *word = bitmap;
-   int word_offset = MAX_APIC_VECTOR  5;
+   int vec;
+   u32 *reg;
 
-   while ((word_offset != 0)  (word[(--word_offset)  2] == 0))
-   continue;
+   for (vec = MAX_APIC_VECTOR - APIC_VECTORS_PER_REG;
+vec = 0; vec -= APIC_VECTORS_PER_REG) {
+   reg = bitmap + REG_POS(vec);
+   if (*reg)
+   return fls(*reg) - 1 + vec;
+   }
 
-   if (likely(!word_offset  !word[0]))
-   return -1;
-   else
-   return fls(word[word_offset  2]) - 1 + (word_offset  5);
+   return -1;
 }
 
 static u8 count_vectors(void *bitmap)
 {
-   u32 *word = bitmap;
-   int word_offset;
+   int vec;
+   u32 *reg;
u8 count = 0;
-   for (word_offset = 0; word_offset  MAX_APIC_VECTOR  5; ++word_offset)
-   count += hweight32(word[word_offset  2]);
+
+   for (vec = 0; vec  MAX_APIC_VECTOR; vec += APIC_VECTORS_PER_REG) {
+   reg = bitmap + REG_POS(vec);
+   count += hweight32(*reg);
+   }
+
return count;
 }
 
-- 
1.7.5.4

--
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 -v4] KVM: x86: lapic: Clean up find_highest_vector() and count_vectors()

2012-09-05 Thread Michael S. Tsirkin
On Wed, Sep 05, 2012 at 07:30:01PM +0900, Takuya Yoshikawa wrote:
 find_highest_vector() and count_vectors():
  - Instead of using magic values, define and use proper macros.
 
 find_highest_vector():
  - Remove likely() which is there only for historical reasons and not
doing correct branch predictions anymore.  Using such heuristics
to optimize this function is not worth it now.  Let CPUs predict
things instead.
 
  - Stop checking word[0] separately.  This was only needed for doing
likely() optimization.
 
  - Use for loop, not while, to iterate over the register array to make
the code clearer.
 
 Note that we actually confirmed that the likely() did wrong predictions
 by inserting debug code.
 
 Signed-off-by: Takuya Yoshikawa yoshikawa.tak...@oss.ntt.co.jp
 Cc: Michael S. Tsirkin m...@redhat.com

Looks like a nice cleanup.
Acked-by: Michael S. Tsirkin m...@redhat.com


 ---
  arch/x86/kvm/lapic.c |   30 ++
  1 files changed, 18 insertions(+), 12 deletions(-)
 
 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
 index 18d149d..8ace252 100644
 --- a/arch/x86/kvm/lapic.c
 +++ b/arch/x86/kvm/lapic.c
 @@ -66,6 +66,7 @@
  #define APIC_DEST_NOSHORT0x0
  #define APIC_DEST_MASK   0x800
  #define MAX_APIC_VECTOR  256
 +#define APIC_VECTORS_PER_REG 32
  
  #define VEC_POS(v) ((v)  (32 - 1))
  #define REG_POS(v) (((v)  5)  4)
 @@ -208,25 +209,30 @@ static unsigned int apic_lvt_mask[APIC_LVT_NUM] = {
  
  static int find_highest_vector(void *bitmap)
  {
 - u32 *word = bitmap;
 - int word_offset = MAX_APIC_VECTOR  5;
 + int vec;
 + u32 *reg;
  
 - while ((word_offset != 0)  (word[(--word_offset)  2] == 0))
 - continue;
 + for (vec = MAX_APIC_VECTOR - APIC_VECTORS_PER_REG;
 +  vec = 0; vec -= APIC_VECTORS_PER_REG) {
 + reg = bitmap + REG_POS(vec);
 + if (*reg)
 + return fls(*reg) - 1 + vec;
 + }
  
 - if (likely(!word_offset  !word[0]))
 - return -1;
 - else
 - return fls(word[word_offset  2]) - 1 + (word_offset  5);
 + return -1;
  }
  
  static u8 count_vectors(void *bitmap)
  {
 - u32 *word = bitmap;
 - int word_offset;
 + int vec;
 + u32 *reg;
   u8 count = 0;
 - for (word_offset = 0; word_offset  MAX_APIC_VECTOR  5; ++word_offset)
 - count += hweight32(word[word_offset  2]);
 +
 + for (vec = 0; vec  MAX_APIC_VECTOR; vec += APIC_VECTORS_PER_REG) {
 + reg = bitmap + REG_POS(vec);
 + count += hweight32(*reg);
 + }
 +
   return count;
  }
  
 -- 
 1.7.5.4
--
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] kvm tools: Export DISPLAY ENV as our default host ip address

2012-09-05 Thread Avi Kivity
On 09/05/2012 01:14 PM, Asias He wrote:
 On Wed, Sep 5, 2012 at 5:53 PM, Avi Kivity a...@redhat.com wrote:
 On 09/05/2012 12:46 PM, Asias He wrote:
 Ok.  Then the socat command not only exposes the display to the guest,
 but also to any local process with access to localhost:6000.

 Yes.  It is a trick for people with 'Xorg -nolisten tcp' enabled.

 Which is hopefully everyone.
 
 Yup. That's why I want the socat trick ;-d

No, it's horribly insecure.

One option is to generate a temporary keypair and use ssh.  Or you can
make the guest talk to an internal unix-domain socket, tunnel that
through virtio-serial, terminate virtio-serial in lkvm, and direct it
towards the local X socket.  It's more work than exposing X11 via tcp,
but if the user said -nolisten tcp, you must respect it.


-- 
error compiling committee.c: too many arguments to function
--
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 v2] kvm/fpu: Enable fully eager restore kvm FPU

2012-09-05 Thread Avi Kivity
On 09/05/2012 04:26 AM, Xudong Hao wrote:
 Enable KVM FPU fully eager restore, if there is other FPU state which isn't
 tracked by CR0.TS bit.
 
 Changes from v1:
 Expand KVM_XSTATE_LAZY to 64 bits before negating it.
 
 Signed-off-by: Xudong Hao xudong@intel.com
 ---
  arch/x86/include/asm/kvm.h |4 
  arch/x86/kvm/x86.c |   13 -
  2 files changed, 16 insertions(+), 1 deletions(-)
 
 diff --git a/arch/x86/include/asm/kvm.h b/arch/x86/include/asm/kvm.h
 index 521bf25..4c27056 100644
 --- a/arch/x86/include/asm/kvm.h
 +++ b/arch/x86/include/asm/kvm.h
 @@ -8,6 +8,8 @@
  
  #include linux/types.h
  #include linux/ioctl.h
 +#include asm/user.h
 +#include asm/xsave.h
  
  /* Select x86 specific features in linux/kvm.h */
  #define __KVM_HAVE_PIT
 @@ -30,6 +32,8 @@
  /* Architectural interrupt line count. */
  #define KVM_NR_INTERRUPTS 256
  
 +#define KVM_XSTATE_LAZY  (XSTATE_FP | XSTATE_SSE | XSTATE_YMM)
 +
  struct kvm_memory_alias {
   __u32 slot;  /* this has a different namespace than memory slots */
   __u32 flags;
 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
 index 20f2266..a632042 100644
 --- a/arch/x86/kvm/x86.c
 +++ b/arch/x86/kvm/x86.c
 @@ -5969,7 +5969,18 @@ void kvm_put_guest_fpu(struct kvm_vcpu *vcpu)
   vcpu-guest_fpu_loaded = 0;
   fpu_save_init(vcpu-arch.guest_fpu);
   ++vcpu-stat.fpu_reload;
 - kvm_make_request(KVM_REQ_DEACTIVATE_FPU, vcpu);
 + /*
 +  * Currently KVM trigger FPU restore by #NM (via CR0.TS),
 +  * till now only XCR0.bit0, XCR0.bit1, XCR0.bit2 is tracked
 +  * by TS bit, there might be other FPU state is not tracked
 +  * by TS bit. Here it only make FPU deactivate request and do 
 +  * FPU lazy restore for these cases: 1)xsave isn't enabled 
 +  * in guest, 2)all guest FPU states can be tracked by TS bit.
 +  * For others, doing fully FPU eager restore.
 +  */
 + if (!kvm_read_cr4_bits(vcpu, X86_CR4_OSXSAVE) ||
 + !(vcpu-arch.xcr0  ~((u64)KVM_XSTATE_LAZY)))
 + kvm_make_request(KVM_REQ_DEACTIVATE_FPU, vcpu);
   trace_kvm_fpu(0);
  }
  

I think something is missing.  This patch prevents
KVM_REQ_DEACTIVATE_FPU, but the fpu may not be active when non-lazy bits
are added to xcr0 (or cr4.osxsave is enabled).  I think you need to
activate the fpu at that time as well.


-- 
error compiling committee.c: too many arguments to function
--
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: NFS over RDMA small block DIRECT_IO bug

2012-09-05 Thread Avi Kivity
On 09/04/2012 03:04 PM, Myklebust, Trond wrote:
 On Tue, 2012-09-04 at 11:31 +0200, Andrew Holway wrote:
 Hello.
 
 # Avi Kivity avi(a)redhat recommended I copy kvm in on this. It would also 
 seem relevent to libvirt. #
 
 I have a Centos 6.2 server and Centos 6.2 client.
 
 [root@store ~]# cat /etc/exports 
 /dev/shm 
 10.149.0.0/16(rw,fsid=1,no_root_squash,insecure)(I have tried with non 
 tempfs targets also)
 
 
 [root@node001 ~]# cat /etc/fstab 
 store.ibnet:/dev/shm /mnt nfs  
 rdma,port=2050,defaults 0 0
 
 
 I wrote a little for loop one liner that dd'd the centos net install image 
 to a file called 'hello' then checksummed that file. Each iteration uses a 
 different block size.
 
 Non DIRECT_IO seems to work fine. DIRECT_IO with 512byte, 1K and 2K block 
 sizes get corrupted.
 
 
 That is expected behaviour. DIRECT_IO over RDMA needs to be page aligned
 so that it can use the more efficient RDMA READ and RDMA WRITE memory
 semantics (instead of the SEND/RECEIVE channel semantics).

Shouldn't subpage requests fail then?  O_DIRECT block requests fail for
subsector writes, instead of corrupting your data.

Hopefully this is documented somewhere.

-- 
error compiling committee.c: too many arguments to function
--
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 v3 2/2] virtio-ring: Allocate indirect buffers from cache when possible

2012-09-05 Thread Avi Kivity
On 09/04/2012 09:41 PM, Michael S. Tsirkin wrote:
 On Tue, Sep 04, 2012 at 07:34:19PM +0300, Avi Kivity wrote:
 On 08/31/2012 12:56 PM, Michael S. Tsirkin wrote:
  On Fri, Aug 31, 2012 at 11:36:07AM +0200, Sasha Levin wrote:
  On 08/30/2012 03:38 PM, Michael S. Tsirkin wrote:
   +static unsigned int indirect_alloc_thresh = 16;
   Why 16?  Please make is MAX_SG + 1 this makes some sense.
  
  Wouldn't MAX_SG mean we always allocate from the cache? Isn't the memory 
  waste
  too big in this case?
  
  Sorry. I really meant MAX_SKB_FRAGS + 1. MAX_SKB_FRAGS is 17 so gets us
  threshold of 18. It is less than the size of an skb+shinfo itself so -
  does it look too big to you? Also why do you think 16 is not too big but
  18 is?  If there's a reason then I am fine with 16 too but then please
  put it in code comment near where the value is set.
  
  Yes this means virtio net always allocates from cache
  but this is a good thing, isn't it? Gets us more consistent
  performance.
 
 kmalloc() also goes to a cache.  Is there a measurable difference?
 
 Yes see 0/2 and followup discussion.

I don't see 0/2, looks like this was not threaded properly.  What was
the subject line?


-- 
error compiling committee.c: too many arguments to function
--
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 v3 2/2] virtio-ring: Allocate indirect buffers from cache when possible

2012-09-05 Thread Michael S. Tsirkin
On Wed, Sep 05, 2012 at 05:21:12PM +0300, Avi Kivity wrote:
 On 09/04/2012 09:41 PM, Michael S. Tsirkin wrote:
  On Tue, Sep 04, 2012 at 07:34:19PM +0300, Avi Kivity wrote:
  On 08/31/2012 12:56 PM, Michael S. Tsirkin wrote:
   On Fri, Aug 31, 2012 at 11:36:07AM +0200, Sasha Levin wrote:
   On 08/30/2012 03:38 PM, Michael S. Tsirkin wrote:
+static unsigned int indirect_alloc_thresh = 16;
Why 16?  Please make is MAX_SG + 1 this makes some sense.
   
   Wouldn't MAX_SG mean we always allocate from the cache? Isn't the 
   memory waste
   too big in this case?
   
   Sorry. I really meant MAX_SKB_FRAGS + 1. MAX_SKB_FRAGS is 17 so gets us
   threshold of 18. It is less than the size of an skb+shinfo itself so -
   does it look too big to you? Also why do you think 16 is not too big but
   18 is?  If there's a reason then I am fine with 16 too but then please
   put it in code comment near where the value is set.
   
   Yes this means virtio net always allocates from cache
   but this is a good thing, isn't it? Gets us more consistent
   performance.
  
  kmalloc() also goes to a cache.  Is there a measurable difference?
  
  Yes see 0/2 and followup discussion.
 
 I don't see 0/2, looks like this was not threaded properly.  What was
 the subject line?

My mistake, there is no 0/2, the resolts where in the followup thread
of the previous version:
[PATCH v2 2/2] virtio-ring: Allocate indirect buffers from cache when 
possible

Sasha, could you please accompany the next version
with a cover letter 0/2) including performance results?

 
 -- 
 error compiling committee.c: too many arguments to function
--
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 v9 1/2] kvm: Use a reserved IRQ source ID for irqfd

2012-09-05 Thread Avi Kivity
On 08/22/2012 03:41 AM, Michael S. Tsirkin wrote:
 
 I assumed you were pointing out the level vs edge interaction.  If we
 call that a userspace bug, I can just drop this.  Thanks,
 
 Alex
 
 level is userspace bug I think :)

I don't see how it's a bug.  Suppose we have a vfio device that shares a
gsi with an emulated device.  The emulated device naturally uses
KVM_IRQ_LINE (it has no need to re-sample on ADN), while vfio naturally
has to use irqfd.

Note one would expect that each irqfd gets its own irq source id, since
they are all independent level sources.  The reason they don't is that
we shut them down anyway and let the sources re-trigger (it is more
accurate to say that they have no irq source id, but that would just
muddle the implementation).

Alex, if the conclusion is that we do need this patch, then please add a
comment explaining why we can share the source id among all irqfd users.

-- 
error compiling committee.c: too many arguments to function
--
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 v9 0/2] kvm: level irqfd support

2012-09-05 Thread Avi Kivity
On 08/21/2012 10:28 PM, Alex Williamson wrote:
 Here's the much anticipated re-write of support for level irqfds.  As
 Michael suggested, I've rolled the eoi/ack notification fd into
 KVM_IRQFD as a new mode.  For lack of a better name, as there seems to
 be objections to associating this specifically with an EOI or an ACK,
 I've name this OADN or On Ack, De-assert  Notify.

Perhaps we can call it resample, since this is what it is doing.
irqfd tells kvm that the line as been asserted, resample tells the
caller to check again.

-- 
error compiling committee.c: too many arguments to function
--
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 v9 1/2] kvm: Use a reserved IRQ source ID for irqfd

2012-09-05 Thread Avi Kivity
On 08/21/2012 10:29 PM, Alex Williamson wrote:
 KVM_IRQFD currently uses the reserved KVM_USERSPACE_IRQ_SOURCE_ID
 which is also shared with userspace injection methods like
 KVM_IRQ_LINE.  This can cause a conflict if an irqfd triggers on
 a GSI asserted through KVM_IRQ_LINE.  Move irqfd to it's own
 reserved IRQ source ID.  Add a capability for userspace to test
 for this fix.

I don't think we need a cap, rather a backport if we identify real cases
where an edge gsi is shared among several devices.  Otherwise it is just
a theoretical bug before level irqfd is introduced.

-- 
error compiling committee.c: too many arguments to function
--
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 v9 1/2] kvm: Use a reserved IRQ source ID for irqfd

2012-09-05 Thread Michael S. Tsirkin
On Wed, Sep 05, 2012 at 05:35:43PM +0300, Avi Kivity wrote:
 On 08/22/2012 03:41 AM, Michael S. Tsirkin wrote:
  
  I assumed you were pointing out the level vs edge interaction.  If we
  call that a userspace bug, I can just drop this.  Thanks,
  
  Alex
  
  level is userspace bug I think :)
 
 I don't see how it's a bug.  Suppose we have a vfio device that shares a
 gsi with an emulated device.  The emulated device naturally uses
 KVM_IRQ_LINE (it has no need to re-sample on ADN), while vfio naturally
 has to use irqfd.

Absolutely. But vfio needs to use irqfd with the new flag.
Using existing irqfd for level is a bug.

 Note one would expect that each irqfd gets its own irq source id, since
 they are all independent level sources.  The reason they don't is that
 we shut them down anyway and let the sources re-trigger (it is more
 accurate to say that they have no irq source id, but that would just
 muddle the implementation).
 
 Alex, if the conclusion is that we do need this patch, then please add a
 comment explaining why we can share the source id among all irqfd users.
 
 -- 
 error compiling committee.c: too many arguments to function
--
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 v9 0/2] kvm: level irqfd support

2012-09-05 Thread Michael S. Tsirkin
On Wed, Sep 05, 2012 at 05:42:38PM +0300, Avi Kivity wrote:
 On 08/21/2012 10:28 PM, Alex Williamson wrote:
  Here's the much anticipated re-write of support for level irqfds.  As
  Michael suggested, I've rolled the eoi/ack notification fd into
  KVM_IRQFD as a new mode.  For lack of a better name, as there seems to
  be objections to associating this specifically with an EOI or an ACK,
  I've name this OADN or On Ack, De-assert  Notify.
 
 Perhaps we can call it resample, since this is what it is doing.
 irqfd tells kvm that the line as been asserted, resample tells the
 caller to check again.

Sounds good.

 -- 
 error compiling committee.c: too many arguments to function
--
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 v9 2/2] kvm: On Ack, De-assert Notify KVM_IRQFD extension

2012-09-05 Thread Avi Kivity
On 08/21/2012 10:29 PM, Alex Williamson wrote:
 For VFIO based device assignment we'd like a mechanism to allow level
 triggered interrutps to be directly injected into KVM.  KVM_IRQFD
 already allows this for edge triggered interrupts, but for level, we
 need to watch for acknowledgement of the interrupt from the guest to
 provide us a hint when to test the device and allow it to re-assert
 if necessary.  To do this, we create a new KVM_IRQFD mode called
 On Ack, De-assert  Notify, or OADN.  In this mode, an interrupt
 injection provides only a gsi assertion.  We then hook into the IRQ
 ACK notifier, which when triggered de-asserts the gsi and notifies
 via another eventfd.  It's then the responsibility of the user to
 re-assert the interrupt is service is still required.
 
 
 diff --git a/Documentation/virtual/kvm/api.txt 
 b/Documentation/virtual/kvm/api.txt
 index bf33aaa..87d7321 100644
 --- a/Documentation/virtual/kvm/api.txt
 +++ b/Documentation/virtual/kvm/api.txt
 @@ -1946,6 +1946,19 @@ the guest using the specified gsi pin.  The irqfd is 
 removed using
  the KVM_IRQFD_FLAG_DEASSIGN flag, specifying both kvm_irqfd.fd
  and kvm_irqfd.gsi.
  
 +With KVM_CAP_IRQFD_OADN, KVM_IRQFD supports an On Ack, De-assert 
 +Notify option that allows emulation of level-triggered interrupts.
 +When kvm_irqfd.fd is triggered, the requested gsi is asserted and
 +remains asserted until interaction with the irqchip indicates the
 +VM has acknowledged the interrupt, such as an EOI.  On acknoledgement
 +the gsi is automatically de-asserted and the user is notified via
 +kvm_irqfd.notifyfd.  The user is then required to re-assert the
 +interrupt if the associated device still requires service.  To enable
 +this mode, configure the KVM_IRQFD using the KVM_IRQFD_FLAG_OADN flag
 +and specify kvm_irqfd.notifyfd.  Note that closing kvm_irqfd.notifyfd
 +while configured in this mode does not disable the irqfd.  The
 +KVM_IRQFD_FLAG_OADN flag is only necessary on assignment.

Under my suggested naming, this would be called a resampling irqfd,
with resampling requested via kvm_irqfd.resamplefd.

 diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
 index 2245cfa..dfdb5b2 100644
 --- a/virt/kvm/eventfd.c
 +++ b/virt/kvm/eventfd.c
 @@ -43,6 +43,23 @@
   * 
   */
  
 +/*
 + * OADN irqfds (On Ack, De-assert  Notify) are a special variety of
 + * irqfds that assert an interrupt to the irqchip on eventfd trigger,
 + * receieve notification when userspace acknowledges the interrupt,
 + * automatically de-asserts the irqchip level, and notifies userspace
 + * via the oadn_eventfd.  This object helps to provide one-to-many
 + * deassert-to-notify so we can share a single irq source ID per OADN.
 + */
 +struct _irqfd_oadn {
 + struct kvm *kvm;
 + int irq_source_id; /* IRQ source ID shared by these irqfds */
 + struct list_head irqfds; /* list of irqfds using this object */
 + struct kvm_irq_ack_notifier notifier; /* IRQ ACK notification */
 + struct kref kref; /* Race-free removal */
 + struct list_head list;
 +};


Why do you need per-gsi irq source IDs?  irq source ids only matter
within a gsi.  For example KVM_IRQ_LINE shares one source ID for all
lines (with result that userspace is forced to manage the ORing of
shared inputs itself).




-- 
error compiling committee.c: too many arguments to function
--
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 v9 1/2] kvm: Use a reserved IRQ source ID for irqfd

2012-09-05 Thread Avi Kivity
On 09/05/2012 05:51 PM, Michael S. Tsirkin wrote:
 On Wed, Sep 05, 2012 at 05:35:43PM +0300, Avi Kivity wrote:
 On 08/22/2012 03:41 AM, Michael S. Tsirkin wrote:
  
  I assumed you were pointing out the level vs edge interaction.  If we
  call that a userspace bug, I can just drop this.  Thanks,
  
  Alex
  
  level is userspace bug I think :)
 
 I don't see how it's a bug.  Suppose we have a vfio device that shares a
 gsi with an emulated device.  The emulated device naturally uses
 KVM_IRQ_LINE (it has no need to re-sample on ADN), while vfio naturally
 has to use irqfd.
 
 Absolutely. But vfio needs to use irqfd with the new flag.
 Using existing irqfd for level is a bug.

I see we're not reusing this irq source id for level irqfd.  But I think
we should, there's no need for per-gsi irq source id.  Plus I'd like to
fix the theoretical bug even if it doesn't bite in practice.



-- 
error compiling committee.c: too many arguments to function
--
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 v9 1/2] kvm: Use a reserved IRQ source ID for irqfd

2012-09-05 Thread Michael S. Tsirkin
On Wed, Sep 05, 2012 at 05:46:17PM +0300, Avi Kivity wrote:
 On 08/21/2012 10:29 PM, Alex Williamson wrote:
  KVM_IRQFD currently uses the reserved KVM_USERSPACE_IRQ_SOURCE_ID
  which is also shared with userspace injection methods like
  KVM_IRQ_LINE.  This can cause a conflict if an irqfd triggers on
  a GSI asserted through KVM_IRQ_LINE.  Move irqfd to it's own
  reserved IRQ source ID.  Add a capability for userspace to test
  for this fix.
 
 I don't think we need a cap, rather a backport if we identify real cases
 where an edge gsi is shared among several devices.  Otherwise it is just
 a theoretical bug before level irqfd is introduced.

In that case, I think it's safer to preserve the bug as is: we are
changing userspace-visible behaviour for edge interrupts otherwise.
For example if userspace uses kvm_irq_line for an edge
interrupt, set it to 1, previously it could then
continue to send any number of interrupts with irqfd,
now it can't.

Basically the logical OR functionality of source IDs
does not make sense for edge.

How about we do
 if (flagsRESAMPLE)
source_id = USERSPACE
else
source_id = IRQFD

 -- 
 error compiling committee.c: too many arguments to function
--
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 v9 1/2] kvm: Use a reserved IRQ source ID for irqfd

2012-09-05 Thread Michael S. Tsirkin
On Wed, Sep 05, 2012 at 05:51:53PM +0300, Michael S. Tsirkin wrote:
 On Wed, Sep 05, 2012 at 05:35:43PM +0300, Avi Kivity wrote:
  On 08/22/2012 03:41 AM, Michael S. Tsirkin wrote:
   
   I assumed you were pointing out the level vs edge interaction.  If we
   call that a userspace bug, I can just drop this.  Thanks,
   
   Alex
   
   level is userspace bug I think :)
  
  I don't see how it's a bug.  Suppose we have a vfio device that shares a
  gsi with an emulated device.  The emulated device naturally uses
  KVM_IRQ_LINE (it has no need to re-sample on ADN), while vfio naturally
  has to use irqfd.
 
 Absolutely. But vfio needs to use irqfd with the new flag.
 Using existing irqfd for level is a bug.
 
  Note one would expect that each irqfd gets its own irq source id, since
  they are all independent level sources.  The reason they don't is that
  we shut them down anyway and let the sources re-trigger (it is more
  accurate to say that they have no irq source id, but that would just
  muddle the implementation).
  
  Alex, if the conclusion is that we do need this patch, then please add a
  comment explaining why we can share the source id among all irqfd users.

Something along the lines of

/* 
   For resample irqfds, level is a logical OR of all inputs;
   to support this, track state for RESAMPLE irqfds separately
   from userspace. We do not need to track state for each input since
   they are all deasserted at the same time, before resampling.
   */

?

  -- 
  error compiling committee.c: too many arguments to function
--
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 v9 1/2] kvm: Use a reserved IRQ source ID for irqfd

2012-09-05 Thread Avi Kivity
On 09/05/2012 06:09 PM, Michael S. Tsirkin wrote:
 On Wed, Sep 05, 2012 at 05:51:53PM +0300, Michael S. Tsirkin wrote:
 On Wed, Sep 05, 2012 at 05:35:43PM +0300, Avi Kivity wrote:
  On 08/22/2012 03:41 AM, Michael S. Tsirkin wrote:
   
   I assumed you were pointing out the level vs edge interaction.  If we
   call that a userspace bug, I can just drop this.  Thanks,
   
   Alex
   
   level is userspace bug I think :)
  
  I don't see how it's a bug.  Suppose we have a vfio device that shares a
  gsi with an emulated device.  The emulated device naturally uses
  KVM_IRQ_LINE (it has no need to re-sample on ADN), while vfio naturally
  has to use irqfd.
 
 Absolutely. But vfio needs to use irqfd with the new flag.
 Using existing irqfd for level is a bug.
 
  Note one would expect that each irqfd gets its own irq source id, since
  they are all independent level sources.  The reason they don't is that
  we shut them down anyway and let the sources re-trigger (it is more
  accurate to say that they have no irq source id, but that would just
  muddle the implementation).
  
  Alex, if the conclusion is that we do need this patch, then please add a
  comment explaining why we can share the source id among all irqfd users.
 
 Something along the lines of
 
 /* 
For resample irqfds, level is a logical OR of all inputs;
to support this, track state for RESAMPLE irqfds separately
from userspace. We do not need to track state for each input since
they are all deasserted at the same time, before resampling.
*/

Well the comment style is wrong.

To expand a little more, irqfd only sends assert events, so assigning
the level is equivalent to an OR.  Clearing an resampling simply builds
the state again.

btw, there can be other irq source IDs if the lines are shared with the
PIT or kvm assigned devices.

-- 
error compiling committee.c: too many arguments to function
--
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 v9 1/2] kvm: Use a reserved IRQ source ID for irqfd

2012-09-05 Thread Michael S. Tsirkin
On Wed, Sep 05, 2012 at 05:59:46PM +0300, Avi Kivity wrote:
 On 09/05/2012 05:51 PM, Michael S. Tsirkin wrote:
  On Wed, Sep 05, 2012 at 05:35:43PM +0300, Avi Kivity wrote:
  On 08/22/2012 03:41 AM, Michael S. Tsirkin wrote:
   
   I assumed you were pointing out the level vs edge interaction.  If we
   call that a userspace bug, I can just drop this.  Thanks,
   
   Alex
   
   level is userspace bug I think :)
  
  I don't see how it's a bug.  Suppose we have a vfio device that shares a
  gsi with an emulated device.  The emulated device naturally uses
  KVM_IRQ_LINE (it has no need to re-sample on ADN), while vfio naturally
  has to use irqfd.
  
  Absolutely. But vfio needs to use irqfd with the new flag.
  Using existing irqfd for level is a bug.
 
 I see we're not reusing this irq source id for level irqfd.  But I think
 we should, there's no need for per-gsi irq source id.

I agree. All resample irqfds are deasserted at the same time,
tracking them separately gets us nothing.

 Plus I'd like to
 fix the theoretical bug even if it doesn't bite in practice.
 

I'm not sure what the bug is, for edge, and how a separate ID fixes it.
Could you clarify?

 
 -- 
 error compiling committee.c: too many arguments to function
--
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 v9 1/2] kvm: Use a reserved IRQ source ID for irqfd

2012-09-05 Thread Michael S. Tsirkin
On Wed, Sep 05, 2012 at 06:12:04PM +0300, Avi Kivity wrote:
 On 09/05/2012 06:09 PM, Michael S. Tsirkin wrote:
  On Wed, Sep 05, 2012 at 05:51:53PM +0300, Michael S. Tsirkin wrote:
  On Wed, Sep 05, 2012 at 05:35:43PM +0300, Avi Kivity wrote:
   On 08/22/2012 03:41 AM, Michael S. Tsirkin wrote:

I assumed you were pointing out the level vs edge interaction.  If we
call that a userspace bug, I can just drop this.  Thanks,

Alex

level is userspace bug I think :)
   
   I don't see how it's a bug.  Suppose we have a vfio device that shares a
   gsi with an emulated device.  The emulated device naturally uses
   KVM_IRQ_LINE (it has no need to re-sample on ADN), while vfio naturally
   has to use irqfd.
  
  Absolutely. But vfio needs to use irqfd with the new flag.
  Using existing irqfd for level is a bug.
  
   Note one would expect that each irqfd gets its own irq source id, since
   they are all independent level sources.  The reason they don't is that
   we shut them down anyway and let the sources re-trigger (it is more
   accurate to say that they have no irq source id, but that would just
   muddle the implementation).
   
   Alex, if the conclusion is that we do need this patch, then please add a
   comment explaining why we can share the source id among all irqfd users.
  
  Something along the lines of
  
  /* 
 For resample irqfds, level is a logical OR of all inputs;
 to support this, track state for RESAMPLE irqfds separately
 from userspace. We do not need to track state for each input since
 they are all deasserted at the same time, before resampling.
 */
 
 Well the comment style is wrong.

Ouch.

 To expand a little more, irqfd only sends assert events, so assigning
 the level is equivalent to an OR.  Clearing an resampling simply builds
 the state again.
 
 btw, there can be other irq source IDs if the lines are shared with the
 PIT or kvm assigned devices.

Nod.

 -- 
 error compiling committee.c: too many arguments to function
--
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 v9 1/2] kvm: Use a reserved IRQ source ID for irqfd

2012-09-05 Thread Avi Kivity
On 09/05/2012 06:07 PM, Michael S. Tsirkin wrote:
 On Wed, Sep 05, 2012 at 05:46:17PM +0300, Avi Kivity wrote:
 On 08/21/2012 10:29 PM, Alex Williamson wrote:
  KVM_IRQFD currently uses the reserved KVM_USERSPACE_IRQ_SOURCE_ID
  which is also shared with userspace injection methods like
  KVM_IRQ_LINE.  This can cause a conflict if an irqfd triggers on
  a GSI asserted through KVM_IRQ_LINE.  Move irqfd to it's own
  reserved IRQ source ID.  Add a capability for userspace to test
  for this fix.
 
 I don't think we need a cap, rather a backport if we identify real cases
 where an edge gsi is shared among several devices.  Otherwise it is just
 a theoretical bug before level irqfd is introduced.
 
 In that case, I think it's safer to preserve the bug as is: we are
 changing userspace-visible behaviour for edge interrupts otherwise.
 For example if userspace uses kvm_irq_line for an edge
 interrupt, set it to 1, previously it could then
 continue to send any number of interrupts with irqfd,
 now it can't.

If anyone did that, they should have reported a bug, since they surely
didn't expect edges if the line was held high.

 
 Basically the logical OR functionality of source IDs
 does not make sense for edge.

Edge is only interpreted at the ioapic or pic input; the line is just a
line (an open collector line that ORs anything connected to it, or an
equivalent).

 
 How about we do
if (flagsRESAMPLE)
   source_id = USERSPACE
   else
   source_id = IRQFD

Okay if we identify something that depends on the bug, otherwise not.

-- 
error compiling committee.c: too many arguments to function
--
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 v9 1/2] kvm: Use a reserved IRQ source ID for irqfd

2012-09-05 Thread Avi Kivity
On 09/05/2012 06:13 PM, Michael S. Tsirkin wrote:
 On Wed, Sep 05, 2012 at 05:59:46PM +0300, Avi Kivity wrote:
 On 09/05/2012 05:51 PM, Michael S. Tsirkin wrote:
  On Wed, Sep 05, 2012 at 05:35:43PM +0300, Avi Kivity wrote:
  On 08/22/2012 03:41 AM, Michael S. Tsirkin wrote:
   
   I assumed you were pointing out the level vs edge interaction.  If we
   call that a userspace bug, I can just drop this.  Thanks,
   
   Alex
   
   level is userspace bug I think :)
  
  I don't see how it's a bug.  Suppose we have a vfio device that shares a
  gsi with an emulated device.  The emulated device naturally uses
  KVM_IRQ_LINE (it has no need to re-sample on ADN), while vfio naturally
  has to use irqfd.
  
  Absolutely. But vfio needs to use irqfd with the new flag.
  Using existing irqfd for level is a bug.
 
 I see we're not reusing this irq source id for level irqfd.  But I think
 we should, there's no need for per-gsi irq source id.
 
 I agree. All resample irqfds are deasserted at the same time,
 tracking them separately gets us nothing.

That's not the reason.  Separate irq source ids only have meanings
within a gsi.  We could have two lines (gsi 3 isid 4) and (gsi 4 isid 4)
that can be toggled independently with no effect on the other gsi.
Within a gsi we do need a separate irq source id usually, but as 2/2
recognizes, AODNs are a special case since we clear all inputs anyway.
The end result is that all AODNs can share a single isid.

 
 Plus I'd like to
 fix the theoretical bug even if it doesn't bite in practice.
 
 
 I'm not sure what the bug is, for edge, and how a separate ID fixes it.
 Could you clarify?

gsi 3 is configured as edge in the ioapic.  It has (unusually) two
inputs: one driven by userspace, the other by irqfd.

cpu 0cpu 1
 -
irqfd: set to 1
ioapic: recognize edge
inject irq
EOI
 KVM_IRQ_LINE: set to 1
 ioapic: ignore
 KVM_IRQ_LINE: set to 0
irqfd: set to 0

We had two edges with an EOI between them, but injected just on interrupt.

-- 
error compiling committee.c: too many arguments to function
--
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 v9 1/2] kvm: Use a reserved IRQ source ID for irqfd

2012-09-05 Thread Michael S. Tsirkin
On Wed, Sep 05, 2012 at 06:22:57PM +0300, Avi Kivity wrote:
 On 09/05/2012 06:13 PM, Michael S. Tsirkin wrote:
  On Wed, Sep 05, 2012 at 05:59:46PM +0300, Avi Kivity wrote:
  On 09/05/2012 05:51 PM, Michael S. Tsirkin wrote:
   On Wed, Sep 05, 2012 at 05:35:43PM +0300, Avi Kivity wrote:
   On 08/22/2012 03:41 AM, Michael S. Tsirkin wrote:

I assumed you were pointing out the level vs edge interaction.  If we
call that a userspace bug, I can just drop this.  Thanks,

Alex

level is userspace bug I think :)
   
   I don't see how it's a bug.  Suppose we have a vfio device that shares a
   gsi with an emulated device.  The emulated device naturally uses
   KVM_IRQ_LINE (it has no need to re-sample on ADN), while vfio naturally
   has to use irqfd.
   
   Absolutely. But vfio needs to use irqfd with the new flag.
   Using existing irqfd for level is a bug.
  
  I see we're not reusing this irq source id for level irqfd.  But I think
  we should, there's no need for per-gsi irq source id.
  
  I agree. All resample irqfds are deasserted at the same time,
  tracking them separately gets us nothing.
 
 That's not the reason.  Separate irq source ids only have meanings
 within a gsi.  We could have two lines (gsi 3 isid 4) and (gsi 4 isid 4)
 that can be toggled independently with no effect on the other gsi.
 Within a gsi we do need a separate irq source id usually, but as 2/2
 recognizes, AODNs are a special case since we clear all inputs anyway.
 The end result is that all AODNs can share a single isid.
 
  
  Plus I'd like to
  fix the theoretical bug even if it doesn't bite in practice.
  
  
  I'm not sure what the bug is, for edge, and how a separate ID fixes it.
  Could you clarify?
 
 gsi 3 is configured as edge in the ioapic.  It has (unusually) two
 inputs: one driven by userspace, the other by irqfd.
 
 cpu 0cpu 1
  -
 irqfd: set to 1
 ioapic: recognize edge
 inject irq
 EOI
  KVM_IRQ_LINE: set to 1
  ioapic: ignore
  KVM_IRQ_LINE: set to 0
 irqfd: set to 0
 
 We had two edges with an EOI between them, but injected just on interrupt.

I see. Makes sense, ACK this patch.


 -- 
 error compiling committee.c: too many arguments to function
--
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: [Qemu-devel] [PATCH 4/4] kvm: i386: Add classic PCI device assignment

2012-09-05 Thread Avi Kivity
On 09/05/2012 12:00 AM, Anthony Liguori wrote:

 Why? The way this is being submitted I don't see why we should treat
 Jan's patch any different from a patch by IBM or Samsung where we've
 asked folks to fix the license to comply with what I thought was our new
 policy (it does not even contain a from-x-on-GPLv2+ notice).
 
 Asking is one thing.  Requiring is another.
 
 I would prefer that people submitted GPLv2+, but I don't think it should
 be a hard requirement.  It means, among other things, that we cannot
 accept most code that originates from the Linux kernel.

We could extend this to require unless there is a reason to grant an
exception if we wanted to (not saying I know whether we want to or not).


-- 
error compiling committee.c: too many arguments to function
--
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: [Qemu-devel] [PATCH 4/4] kvm: i386: Add classic PCI device assignment

2012-09-05 Thread Michael S. Tsirkin
On Wed, Sep 05, 2012 at 06:26:54PM +0300, Avi Kivity wrote:
 On 09/05/2012 12:00 AM, Anthony Liguori wrote:
 
  Why? The way this is being submitted I don't see why we should treat
  Jan's patch any different from a patch by IBM or Samsung where we've
  asked folks to fix the license to comply with what I thought was our new
  policy (it does not even contain a from-x-on-GPLv2+ notice).
  
  Asking is one thing.  Requiring is another.
  
  I would prefer that people submitted GPLv2+, but I don't think it should
  be a hard requirement.  It means, among other things, that we cannot
  accept most code that originates from the Linux kernel.
 
 We could extend this to require unless there is a reason to grant an
 exception if we wanted to (not saying I know whether we want to or not).

Would be nice to add a clarification in the header: people
tend to copy boilerplate around.

 
 -- 
 error compiling committee.c: too many arguments to function
--
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 v9 1/2] kvm: Use a reserved IRQ source ID for irqfd

2012-09-05 Thread Avi Kivity
On 09/05/2012 06:28 PM, Michael S. Tsirkin wrote:

 gsi 3 is configured as edge in the ioapic.  It has (unusually) two
 inputs: one driven by userspace, the other by irqfd.
 
 cpu 0cpu 1
  -
 irqfd: set to 1
 ioapic: recognize edge
 inject irq
 EOI
  KVM_IRQ_LINE: set to 1
  ioapic: ignore
  KVM_IRQ_LINE: set to 0
 irqfd: set to 0
 
 We had two edges with an EOI between them, but injected just on interrupt.
 
 I see. Makes sense, ACK this patch.

Actually it's wrong.  The two sources are not synchronized, so there is
no way for them to know the two edges did not coalesce.  On real
hardware, after all, edge interrupts have a non-zero pulse width, and
kvm faithfully emulates this.

But this patch makes sense for level irqfd, so we might as well keep it
with a different description.

-- 
error compiling committee.c: too many arguments to function
--
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 v2] add acpi pmtimer support

2012-09-05 Thread Don Slutz

On 09/05/12 01:27, Gerd Hoffmann wrote:

On 09/02/12 22:42, Kevin O'Connor wrote:

On Tue, Aug 14, 2012 at 07:29:19AM +0200, Gerd Hoffmann wrote:

This patch makes seabios use the acpi pmtimer instead of tsc for
timekeeping.  The pmtimer has a fixed frequency and doesn't need
calibration, thus it doesn't suffer from calibration errors due to a
loaded host machine.

The patch looks okay to me, but is it still needed?  (I recall seeing
something on the kvm list about a bug fix to the main timer.)

It is still a good idea to make timing in a virtual machine more robust.


+u32 pmtimer = inl(ioport);
+return (u64)wraps  24 | pmtimer;

BTW, why is this  24, and if it should be that way, shouldn't the
pmtimer be inl(ioport)  0xff ?

The pmtimer is defined to be 24 bits wide, so the shift is correct.
This is not true in general.  It can be either 24 or 32 bits.  What it 
is depends on ACPI data (acpi_gbl_FADT-tmr_val_ext).  However it is 
valid to only used 24 bits.


*/
/*


But, yes, the ioport read should better be masked to be on the safe
side.  v3 will go out in a minute.

cheers,
   Gerd

___
SeaBIOS mailing list
seab...@seabios.org
http://www.seabios.org/mailman/listinfo/seabios

  -Don Slutz
--
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: [Qemu-devel] [PATCH 4/4] kvm: i386: Add classic PCI device assignment

2012-09-05 Thread Anthony Liguori
Avi Kivity a...@redhat.com writes:

 On 09/05/2012 12:00 AM, Anthony Liguori wrote:

 Why? The way this is being submitted I don't see why we should treat
 Jan's patch any different from a patch by IBM or Samsung where we've
 asked folks to fix the license to comply with what I thought was our new
 policy (it does not even contain a from-x-on-GPLv2+ notice).
 
 Asking is one thing.  Requiring is another.
 
 I would prefer that people submitted GPLv2+, but I don't think it should
 be a hard requirement.  It means, among other things, that we cannot
 accept most code that originates from the Linux kernel.

 We could extend this to require unless there is a reason to grant an
 exception if we wanted to (not saying I know whether we want to or
 not).

I don't want QEMU to be GPLv3.  I don't like the terms of the GPLv3.

I don't mind GPLv2+, if people want to share code from QEMU in GPLv3
projects, GPLv2+ enables that.

But if new code is coming in and happens to be under GPLv2, that just
means that the contribution cannot be used outside of QEMU in a GPLv3
project.  That's fine and that's a decision for the submitter to make.

Regards,

Anthony Liguori



 -- 
 error compiling committee.c: too many arguments to function
--
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: [Qemu-devel] [PATCH 4/4] kvm: i386: Add classic PCI device assignment

2012-09-05 Thread Avi Kivity
On 09/05/2012 06:41 PM, Anthony Liguori wrote:
 Avi Kivity a...@redhat.com writes:
 
 On 09/05/2012 12:00 AM, Anthony Liguori wrote:

 Why? The way this is being submitted I don't see why we should treat
 Jan's patch any different from a patch by IBM or Samsung where we've
 asked folks to fix the license to comply with what I thought was our new
 policy (it does not even contain a from-x-on-GPLv2+ notice).
 
 Asking is one thing.  Requiring is another.
 
 I would prefer that people submitted GPLv2+, but I don't think it should
 be a hard requirement.  It means, among other things, that we cannot
 accept most code that originates from the Linux kernel.

 We could extend this to require unless there is a reason to grant an
 exception if we wanted to (not saying I know whether we want to or
 not).
 
 I don't want QEMU to be GPLv3.  I don't like the terms of the GPLv3.
 
 I don't mind GPLv2+, if people want to share code from QEMU in GPLv3
 projects, GPLv2+ enables that.
 
 But if new code is coming in and happens to be under GPLv2, that just
 means that the contribution cannot be used outside of QEMU in a GPLv3
 project.  That's fine and that's a decision for the submitter to make.

Makes sense.

-- 
error compiling committee.c: too many arguments to function
--
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] kvm/x86: use symbolic constant for nr interrupts

2012-09-05 Thread Michael S. Tsirkin
interrupt_bitmap is KVM_NR_INTERRUPTS bits in size,
so just use that instead of hard-coded constants
and math.

Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 arch/x86/kvm/x86.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index dce75b76..62bba66 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2365,7 +2365,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
struct kvm_interrupt *irq)
 {
-   if (irq-irq  0 || irq-irq = 256)
+   if (irq-irq  0 || irq-irq = KVM_NR_INTERRUPTS)
return -EINVAL;
if (irqchip_in_kernel(vcpu-kvm))
return -ENXIO;
@@ -5789,7 +5789,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
if (mmu_reset_needed)
kvm_mmu_reset_context(vcpu);
 
-   max_bits = (sizeof sregs-interrupt_bitmap)  3;
+   max_bits = KVM_NR_INTERRUPTS;
pending_vec = find_first_bit(
(const unsigned long *)sregs-interrupt_bitmap, max_bits);
if (pending_vec  max_bits) {
-- 
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: [PATCHv2] x86info: dump kvm cpuid's

2012-09-05 Thread Michael S. Tsirkin
On Mon, Apr 30, 2012 at 05:38:35PM +0300, Michael S. Tsirkin wrote:
 The following makes 'x86info -r' dump hypervisor leaf cpu ids
 (for kvm this is signature+features) when running in a vm.
 
 On the guest we see the signature and the features:
 eax in: 0x4000, eax =  ebx = 4b4d564b ecx = 564b4d56 edx = 
 004d
 eax in: 0x4001, eax = 017b ebx =  ecx =  edx = 
 
 
 Hypervisor flag is checked to avoid output changes when not
 running on a VM.
 
 Signed-off-by: Michael S. Tsirkin m...@redhat.com
 
 Changes from v1:
   Make work on non KVM hypervisors (only KVM was tested).
   Avi Kivity said kvm will in the future report
   max HV leaf in eax. For now it reports eax = 0
 so add a work around for that.

Ping.
Davej, any comments?
Would be nice to have this in.


 ---
 
 diff --git a/identify.c b/identify.c
 index 33f35de..a4a3763 100644
 --- a/identify.c
 +++ b/identify.c
 @@ -9,8 +9,8 @@
  
  void get_cpu_info_basics(struct cpudata *cpu)
  {
 - unsigned int maxi, maxei, vendor, address_bits;
 - unsigned int eax;
 + unsigned int maxi, maxei, maxhv, vendor, address_bits;
 + unsigned int eax, ebx, ecx;
  
   cpuid(cpu-number, 0, maxi, vendor, NULL, NULL);
   maxi = 0x; /* The high-order word is non-zero on some 
 Cyrix CPUs */
 @@ -19,7 +19,7 @@ void get_cpu_info_basics(struct cpudata *cpu)
   return;
  
   /* Everything that supports cpuid supports these. */
 - cpuid(cpu-number, 1, eax, NULL, NULL, NULL);
 + cpuid(cpu-number, 1, eax, ebx, ecx, NULL);
   cpu-stepping = eax  0xf;
   cpu-model = (eax  4)  0xf;
   cpu-family = (eax  8)  0xf;
 @@ -29,6 +29,19 @@ void get_cpu_info_basics(struct cpudata *cpu)
  
   cpuid(cpu-number, 0xC000, maxei, NULL, NULL, NULL);
   cpu-maxei2 = maxei;
 + if (ecx  0x8000) {
 + cpuid(cpu-number, 0x4000, maxhv, NULL, NULL, NULL);
 + /*
 +  * KVM up to linux 3.4 reports 0 as the max hypervisor leaf,
 +  * where it really means 0x4001.
 +  * Most (all?) hypervisors have at least one CPUID besides
 +  * the vendor ID so assume that.
 +  */
 + cpu-maxhv = maxhv ? maxhv : 0x4001;
 + } else {
 + /* Suppress hypervisor cpuid unless running on a hypervisor */
 + cpu-maxhv = 0;
 + }
  
   cpuid(cpu-number, 0x8008,address_bits, NULL, NULL, NULL);
   cpu-phyaddr_bits = address_bits  0xFF;
 diff --git a/x86info.c b/x86info.c
 index 22c4734..80cae36 100644
 --- a/x86info.c
 +++ b/x86info.c
 @@ -44,6 +44,10 @@ static void display_detailed_info(struct cpudata *cpu)
  
   if (cpu-maxei2 =0xC000)
   dump_raw_cpuid(cpu-number, 0xC000, cpu-maxei2);
 +
 + if (cpu-maxhv = 0x4000)
 + dump_raw_cpuid(cpu-number, 0x4000, cpu-maxhv);
 +
   }
  
   if (show_cacheinfo) {
 diff --git a/x86info.h b/x86info.h
 index 7d2a455..c4f5d81 100644
 --- a/x86info.h
 +++ b/x86info.h
 @@ -84,7 +84,7 @@ struct cpudata {
   unsigned int cachesize_trace;
   unsigned int phyaddr_bits;
   unsigned int viraddr_bits;
 - unsigned int cpuid_level, maxei, maxei2;
 + unsigned int cpuid_level, maxei, maxei2, maxhv;
   char name[CPU_NAME_LEN];
   enum connector connector;
   unsigned int flags_ecx;
--
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] virtio: support reserved vqs

2012-09-05 Thread Michael S. Tsirkin
virtio network device multiqueue support reserves
vq 3 for future use (useful both for future extensions and to make it
pretty - this way receive vqs have even and transmit - odd numbers).
Make it possible to skip initialization for
specific vq numbers by specifying NULL for name.
Document this usage as well as (existing) NULL callback.

Drivers using this not coded up yet, so I simply tested
with virtio-pci and verified that this patch does
not break existing drivers.

Signed-off-by: Michael S. Tsirkin m...@redhat.com
---
 drivers/lguest/lguest_device.c | 3 +++
 drivers/remoteproc/remoteproc_virtio.c | 3 +++
 drivers/s390/kvm/kvm_virtio.c  | 3 +++
 drivers/virtio/virtio_mmio.c   | 3 +++
 drivers/virtio/virtio_pci.c| 5 -
 include/linux/virtio_config.h  | 2 ++
 6 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/lguest/lguest_device.c b/drivers/lguest/lguest_device.c
index 9e8388e..e849e12 100644
--- a/drivers/lguest/lguest_device.c
+++ b/drivers/lguest/lguest_device.c
@@ -263,6 +263,9 @@ static struct virtqueue *lg_find_vq(struct virtio_device 
*vdev,
struct virtqueue *vq;
int err;
 
+   if (!name)
+   return NULL;
+
/* We must have this many virtqueues. */
if (index = ldev-desc-num_vq)
return ERR_PTR(-ENOENT);
diff --git a/drivers/remoteproc/remoteproc_virtio.c 
b/drivers/remoteproc/remoteproc_virtio.c
index 3541b44..bda6750 100644
--- a/drivers/remoteproc/remoteproc_virtio.c
+++ b/drivers/remoteproc/remoteproc_virtio.c
@@ -84,6 +84,9 @@ static struct virtqueue *rp_find_vq(struct virtio_device 
*vdev,
if (id = ARRAY_SIZE(rvdev-vring))
return ERR_PTR(-EINVAL);
 
+   if (!name)
+   return NULL;
+
ret = rproc_alloc_vring(rvdev, id);
if (ret)
return ERR_PTR(ret);
diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
index 47cccd5..6e842d1 100644
--- a/drivers/s390/kvm/kvm_virtio.c
+++ b/drivers/s390/kvm/kvm_virtio.c
@@ -190,6 +190,9 @@ static struct virtqueue *kvm_find_vq(struct virtio_device 
*vdev,
if (index = kdev-desc-num_vq)
return ERR_PTR(-ENOENT);
 
+   if (!name)
+   return NULL;
+
config = kvm_vq_config(kdev-desc)+index;
 
err = vmem_add_mapping(config-address,
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index 453db0c..b1f342e 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -309,6 +309,9 @@ static struct virtqueue *vm_setup_vq(struct virtio_device 
*vdev, unsigned index,
unsigned long flags, size;
int err;
 
+   if (!name)
+   return NULL;
+
/* Select the queue we're interested in */
writel(index, vm_dev-base + VIRTIO_MMIO_QUEUE_SEL);
 
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index 2e03d41..92809ba 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -542,7 +542,10 @@ static int vp_try_to_find_vqs(struct virtio_device *vdev, 
unsigned nvqs,
vp_dev-per_vq_vectors = per_vq_vectors;
allocated_vectors = vp_dev-msix_used_vectors;
for (i = 0; i  nvqs; ++i) {
-   if (!callbacks[i] || !vp_dev-msix_enabled)
+   if (!names[i]) {
+   vqs[i] = NULL;
+   continue;
+   } else if (!callbacks[i] || !vp_dev-msix_enabled)
msix_vec = VIRTIO_MSI_NO_VECTOR;
else if (vp_dev-per_vq_vectors)
msix_vec = allocated_vectors++;
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index fc457f4..07c0c69 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -84,7 +84,9 @@
  * nvqs: the number of virtqueues to find
  * vqs: on success, includes new virtqueues
  * callbacks: array of callbacks, for each virtqueue
+ * include a NULL entry for vqs that do not need a callback
  * names: array of virtqueue names (mainly for debugging)
+ * include a NULL entry for vqs unused by driver
  * Returns 0 on success or error status
  * @del_vqs: free virtqueues found by find_vqs().
  * @get_features: get the array of feature bits for this device.
-- 
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] target-i386: Allow changing of Hypervisor CPUIDs.

2012-09-05 Thread Marcelo Tosatti
On Thu, Aug 30, 2012 at 03:20:35PM -0400, Don Slutz wrote:
 This is primarily done so that the guest will think it is running
 under vmware when hypervisor=vmware is specified as a property of a
 cpu.
 
 Also allow this to work in accel=tcg mode.
 
 The new cpu properties hyper_level, hyper_extra, hyper_extra_a, and
 hyper_extra_b can be used to further adjust what the guest sees.
 
 Signed-off-by: Don Slutz d...@cloudswitch.com

For what purpose? 

Is the VMWare interface documented somewhere?

 ---
  target-i386/cpu.c |  178 
 +
  target-i386/cpu.h |9 +++
  target-i386/kvm.c |   33 --
  3 files changed, 214 insertions(+), 6 deletions(-)
 
 diff --git a/target-i386/cpu.c b/target-i386/cpu.c
 index f3cac49..a444b95 100644
 --- a/target-i386/cpu.c
 +++ b/target-i386/cpu.c
 @@ -26,6 +26,7 @@
  
  #include qemu-option.h
  #include qemu-config.h
 +#include qemu-timer.h
  
  #include qapi/qapi-visit-core.h
  #include arch_init.h
 @@ -244,6 +245,15 @@ typedef struct x86_def_t {
  uint32_t xlevel2;
  /* The feature bits on CPUID[EAX=7,ECX=0].EBX */
  uint32_t cpuid_7_0_ebx_features;
 +/* Hypervisor CPUIDs */
 +uint32_t cpuid_hv_level;
 +uint32_t cpuid_hv_vendor1;
 +uint32_t cpuid_hv_vendor2;
 +uint32_t cpuid_hv_vendor3;
 +/* VMware extra data */
 +uint32_t cpuid_hv_extra;
 +uint32_t cpuid_hv_extra_a;
 +uint32_t cpuid_hv_extra_b;
  } x86_def_t;
  
  #define I486_FEATURES (CPUID_FP87 | CPUID_VME | CPUID_PSE)
 @@ -860,6 +870,18 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor 
 *v, void *opaque,
  cpu-env.tsc_khz = value / 1000;
  }
  
 +static void x86_cpuid_set_hv(x86_def_t *x86_cpu_def, uint32_t level,
 + const char *who)
 +{
 +uint32_t signature[3];
 +
 +memcpy(signature, who, 12);
 +x86_cpu_def-cpuid_hv_level = level;
 +x86_cpu_def-cpuid_hv_vendor1 = signature[0];
 +x86_cpu_def-cpuid_hv_vendor2 = signature[1];
 +x86_cpu_def-cpuid_hv_vendor3 = signature[2];
 +}
 +
  static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, const char 
 *cpu_model)
  {
  unsigned int i;
 @@ -867,6 +889,10 @@ static int cpu_x86_find_by_name(x86_def_t *x86_cpu_def, 
 const char *cpu_model)
  
  char *s = g_strdup(cpu_model);
  char *featurestr, *name = strtok(s, ,);
 +bool hyperv_enabled = false;
 +bool hv_enabled = false;
 +long hyper_level = -1;
 +long hyper_extra = -1;
  /* Features to be added*/
  uint32_t plus_features = 0, plus_ext_features = 0;
  uint32_t plus_ext2_features = 0, plus_ext3_features = 0;
 @@ -993,12 +1019,84 @@ static int cpu_x86_find_by_name(x86_def_t 
 *x86_cpu_def, const char *cpu_model)
  x86_cpu_def-tsc_khz = tsc_freq / 1000;
  } else if (!strcmp(featurestr, hv_spinlocks)) {
  char *err;
 +
 +if (hv_enabled) {
 +fprintf(stderr,
 +Only one of hypervisor= or hv_* can be used at 
 one time.\n);
 +goto error;
 +}
  numvalue = strtoul(val, err, 0);
  if (!*val || *err) {
  fprintf(stderr, bad numerical value %s\n, val);
  goto error;
  }
 +hyperv_enabled = true;
  hyperv_set_spinlock_retries(numvalue);
 +} else if (!strcmp(featurestr, hyper_level)) {
 +char *err;
 +long longvalue = strtol(val, err, 0);
 +
 +if (!*val || *err) {
 +fprintf(stderr, bad numerical value for 
 hyper_level=%s\n,
 +val);
 +goto error;
 +}
 +hyper_level = longvalue;
 +} else if (!strcmp(featurestr, hyper_extra)) {
 +char *err;
 +long longvalue = strtol(val, err, 0);
 +
 +if (!*val || *err) {
 +fprintf(stderr, bad numerical value for 
 hyper_extra=%s\n,
 +val);
 +goto error;
 +}
 +hyper_extra = longvalue;
 +} else if (!strcmp(featurestr, hyper_extra_a)) {
 +char *err;
 +
 +numvalue = strtoul(val, err, 0);
 +if (!*val || *err) {
 +fprintf(stderr,
 +bad numerical value for hyper_extra_a=%s\n,
 +val);
 +goto error;
 +}
 +x86_cpu_def-cpuid_hv_extra_a = (uint32_t)numvalue;
 +} else if (!strcmp(featurestr, hyper_extra_b)) {
 +char *err;
 +
 +numvalue = strtoul(val, err, 0);
 +if (!*val || *err) {
 +fprintf(stderr,
 +bad numerical value for 

Re: [Qemu-devel] [PATCH 4/4] kvm: i386: Add classic PCI device assignment

2012-09-05 Thread Blue Swirl
On Wed, Sep 5, 2012 at 3:41 PM, Anthony Liguori anth...@codemonkey.ws wrote:
 Avi Kivity a...@redhat.com writes:

 On 09/05/2012 12:00 AM, Anthony Liguori wrote:

 Why? The way this is being submitted I don't see why we should treat
 Jan's patch any different from a patch by IBM or Samsung where we've
 asked folks to fix the license to comply with what I thought was our new
 policy (it does not even contain a from-x-on-GPLv2+ notice).

 Asking is one thing.  Requiring is another.

 I would prefer that people submitted GPLv2+, but I don't think it should
 be a hard requirement.  It means, among other things, that we cannot
 accept most code that originates from the Linux kernel.

 We could extend this to require unless there is a reason to grant an
 exception if we wanted to (not saying I know whether we want to or
 not).

 I don't want QEMU to be GPLv3.  I don't like the terms of the GPLv3.

 I don't mind GPLv2+, if people want to share code from QEMU in GPLv3
 projects, GPLv2+ enables that.

The advantage of 100% GPLv2+ (or other GPLv3 compatible) would be that
QEMU could share code from GPLv3 projects, specifically latest
binutils. Reinventing a disassembler for ever growing x86 assembly is
no fun.


 But if new code is coming in and happens to be under GPLv2, that just
 means that the contribution cannot be used outside of QEMU in a GPLv3
 project.  That's fine and that's a decision for the submitter to make.

This policy means that we are locked in with GPLv2.


 Regards,

 Anthony Liguori



 --
 error compiling committee.c: too many arguments to function
--
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


  1   2   >