[Qemu-devel] [PATCH V11 6/7] libqblock API implement

2012-11-24 Thread Wenchao Xia
  This patch contains implemention for APIs.
Important APIs:
  1 QBlockContext. This structure was used to retrieve errors, every thread
must create one first.
  2 QBlockImage. It stands for an block image object.
  3 QBlockStaticInfo. It contains static information such as location, backing
file, size.
  4 Sync I/O. It is similar to C file open, read, write and close operations.

v11:
  Moved API design out of this patch.
  Spell fix.
  Use a new function in libqblock-aio.c to do bdrv init and aio init, removed
this section from library loading call back function, which allows map different
aio-context to differenct QBlockContext in the future.
  Renamed QBlockState to QBlockImage.
  Added reference counter in QBlockImage, which is only used in new/delete pair
function now.
  Removed useless parentheses around  argument.
  Move virt_size out of format unions, removed virt_size from 
QBlockStaticInfoAddr.
  bdrv_read and bdrv_write, Report I/O error when block api return negative 
value.
  qb_check_allocation, fixed the length check condition and added comments for
it.
  qb_info_image_static_get, renamed info to p_info and info_tmp to info, also
renamed all double pointing parameters with prefix “p_”in all API.
  qb_str2fmttype and qb_fmttype2str, added parameter check.
  qb_setup_info_addr, moved memset into it.
  qb_info_image_static_get, added format valid check, removed variable 
member_addr,
moved memset to qb_setup_info_addr.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 libqblock/libqblock-aio.c   |  110 -
 libqblock/libqblock-error.c |   57 ++
 libqblock/libqblock.c   | 1191 ++-
 3 files changed, 1349 insertions(+), 9 deletions(-)

diff --git a/libqblock/libqblock-aio.c b/libqblock/libqblock-aio.c
index 605eee8..97d7ad9 100644
--- a/libqblock/libqblock-aio.c
+++ b/libqblock/libqblock-aio.c
@@ -11,31 +11,63 @@
  *
  */
 
+/* This file was only used in libqblock, codes are copied from main-loop.c,
+ iohandler.c, compatfd.c now, it may have different implemention in the future.
+*/
+
 #include sys/syscall.h
 
+#include libqblock-aio.h
+
 #include qemu-common.h
 #include qemu-aio.h
 #include main-loop.h
 #include compatfd.h
 
-void qemu_notify_event(void)
+#include block.h
+
+/* Aio support, copied from main-loop.c */
+
+static AioContext *qemu_aio_context;
+
+/* This function should only be called once now. */
+void libqblock_aio_init(void)
 {
+GSource *src;
+
+qemu_aio_context = aio_context_new();
+/* bdrv_init must be called after qemu_aio_context was set. */
+bdrv_init();
+
+src = aio_get_g_source(qemu_aio_context);
+g_source_attach(src, NULL);
+g_source_unref(src);
 return;
 }
 
+void qemu_notify_event(void)
+{
+if (!qemu_aio_context) {
+return;
+}
+aio_notify(qemu_aio_context);
+}
+
+/* Functions to operate on the main QEMU AioContext.  */
+
 QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
 {
-return NULL;
+return aio_bh_new(qemu_aio_context, cb, opaque);
 }
 
 void qemu_aio_flush(void)
 {
-return;
+aio_flush(qemu_aio_context);
 }
 
 bool qemu_aio_wait(void)
 {
-return false;
+return aio_poll(qemu_aio_context, true);
 }
 
 #ifdef CONFIG_POSIX
@@ -45,7 +77,8 @@ void qemu_aio_set_fd_handler(int fd,
  AioFlushHandler *io_flush,
  void *opaque)
 {
-return;
+aio_set_fd_handler(qemu_aio_context, fd, io_read, io_write, io_flush,
+   opaque);
 }
 #endif
 
@@ -53,22 +86,83 @@ void qemu_aio_set_event_notifier(EventNotifier *notifier,
  EventNotifierHandler *io_read,
  AioFlushEventNotifierHandler *io_flush)
 {
-return;
+aio_set_event_notifier(qemu_aio_context, notifier, io_read, io_flush);
 }
 
+
+/* Signal fd support, copied from compatfd.c */
+
 bool qemu_signalfd_available(void)
 {
+#ifdef CONFIG_SIGNALFD
+sigset_t mask;
+int fd;
+bool ok;
+sigemptyset(mask);
+errno = 0;
+fd = syscall(SYS_signalfd, -1, mask, _NSIG / 8);
+ok = (errno != ENOSYS);
+if (fd = 0) {
+close(fd);
+}
+return ok;
+#else
 return false;
+#endif
 }
 
-typedef struct IOHandlerRecord IOHandlerRecord;
 
+/* Fd handler support, copied from iohandler.c. */
+
+typedef struct IOHandlerRecord {
+IOCanReadHandler *fd_read_poll;
+IOHandler *fd_read;
+IOHandler *fd_write;
+void *opaque;
+QLIST_ENTRY(IOHandlerRecord) next;
+int fd;
+bool deleted;
+} IOHandlerRecord;
+
+static QLIST_HEAD(, IOHandlerRecord) io_handlers =
+QLIST_HEAD_INITIALIZER(io_handlers);
+
+/* XXX: fd_read_poll should be suppressed, but an API change is
+   necessary in the character devices to suppress fd_can_read(). */
 int qemu_set_fd_handler2(int fd,
  IOCanReadHandler *fd_read_poll,
  IOHandler *fd_read,
  IOHandler 

[Qemu-devel] [PATCH V11 3/7] block export function path_has_protocol

2012-11-24 Thread Wenchao Xia
  This function is needed in other module, so export it. There is
already some patch on mail-list try export it, If that patch was applied,
pls ignore this one.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 block.c |2 +-
 block.h |2 ++
 2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/block.c b/block.c
index 854ebd6..bfb2be8 100644
--- a/block.c
+++ b/block.c
@@ -199,7 +199,7 @@ static void bdrv_io_limits_intercept(BlockDriverState *bs,
 }
 
 /* check if the path starts with protocol: */
-static int path_has_protocol(const char *path)
+int path_has_protocol(const char *path)
 {
 const char *p;
 
diff --git a/block.h b/block.h
index 722c620..6805245 100644
--- a/block.h
+++ b/block.h
@@ -428,6 +428,8 @@ typedef enum {
 BLKDBG_EVENT_MAX,
 } BlkDebugEvent;
 
+int path_has_protocol(const char *path);
+
 #define BLKDBG_EVENT(bs, evt) bdrv_debug_event(bs, evt)
 void bdrv_debug_event(BlockDriverState *bs, BlkDebugEvent event);
 
-- 
1.7.1





[Qemu-devel] [PATCH V11 5/7] libqblock API design and type defines

2012-11-24 Thread Wenchao Xia
  Public API design header files: libqblock.h, libqblock-error.h.
  Public type define header files: libqblock-types.h.
  Private internal used header files: libqblock-internal, libqblock-aio.h.

  For ABI some reserved bytes are used in structure defines.

v11:
  Moved API design into this patch.
  Added libqblock-aio.h, which contain aio internal function prototype,
although it is not implemented yet.
  Added doc about thread not safe in libqblock.h.
  Moved including of block_int.h from libqblock.h to libqblock.c
  Spell fix.
  Use g_malloc0_n instead of g_malloc0.
  Renamed FUNC_CLEAN to QB_CLEAN, removed unused macros, use glib function 
directly,
for malloc, free and strdup.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 libqblock/libqblock-aio.h  |6 +
 libqblock/libqblock-error.h|   49 ++
 libqblock/libqblock-internal.h |   68 
 libqblock/libqblock-types.h|  245 
 libqblock/libqblock.h  |  345 +++-
 5 files changed, 712 insertions(+), 1 deletions(-)
 create mode 100644 libqblock/libqblock-aio.h
 create mode 100644 libqblock/libqblock-internal.h

diff --git a/libqblock/libqblock-aio.h b/libqblock/libqblock-aio.h
new file mode 100644
index 000..956331f
--- /dev/null
+++ b/libqblock/libqblock-aio.h
@@ -0,0 +1,6 @@
+#ifndef LIBQBLOCK_AIO_H
+#define LIBQBLOCK_AIO_H
+
+void libqblock_aio_init(void);
+
+#endif
diff --git a/libqblock/libqblock-error.h b/libqblock/libqblock-error.h
index e69de29..4ffd1f1 100644
--- a/libqblock/libqblock-error.h
+++ b/libqblock/libqblock-error.h
@@ -0,0 +1,49 @@
+/*
+ * QEMU block layer library
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Wenchao Xia   xiaw...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#ifndef LIBQBLOCK_ERROR
+#define LIBQBLOCK_ERROR
+
+#include libqblock-types.h
+
+#define QB_ERR_INTERNAL_ERR (-1)
+#define QB_ERR_INVALID_PARAM (-100)
+#define QB_ERR_BLOCK_OUT_OF_RANGE (-101)
+
+/* error handling */
+/**
+ * qb_error_get_human_str: get human readable error string.
+ *
+ * return a human readable string, it would be truncated if buf is not big
+ *  enough.
+ *
+ * @context: operation context, must be valid.
+ * @buf: buf to receive the string.
+ * @buf_size: the size of the string buf.
+ */
+DLL_PUBLIC
+void qb_error_get_human_str(QBlockContext *context,
+char *buf, size_t buf_size);
+
+/**
+ * qb_error_get_errno: get error number, only valid when err_ret is
+ *   QB_ERR_INTERNAL_ERR.
+ *
+ * return negative errno if last error is QB_ERR_INTERNAL_ERR, otherwise 0.
+ *
+ * @context: operation context.
+ */
+DLL_PUBLIC
+int qb_error_get_errno(QBlockContext *context);
+
+#endif
diff --git a/libqblock/libqblock-internal.h b/libqblock/libqblock-internal.h
new file mode 100644
index 000..93f24d9
--- /dev/null
+++ b/libqblock/libqblock-internal.h
@@ -0,0 +1,68 @@
+/*
+ * QEMU block layer library
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Wenchao Xia   xiaw...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#ifndef LIBQBLOCK_INTERNAL
+#define LIBQBLOCK_INTERNAL
+
+#include glib.h
+
+#include block.h
+#include libqblock-types.h
+
+/* this file contains defines and types used inside the library. */
+
+#define QB_FREE(p) { \
+g_free(p); \
+(p) = NULL; \
+}
+
+/* details should be hidden to user */
+struct QBlockImage {
+BlockDriverState *bdrvs;
+/* internal used file name now, if it is not NULL, it means
+   image was opened.
+*/
+char *filename;
+int ref_count;
+};
+
+struct QBlockContext {
+/* last error */
+GError *g_error;
+int err_ret; /* 1st level of error, the libqblock error number */
+int err_no; /* 2nd level of error, errno what below reports */
+};
+
+/**
+ * QBlockStaticInfoAddr: a structure contains a set of pointer.
+ *
+ *this struct contains a set of pointer pointing to some
+ *  property related to format or protocol. If a property is not available,
+ *  it will be set as NULL. User could use this to get properties directly.
+ *
+ *  @backing_loc: backing file location.
+ *  @encrypt: encryption flag.
+*/
+
+typedef struct QBlockStaticInfoAddr {
+QBlockLocationInfo *backing_loc;
+bool *encrypt;
+} QBlockStaticInfoAddr;
+
+#define G_LIBQBLOCK_ERROR g_libqblock_error_quark()
+
+static inline GQuark g_libqblock_error_quark(void)
+{
+return g_quark_from_static_string(g-libqblock-error-quark);
+}
+#endif
diff --git a/libqblock/libqblock-types.h b/libqblock/libqblock-types.h
index e69de29..4352bf2 100644
--- a/libqblock/libqblock-types.h
+++ b/libqblock/libqblock-types.h
@@ -0,0 +1,245 @@
+/*
+ * QEMU block layer library
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ 

[Qemu-devel] [PATCH V11 4/7] libqblock build system

2012-11-24 Thread Wenchao Xia
  Libqblock was placed in new directory ./libqblock, libtool will build
dynamic library there, source files of block layer remains in ./block.
So block related source code will generate 3 sets of binary, first is old
ones used in qemu, second and third are non PIC and PIC ones in ./libqblock.
  GCC compiler flag visibility=hidden was used with special macro, to export
only symbols that was marked as PUBLIC.
  For testing, make check-libqblock will build binaries and execute it, make
clean or make check-clean will delete generated binaries.
  By default this library will be built and tested if libtool present, out of
tree building is supported.

v10:
  Use $(SRC_PATH) in install rules.
  Call install libqblock from install target in root Makefile.
  Make libqblock and check-libqblock is conditional to a configure option and
libtool now, if libtool is not present it is forced to be disabled.
  Removed unnest-vars in libqblock Makfile for that it was done in 
Makefile.objs.
  Picked out only needed objects files for libqblock, added stub objects in
libqblock linking.
  Use libtool to link check-libqblock.
  Removed -fPIC cc flag replacement in tests/Makefile.
  Removed seperate directory for libqblock test case.
  Added target subdir-libqblock.
  Added targets to .phony.
  Generate files at root directory instead of ./libqblock.

v11:
  Set libqblock initial string to empty instead of “yes” in configure, by 
default
it will be set depending on libtool’s state, fail when user set it to yes but
libtool not present.
  Removed link flag in check-libqblock linkage, use libtool to search library.
  Added libqblock-aio.c, which contains code from main-loop.c, iohandler.c
compatfd.c, removed these three files from compile and link objects.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 .gitignore|2 +
 Makefile  |   25 -
 configure |   39 
 libqblock/Makefile|   74 +
 libqblock/libqblock-aio.c |   81 +
 libqblock/libqblock.c |6 +++
 libqblock/libqblock.h |1 +
 libqblock/libqblock.pc.in |   13 +++
 tests/Makefile|   29 ++-
 tests/check-libqblock-qcow2.c |6 +++
 10 files changed, 272 insertions(+), 4 deletions(-)
 create mode 100644 libqblock/Makefile
 create mode 100644 libqblock/libqblock-aio.c
 create mode 100644 libqblock/libqblock-error.c
 create mode 100644 libqblock/libqblock-error.h
 create mode 100644 libqblock/libqblock-types.h
 create mode 100644 libqblock/libqblock.c
 create mode 100644 libqblock/libqblock.h
 create mode 100644 libqblock/libqblock.pc.in
 create mode 100644 tests/check-libqblock-qcow2.c

diff --git a/.gitignore b/.gitignore
index bd6ba1c..77c1910 100644
--- a/.gitignore
+++ b/.gitignore
@@ -93,3 +93,5 @@ cscope.*
 tags
 TAGS
 *~
+tests/check-libqblock-qcow2
+tests/test_images
diff --git a/Makefile b/Makefile
index b04d862..dd01fe7 100644
--- a/Makefile
+++ b/Makefile
@@ -195,6 +195,27 @@ qemu-img$(EXESUF): qemu-img.o $(tools-obj-y) 
$(block-obj-y) libqemustub.a
 qemu-nbd$(EXESUF): qemu-nbd.o $(tools-obj-y) $(block-obj-y) libqemustub.a
 qemu-io$(EXESUF): qemu-io.o cmd.o $(tools-obj-y) $(block-obj-y) libqemustub.a
 
+##
+# Support building shared library libqblock
+.PHONY: install-libqblock subdir-libqblock
+
+ifeq ($(CONFIG_LIBQBLOCK), y)
+subdir-libqblock: $(GENERATED_HEADERS) $(GENERATED_SOURCES)
+   $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V=$(V) 
TARGET_DIR=$*/ all,)
+
+install-libqblock: subdir-libqblock
+   $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C libqblock V=$(V) 
TARGET_DIR=$*/ install-libqblock,)
+else
+LIBQBLOCK_WARN = Libqblock was not enabled, skip. Make sure libtool was 
installed and libqblock was enabled.
+subdir-libqblock: $(GENERATED_HEADERS) $(GENERATED_SOURCES)
+   @echo $(LIBQBLOCK_WARN)
+
+install-libqblock:
+   @echo $(LIBQBLOCK_WARN)
+endif
+
+###
+
 qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o
 
 vscclient$(EXESUF): $(libcacard-y) $(oslib-obj-y) $(trace-obj-y) 
libcacard/vscclient.o libqemustub.a
@@ -258,7 +279,7 @@ clean:
rm -rf qapi-generated
rm -rf qga/qapi-generated
$(MAKE) check-clean
-   for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard; do \
+   for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard libqblock; do \
if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
rm -f $$d/qemu-options.def; \
 done
@@ -331,7 +352,7 @@ install-confdir:
 install-sysconfig: install-datadir install-confdir
$(INSTALL_DATA) $(SRC_PATH)/sysconfigs/target/target-x86_64.conf 
$(DESTDIR)$(qemu_confdir)
 
-install: all $(if $(BUILD_DOCS),install-doc) install-sysconfig 

[Qemu-devel] [PATCH V11 2/7] Build system clean tests directory clearly

2012-11-24 Thread Wenchao Xia
  Currently root Makefile try clean tests/tcg, hard to extend.
This patch added command make check-clean, which clean all
generated files used in tests. With this command root Makefile
do not care tests clean method any more, it simply calls the
command to do it, so any more clean script could be added in
tests/Makefile, make it easier to extend.

v2:
  Discard env MAKEFILES, always include tests/Makefile.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 Makefile   |6 ++
 configure  |2 +-
 tests/Makefile |7 +++
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index 9ecbcbb..b04d862 100644
--- a/Makefile
+++ b/Makefile
@@ -211,9 +211,7 @@ qemu-ga$(EXESUF): QEMU_CFLAGS += -I qga/qapi-generated
 
 gen-out-type = $(subst .,-,$(suffix $@))
 
-ifneq ($(wildcard config-host.mak),)
-include $(SRC_PATH)/tests/Makefile
-endif
+include tests/Makefile
 
 qapi-py = $(SRC_PATH)/scripts/qapi.py $(SRC_PATH)/scripts/ordereddict.py
 
@@ -259,7 +257,7 @@ clean:
rm -f $(foreach f,$(GENERATED_SOURCES),$(f) $(f)-timestamp)
rm -rf qapi-generated
rm -rf qga/qapi-generated
-   $(MAKE) -C tests/tcg clean
+   $(MAKE) check-clean
for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard; do \
if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
rm -f $$d/qemu-options.def; \
diff --git a/configure b/configure
index 780b19a..801585c 100755
--- a/configure
+++ b/configure
@@ -4166,7 +4166,7 @@ DIRS=$DIRS pc-bios/optionrom pc-bios/spapr-rtas
 DIRS=$DIRS roms/seabios roms/vgabios
 DIRS=$DIRS qapi-generated
 DIRS=$DIRS libcacard libcacard/libcacard libcacard/trace
-FILES=Makefile tests/tcg/Makefile qdict-test-data.txt
+FILES=Makefile tests/Makefile tests/tcg/Makefile qdict-test-data.txt
 FILES=$FILES tests/tcg/cris/Makefile tests/tcg/cris/.gdbinit
 FILES=$FILES tests/tcg/lm32/Makefile libcacard/Makefile
 FILES=$FILES pc-bios/optionrom/Makefile pc-bios/keymaps
diff --git a/tests/Makefile b/tests/Makefile
index ca680e5..ef6c9f2 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -94,6 +94,7 @@ check-help:
@echo  make check-unit   Run qobject tests
@echo  make check-block  Run block tests
@echo  make check-report.htmlGenerates an HTML test report
+   @echo  make check-clean  Clean the tests
@echo
@echo Please note that HTML reports do not regenerate if the unit 
tests
@echo has not changed.
@@ -148,4 +149,10 @@ check-unit: $(patsubst %,check-%, $(check-unit-y))
 check-block: $(patsubst %,check-%, $(check-block-y))
 check: check-unit check-qtest
 
+check-clean:
+   $(MAKE) -C tests/tcg clean
+   rm -f $(check-unit-y)
+   rm -f $(check-qtest-i386-y) $(check-qtest-x86_64-y) 
$(check-qtest-sparc64-y) $(check-qtest-sparc-y)
+   rm -f tests/*.o
+
 -include $(wildcard tests/*.d)
-- 
1.7.1





[Qemu-devel] [PATCH V11 1/7] Build system fix distclean error for pixman

2012-11-24 Thread Wenchao Xia
  Currently Makefile test if pixman have configure log, but the script directly
return error if that file do not exist. This patch fix it.

v2: print out the command.
v3: resend as a stand alone fix patch, add reviewer.

  This patch have been sent as a stand alone fix for 1.3, if it is already
merged pls ignore it.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
---
 Makefile |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 3e8d441..9ecbcbb 100644
--- a/Makefile
+++ b/Makefile
@@ -286,7 +286,7 @@ distclean: clean
for d in $(TARGET_DIRS) $(QEMULIBS); do \
rm -rf $$d || exit 1 ; \
 done
-   test -f pixman/config.log  make -C pixman distclean
+   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 \
 ar  de en-us  fi  fr-be  hr it  lv  nl pl  ru th \
-- 
1.7.1





[Qemu-devel] [PATCH V11 7/7] libqblock test example

2012-11-24 Thread Wenchao Xia
  In this example, first it will create some qcow2 images, then try get
information including backing file relationship, then it will do sync IO on
the image.

v11:
  Use only gtester option -k, to avoid silent fail for segment fault.
  Little change according to API.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 tests/Makefile|5 +-
 tests/check-libqblock-qcow2.c |  390 -
 2 files changed, 392 insertions(+), 3 deletions(-)

diff --git a/tests/Makefile b/tests/Makefile
index bc1a94c..ed19b5d 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -144,9 +144,12 @@ check-report-unit.xml: $(check-unit-y)
 
 # gtester tests with libqblock
 
+# remove quite option to show error if program is terminated by seg fault, 
otherwise it fails silently.
+GTESTER_OPTIONS_LIBQBLOCK:= -k
+
 .PHONY: $(patsubst %, check-%, $(check-libqblock-y))
 $(patsubst %, check-%, $(check-libqblock-y)): check-%: %
-   $(call quiet-command, LIBQBLOCK_TEST_DIR=$(LIBQBLOCK_TEST_DIR) gtester 
$(GTESTER_OPTIONS) -m=$(SPEED) $*,GTESTER $*)
+   $(call quiet-command, LIBQBLOCK_TEST_DIR=$(LIBQBLOCK_TEST_DIR) gtester 
$(GTESTER_OPTIONS_LIBQBLOCK) -m=$(SPEED) $*,GTESTER $*)
 
 # Reports and overall runs
 
diff --git a/tests/check-libqblock-qcow2.c b/tests/check-libqblock-qcow2.c
index 50a4df3..1c33571 100644
--- a/tests/check-libqblock-qcow2.c
+++ b/tests/check-libqblock-qcow2.c
@@ -1,6 +1,392 @@
+/*
+ * QEMU block layer library test
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Wenchao Xia   xiaw...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ * Limitation:
+ *1 filename do not support relative path, to save trouble in creating
+ * backing files.
+ */
+
+#include glib.h
+#include stdarg.h
+#include stdio.h
+#include unistd.h
+#include inttypes.h
+#include string.h
+#include stdlib.h
+#include sys/stat.h
+#include sys/types.h
+
+
 #include libqblock.h
+#include libqtest.h
+
+#define LIBQB_TEST_ENV_DIR LIBQBLOCK_TEST_DIR
+#define LIBQB_TEST_DEFAULT_DIR /tmp
+#define LIBQB_TEST_DEFAULT_FILENAME libqblock_qcow2_test_img
+
+typedef struct LibqbTestSettings {
+const char *image_filename;
+uint64_t image_size;
+unsigned int num_backings;
+unsigned int io_buf_size;
+uint64_t io_offset;
+int print_flag;
+} LibqbTestSettings;
+
+LibqbTestSettings libqb_test_settings;
+
+static void print_loc(const QBlockLocationInfo *loc)
+{
+if (loc == NULL) {
+printf(loc is NULL.);
+return;
+}
+switch (loc-prot_type) {
+case QB_PROTO_NONE:
+printf(protocol type [none].);
+break;
+case QB_PROTO_FILE:
+printf(protocol type [file], filename [%s].,
+   loc-o_file.filename);
+break;
+default:
+printf(protocol type not supported.);
+break;
+}
+}
+
+static void print_info_image_static(QBlockStaticInfo *info)
+{
+const uint64_t *virt_size = qb_get_virt_size(info);
+const QBlockLocationInfo *backing_loc = qb_get_backing_loc(info);
+g_assert(virt_size != NULL);
+
+printf(===image location:\n);
+print_loc(info-loc);
+printf(\nvirtual_size % PRId64 , format type %d [%s],
+   *(virt_size),
+   info-fmt.fmt_type, qb_fmttype2str(info-fmt.fmt_type));
+printf(\nbacking image location:\n);
+print_loc(backing_loc);
+printf(\n);
+}
+
+static char *generate_backing_filename(const char *filename, int index)
+{
+char *backing_filename = NULL;
+
+backing_filename = g_strdup_printf(%s_backing_%d, filename, index);
+return backing_filename;
+}
+
+/* get filename in a full path */
+static const char *get_filename(const char *path)
+{
+const char *filename;
+filename = strrchr(path, '/');
+if (filename == NULL) {
+filename = path;
+} else {
+filename++;
+}
+return filename;
+}
+
+/* create a chain of files, num_backings must = 0. */
+static void files_create_qcow2(const char *filename,
+   int num_backings,
+   uint64_t virt_size)
+{
+QBlockContext *context = NULL;
+QBlockImage *qbi = NULL;
+QBlockLocationInfo *loc_info = NULL;
+QBlockFormatInfo *fmt_info = NULL;
+int ret;
+int index;
+int flag;
+char *backing_filename = NULL, *new_filename = NULL;
+const char *relative_filename = NULL;
+
+ret = qb_context_new(context);
+g_assert(ret == 0);
+
+ret = qb_image_new(context, qbi);
+g_assert(ret == 0);
+
+ret = qb_loc_info_new(context, loc_info);
+g_assert(ret == 0);
+
+ret = qb_fmt_info_new(context, fmt_info);
+g_assert(ret == 0);
+
+loc_info-prot_type = QB_PROTO_FILE;
+fmt_info-fmt_type = QB_FMT_QCOW2;
+fmt_info-virt_size = virt_size;
+flag = 0;
+
+index = 0;
+while (index  num_backings) {
+new_filename = 

[Qemu-devel] [PATCH V11 0/7] libqblock qemu block layer library

2012-11-24 Thread Wenchao Xia
  These patches introduce libqblock API, make subdir-libqblock and make
check-libqblock could build this library.
Functionalities:
 1 create a new image.
 2 sync access of an image.
 3 basic image information retrieving such as backing file.
 4 detect if a sector is allocated in an image.
Supported Formats:
 ALL using file protocols.

  Patch 1 to 3 is independent with libqblock, which fix small bug and improve
qemu, can be applied without libqblock. Patch 1 have been sent as a fix for
Qemu 1.3, Patch 3 have been sent by others, include them here just to make sure
it can work. If they are upstreamed pls ignore.

v2:
  Insert reserved bytes into union.
  Use uint64_t instead of size_t, offset.
  Use const char * in filename pointer.
  Initialization function removed and it was automatically executed when
library is loaded.
  Added compile flag visibility=hidden, to avoid name space pollution.
  Structure naming style changed.
  Using byte unit instead of sector for every API.
  Added a member in image static information structure, to report logical
sector size, which is always 512 now.
  Read and write API can take request not aligned to 512 now. It returns the
byte number that have succeed in operation, but now either negative value
or the number requested would be returned, because qemu block sync I/O API
would not return such number.
  Typo fix due to comments and improved documents.

v3:
  Removed the code about OOM error, introduced GError.
  Used a table to map from string to enum types about format.
  Use typedef for every structure.
  Improved the gcc compiler macro to warn if gcc was not used.
  Global variable name changed with prefix libqb_.
  The struct QBlockStaticInfo was changed to folder full format related
information inside, and a new member with pointers pointing to the mostly used
members, such as backing file, virt size, was added. This would allow the user
to get full information about how it is created in the future.
  Each patch in the serial can work with qemu now.
  Typo fixes.

v4:
  Renamed QBroker to QBlockContext.
  Removed tool objs out of libqblock.
  Added a check in initialization about structure size for ABI.
  Added a new helper API to duplicate protocol information, helps to open files
in a backing file chain.
  Check-libqblock will not rebuild libqblock every time now.
  Test case file renamed to libqblock-[FMT].c.
  Test use gtest framework now.
  Test do random creation of test file now, added check for information API in
it.
  Test do random sync io instead of fixed offset io now.
  Test accept one parameter about where to place the test image, now it is
./tests/libqblock/test_images.

v5:
  Makefile of libqblock was adjusted to be similar as libcacard, added spec
file and install section.
  Removed warning when GCC was not found.
  Structure names were changed to better ones.
  Removed the union typedef that contain reserved bytes to reduce the folder
depth.
  Some format related enum options was changed to better name.
  Added accessors about image static information, hide indirect accessing
member detail in the structure.
  Test Makefile do not create diretory now, test case create it themself.
  Test build system do not use libtool now, and removed qtest-obj-y in its
dependency, make check will automatically execute test anyway now.
  Removed ifeq ($(LIBTOOL),) in Makefile.

v6:
  Remove address pointer member in image static info structure.

v7:
  Support out of tree building.

v8:
  Fix a bug in out of tree building.

v9:
  Rebase and splitted out small fix patch for qemu.

v10:
  Rebased to upstream, adjusted libqblock build system according to Paolo's
comments.

v11:
  Adjusting code in patch 4 to 7, details are in the child patch's commit
message.

Wenchao Xia (7):
  Build system fix distclean error for pixman
  Build system clean tests directory clearly
  block export function path_has_protocol
  libqblock build system
  libqblock API design and type defines
  libqblock API implement
  libqblock test example

 .gitignore |2 +
 Makefile   |   33 +-
 block.c|2 +-
 block.h|2 +
 configure  |   41 ++-
 libqblock/Makefile |   74 +++
 libqblock/libqblock-aio.c  |  175 ++
 libqblock/libqblock-aio.h  |6 +
 libqblock/libqblock-error.c|   57 ++
 libqblock/libqblock-error.h|   49 ++
 libqblock/libqblock-internal.h |   68 +++
 libqblock/libqblock-types.h|  245 
 libqblock/libqblock.c  | 1195 
 libqblock/libqblock.h  |  344 
 libqblock/libqblock.pc.in  |   13 +
 tests/Makefile |   39 ++-
 tests/check-libqblock-qcow2.c  |  392 +
 17 files changed, 2726 insertions(+), 11 deletions(-)
 create mode 100644 libqblock/Makefile
 create mode 100644 libqblock/libqblock-aio.c
 create mode 100644 

[Qemu-devel] [PATCH] tcg: mark local temps as MEM in dead_temp()

2012-11-24 Thread Aurelien Jarno
In dead_temp, local temps should always be marked as back to memory,
even if they have not been allocated (i.e. they are discared before
cross a basic block).

It fixes the following assertion in target-xtensa:

qemu-system-xtensa: tcg/tcg.c:1665: temp_save: Assertion 
`s-temps[temp].val_type == 2 || s-temps[temp].fixed_reg' failed.
Aborted

Reported-by: Max Filippov jcmvb...@gmail.com
Signed-off-by: Aurelien Jarno aurel...@aurel32.net
---
 tcg/tcg.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tcg/tcg.c b/tcg/tcg.c
index 4f75696..cb193f2 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -1615,7 +1615,7 @@ static inline void temp_dead(TCGContext *s, int temp)
 if (ts-val_type == TEMP_VAL_REG) {
 s-reg_to_temp[ts-reg] = -1;
 }
-if (temp  s-nb_globals || (ts-temp_local  ts-mem_allocated)) {
+if (temp  s-nb_globals || ts-temp_local) {
 ts-val_type = TEMP_VAL_MEM;
 } else {
 ts-val_type = TEMP_VAL_DEAD;
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH] target-xtensa: make sar_m32 global instead of local temp

2012-11-24 Thread Aurelien Jarno
On Sat, Nov 24, 2012 at 04:51:36AM +0400, Max Filippov wrote:
 This fixes the following assertion caused by local temp reaching the end
 of TB in discarded state:
 
   qemu-system-xtensa: tcg/tcg.c:1665: temp_save: Assertion 
 `s-temps[temp].val_type == 2 || s-temps[temp].fixed_reg' failed.
   Aborted
 
 Signed-off-by: Max Filippov jcmvb...@gmail.com
 ---
  target-xtensa/cpu.h   |1 +
  target-xtensa/translate.c |   28 
  2 files changed, 9 insertions(+), 20 deletions(-)

I have just send a patch to fix the issue in the TCG code instead (sorry
for being so long, the last weeks have been quite busy). I think it is
better than fixing the issue in target-xtensa.

If it works for you, I'll commit it.

 diff --git a/target-xtensa/cpu.h b/target-xtensa/cpu.h
 index 74e9888..f021a9a 100644
 --- a/target-xtensa/cpu.h
 +++ b/target-xtensa/cpu.h
 @@ -323,6 +323,7 @@ typedef struct CPUXtensaState {
  const XtensaConfig *config;
  uint32_t regs[16];
  uint32_t pc;
 +uint32_t sar_m32;
  uint32_t sregs[256];
  uint32_t uregs[256];
  uint32_t phys_regs[MAX_NAREG];
 diff --git a/target-xtensa/translate.c b/target-xtensa/translate.c
 index e5a3f49..4f3cf32 100644
 --- a/target-xtensa/translate.c
 +++ b/target-xtensa/translate.c
 @@ -56,8 +56,6 @@ typedef struct DisasContext {
  
  bool sar_5bit;
  bool sar_m32_5bit;
 -bool sar_m32_allocated;
 -TCGv_i32 sar_m32;
  
  uint32_t ccount_delta;
  unsigned used_window;
 @@ -71,6 +69,7 @@ typedef struct DisasContext {
  
  static TCGv_ptr cpu_env;
  static TCGv_i32 cpu_pc;
 +static TCGv_i32 cpu_sar_m32;
  static TCGv_i32 cpu_R[16];
  static TCGv_i32 cpu_FR[16];
  static TCGv_i32 cpu_SR[256];
 @@ -169,6 +168,8 @@ void xtensa_translate_init(void)
  cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, env);
  cpu_pc = tcg_global_mem_new_i32(TCG_AREG0,
  offsetof(CPUXtensaState, pc), pc);
 +cpu_sar_m32 = tcg_global_mem_new_i32(TCG_AREG0,
 +offsetof(CPUXtensaState, sar_m32), sar_m32);
  
  for (i = 0; i  16; i++) {
  cpu_R[i] = tcg_global_mem_new_i32(TCG_AREG0,
 @@ -230,21 +231,13 @@ static void init_sar_tracker(DisasContext *dc)
  {
  dc-sar_5bit = false;
  dc-sar_m32_5bit = false;
 -dc-sar_m32_allocated = false;
 -}
 -
 -static void reset_sar_tracker(DisasContext *dc)
 -{
 -if (dc-sar_m32_allocated) {
 -tcg_temp_free(dc-sar_m32);
 -}
  }
  
  static void gen_right_shift_sar(DisasContext *dc, TCGv_i32 sa)
  {
  tcg_gen_andi_i32(cpu_SR[SAR], sa, 0x1f);
  if (dc-sar_m32_5bit) {
 -tcg_gen_discard_i32(dc-sar_m32);
 +tcg_gen_discard_i32(cpu_sar_m32);
  }
  dc-sar_5bit = true;
  dc-sar_m32_5bit = false;
 @@ -253,12 +246,8 @@ static void gen_right_shift_sar(DisasContext *dc, 
 TCGv_i32 sa)
  static void gen_left_shift_sar(DisasContext *dc, TCGv_i32 sa)
  {
  TCGv_i32 tmp = tcg_const_i32(32);
 -if (!dc-sar_m32_allocated) {
 -dc-sar_m32 = tcg_temp_local_new_i32();
 -dc-sar_m32_allocated = true;
 -}
 -tcg_gen_andi_i32(dc-sar_m32, sa, 0x1f);
 -tcg_gen_sub_i32(cpu_SR[SAR], tmp, dc-sar_m32);
 +tcg_gen_andi_i32(cpu_sar_m32, sa, 0x1f);
 +tcg_gen_sub_i32(cpu_SR[SAR], tmp, cpu_sar_m32);
  dc-sar_5bit = false;
  dc-sar_m32_5bit = true;
  tcg_temp_free(tmp);
 @@ -498,7 +487,7 @@ static void gen_wsr_sar(DisasContext *dc, uint32_t sr, 
 TCGv_i32 s)
  {
  tcg_gen_andi_i32(cpu_SR[sr], s, 0x3f);
  if (dc-sar_m32_5bit) {
 -tcg_gen_discard_i32(dc-sar_m32);
 +tcg_gen_discard_i32(cpu_sar_m32);
  }
  dc-sar_5bit = false;
  dc-sar_m32_5bit = false;
 @@ -1483,7 +1472,7 @@ static void disas_xtensa_insn(CPUXtensaState *env, 
 DisasContext *dc)
  case 10: /*SLL*/
  gen_window_check2(dc, RRR_R, RRR_S);
  if (dc-sar_m32_5bit) {
 -tcg_gen_shl_i32(cpu_R[RRR_R], cpu_R[RRR_S], dc-sar_m32);
 +tcg_gen_shl_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_sar_m32);
  } else {
  TCGv_i64 v = tcg_temp_new_i64();
  TCGv_i32 s = tcg_const_i32(32);
 @@ -2947,7 +2936,6 @@ static void gen_intermediate_code_internal(
  tcg_ctx.gen_opc_ptr  gen_opc_end);
  
  reset_litbase(dc);
 -reset_sar_tracker(dc);
  if (dc.icount) {
  tcg_temp_free(dc.next_icount);
  }
 -- 
 1.7.7.6
 
 

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



Re: [Qemu-devel] [PATCH] target-xtensa: make sar_m32 global instead of local temp

2012-11-24 Thread Max Filippov
On Sat, Nov 24, 2012 at 2:59 PM, Aurelien Jarno aurel...@aurel32.net wrote:
 On Sat, Nov 24, 2012 at 04:51:36AM +0400, Max Filippov wrote:
 This fixes the following assertion caused by local temp reaching the end
 of TB in discarded state:

   qemu-system-xtensa: tcg/tcg.c:1665: temp_save: Assertion 
 `s-temps[temp].val_type == 2 || s-temps[temp].fixed_reg' failed.
   Aborted

 Signed-off-by: Max Filippov jcmvb...@gmail.com
 ---
  target-xtensa/cpu.h   |1 +
  target-xtensa/translate.c |   28 
  2 files changed, 9 insertions(+), 20 deletions(-)

 I have just send a patch to fix the issue in the TCG code instead (sorry
 for being so long, the last weeks have been quite busy). I think it is
 better than fixing the issue in target-xtensa.

 If it works for you, I'll commit it.

Works perfectly, thanks. (nothing to be sorry for, BTW).

And it seems to me that switch from local temp to global makes code a bit
cleaner. However, since it's no longer a fix I will hold it until 1.3 is out.

-- 
Thanks.
-- Max



Re: [Qemu-devel] [PATCH] tcg: mark local temps as MEM in dead_temp()

2012-11-24 Thread Max Filippov
On Sat, Nov 24, 2012 at 2:58 PM, Aurelien Jarno aurel...@aurel32.net wrote:
 In dead_temp, local temps should always be marked as back to memory,
 even if they have not been allocated (i.e. they are discared before
 cross a basic block).

 It fixes the following assertion in target-xtensa:

 qemu-system-xtensa: tcg/tcg.c:1665: temp_save: Assertion 
 `s-temps[temp].val_type == 2 || s-temps[temp].fixed_reg' failed.
 Aborted

 Reported-by: Max Filippov jcmvb...@gmail.com
 Signed-off-by: Aurelien Jarno aurel...@aurel32.net

Tested-by: Max Filippov jcmvb...@gmail.com

-- 
Thanks.
-- Max



Re: [Qemu-devel] [PATCH] tcg: mark local temps as MEM in dead_temp()

2012-11-24 Thread Aurelien Jarno
On Sat, Nov 24, 2012 at 02:28:15PM +0300, Max Filippov wrote:
 On Sat, Nov 24, 2012 at 2:58 PM, Aurelien Jarno aurel...@aurel32.net wrote:
  In dead_temp, local temps should always be marked as back to memory,
  even if they have not been allocated (i.e. they are discared before
  cross a basic block).
 
  It fixes the following assertion in target-xtensa:
 
  qemu-system-xtensa: tcg/tcg.c:1665: temp_save: Assertion 
  `s-temps[temp].val_type == 2 || s-temps[temp].fixed_reg' failed.
  Aborted
 
  Reported-by: Max Filippov jcmvb...@gmail.com
  Signed-off-by: Aurelien Jarno aurel...@aurel32.net
 
 Tested-by: Max Filippov jcmvb...@gmail.com
 

Thanks for the test, I have applied the patch.


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



Re: [Qemu-devel] [PATCH v2] target-mips: Add comments on POOL32Axf encoding

2012-11-24 Thread Aurelien Jarno
On Wed, Nov 21, 2012 at 01:50:45PM +0800, 陳韋任 (Wei-Ren Chen) wrote:
   Current QEMU MIPS POOL32AXF encoding comes from microMIPS32
 and microMIPS32 DSP. Add comment here to help reading.
 
 Signed-off-by: Chen Wei-Ren che...@iis.sinica.edu.tw
 ---
 
 v2: Correct commit message formatting
 
  target-mips/translate.c | 17 +
  1 file changed, 17 insertions(+)

Thanks, applied.

 diff --git a/target-mips/translate.c b/target-mips/translate.c
 index 8b438f8..e453d9e 100644
 --- a/target-mips/translate.c
 +++ b/target-mips/translate.c
 @@ -10359,6 +10359,19 @@ enum {
  
  /* POOL32AXF encoding of minor opcode field extension */
  
 +/*
 + * 1. MIPS Architecture for Programmers Volume II-B:
 + *  The microMIPS32 Instruction Set (Revision 3.05)
 + *
 + *Table 6.5 POOL32Axf Encoding of Minor Opcode Extension Field
 + *
 + * 2. MIPS Architecture for Programmers VolumeIV-e:
 + *  The MIPS DSP Application-Specific Extension
 + *to the microMIPS32 Architecture (Revision 2.34)
 + *
 + *Table 5.5 POOL32Axf Encoding of Minor Opcode Extension Field
 + */ 
 +
  enum {
  /* bits 11..6 */
  TEQ = 0x00,
 @@ -10371,6 +10384,8 @@ enum {
  MFC0 = 0x03,
  MTC0 = 0x0b,
  
 +/* begin of microMIPS32 DSP */
 +
  /* bits 13..12 for 0x01 */
  MFHI_ACC = 0x0,
  MFLO_ACC = 0x1,
 @@ -10387,6 +10402,8 @@ enum {
  MULT_ACC = 0x0,
  MULTU_ACC = 0x1,
  
 +/* end of microMIPS32 DSP */
 +
  /* bits 15..12 for 0x2c */
  SEB = 0x2,
  SEH = 0x3,
 -- 
 1.7.12.3
 

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



Re: [Qemu-devel] [PATCH v3] target-mips: Clean up microMIPS32 major opcode

2012-11-24 Thread Aurelien Jarno
On Wed, Nov 21, 2012 at 02:04:41PM +0800, 陳韋任 (Wei-Ren Chen) wrote:
   I check MIPS microMIPS manual [1], and found the major opcode might
 be wrong. I add a comment to explicitly indicate what manual I am refering
 to, and according that manual I remove microMIPS32 major opcodes 0x1f.
 As for others, like 0x16, 0x17, 0x36 and 0x37, they are for higher-order
 MIPS ISA level or new revision of this microMIPS architecture. Quote
 from Johnson, they are belong MIPS64 [2].
 
 [1] http://www.mips.com/products/architectures/micromips/#specifications
 
 MIPS Architecture for Programmers Volume II-B:
   The microMIPS32 Instruction Set (Revision 3.05)
 
 MD00582-2B-microMIPS-AFP-03.05.pdf
 
 [2] http://www.mips.com/products/architectures/mips64/
 
 MIPS Architecture For Programmers
   Volume II-A: The MIPS64 Instruction Set
 
 MD00087-2B-MIPS64BIS-AFP-03.51.pdf
 
 Signed-off-by: Chen Wei-Ren che...@iis.sinica.edu.tw
 ---
 
 v3: Correct commit message formatting.
 
 v2: Remove POOL48A only. The other three opcode are belong MIPS64.
 
  target-mips/translate.c | 24 +---
  1 file changed, 17 insertions(+), 7 deletions(-)

Thanks, applied.

 diff --git a/target-mips/translate.c b/target-mips/translate.c
 index 8b438f8..7fe8d83 100644
 --- a/target-mips/translate.c
 +++ b/target-mips/translate.c
 @@ -10239,9 +10239,19 @@ static int decode_mips16_opc (CPUMIPSState *env, 
 DisasContext *ctx,
  return n_bytes;
  }
  
 -/* microMIPS extension to MIPS32 */
 +/* microMIPS extension to MIPS32/MIPS64 */
  
 -/* microMIPS32 major opcodes */
 +/*
 + * microMIPS32/microMIPS64 major opcodes
 + *
 + * 1. MIPS Architecture for Programmers Volume II-B:
 + *  The microMIPS32 Instruction Set (Revision 3.05)
 + *
 + *Table 6.2 microMIPS32 Encoding of Major Opcode Field
 + *
 + * 2. MIPS Architecture For Programmers Volume II-A:
 + *  The MIPS64 Instruction Set (Revision 3.51)
 + */
  
  enum {
  POOL32A = 0x00,
 @@ -10268,9 +10278,10 @@ enum {
  POOL16D = 0x13,
  ORI32 = 0x14,
  POOL32F = 0x15,
 -POOL32S = 0x16,
 -DADDIU32 = 0x17,
 +POOL32S = 0x16,  /* MIPS64 */
 +DADDIU32 = 0x17, /* MIPS64 */
  
 +/* 0x1f is reserved */
  POOL32C = 0x18,
  LWGP16 = 0x19,
  LW16 = 0x1a,
 @@ -10278,7 +10289,6 @@ enum {
  XORI32 = 0x1c,
  JALS32 = 0x1d,
  ADDIUPC = 0x1e,
 -POOL48A = 0x1f,
  
  /* 0x20 is reserved */
  RES_20 = 0x20,
 @@ -10307,8 +10317,8 @@ enum {
  B16 = 0x33,
  ANDI32 = 0x34,
  J32 = 0x35,
 -SD32 = 0x36,
 -LD32 = 0x37,
 +SD32 = 0x36, /* MIPS64 */
 +LD32 = 0x37, /* MIPS64 */
  
  /* 0x38 and 0x39 are reserved */
  RES_38 = 0x38,
 -- 
 1.7.12.3
 
 
 -- 
 Wei-Ren Chen (陳韋任)
 Computer Systems Lab, Institute of Information Science,
 Academia Sinica, Taiwan (R.O.C.)
 Tel:886-2-2788-3799 #1667
 Homepage: http://people.cs.nctu.edu.tw/~chenwj
 

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



[Qemu-devel] [PATCH for 1.3] target-i386: enable SSSE3 TCG support

2012-11-24 Thread Aurelien Jarno
SSSE3 support has been added to TCG more than 4 years ago in commit
4242b1bd8acc19cffdaad4ac23213d72a72b. It has been disabled by
mistake in commit 551a2dec8fa55006a68393b9d6fb63577d2b3f1c.

Signed-off-by: Aurelien Jarno aurel...@aurel32.net
---
 target-i386/cpu.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

SSE4.1 and SSE4.2 are wrongly disabled too, but some instructions from
SSE4.2 (I haven't investigated more yet) are wrongly emulated, which
causes some crashes now that GLIBC is using them through gnu indirect
functions.

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 64c3491..68f6f5d 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -315,7 +315,7 @@ typedef struct x86_def_t {
   /* missing:
   CPUID_VME, CPUID_DTS, CPUID_SS, CPUID_HT, CPUID_TM, CPUID_PBE */
 #define TCG_EXT_FEATURES (CPUID_EXT_SSE3 | CPUID_EXT_MONITOR | \
-  CPUID_EXT_CX16 | CPUID_EXT_POPCNT | \
+  CPUID_EXT_SSSE3 | CPUID_EXT_CX16 | CPUID_EXT_POPCNT | \
   CPUID_EXT_HYPERVISOR)
   /* missing:
   CPUID_EXT_DTES64, CPUID_EXT_DSCPL, CPUID_EXT_VMX, CPUID_EXT_EST,
-- 
1.7.10.4




Re: [Qemu-devel] net: RFC New Socket-Based, Switched Network Backend (QDES)

2012-11-24 Thread Stefan Hajnoczi
On Mon, Jun 25, 2012 at 7:42 AM, Mike Lovell m...@dev-zero.net wrote:
 This is what I've been calling QDES or QEMU Distributed Ethernet Switch. I
 first had the idea when I was playing with the udp and mcast socket network
 backends while exploring how to build a VM infrastructure. I liked the idea of
 using the sockets backends cause it doesn't require escalated permissions to
 configure and run as well as the ability to talk over IP networks.

Hi Mike,
I was just reading the VXLAN spec and Linux code when I realized this
is similar to your QDES approach:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=d342894c5d2f8c7df194c793ec4059656e09ca31
http://tools.ietf.org/html/draft-mahalingam-dutt-dcops-vxlan-02

If you're still hacking on QDES you may be interested.

VXLAN is a VLAN mechanism that gets around the 12-bit 802.1Q tag size.
 In large deployments it may be necessary to have more than 4096
VLANs, this is where VXLAN comes in.

It's a tiny header with VXLAN Network ID that encapsulates Ethernet inside UDP:

[Outer Ethernet][IP][UDP] [VXLAN] [Inner Ethernet][...]

UDP is used as follows:
1. If the host has already learnt an Inner MAC - Outer IP mapping,
then it transmits a unicast UDP packet.
2. Otherwise it transmits a multicast UDP packet.

That means all hosts join a multicast group - this enables broadcast
similar to what you've done in your patches.

Typically traffic from a VM on Host A to another VM on Host B will use
unicast UDP because the Inner MAC - Outer IP mapping has been learnt.

I'm not sure if it makes sense to implement VXLAN in QEMU because the
multicast UDP socket uses a well-known port.  I guess that means
multiple QEMUs running on the same host cannot use VXLAN unless they
bind to unique IP addresses.  At that point we lose the advantage of a
pure userspace implementation and might as well use the kernel
implementation (or OpenVSwitch) with tap devices.

Anyway, it's still interesting and maybe there's a way to solve this.

Stefan



[Qemu-devel] [PATCH] tcg-i386: Improve cmov detection

2012-11-24 Thread Richard Henderson
In addition to better compile-time detection, perform runtime detection.

Signed-off-by: Richard Henderson r...@twiddle.net
---
 tcg/i386/tcg-target.c | 34 +-
 tcg/i386/tcg-target.h |  5 -
 2 files changed, 33 insertions(+), 6 deletions(-)

Yall are right that there's no particularly good method with which
to detect i686 *or later*, and thus cmov support, in gcc.  If one
uses -march=native with any processor made in the last 5 years,
one will have at least SSE1 support.  So we can reasonably use that
as a clue.

To fill in the holes, we can do the check at runtime.  That does
involve a tiny amount of runtime overhead, testing a global variable.
I suspect that this is overhead is unmeasurable.


r~


diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c
index 6f3ad3c..b333b46 100644
--- a/tcg/i386/tcg-target.c
+++ b/tcg/i386/tcg-target.c
@@ -97,6 +97,20 @@ static const int tcg_target_call_oarg_regs[] = {
 # define TCG_REG_L1 TCG_REG_EDX
 #endif
 
+/* Attempt to determine at compile-time whether the compiler assumes that
+   cmov is available.  We get 64-bit for free.  P6 (i686) and later include
+   support for cmov, but there is no one preprocessor define that determines
+   this.  Assume that all processors that include sse also support cmov, so
+   that we sorta future-proof this test against new preprocessor defines.  */
+#include cpuid.h
+#if (TCG_TARGET_REG_BITS == 64 \
+ || defined(__i686__) || defined(__pentium4__) \
+ || defined(__athlon__) || defined(__SSE__))
+# define have_cmov 1
+#else
+static bool have_cmov;
+#endif
+
 static uint8_t *tb_ret_addr;
 
 static void patch_reloc(uint8_t *code_ptr, int type,
@@ -943,7 +957,14 @@ static void tcg_out_movcond32(TCGContext *s, TCGCond cond, 
TCGArg dest,
   TCGArg v1)
 {
 tcg_out_cmp(s, c1, c2, const_c2, 0);
-tcg_out_modrm(s, OPC_CMOVCC | tcg_cond_to_jcc[cond], dest, v1);
+if (have_cmov) {
+tcg_out_modrm(s, OPC_CMOVCC | tcg_cond_to_jcc[cond], dest, v1);
+} else {
+int over = gen_new_label();
+tcg_out_jxx(s, tcg_cond_to_jcc[tcg_invert_cond(cond)], over, 1);
+tcg_out_mov(s, TCG_TYPE_I32, dest, v1);
+tcg_out_label(s, over, s-code_ptr);
+}
 }
 
 #if TCG_TARGET_REG_BITS == 64
@@ -2243,6 +2264,17 @@ static void tcg_target_qemu_prologue(TCGContext *s)
 
 static void tcg_target_init(TCGContext *s)
 {
+/* If we could not determine cmov availablity at compile time, perform
+   the check at runtime.  99% certainty that we're running on hardware
+   that supports cmov, but we still need to check.  In case cmov is not
+   available, we'll use a small forward branch.  */
+#ifndef have_cmov
+{
+unsigned a, b, c, d;
+have_cmov = (__get_cpuid(1, a, b, c, d)  (d  bit_CMOV));
+}
+#endif
+
 #if !defined(CONFIG_USER_ONLY)
 /* fail safe */
 if ((1  CPU_TLB_ENTRY_BITS) != sizeof(CPUTLBEntry))
diff --git a/tcg/i386/tcg-target.h b/tcg/i386/tcg-target.h
index dbc6756..450078b 100644
--- a/tcg/i386/tcg-target.h
+++ b/tcg/i386/tcg-target.h
@@ -90,12 +90,7 @@ typedef enum {
 #define TCG_TARGET_HAS_nand_i32 0
 #define TCG_TARGET_HAS_nor_i32  0
 #define TCG_TARGET_HAS_deposit_i32  1
-#if defined(__x86_64__) || defined(__i686__)
-/* Use cmov only if the compiler is already doing so.  */
 #define TCG_TARGET_HAS_movcond_i32  1
-#else
-#define TCG_TARGET_HAS_movcond_i32  0
-#endif
 
 #if TCG_TARGET_REG_BITS == 64
 #define TCG_TARGET_HAS_div2_i64 1
-- 
1.7.11.7




Re: [Qemu-devel] [PATCH] tcg-i386: Improve cmov detection

2012-11-24 Thread Peter Maydell
On 24 November 2012 17:39, Richard Henderson r...@twiddle.net wrote:
 --- a/tcg/i386/tcg-target.c
 +++ b/tcg/i386/tcg-target.c
 @@ -97,6 +97,20 @@ static const int tcg_target_call_oarg_regs[] = {
  # define TCG_REG_L1 TCG_REG_EDX
  #endif

 +/* Attempt to determine at compile-time whether the compiler assumes that
 +   cmov is available.  We get 64-bit for free.  P6 (i686) and later include
 +   support for cmov, but there is no one preprocessor define that determines
 +   this.  Assume that all processors that include sse also support cmov, so
 +   that we sorta future-proof this test against new preprocessor defines.  */
 +#include cpuid.h

MacOS gcc objects to this:
In file included from /Users/pm215/src/qemu/tcg/tcg.c:174:
/Users/pm215/src/qemu/tcg/i386/tcg-target.c:105:19: warning: cpuid.h:
No such file or directory

(though for some reason not as a fatal error).

-- PMM



[Qemu-devel] [Bug 1082292] Re: [ARM] pflash_write: Unimplemented flash cmd sequence

2012-11-24 Thread Stefan Weil
The message from pflash_write is a warning which only says that the Intel flash 
emulation
got a command sequence which is only supported by the AMD flash emulation.

This warning is currently normal when Linux kernels try to determine the flash 
type.
Linux tries AMD before Intel.

So if there is any problem, it is not related to the flash emulation.

The test scenario works without any problem on a Debian Linux host
(tested up to the boot prompt).

Note that there are three location where you get output:
* stdout / stderr on the console
* serial output from the emulation (Alt-Ctrl-3 in QEMU SDL window)
* framebuffer output from the emulation (Alt-Ctrl-1 in QEMU SDL window)

It takes some time until the kernel sends output to the framebuffer (therefore 
50 % cpu load),
but it works.

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

Title:
  [ARM] pflash_write: Unimplemented flash cmd sequence

Status in QEMU:
  New
Status in Linaro QEMU:
  New

Bug description:
  I find the bug already reported on qemu-devel mailing-list [1] w/o
  replies also on other sources.

  Tested on Darwin (Mac OS X 10.7.5) and Scientific Linux 6.3 hosts.
  Also using the latest 1.2.X and 1.3.0-rc0 and qemu-linaro. On all host
  operating systems and with different versions on qemu results are the
  same.

  I was following the official Ubuntu ARM instructions [2] how to test
  OS on ARM emulator.

  oss: Could not initialize DAC
  oss: Failed to open `/dev/dsp'
  oss: Reason: No such file or directory
  oss: Could not initialize DAC
  oss: Failed to open `/dev/dsp'
  oss: Reason: No such file or directory
  audio: Failed to create voice `lm4549.out'
  Uncompressing 
Linux.
 done, booting the kernel.
  pflash_write: Unimplemented flash cmd sequence (offset , 
wcycle 0x0 cmd 0x0 value 0xf000f0)
  pflash_write: Unimplemented flash cmd sequence (offset , 
wcycle 0x0 cmd 0x0 value 0xf0)

  And it freezes, but still eats 40-50% of CPU core.

  ## Instructions ##

  wget -c http://w3.impa.br/~gabrield/data/ubuntu-arm-development-rootfs.tar.bz2
  tar jxfv ubuntu-arm-development-rootfs.tar.bz2
  chmod +x run.sh
  ./run.sh

  The user to login is ubuntu and password temppwd.

  More details on [2].

  - - -
  [1] http://lists.gnu.org/archive/html/qemu-devel/2012-11/msg00863.html
  [2] https://wiki.ubuntu.com/ARM/RootfsFromScratch

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



[Qemu-devel] [Bug 1082292] Re: [ARM] pflash_write: Unimplemented flash cmd sequence

2012-11-24 Thread Peter Maydell
We could drop it to a LOG_UNIMP/LOG_GUEST_ERROR qemu_log warning instead
of a plain printf, I guess.

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

Title:
  [ARM] pflash_write: Unimplemented flash cmd sequence

Status in QEMU:
  New
Status in Linaro QEMU:
  New

Bug description:
  I find the bug already reported on qemu-devel mailing-list [1] w/o
  replies also on other sources.

  Tested on Darwin (Mac OS X 10.7.5) and Scientific Linux 6.3 hosts.
  Also using the latest 1.2.X and 1.3.0-rc0 and qemu-linaro. On all host
  operating systems and with different versions on qemu results are the
  same.

  I was following the official Ubuntu ARM instructions [2] how to test
  OS on ARM emulator.

  oss: Could not initialize DAC
  oss: Failed to open `/dev/dsp'
  oss: Reason: No such file or directory
  oss: Could not initialize DAC
  oss: Failed to open `/dev/dsp'
  oss: Reason: No such file or directory
  audio: Failed to create voice `lm4549.out'
  Uncompressing 
Linux.
 done, booting the kernel.
  pflash_write: Unimplemented flash cmd sequence (offset , 
wcycle 0x0 cmd 0x0 value 0xf000f0)
  pflash_write: Unimplemented flash cmd sequence (offset , 
wcycle 0x0 cmd 0x0 value 0xf0)

  And it freezes, but still eats 40-50% of CPU core.

  ## Instructions ##

  wget -c http://w3.impa.br/~gabrield/data/ubuntu-arm-development-rootfs.tar.bz2
  tar jxfv ubuntu-arm-development-rootfs.tar.bz2
  chmod +x run.sh
  ./run.sh

  The user to login is ubuntu and password temppwd.

  More details on [2].

  - - -
  [1] http://lists.gnu.org/archive/html/qemu-devel/2012-11/msg00863.html
  [2] https://wiki.ubuntu.com/ARM/RootfsFromScratch

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



Re: [Qemu-devel] [PATCH v2 3/4] buffered_file: rate-limit producers based on buffer size

2012-11-24 Thread Blue Swirl
On Tue, Nov 20, 2012 at 4:45 PM, Paolo Bonzini pbonz...@redhat.com wrote:
 buffered_rate_limit is called to prevent the RAM migration callback
 from putting too much data in the buffer.  So it has to check against
 the amount of data currently in the buffer, not against the amount
 of data that has been transferred so far.

 s-bytes_xfer is used to communicate between successive calls of
 buffered_put_buffer.  Buffered_rate_tick resets it every now and
 then to prevent moving too much buffered data to the socket at
 once.  However, its value does not matter for the producer of the
 data.

 Here is the result for migrating an idle guest with 3GB of memory
 and ~360MB of non-zero memory:

   migrate_set_speed   BeforeAfter
   
   default (32MB/sec)  ~3 sec~13 sec
   infinite (10GB/sec) ~3 sec~3 sec

 Note that before this patch, QEMU is transferring of 100 MB/sec
 despite the rate limiting.

 Also fix an off-by-one error, where  was used instead of =.  With this
 fix, the condition in buffered_put_buffer is really the opposite of
 rate limit reached, so write it explicitly like that.

 Signed-off-by: Paolo Bonzini pbonz...@redhat.com
 ---
  buffered_file.c |7 ++-
  1 files changed, 2 insertions(+), 5 deletions(-)

 diff --git a/buffered_file.c b/buffered_file.c
 index edead5c..2dac99a 100644
 --- a/buffered_file.c
 +++ b/buffered_file.c
 @@ -125,7 +125,7 @@ static int buffered_put_buffer(void *opaque, const 
 uint8_t *buf, int64_t pos, in

  if (pos == 0  size == 0) {
  DPRINTF(file is ready\n);
 -if (!s-freeze_output  s-bytes_xfer  s-xfer_limit) {
 +if (!qemu_file_rate_limit(s-file)) {
  DPRINTF(notifying client\n);
  migrate_fd_put_ready(s-migration_state);
  }
 @@ -190,10 +190,7 @@ static int buffered_rate_limit(void *opaque)
  if (ret) {
  return ret;
  }
 -if (s-freeze_output)
 -return 1;
 -
 -if (s-bytes_xfer  s-xfer_limit)
 +if (s-buffer_size = s-xfer_limit)

Please add braces.

  return 1;

  return 0;
 --
 1.7.1






Re: [Qemu-devel] [PATCH] rbd block driver fix race between aio completition and aio cancel

2012-11-24 Thread Blue Swirl
On Thu, Nov 22, 2012 at 10:00 AM, Stefan Priebe s.pri...@profihost.ag wrote:
 This one fixes a race which qemu had also in iscsi block driver
 between cancellation and io completition.

 qemu_rbd_aio_cancel was not synchronously waiting for the end of
 the command.

 To archieve this it introduces a new status flag which uses
 -EINPROGRESS.

 Signed-off-by: Stefan Priebe s.pri...@profihost.ag
 ---
  block/rbd.c |   23 ++-
  1 file changed, 14 insertions(+), 9 deletions(-)

 diff --git a/block/rbd.c b/block/rbd.c
 index 0384c6c..783c3d7 100644
 --- a/block/rbd.c
 +++ b/block/rbd.c
 @@ -77,6 +77,7 @@ typedef struct RBDAIOCB {
  int error;
  struct BDRVRBDState *s;
  int cancelled;
 +int status;
  } RBDAIOCB;

  typedef struct RADOSCB {
 @@ -376,12 +377,6 @@ static void qemu_rbd_complete_aio(RADOSCB *rcb)
  RBDAIOCB *acb = rcb-acb;
  int64_t r;

 -if (acb-cancelled) {
 -qemu_vfree(acb-bounce);
 -qemu_aio_release(acb);
 -goto done;
 -}
 -
  r = rcb-ret;

  if (acb-cmd == RBD_AIO_WRITE ||
 @@ -406,10 +401,11 @@ static void qemu_rbd_complete_aio(RADOSCB *rcb)
  acb-ret = r;
  }
  }
 +acb-status = 0;
 +
  /* Note that acb-bh can be NULL in case where the aio was cancelled */
  acb-bh = qemu_bh_new(rbd_aio_bh_cb, acb);
  qemu_bh_schedule(acb-bh);
 -done:
  g_free(rcb);
  }

 @@ -574,6 +570,12 @@ static void qemu_rbd_aio_cancel(BlockDriverAIOCB 
 *blockacb)
  {
  RBDAIOCB *acb = (RBDAIOCB *) blockacb;
  acb-cancelled = 1;
 +
 +while (acb-status == -EINPROGRESS) {
 +qemu_aio_wait();
 +}
 +
 +qemu_aio_release(acb);
  }

  static AIOPool rbd_aio_pool = {
 @@ -646,7 +648,8 @@ static void rbd_aio_bh_cb(void *opaque)
  qemu_bh_delete(acb-bh);
  acb-bh = NULL;

 -qemu_aio_release(acb);
 +if (!acb-cancelled)

Missing braces, please read CODING_STYLE.

 +qemu_aio_release(acb);
  }

  static int rbd_aio_discard_wrapper(rbd_image_t image,
 @@ -691,6 +694,7 @@ static BlockDriverAIOCB *rbd_start_aio(BlockDriverState 
 *bs,
  acb-s = s;
  acb-cancelled = 0;
  acb-bh = NULL;
 +acb-status = -EINPROGRESS;

  if (cmd == RBD_AIO_WRITE) {
  qemu_iovec_to_buf(acb-qiov, 0, acb-bounce, qiov-size);
 @@ -737,7 +741,8 @@ static BlockDriverAIOCB *rbd_start_aio(BlockDriverState 
 *bs,
  failed:
  g_free(rcb);
  s-qemu_aio_count--;
 -qemu_aio_release(acb);
 +if (!acb-cancelled)
 +qemu_aio_release(acb);

Also here.

  return NULL;
  }

 --
 1.7.10.4





Re: [Qemu-devel] [PATCH] rbd block driver fix race between aio completition and aio cancel

2012-11-24 Thread Stefan Priebe

Am 24.11.2012 20:54, schrieb Blue Swirl:

On Thu, Nov 22, 2012 at 10:00 AM, Stefan Priebe s.pri...@profihost.ag wrote:

This one fixes a race which qemu had also in iscsi block driver
between cancellation and io completition.

qemu_rbd_aio_cancel was not synchronously waiting for the end of
the command.

To archieve this it introduces a new status flag which uses
-EINPROGRESS.

Signed-off-by: Stefan Priebe s.pri...@profihost.ag

...


-qemu_aio_release(acb);
+if (!acb-cancelled)


Missing braces, please read CODING_STYLE.


Will fix this if the rest is OK. Waiting for Stefan and Paolo.

Stefan



Re: [Qemu-devel] [PATCH] tci: Fix type of tci_read_label

2012-11-24 Thread Blue Swirl
Thanks, applied.

On Mon, Nov 19, 2012 at 8:43 PM, Richard Henderson r...@twiddle.net wrote:
 Fixes the pointer truncation that was occurring for branches.

 Cc: Stefan Weil s...@weilnetz.de
 Cc: Blue Swirl blauwir...@gmail.com
 Signed-off-by: Richard Henderson r...@twiddle.net
 ---
  tci.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

 diff --git a/tci.c b/tci.c
 index 9c87c8e..54cf1d9 100644
 --- a/tci.c
 +++ b/tci.c
 @@ -338,9 +338,9 @@ static uint64_t tci_read_ri64(uint8_t **tb_ptr)
  }
  #endif

 -static target_ulong tci_read_label(uint8_t **tb_ptr)
 +static tcg_target_ulong tci_read_label(uint8_t **tb_ptr)
  {
 -target_ulong label = tci_read_i(tb_ptr);
 +tcg_target_ulong label = tci_read_i(tb_ptr);
  assert(label != 0);
  return label;
  }
 --
 1.7.11.7




Re: [Qemu-devel] [PATCH for 1.3 v2] block: Fix regression for MinGW (assertion caused by short string)

2012-11-24 Thread Blue Swirl
Thanks, applied.

On Thu, Nov 22, 2012 at 6:25 AM, Stefan Weil s...@weilnetz.de wrote:
 The local string tmp_filename is passed to function get_tmp_filename
 which expects a string with minimum size MAX_PATH for w32 hosts.

 MAX_PATH is 260 and PATH_MAX is 259, so tmp_filename was too short.

 Commit eba25057b9a5e19d10ace2bc7716667a31297169 introduced this
 regression.

 Signed-off-by: Stefan Weil s...@weilnetz.de
 ---

 v2: Added TODO comment as suggested by Stefan Hajnoczi.

 Hi Anthony, hi Blue,

 this fix is needed for 1.3 to avoid a fatal assertion on Windows.
 As discussed on qemu-devel, it is a minimal solution and can be
 replaced by a better one after 1.3.

 Please commit it to git master.

 Regards
 Stefan


  block.c |3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

 diff --git a/block.c b/block.c
 index 854ebd6..c05875f 100644
 --- a/block.c
 +++ b/block.c
 @@ -787,7 +787,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, 
 int flags,
BlockDriver *drv)
  {
  int ret;
 -char tmp_filename[PATH_MAX];
 +/* TODO: extra byte is a hack to ensure MAX_PATH space on Windows. */
 +char tmp_filename[PATH_MAX + 1];

  if (flags  BDRV_O_SNAPSHOT) {
  BlockDriverState *bs1;
 --
 1.7.10.4




Re: [Qemu-devel] [PATCH V11 1/7] Build system fix distclean error for pixman

2012-11-24 Thread Blue Swirl
Thanks, applied this patch only.

On Sat, Nov 24, 2012 at 9:27 AM, Wenchao Xia xiaw...@linux.vnet.ibm.com wrote:
   Currently Makefile test if pixman have configure log, but the script 
 directly
 return error if that file do not exist. This patch fix it.

 v2: print out the command.
 v3: resend as a stand alone fix patch, add reviewer.

   This patch have been sent as a stand alone fix for 1.3, if it is already
 merged pls ignore it.

 Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
 Reviewed-by: Peter Maydell peter.mayd...@linaro.org
 ---
  Makefile |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

 diff --git a/Makefile b/Makefile
 index 3e8d441..9ecbcbb 100644
 --- a/Makefile
 +++ b/Makefile
 @@ -286,7 +286,7 @@ distclean: clean
 for d in $(TARGET_DIRS) $(QEMULIBS); do \
 rm -rf $$d || exit 1 ; \
  done
 -   test -f pixman/config.log  make -C pixman distclean
 +   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 \
  ar  de en-us  fi  fr-be  hr it  lv  nl pl  ru th \
 --
 1.7.1





Re: [Qemu-devel] [PATCH] chardev: Use real-time clock for open timer

2012-11-24 Thread Blue Swirl
Thanks, applied.

On Thu, Nov 22, 2012 at 5:30 PM, Jan Kiszka jan.kis...@siemens.com wrote:
 The vm clock may be stopped, and then we won't get open events anymore.
 Seen with QMP sessions.

 Reported-by: Dietmar Maurer diet...@proxmox.com
 Tested-by: Luiz Capitulino lcapitul...@redhat.com
 Signed-off-by: Jan Kiszka jan.kis...@siemens.com
 ---
  qemu-char.c |4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)

 diff --git a/qemu-char.c b/qemu-char.c
 index 88f4025..242b799 100644
 --- a/qemu-char.c
 +++ b/qemu-char.c
 @@ -134,9 +134,9 @@ static void qemu_chr_fire_open_event(void *opaque)
  void qemu_chr_generic_open(CharDriverState *s)
  {
  if (s-open_timer == NULL) {
 -s-open_timer = qemu_new_timer_ms(vm_clock,
 +s-open_timer = qemu_new_timer_ms(rt_clock,
qemu_chr_fire_open_event, s);
 -qemu_mod_timer(s-open_timer, qemu_get_clock_ms(vm_clock) - 1);
 +qemu_mod_timer(s-open_timer, qemu_get_clock_ms(rt_clock) - 1);
  }
  }

 --
 1.7.3.4




[Qemu-devel] [PATCH for 1.3] pflash_cfi01: Suppress warning when Linux probes for AMD flash

2012-11-24 Thread Stefan Weil
There are several ARM and MIPS boards which are manufactured with
either Intel (pflash_cfi01.c) or AMD (pflash_cfi02.c) flash memory.

The Linux kernel supports both and first probes for AMD flash which
resulted in one or two warnings from the Intel flash emulation:

pflash_write: Unimplemented flash cmd sequence (offset , wcycle 
0x0 cmd 0x0 value 0xf000f0)
pflash_write: Unimplemented flash cmd sequence (offset , wcycle 
0x0 cmd 0x0 value 0xf0)

These warnings confuse users, so suppress them.

Signed-off-by: Stefan Weil s...@weilnetz.de
---

This is strictly speaking not a bug fix, but it fixes a warning
which confuses QEMU users since a long time (see previous mails
on qemu-devel and bug report).

It is also safe. Therefore I think it can be applied to 1.3.

Regards
Stefan

 hw/pflash_cfi01.c |3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/pflash_cfi01.c b/hw/pflash_cfi01.c
index 7d040b5..a4dbe19 100644
--- a/hw/pflash_cfi01.c
+++ b/hw/pflash_cfi01.c
@@ -319,6 +319,9 @@ static void pflash_write(pflash_t *pfl, hwaddr offset,
 DPRINTF(%s: Write to buffer\n, __func__);
 pfl-status |= 0x80; /* Ready! */
 break;
+case 0xf0: /* Probe for AMD flash */
+DPRINTF(%s: Probe for AMD flash\n, __func__);
+goto reset_flash;
 case 0xff: /* Read array mode */
 DPRINTF(%s: Read array mode\n, __func__);
 goto reset_flash;
-- 
1.7.10.4




Re: [Qemu-devel] [RFC PATCH v2 1/3] virtio-bus : Introduce VirtioBus.

2012-11-24 Thread Andreas Färber
Am 22.11.2012 15:50, schrieb fred.kon...@greensocs.com:
 diff --git a/hw/virtio-bus.c b/hw/virtio-bus.c
 new file mode 100644
 index 000..991b6f5
 --- /dev/null
 +++ b/hw/virtio-bus.c
[...]
 +#define DEBUG_VIRTIO_BUS 1

We probably want to disable debug output by default as done elsewhere?

 +
 +#define DPRINTF(fmt, ...) if (DEBUG_VIRTIO_BUS) {\
 +printf(virtio_bus:  fmt , ## __VA_ARGS__); \
 +  }
 +
 +static void virtio_bus_init_cb(VirtioBus *bus);
 +static int virtio_bus_reset(BusState *qbus);
 +
 +static void virtio_bus_class_init(ObjectClass *klass, void *data)
 +{
 +BusClass *k = BUS_CLASS(klass);
 +k-reset = virtio_bus_reset;
 +}
 +
 +static TypeInfo virtio_bus_info = {

Somehow you lost const here since v1.

 +.name = TYPE_VIRTIO_BUS,
 +.parent = TYPE_BUS,
 +.instance_size = sizeof(VirtioBus),
 +.class_init = virtio_bus_class_init,
 +};

The BUS()-related changes look good, 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



[Qemu-devel] [PATCH v7 0/7] push mmio dispatch out of big lock

2012-11-24 Thread Liu Ping Fan
From: Liu Ping Fan pingf...@linux.vnet.ibm.com

v1:
https://lists.gnu.org/archive/html/qemu-devel/2012-07/msg03312.html

v2:
http://lists.gnu.org/archive/html/qemu-devel/2012-08/msg01275.html

v3:
http://lists.nongnu.org/archive/html/qemu-devel/2012-09/msg01474.html

v4:
http://lists.gnu.org/archive/html/qemu-devel/2012-10/msg03857.html

v5:
https://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04867.html

v6:
http://lists.gnu.org/archive/html/qemu-devel/2012-11/msg00542.html
--
changes v5-v6:
 Apply fine-grain lock for all address space.
 Introduce separated interface to allow mmio dispatcher called with/without big 
lock.

changes v6-v7:
 drop wrapper of gcc atomic builtin
  

Liu Ping Fan (7):
  qom: apply atomic on object's refcount
  hotplug: introduce qdev_unplug_complete() to remove device from views
  pci: remove pci device from mem view when unplug
  memory: introduce local lock for address space
  memory: make mmio dispatch able to be out of biglock
  memory: introduce tls context to trace nested mmio request issue
  vcpu: push mmio dispatcher out of big lock

 cpu-common.h  |3 +
 docs/memory.txt   |4 +
 exec.c|  206 -
 hw/acpi_piix4.c   |2 +-
 hw/pci.c  |   13 +++-
 hw/pci.h  |1 +
 hw/qdev.c |   26 +++
 hw/qdev.h |3 +-
 kvm-all.c |4 +-
 memory-internal.h |1 +
 memory.c  |1 +
 memory.h  |5 ++
 qom/object.c  |5 +-
 13 files changed, 250 insertions(+), 24 deletions(-)

-- 
1.7.4.4




[Qemu-devel] [PATCH v7 1/7] qom: apply atomic on object's refcount

2012-11-24 Thread Liu Ping Fan
From: Liu Ping Fan pingf...@linux.vnet.ibm.com

Signed-off-by: Liu Ping Fan pingf...@linux.vnet.ibm.com
---
 qom/object.c |5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index e3e9242..1a697b3 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -600,16 +600,15 @@ GSList *object_class_get_list(const char *implements_type,
 
 void object_ref(Object *obj)
 {
-obj-ref++;
+ __sync_fetch_and_add(obj-ref, 1);
 }
 
 void object_unref(Object *obj)
 {
 g_assert(obj-ref  0);
-obj-ref--;
 
 /* parent always holds a reference to its children */
-if (obj-ref == 0) {
+if (__sync_fetch_and_sub(obj-ref, 1) == 1) {
 object_finalize(obj);
 }
 }
-- 
1.7.4.4




[Qemu-devel] [PATCH v7 2/7] hotplug: introduce qdev_unplug_complete() to remove device from views

2012-11-24 Thread Liu Ping Fan
From: Liu Ping Fan pingf...@linux.vnet.ibm.com

When device unplug has been ack by guest, we first remove it from memory
to prevent incoming access from dispatcher. Then we isolate it from
device composition tree

Signed-off-by: Liu Ping Fan pingf...@linux.vnet.ibm.com
---
 hw/qdev.c |   26 ++
 hw/qdev.h |3 ++-
 2 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index 9b9aba3..681e133 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -98,6 +98,14 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
 bus_add_child(bus, dev);
 }
 
+static void qdev_unset_parent(DeviceState *dev)
+{
+BusState *b = dev-parent_bus;
+
+object_unparent(OBJECT(dev));
+bus_remove_child(b, dev);
+}
+
 /* Create a new device.  This only initializes the device state structure
and allows properties to be set.  qdev_init should be called to
initialize the actual device emulation.  */
@@ -187,6 +195,24 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int 
alias_id,
 dev-alias_required_for_version = required_for_version;
 }
 
+static int qdev_unmap(DeviceState *dev)
+{
+DeviceClass *dc =  DEVICE_GET_CLASS(dev);
+if (dc-unmap) {
+dc-unmap(dev);
+}
+return 0;
+}
+
+void qdev_unplug_complete(DeviceState *dev, Error **errp)
+{
+/* isolate from mem view */
+qdev_unmap(dev);
+/* isolate from device tree */
+qdev_unset_parent(dev);
+object_unref(OBJECT(dev));
+}
+
 void qdev_unplug(DeviceState *dev, Error **errp)
 {
 DeviceClass *dc = DEVICE_GET_CLASS(dev);
diff --git a/hw/qdev.h b/hw/qdev.h
index c6ac636..71eb9ca 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -47,7 +47,7 @@ typedef struct DeviceClass {
 
 /* callbacks */
 void (*reset)(DeviceState *dev);
-
+void (*unmap)(DeviceState *dev);
 /* device state */
 const VMStateDescription *vmsd;
 
@@ -160,6 +160,7 @@ void qdev_init_nofail(DeviceState *dev);
 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
  int required_for_version);
 void qdev_unplug(DeviceState *dev, Error **errp);
+void qdev_unplug_complete(DeviceState *dev, Error **errp);
 void qdev_free(DeviceState *dev);
 int qdev_simple_unplug_cb(DeviceState *dev);
 void qdev_machine_creation_done(void);
-- 
1.7.4.4




[Qemu-devel] [PATCH v7 3/7] pci: remove pci device from mem view when unplug

2012-11-24 Thread Liu Ping Fan
From: Liu Ping Fan pingf...@linux.vnet.ibm.com

Signed-off-by: Liu Ping Fan pingf...@linux.vnet.ibm.com
---
 hw/acpi_piix4.c |2 +-
 hw/pci.c|   13 -
 hw/pci.h|1 +
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
index 15275cf..b45a016 100644
--- a/hw/acpi_piix4.c
+++ b/hw/acpi_piix4.c
@@ -306,7 +306,7 @@ static void acpi_piix_eject_slot(PIIX4PMState *s, unsigned 
slots)
 if (pc-no_hotplug) {
 slot_free = false;
 } else {
-qdev_free(qdev);
+qdev_unplug_complete(qdev, NULL);
 }
 }
 }
diff --git a/hw/pci.c b/hw/pci.c
index 7eeaac0..9ba589e 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -869,7 +869,6 @@ static int pci_unregister_device(DeviceState *dev)
 PCIDevice *pci_dev = PCI_DEVICE(dev);
 PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pci_dev);
 
-pci_unregister_io_regions(pci_dev);
 pci_del_option_rom(pci_dev);
 
 if (pc-exit) {
@@ -880,6 +879,17 @@ static int pci_unregister_device(DeviceState *dev)
 return 0;
 }
 
+static void pci_unmap_device(DeviceState *dev)
+{
+PCIDevice *pci_dev = PCI_DEVICE(dev);
+PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(pci_dev);
+
+pci_unregister_io_regions(pci_dev);
+if (pc-unmap) {
+pc-unmap(pci_dev);
+}
+}
+
 void pci_register_bar(PCIDevice *pci_dev, int region_num,
   uint8_t type, MemoryRegion *memory)
 {
@@ -2105,6 +2115,7 @@ static void pci_device_class_init(ObjectClass *klass, 
void *data)
 DeviceClass *k = DEVICE_CLASS(klass);
 k-init = pci_qdev_init;
 k-unplug = pci_unplug_device;
+k-unmap = pci_unmap_device;
 k-exit = pci_unregister_device;
 k-bus_type = TYPE_PCI_BUS;
 k-props = pci_props;
diff --git a/hw/pci.h b/hw/pci.h
index 1f902f5..898cc5e 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -154,6 +154,7 @@ typedef struct PCIDeviceClass {
 DeviceClass parent_class;
 
 int (*init)(PCIDevice *dev);
+void (*unmap)(PCIDevice *dev);
 PCIUnregisterFunc *exit;
 PCIConfigReadFunc *config_read;
 PCIConfigWriteFunc *config_write;
-- 
1.7.4.4




[Qemu-devel] [PATCH v7 4/7] memory: introduce local lock for address space

2012-11-24 Thread Liu Ping Fan
From: Liu Ping Fan pingf...@linux.vnet.ibm.com

For those address spaces which want to be able out of big lock, they
will be protected by their own local.

Signed-off-by: Liu Ping Fan pingf...@linux.vnet.ibm.com
---
 memory.c |1 +
 memory.h |3 +++
 2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/memory.c b/memory.c
index 2f68d67..18425fd 100644
--- a/memory.c
+++ b/memory.c
@@ -1535,6 +1535,7 @@ void memory_listener_unregister(MemoryListener *listener)
 void address_space_init(AddressSpace *as, MemoryRegion *root)
 {
 memory_region_transaction_begin();
+qemu_mutex_init(as-lock);
 as-root = root;
 as-current_map = g_new(FlatView, 1);
 flatview_init(as-current_map);
diff --git a/memory.h b/memory.h
index 79393f1..13a9e3e 100644
--- a/memory.h
+++ b/memory.h
@@ -22,6 +22,7 @@
 #include cpu-common.h
 #include targphys.h
 #include qemu-queue.h
+#include qemu-thread.h
 #include iorange.h
 #include ioport.h
 #include int128.h
@@ -164,6 +165,7 @@ typedef struct AddressSpace AddressSpace;
  */
 struct AddressSpace {
 /* All fields are private. */
+QemuMutex lock;
 const char *name;
 MemoryRegion *root;
 struct FlatView *current_map;
@@ -801,6 +803,7 @@ void mtree_info(fprintf_function mon_printf, void *f);
  *
  * @as: an uninitialized #AddressSpace
  * @root: a #MemoryRegion that routes addesses for the address space
+ * @lock: if true, the physmap protected by local lock, otherwise big lock
  */
 void address_space_init(AddressSpace *as, MemoryRegion *root);
 
-- 
1.7.4.4




[Qemu-devel] [PATCH v7 5/7] memory: make mmio dispatch able to be out of biglock

2012-11-24 Thread Liu Ping Fan
From: Liu Ping Fan pingf...@linux.vnet.ibm.com

Without biglock, we try to protect the mr by increase refcnt.
If we cannot inc refcnt, go backward and resort to biglock.

Another point is memory radix-tree can be flushed by another
thread, so we should get the copy of terminal mr to survive
from such issue.

Signed-off-by: Liu Ping Fan pingf...@linux.vnet.ibm.com
---
 docs/memory.txt   |4 ++
 exec.c|  154 +++-
 memory-internal.h |1 +
 memory.h  |2 +
 4 files changed, 146 insertions(+), 15 deletions(-)

diff --git a/docs/memory.txt b/docs/memory.txt
index 5bbee8e..6b3d15a 100644
--- a/docs/memory.txt
+++ b/docs/memory.txt
@@ -170,3 +170,7 @@ various constraints can be supplied to control how these 
callbacks are called:
  - .old_portio and .old_mmio can be used to ease porting from code using
cpu_register_io_memory() and register_ioport().  They should not be used
in new code.
+
+MMIO regions are provided with -ref() and -unref() callbacks; This pair 
callbacks
+are optional. When ref() return non-zero, Both MemoryRegion and its opaque are
+safe to use.
diff --git a/exec.c b/exec.c
index 750008c..fa34ef9 100644
--- a/exec.c
+++ b/exec.c
@@ -2280,7 +2280,7 @@ static void register_multipage(AddressSpaceDispatch *d, 
MemoryRegionSection *sec
   section_index);
 }
 
-static void mem_add(MemoryListener *listener, MemoryRegionSection *section)
+static void mem_nop(MemoryListener *listener, MemoryRegionSection *section)
 {
 AddressSpaceDispatch *d = container_of(listener, AddressSpaceDispatch, 
listener);
 MemoryRegionSection now = *section, remain = *section;
@@ -2314,6 +2314,26 @@ static void mem_add(MemoryListener *listener, 
MemoryRegionSection *section)
 }
 }
 
+static void mem_add(MemoryListener *listener, MemoryRegionSection *section)
+{
+MemoryRegion *mr = section-mr;
+
+if (mr-ops  mr-ops-ref) {
+mr-ops-ref(mr);
+}
+mem_nop(listener, section);
+}
+
+static void mem_del(MemoryListener *listener,
+MemoryRegionSection *section)
+{
+MemoryRegion *mr = section-mr;
+
+if (mr-ops  mr-ops-unref) {
+mr-ops-unref(mr);
+}
+}
+
 void qemu_flush_coalesced_mmio_buffer(void)
 {
 if (kvm_enabled())
@@ -3165,11 +3185,23 @@ static void io_mem_init(void)
 static void mem_begin(MemoryListener *listener)
 {
 AddressSpaceDispatch *d = container_of(listener, AddressSpaceDispatch, 
listener);
+AddressSpace *as = d-as;
 
+/* protect the updating process of mrs in memory core agaist readers */
+qemu_mutex_lock(as-lock);
 destroy_all_mappings(d);
 d-phys_map.ptr = PHYS_MAP_NODE_NIL;
 }
 
+static void mem_commit(MemoryListener *listener)
+{
+AddressSpaceDispatch *d = container_of(listener, AddressSpaceDispatch,
+listener);
+AddressSpace *as = d-as;
+
+qemu_mutex_unlock(as-lock);
+}
+
 static void core_begin(MemoryListener *listener)
 {
 phys_sections_clear();
@@ -3243,11 +3275,14 @@ void address_space_init_dispatch(AddressSpace *as)
 d-phys_map  = (PhysPageEntry) { .ptr = PHYS_MAP_NODE_NIL, .is_leaf = 0 };
 d-listener = (MemoryListener) {
 .begin = mem_begin,
+.commit = mem_commit,
 .region_add = mem_add,
-.region_nop = mem_add,
+.region_del = mem_del,
+.region_nop = mem_nop,
 .priority = 0,
 };
 as-dispatch = d;
+as-dispatch-as = as;
 memory_listener_register(d-listener, as);
 }
 
@@ -3345,6 +3380,68 @@ static void invalidate_and_set_dirty(target_phys_addr_t 
addr,
 xen_modified_memory(addr, length);
 }
 
+static MemoryRegionSection *subpage_get_terminal(subpage_t *mmio,
+target_phys_addr_t addr)
+{
+MemoryRegionSection *section;
+unsigned int idx = SUBPAGE_IDX(addr);
+
+section = phys_sections[mmio-sub_section[idx]];
+return section;
+}
+
+static bool memory_region_section_ref(MemoryRegionSection *mrs)
+{
+MemoryRegion *mr;
+bool ret = false;
+
+mr = mrs-mr;
+if (mr-ops  mr-ops-ref) {
+mr-ops-ref(mr);
+ret = true;
+}
+return ret;
+}
+
+static void memory_region_section_unref(MemoryRegionSection *mrs)
+{
+MemoryRegion *mr;
+
+mr = mrs-mr;
+if (mr-ops  mr-ops-unref) {
+mr-ops-unref(mr);
+}
+}
+
+static bool memory_region_section_lookup_ref(AddressSpaceDispatch *d,
+target_phys_addr_t addr, MemoryRegionSection *mrs)
+{
+MemoryRegionSection *section;
+bool ret;
+
+section = phys_page_find(d, addr  TARGET_PAGE_BITS);
+if (section-mr-subpage) {
+section = subpage_get_terminal(section-mr-opaque, addr);
+}
+*mrs = *section;
+ret = memory_region_section_ref(mrs);
+
+return ret;
+}
+
+static bool address_space_section_lookup_ref(AddressSpace *as,
+target_phys_addr_t page, MemoryRegionSection *mrs)
+{
+bool safe_ref;
+AddressSpaceDispatch *d = as-dispatch;
+
+

[Qemu-devel] [PATCH v7 6/7] memory: introduce tls context to trace nested mmio request issue

2012-11-24 Thread Liu Ping Fan
From: Liu Ping Fan pingf...@linux.vnet.ibm.com

After breaking down big lock, nested MMIO request which not targeting
at RAM can cause deadlock issue. Supposing the scene: dev_a,b with
fine-grain locks lockA/B, then ABBA dealock issue can be triggered.
We fix this by tracing and rejecting such request.

Signed-off-by: Liu Ping Fan pingf...@linux.vnet.ibm.com
---
 exec.c |   37 -
 1 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/exec.c b/exec.c
index fa34ef9..7eae54e 100644
--- a/exec.c
+++ b/exec.c
@@ -3442,6 +3442,32 @@ static bool 
address_space_section_lookup_ref(AddressSpace *as,
 return safe_ref;
 }
 
+typedef struct ThreadContext {
+  unsigned int req_pending;
+} ThreadContext;
+
+static DEFINE_TLS(ThreadContext, thread_context) = {
+.req_pending = 0
+};
+#define thread_context tls_var(thread_context)
+
+static bool address_space_check_inc_req_pending(MemoryRegionSection *section)
+{
+bool nested;
+
+nested = ++thread_context.req_pending  1 ? true : false;
+/* To fix, will filter iommu case */
+if (nested  !memory_region_is_ram(section-mr)) {
+fprintf(stderr, waring: nested target not RAM is not support);
+}
+return nested;
+}
+
+static void address_space_dec_req_pending(void)
+{
+thread_context.req_pending--;
+}
+
 void address_space_rw(AddressSpace *as, target_phys_addr_t addr, uint8_t *buf,
   int len, bool is_write)
 {
@@ -3450,7 +3476,7 @@ void address_space_rw(AddressSpace *as, 
target_phys_addr_t addr, uint8_t *buf,
 uint8_t *ptr;
 uint32_t val;
 target_phys_addr_t page;
-bool safe_ref;
+bool safe_ref, nested;
 MemoryRegionSection *section, obj_mrs;
 
 while (len  0) {
@@ -3462,6 +3488,11 @@ void address_space_rw(AddressSpace *as, 
target_phys_addr_t addr, uint8_t *buf,
 qemu_mutex_lock(as-lock);
 safe_ref = memory_region_section_lookup_ref(d, page, obj_mrs);
 qemu_mutex_unlock(as-lock);
+nested = address_space_check_inc_req_pending(obj_mrs);
+if (nested) {
+goto skip;
+}
+
 if (!safe_ref) {
 qemu_mutex_lock_iothread();
 qemu_mutex_lock(as-lock);
@@ -3477,6 +3508,7 @@ void address_space_rw(AddressSpace *as, 
target_phys_addr_t addr, uint8_t *buf,
 if (is_write) {
 if (!memory_region_is_ram(section-mr)) {
 target_phys_addr_t addr1;
+
 addr1 = memory_region_section_addr(section, addr);
 /* XXX: could force cpu_single_env to NULL to avoid
potential bugs */
@@ -3510,6 +3542,7 @@ void address_space_rw(AddressSpace *as, 
target_phys_addr_t addr, uint8_t *buf,
 if (!(memory_region_is_ram(section-mr) ||
   memory_region_is_romd(section-mr))) {
 target_phys_addr_t addr1;
+
 /* I/O case */
 addr1 = memory_region_section_addr(section, addr);
 if (l = 4  ((addr1  3) == 0)) {
@@ -3537,6 +3570,8 @@ void address_space_rw(AddressSpace *as, 
target_phys_addr_t addr, uint8_t *buf,
 qemu_put_ram_ptr(ptr);
 }
 }
+skip:
+address_space_dec_req_pending();
 memory_region_section_unref(obj_mrs);
 len -= l;
 buf += l;
-- 
1.7.4.4




[Qemu-devel] [PATCH v7 7/7] vcpu: push mmio dispatcher out of big lock

2012-11-24 Thread Liu Ping Fan
From: Liu Ping Fan pingf...@linux.vnet.ibm.com

To anti the recursive big lock, introduce separate interfaces to allow
address space dispatcher called with/without big lock.

Signed-off-by: Liu Ping Fan pingf...@linux.vnet.ibm.com
---
 cpu-common.h |3 +++
 exec.c   |   21 +
 kvm-all.c|4 +++-
 3 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/cpu-common.h b/cpu-common.h
index c0d27af..69c1d7a 100644
--- a/cpu-common.h
+++ b/cpu-common.h
@@ -51,6 +51,9 @@ void qemu_ram_set_idstr(ram_addr_t addr, const char *name, 
DeviceState *dev);
 
 void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
 int len, int is_write);
+void cpu_physical_memory_nolock_rw(target_phys_addr_t addr, uint8_t *buf,
+int len, int is_write);
+
 static inline void cpu_physical_memory_read(target_phys_addr_t addr,
 void *buf, int len)
 {
diff --git a/exec.c b/exec.c
index 7eae54e..9fec600 100644
--- a/exec.c
+++ b/exec.c
@@ -3468,8 +3468,8 @@ static void address_space_dec_req_pending(void)
 thread_context.req_pending--;
 }
 
-void address_space_rw(AddressSpace *as, target_phys_addr_t addr, uint8_t *buf,
-  int len, bool is_write)
+static void address_space_rw_internal(AddressSpace *as, target_phys_addr_t 
addr,
+  uint8_t *buf, int len, bool is_write, bool biglock)
 {
 AddressSpaceDispatch *d = as-dispatch;
 int l;
@@ -3493,7 +3493,7 @@ void address_space_rw(AddressSpace *as, 
target_phys_addr_t addr, uint8_t *buf,
 goto skip;
 }
 
-if (!safe_ref) {
+if (!safe_ref  !biglock) {
 qemu_mutex_lock_iothread();
 qemu_mutex_lock(as-lock);
 /* when 2nd try, mem map can change, need to judge it again */
@@ -3576,12 +3576,18 @@ skip:
 len -= l;
 buf += l;
 addr += l;
-if (!safe_ref) {
+if (!safe_ref  !biglock) {
 qemu_mutex_unlock_iothread();
 }
 }
 }
 
+void address_space_rw(AddressSpace *as, target_phys_addr_t addr, uint8_t *buf,
+  int len, bool is_write)
+{
+address_space_rw_internal(as, addr, buf, len, is_write, true);
+}
+
 void address_space_write(AddressSpace *as, target_phys_addr_t addr,
  const uint8_t *buf, int len)
 {
@@ -3607,6 +3613,13 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, 
uint8_t *buf,
 return address_space_rw(address_space_memory, addr, buf, len, is_write);
 }
 
+void cpu_physical_memory_nolock_rw(target_phys_addr_t addr, uint8_t *buf,
+int len, int is_write)
+{
+return address_space_rw_internal(address_space_memory, addr, buf, len,
+   is_write, false);
+}
+
 /* used for ROM loading : can write in RAM and ROM */
 void cpu_physical_memory_write_rom(target_phys_addr_t addr,
const uint8_t *buf, int len)
diff --git a/kvm-all.c b/kvm-all.c
index c2c6909..41261d2 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1573,10 +1573,12 @@ int kvm_cpu_exec(CPUArchState *env)
 break;
 case KVM_EXIT_MMIO:
 DPRINTF(handle_mmio\n);
-cpu_physical_memory_rw(run-mmio.phys_addr,
+qemu_mutex_unlock_iothread();
+cpu_physical_memory_nolock_rw(run-mmio.phys_addr,
run-mmio.data,
run-mmio.len,
run-mmio.is_write);
+qemu_mutex_lock_iothread();
 ret = 0;
 break;
 case KVM_EXIT_IRQ_WINDOW_OPEN:
-- 
1.7.4.4




[Qemu-devel] [PATCH v2 1/2] ivshmem: remove msix_write_config

2012-11-24 Thread Liu Ping Fan
From: Liu Ping Fan pingf...@linux.vnet.ibm.com

This logic has been integrated into pci core, so remove it.

Signed-off-by: Liu Ping Fan pingf...@linux.vnet.ibm.com
---
 hw/ivshmem.c |1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/hw/ivshmem.c b/hw/ivshmem.c
index f6dbb21..7c8630c 100644
--- a/hw/ivshmem.c
+++ b/hw/ivshmem.c
@@ -629,7 +629,6 @@ static void ivshmem_write_config(PCIDevice *pci_dev, 
uint32_t address,
 uint32_t val, int len)
 {
 pci_default_write_config(pci_dev, address, val, len);
-msix_write_config(pci_dev, address, val, len);
 }
 
 static int pci_ivshmem_init(PCIDevice *dev)
-- 
1.7.4.4




[Qemu-devel] [PATCH v2 2/2] ivshmem: use irqfd to interrupt among VMs

2012-11-24 Thread Liu Ping Fan
From: Liu Ping Fan pingf...@linux.vnet.ibm.com

Using irqfd, so we can avoid switch between kernel and user when
VMs interrupts each other.

Signed-off-by: Liu Ping Fan pingf...@linux.vnet.ibm.com
---
 hw/ivshmem.c |   54 +-
 1 files changed, 53 insertions(+), 1 deletions(-)

diff --git a/hw/ivshmem.c b/hw/ivshmem.c
index 7c8630c..5709e89 100644
--- a/hw/ivshmem.c
+++ b/hw/ivshmem.c
@@ -19,6 +19,7 @@
 #include hw.h
 #include pc.h
 #include pci.h
+#include msi.h
 #include msix.h
 #include kvm.h
 #include migration.h
@@ -83,6 +84,7 @@ typedef struct IVShmemState {
 uint32_t vectors;
 uint32_t features;
 EventfdEntry *eventfd_table;
+int *vector_virqs;
 
 Error *migration_blocker;
 
@@ -625,16 +627,62 @@ static int ivshmem_load(QEMUFile* f, void *opaque, int 
version_id)
 return 0;
 }
 
+static int ivshmem_vector_use(PCIDevice *dev, unsigned vector,
+ MSIMessage msg)
+{
+IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+int virq;
+EventNotifier *n = s-peers[s-vm_id].eventfds[vector];
+
+virq = kvm_irqchip_add_msi_route(kvm_state, msg);
+if (virq = 0  kvm_irqchip_add_irqfd_notifier(kvm_state, n, virq) = 0) {
+s-vector_virqs[vector] = virq;
+qemu_chr_add_handlers(s-eventfd_chr[vector], NULL, NULL, NULL, NULL);
+} else if (virq = 0) {
+kvm_irqchip_release_virq(kvm_state, virq);
+error_report(ivshmem, can not setup irqfd\n);
+return -1;
+} else {
+error_report(ivshmem, no enough msi route to setup irqfd\n);
+return -1;
+}
+
+return 0;
+}
+
+static void ivshmem_vector_release(PCIDevice *dev, unsigned vector)
+{
+IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
+EventNotifier *n = s-peers[s-vm_id].eventfds[vector];
+int virq = s-vector_virqs[vector];
+
+if (s-vector_virqs[vector] = 0) {
+kvm_irqchip_remove_irqfd_notifier(kvm_state, n, virq);
+kvm_irqchip_release_virq(kvm_state, virq);
+s-vector_virqs[vector] = -1;
+}
+}
+
 static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
 uint32_t val, int len)
 {
+bool is_enabled, was_enabled = msi_enabled(pci_dev);
+
 pci_default_write_config(pci_dev, address, val, len);
+is_enabled = msi_enabled(pci_dev);
+if (!was_enabled  is_enabled) {
+msix_set_vector_notifiers(pci_dev, ivshmem_vector_use,
+ivshmem_vector_release);
+} else if (was_enabled  !is_enabled) {
+msix_unset_vector_notifiers(pci_dev);
+}
 }
 
 static int pci_ivshmem_init(PCIDevice *dev)
 {
 IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
 uint8_t *pci_conf;
+int i;
 
 if (s-sizearg == NULL)
 s-ivshmem_size = 4  20; /* 4 MB default */
@@ -758,7 +806,10 @@ static int pci_ivshmem_init(PCIDevice *dev)
 }
 
 s-dev.config_write = ivshmem_write_config;
-
+s-vector_virqs = g_new0(int, s-vectors);
+for (i = 0; i  s-vectors; i++) {
+s-vector_virqs[i] = -1;
+}
 return 0;
 }
 
@@ -770,6 +821,7 @@ static void pci_ivshmem_uninit(PCIDevice *dev)
 migrate_del_blocker(s-migration_blocker);
 error_free(s-migration_blocker);
 }
+g_free(s-vector_virqs);
 
 memory_region_destroy(s-ivshmem_mmio);
 memory_region_del_subregion(s-bar, s-ivshmem);
-- 
1.7.4.4




[Qemu-devel] qemu-system-arm v1.3.0-rc0 / 1.2.1 freeze on OSX 10.8.2

2012-11-24 Thread Pi LFS
I've compiled it using the apple-gcc42 toolchain from homebrew.
qemu-system-arm starts up with a white window, CPU usage goes up but window
just hangs there. I can access the menus and click the window to switch
input focus, that's about it.
There is no debug output/logging to give any clue what it's doing.

My qemu-system-i386 runs fine, so it's probably ARM specific.

I've encountered other users with the same problem.


Re: [Qemu-devel] [PATCH] exec.c: Use tb1-phys_hash_next directly in tb_remove

2012-11-24 Thread Wei-Ren Chen
  ping?

On Tue, Nov 20, 2012 at 12:41:03PM +, Peter Maydell wrote:
 On 20 November 2012 12:30, 陳韋任 (Wei-Ren Chen) che...@iis.sinica.edu.tw 
 wrote:
When tb_remove was first commited at fd6ce8f6, there were three different
  calls pass different names to offsetof. In current codebase, the other two
  calls are replaced with tb_page_remove. There is no need to have a general
  tb_remove. Omit passing the third parameter and using tb1-phys_hash_next
  directly.
 
 I like this, it makes the function less confusing to remove this
 now-unneeded generality.
 
  Signed-off-by: Chen Wei-Ren che...@iis.sinica.edu.tw
  ---
   exec.c |   10 --
   1 files changed, 4 insertions(+), 6 deletions(-)
 
  diff --git a/exec.c b/exec.c
  index 8435de0..e54fce2 100644
  --- a/exec.c
  +++ b/exec.c
  @@ -863,17 +863,16 @@ static void tb_page_check(void)
   #endif
 
   /* invalidate one TB */
 
 This comment is now a bit out of date (and in fact it has been for
 some time) and should probably be deleted. (The function that really
 needs a comment is the top level tb_phys_invalidate(), rather than
 the helpers tb_hash_remove/tb_page_remove/tb_jmp_remove.)
 
  -static inline void tb_remove(TranslationBlock **ptb, TranslationBlock *tb,
  - int next_offset)
  +static inline void tb_hash_remove(TranslationBlock **ptb, TranslationBlock 
  *tb)
   {
   TranslationBlock *tb1;
   for(;;) {
   tb1 = *ptb;
   if (tb1 == tb) {
  -*ptb = *(TranslationBlock **)((char *)tb1 + next_offset);
  +*ptb = tb1-phys_hash_next;
   break;
   }
  -ptb = (TranslationBlock **)((char *)tb1 + next_offset);
  +ptb = (tb1-phys_hash_next);
 
 You don't need these brackets.
 
   }
   }
 
  @@ -940,8 +939,7 @@ void tb_phys_invalidate(TranslationBlock *tb, 
  tb_page_addr_t page_addr)
   /* remove the TB from the hash list */
   phys_pc = tb-page_addr[0] + (tb-pc  ~TARGET_PAGE_MASK);
   h = tb_phys_hash_func(phys_pc);
  -tb_remove(tb_phys_hash[h], tb,
  -  offsetof(TranslationBlock, phys_hash_next));
  +tb_hash_remove(tb_phys_hash[h], tb);
 
   /* remove the TB from the page list */
   if (tb-page_addr[0] != page_addr) {
  --
  1.7.3.4
 
 
 -- PMM

-- 
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
Homepage: http://people.cs.nctu.edu.tw/~chenwj