Re: [Qemu-devel] [PATCH][QEMU] vmxcap: Augment reported information

2013-02-13 Thread Gleb Natapov
On Wed, Feb 13, 2013 at 12:44:06PM +0100, Jan Kiszka wrote:
> Parse the Basic VMX Information MSR and add the bit for the new posted
> interrupts.
> 
> Signed-off-by: Jan Kiszka 
Applied, thanks.

> ---
>  scripts/kvm/vmxcap |   14 ++
>  1 files changed, 14 insertions(+), 0 deletions(-)
> 
> diff --git a/scripts/kvm/vmxcap b/scripts/kvm/vmxcap
> index 6363e73..a1a44a0 100755
> --- a/scripts/kvm/vmxcap
> +++ b/scripts/kvm/vmxcap
> @@ -96,6 +96,19 @@ class Misc(object):
>  print '  %-40s %s' % (self.bits[bits], fmt(v))
>  
>  controls = [
> +Misc(
> +name = 'Basic VMX Information',
> +bits = {
> +(0, 31): 'Revision',
> +(32,44): 'VMCS size',
> +48: 'VMCS restricted to 32 bit addresses',
> +49: 'Dual-monitor support',
> +(50, 53): 'VMCS memory type',
> +54: 'INS/OUTS instruction information',
> +55: 'IA32_VMX_TRUE_*_CTLS support',
> +},
> +msr = MSR_IA32_VMX_BASIC,
> +),
>  Control(
>  name = 'pin-based controls',
>  bits = {
> @@ -103,6 +116,7 @@ controls = [
>  3: 'NMI exiting',
>  5: 'Virtual NMIs',
>  6: 'Activate VMX-preemption timer',
> +7: 'Process posted interrupts',
>  },
>  cap_msr = MSR_IA32_VMX_PINBASED_CTLS,
>  true_cap_msr = MSR_IA32_VMX_TRUE_PINBASED_CTLS,
> -- 
> 1.7.3.4

--
Gleb.



Re: [Qemu-devel] [PATCH][QEMU] vmxcap: Open MSR file in unbuffered mode

2013-02-13 Thread Gleb Natapov
On Wed, Feb 13, 2013 at 12:43:10PM +0100, Jan Kiszka wrote:
> Python may otherwise decide to to read larger chunks, applying the seek
> only on the software buffer. This will return results from the wrong
> MSRs.
> 
> Signed-off-by: Jan Kiszka 
Applied, thanks.

> ---
>  scripts/kvm/vmxcap |4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/kvm/vmxcap b/scripts/kvm/vmxcap
> index 0b23f77..6363e73 100755
> --- a/scripts/kvm/vmxcap
> +++ b/scripts/kvm/vmxcap
> @@ -27,9 +27,9 @@ MSR_IA32_VMX_VMFUNC = 0x491
>  class msr(object):
>  def __init__(self):
>  try:
> -self.f = file('/dev/cpu/0/msr')
> +self.f = open('/dev/cpu/0/msr', 'r', 0)
>  except:
> -self.f = file('/dev/msr0')
> +self.f = open('/dev/msr0', 'r', 0)
>  def read(self, index, default = None):
>  import struct
>  self.f.seek(index)
> -- 
> 1.7.3.4

--
Gleb.



[Qemu-devel] [PATCH] hw/mc146818rtc.c: Fix reading and writing of time registers

2013-02-13 Thread Antoine Mathys
This patch consolidates the bit twidling involved in reading and
writing the time registers to four functions that are used consistently.

This also has the effect of fixing bug 1090558.

Signed-off-by: Antoine Mathys 
---
 hw/mc146818rtc.c |  163 +-
 1 file changed, 99 insertions(+), 64 deletions(-)

diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 2fb11f6..646cbd0 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -86,8 +86,14 @@ typedef struct RTCState {
 
 static void rtc_set_time(RTCState *s);
 static void rtc_update_time(RTCState *s);
+
+/* data encoding / decoding */
+static inline uint8_t rtc_encode(RTCState *s, uint8_t a);
+static inline int rtc_decode(RTCState *s, uint8_t a);
+static inline uint8_t rtc_hour_encode(RTCState *s, uint8_t hour);
+static inline int rtc_hour_decode(RTCState *s, uint8_t a);
+
 static void rtc_set_cmos(RTCState *s, const struct tm *tm);
-static inline int rtc_from_bcd(RTCState *s, int a);
 static uint64_t get_next_alarm(RTCState *s);
 
 static inline bool rtc_running(RTCState *s)
@@ -254,17 +260,84 @@ static void check_update_timer(RTCState *s)
 }
 }
 
-static inline uint8_t convert_hour(RTCState *s, uint8_t hour)
+/* data encoding / decoding */
+
+static inline uint8_t rtc_encode(RTCState *s, uint8_t a)
+{
+if (s->cmos_data[RTC_REG_B] & REG_B_DM) {
+return a;
+} else {
+return to_bcd(a);
+}
+}
+
+static inline int rtc_decode(RTCState *s, uint8_t a)
+{
+if ((a & 0xc0) == 0xc0) {
+return -1;
+}
+if (s->cmos_data[RTC_REG_B] & REG_B_DM) {
+return a;
+} else {
+return from_bcd(a);
+}
+}
+
+/*
+  Note: The next two functions implement the following mapping between
+  the 12 hour and 24 hour formats:
+
+  0<->12 AM
+  1-11 <->1 - 11 AM
+  12   <->12 PM
+  13-23<->1 - 11 PM
+*/
+
+static inline uint8_t rtc_hour_encode(RTCState *s, uint8_t hour)
+{
+uint8_t tmp;
+
+if (s->cmos_data[RTC_REG_B] & REG_B_24H) {
+/* 24 hour format */
+tmp = rtc_encode(s, hour);
+} else {
+/* 12 hour format */
+uint8_t h = (hour % 12) ? (hour % 12) : 12;
+tmp = rtc_encode(s, h);
+if (hour >= 12) {
+tmp |= 0x80;
+}
+}
+return tmp;
+}
+
+static inline int rtc_hour_decode(RTCState *s, uint8_t a)
 {
-if (!(s->cmos_data[RTC_REG_B] & REG_B_24H)) {
+uint8_t hour;
+
+/* Note: in 12 hour mode we clear bit 7 before calling
+   rtc_decode(), hence we cannot rely on the later to check the
+   don't care condition. While we could skip this check in 24 hour
+   mode it is simpler to do it in any case. */
+if ((a & 0xc0) == 0xc0) {
+return -1;
+}
+
+if (s->cmos_data[RTC_REG_B] & REG_B_24H) {
+/* 24 hour format */
+hour = rtc_decode(s, a);
+} else {
+/* 12 hour format */
+hour = rtc_decode(s, a & 0x7f);
 hour %= 12;
-if (s->cmos_data[RTC_HOURS] & 0x80) {
+if (a & 0x80) {
 hour += 12;
 }
 }
 return hour;
 }
 
+
 static uint64_t get_next_alarm(RTCState *s)
 {
 int32_t alarm_sec, alarm_min, alarm_hour, cur_hour, cur_min, cur_sec;
@@ -272,15 +345,13 @@ static uint64_t get_next_alarm(RTCState *s)
 
 rtc_update_time(s);
 
-alarm_sec = rtc_from_bcd(s, s->cmos_data[RTC_SECONDS_ALARM]);
-alarm_min = rtc_from_bcd(s, s->cmos_data[RTC_MINUTES_ALARM]);
-alarm_hour = rtc_from_bcd(s, s->cmos_data[RTC_HOURS_ALARM]);
-alarm_hour = alarm_hour == -1 ? -1 : convert_hour(s, alarm_hour);
+alarm_sec = rtc_decode(s, s->cmos_data[RTC_SECONDS_ALARM]);
+alarm_min = rtc_decode(s, s->cmos_data[RTC_MINUTES_ALARM]);
+alarm_hour = rtc_hour_decode(s, s->cmos_data[RTC_HOURS_ALARM]);
 
-cur_sec = rtc_from_bcd(s, s->cmos_data[RTC_SECONDS]);
-cur_min = rtc_from_bcd(s, s->cmos_data[RTC_MINUTES]);
-cur_hour = rtc_from_bcd(s, s->cmos_data[RTC_HOURS]);
-cur_hour = convert_hour(s, cur_hour);
+cur_sec = rtc_decode(s, s->cmos_data[RTC_SECONDS]);
+cur_min = rtc_decode(s, s->cmos_data[RTC_MINUTES]);
+cur_hour = rtc_hour_decode(s, s->cmos_data[RTC_HOURS]);
 
 if (alarm_hour == -1) {
 alarm_hour = cur_hour;
@@ -486,44 +557,17 @@ static void cmos_ioport_write(void *opaque, hwaddr addr,
 }
 }
 
-static inline int rtc_to_bcd(RTCState *s, int a)
-{
-if (s->cmos_data[RTC_REG_B] & REG_B_DM) {
-return a;
-} else {
-return ((a / 10) << 4) | (a % 10);
-}
-}
-
-static inline int rtc_from_bcd(RTCState *s, int a)
-{
-if ((a & 0xc0) == 0xc0) {
-return -1;
-}
-if (s->cmos_data[RTC_REG_B] & REG_B_DM) {
-return a;
-} else {
-return ((a >> 4) * 10) + (a & 0x0f);
-}
-}
-
 static void rtc_get_time(RTCState *s, struct tm *tm)
 {
-tm->tm_sec = rtc_from_bcd(s, s->cmos_data[RTC_SECONDS]);
-tm->tm_min = rtc_from_bcd(s, s->cmos_data[RTC

[Qemu-devel] [RFC PATCH 09/10] QMP/qemu-ga-client: make timeout longer for guest-fsfreeze-freeze command

2013-02-13 Thread Tomoki Sekiyama
guest-fsfreeze-freeze command can take longer than 3 seconds when heavy
disk I/O is running. To avoid unexpected timeout, this changes the timeout
to 30 seconds.

Signed-off-by: Tomoki Sekiyama 
---
 QMP/qemu-ga-client |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/QMP/qemu-ga-client b/QMP/qemu-ga-client
index 46676c3..1f7011a 100755
--- a/QMP/qemu-ga-client
+++ b/QMP/qemu-ga-client
@@ -267,7 +267,9 @@ def main(address, cmd, args):
 print('Hint: qemu is not running?')
 sys.exit(1)
 
-if cmd != 'ping':
+if cmd == 'fsfreeze' and args[0] == 'freeze':
+client.sync(30)
+elif cmd != 'ping':
 client.sync()
 
 globals()['_cmd_' + cmd](client, args)




Re: [Qemu-devel] kvm segfaulting

2013-02-13 Thread Stefan Priebe - Profihost AG
Hi,

no VM crashed this morning.

Stefan

Am 13.02.2013 16:24, schrieb Paolo Bonzini:
> Il 13/02/2013 15:30, Stefan Priebe - Profihost AG ha scritto:
>> I added this:
>> -trace events=/tmp/events,file=/root/qemu.123.trace
>>
>> and put the events in the events file as i couldn't handle \n in my app
>> starting the kvm process. But even when doing an fstrim the trace file
>> stays at 24 bytes - is this correct?
> 
> Right... it would eventually flush, but not if qemu-kvm crash.
> 
> Answering your other question, the patch subsumes the other.  But if the
> provisioning mode is writesame_16, this hunk alone will most likely fix
> the crash:
> 
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index d411586..4a0673c 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -178,6 +178,9 @@ static void scsi_aio_complete(void *opaque, int ret)
>  assert(r->req.aiocb != NULL);
>  r->req.aiocb = NULL;
>  bdrv_acct_done(s->qdev.conf.bs, &r->acct);
> +if (r->req.io_canceled) {
> +goto done;
> +}
> 
>  if (ret < 0) {
>  if (scsi_handle_rw_error(r, -ret)) {
> 
> Paolo
> 



[Qemu-devel] [RFC ppc-next PATCH 5/6] kvm: export result of irqchip config check

2013-02-13 Thread Scott Wood
This allows platform code to register in-kernel irqchips that
don't use the legacy KVM_CAP_IRQCHIP/KVM_CREATE_IRQCHIP interface.

Signed-off-by: Scott Wood 
---
 include/sysemu/kvm.h |   10 ++
 kvm-all.c|   11 +--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index f2d97b5..b9a8701 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -45,6 +45,7 @@ extern bool kvm_async_interrupts_allowed;
 extern bool kvm_irqfds_allowed;
 extern bool kvm_msi_via_irqfd_allowed;
 extern bool kvm_gsi_routing_allowed;
+extern bool kvm_irqchip_wanted;
 
 #if defined CONFIG_KVM || !defined NEED_CPU_H
 #define kvm_enabled()   (kvm_allowed)
@@ -97,6 +98,14 @@ extern bool kvm_gsi_routing_allowed;
  */
 #define kvm_gsi_routing_enabled() (kvm_gsi_routing_allowed)
 
+/**
+ * kvm_irqchip_wanted
+ *
+ * Returns: true if the user requested that an in-kernel IRQ chip be
+ * used, regardless of whether support has been detected.
+ */
+#define kvm_irqchip_wanted() (kvm_irqchip_wanted)
+
 #else
 #define kvm_enabled()   (0)
 #define kvm_irqchip_in_kernel() (false)
@@ -104,6 +113,7 @@ extern bool kvm_gsi_routing_allowed;
 #define kvm_irqfds_enabled() (false)
 #define kvm_msi_via_irqfd_enabled() (false)
 #define kvm_gsi_routing_allowed() (false)
+#define kvm_irqchip_wanted() (false)
 #endif
 
 struct kvm_run;
diff --git a/kvm-all.c b/kvm-all.c
index 04ec2d5..13a628d 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -109,6 +109,7 @@ bool kvm_async_interrupts_allowed;
 bool kvm_irqfds_allowed;
 bool kvm_msi_via_irqfd_allowed;
 bool kvm_gsi_routing_allowed;
+bool kvm_irqchip_wanted;
 
 static const KVMCapabilityInfo kvm_required_capabilites[] = {
 KVM_CAP_INFO(USER_MEMORY),
@@ -1205,8 +1206,14 @@ static int kvm_irqchip_create(KVMState *s)
 
 if (QTAILQ_EMPTY(&list->head) ||
 !qemu_opt_get_bool(QTAILQ_FIRST(&list->head),
-   "kernel_irqchip", true) ||
-!kvm_check_extension(s, KVM_CAP_IRQCHIP)) {
+   "kernel_irqchip", true)) {
+return 0;
+}
+
+kvm_irqchip_wanted = true;
+
+/* Platform code may have a different way of enabling an IRQ chip */
+if (!kvm_check_extension(s, KVM_CAP_IRQCHIP)) {
 return 0;
 }
 
-- 
1.7.9.5





[Qemu-devel] [RFC PATCH 10/10] QMP/qmp.py: set locale for exceptions to display non-ascii messages correctly

2013-02-13 Thread Tomoki Sekiyama
qemu-ga in Windows might return error message with multibyte characters
when the guest OS language is set to other than English. To display such
messages correctly, this decodes the message based on locale settings.

Signed-off-by: Tomoki Sekiyama 
---
 QMP/qmp.py |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/QMP/qmp.py b/QMP/qmp.py
index c551df1..ee21819 100644
--- a/QMP/qmp.py
+++ b/QMP/qmp.py
@@ -11,6 +11,7 @@
 import json
 import errno
 import socket
+import locale
 
 class QMPError(Exception):
 pass
@@ -133,7 +134,8 @@ class QEMUMonitorProtocol:
 def command(self, cmd, **kwds):
 ret = self.cmd(cmd, kwds)
 if ret.has_key('error'):
-raise Exception(ret['error']['desc'])
+enc = locale.getpreferredencoding()
+raise Exception(ret['error']['desc'].encode(enc))
 return ret['return']
 
 def pull_event(self, wait=False):




[Qemu-devel] [RFC ppc-next PATCH 3/6] memory: add memory_region_to_address()

2013-02-13 Thread Scott Wood
This is useful for when a user of the memory region API needs to
communicate the absolute bus address to something outside QEMU
(in particular, KVM).

Signed-off-by: Scott Wood 
---
 include/exec/memory.h |9 +
 memory.c  |   38 ++
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 2322732..b800391 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -892,6 +892,15 @@ void *address_space_map(AddressSpace *as, hwaddr addr,
 void address_space_unmap(AddressSpace *as, void *buffer, hwaddr len,
  int is_write, hwaddr access_len);
 
+/* memory_region_to_address: Find the full address of the start of the
+ *  given #MemoryRegion, ignoring aliases.  There is no guarantee
+ *  that the #MemoryRegion is actually visible at this address, if
+ *  there are overlapping regions.
+ *
+ * @mr: #MemoryRegion being queried
+ * @asp: if non-NULL, returns the #AddressSpace @mr is mapped in, if any
+ */
+hwaddr memory_region_to_address(MemoryRegion *mr, AddressSpace **asp);
 
 #endif
 
diff --git a/memory.c b/memory.c
index cd7d5e0..0099f12 100644
--- a/memory.c
+++ b/memory.c
@@ -453,21 +453,51 @@ const IORangeOps memory_region_iorange_ops = {
 .destructor = memory_region_iorange_destructor,
 };
 
-static AddressSpace *memory_region_to_address_space(MemoryRegion *mr)
+static AddressSpace *memory_region_root_to_address_space(MemoryRegion *mr)
 {
 AddressSpace *as;
 
-while (mr->parent) {
-mr = mr->parent;
-}
 QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) {
 if (mr == as->root) {
 return as;
 }
 }
+
+return NULL;
+}
+
+static AddressSpace *memory_region_to_address_space(MemoryRegion *mr)
+{
+AddressSpace *as;
+
+while (mr->parent) {
+mr = mr->parent;
+}
+
+as = memory_region_root_to_address_space(mr);
+if (as) {
+return as;
+}
+
 abort();
 }
 
+hwaddr memory_region_to_address(MemoryRegion *mr, AddressSpace **asp)
+{
+hwaddr addr = mr->addr;
+
+while (mr->parent) {
+mr = mr->parent;
+addr += mr->addr;
+}
+
+if (asp) {
+*asp = memory_region_root_to_address_space(mr);
+}
+
+return addr;
+}
+
 /* Render a memory region into the global view.  Ranges in @view obscure
  * ranges in @mr.
  */
-- 
1.7.9.5





[Qemu-devel] [RFC PATCH 03/10] qemu-ga: Add an configure option to specify path to Windows VSS SDK

2013-02-13 Thread Tomoki Sekiyama
To enable VSS support in qemu-ga for Windows, header files included in
VSS SDK is required.
The VSS support is enabled when the option like below:
  ./configure --with-vss-sdk="/pass/to/VSS SDK"

VSS SDK is available from:
  http://www.microsoft.com/en-us/download/details.aspx?id=23490

To cross-compilie using mingw32 for Linux, you need to setup the SDK on
Windows environments to extract headers. You can also use wine to run the
setup of SDK on Linux etc.

Signed-off-by: Tomoki Sekiyama 
---
 .gitignore |1 +
 Makefile   |1 +
 configure  |   41 +
 3 files changed, 43 insertions(+)

diff --git a/.gitignore b/.gitignore
index 53fe9c3..3f450e8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -77,6 +77,7 @@ fsdev/virtfs-proxy-helper.pod
 *.la
 *.pc
 .libs
+.sdk
 *.swp
 *.orig
 .pc
diff --git a/Makefile b/Makefile
index 0d9099a..fab664f 100644
--- a/Makefile
+++ b/Makefile
@@ -252,6 +252,7 @@ distclean: clean
for d in $(TARGET_DIRS); do \
rm -rf $$d || exit 1 ; \
 done
+   rm -Rf .sdk
if test -f pixman/config.log; then make -C pixman distclean; fi
 
 KEYMAPS=da en-gb  et  fr fr-ch  is  lt  modifiers  no  pt-br  sv \
diff --git a/configure b/configure
index e279263..da49c52 100755
--- a/configure
+++ b/configure
@@ -220,6 +220,8 @@ usb_redir=""
 opengl=""
 zlib="yes"
 guest_agent="yes"
+guest_agent_with_vss="no"
+vss_win32_sdk=""
 want_tools="yes"
 libiscsi=""
 coroutine=""
@@ -884,6 +886,8 @@ for opt do
   ;;
   --disable-guest-agent) guest_agent="no"
   ;;
+  --with-vss-sdk=*) vss_win32_sdk="$optarg"
+  ;;
   --enable-tools) want_tools="yes"
   ;;
   --disable-tools) want_tools="no"
@@ -1142,6 +1146,7 @@ echo "  --disable-usb-redir  disable usb network 
redirection support"
 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 "  --with-vss-sdk=SDK-path  enable Windows VSS support in QEMU Guest 
Agent"
 echo "  --disable-seccompdisable seccomp support"
 echo "  --enable-seccomp enables seccomp support"
 echo "  --with-coroutine=BACKEND coroutine backend. Supported options:"
@@ -2897,6 +2902,38 @@ if test "$usb_redir" != "no" ; then
 fi
 
 ##
+# check if we have VSS SDK headers for win
+
+if test "$mingw32" = "yes" -a "$guest_agent" = "yes" ; then
+  case "$vss_win32_sdk" in
+"")   vss_win32_include="" ;;
+*\ *) # The SDK is installed in "Program Files" by default, but we cannot
+  # handle path with spaces. So we copy the headers into ".sdk/sdk".
+  vss_win32_include="-I$source_path/.sdk/vss"
+  symlink "$vss_win32_sdk/inc" "$source_path/.sdk/vss/inc"
+ ;;
+*)vss_win32_include="-I$vss_win32_sdk"
+  esac
+  cat > $TMPC << EOF
+#define __MIDL_user_allocate_free_DEFINED__
+#include 
+int main(void) { return VSS_CTX_BACKUP; }
+EOF
+  if compile_prog "$vss_win32_include" "" ; then
+guest_agent_with_vss="yes"
+QEMU_CFLAGS="$QEMU_CFLAGS $vss_win32_include"
+libs_qga="-lole32 -loleaut32 -lshlwapi -luuid -lstdc++ 
-Wl,--enable-stdcall-fixup $libs_qga"
+  else
+if test "$vss_win32_sdk" != "" ; then
+  echo "ERROR: Please download and install Microsoft VSS SDK from"
+  echo "ERROR: 
http://www.microsoft.com/en-us/download/details.aspx?id=23490";
+  feature_not_found "VSS support"
+fi
+guest_agent_with_vss="no"
+  fi
+fi
+
+##
 
 ##
 # check if we have fdatasync
@@ -3343,6 +3380,7 @@ echo "usb net redir $usb_redir"
 echo "OpenGL support$opengl"
 echo "libiscsi support  $libiscsi"
 echo "build guest agent $guest_agent"
+echo "QGA VSS support   $guest_agent_with_vss"
 echo "seccomp support   $seccomp"
 echo "coroutine backend $coroutine_backend"
 echo "GlusterFS support $glusterfs"
@@ -3404,6 +3442,9 @@ if test "$mingw32" = "yes" ; then
   version_micro=0
   echo 
"CONFIG_FILEVERSION=$version_major,$version_minor,$version_subminor,$version_micro"
 >> $config_host_mak
   echo 
"CONFIG_PRODUCTVERSION=$version_major,$version_minor,$version_subminor,$version_micro"
 >> $config_host_mak
+  if test "$guest_agent_with_vss" = "yes" ; then
+echo "CONFIG_QGA_VSS=y" >> $config_host_mak
+  fi
 else
   echo "CONFIG_POSIX=y" >> $config_host_mak
 fi




[Qemu-devel] [RFC ppc-next PATCH 2/6] kvm: hw/kvm is not x86-specific

2013-02-13 Thread Scott Wood
Signed-off-by: Scott Wood 
---
 hw/Makefile.objs  |1 +
 hw/i386/Makefile.objs |1 -
 hw/kvm/Makefile.objs  |2 +-
 3 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index 447e32a..46bc395 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -216,4 +216,5 @@ obj-$(CONFIG_LINUX) += vfio_pci.o
 endif
 
 $(obj)/baum.o: QEMU_CFLAGS += $(SDL_CFLAGS) 
+obj-$(CONFIG_KVM) += kvm/
 endif
diff --git a/hw/i386/Makefile.objs b/hw/i386/Makefile.objs
index 025803a..370f799 100644
--- a/hw/i386/Makefile.objs
+++ b/hw/i386/Makefile.objs
@@ -10,7 +10,6 @@ obj-y += lpc_ich9.o q35.o pc_q35.o
 obj-$(CONFIG_XEN) += xen_platform.o xen_apic.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen-host-pci-device.o
 obj-$(CONFIG_XEN_PCI_PASSTHROUGH) += xen_pt.o xen_pt_config_init.o xen_pt_msi.o
-obj-y += kvm/
 obj-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
 obj-y += pc-testdev.o
 
diff --git a/hw/kvm/Makefile.objs b/hw/kvm/Makefile.objs
index f620d7f..6ccb6ed 100644
--- a/hw/kvm/Makefile.objs
+++ b/hw/kvm/Makefile.objs
@@ -1 +1 @@
-obj-$(CONFIG_KVM) += clock.o apic.o i8259.o ioapic.o i8254.o pci-assign.o
+obj-$(TARGET_I386) += clock.o apic.o i8259.o ioapic.o i8254.o pci-assign.o
-- 
1.7.9.5





[Qemu-devel] [RFC PATCH 01/10] configure: Support configuring c++ compiler

2013-02-13 Thread Tomoki Sekiyama
Add configuration for c++ compiler (${corss_prefix}g++ as default) in
configure and Makefiles.

Currently, usage of c++ language is only for access to Windows VSS
using COM+ services in qemu-guest-agent for Windows.

Signed-off-by: Tomoki Sekiyama 
---
 configure |6 ++
 rules.mak |7 +++
 2 files changed, 13 insertions(+)

diff --git a/configure b/configure
index 0657b1a..e279263 100755
--- a/configure
+++ b/configure
@@ -265,6 +265,7 @@ else
   cc="${CC-${cross_prefix}gcc}"
 fi
 
+cxx="${CXX-${cross_prefix}g++}"
 ar="${AR-${cross_prefix}ar}"
 as="${AS-${cross_prefix}as}"
 cpp="${CPP-$cc -E}"
@@ -598,6 +599,8 @@ for opt do
   ;;
   --host-cc=*) host_cc="$optarg"
   ;;
+  --cxx=*) cxx="$optarg"
+  ;;
   --objcc=*) objcc="$optarg"
   ;;
   --make=*) make="$optarg"
@@ -1023,6 +1026,7 @@ echo "  --cross-prefix=PREFIXuse PREFIX for compile 
tools [$cross_prefix]"
 echo "  --cc=CC  use C compiler CC [$cc]"
 echo "  --host-cc=CC use C compiler CC [$host_cc] for code run at"
 echo "   build time"
+echo "  --cxx=CXXuse C++ compiler CXX [$cxx]"
 echo "  --objcc=OBJCCuse Objective-C compiler OBJCC [$objcc]"
 echo "  --extra-cflags=CFLAGSappend extra C compiler flags QEMU_CFLAGS"
 echo "  --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS"
@@ -3260,6 +3264,7 @@ fi
 echo "Source path   $source_path"
 echo "C compiler$cc"
 echo "Host C compiler   $host_cc"
+echo "C++ compiler  $cxx"
 echo "Objective-C compiler $objcc"
 echo "CFLAGS$CFLAGS"
 echo "QEMU_CFLAGS   $QEMU_CFLAGS"
@@ -3760,6 +3765,7 @@ echo "PYTHON=$python" >> $config_host_mak
 echo "CC=$cc" >> $config_host_mak
 echo "CC_I386=$cc_i386" >> $config_host_mak
 echo "HOST_CC=$host_cc" >> $config_host_mak
+echo "CXX=$cxx" >> $config_host_mak
 echo "OBJCC=$objcc" >> $config_host_mak
 echo "AR=$ar" >> $config_host_mak
 echo "AS=$as" >> $config_host_mak
diff --git a/rules.mak b/rules.mak
index edc2552..f468f3f 100644
--- a/rules.mak
+++ b/rules.mak
@@ -8,9 +8,13 @@ MAKEFLAGS += -rR
 %.d:
 %.h:
 %.c:
+%.cpp:
 %.m:
 %.mak:
 
+# Flags for C++ compilation
+QEMU_CXXFLAGS = -D__STDC_LIMIT_MACROS $(filter-out -Wstrict-prototypes 
-Wmissing-prototypes -Wnested-externs -Wold-style-declaration 
-Wold-style-definition -Wredundant-decls, $(QEMU_CFLAGS))
+
 # Flags for dependency generation
 QEMU_DGFLAGS += -MMD -MP -MT $@ -MF $(*D)/$(*F).d
 
@@ -45,6 +49,9 @@ endif
 %.o: %.asm
$(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<,"  AS
$(TARGET_DIR)$@")
 
+%.o: %.cpp
+   $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) 
$(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<,"  CXX   $(TARGET_DIR)$@")
+
 %.o: %.m
$(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) 
$(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<,"  OBJC  $(TARGET_DIR)$@")
 




[Qemu-devel] [RFC ppc-next PATCH 0/6] kvm/openpic: in-kernel irqchip

2013-02-13 Thread Scott Wood
This allows QEMU to use the in-kernel KVM MPIC on some PPC platforms.

Scott Wood (6):
  kvm: update linux-headers
  kvm: hw/kvm is not x86-specific
  memory: add memory_region_to_address()
  openpic: factor out some common defines into openpic.h
  kvm: export result of irqchip config check
  kvm/openpic: in-kernel mpic support

 hw/Makefile.objs  |1 +
 hw/i386/Makefile.objs |1 -
 hw/kvm/Makefile.objs  |3 +-
 hw/kvm/openpic.c  |  295 +
 hw/openpic.c  |   40 +++---
 hw/openpic.h  |   11 ++
 hw/ppc/e500.c |   28 +++--
 include/exec/memory.h |9 ++
 include/sysemu/kvm.h  |   10 ++
 kvm-all.c |   11 +-
 linux-headers/linux/kvm.h |   34 ++
 memory.c  |   38 +-
 12 files changed, 444 insertions(+), 37 deletions(-)
 create mode 100644 hw/kvm/openpic.c

-- 
1.7.9.5





[Qemu-devel] [RFC PATCH 02/10] Fix errors and warnings while compiling with c++ compilier

2013-02-13 Thread Tomoki Sekiyama
Rename 'class' member in class_info of PciDeviceInfo to 'dev_class', and
add some casts to avoid errors from c++ compiler.

Signed-off-by: Tomoki Sekiyama 
---
 hmp.c|2 +-
 hw/pci/pci.c |2 +-
 qapi-schema.json |4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hmp.c b/hmp.c
index 1689e6f..a889c89 100644
--- a/hmp.c
+++ b/hmp.c
@@ -482,7 +482,7 @@ static void hmp_info_pci_device(Monitor *mon, const 
PciDeviceInfo *dev)
 if (dev->class_info.has_desc) {
 monitor_printf(mon, "%s", dev->class_info.desc);
 } else {
-monitor_printf(mon, "Class %04" PRId64, dev->class_info.class);
+monitor_printf(mon, "Class %04" PRId64, dev->class_info.dev_class);
 }
 
 monitor_printf(mon, ": PCI device %04" PRIx64 ":%04" PRIx64 "\n",
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 905dc4a..2ca0675 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1385,7 +1385,7 @@ static PciDeviceInfo *qmp_query_pci_device(PCIDevice 
*dev, PCIBus *bus,
 info->function = PCI_FUNC(dev->devfn);
 
 class = pci_get_word(dev->config + PCI_CLASS_DEVICE);
-info->class_info.class = class;
+info->class_info.dev_class = class;
 desc = get_class_desc(class);
 if (desc->desc) {
 info->class_info.has_desc = true;
diff --git a/qapi-schema.json b/qapi-schema.json
index cdd8384..413df5c 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1150,7 +1150,7 @@
 #
 # @class_info.desc: #optional a string description of the device's class
 #
-# @class_info.class: the class code of the device
+# @class_info.dev_class: the class code of the device
 #
 # @id.device: the PCI device id
 #
@@ -1171,7 +1171,7 @@
 ##
 { 'type': 'PciDeviceInfo',
   'data': {'bus': 'int', 'slot': 'int', 'function': 'int',
-   'class_info': {'*desc': 'str', 'class': 'int'},
+   'class_info': {'*desc': 'str', 'dev_class': 'int'},
'id': {'device': 'int', 'vendor': 'int'},
'*irq': 'int', 'qdev_id': 'str', '*pci_bridge': 'PciBridgeInfo',
'regions': ['PciMemoryRegion']} }




[Qemu-devel] [RFC ppc-next PATCH 1/6] kvm: update linux-headers

2013-02-13 Thread Scott Wood
These headers have not yet been merged into Linux -- this is an RFC
patchset.

Signed-off-by: Scott Wood 
---
 linux-headers/linux/kvm.h |   34 ++
 1 file changed, 34 insertions(+)

diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index 5af9357..8607ac1 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -662,6 +662,7 @@ struct kvm_ppc_smmu_info {
 #define KVM_CAP_PPC_HTAB_FD 84
 #define KVM_CAP_S390_CSS_SUPPORT 85
 #define KVM_CAP_PPC_EPR 86
+#define KVM_CAP_DEVICE_CTRL 87
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
@@ -890,6 +891,39 @@ struct kvm_s390_ucas_mapping {
 /* Available with KVM_CAP_PPC_HTAB_FD */
 #define KVM_PPC_GET_HTAB_FD  _IOW(KVMIO,  0xaa, struct kvm_get_htab_fd)
 
+/* Available with KVM_CAP_DEVICE_CTRL */
+#define KVM_CREATE_DEVICE_TEST 1
+
+struct kvm_create_device {
+   __u32   type;   /* in: KVM_DEV_TYPE_xxx */
+   __u32   id; /* out: device handle */
+   __u32   flags;  /* in: KVM_CREATE_DEVICE_xxx */
+};
+
+struct kvm_device_attr {
+   __u32   dev;/* id from KVM_CREATE_DEVICE */
+   __u32   group;  /* KVM_DEV_ATTR_COMMON or device-defined */
+   __u64   attr;   /* group-defined */
+   __u64   addr;   /* userspace address of attr data */
+};
+
+#define KVM_DEV_ATTR_COMMON0
+#define   KVM_DEV_ATTR_TYPE0 /* 32-bit */
+
+#define KVM_DEV_TYPE_FSL_MPIC_20   1
+#define KVM_DEV_TYPE_FSL_MPIC_42   2
+
+#define KVM_DEV_MPIC_GRP_MISC  1
+#define   KVM_DEV_MPIC_BASE_ADDR   0   /* 64-bit */
+
+#define KVM_DEV_MPIC_GRP_REGISTER  2   /* 32-bit */
+#define KVM_DEV_MPIC_GRP_IRQ_ACTIVE3   /* 32-bit */
+
+#define KVM_CREATE_DEVICE_IOWR(KVMIO,  0xab, struct kvm_create_device)
+#define KVM_SET_DEVICE_ATTR  _IOW(KVMIO,  0xac, struct kvm_device_attr)
+#define KVM_GET_DEVICE_ATTR  _IOW(KVMIO,  0xad, struct kvm_device_attr)
+#define KVM_HAS_DEVICE_ATTR  _IOW(KVMIO,  0xae, struct kvm_device_attr)
+
 /*
  * ioctls for vcpu fds
  */
-- 
1.7.9.5





[Qemu-devel] [RFC PATCH 07/10] qemu-ga: install Windows VSS provider on `qemu-ga -s install'

2013-02-13 Thread Tomoki Sekiyama
Register QGA VSS provider library into Windows when qemu-ga is installed as
Windows service ('-s install' option). It is deregistered when the service
is uninstalled ('-s uninstall' option).

Signed-off-by: Tomoki Sekiyama 
---
 qga/main.c |8 
 1 file changed, 8 insertions(+)

diff --git a/qga/main.c b/qga/main.c
index 423d41b..3e6d95e 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -850,8 +850,16 @@ int main(int argc, char **argv)
 case 's':
 service = optarg;
 if (strcmp(service, "install") == 0) {
+#ifdef HAS_VSS_SDK
+if (FAILED(COMRegister())) {
+return EXIT_FAILURE;
+}
+#endif
 return ga_install_service(path, log_filepath);
 } else if (strcmp(service, "uninstall") == 0) {
+#ifdef HAS_VSS_SDK
+COMUnregister();
+#endif
 return ga_uninstall_service();
 } else {
 printf("Unknown service command.\n");




[Qemu-devel] [RFC ppc-next PATCH 6/6] kvm/openpic: in-kernel mpic support

2013-02-13 Thread Scott Wood
This depends on RFC kernel interfaces proposed at:
http://patchwork.ozlabs.org/patch/220359/
http://patchwork.ozlabs.org/patch/220362/

Signed-off-by: Scott Wood 
---
 hw/kvm/Makefile.objs |1 +
 hw/kvm/openpic.c |  295 ++
 hw/ppc/e500.c|   28 +++--
 3 files changed, 317 insertions(+), 7 deletions(-)
 create mode 100644 hw/kvm/openpic.c

diff --git a/hw/kvm/Makefile.objs b/hw/kvm/Makefile.objs
index 6ccb6ed..8df0fe1 100644
--- a/hw/kvm/Makefile.objs
+++ b/hw/kvm/Makefile.objs
@@ -1 +1,2 @@
 obj-$(TARGET_I386) += clock.o apic.o i8259.o ioapic.o i8254.o pci-assign.o
+obj-$(TARGET_PPC) += openpic.o
diff --git a/hw/kvm/openpic.c b/hw/kvm/openpic.c
new file mode 100644
index 000..aabc4a6
--- /dev/null
+++ b/hw/kvm/openpic.c
@@ -0,0 +1,295 @@
+/*
+ * KVM in-kernel OpenPIC
+ *
+ * Copyright 2013 Freescale Semiconductor, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "exec/address-spaces.h"
+#include "hw/hw.h"
+#include "hw/openpic.h"
+#include "hw/pci/msi.h"
+#include "hw/sysbus.h"
+#include "sysemu/kvm.h"
+
+typedef struct KVMOpenPICState {
+SysBusDevice busdev;
+MemoryRegion mem;
+MemoryListener mem_listener;
+hwaddr reg_base;
+uint32_t kern_id;
+uint32_t model;
+} KVMOpenPICState;
+
+static void kvm_openpic_set_irq(void *opaque, int n_IRQ, int level)
+{
+KVMOpenPICState *opp = opaque;
+struct kvm_device_attr attr;
+uint32_t val32 = level;
+int ret;
+
+attr.dev = opp->kern_id;
+attr.group = KVM_DEV_MPIC_GRP_IRQ_ACTIVE;
+attr.attr = n_IRQ;
+attr.addr = (uint64_t)(long)&val32;
+
+ret = kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
+if (ret < 0) {
+fprintf(stderr, "%s: %s %llx\n", __func__, strerror(errno), attr.attr);
+}
+}
+
+static void kvm_openpic_reset(DeviceState *d)
+{
+#if 0
+OpenPICState *opp = FROM_SYSBUS(typeof(*opp), SYS_BUS_DEVICE(d));
+int i;
+
+opp->gcr = GCR_RESET;
+/* Initialise controller registers */
+opp->frr = ((opp->nb_irqs - 1) << FRR_NIRQ_SHIFT) |
+   ((opp->nb_cpus - 1) << FRR_NCPU_SHIFT) |
+   (opp->vid << FRR_VID_SHIFT);
+
+opp->pir = 0;
+opp->spve = -1 & opp->vector_mask;
+opp->tfrr = opp->tfrr_reset;
+/* Initialise IRQ sources */
+for (i = 0; i < opp->max_irq; i++) {
+opp->src[i].ivpr = opp->ivpr_reset;
+opp->src[i].idr  = opp->idr_reset;
+
+switch (opp->src[i].type) {
+case IRQ_TYPE_NORMAL:
+opp->src[i].level = !!(opp->ivpr_reset & IVPR_SENSE_MASK);
+break;
+
+case IRQ_TYPE_FSLINT:
+opp->src[i].ivpr |= IVPR_POLARITY_MASK;
+break;
+
+case IRQ_TYPE_FSLSPECIAL:
+break;
+}
+}
+/* Initialise IRQ destinations */
+for (i = 0; i < MAX_CPU; i++) {
+opp->dst[i].ctpr  = 15;
+memset(&opp->dst[i].raised, 0, sizeof(IRQQueue));
+opp->dst[i].raised.next = -1;
+memset(&opp->dst[i].servicing, 0, sizeof(IRQQueue));
+opp->dst[i].servicing.next = -1;
+}
+/* Initialise timers */
+for (i = 0; i < OPENPIC_MAX_TMR; i++) {
+opp->timers[i].tccr = 0;
+opp->timers[i].tbcr = TBCR_CI;
+}
+/* Go out of RESET state */
+opp->gcr = 0;
+#endif
+}
+
+static void kvm_openpic_write(void *opaque, hwaddr addr, uint64_t val,
+  unsigned size)
+{
+KVMOpenPICState *opp = opaque;
+struct kvm_device_attr attr;
+uint32_t val32 = val;
+int ret;
+
+attr.dev = opp->kern_id;
+attr.group = KVM_DEV_MPIC_GRP_REGISTER;
+attr.attr = addr;
+attr.addr = (uint64_t)(long)&val32;
+
+ret = kvm_vm_ioctl(kvm_state, KVM_SET_DEVICE_ATTR, &attr);
+if (ret < 0) {
+qemu_log_mask(LOG_UNIMP, "%s: %s %llx\n", __func__,
+  strerror(errno), attr.attr);
+}
+}
+
+static uint64_t kvm_openpic_rea

[Qemu-devel] [RFC ppc-next PATCH 4/6] openpic: factor out some common defines into openpic.h

2013-02-13 Thread Scott Wood
...for use by the KVM in-kernel irqchip stub.

Signed-off-by: Scott Wood 
---
 hw/openpic.c |   40 ++--
 hw/openpic.h |   11 +++
 2 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/hw/openpic.c b/hw/openpic.c
index 20a479c..0d55ef4 100644
--- a/hw/openpic.c
+++ b/hw/openpic.c
@@ -57,11 +57,7 @@ static const int debug_openpic = 0;
 } while (0)
 
 #define MAX_CPU 32
-#define MAX_SRC 256
-#define MAX_TMR 4
-#define MAX_IPI 4
 #define MAX_MSI 8
-#define MAX_IRQ (MAX_SRC + MAX_IPI + MAX_TMR)
 #define VID 0x03 /* MPIC version ID */
 
 /* OpenPIC capability flags */
@@ -78,7 +74,7 @@ static const int debug_openpic = 0;
 #define OPENPIC_SUMMARY_REG_START   0x3800
 #define OPENPIC_SUMMARY_REG_SIZE0x800
 #define OPENPIC_SRC_REG_START0x1
-#define OPENPIC_SRC_REG_SIZE (MAX_SRC * 0x20)
+#define OPENPIC_SRC_REG_SIZE (OPENPIC_MAX_SRC * 0x20)
 #define OPENPIC_CPU_REG_START0x2
 #define OPENPIC_CPU_REG_SIZE 0x100 + ((MAX_CPU - 1) * 0x1000)
 
@@ -86,8 +82,8 @@ static const int debug_openpic = 0;
 #define RAVEN_MAX_CPU  2
 #define RAVEN_MAX_EXT 48
 #define RAVEN_MAX_IRQ 64
-#define RAVEN_MAX_TMR  MAX_TMR
-#define RAVEN_MAX_IPI  MAX_IPI
+#define RAVEN_MAX_TMR  OPENPIC_MAX_TMR
+#define RAVEN_MAX_IPI  OPENPIC_MAX_IPI
 
 /* Interrupt definitions */
 #define RAVEN_FE_IRQ (RAVEN_MAX_EXT) /* Internal functional IRQ */
@@ -209,7 +205,7 @@ typedef struct IRQQueue {
 /* Round up to the nearest 64 IRQs so that the queue length
  * won't change when moving between 32 and 64 bit hosts.
  */
-unsigned long queue[BITS_TO_LONGS((MAX_IRQ + 63) & ~63)];
+unsigned long queue[BITS_TO_LONGS((OPENPIC_MAX_IRQ + 63) & ~63)];
 int next;
 int priority;
 } IRQQueue;
@@ -283,7 +279,7 @@ typedef struct OpenPICState {
 uint32_t spve; /* Spurious vector register */
 uint32_t tfrr; /* Timer frequency reporting register */
 /* Source registers */
-IRQSource src[MAX_IRQ];
+IRQSource src[OPENPIC_MAX_IRQ];
 /* Local registers per output pin */
 IRQDest dst[MAX_CPU];
 uint32_t nb_cpus;
@@ -291,7 +287,7 @@ typedef struct OpenPICState {
 struct {
 uint32_t tccr;  /* Global timer current count register */
 uint32_t tbcr;  /* Global timer base count register */
-} timers[MAX_TMR];
+} timers[OPENPIC_MAX_TMR];
 /* Shared MSI registers */
 struct {
 uint32_t msir;   /* Shared Message Signaled Interrupt Register */
@@ -503,7 +499,7 @@ static void openpic_set_irq(void *opaque, int n_IRQ, int 
level)
 OpenPICState *opp = opaque;
 IRQSource *src;
 
-if (n_IRQ >= MAX_IRQ) {
+if (n_IRQ >= OPENPIC_MAX_IRQ) {
 fprintf(stderr, "%s: IRQ %d out of range\n", __func__, n_IRQ);
 abort();
 }
@@ -576,7 +572,7 @@ static void openpic_reset(DeviceState *d)
 opp->dst[i].servicing.next = -1;
 }
 /* Initialise timers */
-for (i = 0; i < MAX_TMR; i++) {
+for (i = 0; i < OPENPIC_MAX_TMR; i++) {
 opp->timers[i].tccr = 0;
 opp->timers[i].tbcr = TBCR_CI;
 }
@@ -1182,7 +1178,7 @@ static uint32_t openpic_iack(OpenPICState *opp, IRQDest 
*dst, int cpu)
 IRQ_resetbit(&dst->raised, irq);
 }
 
-if ((irq >= opp->irq_ipi0) &&  (irq < (opp->irq_ipi0 + MAX_IPI))) {
+if ((irq >= opp->irq_ipi0) &&  (irq < (opp->irq_ipi0 + OPENPIC_MAX_IPI))) {
 src->destmask &= ~(1 << cpu);
 if (src->destmask && !src->level) {
 /* trigger on CPUs that didn't know about it yet */
@@ -1381,7 +1377,7 @@ static void openpic_save(QEMUFile* f, void *opaque)
 sizeof(opp->dst[i].outputs_active));
 }
 
-for (i = 0; i < MAX_TMR; i++) {
+for (i = 0; i < OPENPIC_MAX_TMR; i++) {
 qemu_put_be32s(f, &opp->timers[i].tccr);
 qemu_put_be32s(f, &opp->timers[i].tbcr);
 }
@@ -1440,7 +1436,7 @@ static int openpic_load(QEMUFile* f, void *opaque, int 
version_id)
 sizeof(opp->dst[i].outputs_active));
 }
 
-for (i = 0; i < MAX_TMR; i++) {
+for (i = 0; i < OPENPIC_MAX_TMR; i++) {
 qemu_get_be32s(f, &opp->timers[i].tccr);
 qemu_get_be32s(f, &opp->timers[i].tbcr);
 }
@@ -1473,7 +1469,7 @@ typedef struct MemReg {
 static void fsl_common_init(OpenPICState *opp)
 {
 int i;
-int virq = MAX_SRC;
+int virq = OPENPIC_MAX_SRC;
 
 opp->vid = VID_REVISION_1_2;
 opp->vir = VIR_GENERIC;
@@ -1481,14 +1477,14 @@ static void fsl_common_init(OpenPICState *opp)
 opp->tfrr_reset = 0;
 opp->ivpr_reset = IVPR_MASK_MASK;
 opp->idr_reset = 1 << 0;
-opp->max_irq = MAX_IRQ;
+opp->max_irq = OPENPIC_MAX_IRQ;
 
 opp->irq_ipi0 = virq;
-virq += MAX_IPI;
+virq += OPENPIC_MAX_IPI;
 opp->irq_tim0 = virq;
-virq += MAX_TMR;
+virq += OPENPIC_MAX_TMR;
 
-assert(virq <= MAX_IRQ);
+assert(virq <= OPENPI

[Qemu-devel] [RFC PATCH 08/10] qemu-ga: Add VSS provider .tlb file in the repository

2013-02-13 Thread Tomoki Sekiyama
To build type library (.tlb) from COM IDL (.idl), MIDL program in
VisualC++ is required. Because MinGW does not support building .tlb files,
this file cannot be cross-compiled in non-Windows systems.

This patch adds pre-compiled .tlb file in the repository in order to
enable cross-compile qemu-ga for Windows with VSS support.

Signed-off-by: Tomoki Sekiyama 
---
 Makefile|2 +-
 qga/vss-win32-provider/qga-provider.tlb |  Bin
 2 files changed, 1 insertion(+), 1 deletion(-)
 create mode 100644 qga/vss-win32-provider/qga-provider.tlb

diff --git a/Makefile b/Makefile
index f0734b7..405657f 100644
--- a/Makefile
+++ b/Makefile
@@ -215,7 +215,7 @@ clean:
rm -f qemu-options.def
find . -name '*.[oda]' -type f -exec rm -f {} +
find . -name '*.l[oa]' -type f -exec rm -f {} +
-   rm -f $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~
+   rm -f $(filter-out %.tlb,$(TOOLS)) $(HELPERS-y) qemu-ga TAGS cscope.* 
*.pod *~ */*~
rm -Rf .libs
rm -f qemu-img-cmds.h
@# May not be present in GENERATED_HEADERS
diff --git a/qga/vss-win32-provider/qga-provider.tlb 
b/qga/vss-win32-provider/qga-provider.tlb
new file mode 100644
index 
..226452a1861371ffe0cad1019cf90fdfdcd5ef49
GIT binary patch
literal 1528
zcmeYbb_-!*U}OLRP8Kl5;0UB3A_y8H!@$4OPh6a(1_GM|T)fx!kz-UGh_rLWKC!yoBjb#vz`9Lwu4+R-SJ!kIOX4xLBUUGN9-NyTyP76j}@n
z2f!qQ8-xepfXD+7rW+{SKz4&@7#qX~^1#sn3O|tFK>%ciE<&_Q3PuKoMqI)S5zj9Ngog_=
gXfrXehlhjmFbIJB4$8MKU>*YlD1Z9^F{m5{03Vre%>V!Z

literal 0
HcmV?d1





[Qemu-devel] [RFC PATCH 04/10] qemu-ga: Add Windows VSS provider to quiesce applications on fsfreeze

2013-02-13 Thread Tomoki Sekiyama
Implements a basic stub of software VSS provider. Currently, this modules
only provides a relay function of events between qemu-guest-agent and
Windows VSS when VSS finished filesystem freeze and when qemu snapshot
is done.

In the future, this module could be extended to support the other VSS
functions, such as query for snapshot volumes and recovery.

Signed-off-by: Tomoki Sekiyama 
---
 Makefile|1 
 configure   |5 
 qga/vss-win32-provider.h|   26 ++
 qga/vss-win32-provider/Makefile |   30 ++
 qga/vss-win32-provider/install.cpp  |  494 +++
 qga/vss-win32-provider/provider.cpp |  474 ++
 qga/vss-win32-provider/qga-provider.def |   10 +
 qga/vss-win32-provider/qga-provider.idl |   20 +
 qga/vss-win32.h |   93 ++
 9 files changed, 1152 insertions(+), 1 deletion(-)
 create mode 100644 qga/vss-win32-provider.h
 create mode 100644 qga/vss-win32-provider/Makefile
 create mode 100644 qga/vss-win32-provider/install.cpp
 create mode 100644 qga/vss-win32-provider/provider.cpp
 create mode 100644 qga/vss-win32-provider/qga-provider.def
 create mode 100644 qga/vss-win32-provider/qga-provider.idl
 create mode 100644 qga/vss-win32.h

diff --git a/Makefile b/Makefile
index fab664f..f0734b7 100644
--- a/Makefile
+++ b/Makefile
@@ -225,6 +225,7 @@ clean:
rm -f $(foreach f,$(GENERATED_SOURCES),$(f) $(f)-timestamp)
rm -rf qapi-generated
rm -rf qga/qapi-generated
+   $(MAKE) -C qga/vss-win32-provider clean
$(MAKE) -C tests/tcg clean
for d in $(ALL_SUBDIRS); do \
if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
diff --git a/configure b/configure
index da49c52..15abdc4 100755
--- a/configure
+++ b/configure
@@ -3264,9 +3264,12 @@ if test "$softmmu" = yes ; then
   virtfs=no
 fi
   fi
-  if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" ] ; then
+  if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" -o "$mingw32" 
= "yes" ] ; then
 if [ "$guest_agent" = "yes" ]; then
   tools="qemu-ga\$(EXESUF) $tools"
+  if [ "$mingw32" = "yes" ]; then
+tools="qga/vss-win32-provider/qga-provider.dll 
qga/vss-win32-provider/qga-provider.tlb $tools"
+  fi
 fi
   fi
 fi
diff --git a/qga/vss-win32-provider.h b/qga/vss-win32-provider.h
new file mode 100644
index 000..e312977
--- /dev/null
+++ b/qga/vss-win32-provider.h
@@ -0,0 +1,26 @@
+/*
+ * QEMU Guest Agent win32 VSS provider declarations
+ *
+ * Copyright Hitachi, Ltd. 2013
+ *
+ * Authors:
+ *  Tomoki Sekiyama   
+ *
+ * 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 VSS_WIN32_PROVIDER_H
+#define VSS_WIN32_PROVIDER_H
+
+#include 
+
+STDAPI VSSCheckOSVersion(void);
+
+STDAPI COMRegister(void);
+STDAPI COMUnregister(void);
+
+STDAPI DllRegisterServer(void);
+STDAPI DllUnregisterServer(void);
+
+#endif
diff --git a/qga/vss-win32-provider/Makefile b/qga/vss-win32-provider/Makefile
new file mode 100644
index 000..1f213f2
--- /dev/null
+++ b/qga/vss-win32-provider/Makefile
@@ -0,0 +1,30 @@
+-include ../../config-host.mak
+-include ../../rules.mak
+
+# To build .tlb from .idl, WindowsSDK and C++ must be installed
+MIDL=midl
+WINSDK="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Include"
+
+qga-prv-dll = qga-provider.dll
+qga-prv-tlb = $(qga-prv-dll:.dll=.tlb)
+qga-prv-def = $(qga-prv-dll:.dll=.def)
+qga-prv-idl = $(qga-prv-dll:.dll=.idl)
+qga-prv-obj-y = provider.o install.o
+
+.PYONY: all clean
+
+all: $(qga-prv-dll)
+
+$(qga-prv-tlb): $(qga-prv-idl)
+   $(call quiet-command,$(MIDL) -I $(WINSDK) $<,"  MIDL  $(TARGET_DIR)$@")
+
+$(qga-prv-obj-y): QEMU_CXXFLAGS = $(filter-out -Wstrict-prototypes 
-Wmissing-prototypes -Wnested-externs -Wold-style-declaration 
-Wold-style-definition -Wredundant-decls -fstack-protector-all, $(QEMU_CFLAGS))
+$(qga-prv-obj-y): QEMU_CXXFLAGS += -Wno-unknown-pragmas 
-Wno-delete-non-virtual-dtor
+
+$(qga-prv-dll): LDFLAGS = -shared 
-Wl,--add-stdcall-alias,--enable-stdcall-fixup -lole32 -loleaut32 -lshlwapi 
-luuid -static
+$(qga-prv-dll): $(qga-prv-obj-y) $(qga-prv-def) $(qga-prv-tlb)
+   $(call quiet-command,$(CXX) -o $@ $(qga-prv-obj-y) $(qga-prv-def) 
$(CXXFLAGS) $(LDFLAGS),"  LINK  $(TARGET_DIR)$@")
+
+# *.tlb is not removed because it is not generated by MinGW
+clean:
+   rm -f *.o *.d *.dll *.exe *~
diff --git a/qga/vss-win32-provider/install.cpp 
b/qga/vss-win32-provider/install.cpp
new file mode 100644
index 000..43a12d7
--- /dev/null
+++ b/qga/vss-win32-provider/install.cpp
@@ -0,0 +1,494 @@
+/*
+ * QEMU Guest Agent win32 VSS Provider installer
+ *
+ * Copyright Hitachi, Ltd. 2013
+ *
+ * Authors:
+ *  Tomoki Sekiyama   
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level direc

[Qemu-devel] [RFC PATCH 06/10] qemu-ga: call Windows VSS requester in fsfreeze command handler

2013-02-13 Thread Tomoki Sekiyama
Support guest-fsfreeze-freeze and guest-fsfreeze-thaw commands for Windows
guests. When fsfreeze command is issued, it calls the VSS requester to
freeze filesystems and applications. On thaw command, it again tells the VSS
requester to thaw them.

This also adds calling of initialize functions for the VSS requester.

Signed-off-by: Tomoki Sekiyama 
---
 qga/commands-win32.c |   74 ++
 qga/main.c   |   33 ++
 2 files changed, 100 insertions(+), 7 deletions(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 7e8ecb3..1ed9fc1 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include "qga/guest-agent-core.h"
+#include "qga/vss-win32-requester.h"
 #include "qga-qmp-commands.h"
 #include "qapi/qmp/qerror.h"
 
@@ -145,34 +146,95 @@ void qmp_guest_file_flush(int64_t handle, Error **err)
 error_set(err, QERR_UNSUPPORTED);
 }
 
+#ifdef HAS_VSS_SDK
+
 /*
  * Return status of freeze/thaw
  */
 GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **err)
 {
-error_set(err, QERR_UNSUPPORTED);
-return 0;
+if (!vss_initialized()) {
+error_set(err, QERR_UNSUPPORTED);
+return 0;
+}
+
+if (ga_is_frozen(ga_state)) {
+return GUEST_FSFREEZE_STATUS_FROZEN;
+}
+
+return GUEST_FSFREEZE_STATUS_THAWED;
 }
 
 /*
- * Walk list of mounted file systems in the guest, and freeze the ones which
- * are real local file systems.
+ * Freeze local file systems using Volume Shadow-copy Service.
+ * The frozen state is limited for up to 10 seconds by VSS.
  */
 int64_t qmp_guest_fsfreeze_freeze(Error **err)
 {
-error_set(err, QERR_UNSUPPORTED);
+int i;
+
+slog("guest-fsfreeze called");
+
+if (!vss_initialized()) {
+error_set(err, QERR_UNSUPPORTED);
+return 0;
+}
+
+/* cannot risk guest agent blocking itself on a write in this state */
+ga_set_frozen(ga_state);
+
+qga_vss_fsfreeze_freeze(&i, err);
+if (error_is_set(err)) {
+goto error;
+}
+
+return i;
+
+error:
+qmp_guest_fsfreeze_thaw(NULL);
 return 0;
 }
 
 /*
- * Walk list of frozen file systems in the guest, and thaw them.
+ * Thaw local file systems using Volume Shadow-copy Service.
  */
 int64_t qmp_guest_fsfreeze_thaw(Error **err)
 {
+int i;
+
+if (!vss_initialized()) {
+error_set(err, QERR_UNSUPPORTED);
+return 0;
+}
+
+qga_vss_fsfreeze_thaw(&i, err);
+
+ga_unset_frozen(ga_state);
+return i;
+}
+
+#else
+
+GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **err)
+{
+error_set(err, QERR_UNSUPPORTED);
+return 0;
+}
+
+int64_t qmp_guest_fsfreeze_freeze(Error **err)
+{
+error_set(err, QERR_UNSUPPORTED);
+return 0;
+}
+
+int64_t qmp_guest_fsfreeze_thaw(Error **err)
+{
 error_set(err, QERR_UNSUPPORTED);
 return 0;
 }
 
+#endif
+
 /*
  * Walk list of mounted file systems in the guest, and discard unused
  * areas.
diff --git a/qga/main.c b/qga/main.c
index db281a5..423d41b 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -32,6 +32,10 @@
 #include "qga/channel.h"
 #ifdef _WIN32
 #include "qga/service-win32.h"
+#ifdef HAS_VSS_SDK
+#include "qga/vss-win32-provider.h"
+#include "qga/vss-win32-requester.h"
+#endif
 #include 
 #endif
 #ifdef __linux__
@@ -675,6 +679,25 @@ static gboolean channel_init(GAState *s, const gchar 
*method, const gchar *path)
 }
 
 #ifdef _WIN32
+
+static gboolean vss_win32_init(void)
+{
+#ifdef HAS_VSS_SDK
+if (FAILED(vss_init())) {
+g_critical("failed to initialize VSS");
+return false;
+}
+#endif
+return true;
+}
+
+static void vss_win32_deinit(void)
+{
+#ifdef HAS_VSS_SDK
+vss_deinit();
+#endif
+}
+
 DWORD WINAPI service_ctrl_handler(DWORD ctrl, DWORD type, LPVOID data,
   LPVOID ctx)
 {
@@ -717,8 +740,12 @@ VOID WINAPI service_main(DWORD argc, TCHAR *argv[])
 service->status.dwWaitHint = 0;
 SetServiceStatus(service->status_handle, &service->status);
 
+if (!vss_win32_init()) {
+goto out_bad;
+}
 g_main_loop_run(ga_state->main_loop);
-
+vss_win32_deinit();
+out_bad:
 service->status.dwCurrentState = SERVICE_STOPPED;
 SetServiceStatus(service->status_handle, &service->status);
 }
@@ -943,7 +970,11 @@ int main(int argc, char **argv)
 { (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } };
 StartServiceCtrlDispatcher(service_table);
 } else {
+if (!vss_win32_init()) {
+goto out_bad;
+}
 g_main_loop_run(ga_state->main_loop);
+vss_win32_deinit();
 }
 #endif
 




[Qemu-devel] [RFC PATCH 05/10] qemu-ga: Add Windows VSS requester to quisce applications and filesystems

2013-02-13 Thread Tomoki Sekiyama
This adds VSS requester functions for to qemu-ga.
This provides facility to request VSS service in Windows guest to quisce
applications and filesystems.
This function is only supported in Windows 2003 or later. In older guests,
this function does nothing.

Signed-off-by: Tomoki Sekiyama 
---
 qga/Makefile.objs   |   15 ++
 qga/vss-win32-requester.cpp |  393 +++
 qga/vss-win32-requester.h   |   31 +++
 3 files changed, 439 insertions(+)
 create mode 100644 qga/vss-win32-requester.cpp
 create mode 100644 qga/vss-win32-requester.h

diff --git a/qga/Makefile.objs b/qga/Makefile.objs
index b8d7cd0..2e4a8d6 100644
--- a/qga/Makefile.objs
+++ b/qga/Makefile.objs
@@ -3,3 +3,18 @@ qga-obj-$(CONFIG_POSIX) += commands-posix.o channel-posix.o
 qga-obj-$(CONFIG_WIN32) += commands-win32.o channel-win32.o service-win32.o
 qga-obj-y += qapi-generated/qga-qapi-types.o qapi-generated/qga-qapi-visit.o
 qga-obj-y += qapi-generated/qga-qmp-marshal.o
+
+ifeq ($(CONFIG_QGA_VSS),y)
+
+qga-obj-$(CONFIG_WIN32) += vss-win32-requester.o
+QEMU_CFLAGS += -DHAS_VSS_SDK
+QGALIB_EXTDIR = $(obj)/vss-win32-provider
+
+qemu-ga$(EXESUF): $(QGALIB_EXTDIR)/qga-provider.dll
+$(obj)/vss-win32-requester.o: QEMU_CXXFLAGS += -Wno-unknown-pragmas
+
+$(QGALIB_EXTDIR)/qga-provider.tlb: $(QGALIB_EXTDIR)/qga-provider.dll
+$(QGALIB_EXTDIR)/qga-provider.dll: $(qga-lib-src) $(obj)/vss-win32.h
+   $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C 
qga/$(QGALIB_EXTDIR) V="$(V)" all,)
+
+endif
diff --git a/qga/vss-win32-requester.cpp b/qga/vss-win32-requester.cpp
new file mode 100644
index 000..f84f464
--- /dev/null
+++ b/qga/vss-win32-requester.cpp
@@ -0,0 +1,393 @@
+/*
+ * QEMU Guest Agent win32 VSS Requester implementations
+ *
+ * Copyright Hitachi, Ltd. 2013
+ *
+ * Authors:
+ *  Tomoki Sekiyama   
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include 
+#include 
+extern "C" {
+#include "guest-agent-core.h"
+}
+#include "vss-win32-requester.h"
+#include "vss-win32-provider.h"
+#include "vss-win32.h"
+#include "inc/win2003/vswriter.h"
+#include "inc/win2003/vsbackup.h"
+
+/* Functions in VSSAPI.DLL */
+typedef HRESULT (STDAPICALLTYPE* t_CreateVssBackupComponents)(OUT 
IVssBackupComponents **);
+typedef void (APIENTRY* t_VssFreeSnapshotProperties)(IN VSS_SNAPSHOT_PROP*);
+
+static t_CreateVssBackupComponents _CreateVssBackupComponents = NULL;
+static t_VssFreeSnapshotProperties _VssFreeSnapshotProperties = NULL;
+static IVssBackupComponents *pVssbc = NULL;
+static IVssAsync *pAsyncSnapshot = NULL;
+static HMODULE hLib = NULL;
+static HANDLE hEvent = INVALID_HANDLE_VALUE, hEvent2 = INVALID_HANDLE_VALUE;
+static int cFrozenVols = 0;
+
+GCC_FMT_ATTR(1, 2)
+static void errmsg(const char *fmt, ...)
+{
+va_list ap;
+va_start(ap, fmt);
+char *msg = g_strdup_vprintf(fmt, ap);
+va_end(ap);
+MessageBox(NULL, msg, "Error in QEMU guest agent", MB_OK | MB_ICONWARNING);
+g_free(msg);
+}
+
+static void error_set_win32(Error **errp, DWORD err,
+ErrorClass eclass, const char *text)
+{
+char *msg = NULL, *nul = strchr(text, '(');
+int len = nul ? nul - text : -1;
+
+/* print error message in native encoding */
+FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+  FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+  NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+  (char *)&msg, 0, NULL);
+printf("%.*s. (Error: %lx) %s\n", len, text, err, msg);
+LocalFree(msg);
+
+/* set error message in UTF-8 encoding */
+msg = g_win32_error_message(err);
+error_set(errp, eclass, "%.*s. (Error: %lx) %s", len, text, err, msg);
+g_free(msg);
+}
+#define error_setg_win32(errp, err, text) \
+error_set_win32(errp, err, ERROR_CLASS_GENERIC_ERROR, text)
+
+#define _chk(status, text, errp, err_label)\
+do {\
+HRESULT __hr = (status);\
+if (FAILED(__hr)) { \
+error_setg_win32(errp, __hr, text); \
+goto err_label; \
+}   \
+} while(0)
+
+#define chk(status) _chk(status, "Failed to " #status, err, out)
+
+
+HRESULT WaitForAsync(IVssAsync *pAsync)
+{
+HRESULT ret, hr;
+
+do {
+hr = pAsync->Wait();
+if (FAILED(hr)) {
+ret = hr;
+break;
+}
+hr = pAsync->QueryStatus(&ret, NULL);
+if (FAILED(hr)) {
+ret = hr;
+break;
+}
+} while (ret == VSS_S_ASYNC_PENDING);
+
+return ret;
+}
+
+HRESULT vss_init(void)
+{
+HRESULT hr;
+
+hr = VSSCheckOSVersion();
+if (hr == S_FALSE) {
+return hr;
+}
+
+hr = CoInitialize(NULL);
+if (FAILED(hr)) {
+errmsg("CoInitialize failed [%lx]

[Qemu-devel] [RFC PATCH 00/10] qemu-ga: support fsfreeze on Windows using VSS

2013-02-13 Thread Tomoki Sekiyama
Hi,

This patch series attempts to add fsfreeze support for Windows
qemu-guest-agent.

In Windows, VSS (Volume Shadow Copy Service) can provide a facility to
quiesce filesystems and applications before snapshots are taken.

VSS consists from some components.
 - VSS Writers:applications to be quiesced.
 - VSS Providers:  modules to provide a snapshot feature
 - VSS Requesters: modules to control snapshotting processes

This patch series adds VSS provider and requester feature to qemu-ga.

When guest-fsfreeze-freeze command is sent, qemu-ga request VSS to freeze
applications and filesystems. After frozen, VSS requests providers to take
snapshots using COM+. Qemu-ga hooks this event by registering its own
VSS provider and relay it to qemu-ga. guest-fsfreeze-freeze command is
finished by this event.
When guest-fsfreeze-thaw command is sent, qemu-ga provider tells VSS that
snapshot is finished. Then, VSS thaws the filesystems and applications
and notify the requester of snapshot completion.

The VSS provider in this patch series only provides snapshotting to
implement fsfreeze commands, but doesn't provide functions to query for
snapshots, recovery, and so on. Auto-recovery(*) feature of VSS is not
either supported becuase it requires writable snapshots.
*http://msdn.microsoft.com/en-us//library/windows/desktop/aa819771(v=vs.85).aspx
Still, this could be useful as a base for future extentions.


* How to build & run qemu-ga with VSS support

 - Download Microsoft VSS SDK from:
   http://www.microsoft.com/en-us/download/details.aspx?id=23490

 - Setup the SDK (wine can be used to run the setup)

 - Specify installed SDK directory to configure option as:
   ./configure -with-vss-sdk="path/to/VSS SDK" --cross-prefix=i686-w64-mingw32-

 - Make qemu-ga.exe

 - Install qemu-ga.exe and qga/vss-win32-provider/qga-provider.{dll,tlb} into
   the same directory in guests

 - Run `qemu-ga.exe -s install' and `net start qemu-ga' in the guests

---
Tomoki Sekiyama (10):
  configure: Support configuring c++ compiler
  Fix errors and warnings while compiling with c++ compilier
  qemu-ga: Add an configure option to specify path to Windows VSS SDK
  qemu-ga: Add Windows VSS provider to quiesce applications on fsfreeze
  qemu-ga: Add Windows VSS requester to quisce applications and filesystems
  qemu-ga: call Windows VSS requester in fsfreeze command handler
  qemu-ga: install Windows VSS provider on `qemu-ga -s install'
  qemu-ga: Add VSS provider .tlb file in the repository
  QMP/qemu-ga-client: make timeout longer for guest-fsfreeze-freeze command
  QMP/qmp.py: set locale for exceptions to display non-ascii messages 
correctly

 .gitignore  |1 
 Makefile|4 
 QMP/qemu-ga-client  |4 
 QMP/qmp.py  |4 
 configure   |   52 +++
 hmp.c   |2 
 hw/pci/pci.c|2 
 qapi-schema.json|4 
 qga/Makefile.objs   |   15 +
 qga/commands-win32.c|   74 -
 qga/main.c  |   41 +++
 qga/vss-win32-provider.h|   26 ++
 qga/vss-win32-provider/Makefile |   30 ++
 qga/vss-win32-provider/install.cpp  |  494 +++
 qga/vss-win32-provider/provider.cpp |  474 ++
 qga/vss-win32-provider/qga-provider.def |   10 +
 qga/vss-win32-provider/qga-provider.idl |   20 +
 qga/vss-win32-provider/qga-provider.tlb |  Bin
 qga/vss-win32-requester.cpp |  393 +
 qga/vss-win32-requester.h   |   31 ++
 qga/vss-win32.h |   93 ++
 rules.mak   |7 
 22 files changed, 1766 insertions(+), 15 deletions(-)
 create mode 100644 qga/vss-win32-provider.h
 create mode 100644 qga/vss-win32-provider/Makefile
 create mode 100644 qga/vss-win32-provider/install.cpp
 create mode 100644 qga/vss-win32-provider/provider.cpp
 create mode 100644 qga/vss-win32-provider/qga-provider.def
 create mode 100644 qga/vss-win32-provider/qga-provider.idl
 create mode 100644 qga/vss-win32-provider/qga-provider.tlb
 create mode 100644 qga/vss-win32-requester.cpp
 create mode 100644 qga/vss-win32-requester.h
 create mode 100644 qga/vss-win32.h


Any feedback are appliciated.
Thanks,
-- 
Tomoki Sekiyama 
Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory



[Qemu-devel] [Bug 1123975] Re: QEmu 1.3.90 cannot restore a 1.1.2 live snapshot

2013-02-13 Thread Michael Tokarev
And one more thing -- from what to what are you trying to migrate?  I
see you have qemu-kvm installed too, -- were you using it previously?
Note that qemu-kvm 1.1 had the same video ram size = 16Mb as current
qemu have.  But my cross-version migration comment stays and in this
case it becomes even stronger.

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

Title:
  QEmu 1.3.90 cannot restore a 1.1.2 live snapshot

Status in QEMU:
  New

Bug description:
  I have upgraded to QEmu 1.3.90 (Debian 1.4.0~rc0+dfsg-1exp) but now
  when I try to restore a live snapshot made in QEmu 1.1.2 (Debian
  1.1.2+dfsg-5) I get the following message:

  virsh # snapshot-revert fgtbbuild wtb
  error: operation failed: Error -22 while loading VM state

  I have test VMs with live snapshots coreresponding to different
  testing configurations. So I typically revert the VMs in one of the
  live snapshots and run the tests. It would be pretty annoying to have
  to recreate all these live snapshots any time I upgrade QEmu.

  
  ipxe-qemu  1.0.0+git-20120202.f6840ba-3
  qemu   1.4.0~rc0+dfsg-1exp
  qemu-keymaps   1.4.0~rc0+dfsg-1exp
  qemu-kvm   1.4.0~rc0+dfsg-1exp
  qemu-system1.4.0~rc0+dfsg-1exp
  qemu-system-arm1.4.0~rc0+dfsg-1exp
  qemu-system-common 1.4.0~rc0+dfsg-1exp
  qemu-system-mips   1.4.0~rc0+dfsg-1exp
  qemu-system-misc   1.4.0~rc0+dfsg-1exp
  qemu-system-ppc1.4.0~rc0+dfsg-1exp
  qemu-system-sparc  1.4.0~rc0+dfsg-1exp
  qemu-system-x861.4.0~rc0+dfsg-1exp
  qemu-user  1.4.0~rc0+dfsg-1exp
  qemu-utils 1.4.0~rc0+dfsg-1exp
  libvirt-bin1.0.2-1
  libvirt-dev1.0.2-1
  libvirt-doc1.0.2-1
  libvirt-glib-1.0-0 0.1.2-1
  libvirt0   1.0.2-1
  libvirtodbc0   6.1.4+dfsg1-5

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



[Qemu-devel] [Bug 1123975] Re: QEmu 1.3.90 cannot restore a 1.1.2 live snapshot

2013-02-13 Thread Michael Tokarev
This sounds pretty much like a prob with video ram size.  In 1.1.x, we
had video ram of 8Mb, in 1.3 it is 16Mb...  should this be a problem, to
come from smaller to larger size?

Besides that, debian uses almost unmodified qemu, so the same prob
should exist for upstream qemu too.

But at any rate, I never recommended any sort of cross-version migration
as in practice, despite countless efforts spent to make it to work, it
almost always does NOT work.

Thanks,

/mjt

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

Title:
  QEmu 1.3.90 cannot restore a 1.1.2 live snapshot

Status in QEMU:
  New

Bug description:
  I have upgraded to QEmu 1.3.90 (Debian 1.4.0~rc0+dfsg-1exp) but now
  when I try to restore a live snapshot made in QEmu 1.1.2 (Debian
  1.1.2+dfsg-5) I get the following message:

  virsh # snapshot-revert fgtbbuild wtb
  error: operation failed: Error -22 while loading VM state

  I have test VMs with live snapshots coreresponding to different
  testing configurations. So I typically revert the VMs in one of the
  live snapshots and run the tests. It would be pretty annoying to have
  to recreate all these live snapshots any time I upgrade QEmu.

  
  ipxe-qemu  1.0.0+git-20120202.f6840ba-3
  qemu   1.4.0~rc0+dfsg-1exp
  qemu-keymaps   1.4.0~rc0+dfsg-1exp
  qemu-kvm   1.4.0~rc0+dfsg-1exp
  qemu-system1.4.0~rc0+dfsg-1exp
  qemu-system-arm1.4.0~rc0+dfsg-1exp
  qemu-system-common 1.4.0~rc0+dfsg-1exp
  qemu-system-mips   1.4.0~rc0+dfsg-1exp
  qemu-system-misc   1.4.0~rc0+dfsg-1exp
  qemu-system-ppc1.4.0~rc0+dfsg-1exp
  qemu-system-sparc  1.4.0~rc0+dfsg-1exp
  qemu-system-x861.4.0~rc0+dfsg-1exp
  qemu-user  1.4.0~rc0+dfsg-1exp
  qemu-utils 1.4.0~rc0+dfsg-1exp
  libvirt-bin1.0.2-1
  libvirt-dev1.0.2-1
  libvirt-doc1.0.2-1
  libvirt-glib-1.0-0 0.1.2-1
  libvirt0   1.0.2-1
  libvirtodbc0   6.1.4+dfsg1-5

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



Re: [Qemu-devel] using -net dump with tap networking

2013-02-13 Thread Alexey Kardashevskiy

On 14/02/13 05:02, Laszlo Ersek wrote:

On 02/13/13 15:48, Alexey Kardashevskiy wrote:

Hi!

I am running qemu as:

qemu/ppc64-softmmu/qemu-system-ppc64 -m 1024 -M pseries -trace
events=trace_events -netdev user,id=virtnet,hostfwd=tcp::5000-:22
-device virtio-net-pci,netdev=virtnet -nographic -vga none -enable-kvm
-kernel vml36_64k -initrd 1.cpio

Now I want to enable network dump. With the old "-net" syntax I could do
that with "-net dump" but I cannot with the new syntax, tried many
variants, none works. What would the correct syntax be for the case above?


Ugh, I'm a bit confused, but if I say something stupid that should still
help "ignite" the discussion.

So, in general there are two ways to specify this:

(1) -net dump,id=dump0,vlan=VLAN_ID,len=SIZE_LIMIT,file=PATHNAME

(2) -netdev dump,id=dump0,len=SIZE_LIMIT,file=PATHNAME

I believe the first option (legacy) should work.

The second one will not work; actually I think it will trigger an
assert. The generic init code in net_client_init1() [net/net.c] says:

 NetClientState *peer = NULL;

 /* Do not add to a vlan if it's a -netdev or a nic with a netdev=
  * parameter. */
 if (!is_netdev &&
 (opts->kind != NET_CLIENT_OPTIONS_KIND_NIC ||
  !opts->nic->has_netdev)) {
 peer = net_hub_add_port(u.net->has_vlan ? u.net->vlan : 0, NULL);
 }

 if (net_client_init_fun[opts->kind](opts, name, peer) < 0) {

So in (2) we don't add the dump netdev to any hub/vlan; however the
specific code (net_init_dump(), [net/dump.c]) asserts (peer != NULL).

Otherwise I think the idea would be to add the dump netdev *afterwards*
to a vlan/hub, by changing its vlan property. See set_vlan() in
[hw/qdev-properties-system.c]; it calls net_hub_port_find() [net/hub.c]
whose task is to "Find a available port on a hub; otherwise create one
new port".

See
.

Hence I think you're back to (1), the legacy format. Assuming qemu
doesn't barf on that option immediately, I believe you *also* have to
add your "-netdev user" to the same hub as the dumper is on.

In total you have to create both netdevs (a, b) and assign both to a
common hub/vlan (c, d). Again, unfortunately the dump netdev only works
with the legacy format, but that already includes the assignment to the
hub (a, c). So you have to take care of creating the other netdev
(-netdev user, b), and assign it through its vlan qdev property to the
same hub (d), so that data can flow from it to the dump netdev.

Hm... Looks like you can't do that directly on "-netdev user" (it seems
to have no such property). "virtio-net-pci" does have it however. At
least in a quick "info qtree" check:

bus: main-system-bus
   type System
   dev: i440FX-pcihost, id ""
 bus: pci.0
   type PCI
   dev: virtio-net-pci, id "net0"
 dev-prop: vlan = 

Also confirmed by "qemu-system-x86_64 -device virtio-net-pci,help".

So

-netdev user,id=virtnet,hostfwd=tcp::5000-:22 \
-device virtio-net-pci,netdev=virtnet,vlan=2 \
-net dump,vlan=2,len=SIZE_LIMIT,file=PATHNAME

Or some such...


Ok. So, there is "user" device (interface to the world) and 2 QEMU network 
devices - "virtio" and "dump", attached to the same virtual bridge within 
the QEMU.


Now let's make it more fun. Actually I want to trace a "tap" config (I put 
it into the subject but later changed the actual example in a hope that it 
makes things simpler but I was wrong :-) ):


qemu-impreza/ppc64-softmmu/qemu-system-ppc64 -m 1024 -M pseries
-nographic -vga none -enable-kvm -kernel vml36_64k -initrd 1.cpio
-netdev tap,id=tapnet,ifname=tap0,script=qemu-ifup.sh
-device virtio-net-pci,netdev=tapnet,vlan=100
-net dump,vlan=100,file=./dump.lan.qemu.virtio

So I have a virtual bridge but it is in the host, not in the QEMU. To the 
command line above QEMU says:


Warning: vlan 100 is not connected to host network
Warning: netdev tapnet has no peer

"qemu -help" says "-net tap" accepts "vlan=n" but "-netdev 
tap,vlan=100,..." generates an error (Invalid parameter 'vlan').


Sure I can run tcpdump on the host with the tap0 interface but I would like 
to catch trafic between virtio-net-pci and tap0 if it is possible. Is it?


btw is there any way to get for the -netdev device what "-device NAME,help" 
does (i.e. list of actually supported parameters)?



--
Alexey



[Qemu-devel] [PATCH 09/10] bitops: Replace bitops_ctol with ctzl

2013-02-13 Thread Richard Henderson
The is the only remaining user.

Signed-off-by: Richard Henderson 
---
 util/bitops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/bitops.c b/util/bitops.c
index 50b4a81..e72237a 100644
--- a/util/bitops.c
+++ b/util/bitops.c
@@ -109,7 +109,7 @@ found_first:
 return result + size;  /* Nope. */
 }
 found_middle:
-return result + bitops_ctol(tmp);
+return result + ctzl(~tmp);
 }
 
 unsigned long find_last_bit(const unsigned long *addr, unsigned long size)
-- 
1.8.1.2




[Qemu-devel] [PATCH 05/10] memory: Use non-bitops ctzl

2013-02-13 Thread Richard Henderson
A memory size of zero is invalid, and so that edge condition
does not occur.

Signed-off-by: Richard Henderson 
---
 memory.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/memory.c b/memory.c
index cd7d5e0..92a2196 100644
--- a/memory.c
+++ b/memory.c
@@ -855,7 +855,7 @@ static uint64_t memory_region_dispatch_read1(MemoryRegion 
*mr,
 }
 
 if (!mr->ops->read) {
-return mr->ops->old_mmio.read[bitops_ctzl(size)](mr->opaque, addr);
+return mr->ops->old_mmio.read[ctz32(size)](mr->opaque, addr);
 }
 
 /* FIXME: support unaligned access */
@@ -908,7 +908,7 @@ static void memory_region_dispatch_write(MemoryRegion *mr,
 adjust_endianness(mr, &data, size);
 
 if (!mr->ops->write) {
-mr->ops->old_mmio.write[bitops_ctzl(size)](mr->opaque, addr, data);
+mr->ops->old_mmio.write[ctz32(size)](mr->opaque, addr, data);
 return;
 }
 
-- 
1.8.1.2




[Qemu-devel] [PATCH 04/10] bitops: Use non-bitops ctzl

2013-02-13 Thread Richard Henderson
The use of ctz has already eliminated zero, and thus the difference
in edge conditions between the two routines is irrelevant.

Signed-off-by: Richard Henderson 
---
 util/bitops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/bitops.c b/util/bitops.c
index 7b853cf..9cd1c3a 100644
--- a/util/bitops.c
+++ b/util/bitops.c
@@ -60,7 +60,7 @@ found_first:
 return result + size;  /* Nope. */
 }
 found_middle:
-return result + bitops_ctzl(tmp);
+return result + ctzl(tmp);
 }
 
 /*
-- 
1.8.1.2




[Qemu-devel] [PATCH v2 00/10] Cleanup bitops vs host-utils

2013-02-13 Thread Richard Henderson
Version 1 merely tried to adjust bitops_flsl, here I instead eliminate
it all from bitops.h, and standardizes on the routines from host-utils.h.


r~


Richard Henderson (10):
  host-utils: Add host long specific aliases for clz, ctz, ctpop
  host-utils: Fix coding style and add comments
  hbitmap: Use non-bitops ctzl
  bitops: Use non-bitops ctzl
  memory: Use non-bitops ctzl
  bitops: Write bitops_flsl in terms of clzl
  target-i386: Inline bitops_flsl
  bitops: Inline bitops_flsl
  bitops: Replace bitops_ctol with ctzl
  bitops: Remove routines redundant with host-utils

 include/qemu/bitops.h |  75 -
 include/qemu/hbitmap.h|   3 +-
 include/qemu/host-utils.h | 119 +++---
 memory.c  |   4 +-
 target-i386/topology.h|   6 +--
 util/bitops.c |   6 +--
 util/hbitmap.c|   3 +-
 7 files changed, 112 insertions(+), 104 deletions(-)

-- 
1.8.1.2




[Qemu-devel] [PATCH 06/10] bitops: Write bitops_flsl in terms of clzl

2013-02-13 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 include/qemu/bitops.h | 29 +
 1 file changed, 1 insertion(+), 28 deletions(-)

diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h
index 8b88791..b50629b 100644
--- a/include/qemu/bitops.h
+++ b/include/qemu/bitops.h
@@ -57,34 +57,7 @@ static unsigned long bitops_ctzl(unsigned long word)
  */
 static inline unsigned long bitops_flsl(unsigned long word)
 {
-   int num = BITS_PER_LONG - 1;
-
-#if LONG_MAX > 0x7FFF
-   if (!(word & (~0ul << 32))) {
-   num -= 32;
-   word <<= 32;
-   }
-#endif
-   if (!(word & (~0ul << (BITS_PER_LONG-16 {
-   num -= 16;
-   word <<= 16;
-   }
-   if (!(word & (~0ul << (BITS_PER_LONG-8 {
-   num -= 8;
-   word <<= 8;
-   }
-   if (!(word & (~0ul << (BITS_PER_LONG-4 {
-   num -= 4;
-   word <<= 4;
-   }
-   if (!(word & (~0ul << (BITS_PER_LONG-2 {
-   num -= 2;
-
-   word <<= 2;
-   }
-   if (!(word & (~0ul << (BITS_PER_LONG-1
-   num -= 1;
-   return num;
+return BITS_PER_LONG - 1 - clzl(word);
 }
 
 /**
-- 
1.8.1.2




[Qemu-devel] [PATCH 08/10] bitops: Inline bitops_flsl

2013-02-13 Thread Richard Henderson
This is the only remaining user.

Signed-off-by: Richard Henderson 
---
 util/bitops.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/bitops.c b/util/bitops.c
index 9cd1c3a..50b4a81 100644
--- a/util/bitops.c
+++ b/util/bitops.c
@@ -133,7 +133,7 @@ unsigned long find_last_bit(const unsigned long *addr, 
unsigned long size)
 tmp = addr[--words];
 if (tmp) {
 found:
-return words * BITS_PER_LONG + bitops_flsl(tmp);
+return words * BITS_PER_LONG + BITS_PER_LONG - 1 - clzl(tmp);
 }
 }
 
-- 
1.8.1.2




[Qemu-devel] [PATCH 01/10] host-utils: Add host long specific aliases for clz, ctz, ctpop

2013-02-13 Thread Richard Henderson
We will standardize on these names, rather than the similar routines
currently residing in qemu/bitops.h.


Signed-off-by: Richard Henderson 
---
 include/qemu/host-utils.h | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
index 81c9a75..d72b72d 100644
--- a/include/qemu/host-utils.h
+++ b/include/qemu/host-utils.h
@@ -26,6 +26,7 @@
 #define HOST_UTILS_H 1
 
 #include "qemu/compiler.h"   /* QEMU_GNUC_PREREQ */
+#include 
 
 #if defined(__x86_64__)
 #define __HAVE_FAST_MULU64__
@@ -237,4 +238,22 @@ static inline int ctpop64(uint64_t val)
 #endif
 }
 
+/* Host type specific sizes of these routines.  */
+
+#if ULONG_MAX == UINT32_MAX
+# define clzl   clz32
+# define ctzl   ctz32
+# define clol   clo32
+# define ctol   cto32
+# define ctpopl ctpop32
+#elif ULONG_MAX == UINT64_MAX
+# define clzl   clz64
+# define ctzl   ctz64
+# define clol   clo64
+# define ctol   cto64
+# define ctpopl ctpop64
+#else
+# error Unknown sizeof long
+#endif
+
 #endif
-- 
1.8.1.2




Re: [Qemu-devel] [PATCH v2] Move File operations to qemu-file.c

2013-02-13 Thread Anthony Liguori
Joel Schopp  writes:

>>> +if(popen_file == NULL) {
>>
>> Please make a preparatory patch which adds missing spaces between 'if'
>> statements and '('.
>
> I'll do a preparatory style cleanup patch of existing code if it is 
> deemed necessary by the maintainers, but I don't think it's a good
> idea. 

I basically hate checkpatch :-)  There's no need to do a style cleanup,
it's just going to confuse gits move detection and screw up merging.  In
this case, it's such a trivial thing too.

I disabled the automated checkpatch bot because it got too annoying.  It
throws way too many false positives or annoying nits that shouldn't keep
us from merging useful code.

I haven't applied this patch because we're in freeze for the 1.4
release.

Regards,

Anthony Liguori

>   The patch as it stands now simply moves existing code to another file 
> and thus is pretty safe.  Adding a preparatory patch to reformat the 
> code is easy to mess up and raises the chances of introducing a regression.
>
> Why not just submit patches to clean up coding style for the entire code 
> base independent of any refactoring?
>
> When I originally wrote checkpatch.pl it was with the intention of 
> avoiding arguments over coding style.  I see that I missed a corner case 
> by having it not notice code moves as a special case to ignore.
>
> -Joel



Re: [Qemu-devel] [PATCH moxie 2/5] Add moxie disassembler

2013-02-13 Thread Anthony Liguori
Anthony Green  writes:

> This patch adds the disassembler logic for moxie.
>
>
> Signed-off-by: Anthony Green 
> diff --git a/disas/moxie.c b/disas/moxie.c
>  new file mode 100644
> index 000..20ae0eb
> --- /dev/null
> +++ b/disas/moxie.c
> @@ -0,0 +1,369 @@
> +/* Disassemble moxie instructions.
> +   Copyright 2009
> +   Free Software Foundation, Inc.
> +
> +   This file is part of the GNU opcodes library.
> +
> +   This library is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3, or (at your option)
> +   any later version.
> +
> +   It is distributed in the hope that it will be useful, but WITHOUT
> +   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
> +   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
> +   License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program; if not, write to the Free Software
> +   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
> +   MA 02110-1301, USA.  */

QEMU is GPLv2 only so we can't take GPLv3 code.  We're stuck on binutils
code that predates the v3 relicense.

Regards,

Anthony Liguori



[Qemu-devel] [PATCH 07/10] target-i386: Inline bitops_flsl

2013-02-13 Thread Richard Henderson
Use clz32 directly.  Which makes slightly more sense given
that the input is type "int" and not type "long".

Signed-off-by: Richard Henderson 
---
 target-i386/topology.h | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/target-i386/topology.h b/target-i386/topology.h
index 24ed525..07a6c5f 100644
--- a/target-i386/topology.h
+++ b/target-i386/topology.h
@@ -52,10 +52,8 @@ typedef uint32_t apic_id_t;
 static unsigned apicid_bitwidth_for_count(unsigned count)
 {
 g_assert(count >= 1);
-if (count == 1) {
-return 0;
-}
-return bitops_flsl(count - 1) + 1;
+count -= 1;
+return count ? 32 - clz32(count) : 0;
 }
 
 /* Bit width of the SMT_ID (thread ID) field on the APIC ID
-- 
1.8.1.2




[Qemu-devel] [PATCH 03/10] hbitmap: Use non-bitops ctzl

2013-02-13 Thread Richard Henderson
Both uses of ctz have already eliminated zero, and thus the difference
in edge conditions between the two routines is irrelevant.

Signed-off-by: Richard Henderson 
---
 include/qemu/hbitmap.h | 3 ++-
 util/hbitmap.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h
index 250de03..550d7ce 100644
--- a/include/qemu/hbitmap.h
+++ b/include/qemu/hbitmap.h
@@ -16,6 +16,7 @@
 #include 
 #include 
 #include "bitops.h"
+#include "host-utils.h"
 
 typedef struct HBitmap HBitmap;
 typedef struct HBitmapIter HBitmapIter;
@@ -170,7 +171,7 @@ static inline int64_t hbitmap_iter_next(HBitmapIter *hbi)
 
 /* The next call will resume work from the next bit.  */
 hbi->cur[HBITMAP_LEVELS - 1] = cur & (cur - 1);
-item = ((uint64_t)hbi->pos << BITS_PER_LEVEL) + bitops_ctzl(cur);
+item = ((uint64_t)hbi->pos << BITS_PER_LEVEL) + ctzl(cur);
 
 return item << hbi->granularity;
 }
diff --git a/util/hbitmap.c b/util/hbitmap.c
index a0df5d3..d936831 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -126,7 +126,8 @@ unsigned long hbitmap_iter_skip_words(HBitmapIter *hbi)
  * The index of this word's least significant set bit provides
  * the low-order bits.
  */
-pos = (pos << BITS_PER_LEVEL) + bitops_ctzl(cur);
+assert(cur);
+pos = (pos << BITS_PER_LEVEL) + ctzl(cur);
 hbi->cur[i] = cur & (cur - 1);
 
 /* Set up next level for iteration.  */
-- 
1.8.1.2




[Qemu-devel] [PATCH 10/10] bitops: Remove routines redundant with host-utils

2013-02-13 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 include/qemu/bitops.h | 48 
 1 file changed, 48 deletions(-)

diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h
index b50629b..affcc96 100644
--- a/include/qemu/bitops.h
+++ b/include/qemu/bitops.h
@@ -24,54 +24,6 @@
 #define BITS_TO_LONGS(nr)  DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
 
 /**
- * bitops_ctzl - count trailing zeroes in word.
- * @word: The word to search
- *
- * Returns -1 if no bit exists.  Note that compared to the C library
- * routine ffsl, this one returns one less.
- */
-static unsigned long bitops_ctzl(unsigned long word)
-{
-#if QEMU_GNUC_PREREQ(3, 4)
-return __builtin_ffsl(word) - 1;
-#else
-if (!word) {
-return -1;
-}
-
-if (sizeof(long) == 4) {
-return ctz32(word);
-} else if (sizeof(long) == 8) {
-return ctz64(word);
-} else {
-abort();
-}
-#endif
-}
-
-/**
- * bitops_fls - find last (most-significant) set bit in a long word
- * @word: the word to search
- *
- * Undefined if no set bit exists, so code should check against 0 first.
- */
-static inline unsigned long bitops_flsl(unsigned long word)
-{
-return BITS_PER_LONG - 1 - clzl(word);
-}
-
-/**
- * cto - count trailing ones in word.
- * @word: The word to search
- *
- * Returns -1 if all bit are set.
- */
-static inline unsigned long bitops_ctol(unsigned long word)
-{
-return bitops_ctzl(~word);
-}
-
-/**
  * set_bit - Set a bit in memory
  * @nr: the bit to set
  * @addr: the address to start counting from
-- 
1.8.1.2




[Qemu-devel] [PATCH 02/10] host-utils: Fix coding style and add comments

2013-02-13 Thread Richard Henderson
Add function comments to the routines, documenting the corner
cases upon which we are standardizing.  Fix the few instances
of non-standard coding style.

Signed-off-by: Richard Henderson 
---
 include/qemu/host-utils.h | 100 +-
 1 file changed, 82 insertions(+), 18 deletions(-)

diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h
index d72b72d..f0dd850 100644
--- a/include/qemu/host-utils.h
+++ b/include/qemu/host-utils.h
@@ -50,16 +50,19 @@ void muls64(uint64_t *phigh, uint64_t *plow, int64_t a, 
int64_t b);
 void mulu64(uint64_t *phigh, uint64_t *plow, uint64_t a, uint64_t b);
 #endif
 
-/* Binary search for leading zeros.  */
-
+/**
+ * clz32 - count leading zeros in a 32-bit value.
+ * @val: The value to search
+ *
+ * Returns 32 if the value is zero.  Note that the GCC builtin is
+ * undefined if the value is zero.
+ */
 static inline int clz32(uint32_t val)
 {
 #if QEMU_GNUC_PREREQ(3, 4)
-if (val)
-return __builtin_clz(val);
-else
-return 32;
+return val ? __builtin_clz(val) : 32;
 #else
+/* Binary search for the leading one bit.  */
 int cnt = 0;
 
 if (!(val & 0xU)) {
@@ -89,18 +92,28 @@ static inline int clz32(uint32_t val)
 #endif
 }
 
+/**
+ * clo32 - count leading ones in a 32-bit value.
+ * @val: The value to search
+ *
+ * Returns 32 if the value is -1.
+ */
 static inline int clo32(uint32_t val)
 {
 return clz32(~val);
 }
 
+/**
+ * clz64 - count leading zeros in a 64-bit value.
+ * @val: The value to search
+ *
+ * Returns 64 if the value is zero.  Note that the GCC builtin is
+ * undefined if the value is zero.
+ */
 static inline int clz64(uint64_t val)
 {
 #if QEMU_GNUC_PREREQ(3, 4)
-if (val)
-return __builtin_clzll(val);
-else
-return 64;
+return val ? __builtin_clzll(val) : 64;
 #else
 int cnt = 0;
 
@@ -114,19 +127,30 @@ static inline int clz64(uint64_t val)
 #endif
 }
 
+/**
+ * clo64 - count leading ones in a 64-bit value.
+ * @val: The value to search
+ *
+ * Returns 64 if the value is -1.
+ */
 static inline int clo64(uint64_t val)
 {
 return clz64(~val);
 }
 
+/**
+ * ctz32 - count trailing zeros in a 32-bit value.
+ * @val: The value to search
+ *
+ * Returns 32 if the value is zero.  Note that the GCC builtin is
+ * undefined if the value is zero.
+ */
 static inline int ctz32(uint32_t val)
 {
 #if QEMU_GNUC_PREREQ(3, 4)
-if (val)
-return __builtin_ctz(val);
-else
-return 32;
+return val ? __builtin_ctz(val) : 32;
 #else
+/* Binary search for the trailing one bit.  */
 int cnt;
 
 cnt = 0;
@@ -158,18 +182,28 @@ static inline int ctz32(uint32_t val)
 #endif
 }
 
+/**
+ * cto32 - count trailing ones in a 32-bit value.
+ * @val: The value to search
+ *
+ * Returns 32 if the value is -1.
+ */
 static inline int cto32(uint32_t val)
 {
 return ctz32(~val);
 }
 
+/**
+ * ctz64 - count trailing zeros in a 64-bit value.
+ * @val: The value to search
+ *
+ * Returns 64 if the value is zero.  Note that the GCC builtin is
+ * undefined if the value is zero.
+ */
 static inline int ctz64(uint64_t val)
 {
 #if QEMU_GNUC_PREREQ(3, 4)
-if (val)
-return __builtin_ctzll(val);
-else
-return 64;
+return val ? __builtin_ctzll(val) : 64;
 #else
 int cnt;
 
@@ -183,30 +217,56 @@ static inline int ctz64(uint64_t val)
 #endif
 }
 
+/**
+ * ctz64 - count trailing ones in a 64-bit value.
+ * @val: The value to search
+ *
+ * Returns 64 if the value is -1.
+ */
 static inline int cto64(uint64_t val)
 {
 return ctz64(~val);
 }
 
+/**
+ * ctpop8 - count the population of one bits in an 8-bit value.
+ * @val: The value to search
+ */
 static inline int ctpop8(uint8_t val)
 {
+#if QEMU_GNUC_PREREQ(3, 4)
+return __builtin_popcount(val);
+#else
 val = (val & 0x55) + ((val >> 1) & 0x55);
 val = (val & 0x33) + ((val >> 2) & 0x33);
 val = (val & 0x0f) + ((val >> 4) & 0x0f);
 
 return val;
+#endif
 }
 
+/**
+ * ctpop16 - count the population of one bits in a 16-bit value.
+ * @val: The value to search
+ */
 static inline int ctpop16(uint16_t val)
 {
+#if QEMU_GNUC_PREREQ(3, 4)
+return __builtin_popcount(val);
+#else
 val = (val & 0x) + ((val >> 1) & 0x);
 val = (val & 0x) + ((val >> 2) & 0x);
 val = (val & 0x0f0f) + ((val >> 4) & 0x0f0f);
 val = (val & 0x00ff) + ((val >> 8) & 0x00ff);
 
 return val;
+#endif
 }
 
+/**
+ * ctpop32 - count the population of one bits in a 32-bit value.
+ * @val: The value to search
+ */
 static inline int ctpop32(uint32_t val)
 {
 #if QEMU_GNUC_PREREQ(3, 4)
@@ -222,6 +282,10 @@ static inline int ctpop32(uint32_t val)
 #endif
 }
 
+/**
+ * ctpop64 - count the population of one bits in a 64-bit value.
+ * @val: The value to search
+ */
 static inline int ctpop64(uint64_t val)
 {
 #if QEMU_GNUC_PREREQ(3, 4)
-- 
1.8.1.2




[Qemu-devel] [PATCH moxie 5/5] Top level changes for moxie port

2013-02-13 Thread Anthony Green
The final patch adds top level changes in support of the new moxie port.

Thanks,

AG


Signed-off-by: Anthony Green 
---
 hw/moxie/Makefile.objs     |   5 ++
 hw/moxiesim.c              | 200 +
 include/sysemu/arch_init.h |   1 +
 3 files changed, 206 insertions(+)
 create mode 100644 hw/moxie/Makefile.objs
 create mode 100644 hw/moxiesim.c

diff --git a/hw/moxie/Makefile.objs b/hw/moxie/Makefile.objs
new file mode 100644
index 000..2963363
--- /dev/null
+++ b/hw/moxie/Makefile.objs
@@ -0,0 +1,5 @@
+# moxie boards
+obj-y = moxiesim.o serial.o mc146818rtc.o vga.o
+obj-$(CONFIG_FDT) += device_tree.o
+
+obj-y := $(addprefix ../,$(obj-y))
diff --git a/hw/moxiesim.c b/hw/moxiesim.c
new file mode 100644
index 000..feae538
--- /dev/null
+++ b/hw/moxiesim.c
@@ -0,0 +1,200 @@
+/*
+ * QEMU/moxiesim emulation
+ *
+ * Emulates a very simple machine model similiar to the one use by the
+ * GDB moxie simulator.
+ *
+ * Copyright (c) 2008, 2009, 2010 Anthony Green
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the
"Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "sysbus.h"
+#include "hw.h"
+#include "pc.h"
+#include "isa.h"
+#include "net/net.h"
+#include "sysemu/sysemu.h"
+#include "boards.h"
+#include "loader.h"
+#include "serial.h"
+#include "exec/address-spaces.h"
+
+#define PHYS_MEM_BASE 0x8000
+
+static struct _loaderparams {
+    int ram_size;
+    const char *kernel_filename;
+    const char *kernel_cmdline;
+    const char *initrd_filename;
+} loaderparams;
+
+static void load_kernel (CPUMoxieState *env)
+{
+    uint64_t entry, kernel_low, kernel_high;
+    long kernel_size;
+    long initrd_size;
+    ram_addr_t initrd_offset;
+
+    kernel_size = load_elf(loaderparams.kernel_filename,  NULL, NULL,
+                           &entry, &kernel_low, &kernel_high, 1,
ELF_MACHINE, 0);
+    if (kernel_size >= 0)
+      env->pc = (unsigned) entry;
+    else
+      {
+        fprintf(stderr, "qemu: could not load kernel '%s'\n",
+                loaderparams.kernel_filename);
+        exit(1);
+      }
+
+    /* load initrd */
+    initrd_size = 0;
+    initrd_offset = 0;
+    if (loaderparams.initrd_filename) {
+        initrd_size = get_image_size (loaderparams.initrd_filename);
+        if (initrd_size > 0) {
+            initrd_offset = (kernel_high + ~TARGET_PAGE_MASK) &
TARGET_PAGE_MASK;
+            if (initrd_offset + initrd_size > loaderparams.ram_size) {
+                fprintf(stderr,
+                        "qemu: memory too small for initial ram disk '%s'\n",
+                        loaderparams.initrd_filename);
+                exit(1);
+            }
+            initrd_size = load_image_targphys(loaderparams.initrd_filename,
+                                              initrd_offset,
+                                              ram_size);
+        }
+        if (initrd_size == (target_ulong) -1) {
+            fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
+                    loaderparams.initrd_filename);
+            exit(1);
+        }
+    }
+}
+
+static void main_cpu_reset(void *opaque)
+{
+    MoxieCPU *cpu = opaque;
+
+    cpu_reset(CPU(cpu));
+}
+
+static inline DeviceState *
+moxie_intc_create(hwaddr base, qemu_irq irq, int kind_of_intr)
+{
+    DeviceState *dev;
+
+    dev = qdev_create(NULL, "moxie,intc");
+    qdev_prop_set_uint32(dev, "kind-of-intr", kind_of_intr);
+    qdev_init_nofail(dev);
+    sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
+    sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq);
+    return dev;
+}
+
+static void moxiesim_init(QEMUMachineInitArgs *args)
+{
+    MoxieCPU *cpu = NULL;
+    ram_addr_t ram_size = args->ram_size;
+    const char *cpu_model = args->cpu_model;
+    const char *kernel_filename = args->kernel_filename;
+    const char *kernel_cmdline = args->kernel_cmdline;
+    const char *initrd_filename = args->initrd_filename;
+    CPUMoxieState *env;
+    MemoryRegion *address_space_mem = g

[Qemu-devel] [PATCH moxie 2/5] Add moxie disassembler

2013-02-13 Thread Anthony Green
This patch adds the disassembler logic for moxie.


Signed-off-by: Anthony Green 
---
 disas.c             |   6 +
 disas/Makefile.objs |   1 +
 disas/moxie.c       | 369 
 include/disas/bfd.h |   2 +
 4 files changed, 378 insertions(+)
 create mode 100644 disas/moxie.c

diff --git a/disas.c b/disas.c
index a46faee..74d3ba0 100644
--- a/disas.c
+++ b/disas.c
@@ -256,6 +256,9 @@ void target_disas(FILE *out, CPUArchState *env,
target_ulong code,
 #elif defined(TARGET_MICROBLAZE)
     s.info.mach = bfd_arch_microblaze;
     print_insn = print_insn_microblaze;
+#elif defined(TARGET_MOXIE)
+    s.info.mach = bfd_arch_moxie;
+    print_insn = print_insn_moxie;
 #elif defined(TARGET_LM32)
     s.info.mach = bfd_mach_lm32;
     print_insn = print_insn_lm32;
@@ -462,6 +465,9 @@ void monitor_disas(Monitor *mon, CPUArchState *env,
 #elif defined(TARGET_S390X)
     s.info.mach = bfd_mach_s390_64;
     print_insn = print_insn_s390;
+#elif defined(TARGET_MOXIE)
+    s.info.mach = bfd_arch_moxie;
+    print_insn = print_insn_moxie;
 #elif defined(TARGET_LM32)
     s.info.mach = bfd_mach_lm32;
     print_insn = print_insn_lm32;
diff --git a/disas/Makefile.objs b/disas/Makefile.objs
index ed75f9a..3b1e77a 100644
--- a/disas/Makefile.objs
+++ b/disas/Makefile.objs
@@ -7,6 +7,7 @@ common-obj-$(CONFIG_IA64_DIS) += ia64.o
 common-obj-$(CONFIG_M68K_DIS) += m68k.o
 common-obj-$(CONFIG_MICROBLAZE_DIS) += microblaze.o
 common-obj-$(CONFIG_MIPS_DIS) += mips.o
+common-obj-$(CONFIG_MOXIE_DIS) += moxie.o
 common-obj-$(CONFIG_PPC_DIS) += ppc.o
 common-obj-$(CONFIG_S390_DIS) += s390.o
 common-obj-$(CONFIG_SH4_DIS) += sh4.o
diff --git a/disas/moxie.c b/disas/moxie.c
 new file mode 100644
index 000..20ae0eb
--- /dev/null
+++ b/disas/moxie.c
@@ -0,0 +1,369 @@
+/* Disassemble moxie instructions.
+   Copyright 2009
+   Free Software Foundation, Inc.
+
+   This file is part of the GNU opcodes library.
+
+   This library is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   It is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
+
+#include 
+#define STATIC_TABLE
+#define DEFINE_TABLE
+
+#include "disas/bfd.h"
+
+static void *stream;
+
+/* Form 1 instructions come in different flavors:
+
+   Some have no arguments                          (MOXIE_F1_NARG)
+   Some only use the A operand                     (MOXIE_F1_A)
+   Some use A and B registers                      (MOXIE_F1_AB)
+   Some use A and consume a 4 byte immediate value (MOXIE_F1_A4)
+   Some use just a 4 byte immediate value          (MOXIE_F1_4)
+   Some use just a 4 byte memory address           (MOXIE_F1_M)
+   Some use B and an indirect A                    (MOXIE_F1_AiB)
+   Some use A and an indirect B                    (MOXIE_F1_ABi)
+   Some consume a 4 byte immediate value and use X (MOXIE_F1_4A)
+   Some use B and an indirect A plus 4 bytes       (MOXIE_F1_AiB4)
+   Some use A and an indirect B plus 4 bytes       (MOXIE_F1_ABi4)
+
+   Form 2 instructions also come in different flavors:
+
+   Some have no arguments                          (MOXIE_F2_NARG)
+   Some use the A register and an 8-bit value      (MOXIE_F2_A8V)
+
+   Form 3 instructions also come in different flavors:
+
+   Some have no arguments                          (MOXIE_F3_NARG)
+   Some have a 10-bit PC relative operand          (MOXIE_F3_PCREL).  */
+
+#define MOXIE_F1_NARG 0x100
+#define MOXIE_F1_A    0x101
+#define MOXIE_F1_AB   0x102
+/* #define MOXIE_F1_ABC  0x103 */
+#define MOXIE_F1_A4   0x104
+#define MOXIE_F1_4    0x105
+#define MOXIE_F1_AiB  0x106
+#define MOXIE_F1_ABi  0x107
+#define MOXIE_F1_4A   0x108
+#define MOXIE_F1_AiB4 0x109
+#define MOXIE_F1_ABi4 0x10a
+#define MOXIE_F1_M    0x10b
+
+#define MOXIE_F2_NARG 0x200
+#define MOXIE_F2_A8V  0x201
+
+#define MOXIE_F3_NARG  0x300
+#define MOXIE_F3_PCREL 0x301
+
+typedef struct moxie_opc_info_t {
+  short         opcode;
+  unsigned      itype;
+  const char *  name;
+} moxie_opc_info_t;
+
+extern const moxie_opc_info_t moxie_form1_opc_info[64];
+extern const moxie_opc_info_t moxie_form2_opc_info[4];
+extern const moxie_opc_info_t moxie_form3_opc_info[16];
+
+/* The moxie processor's 16-bit instructions come in two forms:
+
+   FORM 1 instructions start with a 0 bit...
+
+   0ooo
+   0              F
+
+   ooo - form 1 opcode number
+       - operand A
+       - operand B
+
+   FORM 2 instr

[Qemu-devel] [PATCH moxie 1/5] New processor port

2013-02-13 Thread Anthony Green
Hello qemu maintainers,

  I have been maintaining a qemu port for moxie on github for a few
years now, and would now like to submit it upstream.  Moxie is a
soft-core architecture, similar to lm32 and microblaze.  The GNU
toolchain has supported moxie for several years now.  The qemu port is
very basic, but sufficient to bring up a uClinux kernel port.

Thank you,

Anthony Green


Signed-off-by: Anthony Green 
---
 MAINTAINERS | 5 +
 1 file changed, 5 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 21043e4..b970159 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -91,6 +91,11 @@ M: Aurelien Jarno 
 S: Odd Fixes
 F: target-mips/

+Moxie
+M: Anthony Green 
+S: Maintained
+F: target-moxie/
+
 PowerPC
 M: Alexander Graf 
 L: qemu-...@nongnu.org



Re: [Qemu-devel] [Qemu-ppc] [PATCH] Revert "Update OpenBIOS images"

2013-02-13 Thread Alexander Graf

On 14.02.2013, at 01:54, Mark Cave-Ayland wrote:

> On 14/02/13 00:17, Alexander Graf wrote:
> 
>> With the following patch fixing the issue at hand for me. Though I don't 
>> fully understand why str would be NULL yet:
>> 
>> 
>> diff --git a/packages/mac-parts.c b/packages/mac-parts.c
>> index a286870..443455e 100644
>> --- a/packages/mac-parts.c
>> +++ b/packages/mac-parts.c
>> @@ -140,7 +140,7 @@ macparts_open( macparts_info_t *di )
>>  * Implement partition selection as per the PowerPC Microprocessor 
>> CHRP bindings
>>  */
>> 
>> -   if (parnum == 0) {
>> +   if (str == NULL || parnum == 0) {
>> /* According to the spec, partition 0 as well as no 
>> arguments means the whole disk */
>> offs = (long long)0;
>> size = (long long)__be32_to_cpu(dmap.sbBlkCount) * bs;
>> 
>> Alex
> 
> Ah okay. It's actually caused by this bit of logic in libopenbios/bindings.c 
> and assuming that my_args() is a zero length Forth string:
> 
> char *
> pop_fstr_copy( void )
> {
>int len = POP();
>char *str, *p = (char*)cell2pointer(POP());
>if( !len )
>return NULL;
>str = malloc( len + 1 );
>if( !str )
>return NULL;
>memcpy( str, p, len );
>str[len] = 0;
>return str;
> }
> 
> The check for a zero length string and returning NULL has caused me problems 
> before when round-tripping strings between Forth and C.
> 
> Without testing the patch myself, I'd say that it looks good. I can run it 
> over my complete set of test images tomorrow evening if that would be 
> acceptable?

Either we get the fix in in the next few hours (and thus agree that it's the 
right way forward) or there's no rush - QEMU 1.5 is quite a while to go.

> Can you post a git diff version to the OpenBIOS mailing list too?

Sure!


Alex




Re: [Qemu-devel] [PATCH] Fix guest OS hangs on boot when 64bit PCI BAR present

2013-02-13 Thread Alexey Korolev
On 13/02/13 23:26, Michael S. Tsirkin wrote:
> On Wed, Feb 13, 2013 at 06:14:33PM +1300, Alexey Korolev wrote:
>> At the moment may_overlap flag of MemoryRegion structure
>> is ignored by the address range assignment process.
>> This may lead to guest OS hangs if critical qemu
>> resources are overlapped by PCI BARs. For example
>> ivshmem 64bit PCI BAR may overlap kvm-apic-msi under
>> certain conditions. This patch adds a rule that the
>> regions which should not be overlapped are added to the
>> view first (i.e. having highest priority). The patch
>> also corrects ivshmem bar resource to be overlapable
>> which is the default for PCI BARs
>>
>> Signed-off-by: Alexey Korolev 
> Since overlap is currently used inconsistently, it's hard to
> know what this will do. Maybe we should just drop the overlap
> flag and use priorities instead?
It sounds like a good idea.
>
>> ---
>>  hw/ivshmem.c |2 +-
>>  memory.c |   15 ++-
>>  2 files changed, 11 insertions(+), 6 deletions(-)
>>
>> diff --git a/hw/ivshmem.c b/hw/ivshmem.c
>> index afaf9b3..1770fa3 100644
>> --- a/hw/ivshmem.c
>> +++ b/hw/ivshmem.c
>> @@ -341,7 +341,7 @@ static void create_shared_memory_BAR(IVShmemState *s, 
>> int fd) {
>>  memory_region_init_ram_ptr(&s->ivshmem, "ivshmem.bar2",
>> s->ivshmem_size, ptr);
>>  vmstate_register_ram(&s->ivshmem, &s->dev.qdev);
>> -memory_region_add_subregion(&s->bar, 0, &s->ivshmem);
>> +memory_region_add_subregion_overlap(&s->bar, 0, &s->ivshmem, 1);
>>  
>>  /* region for shared memory */
>>  pci_register_bar(&s->dev, 2, s->ivshmem_attr, &s->bar);
> So why this change, exactly?
memory_region_add_subregion adds a non-overlappable memory region, this is 
incorrect, becauase rest PCI bars by default are overlappable.
I replaced memory_region_add_subregion with memory_region_add_subregion_overlap 
to make the region overlappable so it doesn't  compete with
kvm-apic-msi for address range.

In other words without this change ivshmem.bar2 will occupy address range of 
kvm-apic-msi because they have same priority and flags.

>
>> diff --git a/memory.c b/memory.c
>> index cd7d5e0..f1119e7 100644
>> --- a/memory.c
>> +++ b/memory.c
>> @@ -475,7 +475,8 @@ static void render_memory_region(FlatView *view,
>>   MemoryRegion *mr,
>>   Int128 base,
>>   AddrRange clip,
>> - bool readonly)
>> + bool readonly,
>> + bool overlap)
>>  {
>>  MemoryRegion *subregion;
>>  unsigned i;
>> @@ -503,16 +504,16 @@ static void render_memory_region(FlatView *view,
>>  if (mr->alias) {
>>  int128_subfrom(&base, int128_make64(mr->alias->addr));
>>  int128_subfrom(&base, int128_make64(mr->alias_offset));
>> -render_memory_region(view, mr->alias, base, clip, readonly);
>> +render_memory_region(view, mr->alias, base, clip, readonly, 
>> overlap);
>>  return;
>>  }
>>  
>>  /* Render subregions in priority order. */
>>  QTAILQ_FOREACH(subregion, &mr->subregions, subregions_link) {
>> -render_memory_region(view, subregion, base, clip, readonly);
>> +render_memory_region(view, subregion, base, clip, readonly, 
>> overlap);
>>  }
>>  
>> -if (!mr->terminates) {
>> +if (mr->may_overlap != overlap || !mr->terminates) {
>>  return;
>>  }
>>  
>> @@ -567,7 +568,11 @@ static FlatView generate_memory_topology(MemoryRegion 
>> *mr)
>>  
>>  if (mr) {
>>  render_memory_region(&view, mr, int128_zero(),
>> - addrrange_make(int128_zero(), int128_2_64()), 
>> false);
>> + addrrange_make(int128_zero(), int128_2_64()),
>> + false, false);
>> +render_memory_region(&view, mr, int128_zero(),
>> + addrrange_make(int128_zero(), int128_2_64()),
>> + false, true);
>>  }
>>  flatview_simplify(&view);
>>  
>> -- 
>> 1.7.9.5




Re: [Qemu-devel] [Qemu-ppc] [PATCH] Revert "Update OpenBIOS images"

2013-02-13 Thread Mark Cave-Ayland

On 14/02/13 00:17, Alexander Graf wrote:


With the following patch fixing the issue at hand for me. Though I don't fully 
understand why str would be NULL yet:


diff --git a/packages/mac-parts.c b/packages/mac-parts.c
index a286870..443455e 100644
--- a/packages/mac-parts.c
+++ b/packages/mac-parts.c
@@ -140,7 +140,7 @@ macparts_open( macparts_info_t *di )
  * Implement partition selection as per the PowerPC Microprocessor 
CHRP bindings
  */

-   if (parnum == 0) {
+   if (str == NULL || parnum == 0) {
 /* According to the spec, partition 0 as well as no arguments 
means the whole disk */
 offs = (long long)0;
 size = (long long)__be32_to_cpu(dmap.sbBlkCount) * bs;

Alex


Ah okay. It's actually caused by this bit of logic in 
libopenbios/bindings.c and assuming that my_args() is a zero length 
Forth string:


char *
pop_fstr_copy( void )
{
int len = POP();
char *str, *p = (char*)cell2pointer(POP());
if( !len )
return NULL;
str = malloc( len + 1 );
if( !str )
return NULL;
memcpy( str, p, len );
str[len] = 0;
return str;
}

The check for a zero length string and returning NULL has caused me 
problems before when round-tripping strings between Forth and C.


Without testing the patch myself, I'd say that it looks good. I can run 
it over my complete set of test images tomorrow evening if that would be 
acceptable? Can you post a git diff version to the OpenBIOS mailing list 
too?



ATB,

Mark.



Re: [Qemu-devel] [Qemu-ppc] [PATCH] Revert "Update OpenBIOS images"

2013-02-13 Thread Alexander Graf

On 14.02.2013, at 01:01, Mark Cave-Ayland wrote:

> On 13/02/13 23:45, Alexander Graf wrote:
> 
>>> The release is basically done. I don't think we have time for any fix 
>>> beyond reverting the commit. And I'd rather have it reverted, since we 
>>> regress heavily against 1.3 with the updated OpenBIOS.
>> 
>> [12:43am]aliguori:agraf, i can wait until the very start (7am my time) of 
>> tomorrow morning to tag -rc2 if you think having a little more time would be 
>> helpful here
>> [12:43am]agraf:aliguori: but to me a regression weighs more than missing bug 
>> fixes
>> [12:43am]agraf:aliguori: if mark can debug this down within that time, would 
>> that work for you?
>> [12:43am]aliguori:agraf, yes
>> 
>> Mark, do you think you could narrow this down within the next few hours? Or 
>> rather - would you like to give it a try?
> 
> H if I had to guess which patch may stop quik from booting then I'd go 
> with this one: 
> http://git.qemu.org/?p=openbios.git;a=commit;h=3caf41bf4a0f9ef7c8b294aca69fbe3366aec21b.

Nope, that's not the one. Reverting it doesn't help.

OpenBIOS gets stuck because it accesses an illegal instruction at a very odd 
address:

(gdb) x /10i 0x03e0014
0x3e0014:   lfduf23,5483(r10)
0x3e0018:   lhaur7,-19710(r11)
0x3e001c:   andi.   r3,r24,19569
0x3e0020:   stmwr19,-15465(r26)
0x3e0024:   bdzt-   4*cr3+so,0x3dbf20
0x3e0028:   lfquf14,-9471(r10)
0x3e002c:   .long 0x4f1bbde8
0x3e0030:   stwur1,-25243(r3)
0x3e0034:   addis   r9,r3,17526
0x3e0038:   lha r19,3371(r26)

This almost looks as if it's jumping into some data section - maybe forth 
bytecode or so.


> 
> Unfortunately at the moment I can't build qemu master after git pull (even 
> with a make distclean) as I get the following compile error:
> 
> cc -I. -I/home/build/src/qemu/git/qemu 
> -I/home/build/src/qemu/git/qemu/include -Werror -fPIE -DPIE -m64 
> -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes 
> -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes 
> -fno-strict-aliasing  -fstack-protector-all -Wendif-labels 
> -Wmissing-include-dirs -Wempty-body -Wnested-externs -Wformat-security 
> -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration 
> -Wold-style-definition -Wtype-limits -I/usr/include/p11-kit-1 
> -I/usr/include/libpng12 -I/usr/include/pixman-1   -Iutil -Iutil -pthread 
> -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include   -I 
> qga/qapi-generated -MMD -MP -MT util/acl.o -MF util/acl.d -O2 
> -D_FORTIFY_SOURCE=2 -g  -c -o util/acl.o util/acl.c
> util/hbitmap.c: In function ‘hbitmap_iter_skip_words’:
> util/hbitmap.c:137:5: error: implicit declaration of function 
> ‘trace_hbitmap_iter_skip_words’ [-Werror=implicit-function-declaration]
> util/hbitmap.c:137:5: error: nested extern declaration of 
> ‘trace_hbitmap_iter_skip_words’ [-Werror=nested-externs]
> util/hbitmap.c: In function ‘hbitmap_set’:
> util/hbitmap.c:270:5: error: implicit declaration of function 
> ‘trace_hbitmap_set’ [-Werror=implicit-function-declaration]
> util/hbitmap.c:270:5: error: nested extern declaration of ‘trace_hbitmap_set’ 
> [-Werror=nested-externs]
> util/hbitmap.c: In function ‘hbitmap_reset’:
> util/hbitmap.c:350:5: error: implicit declaration of function 
> ‘trace_hbitmap_reset’ [-Werror=implicit-function-declaration]
> util/hbitmap.c:350:5: error: nested extern declaration of 
> ‘trace_hbitmap_reset’ [-Werror=nested-externs]
> cc1: all warnings being treated as errors
> make: *** [util/hbitmap.o] Error 1
> make: *** Waiting for unfinished jobs
> 
> On the basis of that, it's unlikely to get fixed by 7am tomorrow morning but 
> I am still happy to make debugging this a priority.

Does a fresh checkout work? If that takes too long you probably want to remove 
the generated trace header files. Tracing is a constant pain point when you 
track the QEMU git.


Alex




Re: [Qemu-devel] [Qemu-ppc] [PATCH] Revert "Update OpenBIOS images"

2013-02-13 Thread Alexander Graf

On 14.02.2013, at 01:04, Alexander Graf wrote:

> 
> On 14.02.2013, at 01:01, Mark Cave-Ayland wrote:
> 
>> On 13/02/13 23:45, Alexander Graf wrote:
>> 
 The release is basically done. I don't think we have time for any fix 
 beyond reverting the commit. And I'd rather have it reverted, since we 
 regress heavily against 1.3 with the updated OpenBIOS.
>>> 
>>> [12:43am]aliguori:agraf, i can wait until the very start (7am my time) of 
>>> tomorrow morning to tag -rc2 if you think having a little more time would 
>>> be helpful here
>>> [12:43am]agraf:aliguori: but to me a regression weighs more than missing 
>>> bug fixes
>>> [12:43am]agraf:aliguori: if mark can debug this down within that time, 
>>> would that work for you?
>>> [12:43am]aliguori:agraf, yes
>>> 
>>> Mark, do you think you could narrow this down within the next few hours? Or 
>>> rather - would you like to give it a try?
>> 
>> H if I had to guess which patch may stop quik from booting then I'd go 
>> with this one: 
>> http://git.qemu.org/?p=openbios.git;a=commit;h=3caf41bf4a0f9ef7c8b294aca69fbe3366aec21b.
> 
> Nope, that's not the one. Reverting it doesn't help.

65bbf2e226266d8f7de0e23b584e184bac5fd273 is first bad commit
commit 65bbf2e226266d8f7de0e23b584e184bac5fd273
Author: mcayland 
Date:   Sat Nov 24 14:43:09 2012 +

Fix dir cd:,\ (no partition specified) when reading from Mac partitions.

The existing checks in mac-parts,c were wrong; regardless of whether or not 
we
have an argument string specified, if a partition is not specified then we
must still search for the first valid partition.

Signed-off-by: Mark Cave-Ayland 

git-svn-id: svn://openfirmware.info/openbios/trunk/openbios-devel@1072 
f158a5a8-5612-0410-a976-696ce0be7e32

:04 04 18be4df16bc546c313051b01cd0587b2a6faacdf 
f4815007b57d11018edc2293db3ccd1e01adf6cb M  packages


With the following patch fixing the issue at hand for me. Though I don't fully 
understand why str would be NULL yet:


diff --git a/packages/mac-parts.c b/packages/mac-parts.c
index a286870..443455e 100644
--- a/packages/mac-parts.c
+++ b/packages/mac-parts.c
@@ -140,7 +140,7 @@ macparts_open( macparts_info_t *di )
 * Implement partition selection as per the PowerPC Microprocessor CHRP 
bindings
 */
 
-   if (parnum == 0) {
+   if (str == NULL || parnum == 0) {
/* According to the spec, partition 0 as well as no arguments 
means the whole disk */
offs = (long long)0;
size = (long long)__be32_to_cpu(dmap.sbBlkCount) * bs;

Alex




Re: [Qemu-devel] [Qemu-ppc] [PATCH] Revert "Update OpenBIOS images"

2013-02-13 Thread Mark Cave-Ayland

On 13/02/13 23:45, Alexander Graf wrote:


The release is basically done. I don't think we have time for any fix beyond 
reverting the commit. And I'd rather have it reverted, since we regress heavily 
against 1.3 with the updated OpenBIOS.


[12:43am]aliguori:agraf, i can wait until the very start (7am my time) of 
tomorrow morning to tag -rc2 if you think having a little more time would be 
helpful here
[12:43am]agraf:aliguori: but to me a regression weighs more than missing bug 
fixes
[12:43am]agraf:aliguori: if mark can debug this down within that time, would 
that work for you?
[12:43am]aliguori:agraf, yes

Mark, do you think you could narrow this down within the next few hours? Or 
rather - would you like to give it a try?


H if I had to guess which patch may stop quik from booting then I'd 
go with this one: 
http://git.qemu.org/?p=openbios.git;a=commit;h=3caf41bf4a0f9ef7c8b294aca69fbe3366aec21b.


Unfortunately at the moment I can't build qemu master after git pull 
(even with a make distclean) as I get the following compile error:


cc -I. -I/home/build/src/qemu/git/qemu 
-I/home/build/src/qemu/git/qemu/include -Werror -fPIE -DPIE -m64 
-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE 
-Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings 
-Wmissing-prototypes -fno-strict-aliasing  -fstack-protector-all 
-Wendif-labels -Wmissing-include-dirs -Wempty-body -Wnested-externs 
-Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers 
-Wold-style-declaration -Wold-style-definition -Wtype-limits 
-I/usr/include/p11-kit-1 -I/usr/include/libpng12 
-I/usr/include/pixman-1   -Iutil -Iutil -pthread -I/usr/include/glib-2.0 
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include   -I qga/qapi-generated 
-MMD -MP -MT util/acl.o -MF util/acl.d -O2 -D_FORTIFY_SOURCE=2 -g  -c -o 
util/acl.o util/acl.c

util/hbitmap.c: In function ‘hbitmap_iter_skip_words’:
util/hbitmap.c:137:5: error: implicit declaration of function 
‘trace_hbitmap_iter_skip_words’ [-Werror=implicit-function-declaration]
util/hbitmap.c:137:5: error: nested extern declaration of 
‘trace_hbitmap_iter_skip_words’ [-Werror=nested-externs]

util/hbitmap.c: In function ‘hbitmap_set’:
util/hbitmap.c:270:5: error: implicit declaration of function 
‘trace_hbitmap_set’ [-Werror=implicit-function-declaration]
util/hbitmap.c:270:5: error: nested extern declaration of 
‘trace_hbitmap_set’ [-Werror=nested-externs]

util/hbitmap.c: In function ‘hbitmap_reset’:
util/hbitmap.c:350:5: error: implicit declaration of function 
‘trace_hbitmap_reset’ [-Werror=implicit-function-declaration]
util/hbitmap.c:350:5: error: nested extern declaration of 
‘trace_hbitmap_reset’ [-Werror=nested-externs]

cc1: all warnings being treated as errors
make: *** [util/hbitmap.o] Error 1
make: *** Waiting for unfinished jobs

On the basis of that, it's unlikely to get fixed by 7am tomorrow morning 
but I am still happy to make debugging this a priority.



ATB,

Mark.



Re: [Qemu-devel] [Qemu-ppc] [PATCH] Revert "Update OpenBIOS images"

2013-02-13 Thread Alexander Graf

On 14.02.2013, at 00:41, Alexander Graf wrote:

> 
> On 14.02.2013, at 00:38, Mark Cave-Ayland wrote:
> 
>> On 13/02/13 22:58, Alexander Graf wrote:
>> 
>>> This reverts commit 10442558ab1797bfbb01285b909e34c5cf038f12.
>>> 
>>> With the updated OpenBIOS image, -M g3beige fails to boot quik.
>> 
>> Hi Alex,
>> 
>> Can you point me towards a test ISO image for this?
> 
> Sure!
> 
> http://people.debian.org/~aurel32/qemu/powerpc/debian_lenny_powerpc_standard.qcow2
> 
>> There are so many other PPC fixes in OpenBIOS worth having that I'd hope 
>> we'd only have to consider this as a last resort.
> 
> The release is basically done. I don't think we have time for any fix beyond 
> reverting the commit. And I'd rather have it reverted, since we regress 
> heavily against 1.3 with the updated OpenBIOS.

[12:43am]aliguori:agraf, i can wait until the very start (7am my time) of 
tomorrow morning to tag -rc2 if you think having a little more time would be 
helpful here
[12:43am]agraf:aliguori: but to me a regression weighs more than missing bug 
fixes
[12:43am]agraf:aliguori: if mark can debug this down within that time, would 
that work for you?
[12:43am]aliguori:agraf, yes

Mark, do you think you could narrow this down within the next few hours? Or 
rather - would you like to give it a try?


Alex




Re: [Qemu-devel] [Qemu-ppc] [PATCH] Revert "Update OpenBIOS images"

2013-02-13 Thread Alexander Graf

On 14.02.2013, at 00:38, Mark Cave-Ayland wrote:

> On 13/02/13 22:58, Alexander Graf wrote:
> 
>> This reverts commit 10442558ab1797bfbb01285b909e34c5cf038f12.
>> 
>> With the updated OpenBIOS image, -M g3beige fails to boot quik.
> 
> Hi Alex,
> 
> Can you point me towards a test ISO image for this?

Sure!

http://people.debian.org/~aurel32/qemu/powerpc/debian_lenny_powerpc_standard.qcow2

> There are so many other PPC fixes in OpenBIOS worth having that I'd hope we'd 
> only have to consider this as a last resort.

The release is basically done. I don't think we have time for any fix beyond 
reverting the commit. And I'd rather have it reverted, since we regress heavily 
against 1.3 with the updated OpenBIOS.


Alex




Re: [Qemu-devel] [PATCH] Revert "Update OpenBIOS images"

2013-02-13 Thread Mark Cave-Ayland

On 13/02/13 22:58, Alexander Graf wrote:


This reverts commit 10442558ab1797bfbb01285b909e34c5cf038f12.

With the updated OpenBIOS image, -M g3beige fails to boot quik.


Hi Alex,

Can you point me towards a test ISO image for this? There are so many 
other PPC fixes in OpenBIOS worth having that I'd hope we'd only have to 
consider this as a last resort.



ATB,

Mark.



[Qemu-devel] [PATCH moxie 4/5] Add sample moxie system

2013-02-13 Thread Anthony Green
Add a simple moxie target, similar to what we have in the gdb simulator today.


Signed-off-by: Anthony Green 
---
 hw/moxie/Makefile.objs |   5 ++
 hw/moxiesim.c  | 200 +
 include/sysemu/arch_init.h |   1 +
 3 files changed, 206 insertions(+)
 create mode 100644 hw/moxie/Makefile.objs
 create mode 100644 hw/moxiesim.c

diff --git a/hw/moxie/Makefile.objs b/hw/moxie/Makefile.objs
new file mode 100644
index 000..2963363
--- /dev/null
+++ b/hw/moxie/Makefile.objs
@@ -0,0 +1,5 @@
+# moxie boards
+obj-y = moxiesim.o serial.o mc146818rtc.o vga.o
+obj-$(CONFIG_FDT) += device_tree.o
+
+obj-y := $(addprefix ../,$(obj-y))
diff --git a/hw/moxiesim.c b/hw/moxiesim.c
new file mode 100644
index 000..feae538
--- /dev/null
+++ b/hw/moxiesim.c
@@ -0,0 +1,200 @@
+/*
+ * QEMU/moxiesim emulation
+ *
+ * Emulates a very simple machine model similiar to the one use by the
+ * GDB moxie simulator.
+ *
+ * Copyright (c) 2008, 2009, 2010 Anthony Green
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the
"Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "sysbus.h"
+#include "hw.h"
+#include "pc.h"
+#include "isa.h"
+#include "net/net.h"
+#include "sysemu/sysemu.h"
+#include "boards.h"
+#include "loader.h"
+#include "serial.h"
+#include "exec/address-spaces.h"
+
+#define PHYS_MEM_BASE 0x8000
+
+static struct _loaderparams {
+int ram_size;
+const char *kernel_filename;
+const char *kernel_cmdline;
+const char *initrd_filename;
+} loaderparams;
+
+static void load_kernel (CPUMoxieState *env)
+{
+uint64_t entry, kernel_low, kernel_high;
+long kernel_size;
+long initrd_size;
+ram_addr_t initrd_offset;
+
+kernel_size = load_elf(loaderparams.kernel_filename,  NULL, NULL,
+   &entry, &kernel_low, &kernel_high, 1,
ELF_MACHINE, 0);
+if (kernel_size >= 0)
+  env->pc = (unsigned) entry;
+else
+  {
+fprintf(stderr, "qemu: could not load kernel '%s'\n",
+loaderparams.kernel_filename);
+exit(1);
+  }
+
+/* load initrd */
+initrd_size = 0;
+initrd_offset = 0;
+if (loaderparams.initrd_filename) {
+initrd_size = get_image_size (loaderparams.initrd_filename);
+if (initrd_size > 0) {
+initrd_offset = (kernel_high + ~TARGET_PAGE_MASK) &
TARGET_PAGE_MASK;
+if (initrd_offset + initrd_size > loaderparams.ram_size) {
+fprintf(stderr,
+"qemu: memory too small for initial ram disk '%s'\n",
+loaderparams.initrd_filename);
+exit(1);
+}
+initrd_size = load_image_targphys(loaderparams.initrd_filename,
+  initrd_offset,
+  ram_size);
+}
+if (initrd_size == (target_ulong) -1) {
+fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
+loaderparams.initrd_filename);
+exit(1);
+}
+}
+}
+
+static void main_cpu_reset(void *opaque)
+{
+MoxieCPU *cpu = opaque;
+
+cpu_reset(CPU(cpu));
+}
+
+static inline DeviceState *
+moxie_intc_create(hwaddr base, qemu_irq irq, int kind_of_intr)
+{
+DeviceState *dev;
+
+dev = qdev_create(NULL, "moxie,intc");
+qdev_prop_set_uint32(dev, "kind-of-intr", kind_of_intr);
+qdev_init_nofail(dev);
+sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
+sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq);
+return dev;
+}
+
+static void moxiesim_init(QEMUMachineInitArgs *args)
+{
+MoxieCPU *cpu = NULL;
+ram_addr_t ram_size = args->ram_size;
+const char *cpu_model = args->cpu_model;
+const char *kernel_filename = args->kernel_filename;
+const char *kernel_cmdline = args->kernel_cmdline;
+const char *initrd_filename = args->initrd_filename;
+CPUMoxieState *env;
+MemoryRegion *address_space_mem = get_syst

Re: [Qemu-devel] using -net dump with tap networking

2013-02-13 Thread Paolo Bonzini
Il 13/02/2013 19:02, Laszlo Ersek ha scritto:
>> > I am running qemu as:
>> >
>> > qemu/ppc64-softmmu/qemu-system-ppc64 -m 1024 -M pseries -trace
>> > events=trace_events -netdev user,id=virtnet,hostfwd=tcp::5000-:22
>> > -device virtio-net-pci,netdev=virtnet -nographic -vga none -enable-kvm
>> > -kernel vml36_64k -initrd 1.cpio
>> >
>> > Now I want to enable network dump. With the old "-net" syntax I could do
>> > that with "-net dump" but I cannot with the new syntax, tried many
>> > variants, none works. What would the correct syntax be for the case above?
> Ugh, I'm a bit confused, but if I say something stupid that should still
> help "ignite" the discussion.
> 
> So, in general there are two ways to specify this:
> 
> (1) -net dump,id=dump0,vlan=VLAN_ID,len=SIZE_LIMIT,file=PATHNAME
> 
> (2) -netdev dump,id=dump0,len=SIZE_LIMIT,file=PATHNAME
> 
> I believe the first option (legacy) should work.

Yes.  -net dump is meant to be used with vlans: you typically use a
3-port VLAN (actually a hub, not just in code but also as a mental
model) with a tap device, a NIC and the dumper.

> Hence I think you're back to (1), the legacy format. Assuming qemu
> doesn't barf on that option immediately, I believe you *also* have to
> add your "-netdev user" to the same hub as the dumper is on.
> 
> In total you have to create both netdevs (a, b) and assign both to a
> common hub/vlan (c, d). Again, unfortunately the dump netdev only works
> with the legacy format, but that already includes the assignment to the
> hub (a, c). So you have to take care of creating the other netdev
> (-netdev user, b), and assign it through its vlan qdev property to the
> same hub (d), so that data can flow from it to the dump netdev.
> 
> Hm... Looks like you can't do that directly on "-netdev user" (it seems
> to have no such property).

Right, just use "-net user"/"-net tap" and it will create both a hub
port and a backend.

> "virtio-net-pci" does have it however. At
> least in a quick "info qtree" check:
> 
> bus: main-system-bus
>   type System
>   dev: i440FX-pcihost, id ""
> bus: pci.0
>   type PCI
>   dev: virtio-net-pci, id "net0"
> dev-prop: vlan = 
> 
> Also confirmed by "qemu-system-x86_64 -device virtio-net-pci,help".

It may well be broken.  In this case, again just use "-net nic".

I learnt yesterday that the legacy syntax disables checksum and
fragmentation offloading.  The reason is that peer_test_vnet_hdr only
work if the NIC is connected directly to the TAP device, with no hubs in
between.  Anyway you probably don't care about that if you want to get
dumps; in fact having correct checksums in the dumps will probably help.

Paolo



Re: [Qemu-devel] [BUG] Guest OS hangs on boot when 64bit BAR present (kvm-apic -msi resource conflict)

2013-02-13 Thread Alexey Korolev

> On Wed, Feb 13, 2013 at 11:34:52AM +0100, Jan Kiszka wrote:
>> On 2013-02-13 11:24, Michael S. Tsirkin wrote:
>>> On Wed, Feb 13, 2013 at 06:06:37PM +1300, Alexey Korolev wrote:
 Sometime ago I reported an issue about guest OS hang when 64bit BAR 
 present.
 http://lists.gnu.org/archive/html/qemu-devel/2012-01/msg03189.html
 http://lists.gnu.org/archive/html/qemu-devel/2012-12/msg00413.html

 Some more investigation has been done, so in this post I'll try to explain 
 why it happens and offer possible solutions:

 *When the issue happens*
 The issue occurs on Linux guest OS if kernel version <2.6.36
 A Guest OS hangs on boot when a 64bit PCI BAR is present in a system (if 
 we use ivshmem driver for example) and occupies range within first
 4 GB.

 *How to reproduce*
 I used the following qemu command to reproduce the case:
 /usr/local/bin/qemu-system-x86_64 -M pc-1.3 -enable-kvm -m 2000 -smp 
 1,sockets=1,cores=1,threads=1 -name Rh5332 -chardev
 socket,id=charmonitor,path=/var/lib/libvirt/qemu/Rh5332.monitor,server,nowait
  -mon chardev=charmonitor,id=monitor,mode=readline -rtc
 base=utc -boot cd -drive 
 file=/home/akorolev/rh5332.img,if=none,id=drive-ide0-0-0,format=raw -device
 ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 -chardev 
 file,id=charserial0,path=/home/akorolev/serial.log -device
 isa-serial,chardev=charserial0,id=serial0 -usb -vnc 127.0.0.1:0 -k en-us 
 -vga cirrus -device ivshmem,shm,size=32M-device
 virtio-balloon-pci,id=balloon0

 Tried different guests: Centos 5.8 64bit, RHEL 5.3 32bit, FC 12 64bit on 
 all machines hang occurs in 100% cases

 *Why it happens*
 The issue basically comes from Linux PCI enumeration code.

 The OS enumerates 64BIT bars when device is enabled using the following 
 procedure.
 1. Write all FF's to lower half of 64bit BAR
 2. Write address back to lower half of 64bit BAR
 3. Write all FF's to higher half of 64bit BAR
 4. Write address back to higher half of 64bit BAR

 For qemu it means that  qemu pci_default_write_config() recevies all FFs 
 for lower part of the 64bit BAR.
 Then it applies the mask and converts the value to "All FF's - size + 1" 
 (FE00 if size is 32MB).

 So for short period of time the range [0xFE00 - 0x] will be 
 occupied by ivshmem resource.
 For some reason it is lethal for further boot process.

 We have found that boot process screws up completely if kvm-apic-msi range 
 is overlapped even for short period of time.  (We still don't
 know why it happens, hope that the qemu maintainers can answer?)

 If we look at kvm-apic-msi memory region it is a non-overlapable memory 
 region with hardcoded address range [0xFEE0 - 0xFEF0].
>>> Thanks for looking into this!
>>>
 Here is a log we collected from render_memory_regions:

  system overlap 0 pri 0 [0x0 - 0x7fff]
  kvmvapic-rom overlap 1 pri 1000 [0xca000 - 0xcd000]
  pc.ram overlap 0 pri 0 [0xca000 - 0xcd000]
  ++ pc.ram [0xca000 - 0xcd000] is added to view
  
  smram-region overlap 1 pri 1 [0xa - 0xc]
  pci overlap 0 pri 0 [0xa - 0xc]
  cirrus-lowmem-container overlap 1 pri 1 [0xa - 0xc]
  cirrus-low-memory overlap 0 pri 0 [0xa - 0xc]
 ++cirrus-low-memory [0xa - 0xc] is added to view
  kvm-ioapic overlap 0 pri 0 [0xfec0 - 0xfec01000]
 ++kvm-ioapic [0xfec0 - 0xfec01000] is added to view
  pci-hole64 overlap 0 pri 0 [0x1 - 0x4001]
  pci overlap 0 pri 0 [0x1 - 0x4001]
  pci-hole overlap 0 pri 0 [0x7d00 - 0x1]
>>> So we have ioapic and pci-hole which should be non-overlap,
>>> actually overlap each other.
>>> Isn't this a problem?
>>>
  pci overlap 0 pri 0 [0x7d00 - 0x1]
  ivshmem-bar2-container overlap 1 pri 1 [0xfe00 - 
 0x1]
  ivshmem.bar2 overlap 0 pri 0 [0xfe00 - 0x1]
 ++ivshmem.bar2 [0xfe00 - 0xfec0] is added to view
 ++ivshmem.bar2  [0xfec01000 - 0x1] is added to view
  ivshmem-mmio overlap 1 pri 1 [0xfebf1000 - 0xfebf1100]
  e1000-mmio overlap 1 pri 1 [0xfeba - 0xfebc]
  cirrus-mmio overlap 1 pri 1 [0xfebf - 0xfebf1000]
  cirrus-pci-bar0 overlap 1 pri 1 [0xfa00 - 0xfc00]
  vga.vram overlap 1 pri 1 [0xfa00 - 0xfa80]
 ++vga.vram [0xfa00 - 0xfa80] is added to view
  cirrus-bitblt-mmio overlap 0 pri 0 [0xfb00 - 
 0xfb4000

Re: [Qemu-devel] [PATCH v2] Move File operations to qemu-file.c

2013-02-13 Thread Joel Schopp



+if(popen_file == NULL) {


Please make a preparatory patch which adds missing spaces between 'if'
statements and '('.


I'll do a preparatory style cleanup patch of existing code if it is 
deemed necessary by the maintainers, but I don't think it's a good idea. 
 The patch as it stands now simply moves existing code to another file 
and thus is pretty safe.  Adding a preparatory patch to reformat the 
code is easy to mess up and raises the chances of introducing a regression.


Why not just submit patches to clean up coding style for the entire code 
base independent of any refactoring?


When I originally wrote checkpatch.pl it was with the intention of 
avoiding arguments over coding style.  I see that I missed a corner case 
by having it not notice code moves as a special case to ignore.


-Joel




Re: [Qemu-devel] [PATCH 3/5] target-i386: Slim conversion to X86CPU subclasses

2013-02-13 Thread Eduardo Habkost

TL;DR: I still disagree about some points, but those points aren't so
relevant anymore because I am starting to like having
KVM-specific/TCG-specific subclasses (because of other problems that
would be solved by them).


On Wed, Feb 13, 2013 at 04:20:43PM +0100, Igor Mammedov wrote:
[...]
> > > > > > 
> > > > > > My big question is: why exactly we want to initialize this stuff
> > > > > > inside class_init? Can't we (please!) put the KVM-specific logic
> > > > > > inside instance_init?
> > > I see 2 issues with it:
> > > 1. a rather abstract introspection. defaults are belong to class data and
> > >user who introspected class would expect to get CPU he saw during it,
> > > which he won't get if instance_init() will set another defaults, It will
> > > be already another CPU. So introspection becomes useless here.
> > 
> > Really, it does not become useless, it has very clear semantics. The
> > difference is that now the defaults won't depend on the kvm=on/off
> > configuration.
> >
> > I believe strongly that one of the purposes of class-based introspection
> > is to have introspectable _static_ data that do not depend on any
> > configuration data.
> It isn't static (look at model_id in class_init), I'd say it should be
> immutable after class is initialized, which means it could be determined
> dynamically in class_init.

That's were I believe we disagree. It's not about being immutable, it's
about being introspectable before anything is configured.

We could change the values between QEMU versions (it would be nice to
avoid it, but not a must), but we can't make depend on configuration
data unless we find a solution to the dependency/ordering problem.

Note that I would be happy enough if the QEMU maintainers decided that
CPUs are special for QEMU and the CPU classes must be initialized very
late, or that accelerator initialization is special and can happen
before any class is initialized. But we must make an explicit decision
about that, if we want to. That's why I listed the posible options I
see, below (after the paragraph I say "I believe the current dependency
chain is").


> > > 
> > > 2. more close to code:
> > > * vendor property, you offering to add a new tcg-vendor property. If
> > > we are dumping goal [1] then it might work.
> > 
> > We're now dumping goal [1], we would be enabling it to be achieved,
> > because the default values of "vendor" and "tcg-vendor" would be
> > completely static.
> > 
> > The assumption you seem to be unwilling to drop is that cpuid_vendor
> > should always unconditionally correspond to the value of the "vendor"
> > property set by the class. But it doesn't have to. The CPU class may
> > choose to do anything with cpuid_vendor on instance_init, including
> > using the "tcg-vendor" property to set it if KVM is disabled and
> > "vendor" is empty.
> > 
> > 
> > > But that new property is just
> > >   another reincarnation of vendor_override field in CPUState that
> > > we've just gotten rid of and brings back hack of selecting what guest os
> > > will see.
> > 
> > In a way, yes. But it looks like it is necessary. But at least is a very
> > understandable model that can be seen from the outside. "tcg-vendor" is
> > obviously tcg-only, and "vendor" overrides everything if set.
> I'm not sure it's necessary and I dislike adding extra semantics to CPU
> unless it's how it's made in real hardware or we have to due to lack of
> another way to implement it correctly. CPUID has only one 'vendor' so lets
> try to make it work instead of working around deficiencies of current
> modeling.

We are not adding "extra" semantics, we are just modelling the existing
(weird) KVM vs. TCG semantics, unfortunately. The class model is not
just a hardware model, but a "configuration data" model.

AFAIU, not every property is about modelling hardware, but also about
modelling the knobs we ahve to configure the software. The block device
"cache" option is not about modelling hardware, the virtio-net "timer"
option is not about modelling hardware.

So, if we have to keep the weird semantics, the point is that the weird
semantics belong to instance_init and not class_init (because of the
ordering/dependency problem we have).

> 
> > 
> > 
> > > * cpuid_kvm_features defaults also different for KVM and TCG. Which
> > > also makes 2 different CPUs, and makes guest behave differently.
> > >   If we set defaults in instance_init(), we would loose possibility
> > > to use global(cmd line) and compat(pv_eoi) properties with respective
> > >   feature bits or invent another special case to detect that
> > >   global/compat properties were used and workaround it.
> > 
> > I don't propose setting property defaults on instance_init. I propose
> > using the _static_ defaults set by class_init to initialize the CPU
> > state on instance_init. Just like nobody said that the CPU _must_
> > initialize cpuid_vendor using the "vendor" property only, nobody said
> > that the CPU can'

[Qemu-devel] [Bug 955379] Re: cmake hangs with qemu-arm-static

2013-02-13 Thread Dereck Wonnacott
I wouldn't mind giving this patch a test if given some instructions on
doing so.

I am also unable to compile pcl because of this bug.

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

Title:
  cmake hangs with qemu-arm-static

Status in QEMU:
  Confirmed
Status in Linaro QEMU:
  Confirmed
Status in “qemu-linaro” package in Ubuntu:
  Confirmed

Bug description:
  I'm using git commit 3e7ecd976b06f... configured with --target-list
  =arm-linux-user --static in a chroot environment to compile some
  things. I ran into this problem with both pcl and opencv-2.3.1. cmake
  consistently freezes at some point during its execution, though in a
  different spot each time, usually during a step when it's searching
  for some libraries. For instance, pcl most commonly stops after:

  [snip]
  -- Boost version: 1.46.1
  -- Found the following Boost libraries:
  --   system
  --   filesystem
  --   thread
  --   date_time
  -- checking for module 'eigen3'
  --   found eigen3, version 3.0.1

  which is perplexing because it freezes after finding what it wants,
  not during the search. When it does get past that point, it does so
  almost immediately but freezes somewhere else.

  I'm using 64-bit Ubuntu 11.10 with kernel release 3.0.0-16-generic
  with an Intel i5.

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



Re: [Qemu-devel] [PATCH v2] Move File operations to qemu-file.c

2013-02-13 Thread Blue Swirl
On Wed, Feb 13, 2013 at 8:43 PM, Joel Schopp  wrote:
> This patch reorganizes qemu file operations to be in their own source file
> instead of being lumped in savevm.c.  Besides being more logical for 
> maintenance
> it also makes it easier for future users of the file functions to add tests.
>
> v2 forward port to resolve conflicts, strip trailing whitespace during move
>
> Signed-off-by: Stefan Berger 
> Signed-off-by: Joel Schopp 
> ---
>  Makefile.objs |2
>  include/migration/qemu-file.h |4
>  qemu-file.c   |  670 
> ++
>  savevm.c  |  646 
>  4 files changed, 675 insertions(+), 647 deletions(-)
>
> Index: b/Makefile.objs
> ===
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -57,7 +57,7 @@ common-obj-$(CONFIG_POSIX) += os-posix.o
>  common-obj-$(CONFIG_LINUX) += fsdev/
>
>  common-obj-y += migration.o migration-tcp.o
> -common-obj-y += qemu-char.o #aio.o
> +common-obj-y += qemu-char.o qemu-file.o #aio.o
>  common-obj-y += block-migration.o
>  common-obj-y += page_cache.o xbzrle.o
>
> Index: b/include/migration/qemu-file.h
> ===
> --- a/include/migration/qemu-file.h
> +++ b/include/migration/qemu-file.h
> @@ -113,6 +113,10 @@ int qemu_file_rate_limit(QEMUFile *f);
>  int64_t qemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate);
>  int64_t qemu_file_get_rate_limit(QEMUFile *f);
>  int qemu_file_get_error(QEMUFile *f);
> +QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int is_writable);
> +int qemu_peek_buffer(QEMUFile *f, uint8_t *buf, int size, size_t offset);
> +int qemu_peek_byte(QEMUFile *f, int offset);
> +void qemu_file_skip(QEMUFile *f, int size);
>
>  static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
>  {
> Index: b/qemu-file.c
> ===
> --- /dev/null
> +++ b/qemu-file.c
> @@ -0,0 +1,670 @@
> +/*
> + * QEMU System Emulator
> + *
> + * Copyright (c) 2003-2008 Fabrice Bellard
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a 
> copy
> + * of this software and associated documentation files (the "Software"), to 
> deal
> + * in the Software without restriction, including without limitation the 
> rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
> FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +#include "qemu-common.h"
> +#include "hw/hw.h"
> +#include "block/block.h"
> +#include "qemu/sockets.h"
> +
> +#define IO_BUF_SIZE 32768
> +
> +struct QEMUFile {
> +const QEMUFileOps *ops;
> +void *opaque;
> +int is_write;
> +
> +int64_t buf_offset; /* start of buffer when writing, end of buffer
> +   when reading */
> +int buf_index;
> +int buf_size; /* 0 when writing */
> +uint8_t buf[IO_BUF_SIZE];
> +
> +int last_error;
> +};
> +
> +typedef struct QEMUFileStdio
> +{
> +FILE *stdio_file;
> +QEMUFile *file;
> +} QEMUFileStdio;
> +
> +typedef struct QEMUFileSocket
> +{
> +int fd;
> +QEMUFile *file;
> +} QEMUFileSocket;
> +
> +typedef struct {
> +Coroutine *co;
> +int fd;
> +} FDYieldUntilData;
> +
> +static void fd_coroutine_enter(void *opaque)
> +{
> +FDYieldUntilData *data = opaque;
> +qemu_set_fd_handler(data->fd, NULL, NULL, NULL);
> +qemu_coroutine_enter(data->co, NULL);
> +}
> +
> +/**
> + * Yield until a file descriptor becomes readable
> + *
> + * Note that this function clobbers the handlers for the file descriptor.
> + */
> +static void coroutine_fn yield_until_fd_readable(int fd)
> +{
> +FDYieldUntilData data;
> +
> +assert(qemu_in_coroutine());
> +data.co = qemu_coroutine_self();
> +data.fd = fd;
> +qemu_set_fd_handler(fd, fd_coroutine_enter, NULL, &data);
> +qemu_coroutine_yield();
> +}
> +
> +static int socket_get_fd(void *opaque)
> +{
> +QEMUFileSocket *s = opaque;
> +
> +return s->fd;
> +}
> +
> +static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int 
> size)
> +{
> +QEMUFileSocket *s = opaque

Re: [Qemu-devel] [RFC PATCH v2 13/23] qcow2: handle_copied(): Implement non-zero host_offset

2013-02-13 Thread Blue Swirl
On Wed, Feb 13, 2013 at 1:22 PM, Kevin Wolf  wrote:
> Look only for clusters that start at a given physical offset.
>
> Signed-off-by: Kevin Wolf 
> ---
>  block/qcow2-cluster.c |   26 ++
>  1 files changed, 18 insertions(+), 8 deletions(-)
>
> diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
> index 5ce2c88..90fe36c 100644
> --- a/block/qcow2-cluster.c
> +++ b/block/qcow2-cluster.c
> @@ -827,8 +827,6 @@ static int handle_dependencies(BlockDriverState *bs, 
> uint64_t guest_offset,
>   *  the length of the area that can be written to.
>   *
>   *  -errno: in error cases
> - *
> - * TODO Make non-zero host_offset behave like describe above
>   */
>  static int handle_copied(BlockDriverState *bs, uint64_t guest_offset,
>  uint64_t *host_offset, uint64_t *bytes, QCowL2Meta **m)
> @@ -843,7 +841,6 @@ static int handle_copied(BlockDriverState *bs, uint64_t 
> guest_offset,
>
>  trace_qcow2_handle_copied(qemu_coroutine_self(), guest_offset, 
> *host_offset,
>*bytes);
> -assert(*host_offset == 0);
>
>  /*
>   * Calculate the number of clusters to look for. We stop at L2 table
> @@ -867,6 +864,15 @@ static int handle_copied(BlockDriverState *bs, uint64_t 
> guest_offset,
>  if (qcow2_get_cluster_type(cluster_offset) == QCOW2_CLUSTER_NORMAL
>  && (cluster_offset & QCOW_OFLAG_COPIED))
>  {
> +/* If a specific host_offset is required, check it */
> +if (*host_offset != 0
> +&& (cluster_offset & L2E_OFFSET_MASK) != *host_offset)
> +{

Braces should cuddle with the previous line.

> +*bytes = 0;
> +ret = 0;
> +goto out;
> +}
> +
>  /* We keep all QCOW_OFLAG_COPIED clusters */
>  keep_clusters =
>  count_contiguous_clusters(nb_clusters, s->cluster_size,
> @@ -880,19 +886,22 @@ static int handle_copied(BlockDriverState *bs, uint64_t 
> guest_offset,
>
>  ret = 1;
>  } else {
> -cluster_offset = 0;
>  ret = 0;
>  }
>
> -cluster_offset &= L2E_OFFSET_MASK;
> -*host_offset = cluster_offset;
> -
>  /* Cleanup */
> +out:
>  pret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
>  if (pret < 0) {
>  return pret;
>  }
>
> +/* Only return a host offset if we actually made progress. Otherwise we
> + * would make requirements for handle_alloc() that it can't fulfill */
> +if (ret) {
> +*host_offset = cluster_offset & L2E_OFFSET_MASK;
> +}
> +
>  return ret;
>  }
>
> @@ -1162,7 +1171,6 @@ again:
>
>  /*
>   * 2. Count contiguous COPIED clusters.
> - *TODO: Consider cluster_offset if set in step 1c.
>   */
>  ret = handle_copied(bs, offset, &cluster_offset, &cur_bytes, m);
>  if (ret < 0) {
> @@ -1175,6 +1183,8 @@ again:
>  if (!*host_offset) {
>  *host_offset = cluster_offset;
>  }
> +} else if (cur_bytes == 0) {
> +goto done;
>  } else {
>  keep_clusters = 0;
>  }
> --
> 1.7.6.5
>
>



Re: [Qemu-devel] [PATCH v2] ui/vnc: VA API based H.264 encoding for VNC

2013-02-13 Thread Blue Swirl
On Wed, Feb 13, 2013 at 10:45 AM, David Verbeiren
 wrote:
> This patch implements H.264 encoding of the VNC framebuffer updates
> using hardware acceleration through the VA API.
>
> This is experimental support to let the community explore the possibilities
> offered by the potential bandwidth and latency reductions that H.264
> encoding allows. This may be particularly useful for use cases such as
> online gaming, hosted desktops, hosted set top boxes...
> This patch provides the VNC server side support. Corresponding VNC
> client side support is required. To this end, we are also contributing
> patches to the gtk-vnc and libvncserver/libvncclient projects which can be
> used to test this experimental feature.
> See instructions below for how to build a test VNC client.
>
> In case multiple regions are updated, only the first framebuffer
> update message of the batch carries the H.264 frame data.
> Subsequent update framebuffer messages will contain only the
> coordinates and size of the other updated regions.
>
> This is backwards compatible with standard VNC clients thanks to
> the encoding scheme negotiation included in VNC. If the client doesn't
> support H.264 encoding, the server will fall back to one of the usual
> VNC encodings.
>
> Instructions/Requirements:
> * Currently only works with libva 1.0: use branch "v1.0-branch" for libva
> and intel-driver. Those can be built as follows:
>cd libva
>git checkout v1.0-branch
>./autogen.sh
>make
>sudo make install
>cd ..
>git clone git://anongit.freedesktop.org/vaapi/intel-driver
>cd intel-driver
>git checkout v1.0-branch
>./autogen.sh
>make
>sudo make install
> * A graphical environment must be running as the v1.0-branch of VA API
> does not support headless operation.
> * When using Intel integrated graphics, hardware encoding support requires
> a 2nd generation (or later) i3, i5 or i7 processor ("Sandy Bridge" or
> later), or similar, with enabled Intel(R) HD graphics.
> See http://intellinuxgraphics.org/h264.html for details.
>
> Instructions for building and using a gtk-vnc test client:
> * Get gtk-vnc project
>git clone git://git.gnome.org/gtk-vnc
>cd gtk-vnc
>git checkout a4f1d1912090d5
> * Download and apply (git apply ) patch from:
>https://mail.gnome.org/archives/gtk-vnc-list/2013-February/msg0.html
> * Build
>./autogen.sh --with-libva
>make -j4
> * Run the client, for example:
>./examples/gvncviewer :1
>
> Instructions for building and using a libvncclient test client:
> * Get LibVNCServer project
>git clone 
> git://libvncserver.git.sourceforge.net/gitroot/libvncserver/libvncserver
>cd libvncserver
>git checkout 55bdab02574e3ac
> * Download and apply (git apply ) following two patches
>   in sequence:
>http://sourceforge.net/mailarchive/message.php?msg_id=30323804
>http://sourceforge.net/mailarchive/message.php?msg_id=30327573
> * Build:
>./autogen.sh --with-libva
>make -j4
> * Run the client, for example:
>./client_examples/gtkvncviewer :5901
>
> Signed-off-by: David Verbeiren 
> ---
>  Changes for v1->v2:
>   * No more statics; most moved into the VncDisplayH264 struct.
>   * All variable declarations at top of funcs
>   * VA encoder init now performed as part of set_encodings() so we can
> fallback to another encoding in case VA init fails.
>   * configure script now defaults to libva=""
>   * (no code change) "VA H.264" RFB encoding type number is now registered
> with IANA at http://www.iana.org/assignments/rfb/rfb.xml
>
>  Also note that you can now use clients based on either libvncclient
>  or gtk-vnc as a patch for the latter project was also submitted.
>
>
>  configure |   39 
>  ui/Makefile.objs  |1 +
>  ui/vnc-enc-h264.c |  616 
> +
>  ui/vnc-enc-h264.h |   74 +++
>  ui/vnc-jobs.c |6 +
>  ui/vnc.c  |   26 +++
>  ui/vnc.h  |   18 ++
>  7 files changed, 780 insertions(+)
>  create mode 100644 ui/vnc-enc-h264.c
>  create mode 100644 ui/vnc-enc-h264.h
>
> diff --git a/configure b/configure
> index 8789324..d742a6c 100755
> --- a/configure
> +++ b/configure
> @@ -213,6 +213,7 @@ pie=""
>  zero_malloc=""
>  trace_backend="nop"
>  trace_file="trace"
> +libva=""
>  spice=""
>  rbd=""
>  smartcard_nss=""
> @@ -771,6 +772,10 @@ for opt do
>;;
>--enable-spice) spice="yes"
>;;
> +  --disable-libva) libva="no"
> +  ;;
> +  --enable-libva) libva="yes"
> +  ;;
>--disable-libiscsi) libiscsi="no"
>;;
>--enable-libiscsi) libiscsi="yes"
> @@ -1129,6 +1134,8 @@ echo "  --with-trace-file=NAME   Full PATH,NAME of file 
> to store traces"
>  echo "   Default:trace-"
>  echo "  --disable-spice  disable spice"
>  echo "  --enable-spice   enable spice"
> +echo "  --disable-libva  disable H.264 encoding with libva"
> +echo "  --enable-libva   enable H.264 encoding wi

Re: [Qemu-devel] [Qemu-ppc] [0/8] RFC: target-ppc: Start disentangling different MMU types

2013-02-13 Thread Blue Swirl
On Tue, Feb 12, 2013 at 10:40 AM, Andreas Färber  wrote:
> Am 12.02.2013 03:00, schrieb David Gibson:
>> The target-ppc code supports CPUs with a number of different MMU
>> types: there's both the 32-bit and 64-bit versions of the "classic"
>> hash page table based powerpc mmu and there's also the BookE and 40x
>> MMUs.
>>
>> Currently handling of all these has a roughly shared path in
>> mmu_helper.c.  Although code sharing is usually a good idea, in this
>> case the MMUs really aren't similar enough for this to be useful.
>> Instead it results in checking and behaving differently at many, many
>> different points in the path leading to an unreadable tangle of code.
>>
>> This patch series is a first step to cleaning this up, moving to a
>> model where we have a single switch on the MMU family at the top-level
>> entry points, then have a simpler, clearer separate code path for each
>> MMU type.  More specifically, it disentangles the path for the 64-bit
>> classic hash MMU into its own new file.  The other MMU types keep the
>> existing code (minus 64-bit hash specific conditionals) for now.
>> Disentangling those as well would be a good idea, but would be best
>> done by someone with more resources to test those other platforms than
>> I have.
>>
>> For now, the resulting 64-bit hash path retains the same structure as
>> the original shared code, just the obvious conditionals on other mmu
>> types are removed.  This path is fairly ugly in itself, but cleaning
>> that up is a later step, now much simpler without the other MMU types
>> to deal with at the same time.
>
> Some general comments: The idea of the ongoing QOM work just sent out is
> to change the hierarchy from:
>
> Object
> - DeviceState
>   - CPUState
> - PowerPCCPU
>   - 970 vX.Y
>   - POWER7 vX.Y
>   ...
>
> to:
>
> Object
> - DeviceState
>   - CPUState
> - PowerPCCPU
>   - 970 family
> - 970 vX.Y
>   - POWER7 family
> - POWER7 vX.Y
>   ...
>
> PowerPCCPUClass is expected to grow methods overridden per family or
> model. I.e., where sensible the class should serve as indirection for
> which MMU/... implementation to choose rather than ifs or #ifdefs or
> _family glue sprinkled througout code.
>
> As reminded repeatedly, please do not introduce new static or global
> helper functions using CPUPPCState, use PowerPCCPU instead.
>
> If you introduce global functions, please make them unique by using ppc_
> prefix for arbitrary functions and ppc_cpu_ for functions taking
> PowerPCCPU as first argument.

I'd also add that separating the MMU functions could help if one day
we introduce CPU model specific TCG memory access helpers.

>
> Thanks,
> Andreas
>
> --
> SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
> GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
>



Re: [Qemu-devel] [Qemu-ppc] [PATCH 7/8] target-ppc: Disentangle 64-bit hash MMU get_physical_address() paths

2013-02-13 Thread Blue Swirl
On Tue, Feb 12, 2013 at 2:00 AM, David Gibson
 wrote:
> Depending on the MSR state, for 64-bit hash MMUs, get_physical_address
> can either call check_physical (which has further tests for mmu type)
> or get_segment64.
>
> This patch splits off the whole get_physical_addresss() path for 64-bit
> hash MMUs into its own function, which handles real mode correctly for
> such MMUs without going to check_physical and rechecking the mmu type.
> Correspondingly, the 64-bit hash MMU specific path in check_physical() is
> removed.
>
> Signed-off-by: David Gibson 
> ---
>  target-ppc/cpu.h|4 ++--
>  target-ppc/mmu-hash64.c |   19 +--
>  target-ppc/mmu_helper.c |   27 +--
>  3 files changed, 24 insertions(+), 26 deletions(-)
>
> diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
> index cf12632..6143142 100644
> --- a/target-ppc/cpu.h
> +++ b/target-ppc/cpu.h
> @@ -1153,8 +1153,8 @@ hwaddr get_pteg_offset(CPUPPCState *env, hwaddr hash, 
> int pte_size);
>  void ppc_store_asr (CPUPPCState *env, target_ulong value);
>  int ppc_store_slb (CPUPPCState *env, target_ulong rb, target_ulong rs);
>  void dump_slb(FILE *f, fprintf_function cpu_fprintf, CPUPPCState *env);
> -int get_segment64(CPUPPCState *env, mmu_ctx_t *ctx,
> -  target_ulong eaddr, int rw, int type);
> +int ppc_hash64_get_physical_address(CPUPPCState *env, mmu_ctx_t *ctx,
> +target_ulong eaddr, int rw, int 
> access_type);
>  #endif /* defined(TARGET_PPC64) */
>  #endif /* !defined(CONFIG_USER_ONLY) */
>  void ppc_store_msr (CPUPPCState *env, target_ulong value);
> diff --git a/target-ppc/mmu-hash64.c b/target-ppc/mmu-hash64.c
> index 1d6425c..0f40e0a 100644
> --- a/target-ppc/mmu-hash64.c
> +++ b/target-ppc/mmu-hash64.c
> @@ -349,8 +349,8 @@ static int find_pte64(CPUPPCState *env, mmu_ctx_t *ctx, 
> int h,
>  return ret;
>  }
>
> -int get_segment64(CPUPPCState *env, mmu_ctx_t *ctx,
> -  target_ulong eaddr, int rw, int type)
> +static int get_segment64(CPUPPCState *env, mmu_ctx_t *ctx,
> + target_ulong eaddr, int rw, int type)
>  {
>  hwaddr hash;
>  target_ulong vsid;
> @@ -456,3 +456,18 @@ int get_segment64(CPUPPCState *env, mmu_ctx_t *ctx,
>
>  return ret;
>  }
> +
> +int ppc_hash64_get_physical_address(CPUPPCState *env, mmu_ctx_t *ctx,
> +target_ulong eaddr, int rw, int 
> access_type)
> +{
> +bool real_mode = (access_type == ACCESS_CODE && msr_ir == 0)
> +|| (access_type != ACCESS_CODE && msr_dr == 0);
> +
> +if (real_mode) {
> +ctx->raddr = eaddr & 0x0FFFULL;
> +ctx->prot = PAGE_READ | PAGE_EXEC | PAGE_WRITE;
> +return 0;
> +} else {
> +return get_segment64(env, ctx, eaddr, rw, access_type);
> +}
> +}
> diff --git a/target-ppc/mmu_helper.c b/target-ppc/mmu_helper.c
> index e787843..98143dd 100644
> --- a/target-ppc/mmu_helper.c
> +++ b/target-ppc/mmu_helper.c
> @@ -1361,15 +1361,7 @@ static inline int check_physical(CPUPPCState *env, 
> mmu_ctx_t *ctx,
>  case POWERPC_MMU_BOOKE:
>  ctx->prot |= PAGE_WRITE;
>  break;
> -#if defined(TARGET_PPC64)
> -case POWERPC_MMU_64B:
> -case POWERPC_MMU_2_06:
> -case POWERPC_MMU_2_06d:
> -/* Real address are 60 bits long */
> -ctx->raddr &= 0x0FFFULL;
> -ctx->prot |= PAGE_WRITE;
> -break;
> -#endif
> +
>  case POWERPC_MMU_SOFT_4xx_Z:
>  if (unlikely(msr_pe != 0)) {
>  /* 403 family add some particular protections,
> @@ -1394,15 +1386,10 @@ static inline int check_physical(CPUPPCState *env, 
> mmu_ctx_t *ctx,
>  }
>  }
>  break;
> -case POWERPC_MMU_MPC8xx:
> -/* XXX: TODO */
> -cpu_abort(env, "MPC8xx MMU model is not implemented\n");
> -break;
> -case POWERPC_MMU_BOOKE206:
> -cpu_abort(env, "BookE 2.06 MMU doesn't have physical real mode\n");
> -break;
> +
>  default:
> -cpu_abort(env, "Unknown or invalid MMU model\n");
> +/* Caller's checks we should never get here for other models */
> +assert(0);

abort()

>  return -1;
>  }
>
> @@ -1443,11 +1430,7 @@ static int get_physical_address(CPUPPCState *env, 
> mmu_ctx_t *ctx,
>  case POWERPC_MMU_64B:
>  case POWERPC_MMU_2_06:
>  case POWERPC_MMU_2_06d:
> -if (real_mode) {
> -ret = check_physical(env, ctx, eaddr, rw);
> -} else {
> -ret = get_segment64(env, ctx, eaddr, rw, access_type);
> -}
> +ret = ppc_hash64_get_physical_address(env, ctx, eaddr, rw, 
> access_type);
>  break;
>  #endif
>
> --
> 1.7.10.4
>
>



Re: [Qemu-devel] [PATCH V18 08/10] libqblock: libqblock API implement

2013-02-13 Thread Blue Swirl
On Wed, Feb 13, 2013 at 2:08 AM, Wenchao Xia  wrote:
>
>> On Sat, Feb 9, 2013 at 7:42 AM, Wenchao Xia 
>> wrote:
>>>
>>>This patch contains implemention for APIs. Basically it is a layer
>>> above qemu block general layer now.
>>>qb_image_new() will try do init for this library.
>>>
>>> Signed-off-by: Wenchao Xia 
>>> ---
>>>   libqblock/libqblock-error.c |   49 +++
>>>   libqblock/libqblock.c   |  991
>>> +++
>>>   2 files changed, 1040 insertions(+), 0 deletions(-)
>>>
>>> diff --git a/libqblock/libqblock-error.c b/libqblock/libqblock-error.c
>>> index e69de29..2367ab4 100644
>>> --- a/libqblock/libqblock-error.c
>>> +++ b/libqblock/libqblock-error.c
>>> @@ -0,0 +1,49 @@
>
>
>>> +
>>> +typedef struct LibqbFormatStrMapping {
>>> +const char *fmt_str;
>>> +QBlockFormat fmt_type;
>>> +} LibqbFormatStrMapping;
>>> +
>>> +LibqbFormatStrMapping libqb_formatstr_table[] = {
>>
>>
>> static const
>>
>   OK.
>
>
>>> +{"cow", QB_FORMAT_COW},
>>> +{"qed", QB_FORMAT_QED},
>>> +{"qcow", QB_FORMAT_QCOW},
>>> +{"qcow2", QB_FORMAT_QCOW2},
>>> +{"raw", QB_FORMAT_RAW},
>>> +{"rbd", QB_FORMAT_RBD},
>>> +{"sheepdog", QB_FORMAT_SHEEPDOG},
>>> +{"vdi", QB_FORMAT_VDI},
>>> +{"vmdk", QB_FORMAT_VMDK},
>>> +{"vpc", QB_FORMAT_VPC},
>>> +{NULL, 0},
>>
>>
>> You can avoid this NULL entry and save space by using ARRAY_SIZE() in
>> the loop. Compiler could also unroll the loop.
>>
>   OK.
>
>
>>> +};
>>> +
>>> +__attribute__((constructor))
>>> +static void libqblock_init(void)
>>> +{
>>> +/* Todo: add an assertion about the ABI. */
>>> +libqb_global_data.init_flag = 0;
>>> +pthread_mutex_init(&libqb_global_data.mutex, NULL);
>>> +}
>>> +
>>> +const char *qb_formattype2str(QBlockFormat fmt_type)
>>> +{
>>> +int i = 0;
>>> +LibqbFormatStrMapping *tb = libqb_formatstr_table;
>>
>>
>> This does not seem to be useful, you could use libqb_formatstr_table
>> directly.
>>
>   OK.
>
>
>>> +
>>> +if ((fmt_type <= QB_FORMAT_NONE) || (fmt_type >= QB_FORMAT_MAX)) {
>>> +return NULL;
>>> +}
>>> +while (tb[i].fmt_str != NULL) {
>>
>>
>> for (i = 0; i < ARRAY_SIZE(libqb_formatstr_table); i++) {
>>
>   OK.
>
>
>>> +if (tb[i].fmt_type == fmt_type) {
>>> +return tb[i].fmt_str;
>>> +}
>>> +i++;
>>> +}
>>> +return NULL;
>>> +}
>>> +
>>> +QBlockFormat qb_str2fmttype(const char *fmt_str)
>>> +{
>>> +int i = 0;
>>> +LibqbFormatStrMapping *tb = libqb_formatstr_table;
>>> +
>>> +if (fmt_str == NULL) {
>>> +return QB_FORMAT_NONE;
>>> +}
>>> +while (tb[i].fmt_str != NULL) {
>>> +if ((strcmp(fmt_str, tb[i].fmt_str) == 0)) {
>>> +return tb[i].fmt_type;
>>> +}
>>> +i++;
>>> +}
>>> +return QB_FORMAT_NONE;
>>> +}
>>> +
>>> +static void set_context_err(QBlockContext *context, int err_ret,
>>> +const char *fmt, ...)
>>
>>
>> GCC_FMT_ATTR()?
>>
>   Do you mean this declaration is needed here?

It declares to GCC that this function uses printf like format strings,
so it can perform additional checks. This helps catching bugs by
callers supplying incorrect arguments.

>
>
>>> +{
>>> +va_list ap;
>>> +
>>> +if (context->g_error != NULL) {
>>> +g_error_free(context->g_error);
>>> +}
>>> +
>>> +va_start(ap, fmt);
>>> +context->g_error = g_error_new_valist(qb_error_quark(), err_ret,
>>> fmt, ap);
>>> +va_end(ap);
>>> +
>>> +context->err_ret = err_ret;
>>> +if (err_ret == QB_ERR_INTERNAL_ERR) {
>>> +context->err_no = -errno;
>>> +} else {
>>> +context->err_no = 0;
>>> +}
>>> +}
>>> +
>
>
>>> +static void delete_context(QBlockContext **p_context)
>>> +{
>>> +if ((*p_context)->g_error != NULL) {
>>> +g_error_free((*p_context)->g_error);
>>> +}
>>> +g_free(*p_context);
>>> +*p_context = NULL;
>>> +return;
>>
>>
>> Useless return, please remove.
>>
>   OK.
>
>
>>> --
>>> 1.7.1
>>>
>>>
>>>
>>
>
>
> --
> Best Regards
>
> Wenchao Xia
>



Re: [Qemu-devel] [PATCH 0/6] qemu_log: remove 'cpu' from qemu log function names

2013-02-13 Thread Blue Swirl
On Mon, Feb 11, 2013 at 4:41 PM, Peter Maydell  wrote:
> This patchset is just cleanups; it has two major aims:
>  * remove 'cpu' from public-facing qemu_log function/type/etc
>names, since the logging is now entirely generic and not
>tied to TCG CPU debug logging at all
>  * remove unnecessary indirection through cpus.c (ie set_cpu_log
>and set_cpu_log_filename) in favour of just having vl.c
>call the appropriate qemu_log functions. [I think this indirection
>was a legacy from before commit 3b823210, when qemu-log.h
>could not be included in files that were in libhw.]

Nice series.
Acked-by: Blue Swirl 

>
> thanks
> -- PMM
>
> Peter Maydell (6):
>   qemu-log: Unify {cpu_set,set_cpu}_log_filename as
> qemu_set_log_filename
>   qemu-log: Abstract out "print usage message about valid log
> categories"
>   qemu-log: Rename cpu_str_to_log_mask to qemu_str_to_log_mask
>   qemu-log: Rename the public-facing cpu_set_log function to
> qemu_set_log
>   cpus.c: Drop unnecessary set_cpu_log()
>   qemu-log: Rename CPULogItem, cpu_log_items to QEMULogItem,
> qemu_log_items
>
>  bsd-user/main.c |   12 
>  cpus.c  |   21 -
>  hw/ppc.c|2 +-
>  include/qemu/log.h  |   27 ++-
>  include/sysemu/cpus.h   |2 --
>  linux-user/main.c   |   14 +-
>  monitor.c   |   10 +-
>  qemu-log.c  |   25 +
>  target-i386/translate.c |2 +-
>  tcg/tci/tcg-target.c|2 +-
>  vl.c|   11 +--
>  11 files changed, 61 insertions(+), 67 deletions(-)
>
> --
> 1.7.9.5
>



[Qemu-devel] [PATCH v2] Move File operations to qemu-file.c

2013-02-13 Thread Joel Schopp
This patch reorganizes qemu file operations to be in their own source file
instead of being lumped in savevm.c.  Besides being more logical for maintenance
it also makes it easier for future users of the file functions to add tests.

v2 forward port to resolve conflicts, strip trailing whitespace during move

Signed-off-by: Stefan Berger 
Signed-off-by: Joel Schopp 
---
 Makefile.objs |2 
 include/migration/qemu-file.h |4 
 qemu-file.c   |  670 ++
 savevm.c  |  646 
 4 files changed, 675 insertions(+), 647 deletions(-)

Index: b/Makefile.objs
===
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -57,7 +57,7 @@ common-obj-$(CONFIG_POSIX) += os-posix.o
 common-obj-$(CONFIG_LINUX) += fsdev/
 
 common-obj-y += migration.o migration-tcp.o
-common-obj-y += qemu-char.o #aio.o
+common-obj-y += qemu-char.o qemu-file.o #aio.o
 common-obj-y += block-migration.o
 common-obj-y += page_cache.o xbzrle.o
 
Index: b/include/migration/qemu-file.h
===
--- a/include/migration/qemu-file.h
+++ b/include/migration/qemu-file.h
@@ -113,6 +113,10 @@ int qemu_file_rate_limit(QEMUFile *f);
 int64_t qemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate);
 int64_t qemu_file_get_rate_limit(QEMUFile *f);
 int qemu_file_get_error(QEMUFile *f);
+QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int is_writable);
+int qemu_peek_buffer(QEMUFile *f, uint8_t *buf, int size, size_t offset);
+int qemu_peek_byte(QEMUFile *f, int offset);
+void qemu_file_skip(QEMUFile *f, int size);
 
 static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
 {
Index: b/qemu-file.c
===
--- /dev/null
+++ b/qemu-file.c
@@ -0,0 +1,670 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "qemu-common.h"
+#include "hw/hw.h"
+#include "block/block.h"
+#include "qemu/sockets.h"
+
+#define IO_BUF_SIZE 32768
+
+struct QEMUFile {
+const QEMUFileOps *ops;
+void *opaque;
+int is_write;
+
+int64_t buf_offset; /* start of buffer when writing, end of buffer
+   when reading */
+int buf_index;
+int buf_size; /* 0 when writing */
+uint8_t buf[IO_BUF_SIZE];
+
+int last_error;
+};
+
+typedef struct QEMUFileStdio
+{
+FILE *stdio_file;
+QEMUFile *file;
+} QEMUFileStdio;
+
+typedef struct QEMUFileSocket
+{
+int fd;
+QEMUFile *file;
+} QEMUFileSocket;
+
+typedef struct {
+Coroutine *co;
+int fd;
+} FDYieldUntilData;
+
+static void fd_coroutine_enter(void *opaque)
+{
+FDYieldUntilData *data = opaque;
+qemu_set_fd_handler(data->fd, NULL, NULL, NULL);
+qemu_coroutine_enter(data->co, NULL);
+}
+
+/**
+ * Yield until a file descriptor becomes readable
+ *
+ * Note that this function clobbers the handlers for the file descriptor.
+ */
+static void coroutine_fn yield_until_fd_readable(int fd)
+{
+FDYieldUntilData data;
+
+assert(qemu_in_coroutine());
+data.co = qemu_coroutine_self();
+data.fd = fd;
+qemu_set_fd_handler(fd, fd_coroutine_enter, NULL, &data);
+qemu_coroutine_yield();
+}
+
+static int socket_get_fd(void *opaque)
+{
+QEMUFileSocket *s = opaque;
+
+return s->fd;
+}
+
+static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size)
+{
+QEMUFileSocket *s = opaque;
+ssize_t len;
+
+for (;;) {
+len = qemu_recv(s->fd, buf, size, 0);
+if (len != -1) {
+break;
+}
+if (socket_error() == EAGAIN) {
+yield_until_fd_readable(s->fd);
+} else if (socket_error() != EINTR) {
+break;
+}
+}
+
+if (len == -1) {
+   

[Qemu-devel] [PATCH for-1.4 4/7] doc: Fix texinfo @table markup in qemu-options.hx

2013-02-13 Thread Markus Armbruster
End tables before headings, start new ones afterwards.  Fixes
incorrect indentation of headings "File system options" and "Virtual
File system pass-through options" in manual page and qemu-doc.

Normalize markup some to increase chances it survives future edits.

Signed-off-by: Markus Armbruster 
---
 qemu-options.hx | 56 +---
 1 file changed, 37 insertions(+), 19 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index d57cf2b..8d288f5 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -539,13 +539,15 @@ STEXI
 @end table
 ETEXI
 
-DEF("usb", 0, QEMU_OPTION_usb,
-"-usbenable the USB driver (will be the default soon)\n",
-QEMU_ARCH_ALL)
 STEXI
 USB options:
 @table @option
+ETEXI
 
+DEF("usb", 0, QEMU_OPTION_usb,
+"-usbenable the USB driver (will be the default soon)\n",
+QEMU_ARCH_ALL)
+STEXI
 @item -usb
 @findex -usb
 Enable the USB driver (will be the default soon)
@@ -612,9 +614,15 @@ possible drivers and properties, use @code{-device help} 
and
 @code{-device @var{driver},help}.
 ETEXI
 
+STEXI
+@end table
+ETEXI
 DEFHEADING()
 
 DEFHEADING(File system options:)
+STEXI
+@table @option
+ETEXI
 
 DEF("fsdev", HAS_ARG, QEMU_OPTION_fsdev,
 "-fsdev 
fsdriver,id=id[,path=path,][security_model={mapped-xattr|mapped-file|passthrough|none}]\n"
@@ -678,9 +686,15 @@ Specifies the tag name to be used by the guest to mount 
this export point
 
 ETEXI
 
+STEXI
+@end table
+ETEXI
 DEFHEADING()
 
 DEFHEADING(Virtual File system pass-through options:)
+STEXI
+@table @option
+ETEXI
 
 DEF("virtfs", HAS_ARG, QEMU_OPTION_virtfs,
 "-virtfs 
local,path=path,mount_tag=tag,security_model=[mapped-xattr|mapped-file|passthrough|none]\n"
@@ -771,11 +785,9 @@ ETEXI
 STEXI
 @end table
 ETEXI
-
 DEFHEADING()
 
 DEFHEADING(Display options:)
-
 STEXI
 @table @option
 ETEXI
@@ -1217,7 +1229,6 @@ ETEXI
 STEXI
 @end table
 ETEXI
-
 ARCHHEADING(, QEMU_ARCH_I386)
 
 ARCHHEADING(i386 target only:, QEMU_ARCH_I386)
@@ -1302,10 +1313,10 @@ Specify SMBIOS type 0 fields
 Specify SMBIOS type 1 fields
 ETEXI
 
-DEFHEADING()
 STEXI
 @end table
 ETEXI
+DEFHEADING()
 
 DEFHEADING(Network options:)
 STEXI
@@ -1720,13 +1731,19 @@ libpcap, so it can be analyzed with tools such as 
tcpdump or Wireshark.
 Indicate that no network devices should be configured. It is used to
 override the default configuration (@option{-net nic -net user}) which
 is activated if no @option{-net} options are provided.
+ETEXI
 
+STEXI
 @end table
 ETEXI
-
 DEFHEADING()
 
 DEFHEADING(Character device options:)
+STEXI
+
+The general form of a character device option is:
+@table @option
+ETEXI
 
 DEF("chardev", HAS_ARG, QEMU_OPTION_chardev,
 "-chardev null,id=id[,mux=on|off]\n"
@@ -1768,10 +1785,6 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev,
 )
 
 STEXI
-
-The general form of a character device option is:
-@table @option
-
 @item -chardev @var{backend} ,id=@var{id} [,mux=on|off] [,@var{options}]
 @findex -chardev
 Backend is one of:
@@ -1992,14 +2005,15 @@ Connect to a spice virtual machine channel, such as 
vdiport.
 
 Connect to a spice port, allowing a Spice client to handle the traffic
 identified by a name (preferably a fqdn).
+ETEXI
 
+STEXI
 @end table
 ETEXI
-
 DEFHEADING()
 
-STEXI
 DEFHEADING(Device URL Syntax:)
+STEXI
 
 In addition to using normal file images for the emulated storage devices,
 QEMU can also use networked resources such as iSCSI devices. These are
@@ -2115,10 +2129,16 @@ qemu-system-x86_84 --drive 
file=gluster://192.0.2.1/testvol/a.img
 @end example
 
 See also @url{http://www.gluster.org}.
+ETEXI
+
+STEXI
 @end table
 ETEXI
 
 DEFHEADING(Bluetooth(R) options:)
+STEXI
+@table @option
+ETEXI
 
 DEF("bt", HAS_ARG, QEMU_OPTION_bt, \
 "-bt hci,nulldumb bluetooth HCI - doesn't respond to commands\n" \
@@ -2132,8 +2152,6 @@ DEF("bt", HAS_ARG, QEMU_OPTION_bt, \
 "emulate a bluetooth device 'dev' in scatternet 'n'\n",
 QEMU_ARCH_ALL)
 STEXI
-@table @option
-
 @item -bt hci[...]
 @findex -bt
 Defines the function of the corresponding Bluetooth HCI.  -bt options
@@ -2185,9 +2203,11 @@ currently:
 @item keyboard
 Virtual wireless keyboard implementing the HIDP bluetooth profile.
 @end table
-@end table
 ETEXI
 
+STEXI
+@end table
+ETEXI
 DEFHEADING()
 
 DEFHEADING(Linux/Multiboot boot specific:)
@@ -2244,11 +2264,9 @@ ETEXI
 STEXI
 @end table
 ETEXI
-
 DEFHEADING()
 
 DEFHEADING(Debug/Expert options:)
-
 STEXI
 @table @option
 ETEXI
-- 
1.7.11.7




Re: [Qemu-devel] [PATCH for-1.4 v2 1/6] error: Clean up error strings with embedded newlines

2013-02-13 Thread Luiz Capitulino
On Fri, 08 Feb 2013 20:48:18 +0100
Markus Armbruster  wrote:

> It's a cleanup.  It's only user-visible effect is getting rid of an
> extra newline on stderr.  I'm fixing those globally.  Tiny improvement
> in user experience, but next to no risk, thus proposed for 1.4.  Since I
> need to touch this call anyway for that, I can just as well clean up the
> API abuse.  The alternative is to leave the abuse alone and just strip
> the final newline.  That would make me sad.
> 
> If you hate the API, fix it.  Don't make me not fix abuses of it :)

I honestly would prefer to defer this and fix the API once and for all.
But it's not worth to discuss this anymore, as this patch has already
been merged.



[Qemu-devel] [PATCH for-1.4 7/7] doc help: Collect block device stuff under its own heading

2013-02-13 Thread Markus Armbruster
Collect them from "Standard options", "File system options", "Virtual
File system pass-through options", "Debug/Expert options".

Signed-off-by: Markus Armbruster 
---
 qemu-options.hx | 722 
 1 file changed, 356 insertions(+), 366 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index a252908..0e68b0d 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -103,196 +103,6 @@ Simulate a multi node NUMA system. If mem and cpus are 
omitted, resources
 are split equally.
 ETEXI
 
-DEF("fda", HAS_ARG, QEMU_OPTION_fda,
-"-fda/-fdb file  use 'file' as floppy disk 0/1 image\n", QEMU_ARCH_ALL)
-DEF("fdb", HAS_ARG, QEMU_OPTION_fdb, "", QEMU_ARCH_ALL)
-STEXI
-@item -fda @var{file}
-@item -fdb @var{file}
-@findex -fda
-@findex -fdb
-Use @var{file} as floppy disk 0/1 image (@pxref{disk_images}). You can
-use the host floppy by using @file{/dev/fd0} as filename (@pxref{host_drives}).
-ETEXI
-
-DEF("hda", HAS_ARG, QEMU_OPTION_hda,
-"-hda/-hdb file  use 'file' as IDE hard disk 0/1 image\n", QEMU_ARCH_ALL)
-DEF("hdb", HAS_ARG, QEMU_OPTION_hdb, "", QEMU_ARCH_ALL)
-DEF("hdc", HAS_ARG, QEMU_OPTION_hdc,
-"-hdc/-hdd file  use 'file' as IDE hard disk 2/3 image\n", QEMU_ARCH_ALL)
-DEF("hdd", HAS_ARG, QEMU_OPTION_hdd, "", QEMU_ARCH_ALL)
-STEXI
-@item -hda @var{file}
-@item -hdb @var{file}
-@item -hdc @var{file}
-@item -hdd @var{file}
-@findex -hda
-@findex -hdb
-@findex -hdc
-@findex -hdd
-Use @var{file} as hard disk 0, 1, 2 or 3 image (@pxref{disk_images}).
-ETEXI
-
-DEF("cdrom", HAS_ARG, QEMU_OPTION_cdrom,
-"-cdrom file use 'file' as IDE cdrom image (cdrom is ide1 master)\n",
-QEMU_ARCH_ALL)
-STEXI
-@item -cdrom @var{file}
-@findex -cdrom
-Use @var{file} as CD-ROM image (you cannot use @option{-hdc} and
-@option{-cdrom} at the same time). You can use the host CD-ROM by
-using @file{/dev/cdrom} as filename (@pxref{host_drives}).
-ETEXI
-
-DEF("drive", HAS_ARG, QEMU_OPTION_drive,
-"-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]\n"
-"   [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off]\n"
-"   
[,cache=writethrough|writeback|none|directsync|unsafe][,format=f]\n"
-"   [,serial=s][,addr=A][,id=name][,aio=threads|native]\n"
-"   [,readonly=on|off][,copy-on-read=on|off]\n"
-"   
[[,bps=b]|[[,bps_rd=r][,bps_wr=w]]][[,iops=i]|[[,iops_rd=r][,iops_wr=w]]\n"
-"use 'file' as a drive image\n", QEMU_ARCH_ALL)
-STEXI
-@item -drive @var{option}[,@var{option}[,@var{option}[,...]]]
-@findex -drive
-
-Define a new drive. Valid options are:
-
-@table @option
-@item file=@var{file}
-This option defines which disk image (@pxref{disk_images}) to use with
-this drive. If the filename contains comma, you must double it
-(for instance, "file=my,,file" to use file "my,file").
-
-Special files such as iSCSI devices can be specified using protocol
-specific URLs. See the section for "Device URL Syntax" for more information.
-@item if=@var{interface}
-This option defines on which type on interface the drive is connected.
-Available types are: ide, scsi, sd, mtd, floppy, pflash, virtio.
-@item bus=@var{bus},unit=@var{unit}
-These options define where is connected the drive by defining the bus number 
and
-the unit id.
-@item index=@var{index}
-This option defines where is connected the drive by using an index in the list
-of available connectors of a given interface type.
-@item media=@var{media}
-This option defines the type of the media: disk or cdrom.
-@item cyls=@var{c},heads=@var{h},secs=@var{s}[,trans=@var{t}]
-These options have the same definition as they have in @option{-hdachs}.
-@item snapshot=@var{snapshot}
-@var{snapshot} is "on" or "off" and allows to enable snapshot for given drive 
(see @option{-snapshot}).
-@item cache=@var{cache}
-@var{cache} is "none", "writeback", "unsafe", "directsync" or "writethrough" 
and controls how the host cache is used to access block data.
-@item aio=@var{aio}
-@var{aio} is "threads", or "native" and selects between pthread based disk I/O 
and native Linux AIO.
-@item format=@var{format}
-Specify which disk @var{format} will be used rather than detecting
-the format.  Can be used to specifiy format=raw to avoid interpreting
-an untrusted format header.
-@item serial=@var{serial}
-This option specifies the serial number to assign to the device.
-@item addr=@var{addr}
-Specify the controller's PCI address (if=virtio only).
-@item werror=@var{action},rerror=@var{action}
-Specify which @var{action} to take on write and read errors. Valid actions are:
-"ignore" (ignore the error and try to continue), "stop" (pause QEMU),
-"report" (report the error to the guest), "enospc" (pause QEMU only if the
-host disk is full; report the error to the guest otherwise).
-The default setting is @option{werror=enospc} and @option{rerror=report}.
-@item readonly
-Open drive @option{file} as read-only. Guest write attempts will fail.
-@item copy-on-read=@var{cop

[Qemu-devel] [PATCH for-1.4 6/7] doc help: A few options are under inappropriate headings, fix

2013-02-13 Thread Markus Armbruster
--device is under heading "USB options".  --name and --uuid are under
"Virtual File system pass-through options".  Move all three to
"Standard options".

Signed-off-by: Markus Armbruster 
---
 qemu-options.hx | 80 -
 1 file changed, 39 insertions(+), 41 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index 071b1b3..a252908 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -535,6 +535,45 @@ Enable virtio balloon device (default), optionally with 
PCI address
 @var{addr}.
 ETEXI
 
+DEF("device", HAS_ARG, QEMU_OPTION_device,
+"-device driver[,prop[=value][,...]]\n"
+"add device (based on driver)\n"
+"prop=value,... sets driver properties\n"
+"use '-device help' to print all possible drivers\n"
+"use '-device driver,help' to print all possible 
properties\n",
+QEMU_ARCH_ALL)
+STEXI
+@item -device @var{driver}[,@var{prop}[=@var{value}][,...]]
+@findex -device
+Add device @var{driver}.  @var{prop}=@var{value} sets driver
+properties.  Valid properties depend on the driver.  To get help on
+possible drivers and properties, use @code{-device help} and
+@code{-device @var{driver},help}.
+ETEXI
+
+DEF("name", HAS_ARG, QEMU_OPTION_name,
+"-name string1[,process=string2]\n"
+"set the name of the guest\n"
+"string1 sets the window title and string2 the process 
name (on Linux)\n",
+QEMU_ARCH_ALL)
+STEXI
+@item -name @var{name}
+@findex -name
+Sets the @var{name} of the guest.
+This name will be displayed in the SDL window caption.
+The @var{name} will also be used for the VNC server.
+Also optionally set the top visible process name in Linux.
+ETEXI
+
+DEF("uuid", HAS_ARG, QEMU_OPTION_uuid,
+"-uuid %08x-%04x-%04x-%04x-%012x\n"
+"specify machine UUID\n", QEMU_ARCH_ALL)
+STEXI
+@item -uuid @var{uuid}
+@findex -uuid
+Set system UUID.
+ETEXI
+
 STEXI
 @end table
 ETEXI
@@ -599,22 +638,6 @@ Network adapter that supports CDC ethernet and RNDIS 
protocols.
 @end table
 ETEXI
 
-DEF("device", HAS_ARG, QEMU_OPTION_device,
-"-device driver[,prop[=value][,...]]\n"
-"add device (based on driver)\n"
-"prop=value,... sets driver properties\n"
-"use '-device help' to print all possible drivers\n"
-"use '-device driver,help' to print all possible 
properties\n",
-QEMU_ARCH_ALL)
-STEXI
-@item -device @var{driver}[,@var{prop}[=@var{value}][,...]]
-@findex -device
-Add device @var{driver}.  @var{prop}=@var{value} sets driver
-properties.  Valid properties depend on the driver.  To get help on
-possible drivers and properties, use @code{-device help} and
-@code{-device @var{driver},help}.
-ETEXI
-
 STEXI
 @end table
 ETEXI
@@ -758,31 +781,6 @@ STEXI
 Create synthetic file system image
 ETEXI
 
-DEFHEADING()
-
-DEF("name", HAS_ARG, QEMU_OPTION_name,
-"-name string1[,process=string2]\n"
-"set the name of the guest\n"
-"string1 sets the window title and string2 the process 
name (on Linux)\n",
-QEMU_ARCH_ALL)
-STEXI
-@item -name @var{name}
-@findex -name
-Sets the @var{name} of the guest.
-This name will be displayed in the SDL window caption.
-The @var{name} will also be used for the VNC server.
-Also optionally set the top visible process name in Linux.
-ETEXI
-
-DEF("uuid", HAS_ARG, QEMU_OPTION_uuid,
-"-uuid %08x-%04x-%04x-%04x-%012x\n"
-"specify machine UUID\n", QEMU_ARCH_ALL)
-STEXI
-@item -uuid @var{uuid}
-@findex -uuid
-Set system UUID.
-ETEXI
-
 STEXI
 @end table
 ETEXI
-- 
1.7.11.7




Re: [Qemu-devel] [PATCH for-1.4 v2 4/6] qemu-option: Disable two helpful messages that got broken recently

2013-02-13 Thread Luiz Capitulino
On Fri, 08 Feb 2013 20:34:20 +0100
Markus Armbruster  wrote:

> > The real problem here is that the k, M, G suffixes, for example, are not
> > good to be reported by QMP. So maybe we should refactor the code in a way
> > that we separate what's done in QMP from what is done in HMP/command-line.
> 
> Isn't it separated already?  parse_option_size() is used when parsing
> key=value,...  Such strings should not exist in QMP.  If they do, it's a
> design bug.

No and no. Such strings don't exist in QMP as far as can tell (see bugs
below though), but parse_option_size() is theoretically "present" in a
possible QMP call stack:

qemu_opts_from_dict_1()
  qemu_opt_set_err()
opt_set()
  qemu_opt_paser()
parse_option_size()

I can't tell if this will ever happen because qemu_opts_from_dict_1()
restricts the call to qemu_opt_set_err() to certain values, but the
fact that it's not clear is an indication that a better separation is
necessary.

Now, I think I've found at least two bugs. The first one is the
netdev_add doc in the schema, which states that we do accept key=value
strings. The problem is here is that that's about the C API, on the
wire we act as before (ie. accepting each key as a separate argument).
The qapi-schame.json is more or less format-independent, so I'm not
exactly sure what's the best way to describe commands using QemuOpts
the way QMP uses it.

The second bug is that I entirely ignored how set_option_paramater()
handles errors when doing parse_option_size() conversion to Error **
and also when converting bdrv_img_create(). The end result is that
we can report an error twice, once with error_set() and later with
qerror_report() (or vice-versa). Shouldn't hurt on QMP as it knows
how to deal with this, on HMP and command-line we get complementary
error messages if we're lucky.

I'm very surprised with my mistakes on the second bug (although some
of the mess with fprintf() was already there), but I honestly think we
should defer this to 1.5 (and I can do it myself next week).



[Qemu-devel] [PATCH for-1.4 0/7] Option doc fixes for -help and qemu-doc

2013-02-13 Thread Markus Armbruster
Hope it's not too late for -help and doc fixes.

Markus Armbruster (7):
  help: Drop bogus help on -qtest and -qtest-log
  doc: Fix some option entries in qemu-doc's function index
  doc: Fill some option doc gaps in manual page and qemu-doc
  doc: Fix texinfo @table markup in qemu-options.hx
  help: Fix markup of heading "USB options" so it appears in -help
  doc help: A few options are under inappropriate headings, fix
  doc help: Collect block device stuff under its own heading

 qemu-options.hx | 754 +---
 1 file changed, 384 insertions(+), 370 deletions(-)

-- 
1.7.11.7




[Qemu-devel] [PATCH for-1.4 3/7] doc: Fill some option doc gaps in manual page and qemu-doc

2013-02-13 Thread Markus Armbruster

Signed-off-by: Markus Armbruster 
---
 qemu-options.hx | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index 932d6c5..d57cf2b 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -326,9 +326,9 @@ DEF("set", HAS_ARG, QEMU_OPTION_set,
 "set  parameter for item  of type \n"
 "i.e. -set drive.$id.file=/path/to/image\n", QEMU_ARCH_ALL)
 STEXI
-@item -set
+@item -set @var{group}.@var{id}.@var{arg}=@var{value}
 @findex -set
-TODO
+Set parameter @var{arg} for item @var{id} of type @var{group}\n"
 ETEXI
 
 DEF("global", HAS_ARG, QEMU_OPTION_global,
@@ -1000,7 +1000,7 @@ DEF("rotate", HAS_ARG, QEMU_OPTION_rotate,
 "-rotaterotate graphical output some deg left (only PXA LCD)\n",
 QEMU_ARCH_ALL)
 STEXI
-@item -rotate
+@item -rotate @var{deg}
 @findex -rotate
 Rotate graphical output some deg left (only PXA LCD).
 ETEXI
@@ -2858,7 +2858,7 @@ DEF("sandbox", HAS_ARG, QEMU_OPTION_sandbox, \
 "-sandbox   Enable seccomp mode 2 system call filter (default 
'off').\n",
 QEMU_ARCH_ALL)
 STEXI
-@item -sandbox
+@item -sandbox @var{arg}
 @findex -sandbox
 Enable Seccomp mode 2 system call filter. 'on' will enable syscall filtering 
and 'off' will
 disable it.  The default is 'off'.
@@ -2969,6 +2969,14 @@ DEF("object", HAS_ARG, QEMU_OPTION_object,
 "property must be set.  These objects are placed in the\n"
 "'/objects' path.\n",
 QEMU_ARCH_ALL)
+STEXI
+@item -object @var{typename}[,@var{prop1}=@var{value1},...]
+@findex -object
+Create an new object of type @var{typename} setting properties
+in the order they are specified.  Note that the 'id'
+property must be set.  These objects are placed in the
+'/objects' path.
+ETEXI
 
 HXCOMM This is the last statement. Insert new options before this line!
 STEXI
-- 
1.7.11.7




Re: [Qemu-devel] [PATCH for-1.4 1/7] help: Drop bogus help on -qtest and -qtest-log

2013-02-13 Thread Anthony Liguori

Haven't seen all the patches, but just FYI, this is too late for 1.4.
I'm already testing a locally tagged version.  But looks like it will
potentially be a nice cleanup!

Regards,

Anthony Liguori

Markus Armbruster  writes:

> Signed-off-by: Markus Armbruster 
> ---
>  qemu-options.hx | 10 +++---
>  1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 046bdc0..3800c9c 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -2928,13 +2928,9 @@ the @var{simple} tracing backend.
>  @end table
>  ETEXI
>  
> -DEF("qtest", HAS_ARG, QEMU_OPTION_qtest,
> -"-qtest CHR  specify tracing options\n",
> -QEMU_ARCH_ALL)
> -
> -DEF("qtest-log", HAS_ARG, QEMU_OPTION_qtest_log,
> -"-qtest-log LOG  specify tracing options\n",
> -QEMU_ARCH_ALL)
> +HXCOMM Internal use
> +DEF("qtest", HAS_ARG, QEMU_OPTION_qtest, "", QEMU_ARCH_ALL)
> +DEF("qtest-log", HAS_ARG, QEMU_OPTION_qtest_log, "", QEMU_ARCH_ALL)
>  
>  #ifdef __linux__
>  DEF("enable-fips", 0, QEMU_OPTION_enablefips,
> -- 
> 1.7.11.7




Re: [Qemu-devel] kvm segfaulting

2013-02-13 Thread Stefan Priebe

Hi,

Am 13.02.2013 16:24, schrieb Paolo Bonzini:

Il 13/02/2013 15:30, Stefan Priebe - Profihost AG ha scritto:

I added this:
-trace events=/tmp/events,file=/root/qemu.123.trace

and put the events in the events file as i couldn't handle \n in my app
starting the kvm process. But even when doing an fstrim the trace file
stays at 24 bytes - is this correct?


Right... it would eventually flush, but not if qemu-kvm crash.

Answering your other question, the patch subsumes the other.  But if the
provisioning mode is writesame_16, this hunk alone will most likely fix
the crash:


I've now added your "big" one but removed all you sent me in the past. 
Let's see what happens tomorrow morning. GMT+1


Thanks!

Greets,
Stefan



[Qemu-devel] [PATCH for-1.4 2/7] doc: Fix some option entries in qemu-doc's function index

2013-02-13 Thread Markus Armbruster

Signed-off-by: Markus Armbruster 
---
 qemu-options.hx | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index 3800c9c..932d6c5 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -446,6 +446,7 @@ DEF("mem-path", HAS_ARG, QEMU_OPTION_mempath,
 "-mem-path FILE  provide backing storage for guest RAM\n", QEMU_ARCH_ALL)
 STEXI
 @item -mem-path @var{path}
+@findex -mem-path
 Allocate guest RAM from a temporarily created file in @var{path}.
 ETEXI
 
@@ -455,6 +456,7 @@ DEF("mem-prealloc", 0, QEMU_OPTION_mem_prealloc,
 QEMU_ARCH_ALL)
 STEXI
 @item -mem-prealloc
+@findex -mem-prealloc
 Preallocate memory when using -mem-path.
 ETEXI
 #endif
@@ -827,7 +829,7 @@ DEF("curses", 0, QEMU_OPTION_curses,
 QEMU_ARCH_ALL)
 STEXI
 @item -curses
-@findex curses
+@findex -curses
 Normally, QEMU uses SDL to display the VGA output.  With this option,
 QEMU can display the VGA output when in text mode using a
 curses/ncurses interface.  Nothing is displayed in graphical mode.
@@ -1294,7 +1296,6 @@ STEXI
 Load SMBIOS entry from binary file.
 
 @item -smbios 
type=0[,vendor=@var{str}][,version=@var{str}][,date=@var{str}][,release=@var{%d.%d}]
-@findex -smbios
 Specify SMBIOS type 0 fields
 
 @item -smbios type=1[,manufacturer=@var{str}][,product=@var{str}] 
[,version=@var{str}][,serial=@var{str}][,uuid=@var{uuid}][,sku=@var{str}] 
[,family=@var{str}]
@@ -1409,6 +1410,7 @@ Not all devices are supported on all targets.  Use 
@code{-net nic,model=help}
 for a list of available devices for your target.
 
 @item -netdev user,id=@var{id}[,@var{option}][,@var{option}][,...]
+@findex -netdev
 @item -net user[,@var{option}][,@var{option}][,...]
 Use the user mode network stack which requires no administrator
 privilege to run. Valid options are:
@@ -2709,6 +2711,7 @@ DEF("watchdog-action", HAS_ARG, 
QEMU_OPTION_watchdog_action, \
 QEMU_ARCH_ALL)
 STEXI
 @item -watchdog-action @var{action}
+@findex -watchdog-action
 
 The @var{action} controls what QEMU will do when the watchdog timer
 expires.
-- 
1.7.11.7




[Qemu-devel] [Bug 1123975] [NEW] QEmu 1.3.90 cannot restore a 1.1.2 live snapshot

2013-02-13 Thread Francois Gouget
Public bug reported:

I have upgraded to QEmu 1.3.90 (Debian 1.4.0~rc0+dfsg-1exp) but now when
I try to restore a live snapshot made in QEmu 1.1.2 (Debian
1.1.2+dfsg-5) I get the following message:

virsh # snapshot-revert fgtbbuild wtb
error: operation failed: Error -22 while loading VM state

I have test VMs with live snapshots coreresponding to different testing
configurations. So I typically revert the VMs in one of the live
snapshots and run the tests. It would be pretty annoying to have to
recreate all these live snapshots any time I upgrade QEmu.


ipxe-qemu  1.0.0+git-20120202.f6840ba-3
qemu   1.4.0~rc0+dfsg-1exp
qemu-keymaps   1.4.0~rc0+dfsg-1exp
qemu-kvm   1.4.0~rc0+dfsg-1exp
qemu-system1.4.0~rc0+dfsg-1exp
qemu-system-arm1.4.0~rc0+dfsg-1exp
qemu-system-common 1.4.0~rc0+dfsg-1exp
qemu-system-mips   1.4.0~rc0+dfsg-1exp
qemu-system-misc   1.4.0~rc0+dfsg-1exp
qemu-system-ppc1.4.0~rc0+dfsg-1exp
qemu-system-sparc  1.4.0~rc0+dfsg-1exp
qemu-system-x861.4.0~rc0+dfsg-1exp
qemu-user  1.4.0~rc0+dfsg-1exp
qemu-utils 1.4.0~rc0+dfsg-1exp
libvirt-bin1.0.2-1
libvirt-dev1.0.2-1
libvirt-doc1.0.2-1
libvirt-glib-1.0-0 0.1.2-1
libvirt0   1.0.2-1
libvirtodbc0   6.1.4+dfsg1-5

** Affects: qemu
 Importance: Undecided
 Status: New

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

Title:
  QEmu 1.3.90 cannot restore a 1.1.2 live snapshot

Status in QEMU:
  New

Bug description:
  I have upgraded to QEmu 1.3.90 (Debian 1.4.0~rc0+dfsg-1exp) but now
  when I try to restore a live snapshot made in QEmu 1.1.2 (Debian
  1.1.2+dfsg-5) I get the following message:

  virsh # snapshot-revert fgtbbuild wtb
  error: operation failed: Error -22 while loading VM state

  I have test VMs with live snapshots coreresponding to different
  testing configurations. So I typically revert the VMs in one of the
  live snapshots and run the tests. It would be pretty annoying to have
  to recreate all these live snapshots any time I upgrade QEmu.

  
  ipxe-qemu  1.0.0+git-20120202.f6840ba-3
  qemu   1.4.0~rc0+dfsg-1exp
  qemu-keymaps   1.4.0~rc0+dfsg-1exp
  qemu-kvm   1.4.0~rc0+dfsg-1exp
  qemu-system1.4.0~rc0+dfsg-1exp
  qemu-system-arm1.4.0~rc0+dfsg-1exp
  qemu-system-common 1.4.0~rc0+dfsg-1exp
  qemu-system-mips   1.4.0~rc0+dfsg-1exp
  qemu-system-misc   1.4.0~rc0+dfsg-1exp
  qemu-system-ppc1.4.0~rc0+dfsg-1exp
  qemu-system-sparc  1.4.0~rc0+dfsg-1exp
  qemu-system-x861.4.0~rc0+dfsg-1exp
  qemu-user  1.4.0~rc0+dfsg-1exp
  qemu-utils 1.4.0~rc0+dfsg-1exp
  libvirt-bin1.0.2-1
  libvirt-dev1.0.2-1
  libvirt-doc1.0.2-1
  libvirt-glib-1.0-0 0.1.2-1
  libvirt0   1.0.2-1
  libvirtodbc0   6.1.4+dfsg1-5

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



[Qemu-devel] qemu / KVM modification to yield to external component (how to make it ignore the time the external component is running)

2013-02-13 Thread Lloret, Luis
Hi, qemu experts,

We are using qemu with KVM for some experiments that involve qemu yielding to 
an external process periodically. By yielding, what I mean is that qemu will 
stop executing for some time while the external process does its job and 
reports back to qemu. The external process is a remote HW model. The handshake 
happens with normal TCP sockets, and the platform that this is running on has 
the constraint that qemu and the external model cannot execute concurrently. So 
they need to work in a kind of ping-pong mode. That is why we need this 
synchronization mechanism. 

The yield is done inside a normal qemu timer callback. And this is the relevant 
code for what I am talking about.
// Install the timer
sim_sync_timer = qemu_new_timer_ns (vm_clock, sim_sync_callback, NULL);

-

// This is the callback definition. It just calls the sync function and 
reprograms the periodic timer
static void sim_sync_callback (void *p){
  qemutbx_send_sync (qemu_get_clock_ns (vm_clock));
  qemu_mod_timer (sim_sync_timer, qemu_get_clock_ns (vm_clock) + 
syncTimerExpiredTime );
}

--

// This is the function where we yield to the external program 
int qemu_send_sync (unsigned long long vmtime)
{
struct qemu_message msg;
memset(&msg,0,sizeof(struct qemutbx_message));
//vm_stop_sync();
msg.mtype   = QEMU_MESSAGE_SYNC;
msg.mAck= QEMU_MESSAGE_SYNC_DONE;
msg.vm_time = vmtime;

// send the sync message to the external program. We will wait here until the 
external program replies back
qemu_send_msg_and_wait_ack(&msg); // This is just blocking TCP send and 
receive
//vm_start();
return 0;
}


What we want is that this time where the external process is executing and qemu 
is waiting, was completely transparent to the software, drivers, etc, running 
inside qemu. And we do not care if clocks and time inside qemu deviate from 
real wall clock time. What we want is that this external execution time is not 
seen by qemu and the guest in general. So, for example if qemu runs for 2 
seconds of virtual time, then yields to the external process that takes 3 
seconds to process, what we expect is that when qemu resumes it does at virtual 
time 2, without trying to synchronize at all with the real time on the host. 
Like if the 3 seconds of real time hadn't existed.

So far, I have been trying with linux clocksources (to change from the default 
kvm-clock), vm_stop and vm_start (so that the yield to external happens inside 
a vm_stop / vm_start block), but nothing seems to work as I expect.

For example, some driver code seems to time out, because it is probably seeing 
the time that this external process is running (and qemu isn't) as time that 
has elapsed from its point of view. 

Perhaps this would be easier without KVM (I don't know), but KVM is a must 
too... 

Can someone give some pointers as to what we should do to achieve this? Any 
idea would be greatly appreciated.

Thanks in advance,
Luis



[Qemu-devel] [PATCH for-1.4 5/7] help: Fix markup of heading "USB options" so it appears in -help

2013-02-13 Thread Markus Armbruster

Signed-off-by: Markus Armbruster 
---
 qemu-options.hx | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index 8d288f5..071b1b3 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -538,9 +538,10 @@ ETEXI
 STEXI
 @end table
 ETEXI
+DEFHEADING()
 
+DEFHEADING(USB options:)
 STEXI
-USB options:
 @table @option
 ETEXI
 
-- 
1.7.11.7




[Qemu-devel] [PATCH for-1.4 1/7] help: Drop bogus help on -qtest and -qtest-log

2013-02-13 Thread Markus Armbruster

Signed-off-by: Markus Armbruster 
---
 qemu-options.hx | 10 +++---
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index 046bdc0..3800c9c 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -2928,13 +2928,9 @@ the @var{simple} tracing backend.
 @end table
 ETEXI
 
-DEF("qtest", HAS_ARG, QEMU_OPTION_qtest,
-"-qtest CHR  specify tracing options\n",
-QEMU_ARCH_ALL)
-
-DEF("qtest-log", HAS_ARG, QEMU_OPTION_qtest_log,
-"-qtest-log LOG  specify tracing options\n",
-QEMU_ARCH_ALL)
+HXCOMM Internal use
+DEF("qtest", HAS_ARG, QEMU_OPTION_qtest, "", QEMU_ARCH_ALL)
+DEF("qtest-log", HAS_ARG, QEMU_OPTION_qtest_log, "", QEMU_ARCH_ALL)
 
 #ifdef __linux__
 DEF("enable-fips", 0, QEMU_OPTION_enablefips,
-- 
1.7.11.7




Re: [Qemu-devel] [PATCH for-1.4 0/2] chardev-add

2013-02-13 Thread Anthony Liguori
Eric Blake  writes:

> On 02/13/2013 07:54 AM, Markus Armbruster wrote:
>> Why am I proposing these patches for 1.4?
>> 
>> PATCH 1/2 is a straightforward doc fix.
>> 
>> PATCH 2/2 cleans up a part of QAPI that has never been released,
>> before it's too late.  If we're already beyond the point where we can
>> do that, too bad, we'll live.
>> 
>> Please consider seriously.
>
> Seems reasonable to me to get this into 1.4.
>
> Series: Reviewed-by: Eric Blake 

Agreed. Assuming it doesn't break anything, I'll include it in -rc2.

Regards,

Anthony Liguori

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




Re: [Qemu-devel] using -net dump with tap networking

2013-02-13 Thread Laszlo Ersek
On 02/13/13 15:48, Alexey Kardashevskiy wrote:
> Hi!
>
> I am running qemu as:
>
> qemu/ppc64-softmmu/qemu-system-ppc64 -m 1024 -M pseries -trace
> events=trace_events -netdev user,id=virtnet,hostfwd=tcp::5000-:22
> -device virtio-net-pci,netdev=virtnet -nographic -vga none -enable-kvm
> -kernel vml36_64k -initrd 1.cpio
>
> Now I want to enable network dump. With the old "-net" syntax I could do
> that with "-net dump" but I cannot with the new syntax, tried many
> variants, none works. What would the correct syntax be for the case above?

Ugh, I'm a bit confused, but if I say something stupid that should still
help "ignite" the discussion.

So, in general there are two ways to specify this:

(1) -net dump,id=dump0,vlan=VLAN_ID,len=SIZE_LIMIT,file=PATHNAME

(2) -netdev dump,id=dump0,len=SIZE_LIMIT,file=PATHNAME

I believe the first option (legacy) should work.

The second one will not work; actually I think it will trigger an
assert. The generic init code in net_client_init1() [net/net.c] says:

NetClientState *peer = NULL;

/* Do not add to a vlan if it's a -netdev or a nic with a netdev=
 * parameter. */
if (!is_netdev &&
(opts->kind != NET_CLIENT_OPTIONS_KIND_NIC ||
 !opts->nic->has_netdev)) {
peer = net_hub_add_port(u.net->has_vlan ? u.net->vlan : 0, NULL);
}

if (net_client_init_fun[opts->kind](opts, name, peer) < 0) {

So in (2) we don't add the dump netdev to any hub/vlan; however the
specific code (net_init_dump(), [net/dump.c]) asserts (peer != NULL).

Otherwise I think the idea would be to add the dump netdev *afterwards*
to a vlan/hub, by changing its vlan property. See set_vlan() in
[hw/qdev-properties-system.c]; it calls net_hub_port_find() [net/hub.c]
whose task is to "Find a available port on a hub; otherwise create one
new port".

See
.

Hence I think you're back to (1), the legacy format. Assuming qemu
doesn't barf on that option immediately, I believe you *also* have to
add your "-netdev user" to the same hub as the dumper is on.

In total you have to create both netdevs (a, b) and assign both to a
common hub/vlan (c, d). Again, unfortunately the dump netdev only works
with the legacy format, but that already includes the assignment to the
hub (a, c). So you have to take care of creating the other netdev
(-netdev user, b), and assign it through its vlan qdev property to the
same hub (d), so that data can flow from it to the dump netdev.

Hm... Looks like you can't do that directly on "-netdev user" (it seems
to have no such property). "virtio-net-pci" does have it however. At
least in a quick "info qtree" check:

bus: main-system-bus
  type System
  dev: i440FX-pcihost, id ""
bus: pci.0
  type PCI
  dev: virtio-net-pci, id "net0"
dev-prop: vlan = 

Also confirmed by "qemu-system-x86_64 -device virtio-net-pci,help".

So

-netdev user,id=virtnet,hostfwd=tcp::5000-:22 \
-device virtio-net-pci,netdev=virtnet,vlan=2 \
-net dump,vlan=2,len=SIZE_LIMIT,file=PATHNAME

Or some such...

Laszlo



Re: [Qemu-devel] [Qemu-ppc] [PATCH] Fix circular dependency for HOST_LONG_BITS qemu-common.h <-> bswap.h

2013-02-13 Thread Andreas Färber
Am 13.02.2013 18:41, schrieb Anthony Liguori:
> David Gibson  writes:
> 
>> On Tue, Feb 05, 2013 at 11:42:30AM +0100, Andreas Färber wrote:
>>> Am 05.02.2013 01:07, schrieb Peter Maydell:
 On 4 February 2013 23:52, Richard Henderson  wrote:
> On 2013-02-04 15:30, David Gibson wrote:
>> Anthony, Richard, anyone?
>>
>> Please apply - qemu has now been build-broken on all big endian
>> platforms for a month.
>
>
> I know.  See also my bswap.h patch which also fixes the width
> of long vs uintptr_t.  No one seems willing to pick these up...

 In both cases, the patch:
  * was sent out after the soft freeze
  * doesn't have a "for-1.4" tag
  * doesn't have a summary line that clearly says "fixes build
failure" either
  * hasn't got a Reviewed-by: tag from anybody
>>>
>>> I ack'ed it, which in my terminology usually means that I reviewed and
>>> tested it.
>>>

 so I'm not terribly surprised they haven't got picked up.
 You could start by reviewing each others' patches :-)
>>>
>>> Personally I see no reason to keep around misnamed HOST_LONG_BITS at all
>>> when we can easily calculate its value using sizeof(uintptr_t) * 8 or
>>> replace it by different conditions as suggested by rth. I thus prefer
>>
>> Ok, I missed rth's patch to do this differently.  Note that sizeof()
>> will not work in this case, because we need the correct value at cpp
>> time.
>>
>>> his patch and have been waiting for Blue to pick it up for 1.4.
>>
>> Sure, whatever.  Can we please just get whichever damn fix *in*.
> 
> For the sake of completeness, "rth's patch" means:
> 
> commit 91107fdf4443d2171e06840e87277bb7a047343b
> Author: Richard Henderson 
> Date:   Mon Feb 4 16:21:06 2013 -0800
> 
> bswap: Fix width of swap in leul_to_cpu
> 
> Correct?

Yes.

> If so, this was committed before you sent this note.  Can someone
> confirm if we still have a problem on big endian hosts?

Around Central European lunch time today things seemed to compile fine,
and `make check` worked, too. (Thanks!)

Regards,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



Re: [Qemu-devel] [Qemu-ppc] [PATCH] Fix circular dependency for HOST_LONG_BITS qemu-common.h <-> bswap.h

2013-02-13 Thread Anthony Liguori
David Gibson  writes:

> On Tue, Feb 05, 2013 at 11:42:30AM +0100, Andreas Färber wrote:
>> Am 05.02.2013 01:07, schrieb Peter Maydell:
>> > On 4 February 2013 23:52, Richard Henderson  wrote:
>> >> On 2013-02-04 15:30, David Gibson wrote:
>> >>> Anthony, Richard, anyone?
>> >>>
>> >>> Please apply - qemu has now been build-broken on all big endian
>> >>> platforms for a month.
>> >>
>> >>
>> >> I know.  See also my bswap.h patch which also fixes the width
>> >> of long vs uintptr_t.  No one seems willing to pick these up...
>> > 
>> > In both cases, the patch:
>> >  * was sent out after the soft freeze
>> >  * doesn't have a "for-1.4" tag
>> >  * doesn't have a summary line that clearly says "fixes build
>> >failure" either
>> >  * hasn't got a Reviewed-by: tag from anybody
>> 
>> I ack'ed it, which in my terminology usually means that I reviewed and
>> tested it.
>> 
>> > 
>> > so I'm not terribly surprised they haven't got picked up.
>> > You could start by reviewing each others' patches :-)
>> 
>> Personally I see no reason to keep around misnamed HOST_LONG_BITS at all
>> when we can easily calculate its value using sizeof(uintptr_t) * 8 or
>> replace it by different conditions as suggested by rth. I thus prefer
>
> Ok, I missed rth's patch to do this differently.  Note that sizeof()
> will not work in this case, because we need the correct value at cpp
> time.
>
>> his patch and have been waiting for Blue to pick it up for 1.4.
>
> Sure, whatever.  Can we please just get whichever damn fix *in*.

For the sake of completeness, "rth's patch" means:

commit 91107fdf4443d2171e06840e87277bb7a047343b
Author: Richard Henderson 
Date:   Mon Feb 4 16:21:06 2013 -0800

bswap: Fix width of swap in leul_to_cpu

Correct?

If so, this was committed before you sent this note.  Can someone
confirm if we still have a problem on big endian hosts?

Regards,

Anthony Liguori

>
> -- 
> 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] [PATCH] pseries: Add cleanup hook for PAPR virtual LAN device

2013-02-13 Thread Anthony Liguori
Andreas Färber  writes:

> Am 11.02.2013 05:59, schrieb David Gibson:
>> Currently the spapr-vlan device does not supply a cleanup call for its
>> NetClientInfo structure.  With current qemu versions, that leads to a SEGV
>> on exit, when net_cleanup() attempts to call the cleanup handlers on all
>> net clients.
>> 
>> Signed-off-by: David Gibson 
>
> Tested-by: Andreas Färber 
>
> On Anthony's request I posted a patch that adds back the if surrounding
> the cleanup callback, fixing also the other affected nics.

Since this cleanup hook doesn't do anything useful and we need to apply
Andreas' patch anyway, I don't think there's any benefit to apply this one.

Regards,

Anthony Liguori

>
> Regards,
> Andreas
>
> -- 
> SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
> GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



Re: [Qemu-devel] [PATCH for-1.4 0/2] chardev-add

2013-02-13 Thread Eric Blake
On 02/13/2013 07:54 AM, Markus Armbruster wrote:
> Why am I proposing these patches for 1.4?
> 
> PATCH 1/2 is a straightforward doc fix.
> 
> PATCH 2/2 cleans up a part of QAPI that has never been released,
> before it's too late.  If we're already beyond the point where we can
> do that, too bad, we'll live.
> 
> Please consider seriously.

Seems reasonable to me to get this into 1.4.

Series: Reviewed-by: Eric Blake 

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH for-1.4 0/2] chardev-add

2013-02-13 Thread Laszlo Ersek
On 02/13/13 15:54, Markus Armbruster wrote:
> Why am I proposing these patches for 1.4?
> 
> PATCH 1/2 is a straightforward doc fix.
> 
> PATCH 2/2 cleans up a part of QAPI that has never been released,
> before it's too late.  If we're already beyond the point where we can
> do that, too bad, we'll live.
> 
> Please consider seriously.
> 
> Markus Armbruster (2):
>   chardev: Fix manual page and qemu-doc for -chardev tty
>   qapi: Flatten away ChardevPort
> 
>  qapi-schema.json | 11 +++-
>  qemu-char.c  | 76 
> ++--
>  qemu-options.hx  |  2 +-
>  3 files changed, 46 insertions(+), 43 deletions(-)
> 

Looks good to me.

Reviewed-by: Laszlo Ersek 



Re: [Qemu-devel] [PATCH 0/2] block: refuse negative iops and bps values

2013-02-13 Thread Kevin Wolf
Am 13.02.2013 16:53, schrieb Stefan Hajnoczi:
> These patches report an error if negative values are given for I/O throttling
> iops or bps.
> 
> Patch 1 gets do_check_io_limits() into shape so that we can add checks.
> 
> Patch 2 adds the negative check.
> 
> Stefan Hajnoczi (2):
>   block: use Error in do_check_io_limits()
>   block: refuse negative iops and bps values
> 
>  blockdev.c | 24 ++--
>  1 file changed, 18 insertions(+), 6 deletions(-)

Reviewed-by: Kevin Wolf 



Re: [Qemu-devel] [RFC ppc-next 39/39] target-ppc: Convert CPU definitions

2013-02-13 Thread Andreas Färber
Am 12.02.2013 17:48, schrieb Andreas Färber:
> Am 12.02.2013 11:13, schrieb Andreas Färber:
>> Turn the array of model definitions into a set of self-registering QOM
>> types with their own class_init. Unique identifiers are obtained from
>> the combination of PVR, SVR and family identifiers; this requires all
>> alias #defines to be removed from the list. Possibly there are some more
>> left after this commit that are not currently being compiled.
>>
>> Prepares for introducing abstract intermediate CPU types for families.
>>
>> Keep the right-aligned macro line breaks within 78 chars to aid
>> three-way merges.
>>
>> Signed-off-by: Andreas Färber 
>> ---
>>  target-ppc/cpu-qom.h|   17 -
>>  target-ppc/cpu.h|   20 --
>>  target-ppc/translate_init.c |  152 
>> ---
>>  3 Dateien geändert, 85 Zeilen hinzugefügt(+), 104 Zeilen entfernt(-)
> [...]
>> diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
>> index fd8bf00..93e38ba 100644
>> --- a/target-ppc/translate_init.c
>> +++ b/target-ppc/translate_init.c
> [...]
>> @@ -10316,20 +10317,7 @@ static const TypeInfo ppc_cpu_type_info = {
>>  
>>  static void ppc_cpu_register_types(void)
>>  {
>> -int i;
>> -
>>  type_register_static(&ppc_cpu_type_info);
>> -
>> -for (i = 0; i < ARRAY_SIZE(ppc_defs); i++) {
>> -const ppc_def_t *def = &ppc_defs[i];
>> -#if defined(TARGET_PPCEMB)
>> -/* When using the ppcemb target, we only support 440 style cores */
>> -if (def->mmu_model != POWERPC_MMU_BOOKE) {
>> -continue;
>> -}
>> -#endif
>> -ppc_cpu_register_model(def);
>> -}
>>  }
>>  
>>  type_init(ppc_cpu_register_types)
> 
> Sorry, I forgot to re-add the TARGET_PPCEMB check above.

Here's the fix (sorry for linewraps):

@@ -7507,6 +7507,14 @@ enum {
 /* PowerPC CPU definitions
  */
 #define POWERPC_DEF_PREFIX(pvr, svr, type)
 \
 glue(glue(glue(glue(pvr, _), svr), _), type)
+#if defined(TARGET_PPCEMB)
+#define POWERPC_DEF_CONDITION(type)
 \
+if (glue(POWERPC_MMU_, type) != POWERPC_MMU_BOOKE) {
 \
+return;
 \
+}
+#else
+#define POWERPC_DEF_CONDITION(type)
+#endif
 #define POWERPC_DEF_SVR(_name, _pvr, _svr, _type)
   \
 static void
 \
 glue(POWERPC_DEF_PREFIX(_pvr, _svr, _type), _cpu_class_init)
 \
@@ -7539,6 +7547,7 @@ enum {
 static void
 \
 glue(POWERPC_DEF_PREFIX(_pvr, _svr, _type),
_cpu_register_types)(void)  \
 {
 \
+POWERPC_DEF_CONDITION(_type)
 \
 type_register_static(
 \
 &glue(POWERPC_DEF_PREFIX(_pvr, _svr, _type),
_cpu_type_info));  \
 }
 \

I'll repost when the family definitions are cleaned up.

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



[Qemu-devel] [PATCH 0/2] block: refuse negative iops and bps values

2013-02-13 Thread Stefan Hajnoczi
These patches report an error if negative values are given for I/O throttling
iops or bps.

Patch 1 gets do_check_io_limits() into shape so that we can add checks.

Patch 2 adds the negative check.

Stefan Hajnoczi (2):
  block: use Error in do_check_io_limits()
  block: refuse negative iops and bps values

 blockdev.c | 24 ++--
 1 file changed, 18 insertions(+), 6 deletions(-)

-- 
1.8.1.2




[Qemu-devel] [PATCH 2/2] block: refuse negative iops and bps values

2013-02-13 Thread Stefan Hajnoczi
Negative I/O throttling iops and bps values do not make sense so reject
them with an error message.

Signed-off-by: Stefan Hajnoczi 
---
 blockdev.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/blockdev.c b/blockdev.c
index 9b03513..ba3759c 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -274,6 +274,16 @@ static bool do_check_io_limits(BlockIOLimit *io_limits, 
Error **errp)
 return false;
 }
 
+if (io_limits->bps[BLOCK_IO_LIMIT_TOTAL] < 0 ||
+io_limits->bps[BLOCK_IO_LIMIT_WRITE] < 0 ||
+io_limits->bps[BLOCK_IO_LIMIT_READ] < 0 ||
+io_limits->iops[BLOCK_IO_LIMIT_TOTAL] < 0 ||
+io_limits->iops[BLOCK_IO_LIMIT_WRITE] < 0 ||
+io_limits->iops[BLOCK_IO_LIMIT_READ] < 0) {
+error_setg(errp, "bps and iops values must be 0 or greater");
+return false;
+}
+
 return true;
 }
 
-- 
1.8.1.2




[Qemu-devel] [RFC PATCH v2 07/23] qcow2: handle_alloc(): Get rid of keep_clusters parameter

2013-02-13 Thread Kevin Wolf
handle_alloc() is now called with the offset at which the actual new
allocation starts instead of the offset at which the whole write request
starts, part of which may already be processed.

Signed-off-by: Kevin Wolf 
---
 block/qcow2-cluster.c |   44 +++-
 block/qcow2.h |5 +
 2 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 2492235..2f64bf7 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -873,12 +873,12 @@ static int do_alloc_cluster_offset(BlockDriverState *bs, 
uint64_t guest_offset,
  *
  *  -errno: in error cases
  *
- * TODO Get rid of keep_clusters, n_start, n_end
+ * TODO Get rid of n_start, n_end
  * TODO Make *bytes actually behave as specified above
  */
 static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset,
 uint64_t *host_offset, uint64_t *bytes, QCowL2Meta **m,
-int keep_clusters, int n_start, int n_end)
+int n_start, int n_end)
 {
 BDRVQcowState *s = bs->opaque;
 int l2_index;
@@ -889,7 +889,6 @@ static int handle_alloc(BlockDriverState *bs, uint64_t 
guest_offset,
 
 uint64_t alloc_offset;
 uint64_t alloc_cluster_offset;
-uint64_t keep_bytes = keep_clusters * s->cluster_size;
 
 trace_qcow2_handle_alloc(qemu_coroutine_self(), guest_offset, *host_offset,
  *bytes);
@@ -908,14 +907,13 @@ static int handle_alloc(BlockDriverState *bs, uint64_t 
guest_offset,
 return ret;
 }
 
-entry = be64_to_cpu(l2_table[l2_index + keep_clusters]);
+entry = be64_to_cpu(l2_table[l2_index]);
 
 /* For the moment, overwrite compressed clusters one by one */
 if (entry & QCOW_OFLAG_COMPRESSED) {
 nb_clusters = 1;
 } else {
-nb_clusters = count_cow_clusters(s, nb_clusters, l2_table,
- l2_index + keep_clusters);
+nb_clusters = count_cow_clusters(s, nb_clusters, l2_table, l2_index);
 }
 
 ret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
@@ -929,13 +927,8 @@ static int handle_alloc(BlockDriverState *bs, uint64_t 
guest_offset,
 }
 
 /* Calculate start and size of allocation */
-alloc_offset = guest_offset + keep_bytes;
-
-if (keep_clusters == 0) {
-alloc_cluster_offset = 0;
-} else {
-alloc_cluster_offset = *host_offset + keep_bytes;
-}
+alloc_offset = guest_offset;
+alloc_cluster_offset = *host_offset;
 
 /* Allocate, if necessary at a given offset in the image file */
 ret = do_alloc_cluster_offset(bs, alloc_offset, &alloc_cluster_offset,
@@ -958,13 +951,13 @@ static int handle_alloc(BlockDriverState *bs, uint64_t 
guest_offset,
  * newly allocated cluster to the end of the aread that the write
  * request actually writes to (excluding COW at the end)
  */
-int requested_sectors = n_end - keep_clusters * s->cluster_sectors;
+int requested_sectors = n_end;
 int avail_sectors = nb_clusters
 << (s->cluster_bits - BDRV_SECTOR_BITS);
-int alloc_n_start = keep_clusters == 0 ? n_start : 0;
+int alloc_n_start = *host_offset == 0 ? n_start : 0;
 int nb_sectors = MIN(requested_sectors, avail_sectors);
 
-if (keep_clusters == 0) {
+if (*host_offset == 0) {
 *host_offset = alloc_cluster_offset;
 }
 
@@ -1127,9 +1120,26 @@ again:
 goto done;
 }
 
+int alloc_n_start;
+int alloc_n_end;
+
+if (keep_clusters != 0) {
+offset = start_of_cluster(s, offset
+ + keep_clusters * 
s->cluster_size);
+cluster_offset = start_of_cluster(s, cluster_offset
+ + keep_clusters * 
s->cluster_size);
+
+alloc_n_start = 0;
+alloc_n_end = n_end - keep_clusters * s->cluster_sectors;
+} else {
+alloc_n_start = n_start;
+alloc_n_end = n_end;
+}
+
 cur_bytes = nb_clusters * s->cluster_size;
+
 ret = handle_alloc(bs, offset, &cluster_offset, &cur_bytes, m,
-   keep_clusters, n_start, n_end);
+   alloc_n_start, alloc_n_end);
 if (ret < 0) {
 return ret;
 }
diff --git a/block/qcow2.h b/block/qcow2.h
index 72e6d12..f90bfb1 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -262,6 +262,11 @@ enum {
 
 #define REFT_OFFSET_MASK 0xff00ULL
 
+static inline int64_t start_of_cluster(BDRVQcowState *s, int64_t offset)
+{
+return offset & ~(s->cluster_size - 1);
+}
+
 static inline int size_to_clusters(BDRVQcowState *s, int64_t size)
 {
 return (size + (s->cluster_size - 1)) >> s->cluster_bits;
-- 
1.7.6.5




[Qemu-devel] [PATCH 1/2] block: use Error in do_check_io_limits()

2013-02-13 Thread Stefan Hajnoczi
The do_check_io_limits() function returns false when I/O limits are
invalid but it doesn't set an Error to indicate why.  The two
do_check_io_limits() callers duplicate error reporting.  Solve this by
passing an Error pointer into do_check_io_limits().

Note that the two callers report slightly different errors: drive_init()
prints a custom error message while qmp_block_set_io_throttle() does
error_set(errp, QERR_INVALID_PARAMETER_COMBINATION).

QERR_INVALID_PARAMETER_COMBINATION is a generic error, see
include/qapi/qmp/qerror.h:

  #define QERR_INVALID_PARAMETER_COMBINATION \
ERROR_CLASS_GENERIC_ERROR, "Invalid parameter combination"

Since it is generic we are not obliged to keep this error.  Switch to
the custom error message which contains more information.

This patch prepares for adding additional checks with their own error
messages to do_check_io_limits().  The next patch adds a new check.

Signed-off-by: Stefan Hajnoczi 
---
 blockdev.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 63e6f1e..9b03513 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -255,7 +255,7 @@ static int parse_block_error_action(const char *buf, bool 
is_read)
 }
 }
 
-static bool do_check_io_limits(BlockIOLimit *io_limits)
+static bool do_check_io_limits(BlockIOLimit *io_limits, Error **errp)
 {
 bool bps_flag;
 bool iops_flag;
@@ -269,6 +269,8 @@ static bool do_check_io_limits(BlockIOLimit *io_limits)
  && ((io_limits->iops[BLOCK_IO_LIMIT_READ] != 0)
  || (io_limits->iops[BLOCK_IO_LIMIT_WRITE] != 0));
 if (bps_flag || iops_flag) {
+error_setg(errp, "bps(iops) and bps_rd/bps_wr(iops_rd/iops_wr) "
+ "cannot be used at the same time");
 return false;
 }
 
@@ -297,6 +299,7 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType 
block_default_type)
 int snapshot = 0;
 bool copy_on_read;
 int ret;
+Error *error = NULL;
 
 translation = BIOS_ATA_TRANSLATION_AUTO;
 media = MEDIA_DISK;
@@ -427,9 +430,9 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType 
block_default_type)
 io_limits.iops[BLOCK_IO_LIMIT_WRITE] =
qemu_opt_get_number(opts, "iops_wr", 0);
 
-if (!do_check_io_limits(&io_limits)) {
-error_report("bps(iops) and bps_rd/bps_wr(iops_rd/iops_wr) "
- "cannot be used at the same time");
+if (!do_check_io_limits(&io_limits, &error)) {
+error_report("%s", error_get_pretty(error));
+error_free(error);
 return NULL;
 }
 
@@ -975,8 +978,7 @@ void qmp_block_set_io_throttle(const char *device, int64_t 
bps, int64_t bps_rd,
 io_limits.iops[BLOCK_IO_LIMIT_READ] = iops_rd;
 io_limits.iops[BLOCK_IO_LIMIT_WRITE]= iops_wr;
 
-if (!do_check_io_limits(&io_limits)) {
-error_set(errp, QERR_INVALID_PARAMETER_COMBINATION);
+if (!do_check_io_limits(&io_limits, errp)) {
 return;
 }
 
-- 
1.8.1.2




[Qemu-devel] [RFC PATCH v2 09/23] qcow2: Clean up handle_alloc()

2013-02-13 Thread Kevin Wolf
Things can be simplified a bit now. No semantic changes.

Signed-off-by: Kevin Wolf 
---
 block/qcow2-cluster.c |  110 +++-
 1 files changed, 53 insertions(+), 57 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index e32bfe3..0642ffa 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -883,7 +883,6 @@ static int handle_alloc(BlockDriverState *bs, uint64_t 
guest_offset,
 unsigned int nb_clusters;
 int ret;
 
-uint64_t alloc_offset;
 uint64_t alloc_cluster_offset;
 
 trace_qcow2_handle_alloc(qemu_coroutine_self(), guest_offset, *host_offset,
@@ -925,72 +924,69 @@ static int handle_alloc(BlockDriverState *bs, uint64_t 
guest_offset,
 return 0;
 }
 
-/* Calculate start and size of allocation */
-alloc_offset = guest_offset;
-alloc_cluster_offset = *host_offset;
-
 /* Allocate, if necessary at a given offset in the image file */
-ret = do_alloc_cluster_offset(bs, alloc_offset, &alloc_cluster_offset,
+alloc_cluster_offset = *host_offset;
+ret = do_alloc_cluster_offset(bs, guest_offset, &alloc_cluster_offset,
   &nb_clusters);
 if (ret < 0) {
 goto fail;
 }
 
-/* save info needed for meta data update */
-if (nb_clusters > 0) {
-/*
- * requested_sectors: Number of sectors from the start of the first
- * newly allocated cluster to the end of the (possibly shortened
- * before) write request.
- *
- * avail_sectors: Number of sectors from the start of the first
- * newly allocated to the end of the last newly allocated cluster.
- *
- * nb_sectors: The number of sectors from the start of the first
- * newly allocated cluster to the end of the aread that the write
- * request actually writes to (excluding COW at the end)
- */
-int requested_sectors =
-(*bytes + offset_into_cluster(s, guest_offset))
->> BDRV_SECTOR_BITS;
-int avail_sectors = nb_clusters
-<< (s->cluster_bits - BDRV_SECTOR_BITS);
-int alloc_n_start = offset_into_cluster(s, guest_offset)
->> BDRV_SECTOR_BITS;
-int nb_sectors = MIN(requested_sectors, avail_sectors);
-
-if (*host_offset == 0) {
-*host_offset = alloc_cluster_offset;
-}
-
-*m = g_malloc0(sizeof(**m));
-
-**m = (QCowL2Meta) {
-.alloc_offset   = alloc_cluster_offset,
-.offset = alloc_offset & ~(s->cluster_size - 1),
-.nb_clusters= nb_clusters,
-.nb_available   = nb_sectors,
-
-.cow_start = {
-.offset = 0,
-.nb_sectors = alloc_n_start,
-},
-.cow_end = {
-.offset = nb_sectors * BDRV_SECTOR_SIZE,
-.nb_sectors = avail_sectors - nb_sectors,
-},
-};
-qemu_co_queue_init(&(*m)->dependent_requests);
-QLIST_INSERT_HEAD(&s->cluster_allocs, *m, next_in_flight);
-
-*bytes = MIN(*bytes, (nb_sectors * BDRV_SECTOR_SIZE)
- - offset_into_cluster(s, guest_offset));
-assert(*bytes != 0);
-} else {
+/* Can't extend contiguous allocation */
+if (nb_clusters == 0) {
 *bytes = 0;
 return 0;
 }
 
+/*
+ * Save info needed for meta data update.
+ *
+ * requested_sectors: Number of sectors from the start of the first
+ * newly allocated cluster to the end of the (possibly shortened
+ * before) write request.
+ *
+ * avail_sectors: Number of sectors from the start of the first
+ * newly allocated to the end of the last newly allocated cluster.
+ *
+ * nb_sectors: The number of sectors from the start of the first
+ * newly allocated cluster to the end of the aread that the write
+ * request actually writes to (excluding COW at the end)
+ */
+int requested_sectors =
+(*bytes + offset_into_cluster(s, guest_offset))
+>> BDRV_SECTOR_BITS;
+int avail_sectors = nb_clusters
+<< (s->cluster_bits - BDRV_SECTOR_BITS);
+int alloc_n_start = offset_into_cluster(s, guest_offset)
+>> BDRV_SECTOR_BITS;
+int nb_sectors = MIN(requested_sectors, avail_sectors);
+
+*host_offset = alloc_cluster_offset;
+
+*m = g_malloc0(sizeof(**m));
+
+**m = (QCowL2Meta) {
+.alloc_offset   = *host_offset,
+.offset = start_of_cluster(s, guest_offset),
+.nb_clusters= nb_clusters,
+.nb_available   = nb_sectors,
+
+.cow_start = {
+.offset = 0,
+.nb_sectors = alloc_n_start,
+},
+.cow_end = {
+.offset = nb_sectors * BDRV_SECTOR_SIZE,
+.nb_sectors = avail_sectors - nb_sectors,
+ 

[Qemu-devel] [RFC v5] target-i386: Slim conversion to X86CPU subclasses + KVM subclasses

2013-02-13 Thread Igor Mammedov
From: Andreas Färber 

Depends on http://lists.gnu.org/archive/html/qemu-devel/2013-02/msg00677.html

Move x86_def_t definition to header and embed into X86CPUClass.
Register types per built-in model definition.

Move version initialization from x86_cpudef_setup() to class_init().

Move default setting of CPUID_EXT_HYPERVISOR to class_init().

Move KVM specific built-in CPU defaults overrides in a kvm specific
x86_cpu_kvm_def_class_init(). And select TCG vs KVM class of CPU
to create at runtime in x86_cpu_class_by_name() when kvm_enable()
is available.

Inline cpu_x86_register() into the X86CPU initfn.
Since instance_init cannot reports errors, die there if some
of default values are incorrect, instead of ignoring errors.

Replace cpu_x86_find_by_name() with x86_cpu_class_by_name().
Move handling of KVM host vendor override from cpu_x86_find_by_name()
to the kvm_arch_init() and class_init(). Use TYPE_X86_CPU class to
communicate kvm specific defaults to other sub-classes.

Register host-kvm-{i386,x86_64}-cpu type from KVM code to avoid #ifdefs
and only when KVM is enabled to avoid workarounds in name to class
lookup code in x86_cpu_class_by_name().
Make kvm_cpu_fill_host() into a host specific class_init and inline
cpu_x86_fill_model_id().

Let kvm_check_features_against_host() obtain host-kvm-{i386,86_64}-cpu
for comparison.

Signed-off-by: Andreas Färber 
Signed-off-by: Igor Mammedov 
---
v5:
  * remove special case for 'host' CPU check in x86_cpu_class_by_name(),
due to 'host' CPU will not find anything if not in KVM mode or
return 'host' CPU class in KVM mode, i.e. treat it as regular CPUs.
  * register KVM specific subclasses for built-in CPU models.
  * abort() in instance_init() if property setter fails to set default
value.
v4:
  * set error if cpu model is not found and goto out;
  * copy vendor override from 'host' CPU class in sub-class'es
class_init() if 'host' CPU class is available.
  * register type TYPE_HOST_X86_CPU in kvm_arch_init(), this type
should be available only in KVM mode and we haven't printed it in
-cpu ? output so far, so we can continue doing so. It's not
really confusing to show 'host' cpu (even if we do it) when KVM
is not enabled.
---
 target-i386/cpu-qom.h |   24 
 target-i386/cpu.c |  348 +++--
 target-i386/cpu.h |5 +-
 target-i386/kvm.c |   72 ++
 4 files changed, 232 insertions(+), 217 deletions(-)

diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
index 48e6b54..c8f320d 100644
--- a/target-i386/cpu-qom.h
+++ b/target-i386/cpu-qom.h
@@ -30,6 +30,27 @@
 #define TYPE_X86_CPU "i386-cpu"
 #endif
 
+#define TYPE_HOST_X86_CPU "host-kvm-" TYPE_X86_CPU
+
+typedef struct x86_def_t {
+const char *name;
+uint32_t level;
+/* vendor is zero-terminated, 12 character ASCII string */
+char vendor[CPUID_VENDOR_SZ + 1];
+int family;
+int model;
+int stepping;
+uint32_t features, ext_features, ext2_features, ext3_features;
+uint32_t kvm_features, svm_features;
+uint32_t xlevel;
+char model_id[48];
+/* Store the results of Centaur's CPUID instructions */
+uint32_t ext4_features;
+uint32_t xlevel2;
+/* The feature bits on CPUID[EAX=7,ECX=0].EBX */
+uint32_t cpuid_7_0_ebx_features;
+} x86_def_t;
+
 #define X86_CPU_CLASS(klass) \
 OBJECT_CLASS_CHECK(X86CPUClass, (klass), TYPE_X86_CPU)
 #define X86_CPU(obj) \
@@ -41,6 +62,7 @@
  * X86CPUClass:
  * @parent_realize: The parent class' realize handler.
  * @parent_reset: The parent class' reset handler.
+ * @info: Model-specific data.
  *
  * An x86 CPU model or family.
  */
@@ -51,6 +73,8 @@ typedef struct X86CPUClass {
 
 DeviceRealize parent_realize;
 void (*parent_reset)(CPUState *cpu);
+
+x86_def_t info;
 } X86CPUClass;
 
 /**
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 1aee097..b786a57 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -47,8 +47,8 @@
 #include "hw/apic_internal.h"
 #endif
 
-static void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1,
- uint32_t vendor2, uint32_t vendor3)
+void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1,
+  uint32_t vendor2, uint32_t vendor3)
 {
 int i;
 for (i = 0; i < 4; i++) {
@@ -346,25 +346,6 @@ static void add_flagname_to_bitmaps(const char *flagname,
 }
 }
 
-typedef struct x86_def_t {
-const char *name;
-uint32_t level;
-/* vendor is zero-terminated, 12 character ASCII string */
-char vendor[CPUID_VENDOR_SZ + 1];
-int family;
-int model;
-int stepping;
-uint32_t features, ext_features, ext2_features, ext3_features;
-uint32_t kvm_features, svm_features;
-uint32_t xlevel;
-char model_id[48];
-/* Store the results of Centaur's CPUID instructions */
-uint32_t ext4_features;
-uint32_t xlevel2;
-/* The feature bits on CPUID[EAX=7,ECX=0].EBX */
-

[Qemu-devel] [RFC PATCH v2 12/23] qcow2: handle_copied(): Get rid of keep_clusters parameter

2013-02-13 Thread Kevin Wolf
Now *bytes is used to return the length of the area that can be written
to without performing an allocation or COW.

Signed-off-by: Kevin Wolf 
---
 block/qcow2-cluster.c |   23 +--
 1 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index cbe98bc..5ce2c88 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -828,19 +828,17 @@ static int handle_dependencies(BlockDriverState *bs, 
uint64_t guest_offset,
  *
  *  -errno: in error cases
  *
- * TODO Get rid of keep_clusters parameter
- * TODO Make bytes behave like described above
  * TODO Make non-zero host_offset behave like describe above
  */
 static int handle_copied(BlockDriverState *bs, uint64_t guest_offset,
-uint64_t *host_offset, uint64_t *bytes, QCowL2Meta **m,
-unsigned int *keep_clusters)
+uint64_t *host_offset, uint64_t *bytes, QCowL2Meta **m)
 {
 BDRVQcowState *s = bs->opaque;
 int l2_index;
 uint64_t cluster_offset;
 uint64_t *l2_table;
 unsigned int nb_clusters;
+unsigned int keep_clusters;
 int ret, pret;
 
 trace_qcow2_handle_copied(qemu_coroutine_self(), guest_offset, 
*host_offset,
@@ -870,17 +868,19 @@ static int handle_copied(BlockDriverState *bs, uint64_t 
guest_offset,
 && (cluster_offset & QCOW_OFLAG_COPIED))
 {
 /* We keep all QCOW_OFLAG_COPIED clusters */
-*keep_clusters =
+keep_clusters =
 count_contiguous_clusters(nb_clusters, s->cluster_size,
   &l2_table[l2_index], 0,
   QCOW_OFLAG_COPIED | QCOW_OFLAG_ZERO);
-assert(*keep_clusters <= nb_clusters);
+assert(keep_clusters <= nb_clusters);
+
+*bytes = MIN(*bytes,
+ keep_clusters * s->cluster_size
+ - offset_into_cluster(s, guest_offset));
 
 ret = 1;
 } else {
-*keep_clusters = 0;
 cluster_offset = 0;
-
 ret = 0;
 }
 
@@ -1164,16 +1164,19 @@ again:
  * 2. Count contiguous COPIED clusters.
  *TODO: Consider cluster_offset if set in step 1c.
  */
-ret = handle_copied(bs, offset, &cluster_offset, &cur_bytes, m,
-&keep_clusters);
+ret = handle_copied(bs, offset, &cluster_offset, &cur_bytes, m);
 if (ret < 0) {
 return ret;
 } else if (ret) {
+keep_clusters =
+size_to_clusters(s, cur_bytes + offset_into_cluster(s, offset));
 nb_clusters -= keep_clusters;
 
 if (!*host_offset) {
 *host_offset = cluster_offset;
 }
+} else {
+keep_clusters = 0;
 }
 
 /* If there is something left to allocate, do that now */
-- 
1.7.6.5




[Qemu-devel] [RFC PATCH v2 03/23] qcow2: Change handle_dependency to byte granularity

2013-02-13 Thread Kevin Wolf
Signed-off-by: Kevin Wolf 
---
 block/qcow2-cluster.c |   40 
 block/qcow2.h |   11 +++
 2 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 0e804ba..a3b2447 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -756,31 +756,41 @@ out:
  * Check if there already is an AIO write request in flight which allocates
  * the same cluster. In this case we need to wait until the previous
  * request has completed and updated the L2 table accordingly.
+ *
+ * Returns:
+ *   0   if there was no dependency. *cur_bytes indicates the number of
+ *   bytes from guest_offset that can be read before the next
+ *   dependency must be processed (or the request is complete)
+ *
+ *   -EAGAIN if we had to wait for another request, previously gathered
+ *   information on cluster allocation may be invalid now. The caller
+ *   must start over anyway, so consider *cur_bytes undefined.
  */
 static int handle_dependencies(BlockDriverState *bs, uint64_t guest_offset,
-unsigned int *nb_clusters)
+uint64_t *cur_bytes)
 {
 BDRVQcowState *s = bs->opaque;
 QCowL2Meta *old_alloc;
+uint64_t bytes = *cur_bytes;
 
 QLIST_FOREACH(old_alloc, &s->cluster_allocs, next_in_flight) {
 
-uint64_t start = guest_offset >> s->cluster_bits;
-uint64_t end = start + *nb_clusters;
-uint64_t old_start = old_alloc->offset >> s->cluster_bits;
-uint64_t old_end = old_start + old_alloc->nb_clusters;
+uint64_t start = guest_offset;
+uint64_t end = start + bytes;
+uint64_t old_start = l2meta_cow_start(old_alloc);
+uint64_t old_end = l2meta_cow_end(old_alloc);
 
 if (end <= old_start || start >= old_end) {
 /* No intersection */
 } else {
 if (start < old_start) {
 /* Stop at the start of a running allocation */
-*nb_clusters = old_start - start;
+bytes = old_start - start;
 } else {
-*nb_clusters = 0;
+bytes = 0;
 }
 
-if (*nb_clusters == 0) {
+if (bytes == 0) {
 /* Wait for the dependency to complete. We need to recheck
  * the free/allocated clusters when we continue. */
 qemu_co_mutex_unlock(&s->lock);
@@ -791,9 +801,9 @@ static int handle_dependencies(BlockDriverState *bs, 
uint64_t guest_offset,
 }
 }
 
-if (!*nb_clusters) {
-abort();
-}
+/* Make sure that existing clusters and new allocations are only used up to
+ * the next dependency if we shortened the request above */
+*cur_bytes = bytes;
 
 return 0;
 }
@@ -872,6 +882,7 @@ int qcow2_alloc_cluster_offset(BlockDriverState *bs, 
uint64_t offset,
 uint64_t *l2_table;
 unsigned int nb_clusters, keep_clusters;
 uint64_t cluster_offset;
+uint64_t cur_bytes;
 
 trace_qcow2_alloc_clusters_offset(qemu_coroutine_self(), offset,
   n_start, n_end);
@@ -884,6 +895,7 @@ again:
 l2_index = offset_to_l2_index(s, offset);
 nb_clusters = MIN(size_to_clusters(s, n_end << BDRV_SECTOR_BITS),
   s->l2_size - l2_index);
+n_end = MIN(n_end, nb_clusters * s->cluster_sectors);
 
 /*
  * Now start gathering as many contiguous clusters as possible:
@@ -908,7 +920,8 @@ again:
  * 3. If the request still hasn't completed, allocate new clusters,
  *considering any cluster_offset of steps 1c or 2.
  */
-ret = handle_dependencies(bs, offset, &nb_clusters);
+cur_bytes = (n_end - n_start) * BDRV_SECTOR_SIZE;
+ret = handle_dependencies(bs, offset, &cur_bytes);
 if (ret == -EAGAIN) {
 goto again;
 } else if (ret < 0) {
@@ -919,6 +932,9 @@ again:
  * correctly during the next loop iteration. */
 }
 
+nb_clusters = size_to_clusters(s, offset + cur_bytes)
+- (offset >> s->cluster_bits);
+
 /* Find L2 entry for the first involved cluster */
 ret = get_cluster_table(bs, offset, &l2_table, &l2_index);
 if (ret < 0) {
diff --git a/block/qcow2.h b/block/qcow2.h
index 1322012..72e6d12 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -303,6 +303,17 @@ static inline bool 
qcow2_need_accurate_refcounts(BDRVQcowState *s)
 return !(s->incompatible_features & QCOW2_INCOMPAT_DIRTY);
 }
 
+static inline uint64_t l2meta_cow_start(QCowL2Meta *m)
+{
+return m->offset + m->cow_start.offset;
+}
+
+static inline uint64_t l2meta_cow_end(QCowL2Meta *m)
+{
+return m->offset + m->cow_end.offset
++ (m->cow_end.nb_sectors << BDRV_SECTOR_BITS);
+}
+
 // FIXME Need qcow2_ prefix to global functions
 
 /* qcow2.c functions */
-- 
1.7.6.5




Re: [Qemu-devel] kvm segfaulting

2013-02-13 Thread Paolo Bonzini
Il 13/02/2013 15:30, Stefan Priebe - Profihost AG ha scritto:
> I added this:
> -trace events=/tmp/events,file=/root/qemu.123.trace
> 
> and put the events in the events file as i couldn't handle \n in my app
> starting the kvm process. But even when doing an fstrim the trace file
> stays at 24 bytes - is this correct?

Right... it would eventually flush, but not if qemu-kvm crash.

Answering your other question, the patch subsumes the other.  But if the
provisioning mode is writesame_16, this hunk alone will most likely fix
the crash:

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index d411586..4a0673c 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -178,6 +178,9 @@ static void scsi_aio_complete(void *opaque, int ret)
 assert(r->req.aiocb != NULL);
 r->req.aiocb = NULL;
 bdrv_acct_done(s->qdev.conf.bs, &r->acct);
+if (r->req.io_canceled) {
+goto done;
+}

 if (ret < 0) {
 if (scsi_handle_rw_error(r, -ret)) {

Paolo



Re: [Qemu-devel] [PATCH 3/5] target-i386: Slim conversion to X86CPU subclasses

2013-02-13 Thread Igor Mammedov
On Tue, 12 Feb 2013 12:48:47 -0200
Eduardo Habkost  wrote:

> On Mon, Feb 11, 2013 at 02:52:49AM +0100, Igor Mammedov wrote:
> > On Fri, 8 Feb 2013 16:13:02 -0200
> > Eduardo Habkost  wrote:
> > 
> > > On Fri, Feb 08, 2013 at 05:54:50PM +0100, Andreas Färber wrote:
> > > > Am 08.02.2013 15:52, schrieb Eduardo Habkost:
> > > > > On Fri, Feb 08, 2013 at 01:58:42PM +0100, Igor Mammedov wrote:
> > > > >> On Fri, 08 Feb 2013 12:16:17 +0100
> > > > >> Andreas Färber  wrote:
> > > > >>> Am 08.02.2013 10:03, schrieb Igor Mammedov:
> > > >  On Thu, 7 Feb 2013 13:08:19 -0200
> > > >  Eduardo Habkost  wrote:
> > > > 
> > > > > On Tue, Feb 05, 2013 at 05:39:22PM +0100, Igor Mammedov wrote:
> > > > >> @@ -2236,6 +2083,44 @@ static void x86_cpu_initfn(Object *obj)
> > > > >>  }
> > > > >>  }
> > > > >>  
> > > > >> +static void x86_cpu_def_class_init(ObjectClass *oc, void
> > > > >> *data) +{
> > > > >> +X86CPUClass *xcc = X86_CPU_CLASS(oc);
> > > > >> +ObjectClass *hoc =
> > > > >> object_class_by_name(TYPE_HOST_X86_CPU);
> > > > >> +X86CPUClass *hostcc;
> > > > >> +x86_def_t *def = data;
> > > > >> +int i;
> > > > >> +static const char *versioned_models[] = { "qemu32",
> > > > >> "qemu64", "athlon" }; +
> > > > >> +memcpy(&xcc->info, def, sizeof(x86_def_t));
> > > > >> +
> > > > >> +/* host cpu class is available if KVM is enabled,
> > > > >> + * get kvm overrides from it */
> > > > >> +if (hoc) {
> > > > >> +hostcc = X86_CPU_CLASS(hoc);
> > > > >> +/* sysenter isn't supported in compatibility mode on
> > > > >> AMD,
> > > > >> + * syscall isn't supported in compatibility mode on
> > > > >> Intel.
> > > > >> + * Normally we advertise the actual CPU vendor, but
> > > > >> you can
> > > > >> + * override this using the 'vendor' property if you
> > > > >> want to use
> > > > >> + * KVM's sysenter/syscall emulation in compatibility
> > > > >> mode and
> > > > >> + * when doing cross vendor migration
> > > > >> + */
> > > > >> +memcpy(xcc->info.vendor, hostcc->info.vendor,
> > > > >> +   sizeof(xcc->info.vendor));
> > > > >> +}
> > > > >
> > > > > Again, we have the same problem we had before, but now in the
> > > > > non-host classes. What if class_init is called before KVM is
> > > > > initialized? I believe we will be forced to move this hack to
> > > > > the instance init function.
> > > >  I believe, the in the case where non-host CPU classes might be
> > > >  initialized before KVM "-cpu ?" we do not care what their
> > > >  defaults are, since we only would use class names there and then
> > > >  exit.
> > > > 
> > > >  For case where classes could be inspected over QMP, OQM, KVM
> > > >  would be already initialized if enabled and we would get proper
> > > >  initialization order without hack.
> > > > > 
> > > > > Who guarantees that KVM will be already initialized when we get a
> > > > > QMP monitor? We can't do that today because of limitations in the
> > > > > QEMU main code, but I believe we want to get rid of this limitation
> > > > > eventually, instead of making it harder to get rid of.
> > > > > 
> > > > > If we could initialize KVM before QMP is initialized, we could
> > > > > simply initialize KVM before class_init is called, instead. It
> > > > > would be easier to reason about, and it would make the limitations
> > > > > of our code very clear to anybody reading the code in main().
> > > > That wouldn't work (currently) due to -device and -object being
> > > > command line options just like -enable-kvm, -disable-kvm and -machine
> > > > accel=.
> > > 
> > > Well, we could loop over the command-line options twice.
> > > 
> > > It is just an alternative that would be better than making class_init
> > > unreliable. I don't think it would be a great solution anyway.
> > > 
> > > > 
> > > > >>>
> > > > >>> I think you're missing Eduardo's and my point:
> > > > >>>
> > > > >>> diff --git a/vl.c b/vl.c
> > > > >>> index a8dc73d..6b9378e 100644
> > > > >>> --- a/vl.c
> > > > >>> +++ b/vl.c
> > > > >>> @@ -2844,6 +2844,7 @@ int main(int argc, char **argv, char **envp)
> > > > >>>  }
> > > > >>>
> > > > >>>  module_call_init(MODULE_INIT_QOM);
> > > > >>> +object_class_foreach(walkerfn, TYPE_OBJECT, false, NULL);
> > > > >>>
> > > > >>>  qemu_add_opts(&qemu_drive_opts);
> > > > >>>  qemu_add_opts(&qemu_chardev_opts);
> > > > >>>
> > > > >>> Anyone may iterate over QOM classes at any time after their type
> > > > >>> registration, which is before the first round of option parsing.
> > > > >>> Sometime later, after option parsing, there's the -cpu ? handling
> > > > >>> in vl.c:3854, then vl.c:4018:configure_accelerator().
> > > > >>>
> > > > >>> Like I said, mos

[Qemu-devel] [RFC PATCH v2 13/23] qcow2: handle_copied(): Implement non-zero host_offset

2013-02-13 Thread Kevin Wolf
Look only for clusters that start at a given physical offset.

Signed-off-by: Kevin Wolf 
---
 block/qcow2-cluster.c |   26 ++
 1 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 5ce2c88..90fe36c 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -827,8 +827,6 @@ static int handle_dependencies(BlockDriverState *bs, 
uint64_t guest_offset,
  *  the length of the area that can be written to.
  *
  *  -errno: in error cases
- *
- * TODO Make non-zero host_offset behave like describe above
  */
 static int handle_copied(BlockDriverState *bs, uint64_t guest_offset,
 uint64_t *host_offset, uint64_t *bytes, QCowL2Meta **m)
@@ -843,7 +841,6 @@ static int handle_copied(BlockDriverState *bs, uint64_t 
guest_offset,
 
 trace_qcow2_handle_copied(qemu_coroutine_self(), guest_offset, 
*host_offset,
   *bytes);
-assert(*host_offset == 0);
 
 /*
  * Calculate the number of clusters to look for. We stop at L2 table
@@ -867,6 +864,15 @@ static int handle_copied(BlockDriverState *bs, uint64_t 
guest_offset,
 if (qcow2_get_cluster_type(cluster_offset) == QCOW2_CLUSTER_NORMAL
 && (cluster_offset & QCOW_OFLAG_COPIED))
 {
+/* If a specific host_offset is required, check it */
+if (*host_offset != 0
+&& (cluster_offset & L2E_OFFSET_MASK) != *host_offset)
+{
+*bytes = 0;
+ret = 0;
+goto out;
+}
+
 /* We keep all QCOW_OFLAG_COPIED clusters */
 keep_clusters =
 count_contiguous_clusters(nb_clusters, s->cluster_size,
@@ -880,19 +886,22 @@ static int handle_copied(BlockDriverState *bs, uint64_t 
guest_offset,
 
 ret = 1;
 } else {
-cluster_offset = 0;
 ret = 0;
 }
 
-cluster_offset &= L2E_OFFSET_MASK;
-*host_offset = cluster_offset;
-
 /* Cleanup */
+out:
 pret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
 if (pret < 0) {
 return pret;
 }
 
+/* Only return a host offset if we actually made progress. Otherwise we
+ * would make requirements for handle_alloc() that it can't fulfill */
+if (ret) {
+*host_offset = cluster_offset & L2E_OFFSET_MASK;
+}
+
 return ret;
 }
 
@@ -1162,7 +1171,6 @@ again:
 
 /*
  * 2. Count contiguous COPIED clusters.
- *TODO: Consider cluster_offset if set in step 1c.
  */
 ret = handle_copied(bs, offset, &cluster_offset, &cur_bytes, m);
 if (ret < 0) {
@@ -1175,6 +1183,8 @@ again:
 if (!*host_offset) {
 *host_offset = cluster_offset;
 }
+} else if (cur_bytes == 0) {
+goto done;
 } else {
 keep_clusters = 0;
 }
-- 
1.7.6.5




[Qemu-devel] [RFC PATCH v2 23/23] qcow2: Gather clusters in a looping loop

2013-02-13 Thread Kevin Wolf
Instead of just checking once in exactly this order if there are
dependendies, non-COW clusters and new allocation, this starts looping
around these. This way we can, for example, gather non-COW clusters after
new allocations as long as the host cluster offsets stay contiguous.

More importantly, after overwriting a COW in handle_dependencies() we
can now continue with gathering other clusters (we couldn't do that
before because we would miss a possible second dependency in one of the
next clusters).

This means that in the typical sequential write case, we can combine the
COW overwrite of one cluster with the allocation of the next cluster.
Only by avoiding splitting requests this way Delayed COW actually starts
improving performance noticably.

Signed-off-by: Kevin Wolf 
---
 block/qcow2-cluster.c |   66 ++--
 1 files changed, 30 insertions(+), 36 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 5a97d87..34f7299 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1209,16 +1209,16 @@ static int handle_alloc(BlockDriverState *bs, uint64_t 
guest_offset,
 nb_clusters = count_cow_clusters(s, nb_clusters, l2_table, l2_index);
 }
 
+/* This function is only called when there were no non-COW clusters, so if
+ * we can't find any unallocated or COW clusters either, something is
+ * wrong with our code. */
+assert(nb_clusters > 0);
+
 ret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
 if (ret < 0) {
 return ret;
 }
 
-if (nb_clusters == 0) {
-*bytes = 0;
-return 0;
-}
-
 /* Allocate, if necessary at a given offset in the image file */
 alloc_cluster_offset = *host_offset;
 ret = do_alloc_cluster_offset(bs, guest_offset, &alloc_cluster_offset,
@@ -1334,9 +1334,27 @@ again:
 remaining = (n_end - n_start) << BDRV_SECTOR_BITS;
 cluster_offset = 0;
 *host_offset = 0;
+cur_bytes = 0;
 *m = NULL;
 
 while (true) {
+
+if (!*host_offset) {
+*host_offset = start_of_cluster(s, cluster_offset);
+}
+
+assert(remaining >= cur_bytes);
+
+start   += cur_bytes;
+remaining   -= cur_bytes;
+cluster_offset  += cur_bytes;
+
+if (remaining == 0) {
+break;
+}
+
+cur_bytes = remaining;
+
 /*
  * Now start gathering as many contiguous clusters as possible:
  *
@@ -1355,20 +1373,17 @@ again:
  * the right synchronisation between the in-flight request and
  * the new one.
  */
-cur_bytes = remaining;
 ret = handle_dependencies(bs, start, &cluster_offset, &cur_bytes, m);
 if (ret == -EAGAIN) {
+/* Currently handle_dependencies() doesn't yield if we already had
+ * an allocation. If it did, we would have to clean up the L2Meta
+ * structs before starting over. */
+assert(*m == NULL);
 goto again;
 } else if (ret < 0) {
 return ret;
 } else if (ret) {
-*host_offset = start_of_cluster(s, cluster_offset);
-
-start   += cur_bytes;
-remaining   -= cur_bytes;
-cluster_offset  += cur_bytes;
-
-break;
+continue;
 } else if (cur_bytes == 0) {
 break;
 } else {
@@ -1384,24 +1399,11 @@ again:
 if (ret < 0) {
 return ret;
 } else if (ret) {
-if (!*host_offset) {
-*host_offset = cluster_offset;
-}
-
-start   += cur_bytes;
-remaining   -= cur_bytes;
-cluster_offset  += cur_bytes;
-
-cur_bytes = remaining;
+continue;
 } else if (cur_bytes == 0) {
 break;
 }
 
-/* If there is something left to allocate, do that now */
-if (remaining == 0) {
-break;
-}
-
 /*
  * 3. If the request still hasn't completed, allocate new clusters,
  *considering any cluster_offset of steps 1c or 2.
@@ -1410,15 +1412,7 @@ again:
 if (ret < 0) {
 return ret;
 } else if (ret) {
-if (!*host_offset) {
-*host_offset = cluster_offset;
-}
-
-start   += cur_bytes;
-remaining   -= cur_bytes;
-cluster_offset  += cur_bytes;
-
-break;
+continue;
 } else {
 assert(cur_bytes == 0);
 break;
-- 
1.7.6.5




[Qemu-devel] [RFC PATCH v2 15/23] qcow2: Allow requests with multiple l2metas

2013-02-13 Thread Kevin Wolf
Instead of expecting a single l2meta, have a list of them. This allows
to still have a single I/O request for the guest data, even though
multiple l2meta may be needed in order to describe both a COW overwrite
and a new cluster allocation (typical sequential write case).

Signed-off-by: Kevin Wolf 
---
 block/qcow2-cluster.c |3 +++
 block/qcow2.c |   14 +++---
 block/qcow2.h |3 +++
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 9e6b746..645ea25 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -1057,12 +1057,15 @@ static int handle_alloc(BlockDriverState *bs, uint64_t 
guest_offset,
 int alloc_n_start = offset_into_cluster(s, guest_offset)
 >> BDRV_SECTOR_BITS;
 int nb_sectors = MIN(requested_sectors, avail_sectors);
+QCowL2Meta *old_m = *m;
 
 *host_offset = alloc_cluster_offset;
 
 *m = g_malloc0(sizeof(**m));
 
 **m = (QCowL2Meta) {
+.next   = old_m,
+
 .alloc_offset   = *host_offset,
 .offset = start_of_cluster(s, guest_offset),
 .nb_clusters= nb_clusters,
diff --git a/block/qcow2.c b/block/qcow2.c
index 971dd42..345487e 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -824,7 +824,9 @@ static coroutine_fn int qcow2_co_writev(BlockDriverState 
*bs,
 goto fail;
 }
 
-if (l2meta != NULL) {
+while (l2meta != NULL) {
+QCowL2Meta *next;
+
 ret = qcow2_alloc_cluster_link_l2(bs, l2meta);
 if (ret < 0) {
 goto fail;
@@ -837,8 +839,9 @@ static coroutine_fn int qcow2_co_writev(BlockDriverState 
*bs,
 
 qemu_co_queue_restart_all(&l2meta->dependent_requests);
 
+next = l2meta->next;
 g_free(l2meta);
-l2meta = NULL;
+l2meta = next;
 }
 
 remaining_sectors -= cur_nr_sectors;
@@ -851,12 +854,17 @@ static coroutine_fn int qcow2_co_writev(BlockDriverState 
*bs,
 fail:
 qemu_co_mutex_unlock(&s->lock);
 
-if (l2meta != NULL) {
+while (l2meta != NULL) {
+QCowL2Meta *next;
+
 if (l2meta->nb_clusters != 0) {
 QLIST_REMOVE(l2meta, next_in_flight);
 }
 qemu_co_queue_restart_all(&l2meta->dependent_requests);
+
+next = l2meta->next;
 g_free(l2meta);
+l2meta = next;
 }
 
 qemu_iovec_destroy(&hd_qiov);
diff --git a/block/qcow2.h b/block/qcow2.h
index bfdf71d..9b16538 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -246,6 +246,9 @@ typedef struct QCowL2Meta
  */
 Qcow2COWRegion cow_end;
 
+/** Pointer to next L2Meta of the same write request */
+struct QCowL2Meta *next;
+
 QLIST_ENTRY(QCowL2Meta) next_in_flight;
 } QCowL2Meta;
 
-- 
1.7.6.5




  1   2   >