Re: [Qemu-devel] [PATCH] numa: check for busy memory backend

2014-06-29 Thread Michael S. Tsirkin
On Mon, Jun 30, 2014 at 01:33:42PM +0800, Hu Tao wrote:
> On Sun, Jun 29, 2014 at 06:20:22PM +0300, Michael S. Tsirkin wrote:
> > On Wed, Jun 25, 2014 at 05:04:14PM +0800, Hu Tao wrote:
> > > ..to prevent one memory backend from being used by more than one numa
> > > node.
> > 
> > Thanks, but please always make the msg content self-contained
> > so it can be understood without the subject.
> > E.g. here, just drop "..to".
> > 
> > Are you sure we want this? Is there a chance sharing a backend
> > can be useful?
> 
> This patch is actually a bug fix.

It is?  What is the bug and how to reproduce it?
I am not sure we should write a ton of code to validate qemu
configuration, as long as qemu does not assert.

> Even if we will want backend sharing, we
> can do it after.

By reverting this patch? So why merge it?

> > 
> > Igor, what's your take?
> > 
> > > 
> > > Signed-off-by: Hu Tao 
> > > ---
> > >  numa.c | 7 +++
> > >  1 file changed, 7 insertions(+)
> > > 
> > > diff --git a/numa.c b/numa.c
> > > index e471afe..6c1c554 100644
> > > --- a/numa.c
> > > +++ b/numa.c
> > > @@ -279,6 +279,13 @@ void 
> > > memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
> > >  exit(1);
> > >  }
> > >  
> > > +if (memory_region_is_mapped(seg)) {
> > > +char *path = 
> > > object_get_canonical_path_component(OBJECT(backend));
> > > +error_report("memory backend %s is busy", path);
> > > +g_free(path);
> > > +exit(1);
> > > +}
> > > +
> > >  memory_region_add_subregion(mr, addr, seg);
> > >  vmstate_register_ram_global(seg);
> > >  addr += size;
> > > -- 
> > > 1.9.3



Re: [Qemu-devel] [PATCH v9 00/22] legacy virtio support for cross-endian targets

2014-06-29 Thread Greg Kurz
On Sun, 29 Jun 2014 18:13:53 +0300
"Michael S. Tsirkin"  wrote:
> On Tue, Jun 24, 2014 at 07:06:58PM +0200, Greg Kurz wrote:
> > The current legacy virtio devices have a fundamental flaw: they all share
> > data between host and guest with guest endianness ordering. This is ok for
> > nearly all architectures that have fixed endianness. Unfortunately, it 
> > breaks
> > for recent PPC64 and ARM targets that can change endianness at runtime.
> > The virtio-1.0 specification fixes the issue by enforcing little-endian
> > ordering. It may take some time though until the code for 1.0 gets available
> > and supported, and all the users can migrate. There have been discussions
> > for some monthes about supporting such oddity: now we have little-endian
> > PPC64 distros available, it is worth to propose something.
> > 
> > This patch set brings legacy virtio support for cross-endian targets. The
> > rationale is that we add a new device_endianness property to VirtIODevice.
> > This property is used as a runtime indicator to decide wether we should
> > do little-endian or big-endian conversion, as opposed to the compile time
> > choice we have now with TARGTE_WORDS_BIGENDIAN. The choice was made to
> > sample the device endianness out of the endianness mode of the guest
> > CPU that does the reset. It is an evil but logical consequence of the
> > initial flaw in the virtio specification, and it was agreed that the concept
> > would be a good common base for ARM and PPC64 enablement at least. Please
> > note also that this new property is state and must be preserved across
> > migrations.
> > 
> > There are several parts in the serie:
> > - patches 1 and 2 are simple fixes
> > - patches 3 to 9 introduce VMState based subsections in the virtio
> >   migration code. This is needed because we introduce a new property
> >   in VirtIODevice that we want to migrate without ruining compatibility
> >   efforts
> > - patches 10 to 13 bring virtio device endianness and memory accessors
> >   to be used by the virtio code
> > - patches 14 to 20 wire the new memory accessors everywhere accross the
> >   virtio code
> > - patch 21 is the PPC64 enablement
> > - patch 22 is a follow-up workaround to disable vhost-net acceleration
> >   in the case the host and guest have different endianness, because
> >   it is not supported for the moment
> > 
> > Changes since v8 are provided in each patch.
> > 
> > Cheers.
> 
> Applied, thanks everyone.
> 

\O/

Thanks Michael !

--
Greg

> > ---
> > 
> > Alexander Graf (1):
> >   virtio-serial: don't migrate the config space
> > 
> > Cédric Le Goater (1):
> >   virtio-net: byteswap virtio-net header
> > 
> > Greg Kurz (14):
> >   virtio: introduce device specific migration calls
> >   virtio-net: implement per-device migration calls
> >   virtio-blk: implement per-device migration calls
> >   virtio-serial: implement per-device migration calls
> >   virtio-balloon: implement per-device migration calls
> >   virtio-rng: implement per-device migration calls
> >   virtio: add subsections to the migration stream
> >   exec: introduce target_words_bigendian() helper
> >   cpu: introduce CPUClass::virtio_is_big_endian()
> >   virtio: add endian-ambivalent support to VirtIODevice
> >   virtio: memory accessors for endian-ambivalent targets
> >   virtio-9p: use virtio wrappers to access headers
> >   target-ppc: enable virtio endian ambivalent support
> >   vhost-net: disable when cross-endian
> > 
> > Rusty Russell (6):
> >   virtio: allow byte swapping for vring
> >   virtio-net: use virtio wrappers to access headers
> >   virtio-balloon: use virtio wrappers to access page frame numbers
> >   virtio-blk: use virtio wrappers to access headers
> >   virtio-scsi: use virtio wrappers to access headers
> >   virtio-serial-bus: use virtio wrappers to access headers
> > 
> > 
> >  exec.c|8 -
> >  hw/9pfs/virtio-9p-device.c|3 -
> >  hw/block/virtio-blk.c |   62 ++-
> >  hw/char/virtio-serial-bus.c   |   94 ++--
> >  hw/net/vhost_net.c|   19 +++
> >  hw/net/virtio-net.c   |   56 +++---
> >  hw/scsi/virtio-scsi.c |   40 ---
> >  hw/virtio/virtio-balloon.c|   33 +++---
> >  hw/virtio/virtio-pci.c|   11 +-
> >  hw/virtio/virtio-rng.c|   12 +-
> >  hw/virtio/virtio.c|  216 
> > -
> >  include/hw/virtio/virtio-access.h |  170 +
> >  include/hw/virtio/virtio.h|   17 +++
> >  include/qom/cpu.h |1 
> >  qom/cpu.c |6 +
> >  target-ppc/cpu.h  |2 
> >  target-ppc/translate_init.c   |   15 +++
> >  17 files changed, 583 insertions(+), 182 deletions(-)
> >  create mode 100644 include/hw/virtio/virtio-access.h
> > 
> >

Re: [Qemu-devel] [v5][PATCH 0/5] xen: add Intel IGD passthrough support

2014-06-29 Thread Michael S. Tsirkin
On Mon, Jun 30, 2014 at 10:51:49AM +0800, Chen, Tiejun wrote:
> On 2014/6/26 18:03, Paolo Bonzini wrote:
> >Il 26/06/2014 11:18, Chen, Tiejun ha scritto:
> >>
> >>>
> >>>- offsets 0x..0x0fff map to configuration space of the host MCH
> >>>
> >>
> >>Are you saying the config space in the video device?
> >
> >No, I am saying in a new BAR, or at some magic offset of an existing
> >MMIO BAR.
> >
> 
> As I mentioned previously, the IGD guy told me we have no any unused a
> offset or BAR in the config space.
> 
> And guy who are responsible for the native driver seems not be accept to
> extend some magic offset of an existing MMIO BAR.
> 
> In addition I think in a short time its not possible to migrate i440fx to
> q35 as a PCIe machine of xen.

That seems like a weak motivation.  I don't see a need to get something
merged upstream in a short time: this seems sure to miss 2.1,
so you have the time to make it architecturally sound.
"Making existing guests work" would be a better motivation.
Isn't this possible with an mch chipset?


> So could we do this step by step:
> 
> #1 phase: We just cover current qemu-xen implementation based on i44fx, so
> still provide that pseudo ISA bridge at 00:1f.0 as we already did.

By the way there is no reason to put it at 00:1f.0 specifically I think.
So it seems simple: create a dummy device that gets device and
vendor id as properties. If you really like, add an option to get values
from sysfs: device and vendor id are world readable, so just get them
directly and not through xen wrappers, this way you can open the files
RO and not RW.
You seem to poke at revision as well, I don't see
driver looking at that - strictly necessary?
If yes please patch host kernel to expose that info in sysfs,
though we can fall back on pci config if not there.

MCH (bridge_dev) hacks in i915 are nastier.
To clean them up, we really have to have an explicit driver for this
bridge, not a pass-through device.  Long term, the right thing to do is
likely to extend host driver and expose the necessary information in
sysfs on host kernel.




> #2 phase: Now, we will choose a capability ID that won't be conflicting with
> others. To do this properly, we need to get one from PCI SIG group. To have
> this workable and consistently validated, this method shouldn't be virt
> specific. Then native driver should use the same method.

You mean you will be able to talk sense into hardware guys?
I doubt that. If they could be convinced to make e.g. i915 base a
proper BAR, why didn't they?


> So when xen work on
> q35 PCIe machine, we can walk this way.

If you are emulating MCH anyway, pick one that is close
to what i915 driver expects. It would then work with existing
devices, without new capability IDs.


> Anthony,
> 
> Any comments to address this in xen case?
> 
> Thanks
> Tiejun



[Qemu-devel] [PATCH V4] qemu-img create: add 'nocow' option

2014-06-29 Thread Chunyan Liu
Add 'nocow' option so that users could have a chance to set NOCOW flag to
newly created files. It's useful on btrfs file system to enhance performance.

Btrfs has low performance when hosting VM images, even more when the guest
in those VM are also using btrfs as file system. One way to mitigate this bad
performance is to turn off COW attributes on VM files. Generally, there are
two ways to turn off NOCOW on btrfs: a) by mounting fs with nodatacow, then
all newly created files will be NOCOW. b) per file. Add the NOCOW file
attribute. It could only be done to empty or new files.

This patch tries the second way, according to the option, it could add NOCOW
per file.

For most block drivers, since the create file step is in raw-posix.c, so we
can do setting NOCOW flag ioctl in raw-posix.c only.

But there are some exceptions, like block/vpc.c and block/vdi.c, they are
creating file by calling qemu_open directly. For them, do the same setting
NOCOW flag ioctl work in them separately.

Signed-off-by: Chunyan Liu 
---
  Changes to v3:
* remove NOCOW option from .create_opts of those drivers calling
  bdrv_create_file to create file. Adding NOCOW to raw-posix.c is
  enough. No difference to users when using 'qemu-img create' interface.
  Make the patch cleaner. 

 block/qed.c   |  6 +++---
 block/raw-posix.c | 25 +
 block/vdi.c   | 29 +
 block/vmdk.c  |  6 +++---
 block/vpc.c   | 29 +
 include/block/block_int.h |  1 +
 qemu-doc.texi | 16 
 qemu-img.texi | 16 
 8 files changed, 122 insertions(+), 6 deletions(-)

diff --git a/block/qed.c b/block/qed.c
index eddae92..b69374b 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -567,7 +567,7 @@ static void bdrv_qed_close(BlockDriverState *bs)
 static int qed_create(const char *filename, uint32_t cluster_size,
   uint64_t image_size, uint32_t table_size,
   const char *backing_file, const char *backing_fmt,
-  Error **errp)
+  QemuOpts *opts, Error **errp)
 {
 QEDHeader header = {
 .magic = QED_MAGIC,
@@ -586,7 +586,7 @@ static int qed_create(const char *filename, uint32_t 
cluster_size,
 int ret = 0;
 BlockDriverState *bs;
 
-ret = bdrv_create_file(filename, NULL, &local_err);
+ret = bdrv_create_file(filename, opts, &local_err);
 if (ret < 0) {
 error_propagate(errp, local_err);
 return ret;
@@ -682,7 +682,7 @@ static int bdrv_qed_create(const char *filename, QemuOpts 
*opts, Error **errp)
 }
 
 ret = qed_create(filename, cluster_size, image_size, table_size,
- backing_file, backing_fmt, errp);
+ backing_file, backing_fmt, opts, errp);
 
 finish:
 g_free(backing_file);
diff --git a/block/raw-posix.c b/block/raw-posix.c
index dacf4fb..825a0c8 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -55,6 +55,9 @@
 #include 
 #include 
 #include 
+#ifndef FS_NOCOW_FL
+#define FS_NOCOW_FL 0x0080 /* Do not cow file */
+#endif
 #endif
 #ifdef CONFIG_FIEMAP
 #include 
@@ -1278,12 +1281,14 @@ static int raw_create(const char *filename, QemuOpts 
*opts, Error **errp)
 int fd;
 int result = 0;
 int64_t total_size = 0;
+bool nocow = false;
 
 strstart(filename, "file:", &filename);
 
 /* Read out options */
 total_size =
 qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0) / BDRV_SECTOR_SIZE;
+nocow = qemu_opt_get_bool(opts, BLOCK_OPT_NOCOW, false);
 
 fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644);
@@ -1291,6 +1296,21 @@ static int raw_create(const char *filename, QemuOpts 
*opts, Error **errp)
 result = -errno;
 error_setg_errno(errp, -result, "Could not create file");
 } else {
+if (nocow) {
+#ifdef __linux__
+/* Set NOCOW flag to solve performance issue on fs like btrfs.
+ * This is an optimisation. The FS_IOC_SETFLAGS ioctl return value
+ * will be ignored since any failure of this operation should not
+ * block the left work.
+ */
+int attr;
+if (ioctl(fd, FS_IOC_GETFLAGS, &attr) == 0) {
+attr |= FS_NOCOW_FL;
+ioctl(fd, FS_IOC_SETFLAGS, &attr);
+}
+#endif
+}
+
 if (ftruncate(fd, total_size * BDRV_SECTOR_SIZE) != 0) {
 result = -errno;
 error_setg_errno(errp, -result, "Could not resize file");
@@ -1477,6 +1497,11 @@ static QemuOptsList raw_create_opts = {
 .type = QEMU_OPT_SIZE,
 .help = "Virtual disk size"
 },
+{
+.name = BLOCK_OPT_NOCOW,
+.type = QEMU_OPT_BOOL,
+.help = "Turn off copy-on-write (valid only on btrfs)"
+ 

Re: [Qemu-devel] [PATCH] numa: check for busy memory backend

2014-06-29 Thread Hu Tao
On Sun, Jun 29, 2014 at 06:20:22PM +0300, Michael S. Tsirkin wrote:
> On Wed, Jun 25, 2014 at 05:04:14PM +0800, Hu Tao wrote:
> > ..to prevent one memory backend from being used by more than one numa
> > node.
> 
> Thanks, but please always make the msg content self-contained
> so it can be understood without the subject.
> E.g. here, just drop "..to".
> 
> Are you sure we want this? Is there a chance sharing a backend
> can be useful?

This patch is actually a bug fix. Even if we will want backend sharing, we
can do it after.

> 
> Igor, what's your take?
> 
> > 
> > Signed-off-by: Hu Tao 
> > ---
> >  numa.c | 7 +++
> >  1 file changed, 7 insertions(+)
> > 
> > diff --git a/numa.c b/numa.c
> > index e471afe..6c1c554 100644
> > --- a/numa.c
> > +++ b/numa.c
> > @@ -279,6 +279,13 @@ void memory_region_allocate_system_memory(MemoryRegion 
> > *mr, Object *owner,
> >  exit(1);
> >  }
> >  
> > +if (memory_region_is_mapped(seg)) {
> > +char *path = 
> > object_get_canonical_path_component(OBJECT(backend));
> > +error_report("memory backend %s is busy", path);
> > +g_free(path);
> > +exit(1);
> > +}
> > +
> >  memory_region_add_subregion(mr, addr, seg);
> >  vmstate_register_ram_global(seg);
> >  addr += size;
> > -- 
> > 1.9.3



Re: [Qemu-devel] [Qemu-ppc] [PATCH v4] ppc: spapr-rtas - implement os-term rtas call

2014-06-29 Thread Nikunj A Dadhania
Tyrel Datwyler  writes:

> On 06/27/2014 12:37 AM, Nikunj A Dadhania wrote:
>> PAPR compliant guest calls this in absence of kdump. This finally
>> reaches the guest and can be handled according to the policies set by
>> higher level tools(like taking dump) for further analysis by tools like
>> crash.
>> 
>> Linux kernel calls this only when the extended version of os,term is
>> implemented to make sure that a return to the linux kernel is gauranteed.
>> 
>> CC: Benjamin Herrenschmidt 
>> CC: Anton Blanchard 
>> CC: Alexander Graf 
>> Signed-off-by: Nikunj A Dadhania 
>> 
>> ---
>> 
>> v2: rebase to ppcnext
>> v3: Do not stop the VM, and update comments
>> v4: update spapr_register_rtas and qapi_event changes
>> ---
>>  hw/ppc/spapr_rtas.c | 36 
>>  1 file changed, 36 insertions(+)
>> 
>> diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
>> index 9ba1ba6..b11de41 100644
>> --- a/hw/ppc/spapr_rtas.c
>> +++ b/hw/ppc/spapr_rtas.c
>> @@ -277,6 +277,38 @@ static void rtas_ibm_set_system_parameter(PowerPCCPU 
>> *cpu,
>>  rtas_st(rets, 0, ret);
>>  }
>>  
>> +static void rtas_ibm_os_term(PowerPCCPU *cpu,
>> +sPAPREnvironment *spapr,
>> +uint32_t token, uint32_t nargs,
>> +target_ulong args,
>> +uint32_t nret, target_ulong rets)
>> +{
>> +target_ulong ret = 0;
>> +
>> +qapi_event_send_guest_panicked(GUEST_PANIC_ACTION_PAUSE, &error_abort);
>> +
>> +rtas_st(rets, 0, ret);
>> +}
>> +
>> +/*
>> + * According to PAPR, rtas ibm,os-term, does not gaurantee a return
>> + * back to the guest cpu.
>> + *
>> + * While an additional ibm,extended-os-term property indicates that
>> + * rtas call return will always occur. Below function implements a
>> + * place holder for the same.
>> + */
>
> PAPR defines ibm,extended-os-term as a null encoded property not a rtas
> function. It should be added to the device tree in the
> spapr_create_fdt_skel function under the "rtas" node. The following
> should suffice.
>
> _FDT((fdt_property(fdt, "ibm,extended-os-term", NULL, 0)));
>

Sure, I can do that, much better.

Regards
Nikunj




Re: [Qemu-devel] [PATCH V3] qemu-img create: add 'nocow' option

2014-06-29 Thread Chun Yan Liu


>>> On 6/27/2014 at 07:48 PM, in message
<20140627114806.gm12...@stefanha-thinkpad.muc.redhat.com>, Stefan Hajnoczi
 wrote: 
> On Mon, Jun 23, 2014 at 05:17:02PM +0800, Chunyan Liu wrote: 
> > Add 'nocow' option so that users could have a chance to set NOCOW flag to 
> > newly created files. It's useful on btrfs file system to enhance  
> performance. 
> >  
> > Btrfs has low performance when hosting VM images, even more when the guest 
> > in those VM are also using btrfs as file system. One way to mitigate this  
> bad 
> > performance is to turn off COW attributes on VM files. Generally, there are 
> > two ways to turn off NOCOW on btrfs: a) by mounting fs with nodatacow, then 
> > all newly created files will be NOCOW. b) per file. Add the NOCOW file 
> > attribute. It could only be done to empty or new files. 
> >  
> > This patch tries the second way, according to the option, it could add  
> NOCOW 
> > per file. 
> >  
> > For most block drivers, since the create file step is in raw-posix.c, so we 
> > can do setting NOCOW flag ioctl in raw-posix.c only. 
> >  
> > But there are some exceptions, like block/vpc.c and block/vdi.c, they are 
> > creating file by calling qemu_open directly. For them, do the same setting 
> > NOCOW flag ioctl work in them separately. 
> >  
> > Signed-off-by: Chunyan Liu  
> > --- 
> > Changes to v2: 
> >   * based on QemuOpts instead of old QEMUOptionParameters 
> >   * add nocow description in man page and html doc 
> >  
> >   Old v2 is here: 
> >   http://lists.gnu.org/archive/html/qemu-devel/2013-11/msg02429.html 
> >  
> > --- 
> >  block/cow.c   |  5 + 
> >  block/qcow.c  |  5 + 
> >  block/qcow2.c |  5 + 
> >  block/qed.c   | 11 --- 
> >  block/raw-posix.c | 25 + 
> >  block/vdi.c   | 29 + 
> >  block/vhdx.c  |  5 + 
> >  block/vmdk.c  | 11 --- 
> >  block/vpc.c   | 29 + 
> >  include/block/block_int.h |  1 + 
> >  qemu-doc.texi | 16  
> >  qemu-img.texi | 16  
> >  12 files changed, 152 insertions(+), 6 deletions(-) 
>  
> Are you sure it's necessary to touch all image formats in order to pass 
> through the nocow option?  Looking at bdrv_img_create() I think it will 
> work without touching all image formats since both drv and 
> proto_drv->create_opts are appended: 

Right. For those calling bdrv_create_file to create file, it's not necessary
to add NOCOW option to their .create_opts. Adding NOCOW to raw-posix.c
is enough. There will be no difference to users when they do:
qemu-img create -f fmt name size -o nocow=on
or
qemu-img create -f fmt name size -o ?

>  
> void bdrv_img_create(const char *filename, const char *fmt, 
>  const char *base_filename, const char *base_fmt, 
>  char *options, uint64_t img_size, int flags, 
>  Error **errp, bool quiet) 
> { 
> QemuOptsList *create_opts = NULL; 
> ... 
> create_opts = qemu_opts_append(create_opts, drv->create_opts); 
> create_opts = qemu_opts_append(create_opts, proto_drv->create_opts); 
>  
> /* Create parameter list with default values */ 
> opts = qemu_opts_create(create_opts, NULL, 0, &error_abort); 
> qemu_opt_set_number(opts, BLOCK_OPT_SIZE, img_size); 
>  
> /* Parse -o options */ 
> if (options) { 
> if (qemu_opts_do_parse(opts, options, NULL) != 0) { 
> error_setg(errp, "Invalid options for file format '%s'", fmt); 
> goto out; 
> } 
> } 
>  




[Qemu-devel] QApi: Java interface

2014-06-29 Thread Shevek

Hi,

I have written a Java code generator to allow a Java control process to 
interface with the QApi subsystem. The code is autogenerated from the 
JSON schema, and imposes as much strict typing as is possible. It can 
easily be regenerated from any branch or directory if you want to test 
against a development version of QApi.


The code is available here:

https://github.com/shevek/qemu-qapi-java

I would be interested in offering this to the community, and in hearing 
any feedback.


Feedback to QApi developers: The QApi specification uses a lot of 
oddities, including "**" as a type, various odd things like "number" (I 
forget offhand), and using Java/C reserved words as key names, which 
make it a little harder to do an elegant code generation job from the 
QApi schema. However, inelegance permitted, here it is.


Thank you.

S.



Re: [Qemu-devel] [RFC][PATCH] gpu:drm:i915:intel_detect_pch: back to check devfn instead of check class type

2014-06-29 Thread Chen, Tiejun

On 2014/6/25 15:55, Paolo Bonzini wrote:

Il 25/06/2014 09:34, Chen, Tiejun ha scritto:

On 2014/6/25 14:48, Paolo Bonzini wrote:

Second problem.  Your IGD passthrough code currently works with QEMU's
PIIX4-based machine.  But what happens if you try to extend it, so that


Yes, current xen machine, xenpv, is based on pii4, and also I don't
known if we will plan to migrate to q35 or others. So its hard to
further say more now.


it works with QEMU's ICH9-based machine?  That's a more modern machine
that has a PCIe chipset and hence has its ISA bridge at 00:1f.0.  Now


But even in this case, could we set the real vendor/device ids for that
ISA bridge at 00:1f.0? If not, what's broken?


The config space layout changes for different vendor/device ids, so the
guest firmware only works if you have the right vendor/device id.


Paolo,

After I discuss internal, we think even we just set the real 
vendor/device ids to this ISA bridge at 00:1f.0, guest firmware should 
still work well with these pair of real vendor/device ids.


So if you think something would conflict or be broken, could you tell us 
what's exactly that? Then we will double check.


Thanks
Tiejun




It is only slightly better, but the right solution is to fix the driver.
  There is absolutely zero reason why a graphics driver should know
about the vendor/device ids of the PCH.


This means we have to fix this both on Linux and Windows but I'm not
sure if this is feasible to us.


You have to do it if you want this feature in QEMU in a future-proof way.

You _can_ provide the ugly PIIX4-specific hack as a compatibility
fallback (and this patch is okay to make the compatibility fallback less
hacky).  However, I don't think QEMU should accept the patch for IGD
passthrough unless Intel is willing to make drivers
virtualization-friendly.  Once you assign the IGD, it is not that
integrated anymore and the drivers must take that into account.

It is worthwhile pointing out that neither AMD nor nVidia need any of this.


The right way could be to make QEMU add a vendor-specific capability to
the video device. The driver can probe for that capability before


Do you mean we can pick two unused offsets in the configuration space of
the video device as a vendor-specific capability to hold the
vendor/device ids of the PCH?


Yes, either that or add a new capability (which lets you choose the
offsets more freely).

If the IGD driver needs config space fields of the MCH, those fields
could also be mirrored in the new capability.  QEMU would forward them
automatically.

It could even be a new BAR, which gives even more freedom to allocate
the fields.


looking at the PCI bus.  QEMU can add the capability to the list, it is
easy because all accesses to the video device's configuration space trap
to QEMU.  Then you do not need to add fake devices to the machine.

In fact, it would be nice if Intel added such a capability on the next
generation of integrated graphics, too.  On real hardware, ACPI or some


Maybe, but even this would be implemented, shouldn't we need to be
compatible with those old generations?


Yes.

- old generation / old driver: use 00:1f.0 hack, only guaranteed to work
on PIIX4-based virtual guest

- old generation / new driver: use 00:1f.0 hack on real hardware, use
capability on 00:02.0 on virtual guest, can work on PCIe virtual guest

- new generation / old driver: doesn't exist

- new generation / new driver: always use capability on 00:02.0, can
work on PCIe virtual guest.

Paolo






Re: [Qemu-devel] [v5][PATCH 4/5] xen, gfx passthrough: create host bridge to passthrough

2014-06-29 Thread Chen, Tiejun

On 2014/6/29 20:14, Michael S. Tsirkin wrote:

On Sun, Jun 29, 2014 at 03:56:10PM +0800, Chen, Tiejun wrote:

On 2014/6/27 19:26, Paolo Bonzini wrote:

Il 27/06/2014 10:34, Chen, Tiejun ha scritto:



So how to separate this to specific to xen? Or you mean we need to
create an new machine to address this scenario? But actually this is
same as xenfv_machine except for these little codes.


Yes, please create a new machine so that "-M pc" doesn't have any of
these hacks.


But regardless of the machine is 'xenfv' or 'pc', we always call
pc_init_pci(), then inside, i440fx_init() is always performed. So I think
even we create a new machine, shouldn't we still call pc_init_pci()?



Note that "-M xenfv" is obsolete, Xen can now use "-M pc" (i.e. the
default).



Yes, Xen can use 'pc'.

Thanks
Tiejun


You are creating a new machine type where the pci host
looks like MCH but a bunch of other things are from i440fx.


Anthony,

Any comments to address this in xen case?

Thanks
Tiejun



I have some doubts about this combination being worth supporting - it
does not seem useful for anything except xen from the code you posted,
but maybe you can whittle down the number of places where you poke at
the host to make it reasonable: I can imagine that, if you are lucky and
the registers that i915 wants to poke to make it work on real hardware
happen to fall on top of reserved registers in the i440FX/PIIX3 pci
bridge.  OTOH it would be much more likely if you just start with
something that does have MCH, like Q35, or emulate a newer
machine type.  This is the path that people who wanted
to boot iOS on QEMU took, and the result is pretty good.

But regardless, this is clearly not a i440fx nor a q35 pc
so it needs a separate name.





Re: [Qemu-devel] [v5][PATCH 0/5] xen: add Intel IGD passthrough support

2014-06-29 Thread Chen, Tiejun

On 2014/6/26 18:03, Paolo Bonzini wrote:

Il 26/06/2014 11:18, Chen, Tiejun ha scritto:




- offsets 0x..0x0fff map to configuration space of the host MCH



Are you saying the config space in the video device?


No, I am saying in a new BAR, or at some magic offset of an existing
MMIO BAR.



As I mentioned previously, the IGD guy told me we have no any unused a 
offset or BAR in the config space.


And guy who are responsible for the native driver seems not be accept to 
extend some magic offset of an existing MMIO BAR.


In addition I think in a short time its not possible to migrate i440fx 
to q35 as a PCIe machine of xen. So could we do this step by step:


#1 phase: We just cover current qemu-xen implementation based on i44fx, 
so still provide that pseudo ISA bridge at 00:1f.0 as we already did.


#2 phase: Now, we will choose a capability ID that won't be conflicting 
with others. To do this properly, we need to get one from PCI SIG group. 
To have this workable and consistently validated, this method shouldn't 
be virt specific. Then native driver should use the same method. So when 
xen work on q35 PCIe machine, we can walk this way.


Anthony,

Any comments to address this in xen case?

Thanks
Tiejun



[Qemu-devel] [questions] about KVM as a Microsoft-compatible hypervisor

2014-06-29 Thread Zhang Haoyu
Hi, Vadim
I read the kvm-2012-forum paper < KVM as a Microsoft-compatible hypervisor>, 
Any update and other references, please?

Thanks,
Zhang Haoyu




Re: [Qemu-devel] [v5][PATCH 5/5] xen, gfx passthrough: add opregion mapping

2014-06-29 Thread Chen, Tiejun

On 2014/6/29 19:43, Michael S. Tsirkin wrote:

On Fri, Jun 27, 2014 at 05:22:18PM +0800, Chen, Tiejun wrote:

On 2014/6/25 15:13, Michael S. Tsirkin wrote:

On Wed, Jun 25, 2014 at 10:17:21AM +0800, Tiejun Chen wrote:


[snip]


diff --git a/hw/xen/xen_pt.h b/hw/xen/xen_pt.h
index 507165c..25147cf 100644
--- a/hw/xen/xen_pt.h
+++ b/hw/xen/xen_pt.h
@@ -63,7 +63,7 @@ typedef int (*xen_pt_conf_byte_read)
  #define XEN_PT_BAR_UNMAPPED (-1)

  #define PCI_CAP_MAX 48
-
+#define PCI_INTEL_OPREGION 0xfc



XEN_ please

PCI_CAP_MAX should be fixed too.


They are specific to PCI, not XEN.


They are?  Where in the PCI spec does it say 48?
Same for PCI_INTEL_OPREGION.


Why should we add such a prefix?


So that people working on core pci do not have to worry about breaking
your devices by adding a symbol in the global header.


Okay.









[snip]



+if (igd_guest_opregion) {
+ret = xc_domain_memory_mapping(xen_xc, xen_domid,
+(unsigned long)(igd_guest_opregion >> XC_PAGE_SHIFT),
+(unsigned long)(igd_host_opregion >> XC_PAGE_SHIFT),


don't spread casts all around.
Should be a last resort.


Okay.




+3,
+DPCI_REMOVE_MAPPING);
+if (ret) {
+return ret;
+}
+}
+
  return 0;
  }

@@ -447,3 +462,52 @@ err_out:
  XEN_PT_ERR(pci_dev, "Can't get pci_dev_host_bridge\n");
  return -1;
  }
+
+uint32_t igd_read_opregion(XenPCIPassthroughState *s)
+{
+uint32_t val = 0;
+
+if (igd_guest_opregion == 0) {


!igd_guest_opregion is shorter and does the same,


Okay.




+return val;
+}
+
+val = igd_guest_opregion;
+
+XEN_PT_LOG(&s->dev, "Read opregion val=%x\n", val);
+return val;
+}
+
+void igd_write_opregion(XenPCIPassthroughState *s, uint32_t val)
+{
+int ret;
+
+if (igd_guest_opregion) {
+XEN_PT_LOG(&s->dev, "opregion register already been set, ignoring 
%x\n",
+   val);
+return;
+}
+
+xen_host_pci_get_block(&s->real_device, PCI_INTEL_OPREGION,
+(uint8_t *)&igd_host_opregion, 4);
+igd_guest_opregion = (unsigned long)(val & ~0xfff)
+| (igd_host_opregion & 0xfff);
+


Clearly broken on BE.


I still can't understand why we need to address this in BE case.


So code is clean and reusable. Copy and paste is a fact of life,
you don't want people to inherit bugs.


Understood.


If some code absolutely must be LE specific,
it needs a comment that explains this and cautions
people against trying to use it elsewhere in QEMU.


I think its fine enough to add a comment.

Thanks
Tiejun





Maybe not important here but writing clean code is
just as easy.
uint8_t igd_host_opregion[4];

...

 xen_host_pci_get_block(&s->real_device, PCI_INTEL_OPREGION,
   igd_host_opregion, sizeof igd_host_opregion);

 igd_guest_opregion = (val & ~0xfff) |
(pci_get_word(igd_host_opregion) & 0xfff);

0xfff should be a macro too to avoid duplication.



Okay.

Thanks
Tiejun






Re: [Qemu-devel] [PATCH 0/4] ui/cocoa: Fix absolute positioning and other bugs

2014-06-29 Thread Peter Maydell
On 23 June 2014 10:35, Peter Maydell  wrote:
> This set of cocoa UI patches:
>  * fixes the completely broken handling of absolute positioning
>(tablet-style) input devices
>  * fixes a bug where if the first surface created was the same 640x480
>as the initial window we'd never actually draw it
>  * implements support for the -show-cursor command line option
>
> The GTK and SDL UI frontends don't seem to be consistent about how they
> handle mousegrab for absolute-position devices; I followed SDL on the
> basis that it was the older and more established UI. (GTK doesn't
> implement -show-cursor at all, incidentally.)
>
> Peter Maydell (4):
>   ui/cocoa: Cope with first surface being same as initial window size
>   ui/cocoa: Add utility method to check if point is within window
>   ui/cocoa: Fix handling of absolute positioning devices
>   ui/cocoa: Honour -show-cursor command line option

I double-checked and none of these patches add new calls
to MacOSX functions (they're just fixing/rearranging logic) so
I don't expect this to break older versions (tested on 10.9).
I'm planning to send a cocoa.next pullreq with these in on Monday.

thanks
-- PMM



[Qemu-devel] [PATCH v2] tests: Functions bus_foreach and device_find from libqos virtio API

2014-06-29 Thread Marc Marí
Virtio header has been changed to compile and work with a real device.
Functions bus_foreach and device_find have been implemented for PCI.
Virtio-blk test case now opens a fake device.

Signed-off-by: Marc Marí 
---
 tests/Makefile|3 +-
 tests/libqos/virtio-pci.c |  127 +
 tests/libqos/virtio-pci.h |   33 
 tests/libqos/virtio.h |   57 
 tests/virtio-blk-test.c   |   65 ---
 5 files changed, 276 insertions(+), 9 deletions(-)
 create mode 100644 tests/libqos/virtio-pci.c
 create mode 100644 tests/libqos/virtio-pci.h
 create mode 100644 tests/libqos/virtio.h

diff --git a/tests/Makefile b/tests/Makefile
index 7e53d0d..028c462 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -292,6 +292,7 @@ libqos-obj-y += tests/libqos/i2c.o
 libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o
 libqos-pc-obj-y += tests/libqos/malloc-pc.o
 libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o
+libqos-virtio-obj-y = $(libqos-obj-y) $(libqos-pc-obj-y) 
tests/libqos/virtio-pci.o
 
 tests/rtc-test$(EXESUF): tests/rtc-test.o
 tests/m48t59-test$(EXESUF): tests/m48t59-test.o
@@ -312,7 +313,7 @@ tests/eepro100-test$(EXESUF): tests/eepro100-test.o
 tests/vmxnet3-test$(EXESUF): tests/vmxnet3-test.o
 tests/ne2000-test$(EXESUF): tests/ne2000-test.o
 tests/virtio-balloon-test$(EXESUF): tests/virtio-balloon-test.o
-tests/virtio-blk-test$(EXESUF): tests/virtio-blk-test.o
+tests/virtio-blk-test$(EXESUF): tests/virtio-blk-test.o $(libqos-virtio-obj-y)
 tests/virtio-net-test$(EXESUF): tests/virtio-net-test.o
 tests/virtio-rng-test$(EXESUF): tests/virtio-rng-test.o
 tests/virtio-scsi-test$(EXESUF): tests/virtio-scsi-test.o
diff --git a/tests/libqos/virtio-pci.c b/tests/libqos/virtio-pci.c
new file mode 100644
index 000..933cfdd
--- /dev/null
+++ b/tests/libqos/virtio-pci.c
@@ -0,0 +1,127 @@
+/*
+ * libqos virtio PCI driver
+ *
+ * Copyright (c) 2014 Marc Marí
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include 
+#include 
+#include "libqtest.h"
+#include "libqos/virtio.h"
+#include "libqos/virtio-pci.h"
+#include "libqos/pci.h"
+#include "libqos/pci-pc.h"
+
+#include "hw/pci/pci_regs.h"
+
+static QVirtioPCIDevice *qpcidevice_to_qvirtiodevice(QPCIDevice *pdev)
+{
+QVirtioPCIDevice *vpcidev;
+vpcidev = g_malloc0(sizeof(*vpcidev));
+
+if (pdev) {
+vpcidev->pdev = pdev;
+vpcidev->vdev.device_type =
+qpci_config_readw(vpcidev->pdev, PCI_SUBSYSTEM_ID);
+/* TODO: When QVirtQueue is defined, change for
+g_malloc0(sizeof(QVirtQueue)); */
+vpcidev->vdev.vq = NULL;
+}
+
+return vpcidev;
+}
+
+static void qvirtio_pci_foreach_callback(
+QPCIDevice *dev, int devfn, void *data)
+{
+QVirtioPCIForeachData *d = data;
+QVirtioPCIDevice *vpcidev = qpcidevice_to_qvirtiodevice(dev);
+
+if (vpcidev->vdev.device_type == d->device_type) {
+d->func(&vpcidev->vdev, d->user_data);
+}
+}
+
+static void qvirtio_pci_assign_device(QVirtioDevice *d, void *data)
+{
+QVirtioPCIDevice *vpcidev = data;
+vpcidev->pdev   = ((QVirtioPCIDevice *)d)->pdev;
+vpcidev->vdev.device_type   = ((QVirtioPCIDevice *)d)->vdev.device_type;
+vpcidev->vdev.vq= ((QVirtioPCIDevice *)d)->vdev.vq;
+}
+
+static void qvirtio_pci_notify(QVirtioDevice *d, uint16_t vector)
+{
+
+}
+
+static void qvirtio_pci_get_config(QVirtioDevice *d, void *config)
+{
+
+}
+
+static void qvirtio_pci_set_config(QVirtioDevice *d, void *config)
+{
+
+}
+
+static uint32_t qvirtio_pci_get_features(QVirtioDevice *d)
+{
+return 0;
+}
+
+static uint8_t qvirtio_pci_get_status(QVirtioDevice *d)
+{
+return 0;
+}
+
+static void qvirtio_pci_set_status(QVirtioDevice *d, uint8_t val)
+{
+
+}
+
+static void qvirtio_pci_reset(QVirtioDevice *d)
+{
+
+}
+
+static uint8_t qvirtio_pci_query_isr(QVirtioDevice *d)
+{
+return 0;
+}
+
+void qvirtio_pci_foreach(QPCIBus *bus, uint16_t device_type,
+void (*func)(QVirtioDevice *d, void *data), void *data)
+{
+QVirtioPCIForeachData d = { .func = func,
+.device_type = device_type,
+.user_data = data };
+
+qpci_device_foreach(bus, QVIRTIO_VENDOR_ID, -1,
+qvirtio_pci_foreach_callback, &d);
+}
+
+QVirtioPCIDevice *qvirtio_pci_device_find(QPCIBus *bus, uint16_t device_type)
+{
+QVirtioPCIDevice *dev;
+
+dev = g_malloc0(sizeof(*dev));
+qvirtio_pci_foreach(bus, device_type, qvirtio_pci_assign_device, dev);
+
+return dev;
+}
+
+const QVirtioBus qvirtio_pci = {
+.notify = qvirtio_pci_notify,
+.get_config = qvirtio_pci_get_config,
+.set_config = qvirtio_pci_set_config,
+.get_features = qvirtio_pci_get_features,
+.get_status = qvirtio_pci_get

Re: [Qemu-devel] [PULL 00/37] pc,vhost,virtio fixes, enhancements

2014-06-29 Thread Peter Maydell
On 29 June 2014 21:34, Michael S. Tsirkin  wrote:
> BTW, I notice that out of the multiple make check runs,
> one failed:
>
> https://travis-ci.org/qemu/qemu/jobs/28721760
>
> I'm guessing this is unrelated to the tree itself,
> this could be the race PM saw on arm manifesting on x86.
> we should try a ton of runs of make check onx86 and see
> whether the failure trigggers sometimes.

Travis does that "no output for 10 minutes" thing all the time
(including for things like "midway through compile" or "doing
a git checkout") so I basically ignore those "build has errored"
results as false positives. I assume their infrastructure is just
flaky (which is a shame for a continuous integration product).

thanks
-- PMM



Re: [Qemu-devel] [PULL 00/37] pc,vhost,virtio fixes, enhancements

2014-06-29 Thread Michael S. Tsirkin
On Sun, Jun 29, 2014 at 06:36:49PM +0100, Peter Maydell wrote:
> On 29 June 2014 17:58, Michael S. Tsirkin  wrote:
> > The following changes since commit 4daebe014effba37246b81d25acca5fa2df82f01:
> >
> >   Merge remote-tracking branch 'remotes/xtensa/tags/20140629-xtensa' into 
> > staging (2014-06-29 16:17:50 +0100)
> >
> > are available in the git repository at:
> >
> >   git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
> >
> > for you to fetch changes up to b4900c0e8a606bed834bd610fbae0fdf1d697ff9:
> >
> >   tests: add human format test for string output visitor (2014-06-29 
> > 19:39:43 +0300)
> 
> Applied, thanks.
> 
> -- PMM

BTW, I notice that out of the multiple make check runs,
one failed:

https://travis-ci.org/qemu/qemu/jobs/28721760

I'm guessing this is unrelated to the tree itself,
this could be the race PM saw on arm manifesting on x86.
we should try a ton of runs of make check onx86 and see
whether the failure trigggers sometimes.

-- 
MST



Re: [Qemu-devel] [PATCH FOR 2.1 1/5] tests/test-qmp-event: fix for GLib < 2.31

2014-06-29 Thread Peter Maydell
On 27 June 2014 19:28, Luiz Capitulino  wrote:
> On Wed, 25 Jun 2014 15:15:35 +0200
> Paolo Bonzini  wrote:
>
>> Il 25/06/2014 15:13, Luiz Capitulino ha scritto:
>> > On Tue, 24 Jun 2014 16:33:56 -0700
>> > Wenchao Xia  wrote:
>> >
>> >> From: Paolo Bonzini 
>> >>
>> >> On old GLib, the test needs a g_thread_init call.
>> >>
>> >> Reported-by: Wenchao Xia 
>> >> Signed-off-by: Paolo Bonzini 
>> >> Tested-by: Wenchao Xia 
>> >> Signed-off-by: Wenchao Xia 
>> >> ---
>> >>  tests/test-qmp-event.c |1 +
>> >>  1 files changed, 1 insertions(+), 0 deletions(-)
>> >>
>> >> diff --git a/tests/test-qmp-event.c b/tests/test-qmp-event.c
>> >> index cb1e441..17c6444 100644
>> >> --- a/tests/test-qmp-event.c
>> >> +++ b/tests/test-qmp-event.c
>> >> @@ -251,6 +251,7 @@ static void test_event_d(TestEventData *data,
>> >>
>> >>  int main(int argc, char **argv)
>> >>  {
>> >> +g_thread_init(NULL);
>> >>  qmp_event_set_func_emit(event_test_emit);
>> >>
>> >>  g_test_init(&argc, &argv, NULL);
>> >
>> > This breaks make check on F20:
>> >
>> > """
>> > /home/lcapitulino/work/src/upstream/qmp-unstable/tests/test-qmp-event.c: 
>> > In function ‘main’:
>> > /home/lcapitulino/work/src/upstream/qmp-unstable/tests/test-qmp-event.c:254:5:
>> >  error: ‘g_thread_init’ is deprecated (declared at 
>> > /usr/include/glib-2.0/glib/deprecated/gthread.h:260) 
>> > [-Werror=deprecated-declarations]
>> >  g_thread_init(NULL);
>> >  ^
>> > cc1: all warnings being treated as errors
>> > make: *** [tests/test-qmp-event.o] Error 1
>> > """
>> >
>> > I think the best way to fix this is to make util/osdep.c:thread_init()
>> > public (maybe by moving it to include/glib-compat.h) and use that instead.
>> > Also, note that thread_init()'s body is duplicated in a few other places,
>> > so maybe those places should call it too.
>> >
>> > You may want to do this in a different series, then I can skip this patch
>> > and apply the rest of the series.
>> >
>>
>> Thanks Luiz, it's a good suggestion.
>
> Paolo, Wenchao, are one of one going to work on this?

Ping! Can we have at least a local fix using glib version #ifdefs before
Tuesday please? Otherwise we need to do something like this
to avoid shipping an rc0 which doesn't pass make check on some
systems.

diff --git a/tests/Makefile b/tests/Makefile
index 7e53d0d..a1a0dae 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -27,8 +27,6 @@ check-unit-y += tests/test-string-input-visitor$(EXESUF)
 gcov-files-test-string-input-visitor-y = qapi/string-input-visitor.c
 check-unit-y += tests/test-string-output-visitor$(EXESUF)
 gcov-files-test-string-output-visitor-y = qapi/string-output-visitor.c
-check-unit-y += tests/test-qmp-event$(EXESUF)
-gcov-files-test-qmp-event-y += qapi/qmp-event.c
 check-unit-y += tests/test-opts-visitor$(EXESUF)
 gcov-files-test-opts-visitor-y = qapi/opts-visitor.c
 check-unit-y += tests/test-coroutine$(EXESUF)
@@ -213,7 +211,7 @@ test-obj-y = tests/check-qint.o
tests/check-qstring.o tests/check-qdict.o \
tests/test-qmp-input-visitor.o tests/test-qmp-input-strict.o \
tests/test-qmp-commands.o tests/test-visitor-serialization.o \
tests/test-x86-cpuid.o tests/test-mul64.o tests/test-int128.o \
-   tests/test-opts-visitor.o tests/test-qmp-event.o
+   tests/test-opts-visitor.o

 test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \
   tests/test-qapi-event.o

thanks
-- PMM



[Qemu-devel] [PULL 24/37] exec: introduce target_words_bigendian() helper

2014-06-29 Thread Michael S. Tsirkin
From: Greg Kurz 

We currently have a virtio_is_big_endian() helper that provides the target
endianness to the virtio code. As of today, the helper returns a fixed
compile-time value. Of course, this will have to change if we want to
support target endianness changes at run-time.

Let's move the TARGET_WORDS_BIGENDIAN bits out to a new helper and have
virtio_is_big_endian() implemented on top of it.

This patch doesn't change any functionality.

Signed-off-by: Greg Kurz 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 include/hw/virtio/virtio.h | 6 ++
 exec.c | 8 ++--
 hw/virtio/virtio-pci.c | 3 ---
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 3505ce5..9000ee2 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -255,4 +255,10 @@ void virtio_queue_set_host_notifier_fd_handler(VirtQueue 
*vq, bool assign,
bool set_handler);
 void virtio_queue_notify_vq(VirtQueue *vq);
 void virtio_irq(VirtQueue *vq);
+
+bool target_words_bigendian(void);
+static inline bool virtio_is_big_endian(void)
+{
+return target_words_bigendian();
+}
 #endif
diff --git a/exec.c b/exec.c
index a94c583..18d6c35 100644
--- a/exec.c
+++ b/exec.c
@@ -2759,14 +2759,12 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong 
addr,
 }
 #endif
 
-#if !defined(CONFIG_USER_ONLY)
-
 /*
  * A helper function for the _utterly broken_ virtio device model to find out 
if
  * it's running on a big endian machine. Don't do this at home kids!
  */
-bool virtio_is_big_endian(void);
-bool virtio_is_big_endian(void)
+bool target_words_bigendian(void);
+bool target_words_bigendian(void)
 {
 #if defined(TARGET_WORDS_BIGENDIAN)
 return true;
@@ -2775,8 +2773,6 @@ bool virtio_is_big_endian(void)
 #endif
 }
 
-#endif
-
 #ifndef CONFIG_USER_ONLY
 bool cpu_physical_memory_is_io(hwaddr phys_addr)
 {
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 57e1e61..e11f759 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -89,9 +89,6 @@
 /* Flags track per-device state like workarounds for quirks in older guests. */
 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG  (1 << 0)
 
-/* HACK for virtio to determine if it's running a big endian guest */
-bool virtio_is_big_endian(void);
-
 static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
VirtIOPCIProxy *dev);
 
-- 
MST




[Qemu-devel] [PULL 12/37] numa: Reject configuration if not all node IDs are present

2014-06-29 Thread Michael S. Tsirkin
From: Eduardo Habkost 

We don't support sparse NUMA node IDs yet, so this changes QEMU to
reject configs where not all nodes are present.

Signed-off-by: Eduardo Habkost 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
Reviewed-by: Eric Blake 
---
 numa.c | 17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/numa.c b/numa.c
index c254127..2fde740 100644
--- a/numa.c
+++ b/numa.c
@@ -160,9 +160,24 @@ error:
 
 void set_numa_nodes(void)
 {
+int i;
+
+assert(max_numa_nodeid <= MAX_NODES);
+
+/* No support for sparse NUMA node IDs yet: */
+for (i = max_numa_nodeid - 1; i >= 0; i--) {
+/* Report large node IDs first, to make mistakes easier to spot */
+if (!numa_info[i].present) {
+error_report("numa: Node ID missing: %d", i);
+exit(1);
+}
+}
+
+/* This must be always true if all nodes are present: */
+assert(nb_numa_nodes == max_numa_nodeid);
+
 if (nb_numa_nodes > 0) {
 uint64_t numa_total;
-int i;
 
 if (nb_numa_nodes > MAX_NODES) {
 nb_numa_nodes = MAX_NODES;
-- 
MST




[Qemu-devel] [PULL 21/37] virtio-balloon: implement per-device migration calls

2014-06-29 Thread Michael S. Tsirkin
From: Greg Kurz 

Signed-off-by: Greg Kurz 
Reviewed-by: Alexander Graf 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/virtio/virtio-balloon.c | 25 ++---
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index 165592e..e0ed5ee 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -325,10 +325,12 @@ static void virtio_balloon_to_target(void *opaque, 
ram_addr_t target)
 
 static void virtio_balloon_save(QEMUFile *f, void *opaque)
 {
-VirtIOBalloon *s = VIRTIO_BALLOON(opaque);
-VirtIODevice *vdev = VIRTIO_DEVICE(s);
+virtio_save(VIRTIO_DEVICE(opaque), f);
+}
 
-virtio_save(vdev, f);
+static void virtio_balloon_save_device(VirtIODevice *vdev, QEMUFile *f)
+{
+VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
 
 qemu_put_be32(f, s->num_pages);
 qemu_put_be32(f, s->actual);
@@ -336,17 +338,16 @@ static void virtio_balloon_save(QEMUFile *f, void *opaque)
 
 static int virtio_balloon_load(QEMUFile *f, void *opaque, int version_id)
 {
-VirtIOBalloon *s = VIRTIO_BALLOON(opaque);
-VirtIODevice *vdev = VIRTIO_DEVICE(s);
-int ret;
-
 if (version_id != 1)
 return -EINVAL;
 
-ret = virtio_load(vdev, f, version_id);
-if (ret) {
-return ret;
-}
+return virtio_load(VIRTIO_DEVICE(opaque), f, version_id);
+}
+
+static int virtio_balloon_load_device(VirtIODevice *vdev, QEMUFile *f,
+  int version_id)
+{
+VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
 
 s->num_pages = qemu_get_be32(f);
 s->actual = qemu_get_be32(f);
@@ -416,6 +417,8 @@ static void virtio_balloon_class_init(ObjectClass *klass, 
void *data)
 vdc->get_config = virtio_balloon_get_config;
 vdc->set_config = virtio_balloon_set_config;
 vdc->get_features = virtio_balloon_get_features;
+vdc->save = virtio_balloon_save_device;
+vdc->load = virtio_balloon_load_device;
 }
 
 static const TypeInfo virtio_balloon_info = {
-- 
MST




[Qemu-devel] [PULL 32/37] virtio-scsi: use virtio wrappers to access headers

2014-06-29 Thread Michael S. Tsirkin
From: Rusty Russell 

Note that st*_raw and ld*_raw are effectively replaced by st*_p and ld*_p.

Signed-off-by: Rusty Russell 
Reviewed-by: Anthony Liguori 
[ pass VirtIODevice * to memory accessors,
  converted new tswap locations to virtio_tswap,
  Greg Kurz  ]
Signed-off-by: Greg Kurz 
Reviewed-by: Alexander Graf 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/scsi/virtio-scsi.c | 38 --
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 6b4fd6f..04ecfa7 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include "hw/virtio/virtio-access.h"
 
 typedef struct VirtIOSCSIReq {
 VirtIOSCSI *dev;
@@ -235,7 +236,7 @@ static void virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq 
*req)
 /* Here VIRTIO_SCSI_S_OK means "FUNCTION COMPLETE".  */
 req->resp.tmf.response = VIRTIO_SCSI_S_OK;
 
-tswap32s(&req->req.tmf.subtype);
+virtio_tswap32s(VIRTIO_DEVICE(s), &req->req.tmf.subtype);
 switch (req->req.tmf.subtype) {
 case VIRTIO_SCSI_T_TMF_ABORT_TASK:
 case VIRTIO_SCSI_T_TMF_QUERY_TASK:
@@ -346,7 +347,7 @@ static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, 
VirtQueue *vq)
 continue;
 }
 
-tswap32s(&req->req.tmf.type);
+virtio_tswap32s(vdev, &req->req.tmf.type);
 if (req->req.tmf.type == VIRTIO_SCSI_T_TMF) {
 if (virtio_scsi_parse_req(req, sizeof(VirtIOSCSICtrlTMFReq),
   sizeof(VirtIOSCSICtrlTMFResp)) < 0) {
@@ -384,6 +385,7 @@ static void virtio_scsi_command_complete(SCSIRequest *r, 
uint32_t status,
 VirtIOSCSIReq *req = r->hba_private;
 uint8_t sense[SCSI_SENSE_BUF_SIZE];
 uint32_t sense_len;
+VirtIODevice *vdev = VIRTIO_DEVICE(req->dev);
 
 if (r->io_canceled) {
 return;
@@ -392,14 +394,14 @@ static void virtio_scsi_command_complete(SCSIRequest *r, 
uint32_t status,
 req->resp.cmd.response = VIRTIO_SCSI_S_OK;
 req->resp.cmd.status = status;
 if (req->resp.cmd.status == GOOD) {
-req->resp.cmd.resid = tswap32(resid);
+req->resp.cmd.resid = virtio_tswap32(vdev, resid);
 } else {
 req->resp.cmd.resid = 0;
 sense_len = scsi_req_get_sense(r, sense, sizeof(sense));
 sense_len = MIN(sense_len, req->resp_iov.size - sizeof(req->resp.cmd));
 qemu_iovec_from_buf(&req->resp_iov, sizeof(req->resp.cmd),
 &req->resp, sense_len);
-req->resp.cmd.sense_len = tswap32(sense_len);
+req->resp.cmd.sense_len = virtio_tswap32(vdev, sense_len);
 }
 virtio_scsi_complete_cmd_req(req);
 }
@@ -487,16 +489,16 @@ static void virtio_scsi_get_config(VirtIODevice *vdev,
 VirtIOSCSIConfig *scsiconf = (VirtIOSCSIConfig *)config;
 VirtIOSCSICommon *s = VIRTIO_SCSI_COMMON(vdev);
 
-stl_p(&scsiconf->num_queues, s->conf.num_queues);
-stl_p(&scsiconf->seg_max, 128 - 2);
-stl_p(&scsiconf->max_sectors, s->conf.max_sectors);
-stl_p(&scsiconf->cmd_per_lun, s->conf.cmd_per_lun);
-stl_p(&scsiconf->event_info_size, sizeof(VirtIOSCSIEvent));
-stl_p(&scsiconf->sense_size, s->sense_size);
-stl_p(&scsiconf->cdb_size, s->cdb_size);
-stw_p(&scsiconf->max_channel, VIRTIO_SCSI_MAX_CHANNEL);
-stw_p(&scsiconf->max_target, VIRTIO_SCSI_MAX_TARGET);
-stl_p(&scsiconf->max_lun, VIRTIO_SCSI_MAX_LUN);
+virtio_stl_p(vdev, &scsiconf->num_queues, s->conf.num_queues);
+virtio_stl_p(vdev, &scsiconf->seg_max, 128 - 2);
+virtio_stl_p(vdev, &scsiconf->max_sectors, s->conf.max_sectors);
+virtio_stl_p(vdev, &scsiconf->cmd_per_lun, s->conf.cmd_per_lun);
+virtio_stl_p(vdev, &scsiconf->event_info_size, sizeof(VirtIOSCSIEvent));
+virtio_stl_p(vdev, &scsiconf->sense_size, s->sense_size);
+virtio_stl_p(vdev, &scsiconf->cdb_size, s->cdb_size);
+virtio_stw_p(vdev, &scsiconf->max_channel, VIRTIO_SCSI_MAX_CHANNEL);
+virtio_stw_p(vdev, &scsiconf->max_target, VIRTIO_SCSI_MAX_TARGET);
+virtio_stl_p(vdev, &scsiconf->max_lun, VIRTIO_SCSI_MAX_LUN);
 }
 
 static void virtio_scsi_set_config(VirtIODevice *vdev,
@@ -505,14 +507,14 @@ static void virtio_scsi_set_config(VirtIODevice *vdev,
 VirtIOSCSIConfig *scsiconf = (VirtIOSCSIConfig *)config;
 VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
 
-if ((uint32_t) ldl_p(&scsiconf->sense_size) >= 65536 ||
-(uint32_t) ldl_p(&scsiconf->cdb_size) >= 256) {
+if ((uint32_t) virtio_ldl_p(vdev, &scsiconf->sense_size) >= 65536 ||
+(uint32_t) virtio_ldl_p(vdev, &scsiconf->cdb_size) >= 256) {
 error_report("bad data written to virtio-scsi configuration space");
 exit(1);
 }
 
-vs->sense_size = ldl_p(&scsiconf->sense_size);
-vs->cdb_size = ldl_p(&scsiconf->cdb_size);
+vs->sense_size = virtio_ldl_p(vdev, &scsiconf->sense_size);
+vs->cdb_size = virtio_ldl_p(vdev, 

[Qemu-devel] [PULL 31/37] virtio-blk: use virtio wrappers to access headers

2014-06-29 Thread Michael S. Tsirkin
From: Rusty Russell 

Note that st*_raw and ld*_raw are effectively replaced by st*_p and ld*_p.

Signed-off-by: Rusty Russell 
Reviewed-by: Anthony Liguori 
[ pass VirtIODevice * to memory accessors,
  Greg Kurz  ]
Signed-off-by: Greg Kurz 
Reviewed-by: Alexander Graf 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/block/virtio-blk.c | 38 +-
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index b06af8c..e59ebc9 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -27,6 +27,7 @@
 # include 
 #endif
 #include "hw/virtio/virtio-bus.h"
+#include "hw/virtio/virtio-access.h"
 
 static VirtIOBlockReq *virtio_blk_alloc_request(VirtIOBlock *s)
 {
@@ -88,7 +89,8 @@ static void virtio_blk_rw_complete(void *opaque, int ret)
 trace_virtio_blk_rw_complete(req, ret);
 
 if (ret) {
-bool is_read = !(ldl_p(&req->out.type) & VIRTIO_BLK_T_OUT);
+int p = virtio_ldl_p(VIRTIO_DEVICE(req->dev), &req->out.type);
+bool is_read = !(p & VIRTIO_BLK_T_OUT);
 if (virtio_blk_handle_rw_error(req, -ret, is_read))
 return;
 }
@@ -130,6 +132,8 @@ int virtio_blk_handle_scsi_req(VirtIOBlock *blk,
 {
 int status = VIRTIO_BLK_S_OK;
 struct virtio_scsi_inhdr *scsi = NULL;
+VirtIODevice *vdev = VIRTIO_DEVICE(blk);
+
 #ifdef __linux__
 int i;
 struct sg_io_hdr hdr;
@@ -224,12 +228,12 @@ int virtio_blk_handle_scsi_req(VirtIOBlock *blk,
 hdr.status = CHECK_CONDITION;
 }
 
-stl_p(&scsi->errors,
-  hdr.status | (hdr.msg_status << 8) |
-  (hdr.host_status << 16) | (hdr.driver_status << 24));
-stl_p(&scsi->residual, hdr.resid);
-stl_p(&scsi->sense_len, hdr.sb_len_wr);
-stl_p(&scsi->data_len, hdr.dxfer_len);
+virtio_stl_p(vdev, &scsi->errors,
+ hdr.status | (hdr.msg_status << 8) |
+ (hdr.host_status << 16) | (hdr.driver_status << 24));
+virtio_stl_p(vdev, &scsi->residual, hdr.resid);
+virtio_stl_p(vdev, &scsi->sense_len, hdr.sb_len_wr);
+virtio_stl_p(vdev, &scsi->data_len, hdr.dxfer_len);
 
 return status;
 #else
@@ -239,7 +243,7 @@ int virtio_blk_handle_scsi_req(VirtIOBlock *blk,
 fail:
 /* Just put anything nonzero so that the ioctl fails in the guest.  */
 if (scsi) {
-stl_p(&scsi->errors, 255);
+virtio_stl_p(vdev, &scsi->errors, 255);
 }
 return status;
 }
@@ -289,7 +293,7 @@ static void virtio_blk_handle_write(VirtIOBlockReq *req, 
MultiReqBuffer *mrb)
 BlockRequest *blkreq;
 uint64_t sector;
 
-sector = ldq_p(&req->out.sector);
+sector = virtio_ldq_p(VIRTIO_DEVICE(req->dev), &req->out.sector);
 
 bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BDRV_ACCT_WRITE);
 
@@ -323,7 +327,7 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req)
 {
 uint64_t sector;
 
-sector = ldq_p(&req->out.sector);
+sector = virtio_ldq_p(VIRTIO_DEVICE(req->dev), &req->out.sector);
 
 bdrv_acct_start(req->dev->bs, &req->acct, req->qiov.size, BDRV_ACCT_READ);
 
@@ -374,7 +378,7 @@ void virtio_blk_handle_request(VirtIOBlockReq *req, 
MultiReqBuffer *mrb)
   - sizeof(struct virtio_blk_inhdr);
 iov_discard_back(in_iov, &in_num, sizeof(struct virtio_blk_inhdr));
 
-type = ldl_p(&req->out.type);
+type = virtio_ldl_p(VIRTIO_DEVICE(req->dev), &req->out.type);
 
 if (type & VIRTIO_BLK_T_FLUSH) {
 virtio_blk_handle_flush(req, mrb);
@@ -504,12 +508,12 @@ static void virtio_blk_update_config(VirtIODevice *vdev, 
uint8_t *config)
 
 bdrv_get_geometry(s->bs, &capacity);
 memset(&blkcfg, 0, sizeof(blkcfg));
-stq_p(&blkcfg.capacity, capacity);
-stl_p(&blkcfg.seg_max, 128 - 2);
-stw_p(&blkcfg.cylinders, s->conf->cyls);
-stl_p(&blkcfg.blk_size, blk_size);
-stw_p(&blkcfg.min_io_size, s->conf->min_io_size / blk_size);
-stw_p(&blkcfg.opt_io_size, s->conf->opt_io_size / blk_size);
+virtio_stq_p(vdev, &blkcfg.capacity, capacity);
+virtio_stl_p(vdev, &blkcfg.seg_max, 128 - 2);
+virtio_stw_p(vdev, &blkcfg.cylinders, s->conf->cyls);
+virtio_stl_p(vdev, &blkcfg.blk_size, blk_size);
+virtio_stw_p(vdev, &blkcfg.min_io_size, s->conf->min_io_size / blk_size);
+virtio_stw_p(vdev, &blkcfg.opt_io_size, s->conf->opt_io_size / blk_size);
 blkcfg.heads = s->conf->heads;
 /*
  * We must ensure that the block device capacity is a multiple of
-- 
MST




[Qemu-devel] [PULL 27/37] virtio: memory accessors for endian-ambivalent targets

2014-06-29 Thread Michael S. Tsirkin
From: Greg Kurz 

This is the virtio-access.h header file taken from Rusty's "endian-ambivalent
targets using legacy virtio" patch. It introduces helpers that should be used
when accessing vring data or by drivers for data that contains headers.
The virtio config space is also target endian, but the current code already
handles that with the virtio_is_big_endian() helper. There is no obvious
benefit at using the virtio accessors in this case.

Now we have two distinct paths: a fast inline one for fixed endian targets,
and a slow out-of-line one for targets that define the new TARGET_IS_BIENDIAN
macro.

Signed-off-by: Rusty Russell 
[ relicensed virtio-access.h to GPLv2+ on Rusty's request,
  pass &address_space_memory to physical memory accessors,
  per-device endianness,
  virtio tswap16 and tswap64 helpers,
  faspath for fixed endian targets,
  Greg Kurz  ]
Cc: Cédric Le Goater 
Signed-off-by: Greg Kurz 
Reviewed-by: Alexander Graf 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 include/hw/virtio/virtio-access.h | 170 ++
 1 file changed, 170 insertions(+)
 create mode 100644 include/hw/virtio/virtio-access.h

diff --git a/include/hw/virtio/virtio-access.h 
b/include/hw/virtio/virtio-access.h
new file mode 100644
index 000..46456fd
--- /dev/null
+++ b/include/hw/virtio/virtio-access.h
@@ -0,0 +1,170 @@
+/*
+ * Virtio Accessor Support: In case your target can change endian.
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Rusty Russell   
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ */
+#ifndef _QEMU_VIRTIO_ACCESS_H
+#define _QEMU_VIRTIO_ACCESS_H
+#include "hw/virtio/virtio.h"
+#include "exec/address-spaces.h"
+
+static inline bool virtio_access_is_big_endian(VirtIODevice *vdev)
+{
+#if defined(TARGET_IS_BIENDIAN)
+return virtio_is_big_endian(vdev);
+#elif defined(TARGET_WORDS_BIGENDIAN)
+return true;
+#else
+return false;
+#endif
+}
+
+static inline uint16_t virtio_lduw_phys(VirtIODevice *vdev, hwaddr pa)
+{
+if (virtio_access_is_big_endian(vdev)) {
+return lduw_be_phys(&address_space_memory, pa);
+}
+return lduw_le_phys(&address_space_memory, pa);
+}
+
+static inline uint32_t virtio_ldl_phys(VirtIODevice *vdev, hwaddr pa)
+{
+if (virtio_access_is_big_endian(vdev)) {
+return ldl_be_phys(&address_space_memory, pa);
+}
+return ldl_le_phys(&address_space_memory, pa);
+}
+
+static inline uint64_t virtio_ldq_phys(VirtIODevice *vdev, hwaddr pa)
+{
+if (virtio_access_is_big_endian(vdev)) {
+return ldq_be_phys(&address_space_memory, pa);
+}
+return ldq_le_phys(&address_space_memory, pa);
+}
+
+static inline void virtio_stw_phys(VirtIODevice *vdev, hwaddr pa,
+   uint16_t value)
+{
+if (virtio_access_is_big_endian(vdev)) {
+stw_be_phys(&address_space_memory, pa, value);
+} else {
+stw_le_phys(&address_space_memory, pa, value);
+}
+}
+
+static inline void virtio_stl_phys(VirtIODevice *vdev, hwaddr pa,
+   uint32_t value)
+{
+if (virtio_access_is_big_endian(vdev)) {
+stl_be_phys(&address_space_memory, pa, value);
+} else {
+stl_le_phys(&address_space_memory, pa, value);
+}
+}
+
+static inline void virtio_stw_p(VirtIODevice *vdev, void *ptr, uint16_t v)
+{
+if (virtio_access_is_big_endian(vdev)) {
+stw_be_p(ptr, v);
+} else {
+stw_le_p(ptr, v);
+}
+}
+
+static inline void virtio_stl_p(VirtIODevice *vdev, void *ptr, uint32_t v)
+{
+if (virtio_access_is_big_endian(vdev)) {
+stl_be_p(ptr, v);
+} else {
+stl_le_p(ptr, v);
+}
+}
+
+static inline void virtio_stq_p(VirtIODevice *vdev, void *ptr, uint64_t v)
+{
+if (virtio_access_is_big_endian(vdev)) {
+stq_be_p(ptr, v);
+} else {
+stq_le_p(ptr, v);
+}
+}
+
+static inline int virtio_lduw_p(VirtIODevice *vdev, const void *ptr)
+{
+if (virtio_access_is_big_endian(vdev)) {
+return lduw_be_p(ptr);
+} else {
+return lduw_le_p(ptr);
+}
+}
+
+static inline int virtio_ldl_p(VirtIODevice *vdev, const void *ptr)
+{
+if (virtio_access_is_big_endian(vdev)) {
+return ldl_be_p(ptr);
+} else {
+return ldl_le_p(ptr);
+}
+}
+
+static inline uint64_t virtio_ldq_p(VirtIODevice *vdev, const void *ptr)
+{
+if (virtio_access_is_big_endian(vdev)) {
+return ldq_be_p(ptr);
+} else {
+return ldq_le_p(ptr);
+}
+}
+
+static inline uint16_t virtio_tswap16(VirtIODevice *vdev, uint16_t s)
+{
+#ifdef HOST_WORDS_BIGENDIAN
+return virtio_access_is_big_endian(vdev) ? s : bswap16(s);
+#else
+return virtio_access_is_big_endian(vdev) ? bswap16(s) : s;
+#endif
+}

[Qemu-devel] [PULL 26/37] virtio: add endian-ambivalent support to VirtIODevice

2014-06-29 Thread Michael S. Tsirkin
From: Greg Kurz 

Some CPU families can dynamically change their endianness. This means we
can have little endian ppc or big endian arm guests for example. This has
an impact on legacy virtio data structures since they are target endian.
We hence introduce a new property to track the endianness of each virtio
device. It is reasonnably assumed that endianness won't change while the
device is in use : we hence capture the device endianness when it gets
reset.

We migrate this property in a subsection, after the device descriptor. This
means the load code must not rely on it until it is restored. As a consequence,
the vring sanity checks had to be moved after the call to vmstate_load_state().
We enforce paranoia by poisoning the property at the begining of virtio_load().

Signed-off-by: Greg Kurz 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 include/hw/virtio/virtio.h | 13 --
 hw/virtio/virtio-pci.c |  8 ++--
 hw/virtio/virtio.c | 99 --
 3 files changed, 101 insertions(+), 19 deletions(-)

diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 9000ee2..a60104c 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -104,6 +104,12 @@ typedef struct VirtQueueElement
 #define VIRTIO_DEVICE(obj) \
 OBJECT_CHECK(VirtIODevice, (obj), TYPE_VIRTIO_DEVICE)
 
+enum virtio_device_endian {
+VIRTIO_DEVICE_ENDIAN_UNKNOWN,
+VIRTIO_DEVICE_ENDIAN_LITTLE,
+VIRTIO_DEVICE_ENDIAN_BIG,
+};
+
 struct VirtIODevice
 {
 DeviceState parent_obj;
@@ -121,6 +127,7 @@ struct VirtIODevice
 bool vm_running;
 VMChangeStateEntry *vmstate;
 char *bus_name;
+uint8_t device_endian;
 };
 
 typedef struct VirtioDeviceClass {
@@ -256,9 +263,9 @@ void virtio_queue_set_host_notifier_fd_handler(VirtQueue 
*vq, bool assign,
 void virtio_queue_notify_vq(VirtQueue *vq);
 void virtio_irq(VirtQueue *vq);
 
-bool target_words_bigendian(void);
-static inline bool virtio_is_big_endian(void)
+static inline bool virtio_is_big_endian(VirtIODevice *vdev)
 {
-return target_words_bigendian();
+assert(vdev->device_endian != VIRTIO_DEVICE_ENDIAN_UNKNOWN);
+return vdev->device_endian == VIRTIO_DEVICE_ENDIAN_BIG;
 }
 #endif
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index e11f759..317324f 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -406,13 +406,13 @@ static uint64_t virtio_pci_config_read(void *opaque, 
hwaddr addr,
 break;
 case 2:
 val = virtio_config_readw(vdev, addr);
-if (virtio_is_big_endian()) {
+if (virtio_is_big_endian(vdev)) {
 val = bswap16(val);
 }
 break;
 case 4:
 val = virtio_config_readl(vdev, addr);
-if (virtio_is_big_endian()) {
+if (virtio_is_big_endian(vdev)) {
 val = bswap32(val);
 }
 break;
@@ -440,13 +440,13 @@ static void virtio_pci_config_write(void *opaque, hwaddr 
addr,
 virtio_config_writeb(vdev, addr, val);
 break;
 case 2:
-if (virtio_is_big_endian()) {
+if (virtio_is_big_endian(vdev)) {
 val = bswap16(val);
 }
 virtio_config_writew(vdev, addr, val);
 break;
 case 4:
-if (virtio_is_big_endian()) {
+if (virtio_is_big_endian(vdev)) {
 val = bswap32(val);
 }
 virtio_config_writel(vdev, addr, val);
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 7b317ce..a0676e0 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -545,6 +545,27 @@ void virtio_set_status(VirtIODevice *vdev, uint8_t val)
 vdev->status = val;
 }
 
+bool target_words_bigendian(void);
+static enum virtio_device_endian virtio_default_endian(void)
+{
+if (target_words_bigendian()) {
+return VIRTIO_DEVICE_ENDIAN_BIG;
+} else {
+return VIRTIO_DEVICE_ENDIAN_LITTLE;
+}
+}
+
+static enum virtio_device_endian virtio_current_cpu_endian(void)
+{
+CPUClass *cc = CPU_GET_CLASS(current_cpu);
+
+if (cc->virtio_is_big_endian(current_cpu)) {
+return VIRTIO_DEVICE_ENDIAN_BIG;
+} else {
+return VIRTIO_DEVICE_ENDIAN_LITTLE;
+}
+}
+
 void virtio_reset(void *opaque)
 {
 VirtIODevice *vdev = opaque;
@@ -552,6 +573,13 @@ void virtio_reset(void *opaque)
 int i;
 
 virtio_set_status(vdev, 0);
+if (current_cpu) {
+/* Guest initiated reset */
+vdev->device_endian = virtio_current_cpu_endian();
+} else {
+/* System reset */
+vdev->device_endian = virtio_default_endian();
+}
 
 if (k->reset) {
 k->reset(vdev);
@@ -840,6 +868,24 @@ void virtio_notify_config(VirtIODevice *vdev)
 virtio_notify_vector(vdev, vdev->config_vector);
 }
 
+static bool virtio_device_endian_needed(void *opaque)
+{
+VirtIODevice *vdev = opaque;
+
+assert(vdev->device_endian != VIRTIO_DEVICE_ENDIAN_UNKNOWN);
+return vdev->d

[Qemu-devel] [PATCH] ahci.c: mask unused flags when reading size PRDT DBC

2014-06-29 Thread reza . jelveh
This requires a custom ovmf image with sata controller for testing [0]

[0]: http://reza.jelveh.me/assets/OVMF.fd.bz2




[Qemu-devel] [PATCH] ahci.c: mask unused flags when reading size PRDT DBC

2014-06-29 Thread reza . jelveh
From: Reza Jelveh 

The data byte count(DBC) read from the description information is defined for
21:00. 30:22 are reserved and 31 is the Interrupt on Completion (I) flag.

Interrupt is not implemented in QEMU. tbl_entry_size is a signed integer and
improperly reading the DBC leads to a negative offset that causes sglist
allocation to fail.

Signed-off-by: Reza Jelveh 
---
 hw/ide/ahci.c | 12 +---
 hw/ide/ahci.h |  2 ++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index 9bae22e..93aa981 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -639,6 +639,12 @@ static void ahci_write_fis_d2h(AHCIDevice *ad, uint8_t 
*cmd_fis)
 }
 }
 
+static int prdt_tbl_entry_size(const AHCI_SG tbl)
+{
+return (le32_to_cpu(tbl.flags_size) & AHCI_PRDT_SIZE_MASK) + 1;
+}
+
+
 static int ahci_populate_sglist(AHCIDevice *ad, QEMUSGList *sglist, int offset)
 {
 AHCICmdHdr *cmd = ad->cur_cmd;
@@ -681,7 +687,7 @@ static int ahci_populate_sglist(AHCIDevice *ad, QEMUSGList 
*sglist, int offset)
 sum = 0;
 for (i = 0; i < sglist_alloc_hint; i++) {
 /* flags_size is zero-based */
-tbl_entry_size = (le32_to_cpu(tbl[i].flags_size) + 1);
+tbl_entry_size = prdt_tbl_entry_size(tbl[i]);
 if (offset <= (sum + tbl_entry_size)) {
 off_idx = i;
 off_pos = offset - sum;
@@ -700,12 +706,12 @@ static int ahci_populate_sglist(AHCIDevice *ad, 
QEMUSGList *sglist, int offset)
 qemu_sglist_init(sglist, qbus->parent, (sglist_alloc_hint - off_idx),
  ad->hba->as);
 qemu_sglist_add(sglist, le64_to_cpu(tbl[off_idx].addr + off_pos),
-le32_to_cpu(tbl[off_idx].flags_size) + 1 - off_pos);
+prdt_tbl_entry_size(tbl[off_idx]) - off_pos);
 
 for (i = off_idx + 1; i < sglist_alloc_hint; i++) {
 /* flags_size is zero-based */
 qemu_sglist_add(sglist, le64_to_cpu(tbl[i].addr),
-le32_to_cpu(tbl[i].flags_size) + 1);
+prdt_tbl_entry_size(tbl[i]));
 }
 }
 
diff --git a/hw/ide/ahci.h b/hw/ide/ahci.h
index 9a4064f..f418b30 100644
--- a/hw/ide/ahci.h
+++ b/hw/ide/ahci.h
@@ -201,6 +201,8 @@
 
 #define AHCI_COMMAND_TABLE_ACMD0x40
 
+#define AHCI_PRDT_SIZE_MASK0x3f
+
 #define IDE_FEATURE_DMA1
 
 #define READ_FPDMA_QUEUED  0x60
-- 
1.9.2




[Qemu-devel] [PULL 14/37] vhost-user: typo fixups

2014-06-29 Thread Michael S. Tsirkin
Fix typo in field name.
Strip two consequitive empty lines.

Signed-off-by: Michael S. Tsirkin 
---
 docs/specs/vhost-user.txt | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt
index 6abb697..650bb18 100644
--- a/docs/specs/vhost-user.txt
+++ b/docs/specs/vhost-user.txt
@@ -85,8 +85,7 @@ Depending on the request type, payload can be:
Guest address: a 64-bit guest address of the region
Size: a 64-bit size
User address: a 64-bit user address
-   mmmap offset: 64-bit offset where region starts in the mapped memory
-
+   mmap offset: 64-bit offset where region starts in the mapped memory
 
 In QEMU the vhost-user message is implemented with the following struct:
 
-- 
MST




[Qemu-devel] [PULL 34/37] virtio-9p: use virtio wrappers to access headers

2014-06-29 Thread Michael S. Tsirkin
From: Greg Kurz 

Note that st*_raw and ld*_raw are effectively replaced by st*_p and ld*_p.

Signed-off-by: Greg Kurz 
Reviewed-by: Alexander Graf 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/9pfs/virtio-9p-device.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 653762a..2572747 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -19,6 +19,7 @@
 #include "fsdev/qemu-fsdev.h"
 #include "virtio-9p-xattr.h"
 #include "virtio-9p-coth.h"
+#include "hw/virtio/virtio-access.h"
 
 static uint32_t virtio_9p_get_features(VirtIODevice *vdev, uint32_t features)
 {
@@ -34,7 +35,7 @@ static void virtio_9p_get_config(VirtIODevice *vdev, uint8_t 
*config)
 
 len = strlen(s->tag);
 cfg = g_malloc0(sizeof(struct virtio_9p_config) + len);
-stw_p(&cfg->tag_len, len);
+virtio_stw_p(vdev, &cfg->tag_len, len);
 /* We don't copy the terminating null to config space */
 memcpy(cfg->tag, s->tag, len);
 memcpy(config, cfg, s->config_size);
-- 
MST




[Qemu-devel] [PULL 11/37] numa: Reject duplicate node IDs

2014-06-29 Thread Michael S. Tsirkin
From: Eduardo Habkost 

The same nodeid shouldn't appear multiple times in the command-line.

In addition to detecting command-line mistakes, this will fix a bug
where nb_numa_nodes may become larger than MAX_NODES (and cause
out-of-bounds access on the numa_info array).

Signed-off-by: Eduardo Habkost 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
Reviewed-by: Hu Tao 
Reviewed-by: Eric Blake 
---
 numa.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/numa.c b/numa.c
index db10f95..c254127 100644
--- a/numa.c
+++ b/numa.c
@@ -62,6 +62,11 @@ static void numa_node_parse(NumaNodeOptions *node, QemuOpts 
*opts, Error **errp)
 return;
 }
 
+if (numa_info[nodenr].present) {
+error_setg(errp, "Duplicate NUMA nodeid: %" PRIu16, nodenr);
+return;
+}
+
 for (cpus = node->cpus; cpus; cpus = cpus->next) {
 if (cpus->value > MAX_CPUMASK_BITS) {
 error_setg(errp, "CPU number %" PRIu16 " is bigger than %d",
-- 
MST




Re: [Qemu-devel] [PULL v2 00/13] linux-user changes for 2.1

2014-06-29 Thread Peter Maydell
On 29 June 2014 13:14,   wrote:
> From: Riku Voipio 
>
> The following changes since commit de6793e8c2a4d34e28e5ea385276249fc98109ec:
>
>   Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20140627' into 
> staging (2014-06-29 11:43:31 +0100)
>
> are available in the git repository at:
>
>   git://git.linaro.org/people/riku.voipio/qemu.git linux-user-for-upstream
>
> for you to fetch changes up to f63eb01ac7a5b4437d5589ad4343527534bf9d0b:
>
>   linux-user: support the SIOCGIFINDEX ioctl (2014-06-29 14:19:59 +0300)
>
> Changes since v1 - dropped those patches from Paul that add new syscalls from
> this round, since the won't compile with older libc's.

Applied, thanks.

-- PMM



[Qemu-devel] [PULL 22/37] virtio-rng: implement per-device migration calls

2014-06-29 Thread Michael S. Tsirkin
From: Greg Kurz 

While we are here, we also check virtio_load() return value.

Signed-off-by: Greg Kurz 
Reviewed-by: Alexander Graf 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/virtio/virtio-rng.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index 025de81..1356aca 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -107,19 +107,20 @@ static void virtio_rng_save(QEMUFile *f, void *opaque)
 
 static int virtio_rng_load(QEMUFile *f, void *opaque, int version_id)
 {
-VirtIORNG *vrng = opaque;
-VirtIODevice *vdev = VIRTIO_DEVICE(vrng);
-
 if (version_id != 1) {
 return -EINVAL;
 }
-virtio_load(vdev, f, version_id);
+return virtio_load(VIRTIO_DEVICE(opaque), f, version_id);
+}
 
+static int virtio_rng_load_device(VirtIODevice *vdev, QEMUFile *f,
+  int version_id)
+{
 /* We may have an element ready but couldn't process it due to a quota
  * limit.  Make sure to try again after live migration when the quota may
  * have been reset.
  */
-virtio_rng_process(vrng);
+virtio_rng_process(VIRTIO_RNG(vdev));
 
 return 0;
 }
@@ -219,6 +220,7 @@ static void virtio_rng_class_init(ObjectClass *klass, void 
*data)
 vdc->realize = virtio_rng_device_realize;
 vdc->unrealize = virtio_rng_device_unrealize;
 vdc->get_features = get_features;
+vdc->load = virtio_rng_load_device;
 }
 
 static void virtio_rng_initfn(Object *obj)
-- 
MST




Re: [Qemu-devel] [PULL 00/37] pc,vhost,virtio fixes, enhancements

2014-06-29 Thread Peter Maydell
On 29 June 2014 17:58, Michael S. Tsirkin  wrote:
> The following changes since commit 4daebe014effba37246b81d25acca5fa2df82f01:
>
>   Merge remote-tracking branch 'remotes/xtensa/tags/20140629-xtensa' into 
> staging (2014-06-29 16:17:50 +0100)
>
> are available in the git repository at:
>
>   git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream
>
> for you to fetch changes up to b4900c0e8a606bed834bd610fbae0fdf1d697ff9:
>
>   tests: add human format test for string output visitor (2014-06-29 19:39:43 
> +0300)

Applied, thanks.

-- PMM



[Qemu-devel] [PULL 06/37] mc146818rtc: add rtc-reset-reinjection QMP command

2014-06-29 Thread Michael S. Tsirkin
From: Marcelo Tosatti 

It is necessary to reset RTC interrupt reinjection backlog if
guest time is synchronized via a different mechanism, such as
QGA's guest-set-time command.

Failing to do so causes both corrections to be applied (summed),
resulting in an incorrect guest time.

Signed-off-by: Marcelo Tosatti 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 qapi-schema.json   | 12 
 hw/timer/mc146818rtc.c | 18 ++
 monitor.c  |  7 +++
 qmp-commands.hx| 23 +++
 4 files changed, 60 insertions(+)

diff --git a/qapi-schema.json b/qapi-schema.json
index a83befc..b11aad2 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3468,3 +3468,15 @@
 ##
 { 'enum': 'GuestPanicAction',
   'data': [ 'pause' ] }
+
+##
+# @rtc-reset-reinjection
+#
+# This command will reset the RTC interrupt reinjection backlog.
+# Can be used if another mechanism to synchronize guest time
+# is in effect, for example QEMU guest agent's guest-set-time
+# command.
+#
+# Since: 2.1
+##
+{ 'command': 'rtc-reset-reinjection' }
diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c
index 05002bf..307732c 100644
--- a/hw/timer/mc146818rtc.c
+++ b/hw/timer/mc146818rtc.c
@@ -27,6 +27,7 @@
 #include "hw/timer/mc146818rtc.h"
 #include "qapi/visitor.h"
 #include "qapi-event.h"
+#include "qmp-commands.h"
 
 #ifdef TARGET_I386
 #include "hw/i386/apic.h"
@@ -85,6 +86,7 @@ typedef struct RTCState {
 Notifier clock_reset_notifier;
 LostTickPolicy lost_tick_policy;
 Notifier suspend_notifier;
+QLIST_ENTRY(RTCState) link;
 } RTCState;
 
 static void rtc_set_time(RTCState *s);
@@ -523,6 +525,20 @@ static void rtc_get_time(RTCState *s, struct tm *tm)
 rtc_from_bcd(s, s->cmos_data[RTC_CENTURY]) * 100 - 1900;
 }
 
+static QLIST_HEAD(, RTCState) rtc_devices =
+QLIST_HEAD_INITIALIZER(rtc_devices);
+
+#ifdef TARGET_I386
+void qmp_rtc_reset_reinjection(Error **errp)
+{
+RTCState *s;
+
+QLIST_FOREACH(s, &rtc_devices, link) {
+s->irq_coalesced = 0;
+}
+}
+#endif
+
 static void rtc_set_time(RTCState *s)
 {
 struct tm tm;
@@ -911,6 +927,8 @@ ISADevice *rtc_init(ISABus *bus, int base_year, qemu_irq 
intercept_irq)
 } else {
 isa_init_irq(isadev, &s->irq, RTC_ISA_IRQ);
 }
+QLIST_INSERT_HEAD(&rtc_devices, s, link);
+
 return isadev;
 }
 
diff --git a/monitor.c b/monitor.c
index 5718d0b..799131b 100644
--- a/monitor.c
+++ b/monitor.c
@@ -5441,3 +5441,10 @@ QemuOptsList qemu_mon_opts = {
 { /* end of list */ }
 },
 };
+
+#ifndef TARGET_I386
+void qmp_rtc_reset_reinjection(Error **errp)
+{
+error_set(errp, QERR_FEATURE_DISABLED, "rtc-reset-reinjection");
+}
+#endif
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 65218bc..1ea18b2 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3675,3 +3675,26 @@ Example:
  { "slot": "3", "slot-type": "DIMM", "source": 0, "status": 0}
]}
 EQMP
+
+#if defined TARGET_I386
+{
+.name   = "rtc-reset-reinjection",
+.args_type  = "",
+.mhandler.cmd_new = qmp_marshal_input_rtc_reset_reinjection,
+},
+#endif
+
+SQMP
+rtc-reset-reinjection
+-
+
+Reset the RTC interrupt reinjection backlog.
+
+Arguments: None.
+
+Example:
+
+-> { "execute": "rtc-reset-reinjection" }
+<- { "return": {} }
+
+EQMP
-- 
MST




[Qemu-devel] [PULL 25/37] cpu: introduce CPUClass::virtio_is_big_endian()

2014-06-29 Thread Michael S. Tsirkin
From: Greg Kurz 

If we want to support targets that can change endianness (modern PPC and
ARM for the moment), we need to add a per-CPU class method to be called
from the virtio code. The virtio_ prefix in the name is a hint for people
to avoid misusage (aka. anywhere but from the virtio code).

The default behaviour is to return the compile-time default target
endianness.

Suggested-by: Peter Maydell 
Signed-off-by: Greg Kurz 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 include/qom/cpu.h | 1 +
 qom/cpu.c | 6 ++
 2 files changed, 7 insertions(+)

diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 4b352a2..1aafbf5 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -116,6 +116,7 @@ typedef struct CPUClass {
 CPUUnassignedAccess do_unassigned_access;
 void (*do_unaligned_access)(CPUState *cpu, vaddr addr,
 int is_write, int is_user, uintptr_t retaddr);
+bool (*virtio_is_big_endian)(CPUState *cpu);
 int (*memory_rw_debug)(CPUState *cpu, vaddr addr,
uint8_t *buf, int len, bool is_write);
 void (*dump_state)(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
diff --git a/qom/cpu.c b/qom/cpu.c
index fada2d4..b32dd0a 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -196,6 +196,11 @@ static int cpu_common_gdb_write_register(CPUState *cpu, 
uint8_t *buf, int reg)
 return 0;
 }
 
+bool target_words_bigendian(void);
+static bool cpu_common_virtio_is_big_endian(CPUState *cpu)
+{
+return target_words_bigendian();
+}
 
 void cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
 int flags)
@@ -334,6 +339,7 @@ static void cpu_class_init(ObjectClass *klass, void *data)
 k->write_elf64_note = cpu_common_write_elf64_note;
 k->gdb_read_register = cpu_common_gdb_read_register;
 k->gdb_write_register = cpu_common_gdb_write_register;
+k->virtio_is_big_endian = cpu_common_virtio_is_big_endian;
 dc->realize = cpu_common_realizefn;
 /*
  * Reason: CPUs still need special care by board code: wiring up
-- 
MST




Re: [Qemu-devel] possible denial of service via VNC

2014-06-29 Thread Anthony Liguori
On Sun, Jun 29, 2014 at 5:16 AM, Peter Lieven  wrote:
> Hi,
>
> while debugging a VNC issue I found this:
>
> case VNC_MSG_CLIENT_CUT_TEXT:
> if (len == 1)
> return 8;
>
> if (len == 8) {
> uint32_t dlen = read_u32(data, 4);
> if (dlen > 0)
> return 8 + dlen;
> }
>
> client_cut_text(vs, read_u32(data, 4), data + 8);
> break;
>
> in protocol_client_msg().
>
> Is this really a good idea? This allows for letting the vs->input buffer to 
> grow
> up to 2^32 + 8 byte which will possibly result in an out of memory condition.

The spec allows cut operations of this size.  What would a reasonable limit be?

Regards,

Anthony Liguori

> PeterY
>
>



[Qemu-devel] [PULL 36/37] vhost-net: disable when cross-endian

2014-06-29 Thread Michael S. Tsirkin
From: Greg Kurz 

As of today, vhost assumes guest and host have the same endianness.
This is definitely not compatible with modern PPC64 and ARM that
can change endianness at runtime. Let's disable vhost-net and print
an error message when we detect such a case:

qemu-system-ppc64: vhost-net does not support cross-endian
qemu-system-ppc64: unable to start vhost net: 38: falling back on userspace 
virtio

This way users can continue to run VMs without changing their setup and
have a chance to know that performance will be impacted.

Suggested-by: Michael S. Tsirkin 
Signed-off-by: Greg Kurz 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/net/vhost_net.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 7ac7c21..f87c798 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -275,6 +275,19 @@ static void vhost_net_stop_one(struct vhost_net *net,
 vhost_dev_disable_notifiers(&net->dev, dev);
 }
 
+static bool vhost_net_device_endian_ok(VirtIODevice *vdev)
+{
+#ifdef TARGET_IS_BIENDIAN
+#ifdef HOST_WORDS_BIGENDIAN
+return virtio_is_big_endian(vdev);
+#else
+return !virtio_is_big_endian(vdev);
+#endif
+#else
+return true;
+#endif
+}
+
 int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
 int total_queues)
 {
@@ -283,6 +296,12 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
 VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
 int r, i = 0;
 
+if (!vhost_net_device_endian_ok(dev)) {
+error_report("vhost-net does not support cross-endian");
+r = -ENOSYS;
+goto err;
+}
+
 if (!k->set_guest_notifiers) {
 error_report("binding does not support guest notifiers");
 r = -ENOSYS;
-- 
MST




[Qemu-devel] [PULL 37/37] tests: add human format test for string output visitor

2014-06-29 Thread Michael S. Tsirkin
From: Hu Tao 

Signed-off-by: Hu Tao 
Acked-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 tests/test-string-output-visitor.c | 109 ++---
 1 file changed, 90 insertions(+), 19 deletions(-)

diff --git a/tests/test-string-output-visitor.c 
b/tests/test-string-output-visitor.c
index 28e7359..e89e43c 100644
--- a/tests/test-string-output-visitor.c
+++ b/tests/test-string-output-visitor.c
@@ -21,12 +21,25 @@
 typedef struct TestOutputVisitorData {
 StringOutputVisitor *sov;
 Visitor *ov;
+bool human;
 } TestOutputVisitorData;
 
 static void visitor_output_setup(TestOutputVisitorData *data,
  const void *unused)
 {
-data->sov = string_output_visitor_new(false);
+data->human = false;
+data->sov = string_output_visitor_new(data->human);
+g_assert(data->sov != NULL);
+
+data->ov = string_output_get_visitor(data->sov);
+g_assert(data->ov != NULL);
+}
+
+static void visitor_output_setup_human(TestOutputVisitorData *data,
+   const void *unused)
+{
+data->human = true;
+data->sov = string_output_visitor_new(data->human);
 g_assert(data->sov != NULL);
 
 data->ov = string_output_get_visitor(data->sov);
@@ -53,7 +66,11 @@ static void test_visitor_out_int(TestOutputVisitorData *data,
 
 str = string_output_get_string(data->sov);
 g_assert(str != NULL);
-g_assert_cmpstr(str, ==, "42");
+if (data->human) {
+g_assert_cmpstr(str, ==, "42 (0x2a)");
+} else {
+g_assert_cmpstr(str, ==, "42");
+}
 g_free(str);
 }
 
@@ -78,8 +95,15 @@ static void test_visitor_out_intList(TestOutputVisitorData 
*data,
 
 str = string_output_get_string(data->sov);
 g_assert(str != NULL);
-g_assert_cmpstr(str, ==,
-"0-1,3-6,9-16,21-22,9223372036854775806-9223372036854775807");
+if (data->human) {
+g_assert_cmpstr(str, ==,
+"0-1,3-6,9-16,21-22,9223372036854775806-9223372036854775807 "
+"(0x0-0x1,0x3-0x6,0x9-0x10,0x15-0x16,"
+"0x7ffe-0x7fff)");
+} else {
+g_assert_cmpstr(str, ==,
+"0-1,3-6,9-16,21-22,9223372036854775806-9223372036854775807");
+}
 g_free(str);
 while (list) {
 intList *tmp2;
@@ -125,6 +149,7 @@ static void test_visitor_out_string(TestOutputVisitorData 
*data,
 const void *unused)
 {
 char *string = (char *) "Q E M U";
+const char *string_human = "\"Q E M U\"";
 Error *err = NULL;
 char *str;
 
@@ -133,7 +158,11 @@ static void test_visitor_out_string(TestOutputVisitorData 
*data,
 
 str = string_output_get_string(data->sov);
 g_assert(str != NULL);
-g_assert_cmpstr(str, ==, string);
+if (data->human) {
+g_assert_cmpstr(str, ==, string_human);
+} else {
+g_assert_cmpstr(str, ==, string);
+}
 g_free(str);
 }
 
@@ -150,7 +179,11 @@ static void 
test_visitor_out_no_string(TestOutputVisitorData *data,
 
 str = string_output_get_string(data->sov);
 g_assert(str != NULL);
-g_assert_cmpstr(str, ==, "");
+if (data->human) {
+g_assert_cmpstr(str, ==, "");
+} else {
+g_assert_cmpstr(str, ==, "");
+}
 g_free(str);
 }
 
@@ -162,12 +195,26 @@ static void test_visitor_out_enum(TestOutputVisitorData 
*data,
 EnumOne i;
 
 for (i = 0; i < ENUM_ONE_MAX; i++) {
+char *str_human;
+int len;
+
 visit_type_EnumOne(data->ov, &i, "unused", &err);
 g_assert(!err);
 
+len = strlen(EnumOne_lookup[i]) + 2;
+str_human = g_malloc0(len);
+str_human[0] = '"';
+strncpy(str_human + 1, EnumOne_lookup[i], strlen(EnumOne_lookup[i]));
+str_human[len - 1] = '"';
+
 str = string_output_get_string(data->sov);
 g_assert(str != NULL);
-g_assert_cmpstr(str, ==, EnumOne_lookup[i]);
+if (data->human) {
+g_assert_cmpstr(str, ==, str_human);
+} else {
+g_assert_cmpstr(str, ==, EnumOne_lookup[i]);
+}
+g_free(str_human);
g_free(str);
 }
 }
@@ -186,11 +233,15 @@ static void 
test_visitor_out_enum_errors(TestOutputVisitorData *data,
 }
 }
 
-static void output_visitor_test_add(const char *testpath,
-TestOutputVisitorData *data,
-void (*test_func)(TestOutputVisitorData 
*data, const void *user_data))
+static void
+output_visitor_test_add(const char *testpath,
+TestOutputVisitorData *data,
+void (*test_func)(TestOutputVisitorData *data,
+  const void *user_data),
+bool human)
 {
-g_test_add(testpath, TestOutputVisitorData, data, visitor_output_setup,
+g_test_add(testpath, TestOutputVisitorData, data,
+   human ? visitor_output_setup_huma

[Qemu-devel] [PULL 35/37] target-ppc: enable virtio endian ambivalent support

2014-06-29 Thread Michael S. Tsirkin
From: Greg Kurz 

The device endianness is the cpu endianness at device reset time.

Signed-off-by: Greg Kurz 
Reviewed-by: Alexander Graf 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 target-ppc/cpu.h|  2 ++
 target-ppc/translate_init.c | 15 +++
 2 files changed, 17 insertions(+)

diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
index 08ae527..b64c652 100644
--- a/target-ppc/cpu.h
+++ b/target-ppc/cpu.h
@@ -29,6 +29,8 @@
 #define TARGET_LONG_BITS 64
 #define TARGET_PAGE_BITS 12
 
+#define TARGET_IS_BIENDIAN 1
+
 /* Note that the official physical address space bits is 62-M where M
is implementation dependent.  I've not looked up M for the set of
cpus we emulate at the system level.  */
diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index a3bb336..2ab2810 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -9597,6 +9597,18 @@ static void ppc_cpu_reset(CPUState *s)
 tlb_flush(s, 1);
 }
 
+#ifndef CONFIG_USER_ONLY
+static bool ppc_cpu_is_big_endian(CPUState *cs)
+{
+PowerPCCPU *cpu = POWERPC_CPU(cs);
+CPUPPCState *env = &cpu->env;
+
+cpu_synchronize_state(cs);
+
+return !msr_le;
+}
+#endif
+
 static void ppc_cpu_initfn(Object *obj)
 {
 CPUState *cs = CPU(obj);
@@ -9692,6 +9704,9 @@ static void ppc_cpu_class_init(ObjectClass *oc, void 
*data)
 #else
 cc->gdb_core_xml_file = "power-core.xml";
 #endif
+#ifndef CONFIG_USER_ONLY
+cc->virtio_is_big_endian = ppc_cpu_is_big_endian;
+#endif
 
 dc->fw_name = "PowerPC,UNKNOWN";
 }
-- 
MST




[Qemu-devel] [PULL 33/37] virtio-serial-bus: use virtio wrappers to access headers

2014-06-29 Thread Michael S. Tsirkin
From: Rusty Russell 

We also fix max_nr_ports at reset time as the device endianness may have
changed.

Signed-off-by: Rusty Russell 
Reviewed-by: Anthony Liguori 
[ pass VirtIODevice * to memory accessors,
  fix max_nr_ports at reset time,
  Greg Kurz  ]
Signed-off-by: Greg Kurz 
Reviewed-by: Alexander Graf 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/char/virtio-serial-bus.c | 46 ++---
 1 file changed, 31 insertions(+), 15 deletions(-)

diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index b8af1b1..07bebc0 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -24,6 +24,7 @@
 #include "hw/sysbus.h"
 #include "trace.h"
 #include "hw/virtio/virtio-serial.h"
+#include "hw/virtio/virtio-access.h"
 
 static VirtIOSerialPort *find_port_by_id(VirtIOSerial *vser, uint32_t id)
 {
@@ -183,11 +184,12 @@ static size_t send_control_msg(VirtIOSerial *vser, void 
*buf, size_t len)
 static size_t send_control_event(VirtIOSerial *vser, uint32_t port_id,
  uint16_t event, uint16_t value)
 {
+VirtIODevice *vdev = VIRTIO_DEVICE(vser);
 struct virtio_console_control cpkt;
 
-stl_p(&cpkt.id, port_id);
-stw_p(&cpkt.event, event);
-stw_p(&cpkt.value, value);
+virtio_stl_p(vdev, &cpkt.id, port_id);
+virtio_stw_p(vdev, &cpkt.event, event);
+virtio_stw_p(vdev, &cpkt.value, value);
 
 trace_virtio_serial_send_control_event(port_id, event, value);
 return send_control_msg(vser, &cpkt, sizeof(cpkt));
@@ -278,6 +280,7 @@ void virtio_serial_throttle_port(VirtIOSerialPort *port, 
bool throttle)
 /* Guest wants to notify us of some event */
 static void handle_control_message(VirtIOSerial *vser, void *buf, size_t len)
 {
+VirtIODevice *vdev = VIRTIO_DEVICE(vser);
 struct VirtIOSerialPort *port;
 VirtIOSerialPortClass *vsc;
 struct virtio_console_control cpkt, *gcpkt;
@@ -291,8 +294,8 @@ static void handle_control_message(VirtIOSerial *vser, void 
*buf, size_t len)
 return;
 }
 
-cpkt.event = lduw_p(&gcpkt->event);
-cpkt.value = lduw_p(&gcpkt->value);
+cpkt.event = virtio_lduw_p(vdev, &gcpkt->event);
+cpkt.value = virtio_lduw_p(vdev, &gcpkt->value);
 
 trace_virtio_serial_handle_control_message(cpkt.event, cpkt.value);
 
@@ -312,10 +315,10 @@ static void handle_control_message(VirtIOSerial *vser, 
void *buf, size_t len)
 return;
 }
 
-port = find_port_by_id(vser, ldl_p(&gcpkt->id));
+port = find_port_by_id(vser, virtio_ldl_p(vdev, &gcpkt->id));
 if (!port) {
 error_report("virtio-serial-bus: Unexpected port id %u for device %s",
- ldl_p(&gcpkt->id), vser->bus.qbus.name);
+ virtio_ldl_p(vdev, &gcpkt->id), vser->bus.qbus.name);
 return;
 }
 
@@ -342,9 +345,9 @@ static void handle_control_message(VirtIOSerial *vser, void 
*buf, size_t len)
 }
 
 if (port->name) {
-stl_p(&cpkt.id, port->id);
-stw_p(&cpkt.event, VIRTIO_CONSOLE_PORT_NAME);
-stw_p(&cpkt.value, 1);
+virtio_stl_p(vdev, &cpkt.id, port->id);
+virtio_stw_p(vdev, &cpkt.event, VIRTIO_CONSOLE_PORT_NAME);
+virtio_stw_p(vdev, &cpkt.value, 1);
 
 buffer_len = sizeof(cpkt) + strlen(port->name) + 1;
 buffer = g_malloc(buffer_len);
@@ -510,6 +513,10 @@ static void vser_reset(VirtIODevice *vdev)
 
 vser = VIRTIO_SERIAL(vdev);
 guest_reset(vser);
+
+/* In case we have switched endianness */
+vser->config.max_nr_ports =
+virtio_tswap32(vdev, vser->serial.max_virtserial_ports);
 }
 
 static void virtio_serial_save(QEMUFile *f, void *opaque)
@@ -532,7 +539,7 @@ static void virtio_serial_save_device(VirtIODevice *vdev, 
QEMUFile *f)
 qemu_put_be32s(f, &s->config.max_nr_ports);
 
 /* The ports map */
-max_nr_ports = tswap32(s->config.max_nr_ports);
+max_nr_ports = virtio_tswap32(vdev, s->config.max_nr_ports);
 for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
 qemu_put_be32s(f, &s->ports_map[i]);
 }
@@ -688,6 +695,12 @@ static int virtio_serial_load_device(VirtIODevice *vdev, 
QEMUFile *f,
 qemu_get_be16s(f, (uint16_t *) &tmp);
 qemu_get_be32s(f, &tmp);
 
+/* Note: this is the only location where we use tswap32() instead of
+ * virtio_tswap32() because:
+ * - virtio_tswap32() only makes sense when the device is fully restored
+ * - the target endianness that was used to populate s->config is
+ *   necessarly the default one
+ */
 max_nr_ports = tswap32(s->config.max_nr_ports);
 for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
 qemu_get_be32s(f, &ports_map);
@@ -751,9 +764,10 @@ static void virtser_bus_dev_print(Monitor *mon, 
DeviceState *qdev, int indent)
 /* This function is only used if a port id is not provided by the user */
 static uint32_t find_free_port_id(VirtIOS

[Qemu-devel] [PULL 28/37] virtio: allow byte swapping for vring

2014-06-29 Thread Michael S. Tsirkin
From: Rusty Russell 

Quoting original text from Rusty: "This is based on a simpler patch by Anthony
Liguouri".

Signed-off-by: Rusty Russell 
[ add VirtIODevice * argument to most helpers,
  Greg Kurz  ]
Signed-off-by: Greg Kurz 
Reviewed-by: Thomas Huth 
Reviewed-by: Alexander Graf 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/virtio/virtio.c | 89 +-
 1 file changed, 48 insertions(+), 41 deletions(-)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index a0676e0..5c98180 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -20,6 +20,7 @@
 #include "qemu/atomic.h"
 #include "hw/virtio/virtio-bus.h"
 #include "migration/migration.h"
+#include "hw/virtio/virtio-access.h"
 
 /*
  * The alignment to use between consumer and producer parts of vring.
@@ -102,53 +103,56 @@ static void virtqueue_init(VirtQueue *vq)
  vq->vring.align);
 }
 
-static inline uint64_t vring_desc_addr(hwaddr desc_pa, int i)
+static inline uint64_t vring_desc_addr(VirtIODevice *vdev, hwaddr desc_pa,
+   int i)
 {
 hwaddr pa;
 pa = desc_pa + sizeof(VRingDesc) * i + offsetof(VRingDesc, addr);
-return ldq_phys(&address_space_memory, pa);
+return virtio_ldq_phys(vdev, pa);
 }
 
-static inline uint32_t vring_desc_len(hwaddr desc_pa, int i)
+static inline uint32_t vring_desc_len(VirtIODevice *vdev, hwaddr desc_pa, int 
i)
 {
 hwaddr pa;
 pa = desc_pa + sizeof(VRingDesc) * i + offsetof(VRingDesc, len);
-return ldl_phys(&address_space_memory, pa);
+return virtio_ldl_phys(vdev, pa);
 }
 
-static inline uint16_t vring_desc_flags(hwaddr desc_pa, int i)
+static inline uint16_t vring_desc_flags(VirtIODevice *vdev, hwaddr desc_pa,
+int i)
 {
 hwaddr pa;
 pa = desc_pa + sizeof(VRingDesc) * i + offsetof(VRingDesc, flags);
-return lduw_phys(&address_space_memory, pa);
+return virtio_lduw_phys(vdev, pa);
 }
 
-static inline uint16_t vring_desc_next(hwaddr desc_pa, int i)
+static inline uint16_t vring_desc_next(VirtIODevice *vdev, hwaddr desc_pa,
+   int i)
 {
 hwaddr pa;
 pa = desc_pa + sizeof(VRingDesc) * i + offsetof(VRingDesc, next);
-return lduw_phys(&address_space_memory, pa);
+return virtio_lduw_phys(vdev, pa);
 }
 
 static inline uint16_t vring_avail_flags(VirtQueue *vq)
 {
 hwaddr pa;
 pa = vq->vring.avail + offsetof(VRingAvail, flags);
-return lduw_phys(&address_space_memory, pa);
+return virtio_lduw_phys(vq->vdev, pa);
 }
 
 static inline uint16_t vring_avail_idx(VirtQueue *vq)
 {
 hwaddr pa;
 pa = vq->vring.avail + offsetof(VRingAvail, idx);
-return lduw_phys(&address_space_memory, pa);
+return virtio_lduw_phys(vq->vdev, pa);
 }
 
 static inline uint16_t vring_avail_ring(VirtQueue *vq, int i)
 {
 hwaddr pa;
 pa = vq->vring.avail + offsetof(VRingAvail, ring[i]);
-return lduw_phys(&address_space_memory, pa);
+return virtio_lduw_phys(vq->vdev, pa);
 }
 
 static inline uint16_t vring_used_event(VirtQueue *vq)
@@ -160,44 +164,44 @@ static inline void vring_used_ring_id(VirtQueue *vq, int 
i, uint32_t val)
 {
 hwaddr pa;
 pa = vq->vring.used + offsetof(VRingUsed, ring[i].id);
-stl_phys(&address_space_memory, pa, val);
+virtio_stl_phys(vq->vdev, pa, val);
 }
 
 static inline void vring_used_ring_len(VirtQueue *vq, int i, uint32_t val)
 {
 hwaddr pa;
 pa = vq->vring.used + offsetof(VRingUsed, ring[i].len);
-stl_phys(&address_space_memory, pa, val);
+virtio_stl_phys(vq->vdev, pa, val);
 }
 
 static uint16_t vring_used_idx(VirtQueue *vq)
 {
 hwaddr pa;
 pa = vq->vring.used + offsetof(VRingUsed, idx);
-return lduw_phys(&address_space_memory, pa);
+return virtio_lduw_phys(vq->vdev, pa);
 }
 
 static inline void vring_used_idx_set(VirtQueue *vq, uint16_t val)
 {
 hwaddr pa;
 pa = vq->vring.used + offsetof(VRingUsed, idx);
-stw_phys(&address_space_memory, pa, val);
+virtio_stw_phys(vq->vdev, pa, val);
 }
 
 static inline void vring_used_flags_set_bit(VirtQueue *vq, int mask)
 {
+VirtIODevice *vdev = vq->vdev;
 hwaddr pa;
 pa = vq->vring.used + offsetof(VRingUsed, flags);
-stw_phys(&address_space_memory,
- pa, lduw_phys(&address_space_memory, pa) | mask);
+virtio_stw_phys(vdev, pa, virtio_lduw_phys(vdev, pa) | mask);
 }
 
 static inline void vring_used_flags_unset_bit(VirtQueue *vq, int mask)
 {
+VirtIODevice *vdev = vq->vdev;
 hwaddr pa;
 pa = vq->vring.used + offsetof(VRingUsed, flags);
-stw_phys(&address_space_memory,
- pa, lduw_phys(&address_space_memory, pa) & ~mask);
+virtio_stw_phys(vdev, pa, virtio_lduw_phys(vdev, pa) & ~mask);
 }
 
 static inline void vring_avail_event(VirtQueue *vq, uint16_t val)
@@ -207,7 +211,7 @@ static inline void vring_avail_event(VirtQueue *vq, 
uint16_t v

[Qemu-devel] [PULL 29/37] virtio-net: use virtio wrappers to access headers

2014-06-29 Thread Michael S. Tsirkin
From: Rusty Russell 

Signed-off-by: Rusty Russell 
Reviewed-by: Anthony Liguori 
[ pass VirtIODevice * to memory accessors,
  converted new tswap locations to virtio_tswap,
  Greg Kurz  ]
Signed-off-by: Greg Kurz 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/net/virtio-net.c | 31 +--
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index eead70e..268eff9 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -23,6 +23,7 @@
 #include "hw/virtio/virtio-bus.h"
 #include "qapi/qmp/qjson.h"
 #include "qapi-event.h"
+#include "hw/virtio/virtio-access.h"
 
 #define VIRTIO_NET_VM_VERSION11
 
@@ -72,8 +73,8 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t 
*config)
 VirtIONet *n = VIRTIO_NET(vdev);
 struct virtio_net_config netcfg;
 
-stw_p(&netcfg.status, n->status);
-stw_p(&netcfg.max_virtqueue_pairs, n->max_queues);
+virtio_stw_p(vdev, &netcfg.status, n->status);
+virtio_stw_p(vdev, &netcfg.max_virtqueue_pairs, n->max_queues);
 memcpy(netcfg.mac, n->mac, ETH_ALEN);
 memcpy(config, &netcfg, n->config_size);
 }
@@ -604,6 +605,7 @@ static int virtio_net_handle_offloads(VirtIONet *n, uint8_t 
cmd,
 static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
  struct iovec *iov, unsigned int iov_cnt)
 {
+VirtIODevice *vdev = VIRTIO_DEVICE(n);
 struct virtio_net_ctrl_mac mac_data;
 size_t s;
 NetClientState *nc = qemu_get_queue(n->nic);
@@ -632,7 +634,7 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
 
 s = iov_to_buf(iov, iov_cnt, 0, &mac_data.entries,
sizeof(mac_data.entries));
-mac_data.entries = ldl_p(&mac_data.entries);
+mac_data.entries = virtio_ldl_p(vdev, &mac_data.entries);
 if (s != sizeof(mac_data.entries)) {
 goto error;
 }
@@ -659,7 +661,7 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
 
 s = iov_to_buf(iov, iov_cnt, 0, &mac_data.entries,
sizeof(mac_data.entries));
-mac_data.entries = ldl_p(&mac_data.entries);
+mac_data.entries = virtio_ldl_p(vdev, &mac_data.entries);
 if (s != sizeof(mac_data.entries)) {
 goto error;
 }
@@ -699,12 +701,13 @@ error:
 static int virtio_net_handle_vlan_table(VirtIONet *n, uint8_t cmd,
 struct iovec *iov, unsigned int 
iov_cnt)
 {
+VirtIODevice *vdev = VIRTIO_DEVICE(n);
 uint16_t vid;
 size_t s;
 NetClientState *nc = qemu_get_queue(n->nic);
 
 s = iov_to_buf(iov, iov_cnt, 0, &vid, sizeof(vid));
-vid = lduw_p(&vid);
+vid = virtio_lduw_p(vdev, &vid);
 if (s != sizeof(vid)) {
 return VIRTIO_NET_ERR;
 }
@@ -758,7 +761,7 @@ static int virtio_net_handle_mq(VirtIONet *n, uint8_t cmd,
 return VIRTIO_NET_ERR;
 }
 
-queues = lduw_p(&mq.virtqueue_pairs);
+queues = virtio_lduw_p(vdev, &mq.virtqueue_pairs);
 
 if (queues < VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MIN ||
 queues > VIRTIO_NET_CTRL_MQ_VQ_PAIRS_MAX ||
@@ -875,12 +878,12 @@ static int virtio_net_has_buffers(VirtIONetQueue *q, int 
bufsize)
 return 1;
 }
 
-static void virtio_net_hdr_swap(struct virtio_net_hdr *hdr)
+static void virtio_net_hdr_swap(VirtIODevice *vdev, struct virtio_net_hdr *hdr)
 {
-tswap16s(&hdr->hdr_len);
-tswap16s(&hdr->gso_size);
-tswap16s(&hdr->csum_start);
-tswap16s(&hdr->csum_offset);
+virtio_tswap16s(vdev, &hdr->hdr_len);
+virtio_tswap16s(vdev, &hdr->gso_size);
+virtio_tswap16s(vdev, &hdr->csum_start);
+virtio_tswap16s(vdev, &hdr->csum_offset);
 }
 
 /* dhclient uses AF_PACKET but doesn't pass auxdata to the kernel so
@@ -918,7 +921,7 @@ static void receive_header(VirtIONet *n, const struct iovec 
*iov, int iov_cnt,
 void *wbuf = (void *)buf;
 work_around_broken_dhclient(wbuf, wbuf + n->host_hdr_len,
 size - n->host_hdr_len);
-virtio_net_hdr_swap(wbuf);
+virtio_net_hdr_swap(VIRTIO_DEVICE(n), wbuf);
 iov_from_buf(iov, iov_cnt, 0, buf, sizeof(struct virtio_net_hdr));
 } else {
 struct virtio_net_hdr hdr = {
@@ -1068,7 +1071,7 @@ static ssize_t virtio_net_receive(NetClientState *nc, 
const uint8_t *buf, size_t
 }
 
 if (mhdr_cnt) {
-stw_p(&mhdr.num_buffers, i);
+virtio_stw_p(vdev, &mhdr.num_buffers, i);
 iov_from_buf(mhdr_sg, mhdr_cnt,
  0,
  &mhdr.num_buffers, sizeof mhdr.num_buffers);
@@ -1132,7 +1135,7 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
 error_report("virtio-net header incorrect");
 exit(1);
 }
-virtio_net_hdr_swap((void *) out_sg[0].iov_base);
+virtio_net_hdr_swap(vdev, (void *) out_sg[0].iov_base);
 }
 
 /*
-- 
MST




[Qemu-devel] [PULL 30/37] virtio-balloon: use virtio wrappers to access page frame numbers

2014-06-29 Thread Michael S. Tsirkin
From: Rusty Russell 

Signed-off-by: Rusty Russell 
Reviewed-by: Anthony Liguori 
[ pass VirtIODevice * to memory accessors,
  Greg Kurz  ]
Signed-off-by: Greg Kurz 
Reviewed-by: Alexander Graf 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/virtio/virtio-balloon.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index e0ed5ee..2c30b3d 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -31,6 +31,7 @@
 #endif
 
 #include "hw/virtio/virtio-bus.h"
+#include "hw/virtio/virtio-access.h"
 
 static void balloon_page(void *addr, int deflate)
 {
@@ -206,8 +207,9 @@ static void virtio_balloon_handle_output(VirtIODevice 
*vdev, VirtQueue *vq)
 while (iov_to_buf(elem.out_sg, elem.out_num, offset, &pfn, 4) == 4) {
 ram_addr_t pa;
 ram_addr_t addr;
+int p = virtio_ldl_p(vdev, &pfn);
 
-pa = (ram_addr_t)ldl_p(&pfn) << VIRTIO_BALLOON_PFN_SHIFT;
+pa = (ram_addr_t) p << VIRTIO_BALLOON_PFN_SHIFT;
 offset += 4;
 
 /* FIXME: remove get_system_memory(), but how? */
@@ -248,8 +250,8 @@ static void virtio_balloon_receive_stats(VirtIODevice 
*vdev, VirtQueue *vq)
 
 while (iov_to_buf(elem->out_sg, elem->out_num, offset, &stat, sizeof(stat))
== sizeof(stat)) {
-uint16_t tag = tswap16(stat.tag);
-uint64_t val = tswap64(stat.val);
+uint16_t tag = virtio_tswap16(vdev, stat.tag);
+uint64_t val = virtio_tswap64(vdev, stat.val);
 
 offset += sizeof(stat);
 if (tag < VIRTIO_BALLOON_S_NR)
-- 
MST




[Qemu-devel] [PULL 23/37] virtio: add subsections to the migration stream

2014-06-29 Thread Michael S. Tsirkin
From: Greg Kurz 

There is a need to add some more fields to VirtIODevice that should be
migrated (broken status, endianness). The problem is that we do not
want to break compatibility while adding a new feature... This issue has
been addressed in the generic VMState code with the use of optional
subsections. As a *temporary* alternative to port the whole virtio
migration code to VMState, this patch mimics a similar subsectionning
ability for virtio, using the VMState code.

Since each virtio device is streamed in its own section, the idea is to
stream subsections between the end of the device section and the start
of the next sections. This allows an older QEMU to complain and exit
when fed with subsections:

Unknown savevm section type 5
load of migration failed

Suggested-by: Alexander Graf 
Signed-off-by: Greg Kurz 
Reviewed-by: Alexander Graf 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/virtio/virtio.c | 21 +++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 7f9ac5e..7b317ce 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -19,6 +19,7 @@
 #include "hw/virtio/virtio.h"
 #include "qemu/atomic.h"
 #include "hw/virtio/virtio-bus.h"
+#include "migration/migration.h"
 
 /*
  * The alignment to use between consumer and producer parts of vring.
@@ -839,6 +840,16 @@ void virtio_notify_config(VirtIODevice *vdev)
 virtio_notify_vector(vdev, vdev->config_vector);
 }
 
+static const VMStateDescription vmstate_virtio = {
+.name = "virtio",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields = (VMStateField[]) {
+VMSTATE_END_OF_LIST()
+}
+};
+
 void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 {
 BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
@@ -882,6 +893,9 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 if (vdc->save != NULL) {
 vdc->save(vdev, f);
 }
+
+/* Subsections */
+vmstate_save_state(f, &vmstate_virtio, vdev);
 }
 
 int virtio_set_features(VirtIODevice *vdev, uint32_t val)
@@ -991,10 +1005,13 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int 
version_id)
 virtio_notify_vector(vdev, VIRTIO_NO_VECTOR);
 
 if (vdc->load != NULL) {
-return vdc->load(vdev, f, version_id);
+ret = vdc->load(vdev, f, version_id);
+if (ret) {
+return ret;
+}
 }
 
-return 0;
+return vmstate_load_state(f, &vmstate_virtio, vdev, 1);
 }
 
 void virtio_cleanup(VirtIODevice *vdev)
-- 
MST




[Qemu-devel] [PULL 20/37] virtio-serial: implement per-device migration calls

2014-06-29 Thread Michael S. Tsirkin
From: Greg Kurz 

Signed-off-by: Greg Kurz 
Reviewed-by: Alexander Graf 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/char/virtio-serial-bus.c | 34 --
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index f919ec2..b8af1b1 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -514,14 +514,17 @@ static void vser_reset(VirtIODevice *vdev)
 
 static void virtio_serial_save(QEMUFile *f, void *opaque)
 {
-VirtIOSerial *s = VIRTIO_SERIAL(opaque);
+/* The virtio device */
+virtio_save(VIRTIO_DEVICE(opaque), f);
+}
+
+static void virtio_serial_save_device(VirtIODevice *vdev, QEMUFile *f)
+{
+VirtIOSerial *s = VIRTIO_SERIAL(vdev);
 VirtIOSerialPort *port;
 uint32_t nr_active_ports;
 unsigned int i, max_nr_ports;
 
-/* The virtio device */
-virtio_save(VIRTIO_DEVICE(s), f);
-
 /* The config space */
 qemu_put_be16s(f, &s->config.cols);
 qemu_put_be16s(f, &s->config.rows);
@@ -659,21 +662,22 @@ static int fetch_active_ports_list(QEMUFile *f, int 
version_id,
 
 static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
 {
-VirtIOSerial *s = VIRTIO_SERIAL(opaque);
-uint32_t max_nr_ports, nr_active_ports, ports_map;
-unsigned int i;
-int ret;
-uint32_t tmp;
-
 if (version_id > 3) {
 return -EINVAL;
 }
 
 /* The virtio device */
-ret = virtio_load(VIRTIO_DEVICE(s), f, version_id);
-if (ret) {
-return ret;
-}
+return virtio_load(VIRTIO_DEVICE(opaque), f, version_id);
+}
+
+static int virtio_serial_load_device(VirtIODevice *vdev, QEMUFile *f,
+ int version_id)
+{
+VirtIOSerial *s = VIRTIO_SERIAL(vdev);
+uint32_t max_nr_ports, nr_active_ports, ports_map;
+unsigned int i;
+int ret;
+uint32_t tmp;
 
 if (version_id < 2) {
 return 0;
@@ -1015,6 +1019,8 @@ static void virtio_serial_class_init(ObjectClass *klass, 
void *data)
 vdc->get_config = get_config;
 vdc->set_status = set_status;
 vdc->reset = vser_reset;
+vdc->save = virtio_serial_save_device;
+vdc->load = virtio_serial_load_device;
 }
 
 static const TypeInfo virtio_device_info = {
-- 
MST




[Qemu-devel] [PULL 19/37] virtio-blk: implement per-device migration calls

2014-06-29 Thread Michael S. Tsirkin
From: Greg Kurz 

Signed-off-by: Greg Kurz 
Reviewed-by: Alexander Graf 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/block/virtio-blk.c | 24 
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 5e2693a..b06af8c 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -611,12 +611,16 @@ static void virtio_blk_set_status(VirtIODevice *vdev, 
uint8_t status)
 
 static void virtio_blk_save(QEMUFile *f, void *opaque)
 {
-VirtIOBlock *s = opaque;
-VirtIODevice *vdev = VIRTIO_DEVICE(s);
-VirtIOBlockReq *req = s->rq;
+VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
 
 virtio_save(vdev, f);
+}
 
+static void virtio_blk_save_device(VirtIODevice *vdev, QEMUFile *f)
+{
+VirtIOBlock *s = VIRTIO_BLK(vdev);
+VirtIOBlockReq *req = s->rq;
+
 while (req) {
 qemu_put_sbyte(f, 1);
 qemu_put_buffer(f, (unsigned char *)req->elem,
@@ -630,15 +634,17 @@ static int virtio_blk_load(QEMUFile *f, void *opaque, int 
version_id)
 {
 VirtIOBlock *s = opaque;
 VirtIODevice *vdev = VIRTIO_DEVICE(s);
-int ret;
 
 if (version_id != 2)
 return -EINVAL;
 
-ret = virtio_load(vdev, f, version_id);
-if (ret) {
-return ret;
-}
+return virtio_load(vdev, f, version_id);
+}
+
+static int virtio_blk_load_device(VirtIODevice *vdev, QEMUFile *f,
+  int version_id)
+{
+VirtIOBlock *s = VIRTIO_BLK(vdev);
 
 while (qemu_get_sbyte(f)) {
 VirtIOBlockReq *req = virtio_blk_alloc_request(s);
@@ -799,6 +805,8 @@ static void virtio_blk_class_init(ObjectClass *klass, void 
*data)
 vdc->get_features = virtio_blk_get_features;
 vdc->set_status = virtio_blk_set_status;
 vdc->reset = virtio_blk_reset;
+vdc->save = virtio_blk_save_device;
+vdc->load = virtio_blk_load_device;
 }
 
 static const TypeInfo virtio_device_info = {
-- 
MST




[Qemu-devel] [PULL 17/37] virtio: introduce device specific migration calls

2014-06-29 Thread Michael S. Tsirkin
From: Greg Kurz 

In order to migrate virtio subsections, they should be streamed after
the device itself. We need the device specific code to be called from
the common migration code to achieve this. This patch introduces load
and save methods for this purpose.

Suggested-by: Andreas Färber 
Signed-off-by: Greg Kurz 
Reviewed-by: Alexander Graf 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 include/hw/virtio/virtio.h  |  4 +++-
 hw/block/virtio-blk.c   |  2 +-
 hw/char/virtio-serial-bus.c |  2 +-
 hw/net/virtio-net.c |  2 +-
 hw/scsi/virtio-scsi.c   |  2 +-
 hw/virtio/virtio-balloon.c  |  2 +-
 hw/virtio/virtio-rng.c  |  2 +-
 hw/virtio/virtio.c  | 13 -
 8 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 3e54e90..3505ce5 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -150,6 +150,8 @@ typedef struct VirtioDeviceClass {
  * must mask in frontend instead.
  */
 void (*guest_notifier_mask)(VirtIODevice *vdev, int n, bool mask);
+void (*save)(VirtIODevice *vdev, QEMUFile *f);
+int (*load)(VirtIODevice *vdev, QEMUFile *f, int version_id);
 } VirtioDeviceClass;
 
 void virtio_init(VirtIODevice *vdev, const char *name,
@@ -184,7 +186,7 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);
 
 void virtio_save(VirtIODevice *vdev, QEMUFile *f);
 
-int virtio_load(VirtIODevice *vdev, QEMUFile *f);
+int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id);
 
 void virtio_notify_config(VirtIODevice *vdev);
 
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index a222e3f..5e2693a 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -635,7 +635,7 @@ static int virtio_blk_load(QEMUFile *f, void *opaque, int 
version_id)
 if (version_id != 2)
 return -EINVAL;
 
-ret = virtio_load(vdev, f);
+ret = virtio_load(vdev, f, version_id);
 if (ret) {
 return ret;
 }
diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index e2174b1..f919ec2 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -670,7 +670,7 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, 
int version_id)
 }
 
 /* The virtio device */
-ret = virtio_load(VIRTIO_DEVICE(s), f);
+ret = virtio_load(VIRTIO_DEVICE(s), f, version_id);
 if (ret) {
 return ret;
 }
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index ea1a081..acfe91c 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -1362,7 +1362,7 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int 
version_id)
 if (version_id < 2 || version_id > VIRTIO_NET_VM_VERSION)
 return -EINVAL;
 
-ret = virtio_load(vdev, f);
+ret = virtio_load(vdev, f, version_id);
 if (ret) {
 return ret;
 }
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 8c8c9d1..6b4fd6f 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -549,7 +549,7 @@ static int virtio_scsi_load(QEMUFile *f, void *opaque, int 
version_id)
 VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
 int ret;
 
-ret = virtio_load(vdev, f);
+ret = virtio_load(vdev, f, version_id);
 if (ret) {
 return ret;
 }
diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index 2a2e58a..165592e 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -343,7 +343,7 @@ static int virtio_balloon_load(QEMUFile *f, void *opaque, 
int version_id)
 if (version_id != 1)
 return -EINVAL;
 
-ret = virtio_load(vdev, f);
+ret = virtio_load(vdev, f, version_id);
 if (ret) {
 return ret;
 }
diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index b6ab361..025de81 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -113,7 +113,7 @@ static int virtio_rng_load(QEMUFile *f, void *opaque, int 
version_id)
 if (version_id != 1) {
 return -EINVAL;
 }
-virtio_load(vdev, f);
+virtio_load(vdev, f, version_id);
 
 /* We may have an element ready but couldn't process it due to a quota
  * limit.  Make sure to try again after live migration when the quota may
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index c1d538c..7f9ac5e 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -843,6 +843,7 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 {
 BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
 VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
+VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
 int i;
 
 if (k->save_config) {
@@ -877,6 +878,10 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
 k->save_queue(qbus->parent, i, f);
 }
 }
+
+if (vdc->save != NULL) {
+vdc->save(vdev, f);
+}
 }
 
 int virtio_set_features(VirtIODevice *vdev, uint32_t val)
@@ -895,

[Qemu-devel] [PULL 16/37] virtio-serial: don't migrate the config space

2014-06-29 Thread Michael S. Tsirkin
From: Alexander Graf 

The device configuration is set at realize time and never changes. It
should not be migrated as it is done today. For the sake of compatibility,
let's just skip them at load time.

Signed-off-by: Alexander Graf 
[ added missing casts to uint16_t *,
  added From, SoB and commit message,
  Greg Kurz  ]
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Greg Kurz 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/char/virtio-serial-bus.c | 16 ++--
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/hw/char/virtio-serial-bus.c b/hw/char/virtio-serial-bus.c
index a2958ff..e2174b1 100644
--- a/hw/char/virtio-serial-bus.c
+++ b/hw/char/virtio-serial-bus.c
@@ -663,6 +663,7 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, 
int version_id)
 uint32_t max_nr_ports, nr_active_ports, ports_map;
 unsigned int i;
 int ret;
+uint32_t tmp;
 
 if (version_id > 3) {
 return -EINVAL;
@@ -678,17 +679,12 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, 
int version_id)
 return 0;
 }
 
-/* The config space */
-qemu_get_be16s(f, &s->config.cols);
-qemu_get_be16s(f, &s->config.rows);
-
-qemu_get_be32s(f, &max_nr_ports);
-tswap32s(&max_nr_ports);
-if (max_nr_ports > tswap32(s->config.max_nr_ports)) {
-/* Source could have had more ports than us. Fail migration. */
-return -EINVAL;
-}
+/* Unused */
+qemu_get_be16s(f, (uint16_t *) &tmp);
+qemu_get_be16s(f, (uint16_t *) &tmp);
+qemu_get_be32s(f, &tmp);
 
+max_nr_ports = tswap32(s->config.max_nr_ports);
 for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
 qemu_get_be32s(f, &ports_map);
 
-- 
MST




[Qemu-devel] [PULL 15/37] virtio-net: byteswap virtio-net header

2014-06-29 Thread Michael S. Tsirkin
From: Cédric Le Goater 

TCP connectivity fails when the guest has a different endianness.
The packets are silently dropped on the host by the tap backend
when they are read from user space because the endianness of the
virtio-net header is in the wrong order. These lines may appear
in the guest console:

[  454.709327] skbuff: bad partial csum: csum=8704/4096 len=74
[  455.702554] skbuff: bad partial csum: csum=8704/4096 len=74

The issue that got first spotted with a ppc64le PowerKVM guest,
but it also exists for the less common case of a x86_64 guest run
by a big-endian ppc64 TCG hypervisor.

Signed-off-by: Cédric Le Goater 
[ Ported from PowerKVM,
  Greg Kurz  ]
Signed-off-by: Greg Kurz 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/net/virtio-net.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index e51d753..ea1a081 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -875,6 +875,14 @@ static int virtio_net_has_buffers(VirtIONetQueue *q, int 
bufsize)
 return 1;
 }
 
+static void virtio_net_hdr_swap(struct virtio_net_hdr *hdr)
+{
+tswap16s(&hdr->hdr_len);
+tswap16s(&hdr->gso_size);
+tswap16s(&hdr->csum_start);
+tswap16s(&hdr->csum_offset);
+}
+
 /* dhclient uses AF_PACKET but doesn't pass auxdata to the kernel so
  * it never finds out that the packets don't have valid checksums.  This
  * causes dhclient to get upset.  Fedora's carried a patch for ages to
@@ -910,6 +918,7 @@ static void receive_header(VirtIONet *n, const struct iovec 
*iov, int iov_cnt,
 void *wbuf = (void *)buf;
 work_around_broken_dhclient(wbuf, wbuf + n->host_hdr_len,
 size - n->host_hdr_len);
+virtio_net_hdr_swap(wbuf);
 iov_from_buf(iov, iov_cnt, 0, buf, sizeof(struct virtio_net_hdr));
 } else {
 struct virtio_net_hdr hdr = {
@@ -1118,6 +1127,14 @@ static int32_t virtio_net_flush_tx(VirtIONetQueue *q)
 exit(1);
 }
 
+if (n->has_vnet_hdr) {
+if (out_sg[0].iov_len < n->guest_hdr_len) {
+error_report("virtio-net header incorrect");
+exit(1);
+}
+virtio_net_hdr_swap((void *) out_sg[0].iov_base);
+}
+
 /*
  * If host wants to see the guest header as is, we can
  * pass it on unchanged. Otherwise, copy just the parts
-- 
MST




[Qemu-devel] [PULL 18/37] virtio-net: implement per-device migration calls

2014-06-29 Thread Michael S. Tsirkin
From: Greg Kurz 

Signed-off-by: Greg Kurz 
Reviewed-by: Alexander Graf 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/net/virtio-net.c | 22 --
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index acfe91c..eead70e 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -1314,7 +1314,6 @@ static void virtio_net_set_multiqueue(VirtIONet *n, int 
multiqueue)
 
 static void virtio_net_save(QEMUFile *f, void *opaque)
 {
-int i;
 VirtIONet *n = opaque;
 VirtIODevice *vdev = VIRTIO_DEVICE(n);
 
@@ -1322,6 +1321,12 @@ static void virtio_net_save(QEMUFile *f, void *opaque)
  * it might keep writing to memory. */
 assert(!n->vhost_started);
 virtio_save(vdev, f);
+}
+
+static void virtio_net_save_device(VirtIODevice *vdev, QEMUFile *f)
+{
+VirtIONet *n = VIRTIO_NET(vdev);
+int i;
 
 qemu_put_buffer(f, n->mac, ETH_ALEN);
 qemu_put_be32(f, n->vqs[0].tx_waiting);
@@ -1357,15 +1362,18 @@ static int virtio_net_load(QEMUFile *f, void *opaque, 
int version_id)
 {
 VirtIONet *n = opaque;
 VirtIODevice *vdev = VIRTIO_DEVICE(n);
-int ret, i, link_down;
 
 if (version_id < 2 || version_id > VIRTIO_NET_VM_VERSION)
 return -EINVAL;
 
-ret = virtio_load(vdev, f, version_id);
-if (ret) {
-return ret;
-}
+return virtio_load(vdev, f, version_id);
+}
+
+static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f,
+  int version_id)
+{
+VirtIONet *n = VIRTIO_NET(vdev);
+int i, link_down;
 
 qemu_get_buffer(f, n->mac, ETH_ALEN);
 n->vqs[0].tx_waiting = qemu_get_be32(f);
@@ -1711,6 +1719,8 @@ static void virtio_net_class_init(ObjectClass *klass, 
void *data)
 vdc->set_status = virtio_net_set_status;
 vdc->guest_notifier_mask = virtio_net_guest_notifier_mask;
 vdc->guest_notifier_pending = virtio_net_guest_notifier_pending;
+vdc->load = virtio_net_load_device;
+vdc->save = virtio_net_save_device;
 }
 
 static const TypeInfo virtio_net_info = {
-- 
MST




[Qemu-devel] [PULL 10/37] numa: Keep track of NUMA nodes present on the command-line

2014-06-29 Thread Michael S. Tsirkin
From: Eduardo Habkost 

Based on "enable sparse node numbering" patch from Nishanth Aravamudan,
but without the code to actually support sparse node IDs. This just adds
the code to keep track of present/non-present nodes on the command-line,
without changing any behavior.

Signed-off-by: Nishanth Aravamudan 
[Rename max_numa_node to max_numa_nodeid -Eduardo]
[Initialize max_numa_nodeid to 0 -Eduardo]
[Use MAX() macro when setting max_numa_nodeid -Eduardo]
Signed-off-by: Eduardo Habkost 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
Reviewed-by: Hu Tao 
Reviewed-by: Eric Blake 
---
 include/sysemu/sysemu.h | 7 ++-
 numa.c  | 2 ++
 vl.c| 3 +++
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 285c45b..d8539fd 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -146,11 +146,16 @@ extern int mem_prealloc;
  */
 #define MAX_CPUMASK_BITS 255
 
-extern int nb_numa_nodes;
+extern int nb_numa_nodes;   /* Number of NUMA nodes */
+extern int max_numa_nodeid; /* Highest specified NUMA node ID, plus one.
+ * For all nodes, nodeid < max_numa_nodeid
+ */
+
 typedef struct node_info {
 uint64_t node_mem;
 DECLARE_BITMAP(node_cpu, MAX_CPUMASK_BITS);
 struct HostMemoryBackend *node_memdev;
+bool present;
 } NodeInfo;
 extern NodeInfo numa_info[MAX_NODES];
 void set_numa_nodes(void);
diff --git a/numa.c b/numa.c
index 6c2eae7..db10f95 100644
--- a/numa.c
+++ b/numa.c
@@ -106,6 +106,8 @@ static void numa_node_parse(NumaNodeOptions *node, QemuOpts 
*opts, Error **errp)
 numa_info[nodenr].node_mem = object_property_get_int(o, "size", NULL);
 numa_info[nodenr].node_memdev = MEMORY_BACKEND(o);
 }
+numa_info[nodenr].present = true;
+max_numa_nodeid = MAX(max_numa_nodeid, nodenr + 1);
 }
 
 int numa_init_func(QemuOpts *opts, void *opaque)
diff --git a/vl.c b/vl.c
index a1686ef..41ddcd2 100644
--- a/vl.c
+++ b/vl.c
@@ -196,6 +196,7 @@ static QTAILQ_HEAD(, FWBootEntry) fw_boot_order =
 QTAILQ_HEAD_INITIALIZER(fw_boot_order);
 
 int nb_numa_nodes;
+int max_numa_nodeid;
 NodeInfo numa_info[MAX_NODES];
 
 uint8_t qemu_uuid[16];
@@ -2984,10 +2985,12 @@ int main(int argc, char **argv, char **envp)
 
 for (i = 0; i < MAX_NODES; i++) {
 numa_info[i].node_mem = 0;
+numa_info[i].present = false;
 bitmap_zero(numa_info[i].node_cpu, MAX_CPUMASK_BITS);
 }
 
 nb_numa_nodes = 0;
+max_numa_nodeid = 0;
 nb_nics = 0;
 
 bdrv_init_with_whitelist();
-- 
MST




[Qemu-devel] [PULL 07/37] vhost-user: fix wrong ids in documentation

2014-06-29 Thread Michael S. Tsirkin
From: Damjan Marion 

Signed-off-by: Damjan Marion 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 docs/specs/vhost-user.txt | 28 ++--
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt
index 0ea767e..2641390 100644
--- a/docs/specs/vhost-user.txt
+++ b/docs/specs/vhost-user.txt
@@ -132,7 +132,7 @@ Message types
 
  * VHOST_USER_GET_FEATURES
 
-  Id: 2
+  Id: 1
   Equivalent ioctl: VHOST_GET_FEATURES
   Master payload: N/A
   Slave payload: u64
@@ -141,7 +141,7 @@ Message types
 
  * VHOST_USER_SET_FEATURES
 
-  Id: 3
+  Id: 2
   Ioctl: VHOST_SET_FEATURES
   Master payload: u64
 
@@ -149,7 +149,7 @@ Message types
 
  * VHOST_USER_SET_OWNER
 
-  Id: 4
+  Id: 3
   Equivalent ioctl: VHOST_SET_OWNER
   Master payload: N/A
 
@@ -159,7 +159,7 @@ Message types
 
  * VHOST_USER_RESET_OWNER
 
-  Id: 5
+  Id: 4
   Equivalent ioctl: VHOST_RESET_OWNER
   Master payload: N/A
 
@@ -168,7 +168,7 @@ Message types
 
  * VHOST_USER_SET_MEM_TABLE
 
-  Id: 6
+  Id: 5
   Equivalent ioctl: VHOST_SET_MEM_TABLE
   Master payload: memory regions description
 
@@ -179,7 +179,7 @@ Message types
 
  * VHOST_USER_SET_LOG_BASE
 
-  Id: 7
+  Id: 6
   Equivalent ioctl: VHOST_SET_LOG_BASE
   Master payload: u64
 
@@ -187,7 +187,7 @@ Message types
 
  * VHOST_USER_SET_LOG_FD
 
-  Id: 8
+  Id: 7
   Equivalent ioctl: VHOST_SET_LOG_FD
   Master payload: N/A
 
@@ -195,7 +195,7 @@ Message types
 
  * VHOST_USER_SET_VRING_NUM
 
-  Id: 9
+  Id: 8
   Equivalent ioctl: VHOST_SET_VRING_NUM
   Master payload: vring state description
 
@@ -203,7 +203,7 @@ Message types
 
  * VHOST_USER_SET_VRING_ADDR
 
-  Id: 10
+  Id: 9
   Equivalent ioctl: VHOST_SET_VRING_ADDR
   Master payload: vring address description
   Slave payload: N/A
@@ -212,7 +212,7 @@ Message types
 
  * VHOST_USER_SET_VRING_BASE
 
-  Id: 11
+  Id: 10
   Equivalent ioctl: VHOST_SET_VRING_BASE
   Master payload: vring state description
 
@@ -220,7 +220,7 @@ Message types
 
  * VHOST_USER_GET_VRING_BASE
 
-  Id: 12
+  Id: 11
   Equivalent ioctl: VHOST_USER_GET_VRING_BASE
   Master payload: vring state description
   Slave payload: vring state description
@@ -229,7 +229,7 @@ Message types
 
  * VHOST_USER_SET_VRING_KICK
 
-  Id: 13
+  Id: 12
   Equivalent ioctl: VHOST_SET_VRING_KICK
   Master payload: u64
 
@@ -242,7 +242,7 @@ Message types
 
  * VHOST_USER_SET_VRING_CALL
 
-  Id: 14
+  Id: 13
   Equivalent ioctl: VHOST_SET_VRING_CALL
   Master payload: u64
 
@@ -255,7 +255,7 @@ Message types
 
  * VHOST_USER_SET_VRING_ERR
 
-  Id: 15
+  Id: 14
   Equivalent ioctl: VHOST_SET_VRING_ERR
   Master payload: u64
 
-- 
MST




[Qemu-devel] [PULL 08/37] pc: make isapc and pc-0.10 to pc-0.13 have 1.7.0 memory layout

2014-06-29 Thread Michael S. Tsirkin
From: Don Slutz 

QEMU 2.0 changed memory layout for isapc and pc-0.10 to pc-0.13.
This prevents migration from QEMU 1.7.0 for these
machine types when -m 3.5G is specified.

Paolo Bonzini asked that:

smbios_legacy_mode = true;
has_reserved_memory = false;
option_rom_has_mr = true;
rom_file_has_mr = false;

also be done.

Cc: qemu-sta...@nongnu.org
Cc: Paolo Bonzini 
Signed-off-by: Don Slutz 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
Fixes: https://bugs.launchpad.net/qemu/+bug/1334307
Tested-by: "Slutz, Donald Christopher" 
---
 hw/i386/pc_piix.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 47546b7..2dccb34 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -392,6 +392,11 @@ static void pc_init_pci_no_kvmclock(MachineState *machine)
 has_pci_info = false;
 has_acpi_build = false;
 smbios_defaults = false;
+gigabyte_align = false;
+smbios_legacy_mode = true;
+has_reserved_memory = false;
+option_rom_has_mr = true;
+rom_file_has_mr = false;
 x86_cpu_compat_disable_kvm_features(FEAT_KVM, KVM_FEATURE_PV_EOI);
 enable_compat_apic_id_mode();
 pc_init1(machine, 1, 0);
@@ -402,6 +407,11 @@ static void pc_init_isa(MachineState *machine)
 has_pci_info = false;
 has_acpi_build = false;
 smbios_defaults = false;
+gigabyte_align = false;
+smbios_legacy_mode = true;
+has_reserved_memory = false;
+option_rom_has_mr = true;
+rom_file_has_mr = false;
 if (!machine->cpu_model) {
 machine->cpu_model = "486";
 }
-- 
MST




[Qemu-devel] [PULL 13/37] vhost-user: fix regions provied with VHOST_USER_SET_MEM_TABLE message

2014-06-29 Thread Michael S. Tsirkin
From: Damjan Marion 

Old code was affected by memory gaps which resulted in buffer pointers
pointing to address outside of the mapped regions.

Here we are introducing following changes:
 - new function qemu_get_ram_block_host_ptr() returns host pointer
   to the ram block, it is needed to calculate offset of specific
   region in the host memory
 - new field mmap_offset is added to the VhostUserMemoryRegion. It
   contains offset where specific region starts in the mapped memory.
   As there is stil no wider adoption of vhost-user agreement was made
   that we will not bump version number due to this change
 - other fileds in VhostUserMemoryRegion struct are not changed, as
   they are all needed for usermode app implementation
 - region data is not taken from ram_list.blocks anymore, instead we
   use region data which is alredy calculated for use in vhost-net
 - Now multiple regions can have same FD and user applicaton can call
   mmap() multiple times with the same FD but with different offset
   (user needs to take care for offset page alignment)

Signed-off-by: Damjan Marion 
Acked-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
Signed-off-by: Damjan Marion 
---
 include/exec/ram_addr.h   |  1 +
 exec.c|  7 +++
 hw/virtio/vhost-user.c| 23 ++-
 docs/specs/vhost-user.txt |  7 ---
 4 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index 55ca676..e9eb831 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -29,6 +29,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void 
*host,
MemoryRegion *mr);
 ram_addr_t qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr);
 int qemu_get_ram_fd(ram_addr_t addr);
+void *qemu_get_ram_block_host_ptr(ram_addr_t addr);
 void *qemu_get_ram_ptr(ram_addr_t addr);
 void qemu_ram_free(ram_addr_t addr);
 void qemu_ram_free_from_ptr(ram_addr_t addr);
diff --git a/exec.c b/exec.c
index c849405..a94c583 100644
--- a/exec.c
+++ b/exec.c
@@ -1456,6 +1456,13 @@ int qemu_get_ram_fd(ram_addr_t addr)
 return block->fd;
 }
 
+void *qemu_get_ram_block_host_ptr(ram_addr_t addr)
+{
+RAMBlock *block = qemu_get_ram_block(addr);
+
+return block->host;
+}
+
 /* Return a host pointer to ram allocated with qemu_ram_alloc.
With the exception of the softmmu code in this file, this should
only be used for local memory (e.g. video ram) that the device owns,
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 0df6a93..38e5806 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -14,6 +14,7 @@
 #include "sysemu/kvm.h"
 #include "qemu/error-report.h"
 #include "qemu/sockets.h"
+#include "exec/ram_addr.h"
 
 #include 
 #include 
@@ -47,6 +48,7 @@ typedef struct VhostUserMemoryRegion {
 uint64_t guest_phys_addr;
 uint64_t memory_size;
 uint64_t userspace_addr;
+uint64_t mmap_offset;
 } VhostUserMemoryRegion;
 
 typedef struct VhostUserMemory {
@@ -183,10 +185,10 @@ static int vhost_user_call(struct vhost_dev *dev, 
unsigned long int request,
 {
 VhostUserMsg msg;
 VhostUserRequest msg_request;
-RAMBlock *block = 0;
 struct vhost_vring_file *file = 0;
 int need_reply = 0;
 int fds[VHOST_MEMORY_MAX_NREGIONS];
+int i, fd;
 size_t fd_num = 0;
 
 assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
@@ -212,14 +214,17 @@ static int vhost_user_call(struct vhost_dev *dev, 
unsigned long int request,
 break;
 
 case VHOST_SET_MEM_TABLE:
-QTAILQ_FOREACH(block, &ram_list.blocks, next)
-{
-if (block->fd > 0) {
-msg.memory.regions[fd_num].userspace_addr =
-(uintptr_t) block->host;
-msg.memory.regions[fd_num].memory_size = block->length;
-msg.memory.regions[fd_num].guest_phys_addr = block->offset;
-fds[fd_num++] = block->fd;
+for (i = 0; i < dev->mem->nregions; ++i) {
+struct vhost_memory_region *reg = dev->mem->regions + i;
+fd = qemu_get_ram_fd(reg->guest_phys_addr);
+if (fd > 0) {
+msg.memory.regions[fd_num].userspace_addr = 
reg->userspace_addr;
+msg.memory.regions[fd_num].memory_size  = reg->memory_size;
+msg.memory.regions[fd_num].guest_phys_addr = 
reg->guest_phys_addr;
+msg.memory.regions[fd_num].mmap_offset = reg->userspace_addr -
+(uintptr_t) 
qemu_get_ram_block_host_ptr(reg->guest_phys_addr);
+assert(fd_num < VHOST_MEMORY_MAX_NREGIONS);
+fds[fd_num++] = fd;
 }
 }
 
diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt
index 2641390..6abb697 100644
--- a/docs/specs/vhost-user.txt
+++ b/docs/specs/vhost-user.txt
@@ -78,13 +78,14 @@ Depending on the request type, payload can be:
Padding: 32-bit
 
A

[Qemu-devel] [PULL 09/37] Allow mismatched virtio config-len

2014-06-29 Thread Michael S. Tsirkin
From: "Dr. David Alan Gilbert" 

Commit 'virtio: validate config_len on load' restricted config_len
loaded from the wire to match the config_len that the device had.

Unfortunately, there are cases where this isn't true, the one
we found it on was the wce addition in virtio-blk.

Allow mismatched config-lengths:
   *) If the version on the wire is shorter then fine
   *) If the version on the wire is longer, load what we have space
  for and skip the rest.

(This is m...@redhat.com's rework of what I originally posted)

Signed-off-by: Dr. David Alan Gilbert 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 hw/virtio/virtio.c | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index a3082d5..c1d538c 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -926,12 +926,18 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
 return -1;
 }
 config_len = qemu_get_be32(f);
-if (config_len != vdev->config_len) {
-error_report("Unexpected config length 0x%x. Expected 0x%zx",
- config_len, vdev->config_len);
-return -1;
+
+/*
+ * There are cases where the incoming config can be bigger or smaller
+ * than what we have; so load what we have space for, and skip
+ * any excess that's in the stream.
+ */
+qemu_get_buffer(f, vdev->config, MIN(config_len, vdev->config_len));
+
+while (config_len > vdev->config_len) {
+qemu_get_byte(f);
+config_len--;
 }
-qemu_get_buffer(f, vdev->config, vdev->config_len);
 
 num = qemu_get_be32(f);
 
-- 
MST




[Qemu-devel] [PULL 03/37] numa: fix comment

2014-06-29 Thread Michael S. Tsirkin
s/if given for/is given for/;

Reported-by: Hu Tao 
Signed-off-by: Michael S. Tsirkin 
---
 numa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/numa.c b/numa.c
index 47049a5..6c2eae7 100644
--- a/numa.c
+++ b/numa.c
@@ -161,7 +161,7 @@ void set_numa_nodes(void)
 nb_numa_nodes = MAX_NODES;
 }
 
-/* If no memory size if given for any node, assume the default case
+/* If no memory size is given for any node, assume the default case
  * and distribute the available memory equally across all nodes
  */
 for (i = 0; i < nb_numa_nodes; i++) {
-- 
MST




[Qemu-devel] [PULL 02/37] openrisc: fix comment

2014-06-29 Thread Michael S. Tsirkin
Fix English in comment:

s/the each/each/

s/  \*\// \*\//

Signed-off-by: Michael S. Tsirkin 
Reviewed-by: Igor Mammedov 
---
 target-openrisc/translate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-openrisc/translate.c b/target-openrisc/translate.c
index b728718..55ff935 100644
--- a/target-openrisc/translate.c
+++ b/target-openrisc/translate.c
@@ -531,14 +531,14 @@ static void dec_calc(DisasContext *dc, uint32_t insn)
 TCGv_i64 high = tcg_temp_new_i64();
 TCGv_i32 sr_ove = tcg_temp_local_new_i32();
 int lab = gen_new_label();
-/* Calculate the each result.  */
+/* Calculate each result. */
 tcg_gen_extu_i32_i64(tra, cpu_R[ra]);
 tcg_gen_extu_i32_i64(trb, cpu_R[rb]);
 tcg_gen_mul_i64(result, tra, trb);
 tcg_temp_free_i64(tra);
 tcg_temp_free_i64(trb);
 tcg_gen_shri_i64(high, result, TARGET_LONG_BITS);
-/* Overflow or not.  */
+/* Overflow or not. */
 tcg_gen_brcondi_i64(TCG_COND_EQ, high, 0x, lab);
 tcg_gen_ori_tl(cpu_sr, cpu_sr, (SR_OV | SR_CY));
 tcg_gen_andi_tl(sr_ove, cpu_sr, SR_OVE);
-- 
MST




[Qemu-devel] [PULL 05/37] pc: Fix "prog_if" typo on PC_COMPAT_2_0

2014-06-29 Thread Michael S. Tsirkin
From: Eduardo Habkost 

The property name is "prog_if", not "prof_if".

Signed-off-by: Eduardo Habkost 
Reported-by: BALATON Zoltan 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 include/hw/i386/pc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 81718b8..1c0c382 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -321,7 +321,7 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
 },\
 {\
 .driver   = "pci-serial-2x",\
-.property = "prof_if",\
+.property = "prog_if",\
 .value= stringify(0),\
 },\
 {\
-- 
MST




[Qemu-devel] [PULL 04/37] pc: Move q35 compat props to PC_COMPAT_*

2014-06-29 Thread Michael S. Tsirkin
From: Eduardo Habkost 

For each compat property on PC_Q35_COMPAT_*, there are only two
possibilities:

 * If the device is never instantiated when using a machine other than
   pc-q35, then the compat property can be safely added to
   PC_COMPAT_*;
 * If the device can be instantiated when using a machine other than
   pc-q35, that means the other machines also need the compat property
   to be set.

That means we don't need separate PC_Q35_COMPAT_* macros at all, today.

The hpet.hpet-intcap case is interesting: piix and q35 do have something
that emulates different defaults, but the machine-specific default is
applied _after_ compat_props are applied, by simply checking if the
property is zero (which is the real default on the hpet code).

The hpet.hpet-intcap=0x4 compat property can (should?) be applied to
piix too, because 0x4 was the default on both piix and q35 before the
hpet-intcap property was introduced.

Now, if one day we change the default HPET intcap on one of the PC
machine-types again, we may want to introduce PC_{Q35,I440FX}_COMPAT
macros. But while we don't need that, we can keep the code simple.

Signed-off-by: Eduardo Habkost 
Cc: Liu Ping Fan 
Cc: Peter Maydell 
Reviewed-by: Michael S. Tsirkin 
Signed-off-by: Michael S. Tsirkin 
---
 include/hw/i386/pc.h | 55 +---
 hw/i386/pc_q35.c | 10 +-
 2 files changed, 23 insertions(+), 42 deletions(-)

diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 486e98f..81718b8 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -294,43 +294,6 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);
 int e820_get_num_entries(void);
 bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
 
-#define PC_Q35_COMPAT_2_0 \
-PC_COMPAT_2_0, \
-{\
-.driver   = "ICH9-LPC",\
-.property = "memory-hotplug-support",\
-.value= "off",\
-},{\
-.driver   = "xio3130-downstream",\
-.property = COMPAT_PROP_PCP,\
-.value= "off",\
-},{\
-.driver   = "ioh3420",\
-.property = COMPAT_PROP_PCP,\
-.value= "off",\
-}
- 
-#define PC_Q35_COMPAT_1_7 \
-PC_COMPAT_1_7, \
-PC_Q35_COMPAT_2_0, \
-{\
-.driver   = "hpet",\
-.property = HPET_INTCAP,\
-.value= stringify(4),\
-}
-
-#define PC_Q35_COMPAT_1_6 \
-PC_COMPAT_1_6, \
-PC_Q35_COMPAT_1_7
-
-#define PC_Q35_COMPAT_1_5 \
-PC_COMPAT_1_5, \
-PC_Q35_COMPAT_1_6
-
-#define PC_Q35_COMPAT_1_4 \
-PC_COMPAT_1_4, \
-PC_Q35_COMPAT_1_5
-
 #define PC_COMPAT_2_0 \
 {\
 .driver   = "virtio-scsi-pci",\
@@ -370,6 +333,19 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
 .driver   = "virtio-net-pci",\
 .property = "guest_announce",\
 .value= "off",\
+},\
+{\
+.driver   = "ICH9-LPC",\
+.property = "memory-hotplug-support",\
+.value= "off",\
+},{\
+.driver   = "xio3130-downstream",\
+.property = COMPAT_PROP_PCP,\
+.value= "off",\
+},{\
+.driver   = "ioh3420",\
+.property = COMPAT_PROP_PCP,\
+.value= "off",\
 }
 
 #define PC_COMPAT_1_7 \
@@ -383,6 +359,11 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *);
 .driver   = "PIIX4_PM",\
 .property = "acpi-pci-hotplug-with-bridge-support",\
 .value= "off",\
+},\
+{\
+.driver   = "hpet",\
+.property = HPET_INTCAP,\
+.value= stringify(4),\
 }
 
 #define PC_COMPAT_1_6 \
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 155db99..36b6ab0 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -361,7 +361,7 @@ static QEMUMachine pc_q35_machine_v2_0 = {
 .name = "pc-q35-2.0",
 .init = pc_q35_init_2_0,
 .compat_props = (GlobalProperty[]) {
-PC_Q35_COMPAT_2_0,
+PC_COMPAT_2_0,
 { /* end of list */ }
 },
 };
@@ -373,7 +373,7 @@ static QEMUMachine pc_q35_machine_v1_7 = {
 .name = "pc-q35-1.7",
 .init = pc_q35_init_1_7,
 .compat_props = (GlobalProperty[]) {
-PC_Q35_COMPAT_1_7,
+PC_COMPAT_1_7,
 { /* end of list */ }
 },
 };
@@ -385,7 +385,7 @@ static QEMUMachine pc_q35_machine_v1_6 = {
 .name = "pc-q35-1.6",
 .init = pc_q35_init_1_6,
 .compat_props = (GlobalProperty[]) {
-PC_Q35_COMPAT_1_6,
+PC_COMPAT_1_6,
 { /* end of list */ }
 },
 };
@@ -395,7 +395,7 @@ static QEMUMachine pc_q35_machine_v1_5 = {
 .name = "pc-q35-1.5",
 .init = pc_q35_init_1_5,
 .compat_props = (GlobalProperty[]) {
-PC_Q35_COMPAT_1_5,
+PC_COMPAT_1_5,
 { /* end of list */ }
 },
 };
@@ -409,7 +409,7 @@

[Qemu-devel] [PULL 00/37] pc,vhost,virtio fixes, enhancements

2014-06-29 Thread Michael S. Tsirkin
The following changes since commit 4daebe014effba37246b81d25acca5fa2df82f01:

  Merge remote-tracking branch 'remotes/xtensa/tags/20140629-xtensa' into 
staging (2014-06-29 16:17:50 +0100)

are available in the git repository at:

  git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_upstream

for you to fetch changes up to b4900c0e8a606bed834bd610fbae0fdf1d697ff9:

  tests: add human format test for string output visitor (2014-06-29 19:39:43 
+0300)


pc,vhost,virtio fixes, enhancements

virtio bi-endian support
new command to resync RTC
misc bugfixes and cleanups

Signed-off-by: Michael S. Tsirkin 


Alexander Graf (1):
  virtio-serial: don't migrate the config space

Cédric Le Goater (1):
  virtio-net: byteswap virtio-net header

Damjan Marion (2):
  vhost-user: fix wrong ids in documentation
  vhost-user: fix regions provied with VHOST_USER_SET_MEM_TABLE message

Don Slutz (1):
  pc: make isapc and pc-0.10 to pc-0.13 have 1.7.0 memory layout

Dr. David Alan Gilbert (1):
  Allow mismatched virtio config-len

Eduardo Habkost (5):
  pc: Move q35 compat props to PC_COMPAT_*
  pc: Fix "prog_if" typo on PC_COMPAT_2_0
  numa: Keep track of NUMA nodes present on the command-line
  numa: Reject duplicate node IDs
  numa: Reject configuration if not all node IDs are present

Greg Kurz (14):
  virtio: introduce device specific migration calls
  virtio-net: implement per-device migration calls
  virtio-blk: implement per-device migration calls
  virtio-serial: implement per-device migration calls
  virtio-balloon: implement per-device migration calls
  virtio-rng: implement per-device migration calls
  virtio: add subsections to the migration stream
  exec: introduce target_words_bigendian() helper
  cpu: introduce CPUClass::virtio_is_big_endian()
  virtio: add endian-ambivalent support to VirtIODevice
  virtio: memory accessors for endian-ambivalent targets
  virtio-9p: use virtio wrappers to access headers
  target-ppc: enable virtio endian ambivalent support
  vhost-net: disable when cross-endian

Hu Tao (1):
  tests: add human format test for string output visitor

Marcelo Tosatti (1):
  mc146818rtc: add rtc-reset-reinjection QMP command

Michael S. Tsirkin (4):
  numa: fix comment
  openrisc: fix comment
  numa: fix comment
  vhost-user: typo fixups

Rusty Russell (6):
  virtio: allow byte swapping for vring
  virtio-net: use virtio wrappers to access headers
  virtio-balloon: use virtio wrappers to access page frame numbers
  virtio-blk: use virtio wrappers to access headers
  virtio-scsi: use virtio wrappers to access headers
  virtio-serial-bus: use virtio wrappers to access headers

 qapi-schema.json   |  12 ++
 include/exec/ram_addr.h|   1 +
 include/hw/i386/pc.h   |  57 +++--
 include/hw/virtio/virtio-access.h  | 170 +++
 include/hw/virtio/virtio.h |  17 ++-
 include/qom/cpu.h  |   1 +
 include/sysemu/sysemu.h|   7 +-
 target-ppc/cpu.h   |   2 +
 exec.c |  15 ++-
 hw/9pfs/virtio-9p-device.c |   3 +-
 hw/block/virtio-blk.c  |  62 ++
 hw/char/virtio-serial-bus.c|  94 +--
 hw/i386/pc_piix.c  |  10 ++
 hw/i386/pc_q35.c   |  10 +-
 hw/net/vhost_net.c |  19 +++
 hw/net/virtio-net.c|  56 ++---
 hw/scsi/virtio-scsi.c  |  40 ---
 hw/timer/mc146818rtc.c |  18 +++
 hw/virtio/vhost-user.c |  23 ++--
 hw/virtio/virtio-balloon.c |  33 +++---
 hw/virtio/virtio-pci.c |  11 +-
 hw/virtio/virtio-rng.c |  12 +-
 hw/virtio/virtio.c | 232 +++--
 monitor.c  |   7 ++
 numa.c |  28 -
 qom/cpu.c  |   6 +
 target-openrisc/translate.c|   4 +-
 target-ppc/translate_init.c|  15 +++
 tests/test-string-output-visitor.c | 109 ++---
 vl.c   |   3 +
 docs/specs/vhost-user.txt  |  36 +++---
 qmp-commands.hx|  23 
 32 files changed, 854 insertions(+), 282 deletions(-)
 create mode 100644 include/hw/virtio/virtio-access.h




[Qemu-devel] [PULL 01/37] numa: fix comment

2014-06-29 Thread Michael S. Tsirkin
Fix up English in comments:
s/the each/each/

Signed-off-by: Michael S. Tsirkin 
Reviewed-by: Igor Mammedov 
---
 numa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/numa.c b/numa.c
index e471afe..47049a5 100644
--- a/numa.c
+++ b/numa.c
@@ -172,7 +172,7 @@ void set_numa_nodes(void)
 if (i == nb_numa_nodes) {
 uint64_t usedmem = 0;
 
-/* On Linux, the each node's border has to be 8MB aligned,
+/* On Linux, each node's border has to be 8MB aligned,
  * the final node gets the rest.
  */
 for (i = 0; i < nb_numa_nodes - 1; i++) {
-- 
MST




Re: [Qemu-devel] [PATCH v9 00/22] legacy virtio support for cross-endian targets

2014-06-29 Thread Alexander Graf


> Am 29.06.2014 um 17:13 schrieb "Michael S. Tsirkin" :
> 
>> On Tue, Jun 24, 2014 at 07:06:58PM +0200, Greg Kurz wrote:
>> The current legacy virtio devices have a fundamental flaw: they all share
>> data between host and guest with guest endianness ordering. This is ok for
>> nearly all architectures that have fixed endianness. Unfortunately, it breaks
>> for recent PPC64 and ARM targets that can change endianness at runtime.
>> The virtio-1.0 specification fixes the issue by enforcing little-endian
>> ordering. It may take some time though until the code for 1.0 gets available
>> and supported, and all the users can migrate. There have been discussions
>> for some monthes about supporting such oddity: now we have little-endian
>> PPC64 distros available, it is worth to propose something.
>> 
>> This patch set brings legacy virtio support for cross-endian targets. The
>> rationale is that we add a new device_endianness property to VirtIODevice.
>> This property is used as a runtime indicator to decide wether we should
>> do little-endian or big-endian conversion, as opposed to the compile time
>> choice we have now with TARGTE_WORDS_BIGENDIAN. The choice was made to
>> sample the device endianness out of the endianness mode of the guest
>> CPU that does the reset. It is an evil but logical consequence of the
>> initial flaw in the virtio specification, and it was agreed that the concept
>> would be a good common base for ARM and PPC64 enablement at least. Please
>> note also that this new property is state and must be preserved across
>> migrations.
>> 
>> There are several parts in the serie:
>> - patches 1 and 2 are simple fixes
>> - patches 3 to 9 introduce VMState based subsections in the virtio
>>  migration code. This is needed because we introduce a new property
>>  in VirtIODevice that we want to migrate without ruining compatibility
>>  efforts
>> - patches 10 to 13 bring virtio device endianness and memory accessors
>>  to be used by the virtio code
>> - patches 14 to 20 wire the new memory accessors everywhere accross the
>>  virtio code
>> - patch 21 is the PPC64 enablement
>> - patch 22 is a follow-up workaround to disable vhost-net acceleration
>>  in the case the host and guest have different endianness, because
>>  it is not supported for the moment
>> 
>> Changes since v8 are provided in each patch.
>> 
>> Cheers.
> 
> Applied, thanks everyone.

Woohoo :).


Alex




Re: [Qemu-devel] [PULL 2.1 00/10] target-xtensa queue 2014-06-29

2014-06-29 Thread Max Filippov
On Sun, Jun 29, 2014 at 7:43 PM, Peter Maydell  wrote:
> On 28 June 2014 23:49, Max Filippov  wrote:
>> Hi Peter,
>>
>> please pull my current target-xtensa patch queue.
>> The following changes since commit d4cba13bdf251baeedb36b87c1e9f6766773e380:
>>
>>   tcg/ppc: Fix failure in tcg_out_mem_long (2014-06-27 13:23:41 +0100)
>>
>> are available in the git repository at:
>>
>>   g...@github.com:OSLL/qemu-xtensa.git tags/20140629-xtensa
>
> Can you fix up whatever you're using to generate these emails,
> please? This isn't a valid git url, you probably meant
>git://github.com/OSLL/qemu-xtensa.git tags/20140629-xtensa

Yeah, sorry, used ssh protocol remote instead of git this time.

-- 
Thanks.
-- Max



Re: [Qemu-devel] [PULL 2.1 00/10] target-xtensa queue 2014-06-29

2014-06-29 Thread Peter Maydell
On 28 June 2014 23:49, Max Filippov  wrote:
> Hi Peter,
>
> please pull my current target-xtensa patch queue.
> The following changes since commit d4cba13bdf251baeedb36b87c1e9f6766773e380:
>
>   tcg/ppc: Fix failure in tcg_out_mem_long (2014-06-27 13:23:41 +0100)
>
> are available in the git repository at:
>
>   g...@github.com:OSLL/qemu-xtensa.git tags/20140629-xtensa

Can you fix up whatever you're using to generate these emails,
please? This isn't a valid git url, you probably meant
   git://github.com/OSLL/qemu-xtensa.git tags/20140629-xtensa

> for you to fetch changes up to f55b32e7499b291058a0d0fd7d35b14c24791684:
>
>   hw/xtensa/xtfpga: implement initrd loading (2014-06-29 02:32:42 +0400)
>
> 
> Xtensa fixes and improvements queue 2014-06-29:
> - fix FLASH mapping to boot region for KC705;
> - clean up boot parameters passing;
> - add uImage, DTB and initrd support.

Applied, thanks.

-- PMM



Re: [Qemu-devel] [PATCH 0/3] another round of pci fixes

2014-06-29 Thread Michael S. Tsirkin
On Fri, Jun 20, 2014 at 01:55:40PM +0800, Hu Tao wrote:
> Hi Michael,
> 
> This series is on top of your pci tree.
> 
> This series includes two fixups and one patch for adding test of human
> format of string output visitor, please review. thanks!

All applied, thanks!

> 
> Hu Tao (3):
>   fixup! libqemustub: add more stubs for qemu-char
>   fixup! qapi/string-output-visitor: fix bugs
>   tests: add human format test for string output visitor
> 
>  qapi/string-output-visitor.c   |   2 +-
>  stubs/Makefile.objs|   2 +-
>  tests/test-string-output-visitor.c | 109 
> ++---
>  3 files changed, 92 insertions(+), 21 deletions(-)
> 
> -- 
> 1.9.3



Re: [Qemu-devel] [PATCH] numa: check for busy memory backend

2014-06-29 Thread Michael S. Tsirkin
On Wed, Jun 25, 2014 at 05:04:14PM +0800, Hu Tao wrote:
> ..to prevent one memory backend from being used by more than one numa
> node.

Thanks, but please always make the msg content self-contained
so it can be understood without the subject.
E.g. here, just drop "..to".

Are you sure we want this? Is there a chance sharing a backend
can be useful?

Igor, what's your take?

> 
> Signed-off-by: Hu Tao 
> ---
>  numa.c | 7 +++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/numa.c b/numa.c
> index e471afe..6c1c554 100644
> --- a/numa.c
> +++ b/numa.c
> @@ -279,6 +279,13 @@ void memory_region_allocate_system_memory(MemoryRegion 
> *mr, Object *owner,
>  exit(1);
>  }
>  
> +if (memory_region_is_mapped(seg)) {
> +char *path = 
> object_get_canonical_path_component(OBJECT(backend));
> +error_report("memory backend %s is busy", path);
> +g_free(path);
> +exit(1);
> +}
> +
>  memory_region_add_subregion(mr, addr, seg);
>  vmstate_register_ram_global(seg);
>  addr += size;
> -- 
> 1.9.3



Re: [Qemu-devel] [PULL 00/47] Block patches for 2.1.0-rc0

2014-06-29 Thread Peter Maydell
On 27 June 2014 20:08, Kevin Wolf  wrote:
> The following changes since commit 2b5b7ae917e8db48431631b1c5d909fa46c223a6:
>
>   Merge remote-tracking branch 'remotes/mjt/tags/trivial-patches-2014-06-24' 
> into staging (2014-06-24 17:14:57 +0100)
>
> are available in the git repository at:
>
>
>   git://repo.or.cz/qemu/kevin.git tags/for-upstream
>
> for you to fetch changes up to f5264553c381c5f305d6e11bef18da6a29f3f423:
>
>   iotests: Fix 083 for out-of-tree builds (2014-06-27 20:00:01 +0200)
>
> 

Applied, thanks.

-- PMM



Re: [Qemu-devel] [PATCH v9 00/22] legacy virtio support for cross-endian targets

2014-06-29 Thread Michael S. Tsirkin
On Tue, Jun 24, 2014 at 07:06:58PM +0200, Greg Kurz wrote:
> The current legacy virtio devices have a fundamental flaw: they all share
> data between host and guest with guest endianness ordering. This is ok for
> nearly all architectures that have fixed endianness. Unfortunately, it breaks
> for recent PPC64 and ARM targets that can change endianness at runtime.
> The virtio-1.0 specification fixes the issue by enforcing little-endian
> ordering. It may take some time though until the code for 1.0 gets available
> and supported, and all the users can migrate. There have been discussions
> for some monthes about supporting such oddity: now we have little-endian
> PPC64 distros available, it is worth to propose something.
> 
> This patch set brings legacy virtio support for cross-endian targets. The
> rationale is that we add a new device_endianness property to VirtIODevice.
> This property is used as a runtime indicator to decide wether we should
> do little-endian or big-endian conversion, as opposed to the compile time
> choice we have now with TARGTE_WORDS_BIGENDIAN. The choice was made to
> sample the device endianness out of the endianness mode of the guest
> CPU that does the reset. It is an evil but logical consequence of the
> initial flaw in the virtio specification, and it was agreed that the concept
> would be a good common base for ARM and PPC64 enablement at least. Please
> note also that this new property is state and must be preserved across
> migrations.
> 
> There are several parts in the serie:
> - patches 1 and 2 are simple fixes
> - patches 3 to 9 introduce VMState based subsections in the virtio
>   migration code. This is needed because we introduce a new property
>   in VirtIODevice that we want to migrate without ruining compatibility
>   efforts
> - patches 10 to 13 bring virtio device endianness and memory accessors
>   to be used by the virtio code
> - patches 14 to 20 wire the new memory accessors everywhere accross the
>   virtio code
> - patch 21 is the PPC64 enablement
> - patch 22 is a follow-up workaround to disable vhost-net acceleration
>   in the case the host and guest have different endianness, because
>   it is not supported for the moment
> 
> Changes since v8 are provided in each patch.
> 
> Cheers.

Applied, thanks everyone.

> ---
> 
> Alexander Graf (1):
>   virtio-serial: don't migrate the config space
> 
> Cédric Le Goater (1):
>   virtio-net: byteswap virtio-net header
> 
> Greg Kurz (14):
>   virtio: introduce device specific migration calls
>   virtio-net: implement per-device migration calls
>   virtio-blk: implement per-device migration calls
>   virtio-serial: implement per-device migration calls
>   virtio-balloon: implement per-device migration calls
>   virtio-rng: implement per-device migration calls
>   virtio: add subsections to the migration stream
>   exec: introduce target_words_bigendian() helper
>   cpu: introduce CPUClass::virtio_is_big_endian()
>   virtio: add endian-ambivalent support to VirtIODevice
>   virtio: memory accessors for endian-ambivalent targets
>   virtio-9p: use virtio wrappers to access headers
>   target-ppc: enable virtio endian ambivalent support
>   vhost-net: disable when cross-endian
> 
> Rusty Russell (6):
>   virtio: allow byte swapping for vring
>   virtio-net: use virtio wrappers to access headers
>   virtio-balloon: use virtio wrappers to access page frame numbers
>   virtio-blk: use virtio wrappers to access headers
>   virtio-scsi: use virtio wrappers to access headers
>   virtio-serial-bus: use virtio wrappers to access headers
> 
> 
>  exec.c|8 -
>  hw/9pfs/virtio-9p-device.c|3 -
>  hw/block/virtio-blk.c |   62 ++-
>  hw/char/virtio-serial-bus.c   |   94 ++--
>  hw/net/vhost_net.c|   19 +++
>  hw/net/virtio-net.c   |   56 +++---
>  hw/scsi/virtio-scsi.c |   40 ---
>  hw/virtio/virtio-balloon.c|   33 +++---
>  hw/virtio/virtio-pci.c|   11 +-
>  hw/virtio/virtio-rng.c|   12 +-
>  hw/virtio/virtio.c|  216 
> -
>  include/hw/virtio/virtio-access.h |  170 +
>  include/hw/virtio/virtio.h|   17 +++
>  include/qom/cpu.h |1 
>  qom/cpu.c |6 +
>  target-ppc/cpu.h  |2 
>  target-ppc/translate_init.c   |   15 +++
>  17 files changed, 583 insertions(+), 182 deletions(-)
>  create mode 100644 include/hw/virtio/virtio-access.h
> 
> --
> Greg



Re: [Qemu-devel] [PATCH v9 22/22] vhost-net: disable when cross-endian

2014-06-29 Thread Michael S. Tsirkin
On Tue, Jun 24, 2014 at 07:55:03PM +0200, Greg Kurz wrote:
> As of today, vhost assumes guest and host have the same endianness.
> This is definitely not compatible with modern PPC64 and ARM that
> can change endianness at runtime. Let's disable vhost-net and print
> an error message when we detect such a case:
> 
> qemu-system-ppc64: vhost-net does not support cross-endian
> qemu-system-ppc64: unable to start vhost net: 38: falling back on userspace 
> virtio
> 
> This way users can continue to run VMs without changing their setup and
> have a chance to know that performance will impacted.

s/will/will be/

> 
> Suggested-by: Michael S. Tsirkin 
> Signed-off-by: Greg Kurz 
> ---
>  hw/net/vhost_net.c |   19 +++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> index 7ac7c21..f87c798 100644
> --- a/hw/net/vhost_net.c
> +++ b/hw/net/vhost_net.c
> @@ -275,6 +275,19 @@ static void vhost_net_stop_one(struct vhost_net *net,
>  vhost_dev_disable_notifiers(&net->dev, dev);
>  }
>  
> +static bool vhost_net_device_endian_ok(VirtIODevice *vdev)
> +{
> +#ifdef TARGET_IS_BIENDIAN
> +#ifdef HOST_WORDS_BIGENDIAN
> +return virtio_is_big_endian(vdev);
> +#else
> +return !virtio_is_big_endian(vdev);
> +#endif
> +#else
> +return true;
> +#endif
> +}
> +
>  int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
>  int total_queues)
>  {
> @@ -283,6 +296,12 @@ int vhost_net_start(VirtIODevice *dev, NetClientState 
> *ncs,
>  VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
>  int r, i = 0;
>  
> +if (!vhost_net_device_endian_ok(dev)) {
> +error_report("vhost-net does not support cross-endian");
> +r = -ENOSYS;
> +goto err;
> +}
> +
>  if (!k->set_guest_notifiers) {
>  error_report("binding does not support guest notifiers");
>  r = -ENOSYS;



Re: [Qemu-devel] [PATCH 0/3] Validate NUMA node IDs (reject duplicate/missing node IDs properly)

2014-06-29 Thread Michael S. Tsirkin
On Thu, Jun 26, 2014 at 06:33:17PM -0300, Eduardo Habkost wrote:
> This is just a cleanup to make sure QEMU validate the NUMA node IDs on the
> command-line. After that, we may eventually change the code to accept sparse
> node IDs under some circumstances (but I am not sure that would be material 
> for
> QEMU 2.1).
> 
> Cc: Nishanth Aravamudan 
> Cc: "Michael S. Tsirkin" 
> Cc: Alexey Kardashevskiy 
> Cc: Hu Tao 
> Cc: qemu-devel@nongnu.org
> Cc: Anton Blanchard 
> Cc: David Rientjes 
> Cc: Igor Mammedov 


Applied, thanks!

> Eduardo Habkost (3):
>   numa: Keep track of NUMA nodes present on the command-line
>   numa: Reject duplicate node IDs
>   numa: Reject configuration if not all node IDs are present
> 
>  include/sysemu/sysemu.h |  7 ++-
>  numa.c  | 24 +++-
>  vl.c|  3 +++
>  3 files changed, 32 insertions(+), 2 deletions(-)
> 
> -- 
> 1.9.3



Re: [Qemu-devel] [PATCH v3] vhost-user: fix regions provied with VHOST_USER_SET_MEM_TABLE message

2014-06-29 Thread Michael S. Tsirkin
Subject has a typo.
Fixed it up.


On Thu, Jun 26, 2014 at 11:01:32PM +0200, Damjan Marion wrote:
> Old code was affected by memory gaps which resulted in buffer pointers
> pointing to address outside of the mapped regions.
> 
> Here we are introducing following changes:
>  - new function qemu_get_ram_block_host_ptr() returns host pointer
>to the ram block, it is needed to calculate offset of specific
>region in the host memory
>  - new field mmap_offset is added to the VhostUserMemoryRegion. It
>contains offset where specific region starts in the mapped memory.
>As there is stil no wider adoption of vhost-user agreement was made
>that we will not bump version number due to this change
>  - other fileds in VhostUserMemoryRegion struct are not changed, as
>they are all needed for usermode app implementation
>  - region data is not taken from ram_list.blocks anymore, instead we
>use region data which is alredy calculated for use in vhost-net

s/alredy/already/

>  - Now multiple regions can have same FD and user applicaton can call
>mmap() multiple times with the same FD but with different offset
>(user needs to take care for offset page alignment)
> 
> Signed-off-by: Damjan Marion 

Applied with these fixes.

> ---
>  docs/specs/vhost-user.txt |  7 ---
>  exec.c|  7 +++
>  hw/virtio/vhost-user.c| 23 ++-
>  include/exec/ram_addr.h   |  1 +
>  4 files changed, 26 insertions(+), 12 deletions(-)
> 
> diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt
> index 2641390..6abb697 100644
> --- a/docs/specs/vhost-user.txt
> +++ b/docs/specs/vhost-user.txt
> @@ -78,13 +78,14 @@ Depending on the request type, payload can be:
> Padding: 32-bit
>  
> A region is:
> -   ---
> -   | guest address | size | user address |
> -   ---
> +   -
> +   | guest address | size | user address | mmap offset |
> +   -
>  
> Guest address: a 64-bit guest address of the region
> Size: a 64-bit size
> User address: a 64-bit user address
> +   mmmap offset: 64-bit offset where region starts in the mapped memory
>  
>  
>  In QEMU the vhost-user message is implemented with the following struct:
> diff --git a/exec.c b/exec.c
> index c849405..a94c583 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1456,6 +1456,13 @@ int qemu_get_ram_fd(ram_addr_t addr)
>  return block->fd;
>  }
>  
> +void *qemu_get_ram_block_host_ptr(ram_addr_t addr)
> +{
> +RAMBlock *block = qemu_get_ram_block(addr);
> +
> +return block->host;
> +}
> +
>  /* Return a host pointer to ram allocated with qemu_ram_alloc.
> With the exception of the softmmu code in this file, this should
> only be used for local memory (e.g. video ram) that the device owns,
> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
> index 0df6a93..38e5806 100644
> --- a/hw/virtio/vhost-user.c
> +++ b/hw/virtio/vhost-user.c
> @@ -14,6 +14,7 @@
>  #include "sysemu/kvm.h"
>  #include "qemu/error-report.h"
>  #include "qemu/sockets.h"
> +#include "exec/ram_addr.h"
>  
>  #include 
>  #include 
> @@ -47,6 +48,7 @@ typedef struct VhostUserMemoryRegion {
>  uint64_t guest_phys_addr;
>  uint64_t memory_size;
>  uint64_t userspace_addr;
> +uint64_t mmap_offset;
>  } VhostUserMemoryRegion;
>  
>  typedef struct VhostUserMemory {
> @@ -183,10 +185,10 @@ static int vhost_user_call(struct vhost_dev *dev, 
> unsigned long int request,
>  {
>  VhostUserMsg msg;
>  VhostUserRequest msg_request;
> -RAMBlock *block = 0;
>  struct vhost_vring_file *file = 0;
>  int need_reply = 0;
>  int fds[VHOST_MEMORY_MAX_NREGIONS];
> +int i, fd;
>  size_t fd_num = 0;
>  
>  assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
> @@ -212,14 +214,17 @@ static int vhost_user_call(struct vhost_dev *dev, 
> unsigned long int request,
>  break;
>  
>  case VHOST_SET_MEM_TABLE:
> -QTAILQ_FOREACH(block, &ram_list.blocks, next)
> -{
> -if (block->fd > 0) {
> -msg.memory.regions[fd_num].userspace_addr =
> -(uintptr_t) block->host;
> -msg.memory.regions[fd_num].memory_size = block->length;
> -msg.memory.regions[fd_num].guest_phys_addr = block->offset;
> -fds[fd_num++] = block->fd;
> +for (i = 0; i < dev->mem->nregions; ++i) {
> +struct vhost_memory_region *reg = dev->mem->regions + i;
> +fd = qemu_get_ram_fd(reg->guest_phys_addr);
> +if (fd > 0) {
> +msg.memory.regions[fd_num].userspace_addr = 
> reg->userspace_addr;
> +msg.memory.regions[fd_num].memory_size  = reg->memory_size;
> +msg.memory.regions[fd_num].guest_phys_addr = 
> reg->guest_phys_addr;

Re: [Qemu-devel] [PATCH v3] vhost-user: fix regions provied with VHOST_USER_SET_MEM_TABLE message

2014-06-29 Thread Michael S. Tsirkin
On Fri, Jun 27, 2014 at 08:02:48AM +0300, Nikolay Nikolaev wrote:
> 
> 
> 
> On Fri, Jun 27, 2014 at 12:01 AM, Damjan Marion  wrote:
> 
> Old code was affected by memory gaps which resulted in buffer pointers
> pointing to address outside of the mapped regions.
> 
> Here we are introducing following changes:
>  - new function qemu_get_ram_block_host_ptr() returns host pointer
>    to the ram block, it is needed to calculate offset of specific
>    region in the host memory
>  - new field mmap_offset is added to the VhostUserMemoryRegion. It
>    contains offset where specific region starts in the mapped memory.
>    As there is stil no wider adoption of vhost-user agreement was made
>    that we will not bump version number due to this change
>  - other fileds in VhostUserMemoryRegion struct are not changed, as
>    they are all needed for usermode app implementation
>  - region data is not taken from ram_list.blocks anymore, instead we
>    use region data which is alredy calculated for use in vhost-net
>  - Now multiple regions can have same FD and user applicaton can call
>    mmap() multiple times with the same FD but with different offset
>    (user needs to take care for offset page alignment)
> 
> Signed-off-by: Damjan Marion 
> ---
>  docs/specs/vhost-user.txt |  7 ---
>  exec.c                    |  7 +++
>  hw/virtio/vhost-user.c    | 23 ++-
>  include/exec/ram_addr.h   |  1 +
>  4 files changed, 26 insertions(+), 12 deletions(-)
> 
> diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt
> index 2641390..6abb697 100644
> --- a/docs/specs/vhost-user.txt
> +++ b/docs/specs/vhost-user.txt
> @@ -78,13 +78,14 @@ Depending on the request type, payload can be:
>     Padding: 32-bit
> 
>     A region is:
> -   ---
> -   | guest address | size | user address |
> -   ---
> +   -
> +   | guest address | size | user address | mmap offset |
> +   -
> 
>     Guest address: a 64-bit guest address of the region
>     Size: a 64-bit size
>     User address: a 64-bit user address
> +   mmmap offset: 64-bit offset where region starts in the mapped memory
> 
> 
>  In QEMU the vhost-user message is implemented with the following struct:
> diff --git a/exec.c b/exec.c
> index c849405..a94c583 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1456,6 +1456,13 @@ int qemu_get_ram_fd(ram_addr_t addr)
>      return block->fd;
>  }
> 
> +void *qemu_get_ram_block_host_ptr(ram_addr_t addr)
> +{
> +    RAMBlock *block = qemu_get_ram_block(addr);
> +
> +    return block->host;
> +}
> +
>  /* Return a host pointer to ram allocated with qemu_ram_alloc.
>     With the exception of the softmmu code in this file, this should
>     only be used for local memory (e.g. video ram) that the device owns,
> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
> index 0df6a93..38e5806 100644
> --- a/hw/virtio/vhost-user.c
> +++ b/hw/virtio/vhost-user.c
> @@ -14,6 +14,7 @@
>  #include "sysemu/kvm.h"
>  #include "qemu/error-report.h"
>  #include "qemu/sockets.h"
> +#include "exec/ram_addr.h"
> 
>  #include 
>  #include 
> @@ -47,6 +48,7 @@ typedef struct VhostUserMemoryRegion {
>      uint64_t guest_phys_addr;
>      uint64_t memory_size;
>      uint64_t userspace_addr;
> +    uint64_t mmap_offset;
>  } VhostUserMemoryRegion;
> 
>  typedef struct VhostUserMemory {
> @@ -183,10 +185,10 @@ static int vhost_user_call(struct vhost_dev *dev,
> unsigned long int request,
>  {
>      VhostUserMsg msg;
>      VhostUserRequest msg_request;
> -    RAMBlock *block = 0;
>      struct vhost_vring_file *file = 0;
>      int need_reply = 0;
>      int fds[VHOST_MEMORY_MAX_NREGIONS];
> +    int i, fd;
>      size_t fd_num = 0;
> 
>      assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
> @@ -212,14 +214,17 @@ static int vhost_user_call(struct vhost_dev *dev,
> unsigned long int request,
>          break;
> 
>      case VHOST_SET_MEM_TABLE:
> -        QTAILQ_FOREACH(block, &ram_list.blocks, next)
> -        {
> -            if (block->fd > 0) {
> -                msg.memory.regions[fd_num].userspace_addr =
> -                    (uintptr_t) block->host;
> -                msg.memory.regions[fd_num].memory_size = block->length;
> -                msg.memory.regions[fd_num].guest_phys_addr = block->
> offset;
> -                fds[fd_num++] = block->fd;
> +        for (i = 0; i < dev->mem->nregions; ++i) {
> +            st

Re: [Qemu-devel] [PATCH v3] vhost-user: fix regions provied with VHOST_USER_SET_MEM_TABLE message

2014-06-29 Thread Michael S. Tsirkin
On Thu, Jun 26, 2014 at 11:01:32PM +0200, Damjan Marion wrote:
> Old code was affected by memory gaps which resulted in buffer pointers
> pointing to address outside of the mapped regions.
> 
> Here we are introducing following changes:
>  - new function qemu_get_ram_block_host_ptr() returns host pointer
>to the ram block, it is needed to calculate offset of specific
>region in the host memory
>  - new field mmap_offset is added to the VhostUserMemoryRegion. It
>contains offset where specific region starts in the mapped memory.
>As there is stil no wider adoption of vhost-user agreement was made
>that we will not bump version number due to this change
>  - other fileds in VhostUserMemoryRegion struct are not changed, as
>they are all needed for usermode app implementation
>  - region data is not taken from ram_list.blocks anymore, instead we
>use region data which is alredy calculated for use in vhost-net
>  - Now multiple regions can have same FD and user applicaton can call
>mmap() multiple times with the same FD but with different offset
>(user needs to take care for offset page alignment)
> 
> Signed-off-by: Damjan Marion 
> ---
>  docs/specs/vhost-user.txt |  7 ---
>  exec.c|  7 +++
>  hw/virtio/vhost-user.c| 23 ++-
>  include/exec/ram_addr.h   |  1 +
>  4 files changed, 26 insertions(+), 12 deletions(-)
> 
> diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt
> index 2641390..6abb697 100644
> --- a/docs/specs/vhost-user.txt
> +++ b/docs/specs/vhost-user.txt
> @@ -78,13 +78,14 @@ Depending on the request type, payload can be:
> Padding: 32-bit
>  
> A region is:
> -   ---
> -   | guest address | size | user address |
> -   ---
> +   -
> +   | guest address | size | user address | mmap offset |
> +   -
>  
> Guest address: a 64-bit guest address of the region
> Size: a 64-bit size
> User address: a 64-bit user address
> +   mmmap offset: 64-bit offset where region starts in the mapped memory

mmap I guess?

>  
>  
>  In QEMU the vhost-user message is implemented with the following struct:
> diff --git a/exec.c b/exec.c
> index c849405..a94c583 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1456,6 +1456,13 @@ int qemu_get_ram_fd(ram_addr_t addr)
>  return block->fd;
>  }
>  
> +void *qemu_get_ram_block_host_ptr(ram_addr_t addr)
> +{
> +RAMBlock *block = qemu_get_ram_block(addr);
> +
> +return block->host;
> +}
> +
>  /* Return a host pointer to ram allocated with qemu_ram_alloc.
> With the exception of the softmmu code in this file, this should
> only be used for local memory (e.g. video ram) that the device owns,
> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
> index 0df6a93..38e5806 100644
> --- a/hw/virtio/vhost-user.c
> +++ b/hw/virtio/vhost-user.c
> @@ -14,6 +14,7 @@
>  #include "sysemu/kvm.h"
>  #include "qemu/error-report.h"
>  #include "qemu/sockets.h"
> +#include "exec/ram_addr.h"
>  
>  #include 
>  #include 
> @@ -47,6 +48,7 @@ typedef struct VhostUserMemoryRegion {
>  uint64_t guest_phys_addr;
>  uint64_t memory_size;
>  uint64_t userspace_addr;
> +uint64_t mmap_offset;
>  } VhostUserMemoryRegion;
>  
>  typedef struct VhostUserMemory {
> @@ -183,10 +185,10 @@ static int vhost_user_call(struct vhost_dev *dev, 
> unsigned long int request,
>  {
>  VhostUserMsg msg;
>  VhostUserRequest msg_request;
> -RAMBlock *block = 0;
>  struct vhost_vring_file *file = 0;
>  int need_reply = 0;
>  int fds[VHOST_MEMORY_MAX_NREGIONS];
> +int i, fd;
>  size_t fd_num = 0;
>  
>  assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
> @@ -212,14 +214,17 @@ static int vhost_user_call(struct vhost_dev *dev, 
> unsigned long int request,
>  break;
>  
>  case VHOST_SET_MEM_TABLE:
> -QTAILQ_FOREACH(block, &ram_list.blocks, next)
> -{
> -if (block->fd > 0) {
> -msg.memory.regions[fd_num].userspace_addr =
> -(uintptr_t) block->host;
> -msg.memory.regions[fd_num].memory_size = block->length;
> -msg.memory.regions[fd_num].guest_phys_addr = block->offset;
> -fds[fd_num++] = block->fd;
> +for (i = 0; i < dev->mem->nregions; ++i) {
> +struct vhost_memory_region *reg = dev->mem->regions + i;
> +fd = qemu_get_ram_fd(reg->guest_phys_addr);
> +if (fd > 0) {
> +msg.memory.regions[fd_num].userspace_addr = 
> reg->userspace_addr;
> +msg.memory.regions[fd_num].memory_size  = reg->memory_size;
> +msg.memory.regions[fd_num].guest_phys_addr = 
> reg->guest_phys_addr;
> +msg.memory.regions[fd_num].mmap_offset = reg->us

Re: [Qemu-devel] [PULL for-2.1 0/8] QMP queue

2014-06-29 Thread Peter Maydell
On 27 June 2014 20:41, Luiz Capitulino  wrote:
> The following changes since commit d4cba13bdf251baeedb36b87c1e9f6766773e380:
>
>   tcg/ppc: Fix failure in tcg_out_mem_long (2014-06-27 13:23:41 +0100)
>
> are available in the git repository at:
>
>   git://repo.or.cz/qemu/qmp-unstable.git queue/qmp
>
> for you to fetch changes up to a22d8e47f7efb15a96162b92b50f8fb108b1c5d9:
>
>   docs/qmp: Fix documentation of BLOCK_JOB_READY to match code (2014-06-27 
> 13:40:41 -0400)
>

Applied, thanks.

-- PMM



Re: [Qemu-devel] [PATCH] ui/vnc: avoid memory corruption if width % VNC_DIRTY_PIXELS_PER_BIT != 0

2014-06-29 Thread Peter Lieven
If you find that patch too strict, I have another patch ready (needs some final 
testing) which
works around all the possible corruption issues iff

a) width % VNC_DIRTY_PIXELS_PER_BIT != 0 (while still keep it working)
b) width > VNC_MAX_WIDTH || heigth > VNC_MAX_HEIGTH

Peter


Am 27.06.2014 12:41, schrieb Peter Lieven:
> during resolution change in Windows 7 it happens sometimes that Windows 
> changes to
> an intermediate resolution where server_stride % cmp_bytes != 0 (in 
> vnc_refresh_server_surface).
> The problem that causes memory corruption is where the guest fb is copied to 
> the server fb.
> It could be easily fixed by truncating cmp_bytes in 
> vnc_refresh_server_surface. But by looking at
> the code it seems that none of the encoders called in 
> vnc_send_framebuffer_update really cares about
> w > pixman_image_get_width(vd->server). This patch will therefore remove all 
> DIV_ROUND_UPs for
> now to avoid corruption or illegal reads. I think there are really almost no 
> real resultions out
> there where width % 16 != 0. If we really find some we might need to either 
> decrease
> VNC_DIRTY_PIXELS_PER_BIT or make it dynamic depending on the resolution.
>
> Cc: qemu-sta...@nongnu.org
> Signed-off-by: Peter Lieven 
> ---
>  ui/vnc.c |4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/ui/vnc.c b/ui/vnc.c
> index 14a86c3..9e37d47 100644
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -577,7 +577,7 @@ void *vnc_server_fb_ptr(VncDisplay *vd, int x, int y)
>  memset(bitmap, 0x00, sizeof(bitmap));\
>  for (y = 0; y < h; y++) {\
>  bitmap_set(bitmap[y], 0,\
> -   DIV_ROUND_UP(w, VNC_DIRTY_PIXELS_PER_BIT));\
> +   w / VNC_DIRTY_PIXELS_PER_BIT);\
>  } \
>  }
>  
> @@ -2738,7 +2738,7 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
>  }
>  guest_ptr += x * cmp_bytes;
>  
> -for (; x < DIV_ROUND_UP(width, VNC_DIRTY_PIXELS_PER_BIT);
> +for (; x < width / VNC_DIRTY_PIXELS_PER_BIT;
>   x++, guest_ptr += cmp_bytes, server_ptr += cmp_bytes) {
>  if (!test_and_clear_bit(x, vd->guest.dirty[y])) {
>  continue;




Re: [Qemu-devel] [PATCH v2] [PATCH] Allow mismatched virtio config-len

2014-06-29 Thread Michael S. Tsirkin
On Fri, Jun 27, 2014 at 08:02:48PM +0100, Dr. David Alan Gilbert (git) wrote:
> From: "Dr. David Alan Gilbert" 
> 
> Commit 'virtio: validate config_len on load' restricted config_len
> loaded from the wire to match the config_len that the device had.
> 
> Unfortunately, there are cases where this isn't true, the one
> we found it on was the wce addition in virtio-blk.
> 
> Allow mismatched config-lengths:
>*) If the version on the wire is shorter then fine
>*) If the version on the wire is longer, load what we have space
>   for and skip the rest.
> 
> (This is m...@redhat.com's rework of what I originally posted)
> 
> Signed-off-by: Dr. David Alan Gilbert 

Applied, thanks!

> ---
>  hw/virtio/virtio.c | 16 +++-
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index a3082d5..c1d538c 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -926,12 +926,18 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
>  return -1;
>  }
>  config_len = qemu_get_be32(f);
> -if (config_len != vdev->config_len) {
> -error_report("Unexpected config length 0x%x. Expected 0x%zx",
> - config_len, vdev->config_len);
> -return -1;
> +
> +/*
> + * There are cases where the incoming config can be bigger or smaller
> + * than what we have; so load what we have space for, and skip
> + * any excess that's in the stream.
> + */
> +qemu_get_buffer(f, vdev->config, MIN(config_len, vdev->config_len));
> +
> +while (config_len > vdev->config_len) {
> +qemu_get_byte(f);
> +config_len--;
>  }
> -qemu_get_buffer(f, vdev->config, vdev->config_len);
>  
>  num = qemu_get_be32(f);
>  
> -- 
> 1.9.3



Re: [Qemu-devel] [PULL for-2.1 0/4] Net patches

2014-06-29 Thread Peter Maydell
On 27 June 2014 15:24, Stefan Hajnoczi  wrote:
> The following changes since commit ff4873cb8c81db89668d8b56e19e57b852edb5f5:
>
>   coroutine-win32.c: Add noinline attribute to work around gcc bug 
> (2014-06-26 14:08:14 +0100)
>
> are available in the git repository at:
>
>   git://github.com/stefanha/qemu.git tags/net-pull-request
>
> for you to fetch changes up to 5e80dd223ded254b1802bdd6417ef118456eadce:
>
>   hw/net/eepro100: Implement read-only bits in MDI registers (2014-06-27 
> 12:23:45 +0200)
>
> 
> Net patches
>
> 

Applied, thanks.

-- PMM



[Qemu-devel] [PULL v2 13/13] linux-user: support the SIOCGIFINDEX ioctl

2014-06-29 Thread riku . voipio
From: Paul Burton 

Add a definition of the SIOCGIFINDEX ioctl, allowing its use by target
programs.

Signed-off-by: Paul Burton 
Signed-off-by: Riku Voipio 
---
 linux-user/ioctls.h   | 1 +
 linux-user/syscall_defs.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index f278d3e..07a00da 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -118,6 +118,7 @@
   IOCTL(SIOCSIFMEM, IOC_W, MK_PTR(MK_STRUCT(STRUCT_ptr_ifreq)))
   IOCTL(SIOCADDMULTI, IOC_W, MK_PTR(MK_STRUCT(STRUCT_sockaddr_ifreq)))
   IOCTL(SIOCDELMULTI, IOC_W, MK_PTR(MK_STRUCT(STRUCT_sockaddr_ifreq)))
+  IOCTL(SIOCGIFINDEX, IOC_W | IOC_R, MK_PTR(MK_STRUCT(STRUCT_sockaddr_ifreq)))
   IOCTL(SIOCSIFLINK, 0, TYPE_NULL)
   IOCTL_SPECIAL(SIOCGIFCONF, IOC_W | IOC_R, do_ioctl_ifconf,
 MK_PTR(MK_STRUCT(STRUCT_ifconf)))
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 4adfd3a..8563027 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -865,6 +865,7 @@ struct target_pollfd {
 #define TARGET_SIOCSIFSLAVE0x8930
 #define TARGET_SIOCADDMULTI0x8931  /* Multicast address lists  
*/
 #define TARGET_SIOCDELMULTI0x8932
+#define TARGET_SIOCGIFINDEX0x8933
 
 /* Bridging control calls */
 #define TARGET_SIOCGIFBR   0x8940  /* Bridging support 
*/
-- 
2.0.0.rc2




[Qemu-devel] [PULL v2 11/13] linux-user: allow NULL tv argument for settimeofday

2014-06-29 Thread riku . voipio
From: Paul Burton 

The tv argument to the settimeofday syscall is allowed to be NULL, if
the program only wishes to provide the timezone. QEMU previously
returned -EFAULT when tv was NULL. Instead, execute the syscall &
provide NULL to the kernel as the target program expected.

Signed-off-by: Paul Burton 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 0ce1a4e..8e2762b 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6401,11 +6401,15 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 break;
 case TARGET_NR_settimeofday:
 {
-struct timeval tv;
+struct timeval tv, *ptv = NULL;
 struct timezone tz, *ptz = NULL;
 
-if (copy_from_user_timeval(&tv, arg1))
-goto efault;
+if (arg1) {
+if (copy_from_user_timeval(&tv, arg1)) {
+goto efault;
+}
+ptv = &tv;
+}
 
 if (arg2) {
 if (copy_from_user_timezone(&tz, arg2)) {
@@ -6414,7 +6418,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
 ptz = &tz;
 }
 
-ret = get_errno(settimeofday(&tv, ptz));
+ret = get_errno(settimeofday(ptv, ptz));
 }
 break;
 #if defined(TARGET_NR_select)
-- 
2.0.0.rc2




[Qemu-devel] [PULL v2 07/13] linux-user: allow NULL arguments to mount

2014-06-29 Thread riku . voipio
From: Paul Burton 

Calls to the mount syscall can legitimately provide NULL as the value
for the source of filesystemtype arguments, which QEMU would previously
reject & return -EFAULT to the target program. An example of this is
remounting an already mounted filesystem with different properties.

Instead of rejecting such syscalls with -EFAULT, pass NULL along to the
kernel as the target program expects.

Additionally this patch fixes a potential memory leak when DEBUG_REMAP
is enabled and lock_user_string fails on the target or filesystemtype
arguments but a prior argument was non-NULL and already locked.

Since the patch already touched most lines of the TARGET_NR_mount case,
it fixes the indentation & coding style for good measure.

Signed-off-by: Paul Burton 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c | 75 +---
 1 file changed, 53 insertions(+), 22 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3971cb5..4e48af6 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -5614,29 +5614,60 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 break;
 #endif
 case TARGET_NR_mount:
-   {
-   /* need to look at the data field */
-   void *p2, *p3;
-   p = lock_user_string(arg1);
-   p2 = lock_user_string(arg2);
-   p3 = lock_user_string(arg3);
-if (!p || !p2 || !p3)
-ret = -TARGET_EFAULT;
-else {
-/* FIXME - arg5 should be locked, but it isn't 
clear how to
- * do that since it's not guaranteed to be a 
NULL-terminated
- * string.
- */
-if ( ! arg5 )
-ret = get_errno(mount(p, p2, p3, (unsigned 
long)arg4, NULL));
-else
-ret = get_errno(mount(p, p2, p3, (unsigned 
long)arg4, g2h(arg5)));
-}
+{
+/* need to look at the data field */
+void *p2, *p3;
+
+if (arg1) {
+p = lock_user_string(arg1);
+if (!p) {
+goto efault;
+}
+} else {
+p = NULL;
+}
+
+p2 = lock_user_string(arg2);
+if (!p2) {
+if (arg1) {
+unlock_user(p, arg1, 0);
+}
+goto efault;
+}
+
+if (arg3) {
+p3 = lock_user_string(arg3);
+if (!p3) {
+if (arg1) {
 unlock_user(p, arg1, 0);
-unlock_user(p2, arg2, 0);
-unlock_user(p3, arg3, 0);
-   break;
-   }
+}
+unlock_user(p2, arg2, 0);
+goto efault;
+}
+} else {
+p3 = NULL;
+}
+
+/* FIXME - arg5 should be locked, but it isn't clear how to
+ * do that since it's not guaranteed to be a NULL-terminated
+ * string.
+ */
+if (!arg5) {
+ret = mount(p, p2, p3, (unsigned long)arg4, NULL);
+} else {
+ret = mount(p, p2, p3, (unsigned long)arg4, g2h(arg5));
+}
+ret = get_errno(ret);
+
+if (arg1) {
+unlock_user(p, arg1, 0);
+}
+unlock_user(p2, arg2, 0);
+if (arg3) {
+unlock_user(p3, arg3, 0);
+}
+}
+break;
 #ifdef TARGET_NR_umount
 case TARGET_NR_umount:
 if (!(p = lock_user_string(arg1)))
-- 
2.0.0.rc2




[Qemu-devel] [PULL v2 02/13] linux-user: added fake open() for /proc/self/cmdline

2014-06-29 Thread riku . voipio
From: Wim Vander Schelden 

Signed-off-by: Wim Vander Schelden 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c | 46 ++
 1 file changed, 46 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 007d59d..5c175ba 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -4949,6 +4949,51 @@ int host_to_target_waitstatus(int status)
 return status;
 }
 
+static int open_self_cmdline(void *cpu_env, int fd)
+{
+int fd_orig = -1;
+bool word_skipped = false;
+
+fd_orig = open("/proc/self/cmdline", O_RDONLY);
+if (fd_orig < 0) {
+return fd_orig;
+}
+
+while (true) {
+ssize_t nb_read;
+char buf[128];
+char *cp_buf = buf;
+
+nb_read = read(fd_orig, buf, sizeof(buf));
+if (nb_read < 0) {
+fd_orig = close(fd_orig);
+return -1;
+} else if (nb_read == 0) {
+break;
+}
+
+if (!word_skipped) {
+/* Skip the first string, which is the path to qemu-*-static
+   instead of the actual command. */
+cp_buf = memchr(buf, 0, sizeof(buf));
+if (cp_buf) {
+/* Null byte found, skip one string */
+cp_buf++;
+nb_read -= cp_buf - buf;
+word_skipped = true;
+}
+}
+
+if (word_skipped) {
+if (write(fd, cp_buf, nb_read) != nb_read) {
+return -1;
+}
+}
+}
+
+return close(fd_orig);
+}
+
 static int open_self_maps(void *cpu_env, int fd)
 {
 #if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32)
@@ -5150,6 +5195,7 @@ static int do_open(void *cpu_env, const char *pathname, 
int flags, mode_t mode)
 { "maps", open_self_maps, is_proc_myself },
 { "stat", open_self_stat, is_proc_myself },
 { "auxv", open_self_auxv, is_proc_myself },
+{ "cmdline", open_self_cmdline, is_proc_myself },
 #if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
 { "/proc/net/route", open_net_route, is_proc },
 #endif
-- 
2.0.0.rc2




[Qemu-devel] [PULL v2 12/13] linux-user: support the KDSIGACCEPT ioctl

2014-06-29 Thread riku . voipio
From: Paul Burton 

Add a definition of the KDSIGACCEPT ioctl & allow its use by target
programs.

Signed-off-by: Paul Burton 
Signed-off-by: Riku Voipio 
---
 linux-user/ioctls.h   | 1 +
 linux-user/syscall.c  | 7 +++
 linux-user/syscall_defs.h | 1 +
 3 files changed, 9 insertions(+)

diff --git a/linux-user/ioctls.h b/linux-user/ioctls.h
index 309fb21..f278d3e 100644
--- a/linux-user/ioctls.h
+++ b/linux-user/ioctls.h
@@ -64,6 +64,7 @@
  IOCTL(KDSKBLED, 0, TYPE_INT)
  IOCTL(KDGETLED, 0, TYPE_INT)
  IOCTL(KDSETLED, 0, TYPE_INT)
+ IOCTL_SPECIAL(KDSIGACCEPT, 0, do_ioctl_kdsigaccept, TYPE_INT)
 
  IOCTL(BLKROSET, IOC_W, MK_PTR(TYPE_INT))
  IOCTL(BLKROGET, IOC_R, MK_PTR(TYPE_INT))
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8e2762b..5a272d3 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3689,6 +3689,13 @@ static abi_long do_ioctl_rt(const IOCTLEntry *ie, 
uint8_t *buf_temp,
 return ret;
 }
 
+static abi_long do_ioctl_kdsigaccept(const IOCTLEntry *ie, uint8_t *buf_temp,
+ int fd, abi_long cmd, abi_long arg)
+{
+int sig = target_to_host_signal(arg);
+return get_errno(ioctl(fd, ie->host_cmd, sig));
+}
+
 static IOCTLEntry ioctl_entries[] = {
 #define IOCTL(cmd, access, ...) \
 { TARGET_ ## cmd, cmd, #cmd, access, 0, {  __VA_ARGS__ } },
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index a1f1fce..4adfd3a 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -831,6 +831,7 @@ struct target_pollfd {
 #define TARGET_KDSKBLED0x4B65  /* set led flags (not lights) */
 #define TARGET_KDGETLED0x4B31  /* return current led state */
 #define TARGET_KDSETLED0x4B32  /* set led state [lights, not flags] */
+#define TARGET_KDSIGACCEPT 0x4B4E
 
 #define TARGET_SIOCATMARK  0x8905
 
-- 
2.0.0.rc2




[Qemu-devel] possible denial of service via VNC

2014-06-29 Thread Peter Lieven
Hi,

while debugging a VNC issue I found this:

case VNC_MSG_CLIENT_CUT_TEXT:
if (len == 1)
return 8;

if (len == 8) {
uint32_t dlen = read_u32(data, 4);
if (dlen > 0)
return 8 + dlen;
}

client_cut_text(vs, read_u32(data, 4), data + 8);
break;

in protocol_client_msg().

Is this really a good idea? This allows for letting the vs->input buffer to grow
up to 2^32 + 8 byte which will possibly result in an out of memory condition.

Peter




[Qemu-devel] [PULL v2 09/13] linux-user: fix struct target_epoll_event layout for MIPS

2014-06-29 Thread riku . voipio
From: Paul Burton 

MIPS requires the pad field to 64b-align the data field just as ARM
does.

Signed-off-by: Paul Burton 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall_defs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 69c3982..e379b45 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -2528,7 +2528,7 @@ typedef union target_epoll_data {
 
 struct target_epoll_event {
 uint32_t events;
-#ifdef TARGET_ARM
+#if defined(TARGET_ARM) || defined(TARGET_MIPS) || defined(TARGET_MIPS64)
 uint32_t __pad;
 #endif
 target_epoll_data_t data;
-- 
2.0.0.rc2




[Qemu-devel] [PULL v2 06/13] linux-user: support SO_PASSSEC setsockopt option

2014-06-29 Thread riku . voipio
From: Paul Burton 

Translate the SO_PASSSEC option to setsockopt to the host value &
perform the syscall as expected, allowing use of the option by target
programs.

Signed-off-by: Paul Burton 
Signed-off-by: Riku Voipio 
---
 linux-user/socket.h  | 5 +
 linux-user/syscall.c | 3 +++
 2 files changed, 8 insertions(+)

diff --git a/linux-user/socket.h b/linux-user/socket.h
index ae17959..4dacae6 100644
--- a/linux-user/socket.h
+++ b/linux-user/socket.h
@@ -63,6 +63,7 @@
 #define TARGET_SO_PEERSEC  30
 #define TARGET_SO_SNDBUFFORCE  31
 #define TARGET_SO_RCVBUFFORCE  33
+#define TARGET_SO_PASSSEC  34
 
 /** sock_type - Socket types
  *
@@ -242,6 +243,10 @@
 
 #define TARGET_SOCK_MAX (TARGET_SOCK_PACKET + 1)
 #define TARGET_SOCK_TYPE_MASK0xf  /* Covers up to TARGET_SOCK_MAX-1. */
+
+#define TARGET_SO_PASSSEC31
+#else
+#define TARGET_SO_PASSSEC34
 #endif
 
 /* For setsockopt(2) */
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index bdc60fe..3971cb5 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1531,6 +1531,9 @@ set_timeout:
 case TARGET_SO_PASSCRED:
optname = SO_PASSCRED;
break;
+case TARGET_SO_PASSSEC:
+optname = SO_PASSSEC;
+break;
 case TARGET_SO_TIMESTAMP:
optname = SO_TIMESTAMP;
break;
-- 
2.0.0.rc2




[Qemu-devel] [PULL v2 10/13] linux-user: respect timezone for settimeofday

2014-06-29 Thread riku . voipio
From: Paul Burton 

The settimeofday syscall accepts a tz argument indicating the desired
timezone to the kernel. QEMU previously ignored any argument provided
by the target program & always passed NULL to the kernel. Instead,
translate the argument & pass along the data userland provided.

Although this argument is described by the settimeofday man page as
obsolete, it is used by systemd as of version 213.

Signed-off-by: Paul Burton 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c  | 29 -
 linux-user/syscall_defs.h |  5 +
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 4e48af6..0ce1a4e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -935,6 +935,23 @@ static inline abi_long copy_to_user_timeval(abi_ulong 
target_tv_addr,
 return 0;
 }
 
+static inline abi_long copy_from_user_timezone(struct timezone *tz,
+   abi_ulong target_tz_addr)
+{
+struct target_timezone *target_tz;
+
+if (!lock_user_struct(VERIFY_READ, target_tz, target_tz_addr, 1)) {
+return -TARGET_EFAULT;
+}
+
+__get_user(tz->tz_minuteswest, &target_tz->tz_minuteswest);
+__get_user(tz->tz_dsttime, &target_tz->tz_dsttime);
+
+unlock_user_struct(target_tz, target_tz_addr, 0);
+
+return 0;
+}
+
 #if defined(TARGET_NR_mq_open) && defined(__NR_mq_open)
 #include 
 
@@ -6385,9 +6402,19 @@ abi_long do_syscall(void *cpu_env, int num, abi_long 
arg1,
 case TARGET_NR_settimeofday:
 {
 struct timeval tv;
+struct timezone tz, *ptz = NULL;
+
 if (copy_from_user_timeval(&tv, arg1))
 goto efault;
-ret = get_errno(settimeofday(&tv, NULL));
+
+if (arg2) {
+if (copy_from_user_timezone(&tz, arg2)) {
+goto efault;
+}
+ptz = &tz;
+}
+
+ret = get_errno(settimeofday(&tv, ptz));
 }
 break;
 #if defined(TARGET_NR_select)
diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index e379b45..a1f1fce 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -165,6 +165,11 @@ struct target_timespec {
 abi_long tv_nsec;
 };
 
+struct target_timezone {
+abi_int tz_minuteswest;
+abi_int tz_dsttime;
+};
+
 struct target_itimerval {
 struct target_timeval it_interval;
 struct target_timeval it_value;
-- 
2.0.0.rc2




[Qemu-devel] [PULL v2 05/13] linux-user: support SO_{SND, RCV}BUFFORCE setsockopt options

2014-06-29 Thread riku . voipio
From: Paul Burton 

Translate the SO_SNDBUFFORCE & SO_RCVBUFFORCE options to setsockopt to
the host values & perform the syscall as expected, allowing use of those
options by target programs.

Signed-off-by: Paul Burton 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index b1e57df..bdc60fe 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1502,9 +1502,15 @@ set_timeout:
 case TARGET_SO_SNDBUF:
optname = SO_SNDBUF;
break;
+case TARGET_SO_SNDBUFFORCE:
+optname = SO_SNDBUFFORCE;
+break;
 case TARGET_SO_RCVBUF:
optname = SO_RCVBUF;
break;
+case TARGET_SO_RCVBUFFORCE:
+optname = SO_RCVBUFFORCE;
+break;
 case TARGET_SO_KEEPALIVE:
optname = SO_KEEPALIVE;
break;
-- 
2.0.0.rc2




[Qemu-devel] [PULL v2 04/13] linux-user: support SO_ACCEPTCONN getsockopt option

2014-06-29 Thread riku . voipio
From: Paul Burton 

Translate the SO_ACCEPTCONN option to the host value & execute the
syscall as expected.

Signed-off-by: Paul Burton 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 8d13781..b1e57df 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -1652,6 +1652,9 @@ static abi_long do_getsockopt(int sockfd, int level, int 
optname,
 case TARGET_SO_RCVLOWAT:
 optname = SO_RCVLOWAT;
 goto int_case;
+case TARGET_SO_ACCEPTCONN:
+optname = SO_ACCEPTCONN;
+goto int_case;
 default:
 goto int_case;
 }
-- 
2.0.0.rc2




[Qemu-devel] [PULL v2 08/13] linux-user: support strace of epoll_create1

2014-06-29 Thread riku . voipio
From: Paul Burton 

Add the epoll_create1 syscall to strace.list in order to display that
syscall when it occurs, rather than a message about the syscall being
unknown despite QEMU already implementing support for it.

Signed-off-by: Paul Burton 
Signed-off-by: Riku Voipio 
---
 linux-user/strace.list | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/linux-user/strace.list b/linux-user/strace.list
index cf5841a..fcb258d 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -114,6 +114,9 @@
 #ifdef TARGET_NR_epoll_create
 { TARGET_NR_epoll_create, "epoll_create" , NULL, NULL, NULL },
 #endif
+#ifdef TARGET_NR_epoll_create1
+{ TARGET_NR_epoll_create1, "epoll_create1" , NULL, NULL, NULL },
+#endif
 #ifdef TARGET_NR_epoll_ctl
 { TARGET_NR_epoll_ctl, "epoll_ctl" , NULL, NULL, NULL },
 #endif
-- 
2.0.0.rc2




[Qemu-devel] [PULL v2 01/13] Add support for MAP_NORESERVE mmap flag.

2014-06-29 Thread riku . voipio
From: Christophe Lyon 

mmap_flags_tbl contains a list of mmap flags, and how to map them to
the target. This patch adds MAP_NORESERVE, which was missing to the
list.

Signed-off-by: Christophe Lyon 
Reviewed-by: Peter Maydell 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 7d74079..007d59d 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3908,6 +3908,8 @@ static bitmask_transtbl mmap_flags_tbl[] = {
{ TARGET_MAP_DENYWRITE, TARGET_MAP_DENYWRITE, MAP_DENYWRITE, 
MAP_DENYWRITE },
{ TARGET_MAP_EXECUTABLE, TARGET_MAP_EXECUTABLE, MAP_EXECUTABLE, 
MAP_EXECUTABLE },
{ TARGET_MAP_LOCKED, TARGET_MAP_LOCKED, MAP_LOCKED, MAP_LOCKED },
+{ TARGET_MAP_NORESERVE, TARGET_MAP_NORESERVE, MAP_NORESERVE,
+  MAP_NORESERVE },
{ 0, 0, 0, 0 }
 };
 
-- 
2.0.0.rc2




[Qemu-devel] [PULL v2 03/13] linux-user: translate the result of getsockopt SO_TYPE

2014-06-29 Thread riku . voipio
From: Paul Burton 

QEMU previously passed the result of the host syscall directly to the
target program. This is a problem if the host & target have different
representations of socket types, as is the case when running a MIPS
target program on an x86 host. Introduce a host_to_target_sock_type
helper function mirroring the existing target_to_host_sock_type, and
call it to translate the value provided by getsockopt when called for
the SO_TYPE option.

Signed-off-by: Paul Burton 
Signed-off-by: Riku Voipio 
---
 linux-user/syscall.c | 34 ++
 1 file changed, 34 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 5c175ba..8d13781 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -592,6 +592,37 @@ char *target_strerror(int err)
 return strerror(target_to_host_errno(err));
 }
 
+static inline int host_to_target_sock_type(int host_type)
+{
+int target_type;
+
+switch (host_type & 0xf /* SOCK_TYPE_MASK */) {
+case SOCK_DGRAM:
+target_type = TARGET_SOCK_DGRAM;
+break;
+case SOCK_STREAM:
+target_type = TARGET_SOCK_STREAM;
+break;
+default:
+target_type = host_type & 0xf /* SOCK_TYPE_MASK */;
+break;
+}
+
+#if defined(SOCK_CLOEXEC)
+if (host_type & SOCK_CLOEXEC) {
+target_type |= TARGET_SOCK_CLOEXEC;
+}
+#endif
+
+#if defined(SOCK_NONBLOCK)
+if (host_type & SOCK_NONBLOCK) {
+target_type |= TARGET_SOCK_NONBLOCK;
+}
+#endif
+
+return target_type;
+}
+
 static abi_ulong target_brk;
 static abi_ulong target_original_brk;
 static abi_ulong brk_page;
@@ -1636,6 +1667,9 @@ static abi_long do_getsockopt(int sockfd, int level, int 
optname,
 ret = get_errno(getsockopt(sockfd, level, optname, &val, &lv));
 if (ret < 0)
 return ret;
+if (optname == SO_TYPE) {
+val = host_to_target_sock_type(val);
+}
 if (len > lv)
 len = lv;
 if (len == 4) {
-- 
2.0.0.rc2




[Qemu-devel] [PULL v2 00/13] linux-user changes for 2.1

2014-06-29 Thread riku . voipio
From: Riku Voipio 

The following changes since commit de6793e8c2a4d34e28e5ea385276249fc98109ec:

  Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20140627' into 
staging (2014-06-29 11:43:31 +0100)

are available in the git repository at:

  git://git.linaro.org/people/riku.voipio/qemu.git linux-user-for-upstream

for you to fetch changes up to f63eb01ac7a5b4437d5589ad4343527534bf9d0b:

  linux-user: support the SIOCGIFINDEX ioctl (2014-06-29 14:19:59 +0300)

Changes since v1 - dropped those patches from Paul that add new syscalls from
this round, since the won't compile with older libc's.

Christophe Lyon (1):
  Add support for MAP_NORESERVE mmap flag.

Paul Burton (11):
  linux-user: translate the result of getsockopt SO_TYPE
  linux-user: support SO_ACCEPTCONN getsockopt option
  linux-user: support SO_{SND, RCV}BUFFORCE setsockopt options
  linux-user: support SO_PASSSEC setsockopt option
  linux-user: allow NULL arguments to mount
  linux-user: support strace of epoll_create1
  linux-user: fix struct target_epoll_event layout for MIPS
  linux-user: respect timezone for settimeofday
  linux-user: allow NULL tv argument for settimeofday
  linux-user: support the KDSIGACCEPT ioctl
  linux-user: support the SIOCGIFINDEX ioctl

Wim Vander Schelden (1):
  linux-user: added fake open() for /proc/self/cmdline

 linux-user/ioctls.h   |   2 +
 linux-user/socket.h   |   5 ++
 linux-user/strace.list|   3 +
 linux-user/syscall.c  | 215 --
 linux-user/syscall_defs.h |   9 +-
 5 files changed, 207 insertions(+), 27 deletions(-)

-- 
2.0.0.rc2




Re: [Qemu-devel] [v5][PATCH 4/5] xen, gfx passthrough: create host bridge to passthrough

2014-06-29 Thread Michael S. Tsirkin
On Sun, Jun 29, 2014 at 03:56:10PM +0800, Chen, Tiejun wrote:
> On 2014/6/27 19:26, Paolo Bonzini wrote:
> >Il 27/06/2014 10:34, Chen, Tiejun ha scritto:
> >>
> >>
> >>So how to separate this to specific to xen? Or you mean we need to
> >>create an new machine to address this scenario? But actually this is
> >>same as xenfv_machine except for these little codes.
> >
> >Yes, please create a new machine so that "-M pc" doesn't have any of
> >these hacks.
> 
> But regardless of the machine is 'xenfv' or 'pc', we always call
> pc_init_pci(), then inside, i440fx_init() is always performed. So I think
> even we create a new machine, shouldn't we still call pc_init_pci()?
> 
> >
> >Note that "-M xenfv" is obsolete, Xen can now use "-M pc" (i.e. the
> >default).
> >
> 
> Yes, Xen can use 'pc'.
> 
> Thanks
> Tiejun

You are creating a new machine type where the pci host
looks like MCH but a bunch of other things are from i440fx.

I have some doubts about this combination being worth supporting - it
does not seem useful for anything except xen from the code you posted,
but maybe you can whittle down the number of places where you poke at
the host to make it reasonable: I can imagine that, if you are lucky and
the registers that i915 wants to poke to make it work on real hardware
happen to fall on top of reserved registers in the i440FX/PIIX3 pci
bridge.  OTOH it would be much more likely if you just start with
something that does have MCH, like Q35, or emulate a newer
machine type.  This is the path that people who wanted
to boot iOS on QEMU took, and the result is pretty good.

But regardless, this is clearly not a i440fx nor a q35 pc
so it needs a separate name.

-- 
MST



Re: [Qemu-devel] [PULL 0/5] NBD changes for 2014-06-27

2014-06-29 Thread Hani Benhabiles
On Sun, Jun 29, 2014 at 12:45:27PM +0100, Peter Maydell wrote:
> On 27 June 2014 15:11, Paolo Bonzini  wrote:
> > The following changes since commit d4cba13bdf251baeedb36b87c1e9f6766773e380:
> >
> >   tcg/ppc: Fix failure in tcg_out_mem_long (2014-06-27 13:23:41 +0100)
> >
> > are available in the git repository at:
> >
> >   git://github.com/bonzini/qemu.git nbd-next
> >
> > for you to fetch changes up to 34bf23a5e0e878e3cd650c47d670b881f9f61475:
> >
> >   nbd: Handle NBD_OPT_LIST option. (2014-06-27 16:06:48 +0200)
> >
> > Three bugfixes, and a new feature.
> 
> Hi. I'm afraid this doesn't build on win32:

Hi Peter,

Should be fixed with s/SHUT_RDWR/2/

That is how shutdown() is called elsewhere in nbd.c and block/nbd-client.c

> /home/petmay01/linaro/qemu-for-merges/blockdev-nbd.c: In function 
> ‘nbd_accept’:
> /home/petmay01/linaro/qemu-for-merges/blockdev-nbd.c:31: error:
> ‘SHUT_RDWR’ undeclared (first use in this function)
> /home/petmay01/linaro/qemu-for-merges/blockdev-nbd.c:31: error: (Each
> undeclared identifier is reported only once
> /home/petmay01/linaro/qemu-for-merges/blockdev-nbd.c:31: error: for
> each function it appears in.)
> make: *** [blockdev-nbd.o] Error 1
> 
> thanks
> -- PMM
> 



Re: [Qemu-devel] [PULL 0/5] NBD changes for 2014-06-27

2014-06-29 Thread Peter Maydell
On 27 June 2014 15:11, Paolo Bonzini  wrote:
> The following changes since commit d4cba13bdf251baeedb36b87c1e9f6766773e380:
>
>   tcg/ppc: Fix failure in tcg_out_mem_long (2014-06-27 13:23:41 +0100)
>
> are available in the git repository at:
>
>   git://github.com/bonzini/qemu.git nbd-next
>
> for you to fetch changes up to 34bf23a5e0e878e3cd650c47d670b881f9f61475:
>
>   nbd: Handle NBD_OPT_LIST option. (2014-06-27 16:06:48 +0200)
>
> Three bugfixes, and a new feature.

Hi. I'm afraid this doesn't build on win32:
/home/petmay01/linaro/qemu-for-merges/blockdev-nbd.c: In function ‘nbd_accept’:
/home/petmay01/linaro/qemu-for-merges/blockdev-nbd.c:31: error:
‘SHUT_RDWR’ undeclared (first use in this function)
/home/petmay01/linaro/qemu-for-merges/blockdev-nbd.c:31: error: (Each
undeclared identifier is reported only once
/home/petmay01/linaro/qemu-for-merges/blockdev-nbd.c:31: error: for
each function it appears in.)
make: *** [blockdev-nbd.o] Error 1

thanks
-- PMM



Re: [Qemu-devel] [v5][PATCH 5/5] xen, gfx passthrough: add opregion mapping

2014-06-29 Thread Michael S. Tsirkin
On Fri, Jun 27, 2014 at 05:22:18PM +0800, Chen, Tiejun wrote:
> On 2014/6/25 15:13, Michael S. Tsirkin wrote:
> >On Wed, Jun 25, 2014 at 10:17:21AM +0800, Tiejun Chen wrote:
> 
> [snip]
> 
> >>diff --git a/hw/xen/xen_pt.h b/hw/xen/xen_pt.h
> >>index 507165c..25147cf 100644
> >>--- a/hw/xen/xen_pt.h
> >>+++ b/hw/xen/xen_pt.h
> >>@@ -63,7 +63,7 @@ typedef int (*xen_pt_conf_byte_read)
> >>  #define XEN_PT_BAR_UNMAPPED (-1)
> >>
> >>  #define PCI_CAP_MAX 48
> >>-
> >>+#define PCI_INTEL_OPREGION 0xfc
> >>
> >
> >XEN_ please
> >
> >PCI_CAP_MAX should be fixed too.
> 
> They are specific to PCI, not XEN.

They are?  Where in the PCI spec does it say 48?
Same for PCI_INTEL_OPREGION.

> Why should we add such a prefix?

So that people working on core pci do not have to worry about breaking
your devices by adding a symbol in the global header.


> >
> >
> 
> [snip]
> 
> >>
> >>+if (igd_guest_opregion) {
> >>+ret = xc_domain_memory_mapping(xen_xc, xen_domid,
> >>+(unsigned long)(igd_guest_opregion >> XC_PAGE_SHIFT),
> >>+(unsigned long)(igd_host_opregion >> XC_PAGE_SHIFT),
> >
> >don't spread casts all around.
> >Should be a last resort.
> 
> Okay.
> 
> >
> >>+3,
> >>+DPCI_REMOVE_MAPPING);
> >>+if (ret) {
> >>+return ret;
> >>+}
> >>+}
> >>+
> >>  return 0;
> >>  }
> >>
> >>@@ -447,3 +462,52 @@ err_out:
> >>  XEN_PT_ERR(pci_dev, "Can't get pci_dev_host_bridge\n");
> >>  return -1;
> >>  }
> >>+
> >>+uint32_t igd_read_opregion(XenPCIPassthroughState *s)
> >>+{
> >>+uint32_t val = 0;
> >>+
> >>+if (igd_guest_opregion == 0) {
> >
> >!igd_guest_opregion is shorter and does the same,
> 
> Okay.
> 
> >
> >>+return val;
> >>+}
> >>+
> >>+val = igd_guest_opregion;
> >>+
> >>+XEN_PT_LOG(&s->dev, "Read opregion val=%x\n", val);
> >>+return val;
> >>+}
> >>+
> >>+void igd_write_opregion(XenPCIPassthroughState *s, uint32_t val)
> >>+{
> >>+int ret;
> >>+
> >>+if (igd_guest_opregion) {
> >>+XEN_PT_LOG(&s->dev, "opregion register already been set, ignoring 
> >>%x\n",
> >>+   val);
> >>+return;
> >>+}
> >>+
> >>+xen_host_pci_get_block(&s->real_device, PCI_INTEL_OPREGION,
> >>+(uint8_t *)&igd_host_opregion, 4);
> >>+igd_guest_opregion = (unsigned long)(val & ~0xfff)
> >>+| (igd_host_opregion & 0xfff);
> >>+
> >
> >Clearly broken on BE.
> 
> I still can't understand why we need to address this in BE case.

So code is clean and reusable. Copy and paste is a fact of life,
you don't want people to inherit bugs.
If some code absolutely must be LE specific,
it needs a comment that explains this and cautions
people against trying to use it elsewhere in QEMU.


> >Maybe not important here but writing clean code is
> >just as easy.
> >uint8_t igd_host_opregion[4];
> >
> >...
> >
> > xen_host_pci_get_block(&s->real_device, PCI_INTEL_OPREGION,
> >igd_host_opregion, sizeof igd_host_opregion);
> >
> > igd_guest_opregion = (val & ~0xfff) |
> > (pci_get_word(igd_host_opregion) & 0xfff);
> >
> >0xfff should be a macro too to avoid duplication.
> >
> 
> Okay.
> 
> Thanks
> Tiejun



Re: [Qemu-devel] [PULL 00/32] ppc patch queue 2014-06-27

2014-06-29 Thread Peter Maydell
On 27 June 2014 12:51, Alexander Graf  wrote:
> Hi Peter,
>
> This is my current patch queue for ppc.  Please pull.
>
> Alex
>
>
> The following changes since commit ff4873cb8c81db89668d8b56e19e57b852edb5f5:
>
>   coroutine-win32.c: Add noinline attribute to work around gcc bug 
> (2014-06-26 14:08:14 +0100)
>
> are available in the git repository at:
>
>   git://github.com/agraf/qemu.git tags/signed-ppc-for-upstream
>
> for you to fetch changes up to 79c0ff2cae1f24cb7e041ac2dbdcc329d2a86ba2:
>
>   PPC: e500: Only create dt entries for existing serial ports (2014-06-27 
> 13:48:27 +0200)
>
> 
> Patch queue for ppc - 2014-06-27

Applied, thanks.

-- PMM



Re: [Qemu-devel] [PATCH] machine: replace underscores in machine's property names

2014-06-29 Thread Michael S. Tsirkin
On Sun, Jun 29, 2014 at 12:09:15PM +0300, Marcel Apfelbaum wrote:
> Replaced '_' with '-' to comply with QOM guidelines.
> Made the conversion from HMP to QMP in vl.c
> 
> Signed-off-by: Marcel Apfelbaum 

Nothing to do with me, pls merge through Andrea's or Paolo's tree.
FWIW

Acked-by: Michael S. Tsirkin 


> ---
>  hw/core/machine.c |  8 
>  vl.c  | 12 +++-
>  2 files changed, 15 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index cbba679..7a66c57 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -239,11 +239,11 @@ static void machine_initfn(Object *obj)
>  {
>  object_property_add_str(obj, "accel",
>  machine_get_accel, machine_set_accel, NULL);
> -object_property_add_bool(obj, "kernel_irqchip",
> +object_property_add_bool(obj, "kernel-irqchip",
>   machine_get_kernel_irqchip,
>   machine_set_kernel_irqchip,
>   NULL);
> -object_property_add(obj, "kvm_shadow_mem", "int",
> +object_property_add(obj, "kvm-shadow-mem", "int",
>  machine_get_kvm_shadow_mem,
>  machine_set_kvm_shadow_mem,
>  NULL, NULL, NULL);
> @@ -257,11 +257,11 @@ static void machine_initfn(Object *obj)
>  machine_get_dtb, machine_set_dtb, NULL);
>  object_property_add_str(obj, "dumpdtb",
>  machine_get_dumpdtb, machine_set_dumpdtb, NULL);
> -object_property_add(obj, "phandle_start", "int",
> +object_property_add(obj, "phandle-start", "int",
>  machine_get_phandle_start,
>  machine_set_phandle_start,
>  NULL, NULL, NULL);
> -object_property_add_str(obj, "dt_compatible",
> +object_property_add_str(obj, "dt-compatible",
>  machine_get_dt_compatible,
>  machine_set_dt_compatible,
>  NULL);
> diff --git a/vl.c b/vl.c
> index a1686ef..7587c97 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2820,15 +2820,25 @@ static int object_set_property(const char *name, 
> const char *value, void *opaque
>  Object *obj = OBJECT(opaque);
>  StringInputVisitor *siv;
>  Error *local_err = NULL;
> +char *c, *qom_name;
>  
>  if (strcmp(name, "qom-type") == 0 || strcmp(name, "id") == 0 ||
>  strcmp(name, "type") == 0) {
>  return 0;
>  }
>  
> +qom_name = g_strdup(name);
> +c = qom_name;
> +while (*c++) {
> +if (*c == '_') {
> +*c = '-';
> +}
> +}
> +
>  siv = string_input_visitor_new(value);
> -object_property_set(obj, string_input_get_visitor(siv), name, 
> &local_err);
> +object_property_set(obj, string_input_get_visitor(siv), qom_name, 
> &local_err);
>  string_input_visitor_cleanup(siv);
> +free(qom_name);
>  
>  if (local_err) {
>  qerror_report_err(local_err);
> -- 
> 1.8.3.1



Re: [Qemu-devel] [PULL 00/10] for-2.1: s390-ccw bios patches

2014-06-29 Thread Peter Maydell
On 27 June 2014 12:25, Cornelia Huck  wrote:
> Here are some s390-ccw bios patches I'd like to see in 2.1. Being able
> to finally boot from dasd is quite a useful feature. Please consider pulling.
>
> The following changes since commit ff4873cb8c81db89668d8b56e19e57b852edb5f5:
>
>   coroutine-win32.c: Add noinline attribute to work around gcc bug 
> (2014-06-26 14:08:14 +0100)
>
> are available in the git repository at:
>
>   git://github.com/cohuck/qemu.git tags/s390x-20140627
>
> for you to fetch changes up to 77416f4075a673a27cfe5a7a34e93c0fa9810e35:
>
>   pc-bios/s390-ccw: update binary (2014-06-27 12:11:53 +0200)
>
> 
> A series of patches to the s390-ccw bios:
> - code cleanup
> - improved error reporting

> - most important, support to ipl (boot) from ECKD DASD (CDL, LDL or CMS
>   formatted)

I love these IBM acronyms :-)

Applied, thanks.

-- PMM



Re: [Qemu-devel] [RFC UNTESTED] tcg/ppc: Fix support for 64-bit PPC MacOSX hosts

2014-06-29 Thread Peter Maydell
On 29 June 2014 01:01, Andreas Färber  wrote:
> Am 26.06.2014 17:37, schrieb Peter Maydell:
>> Add back in the support for 64-bit PPC MacOSX hosts that was
>> broken in the recent merge of the 32-bit and 64-bit TCG backends.
>>
>
> Reported-by: Andreas Färber 
>
>> Signed-off-by: Peter Maydell 
>
> Tested-by: Andreas Färber 
>
> Fixes the build, and i386/x86_64 Haiku guest boots up.

Thanks for testing; applied to master as a buildfix.

-- PMM



  1   2   >