[Qemu-devel] [PATCH] monitor: fix client_migrate_info error handling

2012-03-18 Thread Yonit Halperin
Report QERR_INVALID_PARAMETER when port is missing. Otherwise
QERR_UNDEFINED_ERROR will occur.

rhbz #795652

Signed-off-by: Yonit Halperin 
---
 monitor.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/monitor.c b/monitor.c
index d57e7bf..8f46031 100644
--- a/monitor.c
+++ b/monitor.c
@@ -880,6 +880,11 @@ static int client_migrate_info(Monitor *mon, const QDict 
*qdict,
 return -1;
 }
 
+if (port == -1 && tls_port == -1) {
+qerror_report(QERR_MISSING_PARAMETER, "port/tls-port");
+return -1;
+}
+
 ret = qemu_spice_migrate_info(hostname, port, tls_port, subject,
   cb, opaque);
 if (ret != 0) {
-- 
1.7.7.6




[Qemu-devel] [PATCH] Makefile.target: code stp dependency on trace-events

2012-03-18 Thread Alon Levy
Signed-off-by: Alon Levy 
---
 Makefile.target |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.target b/Makefile.target
index eb25941..5c62edb 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -58,7 +58,7 @@ else
 TARGET_TYPE=system
 endif
 
-$(QEMU_PROG).stp:
+$(QEMU_PROG).stp: $(SRC_PATH)/trace-events
$(call quiet-command,sh $(SRC_PATH)/scripts/tracetool \
--$(TRACE_BACKEND) \
--binary $(bindir)/$(QEMU_PROG) \
-- 
1.7.9.3




Re: [Qemu-devel] [PATCH 0/5] VMWare PVSCSI paravirtual device implementation

2012-03-18 Thread Gerhard Wiesinger

Hello Dmitry,

Is PVSCSI also ready to boot through BIOS Int 13h?
If not, do you plan a SEABIOS patch?

Thnx.

Ciao,
Gerhard

On 15.03.2012 10:02, Dmitry Fleytman wrote:

Below is the implementation of VMWare PVSCSI device and
command line parameters to configure vendor name and product name
for SCSI storage are implemented.
Latter is needed to make PVSCSI storage devices look exactly as
on VMWare hypervisors.

With this and VMWARE3 patches V2V migration problem for VMWare
images should be solved relatively easy.

PVSCSI implementation is based on Paolo Bonzini code sumbitted
some time ago but never applied.
See commit messages and file headers for details.

Implementation supports of all the device features.
Code was tested on different OSes:
 Fedora 15
 Ubuntu 10.4
 Centos 6.2
 Windows 2008R2
 Windows 2008 64bit
 Windows 2008 32bit
 Windows 2003 64bit
 Windows 2003 32bit

Dmitry Fleytman (5):
   Utility function strpadcpy() added
   Vendor name and product name parameters for SCSI devices Options
 "vendor_name" and "product_name" added for SCSI disks.
   Header with various utility functions shared by VMWARE SCSI and
 network devices
   PVCSI paravirtualized device implementation
   PVSCSI paravirtualized device integration Bus type "pvscsi"
 added.

  Makefile.objs  |1 +
  blockdev.c |   12 +-
  blockdev.h |   16 +-
  cutils.c   |   13 +
  default-configs/pci.mak|1 +
  docs/specs/pvscsi-spec.txt |   92 
  hw/pc.c|5 +
  hw/pci-hotplug.c   |7 +-
  hw/pci.h   |1 +
  hw/pvscsi.c| 1242 
  hw/pvscsi.h|  442 
  hw/scsi-bus.c  |   14 +-
  hw/scsi-disk.c |   51 ++-
  hw/scsi.h  |1 +
  hw/vmware_utils.h  |  122 +
  qemu-common.h  |1 +
  16 files changed, 1997 insertions(+), 24 deletions(-)
  create mode 100644 docs/specs/pvscsi-spec.txt
  create mode 100644 hw/pvscsi.c
  create mode 100644 hw/pvscsi.h
  create mode 100644 hw/vmware_utils.h






Re: [Qemu-devel] [PATCH v4 0/9] VMXNET3 paravirtual NIC device implementation

2012-03-18 Thread Gerhard Wiesinger

Hello,

I'm still having problems with v4 patch: ping works well, even with 
large packet sizes but ssh doesn't work at all.

Tested with Knoppix 6.7 and Fedora 16.

Thnx.

Ciao,
Gerhard

On 15.03.2012 22:08, Dmitry Fleytman wrote:

This set of patches implements VMWare VMXNET3 paravirtual NIC device.
The device supports of all the device features including offload capabilties,
VLANs and etc.
The device is tested on different OSes:
 Fedora 15
 Ubuntu 10.4
 Centos 6.2
 Windows 2008R2
 Windows 2008 64bit
 Windows 2008 32bit
 Windows 2003 64bit
 Windows 2003 32bit

Changes in V4:
Fixed a few problems uncovered by NETIO test suit
Assertion on failure to initialize MSI/MSI-X replaced with warning
message and fallback to Legacy/MSI respectively

  Reported-by: Gerhard Wiesinger

Various coding style adjustments and patch split-up as suggested by Anthony 
Liguori

  Reported-by: Anthony Liguori

Live migration support added

Changes in V3:
Fixed crash when net device that is used as network fronted has no
virtio HDR support.
Task offloads emulation for cases when net device that is used as
network fronted has no virtio HDR support.

  Reported-by: Gerhard Wiesinger

Changes in V2:
License text changed accoring to community suggestions
Standard license header from GPLv2+ - licensed QEMU files used

Dmitry Fleytman (9):
   Adding missing flag VIRTIO_NET_HDR_F_DATA_VALID from Linux kernel
 source tre Reformatting comments according to checkpatch.pl
 requirements
   Adding utility function net_checksum_add_cont() that allows checksum
calculation of scattered data with odd chunk sizes
   Adding utility function iov_net_csum_add() for iovec checksum
 calculation
   MSI-X state save/load invocations moved to PCI Device save/load
 callbacks to avoid code duplication in MSI-X-enabled devices
 that support live migration
   Header with various utility functions shared by VMWARE SCSI and
 network devi
   Various utility functions used by VMWARE network devices
   Packet abstraction used by VMWARE network devices
   VMXNET3 paravirtual device implementation
   VMXNET3 paravirtualized device integration. Interface type
 "vmxnet3" added.

  Makefile.objs   |1 +
  default-configs/pci.mak |1 +
  hw/pci.c|7 +
  hw/pci.h|1 +
  hw/virtio-net.h |   13 +-
  hw/virtio-pci.c |2 -
  hw/vmware_utils.h   |  122 +++
  hw/vmxnet3.c| 2435 +++
  hw/vmxnet3.h|  757 +++
  hw/vmxnet_debug.h   |  121 +++
  hw/vmxnet_pkt.c | 1243 
  hw/vmxnet_pkt.h |  479 ++
  hw/vmxnet_utils.c   |  165 
  hw/vmxnet_utils.h   |  320 +++
  iov.c   |   29 +
  iov.h   |3 +
  net.c   |2 +-
  net/checksum.c  |   13 +-
  net/checksum.h  |   14 +-
  19 files changed, 5712 insertions(+), 16 deletions(-)
  create mode 100644 hw/vmware_utils.h
  create mode 100644 hw/vmxnet3.c
  create mode 100644 hw/vmxnet3.h
  create mode 100644 hw/vmxnet_debug.h
  create mode 100644 hw/vmxnet_pkt.c
  create mode 100644 hw/vmxnet_pkt.h
  create mode 100644 hw/vmxnet_utils.c
  create mode 100644 hw/vmxnet_utils.h






Re: [Qemu-devel] [PATCH 5/5] PVSCSI paravirtualized device integration Bus type "pvscsi" added.

2012-03-18 Thread Dmitry Fleytman
Good point. Fixed. Thanks.

On Thu, Mar 15, 2012 at 11:46 AM, Paolo Bonzini  wrote:
> Il 15/03/2012 10:02, Dmitry Fleytman ha scritto:
>> Sample command line for pvscsi-based disk is:
>>     -drive file=image.raw,if=none,cache=off,id=pvscsi1 \
>>     -device pvscsi,id=pvscsi -device scsi-disk,drive=pvscsi1,bus=pvscsi.0 \
>>
>> Signed-off-by: Dmitry Fleytman 
>> Signed-off-by: Yan Vugenfirer 
>> ---
>>  Makefile.objs           |    1 +
>>  blockdev.c              |   12 
>>  blockdev.h              |   10 +-
>>  default-configs/pci.mak |    1 +
>>  hw/pc.c                 |    5 +
>>  hw/pci-hotplug.c        |    7 ++-
>>  hw/pci.h                |    1 +
>>  hw/scsi-bus.c           |   14 --
>>  hw/scsi.h               |    1 +
>>  9 files changed, 44 insertions(+), 8 deletions(-)
>>
>> diff --git a/Makefile.objs b/Makefile.objs
>> index 226b01d..bf0a351 100644
>> --- a/Makefile.objs
>> +++ b/Makefile.objs
>> @@ -304,6 +304,7 @@ hw-obj-$(CONFIG_AHCI) += ide/ich.o
>>
>>  # SCSI layer
>>  hw-obj-$(CONFIG_LSI_SCSI_PCI) += lsi53c895a.o
>> +hw-obj-$(CONFIG_PVSCSI_SCSI_PCI) += pvscsi.o
>>  hw-obj-$(CONFIG_ESP) += esp.o
>>
>>  hw-obj-y += dma-helpers.o sysbus.o isa-bus.o
>> diff --git a/blockdev.c b/blockdev.c
>> index 1a500b8..41e8efd 100644
>> --- a/blockdev.c
>> +++ b/blockdev.c
>> @@ -32,6 +32,7 @@ static const char *const if_name[IF_COUNT] = {
>>      [IF_SD] = "sd",
>>      [IF_VIRTIO] = "virtio",
>>      [IF_XEN] = "xen",
>> +    [IF_PVSCSI] = "pvscsi",
>>  };
>>
>>  static const int if_max_devs[IF_COUNT] = {
>> @@ -433,7 +434,8 @@ DriveInfo *drive_init(QemuOpts *opts, int 
>> default_to_scsi)
>>
>>      on_write_error = BLOCK_ERR_STOP_ENOSPC;
>>      if ((buf = qemu_opt_get(opts, "werror")) != NULL) {
>> -        if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO && type 
>> != IF_NONE) {
>> +        if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO &&
>> +            type != IF_PVSCSI && type != IF_NONE) {
>>              error_report("werror is not supported by this bus type");
>>              return NULL;
>>          }
>> @@ -446,7 +448,8 @@ DriveInfo *drive_init(QemuOpts *opts, int 
>> default_to_scsi)
>>
>>      on_read_error = BLOCK_ERR_REPORT;
>>      if ((buf = qemu_opt_get(opts, "rerror")) != NULL) {
>> -        if (type != IF_IDE && type != IF_VIRTIO && type != IF_SCSI && type 
>> != IF_NONE) {
>> +        if (type != IF_IDE && type != IF_VIRTIO && type != IF_SCSI &&
>> +            type != IF_PVSCSI && type != IF_NONE) {
>>              error_report("rerror is not supported by this bus type");
>>              return NULL;
>>          }
>> @@ -516,7 +519,7 @@ DriveInfo *drive_init(QemuOpts *opts, int 
>> default_to_scsi)
>>      } else {
>>          /* no id supplied -> create one */
>>          dinfo->id = g_malloc0(32);
>> -        if (type == IF_IDE || type == IF_SCSI)
>> +        if (type == IF_IDE || type == IF_SCSI || type == IF_PVSCSI)
>>              mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
>>          if (max_devs)
>>              snprintf(dinfo->id, 32, "%s%i%s%i",
>> @@ -545,6 +548,7 @@ DriveInfo *drive_init(QemuOpts *opts, int 
>> default_to_scsi)
>>      case IF_IDE:
>>      case IF_SCSI:
>>      case IF_XEN:
>> +    case IF_PVSCSI:
>>      case IF_NONE:
>>          switch(media) {
>>       case MEDIA_DISK:
>> @@ -596,7 +600,7 @@ DriveInfo *drive_init(QemuOpts *opts, int 
>> default_to_scsi)
>>          ro = 1;
>>      } else if (ro == 1) {
>>          if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY &&
>> -            type != IF_NONE && type != IF_PFLASH) {
>> +            type != IF_PVSCSI && type != IF_NONE && type != IF_PFLASH) {
>>              error_report("readonly not supported by this bus type");
>>              goto err;
>>          }
>> diff --git a/blockdev.h b/blockdev.h
>> index 1813c53..7c531aa 100644
>> --- a/blockdev.h
>> +++ b/blockdev.h
>> @@ -24,7 +24,15 @@ void blockdev_auto_del(BlockDriverState *bs);
>>  typedef enum {
>>      IF_DEFAULT = -1,            /* for use with drive_add() only */
>>      IF_NONE,
>> -    IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN,
>> +    IF_IDE,
>> +    IF_SCSI,
>> +    IF_FLOPPY,
>> +    IF_PFLASH,
>> +    IF_MTD,
>> +    IF_SD,
>> +    IF_VIRTIO,
>> +    IF_XEN,
>> +    IF_PVSCSI,
>>      IF_COUNT
>>  } BlockInterfaceType;
>>
>> diff --git a/default-configs/pci.mak b/default-configs/pci.mak
>> index 21e4ccf..c203bf8 100644
>> --- a/default-configs/pci.mak
>> +++ b/default-configs/pci.mak
>> @@ -11,6 +11,7 @@ CONFIG_EEPRO100_PCI=y
>>  CONFIG_PCNET_PCI=y
>>  CONFIG_PCNET_COMMON=y
>>  CONFIG_LSI_SCSI_PCI=y
>> +CONFIG_PVSCSI_SCSI_PCI=y
>>  CONFIG_RTL8139_PCI=y
>>  CONFIG_E1000_PCI=y
>>  CONFIG_IDE_CORE=y
>> diff --git a/hw/pc.c b/hw/pc.c
>> index 83a1b5b..2140a25 100644
>> --- a/hw/pc.c
>> +++ b/hw/pc.c
>> @@ -1175,4 +1175,9 @@ void pc_pci_device_init(PCIBus *pci_bus)
>>      for (bus = 0; bus <= max_bus; bus++) {
>>          pc

Re: [Qemu-devel] [PATCH 1/5] Utility function strpadcpy() added

2012-03-18 Thread Dmitry Fleytman
Wow! Someone still remembers Pascal.
It was a long time I didn't hear about it.
I think I still have some code I wrote for old DOS TurboPascal with TurboVision,
maybe I'll publish it somewhere :)

Anyway, I believe that difference is rather minor, but let it be...
My implementation replaced with your one.

On Thu, Mar 15, 2012 at 11:53 AM, Paolo Bonzini  wrote:
> Il 15/03/2012 10:02, Dmitry Fleytman ha scritto:
>> Signed-off-by: Dmitry Fleytman 
>> Signed-off-by: Yan Vugenfirer 
>> ---
>>  cutils.c      |   13 +
>>  qemu-common.h |    1 +
>>  2 files changed, 14 insertions(+), 0 deletions(-)
>>
>> diff --git a/cutils.c b/cutils.c
>> index af308cd..0df7fdf 100644
>> --- a/cutils.c
>> +++ b/cutils.c
>> @@ -27,6 +27,19 @@
>>
>>  #include "qemu_socket.h"
>>
>> +void strpadcpy(char *buf, int buf_size, const char *str, char pad)
>> +{
>> +    int i;
>> +    int has_src_data = TRUE;
>> +
>> +    for (i = 0; i < buf_size; i++) {
>> +        if ((has_src_data) && (0 == str[i])) {
>> +            has_src_data = FALSE;
>> +        }
>> +      buf[i] = has_src_data ? str[i] : pad;
>> +    }
>
> No parentheses around simple if conditions, this is not Pascal. :)  But
> since you're at it, why not the simpler:
>
> int len = qemu_strnlen(str, buf_size);
> memcpy(buf, str, len);
> memset(buf + len, pad, buf_size - len);
>
>> +}
>> +
>>  void pstrcpy(char *buf, int buf_size, const char *str)
>>  {
>>      int c;
>> diff --git a/qemu-common.h b/qemu-common.h
>> index b0fdf5c..fdd3d17 100644
>> --- a/qemu-common.h
>> +++ b/qemu-common.h
>> @@ -134,6 +134,7 @@ int qemu_timedate_diff(struct tm *tm);
>>
>>  /* cutils.c */
>>  void pstrcpy(char *buf, int buf_size, const char *str);
>> +void strpadcpy(char *buf, int buf_size, const char *str, char pad);
>>  char *pstrcat(char *buf, int buf_size, const char *s);
>>  int strstart(const char *str, const char *val, const char **ptr);
>>  int stristart(const char *str, const char *val, const char **ptr);
>



Re: [Qemu-devel] [PATCH 3/5] Header with various utility functions shared by VMWARE SCSI and network devices

2012-03-18 Thread Dmitry Fleytman
On Thu, Mar 15, 2012 at 11:56 AM, Paolo Bonzini  wrote:
> Il 15/03/2012 10:02, Dmitry Fleytman ha scritto:
>> Signed-off-by: Dmitry Fleytman 
>> Signed-off-by: Yan Vugenfirer 
>> ---
>>  hw/vmware_utils.h |  122 
>> +
>>  1 files changed, 122 insertions(+), 0 deletions(-)
>>  create mode 100644 hw/vmware_utils.h
>>
>> diff --git a/hw/vmware_utils.h b/hw/vmware_utils.h
>> new file mode 100644
>> index 000..a86e691
>> --- /dev/null
>> +++ b/hw/vmware_utils.h
>> @@ -0,0 +1,122 @@
>> +/*
>> + * QEMU VMWARE paravirtual devices - auxiliary code
>> + *
>> + * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
>> + *
>> + * Developed by Daynix Computing LTD (http://www.daynix.com)
>> + *
>> + * Authors:
>> + * Dmitry Fleytman 
>> + * Yan Vugenfirer 
>> + *
>> + * This work is licensed under the terms of the GNU GPL, version 2 or later.
>> + * See the COPYING file in the top-level directory.
>> + *
>> + */
>> +
>> +#ifndef VMWARE_UTILS_H
>> +#define VMWARE_UTILS_H
>> +
>> +/* Shared memory access functions with byte swap support */
>> +static inline void
>> +vmw_shmem_read(target_phys_addr_t addr, void *buf, int len)
>> +{
>> +    DSHPRINTF("SHMEM r: %" PRIx64 ", len: %d to %p", addr, len, buf);
>
> Please add an #ifndef DSHPRINTF that defines it to nothing.


Done.

>
>> +    cpu_physical_memory_read(addr, buf, len);
>> +}
>> +
>> +static inline void
>> +vmw_shmem_write(target_phys_addr_t addr, void *buf, int len)
>> +{
>> +    DSHPRINTF("SHMEM w: %" PRIx64 ", len: %d to %p", addr, len, buf);
>> +    cpu_physical_memory_write(addr, buf, len);
>> +}
>> +
>> +static inline void
>> +vmw_shmem_rw(target_phys_addr_t addr, void *buf, int len, int is_write)
>> +{
>> +    DSHPRINTF("SHMEM r/w: %" PRIx64 ", len: %d (to %p), is write: %d",
>> +              addr, len, buf, is_write);
>> +
>> +    cpu_physical_memory_rw(addr, buf, len, is_write);
>> +}
>> +
>> +static inline void
>> +vmw_shmem_set(target_phys_addr_t addr, uint8 val, int len)
>> +{
>> +    int i;
>> +    DSHPRINTF("SHMEM set: %" PRIx64 ", len: %d (value 0x%X)", addr, len, 
>> val);
>> +
>> +    for (i = 0; i < len; i++) {
>> +        cpu_physical_memory_write(addr + i, &val, 1);
>> +    }
>> +}
>> +
>> +static inline uint32_t
>> +vmw_shmem_ld8(target_phys_addr_t addr)
>> +{
>> +    uint8_t res = ldub_phys(addr);
>> +    DSHPRINTF("SHMEM load8: %" PRIx64 " (value 0x%X)", addr, res);
>> +    return res;
>> +}
>> +
>> +static inline void
>> +vmw_shmem_st8(target_phys_addr_t addr, uint8_t value)
>> +{
>> +    DSHPRINTF("SHMEM store8: %" PRIx64 " (value 0x%X)", addr, value);
>> +    stb_phys(addr, value);
>> +}
>> +
>> +static inline uint32_t
>> +vmw_shmem_ld16(target_phys_addr_t addr)
>> +{
>> +    uint16_t res = lduw_le_phys(addr);
>> +    DSHPRINTF("SHMEM load16: %" PRIx64 " (value 0x%X)", addr, res);
>> +    return res;
>> +}
>> +
>> +static inline void
>> +vmw_shmem_st16(target_phys_addr_t addr, uint16_t value)
>> +{
>> +    DSHPRINTF("SHMEM store16: %" PRIx64 " (value 0x%X)", addr, value);
>> +    stw_le_phys(addr, value);
>> +}
>> +
>> +static inline uint32_t
>> +vmw_shmem_ld32(target_phys_addr_t addr)
>> +{
>> +    uint32_t res = ldl_le_phys(addr);
>> +    DSHPRINTF("SHMEM load32: %" PRIx64 " (value 0x%X)", addr, res);
>> +    return res;
>> +}
>> +
>> +static inline void
>> +vmw_shmem_st32(target_phys_addr_t addr, uint32_t value)
>> +{
>> +    DSHPRINTF("SHMEM store32: %" PRIx64 " (value 0x%X)", addr, value);
>> +    stl_le_phys(addr, value);
>> +}
>> +
>> +static inline uint64_t
>> +vmw_shmem_ld64(target_phys_addr_t addr)
>> +{
>> +    uint64_t res = ldq_le_phys(addr);
>> +    DSHPRINTF("SHMEM load64: %" PRIx64 " (value %" PRIx64 ")", addr, res);
>> +    return res;
>> +}
>> +
>> +static inline void
>> +vmw_shmem_st64(target_phys_addr_t addr, uint64_t value)
>> +{
>> +    DSHPRINTF("SHMEM store64: %" PRIx64 " (value %" PRIx64 ")", addr, 
>> value);
>> +    stq_le_phys(addr, value);
>> +}
>> +
>> +/* MACROS for simplification of operations on array-style registers */
>> +#define IS_MULTIREG_ADDR(addr, base, cnt, regsize)                 \
>> +    (((addr) >= (base)) && ((addr) < (base) + (cnt) * (regsize)))
>> +
>> +#define MULTIREG_IDX_BY_ADDR(addr, base, regsize)                  \
>> +    (((addr) - (base)) / (regsize))
>> +
>> +#endif
>
> Otherwise looks good.
>
> Paolo



Re: [Qemu-devel] [PATCH 2/5] Vendor name and product name parameters for SCSI devices Options "vendor_name" and "product_name" added for SCSI disks.

2012-03-18 Thread Dmitry Fleytman
Unused stuff cleaned out.

On Thu, Mar 15, 2012 at 11:55 AM, Paolo Bonzini  wrote:
> Il 15/03/2012 10:02, Dmitry Fleytman ha scritto:
>> Sample command line is:
>>
>>     -drive file=image.raw,if=none,cache=off,id=scsi1 \
>>     -device lsi,id=scsi -device 
>> scsi-disk,drive=scsi1,bus=scsi.0,product_name="VENDOR SCSI 
>> DISK",vendor_name="[VENDOR]" \
>>
>> Signed-off-by: Dmitry Fleytman 
>> Signed-off-by: Yan Vugenfirer 
>> ---
>>  blockdev.h     |    6 +-
>>  hw/scsi-disk.c |   51 ---
>>  2 files changed, 41 insertions(+), 16 deletions(-)
>>
>> diff --git a/blockdev.h b/blockdev.h
>> index 260e16b..1813c53 100644
>> --- a/blockdev.h
>> +++ b/blockdev.h
>> @@ -17,7 +17,9 @@
>>  void blockdev_mark_auto_del(BlockDriverState *bs);
>>  void blockdev_auto_del(BlockDriverState *bs);
>>
>> -#define BLOCK_SERIAL_STRLEN 20
>> +#define BLOCK_SERIAL_STRLEN  20
>> +#define BLOCK_VENDOR_STRLEN  8
>> +#define BLOCK_PRODUCT_STRLEN 16
>>
>>  typedef enum {
>>      IF_DEFAULT = -1,            /* for use with drive_add() only */
>> @@ -37,6 +39,8 @@ struct DriveInfo {
>>      int media_cd;
>>      QemuOpts *opts;
>>      char serial[BLOCK_SERIAL_STRLEN + 1];
>> +    char vname[BLOCK_VENDOR_STRLEN + 1];
>> +    char pname[BLOCK_PRODUCT_STRLEN + 1];
>>      QTAILQ_ENTRY(DriveInfo) next;
>>      int refcount;
>>  };
>
> Unused.
>
>> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
>> index add399e..0a12ea2 100644
>> --- a/hw/scsi-disk.c
>> +++ b/hw/scsi-disk.c
>> @@ -70,6 +70,8 @@ struct SCSIDiskState
>>      QEMUBH *bh;
>>      char *version;
>>      char *serial;
>> +    char *vname;
>> +    char *pname;
>>      bool tray_open;
>>      bool tray_locked;
>>  };
>> @@ -566,12 +568,23 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, 
>> uint8_t *outbuf)
>>
>>      outbuf[0] = s->qdev.type & 0x1f;
>>      outbuf[1] = s->removable ? 0x80 : 0;
>> -    if (s->qdev.type == TYPE_ROM) {
>> -        memcpy(&outbuf[16], "QEMU CD-ROM     ", 16);
>> +
>> +    if (NULL != s->pname) {
>> +        strpadcpy((char *) &outbuf[16], 16, s->pname, ' ');
>>      } else {
>> -        memcpy(&outbuf[16], "QEMU HARDDISK   ", 16);
>> +        if (s->qdev.type == TYPE_ROM) {
>> +            memcpy(&outbuf[16], "QEMU CD-ROM     ", 16);
>> +        } else {
>> +            memcpy(&outbuf[16], "QEMU HARDDISK   ", 16);
>> +        }
>>      }
>> -    memcpy(&outbuf[8], "QEMU    ", 8);
>> +
>> +    if (NULL != s->vname) {
>> +        strpadcpy((char *) &outbuf[8], 8, s->vname, ' ');
>> +    } else {
>> +        memcpy(&outbuf[8], "QEMU    ", 8);
>> +    }
>> +
>>      memset(&outbuf[32], 0, 4);
>>      memcpy(&outbuf[32], s->version, MIN(4, strlen(s->version)));
>>      /*
>> @@ -1585,14 +1598,19 @@ static int scsi_initfn(SCSIDevice *dev)
>>          return -1;
>>      }
>>
>> -    if (!s->serial) {
>> -        /* try to fall back to value set with legacy -drive serial=... */
>> -        dinfo = drive_get_by_blockdev(s->qdev.conf.bs);
>> -        if (*dinfo->serial) {
>> -            s->serial = g_strdup(dinfo->serial);
>> -        }
>> -    }
>> +    dinfo = drive_get_by_blockdev(s->qdev.conf.bs);
>>
>> +    /* when no value given try to fall back to */
>> +    /* value set with legacy -drive serial=... */
>> +    if ((!s->serial) && (*dinfo->serial)) {
>> +        s->serial = g_strdup(dinfo->serial);
>> +    }
>
> No need to change the way the serial is handled, because you don't need
> dinfo for vname/pname.
>
>> +    if ((!s->vname) && (*dinfo->vname)) {
>> +        s->vname = g_strdup(dinfo->vname);
>> +    }
>> +    if ((!s->pname) && (*dinfo->pname)) {
>> +        s->pname = g_strdup(dinfo->pname);
>> +    }
>
> (Also, no parentheses around simple conditions).
>
>>      if (!s->version) {
>>          s->version = g_strdup(QEMU_VERSION);
>>      }
>> @@ -1788,10 +1806,13 @@ static SCSIRequest 
>> *scsi_block_new_request(SCSIDevice *d, uint32_t tag,
>>  }
>>  #endif
>>
>> -#define DEFINE_SCSI_DISK_PROPERTIES()                           \
>> -    DEFINE_BLOCK_PROPERTIES(SCSIDiskState, qdev.conf),          \
>> -    DEFINE_PROP_STRING("ver",  SCSIDiskState, version),         \
>> -    DEFINE_PROP_STRING("serial",  SCSIDiskState, serial)
>> +#define DEFINE_SCSI_DISK_PROPERTIES()                                 \
>> +    DEFINE_BLOCK_PROPERTIES(SCSIDiskState, qdev.conf),                \
>> +    DEFINE_PROP_STRING("ver",  SCSIDiskState, version),               \
>> +    DEFINE_PROP_STRING("serial",  SCSIDiskState, serial),             \
>> +    DEFINE_PROP_STRING("vendor_name",  SCSIDiskState, vname),         \
>> +    DEFINE_PROP_STRING("product_name",  SCSIDiskState, pname)
>> +
>>
>>  static Property scsi_hd_properties[] = {
>>      DEFINE_SCSI_DISK_PROPERTIES(),
>
> Paolo



Re: [Qemu-devel] [PATCH v4 9/9] VMXNET3 paravirtualized device integration. Interface type "vmxnet3" added.

2012-03-18 Thread Dmitry Fleytman
Fixed.

On Fri, Mar 16, 2012 at 1:35 PM, Paolo Bonzini  wrote:
> Il 15/03/2012 22:09, Dmitry Fleytman ha scritto:
>> Signed-off-by: Dmitry Fleytman 
>> Signed-off-by: Yan Vugenfirer 
>> ---
>>  Makefile.objs           |    1 +
>>  default-configs/pci.mak |    1 +
>>  hw/pci.c                |    2 ++
>>  hw/pci.h                |    1 +
>>  net.c                   |    2 +-
>>  5 files changed, 6 insertions(+), 1 deletions(-)
>>
>> diff --git a/Makefile.objs b/Makefile.objs
>> index 226b01d..1366e86 100644
>> --- a/Makefile.objs
>> +++ b/Makefile.objs
>> @@ -284,6 +284,7 @@ hw-obj-$(CONFIG_PCNET_PCI) += pcnet-pci.o
>>  hw-obj-$(CONFIG_PCNET_COMMON) += pcnet.o
>>  hw-obj-$(CONFIG_E1000_PCI) += e1000.o
>>  hw-obj-$(CONFIG_RTL8139_PCI) += rtl8139.o
>> +hw-obj-$(CONFIG_VMXNET3_PCI) += vmxnet3.o vmxnet_utils.o vmxnet_pkt.o
>>
>>  hw-obj-$(CONFIG_SMC91C111) += smc91c111.o
>>  hw-obj-$(CONFIG_LAN9118) += lan9118.o
>> diff --git a/default-configs/pci.mak b/default-configs/pci.mak
>> index 21e4ccf..f8e6ee1 100644
>> --- a/default-configs/pci.mak
>> +++ b/default-configs/pci.mak
>> @@ -13,6 +13,7 @@ CONFIG_PCNET_COMMON=y
>>  CONFIG_LSI_SCSI_PCI=y
>>  CONFIG_RTL8139_PCI=y
>>  CONFIG_E1000_PCI=y
>> +CONFIG_VMXNET3_PCI=y
>>  CONFIG_IDE_CORE=y
>>  CONFIG_IDE_QDEV=y
>>  CONFIG_IDE_PCI=y
>
> These parts should be included in part 8.
>
> Paolo
>
>> diff --git a/hw/pci.c b/hw/pci.c
>> index 9146d3f..e2b0045 100644
>> --- a/hw/pci.c
>> +++ b/hw/pci.c
>> @@ -1355,6 +1355,7 @@ static const char * const pci_nic_models[] = {
>>      "e1000",
>>      "pcnet",
>>      "virtio",
>> +    "vmxnet3",
>>      NULL
>>  };
>>
>> @@ -1367,6 +1368,7 @@ static const char * const pci_nic_names[] = {
>>      "e1000",
>>      "pcnet",
>>      "virtio-net-pci",
>> +    "vmxnet3",
>>      NULL
>>  };
>>
>> diff --git a/hw/pci.h b/hw/pci.h
>> index 4f19fdb..fee8250 100644
>> --- a/hw/pci.h
>> +++ b/hw/pci.h
>> @@ -60,6 +60,7 @@
>>  #define PCI_DEVICE_ID_VMWARE_NET         0x0720
>>  #define PCI_DEVICE_ID_VMWARE_SCSI        0x0730
>>  #define PCI_DEVICE_ID_VMWARE_IDE         0x1729
>> +#define PCI_DEVICE_ID_VMWARE_VMXNET3     0x07B0
>>
>>  /* Intel (0x8086) */
>>  #define PCI_DEVICE_ID_INTEL_82551IT      0x1209
>> diff --git a/net.c b/net.c
>> index c34474f..e2f586c 100644
>> --- a/net.c
>> +++ b/net.c
>> @@ -857,7 +857,7 @@ static const struct {
>>              }, {
>>                  .name = "model",
>>                  .type = QEMU_OPT_STRING,
>> -                .help = "device model (e1000, rtl8139, virtio etc.)",
>> +                .help = "device model (e1000, rtl8139, virtio, vmxnet3 
>> etc.)",
>>              }, {
>>                  .name = "addr",
>>                  .type = QEMU_OPT_STRING,
>



[Qemu-devel] [PATCH 0/5 V2] VMWare PVSCSI paravirtual device implementation

2012-03-18 Thread Dmitry Fleytman
Below is the implementation of VMWare PVSCSI device and
command line parameters to configure vendor name and product name
for SCSI storage are implemented.
Latter is needed to make PVSCSI storage devices look exactly as
on VMWare hypervisors.

With this and VMWARE3 patches V2V migration problem for VMWare
images should be solved relatively easy.

PVSCSI implementation is based on Paolo Bonzini code sumbitted
some time ago but never applied.
See commit messages and file headers for details.

Implementation supports of all the device features.
Code was tested on different OSes:
Fedora 15
Ubuntu 10.4
Centos 6.2
Windows 2008R2
Windows 2008 64bit
Windows 2008 32bit
Windows 2003 64bit
Windows 2003 32bit

Changes in V2:
Various fixes and beautification as suggested by Paolo Bonzini
Reported-by: Paolo Bonzini 

Dmitry Fleytman (4):
  Utility function strpadcpy() added
  Vendor name and product name parameters for SCSI devices Options
"vendor_name" and "product_name" added for SCSI disks.
  Header with various utility functions shared by VMWARE SCSI and
network devices
  PVCSI paravirtualized device implementation Bus type "pvscsi"
added.

 Makefile.objs  |1 +
 cutils.c   |7 +
 default-configs/pci.mak|1 +
 docs/specs/pvscsi-spec.txt |   92 
 hw/pci.h   |1 +
 hw/pvscsi.c| 1239 
 hw/pvscsi.h|  442 
 hw/scsi-disk.c |   32 +-
 hw/vmware_utils.h  |  126 +
 qemu-common.h  |1 +
 10 files changed, 1934 insertions(+), 8 deletions(-)
 create mode 100644 docs/specs/pvscsi-spec.txt
 create mode 100644 hw/pvscsi.c
 create mode 100644 hw/pvscsi.h
 create mode 100644 hw/vmware_utils.h

-- 
1.7.7.6




[Qemu-devel] [PATCH 2/4 V2] Vendor name and product name parameters for SCSI devices Options "vendor_name" and "product_name" added for SCSI disks.

2012-03-18 Thread Dmitry Fleytman
Sample command line is:

-drive file=image.raw,if=none,cache=off,id=scsi1 \
-device lsi,id=scsi -device 
scsi-disk,drive=scsi1,bus=scsi.0,product_name="VENDOR SCSI 
DISK",vendor_name="[VENDOR]" \

Signed-off-by: Dmitry Fleytman 
Signed-off-by: Yan Vugenfirer 
---
 hw/scsi-disk.c |   32 
 1 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index add399e..1a2997f 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -70,6 +70,8 @@ struct SCSIDiskState
 QEMUBH *bh;
 char *version;
 char *serial;
+char *vname;
+char *pname;
 bool tray_open;
 bool tray_locked;
 };
@@ -566,12 +568,23 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, 
uint8_t *outbuf)
 
 outbuf[0] = s->qdev.type & 0x1f;
 outbuf[1] = s->removable ? 0x80 : 0;
-if (s->qdev.type == TYPE_ROM) {
-memcpy(&outbuf[16], "QEMU CD-ROM ", 16);
+
+if (NULL != s->pname) {
+strpadcpy((char *) &outbuf[16], 16, s->pname, ' ');
+} else {
+if (s->qdev.type == TYPE_ROM) {
+memcpy(&outbuf[16], "QEMU CD-ROM ", 16);
+} else {
+memcpy(&outbuf[16], "QEMU HARDDISK   ", 16);
+}
+}
+
+if (NULL != s->vname) {
+strpadcpy((char *) &outbuf[8], 8, s->vname, ' ');
 } else {
-memcpy(&outbuf[16], "QEMU HARDDISK   ", 16);
+memcpy(&outbuf[8], "QEMU", 8);
 }
-memcpy(&outbuf[8], "QEMU", 8);
+
 memset(&outbuf[32], 0, 4);
 memcpy(&outbuf[32], s->version, MIN(4, strlen(s->version)));
 /*
@@ -1788,10 +1801,13 @@ static SCSIRequest *scsi_block_new_request(SCSIDevice 
*d, uint32_t tag,
 }
 #endif
 
-#define DEFINE_SCSI_DISK_PROPERTIES()   \
-DEFINE_BLOCK_PROPERTIES(SCSIDiskState, qdev.conf),  \
-DEFINE_PROP_STRING("ver",  SCSIDiskState, version), \
-DEFINE_PROP_STRING("serial",  SCSIDiskState, serial)
+#define DEFINE_SCSI_DISK_PROPERTIES() \
+DEFINE_BLOCK_PROPERTIES(SCSIDiskState, qdev.conf),\
+DEFINE_PROP_STRING("ver",  SCSIDiskState, version),   \
+DEFINE_PROP_STRING("serial",  SCSIDiskState, serial), \
+DEFINE_PROP_STRING("vendor_name",  SCSIDiskState, vname), \
+DEFINE_PROP_STRING("product_name",  SCSIDiskState, pname)
+
 
 static Property scsi_hd_properties[] = {
 DEFINE_SCSI_DISK_PROPERTIES(),
-- 
1.7.7.6




[Qemu-devel] [PATCH 3/4 V2] Header with various utility functions shared by VMWARE SCSI and network devices

2012-03-18 Thread Dmitry Fleytman
Signed-off-by: Dmitry Fleytman 
Signed-off-by: Yan Vugenfirer 
---
 hw/vmware_utils.h |  126 +
 1 files changed, 126 insertions(+), 0 deletions(-)
 create mode 100644 hw/vmware_utils.h

diff --git a/hw/vmware_utils.h b/hw/vmware_utils.h
new file mode 100644
index 000..cc845d7
--- /dev/null
+++ b/hw/vmware_utils.h
@@ -0,0 +1,126 @@
+/*
+ * QEMU VMWARE paravirtual devices - auxiliary code
+ *
+ * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
+ *
+ * Developed by Daynix Computing LTD (http://www.daynix.com)
+ *
+ * Authors:
+ * Dmitry Fleytman 
+ * Yan Vugenfirer 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef VMWARE_UTILS_H
+#define VMWARE_UTILS_H
+
+#ifndef DSHPRINTF
+#define DSHPRINTF(fmt, ...) do {} while (0)
+#endif
+
+/* Shared memory access functions with byte swap support */
+static inline void
+vmw_shmem_read(target_phys_addr_t addr, void *buf, int len)
+{
+DSHPRINTF("SHMEM r: %" PRIx64 ", len: %d to %p", addr, len, buf);
+cpu_physical_memory_read(addr, buf, len);
+}
+
+static inline void
+vmw_shmem_write(target_phys_addr_t addr, void *buf, int len)
+{
+DSHPRINTF("SHMEM w: %" PRIx64 ", len: %d to %p", addr, len, buf);
+cpu_physical_memory_write(addr, buf, len);
+}
+
+static inline void
+vmw_shmem_rw(target_phys_addr_t addr, void *buf, int len, int is_write)
+{
+DSHPRINTF("SHMEM r/w: %" PRIx64 ", len: %d (to %p), is write: %d",
+  addr, len, buf, is_write);
+
+cpu_physical_memory_rw(addr, buf, len, is_write);
+}
+
+static inline void
+vmw_shmem_set(target_phys_addr_t addr, uint8 val, int len)
+{
+int i;
+DSHPRINTF("SHMEM set: %" PRIx64 ", len: %d (value 0x%X)", addr, len, val);
+
+for (i = 0; i < len; i++) {
+cpu_physical_memory_write(addr + i, &val, 1);
+}
+}
+
+static inline uint32_t
+vmw_shmem_ld8(target_phys_addr_t addr)
+{
+uint8_t res = ldub_phys(addr);
+DSHPRINTF("SHMEM load8: %" PRIx64 " (value 0x%X)", addr, res);
+return res;
+}
+
+static inline void
+vmw_shmem_st8(target_phys_addr_t addr, uint8_t value)
+{
+DSHPRINTF("SHMEM store8: %" PRIx64 " (value 0x%X)", addr, value);
+stb_phys(addr, value);
+}
+
+static inline uint32_t
+vmw_shmem_ld16(target_phys_addr_t addr)
+{
+uint16_t res = lduw_le_phys(addr);
+DSHPRINTF("SHMEM load16: %" PRIx64 " (value 0x%X)", addr, res);
+return res;
+}
+
+static inline void
+vmw_shmem_st16(target_phys_addr_t addr, uint16_t value)
+{
+DSHPRINTF("SHMEM store16: %" PRIx64 " (value 0x%X)", addr, value);
+stw_le_phys(addr, value);
+}
+
+static inline uint32_t
+vmw_shmem_ld32(target_phys_addr_t addr)
+{
+uint32_t res = ldl_le_phys(addr);
+DSHPRINTF("SHMEM load32: %" PRIx64 " (value 0x%X)", addr, res);
+return res;
+}
+
+static inline void
+vmw_shmem_st32(target_phys_addr_t addr, uint32_t value)
+{
+DSHPRINTF("SHMEM store32: %" PRIx64 " (value 0x%X)", addr, value);
+stl_le_phys(addr, value);
+}
+
+static inline uint64_t
+vmw_shmem_ld64(target_phys_addr_t addr)
+{
+uint64_t res = ldq_le_phys(addr);
+DSHPRINTF("SHMEM load64: %" PRIx64 " (value %" PRIx64 ")", addr, res);
+return res;
+}
+
+static inline void
+vmw_shmem_st64(target_phys_addr_t addr, uint64_t value)
+{
+DSHPRINTF("SHMEM store64: %" PRIx64 " (value %" PRIx64 ")", addr, value);
+stq_le_phys(addr, value);
+}
+
+/* MACROS for simplification of operations on array-style registers */
+#define IS_MULTIREG_ADDR(addr, base, cnt, regsize) \
+(((addr) >= (base)) && ((addr) < (base) + (cnt) * (regsize)))
+
+#define MULTIREG_IDX_BY_ADDR(addr, base, regsize)  \
+(((addr) - (base)) / (regsize))
+
+#endif
-- 
1.7.7.6




[Qemu-devel] [PATCH 1/4 V2] Utility function strpadcpy() added

2012-03-18 Thread Dmitry Fleytman
Signed-off-by: Dmitry Fleytman 
Signed-off-by: Yan Vugenfirer 
---
 cutils.c  |7 +++
 qemu-common.h |1 +
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/cutils.c b/cutils.c
index af308cd..3ccf45c 100644
--- a/cutils.c
+++ b/cutils.c
@@ -27,6 +27,13 @@
 
 #include "qemu_socket.h"
 
+void strpadcpy(char *buf, int buf_size, const char *str, char pad)
+{
+int len = qemu_strnlen(str, buf_size);
+memcpy(buf, str, len);
+memset(buf + len, pad, buf_size - len);
+}
+
 void pstrcpy(char *buf, int buf_size, const char *str)
 {
 int c;
diff --git a/qemu-common.h b/qemu-common.h
index b0fdf5c..fdd3d17 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -134,6 +134,7 @@ int qemu_timedate_diff(struct tm *tm);
 
 /* cutils.c */
 void pstrcpy(char *buf, int buf_size, const char *str);
+void strpadcpy(char *buf, int buf_size, const char *str, char pad);
 char *pstrcat(char *buf, int buf_size, const char *s);
 int strstart(const char *str, const char *val, const char **ptr);
 int stristart(const char *str, const char *val, const char **ptr);
-- 
1.7.7.6




[Qemu-devel] [PATCH 0/7 v5] VMXNET3 paravirtual NIC device implementation

2012-03-18 Thread Dmitry Fleytman
This set of patches implements VMWare VMXNET3 paravirtual NIC device.
The device supports of all the device features including offload capabilties,
VLANs and etc.
The device is tested on different OSes:
Fedora 15
Ubuntu 10.4
Centos 6.2
Windows 2008R2
Windows 2008 64bit
Windows 2008 32bit
Windows 2003 64bit
Windows 2003 32bit

Changes in V5:
   MSI-X save/load implemented in the device instead of pci bus as
   suggested by Michael S. Tsirkin

 Reported-by: Michael S. Tsirkin 

   Patches regrouped as suggested by Paolo Bonzini

 Reported-by: Paolo Bonzini 

Changes in V4:
   Fixed a few problems uncovered by NETIO test suit
   Assertion on failure to initialize MSI/MSI-X replaced with warning 
   message and fallback to Legacy/MSI respectively   

 Reported-by: Gerhard Wiesinger 

   Various coding style adjustments and patch split-up as suggested by Anthony 
Liguori
 
 Reported-by: Anthony Liguori 

   Live migration support added

Changes in V3:
   Fixed crash when net device that is used as network fronted has no
   virtio HDR support.
   Task offloads emulation for cases when net device that is used as 
   network fronted has no virtio HDR support.

 Reported-by: Gerhard Wiesinger 

Changes in V2:
   License text changed accoring to community suggestions
   Standard license header from GPLv2+ - licensed QEMU files used

Dmitry Fleytman (7):
  Adding missing flag VIRTIO_NET_HDR_F_DATA_VALID from Linux kernel
source tre Reformatting comments according to checkpatch.pl
requirements
  Adding utility function net_checksum_add_cont() that allows checksum 
   calculation of scattered data with odd chunk sizes
  Adding utility function iov_net_csum_add() for iovec checksum
calculation
  Header with various utility functions shared by VMWARE SCSI and
network devices
  Various utility functions used by VMWARE network devices
  Packet abstraction used by VMWARE network devices
  VMXNET3 paravirtualized device implementation Interface type
"vmxnet3" added.

 Makefile.objs   |1 +
 default-configs/pci.mak |1 +
 hw/pci.c|2 +
 hw/pci.h|1 +
 hw/virtio-net.h |   13 +-
 hw/vmware_utils.h   |  126 +++
 hw/vmxnet3.c| 2454 +++
 hw/vmxnet3.h|  757 +++
 hw/vmxnet_debug.h   |  121 +++
 hw/vmxnet_pkt.c | 1243 
 hw/vmxnet_pkt.h |  479 +
 hw/vmxnet_utils.c   |  165 
 hw/vmxnet_utils.h   |  320 ++
 iov.c   |   29 +
 iov.h   |3 +
 net.c   |2 +-
 net/checksum.c  |   13 +-
 net/checksum.h  |   14 +-
 18 files changed, 5730 insertions(+), 14 deletions(-)
 create mode 100644 hw/vmware_utils.h
 create mode 100644 hw/vmxnet3.c
 create mode 100644 hw/vmxnet3.h
 create mode 100644 hw/vmxnet_debug.h
 create mode 100644 hw/vmxnet_pkt.c
 create mode 100644 hw/vmxnet_pkt.h
 create mode 100644 hw/vmxnet_utils.c
 create mode 100644 hw/vmxnet_utils.h

-- 
1.7.7.6




[Qemu-devel] [PATCH 1/7 v5] Adding missing flag VIRTIO_NET_HDR_F_DATA_VALID from Linux kernel source tre Reformatting comments according to checkpatch.pl requirements

2012-03-18 Thread Dmitry Fleytman
Signed-off-by: Dmitry Fleytman 
Signed-off-by: Yan Vugenfirer 
---
 hw/virtio-net.h |   13 +++--
 1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/hw/virtio-net.h b/hw/virtio-net.h
index 4468741..fa3c17b 100644
--- a/hw/virtio-net.h
+++ b/hw/virtio-net.h
@@ -78,13 +78,14 @@ struct virtio_net_config
  * specify GSO or CSUM features, you can simply ignore the header. */
 struct virtio_net_hdr
 {
-#define VIRTIO_NET_HDR_F_NEEDS_CSUM 1   // Use csum_start, csum_offset
+#define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 /* Use csum_start, csum_offset */
+#define VIRTIO_NET_HDR_F_DATA_VALID 2 /* Csum is valid   */
 uint8_t flags;
-#define VIRTIO_NET_HDR_GSO_NONE 0   // Not a GSO frame
-#define VIRTIO_NET_HDR_GSO_TCPV41   // GSO frame, IPv4 TCP (TSO)
-#define VIRTIO_NET_HDR_GSO_UDP  3   // GSO frame, IPv4 UDP (UFO)
-#define VIRTIO_NET_HDR_GSO_TCPV64   // GSO frame, IPv6 TCP
-#define VIRTIO_NET_HDR_GSO_ECN  0x80// TCP has ECN set
+#define VIRTIO_NET_HDR_GSO_NONE 0 /* Not a GSO frame */
+#define VIRTIO_NET_HDR_GSO_TCPV41 /* GSO frame, IPv4 TCP (TSO)   */
+#define VIRTIO_NET_HDR_GSO_UDP  3 /* GSO frame, IPv4 UDP (UFO)   */
+#define VIRTIO_NET_HDR_GSO_TCPV64 /* GSO frame, IPv6 TCP */
+#define VIRTIO_NET_HDR_GSO_ECN  0x80  /* TCP has ECN set */
 uint8_t gso_type;
 uint16_t hdr_len;
 uint16_t gso_size;
-- 
1.7.7.6




[Qemu-devel] [PATCH 2/7 v5] Adding utility function net_checksum_add_cont() that allows checksum calculation of scattered data with odd chunk sizes

2012-03-18 Thread Dmitry Fleytman
Adding utility function net_raw_checksum() that calculates checksum
of buffer given

Signed-off-by: Dmitry Fleytman 
Signed-off-by: Yan Vugenfirer 
---
 net/checksum.c |   13 +++--
 net/checksum.h |   14 +-
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/net/checksum.c b/net/checksum.c
index 9919b2e..4fa5563 100644
--- a/net/checksum.c
+++ b/net/checksum.c
@@ -20,16 +20,17 @@
 #define PROTO_TCP  6
 #define PROTO_UDP 17
 
-uint32_t net_checksum_add(int len, uint8_t *buf)
+uint32_t net_checksum_add_cont(int len, uint8_t *buf, int seq)
 {
 uint32_t sum = 0;
 int i;
 
-for (i = 0; i < len; i++) {
-   if (i & 1)
-   sum += (uint32_t)buf[i];
-   else
-   sum += (uint32_t)buf[i] << 8;
+for (i = seq; i < seq + len; i++) {
+if (i & 1) {
+sum += (uint32_t)buf[i - seq];
+} else {
+sum += (uint32_t)buf[i - seq] << 8;
+}
 }
 return sum;
 }
diff --git a/net/checksum.h b/net/checksum.h
index 1f05298..171924c 100644
--- a/net/checksum.h
+++ b/net/checksum.h
@@ -20,10 +20,22 @@
 
 #include 
 
-uint32_t net_checksum_add(int len, uint8_t *buf);
+uint32_t net_checksum_add_cont(int len, uint8_t *buf, int seq);
 uint16_t net_checksum_finish(uint32_t sum);
 uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
  uint8_t *addrs, uint8_t *buf);
 void net_checksum_calculate(uint8_t *data, int length);
 
+static inline uint32_t
+net_checksum_add(int len, uint8_t *buf)
+{
+return net_checksum_add_cont(len, buf, 0);
+}
+
+static inline uint16_t
+net_raw_checksum(uint8_t *data, int length)
+{
+  return net_checksum_finish(net_checksum_add(length, data));
+}
+
 #endif /* QEMU_NET_CHECKSUM_H */
-- 
1.7.7.6




[Qemu-devel] [PATCH 6/7 v5] Packet abstraction used by VMWARE network devices

2012-03-18 Thread Dmitry Fleytman
Signed-off-by: Dmitry Fleytman 
Signed-off-by: Yan Vugenfirer 
---
 hw/vmxnet_pkt.c | 1243 +++
 hw/vmxnet_pkt.h |  479 +
 2 files changed, 1722 insertions(+), 0 deletions(-)
 create mode 100644 hw/vmxnet_pkt.c
 create mode 100644 hw/vmxnet_pkt.h

diff --git a/hw/vmxnet_pkt.c b/hw/vmxnet_pkt.c
new file mode 100644
index 000..5fe2672
--- /dev/null
+++ b/hw/vmxnet_pkt.c
@@ -0,0 +1,1243 @@
+/*
+ * QEMU VMWARE VMXNET* paravirtual NICs - packets abstractions
+ *
+ * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
+ *
+ * Developed by Daynix Computing LTD (http://www.daynix.com)
+ *
+ * Authors:
+ * Dmitry Fleytman 
+ * Tamir Shomer 
+ * Yan Vugenfirer 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#include "vmxnet_pkt.h"
+#include "vmxnet_utils.h"
+#include "iov.h"
+
+#include "net/checksum.h"
+
+/*=
+ *=
+ *
+ *TX CODE
+ *
+ *=
+ *===*/
+
+enum {
+VMXNET_TX_PKT_VHDR_FRAG = 0,
+VMXNET_TX_PKT_L2HDR_FRAG,
+VMXNET_TX_PKT_L3HDR_FRAG,
+VMXNET_TX_PKT_PL_START_FRAG
+};
+
+/* TX packet private context */
+typedef struct _Vmxnet_TxPkt {
+struct virtio_net_hdr virt_hdr;
+bool has_virt_hdr;
+
+struct iovec *vec;
+
+uint8_t l2_hdr[ETH_MAX_L2_HDR_LEN];
+uint8_t l3_hdr[ETH_MAX_L3_HDR_LEN];
+
+uint32_t payload_len;
+
+uint32_t payload_frags;
+uint32_t max_payload_frags;
+
+uint16_t hdr_len;
+eth_pkt_types_e packet_type;
+uint16_t l3_proto;
+} Vmxnet_TxPkt;
+
+/**
+ *
+ * Function: vmxnet_tx_pkt_init
+ *
+ * Desc: Init function for tx packet functionality.
+ *
+ * Params:  (OUT) pkt - private handle.
+ *  (IN) max_frags - max tx ip fragments.
+ *  (IN) has_virt_hdr - device uses virtio header.
+ *
+ * Return:  0 on success, -1 on error
+ *
+ * Scope: Global
+ *
+ */
+int vmxnet_tx_pkt_init(Vmxnet_TxPkt_h *pkt, uint32_t max_frags,
+bool has_virt_hdr)
+{
+int rc = 0;
+
+Vmxnet_TxPkt *p = g_malloc(sizeof *p);
+if (!p) {
+rc = -1;
+goto Exit;
+}
+
+memset(p, 0, sizeof *p);
+
+p->vec = g_malloc((sizeof *p->vec) *
+(max_frags + VMXNET_TX_PKT_PL_START_FRAG));
+if (!p->vec) {
+rc = -1;
+goto Exit;
+}
+
+p->max_payload_frags = max_frags;
+p->has_virt_hdr = has_virt_hdr;
+p->vec[VMXNET_TX_PKT_VHDR_FRAG].iov_base = &p->virt_hdr;
+p->vec[VMXNET_TX_PKT_VHDR_FRAG].iov_len =
+p->has_virt_hdr ? sizeof p->virt_hdr : 0;
+p->vec[VMXNET_TX_PKT_L2HDR_FRAG].iov_base = &p->l2_hdr;
+p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_base = &p->l3_hdr;
+
+*pkt = p;
+
+Exit:
+if (rc) {
+vmxnet_tx_pkt_uninit(p);
+}
+return rc;
+}
+
+/**
+ *
+ * Function: vmxnet_tx_pkt_uninit
+ *
+ * Desc: Clean all tx packet resources.
+ *
+ * Params:  (IN) pkt - private handle.
+ *
+ * Return:  nothing
+ *
+ * Scope: Global
+ *
+ */
+void vmxnet_tx_pkt_uninit(Vmxnet_TxPkt_h pkt)
+{
+Vmxnet_TxPkt *p = (Vmxnet_TxPkt *)pkt;
+
+if (p) {
+if (p->vec) {
+g_free(p->vec);
+}
+
+g_free(p);
+}
+}
+
+/**
+ *
+ * Function: vmxnet_tx_pkt_update_ip_checksums
+ *
+ * Desc: fix ip header fields and calculate checksums needed.
+ *
+ * Params:  (IN) pkt - private handle.
+ *
+ * Return:  Nothing.
+ *
+ * Scope: Global
+ *
+ */
+void vmxnet_tx_pkt_update_ip_checksums(Vmxnet_TxPkt_h pkt)
+{
+uint16_t csum;
+Vmxnet_TxPkt *p = (Vmxnet_TxPkt *)pkt;
+assert(p);
+uint8_t gso_type = p->virt_hdr.gso_type & ~VIRTIO_NET_HDR_GSO_ECN;
+struct ip_header *ip_hdr;
+target_phys_addr_t payload = (target_phys_addr_t)
+(uint64_t) p->vec[VMXNET_TX_PKT_PL_START_FRAG].iov_base;
+
+if (VIRTIO_NET_HDR_GSO_TCPV4 != gso_type &&
+VIRTIO_NET_HDR_GSO_UDP != gso_type) {
+return;
+}
+
+ip_hdr = p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_base;
+
+if (p->payload_len + p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_len >
+ETH_MAX_IP_DGRAM_LEN) {
+return;
+}
+
+ip_hdr->ip_len = cpu_to_be16(p->payload_len +
+p->vec[VMXNET_TX_PKT_L3HDR_FRAG].iov_le

[Qemu-devel] [PATCH 4/7 v5] Header with various utility functions shared by VMWARE SCSI and network devices

2012-03-18 Thread Dmitry Fleytman
Signed-off-by: Dmitry Fleytman 
Signed-off-by: Yan Vugenfirer 
---
 hw/vmware_utils.h |  126 +
 1 files changed, 126 insertions(+), 0 deletions(-)
 create mode 100644 hw/vmware_utils.h

diff --git a/hw/vmware_utils.h b/hw/vmware_utils.h
new file mode 100644
index 000..cc845d7
--- /dev/null
+++ b/hw/vmware_utils.h
@@ -0,0 +1,126 @@
+/*
+ * QEMU VMWARE paravirtual devices - auxiliary code
+ *
+ * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
+ *
+ * Developed by Daynix Computing LTD (http://www.daynix.com)
+ *
+ * Authors:
+ * Dmitry Fleytman 
+ * Yan Vugenfirer 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef VMWARE_UTILS_H
+#define VMWARE_UTILS_H
+
+#ifndef DSHPRINTF
+#define DSHPRINTF(fmt, ...) do {} while (0)
+#endif
+
+/* Shared memory access functions with byte swap support */
+static inline void
+vmw_shmem_read(target_phys_addr_t addr, void *buf, int len)
+{
+DSHPRINTF("SHMEM r: %" PRIx64 ", len: %d to %p", addr, len, buf);
+cpu_physical_memory_read(addr, buf, len);
+}
+
+static inline void
+vmw_shmem_write(target_phys_addr_t addr, void *buf, int len)
+{
+DSHPRINTF("SHMEM w: %" PRIx64 ", len: %d to %p", addr, len, buf);
+cpu_physical_memory_write(addr, buf, len);
+}
+
+static inline void
+vmw_shmem_rw(target_phys_addr_t addr, void *buf, int len, int is_write)
+{
+DSHPRINTF("SHMEM r/w: %" PRIx64 ", len: %d (to %p), is write: %d",
+  addr, len, buf, is_write);
+
+cpu_physical_memory_rw(addr, buf, len, is_write);
+}
+
+static inline void
+vmw_shmem_set(target_phys_addr_t addr, uint8 val, int len)
+{
+int i;
+DSHPRINTF("SHMEM set: %" PRIx64 ", len: %d (value 0x%X)", addr, len, val);
+
+for (i = 0; i < len; i++) {
+cpu_physical_memory_write(addr + i, &val, 1);
+}
+}
+
+static inline uint32_t
+vmw_shmem_ld8(target_phys_addr_t addr)
+{
+uint8_t res = ldub_phys(addr);
+DSHPRINTF("SHMEM load8: %" PRIx64 " (value 0x%X)", addr, res);
+return res;
+}
+
+static inline void
+vmw_shmem_st8(target_phys_addr_t addr, uint8_t value)
+{
+DSHPRINTF("SHMEM store8: %" PRIx64 " (value 0x%X)", addr, value);
+stb_phys(addr, value);
+}
+
+static inline uint32_t
+vmw_shmem_ld16(target_phys_addr_t addr)
+{
+uint16_t res = lduw_le_phys(addr);
+DSHPRINTF("SHMEM load16: %" PRIx64 " (value 0x%X)", addr, res);
+return res;
+}
+
+static inline void
+vmw_shmem_st16(target_phys_addr_t addr, uint16_t value)
+{
+DSHPRINTF("SHMEM store16: %" PRIx64 " (value 0x%X)", addr, value);
+stw_le_phys(addr, value);
+}
+
+static inline uint32_t
+vmw_shmem_ld32(target_phys_addr_t addr)
+{
+uint32_t res = ldl_le_phys(addr);
+DSHPRINTF("SHMEM load32: %" PRIx64 " (value 0x%X)", addr, res);
+return res;
+}
+
+static inline void
+vmw_shmem_st32(target_phys_addr_t addr, uint32_t value)
+{
+DSHPRINTF("SHMEM store32: %" PRIx64 " (value 0x%X)", addr, value);
+stl_le_phys(addr, value);
+}
+
+static inline uint64_t
+vmw_shmem_ld64(target_phys_addr_t addr)
+{
+uint64_t res = ldq_le_phys(addr);
+DSHPRINTF("SHMEM load64: %" PRIx64 " (value %" PRIx64 ")", addr, res);
+return res;
+}
+
+static inline void
+vmw_shmem_st64(target_phys_addr_t addr, uint64_t value)
+{
+DSHPRINTF("SHMEM store64: %" PRIx64 " (value %" PRIx64 ")", addr, value);
+stq_le_phys(addr, value);
+}
+
+/* MACROS for simplification of operations on array-style registers */
+#define IS_MULTIREG_ADDR(addr, base, cnt, regsize) \
+(((addr) >= (base)) && ((addr) < (base) + (cnt) * (regsize)))
+
+#define MULTIREG_IDX_BY_ADDR(addr, base, regsize)  \
+(((addr) - (base)) / (regsize))
+
+#endif
-- 
1.7.7.6




Re: [Qemu-devel] SPARC64: immediate segfault on startup with git mastervery

2012-03-18 Thread Avi Kivity
On 03/18/2012 04:01 AM, Mark Cave-Ayland wrote:
> Hi Avi/Blue,
>
> I've just updated to git master and found that SPARC64 is broken
> again; a git bisect shows the following commit causes this:
>
>
> commit f3705d53296d78b14f5823472ae2add16a25a0a5
> Author: Avi Kivity 
> Date:   Thu Mar 8 16:16:34 2012 +0200
>
> memory: make phys_page_find() return an unadjusted section
>
> We'd like to store the section index in the iotlb, so we can't
> adjust it before returning.  Return an unadjusted section and
> instead introduce section_addr(), which does the adjustment later.
>
> Signed-off-by: Avi Kivity 
>
>
> The symptom is that qemu-system-sparc64 segfaults immediately on
> startup (note this is with an OpenBIOS image built from SVN r1048).
> I've included a couple of backtraces below:
>

Please try the attached patch.

If it fails, can you upload bios and disk images somewhere?

-- 
error compiling committee.c: too many arguments to function

>From d1429f0bef16eb850a4ccc879cdc2212b41da40c Mon Sep 17 00:00:00 2001
From: Avi Kivity 
Date: Sun, 18 Mar 2012 11:42:00 +0200
Subject: [PATCH] sparc64: trim low-order bits from TLB entry during MMU
 translation

get_physical_address() returns a physical address with random low bits
set, which confuses tlb_set_page().  Fix by masking the low-order bits.

Signed-off-by: Avi Kivity 
---
 target-sparc/mmu_helper.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-sparc/mmu_helper.c b/target-sparc/mmu_helper.c
index 11fb9f5..27f7b27 100644
--- a/target-sparc/mmu_helper.c
+++ b/target-sparc/mmu_helper.c
@@ -491,7 +491,7 @@ static int get_physical_address_data(CPUSPARCState *env,
mmu_idx == MMU_USER_SECONDARY_IDX);
 
 if ((env->lsu & DMMU_E) == 0) { /* DMMU disabled */
-*physical = ultrasparc_truncate_physical(address);
+*physical = ultrasparc_truncate_physical(address) & TARGET_PAGE_MASK;
 *prot = PAGE_READ | PAGE_WRITE;
 return 0;
 }
@@ -610,7 +610,7 @@ static int get_physical_address_code(CPUSPARCState *env,
 
 if ((env->lsu & IMMU_E) == 0 || (env->pstate & PS_RED) != 0) {
 /* IMMU disabled */
-*physical = ultrasparc_truncate_physical(address);
+*physical = ultrasparc_truncate_physical(address) & TARGET_PAGE_MASK;
 *prot = PAGE_EXEC;
 return 0;
 }
-- 
1.7.9



Re: [Qemu-devel] SPARC64: immediate segfault on startup with git mastervery

2012-03-18 Thread Blue Swirl
On Sun, Mar 18, 2012 at 09:44, Avi Kivity  wrote:
> On 03/18/2012 04:01 AM, Mark Cave-Ayland wrote:
>> Hi Avi/Blue,
>>
>> I've just updated to git master and found that SPARC64 is broken
>> again; a git bisect shows the following commit causes this:
>>
>>
>> commit f3705d53296d78b14f5823472ae2add16a25a0a5
>> Author: Avi Kivity 
>> Date:   Thu Mar 8 16:16:34 2012 +0200
>>
>>     memory: make phys_page_find() return an unadjusted section
>>
>>     We'd like to store the section index in the iotlb, so we can't
>>     adjust it before returning.  Return an unadjusted section and
>>     instead introduce section_addr(), which does the adjustment later.
>>
>>     Signed-off-by: Avi Kivity 
>>
>>
>> The symptom is that qemu-system-sparc64 segfaults immediately on
>> startup (note this is with an OpenBIOS image built from SVN r1048).
>> I've included a couple of backtraces below:
>>
>
> Please try the attached patch.

I tried this approach instead, seems to work (except Sparc32, Sparc64
and PPC displays are still not refreshed correctly). The problem is
that f3705d53296d78b14f5823472ae2add16a25a0a5 converted addr & mask +
section.offset to section_addr(), but in some cases the offset within
page was not wanted.

diff --git a/exec.c b/exec.c
index 8fd50a1..ad455be 100644
--- a/exec.c
+++ b/exec.c
@@ -1474,8 +1474,8 @@ static void breakpoint_invalidate(CPUArchState
*env, target_ulong pc)
   || (section->mr->rom_device && section->mr->readable))) {
 return;
 }
-ram_addr = (memory_region_get_ram_addr(section->mr) & TARGET_PAGE_MASK)
-+ section_addr(section, addr);
+ram_addr = (memory_region_get_ram_addr(section->mr)
++ section_addr(section, pc)) & TARGET_PAGE_MASK;
 tb_invalidate_phys_page_range(ram_addr, ram_addr + 1, 0);
 }
 #endif
@@ -2205,14 +2205,14 @@ void tlb_set_page(CPUArchState *env, target_ulong vaddr,
 }
 if (is_ram_rom_romd(section)) {
 addend = (unsigned long)memory_region_get_ram_ptr(section->mr)
- + section_addr(section, paddr);
+ + section_addr(section, paddr & TARGET_PAGE_MASK);
 } else {
 addend = 0;
 }
 if (is_ram_rom(section)) {
 /* Normal RAM.  */
-iotlb = (memory_region_get_ram_addr(section->mr) & TARGET_PAGE_MASK)
-+ section_addr(section, paddr);
+iotlb = (memory_region_get_ram_addr(section->mr)
+ + section_addr(section, paddr)) & TARGET_PAGE_MASK;
 if (!section->readonly)
 iotlb |= phys_section_notdirty;
 else
@@ -2225,7 +2225,7 @@ void tlb_set_page(CPUArchState *env, target_ulong vaddr,
We can't use the high bits of pd for this because
IO_MEM_ROMD uses these as a ram address.  */
 iotlb = section - phys_sections;
-iotlb += section_addr(section, paddr);
+iotlb += section_addr(section, paddr & TARGET_PAGE_MASK);
 }

 code_address = address;
@@ -2265,7 +2265,7 @@ void tlb_set_page(CPUArchState *env, target_ulong vaddr,
 } else if (memory_region_is_ram(section->mr)
&& !cpu_physical_memory_is_dirty(
section->mr->ram_addr
-   + section_addr(section, paddr))) {
+   + section_addr(section, paddr &
TARGET_PAGE_MASK))) {
 te->addr_write = address | TLB_NOTDIRTY;
 } else {
 te->addr_write = address;



> If it fails, can you upload bios and disk images somewhere?
>
> --
> error compiling committee.c: too many arguments to function
>



[Qemu-devel] [PATCH 5/7 v5] Various utility functions used by VMWARE network devices

2012-03-18 Thread Dmitry Fleytman
Signed-off-by: Dmitry Fleytman 
Signed-off-by: Yan Vugenfirer 
---
 hw/vmxnet_debug.h |  121 
 hw/vmxnet_utils.c |  165 +++
 hw/vmxnet_utils.h |  320 +
 3 files changed, 606 insertions(+), 0 deletions(-)
 create mode 100644 hw/vmxnet_debug.h
 create mode 100644 hw/vmxnet_utils.c
 create mode 100644 hw/vmxnet_utils.h

diff --git a/hw/vmxnet_debug.h b/hw/vmxnet_debug.h
new file mode 100644
index 000..cc3471f
--- /dev/null
+++ b/hw/vmxnet_debug.h
@@ -0,0 +1,121 @@
+/*
+ * QEMU VMWARE VMXNET* paravirtual NICs - debugging facilities
+ *
+ * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
+ *
+ * Developed by Daynix Computing LTD (http://www.daynix.com)
+ *
+ * Authors:
+ * Dmitry Fleytman 
+ * Tamir Shomer 
+ * Yan Vugenfirer 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef _QEMU_VMXNET_DEBUG_H
+#define _QEMU_VMXNET_DEBUG_H
+
+#ifdef VMXNET_VERSION_2
+#define VMXNET_DEVICE_NAME "vmxnet"
+#elif defined VMXNET_VERSION_3
+#define VMXNET_DEVICE_NAME "vmxnet3"
+#else
+#error "VMXNET version is not defined"
+#endif
+
+/* #define DEBUG_VMXNET_CB */
+#define DEBUG_VMXNET_WARNINGS
+#define DEBUG_VMXNET_ERRORS
+/* #define DEBUG_VMXNET_INTERRUPTS */
+/* #define DEBUG_VMXNET_CONFIG */
+/* #define DEBUG_VMXNET_RINGS */
+/* #define DEBUG_VMXNET_PACKETS */
+/* #define DEBUG_VMXNET_SHMEM_ACCESS */
+
+#ifdef DEBUG_VMXNET_SHMEM_ACCESS
+#define DSHPRINTF(fmt, ...)   \
+do {  \
+printf("[%s][SH][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,   \
+## __VA_ARGS__);  \
+} while (0)
+#else
+#define DSHPRINTF(fmt, ...) do {} while (0)
+#endif
+
+#ifdef DEBUG_VMXNET_CB
+#define DCBPRINTF(fmt, ...)   \
+do {  \
+printf("[%s][CB][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,   \
+## __VA_ARGS__);  \
+} while (0)
+#else
+#define DCBPRINTF(fmt, ...) do {} while (0)
+#endif
+
+#ifdef DEBUG_VMXNET_PACKETS
+#define DPKPRINTF(fmt, ...)   \
+do {  \
+printf("[%s][PK][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,   \
+## __VA_ARGS__);  \
+} while (0)
+#else
+#define DPKPRINTF(fmt, ...) do {} while (0)
+#endif
+
+#ifdef DEBUG_VMXNET_WARNINGS
+#define DWRPRINTF(fmt, ...)   \
+do {  \
+printf("[%s][WR][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,   \
+## __VA_ARGS__);  \
+} while (0)
+#else
+#define DWRPRINTF(fmt, ...) do {} while (0)
+#endif
+
+#ifdef DEBUG_VMXNET_ERRORS
+#define DERPRINTF(fmt, ...)   \
+do {  \
+printf("[%s][ER][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,   \
+## __VA_ARGS__);  \
+} while (0)
+#else
+#define DERPRINTF(fmt, ...) do {} while (0)
+#endif
+
+#ifdef DEBUG_VMXNET_INTERRUPTS
+#define DIRPRINTF(fmt, ...)   \
+do {  \
+printf("[%s][IR][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,   \
+## __VA_ARGS__);  \
+} while (0)
+#else
+#define DIRPRINTF(fmt, ...) do {} while (0)
+#endif
+
+#ifdef DEBUG_VMXNET_CONFIG
+#define DCFPRINTF(fmt, ...)   \
+do {  \
+printf("[%s][CF][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,   \
+## __VA_ARGS__);  \
+} while (0)
+#else
+#define DCFPRINTF(fmt, ...) do {} while (0)
+#endif
+
+#ifdef DEBUG_VMXNET_RINGS
+#define DRIPRINTF(fmt, ...)   \
+do {  \
+printf("[%s][RI][%s]: " fmt "\n", VMXNET_DEVICE_NAME, __func__,   \
+## __VA_ARGS__);  \
+} while (0)
+#else
+#define DRIPRINTF(fmt, ...) do {} while (0)
+#endif
+
+#def

[Qemu-devel] [PATCH 3/7 v5] Adding utility function iov_net_csum_add() for iovec checksum calculation

2012-03-18 Thread Dmitry Fleytman
Signed-off-by: Dmitry Fleytman 
Signed-off-by: Yan Vugenfirer 
---
 iov.c |   29 +
 iov.h |3 +++
 2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/iov.c b/iov.c
index 0f96493..5d4f94c 100644
--- a/iov.c
+++ b/iov.c
@@ -16,6 +16,7 @@
  */
 
 #include "iov.h"
+#include "net/checksum.h"
 
 size_t iov_from_buf(struct iovec *iov, unsigned int iov_cnt,
 const void *buf, size_t iov_off, size_t size)
@@ -130,3 +131,31 @@ void iov_hexdump(const struct iovec *iov, const unsigned 
int iov_cnt,
 fprintf(fp, "\n");
 }
 }
+
+uint32_t
+iov_net_csum_add(const struct iovec *iov, const unsigned int iov_cnt,
+ size_t iov_off, size_t size)
+{
+size_t iovec_off, buf_off;
+unsigned int i;
+uint32_t res = 0;
+uint32_t seq = 0;
+
+iovec_off = 0;
+buf_off = 0;
+for (i = 0; i < iov_cnt && size; i++) {
+if (iov_off < (iovec_off + iov[i].iov_len)) {
+size_t len = MIN((iovec_off + iov[i].iov_len) - iov_off , size);
+void *chunk_buf = iov[i].iov_base + (iov_off - iovec_off);
+
+res += net_checksum_add_cont(len, chunk_buf, seq);
+seq += len;
+
+buf_off += len;
+iov_off += len;
+size -= len;
+}
+iovec_off += iov[i].iov_len;
+}
+return res;
+}
diff --git a/iov.h b/iov.h
index 94d2f78..ba385f5 100644
--- a/iov.h
+++ b/iov.h
@@ -21,3 +21,6 @@ size_t iov_clear(const struct iovec *iov, const unsigned int 
iov_cnt,
  size_t iov_off, size_t size);
 void iov_hexdump(const struct iovec *iov, const unsigned int iov_cnt,
  FILE *fp, const char *prefix, size_t limit);
+uint32_t
+iov_net_csum_add(const struct iovec *iov, const unsigned int iov_cnt,
+ size_t iov_off, size_t size);
-- 
1.7.7.6




Re: [Qemu-devel] SPARC64: immediate segfault on startup with git mastervery

2012-03-18 Thread Blue Swirl
On Sun, Mar 18, 2012 at 09:44, Avi Kivity  wrote:
> On 03/18/2012 04:01 AM, Mark Cave-Ayland wrote:
>> Hi Avi/Blue,
>>
>> I've just updated to git master and found that SPARC64 is broken
>> again; a git bisect shows the following commit causes this:
>>
>>
>> commit f3705d53296d78b14f5823472ae2add16a25a0a5
>> Author: Avi Kivity 
>> Date:   Thu Mar 8 16:16:34 2012 +0200
>>
>>     memory: make phys_page_find() return an unadjusted section
>>
>>     We'd like to store the section index in the iotlb, so we can't
>>     adjust it before returning.  Return an unadjusted section and
>>     instead introduce section_addr(), which does the adjustment later.
>>
>>     Signed-off-by: Avi Kivity 
>>
>>
>> The symptom is that qemu-system-sparc64 segfaults immediately on
>> startup (note this is with an OpenBIOS image built from SVN r1048).
>> I've included a couple of backtraces below:
>>
>
> Please try the attached patch.

That works too.

> If it fails, can you upload bios and disk images somewhere?
>
> --
> error compiling committee.c: too many arguments to function
>



Re: [Qemu-devel] [PATCH 3/5] exec: fix code tlb entry misused as iotlb in get_page_addr_code()

2012-03-18 Thread Avi Kivity
On 03/15/2012 09:23 PM, jcmvbkbc wrote:
> Hi.
>
>> get_page_addr_code() reads a code tlb entry, but interprets it as an
>> iotlb entry.  This works by accident since the low bits of a RAM code
>> tlb entry are clear, and match a RAM iotlb entry.  This accident is
>> about to unhappen, so fix the code to use an iotlb entry (using the
>> code entry with TLB_MMIO may fail if the page is a watchpoint).
>>
>> Signed-off-by: Avi Kivity
>> ---
>>   exec.c |2 +-
>>   1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/exec.c b/exec.c
>> index a35eb4f..f26d1b0 100644
>> --- a/exec.c
>> +++ b/exec.c
>> @@ -4685,7 +4685,7 @@ tb_page_addr_t get_page_addr_code(CPUState
>> *env1, target_ulong addr)
>>(addr&  TARGET_PAGE_MASK))) {
>>   ldub_code(addr);
>>   }
>> -pd = env1->tlb_table[mmu_idx][page_index].addr_code& 
>> ~TARGET_PAGE_MASK;
>> +pd = env1->iotlb[mmu_idx][page_index]&  ~TARGET_PAGE_MASK;
>>   if (pd != io_mem_ram.ram_addr&&  pd != io_mem_rom.ram_addr
>>   &&  !io_mem_region[pd]->rom_device) {
>>   #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) ||
>> defined(TARGET_SPARC)
>
> With this patch xtensa debug option unit test causes qemu abort with
> the message
>
>  qemu: fatal: Trying to execute code outside RAM or ROM at 0xd88c
>
> This happens immediately after a watchpoint setup for a data
> breakpoint at the same memory page where the currently
> executed code is located. Any idea on how to fix it?

Can you provide details on how to reproduce this?

-- 
error compiling committee.c: too many arguments to function




Re: [Qemu-devel] SPARC64: immediate segfault on startup with git mastervery

2012-03-18 Thread Mark Cave-Ayland

On 18/03/12 09:44, Avi Kivity wrote:


Hi Avi/Blue,

I've just updated to git master and found that SPARC64 is broken
again; a git bisect shows the following commit causes this:


commit f3705d53296d78b14f5823472ae2add16a25a0a5
Author: Avi Kivity
Date:   Thu Mar 8 16:16:34 2012 +0200

 memory: make phys_page_find() return an unadjusted section

 We'd like to store the section index in the iotlb, so we can't
 adjust it before returning.  Return an unadjusted section and
 instead introduce section_addr(), which does the adjustment later.

 Signed-off-by: Avi Kivity


The symptom is that qemu-system-sparc64 segfaults immediately on
startup (note this is with an OpenBIOS image built from SVN r1048).
I've included a couple of backtraces below:



Please try the attached patch.

If it fails, can you upload bios and disk images somewhere?


Hi Avi/Blue,

I can confirm that both patches work for me and enable SPARC64 to boot - 
Blue, what is the VGA display issue that you mention? I didn't see any 
display corruption when testing on both SPARC64 and PPC.


Upon inspection I see that Blue's patch seems to be a more of a global 
fix, whereas Avi's seems restricted to SPARC. Does that make Blue's 
patch a "better" solution since it will resolve the same undiscovered 
issue in other targets that make the same assumption?



Many thanks,

Mark.



Re: [Qemu-devel] SPARC64: immediate segfault on startup with git mastervery

2012-03-18 Thread Avi Kivity
On 03/18/2012 11:51 AM, Blue Swirl wrote:
> On Sun, Mar 18, 2012 at 09:44, Avi Kivity  wrote:
> > On 03/18/2012 04:01 AM, Mark Cave-Ayland wrote:
> >> Hi Avi/Blue,
> >>
> >> I've just updated to git master and found that SPARC64 is broken
> >> again; a git bisect shows the following commit causes this:
> >>
> >>
> >> commit f3705d53296d78b14f5823472ae2add16a25a0a5
> >> Author: Avi Kivity 
> >> Date:   Thu Mar 8 16:16:34 2012 +0200
> >>
> >> memory: make phys_page_find() return an unadjusted section
> >>
> >> We'd like to store the section index in the iotlb, so we can't
> >> adjust it before returning.  Return an unadjusted section and
> >> instead introduce section_addr(), which does the adjustment later.
> >>
> >> Signed-off-by: Avi Kivity 
> >>
> >>
> >> The symptom is that qemu-system-sparc64 segfaults immediately on
> >> startup (note this is with an OpenBIOS image built from SVN r1048).
> >> I've included a couple of backtraces below:
> >>
> >
> > Please try the attached patch.
>
> I tried this approach instead, seems to work 

IMO, my patch is better.  tlb_set_page() should not deal with offsets
within a page.

If you prefer your approach, I suggest masking the address up front in
the beginning of tlb_set_page() instead.

> (except Sparc32, Sparc64
> and PPC displays are still not refreshed correctly).

Details about this please.


-- 
error compiling committee.c: too many arguments to function




Re: [Qemu-devel] SPARC64: immediate segfault on startup with git mastervery

2012-03-18 Thread Blue Swirl
On Sun, Mar 18, 2012 at 10:31, Avi Kivity  wrote:
> On 03/18/2012 11:51 AM, Blue Swirl wrote:
>> On Sun, Mar 18, 2012 at 09:44, Avi Kivity  wrote:
>> > On 03/18/2012 04:01 AM, Mark Cave-Ayland wrote:
>> >> Hi Avi/Blue,
>> >>
>> >> I've just updated to git master and found that SPARC64 is broken
>> >> again; a git bisect shows the following commit causes this:
>> >>
>> >>
>> >> commit f3705d53296d78b14f5823472ae2add16a25a0a5
>> >> Author: Avi Kivity 
>> >> Date:   Thu Mar 8 16:16:34 2012 +0200
>> >>
>> >>     memory: make phys_page_find() return an unadjusted section
>> >>
>> >>     We'd like to store the section index in the iotlb, so we can't
>> >>     adjust it before returning.  Return an unadjusted section and
>> >>     instead introduce section_addr(), which does the adjustment later.
>> >>
>> >>     Signed-off-by: Avi Kivity 
>> >>
>> >>
>> >> The symptom is that qemu-system-sparc64 segfaults immediately on
>> >> startup (note this is with an OpenBIOS image built from SVN r1048).
>> >> I've included a couple of backtraces below:
>> >>
>> >
>> > Please try the attached patch.
>>
>> I tried this approach instead, seems to work
>
> IMO, my patch is better.  tlb_set_page() should not deal with offsets
> within a page.

It looks like all targets except Sparc32/64 mask the addresses before
passing to tlb_set_page(), so I agree.

> If you prefer your approach, I suggest masking the address up front in
> the beginning of tlb_set_page() instead.
>
>> (except Sparc32, Sparc64
>> and PPC displays are still not refreshed correctly).
>
> Details about this please.

Screen is not updated correctly, there are lines from previous
screenful. Pressing ctrl-alt-1 refreshes the display. Perhaps dirty
tracking is broken? VGA in x86 works.

>
> --
> error compiling committee.c: too many arguments to function
>



Re: [Qemu-devel] SPARC64: immediate segfault on startup with git mastervery

2012-03-18 Thread Mark Cave-Ayland

On 18/03/12 10:51, Blue Swirl wrote:


(except Sparc32, Sparc64
and PPC displays are still not refreshed correctly).


Details about this please.


Screen is not updated correctly, there are lines from previous
screenful. Pressing ctrl-alt-1 refreshes the display. Perhaps dirty
tracking is broken? VGA in x86 works.


Is that using SDL? Do you see the same issue with VNC too?


ATB,

Mark.



Re: [Qemu-devel] [PATCH 3/5] exec: fix code tlb entry misused as iotlb in get_page_addr_code()

2012-03-18 Thread Max Filippov
>>> get_page_addr_code() reads a code tlb entry, but interprets it as an
>>> iotlb entry.  This works by accident since the low bits of a RAM code
>>> tlb entry are clear, and match a RAM iotlb entry.  This accident is
>>> about to unhappen, so fix the code to use an iotlb entry (using the
>>> code entry with TLB_MMIO may fail if the page is a watchpoint).
>>>
>>> Signed-off-by: Avi Kivity
>>> ---
>>>   exec.c |    2 +-
>>>   1 files changed, 1 insertions(+), 1 deletions(-)
>>>
>>> diff --git a/exec.c b/exec.c
>>> index a35eb4f..f26d1b0 100644
>>> --- a/exec.c
>>> +++ b/exec.c
>>> @@ -4685,7 +4685,7 @@ tb_page_addr_t get_page_addr_code(CPUState
>>> *env1, target_ulong addr)
>>>                    (addr&  TARGET_PAGE_MASK))) {
>>>           ldub_code(addr);
>>>       }
>>> -    pd = env1->tlb_table[mmu_idx][page_index].addr_code&
>>> ~TARGET_PAGE_MASK;
>>> +    pd = env1->iotlb[mmu_idx][page_index]&  ~TARGET_PAGE_MASK;
>>>       if (pd != io_mem_ram.ram_addr&&  pd != io_mem_rom.ram_addr
>>>           &&  !io_mem_region[pd]->rom_device) {
>>>   #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) ||
>>> defined(TARGET_SPARC)
>>
>> With this patch xtensa debug option unit test causes qemu abort with
>> the message
>>
>>  qemu: fatal: Trying to execute code outside RAM or ROM at 0xd88c
>>
>> This happens immediately after a watchpoint setup for a data
>> breakpoint at the same memory page where the currently
>> executed code is located. Any idea on how to fix it?
>
> Can you provide details on how to reproduce this?

It may be reproduced by running test_break.tst unit test:

qemu-system-xtensa -M sim -cpu dc232b -nographic -semihosting  -kernel
./test_break.tst

Compiled test binary is here:
http://jcmvbkbc.spb.ru/~dumb/ws/osll/qemu-xtensa/20120318/test_break.tst

-- 
Thanks.
-- Max



Re: [Qemu-devel] SPARC64: immediate segfault on startup with git mastervery

2012-03-18 Thread Blue Swirl
On Sun, Mar 18, 2012 at 11:03, Mark Cave-Ayland
 wrote:
> On 18/03/12 10:51, Blue Swirl wrote:
>
 (except Sparc32, Sparc64
 and PPC displays are still not refreshed correctly).
>>>
>>>
>>> Details about this please.
>>
>>
>> Screen is not updated correctly, there are lines from previous
>> screenful. Pressing ctrl-alt-1 refreshes the display. Perhaps dirty
>> tracking is broken? VGA in x86 works.
>
>
> Is that using SDL? Do you see the same issue with VNC too?

Yes to both.

>
>
> ATB,
>
> Mark.



[Qemu-devel] [PATCH] sparc: pass page aligned addresses to tlb_set_page

2012-03-18 Thread Blue Swirl
Mask incoming page address early so that resolved addresses
are page aligned. Remove further address masking.

Signed-off-by: Blue Swirl 
---
 target-sparc/mmu_helper.c |   19 ---
 1 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/target-sparc/mmu_helper.c b/target-sparc/mmu_helper.c
index 11fb9f5..cb73c44 100644
--- a/target-sparc/mmu_helper.c
+++ b/target-sparc/mmu_helper.c
@@ -150,18 +150,17 @@ static int get_physical_address(CPUSPARCState
*env, target_phys_addr_t *physical
 case 3: /* Reserved */
 return (3 << 8) | (4 << 2);
 case 2: /* L3 PTE */
-page_offset = (address & TARGET_PAGE_MASK) &
-(TARGET_PAGE_SIZE - 1);
+page_offset = 0;
 }
 *page_size = TARGET_PAGE_SIZE;
 break;
 case 2: /* L2 PTE */
-page_offset = address & 0x3;
+page_offset = address & 0x3f000;
 *page_size = 0x4;
 }
 break;
 case 2: /* L1 PTE */
-page_offset = address & 0xff;
+page_offset = address & 0xfff000;
 *page_size = 0x100;
 }
 }
@@ -206,11 +205,11 @@ int cpu_sparc_handle_mmu_fault(CPUSPARCState
*env, target_ulong address, int rw,
 target_ulong page_size;
 int error_code = 0, prot, access_index;

+address &= TARGET_PAGE_MASK;
 error_code = get_physical_address(env, &paddr, &prot, &access_index,
   address, rw, mmu_idx, &page_size);
+vaddr = address;
 if (error_code == 0) {
-vaddr = address & TARGET_PAGE_MASK;
-paddr &= TARGET_PAGE_MASK;
 #ifdef DEBUG_MMU
 printf("Translate at " TARGET_FMT_lx " -> " TARGET_FMT_plx ", vaddr "
TARGET_FMT_lx "\n", address, paddr, vaddr);
@@ -230,7 +229,6 @@ int cpu_sparc_handle_mmu_fault(CPUSPARCState *env,
target_ulong address, int rw,
permissions. If no mapping is available, redirect accesses to
neverland. Fake/overridden mappings will be flushed when
switching to normal mode. */
-vaddr = address & TARGET_PAGE_MASK;
 prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC;
 tlb_set_page(env, vaddr, paddr, prot, mmu_idx, TARGET_PAGE_SIZE);
 return 0;
@@ -704,17 +702,16 @@ static int get_physical_address(CPUSPARCState
*env, target_phys_addr_t *physical
 int cpu_sparc_handle_mmu_fault(CPUSPARCState *env, target_ulong
address, int rw,
int mmu_idx)
 {
-target_ulong virt_addr, vaddr;
+target_ulong vaddr;
 target_phys_addr_t paddr;
 target_ulong page_size;
 int error_code = 0, prot, access_index;

+address &= TARGET_PAGE_MASK;
 error_code = get_physical_address(env, &paddr, &prot, &access_index,
   address, rw, mmu_idx, &page_size);
 if (error_code == 0) {
-virt_addr = address & TARGET_PAGE_MASK;
-vaddr = virt_addr + ((address & TARGET_PAGE_MASK) &
- (TARGET_PAGE_SIZE - 1));
+vaddr = address;

 trace_mmu_helper_mmu_fault(address, paddr, mmu_idx, env->tl,
env->dmmu.mmu_primary_context,
-- 
1.7.9



[Qemu-devel] [PATCH 1/2] ioport: use INT64_MAX for IO ranges

2012-03-18 Thread Blue Swirl
Expression UINT64_MAX + 1 will make the range bigger than
what can be represented with a 64 bit type. This would
trigger an assert in int128_get64() after the next patch.

Signed-off-by: Blue Swirl 
---
 ioport.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/ioport.c b/ioport.c
index 78a3b89..6e4ca0d 100644
--- a/ioport.c
+++ b/ioport.c
@@ -385,7 +385,7 @@ static void portio_list_add_1(PortioList *piolist,
  * rather than an offset relative to to start + off_low.
  */
 memory_region_init_io(region, ops, piolist->opaque, piolist->name,
-  UINT64_MAX);
+  INT64_MAX);
 memory_region_init_alias(alias, piolist->name,
  region, start + off_low, off_high - off_low);
 memory_region_add_subregion(piolist->address_space,
-- 
1.7.9
From b13b8706a5a44c1d35c0ce459cbb9fde01dc910f Mon Sep 17 00:00:00 2001
Message-Id: 
From: Blue Swirl 
Date: Sat, 10 Mar 2012 16:57:10 +
Subject: [PATCH 1/2] ioport: use INT64_MAX for IO ranges

Expression UINT64_MAX + 1 will make the range bigger than
what can be represented with a 64 bit type. This would
trigger an assert in int128_get64() after the next patch.

Signed-off-by: Blue Swirl 
---
 ioport.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/ioport.c b/ioport.c
index 78a3b89..6e4ca0d 100644
--- a/ioport.c
+++ b/ioport.c
@@ -385,7 +385,7 @@ static void portio_list_add_1(PortioList *piolist,
  * rather than an offset relative to to start + off_low.
  */
 memory_region_init_io(region, ops, piolist->opaque, piolist->name,
-  UINT64_MAX);
+  INT64_MAX);
 memory_region_init_alias(alias, piolist->name,
  region, start + off_low, off_high - off_low);
 memory_region_add_subregion(piolist->address_space,
-- 
1.7.2.5



[Qemu-devel] [PATCH v2 2/2] memory: print aliased IO ranges in info mtree

2012-03-18 Thread Blue Swirl
Print also I/O ports behind bridges and other aliases.

Signed-off-by: Blue Swirl 
---
 memory.c |   14 +++---
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/memory.c b/memory.c
index 22b0352..a3f5b59 100644
--- a/memory.c
+++ b/memory.c
@@ -1621,6 +1621,13 @@ void mtree_info(fprintf_function mon_printf, void *f)
 mon_printf(f, "memory\n");
 mtree_print_mr(mon_printf, f, address_space_memory.root, 0, 0, &ml_head);

+if (address_space_io.root &&
+!QTAILQ_EMPTY(&address_space_io.root->subregions)) {
+mon_printf(f, "I/O\n");
+mtree_print_mr(mon_printf, f, address_space_io.root, 0, 0, &ml_head);
+}
+
+mon_printf(f, "aliases\n");
 /* print aliased regions */
 QTAILQ_FOREACH(ml, &ml_head, queue) {
 if (!ml->printed) {
@@ -1632,11 +1639,4 @@ void mtree_info(fprintf_function mon_printf, void *f)
 QTAILQ_FOREACH_SAFE(ml, &ml_head, queue, ml2) {
 g_free(ml);
 }
-
-if (address_space_io.root &&
-!QTAILQ_EMPTY(&address_space_io.root->subregions)) {
-QTAILQ_INIT(&ml_head);
-mon_printf(f, "I/O\n");
-mtree_print_mr(mon_printf, f, address_space_io.root, 0, 0, &ml_head);
-}
 }
-- 
1.7.9
From dd09131faaace204878c23c3e019061953ad3305 Mon Sep 17 00:00:00 2001
Message-Id: 
In-Reply-To: 
References: 
From: Blue Swirl 
Date: Sat, 10 Mar 2012 16:58:35 +
Subject: [PATCH 2/2] memory: print aliased IO ranges in info mtree

Print also I/O ports behind bridges and other aliases.

Signed-off-by: Blue Swirl 
---
 memory.c |   14 +++---
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/memory.c b/memory.c
index 22b0352..a3f5b59 100644
--- a/memory.c
+++ b/memory.c
@@ -1621,6 +1621,13 @@ void mtree_info(fprintf_function mon_printf, void *f)
 mon_printf(f, "memory\n");
 mtree_print_mr(mon_printf, f, address_space_memory.root, 0, 0, &ml_head);
 
+if (address_space_io.root &&
+!QTAILQ_EMPTY(&address_space_io.root->subregions)) {
+mon_printf(f, "I/O\n");
+mtree_print_mr(mon_printf, f, address_space_io.root, 0, 0, &ml_head);
+}
+
+mon_printf(f, "aliases\n");
 /* print aliased regions */
 QTAILQ_FOREACH(ml, &ml_head, queue) {
 if (!ml->printed) {
@@ -1632,11 +1639,4 @@ void mtree_info(fprintf_function mon_printf, void *f)
 QTAILQ_FOREACH_SAFE(ml, &ml_head, queue, ml2) {
 g_free(ml);
 }
-
-if (address_space_io.root &&
-!QTAILQ_EMPTY(&address_space_io.root->subregions)) {
-QTAILQ_INIT(&ml_head);
-mon_printf(f, "I/O\n");
-mtree_print_mr(mon_printf, f, address_space_io.root, 0, 0, &ml_head);
-}
 }
-- 
1.7.2.5



Re: [Qemu-devel] SPARC64: immediate segfault on startup with git mastervery

2012-03-18 Thread Avi Kivity
On 03/18/2012 12:51 PM, Blue Swirl wrote:
> >
> > IMO, my patch is better.  tlb_set_page() should not deal with offsets
> > within a page.
>
> It looks like all targets except Sparc32/64 mask the addresses before
> passing to tlb_set_page(), so I agree.

Ok.  Commit my patch then?

> > If you prefer your approach, I suggest masking the address up front in
> > the beginning of tlb_set_page() instead.
> >
> >> (except Sparc32, Sparc64
> >> and PPC displays are still not refreshed correctly).
> >
> > Details about this please.
>
> Screen is not updated correctly, there are lines from previous
> screenful. Pressing ctrl-alt-1 refreshes the display. Perhaps dirty
> tracking is broken? VGA in x86 works.

Ok, I see it.  Will investigate.

-- 
error compiling committee.c: too many arguments to function




Re: [Qemu-devel] SPARC64: immediate segfault on startup with git mastervery

2012-03-18 Thread Blue Swirl
On Sun, Mar 18, 2012 at 12:08, Avi Kivity  wrote:
> On 03/18/2012 12:51 PM, Blue Swirl wrote:
>> >
>> > IMO, my patch is better.  tlb_set_page() should not deal with offsets
>> > within a page.
>>
>> It looks like all targets except Sparc32/64 mask the addresses before
>> passing to tlb_set_page(), so I agree.
>
> Ok.  Commit my patch then?

I sent a different patch which masks incoming address earlier and
removes unnecessary masking in other places.

>> > If you prefer your approach, I suggest masking the address up front in
>> > the beginning of tlb_set_page() instead.
>> >
>> >> (except Sparc32, Sparc64
>> >> and PPC displays are still not refreshed correctly).
>> >
>> > Details about this please.
>>
>> Screen is not updated correctly, there are lines from previous
>> screenful. Pressing ctrl-alt-1 refreshes the display. Perhaps dirty
>> tracking is broken? VGA in x86 works.
>
> Ok, I see it.  Will investigate.
>
> --
> error compiling committee.c: too many arguments to function
>



Re: [Qemu-devel] SPARC64: immediate segfault on startup with git mastervery

2012-03-18 Thread Avi Kivity
On 03/18/2012 02:10 PM, Blue Swirl wrote:
> On Sun, Mar 18, 2012 at 12:08, Avi Kivity  wrote:
> > On 03/18/2012 12:51 PM, Blue Swirl wrote:
> >> >
> >> > IMO, my patch is better.  tlb_set_page() should not deal with offsets
> >> > within a page.
> >>
> >> It looks like all targets except Sparc32/64 mask the addresses before
> >> passing to tlb_set_page(), so I agree.
> >
> > Ok.  Commit my patch then?
>
> I sent a different patch which masks incoming address earlier and
> removes unnecessary masking in other places.

My patch missed the "boot mode" thing.  Does your patch fix it?

-- 
error compiling committee.c: too many arguments to function




Re: [Qemu-devel] SPARC64: immediate segfault on startup with git mastervery

2012-03-18 Thread Blue Swirl
On Sun, Mar 18, 2012 at 12:13, Avi Kivity  wrote:
> On 03/18/2012 02:10 PM, Blue Swirl wrote:
>> On Sun, Mar 18, 2012 at 12:08, Avi Kivity  wrote:
>> > On 03/18/2012 12:51 PM, Blue Swirl wrote:
>> >> >
>> >> > IMO, my patch is better.  tlb_set_page() should not deal with offsets
>> >> > within a page.
>> >>
>> >> It looks like all targets except Sparc32/64 mask the addresses before
>> >> passing to tlb_set_page(), so I agree.
>> >
>> > Ok.  Commit my patch then?
>>
>> I sent a different patch which masks incoming address earlier and
>> removes unnecessary masking in other places.
>
> My patch missed the "boot mode" thing.  Does your patch fix it?

Yes. I also fixed both Sparc32 (which didn't have problems) and Sparc64.

>
> --
> error compiling committee.c: too many arguments to function
>



Re: [Qemu-devel] [PATCH] virtio-spec: split virtio-net device status filed into ro and rw byte

2012-03-18 Thread Michael S. Tsirkin
On Fri, Mar 16, 2012 at 11:20:26PM +0800, Jason Wang wrote:
> This patch splits the device status field of virtio-net into ro and rw
> byte. This would simplify the implementation of both host and guest
> and make the layout more clean. As VIRTIO_NET_S_ANNOUNCE is a rw bit,
> it was moved to bit 8 (0x100).
> 
> btw. looks like there's no implementation that depends on
> VIRTIO_NET_S_ANNOUNCE, so the move is safe.
> 
> Signed-off-by: Jason Wang 

Hmm, I know I proposed this myself, and I thought it will
prevent problems if we will add more rw bits,
but I missed the following race:

host writes VIRTIO_NET_S_ANNOUNCE = 1, interrupt

guest reads VIRTIO_NET_S_ANNOUNCE = 1

host writes VIRTIO_NET_S_SOME_NEW_FIELD = 1, interrupt

guest writes VIRTIO_NET_S_ANNOUNCE = 0
VIRTIO_NET_S_SOME_NEW_FIELD is overwritten

guest reads VIRTIO_NET_S_SOME_NEW_FIELD = 0

How about making the new bit write 1 to clear?
If we do, we can keep it where it is currently ...



> ---
>  virtio-0.9.4.lyx |   20 +++-
>  1 files changed, 19 insertions(+), 1 deletions(-)
> 
> diff --git a/virtio-0.9.4.lyx b/virtio-0.9.4.lyx
> index 6c7bab1..ef3951c 100644
> --- a/virtio-0.9.4.lyx
> +++ b/virtio-0.9.4.lyx
> @@ -58,6 +58,7 @@
>  \html_be_strict false
>  \author -608949062 "Rusty Russell,,," 
>  \author 1531152142 "pbonzini" 
> +\author 2090695081 "Jason" 
>  \end_header
>  
>  \begin_body
> @@ -4012,8 +4013,19 @@ configuration
>  layout Two configuration fields are currently defined.
>   The mac address field always exists (though is only valid if 
> VIRTIO_NET_F_MAC
>   is set), and the status field only exists if VIRTIO_NET_F_STATUS is set.
> +
> +\change_inserted 2090695081 1331907586
> + The low byte of status field is read-only, guest write to this byte would
> + be ignored.
> + Currently only one bit is defined for this byte: VIRTIO_NET_S_LINK_UP.
> + The high byte of status field is read-writable.
> + Currently only one bit is defined for this byte: VIRTIO_NET_S_ANNOUNCE.
> +
> +\change_deleted 2090695081 1331907489
>   Two bits are currently defined for the status field: VIRTIO_NET_S_LINK_UP
>   and VIRTIO_NET_S_ANNOUNCE.
> +
> +\change_unchanged
>   
>  \begin_inset listings
>  inline false
> @@ -4026,7 +4038,13 @@ status open
>  
>  \begin_layout Plain Layout
>  
> -#define VIRTIO_NET_S_ANNOUNCE2
> +#define VIRTIO_NET_S_ANNOUNCE
> +\change_inserted 2090695081 1331907493
> +0x100
> +\change_deleted 2090695081 1331907491
> +2
> +\change_unchanged
> +
>  \end_layout
>  
>  \begin_layout Plain Layout



Re: [Qemu-devel] [PATCH] Remove PCI class code from virtio balloon device

2012-03-18 Thread Michael S. Tsirkin
On Fri, Mar 16, 2012 at 12:03:08PM +1100, David Gibson wrote:
> Currently the virtio balloon device, when using the virtio-pci interface
> advertises itself with PCI class code MEMORY_RAM.  This is wrong; the
> balloon is vaguely related to memory, but is nothing like a PCI memory
> device in the meaning of the class code, and this code is not required or
> suggested by the virtio PCI specification.
> 
> Worse, this patch causes problems on the pseries machine, because the
> firmware, seeing this class code, advertises the device as memory in the
> device tree, and then a guest kernel bug causes it to see this "memory"
> before the real system memory, leading to a crash in early boot.
> 
> This patch fixes the problem by removing the bogus PCI class code on the
> balloon device.
> 
> Cc: Michael S. Tsirkin 
> Cc: Rusty Russell 
> 
> Signed-off-by: David Gibson 

Well, this gives the class a legacy value 00,
and the PCI spec says we should not use this:

D.1.
Base Class 00h
This base class is defined to provide backward compatibility for devices
that were built
before the Class Code field was defined. No new devices should use this
value and existing
devices should switch to a more appropriate value if possible.
For class codes with this base class value, there are two defined values
for the remaining
fields as shown in the table below. All other values are reserved.
Base Class
00h
Sub-Class
Interface
00h
01h
VGA-compatible device
00h
00h
All currently implemented devices
except VGA-compatible devices

You probably want this instead:

#define PCI_CLASS_OTHERS0xff


> ---
>  hw/virtio-pci.c |1 -
>  1 files changed, 0 insertions(+), 1 deletions(-)
> 
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index a0fb7c1..3c3907a 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -919,7 +919,6 @@ static void virtio_balloon_class_init(ObjectClass *klass, 
> void *data)
>  k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
>  k->device_id = PCI_DEVICE_ID_VIRTIO_BALLOON;
>  k->revision = VIRTIO_PCI_ABI_VERSION;
> -k->class_id = PCI_CLASS_MEMORY_RAM;
>  dc->reset = virtio_pci_reset;
>  dc->props = virtio_balloon_properties;
>  }
> -- 
> 1.7.9.1



[Qemu-devel] [PATCH v4 0/3] qxl trace events

2012-03-18 Thread Alon Levy
Changes from v3:
 removed three trace-events that were unused (stap complains)
 added missing #include "trace.h" in spice-display.c
 tested with stap
 added reviewed-by from Stefan Hajnoczi (taking the liberty to
   assume the minor changes from v2 are ok)

Changes from v2:
 split 6+ trace points to X + X_rest (leave qid as first argument in both) 
(Stefan)
 (cleanup as requested by Gerd)
 no trace event for pipe write failure, left dprint there anyway.
 indentation in a separate patch
 qxl-render.c: qxl_render prefix
 spice-display.c: qemu_spice functions trace names prefixed with qemu_spice

Changes from v1:
 add qid prefix to all tracepoints (except vga update which makes no sense)
 rename to ring where suggested (Gerd)
 add some trace points to spice-display
 drop enter/exit in favor of a single command (Gerd)
 some sorting of the trace event list

Alon Levy (3):
  qxl: init_pipe_signaling: exit on failure
  qxl: switch qxl.c to trace-events
  qxl/qxl_render.c: add trace events

 hw/qxl-render.c|   13 ++---
 hw/qxl.c   |  160 ++--
 trace-events   |   66 ++
 ui/spice-display.c |   14 -
 4 files changed, 161 insertions(+), 92 deletions(-)

-- 
1.7.9.3




[Qemu-devel] [PATCH v4 3/3] qxl/qxl_render.c: add trace events

2012-03-18 Thread Alon Levy
Signed-off-by: Alon Levy 
Reviewed-by: Stefan Hajnoczi 
---
 hw/qxl-render.c |   13 -
 trace-events|7 +++
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/hw/qxl-render.c b/hw/qxl-render.c
index 25857f6..28ab182 100644
--- a/hw/qxl-render.c
+++ b/hw/qxl-render.c
@@ -31,11 +31,10 @@ static void qxl_blit(PCIQXLDevice *qxl, QXLRect *rect)
 return;
 }
 if (!qxl->guest_primary.data) {
-dprint(qxl, 1, "%s: initializing guest_primary.data\n", __func__);
+trace_qxl_render_blit_guest_primary_initialized();
 qxl->guest_primary.data = memory_region_get_ram_ptr(&qxl->vga.vram);
 }
-dprint(qxl, 2, "%s: stride %d, [%d, %d, %d, %d]\n", __func__,
-qxl->guest_primary.qxl_stride,
+trace_qxl_render_blit(qxl->guest_primary.qxl_stride,
 rect->left, rect->right, rect->top, rect->bottom);
 src = qxl->guest_primary.data;
 if (qxl->guest_primary.qxl_stride < 0) {
@@ -107,8 +106,7 @@ static void qxl_render_update_area_unlocked(PCIQXLDevice 
*qxl)
 qxl->guest_primary.data = memory_region_get_ram_ptr(&qxl->vga.vram);
 qxl_set_rect_to_surface(qxl, &qxl->dirty[0]);
 qxl->num_dirty_rects = 1;
-dprint(qxl, 1, "%s: %dx%d, stride %d, bpp %d, depth %d\n",
-   __FUNCTION__,
+trace_qxl_render_guest_primary_resized(
qxl->guest_primary.surface.width,
qxl->guest_primary.surface.height,
qxl->guest_primary.qxl_stride,
@@ -118,8 +116,6 @@ static void qxl_render_update_area_unlocked(PCIQXLDevice 
*qxl)
 if (surface->width != qxl->guest_primary.surface.width ||
 surface->height != qxl->guest_primary.surface.height) {
 if (qxl->guest_primary.qxl_stride > 0) {
-dprint(qxl, 1, "%s: using guest_primary for displaysurface\n",
-   __func__);
 qemu_free_displaysurface(vga->ds);
 qemu_create_displaysurface_from(qxl->guest_primary.surface.width,
 qxl->guest_primary.surface.height,
@@ -127,8 +123,6 @@ static void qxl_render_update_area_unlocked(PCIQXLDevice 
*qxl)
 qxl->guest_primary.abs_stride,
 qxl->guest_primary.data);
 } else {
-dprint(qxl, 1, "%s: resizing displaysurface to guest_primary\n",
-   __func__);
 qemu_resize_displaysurface(vga->ds,
 qxl->guest_primary.surface.width,
 qxl->guest_primary.surface.height);
@@ -187,6 +181,7 @@ void qxl_render_update_area_bh(void *opaque)
 void qxl_render_update_area_done(PCIQXLDevice *qxl, QXLCookie *cookie)
 {
 qemu_mutex_lock(&qxl->ssd.lock);
+trace_qxl_render_update_area_done(cookie);
 qemu_bh_schedule(qxl->update_area_bh);
 qxl->render_update_cookie_num--;
 qemu_mutex_unlock(&qxl->ssd.lock);
diff --git a/trace-events b/trace-events
index 27578d3..29eee0f 100644
--- a/trace-events
+++ b/trace-events
@@ -781,3 +781,10 @@ qxl_spice_reset_memslots(int qid) "%d"
 qxl_spice_update_area(int qid, uint32_t surface_id, uint32_t left, uint32_t 
right, uint32_t top, uint32_t bottom) "%d sid=%d [%d,%d,%d,%d]"
 qxl_spice_update_area_rest(int qid, uint32_t num_dirty_rects, uint32_t 
clear_dirty_region) "%d #d=%d clear=%d"
 qxl_surfaces_dirty(int qid, int surface, int offset, int size) "%d surface=%d 
offset=%d size=%d"
+qxl_vga_ioport_while_not_in_vga_mode(int qid) "%d (int qid, reset to VGA mode 
because of VGA io)"
+
+# hw/qxl-render.c
+qxl_render_blit_guest_primary_initialized(void) ""
+qxl_render_blit(int32_t stride, int32_t left, int32_t right, int32_t top, 
int32_t bottom) "stride=%d [%d, %d, %d, %d]"
+qxl_render_guest_primary_resized(int32_t width, int32_t height, int32_t 
stride, int32_t bytes_pp, int32_t bits_pp) "%dx%d, stride %d, bpp %d, depth %d"
+qxl_render_update_area_done(void *cookie) "%p"
-- 
1.7.9.3




[Qemu-devel] [PATCH v4 1/3] qxl: init_pipe_signaling: exit on failure

2012-03-18 Thread Alon Levy
If pipe creation fails, exit, don't log and continue. Fix indentation at
the same time.

Signed-off-by: Alon Levy 
---
 hw/qxl.c |   21 +++--
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/hw/qxl.c b/hw/qxl.c
index e17b0e3..26ca893 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -1452,16 +1452,17 @@ static void qxl_send_events(PCIQXLDevice *d, uint32_t 
events)
 
 static void init_pipe_signaling(PCIQXLDevice *d)
 {
-   if (pipe(d->pipe) < 0) {
-   dprint(d, 1, "%s: pipe creation failed\n", __FUNCTION__);
-   return;
-   }
-   fcntl(d->pipe[0], F_SETFL, O_NONBLOCK);
-   fcntl(d->pipe[1], F_SETFL, O_NONBLOCK);
-   fcntl(d->pipe[0], F_SETOWN, getpid());
-
-   qemu_thread_get_self(&d->main);
-   qemu_set_fd_handler(d->pipe[0], pipe_read, NULL, d);
+if (pipe(d->pipe) < 0) {
+fprintf(stderr, "%s:%s: qxl pipe creation failed\n",
+__FILE__, __func__);
+exit(1);
+}
+fcntl(d->pipe[0], F_SETFL, O_NONBLOCK);
+fcntl(d->pipe[1], F_SETFL, O_NONBLOCK);
+fcntl(d->pipe[0], F_SETOWN, getpid());
+
+qemu_thread_get_self(&d->main);
+qemu_set_fd_handler(d->pipe[0], pipe_read, NULL, d);
 }
 
 /* graphics console */
-- 
1.7.9.3




[Qemu-devel] [PATCH v4 2/3] qxl: switch qxl.c to trace-events

2012-03-18 Thread Alon Levy
dprint is still used for qxl_init_common one time prints.

also switched parts of spice-display.c over, mainly all the callbacks to
spice server.

All qxl device trace events start with the qxl device id.

Signed-off-by: Alon Levy 
Reviewed-by: Stefan Hajnoczi 
---
 hw/qxl.c   |  141 +---
 trace-events   |   59 ++
 ui/spice-display.c |   14 +-
 3 files changed, 140 insertions(+), 74 deletions(-)

diff --git a/hw/qxl.c b/hw/qxl.c
index 26ca893..d28c1c0 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -23,6 +23,7 @@
 #include "qemu-queue.h"
 #include "monitor.h"
 #include "sysemu.h"
+#include "trace.h"
 
 #include "qxl.h"
 
@@ -143,6 +144,10 @@ void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t 
surface_id,
uint32_t clear_dirty_region,
qxl_async_io async, struct QXLCookie *cookie)
 {
+trace_qxl_spice_update_area(qxl->id, surface_id, area->left, area->right,
+area->top, area->bottom);
+trace_qxl_spice_update_area_rest(qxl->id, num_dirty_rects,
+ clear_dirty_region);
 if (async == QXL_SYNC) {
 qxl->ssd.worker->update_area(qxl->ssd.worker, surface_id, area,
 dirty_rects, num_dirty_rects, clear_dirty_region);
@@ -156,6 +161,7 @@ void qxl_spice_update_area(PCIQXLDevice *qxl, uint32_t 
surface_id,
 static void qxl_spice_destroy_surface_wait_complete(PCIQXLDevice *qxl,
 uint32_t id)
 {
+trace_qxl_spice_destroy_surface_wait_complete(qxl->id, id);
 qemu_mutex_lock(&qxl->track_lock);
 qxl->guest_surfaces.cmds[id] = 0;
 qxl->guest_surfaces.count--;
@@ -167,6 +173,7 @@ static void qxl_spice_destroy_surface_wait(PCIQXLDevice 
*qxl, uint32_t id,
 {
 QXLCookie *cookie;
 
+trace_qxl_spice_destroy_surface_wait(qxl->id, id, async);
 if (async) {
 cookie = qxl_cookie_new(QXL_COOKIE_TYPE_IO,
 QXL_IO_DESTROY_SURFACE_ASYNC);
@@ -174,12 +181,13 @@ static void qxl_spice_destroy_surface_wait(PCIQXLDevice 
*qxl, uint32_t id,
 spice_qxl_destroy_surface_async(&qxl->ssd.qxl, id, (uint64_t)cookie);
 } else {
 qxl->ssd.worker->destroy_surface_wait(qxl->ssd.worker, id);
-qxl_spice_destroy_surface_wait_complete(qxl, id);
 }
 }
 
 static void qxl_spice_flush_surfaces_async(PCIQXLDevice *qxl)
 {
+trace_qxl_spice_flush_surfaces_async(qxl->id, qxl->guest_surfaces.count,
+ qxl->num_free_res);
 spice_qxl_flush_surfaces_async(&qxl->ssd.qxl,
 (uint64_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
  QXL_IO_FLUSH_SURFACES_ASYNC));
@@ -188,21 +196,25 @@ static void qxl_spice_flush_surfaces_async(PCIQXLDevice 
*qxl)
 void qxl_spice_loadvm_commands(PCIQXLDevice *qxl, struct QXLCommandExt *ext,
uint32_t count)
 {
+trace_qxl_spice_loadvm_commands(qxl->id, ext, count);
 qxl->ssd.worker->loadvm_commands(qxl->ssd.worker, ext, count);
 }
 
 void qxl_spice_oom(PCIQXLDevice *qxl)
 {
+trace_qxl_spice_oom(qxl->id);
 qxl->ssd.worker->oom(qxl->ssd.worker);
 }
 
 void qxl_spice_reset_memslots(PCIQXLDevice *qxl)
 {
+trace_qxl_spice_reset_memslots(qxl->id);
 qxl->ssd.worker->reset_memslots(qxl->ssd.worker);
 }
 
 static void qxl_spice_destroy_surfaces_complete(PCIQXLDevice *qxl)
 {
+trace_qxl_spice_destroy_surfaces_complete(qxl->id);
 qemu_mutex_lock(&qxl->track_lock);
 memset(&qxl->guest_surfaces.cmds, 0, sizeof(qxl->guest_surfaces.cmds));
 qxl->guest_surfaces.count = 0;
@@ -211,6 +223,7 @@ static void 
qxl_spice_destroy_surfaces_complete(PCIQXLDevice *qxl)
 
 static void qxl_spice_destroy_surfaces(PCIQXLDevice *qxl, qxl_async_io async)
 {
+trace_qxl_spice_destroy_surfaces(qxl->id, async);
 if (async) {
 spice_qxl_destroy_surfaces_async(&qxl->ssd.qxl,
 (uint64_t)qxl_cookie_new(QXL_COOKIE_TYPE_IO,
@@ -223,11 +236,13 @@ static void qxl_spice_destroy_surfaces(PCIQXLDevice *qxl, 
qxl_async_io async)
 
 void qxl_spice_reset_image_cache(PCIQXLDevice *qxl)
 {
+trace_qxl_spice_reset_image_cache(qxl->id);
 qxl->ssd.worker->reset_image_cache(qxl->ssd.worker);
 }
 
 void qxl_spice_reset_cursor(PCIQXLDevice *qxl)
 {
+trace_qxl_spice_reset_cursor(qxl->id);
 qxl->ssd.worker->reset_cursor(qxl->ssd.worker);
 qemu_mutex_lock(&qxl->track_lock);
 qxl->guest_cursor = 0;
@@ -409,7 +424,7 @@ static void interface_attach_worker(QXLInstance *sin, 
QXLWorker *qxl_worker)
 {
 PCIQXLDevice *qxl = container_of(sin, PCIQXLDevice, ssd.qxl);
 
-dprint(qxl, 1, "%s:\n", __FUNCTION__);
+trace_qxl_interface_attach_worker(qxl->id);
 qxl->ssd.worker = qxl_worker;
 }
 
@@ -417,7 +432,7 @@ static void interface_set_compression_level(QXLInstance 
*sin, int level)
 {
 PCIQXLDevice *qxl = contai

Re: [Qemu-devel] [PATCH 0/5] AREG0 patches v6

2012-03-18 Thread Blue Swirl
On Sun, Mar 11, 2012 at 22:23, Blue Swirl  wrote:
> In this version I rebased the series on REGPARM removal, without
> splitting i386 and x86_64.
>
> I've also made some simple performance tests on i386. It looks like
> REGPARM removal accounts for 2.5% performance loss and the full series
> 7.5%, in total 10% loss in this test.
>
> I'd like to move on with the series, so if nobody produces figures
> with other targets that show such loss, I'll commit the series next
> weekend.

Pushed. Please report if there are problems.

> URL     git://repo.or.cz/qemu/blueswirl.git
>        http://repo.or.cz/r/qemu/blueswirl.git
>
> Blue Swirl (5):
>  i386: Remove REGPARM
>  softmmu templates: optionally pass CPUState to memory access
>    functions
>  TCG: add 5 arg helpers to def-helper.h
>  Sparc: avoid AREG0 for memory access helpers
>  Sparc: avoid AREG0 wrappers for memory access helpers
>
>  Makefile.target            |   12 +-
>  configure                  |    7 +
>  cpu-all.h                  |    9 +
>  def-helper.h               |   26 +++
>  exec-all.h                 |    2 +
>  exec.c                     |    4 +
>  osdep.h                    |    6 -
>  softmmu_defs.h             |   60 +--
>  softmmu_header.h           |   60 +--
>  softmmu_template.h         |   86 ++---
>  target-sparc/cpu.h         |    3 +-
>  target-sparc/helper.h      |   20 +-
>  target-sparc/ldst_helper.c |  415 
> 
>  target-sparc/op_helper.c   |   74 
>  target-sparc/translate.c   |   62 ---
>  tcg/arm/tcg-target.c       |   53 ++
>  tcg/hppa/tcg-target.c      |   44 +
>  tcg/i386/tcg-target.c      |  169 --
>  tcg/ia64/tcg-target.c      |   46 +
>  tcg/mips/tcg-target.c      |   44 +
>  tcg/ppc/tcg-target.c       |   45 +
>  tcg/ppc/tcg-target.h       |    2 +-
>  tcg/ppc64/tcg-target.c     |   44 +
>  tcg/s390/tcg-target.c      |   44 +
>  tcg/sparc/tcg-target.c     |   50 +-
>  tcg/tcg.c                  |   14 --
>  tcg/tcg.h                  |    7 +-
>  tcg/tci/tcg-target.c       |    6 +
>  28 files changed, 966 insertions(+), 448 deletions(-)
>  delete mode 100644 target-sparc/op_helper.c
>
> --
> 1.7.9



[Qemu-devel] A second bug in the IO throttling code

2012-03-18 Thread Chris Webb
Whilst you have patches in progress for the queue draining issue with the IO
throttling code which triggers the assert()s in the ide driver, I thought I
should report a second bug I've seen. I'm not sure whether it's related, but
none of the patch series posted so far appear to fix or affect it.

I find that if I start a guest booting linux using extlinux and set a
bytes-per-second throttle value less than about 4MB/s, qemu tends to lock up
completely while the bootloader is loading the kernel. For example, there's
a tiny 10MB ext4 filesystem gzipped up at

  http://cdw.me.uk/tmp/test.img.gz

which just contains extlinux and a kernel. If you run a VM with qemu HEAD as

  qemu -m 1024 -vnc :1 -drive 
if=none,id=ide.0.0,format=raw,cache=none,file=test.img,bps=1000 -device 
ide-drive,bus=ide.0,unit=0,bootindex=1,drive=ide.0.0 -monitor stdio

and watch on VNC, you'll see it hangs whilst loading the kernel. Once this
has happened, no further interaction with the monitor is possible, and the
VNC socket becomes completely unresponsive. This happens about half of the
time with bps set as high as 2*1024*1024.

I first saw this with the version of the block throttling patches I'd
back-ported on top of qemu-kvm 1.0, but have checked that the problem is
still present in HEAD as of this afternoon [361dea401f52].

Best wishes,

Chris.



[Qemu-devel] [PATCH] scripts: add gdb support script

2012-03-18 Thread Avi Kivity
Add a script that enhances gdb to be aware of QEMU data structures.

This patch adds a single gdb command, 'qemu mtree'.  The command is
similar to the monitor's 'info mtree', except that it prints MemoryRegion
addresses, and except for working from a core dump as well as a live instance.

Signed-off-by: Avi Kivity 
---
 scripts/qemu-gdb.py |   89 +++
 1 files changed, 89 insertions(+), 0 deletions(-)
 create mode 100644 scripts/qemu-gdb.py

diff --git a/scripts/qemu-gdb.py b/scripts/qemu-gdb.py
new file mode 100644
index 000..8a0f305
--- /dev/null
+++ b/scripts/qemu-gdb.py
@@ -0,0 +1,89 @@
+#!/usr/bin/python
+
+# GDB debugging support
+#
+# Copyright 2012 Red Hat, Inc. and/or its affiliates
+#
+# Authors:
+#  Avi Kivity 
+#
+# This work is licensed under the terms of the GNU GPL, version 2.  See
+# the COPYING file in the top-level directory.
+#
+# Contributions after 2012-01-13 are licensed under the terms of the
+# GNU GPL, version 2 or (at your option) any later version.
+
+
+import gdb
+
+def isnull(ptr):
+return ptr == gdb.Value(0).cast(ptr.type)
+
+def int128(p):
+return long(p['lo']) + (long(p['hi']) << 64)
+
+class QemuCommand(gdb.Command):
+'''Prefix for QEMU debug support commands'''
+def __init__(self):
+gdb.Command.__init__(self, 'qemu', gdb.COMMAND_DATA,
+ gdb.COMPLETE_NONE, True)
+
+class MtreeCommand(gdb.Command):
+'''Display the memory tree hierarchy'''
+def __init__(self):
+gdb.Command.__init__(self, 'qemu mtree', gdb.COMMAND_DATA,
+ gdb.COMPLETE_NONE)
+self.queue = []
+def invoke(self, arg, from_tty):
+self.seen = set()
+self.queue_root('address_space_memory')
+self.queue_root('address_space_io')
+self.process_queue()
+def queue_root(self, varname):
+ptr = gdb.parse_and_eval(varname)['root']
+self.queue.append(ptr)
+def process_queue(self):
+while self.queue:
+ptr = self.queue.pop(0)
+if long(ptr) in self.seen:
+continue
+self.print_item(ptr)
+def print_item(self, ptr, offset = gdb.Value(0), level = 0):
+self.seen.add(long(ptr))
+addr = ptr['addr']
+addr += offset
+size = int128(ptr['size'])
+alias = ptr['alias']
+klass = ''
+if not isnull(alias):
+klass = ' (alias)'
+elif not isnull(ptr['ops']):
+klass = ' (I/O)'
+elif bool(ptr['ram']):
+klass = ' (RAM)'
+gdb.write('%s%016x-%016x %s%s (@ %s)\n'
+  % ('  ' * level,
+ long(addr),
+ long(addr + (size - 1)),
+ ptr['name'].string(),
+ klass,
+ ptr,
+ ),
+  gdb.STDOUT)
+if not isnull(alias):
+gdb.write('%salias: %s@%016x (@ %s)\n' %
+  ('  ' * level,
+   alias['name'].string(),
+   ptr['alias_offset'],
+   alias,
+   ),
+  gdb.STDOUT)
+self.queue.append(alias)
+subregion = ptr['subregions']['tqh_first']
+level += 1
+while not isnull(subregion):
+self.print_item(subregion, addr, level)
+subregion = subregion['subregions_link']['tqe_next']
+
+QemuCommand()
+MtreeCommand()
-- 
1.7.9




Re: [Qemu-devel] [PATCH v4 0/9] VMXNET3 paravirtual NIC device implementation

2012-03-18 Thread Dmitry Fleytman
Hello, Gerhard

I've rechecked SSH connection both incoming and outgoing with patch v5.
Everything works fine.
If you still see problems, please, provide your exact configuration.

Thanking you for your support,
Dmitry Fleytman.


On Sun, Mar 18, 2012 at 10:29 AM, Gerhard Wiesinger
 wrote:
> Hello,
>
> I'm still having problems with v4 patch: ping works well, even with large
> packet sizes but ssh doesn't work at all.
> Tested with Knoppix 6.7 and Fedora 16.
>
> Thnx.
>
> Ciao,
> Gerhard
>
>
> On 15.03.2012 22:08, Dmitry Fleytman wrote:
>>
>> This set of patches implements VMWare VMXNET3 paravirtual NIC device.
>> The device supports of all the device features including offload
>> capabilties,
>> VLANs and etc.
>> The device is tested on different OSes:
>>     Fedora 15
>>     Ubuntu 10.4
>>     Centos 6.2
>>     Windows 2008R2
>>     Windows 2008 64bit
>>     Windows 2008 32bit
>>     Windows 2003 64bit
>>     Windows 2003 32bit
>>
>> Changes in V4:
>>    Fixed a few problems uncovered by NETIO test suit
>>    Assertion on failure to initialize MSI/MSI-X replaced with warning
>>    message and fallback to Legacy/MSI respectively
>>
>>      Reported-by: Gerhard Wiesinger
>>
>>    Various coding style adjustments and patch split-up as suggested by
>> Anthony Liguori
>>
>>      Reported-by: Anthony Liguori
>>
>>    Live migration support added
>>
>> Changes in V3:
>>    Fixed crash when net device that is used as network fronted has no
>>    virtio HDR support.
>>    Task offloads emulation for cases when net device that is used as
>>    network fronted has no virtio HDR support.
>>
>>      Reported-by: Gerhard Wiesinger
>>
>> Changes in V2:
>>    License text changed accoring to community suggestions
>>    Standard license header from GPLv2+ - licensed QEMU files used
>>
>> Dmitry Fleytman (9):
>>   Adding missing flag VIRTIO_NET_HDR_F_DATA_VALID from Linux kernel
>>     source tre     Reformatting comments according to checkpatch.pl
>>     requirements
>>   Adding utility function net_checksum_add_cont() that allows checksum
>>        calculation of scattered data with odd chunk sizes
>>   Adding utility function iov_net_csum_add() for iovec checksum
>>     calculation
>>   MSI-X state save/load invocations moved to PCI Device save/load
>>     callbacks     to avoid code duplication in MSI-X-enabled devices
>>     that support live migration
>>   Header with various utility functions shared by VMWARE SCSI and
>>     network devi
>>   Various utility functions used by VMWARE network devices
>>   Packet abstraction used by VMWARE network devices
>>   VMXNET3 paravirtual device implementation
>>   VMXNET3 paravirtualized device integration.     Interface type
>>     "vmxnet3" added.
>>
>>  Makefile.objs           |    1 +
>>  default-configs/pci.mak |    1 +
>>  hw/pci.c                |    7 +
>>  hw/pci.h                |    1 +
>>  hw/virtio-net.h         |   13 +-
>>  hw/virtio-pci.c         |    2 -
>>  hw/vmware_utils.h       |  122 +++
>>  hw/vmxnet3.c            | 2435
>> +++
>>  hw/vmxnet3.h            |  757 +++
>>  hw/vmxnet_debug.h       |  121 +++
>>  hw/vmxnet_pkt.c         | 1243 
>>  hw/vmxnet_pkt.h         |  479 ++
>>  hw/vmxnet_utils.c       |  165 
>>  hw/vmxnet_utils.h       |  320 +++
>>  iov.c                   |   29 +
>>  iov.h                   |    3 +
>>  net.c                   |    2 +-
>>  net/checksum.c          |   13 +-
>>  net/checksum.h          |   14 +-
>>  19 files changed, 5712 insertions(+), 16 deletions(-)
>>  create mode 100644 hw/vmware_utils.h
>>  create mode 100644 hw/vmxnet3.c
>>  create mode 100644 hw/vmxnet3.h
>>  create mode 100644 hw/vmxnet_debug.h
>>  create mode 100644 hw/vmxnet_pkt.c
>>  create mode 100644 hw/vmxnet_pkt.h
>>  create mode 100644 hw/vmxnet_utils.c
>>  create mode 100644 hw/vmxnet_utils.h
>>
>



Re: [Qemu-devel] SPARC64: immediate segfault on startup with git mastervery

2012-03-18 Thread Avi Kivity
On 03/18/2012 02:08 PM, Avi Kivity wrote:
> >
> > Screen is not updated correctly, there are lines from previous
> > screenful. Pressing ctrl-alt-1 refreshes the display. Perhaps dirty
> > tracking is broken? VGA in x86 works.
>
> Ok, I see it.  Will investigate.
>

Turns out it's a latent bug in qemu exposed by the memory patches.  I
already had a fix in my tree (though of course I had no memory of this
when debugging).

Please try the attached patch.

-- 
error compiling committee.c: too many arguments to function

>From bb363db2608dfc9b49b53994dc20d68169e66774 Mon Sep 17 00:00:00 2001
From: Avi Kivity 
Date: Wed, 14 Mar 2012 16:19:39 +0200
Subject: [PATCH] exec: fix write tlb entry misused as iotlb

A couple of code paths check the lower bits of CPUTLBEntry::addr_write
against io_mem_ram as a way of looking for a dirty RAM page.  This works
by accident since the value is zero, which matches all clear bits for
TLB_INVALID, TLB_MMIO, and TLB_NOTDIRTY (indicating dirty RAM).

Make it work by design by checking for the proper bits.

Signed-off-by: Avi Kivity 
---
 exec.c |   11 ---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/exec.c b/exec.c
index 8fd50a1..d8b089e 100644
--- a/exec.c
+++ b/exec.c
@@ -2031,14 +2031,19 @@ static void tlb_unprotect_code_phys(CPUArchState *env, ram_addr_t ram_addr,
 cpu_physical_memory_set_dirty_flags(ram_addr, CODE_DIRTY_FLAG);
 }
 
+static bool tlb_is_dirty_ram(CPUTLBEntry *tlbe)
+{
+return (tlbe->addr_write & (TLB_INVALID_MASK|TLB_MMIO|TLB_NOTDIRTY)) == 0;
+}
+
 static inline void tlb_reset_dirty_range(CPUTLBEntry *tlb_entry,
  unsigned long start, unsigned long length)
 {
 unsigned long addr;
-if ((tlb_entry->addr_write & ~TARGET_PAGE_MASK) == io_mem_ram.ram_addr) {
+if (tlb_is_dirty_ram(tlb_entry)) {
 addr = (tlb_entry->addr_write & TARGET_PAGE_MASK) + tlb_entry->addend;
 if ((addr - start) < length) {
-tlb_entry->addr_write = (tlb_entry->addr_write & TARGET_PAGE_MASK) | TLB_NOTDIRTY;
+tlb_entry->addr_write |= TLB_NOTDIRTY;
 }
 }
 }
@@ -2091,7 +2096,7 @@ static inline void tlb_update_dirty(CPUTLBEntry *tlb_entry)
 ram_addr_t ram_addr;
 void *p;
 
-if ((tlb_entry->addr_write & ~TARGET_PAGE_MASK) == io_mem_ram.ram_addr) {
+if (tlb_is_dirty_ram(tlb_entry)) {
 p = (void *)(unsigned long)((tlb_entry->addr_write & TARGET_PAGE_MASK)
 + tlb_entry->addend);
 ram_addr = qemu_ram_addr_from_host_nofail(p);
-- 
1.7.9



Re: [Qemu-devel] [PATCH v4 0/9] VMXNET3 paravirtual NIC device implementation

2012-03-18 Thread Gerhard Wiesinger

Hello,

I'm still having problems with v4 patch: ping works well, even with 
large packet sizes but ssh doesn't work at all.

Tested with Knoppix 6.7 and Fedora 16.

Thnx.

Ciao,
Gerhard

On 15.03.2012 22:08, Dmitry Fleytman wrote:

This set of patches implements VMWare VMXNET3 paravirtual NIC device.
The device supports of all the device features including offload capabilties,
VLANs and etc.
The device is tested on different OSes:
 Fedora 15
 Ubuntu 10.4
 Centos 6.2
 Windows 2008R2
 Windows 2008 64bit
 Windows 2008 32bit
 Windows 2003 64bit
 Windows 2003 32bit

Changes in V4:
Fixed a few problems uncovered by NETIO test suit
Assertion on failure to initialize MSI/MSI-X replaced with warning
message and fallback to Legacy/MSI respectively

  Reported-by: Gerhard Wiesinger

Various coding style adjustments and patch split-up as suggested by Anthony 
Liguori

  Reported-by: Anthony Liguori

Live migration support added

Changes in V3:
Fixed crash when net device that is used as network fronted has no
virtio HDR support.
Task offloads emulation for cases when net device that is used as
network fronted has no virtio HDR support.

  Reported-by: Gerhard Wiesinger

Changes in V2:
License text changed accoring to community suggestions
Standard license header from GPLv2+ - licensed QEMU files used

Dmitry Fleytman (9):
   Adding missing flag VIRTIO_NET_HDR_F_DATA_VALID from Linux kernel
 source tre Reformatting comments according to checkpatch.pl
 requirements
   Adding utility function net_checksum_add_cont() that allows checksum
calculation of scattered data with odd chunk sizes
   Adding utility function iov_net_csum_add() for iovec checksum
 calculation
   MSI-X state save/load invocations moved to PCI Device save/load
 callbacks to avoid code duplication in MSI-X-enabled devices
 that support live migration
   Header with various utility functions shared by VMWARE SCSI and
 network devi
   Various utility functions used by VMWARE network devices
   Packet abstraction used by VMWARE network devices
   VMXNET3 paravirtual device implementation
   VMXNET3 paravirtualized device integration. Interface type
 "vmxnet3" added.

  Makefile.objs   |1 +
  default-configs/pci.mak |1 +
  hw/pci.c|7 +
  hw/pci.h|1 +
  hw/virtio-net.h |   13 +-
  hw/virtio-pci.c |2 -
  hw/vmware_utils.h   |  122 +++
  hw/vmxnet3.c| 2435 +++
  hw/vmxnet3.h|  757 +++
  hw/vmxnet_debug.h   |  121 +++
  hw/vmxnet_pkt.c | 1243 
  hw/vmxnet_pkt.h |  479 ++
  hw/vmxnet_utils.c   |  165 
  hw/vmxnet_utils.h   |  320 +++
  iov.c   |   29 +
  iov.h   |3 +
  net.c   |2 +-
  net/checksum.c  |   13 +-
  net/checksum.h  |   14 +-
  19 files changed, 5712 insertions(+), 16 deletions(-)
  create mode 100644 hw/vmware_utils.h
  create mode 100644 hw/vmxnet3.c
  create mode 100644 hw/vmxnet3.h
  create mode 100644 hw/vmxnet_debug.h
  create mode 100644 hw/vmxnet_pkt.c
  create mode 100644 hw/vmxnet_pkt.h
  create mode 100644 hw/vmxnet_utils.c
  create mode 100644 hw/vmxnet_utils.h






Re: [Qemu-devel] [PATCH 0/5] VMWare PVSCSI paravirtual device implementation

2012-03-18 Thread Gerhard Wiesinger

Hello Dmitry,

Is PVSCSI also ready to boot through BIOS Int 13h?
If not, do you plan a SEABIOS patch?

Thnx.

Ciao,
Gerhard

On 15.03.2012 10:02, Dmitry Fleytman wrote:

Below is the implementation of VMWare PVSCSI device and
command line parameters to configure vendor name and product name
for SCSI storage are implemented.
Latter is needed to make PVSCSI storage devices look exactly as
on VMWare hypervisors.

With this and VMWARE3 patches V2V migration problem for VMWare
images should be solved relatively easy.

PVSCSI implementation is based on Paolo Bonzini code sumbitted
some time ago but never applied.
See commit messages and file headers for details.

Implementation supports of all the device features.
Code was tested on different OSes:
 Fedora 15
 Ubuntu 10.4
 Centos 6.2
 Windows 2008R2
 Windows 2008 64bit
 Windows 2008 32bit
 Windows 2003 64bit
 Windows 2003 32bit

Dmitry Fleytman (5):
   Utility function strpadcpy() added
   Vendor name and product name parameters for SCSI devices Options
 "vendor_name" and "product_name" added for SCSI disks.
   Header with various utility functions shared by VMWARE SCSI and
 network devices
   PVCSI paravirtualized device implementation
   PVSCSI paravirtualized device integration Bus type "pvscsi"
 added.

  Makefile.objs  |1 +
  blockdev.c |   12 +-
  blockdev.h |   16 +-
  cutils.c   |   13 +
  default-configs/pci.mak|1 +
  docs/specs/pvscsi-spec.txt |   92 
  hw/pc.c|5 +
  hw/pci-hotplug.c   |7 +-
  hw/pci.h   |1 +
  hw/pvscsi.c| 1242 
  hw/pvscsi.h|  442 
  hw/scsi-bus.c  |   14 +-
  hw/scsi-disk.c |   51 ++-
  hw/scsi.h  |1 +
  hw/vmware_utils.h  |  122 +
  qemu-common.h  |1 +
  16 files changed, 1997 insertions(+), 24 deletions(-)
  create mode 100644 docs/specs/pvscsi-spec.txt
  create mode 100644 hw/pvscsi.c
  create mode 100644 hw/pvscsi.h
  create mode 100644 hw/vmware_utils.h






Re: [Qemu-devel] [PATCH 0/5] VMWare PVSCSI paravirtual device implementation

2012-03-18 Thread Evgeny Budilovsky
Hi,
Currently there is no support in seabios to boot pvscsi.
What we did was a workaround.
We've reverted the patch which removes extboot support
[2a06024dc1b1e27b1be0266379af397e61b4a9ad]
and used -drive ...boot=on --option-rom extboot.bin to boot the pvscsi disk.

Best Regards,
Evgeny

On Sun, Mar 18, 2012 at 10:32 AM, Gerhard Wiesinger wrote:

> Hello Dmitry,
>
> Is PVSCSI also ready to boot through BIOS Int 13h?
> If not, do you plan a SEABIOS patch?
>
> Thnx.
>
> Ciao,
> Gerhard
>
>
> On 15.03.2012 10:02, Dmitry Fleytman wrote:
>
>> Below is the implementation of VMWare PVSCSI device and
>> command line parameters to configure vendor name and product name
>> for SCSI storage are implemented.
>> Latter is needed to make PVSCSI storage devices look exactly as
>> on VMWare hypervisors.
>>
>> With this and VMWARE3 patches V2V migration problem for VMWare
>> images should be solved relatively easy.
>>
>> PVSCSI implementation is based on Paolo Bonzini code sumbitted
>> some time ago but never applied.
>> See commit messages and file headers for details.
>>
>> Implementation supports of all the device features.
>> Code was tested on different OSes:
>> Fedora 15
>> Ubuntu 10.4
>> Centos 6.2
>> Windows 2008R2
>> Windows 2008 64bit
>> Windows 2008 32bit
>> Windows 2003 64bit
>> Windows 2003 32bit
>>
>> Dmitry Fleytman (5):
>>   Utility function strpadcpy() added
>>   Vendor name and product name parameters for SCSI devices Options
>> "vendor_name" and "product_name" added for SCSI disks.
>>   Header with various utility functions shared by VMWARE SCSI and
>> network devices
>>   PVCSI paravirtualized device implementation
>>   PVSCSI paravirtualized device integration Bus type "pvscsi"
>> added.
>>
>>  Makefile.objs  |1 +
>>  blockdev.c |   12 +-
>>  blockdev.h |   16 +-
>>  cutils.c   |   13 +
>>  default-configs/pci.mak|1 +
>>  docs/specs/pvscsi-spec.txt |   92 
>>  hw/pc.c|5 +
>>  hw/pci-hotplug.c   |7 +-
>>  hw/pci.h   |1 +
>>  hw/pvscsi.c| 1242 ++**
>> ++
>>  hw/pvscsi.h|  442 
>>  hw/scsi-bus.c  |   14 +-
>>  hw/scsi-disk.c |   51 ++-
>>  hw/scsi.h  |1 +
>>  hw/vmware_utils.h  |  122 +
>>  qemu-common.h  |1 +
>>  16 files changed, 1997 insertions(+), 24 deletions(-)
>>  create mode 100644 docs/specs/pvscsi-spec.txt
>>  create mode 100644 hw/pvscsi.c
>>  create mode 100644 hw/pvscsi.h
>>  create mode 100644 hw/vmware_utils.h
>>
>>
>
>


[Qemu-devel] Breakage

2012-03-18 Thread malc

97161e177b4ea2730dff13c4df01475762ab6048 broke booting of a DOS image
i've been using for years, the VM stalls at "Booting from hard disk"
BIOS message never making any progress.

-- 
mailto:av1...@comtv.ru



Re: [Qemu-devel] Breakage

2012-03-18 Thread Avi Kivity
On 03/18/2012 06:12 PM, malc wrote:
> 97161e177b4ea2730dff13c4df01475762ab6048 broke booting of a DOS image
> i've been using for years, the VM stalls at "Booting from hard disk"
> BIOS message never making any progress.

Can you post an image that exhibits the problem?

Also, try the attached patch.

-- 
error compiling committee.c: too many arguments to function

>From bb363db2608dfc9b49b53994dc20d68169e66774 Mon Sep 17 00:00:00 2001
From: Avi Kivity 
Date: Wed, 14 Mar 2012 16:19:39 +0200
Subject: [PATCH] exec: fix write tlb entry misused as iotlb

A couple of code paths check the lower bits of CPUTLBEntry::addr_write
against io_mem_ram as a way of looking for a dirty RAM page.  This works
by accident since the value is zero, which matches all clear bits for
TLB_INVALID, TLB_MMIO, and TLB_NOTDIRTY (indicating dirty RAM).

Make it work by design by checking for the proper bits.

Signed-off-by: Avi Kivity 
---
 exec.c |   11 ---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/exec.c b/exec.c
index 8fd50a1..d8b089e 100644
--- a/exec.c
+++ b/exec.c
@@ -2031,14 +2031,19 @@ static void tlb_unprotect_code_phys(CPUArchState *env, ram_addr_t ram_addr,
 cpu_physical_memory_set_dirty_flags(ram_addr, CODE_DIRTY_FLAG);
 }
 
+static bool tlb_is_dirty_ram(CPUTLBEntry *tlbe)
+{
+return (tlbe->addr_write & (TLB_INVALID_MASK|TLB_MMIO|TLB_NOTDIRTY)) == 0;
+}
+
 static inline void tlb_reset_dirty_range(CPUTLBEntry *tlb_entry,
  unsigned long start, unsigned long length)
 {
 unsigned long addr;
-if ((tlb_entry->addr_write & ~TARGET_PAGE_MASK) == io_mem_ram.ram_addr) {
+if (tlb_is_dirty_ram(tlb_entry)) {
 addr = (tlb_entry->addr_write & TARGET_PAGE_MASK) + tlb_entry->addend;
 if ((addr - start) < length) {
-tlb_entry->addr_write = (tlb_entry->addr_write & TARGET_PAGE_MASK) | TLB_NOTDIRTY;
+tlb_entry->addr_write |= TLB_NOTDIRTY;
 }
 }
 }
@@ -2091,7 +2096,7 @@ static inline void tlb_update_dirty(CPUTLBEntry *tlb_entry)
 ram_addr_t ram_addr;
 void *p;
 
-if ((tlb_entry->addr_write & ~TARGET_PAGE_MASK) == io_mem_ram.ram_addr) {
+if (tlb_is_dirty_ram(tlb_entry)) {
 p = (void *)(unsigned long)((tlb_entry->addr_write & TARGET_PAGE_MASK)
 + tlb_entry->addend);
 ram_addr = qemu_ram_addr_from_host_nofail(p);
-- 
1.7.9



Re: [Qemu-devel] Breakage

2012-03-18 Thread malc
On Sun, 18 Mar 2012, Avi Kivity wrote:

> On 03/18/2012 06:12 PM, malc wrote:
> > 97161e177b4ea2730dff13c4df01475762ab6048 broke booting of a DOS image
> > i've been using for years, the VM stalls at "Booting from hard disk"
> > BIOS message never making any progress.
> 
> Can you post an image that exhibits the problem?

It's 400+MB

> 
> Also, try the attached patch.

Boots with the patch.

-- 
mailto:av1...@comtv.ru



Re: [Qemu-devel] [PATCH 3/5] exec: fix code tlb entry misused as iotlb in get_page_addr_code()

2012-03-18 Thread Avi Kivity
On 03/18/2012 01:07 PM, Max Filippov wrote:
> >>> get_page_addr_code() reads a code tlb entry, but interprets it as an
> >>> iotlb entry.  This works by accident since the low bits of a RAM code
> >>> tlb entry are clear, and match a RAM iotlb entry.  This accident is
> >>> about to unhappen, so fix the code to use an iotlb entry (using the
> >>> code entry with TLB_MMIO may fail if the page is a watchpoint).
> >>>
> >>> Signed-off-by: Avi Kivity
> >>> ---
> >>>   exec.c |2 +-
> >>>   1 files changed, 1 insertions(+), 1 deletions(-)
> >>>
> >>> diff --git a/exec.c b/exec.c
> >>> index a35eb4f..f26d1b0 100644
> >>> --- a/exec.c
> >>> +++ b/exec.c
> >>> @@ -4685,7 +4685,7 @@ tb_page_addr_t get_page_addr_code(CPUState
> >>> *env1, target_ulong addr)
> >>>(addr&  TARGET_PAGE_MASK))) {
> >>>   ldub_code(addr);
> >>>   }
> >>> -pd = env1->tlb_table[mmu_idx][page_index].addr_code&
> >>> ~TARGET_PAGE_MASK;
> >>> +pd = env1->iotlb[mmu_idx][page_index]&  ~TARGET_PAGE_MASK;
> >>>   if (pd != io_mem_ram.ram_addr&&  pd != io_mem_rom.ram_addr
> >>>   &&  !io_mem_region[pd]->rom_device) {
> >>>   #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) ||
> >>> defined(TARGET_SPARC)
> >>
> >> With this patch xtensa debug option unit test causes qemu abort with
> >> the message
> >>
> >>  qemu: fatal: Trying to execute code outside RAM or ROM at 0xd88c
> >>
> >> This happens immediately after a watchpoint setup for a data
> >> breakpoint at the same memory page where the currently
> >> executed code is located. Any idea on how to fix it?
> >
> > Can you provide details on how to reproduce this?
>
> It may be reproduced by running test_break.tst unit test:
>
> qemu-system-xtensa -M sim -cpu dc232b -nographic -semihosting  -kernel
> ./test_break.tst
>
> Compiled test binary is here:
> http://jcmvbkbc.spb.ru/~dumb/ws/osll/qemu-xtensa/20120318/test_break.tst
>

Thanks.  Please try out the attached patch.


-- 
error compiling committee.c: too many arguments to function

>From a7b99c89dfe9784a94af86df344d4ef893c15ee4 Mon Sep 17 00:00:00 2001
From: Avi Kivity 
Date: Sun, 18 Mar 2012 18:31:13 +0200
Subject: [PATCH] memory: check for watchpoints when getting code ram_addr

The code to get the ram_addr from a (tlb entry, vaddr) pair
checks that the resulting memory is not MMIO, but neglects to
check whether the region is hidden by a watchpoint page.

Add the missing check.

Signed-off-by: Avi Kivity 
---
 exec.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/exec.c b/exec.c
index d8b089e..405e277 100644
--- a/exec.c
+++ b/exec.c
@@ -4605,7 +4605,8 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr)
 pd = env1->iotlb[mmu_idx][page_index] & ~TARGET_PAGE_MASK;
 mr = iotlb_to_region(pd);
 if (mr != &io_mem_ram && mr != &io_mem_rom
-&& mr != &io_mem_notdirty && !mr->rom_device) {
+&& mr != &io_mem_notdirty && !mr->rom_device
+&& mr != &io_mem_watch) {
 #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || defined(TARGET_SPARC)
 cpu_unassigned_access(env1, addr, 0, 1, 0, 4);
 #else
-- 
1.7.9



Re: [Qemu-devel] [PATCH 3/5] exec: fix code tlb entry misused as iotlb in get_page_addr_code()

2012-03-18 Thread Max Filippov
>> >>> get_page_addr_code() reads a code tlb entry, but interprets it as an
>> >>> iotlb entry.  This works by accident since the low bits of a RAM code
>> >>> tlb entry are clear, and match a RAM iotlb entry.  This accident is
>> >>> about to unhappen, so fix the code to use an iotlb entry (using the
>> >>> code entry with TLB_MMIO may fail if the page is a watchpoint).
>> >>>
>> >>> Signed-off-by: Avi Kivity
>> >>> ---
>> >>>   exec.c |    2 +-
>> >>>   1 files changed, 1 insertions(+), 1 deletions(-)
>> >>>
>> >>> diff --git a/exec.c b/exec.c
>> >>> index a35eb4f..f26d1b0 100644
>> >>> --- a/exec.c
>> >>> +++ b/exec.c
>> >>> @@ -4685,7 +4685,7 @@ tb_page_addr_t get_page_addr_code(CPUState
>> >>> *env1, target_ulong addr)
>> >>>                    (addr&  TARGET_PAGE_MASK))) {
>> >>>           ldub_code(addr);
>> >>>       }
>> >>> -    pd = env1->tlb_table[mmu_idx][page_index].addr_code&
>> >>> ~TARGET_PAGE_MASK;
>> >>> +    pd = env1->iotlb[mmu_idx][page_index]&  ~TARGET_PAGE_MASK;
>> >>>       if (pd != io_mem_ram.ram_addr&&  pd != io_mem_rom.ram_addr
>> >>>           &&  !io_mem_region[pd]->rom_device) {
>> >>>   #if defined(TARGET_ALPHA) || defined(TARGET_MIPS) ||
>> >>> defined(TARGET_SPARC)
>> >>
>> >> With this patch xtensa debug option unit test causes qemu abort with
>> >> the message
>> >>
>> >>  qemu: fatal: Trying to execute code outside RAM or ROM at 0xd88c
>> >>
>> >> This happens immediately after a watchpoint setup for a data
>> >> breakpoint at the same memory page where the currently
>> >> executed code is located. Any idea on how to fix it?
>> >
>> > Can you provide details on how to reproduce this?
>>
>> It may be reproduced by running test_break.tst unit test:
>>
>> qemu-system-xtensa -M sim -cpu dc232b -nographic -semihosting  -kernel
>> ./test_break.tst
>>
>> Compiled test binary is here:
>> http://jcmvbkbc.spb.ru/~dumb/ws/osll/qemu-xtensa/20120318/test_break.tst
>>
>
> Thanks.  Please try out the attached patch.

Thanks, with this patch it works.

-- Max



[Qemu-devel] [PATCH 0/2] acpi: robust notifications

2012-03-18 Thread Michael S. Tsirkin
acpi currently clears up/down registers on each hotplug
request. This loses events if they are done quickly.
It's easy to clear down on ej write.
To detect that guest was notified of device addition,
we track configuration accesses since system reset.

Michael S. Tsirkin (2):
  pci: track function accesses
  acpi: don't clear up/down on each host change

 hw/acpi_piix4.c |   32 +++-
 hw/pci.c|   26 ++
 hw/pci.h|3 +++
 hw/pci_host.c   |2 ++
 4 files changed, 58 insertions(+), 5 deletions(-)

-- 
1.7.9.111.gf3fb0



[Qemu-devel] [PATCH 1/2] pci: track function accesses

2012-03-18 Thread Michael S. Tsirkin
Set a flag when function is first accessed after system reset.

Signed-off-by: Michael S. Tsirkin 
---
 hw/pci.c  |   26 ++
 hw/pci.h  |3 +++
 hw/pci_host.c |2 ++
 3 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index b706e69..2aaa45e 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -407,6 +407,17 @@ static VMStateInfo vmstate_info_pci_irq_state = {
 .put  = put_pci_irq_state,
 };
 
+static const VMStateDescription pci_vmstate_accessed_since_reset ={
+.name = "pci/accessed_since_reset",
+.version_id = 1,
+.minimum_version_id = 1,
+.minimum_version_id_old = 1,
+.fields  = (VMStateField []) {
+VMSTATE_BOOL(accessed_since_reset, PCIDevice),
+VMSTATE_END_OF_LIST()
+}
+};
+
 const VMStateDescription vmstate_pci_device = {
 .name = "PCIDevice",
 .version_id = 2,
@@ -421,6 +432,12 @@ const VMStateDescription vmstate_pci_device = {
   vmstate_info_pci_irq_state,
   PCI_NUM_PINS * sizeof(int32_t)),
 VMSTATE_END_OF_LIST()
+},
+.subsections = (VMStateSubsection[]) {
+{
+.vmsd = &pci_vmstate_accessed_since_reset,
+},
+VMSTATE_END_OF_LIST()
 }
 };
 
@@ -738,6 +755,12 @@ static void pci_config_free(PCIDevice *pci_dev)
 g_free(pci_dev->used);
 }
 
+static void pci_system_reset_fn(void *opaque)
+{
+PCIDevice *dev = opaque;
+dev->accessed_since_reset = false;
+}
+
 /* -1 for devfn means auto assign */
 static PCIDevice *do_pci_register_device(PCIDevice *pci_dev, PCIBus *bus,
  const char *name, int devfn)
@@ -805,11 +828,14 @@ static PCIDevice *do_pci_register_device(PCIDevice 
*pci_dev, PCIBus *bus,
 bus->devices[devfn] = pci_dev;
 pci_dev->irq = qemu_allocate_irqs(pci_set_irq, pci_dev, PCI_NUM_PINS);
 pci_dev->version_id = 2; /* Current pci device vmstate version */
+pci_dev->accessed_since_reset = false;
+qemu_register_reset(pci_system_reset_fn, pci_dev);
 return pci_dev;
 }
 
 static void do_pci_unregister_device(PCIDevice *pci_dev)
 {
+qemu_unregister_reset(pci_system_reset_fn, pci_dev);
 qemu_free_irqs(pci_dev->irq);
 pci_dev->bus->devices[pci_dev->devfn] = NULL;
 pci_config_free(pci_dev);
diff --git a/hw/pci.h b/hw/pci.h
index 8d0aa49..3fdd1dc 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -243,6 +243,9 @@ struct PCIDevice {
 bool has_rom;
 MemoryRegion rom;
 uint32_t rom_bar;
+
+/* Cleared on first access after system reset */
+bool accessed_since_reset;
 };
 
 void pci_register_bar(PCIDevice *pci_dev, int region_num,
diff --git a/hw/pci_host.c b/hw/pci_host.c
index 44c6c20..3019d72 100644
--- a/hw/pci_host.c
+++ b/hw/pci_host.c
@@ -51,6 +51,7 @@ void pci_host_config_write_common(PCIDevice *pci_dev, 
uint32_t addr,
   uint32_t limit, uint32_t val, uint32_t len)
 {
 assert(len <= 4);
+pci_dev->accessed_since_reset = true;
 pci_dev->config_write(pci_dev, addr, val, MIN(len, limit - addr));
 }
 
@@ -58,6 +59,7 @@ uint32_t pci_host_config_read_common(PCIDevice *pci_dev, 
uint32_t addr,
  uint32_t limit, uint32_t len)
 {
 assert(len <= 4);
+pci_dev->accessed_since_reset = true;
 return pci_dev->config_read(pci_dev, addr, MIN(len, limit - addr));
 }
 
-- 
1.7.9.111.gf3fb0




[Qemu-devel] [PATCH 2/2] acpi: don't clear up/down on each host change

2012-03-18 Thread Michael S. Tsirkin
Instead of clearing up slot on each change, we clear:
- up: when slot is accessed
- down: when device is ejected

Signed-off-by: Michael S. Tsirkin 
---
 hw/acpi_piix4.c |   32 +++-
 1 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
index 797ed24..b6bb486 100644
--- a/hw/acpi_piix4.c
+++ b/hw/acpi_piix4.c
@@ -49,6 +49,7 @@
 struct pci_status {
 uint32_t up;
 uint32_t down;
+BusState *bus;
 };
 
 typedef struct PIIX4PMState {
@@ -268,6 +269,21 @@ static const VMStateDescription vmstate_acpi = {
 }
 };
 
+/* Did guest access any devices in a slot? If yes, clear the up bit. */
+static void piix4_update_up(struct pci_status *s)
+{
+DeviceState *qdev, *next;
+int slot;
+
+QTAILQ_FOREACH_SAFE(qdev, &s->bus->children, sibling, next) {
+PCIDevice *pdev = PCI_DEVICE(qdev);
+slot = PCI_SLOT(pdev->devfn);
+if (pdev->accessed_since_reset) {
+s->up &= ~(1 << slot);
+}
+}
+}
+
 static void piix4_update_hotplug(PIIX4PMState *s)
 {
 PCIDevice *dev = &s->dev;
@@ -290,6 +306,7 @@ static void piix4_update_hotplug(PIIX4PMState *s)
 static void piix4_reset(void *opaque)
 {
 PIIX4PMState *s = opaque;
+struct pci_status *pci0_status = &s->pci0_status;
 uint8_t *pci_conf = s->dev.config;
 
 pci_conf[0x58] = 0;
@@ -301,6 +318,8 @@ static void piix4_reset(void *opaque)
 /* Mark SMM as already inited (until KVM supports SMM). */
 pci_conf[0x5B] = 0x02;
 }
+pci0_status->up = 0;
+pci0_status->down = 0;
 piix4_update_hotplug(s);
 }
 
@@ -454,6 +473,7 @@ static uint32_t pcihotplug_read(void *opaque, uint32_t addr)
 struct pci_status *g = opaque;
 switch (addr) {
 case PCI_BASE:
+piix4_update_up(g);
 val = g->up;
 break;
 case PCI_BASE + 4:
@@ -490,10 +510,13 @@ static uint32_t pciej_read(void *opaque, uint32_t addr)
 
 static void pciej_write(void *opaque, uint32_t addr, uint32_t val)
 {
-BusState *bus = opaque;
+struct pci_status *s = opaque;
+BusState *bus = s->bus;
 DeviceState *qdev, *next;
 int slot = ffs(val) - 1;
 
+s->down &= ~(1 << slot);
+s->up &= ~(1 << slot);
 QTAILQ_FOREACH_SAFE(qdev, &bus->children, sibling, next) {
 PCIDevice *dev = PCI_DEVICE(qdev);
 PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
@@ -524,6 +547,7 @@ static int piix4_device_hotplug(DeviceState *qdev, 
PCIDevice *dev,
 static void piix4_acpi_system_hot_add_init(PCIBus *bus, PIIX4PMState *s)
 {
 struct pci_status *pci0_status = &s->pci0_status;
+pci0_status->bus = qdev_get_parent_bus(&s->dev.qdev);
 
 register_ioport_write(GPE_BASE, GPE_LEN, 1, gpe_writeb, s);
 register_ioport_read(GPE_BASE, GPE_LEN, 1,  gpe_readb, s);
@@ -532,8 +556,8 @@ static void piix4_acpi_system_hot_add_init(PCIBus *bus, 
PIIX4PMState *s)
 register_ioport_write(PCI_BASE, 8, 4, pcihotplug_write, pci0_status);
 register_ioport_read(PCI_BASE, 8, 4,  pcihotplug_read, pci0_status);
 
-register_ioport_write(PCI_EJ_BASE, 4, 4, pciej_write, bus);
-register_ioport_read(PCI_EJ_BASE, 4, 4,  pciej_read, bus);
+register_ioport_write(PCI_EJ_BASE, 4, 4, pciej_write, pci0_status);
+register_ioport_read(PCI_EJ_BASE, 4, 4,  pciej_read, pci0_status);
 
 register_ioport_write(PCI_RMV_BASE, 4, 4, pcirmv_write, s);
 register_ioport_read(PCI_RMV_BASE, 4, 4,  pcirmv_read, s);
@@ -567,8 +591,6 @@ static int piix4_device_hotplug(DeviceState *qdev, 
PCIDevice *dev,
 return 0;
 }
 
-s->pci0_status.up = 0;
-s->pci0_status.down = 0;
 if (state == PCI_HOTPLUG_ENABLED) {
 enable_device(s, slot);
 } else {
-- 
1.7.9.111.gf3fb0



[Qemu-devel] [PATCH] fix multiboot loading if load_end_addr == 0 (fwd)

2012-03-18 Thread Scott Moser
Re-sending to qemu-devel.  I'd originally sent this to kvm mailing list.


-- Forwarded message --
Date: Sat, 17 Mar 2012 00:08:06
From: Scott Moser 
To: k...@vger.kernel.org
Subject: [PATCH] fix multiboot loading if load_end_addr == 0

The previous code did not treat the case where load_end_addr was 0
specially.  The multiboot specification says the following:
 * load_end_addr
   Contains the physical address of the end of the data segment.
   (load_end_addr - load_addr) specifies how much data to load. This
   implies that the text and data segments must be consecutive in the
   OS image; this is true for existing a.out executable formats. If
   this field is zero, the boot loader assumes that the text and data
   segments occupy the whole OS image file.

This was raised initially as launchpad bug
https://bugs.launchpad.net/qemu/+bug/957622

diff --git a/hw/multiboot.c b/hw/multiboot.c
index b4484a3..b1e04c5 100644
--- a/hw/multiboot.c
+++ b/hw/multiboot.c
@@ -202,10 +202,16 @@ int load_multiboot(void *fw_cfg,
 uint32_t mh_bss_end_addr = ldl_p(header+i+24);
 mh_load_addr = ldl_p(header+i+16);
 uint32_t mb_kernel_text_offset = i - (mh_header_addr - mh_load_addr);
-uint32_t mb_load_size = mh_load_end_addr - mh_load_addr;
-
+uint32_t mb_load_size = 0;
 mh_entry_addr = ldl_p(header+i+28);
-mb_kernel_size = mh_bss_end_addr - mh_load_addr;
+
+if (mh_load_end_addr) {
+mb_kernel_size = mh_bss_end_addr - mh_load_addr;
+mb_load_size = mh_load_end_addr - mh_load_addr;
+} else {
+mb_kernel_size = kernel_file_size - mb_kernel_text_offset;
+mb_load_size = mb_kernel_size;
+}

 /* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE.
 uint32_t mh_mode_type = ldl_p(header+i+32);



[Qemu-devel] [PATCH v3 0/5] screendump qapi convertion

2012-03-18 Thread Alon Levy
v3 changes: (Requested by Luiz Capitulino)
 rename helper to qemu_fopen_err
 don't touch unrelated subsystems
 move helper to osdep - I couldn't do it that way without dragging a lot of 
dependencies into libcacard which uses osdep-obj-y, so I split it so that there 
is now a osdep-no-qerror-obj-y that is solemnly used by libcacard and is 
contained in osdep-obj-y.
 rename some of the QERR codes, specifically most of them lost the OPEN_FILE 
substring.
 split the first patch in two, adding error codes and adding qemu_fopen_err

v2 changes:
 split screendump convertion to an addition "add Error** param"
 handle various errors of fopen with new qerror codes

Alon Levy (4):
  qerror: add error codes for fopen failure
  add qemu_fopen_err
  vga_hw_screen_dump: add Error** param
  qapi: convert screendump

Luiz Capitulino (1):
  vga: ppm_save(): Return error on failure

 Makefile.objs  |8 +---
 console.c  |5 +++--
 console.h  |6 --
 hmp-commands.hx|3 +--
 hmp.c  |8 
 hmp.h  |1 +
 hw/blizzard.c  |5 +++--
 hw/g364fb.c|4 +++-
 hw/omap_lcdc.c |4 +++-
 hw/qxl.c   |8 +---
 hw/tcx.c   |   13 +
 hw/vga.c   |   15 ++-
 hw/vga_int.h   |3 ++-
 hw/vmware_vga.c|8 +---
 libcacard/Makefile |2 +-
 monitor.c  |6 --
 osdep-qerror.c |   52 
 osdep-qerror.h |8 
 osdep.c|1 -
 qapi-schema.json   |   24 
 qerror.c   |   36 
 qerror.h   |   27 +++
 qmp-commands.hx|5 +
 qmp.c  |5 +
 24 files changed, 216 insertions(+), 41 deletions(-)
 create mode 100644 osdep-qerror.c
 create mode 100644 osdep-qerror.h

-- 
1.7.9.3




[Qemu-devel] [PATCH v3 2/5] add qemu_fopen_err

2012-03-18 Thread Alon Levy
This adds a helper to conveniently set the correct error based on the
errno after a failed fopen.

The added function is placed in it's own c file to allow libcacard to
not develop dependencies on everything that qerror will bring in, which
includes monitor and half of qemu. I tried to make it as less ugly as I
could, by naming an osdep-no-qerror-obj-y and having that included in
osdep-obj-y, and using only the former for libcacard.

Signed-off-by: Alon Levy 
---
 Makefile.objs  |8 +---
 libcacard/Makefile |2 +-
 osdep-qerror.c |   52 
 osdep-qerror.h |8 
 osdep.c|1 -
 5 files changed, 66 insertions(+), 5 deletions(-)
 create mode 100644 osdep-qerror.c
 create mode 100644 osdep-qerror.h

diff --git a/Makefile.objs b/Makefile.objs
index 226b01d..fb5a73a 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -20,9 +20,11 @@ universal-obj-y += $(qom-obj-y)
 
 ###
 # oslib-obj-y is code depending on the OS (win32 vs posix)
-oslib-obj-y = osdep.o
-oslib-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o
-oslib-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o
+oslib-no-qerror-obj-y = osdep.o
+oslib-no-qerror-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o
+oslib-no-qerror-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o
+oslib-obj-y = $(oslib-no-qerror-obj-y)
+oslib-obj-y += osdep-qerror.o
 
 ###
 # coroutines
diff --git a/libcacard/Makefile b/libcacard/Makefile
index c6a896a..83f483f 100644
--- a/libcacard/Makefile
+++ b/libcacard/Makefile
@@ -8,7 +8,7 @@ libcacard_includedir=$(includedir)/cacard
 $(call set-vpath, $(SRC_PATH):$(libcacard_srcpath))
 
 # objects linked against normal qemu binaries, not compiled with libtool
-QEMU_OBJS=$(addprefix ../,$(oslib-obj-y) qemu-timer-common.o $(trace-obj-y))
+QEMU_OBJS=$(addprefix ../,$(oslib-no-qerror-obj-y) qemu-timer-common.o 
$(trace-obj-y))
 
 # objects linked into a shared library, built with libtool with -fPIC if 
required
 QEMU_OBJS_LIB=$(addsuffix .lo,$(basename $(QEMU_OBJS)))
diff --git a/osdep-qerror.c b/osdep-qerror.c
new file mode 100644
index 000..6dac984
--- /dev/null
+++ b/osdep-qerror.c
@@ -0,0 +1,52 @@
+#include "qerror.h"
+
+#include "osdep-qerror.h"
+
+/*
+ * Helper to set an Error after a failed fopen.
+ *
+ * Uses errno so it must not be changed by another intermediate call.
+ */
+void qemu_fopen_err(Error **errp, const char *file_name)
+{
+const char *fmt = NULL;
+
+switch (errno) {
+case EACCES:
+fmt = QERR_EACCES;
+break;
+case EINTR:
+fmt = QERR_EINTR;
+break;
+case EEXIST:
+fmt = QERR_EEXIST;
+break;
+case EMFILE:
+fmt = QERR_OPEN_FILE_EMFILE;
+break;
+case ENOSPC:
+fmt = QERR_ENOSPC;
+break;
+case EPERM:
+fmt = QERR_EPERM;
+break;
+case EROFS:
+fmt = QERR_READ_ONLY;
+break;
+case ENOTDIR:
+fmt = QERR_ENOTDIR;
+break;
+case EFBIG:
+fmt = QERR_EFBIG;
+break;
+default:
+/*
+ * EINVAL and ENOTSUP will result in the default
+ *
+ * ENOENT too, it's used by (for instance) bdrv_create_file for
+ * a different purpose then open (2) so just give a generic error.
+ */
+fmt = QERR_OPEN_FILE_FAILED;
+}
+error_set(errp, fmt, file_name);
+}
diff --git a/osdep-qerror.h b/osdep-qerror.h
new file mode 100644
index 000..7320f4a
--- /dev/null
+++ b/osdep-qerror.h
@@ -0,0 +1,8 @@
+#ifndef OSDEP_QERROR_H
+#define OSDEP_QERROR_H
+
+#include "error.h"
+
+void qemu_fopen_err(Error **errp, const char *file_name);
+
+#endif
diff --git a/osdep.c b/osdep.c
index 3e6bada..efdd21c 100644
--- a/osdep.c
+++ b/osdep.c
@@ -241,4 +241,3 @@ ssize_t qemu_recv_full(int fd, void *buf, size_t count, int 
flags)
 
 return total;
 }
-
-- 
1.7.9.3




[Qemu-devel] [PATCH v3 3/5] vga_hw_screen_dump: add Error** param

2012-03-18 Thread Alon Levy
To later use for qapi implementation of screendump.

Signed-off-by: Alon Levy 
---
 console.c   |5 +++--
 console.h   |6 --
 hw/blizzard.c   |3 ++-
 hw/g364fb.c |4 +++-
 hw/omap_lcdc.c  |4 +++-
 hw/qxl.c|6 --
 hw/tcx.c|   13 +
 hw/vga.c|7 +--
 hw/vmware_vga.c |6 --
 monitor.c   |2 +-
 10 files changed, 38 insertions(+), 18 deletions(-)

diff --git a/console.c b/console.c
index 6a463f5..d3fccf3 100644
--- a/console.c
+++ b/console.c
@@ -24,6 +24,7 @@
 #include "qemu-common.h"
 #include "console.h"
 #include "qemu-timer.h"
+#include "error.h"
 
 //#define DEBUG_CONSOLE
 #define DEFAULT_BACKSCROLL 512
@@ -173,7 +174,7 @@ void vga_hw_invalidate(void)
 active_console->hw_invalidate(active_console->hw);
 }
 
-void vga_hw_screen_dump(const char *filename)
+void vga_hw_screen_dump(const char *filename, Error **errp)
 {
 TextConsole *previous_active_console;
 bool cswitch;
@@ -187,7 +188,7 @@ void vga_hw_screen_dump(const char *filename)
 console_select(0);
 }
 if (consoles[0] && consoles[0]->hw_screen_dump) {
-consoles[0]->hw_screen_dump(consoles[0]->hw, filename, cswitch);
+consoles[0]->hw_screen_dump(consoles[0]->hw, filename, cswitch, errp);
 } else {
 error_report("screen dump not implemented");
 }
diff --git a/console.h b/console.h
index 4334db5..caf13f5 100644
--- a/console.h
+++ b/console.h
@@ -6,6 +6,7 @@
 #include "notify.h"
 #include "monitor.h"
 #include "trace.h"
+#include "error.h"
 
 /* keyboard/mouse support */
 
@@ -343,7 +344,8 @@ static inline void console_write_ch(console_ch_t *dest, 
uint32_t ch)
 
 typedef void (*vga_hw_update_ptr)(void *);
 typedef void (*vga_hw_invalidate_ptr)(void *);
-typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch);
+typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch,
+   Error **errp);
 typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
 
 DisplayState *graphic_console_init(vga_hw_update_ptr update,
@@ -354,7 +356,7 @@ DisplayState *graphic_console_init(vga_hw_update_ptr update,
 
 void vga_hw_update(void);
 void vga_hw_invalidate(void);
-void vga_hw_screen_dump(const char *filename);
+void vga_hw_screen_dump(const char *filename, Error **errp);
 void vga_hw_text_update(console_ch_t *chardata);
 
 int is_graphic_console(void);
diff --git a/hw/blizzard.c b/hw/blizzard.c
index c7d844d..76df78c 100644
--- a/hw/blizzard.c
+++ b/hw/blizzard.c
@@ -23,6 +23,7 @@
 #include "devices.h"
 #include "vga_int.h"
 #include "pixel_ops.h"
+#include "error.h"
 
 typedef void (*blizzard_fn_t)(uint8_t *, const uint8_t *, unsigned int);
 
@@ -933,7 +934,7 @@ static void blizzard_update_display(void *opaque)
 }
 
 static void blizzard_screen_dump(void *opaque, const char *filename,
- bool cswitch)
+ bool cswitch, Error **errp)
 {
 BlizzardState *s = (BlizzardState *) opaque;
 
diff --git a/hw/g364fb.c b/hw/g364fb.c
index 3a0b68f..7774d05 100644
--- a/hw/g364fb.c
+++ b/hw/g364fb.c
@@ -22,6 +22,7 @@
 #include "pixel_ops.h"
 #include "trace.h"
 #include "sysbus.h"
+#include "error.h"
 
 typedef struct G364State {
 /* hardware */
@@ -289,7 +290,8 @@ static void g364fb_reset(G364State *s)
 g364fb_invalidate_display(s);
 }
 
-static void g364fb_screen_dump(void *opaque, const char *filename, bool 
cswitch)
+static void g364fb_screen_dump(void *opaque, const char *filename, bool 
cswitch,
+   Error **errp)
 {
 G364State *s = opaque;
 int y, x;
diff --git a/hw/omap_lcdc.c b/hw/omap_lcdc.c
index f172093..aec7210 100644
--- a/hw/omap_lcdc.c
+++ b/hw/omap_lcdc.c
@@ -20,6 +20,7 @@
 #include "console.h"
 #include "omap.h"
 #include "framebuffer.h"
+#include "error.h"
 
 struct omap_lcd_panel_s {
 MemoryRegion *sysmem;
@@ -264,7 +265,8 @@ static int ppm_save(const char *filename, uint8_t *data,
 return 0;
 }
 
-static void omap_screen_dump(void *opaque, const char *filename, bool cswitch)
+static void omap_screen_dump(void *opaque, const char *filename, bool cswitch,
+ Error **errp)
 {
 struct omap_lcd_panel_s *omap_lcd = opaque;
 if (cswitch) {
diff --git a/hw/qxl.c b/hw/qxl.c
index e17b0e3..27f27f5 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -23,6 +23,7 @@
 #include "qemu-queue.h"
 #include "monitor.h"
 #include "sysemu.h"
+#include "error.h"
 
 #include "qxl.h"
 
@@ -1492,7 +1493,8 @@ static void qxl_hw_invalidate(void *opaque)
 vga->invalidate(vga);
 }
 
-static void qxl_hw_screen_dump(void *opaque, const char *filename, bool 
cswitch)
+static void qxl_hw_screen_dump(void *opaque, const char *filename, bool 
cswitch,
+   Error **errp)
 {
 PCIQXLDevice *qxl = opaque;
 VGACommonState *vga = &qxl->vga;
@@ -1504,7 +1506,7 @@ static void qxl_hw_screen_dump(v

[Qemu-devel] [PATCH v3 4/5] qapi: convert screendump

2012-03-18 Thread Alon Levy
The documenting comment contains the long list of possible errors from
qemu_fopen_err, this could probably be put somewhere else in the file
once more of the api uses those common error classes.

Signed-off-by: Alon Levy 
---
 hmp-commands.hx  |3 +--
 hmp.c|8 
 hmp.h|1 +
 monitor.c|6 --
 qapi-schema.json |   24 
 qmp-commands.hx  |5 +
 qmp.c|5 +
 7 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 6980214..d26421a 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -194,8 +194,7 @@ ETEXI
 .args_type  = "filename:F",
 .params = "filename",
 .help   = "save screen into PPM image 'filename'",
-.user_print = monitor_user_noop,
-.mhandler.cmd_new = do_screen_dump,
+.mhandler.cmd = hmp_screendump,
 },
 
 STEXI
diff --git a/hmp.c b/hmp.c
index 290c43d..42dc79a 100644
--- a/hmp.c
+++ b/hmp.c
@@ -860,3 +860,11 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
 
 hmp_handle_error(mon, &error);
 }
+
+void hmp_screendump(Monitor *mon, const QDict *qdict)
+{
+Error *err = NULL;
+
+qmp_screendump(qdict_get_str(qdict, "filename"), &err);
+hmp_handle_error(mon, &err);
+}
diff --git a/hmp.h b/hmp.h
index 5409464..25d123f 100644
--- a/hmp.h
+++ b/hmp.h
@@ -59,5 +59,6 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict 
*qdict);
 void hmp_block_stream(Monitor *mon, const QDict *qdict);
 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict);
 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict);
+void hmp_screendump(Monitor *mon, const QDict *qdict);
 
 #endif
diff --git a/monitor.c b/monitor.c
index 2156fcf..34d7617 100644
--- a/monitor.c
+++ b/monitor.c
@@ -893,12 +893,6 @@ static int client_migrate_info(Monitor *mon, const QDict 
*qdict,
 return -1;
 }
 
-static int do_screen_dump(Monitor *mon, const QDict *qdict, QObject **ret_data)
-{
-vga_hw_screen_dump(qdict_get_str(qdict, "filename"), NULL);
-return 0;
-}
-
 static void do_logfile(Monitor *mon, const QDict *qdict)
 {
 cpu_set_log_filename(qdict_get_str(qdict, "filename"));
diff --git a/qapi-schema.json b/qapi-schema.json
index 04fa84f..b9baba9 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1663,3 +1663,27 @@
 { 'command': 'qom-list-types',
   'data': { '*implements': 'str', '*abstract': 'bool' },
   'returns': [ 'ObjectTypeInfo' ] }
+
+##
+# @screendump:
+#
+# Write a PPM of the VGA screen to a file.
+#
+# @filename: the name of a new PPM file to create to store the image
+#
+# Returns: Nothing on success
+#  If @cpu is not a valid VCPU, InvalidParameterValue
+#  If @filename cannot be opened, OpenFileFailed or one of the more
+#  specific errors:
+#EINTR - Interruped during operation
+#EACCES - Cannot access file
+#OpenFileEMFILE - Maximum open file descriptors reached
+#ENOSPC - No space on device
+#EPERM - No permission
+#READ_ONLY - File system is read only
+#ENOTDIR - Path to file contains a non directory element
+#
+##
+# Since: 1.1
+##
+{ 'command': 'screendump', 'data': {'filename': 'str'} }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index dfe8a5b..5fe57fd 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -146,10 +146,7 @@ EQMP
 {
 .name   = "screendump",
 .args_type  = "filename:F",
-.params = "filename",
-.help   = "save screen into PPM image 'filename'",
-.user_print = monitor_user_noop,
-.mhandler.cmd_new = do_screen_dump,
+.mhandler.cmd_new = qmp_marshal_input_screendump,
 },
 
 SQMP
diff --git a/qmp.c b/qmp.c
index a182b51..086cec8 100644
--- a/qmp.c
+++ b/qmp.c
@@ -415,3 +415,8 @@ ObjectTypeInfoList *qmp_qom_list_types(bool has_implements,
 
 return ret;
 }
+
+void qmp_screendump(const char *filename, Error **errp)
+{
+vga_hw_screen_dump(filename, errp);
+}
-- 
1.7.9.3




[Qemu-devel] [PATCH v3 5/5] vga: ppm_save(): Return error on failure

2012-03-18 Thread Alon Levy
From: Luiz Capitulino 

This makes all devices using ppm_save() return an error appropriately
when the screendump command fails.

Based on a code by Anthony Liguori.

Signed-off-by: Luiz Capitulino 
Signed-off-by: Alon Levy 
---
 hw/blizzard.c   |2 +-
 hw/qxl.c|2 +-
 hw/vga.c|8 +---
 hw/vga_int.h|3 ++-
 hw/vmware_vga.c |2 +-
 5 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/hw/blizzard.c b/hw/blizzard.c
index 76df78c..29e5ae6 100644
--- a/hw/blizzard.c
+++ b/hw/blizzard.c
@@ -942,7 +942,7 @@ static void blizzard_screen_dump(void *opaque, const char 
*filename,
 blizzard_update_display(opaque);
 }
 if (s && ds_get_data(s->state))
-ppm_save(filename, s->state->surface);
+ppm_save(filename, s->state->surface, errp);
 }
 
 #define DEPTH 8
diff --git a/hw/qxl.c b/hw/qxl.c
index 27f27f5..aa68612 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -1503,7 +1503,7 @@ static void qxl_hw_screen_dump(void *opaque, const char 
*filename, bool cswitch,
 case QXL_MODE_COMPAT:
 case QXL_MODE_NATIVE:
 qxl_render_update(qxl);
-ppm_save(filename, qxl->ssd.ds->surface);
+ppm_save(filename, qxl->ssd.ds->surface, errp);
 break;
 case QXL_MODE_VGA:
 vga->screen_dump(vga, filename, cswitch, errp);
diff --git a/hw/vga.c b/hw/vga.c
index 79c5c38..80e6dca 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -2365,7 +2365,7 @@ void vga_init_vbe(VGACommonState *s, MemoryRegion 
*system_memory)
 //
 /* vga screen dump */
 
-int ppm_save(const char *filename, struct DisplaySurface *ds)
+int ppm_save(const char *filename, struct DisplaySurface *ds, Error **errp)
 {
 FILE *f;
 uint8_t *d, *d1;
@@ -2377,8 +2377,10 @@ int ppm_save(const char *filename, struct DisplaySurface 
*ds)
 
 trace_ppm_save(filename, ds);
 f = fopen(filename, "wb");
-if (!f)
+if (!f) {
+error_set_file_open_failed(errp, filename, errno);
 return -1;
+}
 fprintf(f, "P6\n%d %d\n%d\n",
 ds->width, ds->height, 255);
 linebuf = g_malloc(ds->width * 3);
@@ -2420,5 +2422,5 @@ static void vga_screen_dump(void *opaque, const char 
*filename, bool cswitch,
 vga_invalidate_display(s);
 vga_hw_update();
 }
-ppm_save(filename, s->ds->surface);
+ppm_save(filename, s->ds->surface, errp);
 }
diff --git a/hw/vga_int.h b/hw/vga_int.h
index 7685b2b..63078ba 100644
--- a/hw/vga_int.h
+++ b/hw/vga_int.h
@@ -24,6 +24,7 @@
 
 #include 
 #include "memory.h"
+#include "error.h"
 
 #define ST01_V_RETRACE  0x08
 #define ST01_DISP_ENABLE0x01
@@ -200,7 +201,7 @@ void vga_ioport_write(void *opaque, uint32_t addr, uint32_t 
val);
 uint32_t vga_mem_readb(VGACommonState *s, target_phys_addr_t addr);
 void vga_mem_writeb(VGACommonState *s, target_phys_addr_t addr, uint32_t val);
 void vga_invalidate_scanlines(VGACommonState *s, int y1, int y2);
-int ppm_save(const char *filename, struct DisplaySurface *ds);
+int ppm_save(const char *filename, struct DisplaySurface *ds, Error **errp);
 
 int vga_ioport_invalid(VGACommonState *s, uint32_t addr);
 void vga_init_vbe(VGACommonState *s, MemoryRegion *address_space);
diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c
index 6868778..0769652 100644
--- a/hw/vmware_vga.c
+++ b/hw/vmware_vga.c
@@ -1016,7 +1016,7 @@ static void vmsvga_screen_dump(void *opaque, const char 
*filename, bool cswitch,
 if (s->depth == 32) {
 DisplaySurface *ds = qemu_create_displaysurface_from(s->width,
 s->height, 32, ds_get_linesize(s->vga.ds), s->vga.vram_ptr);
-ppm_save(filename, ds);
+ppm_save(filename, ds, errp);
 g_free(ds);
 }
 }
-- 
1.7.9.3




[Qemu-devel] [PATCH v3 1/5] qerror: add error codes for fopen failure

2012-03-18 Thread Alon Levy
Added:

QERR_EINTR
QERR_EACCES
QERR_EEXIST
QERR_OPEN_FILE_EMFILE
QERR_ENOSPC
QERR_EPERM
QERR_READ_ONLY
QERR_ENOTDIR
QERR_EFBIG

Signed-off-by: Alon Levy 
---
 qerror.c |   36 
 qerror.h |   27 +++
 2 files changed, 63 insertions(+)

diff --git a/qerror.c b/qerror.c
index f55d435..4915939 100644
--- a/qerror.c
+++ b/qerror.c
@@ -213,6 +213,42 @@ static const QErrorStringTable qerror_table[] = {
 .desc  = "Could not open '%(filename)'",
 },
 {
+.error_fmt = QERR_EINTR,
+.desc  = "Interrupted open of '%(filename)'",
+},
+{
+.error_fmt = QERR_EACCES,
+.desc  = "Cannot access file'",
+},
+{
+.error_fmt = QERR_EEXIST,
+.desc  = "File already exists'",
+},
+{
+.error_fmt = QERR_OPEN_FILE_EMFILE,
+.desc  = "Max open files when opening file'",
+},
+{
+.error_fmt = QERR_ENOSPC,
+.desc  = "No space left opening file'",
+},
+{
+.error_fmt = QERR_EPERM,
+.desc  = "Permission denied (EPERM) opening file'",
+},
+{
+.error_fmt = QERR_READ_ONLY,
+.desc  = "Read only filesystem opening file'",
+},
+{
+.error_fmt = QERR_ENOTDIR,
+.desc  = "Directory related error opening file'",
+},
+{
+.error_fmt = QERR_EFBIG,
+.desc  = "File too big opening'",
+},
+{
 .error_fmt = QERR_PERMISSION_DENIED,
 .desc  = "Insufficient permission to perform this operation",
 },
diff --git a/qerror.h b/qerror.h
index e26c635..ddc04e8 100644
--- a/qerror.h
+++ b/qerror.h
@@ -181,6 +181,33 @@ QError *qobject_to_qerror(const QObject *obj);
 #define QERR_OPEN_FILE_FAILED \
 "{ 'class': 'OpenFileFailed', 'data': { 'filename': %s } }"
 
+#define QERR_OPEN_FILE_EMFILE \
+"{ 'class': 'OpenFileEMFILE', 'data': {} }"
+
+#define QERR_EINTR \
+"{ 'class': 'EINTR', 'data': {} }"
+
+#define QERR_EACCES \
+"{ 'class': 'EACCES', 'data': {} }"
+
+#define QERR_EEXIST \
+"{ 'class': 'EEXIST', 'data': {} }"
+
+#define QERR_ENOSPC \
+"{ 'class': 'ENOSPC', 'data': {} }"
+
+#define QERR_EPERM \
+"{ 'class': 'EPERM', 'data': {} }"
+
+#define QERR_READ_ONLY \
+"{ 'class': 'ReadOnly', 'data': {} }"
+
+#define QERR_ENOTDIR \
+"{ 'class': 'ENOTDIR', 'data': {} }"
+
+#define QERR_EFBIG \
+"{ 'class': 'EFBIG', 'data': {} }"
+
 #define QERR_PERMISSION_DENIED \
 "{ 'class': 'PermissionDenied', 'data': {} }"
 
-- 
1.7.9.3




[Qemu-devel] qemu-ppc during my vacation

2012-03-18 Thread Alexander Graf
Howdy,

it's that time of the year again - I'm off for 3 weeks vacation :). In order 
for things not to go more chaotic than they already are while I'm off, I asked 
Andreas to jump in for the QEMU PPC tree maintenance and he fortunately 
accepted!

So during the next 3 weeks, Andreas Färber will be allowed to do pull requests 
in my stead.

However, this comes with a small nit:

  ** No patch goes in without ack **

Andreas is allowed to ack himself too of course, but since he doesn't know all 
parts of PPC by heart, I'm sure he'll keep that to a minimum. David Gibson 
promised to help out on that front, acking patches whenever he can. Scott, it 
would be great if you could also help and review / ack patches when you see 
them.

However, the sender of a patch is not allowed to ack. So if Scott sends out a 
patch, someone else - David for example - needs to ack it for the patch to be 
accepted into Andreas' tree. I don't think that will be a real issue however - 
you guys have already been an enormous help in review in the past and if you 
continue the same way, you won't even realize I'm not around ;).


With this said, I'm sure we can keep the tree alive, working and kicking while 
I'm off :). So please help out wherever you can!

Alex




[Qemu-devel] [PATCH 3/3] target-sparc: Add compiler attribute to some functions which don't return

2012-03-18 Thread Stefan Weil
helper_raise_exception does not return, nor does do_unaligned_access.

Cc: Blue Swirl 
Signed-off-by: Stefan Weil 
---
 target-sparc/cpu.h|5 +++--
 target-sparc/helper.h |2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/target-sparc/cpu.h b/target-sparc/cpu.h
index 1025752..885ad45 100644
--- a/target-sparc/cpu.h
+++ b/target-sparc/cpu.h
@@ -699,8 +699,9 @@ uint64_t cpu_tick_get_count(CPUTimer *timer);
 void cpu_tick_set_limit(CPUTimer *timer, uint64_t limit);
 trap_state* cpu_tsptr(CPUSPARCState* env);
 #endif
-void do_unaligned_access(CPUSPARCState *env, target_ulong addr, int is_write,
- int is_user, void *retaddr);
+void QEMU_NORETURN do_unaligned_access(CPUSPARCState *env, target_ulong addr,
+   int is_write, int is_user,
+   void *retaddr);
 
 #define TB_FLAG_FPU_ENABLED (1 << 4)
 #define TB_FLAG_AM_ENABLED (1 << 5)
diff --git a/target-sparc/helper.h b/target-sparc/helper.h
index c4d6225..e3c7fdd 100644
--- a/target-sparc/helper.h
+++ b/target-sparc/helper.h
@@ -78,7 +78,7 @@ DEF_HELPER_1(fcmpeq_fcc1, void, env)
 DEF_HELPER_1(fcmpeq_fcc2, void, env)
 DEF_HELPER_1(fcmpeq_fcc3, void, env)
 #endif
-DEF_HELPER_2(raise_exception, void, env, int)
+DEF_HELPER_2(raise_exception, noreturn, env, int)
 #define F_HELPER_0_1(name) DEF_HELPER_1(f ## name, void, env)
 
 DEF_HELPER_3(faddd, f64, env, f64, f64)
-- 
1.7.9




[Qemu-devel] [PATCH 1/3] Add support for target helper functions which don't return

2012-03-18 Thread Stefan Weil
Most functions which handle exceptions don't return.

With a compiler attribute (added by QEMU_NORETURN),
gcc can optimize the code.

Signed-off-by: Stefan Weil 
---
 def-helper.h |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/def-helper.h b/def-helper.h
index 0e70c31..b98ff69 100644
--- a/def-helper.h
+++ b/def-helper.h
@@ -39,6 +39,7 @@
 #endif
 #define dh_alias_ptr ptr
 #define dh_alias_void void
+#define dh_alias_noreturn noreturn
 #define dh_alias_env ptr
 #define dh_alias(t) glue(dh_alias_, t)
 
@@ -52,36 +53,42 @@
 #define dh_ctype_tl target_ulong
 #define dh_ctype_ptr void *
 #define dh_ctype_void void
+#define dh_ctype_noreturn void QEMU_NORETURN
 #define dh_ctype_env CPUArchState *
 #define dh_ctype(t) dh_ctype_##t
 
 /* We can't use glue() here because it falls foul of C preprocessor
recursive expansion rules.  */
 #define dh_retvar_decl0_void void
+#define dh_retvar_decl0_noreturn void
 #define dh_retvar_decl0_i32 TCGv_i32 retval
 #define dh_retvar_decl0_i64 TCGv_i64 retval
 #define dh_retvar_decl0_ptr TCGv_ptr retval
 #define dh_retvar_decl0(t) glue(dh_retvar_decl0_, dh_alias(t))
 
 #define dh_retvar_decl_void
+#define dh_retvar_decl_noreturn
 #define dh_retvar_decl_i32 TCGv_i32 retval,
 #define dh_retvar_decl_i64 TCGv_i64 retval,
 #define dh_retvar_decl_ptr TCGv_ptr retval,
 #define dh_retvar_decl(t) glue(dh_retvar_decl_, dh_alias(t))
 
 #define dh_retvar_void TCG_CALL_DUMMY_ARG
+#define dh_retvar_noreturn TCG_CALL_DUMMY_ARG
 #define dh_retvar_i32 GET_TCGV_i32(retval)
 #define dh_retvar_i64 GET_TCGV_i64(retval)
 #define dh_retvar_ptr GET_TCGV_ptr(retval)
 #define dh_retvar(t) glue(dh_retvar_, dh_alias(t))
 
 #define dh_is_64bit_void 0
+#define dh_is_64bit_noreturn 0
 #define dh_is_64bit_i32 0
 #define dh_is_64bit_i64 1
 #define dh_is_64bit_ptr (TCG_TARGET_REG_BITS == 64)
 #define dh_is_64bit(t) glue(dh_is_64bit_, dh_alias(t))
 
 #define dh_is_signed_void 0
+#define dh_is_signed_noreturn 0
 #define dh_is_signed_i32 0
 #define dh_is_signed_s32 1
 #define dh_is_signed_i64 0
-- 
1.7.9




[Qemu-devel] [PATCH 2/3] target-mips: Add compiler attribute to some functions which don't return

2012-03-18 Thread Stefan Weil
helper_raise_exception_err does not return, nor do helper_raise_exception
and do_unaligned_access.

Cc: Aurelien Jarno 
Signed-off-by: Stefan Weil 
---
 target-mips/helper.h|4 ++--
 target-mips/op_helper.c |3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/target-mips/helper.h b/target-mips/helper.h
index 442f684..76fb451 100644
--- a/target-mips/helper.h
+++ b/target-mips/helper.h
@@ -1,7 +1,7 @@
 #include "def-helper.h"
 
-DEF_HELPER_2(raise_exception_err, void, i32, int)
-DEF_HELPER_1(raise_exception, void, i32)
+DEF_HELPER_2(raise_exception_err, noreturn, i32, int)
+DEF_HELPER_1(raise_exception, noreturn, i32)
 
 #ifdef TARGET_MIPS64
 DEF_HELPER_3(ldl, tl, tl, tl, int)
diff --git a/target-mips/op_helper.c b/target-mips/op_helper.c
index 584f0ab..a825c94 100644
--- a/target-mips/op_helper.c
+++ b/target-mips/op_helper.c
@@ -2274,7 +2274,8 @@ void helper_wait (void)
 
 #if !defined(CONFIG_USER_ONLY)
 
-static void do_unaligned_access (target_ulong addr, int is_write, int is_user, 
void *retaddr);
+static void QEMU_NORETURN do_unaligned_access(target_ulong addr, int is_write,
+  int is_user, void *retaddr);
 
 #define MMUSUFFIX _mmu
 #define ALIGNED_ONLY
-- 
1.7.9




[Qemu-devel] [Bug 957622] Re: kvm -kernel with grub multiboot kernel dumps core or exits

2012-03-18 Thread Scott Moser
Forwarded to qemu-devel mailing list at http://www.mail-archive.com
/qemu-devel@nongnu.org/msg103059.html .

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

Title:
  kvm -kernel with grub multiboot kernel dumps core or exits

Status in QEMU:
  Confirmed
Status in “qemu-kvm” package in Ubuntu:
  In Progress

Bug description:
  I attempted to use kvm -kernel with a grub multiboot image,
  specifically grub-maverick-20100729.img at [1].  That file was built
  using [2]

  $ 
url="http://bazaar.launchpad.net/~ubuntu-on-ec2/vmbuilder/automated-ec2-builds/download/head:/grubmaverick20100729-20100729071944-bevge631maio9jpl-2/grub-maverick-20100729.img";
  $ wget $url -O grub-maverick-20100729.img
  $ qemu-kvm create -f qcow2 disk.img 1G
  $ kvm -curses -kernel grub-maverick-20100729.img -drive 
file=disk.img,if=virtio

  This process works fine on oneiric and you will see a curses
  interface, and some output of grub looking for a image to boot.

  On my laptop (with kvm support), I saw:

  $ kvm -curses -kernel grub-maverick-20100729.img -drive 
file=disk.img,if=virtio;
  fread() failed
  $ echo $?
  1

  On a kvm guest (via openstack instance), it crashed differently:
  $ kvm -curses -kernel grub-maverick-20100729.img -drive 
file=disk.img,if=virtio
  Could not access KVM kernel module: No such file or directory
  failed to initialize KVM: No such file or directory
  Back to tcg accelerator.

  GLib-ERROR **: /build/buildd/glib2.0-2.31.20/./glib/gmem.c:165: failed to 
allocate 4293918720 bytes
  Trace/breakpoint trap (core dumped)

  
  Just for a test, I tried loading kvm-amd, got nested kvm virtualization, but 
the instance fails the same way.

  
  --
  [1] 
http://bazaar.launchpad.net/~ubuntu-on-ec2/vmbuilder/automated-ec2-builds/files/head:/loaders/
  [2] 
http://bazaar.launchpad.net/~ubuntu-on-ec2/vmbuilder/automated-ec2-builds/view/head:/mk-image-mb-loader

  ProblemType: Bug
  DistroRelease: Ubuntu 12.04
  Package: kvm (not installed)
  ProcVersionSignature: User Name 3.2.0-18.29-virtual 3.2.9
  Uname: Linux 3.2.0-18-virtual x86_64
  ApportVersion: 1.94.1-0ubuntu2
  Architecture: amd64
  CurrentDmesg:
   [27230.320857] init: qemu-kvm pre-start process (8659) terminated with 
status 1
   [27230.361904] init: qemu-kvm post-stop process (8664) terminated with 
status 1
   [27249.426836] kvm[9021] trap int3 ip:7f44c2bbc13b sp:7fff447e1120 error:0
   [27263.380598] kvm[9283] trap int3 ip:7f3fba9f713b sp:7fff8b55d1a0 error:0
  Date: Sat Mar 17 01:48:13 2012
  Ec2AMI: ami-
  Ec2AMIManifest: FIXME
  Ec2AvailabilityZone: nova
  Ec2InstanceType: m1.small
  Ec2Kernel: unavailable
  Ec2Ramdisk: unavailable
  KvmCmdLine: Error: command ['ps', '-C', 'kvm', '-F'] failed with exit code 1: 
UIDPID  PPID  CSZ   RSS PSR STIME TTY  TIME CMD
  Lsusb:
   Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
   Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd
  MachineType: Bochs Bochs
  ProcEnviron:
   TERM=screen
   PATH=(custom, user)
   LANG=en_US.UTF-8
   SHELL=/bin/bash
  ProcKernelCmdLine: BOOT_IMAGE=/boot/vmlinuz-3.2.0-18-virtual 
root=LABEL=cloudimg-rootfs ro console=ttyS0
  ProcModules:
   acpiphp 24231 0 - Live 0x
   floppy 70365 0 - Live 0x
   psmouse 87603 0 - Live 0x
   serio_raw 13211 0 - Live 0x
   virtio_balloon 13108 0 - Live 0x
  SourcePackage: qemu-kvm
  UpgradeStatus: No upgrade log present (probably fresh install)
  dmi.bios.date: 01/01/2007
  dmi.bios.vendor: Bochs
  dmi.bios.version: Bochs
  dmi.chassis.type: 1
  dmi.chassis.vendor: Bochs
  dmi.modalias: 
dmi:bvnBochs:bvrBochs:bd01/01/2007:svnBochs:pnBochs:pvr:cvnBochs:ct1:cvr:
  dmi.product.name: Bochs
  dmi.sys.vendor: Bochs

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



[Qemu-devel] [Bug 957622] Re: kvm -kernel with grub multiboot kernel dumps core or exits

2012-03-18 Thread Scott Moser
** Patch added: "suggested debdiff"
   
https://bugs.launchpad.net/qemu/+bug/957622/+attachment/2894794/+files/lp957622.debdiff

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

Title:
  kvm -kernel with grub multiboot kernel dumps core or exits

Status in QEMU:
  Confirmed
Status in “qemu-kvm” package in Ubuntu:
  In Progress

Bug description:
  I attempted to use kvm -kernel with a grub multiboot image,
  specifically grub-maverick-20100729.img at [1].  That file was built
  using [2]

  $ 
url="http://bazaar.launchpad.net/~ubuntu-on-ec2/vmbuilder/automated-ec2-builds/download/head:/grubmaverick20100729-20100729071944-bevge631maio9jpl-2/grub-maverick-20100729.img";
  $ wget $url -O grub-maverick-20100729.img
  $ qemu-kvm create -f qcow2 disk.img 1G
  $ kvm -curses -kernel grub-maverick-20100729.img -drive 
file=disk.img,if=virtio

  This process works fine on oneiric and you will see a curses
  interface, and some output of grub looking for a image to boot.

  On my laptop (with kvm support), I saw:

  $ kvm -curses -kernel grub-maverick-20100729.img -drive 
file=disk.img,if=virtio;
  fread() failed
  $ echo $?
  1

  On a kvm guest (via openstack instance), it crashed differently:
  $ kvm -curses -kernel grub-maverick-20100729.img -drive 
file=disk.img,if=virtio
  Could not access KVM kernel module: No such file or directory
  failed to initialize KVM: No such file or directory
  Back to tcg accelerator.

  GLib-ERROR **: /build/buildd/glib2.0-2.31.20/./glib/gmem.c:165: failed to 
allocate 4293918720 bytes
  Trace/breakpoint trap (core dumped)

  
  Just for a test, I tried loading kvm-amd, got nested kvm virtualization, but 
the instance fails the same way.

  
  --
  [1] 
http://bazaar.launchpad.net/~ubuntu-on-ec2/vmbuilder/automated-ec2-builds/files/head:/loaders/
  [2] 
http://bazaar.launchpad.net/~ubuntu-on-ec2/vmbuilder/automated-ec2-builds/view/head:/mk-image-mb-loader

  ProblemType: Bug
  DistroRelease: Ubuntu 12.04
  Package: kvm (not installed)
  ProcVersionSignature: User Name 3.2.0-18.29-virtual 3.2.9
  Uname: Linux 3.2.0-18-virtual x86_64
  ApportVersion: 1.94.1-0ubuntu2
  Architecture: amd64
  CurrentDmesg:
   [27230.320857] init: qemu-kvm pre-start process (8659) terminated with 
status 1
   [27230.361904] init: qemu-kvm post-stop process (8664) terminated with 
status 1
   [27249.426836] kvm[9021] trap int3 ip:7f44c2bbc13b sp:7fff447e1120 error:0
   [27263.380598] kvm[9283] trap int3 ip:7f3fba9f713b sp:7fff8b55d1a0 error:0
  Date: Sat Mar 17 01:48:13 2012
  Ec2AMI: ami-
  Ec2AMIManifest: FIXME
  Ec2AvailabilityZone: nova
  Ec2InstanceType: m1.small
  Ec2Kernel: unavailable
  Ec2Ramdisk: unavailable
  KvmCmdLine: Error: command ['ps', '-C', 'kvm', '-F'] failed with exit code 1: 
UIDPID  PPID  CSZ   RSS PSR STIME TTY  TIME CMD
  Lsusb:
   Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
   Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd
  MachineType: Bochs Bochs
  ProcEnviron:
   TERM=screen
   PATH=(custom, user)
   LANG=en_US.UTF-8
   SHELL=/bin/bash
  ProcKernelCmdLine: BOOT_IMAGE=/boot/vmlinuz-3.2.0-18-virtual 
root=LABEL=cloudimg-rootfs ro console=ttyS0
  ProcModules:
   acpiphp 24231 0 - Live 0x
   floppy 70365 0 - Live 0x
   psmouse 87603 0 - Live 0x
   serio_raw 13211 0 - Live 0x
   virtio_balloon 13108 0 - Live 0x
  SourcePackage: qemu-kvm
  UpgradeStatus: No upgrade log present (probably fresh install)
  dmi.bios.date: 01/01/2007
  dmi.bios.vendor: Bochs
  dmi.bios.version: Bochs
  dmi.chassis.type: 1
  dmi.chassis.vendor: Bochs
  dmi.modalias: 
dmi:bvnBochs:bvrBochs:bd01/01/2007:svnBochs:pnBochs:pvr:cvnBochs:ct1:cvr:
  dmi.product.name: Bochs
  dmi.sys.vendor: Bochs

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



[Qemu-devel] [PATCH] PNG screendump output alternative

2012-03-18 Thread Rafael
Hi,

 I  had already started to work on supporting PNG dump output on
screendump when got to know there was another effort to do the same
 (see Add PNG screendump thread from Daniel P. Berrange). Anyway, I'd
 like to share my implementation which is a little bit different. It
 does not use any resource/lib besides libpng and qemu itself and is
 based on qemu-kvm 0.15.1 ppm_save code.

 I'm using that for a personal project developed at Mandriva which uses
 QMP directly to communicate with qemu VMs rather than using the
 libvirt although its usage is considered for the future. There is
 something more to show but it is just QMP related and soon I'll have
 it done to share.

 Comments and suggestions are appreciated.

 Cheers
 Rafael Cabral

--- configure   2011-10-19 13:54:48.0 +
+++ configure   2012-03-15 13:33:26.0 +
@@ -141,6 +141,7 @@
 attr=""
 vhost_net=""
 xfs=""
+dump_png=""

 gprof="no"
 debug_tcg="no"
@@ -790,6 +791,10 @@
   ;;
   --disable-guest-agent) guest_agent="no"
   ;;
+  --disable-dump-png) dump_png="no"
+  ;;
+  --enable-dump-png) dump_png="yes"
+  ;;
   *) echo "ERROR: unknown option $opt"; show_help="yes"
   ;;
   esac
@@ -1075,6 +1080,8 @@
 echo "  --enable-usb-redir   enable usb network redirection support"
 echo "  --disable-guest-agentdisable building of the QEMU Guest Agent"
 echo "  --enable-guest-agent enable building of the QEMU Guest Agent"
+echo "  --disable-dump-png   disable PNG for screendump output"
+echo "  --enable-dump-pngenable PNG for screendump output"
 echo ""
 echo "NOTE: The object files are built at the place where configure
is launched"
 exit 1
@@ -2610,6 +2617,40 @@
 fi

 ##
+# DUMP PNG detection
+if test "$dump_png" = "yes" ; then
+cat > $TMPC <
+#include 
+#include 
+int main(void) {
+png_structp png_ptr;
+png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+return 0;
+}
+EOF
+  if $pkg_config libpng --modversion >/dev/null 2>&1; then
+dump_png_cflags=`$pkg_config libpng --cflags 2> /dev/null`
+dump_png_libs=`$pkg_config libpng --libs 2> /dev/null`
+  else
+dump_png_cflags=""
+dump_png_libs="-lpng"
+  fi
+  if compile_prog "$dump_png_cflags" "$dump_png_libs" ; then
+dump_png=yes
+libs_softmmu="$dump_png_libs $libs_softmmu"
+  else
+if test "dump_png" = "yes" ; then
+  feature_not_found "dump-png"
+fi
+dump_png=no
+  fi
+fi
+#
+
+
+
+##
 # End of CC checks
 # After here, no more $cc or $ld runs

@@ -2776,6 +2817,7 @@
 echo "usb net redir $usb_redir"
 echo "OpenGL support$opengl"
 echo "build guest agent $guest_agent"
+echo "Dump png $dump_png"

 if test $sdl_too_old = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -3083,6 +3125,11 @@
   echo "CONFIG_OPENGL=y" >> $config_host_mak
 fi

+if test "$dump_png" = "yes" ; then
+  echo "CONFIG_DUMP_PNG=y" >> $config_host_mak
+  echo "DUMP_PNG_CFLAGS=$dump_png_cflags" >> $config_host_mak
+fi
+
 # XXX: suppress that
 if [ "$bsd" = "yes" ] ; then
   echo "CONFIG_BSD=y" >> $config_host_mak
--- hw/vga.c2011-10-19 13:54:48.0 +
+++ hw/vga.c2012-03-17 21:53:12.0 +
@@ -29,6 +29,10 @@
 #include "pixel_ops.h"
 #include "qemu-timer.h"

+#ifdef CONFIG_DUMP_PNG
+#include 
+#endif
+
 //#define DEBUG_VGA
 //#define DEBUG_VGA_MEM
 //#define DEBUG_VGA_REG
@@ -2329,7 +2333,14 @@
 int x, int y, int w, int h)
 {
 if (screen_dump_filename) {
-ppm_save(screen_dump_filename, ds->surface);
+#ifdef CONFIG_DUMP_PNG
+   if (is_png_extension(screen_dump_filename))
+   png_save(screen_dump_filename, ds->surface);
+   else
+   ppm_save(screen_dump_filename, ds->surface);
+#else
+   ppm_save(screen_dump_filename, ds->surface);
+#endif
 screen_dump_filename = NULL;
 }
 }
@@ -2342,6 +2353,95 @@
 {
 }

+#ifdef CONFIG_DUMP_PNG
+int is_png_extension(const char * filename)
+{
+if (!(filename == NULL)) {
+char * c;
+for (c = filename;*c != NULL; ++c);
+c -= 4;
+if (*c++ == '.' && *c++ == 'p' && *c++ == 'n' && *c == 'g')
+return 1;
+}
+return 0;
+}
+
+int png_save(const char *filename, struct DisplaySurface *ds)
+{
+FILE *f;
+uint8_t *d, *d1;
+uint32_t v;
+int y, x;
+uint8_t r, g, b;
+// int ret;
+
+f = fopen(filename, "wb");
+if (!f)
+return -1;
+
+   /* initialize stuff */
+   png_structp png_ptr;
+png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+   if (!png_ptr)
+   return -1;
+
+   png_infop info_ptr;
+info_ptr = png_create_info_struct(png_ptr);
+if (!info_ptr)
+   return -1;
+
+   /* write header */
+if (setjmp(png_jmpbuf(

Re: [Qemu-devel] Boot failure with MS-Dos 6.22 (due to bad BIOS build?)

2012-03-18 Thread Kevin O'Connor
On Mon, Feb 27, 2012 at 04:25:09PM +0100, Jan Kiszka wrote:
> On 2012-02-27 10:51, Daniel P. Berrange wrote:
> > I'm seeing current QEMU GIT fail to boot MS-Dos 6.22 with the following
> > crash:
> > 
> > # qemu-system-x86_64 -fda ~/MS-DOS\ 6.22.img  -m 1 -curses
> > iPXE v1.0.0-591-g7aee315
> >  iPXE (http://ipxe.org) 00:03.0 C900 
> > PCI2.10 PnP PMM++ C900
> > 
> >  Booting from Floppy..
> > .qemu: fatal: Trying to execute code 
> > outside RAM or ROM at 0x0001000e
> > 
> > EAX= EBX= ECX=c934 EDX=0068
> > ESI=6801 EDI= EBP=002b ESP=fff5

I traced this down, and it appears to be a stack size issue.  It looks
like MSDOS calls "int 0x13" with 229 bytes of stack space during its
boot.  On my build gcc generates the handle_13() function with a
maximum of 140 bytes of stack space utilized (according to
tools/checkstack.py).  On your build, gcc created it with a maximum of
216 bytes.  The entry functions use 42 bytes of stack space.  Add it
up and you can see that the additional stack space that gcc used
caused %esp to wrap and the stack was corrupted.

I'm not sure how to best work around this.  One way is to sprinkle
"noinline" keywords through disk.c.  (It seems like gcc got in trouble
on your build by inlining many functions into disk_13().)  Another way
would be to jump into the extra stack (the disk code already uses its
own stack) earlier in the handle_13 code.

Also, can you see what happens if you change "--param
large-stack-frame=4" to "--param large-stack-frame=0" in the build?

-Kevin



Re: [Qemu-devel] [RFC][PATCH 08/14 v9] target-i386: Add API to write cpu status to core file

2012-03-18 Thread HATAYAMA Daisuke
From: Wen Congyang 
Subject: Re: [RFC][PATCH 08/14 v9] target-i386: Add API to write cpu status to 
core file
Date: Fri, 16 Mar 2012 14:50:06 +0800

> At 03/16/2012 09:48 AM, HATAYAMA Daisuke Wrote:
>> From: Wen Congyang 
>> Subject: [RFC][PATCH 08/14 v9] target-i386: Add API to write cpu status to 
>> core file
>> Date: Wed, 14 Mar 2012 10:09:26 +0800
>> 
>>> +memset(note, 0, note_size);
>>> +if (type == 0) {
>>> +note32 = note;
>>> +note32->n_namesz = cpu_to_le32(name_size);
>>> +note32->n_descsz = cpu_to_le32(descsz);
>>> +note32->n_type = 0;
>>> +} else {
>>> +note64 = note;
>>> +note64->n_namesz = cpu_to_le32(name_size);
>>> +note64->n_descsz = cpu_to_le32(descsz);
>>> +note64->n_type = 0;
>>> +}
>> 
>> Why not give new type for this note information an explicit name?
>> Like NT_QEMUCPUSTATE? There might be another type in the future. This
>> way there's also a merit that we can know all the existing notes
>> relevant to qemu dump by looking at the names in a header file.
> 
> Hmm, how to add a new type? Does someont manage this?
> 

Sorry. I overlooked this.

For the first question, just prepare a name like NT_QEMUCPUSTATE, and
put it in elf.h.

For the second question, we will use it, and someone that will finds
another information worth being note information in qemu would extends
note informaiton. At least, crash needs to use CPU state information,
and Jan says he wants to use this information in his gdb extension.

Also, you've introduced new name "QEMU". The same type on different
name has different meaning. So, in theory, you don't have to worry
about collision of the new type with something else; they belong to
differnet namespace.

But, in reality, looking at elfcore_grok_note() in gdb that reads note
information of corefile, it don't see "CORE" name explicitly. It
regards everything as the one in "CORE" name if it doesn't belong to
any namespace other than "CORE" name. But in "CORE" core namespace,
indexing starts from 1, NT_PRSTATUS; no type 0 in "CORE".

/* Values of note segment descriptor types for core files.  */

#define NT_PRSTATUS 1   /* Contains copy of prstatus struct */
#define NT_FPREGSET 2   /* Contains copy of fpregset struct */
#define NT_PRPSINFO 3   /* Contains copy of prpsinfo struct */
#define NT_TASKSTRUCT   4   /* Contains copy of task struct */
#define NT_AUXV 6   /* Contains copy of Elfxx_auxv_t */
#define NT_PRXFPREG 0x46e62b7f  /* Contains a user_xfpregs_struct; */

It appears to me that type 0 is reserved in order to avoid confilicts.
So, you don't have to fix gdb for now as long as you introduce
NT_QEMUCPUSTATE only and index it with type 0.

Considering name "QEMU", QEMU in NT_QEMUCPUSTATE might be redundant.

Thanks.
HATAYAMA, Daisuke





Re: [Qemu-devel] [PATCH] Remove PCI class code from virtio balloon device

2012-03-18 Thread David Gibson
On Sun, Mar 18, 2012 at 02:38:42PM +0200, Michael S. Tsirkin wrote:
> On Fri, Mar 16, 2012 at 12:03:08PM +1100, David Gibson wrote:
> > Currently the virtio balloon device, when using the virtio-pci interface
> > advertises itself with PCI class code MEMORY_RAM.  This is wrong; the
> > balloon is vaguely related to memory, but is nothing like a PCI memory
> > device in the meaning of the class code, and this code is not required or
> > suggested by the virtio PCI specification.
> > 
> > Worse, this patch causes problems on the pseries machine, because the
> > firmware, seeing this class code, advertises the device as memory in the
> > device tree, and then a guest kernel bug causes it to see this "memory"
> > before the real system memory, leading to a crash in early boot.
> > 
> > This patch fixes the problem by removing the bogus PCI class code on the
> > balloon device.
> > 
> > Cc: Michael S. Tsirkin 
> > Cc: Rusty Russell 
> > 
> > Signed-off-by: David Gibson 
> 
> Well, this gives the class a legacy value 00,
> and the PCI spec says we should not use this:
> 
> D.1.
> Base Class 00h
> This base class is defined to provide backward compatibility for devices
> that were built
> before the Class Code field was defined. No new devices should use this
> value and existing
> devices should switch to a more appropriate value if possible.
> For class codes with this base class value, there are two defined values
> for the remaining
> fields as shown in the table below. All other values are reserved.
> Base Class
> 00h
> Sub-Class
> Interface
> 00h
> 01h
> VGA-compatible device
> 00h
> 00h
> All currently implemented devices
> except VGA-compatible devices
> 
> You probably want this instead:
> 
> #define PCI_CLASS_OTHERS  0xff

Ah, thanks.  I had mistakenly assumed that 0 meant "no class
specified".  I'll respin changing to PCI_CLASS_OTHERS.

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson




Re: [Qemu-devel] [RFC][PATCH 11/14 v9] introduce a new monitor command 'dump' to dump guest's memory

2012-03-18 Thread Wen Congyang
At 03/15/2012 01:18 AM, Luiz Capitulino Wrote:
> On Wed, 14 Mar 2012 10:11:35 +0800
> Wen Congyang  wrote:
> 
>> The command's usage:
>>dump [-p] file
>> file should be start with "file:"(the file's path) or "fd:"(the fd's name).
>>
>> Note:
>>   1. If you want to use gdb to analyse the core, please specify -p option.
>>   2. This command doesn't support the fd that is is associated with a pipe,
>>  socket, or FIFO(lseek will fail with such fd).
>>
>> Signed-off-by: Wen Congyang 



>> +
>> +static DumpState *dump_init(bool paging, Error **errp)
>> +{
>> +CPUState *env;
>> +DumpState *s = dump_get_current();
>> +int ret;
>> +
>> +if (runstate_is_running()) {
>> +vm_stop(RUN_STATE_PAUSED);
>> +s->resume = true;
> 
> Hmm, you actually stop the VM. Seems obvious now, but when people talked about
> making this asynchronous I automatically assumed that what we didn't want was
> having the global mutex held for too much time (ie. while this command was
> running).

Yes, In the earlier version, I add a vm state change handler. If the vm is 
resumed
by the user, qemu dump will be auto cancelled.

> 
> The only disadvantage of having this as a synchronous command is that libvirt
> won't be able to cancel it and won't be able to run other commands in 
> parallel.
> Doesn't seem that serious to me.
> 
> Btw, RUN_STATE_PAUSED is not a good one. Doesn't matter that much, as this
> is unlikely to be visible, but you should use RUN_STATE_SAVE_VM or
> RUN_STATE_DEBUG.

OK, I will use RUN_STATE_SAVE_VM.

> 
>> +} else {



>> +ret = cpu_get_dump_info(&s->dump_info);
>> +if (ret < 0) {
>> +error_set(errp, QERR_UNSUPPORTED);
> 
> This will let the VM paused.

Hmm, in which function the vm is paused?

> 
>> +return NULL;



>> +ret = write(fd, buf, size);
>> +if (ret != size) {
>> +return -1;
>> +}
> 
> I think you should use send_all() instead of plain write().

OK, I will use qemu_write_full() you mentioned in anohter mail.

> 
>> +
>> +return 0;
>> +}



>> +
>> +s->f = fd_write_vmcore;
>> +s->cleanup = fd_cleanup;
>> +s->opaque = (void *)(intptr_t)fd;
> 
> Do we really need all these indirections?

At 02/15/2012 01:31 AM, Jan Kiszka Wrote:
> Is writing to file descriptor generic enough? What if we want to dump
> via QMP, letting the receiver side decide about where to write it?

So I use these indirections.

> 
>> +
>> +return s;
>> +}
>> +
>> +void qmp_dump(bool paging, const char *file, Error **errp)
>> +{
>> +const char *p;
>> +int fd = -1;
>> +DumpState *s;
>> +
>> +#if !defined(WIN32)
>> +if (strstart(file, "fd:", &p)) {
>> +fd = qemu_get_fd(p);
> 
> qemu_get_fd() won't be merged, you should use monitor_get_fd(cur_mon, p);

OK

> 
>> +if (fd == -1) {
>> +error_set(errp, QERR_FD_NOT_FOUND, p);
>> +return;
>> +}
>> +}
>> +#endif
>> +
>> +if  (strstart(file, "file:", &p)) {
>> +fd = open(p, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRUSR);
> 
> This is minor, but I'd use qemu_open() here.

OK

> 
>> +if (fd < 0) {



>> +
>> +qmp_dump(!!paging, file, &errp);
> 
> Why the double negation on 'paging'?

OK, I will remove double negation.

> 
>> +hmp_handle_error(mon, &errp);



>> +
>> +##
>> +# @dump
> 
> 'dump' is too generic, please call this dump-guest-memory-vmcore or something
> more descriptive.

Hmm, dump-guest-memory-vmcore is too long. What about dump-guest-memory or
dump-memory?

> 
>> +#
>> +# Dump guest's memory to vmcore.
>> +#
>> +# @paging: if true, do paging to get guest's memory mapping
>> +# @file: the filename or file descriptor of the vmcore.
> 
> 'file' is not a good name because it can also dump to an fd, maybe 'protocol'?

OK

Thanks for you reviewing
Wen Congyang



Re: [Qemu-devel] [PATCH] virtio-spec: split virtio-net device status filed into ro and rw byte

2012-03-18 Thread Jason Wang

On 03/18/2012 08:22 PM, Michael S. Tsirkin wrote:

On Fri, Mar 16, 2012 at 11:20:26PM +0800, Jason Wang wrote:

This patch splits the device status field of virtio-net into ro and rw
byte. This would simplify the implementation of both host and guest
and make the layout more clean. As VIRTIO_NET_S_ANNOUNCE is a rw bit,
it was moved to bit 8 (0x100).

btw. looks like there's no implementation that depends on
VIRTIO_NET_S_ANNOUNCE, so the move is safe.

Signed-off-by: Jason Wang

Hmm, I know I proposed this myself, and I thought it will
prevent problems if we will add more rw bits,
but I missed the following race:

host writes VIRTIO_NET_S_ANNOUNCE = 1, interrupt

guest reads VIRTIO_NET_S_ANNOUNCE = 1

host writes VIRTIO_NET_S_SOME_NEW_FIELD = 1, interrupt

guest writes VIRTIO_NET_S_ANNOUNCE = 0
VIRTIO_NET_S_SOME_NEW_FIELD is overwritten

guest reads VIRTIO_NET_S_SOME_NEW_FIELD = 0

How about making the new bit write 1 to clear?
If we do, we can keep it where it is currently ...



Didn't follow, do you mean to make VIRITO_NET_S_ANNOUNCE bit clear on 
read? Looks like this can prevent the race and keep what currently we have.





---
  virtio-0.9.4.lyx |   20 +++-
  1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/virtio-0.9.4.lyx b/virtio-0.9.4.lyx
index 6c7bab1..ef3951c 100644
--- a/virtio-0.9.4.lyx
+++ b/virtio-0.9.4.lyx
@@ -58,6 +58,7 @@
  \html_be_strict false
  \author -608949062 "Rusty Russell,,,"
  \author 1531152142 "pbonzini"
+\author 2090695081 "Jason"
  \end_header

  \begin_body
@@ -4012,8 +4013,19 @@ configuration
  layout Two configuration fields are currently defined.
   The mac address field always exists (though is only valid if VIRTIO_NET_F_MAC
   is set), and the status field only exists if VIRTIO_NET_F_STATUS is set.
+
+\change_inserted 2090695081 1331907586
+ The low byte of status field is read-only, guest write to this byte would
+ be ignored.
+ Currently only one bit is defined for this byte: VIRTIO_NET_S_LINK_UP.
+ The high byte of status field is read-writable.
+ Currently only one bit is defined for this byte: VIRTIO_NET_S_ANNOUNCE.
+
+\change_deleted 2090695081 1331907489
   Two bits are currently defined for the status field: VIRTIO_NET_S_LINK_UP
   and VIRTIO_NET_S_ANNOUNCE.
+
+\change_unchanged

  \begin_inset listings
  inline false
@@ -4026,7 +4038,13 @@ status open

  \begin_layout Plain Layout

-#define VIRTIO_NET_S_ANNOUNCE  2
+#define VIRTIO_NET_S_ANNOUNCE  
+\change_inserted 2090695081 1331907493
+0x100
+\change_deleted 2090695081 1331907491
+2
+\change_unchanged
+
  \end_layout

  \begin_layout Plain Layout

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/





Re: [Qemu-devel] [V5 PATCH 1/4] net: announce self after vm start

2012-03-18 Thread Jason Wang

On 03/17/2012 12:31 AM, Paolo Bonzini wrote:

Il 16/03/2012 16:23, Jason Wang ha scritto:

Or just a global need_announce instead of looking at the runstate.

Paolo


Then I think it's better for us introduce a parameter for vm_start()
like what we've done in V4.

But that didn't work because you ended up changing the "cont" semantics.

There are two possibilities.

1) Changing those is okay, in which case you only need to check more
runstates;

2) Changing those is not okay, in which case you need something like
this in qemu_announce_self()

void qemu_announce_self()
{
 if (!runstate_is_running()) {
 need_announce = true;
 return;
 }

 need_announce = false;
 ...
}

and then you just check need_announce in vm_start.  Nothing to change in
all the invocations of vm_start, you just mark that you need to do work
later.

Paolo


Right, I would replace the qemu_announce_self() with a "need_announce = 
true" in process_incoming_migration() and check it later in vm_start().


Thanks



Re: [Qemu-devel] [RESEND PATCH] ioapic: fix build with DEBUG_IOAPIC

2012-03-18 Thread Jason Wang

On 03/16/2012 06:32 PM, Andreas Färber wrote:

Am 16.03.2012 10:10, schrieb Jason Wang:

ioapic.c:198: error: format ‘%08x’ expects type ‘unsigned int’, but argument 3 
has type ‘uint64_t’

Signed-off-by: Jason Wang

PRIx64 is indeed needed here. However, this drops the 08 without mention
in the commit message - was it intended?


Not intended, my fault, thanks for pointing this.

Andreas


---
  hw/ioapic.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/ioapic.c b/hw/ioapic.c
index 3fee011..1ff31a1 100644
--- a/hw/ioapic.c
+++ b/hw/ioapic.c
@@ -195,7 +195,7 @@ ioapic_mem_write(void *opaque, target_phys_addr_t addr, 
uint64_t val,
  if (size != 4) {
  break;
  }
-DPRINTF("write: %08x = %08x\n", s->ioregsel, val);
+DPRINTF("write: %08x = %" PRIx64 "\n", s->ioregsel, val);
  switch (s->ioregsel) {
  case IOAPIC_REG_ID:
  s->id = (val>>  IOAPIC_ID_SHIFT)&  IOAPIC_ID_MASK;





[Qemu-devel] [REPOST PATCH] ioapic: fix build with DEBUG_IOAPIC

2012-03-18 Thread Jason Wang
ioapic.c:198: error: format ‘%08x’ expects type ‘unsigned int’, but argument 3 
has type ‘uint64_t’

Signed-off-by: Jason Wang 
---
 hw/ioapic.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/ioapic.c b/hw/ioapic.c
index 3fee011..e2e4796 100644
--- a/hw/ioapic.c
+++ b/hw/ioapic.c
@@ -195,7 +195,7 @@ ioapic_mem_write(void *opaque, target_phys_addr_t addr, 
uint64_t val,
 if (size != 4) {
 break;
 }
-DPRINTF("write: %08x = %08x\n", s->ioregsel, val);
+DPRINTF("write: %08x = %08" PRIx64 "\n", s->ioregsel, val);
 switch (s->ioregsel) {
 case IOAPIC_REG_ID:
 s->id = (val >> IOAPIC_ID_SHIFT) & IOAPIC_ID_MASK;




[Qemu-devel] [Bug 957622] Re: kvm -kernel with grub multiboot kernel dumps core or exits

2012-03-18 Thread Ubuntu Foundation's Bug Bot
** Tags added: patch

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

Title:
  kvm -kernel with grub multiboot kernel dumps core or exits

Status in QEMU:
  Confirmed
Status in “qemu-kvm” package in Ubuntu:
  In Progress

Bug description:
  I attempted to use kvm -kernel with a grub multiboot image,
  specifically grub-maverick-20100729.img at [1].  That file was built
  using [2]

  $ 
url="http://bazaar.launchpad.net/~ubuntu-on-ec2/vmbuilder/automated-ec2-builds/download/head:/grubmaverick20100729-20100729071944-bevge631maio9jpl-2/grub-maverick-20100729.img";
  $ wget $url -O grub-maverick-20100729.img
  $ qemu-kvm create -f qcow2 disk.img 1G
  $ kvm -curses -kernel grub-maverick-20100729.img -drive 
file=disk.img,if=virtio

  This process works fine on oneiric and you will see a curses
  interface, and some output of grub looking for a image to boot.

  On my laptop (with kvm support), I saw:

  $ kvm -curses -kernel grub-maverick-20100729.img -drive 
file=disk.img,if=virtio;
  fread() failed
  $ echo $?
  1

  On a kvm guest (via openstack instance), it crashed differently:
  $ kvm -curses -kernel grub-maverick-20100729.img -drive 
file=disk.img,if=virtio
  Could not access KVM kernel module: No such file or directory
  failed to initialize KVM: No such file or directory
  Back to tcg accelerator.

  GLib-ERROR **: /build/buildd/glib2.0-2.31.20/./glib/gmem.c:165: failed to 
allocate 4293918720 bytes
  Trace/breakpoint trap (core dumped)

  
  Just for a test, I tried loading kvm-amd, got nested kvm virtualization, but 
the instance fails the same way.

  
  --
  [1] 
http://bazaar.launchpad.net/~ubuntu-on-ec2/vmbuilder/automated-ec2-builds/files/head:/loaders/
  [2] 
http://bazaar.launchpad.net/~ubuntu-on-ec2/vmbuilder/automated-ec2-builds/view/head:/mk-image-mb-loader

  ProblemType: Bug
  DistroRelease: Ubuntu 12.04
  Package: kvm (not installed)
  ProcVersionSignature: User Name 3.2.0-18.29-virtual 3.2.9
  Uname: Linux 3.2.0-18-virtual x86_64
  ApportVersion: 1.94.1-0ubuntu2
  Architecture: amd64
  CurrentDmesg:
   [27230.320857] init: qemu-kvm pre-start process (8659) terminated with 
status 1
   [27230.361904] init: qemu-kvm post-stop process (8664) terminated with 
status 1
   [27249.426836] kvm[9021] trap int3 ip:7f44c2bbc13b sp:7fff447e1120 error:0
   [27263.380598] kvm[9283] trap int3 ip:7f3fba9f713b sp:7fff8b55d1a0 error:0
  Date: Sat Mar 17 01:48:13 2012
  Ec2AMI: ami-
  Ec2AMIManifest: FIXME
  Ec2AvailabilityZone: nova
  Ec2InstanceType: m1.small
  Ec2Kernel: unavailable
  Ec2Ramdisk: unavailable
  KvmCmdLine: Error: command ['ps', '-C', 'kvm', '-F'] failed with exit code 1: 
UIDPID  PPID  CSZ   RSS PSR STIME TTY  TIME CMD
  Lsusb:
   Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
   Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd
  MachineType: Bochs Bochs
  ProcEnviron:
   TERM=screen
   PATH=(custom, user)
   LANG=en_US.UTF-8
   SHELL=/bin/bash
  ProcKernelCmdLine: BOOT_IMAGE=/boot/vmlinuz-3.2.0-18-virtual 
root=LABEL=cloudimg-rootfs ro console=ttyS0
  ProcModules:
   acpiphp 24231 0 - Live 0x
   floppy 70365 0 - Live 0x
   psmouse 87603 0 - Live 0x
   serio_raw 13211 0 - Live 0x
   virtio_balloon 13108 0 - Live 0x
  SourcePackage: qemu-kvm
  UpgradeStatus: No upgrade log present (probably fresh install)
  dmi.bios.date: 01/01/2007
  dmi.bios.vendor: Bochs
  dmi.bios.version: Bochs
  dmi.chassis.type: 1
  dmi.chassis.vendor: Bochs
  dmi.modalias: 
dmi:bvnBochs:bvrBochs:bd01/01/2007:svnBochs:pnBochs:pvr:cvnBochs:ct1:cvr:
  dmi.product.name: Bochs
  dmi.sys.vendor: Bochs

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



[Qemu-devel] [Bug 957622] Re: kvm -kernel with grub multiboot kernel dumps core or exits

2012-03-18 Thread Serge Hallyn
Thanks, Scott.  I"ll wait a day or two to see if there are any upstream
comments, then apply.

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

Title:
  kvm -kernel with grub multiboot kernel dumps core or exits

Status in QEMU:
  Confirmed
Status in “qemu-kvm” package in Ubuntu:
  In Progress

Bug description:
  I attempted to use kvm -kernel with a grub multiboot image,
  specifically grub-maverick-20100729.img at [1].  That file was built
  using [2]

  $ 
url="http://bazaar.launchpad.net/~ubuntu-on-ec2/vmbuilder/automated-ec2-builds/download/head:/grubmaverick20100729-20100729071944-bevge631maio9jpl-2/grub-maverick-20100729.img";
  $ wget $url -O grub-maverick-20100729.img
  $ qemu-kvm create -f qcow2 disk.img 1G
  $ kvm -curses -kernel grub-maverick-20100729.img -drive 
file=disk.img,if=virtio

  This process works fine on oneiric and you will see a curses
  interface, and some output of grub looking for a image to boot.

  On my laptop (with kvm support), I saw:

  $ kvm -curses -kernel grub-maverick-20100729.img -drive 
file=disk.img,if=virtio;
  fread() failed
  $ echo $?
  1

  On a kvm guest (via openstack instance), it crashed differently:
  $ kvm -curses -kernel grub-maverick-20100729.img -drive 
file=disk.img,if=virtio
  Could not access KVM kernel module: No such file or directory
  failed to initialize KVM: No such file or directory
  Back to tcg accelerator.

  GLib-ERROR **: /build/buildd/glib2.0-2.31.20/./glib/gmem.c:165: failed to 
allocate 4293918720 bytes
  Trace/breakpoint trap (core dumped)

  
  Just for a test, I tried loading kvm-amd, got nested kvm virtualization, but 
the instance fails the same way.

  
  --
  [1] 
http://bazaar.launchpad.net/~ubuntu-on-ec2/vmbuilder/automated-ec2-builds/files/head:/loaders/
  [2] 
http://bazaar.launchpad.net/~ubuntu-on-ec2/vmbuilder/automated-ec2-builds/view/head:/mk-image-mb-loader

  ProblemType: Bug
  DistroRelease: Ubuntu 12.04
  Package: kvm (not installed)
  ProcVersionSignature: User Name 3.2.0-18.29-virtual 3.2.9
  Uname: Linux 3.2.0-18-virtual x86_64
  ApportVersion: 1.94.1-0ubuntu2
  Architecture: amd64
  CurrentDmesg:
   [27230.320857] init: qemu-kvm pre-start process (8659) terminated with 
status 1
   [27230.361904] init: qemu-kvm post-stop process (8664) terminated with 
status 1
   [27249.426836] kvm[9021] trap int3 ip:7f44c2bbc13b sp:7fff447e1120 error:0
   [27263.380598] kvm[9283] trap int3 ip:7f3fba9f713b sp:7fff8b55d1a0 error:0
  Date: Sat Mar 17 01:48:13 2012
  Ec2AMI: ami-
  Ec2AMIManifest: FIXME
  Ec2AvailabilityZone: nova
  Ec2InstanceType: m1.small
  Ec2Kernel: unavailable
  Ec2Ramdisk: unavailable
  KvmCmdLine: Error: command ['ps', '-C', 'kvm', '-F'] failed with exit code 1: 
UIDPID  PPID  CSZ   RSS PSR STIME TTY  TIME CMD
  Lsusb:
   Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
   Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd
  MachineType: Bochs Bochs
  ProcEnviron:
   TERM=screen
   PATH=(custom, user)
   LANG=en_US.UTF-8
   SHELL=/bin/bash
  ProcKernelCmdLine: BOOT_IMAGE=/boot/vmlinuz-3.2.0-18-virtual 
root=LABEL=cloudimg-rootfs ro console=ttyS0
  ProcModules:
   acpiphp 24231 0 - Live 0x
   floppy 70365 0 - Live 0x
   psmouse 87603 0 - Live 0x
   serio_raw 13211 0 - Live 0x
   virtio_balloon 13108 0 - Live 0x
  SourcePackage: qemu-kvm
  UpgradeStatus: No upgrade log present (probably fresh install)
  dmi.bios.date: 01/01/2007
  dmi.bios.vendor: Bochs
  dmi.bios.version: Bochs
  dmi.chassis.type: 1
  dmi.chassis.vendor: Bochs
  dmi.modalias: 
dmi:bvnBochs:bvrBochs:bd01/01/2007:svnBochs:pnBochs:pvr:cvnBochs:ct1:cvr:
  dmi.product.name: Bochs
  dmi.sys.vendor: Bochs

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



Re: [Qemu-devel] Breakage

2012-03-18 Thread Roy Tam
2012/3/19 Avi Kivity :
> On 03/18/2012 06:12 PM, malc wrote:
>> 97161e177b4ea2730dff13c4df01475762ab6048 broke booting of a DOS image
>> i've been using for years, the VM stalls at "Booting from hard disk"
>> BIOS message never making any progress.
>
> Can you post an image that exhibits the problem?
>
> Also, try the attached patch.
>

Confirmed fixed for Windows XP.
But I get "*** stack smashing detected ***:  terminated" and crash
when booting BeOS 5.

> --
> error compiling committee.c: too many arguments to function
>



Re: [Qemu-devel] [PATCH 5/5] memory: get rid of cpu_register_io_memory()

2012-03-18 Thread TeLeMan
On Fri, Mar 9, 2012 at 01:20, Avi Kivity  wrote:
> The return value of cpu_register_io_memory() is no longer used anywhere, so
> we can remove it and all associated data and code.
>
> Signed-off-by: Avi Kivity 
> ---
>  cpu-all.h       |    8 ---
>  exec-all.h      |    1 -
>  exec-obsolete.h |    3 --
>  exec.c          |   57 
> ---
>  memory.c        |    5 +---
>  5 files changed, 1 insertions(+), 73 deletions(-)
>
> diff --git a/cpu-all.h b/cpu-all.h
> index 80e6d42..b87f2ce 100644
> --- a/cpu-all.h
> +++ b/cpu-all.h
> @@ -498,14 +498,6 @@ extern RAMList ram_list;
>  extern const char *mem_path;
>  extern int mem_prealloc;
>
> -/* physical memory access */
> -
> -/* MMIO pages are identified by a combination of an IO device index and
> -   3 flags.  The ROMD code stores the page ram offset in iotlb entry,
> -   so only a limited number of ids are avaiable.  */
> -
> -#define IO_MEM_NB_ENTRIES  (1 << TARGET_PAGE_BITS)
> -
>  /* Flags stored in the low bits of the TLB virtual address.  These are
>    defined so that fast path ram access is all zeros.  */
>  /* Zero if TLB entry is valid.  */
> diff --git a/exec-all.h b/exec-all.h
> index 4e8c7f5..3ec60a2 100644
> --- a/exec-all.h
> +++ b/exec-all.h
> @@ -304,7 +304,6 @@ uint64_t io_mem_read(struct MemoryRegion *mr, 
> target_phys_addr_t addr,
>                      unsigned size);
>  void io_mem_write(struct MemoryRegion *mr, target_phys_addr_t addr,
>                   uint64_t value, unsigned size);
> -extern struct MemoryRegion *io_mem_region[IO_MEM_NB_ENTRIES];
>
>  void tlb_fill(CPUState *env1, target_ulong addr, int is_write, int mmu_idx,
>               void *retaddr);
> diff --git a/exec-obsolete.h b/exec-obsolete.h
> index 4dbe476..792c831 100644
> --- a/exec-obsolete.h
> +++ b/exec-obsolete.h
> @@ -32,9 +32,6 @@ void qemu_ram_free(ram_addr_t addr);
>  void qemu_ram_free_from_ptr(ram_addr_t addr);
>
>  struct MemoryRegion;
> -int cpu_register_io_memory(MemoryRegion *mr);
> -void cpu_unregister_io_memory(int table_address);
> -
>  struct MemoryRegionSection;
>  void cpu_register_physical_memory_log(struct MemoryRegionSection *section,
>                                       bool readonly);
> diff --git a/exec.c b/exec.c
> index 6e14048..0c86bce 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -214,9 +214,6 @@ struct PhysPageEntry {
>  static void io_mem_init(void);
>  static void memory_map_init(void);
>
> -/* io memory support */
> -MemoryRegion *io_mem_region[IO_MEM_NB_ENTRIES];
> -static char io_mem_used[IO_MEM_NB_ENTRIES];
>  static MemoryRegion io_mem_watch;
>  #endif
>
> @@ -3503,53 +3500,6 @@ static subpage_t *subpage_init(target_phys_addr_t base)
>     return mmio;
>  }
>
> -static int get_free_io_mem_idx(void)
> -{
> -    int i;
> -
> -    for (i = 0; i -        if (!io_mem_used[i]) {
> -            io_mem_used[i] = 1;
> -            return i;
> -        }
> -    fprintf(stderr, "RAN out out io_mem_idx, max %d !\n", IO_MEM_NB_ENTRIES);
> -    return -1;
> -}
> -
> -/* mem_read and mem_write are arrays of functions containing the
> -   function to access byte (index 0), word (index 1) and dword (index
> -   2). Functions can be omitted with a NULL function pointer.
> -   If io_index is non zero, the corresponding io zone is
> -   modified. If it is zero, a new io zone is allocated. The return
> -   value can be used with cpu_register_physical_memory(). (-1) is
> -   returned if error. */
> -static int cpu_register_io_memory_fixed(int io_index, MemoryRegion *mr)
> -{
> -    if (io_index <= 0) {
> -        io_index = get_free_io_mem_idx();
> -        if (io_index == -1)
> -            return io_index;
> -    } else {
> -        if (io_index >= IO_MEM_NB_ENTRIES)
> -            return -1;
> -    }
> -
> -    io_mem_region[io_index] = mr;
> -
> -    return io_index;
> -}
> -
> -int cpu_register_io_memory(MemoryRegion *mr)
> -{
> -    return cpu_register_io_memory_fixed(0, mr);
> -}
> -
> -void cpu_unregister_io_memory(int io_index)
> -{
> -    io_mem_region[io_index] = NULL;
> -    io_mem_used[io_index] = 0;
> -}
> -
>  static uint16_t dummy_section(MemoryRegion *mr)
>  {
>     MemoryRegionSection section = {
> @@ -3569,11 +3519,7 @@ MemoryRegion *iotlb_to_region(target_phys_addr_t index)
>
>  static void io_mem_init(void)
>  {
> -    int i;
> -
> -    /* Must be first: */
>     memory_region_init_io(&io_mem_ram, &error_mem_ops, NULL, "ram", 
> UINT64_MAX);
> -    assert(io_mem_ram.ram_addr == 0);
>     memory_region_init_io(&io_mem_rom, &rom_mem_ops, NULL, "rom", UINT64_MAX);
>     memory_region_init_io(&io_mem_unassigned, &unassigned_mem_ops, NULL,
>                           "unassigned", UINT64_MAX);
> @@ -3581,9 +3527,6 @@ static void io_mem_init(void)
>                           "notdirty", UINT64_MAX);
>     memory_region_init_io(&io_mem_subpage_ram, &subpage_ram_ops, NULL,
>                           "subpage-ram", UINT64_MAX);
> -    for (i=0; i<5; i++)
> -        io_mem_used[i] = 1;

[Qemu-devel] [PATCH] kvm: Fix dirty tracking with large kernel page size

2012-03-18 Thread David Gibson
If the kernel page size is larger than TARGET_PAGE_SIZE, which
happens for example on ppc64 with kernels compiled for 64K pages,
the dirty tracking doesn't work.

Cc: Avi Kivity 
Cc: Marcelo Tossatti 

Signed-off-by: Benjamin Herrenschmidt 
Signed-off-by: David Gibson 
---
 kvm-all.c |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index ba2cee1..47adc97 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -350,10 +350,11 @@ static int kvm_set_migration_log(int enable)
 static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section,
  unsigned long *bitmap)
 {
-unsigned int i, j;
+  unsigned int i, j;
 unsigned long page_number, c;
 target_phys_addr_t addr, addr1;
 unsigned int len = ((section->size / TARGET_PAGE_SIZE) + HOST_LONG_BITS - 
1) / HOST_LONG_BITS;
+unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE;
 
 /*
  * bitmap-traveling is faster than memory-traveling (for addr...)
@@ -365,10 +366,11 @@ static int 
kvm_get_dirty_pages_log_range(MemoryRegionSection *section,
 do {
 j = ffsl(c) - 1;
 c &= ~(1ul << j);
-page_number = i * HOST_LONG_BITS + j;
+page_number = (i * HOST_LONG_BITS + j) * hpratio;
 addr1 = page_number * TARGET_PAGE_SIZE;
 addr = section->offset_within_region + addr1;
-memory_region_set_dirty(section->mr, addr, TARGET_PAGE_SIZE);
+memory_region_set_dirty(section->mr, addr,
+TARGET_PAGE_SIZE * hpratio);
 } while (c != 0);
 }
 }
-- 
1.7.9.1




[Qemu-devel] [PATCH] pci: Factor out bounds checking on config space accesses

2012-03-18 Thread David Gibson
There are several paths into the code to emulate PCI config space accesses:
one for MMIO to a plain old PCI bridge one for MMIO to a PCIe bridge and
one for the pseries machine which provides para-virtualized access to PCI
config space.  Each of these functions does their own bounds checking
against the size of config space to check for addresses outside the
size of config space.  The pci_host_config_{read,write}_common() (sort
of) checks for partial overruns, that is where the address is within
the size of config space, but address + length is not, it takes a
limit parameter for this purpose.

As well as being a small code duplication, and it being weird to
separate the checks for partial and total overruns, this checking
currently has a few buglets:

* For non PCI-Express we assume that the size of config space is
  PCI_CONFIG_SPACE_SIZE.  That's true for everything we emulate
  now, but is not necessarily true (e.g. PCI-X devices can have
  extended config space)

* The limit parameter is not necessary, since the size of config
  space can be obtained using pci_config_size()

* Partial overruns could only occur with a misaligned access,
  which should have already been dealt with by this point

* Partial overruns are handled as a partial read or write, which
  is very unlikely behaviour for real hardware

* Furthermore, partial reads are 0x0 padded, whereas returning
  0xff for unimplemented addresses us much more common.

* The partial reads/writes only work correctly by assuming
  little-endian byte layout.  While that is always true for PCI
  config space, it's an awfully subtle thing to rely on without
  comment.

This patch, therefore, moves the bounds checking wholly into
pci_host_config_{read,write}_common().  No partial reads or writes are
performed, instead any out-of-bounds write is simply ignored and an
out-of-bounds read returns 0xff.

This simplifies all the callers, and makes the overall semantics saner
for edge cases.

Cc: Michael S. Tsirkin 

Signed-off-by: David Gibson 
---
 hw/pci_host.c  |   26 ++
 hw/pci_host.h  |4 ++--
 hw/pcie_host.c |   18 ++
 hw/spapr_pci.c |   27 ---
 4 files changed, 22 insertions(+), 53 deletions(-)

diff --git a/hw/pci_host.c b/hw/pci_host.c
index 44c6c20..829d797 100644
--- a/hw/pci_host.c
+++ b/hw/pci_host.c
@@ -48,48 +48,50 @@ static inline PCIDevice *pci_dev_find_by_addr(PCIBus *bus, 
uint32_t addr)
 }
 
 void pci_host_config_write_common(PCIDevice *pci_dev, uint32_t addr,
-  uint32_t limit, uint32_t val, uint32_t len)
+  uint32_t val, uint32_t len)
 {
 assert(len <= 4);
-pci_dev->config_write(pci_dev, addr, val, MIN(len, limit - addr));
+if ((addr + len) <= pci_config_size(pci_dev)) {
+pci_dev->config_write(pci_dev, addr, val, len);
+}
 }
 
 uint32_t pci_host_config_read_common(PCIDevice *pci_dev, uint32_t addr,
- uint32_t limit, uint32_t len)
+ uint32_t len)
 {
 assert(len <= 4);
-return pci_dev->config_read(pci_dev, addr, MIN(len, limit - addr));
+if ((addr + len) <= pci_config_size(pci_dev)) {
+return pci_dev->config_read(pci_dev, addr, len);
+} else {
+return ~0x0;
+}
 }
 
 void pci_data_write(PCIBus *s, uint32_t addr, uint32_t val, int len)
 {
 PCIDevice *pci_dev = pci_dev_find_by_addr(s, addr);
-uint32_t config_addr = addr & (PCI_CONFIG_SPACE_SIZE - 1);
 
 if (!pci_dev) {
 return;
 }
 
 PCI_DPRINTF("%s: %s: addr=%02" PRIx32 " val=%08" PRIx32 " len=%d\n",
-__func__, pci_dev->name, config_addr, val, len);
-pci_host_config_write_common(pci_dev, config_addr, PCI_CONFIG_SPACE_SIZE,
- val, len);
+__func__, pci_dev->name, addr, val, len);
+pci_host_config_write_common(pci_dev, addr, val, len);
 }
 
 uint32_t pci_data_read(PCIBus *s, uint32_t addr, int len)
 {
 PCIDevice *pci_dev = pci_dev_find_by_addr(s, addr);
-uint32_t config_addr = addr & (PCI_CONFIG_SPACE_SIZE - 1);
 uint32_t val;
 
 if (!pci_dev) {
 return ~0x0;
 }
 
-val = pci_host_config_read_common(pci_dev, config_addr,
-  PCI_CONFIG_SPACE_SIZE, len);
+val = pci_host_config_read_common(pci_dev, addr, len);
 PCI_DPRINTF("%s: %s: addr=%02"PRIx32" val=%08"PRIx32" len=%d\n",
-__func__, pci_dev->name, config_addr, val, len);
+__func__, pci_dev->name, addr, val, len);
 
 return val;
 }
diff --git a/hw/pci_host.h b/hw/pci_host.h
index 359e38f..4bb0838 100644
--- a/hw/pci_host.h
+++ b/hw/pci_host.h
@@ -42,9 +42,9 @@ struct PCIHostState {
 
 /* common internal helpers for PCI/PCIe hosts, cut off overflows */
 void pci_host_config_write_common(PCIDevice *pci_dev, uint32_t addr,

[Qemu-devel] [PATCH] Remove PCI class code from virtio balloon device

2012-03-18 Thread David Gibson
Currently the virtio balloon device, when using the virtio-pci interface
advertises itself with PCI class code MEMORY_RAM.  This is wrong; the
balloon is vaguely related to memory, but is nothing like a PCI memory
device in the meaning of the class code, and this code is not required or
suggested by the virtio PCI specification.

Worse, this patch causes problems on the pseries machine, because the
firmware, seeing this class code, advertises the device as memory in the
device tree, and then a guest kernel bug causes it to see this "memory"
before the real system memory, leading to a crash in early boot.

This patch fixes the problem by removing the bogus PCI class code on the
balloon device.

Cc: Michael S. Tsirkin 
Cc: Rusty Russell 

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

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index a0fb7c1..da8a382 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -919,7 +919,7 @@ static void virtio_balloon_class_init(ObjectClass *klass, 
void *data)
 k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
 k->device_id = PCI_DEVICE_ID_VIRTIO_BALLOON;
 k->revision = VIRTIO_PCI_ABI_VERSION;
-k->class_id = PCI_CLASS_MEMORY_RAM;
+k->class_id = PCI_CLASS_OTHERS;
 dc->reset = virtio_pci_reset;
 dc->props = virtio_balloon_properties;
 }
-- 
1.7.9.1




[Qemu-devel] [PATCH] .gitignore update

2012-03-18 Thread David Gibson
This adds a few previously missing generated files to .gitignore: the
qemu-bridge-helper binary, and more generated versions of the
linuxboot, multiboot and kvmvapic roms from pc-bios/optionrom.

Signed-off-by: David Gibson 
---
 .gitignore |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore
index 81b1510..9859c7d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -39,6 +39,7 @@ qemu-img-cmds.texi
 qemu-img-cmds.h
 qemu-io
 qemu-ga
+qemu-bridge-helper
 qemu-monitor.texi
 QMP/qmp-commands.txt
 test-coroutine
@@ -75,9 +76,14 @@ patches
 pc-bios/bios-pq/status
 pc-bios/vgabios-pq/status
 pc-bios/optionrom/linuxboot.bin
+pc-bios/optionrom/linuxboot.raw
+pc-bios/optionrom/linuxboot.img
 pc-bios/optionrom/multiboot.bin
 pc-bios/optionrom/multiboot.raw
+pc-bios/optionrom/multiboot.img
 pc-bios/optionrom/kvmvapic.bin
+pc-bios/optionrom/kvmvapic.raw
+pc-bios/optionrom/kvmvapic.img
 .stgit-*
 cscope.*
 tags
-- 
1.7.9.1