Re: [Qemu-devel] [PATCH] curl: fix curl read

2013-05-08 Thread Fam Zheng
On Thu, 05/09 08:41, Stefan Hajnoczi wrote:
> On Fri, May 03, 2013 at 04:00:09PM +0800, Fam Zheng wrote:
> > @@ -391,7 +427,12 @@ static QemuOptsList runtime_opts = {
> >  .type = QEMU_OPT_SIZE,
> >  .help = "Readahead size",
> >  },
> > -{ /* end of list */ }
> > +{
> > +.name = "ssl_no_cert",
> > +.type = QEMU_OPT_BOOL,
> > +.help = "SSL certificate check",
> > +},
> 
> This new option should be in a separate patch.

OK. I'll try to split them to patches.

> 
> > +if (!strncmp(s->url, "http://";, strlen("http://";)) && 
> > !s->accept_range) {
> > +strncpy(state->errmsg, "Server not supporting range.", 
> > CURL_ERROR_SIZE);
> > +goto out;
> > +}
> 
> This check is unrelated to the API change and should be in a separate
> patch.
> 
> >  s->multi = curl_multi_init();
> > -curl_multi_setopt( s->multi, CURLMOPT_SOCKETDATA, s); 
> > -curl_multi_setopt( s->multi, CURLMOPT_SOCKETFUNCTION, curl_sock_cb ); 
> > -curl_multi_do(s);
> > +if (!s->multi) {
> > +goto out_noclean;
> > +}
> > +curl_multi_setopt(s->multi, CURLMOPT_SOCKETDATA, s);
> > +curl_multi_setopt(s->multi, CURLMOPT_SOCKETFUNCTION, curl_sock_cb);
> > +curl_multi_setopt(s->multi, CURLMOPT_TIMERDATA, s);
> > +curl_multi_setopt(s->multi, CURLMOPT_TIMERFUNCTION, 
> > curl_multi_timer_cb);
> > +curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running);
> 
> The timeout should be added in a separate patch.
> 
> > +cache = curl_find_cache(s, aio_base, aio_bytes);
> > +if (cache) {
> > +curl_complete_io(s, acb, cache);
> > +return;
> >  }
> 
> What is the point of the cache?  Can you split it into a separate patch?

The cache is for prefetch. Data is fetched by 256k chunks using libcurl
and stored in cache to fill future io request, reducing overall http
request overhead.

-- 
Fam



Re: [Qemu-devel] [PATCH for-1.5] virtio-pci: bugfix

2013-05-08 Thread Stefan Hajnoczi
On Mon, May 06, 2013 at 06:00:27PM +0300, Michael S. Tsirkin wrote:
> mask notifiers are never called without msix,
> so devices with backend masking like vhost don't work.
> Call mask notifiers explicitly at
> startup/cleanup to make it work.
> 
> Signed-off-by: Michael S. Tsirkin 
> Tested-by: Alexander Graf 
> 
> ---
>  hw/virtio/virtio-pci.c | 4 
>  1 file changed, 4 insertions(+)

Please choose a descriptive commit message, not just "bugfix".

Stefan



Re: [Qemu-devel] [Bug 1176366] [NEW] TCPIP not working on qemu 1.4.50 (master)

2013-05-08 Thread Stefan Hajnoczi
On Sat, May 04, 2013 at 04:13:19PM -, TC1988 wrote:
> whenever I try, in the guest OS, in this case it's NT 3.1, to enable
> TCP/IP, it crashes the whole emulator. With either the ne2000 isa,
> ne2000 pci or PCnet, still crashes
> 
> below is attached a screenshot.

Please use git-bisect(1) to identify the commit that broke networking.

http://git-scm.com/book/en/Git-Tools-Debugging-with-Git#Binary-Search
https://www.kernel.org/pub/software/scm/git/docs/git-bisect.html

Stefan



Re: [Qemu-devel] [ANNOUNCE] QEMU 1.5.0-rc1 is now available

2013-05-08 Thread Dongsheng Song
On Thu, May 9, 2013 at 6:29 AM, Anthony Liguori  wrote:
>
> Hi,
>
> On behalf of the QEMU Team, I'd like to announce the availability of the
> second release candidate for the QEMU 1.5 release.  This release is meant
> for testing purposes and should not be used in a production environment.
>
> http://wiki.qemu.org/download/qemu-1.5.0-rc1.tar.bz2
>
> You can help improve the quality of the QEMU 1.5 release by testing this
> release and reporting bugs on Launchpad:
>
> https://bugs.launchpad.net/qemu/
>
> The release plan for the 1.5 release is available at:
>
> http://wiki.qemu.org/Planning/1.5
>
> Please add entries to the ChangeLog for the 1.5 release below:
>
> http://wiki.qemu.org/ChangeLog/Next
>
> This following changes have been made since 1.5.0-rc0:
>
>  - virtio: properly validate address before accessing config (Jason Wang)
>  - virtio-pci: fix level interrupts (Michael S. Tsirkin)
>  - PPC: Fix rldcl (Alexander Graf)
>  - PPC: Depend behavior of cmp instructions only on instruction encoding 
> (Alexander Graf)
>  - target-mips: fix incorrect behaviour for INSV (Petar Jovanovic)
>  - target-mips: add missing check_dspr2 for multiply instructions (Petar 
> Jovanovic)
>  - qemu-iotests: fix 017 018 for vmdk (Fam Zheng)
>  - qemu-iotests: exclude vmdk and qcow from 043 (Fam Zheng)
>  - qemu-iotests: exclude vmdk for test 042 (Fam Zheng)
>  - qtest/ide-test: Test short and long PRDTs (Kevin Wolf)
>  - qtest/ide-test: Add simple DMA read/write test case (Kevin Wolf)
>  - qtest: Add IDE test case (Kevin Wolf)
>  - libqos/pci: Enable bus mastering (Kevin Wolf)
>  - ide: Reset BMIDEA bit when the bus master is stopped (Kevin Wolf)
>  - de_DE.po: Add missing leading spaces (Kevin Wolf)
>  - ahci: Don't allow creating slave drives (Kevin Wolf)
>
> Regards,
>
> Anthony Liguori


For convenience, I had upload qemu-build-dependency-r1.zip,
qemu-1.5.0-rc1-win32.7z and qemu-1.5.0-rc1-win64.7z

https://code.google.com/p/i18n-zh/downloads/list

Regards,
Dongsheng



[Qemu-devel] Jiajun, add me to your LinkedIn network?

2013-05-08 Thread Zhou Chunhua
LinkedIn





Zhou Chunhua requested to add you as a connection on LinkedIn:
  

--

Jiajun,

I'd like to add you to my professional network on LinkedIn.

- Zhou

Accept invitation from Zhou Chunhua
http://www.linkedin.com/e/-kkb1ec-hghkilms-5b/qTMmi8QEI_f3FNXUkL1mvZgy00BGYniwg3/blk/I516399382_11/3wOtCVFbmdxnSVFbm8JrnpKqlZJrmZzbmNJpjRQnOpBtn9QfmhBt71BoSd1p65Lr6lOfP4NnP8UcPAVcPoNdkALekxPcCNSdR8LczoTdz0UczcOc34LrCBxbOYWrSlI/eml-comm_invm-b-in_ac-inv28/?hs=false&tok=2MY3cz4ADhWRI1

View profile of Zhou Chunhua
http://www.linkedin.com/e/-kkb1ec-hghkilms-5b/rso/223045405/29qh/name/86670410_I516399382_11/?hs=false&tok=1agjIHEZvhWRI1
--
You are receiving Invitation emails.


This email was intended for Jiajun Liu.
Learn why this is included: 
http://www.linkedin.com/e/-kkb1ec-hghkilms-5b/plh/http%3A%2F%2Fhelp%2Elinkedin%2Ecom%2Fapp%2Fanswers%2Fdetail%2Fa_id%2F4788/-GXI/?hs=false&tok=2wwvEflx7hWRI1

(c) 2012, LinkedIn Corporation. 2029 Stierlin Ct, Mountain View, CA 94043, USA.


  


Re: [Qemu-devel] [PATCH] curl: fix curl read

2013-05-08 Thread Stefan Hajnoczi
On Fri, May 03, 2013 at 04:00:09PM +0800, Fam Zheng wrote:
> @@ -391,7 +427,12 @@ static QemuOptsList runtime_opts = {
>  .type = QEMU_OPT_SIZE,
>  .help = "Readahead size",
>  },
> -{ /* end of list */ }
> +{
> +.name = "ssl_no_cert",
> +.type = QEMU_OPT_BOOL,
> +.help = "SSL certificate check",
> +},

This new option should be in a separate patch.

> +if (!strncmp(s->url, "http://";, strlen("http://";)) && !s->accept_range) {
> +strncpy(state->errmsg, "Server not supporting range.", 
> CURL_ERROR_SIZE);
> +goto out;
> +}

This check is unrelated to the API change and should be in a separate
patch.

>  s->multi = curl_multi_init();
> -curl_multi_setopt( s->multi, CURLMOPT_SOCKETDATA, s); 
> -curl_multi_setopt( s->multi, CURLMOPT_SOCKETFUNCTION, curl_sock_cb ); 
> -curl_multi_do(s);
> +if (!s->multi) {
> +goto out_noclean;
> +}
> +curl_multi_setopt(s->multi, CURLMOPT_SOCKETDATA, s);
> +curl_multi_setopt(s->multi, CURLMOPT_SOCKETFUNCTION, curl_sock_cb);
> +curl_multi_setopt(s->multi, CURLMOPT_TIMERDATA, s);
> +curl_multi_setopt(s->multi, CURLMOPT_TIMERFUNCTION, curl_multi_timer_cb);
> +curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running);

The timeout should be added in a separate patch.

> +cache = curl_find_cache(s, aio_base, aio_bytes);
> +if (cache) {
> +curl_complete_io(s, acb, cache);
> +return;
>  }

What is the point of the cache?  Can you split it into a separate patch?

> +/* Try to release some cache */
> +while (0 && s->cache_quota <= 0) {

while 0?



Re: [Qemu-devel] [libvirt]virtio serial device problem

2013-05-08 Thread Alexey Kardashevskiy
On 05/09/2013 04:07 PM, Li Zhang wrote:
> On 2013年05月08日 23:53, fred.kon...@greensocs.com wrote:
>>> On 05/07/2013 07:50 PM, Paolo Bonzini wrote:
 Il 07/05/2013 09:20, Li Zhang ha scritto:
> Hi all,
>> Hi,
> When we use the latest version of QEMU to build ovirt,
> we get this error reported from libvirt.
 What QEMU commit is this?
>>>
>>> b3e6d591b05538056d665572f3e3bbfb3cbb70e7
>> This commit is from 05/29 no?
>>
>> there were issues with that. But it should be fixed.
>>
>> Do you still have the command-line issue with the last git?
>>
>> See commit 80270a19685dd20eda017b0360c743b3e3ed6f57
> 
> Hi Fred,
> 
> This patch is to change bus which can be compatible with old version, right?
> But I saw the current name is still different from old version.
> 
> The current name is: "virtio-serial-bus0.0"
> The old version is: "virtio-serial0.0"
> 
> Is it possible to change it back to the old name?


This is what the most recent qemu produces:

bus: pci
  type PCI
  dev: virtio-serial-pci, id "virtio-serial0"
ioeventfd = on
vectors = 2
class = 0x780
indirect_desc = on
event_idx = on
max_ports = 31
addr = 03.0
romfile = 
rombar = 1
multifunction = off
command_serr_enable = on
class Class 0780, addr 00:03.0, pci id 1af4:1003 (sub 1af4:0003)
bar 0: i/o at 0x [0x1e]
bar 1: mem at 0x [0xffe]
bus: virtio-bus
  type virtio-pci-bus
  dev: virtio-serial-device, id ""
max_ports = 31
bus: virtio-serial0.0
  type virtio-serial-bus
  dev: virtserialport, id "channel0"
chardev = charchannel0
nr = 1
name = "com.redhat.rhevm.vdsm"
port 1, guest off, host off, throttle off


The device layout is new, the bus name is old - "virtio-serial0.0",
everything should be ok now.



> Thanks. :)
> --Li
>>
>> Thanks,
>> Fred
>>
>>>
 It might have been fixed already.
>>> Hm. From what I see, it is all correct from the qemu side, the problem is
>>> in libvirt which does not know about "virtio-pci-bus" yet.
>>>
>>>
>>>
 Paolo

> qemu-system-ppc64: -device
> virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=com.redhat.rhevm.vdsm:
>
>
> Bus 'virtio-serial0.0' is full
> qemu-system-ppc64: -device
> virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=com.redhat.rhevm.vdsm:
>
>
> Bus 'virtio-serial0.0' not found
>
> Libvirt helps create QEMU command line and put virtserialport device to
> bus virtio-serial0.0.
> For latest version of QEMU, the bus type is changed.
>
> (qemu) info qtree
> bus: main-system-bus
>type System
>dev: spapr-pci-host-bridge, id ""
>  index = 0
>  buid = 0x8002000
>  liobn = 0x8000
>  mem_win_addr = 0x100a000
>  mem_win_size = 0x2000
>  io_win_addr = 0x1008000
>  io_win_size = 0x1
>  msi_win_addr = 0x1009000
>  irq 0
>  bus: pci
>type PCI
>dev: virtio-serial-pci, id "virtio-serial0"
>  ioeventfd = on
>  vectors = 2
>  class = 0x780
>  indirect_desc = on
>  event_idx = on
>  max_ports = 31
>  addr = 03.0
>  romfile = 
>  rombar = 1
>  multifunction = off
>  command_serr_enable = on
>  class Class 0780, addr 00:03.0, pci id 1af4:1003 (sub
> 1af4:0003)
>  bar 0: i/o at 0x [0x1e]
>  bar 1: mem at 0x [0xffe]
>  bus: virtio-serial0.0
>type virtio-pci-bus
>dev: virtio-serial-device, id ""
>  max_ports = 31
>  bus: virtio-serial-bus.0
>type virtio-serial-bus
>dev: virtserialport, id "channel1"
>  chardev = charchannel1
>  nr = 2
>  name = "org.qemu.guest_agent.0"
>  port 2, guest off, host off, throttle off
>dev: virtserialport, id "channel0"
>  chardev = charchannel0
>  nr = 1
>  name = "com.redhat.rhevm.vdsm"
>  port 1, guest off, host off, throttle off
>
>
> But we tried to replace virtio-serial0.0 with virtio-serial-bus.0,
> SLOF crashes. It still doesn't work at all.
>
> Does anyone know how to use virtserialport in QEMU command line?
> If configuration is changed in QEMU, libvirt also needs to change it
> accordingly.
>
> Thanks. :)
> --Li
>
>
>
>>>
>>> -- 
>>> Alexey Kardashevskiy
>>> IBM OzL

Re: [Qemu-devel] [PATCH v5 0/5] KVM flash memory support

2013-05-08 Thread Paolo Bonzini
Il 09/05/2013 00:44, Jordan Justen ha scritto:
> git://github.com/jljusten/qemu.git kvm-flash-v5
> 
> Utilize KVM_CAP_READONLY_MEM to support PC system flash emulation
> with KVM.
> 
> v5:
>  * Remove patch to pflash_cfi01 which enabled readonly mode
>  * Adjust kvm code to use KVM READONLY support for ranges that
>either have the readonly flag set, or for devices with
>readable set.
> 
> v4:
>  * With a machine type of isapc, don't mark the BIOS as read-only.
>isapc + seabios will not boot if the BIOS is read-only. This
>matches the current behavior of isapc with KVM, which is the
>only mode under which isapc currently works.
> 
> v3:
>  * Squash patch 2 & 3 based on Xiao's feedback that what I
>was calling a 'workaround' in patch 3 was actually what
>is required by the KVM READONLY memory support.
> 
> v2:
>  * Remove rom_only from PC_COMPAT_1_4
>  * Only enable flash when a pflash drive is created.
> 
> Jordan Justen (5):
>   isapc: Fix non-KVM qemu boot (read/write memory for isapc BIOS)
>   kvm: add kvm_readonly_mem_enabled
>   kvm: support using KVM_MEM_READONLY flag for regions
>   pc_sysfw: allow flash (-pflash) memory to be used with KVM
>   pc_sysfw: change rom_only default to 0
> 
>  hw/block/pc_sysfw.c  |   64 
> --
>  hw/i386/pc_piix.c|5 
>  include/hw/i386/pc.h |4 
>  include/sysemu/kvm.h |   10 
>  kvm-all.c|   44 +++---
>  kvm-stub.c   |1 +
>  6 files changed, 92 insertions(+), 36 deletions(-)
> 

Reviewed-by: Paolo Bonzini 



Re: [Qemu-devel] [PATCH V18 5/6] add-cow file format core code.

2013-05-08 Thread Dong Xu Wang
On Thu, Apr 18, 2013 at 6:03 PM, Stefan Hajnoczi  wrote:
> On Wed, Apr 10, 2013 at 04:11:52PM +0800, Dong Xu Wang wrote:
>> +header.cluster_bits = ffs(cluster_size) - 1;
>> +if (header.cluster_bits < MIN_CLUSTER_BITS ||
>> +header.cluster_bits > MAX_CLUSTER_BITS ||
>> +(1 << header.cluster_bits) != cluster_size) {
>> +error_report(
>> +"Cluster size must be a power of two between %d and %dk",
>> +1 << MIN_CLUSTER_BITS, 1 << (MAX_CLUSTER_BITS - 10));
>> +return -EINVAL;
>> +}
>> +
>> +   header.header_size = MAX(cluster_size, DEFAULT_HEADER_SIZE);
>
> Indentation.
>
>> +if (backing_filename) {
>> +header.backing_offset = sizeof(header);
>> +header.backing_size = strlen(backing_filename);
>> +
>> +if (!backing_fmt) {
>> +backing_bs = bdrv_new("image");
>> +ret = bdrv_open(backing_bs, backing_filename, NULL,
>> +BDRV_O_RDWR | BDRV_O_CACHE_WB, NULL);
>> +if (ret < 0) {
>> +return ret;
>
> backing_bs is leaked.
>
>> +ret = bdrv_file_open(&bs, filename, NULL, BDRV_O_RDWR);
>> +if (ret < 0) {
>> +return ret;
>> +}
>> +snprintf(header.backing_fmt, sizeof(header.backing_fmt), "%s",
>> + backing_fmt ? backing_fmt : "");
>> +snprintf(header.image_fmt, sizeof(header.image_fmt), "%s",
>> + image_format ? image_format : "raw");
>
> snprintf() doesn't have the semantics in the add-cow specification:
>
> " 44 - 59:backing file format
>   Format of backing file. It will be filled with
>   0 if backing file name offset is 0. If backing
>   file name offset is non-empty, it must be
>   non-empty. It is coded in free-form ASCII, and
>   is not NUL-terminated. Zero padded on the right.
>
>   60 - 75:image file format
>   Format of image file. It must be non-empty. It
>   is coded in free-form ASCII, and is not
>   NUL-terminated. Zero padded on the right."
>
> strncpy() does the zero padding and doesn't NUL-terminate if the max buffer
> size is used.
>
>> +if ((s->header.compat_features & ACOW_F_ALL_ALLOCATED) == 0) {
>> +snprintf(bs->backing_format, sizeof(bs->backing_format),
>> + "%s", s->header.backing_fmt);
>
> s->header.backing_fmt is not NUL-terminated so using snprintf() is
> inappropriate (could it read beyond the end of .backing_fmt?).
>
>> +}
>> +
>> +if (s->header.cluster_bits < MIN_CLUSTER_BITS ||
>> +s->header.cluster_bits > MAX_CLUSTER_BITS) {
>> +ret = -EINVAL;
>> +goto fail;
>> +}
>> +
>> +s->cluster_size = 1 << s->header.cluster_bits;
>> +if (s->header.header_size != MAX(s->cluster_size, DEFAULT_HEADER_SIZE)) 
>> {
>> +char buf[64];
>> +snprintf(buf, sizeof(buf), "Header size: %d",
>
> %u or PRIu32 since header_size is uint32_t.  This avoids compiler or
> code scanner warnings.
>
>> +s->image_hd = bdrv_new("");
>> +ret = bdrv_open(s->image_hd, image_filename, NULL, flags,
>> +bdrv_find_format(s->header.image_fmt));
>
> Cannot use image_fmt as a string since it is not NUL-terminated.
>
>> +static coroutine_fn int add_cow_co_writev(BlockDriverState *bs,
>> +  int64_t sector_num,
>> +  int remaining_sectors,
>> +  QEMUIOVector *qiov)
>> +{
>> +BDRVAddCowState *s = bs->opaque;
>> +int ret = 0, i;
>> +QEMUIOVector hd_qiov;
>> +uint8_t *table;
>> +uint64_t offset;
>> +int mask = s->cluster_sectors - 1;
>> +int cluster_mask = s->cluster_size - 1;
>> +
>> +qemu_co_mutex_lock(&s->lock);
>> +qemu_iovec_init(&hd_qiov, qiov->niov);
>> +ret = bdrv_co_writev(s->image_hd, sector_num,
>> + remaining_sectors, qiov);
>
> All writes are serialized.  This means write performance will be very
> poor for multi-threaded workloads.
>
> qcow2 tracks allocating writes and allows them to execute at the same
> time if they do not overlap clusters.
>
>> +
>> +if (ret < 0) {
>> +goto fail;
>> +}
>> +if ((s->header.compat_features & ACOW_F_ALL_ALLOCATED) == 0) {
>> +/* Copy content of unmodified sectors */
>> +if (!is_cluster_head(sector_num, s->cluster_sectors)
>> +&& !is_allocated(bs, sector_num)) {
>> +ret = copy_sectors(bs, sector_num & ~mask, sector_num);
>> +if (ret < 0) {
>> +goto fail;
>> +}
>> +}
>> +
>> +if (!is_cluster_tail(sector_num + remaining_sectors - 1,
>> + s->cluster_sectors)
>> +&& !is_allocated(bs, sector_num + remaining_sectors - 1)) {
>> +ret = copy_sectors(bs, sector_num + remaining_sectors,
>> +   ((sec

Re: [Qemu-devel] [Qemu-trivial] [PATCH 2/2] remove needless semicolon

2013-05-08 Thread Michael Tokarev
08.05.2013 17:25, Anthony Liguori wrote:
> Michael Tokarev  writes:
> 
>> 08.05.2013 13:46, Trival wrote:
>>> Signed-off-by: Trival 
> 
> Something went wrong in sending this.  This is not a valid SoB.

So, do we not accept it?  Should I revert it in the
trivial-patches-next ?

Thanks,

/mjt



[Qemu-devel] [Bug 1178107] [NEW] qemu-system-*.exe -cpu ? (or -M ?) exit silently

2013-05-08 Thread Cauchy Song
Public bug reported:

For example, 'qemu-system-arm -cpu ?' on Linux host give me available
cpu list:

Available CPUs:
  arm1026
  arm1136
  arm1136-r2
  ...

But on Windows host, I got nothing:

C:\opt\qemu-1.5.0-rc0-win64>qemu-system-arm -cpu ?

C:\opt\qemu-1.5.0-rc0-win64>echo %ERRORLEVEL%
0

** Affects: qemu
 Importance: Undecided
 Status: New

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1178107

Title:
  qemu-system-*.exe -cpu ? (or -M ?) exit silently

Status in QEMU:
  New

Bug description:
  For example, 'qemu-system-arm -cpu ?' on Linux host give me available
  cpu list:

  Available CPUs:
arm1026
arm1136
arm1136-r2
...

  But on Windows host, I got nothing:

  C:\opt\qemu-1.5.0-rc0-win64>qemu-system-arm -cpu ?

  C:\opt\qemu-1.5.0-rc0-win64>echo %ERRORLEVEL%
  0

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1178107/+subscriptions



Re: [Qemu-devel] [libvirt]virtio serial device problem

2013-05-08 Thread Li Zhang

On 2013年05月08日 23:53, fred.kon...@greensocs.com wrote:

On 05/07/2013 07:50 PM, Paolo Bonzini wrote:

Il 07/05/2013 09:20, Li Zhang ha scritto:

Hi all,

Hi,

When we use the latest version of QEMU to build ovirt,
we get this error reported from libvirt.

What QEMU commit is this?


b3e6d591b05538056d665572f3e3bbfb3cbb70e7

This commit is from 05/29 no?

there were issues with that. But it should be fixed.

Do you still have the command-line issue with the last git?

See commit 80270a19685dd20eda017b0360c743b3e3ed6f57


Hi Fred,

This patch is to change bus which can be compatible with old version, right?
But I saw the current name is still different from old version.

The current name is: "virtio-serial-bus0.0"
The old version is: "virtio-serial0.0"

Is it possible to change it back to the old name?

Thanks. :)
--Li


Thanks,
Fred




It might have been fixed already.

Hm. From what I see, it is all correct from the qemu side, the problem is
in libvirt which does not know about "virtio-pci-bus" yet.




Paolo


qemu-system-ppc64: -device
virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=com.redhat.rhevm.vdsm:

Bus 'virtio-serial0.0' is full
qemu-system-ppc64: -device
virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=com.redhat.rhevm.vdsm:

Bus 'virtio-serial0.0' not found

Libvirt helps create QEMU command line and put virtserialport device to
bus virtio-serial0.0.
For latest version of QEMU, the bus type is changed.

(qemu) info qtree
bus: main-system-bus
   type System
   dev: spapr-pci-host-bridge, id ""
 index = 0
 buid = 0x8002000
 liobn = 0x8000
 mem_win_addr = 0x100a000
 mem_win_size = 0x2000
 io_win_addr = 0x1008000
 io_win_size = 0x1
 msi_win_addr = 0x1009000
 irq 0
 bus: pci
   type PCI
   dev: virtio-serial-pci, id "virtio-serial0"
 ioeventfd = on
 vectors = 2
 class = 0x780
 indirect_desc = on
 event_idx = on
 max_ports = 31
 addr = 03.0
 romfile = 
 rombar = 1
 multifunction = off
 command_serr_enable = on
 class Class 0780, addr 00:03.0, pci id 1af4:1003 (sub
1af4:0003)
 bar 0: i/o at 0x [0x1e]
 bar 1: mem at 0x [0xffe]
 bus: virtio-serial0.0
   type virtio-pci-bus
   dev: virtio-serial-device, id ""
 max_ports = 31
 bus: virtio-serial-bus.0
   type virtio-serial-bus
   dev: virtserialport, id "channel1"
 chardev = charchannel1
 nr = 2
 name = "org.qemu.guest_agent.0"
 port 2, guest off, host off, throttle off
   dev: virtserialport, id "channel0"
 chardev = charchannel0
 nr = 1
 name = "com.redhat.rhevm.vdsm"
 port 1, guest off, host off, throttle off


But we tried to replace virtio-serial0.0 with virtio-serial-bus.0,
SLOF crashes. It still doesn't work at all.

Does anyone know how to use virtserialport in QEMU command line?
If configuration is changed in QEMU, libvirt also needs to change it
accordingly.

Thanks. :)
--Li





--
Alexey Kardashevskiy
IBM OzLabs, LTC Team

e-mail: a...@au1.ibm.com
notes: Alexey Kardashevskiy/Australia/IBM








[Qemu-devel] [Bug 1178101] [NEW] Could not enable gtk UI on build for Windows target

2013-05-08 Thread Cauchy Song
Public bug reported:

$ ${QEMU_SRC_DIR}/configure --prefix=${BIN_ROOT} --cross-
prefix=${HOST_TRIPLET}- --extra-cflags="-I${BIN_ROOT}/include" --extra-
ldflags="-L${BIN_ROOT}/lib" --enable-gtk --disable-xen

ERROR: User requested feature gtk
   configure was not able to find it


$ cat config.log
# QEMU configure log Thu May  9 13:50:40 CST 2013
# Configured with: '/home/cauchy/vcs/git/qemu/configure' 
'--prefix=/home/cauchy/w32' '--cross-prefix=i686-w64-mingw32-' 
'--extra-cflags=-I/home/cauchy/w32/include' 
'--extra-ldflags=-L/home/cauchy/w32/lib' '--enable-gtk' '--disable-xen'
#
i686-w64-mingw32-gcc -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 
-Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings 
-Wmissing-prototypes -fno-strict-aliasing -I/home/cauchy/w32/include -c -o 
/tmp/qemu-conf--18025-.o /tmp/qemu-conf--18025-.c
/tmp/qemu-conf--18025-.c:2:2: error: #error __linux__ not defined
 #error __linux__ not defined
  ^
i686-w64-mingw32-gcc -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 
-Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings 
-Wmissing-prototypes -fno-strict-aliasing -I/home/cauchy/w32/include -c -o 
/tmp/qemu-conf--18025-.o /tmp/qemu-conf--18025-.c
i686-w64-mingw32-gcc -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 
-Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings 
-Wmissing-prototypes -fno-strict-aliasing -I/home/cauchy/w32/include -c -o 
/tmp/qemu-conf--18025-.o /tmp/qemu-conf--18025-.c
i686-w64-mingw32-gcc -D__USE_MINGW_ANSI_STDIO=1 -DWIN32_LEAN_AND_MEAN 
-DWINVER=0x501 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 
-Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings 
-Wmissing-prototypes -fno-strict-aliasing -I/home/cauchy/w32/include -o 
/tmp/qemu-conf--18025-.exe /tmp/qemu-conf--18025-.c -g -L/home/cauchy/w32/lib 
-liberty
i686-w64-mingw32-gcc -m32 -D__USE_MINGW_ANSI_STDIO=1 -DWIN32_LEAN_AND_MEAN 
-DWINVER=0x501 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 
-Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings 
-Wmissing-prototypes -fno-strict-aliasing -I/home/cauchy/w32/include -c -o 
/tmp/qemu-conf--18025-.o /tmp/qemu-conf--18025-.c
i686-w64-mingw32-gcc -m32 -D__USE_MINGW_ANSI_STDIO=1 -DWIN32_LEAN_AND_MEAN 
-DWINVER=0x501 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 
-Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings 
-Wmissing-prototypes -fno-strict-aliasing -I/home/cauchy/w32/include -Werror 
-Winitializer-overrides -o /tmp/qemu-conf--18025-.exe /tmp/qemu-conf--18025-.c 
-m32 -g -L/home/cauchy/w32/lib
i686-w64-mingw32-gcc: error: unrecognized command line option 
‘-Winitializer-overrides’
i686-w64-mingw32-gcc -m32 -D__USE_MINGW_ANSI_STDIO=1 -DWIN32_LEAN_AND_MEAN 
-DWINVER=0x501 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 
-Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings 
-Wmissing-prototypes -fno-strict-aliasing -I/home/cauchy/w32/include -Werror 
-Wendif-labels -o /tmp/qemu-conf--18025-.exe /tmp/qemu-conf--18025-.c -m32 -g 
-L/home/cauchy/w32/lib
i686-w64-mingw32-gcc -m32 -D__USE_MINGW_ANSI_STDIO=1 -DWIN32_LEAN_AND_MEAN 
-DWINVER=0x501 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 
-Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings 
-Wmissing-prototypes -fno-strict-aliasing -I/home/cauchy/w32/include 
-Wendif-labels -Werror -Wmissing-include-dirs -o /tmp/qemu-conf--18025-.exe 
/tmp/qemu-conf--18025-.c -m32 -g -L/home/cauchy/w32/lib
i686-w64-mingw32-gcc -m32 -D__USE_MINGW_ANSI_STDIO=1 -DWIN32_LEAN_AND_MEAN 
-DWINVER=0x501 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 
-Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings 
-Wmissing-prototypes -fno-strict-aliasing -I/home/cauchy/w32/include 
-Wendif-labels -Wmissing-include-dirs -Werror -Wempty-body -o 
/tmp/qemu-conf--18025-.exe /tmp/qemu-conf--18025-.c -m32 -g 
-L/home/cauchy/w32/lib
i686-w64-mingw32-gcc -m32 -D__USE_MINGW_ANSI_STDIO=1 -DWIN32_LEAN_AND_MEAN 
-DWINVER=0x501 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 
-Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings 
-Wmissing-prototypes -fno-strict-aliasing -I/home/cauchy/w32/include 
-Wendif-labels -Wmissing-include-dirs -Wempty-body -Werror -Wnested-externs -o 
/tmp/qemu-conf--18025-.exe /tmp/qemu-conf--18025-.c -m32 -g 
-L/home/cauchy/w32/lib
i686-w64-mingw32-gcc -m32 -D__USE_MINGW_ANSI_STDIO=1 -DWIN32_LEAN_AND_MEAN 
-DWINVER=0x501 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 
-Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings 
-Wmissing-prototypes -fno-strict-aliasing -I/home/cauchy/w32/include 
-Wendif-labels -Wmissing-include-dirs -Wempty-body -Wnested-externs -Werror 
-Wformat-security -o /tmp/qemu-conf--18025-.exe /tmp/qemu-conf--18025-.c -m32 
-g -L/home/cauchy/w32/lib
i686-w64-mingw32-gcc -m32 -D__USE_MINGW_ANSI_STDIO=1 -DWIN32_LEAN_AND_MEAN 
-DWINVER=0x501 -D_

Re: [Qemu-devel] Query regarding IO paths in QEMU

2013-05-08 Thread Stefan Hajnoczi
On Mon, May 06, 2013 at 02:36:46PM -0700, aayush gupta wrote:
> Thanks for the reply. I am trying to use the tracing with qemu-io as
> suggested in docs/tracing.txt. I did the following steps:
> 
> 1. Configure and make with simple backend
> 2. Create a set of events I am interested in (/tmp/events)
> 3. Now I am running the qemu-iotests by adding T= /tmp/events to  test 001
> testcase (file read path only).
> It runs and generates a trace-x file. However, the file just has a
> couple of lines in it in binary.
> 4. When I pass it through simpletrace.py nothing happens.
> 
> Can you tell me if I missed some step or something else needs to be done.

Invoke simpletrace.py like this:

  $ scripts/simpletrace.py trace-events 

If tracing doesn't work with qemu-iotests, try it manually first:

  $ qemu-io -T /tmp/events -c 'read 0 512' test.img

Stefan



Re: [Qemu-devel] [PATCH] curl: fix curl read

2013-05-08 Thread Stefan Hajnoczi
On Fri, May 03, 2013 at 07:23:31PM +0800, Fam Zheng wrote:
> On Fri, 05/03 13:09, Stefan Hajnoczi wrote:
> > On Fri, May 03, 2013 at 04:00:09PM +0800, Fam Zheng wrote:
> > > CURL library API has changed, the current curl driver is not working.
> > > This patch rewrites the use of API as well as the structure of internal
> > > states. (It is hard to split this to multiple patches as basically all
> > > these changes need to work together.)
> > 
> > Which libcurl APIs have changed?  I expect libcurl to be backwards
> > compatible.
> 
> Function curl_multi_socket_all (see man 3 curl_multi_socket) is
> deprecated, and not working as I tried the current curl driver, build
> against libcurl 7.27.0. It's deprecated to be replaced by
> curl_multi_socket_action.
> 
> The version does not concern, they are all introduced in the same
> version, 7.15.4 [1], and has been there for long.
> 
> [1]: http://curl.haxx.se/libcurl/c/curl_multi_socket_action.html

Great, please include the details in the commit description.

I checked that RHEL 5.x has libcurl 7.15.5 so it should be safe to use
curl_multi_socket_action().  Most other operating systems will have a
newer libcurl than this.

Stefan



Re: [Qemu-devel] [PATCH RFC 0/3] seabios: move acpi table formatting out of bios

2013-05-08 Thread Gleb Natapov
On Wed, May 08, 2013 at 06:55:22PM -0400, Kevin O'Connor wrote:
> On Wed, May 08, 2013 at 03:35:46PM +0300, Michael S. Tsirkin wrote:
> > On Wed, May 08, 2013 at 02:35:44PM +0300, Gleb Natapov wrote:
> > > On Wed, May 08, 2013 at 02:07:24PM +0300, Michael S. Tsirkin wrote:
> > > > On Wed, May 08, 2013 at 01:59:12PM +0300, Gleb Natapov wrote:
> > > > > Where this notion that fw_cfg is only for a small things is coming
> > > > > from? I can assure you this was not the case when the device was
> > > > > introduced. In fact it is used today for not so small things like
> > > > > bootindex splash screen bitmaps, option rom loading and kernel/initrd
> > > > > loading. Some of those are bigger then ACPI tables will ever be.
> > > > > And they all should be migrated, so fw_cfg should be fixed anyway.
> > > > 
> > > > I'm not arguing with that. Convince Anthony please.
> > > > 
> > > Convince him in what? That fw_cfg is broken vrt migration and there are
> > > cases that will fail _today_ without any ACPI related changes? This is
> > > knows for ages.
> > 
> > That we should use fw_cfg to load acpi tables.
> 
> I'm confused.
> 
> ACPI tables are not large.  At most we're talking about 100K of data
> total.
> 
> I don't see what migration has to do with using fw_cfg to pass acpi
> tables - the content is only read at startup.  There may be an issue
> for the corner case of VM restarts, but if so it's nothing new.  If
> the content of a fw_cfg entry changes during a guest reboot it is
> going to have the same impact regardless of whether it's the
> "irq0-override" entry / "numa-nodes" entry - or if it's the "madt"
> entry / "srat" entry, etc.  So, I don't see how fw_cfg would suddenly
> not be suitable.
> 
If the tables at the source of the migration and the destination
differs and migration happens while seabios is reading them guest
will have corrupted ACPI tables at the destination. The problem is
not new. The same is true for reading option rom or splash screen or
bootindex file, basically anything that we read via fw_cfg interface
and it can be different between two qemu version. The window where the
bug may happen is very small, so we never saw such problem in practice
to my knowledge and the fix should be simple too: migrate fw_cfg that
is been read during migration.

> Again, I recommend that ACPI (and mptable, smbios, pir) be generated
> in qemu and that the content be passed to SeaBIOS using one fw_cfg
> "file" per table.
> 
+1 again.

--
Gleb.



Re: [Qemu-devel] [PATCH 9/9] Make monitor command 'dump-guest-memory' dump in kdump-compressed format

2013-05-08 Thread Zhang Xiaohe

于 2013年05月09日 01:16, Eric Blake 写道:

On 05/08/2013 02:50 AM, qiaonuohan wrote:


Thanks for your suggestion. I will fix it like:

{ 'enum': 'DumpCompressionFormat',
   'data': [ 'zlib', 'lzo', 'snappy' ] }

For zlib is treated as the default compression format, and
'uncompressed' won't be an option.


No, I was serious that you need to provide 'uncompressed' as an explicit
enum value.  It is very annoying to toggle between four states (three
compression formats and a fourth state of no compression) when the
fourth is available only by omitting a parameter.  The default MUST be
'uncompressed' for backwards-compatibility, not 'zlib'.


We'd like to make sure that we understand you precisely.

The definion is like below:
{ 'enum': 'DumpGuestMemoryFormat',
  'data': [ 'uncompressed', 'zlib', 'lzo', 'snappy' ] }

{ 'command': 'dump-guest-memory',
  'data': { 'paging': 'bool', 'protocol': 'str', '*begin': 'int',
'*length': 'int', '*format': 'DumpCompressionFormat' } }

'format' is optional:
1. when 'format' is not specified, vmcore will be in ELF format.
2. when 'format' is specified and its parameter is 'uncompressed',
   vmcore will be in ELF format as well.
3. when 'format' is specified and its parameter is 'zlib/lzo/snappy',
   vmcore will be in kdump-compressed format.

If this is what you suggest, then I don't think it is necessary to
add 'uncompressed'. The backwards-compatibility is assured by case 1,
in which the interface is exactly the same as before. So why do we
add another parameter to do the same thing again?



Re: [Qemu-devel] [PATCH RFC 0/3] seabios: move acpi table formatting out of bios

2013-05-08 Thread Gleb Natapov
On Wed, May 08, 2013 at 09:15:44PM +0300, Michael S. Tsirkin wrote:
> On Tue, May 07, 2013 at 07:01:13PM -0400, Kevin O'Connor wrote:
> > On Tue, May 07, 2013 at 09:00:48PM +0300, Michael S. Tsirkin wrote:
> > > On Thu, Apr 25, 2013 at 12:02:20PM +0300, Michael S. Tsirkin wrote:
> > > > Untested yet, but I thought I'd share the
> > > > BIOS bits so we can agree on direction.
> > > > 
> > > > In particular check out ROM sizes:
> > > > - Before patchset with DSDT enabled
> > > > Total size: 127880  Fixed: 59060  Free: 3192 (used 97.6% of 128KiB 
> > > > rom)
> > > > - Before patchset with DSDT disabled
> > > > Total size: 122844  Fixed: 58884  Free: 8228 (used 93.7% of 128KiB 
> > > > rom)
> > > > - After patchset:
> > > > Total size: 128776  Fixed: 59100  Free: 2296 (used 98.2% of 128KiB 
> > > > rom)
> > > > - Legacy disabled at build time:
> > > > Total size: 119836  Fixed: 58996  Free: 11236 (used 91.4% of 128KiB 
> > > > rom)
> > > > 
> > > > As can be seen from this, most size savings come
> > > > from dropping DSDT, but we do save a bit by removing
> > > > other tables. Of course the real reason to move tables to QEMU
> > > > is so that ACPI can better match hardware.
> > > > 
> > > > This patchset adds an option to move all code for formatting acpi tables
> > > > out of BIOS. With this, QEMU has full control over the table layout.
> > > > All tables are loaded from the new "/etc/acpi/" directory.
> > > > Any entries in this directory cause BIOS to disable
> > > > ACPI table generation completely.
> > > > A generic linker script, controlled by QEMU, is
> > > > loaded from "/etc/linker-script". It is used to
> > > > patch in table pointers and checksums.
> > > 
> > > After some thought, there are two additional
> > > options worth considering, in that they simplify
> > > bios code somewhat:
> > > 
> > > - bios could get size from qemu, allocate a buffer
> > >   (e.g. could be one buffer for all tables)
> > >   and pass the address to qemu.
> > >   qemu does all the patching
> > > 
> > > - further, qemu could do the copy of tables into
> > >   that address directly
> > 
> > This seems more complex than necessary to me.
> > 
> > The important task is to get the tables generated in QEMU - I'd focus
> > on getting the tables generated in QEMU (one table per fw_cfg "file").
> > Once that is done, the SeaBIOS side can be easily implemented, and we
> > can add any enhancements on top if we feel it is necessary.
> > 
> > -Kevin
> 
> I have kind of done this, though only compile-tested
> for now - still need to update the bios with the new
> linker interface along the lines suggested by you.
> 
> If you want to see how the code looks like check out
> 
> git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git acpi
> the code is in
> hw/i386/acpi-build.c
> and
> hw/i386/bios-linker-loader.c
> 
> the history is all messed up now, I'll clean it up shortly.
> 
> That said, this uses fw_cfg so for this to be acceptable,
> we need to fix migration with big fw_cfg files.
> 
We need to fix it anyway ;)

--
Gleb.



[Qemu-devel] [Bug 1175513] Re: Qemu 1.5-git gpu clock control doesn`t work after guest reboot

2013-05-08 Thread commiethebeastie
In text mode and on net console there are no errors, host system just
freezes after guest poweroff. This may be a hang-up the pcie?

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1175513

Title:
  Qemu 1.5-git gpu clock control doesn`t work after guest reboot

Status in The Linux Kernel:
  New
Status in QEMU:
  New

Bug description:
  I run qemu from git with such command:

  qemu-system-x86_64 -nodefaults -m 4096 -smp 8,cores=4,threads=2,sockets=1 
-cpu 'kvm64' -device usb-mouse -M q35 -vga qxl -no-hpet -boot once=c,menu=on 
-device vfio-pci,host=02:00.0,x-vga=on \
  -enable-kvm -monitor stdio -chardev 
socket,path=/tmp/qga.sock,server,nowait,id=qga0 -device virtio-serial -device 
virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 -net 
nic,vlan=0,model=e1000 -net tap,ifname=tap0,script=/etc/guest-ifup -usb -device 
intel-hda -device hda-duplex \
  -drive 
file='/home//qemu/win7',if=none,id=drive-virtio-disk0,cache=writeback,aio=native,format=qed,discard=on
 -device virtio-blk-pci,drive=drive-virtio-disk0,id=virtio-disk \
  -drive 
file='/dev/sr0',if=none,id=drive-ide1-0-0,media=cdrom,snapshot=off,format=raw 
-device ide-drive,bus=ide.1,unit=0,drive=drive-ide1-0-0,id=ide1-0-0 \
  -spice port=5930,disable-ticketing

  Before guest (Windows 7) reboot, videocard works in 3D mode with full
  frequency. But after reboot videocard works in 3D only with powersafe
  frequency. Then I must reboot host for recover gpu clock control.

To manage notifications about this bug go to:
https://bugs.launchpad.net/linux/+bug/1175513/+subscriptions



Re: [Qemu-devel] [PATCH 01/40] memory: assert that PhysPageEntry's ptr does not overflow

2013-05-08 Thread liu ping fan
On Wed, May 8, 2013 at 12:08 AM, Paolo Bonzini  wrote:
>
>
> - Messaggio originale -
>> Da: "Peter Maydell" 
>> A: "Paolo Bonzini" 
>> Cc: qemu-devel@nongnu.org, a...@ozlabs.ru, "jan kiszka" 
>> , qemul...@gmail.com,
>> stefa...@redhat.com, da...@gibson.dropbear.id.au
>> Inviato: Martedì, 7 maggio 2013 17:44:59
>> Oggetto: Re: [Qemu-devel] [PATCH 01/40] memory: assert that PhysPageEntry's 
>> ptr does not overflow
>>
>> On 7 May 2013 15:16, Paolo Bonzini  wrote:
>> > Signed-off-by: Paolo Bonzini 
>> > ---
>> >  exec.c |2 ++
>> >  1 files changed, 2 insertions(+), 0 deletions(-)
>> >
>> > diff --git a/exec.c b/exec.c
>> > index 19725db..2e5b89a 100644
>> > --- a/exec.c
>> > +++ b/exec.c
>> > @@ -719,6 +719,8 @@ static void destroy_all_mappings(AddressSpaceDispatch
>> > *d)
>> >
>> >  static uint16_t phys_section_add(MemoryRegionSection *section)
>> >  {
>> > +assert(phys_sections_nb < TARGET_PAGE_SIZE);
>> > +
>> >  if (phys_sections_nb == phys_sections_nb_alloc) {
>> >  phys_sections_nb_alloc = MAX(phys_sections_nb_alloc * 2, 16);
>> >  phys_sections = g_renew(MemoryRegionSection, phys_sections,
>>
>> Why is the limit we're asserting not the same as the maximum
>> size that we pass to g_renew() below?
>
> That's a minimum size, isn't it?
>
> I'm asserting that the physical section number doesn't overflow into
> the page, since the TLB entries are stored as a combination of the two.
>
Could you explain more detail? Why < TARGET_PAGE_SIZE, not 2^15?

Thanks,
Pingfan

> Paolo



Re: [Qemu-devel] [PATCH V14 6/6] remove QEMUOptionParameter related functions and struct

2013-05-08 Thread Dong Xu Wang

On 2013/5/9 1:59, Eric Blake wrote:

[assuming you mis-typed your cc:, and that you meant kwolf instead of
kwol at redhat]

On 05/08/2013 02:45 AM, Dong Xu Wang wrote:

Signed-off-by: Dong Xu Wang 
---
  include/qemu/option.h |  32 --
  util/qemu-option.c| 285 - 
-
  2 files changed, 317 deletions(-)

diff --git a/include/qemu/option.h b/include/qemu/option.h
index d63e447..51814cf 100644
--- a/include/qemu/option.h
+++ b/include/qemu/option.h
@@ -38,17 +38,6 @@ enum QEMUOptionParType {
  OPT_STRING,
  };

-typedef struct QEMUOptionParameter {
-const char *name;
-enum QEMUOptionParType type;


'enum QEMUOptionParType' several lines earlier is now unused; you should
clean that too.


Yes, will remove it after reviewing, thank you, Eric.




Re: [Qemu-devel] [RFC PATCH 0/8] MemoryRegion and FlatView refcounting, replace hostmem with memory_region_find

2013-05-08 Thread liu ping fan
On Wed, May 8, 2013 at 11:44 PM, Paolo Bonzini  wrote:
> Il 08/05/2013 08:20, liu ping fan ha scritto:
>> On Mon, May 6, 2013 at 10:25 PM, Paolo Bonzini  wrote:
>>> Hi,
>>>
>>> this is an alternative approach to refactoring of dataplane's HostMem
>>> code.  Here, I take Ping Fan's idea of RCU-style updating of the
>>> region list and apply it to the AddressSpace's FlatView.  With this
>>
>> In fact, I am worrying about the priority of MemoryListener, if it is
>> true, then we should drop RCU-style idea.
>
> You mean in hostmem, or in general as in this patch?  Note that this
> patch releases the old FlatView at the end of all MemoryListener operations.
>
Both in hostmem and this patch, they all broke the original design of
the  MemoryListener, see notes for priority in code.
I have set out 2 patches to highlight this issue, and have CC you and Stefanha.

Regards,
Pingfan

> Paolo
>
>> Also if it is true, there is
>> already a bug with hostmem listener. It should use region_del, not
>> region_nop to reconstruct the local view. But just let me have a deep
>> thinking.
>>
>> Regards,
>> Pingfan
>>> change, dataplane can simply use memory_region_find instead of
>>> hostmem.
>>>
>>> This is a somewhat larger change, but I prefer it for two reasons.
>>>
>>> 1) it splits the task of adding BQL-less memory dispatch in two parts,
>>>tacking memory_region_find first (which is simpler because locking
>>>is left to the caller).
>>>
>>> 2) HostMem duplicates a lot of the FlatView logic, and adding the
>>>RCU-style update in FlatView benefits everyone.
>>>
>>> The missing ingredients here are:
>>>
>>> 1) remember and unreference the MemoryRegions that are used in
>>>a vring entry.  In order to implement this, it is probably simpler
>>>to change vring.c to use virtio.c's VirtQueueElement data structure.
>>>We want something like that anyway in order to support migration.
>>>
>>> 2) add an owner field to MemoryRegion, and set it for all MemoryRegions
>>>for hot-unpluggable devices.  In this series, ref/unref are stubs.
>>>
>>> For simplicity I based the patches on my IOMMU rebase.  I placed the
>>> tree at git://github.com/bonzini/qemu.git, branch iommu.
>>>
>>> Paolo
>>>
>>> Paolo Bonzini (8):
>>>   memory: add ref/unref calls
>>>   exec: check MRU in qemu_ram_addr_from_host
>>>   memory: return MemoryRegion from qemu_ram_addr_from_host
>>>   memory: ref/unref memory across address_space_map/unmap
>>>   memory: access FlatView from a local variable
>>>   memory: use a new FlatView pointer on every topology update
>>>   memory: add reference counting to FlatView
>>>   dataplane: replace hostmem with memory_region_find
>>>
>>>  exec.c|   63 +---
>>>  hw/core/loader.c  |1 +
>>>  hw/display/exynos4210_fimd.c  |6 +
>>>  hw/display/framebuffer.c  |   10 +-
>>>  hw/i386/kvm/ioapic.c  |2 +
>>>  hw/i386/kvmvapic.c|1 +
>>>  hw/misc/vfio.c|2 +
>>>  hw/virtio/dataplane/Makefile.objs |2 +-
>>>  hw/virtio/dataplane/hostmem.c |  176 
>>> -
>>>  hw/virtio/dataplane/vring.c   |   56 +--
>>>  hw/virtio/vhost.c |2 +
>>>  hw/virtio/virtio-balloon.c|1 +
>>>  hw/xen/xen_pt.c   |4 +
>>>  include/exec/cpu-common.h |2 +-
>>>  include/exec/memory.h |9 ++
>>>  include/hw/virtio/dataplane/hostmem.h |   57 ---
>>>  include/hw/virtio/dataplane/vring.h   |3 +-
>>>  kvm-all.c |2 +
>>>  memory.c  |  142 +-
>>>  target-arm/kvm.c  |2 +
>>>  target-i386/kvm.c |4 +-
>>>  target-sparc/mmu_helper.c |1 +
>>>  xen-all.c |2 +
>>>  23 files changed, 253 insertions(+), 297 deletions(-)
>>>  delete mode 100644 hw/virtio/dataplane/hostmem.c
>>>  delete mode 100644 include/hw/virtio/dataplane/hostmem.h
>>>
>



[Qemu-devel] [0/8] Clean up PCI code to allow for multiple root buses

2013-05-08 Thread David Gibson
The current PCI subsystem has kind of half-hearted support for
multiple independent root buses - aka PCI domains - in the form of the
PCIHostBus structure and its domain field.  However, it doesn't quite
work because pci_host_bus_register() is always called with a domain of
0.

Worse, though, the whole concept of numbered domains isn't general
enough.  Many platforms can have independent root buses (usually on
wholly independent host bridges), but only x86 gives them a
hardware-significant domain number, essentially as a hack to allow all
the separate config spaces to be accessed via the same IO ports.
Linux guests on other platforms will show domain numbers in lspci, but
these are purely guest assigned, so qemu won't know about them.

This patch series, therefore, removes the broken-as-is domain concept
from qemu, and replaces it with a different way of handling multiple
root buses, based on a host bridge class method to provide a
identifier for the root bus.  This hook is designed in such a way as
to allow a single bridge object to support mutiple root buses with
future changes, which will allow future implementations of x86 north
bridges with multiple domains to be supported correctly, and in way
that matches the existing practice for all external interfaces.



[Qemu-devel] [PATCH 2/8] pci: Move pci_read_devaddr to pci-hotplug-old.c

2013-05-08 Thread David Gibson
pci_read_devaddr() is only used by the legacy functions for the old PCI
hotplug interface in pci-hotplug-old.c.  So we move the function there,
and make it static.

Signed-off-by: David Gibson 
---
 hw/pci/pci-hotplug-old.c |   14 ++
 hw/pci/pci.c |   16 +---
 include/hw/pci/pci.h |4 ++--
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
index 724a80b..1aa0ab8 100644
--- a/hw/pci/pci-hotplug-old.c
+++ b/hw/pci/pci-hotplug-old.c
@@ -34,6 +34,20 @@
 #include "sysemu/blockdev.h"
 #include "qapi/error.h"
 
+static int pci_read_devaddr(Monitor *mon, const char *addr, int *domp,
+int *busp, unsigned *slotp)
+{
+/* strip legacy tag */
+if (!strncmp(addr, "pci_addr=", 9)) {
+addr += 9;
+}
+if (pci_parse_devaddr(addr, domp, busp, slotp, NULL)) {
+monitor_printf(mon, "Invalid pci address\n");
+return -1;
+}
+return 0;
+}
+
 static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon,
const char *devaddr,
const char *opts_str)
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index d5257ed..9906e84 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -522,7 +522,7 @@ static void pci_set_default_subsystem_id(PCIDevice *pci_dev)
  * Parse [[:]:], return -1 on error if funcp == NULL
  *   [[:]:]., return -1 on error
  */
-static int pci_parse_devaddr(const char *addr, int *domp, int *busp,
+int pci_parse_devaddr(const char *addr, int *domp, int *busp,
   unsigned int *slotp, unsigned int *funcp)
 {
 const char *p;
@@ -581,20 +581,6 @@ static int pci_parse_devaddr(const char *addr, int *domp, 
int *busp,
 return 0;
 }
 
-int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp,
- unsigned *slotp)
-{
-/* strip legacy tag */
-if (!strncmp(addr, "pci_addr=", 9)) {
-addr += 9;
-}
-if (pci_parse_devaddr(addr, domp, busp, slotp, NULL)) {
-monitor_printf(mon, "Invalid pci address\n");
-return -1;
-}
-return 0;
-}
-
 PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr)
 {
 int dom, bus;
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 8d075ab..3ef2ee1 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -396,8 +396,8 @@ PCIDevice *pci_find_device(PCIBus *bus, int bus_num, 
uint8_t devfn);
 int pci_qdev_find_device(const char *id, PCIDevice **pdev);
 PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr);
 
-int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp,
- unsigned *slotp);
+int pci_parse_devaddr(const char *addr, int *domp, int *busp,
+  unsigned int *slotp, unsigned int *funcp);
 
 void pci_device_deassert_intx(PCIDevice *dev);
 
-- 
1.7.10.4




[Qemu-devel] [PATCH 6/8] pci: Simpler implementation of primary PCI bus

2013-05-08 Thread David Gibson
Currently pci_get_primary_bus() searches the list of root buses for one
with domain 0.  But since host buses are always registered with domain 0,
this just amounts to finding the only PCI host bus.

This simplifies the implementation by defining the primary PCI bus to
be the first one registered, using a global variable to track it.

Signed-off-by: David Gibson 
---
 hw/pci/pci.c |   18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index a3c192c..b25a1a1 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -96,6 +96,7 @@ struct PCIHostBus {
 QLIST_ENTRY(PCIHostBus) next;
 };
 static QLIST_HEAD(, PCIHostBus) host_buses;
+static PCIBus *pci_primary_bus;
 
 static const VMStateDescription vmstate_pcibus = {
 .name = "PCIBUS",
@@ -241,6 +242,12 @@ static int pcibus_reset(BusState *qbus)
 static void pci_host_bus_register(int domain, PCIBus *bus)
 {
 struct PCIHostBus *host;
+
+/* If this is the first one, assume it's the primary bus */
+if (!pci_primary_bus) {
+pci_primary_bus = bus;
+}
+
 host = g_malloc0(sizeof(*host));
 host->domain = domain;
 host->bus = bus;
@@ -249,15 +256,7 @@ static void pci_host_bus_register(int domain, PCIBus *bus)
 
 PCIBus *pci_get_primary_bus(void)
 {
-struct PCIHostBus *host;
-
-QLIST_FOREACH(host, &host_buses, next) {
-if (host->domain == 0) {
-return host->bus;
-}
-}
-
-return NULL;
+return pci_primary_bus;
 }
 
 PCIBus *pci_device_root_bus(const PCIDevice *d)
@@ -300,6 +299,7 @@ static void pci_bus_init(PCIBus *bus, DeviceState *parent,
 
 /* host bridge */
 QLIST_INIT(&bus->child);
+
 pci_host_bus_register(0, bus); /* for now only pci domain 0 is supported */
 
 vmstate_register(NULL, -1, &vmstate_pcibus, bus);
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH 02/40] memory: allow memory_region_find() to run on non-root memory regions

2013-05-08 Thread liu ping fan
On Tue, May 7, 2013 at 10:16 PM, Paolo Bonzini  wrote:
> memory_region_find() is similar to registering a MemoryListener and

But losing the priority of MemoryListener.  Had better document to
warn this, so the user will decide whether it is safe to use the
interfaces based on this or not.

> checking for the MemoryRegionSections that come from a particular
> region.  There is no reason for this to be limited to a root memory
> region.
>
> Signed-off-by: Paolo Bonzini 
> ---
>  include/exec/memory.h |   13 +++--
>  memory.c  |   20 +++-
>  2 files changed, 22 insertions(+), 11 deletions(-)
>
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index 9e88320..efe210b 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -725,17 +725,18 @@ void memory_region_set_alias_offset(MemoryRegion *mr,
>   *
>   * Returns a #MemoryRegionSection that describes a contiguous overlap.
>   * It will have the following characteristics:
> - *.@offset_within_address_space >= @addr
> - *.@offset_within_address_space + .@size <= @addr + @size
>   *.@size = 0 iff no overlap was found
>   *.@mr is non-%NULL iff an overlap was found
>   *
> - * @address_space: a top-level (i.e. parentless) region that contains
> - *   the region to be found
> - * @addr: start of the area within @address_space to be searched
> + * If @mr is parent-less,
> + *.@offset_within_address_space >= @addr
> + *.@offset_within_address_space + .@size <= @addr + @size
> + *
> + * @mr: a (possibly indirect) parent that contains the region to be found
> + * @addr: start of the area within @as to be searched
>   * @size: size of the area to be searched
>   */
> -MemoryRegionSection memory_region_find(MemoryRegion *address_space,
> +MemoryRegionSection memory_region_find(MemoryRegion *mr,
> hwaddr addr, uint64_t size);
>
>  /**
> diff --git a/memory.c b/memory.c
> index 75ca281..34bfb13 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -1451,15 +1451,24 @@ static FlatRange *address_space_lookup(AddressSpace 
> *as, AddrRange addr)
> sizeof(FlatRange), cmp_flatrange_addr);
>  }
>
> -MemoryRegionSection memory_region_find(MemoryRegion *address_space,
> +MemoryRegionSection memory_region_find(MemoryRegion *mr,
> hwaddr addr, uint64_t size)
>  {
> -AddressSpace *as = memory_region_to_address_space(address_space);
> -AddrRange range = addrrange_make(int128_make64(addr),
> - int128_make64(size));
> -FlatRange *fr = address_space_lookup(as, range);
>  MemoryRegionSection ret = { .mr = NULL, .size = 0 };
> +MemoryRegion *root;
> +AddressSpace *as;
> +AddrRange range;
> +FlatRange *fr;
> +
> +addr += mr->addr;
> +for (root = mr; root->parent; ) {
> +root = root->parent;
> +addr += root->addr;
> +}
>
> +as = memory_region_to_address_space(root);
> +range = addrrange_make(int128_make64(addr), int128_make64(size));
> +fr = address_space_lookup(as, range);
>  if (!fr) {
>  return ret;
>  }
> @@ -1470,6 +1479,7 @@ MemoryRegionSection memory_region_find(MemoryRegion 
> *address_space,
>  }
>
>  ret.mr = fr->mr;
> +ret.address_space = as;
>  range = addrrange_intersection(range, fr->addr);
>  ret.offset_within_region = fr->offset_in_region;
>  ret.offset_within_region += int128_get64(int128_sub(range.start,
> --
> 1.7.1
>
>



Re: [Qemu-devel] [libvirt]virtio serial device problem

2013-05-08 Thread Alexey Kardashevskiy
Hi!

On 05/09/2013 01:53 AM, fred.kon...@greensocs.com wrote:
>> On 05/07/2013 07:50 PM, Paolo Bonzini wrote:
>>> Il 07/05/2013 09:20, Li Zhang ha scritto:
 Hi all,
> 
> Hi,

 When we use the latest version of QEMU to build ovirt,
 we get this error reported from libvirt.
>>>
>>> What QEMU commit is this?
>>
>>
>> b3e6d591b05538056d665572f3e3bbfb3cbb70e7
> 
> This commit is from 05/29 no?
> 
> there were issues with that. But it should be fixed.
> 
> Do you still have the command-line issue with the last git?
>
> See commit 80270a19685dd20eda017b0360c743b3e3ed6f57


No, this patch helps, thanks!




> 
> Thanks,
> Fred
> 
>>
>>
>>> It might have been fixed already.
>>
>> Hm. From what I see, it is all correct from the qemu side, the problem is
>> in libvirt which does not know about "virtio-pci-bus" yet.
>>
>>
>>
>>> Paolo
>>>

 qemu-system-ppc64: -device
 virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=com.redhat.rhevm.vdsm:

 Bus 'virtio-serial0.0' is full
 qemu-system-ppc64: -device
 virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=com.redhat.rhevm.vdsm:

 Bus 'virtio-serial0.0' not found

 Libvirt helps create QEMU command line and put virtserialport device to
 bus virtio-serial0.0.
 For latest version of QEMU, the bus type is changed.

 (qemu) info qtree
 bus: main-system-bus
   type System
   dev: spapr-pci-host-bridge, id ""
 index = 0
 buid = 0x8002000
 liobn = 0x8000
 mem_win_addr = 0x100a000
 mem_win_size = 0x2000
 io_win_addr = 0x1008000
 io_win_size = 0x1
 msi_win_addr = 0x1009000
 irq 0
 bus: pci
   type PCI
   dev: virtio-serial-pci, id "virtio-serial0"
 ioeventfd = on
 vectors = 2
 class = 0x780
 indirect_desc = on
 event_idx = on
 max_ports = 31
 addr = 03.0
 romfile = 
 rombar = 1
 multifunction = off
 command_serr_enable = on
 class Class 0780, addr 00:03.0, pci id 1af4:1003 (sub
 1af4:0003)
 bar 0: i/o at 0x [0x1e]
 bar 1: mem at 0x [0xffe]
 bus: virtio-serial0.0
   type virtio-pci-bus
   dev: virtio-serial-device, id ""
 max_ports = 31
 bus: virtio-serial-bus.0
   type virtio-serial-bus
   dev: virtserialport, id "channel1"
 chardev = charchannel1
 nr = 2
 name = "org.qemu.guest_agent.0"
 port 2, guest off, host off, throttle off
   dev: virtserialport, id "channel0"
 chardev = charchannel0
 nr = 1
 name = "com.redhat.rhevm.vdsm"
 port 1, guest off, host off, throttle off


 But we tried to replace virtio-serial0.0 with virtio-serial-bus.0,
 SLOF crashes. It still doesn't work at all.

 Does anyone know how to use virtserialport in QEMU command line?
 If configuration is changed in QEMU, libvirt also needs to change it
 accordingly.

 Thanks. :)
 --Li


-- 
Alexey Kardashevskiy
IBM OzLabs, LTC Team

e-mail: a...@au1.ibm.com
notes: Alexey Kardashevskiy/Australia/IBM




[Qemu-devel] [PATCH 2/2] mem: highlight the listener's priority as enum

2013-05-08 Thread Liu Ping Fan
From: Liu Ping Fan 

It will make the priority prominent, when new listener added.
All the priority's value are kept unchanged, except for vhost
and hostmem.(Changes introduced by prev patch)

Signed-off-by: Liu Ping Fan 
---
 exec.c|4 ++--
 hw/virtio/dataplane/hostmem.c |2 +-
 hw/virtio/vhost.c |2 +-
 include/exec/memory.h |   12 +++-
 kvm-all.c |4 ++--
 xen-all.c |2 +-
 6 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/exec.c b/exec.c
index 19725db..aef0349 100644
--- a/exec.c
+++ b/exec.c
@@ -1766,13 +1766,13 @@ static MemoryListener core_memory_listener = {
 .begin = core_begin,
 .log_global_start = core_log_global_start,
 .log_global_stop = core_log_global_stop,
-.priority = 1,
+.priority = PRI_CORE,
 };
 
 static MemoryListener io_memory_listener = {
 .region_add = io_region_add,
 .region_del = io_region_del,
-.priority = 0,
+.priority = PRI_DEFAULT,
 };
 
 static MemoryListener tcg_memory_listener = {
diff --git a/hw/virtio/dataplane/hostmem.c b/hw/virtio/dataplane/hostmem.c
index 67cbce1..6be182c 100644
--- a/hw/virtio/dataplane/hostmem.c
+++ b/hw/virtio/dataplane/hostmem.c
@@ -158,7 +158,7 @@ void hostmem_init(HostMem *hostmem)
 .eventfd_del = hostmem_listener_eventfd_dummy,
 .coalesced_mmio_add = hostmem_listener_coalesced_mmio_dummy,
 .coalesced_mmio_del = hostmem_listener_coalesced_mmio_dummy,
-.priority = 9,
+.priority = PRI_VRING,
 };
 
 memory_listener_register(&hostmem->listener, &address_space_memory);
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 91c313b..df6d8c5 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -856,7 +856,7 @@ int vhost_dev_init(struct vhost_dev *hdev, int devfd, const 
char *devpath,
 .log_global_stop = vhost_log_global_stop,
 .eventfd_add = vhost_eventfd_add,
 .eventfd_del = vhost_eventfd_del,
-.priority = 9
+.priority = PRI_VRING
 };
 hdev->mem = g_malloc0(offsetof(struct vhost_memory, regions));
 hdev->n_mem_sections = 0;
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 9e88320..77e0d40 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -192,6 +192,16 @@ struct MemoryRegionSection {
 
 typedef struct MemoryListener MemoryListener;
 
+/* The list of priority, ex, vhost should have higher priority (less num) than
+ * kvm, ie PRI_VRING < PRI_HYPV
+ */
+typedef enum {
+PRI_DEFAULT = 0,
+PRI_CORE = 1,
+PRI_VRING = 9,
+PRI_HYPERV = 10,
+} MemListenerPriority;
+
 /**
  * MemoryListener: callbacks structure for updates to the physical memory map
  *
@@ -218,7 +228,7 @@ struct MemoryListener {
 void (*coalesced_mmio_del)(MemoryListener *listener, MemoryRegionSection 
*section,
hwaddr addr, hwaddr len);
 /* Lower = earlier (during add), later (during del) */
-unsigned priority;
+MemListenerPriority priority;
 AddressSpace *address_space_filter;
 QTAILQ_ENTRY(MemoryListener) link;
 };
diff --git a/kvm-all.c b/kvm-all.c
index 3a31602..2794dee 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -875,13 +875,13 @@ static MemoryListener kvm_memory_listener = {
 .eventfd_del = kvm_mem_ioeventfd_del,
 .coalesced_mmio_add = kvm_coalesce_mmio_region,
 .coalesced_mmio_del = kvm_uncoalesce_mmio_region,
-.priority = 10,
+.priority = PRI_HYPERV,
 };
 
 static MemoryListener kvm_io_listener = {
 .eventfd_add = kvm_io_ioeventfd_add,
 .eventfd_del = kvm_io_ioeventfd_del,
-.priority = 10,
+.priority = PRI_HYPERV,
 };
 
 static void kvm_handle_interrupt(CPUState *cpu, int mask)
diff --git a/xen-all.c b/xen-all.c
index 539a154..7062420 100644
--- a/xen-all.c
+++ b/xen-all.c
@@ -562,7 +562,7 @@ static MemoryListener xen_memory_listener = {
 .log_sync = xen_log_sync,
 .log_global_start = xen_log_global_start,
 .log_global_stop = xen_log_global_stop,
-.priority = 10,
+.priority = PRI_HYPERV,
 };
 
 void qmp_xen_set_global_dirty_log(bool enable, Error **errp)
-- 
1.7.4.4




[Qemu-devel] [PATCH 1/2] Vring: vring's listener's priority should higher than kvm

2013-05-08 Thread Liu Ping Fan
From: Liu Ping Fan 

Hosts threads which handle vring should have high MemoryListener priority
than kvm. For currently code, take the following scenario:
  kvm_region_add() run earlier before vhost_region_add(), then in guest,
vring's desc[i] can refer to addressX in the new region known by guest.
But vhost does not know this new region yet, and the vring handler will
fail.

Signed-off-by: Liu Ping Fan 
---
 hw/virtio/dataplane/hostmem.c |2 +-
 hw/virtio/vhost.c |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/virtio/dataplane/hostmem.c b/hw/virtio/dataplane/hostmem.c
index 37292ff..67cbce1 100644
--- a/hw/virtio/dataplane/hostmem.c
+++ b/hw/virtio/dataplane/hostmem.c
@@ -158,7 +158,7 @@ void hostmem_init(HostMem *hostmem)
 .eventfd_del = hostmem_listener_eventfd_dummy,
 .coalesced_mmio_add = hostmem_listener_coalesced_mmio_dummy,
 .coalesced_mmio_del = hostmem_listener_coalesced_mmio_dummy,
-.priority = 10,
+.priority = 9,
 };
 
 memory_listener_register(&hostmem->listener, &address_space_memory);
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index fbabf99..91c313b 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -856,7 +856,7 @@ int vhost_dev_init(struct vhost_dev *hdev, int devfd, const 
char *devpath,
 .log_global_stop = vhost_log_global_stop,
 .eventfd_add = vhost_eventfd_add,
 .eventfd_del = vhost_eventfd_del,
-.priority = 10
+.priority = 9
 };
 hdev->mem = g_malloc0(offsetof(struct vhost_memory, regions));
 hdev->n_mem_sections = 0;
-- 
1.7.4.4




[Qemu-devel] [PATCH 3/8] pci: Abolish pci_find_root_bus()

2013-05-08 Thread David Gibson
pci_find_root_bus() takes a domain parameter.  Currently PCI root buses
with domain other than 0 can't be created, so this is more or less a long
winded way of retrieving the main PCI root bus.  Numbered domains don't
actually properly cover the (non x86) possibilities for multiple PCI root
buses, so this patch for now enforces the domain == 0 restriction in other
places to replace pci_find_root_bus() with an explicit
pci_get_primary_bus().

Signed-off-by: David Gibson 
---
 hw/pci/pci-hotplug-old.c |   34 +-
 hw/pci/pci.c |   19 +++
 include/hw/pci/pci.h |2 +-
 3 files changed, 41 insertions(+), 14 deletions(-)

diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
index 1aa0ab8..55441c6 100644
--- a/hw/pci/pci-hotplug-old.c
+++ b/hw/pci/pci-hotplug-old.c
@@ -34,17 +34,23 @@
 #include "sysemu/blockdev.h"
 #include "qapi/error.h"
 
-static int pci_read_devaddr(Monitor *mon, const char *addr, int *domp,
+static int pci_read_devaddr(Monitor *mon, const char *addr,
 int *busp, unsigned *slotp)
 {
+int dom;
+
 /* strip legacy tag */
 if (!strncmp(addr, "pci_addr=", 9)) {
 addr += 9;
 }
-if (pci_parse_devaddr(addr, domp, busp, slotp, NULL)) {
+if (pci_parse_devaddr(addr, &dom, busp, slotp, NULL)) {
 monitor_printf(mon, "Invalid pci address\n");
 return -1;
 }
+if (dom != 0) {
+monitor_printf(mon, "Multiple PCI domains not supported, use 
device_add\n");
+return -1;
+}
 return 0;
 }
 
@@ -126,18 +132,22 @@ static int scsi_hot_add(Monitor *mon, DeviceState 
*adapter,
 
 int pci_drive_hot_add(Monitor *mon, const QDict *qdict, DriveInfo *dinfo)
 {
-int dom, pci_bus;
+int pci_bus;
 unsigned slot;
+PCIBus *root = pci_get_primary_bus();
 PCIDevice *dev;
 const char *pci_addr = qdict_get_str(qdict, "pci_addr");
 
 switch (dinfo->type) {
 case IF_SCSI:
-if (pci_read_devaddr(mon, pci_addr, &dom, &pci_bus, &slot)) {
+if (!root) {
+monitor_printf(mon, "no primary PCI bus\n");
+goto err;
+}
+if (pci_read_devaddr(mon, pci_addr, &pci_bus, &slot)) {
 goto err;
 }
-dev = pci_find_device(pci_find_root_bus(dom), pci_bus,
-  PCI_DEVFN(slot, 0));
+dev = pci_find_device(root, pci_bus, PCI_DEVFN(slot, 0));
 if (!dev) {
 monitor_printf(mon, "no pci device with address %s\n", pci_addr);
 goto err;
@@ -273,16 +283,22 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict)
 
 static int pci_device_hot_remove(Monitor *mon, const char *pci_addr)
 {
+PCIBus *root = pci_get_primary_bus();
 PCIDevice *d;
-int dom, bus;
+int bus;
 unsigned slot;
 Error *local_err = NULL;
 
-if (pci_read_devaddr(mon, pci_addr, &dom, &bus, &slot)) {
+if (!root) {
+monitor_printf(mon, "no primary PCI bus\n");
+return -1;
+}
+
+if (pci_read_devaddr(mon, pci_addr, &bus, &slot)) {
 return -1;
 }
 
-d = pci_find_device(pci_find_root_bus(dom), bus, PCI_DEVFN(slot, 0));
+d = pci_find_device(root, bus, PCI_DEVFN(slot, 0));
 if (!d) {
 monitor_printf(mon, "slot %d empty\n", slot);
 return -1;
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 9906e84..9503d56 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -246,12 +246,12 @@ static void pci_host_bus_register(int domain, PCIBus *bus)
 QLIST_INSERT_HEAD(&host_buses, host, next);
 }
 
-PCIBus *pci_find_root_bus(int domain)
+PCIBus *pci_get_primary_bus(void)
 {
 struct PCIHostBus *host;
 
 QLIST_FOREACH(host, &host_buses, next) {
-if (host->domain == domain) {
+if (host->domain == 0) {
 return host->bus;
 }
 }
@@ -583,20 +583,31 @@ int pci_parse_devaddr(const char *addr, int *domp, int 
*busp,
 
 PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr)
 {
+PCIBus *root = pci_get_primary_bus();
 int dom, bus;
 unsigned slot;
 
+if (!root) {
+fprintf(stderr, "No primary PCI bus\n");
+return NULL;
+}
+
 if (!devaddr) {
 *devfnp = -1;
-return pci_find_bus_nr(pci_find_root_bus(0), 0);
+return pci_find_bus_nr(root, 0);
 }
 
 if (pci_parse_devaddr(devaddr, &dom, &bus, &slot, NULL) < 0) {
 return NULL;
 }
 
+if (dom != 0) {
+fprintf(stderr, "No support for non-zero PCI domains\n");
+return NULL;
+}
+
 *devfnp = PCI_DEVFN(slot, 0);
-return pci_find_bus_nr(pci_find_root_bus(dom), bus);
+return pci_find_bus_nr(root, bus);
 }
 
 static void pci_init_cmask(PCIDevice *dev)
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 3ef2ee1..38682e8 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -390,7 +390,7 @@ int pci_bus_num(PCIBus *s);
 void pci_for_each_device(PCIBus *bus, int bus_num

[Qemu-devel] [PATCH 8/8] pci: Fold host_buses list into PCIHostState functionality

2013-05-08 Thread David Gibson
The host_buses list is an odd structure - a list of pointers to PCI root
buses existing in parallel to the normal qdev tree structure.  This patch
removes it, instead putting the link pointers into the PCIHostState
structure, which have a 1:1 relationship to PCIHostBus structures anyway.

Signed-off-by: David Gibson 
---
 hw/pci/pci.c  |   28 +++-
 include/hw/pci/pci_host.h |2 ++
 2 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 716f856..cb18862 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -90,11 +90,7 @@ static void pci_del_option_rom(PCIDevice *pdev);
 static uint16_t pci_default_sub_vendor_id = PCI_SUBVENDOR_ID_REDHAT_QUMRANET;
 static uint16_t pci_default_sub_device_id = PCI_SUBDEVICE_ID_QEMU;
 
-struct PCIHostBus {
-struct PCIBus *bus;
-QLIST_ENTRY(PCIHostBus) next;
-};
-static QLIST_HEAD(, PCIHostBus) host_buses;
+static QLIST_HEAD(, PCIHostState) pci_host_bridges;
 static PCIBus *pci_primary_bus;
 
 static const VMStateDescription vmstate_pcibus = {
@@ -238,18 +234,16 @@ static int pcibus_reset(BusState *qbus)
 return 1;
 }
 
-static void pci_host_bus_register(PCIBus *bus)
+static void pci_host_bus_register(PCIBus *bus, DeviceState *parent)
 {
-struct PCIHostBus *host;
+PCIHostState *host_bridge = PCI_HOST_BRIDGE(parent);
 
 /* If this is the first one, assume it's the primary bus */
 if (!pci_primary_bus) {
 pci_primary_bus = bus;
 }
 
-host = g_malloc0(sizeof(*host));
-host->bus = bus;
-QLIST_INSERT_HEAD(&host_buses, host, next);
+QLIST_INSERT_HEAD(&pci_host_bridges, host_bridge, next);
 }
 
 PCIBus *pci_get_primary_bus(void)
@@ -298,7 +292,7 @@ static void pci_bus_init(PCIBus *bus, DeviceState *parent,
 /* host bridge */
 QLIST_INIT(&bus->child);
 
-pci_host_bus_register(bus);
+pci_host_bus_register(bus, parent);
 
 vmstate_register(NULL, -1, &vmstate_pcibus, bus);
 }
@@ -1531,11 +1525,11 @@ static PciInfo *qmp_query_pci_bus(PCIBus *bus, int 
bus_num)
 PciInfoList *qmp_query_pci(Error **errp)
 {
 PciInfoList *info, *head = NULL, *cur_item = NULL;
-struct PCIHostBus *host;
+PCIHostState *host_bridge;
 
-QLIST_FOREACH(host, &host_buses, next) {
+QLIST_FOREACH(host_bridge, &pci_host_bridges, next) {
 info = g_malloc0(sizeof(*info));
-info->value = qmp_query_pci_bus(host->bus, 0);
+info->value = qmp_query_pci_bus(host_bridge->bus, 0);
 
 /* XXX: waiting for the qapi to support GSList */
 if (!cur_item) {
@@ -2199,11 +2193,11 @@ static int pci_qdev_find_recursive(PCIBus *bus,
 
 int pci_qdev_find_device(const char *id, PCIDevice **pdev)
 {
-struct PCIHostBus *host;
+PCIHostState *host_bridge;
 int rc = -ENODEV;
 
-QLIST_FOREACH(host, &host_buses, next) {
-int tmp = pci_qdev_find_recursive(host->bus, id, pdev);
+QLIST_FOREACH(host_bridge, &pci_host_bridges, next) {
+int tmp = pci_qdev_find_recursive(host_bridge->bus, id, pdev);
 if (!tmp) {
 rc = 0;
 break;
diff --git a/include/hw/pci/pci_host.h b/include/hw/pci/pci_host.h
index 44052f2..ba31595 100644
--- a/include/hw/pci/pci_host.h
+++ b/include/hw/pci/pci_host.h
@@ -46,6 +46,8 @@ struct PCIHostState {
 MemoryRegion mmcfg;
 uint32_t config_reg;
 PCIBus *bus;
+
+QLIST_ENTRY(PCIHostState) next;
 };
 
 typedef struct PCIHostBridgeClass {
-- 
1.7.10.4




[Qemu-devel] [PATCH 7/8] pci: Remove domain from PCIHostBus

2013-05-08 Thread David Gibson
There are now no users of the domain field of PCIHostBus, so remove it
from the structure, and as a parameter from the pci_host_bus_register()
function which sets it.

Signed-off-by: David Gibson 
---
 hw/pci/pci.c |6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index b25a1a1..716f856 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -91,7 +91,6 @@ static uint16_t pci_default_sub_vendor_id = 
PCI_SUBVENDOR_ID_REDHAT_QUMRANET;
 static uint16_t pci_default_sub_device_id = PCI_SUBDEVICE_ID_QEMU;
 
 struct PCIHostBus {
-int domain;
 struct PCIBus *bus;
 QLIST_ENTRY(PCIHostBus) next;
 };
@@ -239,7 +238,7 @@ static int pcibus_reset(BusState *qbus)
 return 1;
 }
 
-static void pci_host_bus_register(int domain, PCIBus *bus)
+static void pci_host_bus_register(PCIBus *bus)
 {
 struct PCIHostBus *host;
 
@@ -249,7 +248,6 @@ static void pci_host_bus_register(int domain, PCIBus *bus)
 }
 
 host = g_malloc0(sizeof(*host));
-host->domain = domain;
 host->bus = bus;
 QLIST_INSERT_HEAD(&host_buses, host, next);
 }
@@ -300,7 +298,7 @@ static void pci_bus_init(PCIBus *bus, DeviceState *parent,
 /* host bridge */
 QLIST_INIT(&bus->child);
 
-pci_host_bus_register(0, bus); /* for now only pci domain 0 is supported */
+pci_host_bus_register(bus);
 
 vmstate_register(NULL, -1, &vmstate_pcibus, bus);
 }
-- 
1.7.10.4




[Qemu-devel] [PATCH 1/8] pci: Cleanup configuration for pci-hotplug.c

2013-05-08 Thread David Gibson
pci-hotplug.c and the CONFIG_PCI_HOTPLUG variable which controls its
compilation are misnamed.  They're not about PCI hotplug in general, but
rather about the pci_add/pci_del interface which are now deprecated in
favour of the more general device_add/device_del interface.  This patch
therefore renames them to pci-hotplug-old.c and CONFIG_PCI_HOTPLUG_OLD.

CONFIG_PCI_HOTPLUG=y was listed twice in {i386,x86_64}-softmmu.make for no
particular reason, so we clean that up too.  In addition it was included in
ppc64-softmmu.mak for which the old hotplug interface was never used and is
unsuitable, so we remove that too.

Most of pci-hotplug.c was additionaly protected by #ifdef TARGET_I386.  The
small piece which wasn't is only called from the pci_add and pci_del hooks
in hmp-commands.hx, which themselves were protected by #ifdef TARGET_I386.
This patch therefore also removes the #ifdef from pci-hotplug-old.c,
and changes the ifdefs in hmp-commands.hx to use CONFIG_PCI_HOTPLUG_OLD.

Signed-off-by: David Gibson 
---
 default-configs/i386-softmmu.mak   |3 +-
 default-configs/ppc64-softmmu.mak  |2 -
 default-configs/x86_64-softmmu.mak |3 +-
 hmp-commands.hx|4 +-
 hw/pci/Makefile.objs   |2 +-
 hw/pci/pci-hotplug-old.c   |  290 +++
 hw/pci/pci-hotplug.c   |  292 
 7 files changed, 295 insertions(+), 301 deletions(-)
 create mode 100644 hw/pci/pci-hotplug-old.c
 delete mode 100644 hw/pci/pci-hotplug.c

diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak
index 03deca2..4a0fc9c 100644
--- a/default-configs/i386-softmmu.mak
+++ b/default-configs/i386-softmmu.mak
@@ -28,11 +28,10 @@ CONFIG_APPLESMC=y
 CONFIG_I8259=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_TPM_TIS=$(CONFIG_TPM)
-CONFIG_PCI_HOTPLUG=y
+CONFIG_PCI_HOTPLUG_OLD=y
 CONFIG_MC146818RTC=y
 CONFIG_PAM=y
 CONFIG_PCI_PIIX=y
-CONFIG_PCI_HOTPLUG=y
 CONFIG_WDT_IB700=y
 CONFIG_PC_SYSFW=y
 CONFIG_XEN_I386=$(CONFIG_XEN)
diff --git a/default-configs/ppc64-softmmu.mak 
b/default-configs/ppc64-softmmu.mak
index 884ea8a..d7140c4 100644
--- a/default-configs/ppc64-softmmu.mak
+++ b/default-configs/ppc64-softmmu.mak
@@ -44,7 +44,5 @@ CONFIG_XILINX_ETHLITE=y
 CONFIG_OPENPIC=y
 CONFIG_PSERIES=$(CONFIG_FDT)
 CONFIG_E500=$(CONFIG_FDT)
-# For pSeries
-CONFIG_PCI_HOTPLUG=y
 # For PReP
 CONFIG_MC146818RTC=y
diff --git a/default-configs/x86_64-softmmu.mak 
b/default-configs/x86_64-softmmu.mak
index 599b630..10bb0c6 100644
--- a/default-configs/x86_64-softmmu.mak
+++ b/default-configs/x86_64-softmmu.mak
@@ -28,11 +28,10 @@ CONFIG_APPLESMC=y
 CONFIG_I8259=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_TPM_TIS=$(CONFIG_TPM)
-CONFIG_PCI_HOTPLUG=y
+CONFIG_PCI_HOTPLUG_OLD=y
 CONFIG_MC146818RTC=y
 CONFIG_PAM=y
 CONFIG_PCI_PIIX=y
-CONFIG_PCI_HOTPLUG=y
 CONFIG_WDT_IB700=y
 CONFIG_PC_SYSFW=y
 CONFIG_XEN_I386=$(CONFIG_XEN)
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 9cea415..1d88320 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1077,7 +1077,7 @@ STEXI
 Add drive to PCI storage controller.
 ETEXI
 
-#if defined(TARGET_I386)
+#if defined(CONFIG_PCI_HOTPLUG_OLD)
 {
 .name   = "pci_add",
 .args_type  = "pci_addr:s,type:s,opts:s?",
@@ -1093,7 +1093,7 @@ STEXI
 Hot-add PCI device.
 ETEXI
 
-#if defined(TARGET_I386)
+#if defined(CONFIG_PCI_HOTPLUG_OLD)
 {
 .name   = "pci_del",
 .args_type  = "pci_addr:s",
diff --git a/hw/pci/Makefile.objs b/hw/pci/Makefile.objs
index a7fb9d0..2ad32b6 100644
--- a/hw/pci/Makefile.objs
+++ b/hw/pci/Makefile.objs
@@ -8,4 +8,4 @@ common-obj-$(CONFIG_PCI) += pcie.o pcie_aer.o pcie_port.o
 common-obj-$(CONFIG_NO_PCI) += pci-stub.o
 common-obj-$(CONFIG_ALL) += pci-stub.o
 
-obj-$(CONFIG_PCI_HOTPLUG) += pci-hotplug.o
+obj-$(CONFIG_PCI_HOTPLUG_OLD) += pci-hotplug-old.o
diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
new file mode 100644
index 000..724a80b
--- /dev/null
+++ b/hw/pci/pci-hotplug-old.c
@@ -0,0 +1,290 @@
+/*
+ * QEMU PCI hotplug support
+ *
+ * Copyright (c) 2004 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LI

[Qemu-devel] [PATCH 5/8] pci: Replace pci_find_domain() with more general pci_root_bus_path()

2013-05-08 Thread David Gibson
pci_find_domain() is used in a number of places where we want an id for a
whole PCI domain (i.e. the subtree under a PCI root bus).  The trouble is
that many platforms may support multiple independent host bridges with no
hardware supplied notion of domain number.

This patch, therefore, replaces calls to pci_find_domain() with calls to
a new pci_root_bus_path() returning a string.  The new call is implemented
in terms of a new callback in the host bridge class, so it can be defined
in some way that's well defined for the platform.  When no callback is
available we fall back on the qbus name.

Most current uses of pci_find_domain() are for error or informational
messages, so the change in identifiers should be harmless.  The exception
is pci_get_dev_path(), whose results form part of migration streams.  To
maintain compatibility with old migration streams, the PIIX PCI host is
altered to always supply "" for this path, which matches the old domain
number (since the code didn't actually support domains other than 0).

For the pseries (spapr) PCI bridge we use a different platform-unique
identifier (pseries machines can routinely have dozens of PCI host
bridges).  Theoretically that breaks migration streams, but given that we
don't yet have migration support for pseries, it doesn't matter.

Any other machines that have working migration support including PCI
devices will need to be updated to maintain migration stream compatibility.

Signed-off-by: David Gibson 
---
 hw/pci-host/piix.c|9 +
 hw/pci/pci-hotplug-old.c  |4 ++--
 hw/pci/pci.c  |   38 --
 hw/pci/pci_host.c |1 +
 hw/pci/pcie_aer.c |8 
 hw/ppc/spapr_pci.c|   10 ++
 include/hw/pci/pci.h  |2 +-
 include/hw/pci/pci_host.h |   10 ++
 8 files changed, 57 insertions(+), 25 deletions(-)

diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index f9e68c3..c36e725 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -629,11 +629,20 @@ static const TypeInfo i440fx_info = {
 .class_init= i440fx_class_init,
 };
 
+static const char *i440fx_pcihost_root_bus_path(PCIHostState *host_bridge,
+PCIBus *rootbus)
+{
+/* For backwards compat with old device paths */
+return "";
+}
+
 static void i440fx_pcihost_class_init(ObjectClass *klass, void *data)
 {
 DeviceClass *dc = DEVICE_CLASS(klass);
 SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_CLASS(klass);
 
+hc->root_bus_path = i440fx_pcihost_root_bus_path;
 k->init = i440fx_pcihost_initfn;
 dc->fw_name = "pci";
 dc->no_user = 1;
diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
index 98b4c18..d26674d 100644
--- a/hw/pci/pci-hotplug-old.c
+++ b/hw/pci/pci-hotplug-old.c
@@ -273,8 +273,8 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict)
 }
 
 if (dev) {
-monitor_printf(mon, "OK domain %d, bus %d, slot %d, function %d\n",
-   pci_find_domain(dev),
+monitor_printf(mon, "OK root bus %s, bus %d, slot %d, function %d\n",
+   pci_root_bus_path(dev),
pci_bus_num(dev->bus), PCI_SLOT(dev->devfn),
PCI_FUNC(dev->devfn));
 } else
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index f1cee73..a3c192c 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -25,6 +25,7 @@
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_bridge.h"
 #include "hw/pci/pci_bus.h"
+#include "hw/pci/pci_host.h"
 #include "monitor/monitor.h"
 #include "net/net.h"
 #include "sysemu/sysemu.h"
@@ -270,19 +271,20 @@ PCIBus *pci_device_root_bus(const PCIDevice *d)
 return bus;
 }
 
-int pci_find_domain(const PCIDevice *dev)
+const char *pci_root_bus_path(PCIDevice *dev)
 {
-const PCIBus *rootbus = pci_device_root_bus(dev);
-struct PCIHostBus *host;
+PCIBus *rootbus = pci_device_root_bus(dev);
+PCIHostState *host_bridge = PCI_HOST_BRIDGE(rootbus->qbus.parent);
+PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_GET_CLASS(host_bridge);
 
-QLIST_FOREACH(host, &host_buses, next) {
-if (host->bus == rootbus) {
-return host->domain;
-}
+assert(!rootbus->parent_dev);
+assert(host_bridge->bus == rootbus);
+
+if (hc->root_bus_path) {
+return (*hc->root_bus_path)(host_bridge, rootbus);
 }
 
-abort();/* should not be reached */
-return -1;
+return rootbus->qbus.name;
 }
 
 static void pci_bus_init(PCIBus *bus, DeviceState *parent,
@@ -2005,10 +2007,10 @@ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
 for (i = offset; i < offset + size; i++) {
 overlapping_cap = pci_find_capability_at_offset(pdev, i);
 if (overlapping_cap) {
-fprintf(stderr, "ERROR: %04x:%02x:%02x.%x "
+fprintf(stderr, "ERROR: %s:%02x:%02x.%x "
  

[Qemu-devel] [PATCH 4/8] pci: Use helper o find device's root bus in pci_find_domain()

2013-05-08 Thread David Gibson
Currently pci_find_domain() performs two functions - it locates the PCI
root bus above the given bus, then looks up that root bus's domain number.
This patch adds a helper function to perform the first task, finding the
root bus for a given PCI device.  This is then used in pci_find_domain().
This changes pci_find_domain()'s signature slightly, taking a PCIDevice
instead of a PCIBus - since all callers passed something of the form
dev->bus, this simplifies things slightly.

Signed-off-by: David Gibson 
---
 hw/pci/pci-hotplug-old.c |2 +-
 hw/pci/pci.c |   20 +---
 hw/pci/pcie_aer.c|3 +--
 include/hw/pci/pci.h |3 ++-
 4 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
index 55441c6..98b4c18 100644
--- a/hw/pci/pci-hotplug-old.c
+++ b/hw/pci/pci-hotplug-old.c
@@ -274,7 +274,7 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict)
 
 if (dev) {
 monitor_printf(mon, "OK domain %d, bus %d, slot %d, function %d\n",
-   pci_find_domain(dev->bus),
+   pci_find_domain(dev),
pci_bus_num(dev->bus), PCI_SLOT(dev->devfn),
PCI_FUNC(dev->devfn));
 } else
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 9503d56..f1cee73 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -259,18 +259,24 @@ PCIBus *pci_get_primary_bus(void)
 return NULL;
 }
 
-int pci_find_domain(const PCIBus *bus)
+PCIBus *pci_device_root_bus(const PCIDevice *d)
 {
-PCIDevice *d;
-struct PCIHostBus *host;
+PCIBus *bus = d->bus;
 
-/* obtain root bus */
 while ((d = bus->parent_dev) != NULL) {
 bus = d->bus;
 }
 
+return bus;
+}
+
+int pci_find_domain(const PCIDevice *dev)
+{
+const PCIBus *rootbus = pci_device_root_bus(dev);
+struct PCIHostBus *host;
+
 QLIST_FOREACH(host, &host_buses, next) {
-if (host->bus == bus) {
+if (host->bus == rootbus) {
 return host->domain;
 }
 }
@@ -2002,7 +2008,7 @@ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
 fprintf(stderr, "ERROR: %04x:%02x:%02x.%x "
 "Attempt to add PCI capability %x at offset "
 "%x overlaps existing capability %x at offset %x\n",
-pci_find_domain(pdev->bus), pci_bus_num(pdev->bus),
+pci_find_domain(pdev), pci_bus_num(pdev->bus),
 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
 cap_id, offset, overlapping_cap, i);
 return -EINVAL;
@@ -2157,7 +2163,7 @@ static char *pcibus_get_dev_path(DeviceState *dev)
 path[path_len] = '\0';
 
 /* First field is the domain. */
-s = snprintf(domain, sizeof domain, "%04x:00", pci_find_domain(d->bus));
+s = snprintf(domain, sizeof domain, "%04x:00", pci_find_domain(d));
 assert(s == domain_len);
 memcpy(path, domain, domain_len);
 
diff --git a/hw/pci/pcie_aer.c b/hw/pci/pcie_aer.c
index 1ce72ce..06f77ac 100644
--- a/hw/pci/pcie_aer.c
+++ b/hw/pci/pcie_aer.c
@@ -1022,8 +1022,7 @@ int do_pcie_aer_inject_error(Monitor *mon,
 *ret_data = qobject_from_jsonf("{'id': %s, "
"'domain': %d, 'bus': %d, 'devfn': %d, "
"'ret': %d}",
-   id,
-   pci_find_domain(dev->bus),
+   id, pci_find_domain(dev),
pci_bus_num(dev->bus), dev->devfn,
ret);
 assert(*ret_data);
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 38682e8..1383cfe 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -391,7 +391,8 @@ void pci_for_each_device(PCIBus *bus, int bus_num,
  void (*fn)(PCIBus *bus, PCIDevice *d, void *opaque),
  void *opaque);
 PCIBus *pci_get_primary_bus(void);
-int pci_find_domain(const PCIBus *bus);
+PCIBus *pci_device_root_bus(const PCIDevice *d);
+int pci_find_domain(const PCIDevice *dev);
 PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn);
 int pci_qdev_find_device(const char *id, PCIDevice **pdev);
 PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr);
-- 
1.7.10.4




Re: [Qemu-devel] Reporting Heisenbugs in qemu

2013-05-08 Thread Rob Landley

On 05/08/2013 04:45:45 AM, Torbjorn Granlund wrote:

Paolo Bonzini  writes:

  I guess that's the register windows.  There's only so much you can  
do to
  optimize them, and heavily recursive workloads (like Perl, or the  
RTL

  half of GCC) pay a hefty price.

Two qemu targets stand out for slowness, sparc (32 and 64) and mips  
(64,

don't know about 32).

x86 (32 and 64), arm, and ppc run with a slowdown of < 30 for my bogus
benchmark of GMP configure+make.

With FreeBSD x86_64 I see a slowdown of just 13.  (My reference system
runs FreeBSD, so running FreeBSD under qemu is only far.)

My claimed slowdown factors are affected by kernel, libraries, and
unfortunately very much by gcc speed, which vary with target.

If the sparc emulation speed is due to register windows, then why does
mips seem just as slow?

If register windows shortage is a problem, it should be easy to  
pretend

to have lots of them, right?


sh4 is pretty slow too. Unfortunately:

  http://landley.net/aboriginal/bin/system-image-sh4.tar.bz2

Only has 64 megs of memory in the emulated board. (Enough to build  
hello world, not enough to build most packages.) I have a vague todo  
item to add a command line thing to qemu to plug a physical memory  
address range into an aribtrary address and then tell linux  
discontigmem "add memory range HERE" on the command line. That way I  
wouldn't have to hack up each board emulation to get more memory...)


Rob


Re: [Qemu-devel] [update][PATCH 00/12] target-i386: remove some macros

2013-05-08 Thread li guang
在 2013-05-08三的 10:48 -0300,Eduardo Habkost写道:
> On Wed, May 08, 2013 at 01:43:22PM +0800, li guang wrote:
> > ping ...
> 
> I guess this didn't get any attention because we were already past soft
> freeze, and the focus was to get important features/fixes in shape
> before hard freeze.
> 

OK, thanks for reminding!

> I don't think I can review it because I never worked on the TCG code.
> But I have one question below:
> 
> 
> > 
> > 在 2013-04-23二的 16:16 +0800,liguang写道:
> > > remove macros EAX, EBX, ECX, EDX, EBP, ESP, ESI, EDI, EIP, DF
> > > as suggested by Richard Henderson 
> > > 
> > > Li Guang (12)
> > >target-i386/helper: remove EAX macro
> > >target-i386/helper: remove EBX macro
> > >target-i386/helper: remove ECX macro
> > >target-i386/helper: remove EDX macro
> > >target-i386/helper: remove EBP macro
> > >target-i386/helper: remove ESP macro
> > >target-i386/helper: remove ESI macro
> > >target-i386/helper: remove EDI macro
> > >target-i386/helper: remove EIP macro
> > >target-i386/helper: remove DF macro
> 
> What about CC_DST, CC_SRC, CC_SRC2, CC_OP?

I am not sure whether these also can be removed,
for they are not so sensitive name.

> 
> > >target-i386/helper: remove redundant env->eip assignment
> > >target-i386: fix over 80 chars warnings
> > > 
> > > cpu-exec.c|   4 ++--
> > > target-i386/cc_helper.c   |   2 +-
> > > target-i386/cpu.h |  24 -
> > > target-i386/excp_helper.c |   2 +-
> > > target-i386/int_helper.c  |  86 
> > > ++--
> > > target-i386/mem_helper.c  |  24 +++---
> > > target-i386/misc_helper.c | 107 +++---
> > > target-i386/seg_helper.c  | 182 +++---
> > > target-i386/smm_helper.c  |  64 +++---
> > > target-i386/svm_helper.c  |  66 
> > > 10 files changed, 280 insertions(+), 281 deletions(-)
> > > 
> > 
> > 
> > 
> 





[Qemu-devel] [PATCH] 9p: Be robust against paths without FS_IOC_GETVERSION

2013-05-08 Thread Gabriel de Perthuis
The current implementation checked for supported filesystems at mount
time, but actual support depends on the path.  Don't error out when
finding unversioned paths.

This fix allows booting a linux kernel with the same / filesystem as the
host; otherwise the boot fails when mounting devtmpfs.

Signed-off-by: Gabriel de Perthuis 
---
 hw/9pfs/cofile.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c
index 2efebf3..194c130 100644
--- a/hw/9pfs/cofile.c
+++ b/hw/9pfs/cofile.c
@@ -36,10 +36,14 @@ int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t 
st_mode,
 err = -errno;
 }
 });
 v9fs_path_unlock(s);
 }
+/* The ioctl may not be supported depending on the path */
+if (err == -ENOTTY) {
+err = 0;
+}
 return err;
 }
 
 int v9fs_co_lstat(V9fsPDU *pdu, V9fsPath *path, struct stat *stbuf)
 {
-- 
1.8.2.1.419.ga0b97c6





[Qemu-devel] [PATCH] 9p: Be robust against paths without FS_IOC_GETVERSION

2013-05-08 Thread Gabriel de Perthuis
The current implementation checked for supported filesystems at mount
time, but actual support depends on the path.  Don't error out when
finding unversioned paths.

This fix allows booting a linux kernel with the same / filesystem as the
host; otherwise the boot fails when mounting devtmpfs.

Signed-off-by: Gabriel de Perthuis 
---
 hw/9pfs/cofile.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c
index 2efebf3..194c130 100644
--- a/hw/9pfs/cofile.c
+++ b/hw/9pfs/cofile.c
@@ -36,10 +36,14 @@ int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t 
st_mode,
 err = -errno;
 }
 });
 v9fs_path_unlock(s);
 }
+/* The ioctl may not be supported depending on the path */
+if (err == -ENOTTY) {
+err = 0;
+}
 return err;
 }
 
 int v9fs_co_lstat(V9fsPDU *pdu, V9fsPath *path, struct stat *stbuf)
 {
-- 
1.8.2.1.419.ga0b97c6



[Qemu-devel] [PATCH 8/8] qapi: add native list coverage for QMP input visitor tests

2013-05-08 Thread Michael Roth
This exercises schema-generated visitors for native list types and does
some sanity checking on validity of deserialized data.

Signed-off-by: Michael Roth 
---
 tests/test-qmp-input-visitor.c |  181 
 1 file changed, 181 insertions(+)

diff --git a/tests/test-qmp-input-visitor.c b/tests/test-qmp-input-visitor.c
index 955a4c0..86a1515 100644
--- a/tests/test-qmp-input-visitor.c
+++ b/tests/test-qmp-input-visitor.c
@@ -61,6 +61,31 @@ Visitor *visitor_input_test_init(TestInputVisitorData *data,
 return v;
 }
 
+/* similar to visitor_input_test_init(), but does not expect a string
+ * literal/format json_string argument and so can be used for
+ * programatically generated strings (and we can't pass in programatically
+ * generated strings via %s format parameters since qobject_from_jsonv()
+ * will wrap those in double-quotes and treat the entire object as a
+ * string)
+ */
+static Visitor *visitor_input_test_init_raw(TestInputVisitorData *data,
+const char *json_string)
+{
+Visitor *v;
+
+data->obj = qobject_from_json(json_string);
+
+g_assert(data->obj != NULL);
+
+data->qiv = qmp_input_visitor_new(data->obj);
+g_assert(data->qiv != NULL);
+
+v = qmp_input_get_visitor(data->qiv);
+g_assert(v != NULL);
+
+return v;
+}
+
 static void test_visitor_in_int(TestInputVisitorData *data,
 const void *unused)
 {
@@ -259,6 +284,154 @@ static void test_visitor_in_union(TestInputVisitorData 
*data,
 qapi_free_UserDefUnion(tmp);
 }
 
+static void test_visitor_in_native_list_int(TestInputVisitorData *data,
+const void *unused)
+{
+UserDefNativeListUnion *cvalue = NULL;
+intList *elem = NULL;
+Error *err = NULL;
+Visitor *v;
+GString *gstr_list = g_string_new("");
+GString *gstr_union = g_string_new("");
+int i;
+
+for (i = 0; i < 32; i++) {
+g_string_append_printf(gstr_list, "%d", i);
+if (i != 31) {
+g_string_append(gstr_list, ", ");
+}
+}
+g_string_append_printf(gstr_union,  "{ 'type': 'integer', 'data': [ %s ] 
}",
+   gstr_list->str);
+v = visitor_input_test_init_raw(data,  gstr_union->str);
+
+visit_type_UserDefNativeListUnion(v, &cvalue, NULL, &err);
+g_assert(err == NULL);
+g_assert(cvalue != NULL);
+g_assert_cmpint(cvalue->kind, ==, USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER);
+
+for (i = 0, elem = cvalue->integer; elem; elem = elem->next, i++) {
+g_assert_cmpint(elem->value, ==, i);
+}
+
+g_string_free(gstr_union, true);
+g_string_free(gstr_list, true);
+qapi_free_UserDefNativeListUnion(cvalue);
+}
+
+static void test_visitor_in_native_list_bool(TestInputVisitorData *data,
+const void *unused)
+{
+UserDefNativeListUnion *cvalue = NULL;
+boolList *elem = NULL;
+Error *err = NULL;
+Visitor *v;
+GString *gstr_list = g_string_new("");
+GString *gstr_union = g_string_new("");
+int i;
+
+for (i = 0; i < 32; i++) {
+g_string_append_printf(gstr_list, "%s",
+   (i % 3 == 0) ? "true" : "false");
+if (i != 31) {
+g_string_append(gstr_list, ", ");
+}
+}
+g_string_append_printf(gstr_union,  "{ 'type': 'boolean', 'data': [ %s ] 
}",
+   gstr_list->str);
+v = visitor_input_test_init_raw(data,  gstr_union->str);
+
+visit_type_UserDefNativeListUnion(v, &cvalue, NULL, &err);
+g_assert(err == NULL);
+g_assert(cvalue != NULL);
+g_assert_cmpint(cvalue->kind, ==, USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN);
+
+for (i = 0, elem = cvalue->boolean; elem; elem = elem->next, i++) {
+g_assert_cmpint(elem->value, ==, (i % 3 == 0) ? 1 : 0);
+}
+
+g_string_free(gstr_union, true);
+g_string_free(gstr_list, true);
+qapi_free_UserDefNativeListUnion(cvalue);
+}
+
+static void test_visitor_in_native_list_string(TestInputVisitorData *data,
+   const void *unused)
+{
+UserDefNativeListUnion *cvalue = NULL;
+strList *elem = NULL;
+Error *err = NULL;
+Visitor *v;
+GString *gstr_list = g_string_new("");
+GString *gstr_union = g_string_new("");
+int i;
+
+for (i = 0; i < 32; i++) {
+g_string_append_printf(gstr_list, "'%d'", i);
+if (i != 31) {
+g_string_append(gstr_list, ", ");
+}
+}
+g_string_append_printf(gstr_union,  "{ 'type': 'string', 'data': [ %s ] }",
+   gstr_list->str);
+v = visitor_input_test_init_raw(data,  gstr_union->str);
+
+visit_type_UserDefNativeListUnion(v, &cvalue, NULL, &err);
+g_assert(err == NULL);
+g_assert(cvalue != NULL);
+g_assert_cmpint(cvalue->kind, ==, USER_DEF_NATIVE_LIST_UNION_KIND_STRING);
+
+for (i = 0, 

[Qemu-devel] [PATCH 6/8] qapi: add native list coverage for visitor serialization tests

2013-05-08 Thread Michael Roth
Signed-off-by: Michael Roth 
---
 tests/test-visitor-serialization.c |  247 +---
 1 file changed, 229 insertions(+), 18 deletions(-)

diff --git a/tests/test-visitor-serialization.c 
b/tests/test-visitor-serialization.c
index 8c8adac..b5e1a4b 100644
--- a/tests/test-visitor-serialization.c
+++ b/tests/test-visitor-serialization.c
@@ -23,6 +23,25 @@
 #include "qapi/qmp-output-visitor.h"
 #include "qapi/string-input-visitor.h"
 #include "qapi/string-output-visitor.h"
+#include "qapi-types.h"
+#include "qapi-visit.h"
+#include "qapi/dealloc-visitor.h"
+
+enum PrimitiveTypeKind {
+PTYPE_STRING = 0,
+PTYPE_BOOLEAN,
+PTYPE_NUMBER,
+PTYPE_INTEGER,
+PTYPE_U8,
+PTYPE_U16,
+PTYPE_U32,
+PTYPE_U64,
+PTYPE_S8,
+PTYPE_S16,
+PTYPE_S32,
+PTYPE_S64,
+PTYPE_EOL,
+};
 
 typedef struct PrimitiveType {
 union {
@@ -40,26 +59,34 @@ typedef struct PrimitiveType {
 int64_t s64;
 intmax_t max;
 } value;
-enum {
-PTYPE_STRING = 0,
-PTYPE_BOOLEAN,
-PTYPE_NUMBER,
-PTYPE_INTEGER,
-PTYPE_U8,
-PTYPE_U16,
-PTYPE_U32,
-PTYPE_U64,
-PTYPE_S8,
-PTYPE_S16,
-PTYPE_S32,
-PTYPE_S64,
-PTYPE_EOL,
-} type;
+enum PrimitiveTypeKind type;
 const char *description;
 } PrimitiveType;
 
+typedef struct PrimitiveList {
+union {
+strList *strings;
+boolList *booleans;
+numberList *numbers;
+intList *integers;
+} value;
+enum PrimitiveTypeKind type;
+const char *description;
+} PrimitiveList;
+
 /* test helpers */
 
+typedef void (*VisitorFunc)(Visitor *v, void **native, Error **errp);
+
+static void dealloc_helper(void *native_in, VisitorFunc visit, Error **errp)
+{
+QapiDeallocVisitor *qdv = qapi_dealloc_visitor_new();
+
+visit(qapi_dealloc_get_visitor(qdv), &native_in, errp);
+
+qapi_dealloc_visitor_cleanup(qdv);
+}
+
 static void visit_primitive_type(Visitor *v, void **native, Error **errp)
 {
 PrimitiveType *pt = *native;
@@ -105,6 +132,27 @@ static void visit_primitive_type(Visitor *v, void 
**native, Error **errp)
 }
 }
 
+static void visit_primitive_list(Visitor *v, void **native, Error **errp)
+{
+PrimitiveList *pl = *native;
+switch (pl->type) {
+case PTYPE_STRING:
+visit_type_strList(v, &pl->value.strings, NULL, errp);
+break;
+case PTYPE_BOOLEAN:
+visit_type_boolList(v, &pl->value.booleans, NULL, errp);
+break;
+case PTYPE_NUMBER:
+visit_type_numberList(v, &pl->value.numbers, NULL, errp);
+break;
+case PTYPE_INTEGER:
+visit_type_intList(v, &pl->value.integers, NULL, errp);
+break;
+default:
+g_assert(false);
+}
+}
+
 typedef struct TestStruct
 {
 int64_t integer;
@@ -206,12 +254,11 @@ static void visit_nested_struct_list(Visitor *v, void 
**native, Error **errp)
 
 /* test cases */
 
-typedef void (*VisitorFunc)(Visitor *v, void **native, Error **errp);
-
 typedef enum VisitorCapabilities {
 VCAP_PRIMITIVES = 1,
 VCAP_STRUCTURES = 2,
 VCAP_LISTS = 4,
+VCAP_PRIMITIVE_LISTS = 8,
 } VisitorCapabilities;
 
 typedef struct SerializeOps {
@@ -279,6 +326,151 @@ static void test_primitives(gconstpointer opaque)
 g_free(pt_copy);
 }
 
+static void test_primitive_lists(gconstpointer opaque)
+{
+TestArgs *args = (TestArgs *) opaque;
+const SerializeOps *ops = args->ops;
+PrimitiveType *pt = args->test_data;
+PrimitiveList pl = { .value = { 0 } };
+PrimitiveList pl_copy = { .value = { 0 } };
+PrimitiveList *pl_copy_ptr = &pl_copy;
+Error *err = NULL;
+void *serialize_data;
+void *cur_head = NULL;
+int i;
+
+pl.type = pl_copy.type = pt->type;
+
+/* build up our list of primitive types */
+for (i = 0; i < 32; i++) {
+switch (pl.type) {
+case PTYPE_STRING: {
+strList *tmp = g_new0(strList, 1);
+tmp->value = g_strdup(pt->value.string);
+if (pl.value.strings == NULL) {
+pl.value.strings = tmp;
+} else {
+tmp->next = pl.value.strings;
+pl.value.strings = tmp;
+}
+break;
+}
+case PTYPE_INTEGER: {
+intList *tmp = g_new0(intList, 1);
+tmp->value = pt->value.integer;
+if (pl.value.integers == NULL) {
+pl.value.integers = tmp;
+} else {
+tmp->next = pl.value.integers;
+pl.value.integers = tmp;
+}
+break;
+}
+case PTYPE_NUMBER: {
+numberList *tmp = g_new0(numberList, 1);
+tmp->value = pt->value.number;
+if (pl.value.numbers == NULL) {
+pl.value.numbers = tmp;
+} else {
+tmp->next = pl.value.numbers;
+pl.value.numbers = tmp;
+

[Qemu-devel] [PATCH 7/8] qapi: add native list coverage for QMP output visitor tests

2013-05-08 Thread Michael Roth
This exercises schema-generated visitors for native list types and does
some sanity checking on validity of serialized data.

Signed-off-by: Michael Roth 
---
 qapi-schema-test.json   |8 ++
 tests/test-qmp-output-visitor.c |  172 +++
 2 files changed, 180 insertions(+)

diff --git a/qapi-schema-test.json b/qapi-schema-test.json
index 9eae350..6e37be8 100644
--- a/qapi-schema-test.json
+++ b/qapi-schema-test.json
@@ -32,6 +32,14 @@
 { 'union': 'UserDefUnion',
   'data': { 'a' : 'UserDefA', 'b' : 'UserDefB' } }
 
+# for testing native lists
+{ 'union': 'UserDefNativeListUnion',
+  'data': { 'integer': ['int'],
+'number': ['number'],
+'boolean': ['bool'],
+'string': ['str'],
+'userdef': ['UserDefOne'] } }
+
 # testing commands
 { 'command': 'user_def_cmd', 'data': {} }
 { 'command': 'user_def_cmd1', 'data': {'ud1a': 'UserDefOne'} }
diff --git a/tests/test-qmp-output-visitor.c b/tests/test-qmp-output-visitor.c
index 71367e6..40c583a 100644
--- a/tests/test-qmp-output-visitor.c
+++ b/tests/test-qmp-output-visitor.c
@@ -431,6 +431,170 @@ static void test_visitor_out_union(TestOutputVisitorData 
*data,
 QDECREF(qdict);
 }
 
+static void init_native_list(UserDefNativeListUnion *cvalue)
+{
+int i;
+switch (cvalue->kind) {
+case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER: {
+intList **list = &cvalue->integer;
+for (i = 0; i < 32; i++) {
+*list = g_new0(intList, 1);
+(*list)->value = i;
+(*list)->next = NULL;
+list = &(*list)->next;
+}
+break;
+}
+case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN: {
+boolList **list = &cvalue->boolean;
+for (i = 0; i < 32; i++) {
+*list = g_new0(boolList, 1);
+(*list)->value = (i % 3 == 0);
+(*list)->next = NULL;
+list = &(*list)->next;
+}
+break;
+}
+case USER_DEF_NATIVE_LIST_UNION_KIND_STRING: {
+strList **list = &cvalue->string;
+for (i = 0; i < 32; i++) {
+*list = g_new0(strList, 1);
+(*list)->value = g_strdup_printf("%d", i);
+(*list)->next = NULL;
+list = &(*list)->next;
+}
+break;
+}
+case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER: {
+numberList **list = &cvalue->number;
+for (i = 0; i < 32; i++) {
+*list = g_new0(numberList, 1);
+(*list)->value = (double)i / 3;
+(*list)->next = NULL;
+list = &(*list)->next;
+}
+break;
+}
+default:
+g_assert(false);
+}
+}
+
+static void check_native_list(QObject *qobj,
+  UserDefNativeListUnionKind kind)
+{
+QDict *qdict;
+QList *qlist;
+int i;
+
+g_assert(qobj);
+g_assert(qobject_type(qobj) == QTYPE_QDICT);
+qdict = qobject_to_qdict(qobj);
+g_assert(qdict);
+g_assert(qdict_haskey(qdict, "data"));
+qlist = qlist_copy(qobject_to_qlist(qdict_get(qdict, "data")));
+
+switch (kind) {
+case USER_DEF_NATIVE_LIST_UNION_KIND_INTEGER:
+for (i = 0; i < 32; i++) {
+QObject *tmp;
+QInt *qvalue;
+tmp = qlist_peek(qlist);
+g_assert(tmp);
+qvalue = qobject_to_qint(tmp);
+g_assert_cmpint(qint_get_int(qvalue), ==, i);
+qobject_decref(qlist_pop(qlist));
+}
+break;
+case USER_DEF_NATIVE_LIST_UNION_KIND_BOOLEAN:
+for (i = 0; i < 32; i++) {
+QObject *tmp;
+QBool *qvalue;
+tmp = qlist_peek(qlist);
+g_assert(tmp);
+qvalue = qobject_to_qbool(tmp);
+g_assert_cmpint(qbool_get_int(qvalue), ==, (i % 3 == 0) ? 1 : 0);
+qobject_decref(qlist_pop(qlist));
+}
+break;
+case USER_DEF_NATIVE_LIST_UNION_KIND_STRING:
+for (i = 0; i < 32; i++) {
+QObject *tmp;
+QString *qvalue;
+gchar str[8];
+tmp = qlist_peek(qlist);
+g_assert(tmp);
+qvalue = qobject_to_qstring(tmp);
+sprintf(str, "%d", i);
+g_assert_cmpstr(qstring_get_str(qvalue), ==, str);
+qobject_decref(qlist_pop(qlist));
+}
+break;
+case USER_DEF_NATIVE_LIST_UNION_KIND_NUMBER:
+#define DOUBLE_STR_MAX 16
+for (i = 0; i < 32; i++) {
+QObject *tmp;
+QFloat *qvalue;
+gchar str_expected[DOUBLE_STR_MAX], str_actual[DOUBLE_STR_MAX];
+tmp = qlist_peek(qlist);
+g_assert(tmp);
+qvalue = qobject_to_qfloat(tmp);
+snprintf(str_expected, DOUBLE_STR_MAX, "%3.4f", (double)i / 3);
+snprintf(str_actual, DOUBLE_STR_MAX, "%3.4f", 
qfloat_get_double(qvalue));
+g_assert_cmpstr(str_actual, ==, str_expected);
+qobject_decref(qlist_pop(qlist));

[Qemu-devel] [PATCH 3/8] qapi: qapi-visit.py, native list support

2013-05-08 Thread Michael Roth
Teach visitor generators about native types so they can generate the
appropriate visitor routines.

Signed-off-by: Michael Roth 
---
 scripts/qapi-visit.py |   34 +-
 1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 4c4de4b..6cac05a 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -202,12 +202,14 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj, 
const char *name, Error **
 
 return ret
 
-def generate_declaration(name, members, genlist=True):
-ret = mcgen('''
+def generate_declaration(name, members, genlist=True, builtin_type=False):
+ret = ""
+if not builtin_type:
+ret += mcgen('''
 
 void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error 
**errp);
 ''',
-name=name)
+name=name)
 
 if genlist:
 ret += mcgen('''
@@ -235,8 +237,9 @@ void visit_type_%(name)s(Visitor *m, %(name)s * obj, const 
char *name, Error **e
 name=name)
 
 try:
-opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:",
-   ["source", "header", "prefix=", 
"output-dir="])
+opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:o:",
+   ["source", "header", "builtins", "prefix=",
+"output-dir="])
 except getopt.GetoptError, err:
 print str(err)
 sys.exit(1)
@@ -248,6 +251,7 @@ h_file = 'qapi-visit.h'
 
 do_c = False
 do_h = False
+do_builtins = False
 
 for o, a in opts:
 if o in ("-p", "--prefix"):
@@ -258,6 +262,8 @@ for o, a in opts:
 do_c = True
 elif o in ("-h", "--header"):
 do_h = True
+elif o in ("-b", "--builtins"):
+do_builtins = True
 
 if not do_c and not do_h:
 do_c = True
@@ -324,11 +330,29 @@ fdecl.write(mcgen('''
 
 #include "qapi/visitor.h"
 #include "%(prefix)sqapi-types.h"
+
 ''',
   prefix=prefix, guard=guardname(h_file)))
 
 exprs = parse_schema(sys.stdin)
 
+# to avoid header dependency hell, we always generate declarations
+# for built-in types in our header files and simply guard them
+fdecl.write(guardstart("QAPI_VISIT_BUILTIN_VISITOR_DECL"))
+for typename in builtin_types:
+fdecl.write(generate_declaration(typename, None, genlist=True,
+ builtin_type=True))
+fdecl.write(guardend("QAPI_VISIT_BUILTIN_VISITOR_DECL"))
+
+# ...this doesn't work for cases where we link in multiple objects that
+# have the functions defined, so we use -b option to provide control
+# over these cases
+if do_builtins:
+fdef.write(guardstart("QAPI_VISIT_BUILTIN_VISITOR_DEF"))
+for typename in builtin_types:
+fdef.write(generate_visit_list(typename, None))
+fdef.write(guardend("QAPI_VISIT_BUILTIN_VISITOR_DEF"))
+
 for expr in exprs:
 if expr.has_key('type'):
 ret = generate_visit_struct(expr['type'], expr['data'])
-- 
1.7.9.5




[Qemu-devel] [PATCH 5/8] qapi: fix leak in unit tests

2013-05-08 Thread Michael Roth
qmp_output_get_qobject() increments the qobject's reference count. Since
we currently pass this straight into qobject_to_json() so we can feed
the data into a QMP input visitor, we never actually free the underlying
qobject when qmp_output_visitor_cleanup() is called. This causes leaks
on all of the QMP serialization tests.

Fix this by holding a pointer to the qobject and decref'ing it before
returning from qmp_deserialize().

Signed-off-by: Michael Roth 
---
 tests/test-visitor-serialization.c |9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tests/test-visitor-serialization.c 
b/tests/test-visitor-serialization.c
index e84926f..8c8adac 100644
--- a/tests/test-visitor-serialization.c
+++ b/tests/test-visitor-serialization.c
@@ -657,11 +657,16 @@ static void qmp_deserialize(void **native_out, void 
*datap,
 VisitorFunc visit, Error **errp)
 {
 QmpSerializeData *d = datap;
-QString *output_json = qobject_to_json(qmp_output_get_qobject(d->qov));
-QObject *obj = qobject_from_json(qstring_get_str(output_json));
+QString *output_json;
+QObject *obj_orig, *obj;
+
+obj_orig = qmp_output_get_qobject(d->qov);
+output_json = qobject_to_json(obj_orig);
+obj = qobject_from_json(qstring_get_str(output_json));
 
 QDECREF(output_json);
 d->qiv = qmp_input_visitor_new(obj);
+qobject_decref(obj_orig);
 qobject_decref(obj);
 visit(qmp_input_get_visitor(d->qiv), native_out, errp);
 }
-- 
1.7.9.5




[Qemu-devel] [PATCH 4/8] qapi: enable generation of native list code

2013-05-08 Thread Michael Roth
Also, fix a dependency issue with libqemuutil: qemu-sockets.c needs
qapi-types.c/qapi-visit.c

Signed-off-by: Michael Roth 
---
 Makefile |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 7dc0204..9695c9d 100644
--- a/Makefile
+++ b/Makefile
@@ -178,7 +178,7 @@ Makefile: $(version-obj-y) $(version-lobj-y)
 # Build libraries
 
 libqemustub.a: $(stub-obj-y)
-libqemuutil.a: $(util-obj-y)
+libqemuutil.a: $(util-obj-y) qapi-types.o qapi-visit.o
 
 ##
 
@@ -215,10 +215,10 @@ $(SRC_PATH)/qga/qapi-schema.json 
$(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
 
 qapi-types.c qapi-types.h :\
 $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-types.py $(qapi-py)
-   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py 
$(gen-out-type) -o "." < $<, "  GEN   $@")
+   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-types.py 
$(gen-out-type) -o "." -b < $<, "  GEN   $@")
 qapi-visit.c qapi-visit.h :\
 $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-visit.py $(qapi-py)
-   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py 
$(gen-out-type) -o "."  < $<, "  GEN   $@")
+   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-visit.py 
$(gen-out-type) -o "." -b < $<, "  GEN   $@")
 qmp-commands.h qmp-marshal.c :\
 $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py $(qapi-py)
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py 
$(gen-out-type) -m -o "." < $<, "  GEN   $@")
-- 
1.7.9.5




[Qemu-devel] [PATCH 2/8] qapi: qapi-visit.py, fix list handling for union types

2013-05-08 Thread Michael Roth
Currently we assume non-list types when generating visitor routines for
union types. This is broken, since values like ['Type'] need to mapped
to 'TypeList'.

We already have a type_name() function to handle this that we use for
generating struct visitors, so use that here as well.

Signed-off-by: Michael Roth 
---
 scripts/qapi-visit.py |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index a276540..4c4de4b 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -174,7 +174,7 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const 
char *name, Error **
 ''',
 abbrev = de_camel_case(name).upper(),
 enum = c_fun(de_camel_case(key),False).upper(),
-c_type=members[key],
+c_type=type_name(members[key]),
 c_name=c_fun(key))
 
 ret += mcgen('''
-- 
1.7.9.5




[Qemu-devel] [PATCH 1/8] qapi: qapi-types.py, native list support

2013-05-08 Thread Michael Roth
Teach type generators about native types so they can generate the
appropriate linked list types.

Signed-off-by: Michael Roth 
---
 scripts/qapi-types.py |   44 +---
 scripts/qapi.py   |   21 +
 2 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 9e19920..1fc5644 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -16,7 +16,18 @@ import os
 import getopt
 import errno
 
-def generate_fwd_struct(name, members):
+def generate_fwd_struct(name, members, builtin_type=False):
+if builtin_type:
+return mcgen('''
+typedef struct %(name)sList
+{
+%(type)s value;
+struct %(name)sList *next;
+} %(name)sList;
+''',
+ type=c_type(name),
+ name=name)
+
 return mcgen('''
 typedef struct %(name)s %(name)s;
 
@@ -28,6 +39,7 @@ typedef struct %(name)sList
 ''',
  name=name)
 
+
 def generate_fwd_enum_struct(name, members):
 return mcgen('''
 typedef struct %(name)sList
@@ -164,6 +176,7 @@ void qapi_free_%(type)s(%(c_type)s obj);
 
 def generate_type_cleanup(name):
 ret = mcgen('''
+
 void qapi_free_%(type)s(%(c_type)s obj)
 {
 QapiDeallocVisitor *md;
@@ -184,8 +197,9 @@ void qapi_free_%(type)s(%(c_type)s obj)
 
 
 try:
-opts, args = getopt.gnu_getopt(sys.argv[1:], "chp:o:",
-   ["source", "header", "prefix=", 
"output-dir="])
+opts, args = getopt.gnu_getopt(sys.argv[1:], "chbp:o:",
+   ["source", "header", "builtins",
+"prefix=", "output-dir="])
 except getopt.GetoptError, err:
 print str(err)
 sys.exit(1)
@@ -197,6 +211,7 @@ h_file = 'qapi-types.h'
 
 do_c = False
 do_h = False
+do_builtins = False
 
 for o, a in opts:
 if o in ("-p", "--prefix"):
@@ -207,6 +222,8 @@ for o, a in opts:
 do_c = True
 elif o in ("-h", "--header"):
 do_h = True
+elif o in ("-b", "--builtins"):
+do_builtins = True
 
 if not do_c and not do_h:
 do_c = True
@@ -282,6 +299,11 @@ fdecl.write(mcgen('''
 exprs = parse_schema(sys.stdin)
 exprs = filter(lambda expr: not expr.has_key('gen'), exprs)
 
+fdecl.write(guardstart("QAPI_TYPES_BUILTIN_STRUCT_DECL"))
+for typename in builtin_types:
+fdecl.write(generate_fwd_struct(typename, None, builtin_type=True))
+fdecl.write(guardend("QAPI_TYPES_BUILTIN_STRUCT_DECL"))
+
 for expr in exprs:
 ret = "\n"
 if expr.has_key('type'):
@@ -298,6 +320,22 @@ for expr in exprs:
 continue
 fdecl.write(ret)
 
+# to avoid header dependency hell, we always generate declarations
+# for built-in types in our header files and simply guard them
+fdecl.write(guardstart("QAPI_TYPES_BUILTIN_CLEANUP_DECL"))
+for typename in builtin_types:
+fdecl.write(generate_type_cleanup_decl(typename + "List"))
+fdecl.write(guardend("QAPI_TYPES_BUILTIN_CLEANUP_DECL"))
+
+# ...this doesn't work for cases where we link in multiple objects that
+# have the functions defined, so we use -b option to provide control
+# over these cases
+if do_builtins:
+fdef.write(guardstart("QAPI_TYPES_BUILTIN_CLEANUP_DEF"))
+for typename in builtin_types:
+fdef.write(generate_type_cleanup(typename + "List"))
+fdef.write(guardend("QAPI_TYPES_BUILTIN_CLEANUP_DEF"))
+
 for expr in exprs:
 ret = "\n"
 if expr.has_key('type'):
diff --git a/scripts/qapi.py b/scripts/qapi.py
index afc5f32..0ac8c2b 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -11,6 +11,10 @@
 
 from ordereddict import OrderedDict
 
+builtin_types = [
+'str', 'int', 'number', 'bool'
+]
+
 def tokenize(data):
 while len(data):
 ch = data[0]
@@ -242,3 +246,20 @@ def guardname(filename):
 for substr in [".", " ", "-"]:
 guard = guard.replace(substr, "_")
 return guard.upper() + '_H'
+
+def guardstart(name):
+return mcgen('''
+
+#ifndef %(name)s
+#define %(name)s
+
+''',
+ name=guardname(name))
+
+def guardend(name):
+return mcgen('''
+
+#endif /* %(name)s */
+
+''',
+ name=guardname(name))
-- 
1.7.9.5




[Qemu-devel] [PATCH 0/8] qapi: add support for lists of native types

2013-05-08 Thread Michael Roth
These patches apply on top of qemu.git master, and can also be obtained from:
git://github.com/mdroth/qemu.git qapi-native-lists

Sending this now since a number of series have popped up in the past that
wanted this, and Amos has some pending patches (query-mac-tables) that rely
on this as well.

These patches add support for specifying lists of native qapi types
(int/bool/str/number) like so:

  { 'type': 'foo',
'data': { 'bar': ['int'] }}

for a 'bar' field that is a list of type 'int',

  { 'type': 'foo2',
'data': { 'bar2': ['str'] }}

for a 'bar2' field that is a list of type 'str', and so on.

This uses linked list types for the native C representations, just as we do
for complex schema-defined types. In the future we may add schema annotations
of some sort to specify a more natural/efficient array type for the C
representations, but this should serve the majority of uses-cases for now.

 Makefile   |6 +-
 qapi-schema-test.json  |8 ++
 scripts/qapi-types.py  |   44 ++-
 scripts/qapi-visit.py  |   36 -
 scripts/qapi.py|   21 +++
 tests/test-qmp-input-visitor.c |  181 +
 tests/test-qmp-output-visitor.c|  172 
 tests/test-visitor-serialization.c |  256 +---
 8 files changed, 692 insertions(+), 32 deletions(-)




Re: [Qemu-devel] [PATCH RFC 0/3] seabios: move acpi table formatting out of bios

2013-05-08 Thread Kevin O'Connor
On Wed, May 08, 2013 at 03:35:46PM +0300, Michael S. Tsirkin wrote:
> On Wed, May 08, 2013 at 02:35:44PM +0300, Gleb Natapov wrote:
> > On Wed, May 08, 2013 at 02:07:24PM +0300, Michael S. Tsirkin wrote:
> > > On Wed, May 08, 2013 at 01:59:12PM +0300, Gleb Natapov wrote:
> > > > Where this notion that fw_cfg is only for a small things is coming
> > > > from? I can assure you this was not the case when the device was
> > > > introduced. In fact it is used today for not so small things like
> > > > bootindex splash screen bitmaps, option rom loading and kernel/initrd
> > > > loading. Some of those are bigger then ACPI tables will ever be.
> > > > And they all should be migrated, so fw_cfg should be fixed anyway.
> > > 
> > > I'm not arguing with that. Convince Anthony please.
> > > 
> > Convince him in what? That fw_cfg is broken vrt migration and there are
> > cases that will fail _today_ without any ACPI related changes? This is
> > knows for ages.
> 
> That we should use fw_cfg to load acpi tables.

I'm confused.

ACPI tables are not large.  At most we're talking about 100K of data
total.

I don't see what migration has to do with using fw_cfg to pass acpi
tables - the content is only read at startup.  There may be an issue
for the corner case of VM restarts, but if so it's nothing new.  If
the content of a fw_cfg entry changes during a guest reboot it is
going to have the same impact regardless of whether it's the
"irq0-override" entry / "numa-nodes" entry - or if it's the "madt"
entry / "srat" entry, etc.  So, I don't see how fw_cfg would suddenly
not be suitable.

Again, I recommend that ACPI (and mptable, smbios, pir) be generated
in qemu and that the content be passed to SeaBIOS using one fw_cfg
"file" per table.

-Kevin



[Qemu-devel] [PATCH v5 3/5] kvm: support using KVM_MEM_READONLY flag for regions

2013-05-08 Thread Jordan Justen
For readonly memory regions and rom devices that are readable,
we make use of the KVM_MEM_READONLY. A slot that uses
KVM_MEM_READONLY can be read from and code can execute from the
region, but writes will exit to qemu.

For rom devices that are not readable, we force the slot to be
removed so reads or writes to the region will exit to qemu.
(Note that a memory region in this state is not executable
within kvm.)

Signed-off-by: Jordan Justen 
Reviewed-by: Xiao Guangrong  (v4)
---
 kvm-all.c |   38 +-
 1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 1686adc..636d2b6 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -201,12 +201,18 @@ static int kvm_set_user_memory_region(KVMState *s, 
KVMSlot *slot)
 
 mem.slot = slot->slot;
 mem.guest_phys_addr = slot->start_addr;
-mem.memory_size = slot->memory_size;
 mem.userspace_addr = (unsigned long)slot->ram;
 mem.flags = slot->flags;
 if (s->migration_log) {
 mem.flags |= KVM_MEM_LOG_DIRTY_PAGES;
 }
+if (mem.flags & KVM_MEM_READONLY) {
+/* Set the slot size to 0 before setting the slot to the desired
+ * value. This is needed based on KVM commit 75d61fbc. */
+mem.memory_size = 0;
+kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
+}
+mem.memory_size = slot->memory_size;
 return kvm_vm_ioctl(s, KVM_SET_USER_MEMORY_REGION, &mem);
 }
 
@@ -268,9 +274,14 @@ err:
  * dirty pages logging control
  */
 
-static int kvm_mem_flags(KVMState *s, bool log_dirty)
+static int kvm_mem_flags(KVMState *s, bool log_dirty, bool readonly)
 {
-return log_dirty ? KVM_MEM_LOG_DIRTY_PAGES : 0;
+int flags = 0;
+flags = log_dirty ? KVM_MEM_LOG_DIRTY_PAGES : 0;
+if (readonly && kvm_readonly_mem_allowed) {
+flags |= KVM_MEM_READONLY;
+}
+return flags;
 }
 
 static int kvm_slot_dirty_pages_log_change(KVMSlot *mem, bool log_dirty)
@@ -281,7 +292,7 @@ static int kvm_slot_dirty_pages_log_change(KVMSlot *mem, 
bool log_dirty)
 
 old_flags = mem->flags;
 
-flags = (mem->flags & ~mask) | kvm_mem_flags(s, log_dirty);
+flags = (mem->flags & ~mask) | kvm_mem_flags(s, log_dirty, false);
 mem->flags = flags;
 
 /* If nothing changed effectively, no need to issue ioctl */
@@ -619,6 +630,9 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, 
bool add)
 int err;
 MemoryRegion *mr = section->mr;
 bool log_dirty = memory_region_is_logging(mr);
+bool readable = mr->readable;
+bool writeable = !mr->readonly && !mr->rom_device;
+bool readonly_flag = mr->readonly || memory_region_is_romd(mr);
 hwaddr start_addr = section->offset_within_address_space;
 ram_addr_t size = section->size;
 void *ram = NULL;
@@ -638,7 +652,13 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, 
bool add)
 }
 
 if (!memory_region_is_ram(mr)) {
-return;
+if (writeable || !kvm_readonly_mem_allowed) {
+return;
+} else if (!readable) {
+/* If the memory range is not readable, then we actually want
+ * to remove the kvm memory slot so all accesses will trap. */
+add = false;
+}
 }
 
 ram = memory_region_get_ram_ptr(mr) + section->offset_within_region + 
delta;
@@ -687,7 +707,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, 
bool add)
 mem->memory_size = old.memory_size;
 mem->start_addr = old.start_addr;
 mem->ram = old.ram;
-mem->flags = kvm_mem_flags(s, log_dirty);
+mem->flags = kvm_mem_flags(s, log_dirty, readonly_flag);
 
 err = kvm_set_user_memory_region(s, mem);
 if (err) {
@@ -708,7 +728,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, 
bool add)
 mem->memory_size = start_addr - old.start_addr;
 mem->start_addr = old.start_addr;
 mem->ram = old.ram;
-mem->flags =  kvm_mem_flags(s, log_dirty);
+mem->flags =  kvm_mem_flags(s, log_dirty, readonly_flag);
 
 err = kvm_set_user_memory_region(s, mem);
 if (err) {
@@ -732,7 +752,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, 
bool add)
 size_delta = mem->start_addr - old.start_addr;
 mem->memory_size = old.memory_size - size_delta;
 mem->ram = old.ram + size_delta;
-mem->flags = kvm_mem_flags(s, log_dirty);
+mem->flags = kvm_mem_flags(s, log_dirty, readonly_flag);
 
 err = kvm_set_user_memory_region(s, mem);
 if (err) {
@@ -754,7 +774,7 @@ static void kvm_set_phys_mem(MemoryRegionSection *section, 
bool add)
 mem->memory_size = size;
 mem->start_addr = start_addr;
 mem->ram = ram;
-mem->flags = kvm_mem_flags(s, log_dirty);
+mem->flags = kvm_mem_flags(s, log_dirty, readonly_flag);
 
 err = kvm_set_user_memory_region(s, mem);

[Qemu-devel] [PATCH v5 1/5] isapc: Fix non-KVM qemu boot (read/write memory for isapc BIOS)

2013-05-08 Thread Jordan Justen
The isapc machine with seabios currently requires the BIOS region
to be read/write memory rather than read-only memory.

KVM currently cannot support the BIOS as a ROM region, but qemu
in non-KVM mode can. Based on this, isapc machine currently only
works with KVM.

To work-around this isapc issue, this change avoids marking the
BIOS as readonly for isapc.

This change also will allow KVM to start supporting ROM mode
via KVM_CAP_READONLY_MEM.

Signed-off-by: Jordan Justen 
---
 hw/block/pc_sysfw.c |   14 ++
 hw/i386/pc_piix.c   |5 +
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/hw/block/pc_sysfw.c b/hw/block/pc_sysfw.c
index aad8614..90894af 100644
--- a/hw/block/pc_sysfw.c
+++ b/hw/block/pc_sysfw.c
@@ -39,6 +39,7 @@
 typedef struct PcSysFwDevice {
 SysBusDevice busdev;
 uint8_t rom_only;
+uint8_t isapc_ram_fw;
 } PcSysFwDevice;
 
 static void pc_isa_bios_init(MemoryRegion *rom_memory,
@@ -139,7 +140,7 @@ static void pc_system_flash_init(MemoryRegion *rom_memory,
 pc_isa_bios_init(rom_memory, flash_mem, size);
 }
 
-static void old_pc_system_rom_init(MemoryRegion *rom_memory)
+static void old_pc_system_rom_init(MemoryRegion *rom_memory, bool isapc_ram_fw)
 {
 char *filename;
 MemoryRegion *bios, *isa_bios;
@@ -163,7 +164,9 @@ static void old_pc_system_rom_init(MemoryRegion *rom_memory)
 bios = g_malloc(sizeof(*bios));
 memory_region_init_ram(bios, "pc.bios", bios_size);
 vmstate_register_ram_global(bios);
-memory_region_set_readonly(bios, true);
+if (!isapc_ram_fw) {
+memory_region_set_readonly(bios, true);
+}
 ret = rom_add_file_fixed(bios_name, (uint32_t)(-bios_size), -1);
 if (ret != 0) {
 bios_error:
@@ -186,7 +189,9 @@ static void old_pc_system_rom_init(MemoryRegion *rom_memory)
 0x10 - isa_bios_size,
 isa_bios,
 1);
-memory_region_set_readonly(isa_bios, true);
+if (!isapc_ram_fw) {
+memory_region_set_readonly(isa_bios, true);
+}
 
 /* map all the bios at the top of memory */
 memory_region_add_subregion(rom_memory,
@@ -216,7 +221,7 @@ void pc_system_firmware_init(MemoryRegion *rom_memory)
 qdev_init_nofail(DEVICE(sysfw_dev));
 
 if (sysfw_dev->rom_only) {
-old_pc_system_rom_init(rom_memory);
+old_pc_system_rom_init(rom_memory, sysfw_dev->isapc_ram_fw);
 return;
 }
 
@@ -255,6 +260,7 @@ void pc_system_firmware_init(MemoryRegion *rom_memory)
 }
 
 static Property pcsysfw_properties[] = {
+DEFINE_PROP_UINT8("isapc_ram_fw", PcSysFwDevice, isapc_ram_fw, 0),
 DEFINE_PROP_UINT8("rom_only", PcSysFwDevice, rom_only, 1),
 DEFINE_PROP_END_OF_LIST(),
 };
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index f7c80ad..c1a49ec 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -716,6 +716,11 @@ static QEMUMachine isapc_machine = {
 .property = "rom_only",
 .value= stringify(1),
 },
+{
+.driver   = "pc-sysfw",
+.property = "isapc_ram_fw",
+.value= stringify(1),
+},
 { /* end of list */ }
 },
 DEFAULT_MACHINE_OPTIONS,
-- 
1.7.10.4




[Qemu-devel] [PATCH v5 2/5] kvm: add kvm_readonly_mem_enabled

2013-05-08 Thread Jordan Justen
Signed-off-by: Jordan Justen 
---
 include/sysemu/kvm.h |   10 ++
 kvm-all.c|6 ++
 kvm-stub.c   |1 +
 3 files changed, 17 insertions(+)

diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 9735c1d..13c4b2e 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -45,6 +45,7 @@ extern bool kvm_async_interrupts_allowed;
 extern bool kvm_irqfds_allowed;
 extern bool kvm_msi_via_irqfd_allowed;
 extern bool kvm_gsi_routing_allowed;
+extern bool kvm_readonly_mem_allowed;
 
 #if defined CONFIG_KVM || !defined NEED_CPU_H
 #define kvm_enabled()   (kvm_allowed)
@@ -97,6 +98,14 @@ extern bool kvm_gsi_routing_allowed;
  */
 #define kvm_gsi_routing_enabled() (kvm_gsi_routing_allowed)
 
+/**
+ * kvm_readonly_mem_enabled:
+ *
+ * Returns: true if KVM readonly memory is enabled (ie the kernel
+ * supports it and we're running in a configuration that permits it).
+ */
+#define kvm_readonly_mem_enabled() (kvm_readonly_mem_allowed)
+
 #else
 #define kvm_enabled()   (0)
 #define kvm_irqchip_in_kernel() (false)
@@ -104,6 +113,7 @@ extern bool kvm_gsi_routing_allowed;
 #define kvm_irqfds_enabled() (false)
 #define kvm_msi_via_irqfd_enabled() (false)
 #define kvm_gsi_routing_allowed() (false)
+#define kvm_readonly_mem_enabled() (false)
 #endif
 
 struct kvm_run;
diff --git a/kvm-all.c b/kvm-all.c
index 3a31602..1686adc 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -111,6 +111,7 @@ bool kvm_irqfds_allowed;
 bool kvm_msi_via_irqfd_allowed;
 bool kvm_gsi_routing_allowed;
 bool kvm_allowed;
+bool kvm_readonly_mem_allowed;
 
 static const KVMCapabilityInfo kvm_required_capabilites[] = {
 KVM_CAP_INFO(USER_MEMORY),
@@ -1425,6 +1426,11 @@ int kvm_init(void)
 s->irq_set_ioctl = KVM_IRQ_LINE_STATUS;
 }
 
+#ifdef KVM_CAP_READONLY_MEM
+kvm_readonly_mem_allowed =
+(kvm_check_extension(s, KVM_CAP_READONLY_MEM) > 0);
+#endif
+
 ret = kvm_arch_init(s);
 if (ret < 0) {
 goto err;
diff --git a/kvm-stub.c b/kvm-stub.c
index b2c8f9b..22eaff0 100644
--- a/kvm-stub.c
+++ b/kvm-stub.c
@@ -26,6 +26,7 @@ bool kvm_irqfds_allowed;
 bool kvm_msi_via_irqfd_allowed;
 bool kvm_gsi_routing_allowed;
 bool kvm_allowed;
+bool kvm_readonly_mem_allowed;
 
 int kvm_init_vcpu(CPUState *cpu)
 {
-- 
1.7.10.4




[Qemu-devel] [PATCH v5 5/5] pc_sysfw: change rom_only default to 0

2013-05-08 Thread Jordan Justen
Now KVM can support a flash memory. This feature depends on
KVM_CAP_READONLY_MEM, which was introduced in Linux 3.7.

Flash memory will only be enabled if a pflash device is
created. (For example, by using the -pflash command line
parameter.)

Signed-off-by: Jordan Justen 
---
 hw/block/pc_sysfw.c  |2 +-
 include/hw/i386/pc.h |4 
 2 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/hw/block/pc_sysfw.c b/hw/block/pc_sysfw.c
index d8a499d..259fe5d 100644
--- a/hw/block/pc_sysfw.c
+++ b/hw/block/pc_sysfw.c
@@ -273,7 +273,7 @@ void pc_system_firmware_init(MemoryRegion *rom_memory)
 
 static Property pcsysfw_properties[] = {
 DEFINE_PROP_UINT8("isapc_ram_fw", PcSysFwDevice, isapc_ram_fw, 0),
-DEFINE_PROP_UINT8("rom_only", PcSysFwDevice, rom_only, 1),
+DEFINE_PROP_UINT8("rom_only", PcSysFwDevice, rom_only, 0),
 DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 417afe4..932de04 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -239,10 +239,6 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t);
 .property = "romfile",\
 .value= "pxe-virtio.rom",\
 },{\
-.driver   = "pc-sysfw",\
-.property = "rom_only",\
-.value= stringify(0),\
-},{\
 .driver   = "486-" TYPE_X86_CPU,\
 .property = "model",\
 .value= stringify(0),\
-- 
1.7.10.4




[Qemu-devel] [PATCH v5 4/5] pc_sysfw: allow flash (-pflash) memory to be used with KVM

2013-05-08 Thread Jordan Justen
When pc-sysfw.rom_only == 0, flash memory will be
usable with kvm. In order to enable flash memory mode,
a pflash device must be created. (For example, by
using the -pflash command line parameter.)

Usage of a flash memory device with kvm requires
KVM_CAP_READONLY_MEM, and kvm will abort if
a flash device is used with an older kvm which does
not support this capability.

If a flash device is not used, then qemu/kvm will
operate in the original rom-mode.

Signed-off-by: Jordan Justen 
---
 hw/block/pc_sysfw.c |   50 +++---
 1 file changed, 31 insertions(+), 19 deletions(-)

diff --git a/hw/block/pc_sysfw.c b/hw/block/pc_sysfw.c
index 90894af..d8a499d 100644
--- a/hw/block/pc_sysfw.c
+++ b/hw/block/pc_sysfw.c
@@ -220,28 +220,40 @@ void pc_system_firmware_init(MemoryRegion *rom_memory)
 
 qdev_init_nofail(DEVICE(sysfw_dev));
 
-if (sysfw_dev->rom_only) {
-old_pc_system_rom_init(rom_memory, sysfw_dev->isapc_ram_fw);
-return;
-}
-
 pflash_drv = drive_get(IF_PFLASH, 0, 0);
 
-/* Currently KVM cannot execute from device memory.
-   Use old rom based firmware initialization for KVM. */
-/*
- * This is a Bad Idea, because it makes enabling/disabling KVM
- * guest-visible.  Do it only in bug-compatibility mode.
- */
-if (pc_sysfw_flash_vs_rom_bug_compatible && kvm_enabled()) {
-if (pflash_drv != NULL) {
-fprintf(stderr, "qemu: pflash cannot be used with kvm enabled\n");
-exit(1);
-} else {
-sysfw_dev->rom_only = 1;
-old_pc_system_rom_init(rom_memory);
-return;
+if (pc_sysfw_flash_vs_rom_bug_compatible) {
+/*
+ * This is a Bad Idea, because it makes enabling/disabling KVM
+ * guest-visible.  Do it only in bug-compatibility mode.
+ */
+if (kvm_enabled()) {
+if (pflash_drv != NULL) {
+fprintf(stderr, "qemu: pflash cannot be used with kvm 
enabled\n");
+exit(1);
+} else {
+/* In old pc_sysfw_flash_vs_rom_bug_compatible mode, we assume
+ * that KVM cannot execute from device memory. In this case, we
+ * use old rom based firmware initialization for KVM. But, 
since
+ * this is different from non-kvm mode, this behavior is
+ * undesirable */
+sysfw_dev->rom_only = 1;
+}
 }
+} else if (pflash_drv == NULL) {
+/* When a pflash drive is not found, use rom-mode */
+sysfw_dev->rom_only = 1;
+} else if (kvm_enabled() && !kvm_readonly_mem_enabled()) {
+/* Older KVM cannot execute from device memory. So, flash memory
+ * cannot be used unless the readonly memory kvm capability is 
present. */
+fprintf(stderr, "qemu: pflash with kvm requires KVM readonly memory 
support\n");
+exit(1);
+}
+
+/* If rom-mode is active, use the old pc system rom initialization. */
+if (sysfw_dev->rom_only) {
+old_pc_system_rom_init(rom_memory, sysfw_dev->isapc_ram_fw);
+return;
 }
 
 /* If a pflash drive is not found, then create one using
-- 
1.7.10.4




[Qemu-devel] [PATCH v5 0/5] KVM flash memory support

2013-05-08 Thread Jordan Justen
git://github.com/jljusten/qemu.git kvm-flash-v5

Utilize KVM_CAP_READONLY_MEM to support PC system flash emulation
with KVM.

v5:
 * Remove patch to pflash_cfi01 which enabled readonly mode
 * Adjust kvm code to use KVM READONLY support for ranges that
   either have the readonly flag set, or for devices with
   readable set.

v4:
 * With a machine type of isapc, don't mark the BIOS as read-only.
   isapc + seabios will not boot if the BIOS is read-only. This
   matches the current behavior of isapc with KVM, which is the
   only mode under which isapc currently works.

v3:
 * Squash patch 2 & 3 based on Xiao's feedback that what I
   was calling a 'workaround' in patch 3 was actually what
   is required by the KVM READONLY memory support.

v2:
 * Remove rom_only from PC_COMPAT_1_4
 * Only enable flash when a pflash drive is created.

Jordan Justen (5):
  isapc: Fix non-KVM qemu boot (read/write memory for isapc BIOS)
  kvm: add kvm_readonly_mem_enabled
  kvm: support using KVM_MEM_READONLY flag for regions
  pc_sysfw: allow flash (-pflash) memory to be used with KVM
  pc_sysfw: change rom_only default to 0

 hw/block/pc_sysfw.c  |   64 --
 hw/i386/pc_piix.c|5 
 include/hw/i386/pc.h |4 
 include/sysemu/kvm.h |   10 
 kvm-all.c|   44 +++---
 kvm-stub.c   |1 +
 6 files changed, 92 insertions(+), 36 deletions(-)

-- 
1.7.10.4




[Qemu-devel] [ANNOUNCE] QEMU 1.5.0-rc1 is now available

2013-05-08 Thread Anthony Liguori
Hi,

On behalf of the QEMU Team, I'd like to announce the availability of the
second release candidate for the QEMU 1.5 release.  This release is meant
for testing purposes and should not be used in a production environment.

http://wiki.qemu.org/download/qemu-1.5.0-rc1.tar.bz2

You can help improve the quality of the QEMU 1.5 release by testing this
release and reporting bugs on Launchpad:

https://bugs.launchpad.net/qemu/

The release plan for the 1.5 release is available at:

http://wiki.qemu.org/Planning/1.5

Please add entries to the ChangeLog for the 1.5 release below:

http://wiki.qemu.org/ChangeLog/Next

This following changes have been made since 1.5.0-rc0:

 - virtio: properly validate address before accessing config (Jason Wang)
 - virtio-pci: fix level interrupts (Michael S. Tsirkin)
 - PPC: Fix rldcl (Alexander Graf)
 - PPC: Depend behavior of cmp instructions only on instruction encoding 
(Alexander Graf)
 - target-mips: fix incorrect behaviour for INSV (Petar Jovanovic)
 - target-mips: add missing check_dspr2 for multiply instructions (Petar 
Jovanovic)
 - qemu-iotests: fix 017 018 for vmdk (Fam Zheng)
 - qemu-iotests: exclude vmdk and qcow from 043 (Fam Zheng)
 - qemu-iotests: exclude vmdk for test 042 (Fam Zheng)
 - qtest/ide-test: Test short and long PRDTs (Kevin Wolf)
 - qtest/ide-test: Add simple DMA read/write test case (Kevin Wolf)
 - qtest: Add IDE test case (Kevin Wolf)
 - libqos/pci: Enable bus mastering (Kevin Wolf)
 - ide: Reset BMIDEA bit when the bus master is stopped (Kevin Wolf)
 - de_DE.po: Add missing leading spaces (Kevin Wolf)
 - ahci: Don't allow creating slave drives (Kevin Wolf)

Regards,

Anthony Liguori




[Qemu-devel] Profiling sparc64 emulation

2013-05-08 Thread Artyom Tarasenko
On Wed, May 8, 2013 at 12:57 AM, Aurelien Jarno  wrote:
> On Tue, May 07, 2013 at 11:29:20PM +0200, Artyom Tarasenko wrote:
>> On Tue, May 7, 2013 at 1:38 PM, Torbjorn Granlund  wrote:
>> > The 2nd table of http://gmplib.org/devel/testsystems.html shows all
>> > emulated systems I am using, most of which are qemu-based.
>>
>> Do I read it correct that qemu-system-ppc64 with the slowdown factor
>> of 33 is ~3 times faster than qemu-system-sparc64 with the slowdown
>> factor of 96 ?
>> Do they both use Debian Wheezy guest? You have a remark that ppc64 has
>> problems with its clock. Was it taken into account when the slowdown
>> factors were calculated?
>>
>
> Clock or not, it should be noted that qemu-system-sparc64 is undoubtedly
> slower (at least 5 to 10 times) than qemu-system-{arm,ppc,mips,...} on
> some type of load like perl scripts.

That's interesting. Actually it should be possible to lauch perl under user
mode qemu-sparc32plus. Is it possible to launch perl under user mode
qemu-ppc{32,64} too?

That would allow to understand whether the bad performance has to do
with TCG or the rest of the system emulation.

Artyom

--
Regards,
Artyom Tarasenko

linux/sparc and solaris/sparc under qemu blog:
http://tyom.blogspot.com/search/label/qemu



Re: [Qemu-devel] [PATCH for 1.5] tcg/optimize: fix setcond2 optimization

2013-05-08 Thread Aurelien Jarno
On Wed, May 08, 2013 at 10:42:42PM +0200, Aurelien Jarno wrote:
> When setcond2 is rewritten into setcond, the state of the destination
> temp should be reset, so that a copy of the previous value is not
> used instead of the result.
> 
> Reported-by: Michael Tokarev 
> Cc: Richard Henderson 
> Signed-off-by: Aurelien Jarno 
> ---
>  tcg/optimize.c |1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tcg/optimize.c b/tcg/optimize.c
> index 1b6644c..b35868a 100644
> --- a/tcg/optimize.c
> +++ b/tcg/optimize.c
> @@ -1057,6 +1057,7 @@ static TCGArg *tcg_constant_folding(TCGContext *s, 
> uint16_t *tcg_opc_ptr,
>  /* Simplify LT/GE comparisons vs zero to a single compare
> vs the high word of the input.  */
>  s->gen_opc_buf[op_index] = INDEX_op_setcond_i32;
> +reset_temp(args[0]);
>  gen_args[0] = args[0];
>  gen_args[1] = args[2];
>  gen_args[2] = args[4];

I have just noticed that the problem is there since release 1.3, even if
it appeared more clearly only with commit 7eb0cc85. All 64-bit targets
on 32-bit hosts are possibly affected.

Therefore it should be fixed in the next stable releases. Hence the Cc
to qemu-sta...@nongnu.org.

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



[Qemu-devel] [PATCH for 1.5] tcg/optimize: fix setcond2 optimization

2013-05-08 Thread Aurelien Jarno
When setcond2 is rewritten into setcond, the state of the destination
temp should be reset, so that a copy of the previous value is not
used instead of the result.

Reported-by: Michael Tokarev 
Cc: Richard Henderson 
Signed-off-by: Aurelien Jarno 
---
 tcg/optimize.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/tcg/optimize.c b/tcg/optimize.c
index 1b6644c..b35868a 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -1057,6 +1057,7 @@ static TCGArg *tcg_constant_folding(TCGContext *s, 
uint16_t *tcg_opc_ptr,
 /* Simplify LT/GE comparisons vs zero to a single compare
vs the high word of the input.  */
 s->gen_opc_buf[op_index] = INDEX_op_setcond_i32;
+reset_temp(args[0]);
 gen_args[0] = args[0];
 gen_args[1] = args[2];
 gen_args[2] = args[4];
-- 
1.7.10.4




Re: [Qemu-devel] [PULL 1.5 0/2] ppc patch queue 2013-05-08

2013-05-08 Thread Aurelien Jarno
On Wed, May 08, 2013 at 08:24:46PM +0200, Alexander Graf wrote:
> Hi Blue / Aurelien,
> 
> This is my current patch queue for ppc with fixes that need to go into 1.5.
> 
> Please pull.
> 
> Alex
> 
> 
> The following changes since commit c0f5f9ce86ddca0a7d7ca60012059a5a18aa9c07:
>   Petar Jovanovic (1):
> target-mips: fix incorrect behaviour for INSV
> 
> are available in the git repository at:
> 
>   git://github.com/agraf/qemu.git ppc-for-upstream
> 
> Alexander Graf (2):
>   PPC: Fix rldcl
>   PPC: Depend behavior of cmp instructions only on instruction encoding
> 
>  target-ppc/translate.c |   34 --
>  1 files changed, 16 insertions(+), 18 deletions(-)
> 

Thanks, pulled.

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH v2] po/hu.po: Hungarian translation for the GTK+ interface

2013-05-08 Thread Anthony Liguori
Paolo Bonzini  writes:

> Il 07/05/2013 10:26, Laszlo Ersek ha scritto:
>> I suspected that something like this was in the background, but what I
>> didn't understand was: why single out the public domain, as the GPL
>> itself is in the exact same bucket, generally speaking.
>
> I think because public domain is a concept that _does_ exist in these
> countries, but it is just the set of works that satisfy certain
> conditions (e.g. 70 years passed from the author's death) rather than
> something you can put your work in.
>
> At some point you have to make some assumptions, and "the GPL works" is
> one of them.

BTW, xgettext is stupid and very difficult to make not put this in
here.  I still need to find some time to work that out.  There's an
option that lets you say, "copyrighted by so-and-so" but that's not what
we need.

Regards,

Anthony Liguori

>
> Paolo



[Qemu-devel] [Bug 1174654] Re: qemu-system-x86_64 takes 100% CPU after host machine resumed from suspend to ram

2013-05-08 Thread John Basila
I don't know if this will help, but I had a similar problem.

When creating a snapshot image of an XP machine, all works just fine
when loading it. As time passes on the host the loadvm start to become
very slow.

To reproduce:
1. Create a snapshot image (savevm)
2. leave QEMU
3. move the *HOST* clock one month in the future
4. Start QEMU with -loadvm

It turns out that the "-rtc clock=vm" made this disappear. When using
the default caused the problem.

John

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1174654

Title:
  qemu-system-x86_64 takes 100% CPU after host machine resumed from
  suspend to ram

Status in QEMU:
  Confirmed
Status in “qemu” package in Ubuntu:
  Invalid

Bug description:
  I have Windows XP SP3  inside qemu VM. All works fine in 12.10. But
  after upgraiding to 13.04 i have to restart the VM each time i
  resuming my host machine, because qemu process starts to take CPU
  cycles and OS inside VM is very slow and sluggish. However it's still
  controllable and could be shutdown by itself.

  According to the taskmgr any active process takes 99% CPU. It's not
  stucked on some single process.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1174654/+subscriptions



[Qemu-devel] [Bug 1100843] Missing required logs.

2013-05-08 Thread Brad Figg
This bug is missing log files that will aid in diagnosing the problem.
>From a terminal window please run:

apport-collect 1100843

and then change the status of the bug to 'Confirmed'.

If, due to the nature of the issue you have encountered, you are unable
to run this command, please add a comment stating that fact and change
the bug status to 'Confirmed'.

This change has been made by an automated script, maintained by the
Ubuntu Kernel Team.

** Changed in: linux (Ubuntu)
   Status: New => Incomplete

** Tags added: precise

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1100843

Title:
  Live Migration Causes Performance Issues

Status in QEMU:
  New
Status in “linux” package in Ubuntu:
  Incomplete
Status in “qemu-kvm” package in Ubuntu:
  Triaged

Bug description:
  I have 2 physical hosts running Ubuntu Precise.  With 1.0+noroms-
  0ubuntu14.7 and qemu-kvm 1.2.0+noroms-0ubuntu7 (source from quantal,
  built for Precise with pbuilder.) I attempted to build qemu-1.3.0 debs
  from source to test, but libvirt seems to have an issue with it that I
  haven't been able to track down yet.

   I'm seeing a performance degradation after live migration on Precise,
  but not Lucid.  These hosts are managed by libvirt (tested both
  0.9.8-2ubuntu17 and 1.0.0-0ubuntu4) in conjunction with OpenNebula.  I
  don't seem to have this problem with lucid guests (running a number of
  standard kernels, 3.2.5 mainline and backported linux-
  image-3.2.0-35-generic as well.)

  I first noticed this problem with phoronix doing compilation tests,
  and then tried lmbench where even simple calls experience performance
  degradation.

  I've attempted to post to the kvm mailing list, but so far the only
  suggestion was it may be related to transparent hugepages not being
  used after migration, but this didn't pan out.  Someone else has a
  similar problem here -
  http://thread.gmane.org/gmane.comp.emulators.kvm.devel/100592

  qemu command line example: /usr/bin/kvm -name one-2 -S -M pc-1.2 -cpu
  Westmere -enable-kvm -m 73728 -smp 16,sockets=2,cores=8,threads=1
  -uuid f89e31a4-4945-c12c-6544-149ba0746c2f -no-user-config -nodefaults
  -chardev
  socket,id=charmonitor,path=/var/lib/libvirt/qemu/one-2.monitor,server,nowait
  -mon chardev=charmonitor,id=monitor,mode=control -rtc
  base=utc,driftfix=slew -no-kvm-pit-reinjection -no-shutdown -device
  piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive
  file=/var/lib/one//datastores/0/2/disk.0,if=none,id=drive-virtio-
  disk0,format=raw,cache=none -device virtio-blk-
  pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-
  disk0,bootindex=1 -drive
  file=/var/lib/one//datastores/0/2/disk.1,if=none,id=drive-
  ide0-0-0,readonly=on,format=raw -device ide-cd,bus=ide.0,unit=0,drive
  =drive-ide0-0-0,id=ide0-0-0 -netdev
  tap,fd=23,id=hostnet0,vhost=on,vhostfd=25 -device virtio-net-
  pci,netdev=hostnet0,id=net0,mac=02:00:0a:64:02:fe,bus=pci.0,addr=0x3
  -vnc 0.0.0.0:2,password -vga cirrus -incoming tcp:0.0.0.0:49155
  -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5

  Disk backend is LVM running on SAN via FC connection (using symlink
  from /var/lib/one/datastores/0/2/disk.0 above)

  
  ubuntu-12.04 - first boot
  ==
  Simple syscall: 0.0527 microseconds
  Simple read: 0.1143 microseconds
  Simple write: 0.0953 microseconds
  Simple open/close: 1.0432 microseconds

  Using phoronix pts/compuational
  ImageMagick - 31.54s
  Linux Kernel 3.1 - 43.91s
  Mplayer - 30.49s
  PHP - 22.25s

  
  ubuntu-12.04 - post live migration
  ==
  Simple syscall: 0.0621 microseconds
  Simple read: 0.2485 microseconds
  Simple write: 0.2252 microseconds
  Simple open/close: 1.4626 microseconds

  Using phoronix pts/compilation
  ImageMagick - 43.29s
  Linux Kernel 3.1 - 76.67s
  Mplayer - 45.41s
  PHP - 29.1s

  
  I don't have phoronix results for 10.04 handy, but they were within 1% of 
each other...

  ubuntu-10.04 - first boot
  ==
  Simple syscall: 0.0524 microseconds
  Simple read: 0.1135 microseconds
  Simple write: 0.0972 microseconds
  Simple open/close: 1.1261 microseconds

  
  ubuntu-10.04 - post live migration
  ==
  Simple syscall: 0.0526 microseconds
  Simple read: 0.1075 microseconds
  Simple write: 0.0951 microseconds
  Simple open/close: 1.0413 microseconds

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1100843/+subscriptions



Re: [Qemu-devel] [PATCH v2] PPC: Depend behavior of cmp instructions only on instruction encoding

2013-05-08 Thread Aurelien Jarno
On Wed, May 08, 2013 at 08:21:56PM +0200, Alexander Graf wrote:
> When running an L=1 cmp instruction on a 64bit PPC CPU with SF off, it
> still behaves identical to what it does when SF is on. Remove the implicit
> difference in the code.
> 
> Also, on most 32bit CPUs we should always treat the compare as 32bit
> compare, as the CPU will ignore the L bit. This is not true for e500mc,
> but that's up for a different patch.
> 
> Reported-by: Torbjorn Granlund 
> Reviewed-by: Richard Henderson 
> Signed-off-by: Alexander Graf 
> 
> ---
> 
> v1 -> v2:
> 
>   - ignore L bit
> ---
>  target-ppc/translate.c |   32 
>  1 files changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/target-ppc/translate.c b/target-ppc/translate.c
> index a018616..4590c6f 100644
> --- a/target-ppc/translate.c
> +++ b/target-ppc/translate.c
> @@ -675,48 +675,48 @@ static inline void gen_set_Rc0(DisasContext *ctx, TCGv 
> reg)
>  /* cmp */
>  static void gen_cmp(DisasContext *ctx)
>  {
> -if (NARROW_MODE(ctx) || !(ctx->opcode & 0x0020)) {
> -gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
> - 1, crfD(ctx->opcode));
> -} else {
> +if ((ctx->opcode & 0x0020) && (ctx->insns_flags & PPC_64B)) {
>  gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
> 1, crfD(ctx->opcode));
> +} else {
> +gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
> + 1, crfD(ctx->opcode));
>  }
>  }
>  
>  /* cmpi */
>  static void gen_cmpi(DisasContext *ctx)
>  {
> -if (NARROW_MODE(ctx) || !(ctx->opcode & 0x0020)) {
> -gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
> -  1, crfD(ctx->opcode));
> -} else {
> +if ((ctx->opcode & 0x0020) && (ctx->insns_flags & PPC_64B)) {
>  gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
>  1, crfD(ctx->opcode));
> +} else {
> +gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
> +  1, crfD(ctx->opcode));
>  }
>  }
>  
>  /* cmpl */
>  static void gen_cmpl(DisasContext *ctx)
>  {
> -if (NARROW_MODE(ctx) || !(ctx->opcode & 0x0020)) {
> -gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
> - 0, crfD(ctx->opcode));
> -} else {
> +if ((ctx->opcode & 0x0020) && (ctx->insns_flags & PPC_64B)) {
>  gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
> 0, crfD(ctx->opcode));
> +} else {
> +gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
> + 0, crfD(ctx->opcode));
>  }
>  }
>  
>  /* cmpli */
>  static void gen_cmpli(DisasContext *ctx)
>  {
> -if (NARROW_MODE(ctx) || !(ctx->opcode & 0x0020)) {
> -gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
> -  0, crfD(ctx->opcode));
> -} else {
> +if ((ctx->opcode & 0x0020) && (ctx->insns_flags & PPC_64B)) {
>  gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
>  0, crfD(ctx->opcode));
> +} else {
> +gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
> +  0, crfD(ctx->opcode));
>  }
>  }
>  

Reviewed-by: Aurelien Jarno 


-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



[Qemu-devel] [Bug 1100843] Re: Live Migration Causes Performance Issues

2013-05-08 Thread Serge Hallyn
** Also affects: linux (Ubuntu)
   Importance: Undecided
   Status: New

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1100843

Title:
  Live Migration Causes Performance Issues

Status in QEMU:
  New
Status in “linux” package in Ubuntu:
  New
Status in “qemu-kvm” package in Ubuntu:
  Triaged

Bug description:
  I have 2 physical hosts running Ubuntu Precise.  With 1.0+noroms-
  0ubuntu14.7 and qemu-kvm 1.2.0+noroms-0ubuntu7 (source from quantal,
  built for Precise with pbuilder.) I attempted to build qemu-1.3.0 debs
  from source to test, but libvirt seems to have an issue with it that I
  haven't been able to track down yet.

   I'm seeing a performance degradation after live migration on Precise,
  but not Lucid.  These hosts are managed by libvirt (tested both
  0.9.8-2ubuntu17 and 1.0.0-0ubuntu4) in conjunction with OpenNebula.  I
  don't seem to have this problem with lucid guests (running a number of
  standard kernels, 3.2.5 mainline and backported linux-
  image-3.2.0-35-generic as well.)

  I first noticed this problem with phoronix doing compilation tests,
  and then tried lmbench where even simple calls experience performance
  degradation.

  I've attempted to post to the kvm mailing list, but so far the only
  suggestion was it may be related to transparent hugepages not being
  used after migration, but this didn't pan out.  Someone else has a
  similar problem here -
  http://thread.gmane.org/gmane.comp.emulators.kvm.devel/100592

  qemu command line example: /usr/bin/kvm -name one-2 -S -M pc-1.2 -cpu
  Westmere -enable-kvm -m 73728 -smp 16,sockets=2,cores=8,threads=1
  -uuid f89e31a4-4945-c12c-6544-149ba0746c2f -no-user-config -nodefaults
  -chardev
  socket,id=charmonitor,path=/var/lib/libvirt/qemu/one-2.monitor,server,nowait
  -mon chardev=charmonitor,id=monitor,mode=control -rtc
  base=utc,driftfix=slew -no-kvm-pit-reinjection -no-shutdown -device
  piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive
  file=/var/lib/one//datastores/0/2/disk.0,if=none,id=drive-virtio-
  disk0,format=raw,cache=none -device virtio-blk-
  pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-
  disk0,bootindex=1 -drive
  file=/var/lib/one//datastores/0/2/disk.1,if=none,id=drive-
  ide0-0-0,readonly=on,format=raw -device ide-cd,bus=ide.0,unit=0,drive
  =drive-ide0-0-0,id=ide0-0-0 -netdev
  tap,fd=23,id=hostnet0,vhost=on,vhostfd=25 -device virtio-net-
  pci,netdev=hostnet0,id=net0,mac=02:00:0a:64:02:fe,bus=pci.0,addr=0x3
  -vnc 0.0.0.0:2,password -vga cirrus -incoming tcp:0.0.0.0:49155
  -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5

  Disk backend is LVM running on SAN via FC connection (using symlink
  from /var/lib/one/datastores/0/2/disk.0 above)

  
  ubuntu-12.04 - first boot
  ==
  Simple syscall: 0.0527 microseconds
  Simple read: 0.1143 microseconds
  Simple write: 0.0953 microseconds
  Simple open/close: 1.0432 microseconds

  Using phoronix pts/compuational
  ImageMagick - 31.54s
  Linux Kernel 3.1 - 43.91s
  Mplayer - 30.49s
  PHP - 22.25s

  
  ubuntu-12.04 - post live migration
  ==
  Simple syscall: 0.0621 microseconds
  Simple read: 0.2485 microseconds
  Simple write: 0.2252 microseconds
  Simple open/close: 1.4626 microseconds

  Using phoronix pts/compilation
  ImageMagick - 43.29s
  Linux Kernel 3.1 - 76.67s
  Mplayer - 45.41s
  PHP - 29.1s

  
  I don't have phoronix results for 10.04 handy, but they were within 1% of 
each other...

  ubuntu-10.04 - first boot
  ==
  Simple syscall: 0.0524 microseconds
  Simple read: 0.1135 microseconds
  Simple write: 0.0972 microseconds
  Simple open/close: 1.1261 microseconds

  
  ubuntu-10.04 - post live migration
  ==
  Simple syscall: 0.0526 microseconds
  Simple read: 0.1075 microseconds
  Simple write: 0.0951 microseconds
  Simple open/close: 1.0413 microseconds

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1100843/+subscriptions



Re: [Qemu-devel] [PATCHv3 for-1.5] virtio-pci: fix level interrupts

2013-05-08 Thread Michael S. Tsirkin
On Tue, May 07, 2013 at 03:49:58PM +0300, Michael S. Tsirkin wrote:
> mask notifiers are never called without msix,
> so devices with backend masking like vhost don't work.
> Call mask notifiers explicitly at
> startup/cleanup to make it work.
> 
> Signed-off-by: Michael S. Tsirkin 
> Tested-by: Alexander Graf 
> ---
> 
> changes from v2:
> fix bug spotted by Konrad
> changes from v1:
> rebased to master
> 
> I'm guessing this missed 1.5. Added for-1.5 just in
> case - probably should go into 1.5.1.

Not sure I made this clear.
If we can put it in 1.5 great, if not it must go into
stable branch.

>  hw/virtio/virtio-pci.c | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
> index d8708c1..195ee04 100644
> --- a/hw/virtio/virtio-pci.c
> +++ b/hw/virtio/virtio-pci.c
> @@ -744,6 +744,7 @@ static int virtio_pci_set_guest_notifier(DeviceState *d, 
> int n, bool assign,
>   bool with_irqfd)
>  {
>  VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
> +VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(proxy->vdev);
>  VirtQueue *vq = virtio_get_queue(proxy->vdev, n);
>  EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
>  
> @@ -758,6 +759,10 @@ static int virtio_pci_set_guest_notifier(DeviceState *d, 
> int n, bool assign,
>  event_notifier_cleanup(notifier);
>  }
>  
> +if (!msix_enabled(&proxy->pci_dev) && vdc->guest_notifier_mask) {
> +vdc->guest_notifier_mask(proxy->vdev, n, !assign);
> +}
> +
>  return 0;
>  }
>  
> -- 
> MST



[Qemu-devel] [PATCH 2/2] PPC: Depend behavior of cmp instructions only on instruction encoding

2013-05-08 Thread Alexander Graf
When running an L=1 cmp instruction on a 64bit PPC CPU with SF off, it
still behaves identical to what it does when SF is on. Remove the implicit
difference in the code.

Also, on most 32bit CPUs we should always treat the compare as 32bit
compare, as the CPU will ignore the L bit. This is not true for e500mc,
but that's up for a different patch.

Reported-by: Torbjorn Granlund 
Reviewed-by: Richard Henderson 
Signed-off-by: Alexander Graf 
---
 target-ppc/translate.c |   32 
 1 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/target-ppc/translate.c b/target-ppc/translate.c
index a018616..4590c6f 100644
--- a/target-ppc/translate.c
+++ b/target-ppc/translate.c
@@ -675,48 +675,48 @@ static inline void gen_set_Rc0(DisasContext *ctx, TCGv 
reg)
 /* cmp */
 static void gen_cmp(DisasContext *ctx)
 {
-if (NARROW_MODE(ctx) || !(ctx->opcode & 0x0020)) {
-gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
- 1, crfD(ctx->opcode));
-} else {
+if ((ctx->opcode & 0x0020) && (ctx->insns_flags & PPC_64B)) {
 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
1, crfD(ctx->opcode));
+} else {
+gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
+ 1, crfD(ctx->opcode));
 }
 }
 
 /* cmpi */
 static void gen_cmpi(DisasContext *ctx)
 {
-if (NARROW_MODE(ctx) || !(ctx->opcode & 0x0020)) {
-gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
-  1, crfD(ctx->opcode));
-} else {
+if ((ctx->opcode & 0x0020) && (ctx->insns_flags & PPC_64B)) {
 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
 1, crfD(ctx->opcode));
+} else {
+gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
+  1, crfD(ctx->opcode));
 }
 }
 
 /* cmpl */
 static void gen_cmpl(DisasContext *ctx)
 {
-if (NARROW_MODE(ctx) || !(ctx->opcode & 0x0020)) {
-gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
- 0, crfD(ctx->opcode));
-} else {
+if ((ctx->opcode & 0x0020) && (ctx->insns_flags & PPC_64B)) {
 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
0, crfD(ctx->opcode));
+} else {
+gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
+ 0, crfD(ctx->opcode));
 }
 }
 
 /* cmpli */
 static void gen_cmpli(DisasContext *ctx)
 {
-if (NARROW_MODE(ctx) || !(ctx->opcode & 0x0020)) {
-gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
-  0, crfD(ctx->opcode));
-} else {
+if ((ctx->opcode & 0x0020) && (ctx->insns_flags & PPC_64B)) {
 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
 0, crfD(ctx->opcode));
+} else {
+gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
+  0, crfD(ctx->opcode));
 }
 }
 
-- 
1.6.0.2




[Qemu-devel] [PATCH 1/2] PPC: Fix rldcl

2013-05-08 Thread Alexander Graf
The implementation for rldcl tried to always fetch its
parameters from the opcode, even though the opcode was
already passed in in decoded and different forms.

Use the parameters instead, fixing rldcl.

Reported-by: Torbjorn Granlund 
Reviewed-by: Aurelien Jarno 
Signed-off-by: Alexander Graf 
---
 target-ppc/translate.c |2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/target-ppc/translate.c b/target-ppc/translate.c
index 0886f4d..a018616 100644
--- a/target-ppc/translate.c
+++ b/target-ppc/translate.c
@@ -1733,8 +1733,6 @@ static inline void gen_rldnm(DisasContext *ctx, uint32_t 
mb, uint32_t me)
 {
 TCGv t0;
 
-mb = MB(ctx->opcode);
-me = ME(ctx->opcode);
 t0 = tcg_temp_new();
 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
-- 
1.6.0.2




[Qemu-devel] [PULL 1.5 0/2] ppc patch queue 2013-05-08

2013-05-08 Thread Alexander Graf
Hi Blue / Aurelien,

This is my current patch queue for ppc with fixes that need to go into 1.5.

Please pull.

Alex


The following changes since commit c0f5f9ce86ddca0a7d7ca60012059a5a18aa9c07:
  Petar Jovanovic (1):
target-mips: fix incorrect behaviour for INSV

are available in the git repository at:

  git://github.com/agraf/qemu.git ppc-for-upstream

Alexander Graf (2):
  PPC: Fix rldcl
  PPC: Depend behavior of cmp instructions only on instruction encoding

 target-ppc/translate.c |   34 --
 1 files changed, 16 insertions(+), 18 deletions(-)



[Qemu-devel] [PATCH v2] PPC: Depend behavior of cmp instructions only on instruction encoding

2013-05-08 Thread Alexander Graf
When running an L=1 cmp instruction on a 64bit PPC CPU with SF off, it
still behaves identical to what it does when SF is on. Remove the implicit
difference in the code.

Also, on most 32bit CPUs we should always treat the compare as 32bit
compare, as the CPU will ignore the L bit. This is not true for e500mc,
but that's up for a different patch.

Reported-by: Torbjorn Granlund 
Reviewed-by: Richard Henderson 
Signed-off-by: Alexander Graf 

---

v1 -> v2:

  - ignore L bit
---
 target-ppc/translate.c |   32 
 1 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/target-ppc/translate.c b/target-ppc/translate.c
index a018616..4590c6f 100644
--- a/target-ppc/translate.c
+++ b/target-ppc/translate.c
@@ -675,48 +675,48 @@ static inline void gen_set_Rc0(DisasContext *ctx, TCGv 
reg)
 /* cmp */
 static void gen_cmp(DisasContext *ctx)
 {
-if (NARROW_MODE(ctx) || !(ctx->opcode & 0x0020)) {
-gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
- 1, crfD(ctx->opcode));
-} else {
+if ((ctx->opcode & 0x0020) && (ctx->insns_flags & PPC_64B)) {
 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
1, crfD(ctx->opcode));
+} else {
+gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
+ 1, crfD(ctx->opcode));
 }
 }
 
 /* cmpi */
 static void gen_cmpi(DisasContext *ctx)
 {
-if (NARROW_MODE(ctx) || !(ctx->opcode & 0x0020)) {
-gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
-  1, crfD(ctx->opcode));
-} else {
+if ((ctx->opcode & 0x0020) && (ctx->insns_flags & PPC_64B)) {
 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
 1, crfD(ctx->opcode));
+} else {
+gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
+  1, crfD(ctx->opcode));
 }
 }
 
 /* cmpl */
 static void gen_cmpl(DisasContext *ctx)
 {
-if (NARROW_MODE(ctx) || !(ctx->opcode & 0x0020)) {
-gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
- 0, crfD(ctx->opcode));
-} else {
+if ((ctx->opcode & 0x0020) && (ctx->insns_flags & PPC_64B)) {
 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
0, crfD(ctx->opcode));
+} else {
+gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
+ 0, crfD(ctx->opcode));
 }
 }
 
 /* cmpli */
 static void gen_cmpli(DisasContext *ctx)
 {
-if (NARROW_MODE(ctx) || !(ctx->opcode & 0x0020)) {
-gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
-  0, crfD(ctx->opcode));
-} else {
+if ((ctx->opcode & 0x0020) && (ctx->insns_flags & PPC_64B)) {
 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
 0, crfD(ctx->opcode));
+} else {
+gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
+  0, crfD(ctx->opcode));
 }
 }
 
-- 
1.6.0.2




[Qemu-devel] [Bug 1100843] Re: Live Migration Causes Performance Issues

2013-05-08 Thread C Cormier
Update:

>From our testing this bug affects KVM Hypervisors on Intel processors
that have the EPT feature enabled with Kernels 3.0 and greater. A list
of Intel EPT supported CPUs here
(http://ark.intel.com/Products/VirtualizationTechnology).

When using a KVM Hypervisor Host with Linux kernel 3.0 or newer kernel
with Intel EPT this bug shows itself. If the kvm_intel module is loaded
with option "ept=N" guest performance is significantly decreased versus
enabled, but it does maintain consistent performance pre and post
restoration/migration.

Exceptions:
-A KVM Host with 2.6.32 or 2.6.39 Kernel with EPT enabled this bug is not 
triggered.
-A KVM Host without the EPT feature enabled Intel CPU this bug is not triggered.
-A KVM Host with Kernel 3.0+ and EPT kvm_intel module option disabled in this 
bug is not triggered

A KVM hypervisor with EPT enabled on Linux Kernel > 3.0 appears to be
the key here.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1100843

Title:
  Live Migration Causes Performance Issues

Status in QEMU:
  New
Status in “qemu-kvm” package in Ubuntu:
  Triaged

Bug description:
  I have 2 physical hosts running Ubuntu Precise.  With 1.0+noroms-
  0ubuntu14.7 and qemu-kvm 1.2.0+noroms-0ubuntu7 (source from quantal,
  built for Precise with pbuilder.) I attempted to build qemu-1.3.0 debs
  from source to test, but libvirt seems to have an issue with it that I
  haven't been able to track down yet.

   I'm seeing a performance degradation after live migration on Precise,
  but not Lucid.  These hosts are managed by libvirt (tested both
  0.9.8-2ubuntu17 and 1.0.0-0ubuntu4) in conjunction with OpenNebula.  I
  don't seem to have this problem with lucid guests (running a number of
  standard kernels, 3.2.5 mainline and backported linux-
  image-3.2.0-35-generic as well.)

  I first noticed this problem with phoronix doing compilation tests,
  and then tried lmbench where even simple calls experience performance
  degradation.

  I've attempted to post to the kvm mailing list, but so far the only
  suggestion was it may be related to transparent hugepages not being
  used after migration, but this didn't pan out.  Someone else has a
  similar problem here -
  http://thread.gmane.org/gmane.comp.emulators.kvm.devel/100592

  qemu command line example: /usr/bin/kvm -name one-2 -S -M pc-1.2 -cpu
  Westmere -enable-kvm -m 73728 -smp 16,sockets=2,cores=8,threads=1
  -uuid f89e31a4-4945-c12c-6544-149ba0746c2f -no-user-config -nodefaults
  -chardev
  socket,id=charmonitor,path=/var/lib/libvirt/qemu/one-2.monitor,server,nowait
  -mon chardev=charmonitor,id=monitor,mode=control -rtc
  base=utc,driftfix=slew -no-kvm-pit-reinjection -no-shutdown -device
  piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive
  file=/var/lib/one//datastores/0/2/disk.0,if=none,id=drive-virtio-
  disk0,format=raw,cache=none -device virtio-blk-
  pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-
  disk0,bootindex=1 -drive
  file=/var/lib/one//datastores/0/2/disk.1,if=none,id=drive-
  ide0-0-0,readonly=on,format=raw -device ide-cd,bus=ide.0,unit=0,drive
  =drive-ide0-0-0,id=ide0-0-0 -netdev
  tap,fd=23,id=hostnet0,vhost=on,vhostfd=25 -device virtio-net-
  pci,netdev=hostnet0,id=net0,mac=02:00:0a:64:02:fe,bus=pci.0,addr=0x3
  -vnc 0.0.0.0:2,password -vga cirrus -incoming tcp:0.0.0.0:49155
  -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5

  Disk backend is LVM running on SAN via FC connection (using symlink
  from /var/lib/one/datastores/0/2/disk.0 above)

  
  ubuntu-12.04 - first boot
  ==
  Simple syscall: 0.0527 microseconds
  Simple read: 0.1143 microseconds
  Simple write: 0.0953 microseconds
  Simple open/close: 1.0432 microseconds

  Using phoronix pts/compuational
  ImageMagick - 31.54s
  Linux Kernel 3.1 - 43.91s
  Mplayer - 30.49s
  PHP - 22.25s

  
  ubuntu-12.04 - post live migration
  ==
  Simple syscall: 0.0621 microseconds
  Simple read: 0.2485 microseconds
  Simple write: 0.2252 microseconds
  Simple open/close: 1.4626 microseconds

  Using phoronix pts/compilation
  ImageMagick - 43.29s
  Linux Kernel 3.1 - 76.67s
  Mplayer - 45.41s
  PHP - 29.1s

  
  I don't have phoronix results for 10.04 handy, but they were within 1% of 
each other...

  ubuntu-10.04 - first boot
  ==
  Simple syscall: 0.0524 microseconds
  Simple read: 0.1135 microseconds
  Simple write: 0.0972 microseconds
  Simple open/close: 1.1261 microseconds

  
  ubuntu-10.04 - post live migration
  ==
  Simple syscall: 0.0526 microseconds
  Simple read: 0.1075 microseconds
  Simple write: 0.0951 microseconds
  Simple open/close: 1.0413 microseconds

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1100843/+subscriptions



Re: [Qemu-devel] [PATCH RFC 0/3] seabios: move acpi table formatting out of bios

2013-05-08 Thread Michael S. Tsirkin
On Tue, May 07, 2013 at 07:01:13PM -0400, Kevin O'Connor wrote:
> On Tue, May 07, 2013 at 09:00:48PM +0300, Michael S. Tsirkin wrote:
> > On Thu, Apr 25, 2013 at 12:02:20PM +0300, Michael S. Tsirkin wrote:
> > > Untested yet, but I thought I'd share the
> > > BIOS bits so we can agree on direction.
> > > 
> > > In particular check out ROM sizes:
> > > - Before patchset with DSDT enabled
> > > Total size: 127880  Fixed: 59060  Free: 3192 (used 97.6% of 128KiB 
> > > rom)
> > > - Before patchset with DSDT disabled
> > > Total size: 122844  Fixed: 58884  Free: 8228 (used 93.7% of 128KiB 
> > > rom)
> > > - After patchset:
> > > Total size: 128776  Fixed: 59100  Free: 2296 (used 98.2% of 128KiB 
> > > rom)
> > > - Legacy disabled at build time:
> > > Total size: 119836  Fixed: 58996  Free: 11236 (used 91.4% of 128KiB 
> > > rom)
> > > 
> > > As can be seen from this, most size savings come
> > > from dropping DSDT, but we do save a bit by removing
> > > other tables. Of course the real reason to move tables to QEMU
> > > is so that ACPI can better match hardware.
> > > 
> > > This patchset adds an option to move all code for formatting acpi tables
> > > out of BIOS. With this, QEMU has full control over the table layout.
> > > All tables are loaded from the new "/etc/acpi/" directory.
> > > Any entries in this directory cause BIOS to disable
> > > ACPI table generation completely.
> > > A generic linker script, controlled by QEMU, is
> > > loaded from "/etc/linker-script". It is used to
> > > patch in table pointers and checksums.
> > 
> > After some thought, there are two additional
> > options worth considering, in that they simplify
> > bios code somewhat:
> > 
> > - bios could get size from qemu, allocate a buffer
> >   (e.g. could be one buffer for all tables)
> >   and pass the address to qemu.
> >   qemu does all the patching
> > 
> > - further, qemu could do the copy of tables into
> >   that address directly
> 
> This seems more complex than necessary to me.
> 
> The important task is to get the tables generated in QEMU - I'd focus
> on getting the tables generated in QEMU (one table per fw_cfg "file").
> Once that is done, the SeaBIOS side can be easily implemented, and we
> can add any enhancements on top if we feel it is necessary.
> 
> -Kevin

I have kind of done this, though only compile-tested
for now - still need to update the bios with the new
linker interface along the lines suggested by you.

If you want to see how the code looks like check out

git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git acpi
the code is in
hw/i386/acpi-build.c
and
hw/i386/bios-linker-loader.c

the history is all messed up now, I'll clean it up shortly.

That said, this uses fw_cfg so for this to be acceptable,
we need to fix migration with big fw_cfg files.

-- 
MST



Re: [Qemu-devel] [PATCH V14 6/6] remove QEMUOptionParameter related functions and struct

2013-05-08 Thread Eric Blake
[assuming you mis-typed your cc:, and that you meant kwolf instead of
kwol at redhat]

On 05/08/2013 02:45 AM, Dong Xu Wang wrote:
> Signed-off-by: Dong Xu Wang 
> ---
>  include/qemu/option.h |  32 --
>  util/qemu-option.c| 285 -
> -
>  2 files changed, 317 deletions(-)
> 
> diff --git a/include/qemu/option.h b/include/qemu/option.h
> index d63e447..51814cf 100644
> --- a/include/qemu/option.h
> +++ b/include/qemu/option.h
> @@ -38,17 +38,6 @@ enum QEMUOptionParType {
>  OPT_STRING,
>  };
>  
> -typedef struct QEMUOptionParameter {
> -const char *name;
> -enum QEMUOptionParType type;

'enum QEMUOptionParType' several lines earlier is now unused; you should
clean that too.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH 9/9] Make monitor command 'dump-guest-memory' dump in kdump-compressed format

2013-05-08 Thread Eric Blake
On 05/08/2013 02:50 AM, qiaonuohan wrote:
> 
> Thanks for your suggestion. I will fix it like:
> 
> { 'enum': 'DumpCompressionFormat',
>   'data': [ 'zlib', 'lzo', 'snappy' ] }
> 
> For zlib is treated as the default compression format, and
> 'uncompressed' won't be an option.

No, I was serious that you need to provide 'uncompressed' as an explicit
enum value.  It is very annoying to toggle between four states (three
compression formats and a fourth state of no compression) when the
fourth is available only by omitting a parameter.  The default MUST be
'uncompressed' for backwards-compatibility, not 'zlib'.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v2 2/2] qga: unlink just created guest-file if fchmod() or fdopen() fails on it

2013-05-08 Thread Eric Blake
On 05/08/2013 09:31 AM, Laszlo Ersek wrote:
> We shouldn't allow guest filesystem pollution on error paths.
> 
> Suggested-by: Eric Blake 
> Signed-off-by: Laszlo Ersek 
> ---
>  qga/commands-posix.c |3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)

Reviewed-by: Eric Blake 

> 
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 2eec712..e199738 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -355,6 +355,9 @@ safe_open_or_create(const char *path, const char *mode, 
> Error **err)
>  }
>  
>  close(fd);
> +if (oflag & O_CREAT) {
> +unlink(path);
> +}
>  }
>  }
>  
> 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH] PPC: Depend behavior of cmp instructions only on instruction encoding

2013-05-08 Thread Torbjorn Granlund
Aurelien Jarno  writes:

  Don't people read what I write? From one of my previous email:
  
I do...and even scrutinise it for grammar errors.  ;-)

  Quoting the "IBM PowerPC Microprocessor Family: The Programming   


  Environments Manual for 32 and 64-bit Microprocessors":   


  | Note: In 32-bit implementations, if L = 1 the instruction form is invalid.
  
  This doesn't match what your contact says.
  
I think you're reading too much into that wording.

It is perhaps intended to mean that L = 1 makes no sense, that it will
not have the desired effect.

(I don't much like the way IBM's powerpc docs are written.  They ought
to be much more unambiguous, and could be less wordy.)

-- 
Torbjörn



Re: [Qemu-devel] [libvirt]virtio serial device problem

2013-05-08 Thread fred . konrad
> On 05/07/2013 07:50 PM, Paolo Bonzini wrote:
>> Il 07/05/2013 09:20, Li Zhang ha scritto:
>>> Hi all,

Hi,
>>>
>>> When we use the latest version of QEMU to build ovirt,
>>> we get this error reported from libvirt.
>>
>> What QEMU commit is this?
>
>
> b3e6d591b05538056d665572f3e3bbfb3cbb70e7

This commit is from 05/29 no?

there were issues with that. But it should be fixed.

Do you still have the command-line issue with the last git?

See commit 80270a19685dd20eda017b0360c743b3e3ed6f57

Thanks,
Fred

>
>
>> It might have been fixed already.
>
> Hm. From what I see, it is all correct from the qemu side, the problem is
> in libvirt which does not know about "virtio-pci-bus" yet.
>
>
>
>> Paolo
>>
>>>
>>> qemu-system-ppc64: -device
>>> virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=com.redhat.rhevm.vdsm:
>>>
>>> Bus 'virtio-serial0.0' is full
>>> qemu-system-ppc64: -device
>>> virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=com.redhat.rhevm.vdsm:
>>>
>>> Bus 'virtio-serial0.0' not found
>>>
>>> Libvirt helps create QEMU command line and put virtserialport device to
>>> bus virtio-serial0.0.
>>> For latest version of QEMU, the bus type is changed.
>>>
>>> (qemu) info qtree
>>> bus: main-system-bus
>>>   type System
>>>   dev: spapr-pci-host-bridge, id ""
>>> index = 0
>>> buid = 0x8002000
>>> liobn = 0x8000
>>> mem_win_addr = 0x100a000
>>> mem_win_size = 0x2000
>>> io_win_addr = 0x1008000
>>> io_win_size = 0x1
>>> msi_win_addr = 0x1009000
>>> irq 0
>>> bus: pci
>>>   type PCI
>>>   dev: virtio-serial-pci, id "virtio-serial0"
>>> ioeventfd = on
>>> vectors = 2
>>> class = 0x780
>>> indirect_desc = on
>>> event_idx = on
>>> max_ports = 31
>>> addr = 03.0
>>> romfile = 
>>> rombar = 1
>>> multifunction = off
>>> command_serr_enable = on
>>> class Class 0780, addr 00:03.0, pci id 1af4:1003 (sub
>>> 1af4:0003)
>>> bar 0: i/o at 0x [0x1e]
>>> bar 1: mem at 0x [0xffe]
>>> bus: virtio-serial0.0
>>>   type virtio-pci-bus
>>>   dev: virtio-serial-device, id ""
>>> max_ports = 31
>>> bus: virtio-serial-bus.0
>>>   type virtio-serial-bus
>>>   dev: virtserialport, id "channel1"
>>> chardev = charchannel1
>>> nr = 2
>>> name = "org.qemu.guest_agent.0"
>>> port 2, guest off, host off, throttle off
>>>   dev: virtserialport, id "channel0"
>>> chardev = charchannel0
>>> nr = 1
>>> name = "com.redhat.rhevm.vdsm"
>>> port 1, guest off, host off, throttle off
>>>
>>>
>>> But we tried to replace virtio-serial0.0 with virtio-serial-bus.0,
>>> SLOF crashes. It still doesn't work at all.
>>>
>>> Does anyone know how to use virtserialport in QEMU command line?
>>> If configuration is changed in QEMU, libvirt also needs to change it
>>> accordingly.
>>>
>>> Thanks. :)
>>> --Li
>>>
>>>
>>>
>
>
> --
> Alexey Kardashevskiy
> IBM OzLabs, LTC Team
>
> e-mail: a...@au1.ibm.com
> notes: Alexey Kardashevskiy/Australia/IBM
>
>
>




Re: [Qemu-devel] [PATCH 4/5] qtest/ide-test: Add simple DMA read/write test case

2013-05-08 Thread Paolo Bonzini
Il 08/05/2013 11:43, Kevin Wolf ha scritto:
> This tests that single sectors can be successfully written and correctly
> read back.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  tests/ide-test.c | 221 
> +++
>  1 file changed, 221 insertions(+)
> 
> diff --git a/tests/ide-test.c b/tests/ide-test.c
> index 45036e3..5fc496f 100644
> --- a/tests/ide-test.c
> +++ b/tests/ide-test.c
> @@ -29,8 +29,12 @@
>  #include 
>  
>  #include "libqtest.h"
> +#include "libqos/pci-pc.h"
> +#include "libqos/malloc-pc.h"
>  
>  #include "qemu-common.h"
> +#include "hw/pci/pci_ids.h"
> +#include "hw/pci/pci_regs.h"
>  
>  #define TEST_IMAGE_SIZE 64 * 1024 * 1024
>  
> @@ -60,12 +64,42 @@ enum {
>  };
>  
>  enum {
> +LBA = 0x40,
> +};
> +
> +enum {
> +bmreg_cmd   = 0x0,
> +bmreg_status= 0x2,
> +bmreg_prdt  = 0x4,
> +};
> +
> +enum {
> +CMD_READ_DMA= 0xc8,
> +CMD_WRITE_DMA   = 0xca,
>  CMD_IDENTIFY= 0xec,
>  };
>  
> +enum {
> +BM_CMD_START=  0x1,
> +BM_CMD_WRITE=  0x8, /* write = from device to memory */
> +};
> +
> +enum {
> +BM_STS_ACTIVE   =  0x1,
> +BM_STS_ERROR=  0x2,
> +BM_STS_INTR =  0x4,
> +};
> +
> +enum {
> +PRDT_EOT= 0x8000,
> +};
> +
>  #define assert_bit_set(data, mask) g_assert_cmphex((data) & (mask), ==, 
> (mask))
>  #define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==, 0)
>  
> +static QPCIBus *pcibus = NULL;
> +static QGuestAllocator *guest_malloc;
> +
>  static char tmp_path[] = "/tmp/qtest.XX";
>  
>  static void ide_test_start(const char *cmdline_fmt, ...)
> @@ -79,6 +113,7 @@ static void ide_test_start(const char *cmdline_fmt, ...)
>  
>  qtest_start(cmdline);
>  qtest_irq_intercept_in(global_qtest, "ioapic");
> +guest_malloc = pc_alloc_init();
>  }
>  
>  static void ide_test_quit(void)
> @@ -86,6 +121,188 @@ static void ide_test_quit(void)
>  qtest_quit(global_qtest);
>  }
>  
> +static QPCIDevice *get_pci_device(uint16_t *bmdma_base)
> +{
> +QPCIDevice *dev;
> +uint16_t vendor_id, device_id;
> +
> +if (!pcibus) {
> +pcibus = qpci_init_pc();
> +}
> +
> +/* Find PCI device and verify it's the right one */
> +dev = qpci_device_find(pcibus, QPCI_DEVFN(IDE_PCI_DEV, IDE_PCI_FUNC));
> +g_assert(dev != NULL);
> +
> +vendor_id = qpci_config_readw(dev, PCI_VENDOR_ID);
> +device_id = qpci_config_readw(dev, PCI_DEVICE_ID);
> +g_assert(vendor_id == PCI_VENDOR_ID_INTEL);
> +g_assert(device_id == PCI_DEVICE_ID_INTEL_82371SB_1);
> +
> +/* Map bmdma BAR */
> +*bmdma_base = (uint16_t)(uintptr_t) qpci_iomap(dev, 4);
> +
> +qpci_device_enable(dev);
> +
> +return dev;
> +}
> +
> +static void free_pci_device(QPCIDevice *dev)
> +{
> +/* libqos doesn't have a function for this, so free it manually */
> +g_free(dev);
> +}
> +
> +typedef struct PrdtEntry {
> +uint32_t addr;
> +uint32_t size;
> +} QEMU_PACKED PrdtEntry;
> +
> +#define assert_bit_set(data, mask) g_assert_cmphex((data) & (mask), ==, 
> (mask))
> +#define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==, 0)
> +
> +static int send_dma_request(int cmd, uint64_t sector, int nb_sectors,
> +PrdtEntry *prdt, int prdt_entries)
> +{
> +QPCIDevice *dev;
> +uint16_t bmdma_base;
> +uintptr_t guest_prdt;
> +size_t len;
> +bool from_dev;
> +uint8_t status;
> +
> +dev = get_pci_device(&bmdma_base);
> +
> +switch (cmd) {
> +case CMD_READ_DMA:
> +from_dev = true;
> +break;
> +case CMD_WRITE_DMA:
> +from_dev = false;
> +break;
> +default:
> +g_assert_not_reached();
> +}
> +
> +/* Select device 0 */
> +outb(IDE_BASE + reg_device, 0 | LBA);
> +
> +/* Stop any running transfer, clear any pending interrupt */
> +outb(bmdma_base + bmreg_cmd, 0);
> +outb(bmdma_base + bmreg_status, BM_STS_INTR);
> +
> +/* Setup PRDT */
> +len = sizeof(*prdt) * prdt_entries;
> +guest_prdt = guest_alloc(guest_malloc, len);
> +memwrite(guest_prdt, prdt, len);

What endianness?

Paolo

> +outl(bmdma_base + bmreg_prdt, guest_prdt);




Re: [Qemu-devel] [PATCH] target-mips: add missing check_dspr2 for multiply instructions

2013-05-08 Thread Aurelien Jarno
On Wed, May 08, 2013 at 04:09:04PM +0200, Petar Jovanovic wrote:
> From: Petar Jovanovic 
> 
> The emulator needs to check in hflags if DSP unit has been turned off before
> it generates code for MUL_PH, MUL_S_PH, MULQ_S_W, and MULQ_RS_W.
> 
> Signed-off-by: Petar Jovanovic 
> ---
>  target-mips/translate.c |1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/target-mips/translate.c b/target-mips/translate.c
> index b7f8203..0a53203 100644
> --- a/target-mips/translate.c
> +++ b/target-mips/translate.c
> @@ -13400,6 +13400,7 @@ static void gen_mipsdsp_multiply(DisasContext *ctx, 
> uint32_t op1, uint32_t op2,
>  /* OPC_MULT_G_2E, OPC_ADDUH_QB_DSP, OPC_MUL_PH_DSP have
>   * the same mask and op1. */
>  case OPC_MULT_G_2E:
> +check_dspr2(ctx);
>  switch (op2) {
>  case  OPC_MUL_PH:
>  gen_helper_mul_ph(cpu_gpr[ret], v1_t, v2_t, cpu_env);

Thanks, applied.


-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] [PATCH] PPC: Depend behavior of cmp instructions only on instruction encoding

2013-05-08 Thread Aurelien Jarno
On Wed, May 08, 2013 at 05:54:27PM +0200, Torbjorn Granlund wrote:
> Aurelien Jarno  writes:
> 
>   As it seems you have good contact with IBM, could you please ask them
>   to fix their manuals?
>   
> What flaw have your found?

Don't people read what I write? From one of my previous email:

Quoting the "IBM PowerPC Microprocessor Family: The Programming 

  
Environments Manual for 32 and 64-bit Microprocessors": 

  

| Note: In 32-bit implementations, if L = 1 the instruction form is invalid.

This doesn't match what your contact says.

>   At least Freescale CPUs match what IBM documentation says.
> 
> Which ones?  Freescale 7447 and Freescale e500 disagree.  (Or at least
> some versions of these chips, perhaps newer e500 steppings ignore the L
> bit.)

The e500 CPU doesn't ignore the L bit, like the IBM manual says.

>   IBM CPUs don't.
>   
> Which ones?

The one from your contact saying that reserved fields should be ignored
by hardware.

>   No it's not correct, it doesn't match neither Freescale nor IBM
>   behaviour. It also means the same code executed on a 32-bit emulated CPU
>   run with qemu-system-ppc will behave differently than when run with
>   qemu-system-ppc64. This is fine for now as we are in freeze period, but
>   should be fixed afterwards.
>   
> I think one should check if it is a 64-bit CPU vs 32-bit CPU, as your
> patch did.  (If I read it correctly; while I am an expert in the area, I
> am very little familiar with qemu's innards.)  Except that it should
> probably not cast an exception (but I think either way there is no
> calamity).
> 

Looking more into details about the issue. Old *PowerPC* manuals (the
one from the 7447 era) clearly states that the L bit must trigger an
invalid instruction exception.

*POWER* manuals states that reserved fields in instructions are ignored by
on Server environment, but not on Embedded environment, though it is now
phased-in on the latter.

In short everybody is correct, it only depends on the CPU.

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



Re: [Qemu-devel] Possible ppc comparision optimisation

2013-05-08 Thread Paolo Bonzini
Il 08/05/2013 17:44, Torbjorn Granlund ha scritto:
> Paolo Bonzini  writes:
> 
>   I think that would be faster on 32-bit hosts, truncs are cheap.
>   
> And slower perhaps on 64-bit hosts, at least for operations where
> additional explicit trunctation will be needed (such as before
> comparisions and after right shifts).
> 
>   > There could be a disadvantage of this compared to the old code, since
>   > this has a chained algebraic dependency, while the old code's many
>   > instructions might have been more independent.
>   
>   What about these alternatives:
>   
>   setcond LT, t0, arg0, arg1
>   setcond EQ, t1, arg0, arg1
>   trunc  s0, t0
>   trunc  s1, t1
>   shli   s0, s0, 1; s0 = (arg0 < arg1) ? 2 : 0
>   subi   s1, s1, 2; s1 = (arg0 != arg1) ? -2 : -1
>   subs0, s0, s1   ; < 4   == 1  > 2
>   shli   s0, s0, 1; < 8   == 2  > 4
>   
>   ===
>   
>   setcond LT, t0, arg0, arg1
>   setcond NE, t1, arg0, arg1
>   trunc   s0, t0
>   trunc   s1, t1
>   add s0, s0, s1  ; < 2   == 0  > 1
>   movis1, 1
>   add s0, s0, s1  ; < 3   == 1  > 2
>   shl s1, s1, s0  ; < 8   == 2  > 4
>   
> Surely there are many alternative forms.
> Is your aim to add micro-parallelism?

Yes, I think in this respect I think the first one is better.  The
second could be three instructions on machines that have a set-nth-bit
instruction _and_ a zero register, but I'm not sure they exist...

> (Your sequences look a bit curious.  Did you use a super-optimiser?)

No, but I am attracted to these curious sequences from my previous life
working on compilers. :)  I know your superoptimizer and, in fact, we
both worked on some parts of GCC (optimization of conditional
branches/stores), just 20 years apart.

The second is actually not too curious after you look at it for a while,
it is a variant of the usual (x > y) + (x >= y) trick used to generate a
0/1/2 result.  The first I found by trial and error based on yours; it
is basically (x < y) * 2 - (x == y) + 2, with some reordering to get
parallelism and avoid the need for subfi-like instructions.

Paolo



Re: [Qemu-devel] VFIO VGA test branches

2013-05-08 Thread Alex Williamson
A few notes for anyone trying this...

  * I recommend the q35 machine type and using the default config
file found in the docs directory.  This means your command line
should include:

 -M q35 -nodefconfig -readconfig /path/to/qemu.git/docs/q35-chipset.cfg

  * You're likely passing through a graphics card that is attached
to the host system below a root port, so make it appear that way
to the guest too.  If your graphics card has a graphics function
and audio function, assign them as:

-device 
vfio-pci,host=2:00.0,x-vga=on,multifunction=on,bus=ich9-pcie-port-1,addr=0.0 \
-device vfio-pci,host=2:00.1,bus=ich9-pcie-port-1,addr=0.1

The bus name comes from the q35-chipset.cfg above.  If your
graphics doesn't include a separate audio device, drop the
second line and the multifunction option of the first (addr is
also optional at that point, 0.0 will be the default).

  * If you follow both of the above, your VGA device is now below a
root port, but the version of seabios in qemu doesn't support
initializing VGA routing to that device.  To fix, use upstream
seabios: git://git.seabios.org/seabios.git  The default config
should work.  Then add the following to your qemu commandline:

-L /path/to/seabios.git/out/ -L /path/to/qemu/bios/files/

(the latter is likely /usr/local/share/qemu/)

  * You can use -nographic to prevent QEMU from trying to start SDL
or need a vnc parameter.  You can also specify a -vnc option and
use the window for mouse input.

  * Use -vga none.  At this point I'm not really interested in
dual-headed VMs unless you're interested in working on it.
Having an emulated VGA means we're not really testing VGA
support through VFIO.

  * Do no use the vfio-pci romfile option unless you need it (ie.
try w/o first).  Option ROMs check an internal signature against
the hardware.  If they don't match, it isn't run.  If you
download a ROM from the internet, you may get nowhere.  If you
do need a ROM, it's best to scrape it off the device you're
using.  You can do this through the "rom" file in sysfs for the
device.  "echo 1 > rom" to enable it, the read it as "cat rom
> /tmp/rom".  To do this, it should be a secondary graphics
device and be untouched by host drivers.  You may have better
luck booting from an install CD to get an environment where the
device is untouched for this.

  * USB passthrough is handy for input and easier than figuring out
which ports are connected to which USB controllers for vfio-pci
assignment.  Use lsusb to find the devices, note the bus and
device numbers, the use:

-device usb-host,hostbus=8,hostaddr=2

I think that's it.  Feel free to reply with other best practices.
Thanks,

Alex

On Fri, 2013-05-03 at 16:56 -0600, Alex Williamson wrote:
> Hi folks,
> 
> A number of people have been trying VFIO's VGA support, a few have even
> been successful.  Resetting devices has been a problem and makes it
> very, very difficult to really use VGA assignment effectively.  The code
> in the branches below attempts to address this.  Discrete graphics
> devices are typically on their own bus, which we can reset so we
> theoretically get something pretty close to a power-on state for the GPU
> on each run (or after each guest reset).  With this I'm able to get
> multiple runs on my HD7850 with no need to reset the host.  Hopefully
> this will also cleanup after any host uses of the device so we can
> unload driver rather than blacklisting them.
> 
> If you've been playing with VFIO and VGA, please give the branches below
> a shot and report successes and failures.  Note that this new reset is
> only enable with the x-vga=on option, so should not do gratuitous bus
> resets for other devices.  Thanks,
> 
> Alex
> 
> git://github.com/awilliam/linux-vfio.git vfio-vga-reset
> git://github.com/awilliam/qemu-vfio.git vfio-vga-reset
> 
> PS - The above linux branch is v3.9 based which has a known kvm emulator
> bug.  If you're on Intel and nothing happens, try:
> 
> sudo modprobe -r kvm_intel
> sudo modprobe kvm_intel emulate_invalid_guest_state=0
> 
> This is required to execute the VGA BIOS on my HD7850.
> 
> If things still don't work, apply the following patch:
> 
> --- a/hw/misc/vfio.c
> +++ b/hw/misc/vfio.c
> @@ -40,7 +40,7 @@
>  #include "sysemu/kvm.h"
>  #include "sysemu/sysemu.h"
>  
> -/* #define DEBUG_VFIO */
> +#define DEBUG_VFIO
>  #ifdef DEBUG_VFIO
>  #define DPRINTF(fmt, ...) \
>  do { fprintf(stderr, "vfio: " fmt, ## __VA_ARGS__); } while (0)
> 
> And log the output (there will be lots).
> 
> Also, AMD/ATI and Nvidia are the only devices expected to have a
> reasonable shot at working.  I'm seeing reports of success

Re: [Qemu-devel] [RFC PATCH 0/8] MemoryRegion and FlatView refcounting, replace hostmem with memory_region_find

2013-05-08 Thread Paolo Bonzini
Il 08/05/2013 08:20, liu ping fan ha scritto:
> On Mon, May 6, 2013 at 10:25 PM, Paolo Bonzini  wrote:
>> Hi,
>>
>> this is an alternative approach to refactoring of dataplane's HostMem
>> code.  Here, I take Ping Fan's idea of RCU-style updating of the
>> region list and apply it to the AddressSpace's FlatView.  With this
> 
> In fact, I am worrying about the priority of MemoryListener, if it is
> true, then we should drop RCU-style idea.

You mean in hostmem, or in general as in this patch?  Note that this
patch releases the old FlatView at the end of all MemoryListener operations.

Paolo

> Also if it is true, there is
> already a bug with hostmem listener. It should use region_del, not
> region_nop to reconstruct the local view. But just let me have a deep
> thinking.
> 
> Regards,
> Pingfan
>> change, dataplane can simply use memory_region_find instead of
>> hostmem.
>>
>> This is a somewhat larger change, but I prefer it for two reasons.
>>
>> 1) it splits the task of adding BQL-less memory dispatch in two parts,
>>tacking memory_region_find first (which is simpler because locking
>>is left to the caller).
>>
>> 2) HostMem duplicates a lot of the FlatView logic, and adding the
>>RCU-style update in FlatView benefits everyone.
>>
>> The missing ingredients here are:
>>
>> 1) remember and unreference the MemoryRegions that are used in
>>a vring entry.  In order to implement this, it is probably simpler
>>to change vring.c to use virtio.c's VirtQueueElement data structure.
>>We want something like that anyway in order to support migration.
>>
>> 2) add an owner field to MemoryRegion, and set it for all MemoryRegions
>>for hot-unpluggable devices.  In this series, ref/unref are stubs.
>>
>> For simplicity I based the patches on my IOMMU rebase.  I placed the
>> tree at git://github.com/bonzini/qemu.git, branch iommu.
>>
>> Paolo
>>
>> Paolo Bonzini (8):
>>   memory: add ref/unref calls
>>   exec: check MRU in qemu_ram_addr_from_host
>>   memory: return MemoryRegion from qemu_ram_addr_from_host
>>   memory: ref/unref memory across address_space_map/unmap
>>   memory: access FlatView from a local variable
>>   memory: use a new FlatView pointer on every topology update
>>   memory: add reference counting to FlatView
>>   dataplane: replace hostmem with memory_region_find
>>
>>  exec.c|   63 +---
>>  hw/core/loader.c  |1 +
>>  hw/display/exynos4210_fimd.c  |6 +
>>  hw/display/framebuffer.c  |   10 +-
>>  hw/i386/kvm/ioapic.c  |2 +
>>  hw/i386/kvmvapic.c|1 +
>>  hw/misc/vfio.c|2 +
>>  hw/virtio/dataplane/Makefile.objs |2 +-
>>  hw/virtio/dataplane/hostmem.c |  176 
>> -
>>  hw/virtio/dataplane/vring.c   |   56 +--
>>  hw/virtio/vhost.c |2 +
>>  hw/virtio/virtio-balloon.c|1 +
>>  hw/xen/xen_pt.c   |4 +
>>  include/exec/cpu-common.h |2 +-
>>  include/exec/memory.h |9 ++
>>  include/hw/virtio/dataplane/hostmem.h |   57 ---
>>  include/hw/virtio/dataplane/vring.h   |3 +-
>>  kvm-all.c |2 +
>>  memory.c  |  142 +-
>>  target-arm/kvm.c  |2 +
>>  target-i386/kvm.c |4 +-
>>  target-sparc/mmu_helper.c |1 +
>>  xen-all.c |2 +
>>  23 files changed, 253 insertions(+), 297 deletions(-)
>>  delete mode 100644 hw/virtio/dataplane/hostmem.c
>>  delete mode 100644 include/hw/virtio/dataplane/hostmem.h
>>




Re: [Qemu-devel] [PATCH v2 1/3] block: add basic backup support to block driver

2013-05-08 Thread Paolo Bonzini
Il 08/05/2013 14:39, Kevin Wolf ha scritto:
> Am 29.04.2013 um 09:42 hat Stefan Hajnoczi geschrieben:
>> From: Dietmar Maurer 
>>
>> backup_start() creates a block job that copies a point-in-time snapshot
>> of a block device to a target block device.
>>
>> We call backup_do_cow() for each write during backup. That function
>> reads the original data from the block device before it gets
>> overwritten.  The data is then written to the target device.
>>
>> The tracked_request infrastructure is used to serialize access.  Both
>> reads and writes are serialized if they overlap.
>>
>> Currently backup cluster size is hardcoded to 65536 bytes.
>>
>> [I made a number of changes to Dietmar's original patch and folded them
>> in to make code review easy.  Here is the full list:
>>
>>  * Drop BackupDumpFunc interface in favor of a target block device
>>  * Detect zero clusters with buffer_is_zero()
>>  * Don't write zero clusters to the target
>>  * Use 0 delay instead of 1us, like other block jobs
>>  * Unify creation/start functions into backup_start()
>>  * Simplify cleanup, free bitmap in backup_run() instead of cb function
>>  * Use HBitmap to avoid duplicating bitmap code
>>  * Use bdrv_getlength() instead of accessing ->total_sectors directly
>>  * Delete the backup.h header file, it is no longer necessary
>>  * Move ./backup.c to block/backup.c
>>  * Remove #ifdefed out code
>>  * Coding style and whitespace cleanups
>>
>> -- stefanha]
>>
>> Signed-off-by: Dietmar Maurer 
>> Signed-off-by: Stefan Hajnoczi 
>> ---
>>  block.c   |  69 -
>>  block/Makefile.objs   |   1 +
>>  block/backup.c| 252 
>> ++
>>  include/block/block.h |   2 +
>>  include/block/block_int.h |  16 +++
>>  include/block/blockjob.h  |  10 ++
>>  6 files changed, 345 insertions(+), 5 deletions(-)
>>  create mode 100644 block/backup.c
> 
> (Moving some hunks around so I can comment on the headers first.)
> 
>> diff --git a/include/block/blockjob.h b/include/block/blockjob.h
>> index c290d07..6f42495 100644
>> --- a/include/block/blockjob.h
>> +++ b/include/block/blockjob.h
>> @@ -50,6 +50,13 @@ typedef struct BlockJobType {
>>   * manually.
>>   */
>>  void (*complete)(BlockJob *job, Error **errp);
>> +
>> +/** tracked requests */
>> +int coroutine_fn (*before_read)(BlockDriverState *bs, int64_t 
>> sector_num,
>> +int nb_sectors, QEMUIOVector *qiov);
>> +int coroutine_fn (*before_write)(BlockDriverState *bs, int64_t 
>> sector_num,
>> + int nb_sectors, QEMUIOVector *qiov);

The mechanism to handle different cluster sizes is complex.

I think you could instead use something that resembles the copy-on-read
code, but with the copy-on-read logic cut-and-pasted to block/backup.c.
 This way the state is held in the BlockBackupJob instead of the
BlockDriverState (e.g. using job->bs as the source instead of
bs->backing_file).

The before_write operations can just allocate a dummy buffer, do a
copy-on-read to the buffer (similar to streaming), discard the result
and proceed to do the write on the source BDS.  The serialization would
then happen on the destination BDS's cluster size (which is the one that
matters).  The destination BDS does not get writes from outside the job,
so it is fine to do all the serialization within the job.

I would leave out before_read from the initial patch.  An optimized
version that doesn't do the read twice has complex serialization issues,
as you found out.  And I'm not sure that a simple version that reads
twice (once as above with COR to a dummy buffer, the other on the source
BDS to serve the guest's request) is really faster than just letting the
job do COR in a streaming fashion.

Paolo

>> +
>>  } BlockJobType;
> 
> This is actually a sign that a block job isn't the right tool. Jobs are
> something that runs in the background and doesn't have callbacks. You
> really want to have a filter here (that happens to be coupled to a job).
> Need the BlockBackend split before we can do this right.
> 
> The second thing that this conflicts with is generalising block jobs to
> generic background jobs.
> 
> Each hack like this that we accumulate makes it harder to get the real
> thing eventually.
> 
>>  
>>  /**
>> @@ -103,6 +110,9 @@ struct BlockJob {
>>  /** Speed that was set with @block_job_set_speed.  */
>>  int64_t speed;
>>  
>> +/** tracked requests */
>> +int cluster_size;
> 
> Sure that this is the right comment here?
> 
> Does really every job need a cluster size?
> 
>> diff --git a/block.c b/block.c
>> index aa9a533..c5c09b7 100644
>> --- a/block.c
>> +++ b/block.c
>> @@ -54,6 +54,7 @@
>>  typedef enum {
>>  BDRV_REQ_COPY_ON_READ = 0x1,
>>  BDRV_REQ_ZERO_WRITE   = 0x2,
>> +BDRV_REQ_BACKUP_ONLY  = 0x4,
>>  } BdrvRequestFlags;
> 
> Without having read the rest of the code, it's unclear to me what this

Re: [Qemu-devel] [PATCH] PPC: Depend behavior of cmp instructions only on instruction encoding

2013-05-08 Thread Torbjorn Granlund
Aurelien Jarno  writes:

  As it seems you have good contact with IBM, could you please ask them
  to fix their manuals?
  
What flaw have your found?

  At least Freescale CPUs match what IBM documentation says.

Which ones?  Freescale 7447 and Freescale e500 disagree.  (Or at least
some versions of these chips, perhaps newer e500 steppings ignore the L
bit.)

  IBM CPUs don't.
  
Which ones?

  No it's not correct, it doesn't match neither Freescale nor IBM
  behaviour. It also means the same code executed on a 32-bit emulated CPU
  run with qemu-system-ppc will behave differently than when run with
  qemu-system-ppc64. This is fine for now as we are in freeze period, but
  should be fixed afterwards.
  
I think one should check if it is a 64-bit CPU vs 32-bit CPU, as your
patch did.  (If I read it correctly; while I am an expert in the area, I
am very little familiar with qemu's innards.)  Except that it should
probably not cast an exception (but I think either way there is no
calamity).

-- 
Torbjörn



Re: [Qemu-devel] Possible ppc comparision optimisation

2013-05-08 Thread Torbjorn Granlund
Paolo Bonzini  writes:

  I think that would be faster on 32-bit hosts, truncs are cheap.
  
And slower perhaps on 64-bit hosts, at least for operations where
additional explicit trunctation will be needed (such as before
comparisions and after right shifts).

  > There could be a disadvantage of this compared to the old code, since
  > this has a chained algebraic dependency, while the old code's many
  > instructions might have been more independent.
  
  What about these alternatives:
  
  setcond LT, t0, arg0, arg1
  setcond EQ, t1, arg0, arg1
  trunc  s0, t0
  trunc  s1, t1
  shli   s0, s0, 1; s0 = (arg0 < arg1) ? 2 : 0
  subi   s1, s1, 2; s1 = (arg0 != arg1) ? -2 : -1
  subs0, s0, s1   ; < 4   == 1  > 2
  shli   s0, s0, 1; < 8   == 2  > 4
  
  ===
  
  setcond LT, t0, arg0, arg1
  setcond NE, t1, arg0, arg1
  trunc   s0, t0
  trunc   s1, t1
  add s0, s0, s1  ; < 2   == 0  > 1
  movis1, 1
  add s0, s0, s1  ; < 3   == 1  > 2
  shl s1, s1, s0  ; < 8   == 2  > 4
  
Surely there are many alternative forms.
Is your aim to add micro-parallelism?

(Your sequences look a bit curious.  Did you use a super-optimiser?)

-- 
Torbjörn



Re: [Qemu-devel] [Bug 1174654] Re: qemu-system-x86_64 takes 100% CPU after host machine resumed from suspend to ram

2013-05-08 Thread Serge Hallyn
Quoting Maxim Loparev (laplander...@gmail.com):
> The issue mostly gone after cold reboot via suspend to disk. I managed to 
> reproduce it only once after reboot and it grubs CPU for only minute or two 
> while i checking it and than returned to normal CPU usage. I've checked both 
> distribution and the trunk version.
> So suspend this bug until someone can stably reproduce it.

Thanks, I'll mark it invalid (meaning "can't reproduce it to get more
information") for now, please do re-open if anyone can reproduce.

 status: invalid


** Changed in: qemu (Ubuntu)
   Status: Confirmed => Invalid

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1174654

Title:
  qemu-system-x86_64 takes 100% CPU after host machine resumed from
  suspend to ram

Status in QEMU:
  Confirmed
Status in “qemu” package in Ubuntu:
  Invalid

Bug description:
  I have Windows XP SP3  inside qemu VM. All works fine in 12.10. But
  after upgraiding to 13.04 i have to restart the VM each time i
  resuming my host machine, because qemu process starts to take CPU
  cycles and OS inside VM is very slow and sluggish. However it's still
  controllable and could be shutdown by itself.

  According to the taskmgr any active process takes 99% CPU. It's not
  stucked on some single process.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1174654/+subscriptions



[Qemu-devel] [PATCH v2 0/2] qga umask fix addenda

2013-05-08 Thread Laszlo Ersek
I should have paid more attention to portability and error path cleanup
in the CVE-2013-2007 fix.

(We continue to assume, like the rest of qemu code, that
qemu_set_cloexec() never fails internally. This should be a reasonable
assumption when the input fd is valid.)

Laszlo Ersek (2):
  qga: distinguish binary modes in "guest_file_open_modes" map
  qga: unlink just created guest-file if fchmod() or fdopen() fails on
it

 qga/commands-posix.c |   25 +++--
 1 files changed, 19 insertions(+), 6 deletions(-)




[Qemu-devel] [PATCH v2 2/2] qga: unlink just created guest-file if fchmod() or fdopen() fails on it

2013-05-08 Thread Laszlo Ersek
We shouldn't allow guest filesystem pollution on error paths.

Suggested-by: Eric Blake 
Signed-off-by: Laszlo Ersek 
---
 qga/commands-posix.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 2eec712..e199738 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -355,6 +355,9 @@ safe_open_or_create(const char *path, const char *mode, 
Error **err)
 }
 
 close(fd);
+if (oflag & O_CREAT) {
+unlink(path);
+}
 }
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH v2 1/2] qga: distinguish binary modes in "guest_file_open_modes" map

2013-05-08 Thread Laszlo Ersek
In Windows guests this may make a difference.

Since the original patch (commit c689b4f1) sought to be pedantic and to
consider theoretical corner cases of portability, we should fix it up
where it failed to come through in that pursuit.

Suggested-by: Eric Blake 
Reviewed-by: Eric Blake 
Signed-off-by: Laszlo Ersek 
---
 qga/commands-posix.c |   22 --
 1 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 04c6951..2eec712 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -242,17 +242,27 @@ static GuestFileHandle *guest_file_handle_find(int64_t 
id, Error **err)
 
 typedef const char * const ccpc;
 
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
 /* http://pubs.opengroup.org/onlinepubs/9699919799/functions/fopen.html */
 static const struct {
 ccpc *forms;
 int oflag_base;
 } guest_file_open_modes[] = {
-{ (ccpc[]){ "r",  "rb", NULL }, O_RDONLY  },
-{ (ccpc[]){ "w",  "wb", NULL }, O_WRONLY | O_CREAT | O_TRUNC  },
-{ (ccpc[]){ "a",  "ab", NULL }, O_WRONLY | O_CREAT | O_APPEND },
-{ (ccpc[]){ "r+", "rb+", "r+b", NULL }, O_RDWR},
-{ (ccpc[]){ "w+", "wb+", "w+b", NULL }, O_RDWR   | O_CREAT | O_TRUNC  },
-{ (ccpc[]){ "a+", "ab+", "a+b", NULL }, O_RDWR   | O_CREAT | O_APPEND }
+{ (ccpc[]){ "r",  NULL }, O_RDONLY 
},
+{ (ccpc[]){ "rb", NULL }, O_RDONLY  | O_BINARY 
},
+{ (ccpc[]){ "w",  NULL }, O_WRONLY | O_CREAT | O_TRUNC 
},
+{ (ccpc[]){ "wb", NULL }, O_WRONLY | O_CREAT | O_TRUNC  | O_BINARY 
},
+{ (ccpc[]){ "a",  NULL }, O_WRONLY | O_CREAT | O_APPEND
},
+{ (ccpc[]){ "ab", NULL }, O_WRONLY | O_CREAT | O_APPEND | O_BINARY 
},
+{ (ccpc[]){ "r+", NULL }, O_RDWR   
},
+{ (ccpc[]){ "rb+", "r+b", NULL }, O_RDWR| O_BINARY 
},
+{ (ccpc[]){ "w+", NULL }, O_RDWR   | O_CREAT | O_TRUNC 
},
+{ (ccpc[]){ "wb+", "w+b", NULL }, O_RDWR   | O_CREAT | O_TRUNC  | O_BINARY 
},
+{ (ccpc[]){ "a+", NULL }, O_RDWR   | O_CREAT | O_APPEND
},
+{ (ccpc[]){ "ab+", "a+b", NULL }, O_RDWR   | O_CREAT | O_APPEND | O_BINARY 
}
 };
 
 static int
-- 
1.7.1





Re: [Qemu-devel] [PATCH] PPC: Depend behavior of cmp instructions only on instruction encoding

2013-05-08 Thread Aurelien Jarno
On Wed, May 08, 2013 at 04:48:22PM +0200, Torbjorn Granlund wrote:
> Aurelien Jarno  writes:
> 
>   That said this does implement neither the specification nor the silicon
>   behaviour. This is fine for 1.5 as we are in freeze period, but this 
>   should be fixed for the 1.6 release.
> 
> I talked to IBM now.  Reserved fields should be ignored by hardware.

As it seems you have good contact with IBM, could you please ask them
to fix their manuals?

> The architecture owner is IBM, not Freescale.  That Freescale deviates
> from the architecture, is something that you may decide to ignore,
> unless it is vital for qemu's behaviour in practice.

At least Freescale CPUs matches what IBM documentation says. IBM CPUs
doesn't.

> I very much doubt that L = 1 often, for code targeting a 32-bit
> processor.
> 
> Trying to mimic decoding flaws on a per-processor basis, is going to
> take a lot of research, and will be prone to errors.
> 
> So as far as I can tell, the patch is correct as per the architecture
> specification.

No it's not correct, it doesn't match neither Freescale nor IBM
behaviour. It also means the same code executed on a 32-bit emulated CPU
run with qemu-system-ppc will behave differently than when run with
qemu-system-ppc64. This is fine for now as we are in freeze period, but
should be fixed afterwards.

> One caveat though: Does 32-bit implementations define the SF bit, or
> else, does qemu define it and make sure it is 0 for 32-bit emulation?
> If not, the patch might cause trouble.

QEMU makes sure it is 0 for 32-bit CPU.

> Congrats, you read a "user message" until the last line.  :-)
> 

Like I did for the previous one. Would be nice if you can do the same.

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



[Qemu-devel] [PATCH 02/10] de_DE.po: Add missing leading spaces

2013-05-08 Thread Kevin Wolf
Signed-off-by: Kevin Wolf 
---
 po/de_DE.po | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/po/de_DE.po b/po/de_DE.po
index 92c5df5..e35aaf4 100644
--- a/po/de_DE.po
+++ b/po/de_DE.po
@@ -18,11 +18,11 @@ msgstr ""
 
 #: ../ui/gtk.c:213
 msgid " - Press Ctrl+Alt+G to release grab"
-msgstr "- Strg+Alt+G drücken, um Eingabegeräte freizugeben"
+msgstr " - Strg+Alt+G drücken, um Eingabegeräte freizugeben"
 
 #: ../ui/gtk.c:217
 msgid " [Paused]"
-msgstr "[Angehalten]"
+msgstr " [Angehalten]"
 
 #: ../ui/gtk.c:1250
 msgid "_Machine"
-- 
1.8.1.4




[Qemu-devel] [PATCH 04/10] libqos/pci: Enable bus mastering

2013-05-08 Thread Kevin Wolf
Signed-off-by: Kevin Wolf 
---
 tests/libqos/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/libqos/pci.c b/tests/libqos/pci.c
index 95e287b..7e0907b 100644
--- a/tests/libqos/pci.c
+++ b/tests/libqos/pci.c
@@ -71,7 +71,7 @@ void qpci_device_enable(QPCIDevice *dev)
 
 /* FIXME -- does this need to be a bus callout? */
 cmd = qpci_config_readw(dev, PCI_COMMAND);
-cmd |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY;
+cmd |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
 qpci_config_writew(dev, PCI_COMMAND, cmd);
 }
 
-- 
1.8.1.4




Re: [Qemu-devel] [PATCH] PPC: Depend behavior of cmp instructions only on instruction encoding

2013-05-08 Thread Torbjorn Granlund
Aurelien Jarno  writes:

  That said this does implement neither the specification nor the silicon
  behaviour. This is fine for 1.5 as we are in freeze period, but this 
  should be fixed for the 1.6 release.

I talked to IBM now.  Reserved fields should be ignored by hardware.

The architecture owner is IBM, not Freescale.  That Freescale deviates
from the architecture, is something that you may decide to ignore,
unless it is vital for qemu's behaviour in practice.

I very much doubt that L = 1 often, for code targeting a 32-bit
processor.

Trying to mimic decoding flaws on a per-processor basis, is going to
take a lot of research, and will be prone to errors.

So as far as I can tell, the patch is correct as per the architecture
specification.

One caveat though: Does 32-bit implementations define the SF bit, or
else, does qemu define it and make sure it is 0 for 32-bit emulation?
If not, the patch might cause trouble.

Congrats, you read a "user message" until the last line.  :-)

-- 
Torbjörn



[Qemu-devel] [PATCH 01/10] ahci: Don't allow creating slave drives

2013-05-08 Thread Kevin Wolf
An IDE bus provided by AHCI can only take a single IDE drive. If you add
a drive as slave, qemu used to accept the command line but the device
wouldn't be actually usable. Catch the situation instead and error out.

Signed-off-by: Kevin Wolf 
---
 hw/ide/ahci.c |  2 +-
 hw/ide/cmd646.c   |  2 +-
 hw/ide/internal.h |  3 ++-
 hw/ide/isa.c  |  2 +-
 hw/ide/macio.c|  2 +-
 hw/ide/mmio.c |  2 +-
 hw/ide/piix.c |  2 +-
 hw/ide/qdev.c | 10 +-
 hw/ide/via.c  |  2 +-
 9 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index 3405583..eab6096 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -1163,7 +1163,7 @@ void ahci_init(AHCIState *s, DeviceState *qdev, 
DMAContext *dma, int ports)
 for (i = 0; i < s->ports; i++) {
 AHCIDevice *ad = &s->dev[i];
 
-ide_bus_new(&ad->port, qdev, i);
+ide_bus_new(&ad->port, qdev, i, 1);
 ide_init2(&ad->port, irqs[i]);
 
 ad->hba = s;
diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c
index 541d4ef..a73eb9a 100644
--- a/hw/ide/cmd646.c
+++ b/hw/ide/cmd646.c
@@ -281,7 +281,7 @@ static int pci_cmd646_ide_initfn(PCIDevice *dev)
 
 irq = qemu_allocate_irqs(cmd646_set_irq, d, 2);
 for (i = 0; i < 2; i++) {
-ide_bus_new(&d->bus[i], &d->dev.qdev, i);
+ide_bus_new(&d->bus[i], &d->dev.qdev, i, 2);
 ide_init2(&d->bus[i], irq[i]);
 
 bmdma_init(&d->bus[i], &d->bmdma[i], d);
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 0efb2da..03f1489 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -450,6 +450,7 @@ struct IDEBus {
 IDEDevice *slave;
 IDEState ifs[2];
 int bus_id;
+int max_units;
 IDEDMA *dma;
 uint8_t unit;
 uint8_t cmd;
@@ -574,7 +575,7 @@ void ide_atapi_cmd(IDEState *s);
 void ide_atapi_cmd_reply_end(IDEState *s);
 
 /* hw/ide/qdev.c */
-void ide_bus_new(IDEBus *idebus, DeviceState *dev, int bus_id);
+void ide_bus_new(IDEBus *idebus, DeviceState *dev, int bus_id, int max_units);
 IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive);
 
 #endif /* HW_IDE_INTERNAL_H */
diff --git a/hw/ide/isa.c b/hw/ide/isa.c
index 5e7422f..369a7fa 100644
--- a/hw/ide/isa.c
+++ b/hw/ide/isa.c
@@ -69,7 +69,7 @@ static int isa_ide_initfn(ISADevice *dev)
 {
 ISAIDEState *s = ISA_IDE(dev);
 
-ide_bus_new(&s->bus, DEVICE(dev), 0);
+ide_bus_new(&s->bus, DEVICE(dev), 0, 2);
 ide_init_ioport(&s->bus, dev, s->iobase, s->iobase2);
 isa_init_irq(dev, &s->irq, s->isairq);
 ide_init2(&s->bus, s->irq);
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index 64b2406..bf12a10 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -334,7 +334,7 @@ static void macio_ide_initfn(Object *obj)
 SysBusDevice *d = SYS_BUS_DEVICE(obj);
 MACIOIDEState *s = MACIO_IDE(obj);
 
-ide_bus_new(&s->bus, DEVICE(obj), 0);
+ide_bus_new(&s->bus, DEVICE(obj), 0, 2);
 memory_region_init_io(&s->mem, &pmac_ide_ops, s, "pmac-ide", 0x1000);
 sysbus_init_mmio(d, &s->mem);
 sysbus_init_irq(d, &s->irq);
diff --git a/hw/ide/mmio.c b/hw/ide/mmio.c
index ce88c3a..e80e7e5 100644
--- a/hw/ide/mmio.c
+++ b/hw/ide/mmio.c
@@ -137,7 +137,7 @@ static void mmio_ide_initfn(Object *obj)
 SysBusDevice *d = SYS_BUS_DEVICE(obj);
 MMIOState *s = MMIO_IDE(obj);
 
-ide_bus_new(&s->bus, DEVICE(obj), 0);
+ide_bus_new(&s->bus, DEVICE(obj), 0, 2);
 sysbus_init_irq(d, &s->irq);
 }
 
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index 1de284d..bf2856f 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -135,7 +135,7 @@ static void pci_piix_init_ports(PCIIDEState *d) {
 int i;
 
 for (i = 0; i < 2; i++) {
-ide_bus_new(&d->bus[i], &d->dev.qdev, i);
+ide_bus_new(&d->bus[i], &d->dev.qdev, i, 2);
 ide_init_ioport(&d->bus[i], NULL, port_info[i].iobase,
 port_info[i].iobase2);
 ide_init2(&d->bus[i], isa_get_irq(NULL, port_info[i].isairq));
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 8a9a891..6a272b0 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -47,10 +47,11 @@ static const TypeInfo ide_bus_info = {
 .class_init = ide_bus_class_init,
 };
 
-void ide_bus_new(IDEBus *idebus, DeviceState *dev, int bus_id)
+void ide_bus_new(IDEBus *idebus, DeviceState *dev, int bus_id, int max_units)
 {
 qbus_create_inplace(&idebus->qbus, TYPE_IDE_BUS, dev, NULL);
 idebus->bus_id = bus_id;
+idebus->max_units = max_units;
 }
 
 static char *idebus_get_fw_dev_path(DeviceState *dev)
@@ -76,6 +77,13 @@ static int ide_qdev_init(DeviceState *qdev)
 if (dev->unit == -1) {
 dev->unit = bus->master ? 1 : 0;
 }
+
+if (dev->unit >= bus->max_units) {
+error_report("Can't create IDE unit %d, bus supports only %d units",
+ dev->unit, bus->max_units);
+goto err;
+}
+
 switch (dev->unit) {
 case 0:
 if (bus->master) {
diff --git a/hw/ide/via.c b/hw/ide/via.c
index 9d6a644..5fe053c 10064

[Qemu-devel] [PATCH 06/10] qtest/ide-test: Add simple DMA read/write test case

2013-05-08 Thread Kevin Wolf
This tests that single sectors can be successfully written and correctly
read back.

Signed-off-by: Kevin Wolf 
---
 tests/ide-test.c | 221 +++
 1 file changed, 221 insertions(+)

diff --git a/tests/ide-test.c b/tests/ide-test.c
index 45036e3..5fc496f 100644
--- a/tests/ide-test.c
+++ b/tests/ide-test.c
@@ -29,8 +29,12 @@
 #include 
 
 #include "libqtest.h"
+#include "libqos/pci-pc.h"
+#include "libqos/malloc-pc.h"
 
 #include "qemu-common.h"
+#include "hw/pci/pci_ids.h"
+#include "hw/pci/pci_regs.h"
 
 #define TEST_IMAGE_SIZE 64 * 1024 * 1024
 
@@ -60,12 +64,42 @@ enum {
 };
 
 enum {
+LBA = 0x40,
+};
+
+enum {
+bmreg_cmd   = 0x0,
+bmreg_status= 0x2,
+bmreg_prdt  = 0x4,
+};
+
+enum {
+CMD_READ_DMA= 0xc8,
+CMD_WRITE_DMA   = 0xca,
 CMD_IDENTIFY= 0xec,
 };
 
+enum {
+BM_CMD_START=  0x1,
+BM_CMD_WRITE=  0x8, /* write = from device to memory */
+};
+
+enum {
+BM_STS_ACTIVE   =  0x1,
+BM_STS_ERROR=  0x2,
+BM_STS_INTR =  0x4,
+};
+
+enum {
+PRDT_EOT= 0x8000,
+};
+
 #define assert_bit_set(data, mask) g_assert_cmphex((data) & (mask), ==, (mask))
 #define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==, 0)
 
+static QPCIBus *pcibus = NULL;
+static QGuestAllocator *guest_malloc;
+
 static char tmp_path[] = "/tmp/qtest.XX";
 
 static void ide_test_start(const char *cmdline_fmt, ...)
@@ -79,6 +113,7 @@ static void ide_test_start(const char *cmdline_fmt, ...)
 
 qtest_start(cmdline);
 qtest_irq_intercept_in(global_qtest, "ioapic");
+guest_malloc = pc_alloc_init();
 }
 
 static void ide_test_quit(void)
@@ -86,6 +121,188 @@ static void ide_test_quit(void)
 qtest_quit(global_qtest);
 }
 
+static QPCIDevice *get_pci_device(uint16_t *bmdma_base)
+{
+QPCIDevice *dev;
+uint16_t vendor_id, device_id;
+
+if (!pcibus) {
+pcibus = qpci_init_pc();
+}
+
+/* Find PCI device and verify it's the right one */
+dev = qpci_device_find(pcibus, QPCI_DEVFN(IDE_PCI_DEV, IDE_PCI_FUNC));
+g_assert(dev != NULL);
+
+vendor_id = qpci_config_readw(dev, PCI_VENDOR_ID);
+device_id = qpci_config_readw(dev, PCI_DEVICE_ID);
+g_assert(vendor_id == PCI_VENDOR_ID_INTEL);
+g_assert(device_id == PCI_DEVICE_ID_INTEL_82371SB_1);
+
+/* Map bmdma BAR */
+*bmdma_base = (uint16_t)(uintptr_t) qpci_iomap(dev, 4);
+
+qpci_device_enable(dev);
+
+return dev;
+}
+
+static void free_pci_device(QPCIDevice *dev)
+{
+/* libqos doesn't have a function for this, so free it manually */
+g_free(dev);
+}
+
+typedef struct PrdtEntry {
+uint32_t addr;
+uint32_t size;
+} QEMU_PACKED PrdtEntry;
+
+#define assert_bit_set(data, mask) g_assert_cmphex((data) & (mask), ==, (mask))
+#define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==, 0)
+
+static int send_dma_request(int cmd, uint64_t sector, int nb_sectors,
+PrdtEntry *prdt, int prdt_entries)
+{
+QPCIDevice *dev;
+uint16_t bmdma_base;
+uintptr_t guest_prdt;
+size_t len;
+bool from_dev;
+uint8_t status;
+
+dev = get_pci_device(&bmdma_base);
+
+switch (cmd) {
+case CMD_READ_DMA:
+from_dev = true;
+break;
+case CMD_WRITE_DMA:
+from_dev = false;
+break;
+default:
+g_assert_not_reached();
+}
+
+/* Select device 0 */
+outb(IDE_BASE + reg_device, 0 | LBA);
+
+/* Stop any running transfer, clear any pending interrupt */
+outb(bmdma_base + bmreg_cmd, 0);
+outb(bmdma_base + bmreg_status, BM_STS_INTR);
+
+/* Setup PRDT */
+len = sizeof(*prdt) * prdt_entries;
+guest_prdt = guest_alloc(guest_malloc, len);
+memwrite(guest_prdt, prdt, len);
+outl(bmdma_base + bmreg_prdt, guest_prdt);
+
+/* ATA DMA command */
+outb(IDE_BASE + reg_nsectors, nb_sectors);
+
+outb(IDE_BASE + reg_lba_low,sector & 0xff);
+outb(IDE_BASE + reg_lba_middle, (sector >> 8) & 0xff);
+outb(IDE_BASE + reg_lba_high,   (sector >> 16) & 0xff);
+
+outb(IDE_BASE + reg_command, cmd);
+
+/* Start DMA transfer */
+outb(bmdma_base + bmreg_cmd, BM_CMD_START | (from_dev ? BM_CMD_WRITE : 0));
+
+/* Wait for the DMA transfer to complete */
+do {
+status = inb(bmdma_base + bmreg_status);
+} while ((status & (BM_STS_ACTIVE | BM_STS_INTR)) == BM_STS_ACTIVE);
+
+g_assert_cmpint(get_irq(IDE_PRIMARY_IRQ), ==, !!(status & BM_STS_INTR));
+
+/* Check IDE status code */
+assert_bit_set(inb(IDE_BASE + reg_status), DRDY);
+assert_bit_clear(inb(IDE_BASE + reg_status), BSY | DRQ);
+
+/* Reading the status register clears the IRQ */
+g_assert(!get_irq(IDE_PRIMARY_IRQ));
+
+/* Stop DMA transfer if still active */
+if (status & BM_STS_ACTIVE) {
+outb(bmdma_base + bmreg_cmd, 0);
+}
+
+free_pci_device(dev);
+
+return status;
+}
+
+static void test_bmdma_simple_rw

Re: [Qemu-devel] [PATCH] ahci: Don't allow creating slave drives

2013-05-08 Thread Stefan Hajnoczi
On Mon, May 06, 2013 at 04:02:58PM +0200, Kevin Wolf wrote:
> An IDE bus provided by AHCI can only take a single IDE drive. If you add
> a drive as slave, qemu used to accept the command line but the device
> wouldn't be actually usable. Catch the situation instead and error out.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  hw/ide/ahci.c |  2 +-
>  hw/ide/cmd646.c   |  2 +-
>  hw/ide/internal.h |  3 ++-
>  hw/ide/isa.c  |  2 +-
>  hw/ide/macio.c|  2 +-
>  hw/ide/mmio.c |  2 +-
>  hw/ide/piix.c |  2 +-
>  hw/ide/qdev.c | 10 +-
>  hw/ide/via.c  |  2 +-
>  9 files changed, 18 insertions(+), 9 deletions(-)

Reviewed-by: Stefan Hajnoczi 



[Qemu-devel] [PATCH 03/10] ide: Reset BMIDEA bit when the bus master is stopped

2013-05-08 Thread Kevin Wolf
The device is supposed to reset the Bus Master IDE Active bit in the
status register when 0 is written to the Start/Stop Bus Master bit in
the command register.

In the common cases this happens automatically because bdrv_drain_all()
flushes the requests, but with a large PRDT it could remain set.

Signed-off-by: Kevin Wolf 
---
 hw/ide/pci.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/ide/pci.c b/hw/ide/pci.c
index a310975..635a364 100644
--- a/hw/ide/pci.c
+++ b/hw/ide/pci.c
@@ -312,6 +312,7 @@ void bmdma_cmd_writeb(BMDMAState *bm, uint32_t val)
 bdrv_drain_all();
 assert(bm->bus->dma->aiocb == NULL);
 }
+bm->status &= ~BM_STATUS_DMAING;
 } else {
 bm->cur_addr = bm->addr;
 if (!(bm->status & BM_STATUS_DMAING)) {
-- 
1.8.1.4




[Qemu-devel] [PATCH 10/10] qemu-iotests: fix 017 018 for vmdk

2013-05-08 Thread Kevin Wolf
From: Fam Zheng 

017 and 018 use /bin/mv to move base img from t.IMGFMG to t.IMGFMT.base
after filling data, this is not enough for vmdk, when t.IMGFMT is only a
description text file who points to t-{flat,s001,f001,...}.IMGFMT as
data extent, so testing such subformats alway fails on them.

This patch use the trick of temprorily changing TEST_IMG to avoid using
/bin/mv.

Signed-off-by: Fam Zheng 
Reviewed-by: Jeff Cody 
Signed-off-by: Kevin Wolf 
---
 tests/qemu-iotests/017 | 4 +++-
 tests/qemu-iotests/017.out | 2 +-
 tests/qemu-iotests/018 | 4 +++-
 tests/qemu-iotests/018.out | 2 +-
 4 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/tests/qemu-iotests/017 b/tests/qemu-iotests/017
index 66951eb..45f2c0b 100755
--- a/tests/qemu-iotests/017
+++ b/tests/qemu-iotests/017
@@ -46,6 +46,8 @@ _supported_os Linux
 
 TEST_OFFSETS="0 4294967296"
 
+TEST_IMG_SAVE=$TEST_IMG
+TEST_IMG=$TEST_IMG.base
 _make_test_img 6G
 
 echo "Filling base image"
@@ -63,7 +65,7 @@ _check_test_img
 echo "Creating test image with backing file"
 echo
 
-mv $TEST_IMG $TEST_IMG.base
+TEST_IMG=$TEST_IMG_SAVE
 _make_test_img -b $TEST_IMG.base 6G
 
 echo "Filling test image"
diff --git a/tests/qemu-iotests/017.out b/tests/qemu-iotests/017.out
index a861e58..df34ee7 100644
--- a/tests/qemu-iotests/017.out
+++ b/tests/qemu-iotests/017.out
@@ -1,5 +1,5 @@
 QA output created by 017
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=6442450944 
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=6442450944
 Filling base image
 
 === IO: pattern 0
diff --git a/tests/qemu-iotests/018 b/tests/qemu-iotests/018
index bd2db78..453ce61 100755
--- a/tests/qemu-iotests/018
+++ b/tests/qemu-iotests/018
@@ -46,6 +46,8 @@ _supported_os Linux
 
 TEST_OFFSETS="0 4294967296"
 
+TEST_IMG_SAVE=$TEST_IMG
+TEST_IMG=$TEST_IMG.base
 _make_test_img 6G
 
 echo "Filling base image"
@@ -63,7 +65,7 @@ _check_test_img
 echo "Creating test image with backing file"
 echo
 
-mv $TEST_IMG $TEST_IMG.base
+TEST_IMG=$TEST_IMG_SAVE
 _make_test_img -b $TEST_IMG.base 6G
 
 echo "Filling test image"
diff --git a/tests/qemu-iotests/018.out b/tests/qemu-iotests/018.out
index 6bbd815..3ddb8d8 100644
--- a/tests/qemu-iotests/018.out
+++ b/tests/qemu-iotests/018.out
@@ -1,5 +1,5 @@
 QA output created by 018
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=6442450944 
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=6442450944
 Filling base image
 
 === IO: pattern 0
-- 
1.8.1.4




[Qemu-devel] [PATCH 05/10] qtest: Add IDE test case

2013-05-08 Thread Kevin Wolf
This adds a simple IDE test case and starts by verifying that IDENTIFY
can be successfully used and return the correct serial number, version
and the WCE flag is set for cache=writeback.

Signed-off-by: Kevin Wolf 
---
 tests/Makefile   |   2 +
 tests/ide-test.c | 165 +++
 2 files changed, 167 insertions(+)
 create mode 100644 tests/ide-test.c

diff --git a/tests/Makefile b/tests/Makefile
index bf41d10..a307d5a 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -51,6 +51,7 @@ check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 # really in libqtest, not in the testcases themselves.
 check-qtest-i386-y = tests/fdc-test$(EXESUF)
 gcov-files-i386-y = hw/fdc.c
+check-qtest-i386-y += tests/ide-test$(EXESUF)
 check-qtest-i386-y += tests/hd-geo-test$(EXESUF)
 gcov-files-i386-y += hw/hd-geometry.c
 check-qtest-i386-y += tests/rtc-test$(EXESUF)
@@ -127,6 +128,7 @@ libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o
 tests/rtc-test$(EXESUF): tests/rtc-test.o
 tests/m48t59-test$(EXESUF): tests/m48t59-test.o
 tests/fdc-test$(EXESUF): tests/fdc-test.o
+tests/ide-test$(EXESUF): tests/ide-test.o $(libqos-pc-obj-y)
 tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o
 tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y)
 tests/i440fx-test$(EXESUF): tests/i440fx-test.o $(libqos-pc-obj-y)
diff --git a/tests/ide-test.c b/tests/ide-test.c
new file mode 100644
index 000..45036e3
--- /dev/null
+++ b/tests/ide-test.c
@@ -0,0 +1,165 @@
+/*
+ * IDE test cases
+ *
+ * Copyright (c) 2013 Kevin Wolf 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+
+#include "libqtest.h"
+
+#include "qemu-common.h"
+
+#define TEST_IMAGE_SIZE 64 * 1024 * 1024
+
+#define IDE_PCI_DEV 1
+#define IDE_PCI_FUNC1
+
+#define IDE_BASE 0x1f0
+#define IDE_PRIMARY_IRQ 14
+
+enum {
+reg_data= 0x0,
+reg_nsectors= 0x2,
+reg_lba_low = 0x3,
+reg_lba_middle  = 0x4,
+reg_lba_high= 0x5,
+reg_device  = 0x6,
+reg_status  = 0x7,
+reg_command = 0x7,
+};
+
+enum {
+BSY = 0x80,
+DRDY= 0x40,
+DF  = 0x20,
+DRQ = 0x08,
+ERR = 0x01,
+};
+
+enum {
+CMD_IDENTIFY= 0xec,
+};
+
+#define assert_bit_set(data, mask) g_assert_cmphex((data) & (mask), ==, (mask))
+#define assert_bit_clear(data, mask) g_assert_cmphex((data) & (mask), ==, 0)
+
+static char tmp_path[] = "/tmp/qtest.XX";
+
+static void ide_test_start(const char *cmdline_fmt, ...)
+{
+va_list ap;
+char *cmdline;
+
+va_start(ap, cmdline_fmt);
+cmdline = g_strdup_vprintf(cmdline_fmt, ap);
+va_end(ap);
+
+qtest_start(cmdline);
+qtest_irq_intercept_in(global_qtest, "ioapic");
+}
+
+static void ide_test_quit(void)
+{
+qtest_quit(global_qtest);
+}
+
+static void test_identify(void)
+{
+uint8_t data;
+uint16_t buf[256];
+int i;
+int ret;
+
+ide_test_start(
+"-vnc none "
+"-drive file=%s,if=ide,serial=%s,cache=writeback "
+"-global ide-hd.ver=%s",
+tmp_path, "testdisk", "version");
+
+/* IDENTIFY command on device 0*/
+outb(IDE_BASE + reg_device, 0);
+outb(IDE_BASE + reg_command, CMD_IDENTIFY);
+
+/* Read in the IDENTIFY buffer and check registers */
+data = inb(IDE_BASE + reg_device);
+g_assert_cmpint(data & 0x10, ==, 0);
+
+for (i = 0; i < 256; i++) {
+data = inb(IDE_BASE + reg_status);
+assert_bit_set(data, DRDY | DRQ);
+assert_bit_clear(data, BSY | DF | ERR);
+
+((uint16_t*) buf)[i] = inw(IDE_BASE + reg_data);
+}
+
+data = inb(IDE_BASE + reg_status);
+assert_bit_set(data, DRDY);
+assert_bit_clear(data, BSY | DF | ERR | DRQ);
+
+/* Check serial number/version in the buffer */
+ret = memcmp(&buf[10], "ettsidks", 20);
+g_assert(ret == 0);
+
+ret = memcmp(&buf[23], "evs

  1   2   3   >