[Qemu-devel] [Tracing][RFC v3 PATCH 0/2] QMP Query interfaces for tracing

2010-10-18 Thread Prerna Saxena
This patch set introduces two QMP interfaces for tracing :

* query-trace: to list current contents of trace-buffer
* query-trace-events : to list all available trace-events with their state.

Changelog :
---
Changes v2 - v3 :
- Change declarations of st_print_trace_to_qlist() and 
st_print_trace_events_to_qlist() to return QList*

Changes v1 - v2 :
- Add 'timestamp' field for query-trace output.
- Misc cleanups.

-- 
Prerna Saxena

Linux Technology Centre,
IBM Systems and Technology Lab,
Bangalore, India




[Qemu-devel] Re: [PATCH v4 01/15] pci: make pci_del_capability() update for w1cmask

2010-10-18 Thread Michael S. Tsirkin
On Mon, Oct 18, 2010 at 12:17:42PM +0900, Isaku Yamahata wrote:
 When deleting pci capability, w1cmask should be 0
 to make those registers writablein addition to wmask.
 
 Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp

Applied (typo in commit message fixed).

 ---
  hw/pci.c |1 +
  1 files changed, 1 insertions(+), 0 deletions(-)
 
 diff --git a/hw/pci.c b/hw/pci.c
 index abddc6d..e3462a9 100644
 --- a/hw/pci.c
 +++ b/hw/pci.c
 @@ -1745,6 +1745,7 @@ void pci_del_capability(PCIDevice *pdev, uint8_t 
 cap_id, uint8_t size)
  pdev-config[prev] = pdev-config[offset + PCI_CAP_LIST_NEXT];
  /* Make capability writeable again */
  memset(pdev-wmask + offset, 0xff, size);
 +memset(pdev-w1cmask + offset, 0, size);
  /* Clear cmask as device-specific registers can't be checked */
  memset(pdev-cmask + offset, 0, size);
  memset(pdev-used + offset, 0, size);
 -- 
 1.7.1.1



Re: [Qemu-devel] Snapshots ide0-hd0 issue

2010-10-18 Thread Stefan Hajnoczi
On Mon, Oct 18, 2010 at 12:37 AM, Ubuntu Explorer
ubuntuexplo...@gmail.com wrote:
 I am trying to implement snapshot saving and loading from command line using
 qemu. I am using both the drive and disk options as follows.
 qemu exe \
 --disk path to disk file \
 ...other options \
 -drive file=path to drive file,
 index=0,media=disk,snapshot=on,if=ide,type=drive,cache=writethrough

Remove snapshot=on.  See the documentation about -snapshot versus
savevm snapshots:

http://wiki.qemu.org/download/qemu-doc.html#vm_005fsnapshots

When using the (unrelated) -snapshot option (Snapshot mode), you can
always make VM snapshots, but they are deleted as soon as you exit
QEMU.

Stefan



[Qemu-devel] [Tracing][RFC v3 PATCH 1/2] Introduce QMP interfaces : query-trace query-trace-events

2010-10-18 Thread Prerna Saxena
[PATCH 1/2] Introduce QMP interfaces : query-trace  query-trace-events.

Signed-off-by: Prerna Saxena pre...@linux.vnet.ibm.com
---
 monitor.c |   40 +++---
 simpletrace.c |   58 +
 simpletrace.h |4 +++
 3 files changed, 98 insertions(+), 4 deletions(-)

diff --git a/monitor.c b/monitor.c
index fbb678d..41f3477 100644
--- a/monitor.c
+++ b/monitor.c
@@ -941,15 +941,27 @@ static void do_info_cpu_stats(Monitor *mon)
 #endif
 
 #if defined(CONFIG_SIMPLE_TRACE)
-static void do_info_trace(Monitor *mon)
+static void do_info_trace_print(Monitor *mon)
 {
 st_print_trace((FILE *)mon, monitor_fprintf);
 }
 
-static void do_info_trace_events(Monitor *mon)
+static void do_info_trace(Monitor *mon, QObject **ret_data)
+{
+QList *trace_event_list = st_print_trace_to_qlist();
+*ret_data = QOBJECT(trace_event_list);
+}
+
+static void do_info_trace_events_print(Monitor *mon, const QObject *data)
 {
 st_print_trace_events((FILE *)mon, monitor_fprintf);
 }
+
+static void do_info_trace_events(Monitor *mon, QObject **ret_data)
+{
+QList *trace_event_list = st_print_trace_events_to_qlist();
+*ret_data = QOBJECT(trace_event_list);
+}
 #endif
 
 /**
@@ -2606,14 +2618,16 @@ static const mon_cmd_t info_cmds[] = {
 .args_type  = ,
 .params = ,
 .help   = show current contents of trace buffer,
-.mhandler.info = do_info_trace,
+.user_print = do_info_trace_print,
+.mhandler.info_new = do_info_trace,
 },
 {
 .name   = trace-events,
 .args_type  = ,
 .params = ,
 .help   = show available trace-events  their state,
-.mhandler.info = do_info_trace_events,
+.user_print = do_info_trace_events_print,
+.mhandler.info_new = do_info_trace_events,
 },
 #endif
 {
@@ -2748,6 +2762,24 @@ static const mon_cmd_t qmp_query_cmds[] = {
 .mhandler.info_async = do_info_balloon,
 .flags  = MONITOR_CMD_ASYNC,
 },
+#if defined(CONFIG_SIMPLE_TRACE)
+{
+.name   = trace,
+.args_type  = ,
+.params = ,
+.help   = show current contents of trace buffer,
+.user_print = do_info_trace_print,
+.mhandler.info_new = do_info_trace,
+},
+{
+.name   = trace-events,
+.args_type  = ,
+.params = ,
+.help   = show available trace-events  their state,
+.user_print = do_info_trace_events_print,
+.mhandler.info_new = do_info_trace_events,
+},
+#endif
 { /* NULL */ },
 };
 
diff --git a/simpletrace.c b/simpletrace.c
index f849e42..9d7ec68 100644
--- a/simpletrace.c
+++ b/simpletrace.c
@@ -220,6 +220,43 @@ void st_print_trace(FILE *stream, int 
(*stream_printf)(FILE *stream, const char
 }
 }
 
+/**
+ * Add the current contents of trace-buffer as a QList.
+ *
+ */
+QList* st_print_trace_to_qlist()
+{
+QObject *data;
+QList *tlist;
+unsigned int i;
+
+tlist = qlist_new();
+
+for (i = 0; i  trace_idx; i++) {
+  data = qobject_from_jsonf({
+ 'timestamp': % PRId64 ,
+ 'event': % PRId64 ,
+ 'arg1': % PRId64 ,
+ 'arg2': % PRId64 ,
+ 'arg3': % PRId64 ,
+ 'arg4': % PRId64 ,
+ 'arg5': % PRId64 ,
+ 'arg6': % PRId64
+},
+trace_buf[i].timestamp_ns,
+trace_buf[i].event,
+trace_buf[i].x1,
+trace_buf[i].x2,
+trace_buf[i].x3,
+trace_buf[i].x4,
+trace_buf[i].x5,
+trace_buf[i].x6);
+  qlist_append_obj(tlist, data);
+}
+
+return tlist;
+}
+
 void st_print_trace_events(FILE *stream, int (*stream_printf)(FILE *stream, 
const char *fmt, ...))
 {
 unsigned int i;
@@ -230,6 +267,27 @@ void st_print_trace_events(FILE *stream, int 
(*stream_printf)(FILE *stream, cons
 }
 }
 
+/**
+ * Add current set of trace-events as a QList.
+ *
+ */
+QList* st_print_trace_events_to_qlist()
+{
+QObject *data;
+QList *tlist;
+unsigned int i;
+
+tlist = qlist_new();
+
+for (i = 0; i  NR_TRACE_EVENTS; i++) {
+  data = qobject_from_jsonf({ 'name': %s, 'event-id': %d, 'state': 
%d}, trace_list[i].tp_name, i,
+trace_list[i].state);
+  qlist_append_obj(tlist, data);
+}
+
+return tlist;
+}
+
 static TraceEvent* find_trace_event_by_name(const char 

[Qemu-devel] [Tracing][RFC v3 PATCH 2/2] Add documentation for QMP commands: query-trace query-trace-events.

2010-10-18 Thread Prerna Saxena
[PATCH 2/2] Add documentation for QMP commands: query-trace  
query-trace-events.

Signed-off-by: Prerna Saxena pre...@linux.vnet.ibm.com
---
 qmp-commands.hx |   71 +++
 1 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/qmp-commands.hx b/qmp-commands.hx
index 793cf1c..fefc93d 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1539,3 +1539,74 @@ Example:
 
 EQMP
 
+SQMP
+query-trace
+-
+
+Show contents of trace buffer.
+
+Returns a set of json-objects containing the following data:
+
+- event: Event ID for the trace-event(json-int)
+- timestamp: trace timestamp (json-int)
+- arg1 .. arg6: Arguments logged by the trace-event (json-int)
+
+Example:
+
+- { execute: query-trace }
+- {
+  return:{
+ event: 22,
+ timestamp: 129456235912365,
+ arg1: 886
+ arg2: 80,
+ arg3: 0,
+ arg4: 0,
+ arg5: 0,
+ arg6: 0,
+   },
+   {
+ event: 22,
+ timestamp: 129456235973407,
+ arg1: 886,
+ arg2: 80,
+ arg3: 0,
+ arg4: 0,
+ arg5: 0,
+ arg6: 0
+   },
+   ...
+   }
+
+EQMP
+
+SQMP
+query-trace-events
+--
+
+Show all available trace-events  their state.
+
+Returns a set of json-objects containing the following data:
+
+- name: Name of Trace-event (json-string)
+- event-id: Event ID of Trace-event (json-int)
+- state: State of trace-event [ '0': inactive; '1':active  ] (json-int)
+
+Example:
+
+- { execute: query-trace-events }
+- {
+  return:{
+ name: qemu_malloc,
+ event-id: 0
+ state: 0,
+  },
+  {
+ name: qemu_realloc,
+ event-id: 1,
+ state: 0
+  },
+  ...
+   }
+
+EQMP
-- 
1.7.2.2



-- 
Prerna Saxena

Linux Technology Centre,
IBM Systems and Technology Lab,
Bangalore, India




[Qemu-devel] Re: [PATCH v4 00/15] pcie port switch emulators

2010-10-18 Thread Michael S. Tsirkin
On Mon, Oct 18, 2010 at 12:17:41PM +0900, Isaku Yamahata wrote:
 
 Here is v4 of the pcie patch series.
 - PCIDevice::written
   The abuse of PCIDevice::config to record a written bit of non-modifiable
   registers is confusing and bad style. So I introduced PCIDevice::written.
 - FLR stuff
   I didn't addresse FLR function pointer issue. Anyway in order to
   make FLR work, Qdev bus reset must be addresssed.
   So Let's discuss it at the next phase.

So let's just punt and add FLR as a stub, not call anything from it.

 new patches: 1, 2, 3, 4, 5
 Other patches are (almost) same as before except adjustment to compile.
 The patches of 1, 2, 3 and 5 can be harmlessly merged, I think.
 
 Patch description:
 This patch series implements pcie port switch emulators
 which is basic part for pcie/q35 support.
 This is for mst/pci tree.
 
 changes v3 - v4:
 - introduced new pci config helper functions.(clear set bit)
 - various clean up and some bug fixes.
 - dropped pci_shift_xxx().
 - dropped function pointerin pcie_aer.h
 - dropped pci_exp_cap(), pcie_aer_cap().
 - file rename (pcie_{root, upstream, downsatrem} = ioh33420, x3130).
 
 changes v2 - v3:
 - msi: improved commant and simplified shift/ffs dance
 - pci w1c config register framework
 - split pcie.[ch] into pcie_regs.h, pcie.[ch] and pcie_aer.[ch]
 - pcie, aer: many changes by following reviews.
 
 changes v1 - v2:
 - update msi
 - dropped already pushed out patches.
 - added msix patches.
 
 
 Isaku Yamahata (15):
   pci: make pci_del_capability() update for w1cmask
   pci: introduce helper functions to clear/set bits in configuration
 space
   pci: use pci_clear_bit_word() in pci_device_reset()
   pci: record which is written into pci configuration space
   pci/bridge: fix pci_bridge_reset()
   msi: implements msi
   pcie: add pcie constants to pcie_regs.h
   pcie: helper functions for pcie capability and extended capability
   pcie/aer: helper functions for pcie aer capability
   pcie port: define struct PCIEPort/PCIESlot and helper functions
   ioh3420: pcie root port in X58 ioh
   x3130: pcie upstream port
   x3130: pcie downstream port
   pcie/hotplug: introduce pushing attention button command
   pcie/aer: glue aer error injection into qemu monitor
 
  Makefile.objs   |4 +-
  hw/ioh3420.c|  228 
  hw/ioh3420.h|   10 +
  hw/msi.c|  352 +++
  hw/msi.h|   41 +++
  hw/pci.c|   16 +-
  hw/pci.h|   92 +-
  hw/pci_bridge.c |   15 +-
  hw/pcie.c   |  529 
  hw/pcie.h   |  112 ++
  hw/pcie_aer.c   |  873 
 +++
  hw/pcie_aer.h   |  105 ++
  hw/pcie_port.c  |  197 +++
  hw/pcie_port.h  |   51 +++
  hw/pcie_regs.h  |  154 +
  hw/xio3130_downstream.c |  207 +++
  hw/xio3130_downstream.h |   11 +
  hw/xio3130_upstream.c   |  188 ++
  hw/xio3130_upstream.h   |   10 +
  qemu-common.h   |6 +
  qemu-monitor.hx |   36 ++
  sysemu.h|9 +
  22 files changed, 3233 insertions(+), 13 deletions(-)
  create mode 100644 hw/ioh3420.c
  create mode 100644 hw/ioh3420.h
  create mode 100644 hw/msi.c
  create mode 100644 hw/msi.h
  create mode 100644 hw/pcie.c
  create mode 100644 hw/pcie.h
  create mode 100644 hw/pcie_aer.c
  create mode 100644 hw/pcie_aer.h
  create mode 100644 hw/pcie_port.c
  create mode 100644 hw/pcie_port.h
  create mode 100644 hw/pcie_regs.h
  create mode 100644 hw/xio3130_downstream.c
  create mode 100644 hw/xio3130_downstream.h
  create mode 100644 hw/xio3130_upstream.c
  create mode 100644 hw/xio3130_upstream.h



[Qemu-devel] Re: [PATCH v4 05/15] pci/bridge: fix pci_bridge_reset()

2010-10-18 Thread Michael S. Tsirkin
On Mon, Oct 18, 2010 at 12:17:46PM +0900, Isaku Yamahata wrote:
 lower 4bits of base/limit register is RO, and
 should not be modified on reset.
 
 Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
 ---
  hw/pci_bridge.c |   15 +--
  1 files changed, 9 insertions(+), 6 deletions(-)
 
 diff --git a/hw/pci_bridge.c b/hw/pci_bridge.c
 index 638e3b3..7229610 100644
 --- a/hw/pci_bridge.c
 +++ b/hw/pci_bridge.c
 @@ -161,12 +161,15 @@ void pci_bridge_reset_reg(PCIDevice *dev)
  conf[PCI_SUBORDINATE_BUS] = 0;
  conf[PCI_SEC_LATENCY_TIMER] = 0;
  
 -conf[PCI_IO_BASE] = 0;
 -conf[PCI_IO_LIMIT] = 0;
 -pci_set_word(conf + PCI_MEMORY_BASE, 0);
 -pci_set_word(conf + PCI_MEMORY_LIMIT, 0);
 -pci_set_word(conf + PCI_PREF_MEMORY_BASE, 0);
 -pci_set_word(conf + PCI_PREF_MEMORY_LIMIT, 0);
 +pci_clear_bit_byte(conf + PCI_IO_BASE, PCI_IO_RANGE_MASK  0xff);
 +pci_clear_bit_byte(conf + PCI_IO_LIMIT, PCI_IO_RANGE_MASK  0xff);

No need for  0xff and  0xf here and below.

also, PCI spec also says that these registers' value
is undefined after reset, so no need to clear them?
If there's a reason, pls put it in comment.


 +pci_clear_bit_word(conf + PCI_MEMORY_BASE, PCI_MEMORY_RANGE_MASK  
 0x);
 +pci_clear_bit_word(conf + PCI_MEMORY_LIMIT,
 +   PCI_MEMORY_RANGE_MASK  0x);
 +pci_clear_bit_word(conf + PCI_PREF_MEMORY_BASE,
 +   PCI_PREF_RANGE_MASK  0x);
 +pci_clear_bit_word(conf + PCI_PREF_MEMORY_LIMIT,
 +   PCI_PREF_RANGE_MASK  0x);
  pci_set_word(conf + PCI_PREF_BASE_UPPER32, 0);
  pci_set_word(conf + PCI_PREF_LIMIT_UPPER32, 0);
  
 -- 
 1.7.1.1



[Qemu-devel] Re: [PATCH v4 02/15] pci: introduce helper functions to clear/set bits in configuration space

2010-10-18 Thread Michael S. Tsirkin
On Mon, Oct 18, 2010 at 12:17:43PM +0900, Isaku Yamahata wrote:
 This patch introduces helper functions to clear/set bits in configuration
 space. pci_{clear_set, clear, set}_bit_{byte, word, long, quad}().
 They will be used later.
 
 Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp

I am not very happy with the names we came up with.
pci_clear_bit_byte - it sounds like this clears bit *and* byte.
Also, this gets a mask, not a bit number as the name implies.

How about
pci_word_set_mask
pci_word_clear_mask
Other ideas?

 ---
  hw/pci.h |   72 
 ++
  1 files changed, 72 insertions(+), 0 deletions(-)
 
 diff --git a/hw/pci.h b/hw/pci.h
 index d8b399f..eafa9f3 100644
 --- a/hw/pci.h
 +++ b/hw/pci.h
 @@ -323,6 +323,78 @@ pci_config_set_interrupt_pin(uint8_t *pci_config, 
 uint8_t val)
  pci_set_byte(pci_config[PCI_INTERRUPT_PIN], val);
  }
  
 +static inline void
 +pci_clear_set_bit_byte(uint8_t *config, uint8_t clear, uint8_t set)
 +{
 +pci_set_byte(config, (pci_get_byte(config)  ~clear) | set);
 +}
 +
 +static inline void
 +pci_clear_bit_byte(uint8_t *config, uint8_t clear)
 +{
 +pci_clear_set_bit_byte(config, clear, 0);
 +}
 +
 +static inline void
 +pci_set_bit_byte(uint8_t *config, uint8_t set)
 +{
 +pci_clear_set_bit_byte(config, 0, set);
 +}
 +
 +static inline void
 +pci_clear_set_bit_word(uint8_t *config, uint16_t clear, uint16_t set)
 +{
 +pci_set_word(config, (pci_get_word(config)  ~clear) | set);
 +}
 +
 +static inline void
 +pci_clear_bit_word(uint8_t *config, uint16_t clear)
 +{
 +pci_clear_set_bit_word(config, clear, 0);
 +}
 +
 +static inline void
 +pci_set_bit_word(uint8_t *config, uint16_t set)
 +{
 +pci_clear_set_bit_word(config, 0, set);
 +}
 +
 +static inline void
 +pci_clear_set_bit_long(uint8_t *config, uint32_t clear, uint32_t set)
 +{
 +pci_set_long(config, (pci_get_long(config)  ~clear) | set);
 +}
 +
 +static inline void
 +pci_clear_bit_long(uint8_t *config, uint32_t clear)
 +{
 +pci_clear_set_bit_long(config, clear, 0);
 +}
 +
 +static inline void
 +pci_set_bit_long(uint8_t *config, uint32_t set)
 +{
 +pci_clear_set_bit_long(config, 0, set);
 +}
 +
 +static inline void
 +pci_clear_set_bit_quad(uint8_t *config, uint64_t clear, uint64_t set)
 +{
 +pci_set_quad(config, (pci_get_quad(config)  ~clear) | set);
 +}
 +
 +static inline void
 +pci_clear_bit_quad(uint8_t *config, uint64_t clear)
 +{
 +pci_clear_set_bit_quad(config, clear, 0);
 +}
 +
 +static inline void
 +pci_set_bit_quad(uint8_t *config, uint64_t set)
 +{
 +pci_clear_set_bit_quad(config, 0, set);
 +}
 +
  typedef int (*pci_qdev_initfn)(PCIDevice *dev);
  typedef struct {
  DeviceInfo qdev;
 -- 
 1.7.1.1



[Qemu-devel] [Bug 586175] Re: Windows XP/2003 doesn't boot

2010-10-18 Thread Michael Tokarev
virtio disk is entrely different story, unrelated to this issue.

** Changed in: qemu
   Status: Incomplete = Fix Committed

-- 
Windows XP/2003 doesn't boot
https://bugs.launchpad.net/bugs/586175
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: Fix Committed
Status in “qemu-kvm” package in Ubuntu: Fix Released
Status in Debian GNU/Linux: Fix Released
Status in Fedora: Unknown

Bug description:
Hello everyone,

my qemu doesn't boot any Windows XP/2003 installations if I try to boot the 
image.
If I boot the install cd first, it's boot manager counts down and triggers the 
boot on it's own. That's kinda stupid.

I'm using libvirt, but even by a simple
 qemu-kvm -drive file=image.img,media=disk,if=ide,boot=on
it won't boot. Qemu hangs at the message Booting from Hard Disk...

I'm using qemu-kvm-0.12.4 with SeaBIOS 0.5.1 on Gentoo (No-Multilib and AMD64). 
It's a server, that means I'm using VNC as the primary graphic output but i 
don't think it should be an issue.





[Qemu-devel] Re: [PATCH v4 05/15] pci/bridge: fix pci_bridge_reset()

2010-10-18 Thread Isaku Yamahata
On Mon, Oct 18, 2010 at 08:22:24AM +0200, Michael S. Tsirkin wrote:
 On Mon, Oct 18, 2010 at 12:17:46PM +0900, Isaku Yamahata wrote:
  lower 4bits of base/limit register is RO, and
  should not be modified on reset.
  
  Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
  ---
   hw/pci_bridge.c |   15 +--
   1 files changed, 9 insertions(+), 6 deletions(-)
  
  diff --git a/hw/pci_bridge.c b/hw/pci_bridge.c
  index 638e3b3..7229610 100644
  --- a/hw/pci_bridge.c
  +++ b/hw/pci_bridge.c
  @@ -161,12 +161,15 @@ void pci_bridge_reset_reg(PCIDevice *dev)
   conf[PCI_SUBORDINATE_BUS] = 0;
   conf[PCI_SEC_LATENCY_TIMER] = 0;
   
  -conf[PCI_IO_BASE] = 0;
  -conf[PCI_IO_LIMIT] = 0;
  -pci_set_word(conf + PCI_MEMORY_BASE, 0);
  -pci_set_word(conf + PCI_MEMORY_LIMIT, 0);
  -pci_set_word(conf + PCI_PREF_MEMORY_BASE, 0);
  -pci_set_word(conf + PCI_PREF_MEMORY_LIMIT, 0);
  +pci_clear_bit_byte(conf + PCI_IO_BASE, PCI_IO_RANGE_MASK  0xff);
  +pci_clear_bit_byte(conf + PCI_IO_LIMIT, PCI_IO_RANGE_MASK  0xff);
 
 No need for  0xff and  0xf here and below.

gcc complains like this without them.
hw/pci_bridge.c:165: error: large integer implicitly truncated to unsigned type


 also, PCI spec also says that these registers' value
 is undefined after reset, so no need to clear them?
 If there's a reason, pls put it in comment.

The spec says the lower bits are read-only and they have its meaning.
Anyway I'll add the reference as comment.

For example.

 3.2.5.6 I/O Base Register and I/O Limit Register

 If the low four bits of the I/O Base and I/O Limit registers are 01h,
 then the bridge supports 32-bit I/O address decoding, and the I/O Base
 Upper 16 Bits and the I/O Limit Upper 16 Bits hold the upper 16 bits,
 corresponding to AD[31::16], of the 32-bit I/O Base and I/O Limit
 addresses respectively. In this case, system configuration software is
 permitted to locate the I/O address range supported by the bridge
 anywhere in the 4-GB I/O Space. Note that the 4-KB alignment and
 granularity restrictions still apply when the bridge supports 32-bit
 I/O addressing.
 table 3-7



 
 
  +pci_clear_bit_word(conf + PCI_MEMORY_BASE, PCI_MEMORY_RANGE_MASK  
  0x);
  +pci_clear_bit_word(conf + PCI_MEMORY_LIMIT,
  +   PCI_MEMORY_RANGE_MASK  0x);
  +pci_clear_bit_word(conf + PCI_PREF_MEMORY_BASE,
  +   PCI_PREF_RANGE_MASK  0x);
  +pci_clear_bit_word(conf + PCI_PREF_MEMORY_LIMIT,
  +   PCI_PREF_RANGE_MASK  0x);
   pci_set_word(conf + PCI_PREF_BASE_UPPER32, 0);
   pci_set_word(conf + PCI_PREF_LIMIT_UPPER32, 0);
   
  -- 
  1.7.1.1
 

-- 
yamahata



[Qemu-devel] Re: [PATCH v4 05/15] pci/bridge: fix pci_bridge_reset()

2010-10-18 Thread Michael S. Tsirkin
On Mon, Oct 18, 2010 at 04:10:17PM +0900, Isaku Yamahata wrote:
 On Mon, Oct 18, 2010 at 08:22:24AM +0200, Michael S. Tsirkin wrote:
  On Mon, Oct 18, 2010 at 12:17:46PM +0900, Isaku Yamahata wrote:
   lower 4bits of base/limit register is RO, and
   should not be modified on reset.
   
   Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
   ---
hw/pci_bridge.c |   15 +--
1 files changed, 9 insertions(+), 6 deletions(-)
   
   diff --git a/hw/pci_bridge.c b/hw/pci_bridge.c
   index 638e3b3..7229610 100644
   --- a/hw/pci_bridge.c
   +++ b/hw/pci_bridge.c
   @@ -161,12 +161,15 @@ void pci_bridge_reset_reg(PCIDevice *dev)
conf[PCI_SUBORDINATE_BUS] = 0;
conf[PCI_SEC_LATENCY_TIMER] = 0;

   -conf[PCI_IO_BASE] = 0;
   -conf[PCI_IO_LIMIT] = 0;
   -pci_set_word(conf + PCI_MEMORY_BASE, 0);
   -pci_set_word(conf + PCI_MEMORY_LIMIT, 0);
   -pci_set_word(conf + PCI_PREF_MEMORY_BASE, 0);
   -pci_set_word(conf + PCI_PREF_MEMORY_LIMIT, 0);
   +pci_clear_bit_byte(conf + PCI_IO_BASE, PCI_IO_RANGE_MASK  0xff);
   +pci_clear_bit_byte(conf + PCI_IO_LIMIT, PCI_IO_RANGE_MASK  0xff);
  
  No need for  0xff and  0xf here and below.
 
 gcc complains like this without them.
 hw/pci_bridge.c:165: error: large integer implicitly truncated to unsigned 
 type

I see.

 
  also, PCI spec also says that these registers' value
  is undefined after reset, so no need to clear them?
  If there's a reason, pls put it in comment.
 
 The spec says the lower bits are read-only and they have its meaning.

Yes. but my question is why even touch io base/io limit at all
in this function?
It looks like guest can not rely on these being 0 after reset.

 Anyway I'll add the reference as comment.
 
 For example.
 
  3.2.5.6 I/O Base Register and I/O Limit Register
 
  If the low four bits of the I/O Base and I/O Limit registers are 01h,
  then the bridge supports 32-bit I/O address decoding, and the I/O Base
  Upper 16 Bits and the I/O Limit Upper 16 Bits hold the upper 16 bits,
  corresponding to AD[31::16], of the 32-bit I/O Base and I/O Limit
  addresses respectively. In this case, system configuration software is
  permitted to locate the I/O address range supported by the bridge
  anywhere in the 4-GB I/O Space. Note that the 4-KB alignment and
  granularity restrictions still apply when the bridge supports 32-bit
  I/O addressing.
  table 3-7

I don't think this is required but up to you.

  
  
   +pci_clear_bit_word(conf + PCI_MEMORY_BASE, PCI_MEMORY_RANGE_MASK  
   0x);
   +pci_clear_bit_word(conf + PCI_MEMORY_LIMIT,
   +   PCI_MEMORY_RANGE_MASK  0x);
   +pci_clear_bit_word(conf + PCI_PREF_MEMORY_BASE,
   +   PCI_PREF_RANGE_MASK  0x);
   +pci_clear_bit_word(conf + PCI_PREF_MEMORY_LIMIT,
   +   PCI_PREF_RANGE_MASK  0x);
pci_set_word(conf + PCI_PREF_BASE_UPPER32, 0);
pci_set_word(conf + PCI_PREF_LIMIT_UPPER32, 0);

   -- 
   1.7.1.1
  
 
 -- 
 yamahata



[Qemu-devel] Re: [PATCH v4 04/15] pci: record which is written into pci configuration space

2010-10-18 Thread Isaku Yamahata
On Mon, Oct 18, 2010 at 07:38:53AM +0200, Michael S. Tsirkin wrote:
 On Mon, Oct 18, 2010 at 12:17:45PM +0900, Isaku Yamahata wrote:
  record which is written into pci configuration space.
  introduce helper function to zero PCIDevice::written.
  They will be used later.
  
  Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
 
 This really exposes an internal variable.
 I really dislike this, and I don't think it's needed
 at all: just make the bit writeable.
 Commented on appropriate patches.

I see. So You really want those bit writable.
Then how about introducing pci_{byte, word, long}_test_and_clear_mask()
helper functions?



 
  ---
   hw/pci.c |   10 ++
   hw/pci.h |5 +
   2 files changed, 15 insertions(+), 0 deletions(-)
  
  diff --git a/hw/pci.c b/hw/pci.c
  index 5954476..eca9324 100644
  --- a/hw/pci.c
  +++ b/hw/pci.c
  @@ -627,6 +627,7 @@ static void pci_config_alloc(PCIDevice *pci_dev)
   pci_dev-cmask = qemu_mallocz(config_size);
   pci_dev-wmask = qemu_mallocz(config_size);
   pci_dev-w1cmask = qemu_mallocz(config_size);
  +pci_dev-written = qemu_mallocz(config_size);
   pci_dev-used = qemu_mallocz(config_size);
   }
   
  @@ -636,6 +637,7 @@ static void pci_config_free(PCIDevice *pci_dev)
   qemu_free(pci_dev-cmask);
   qemu_free(pci_dev-wmask);
   qemu_free(pci_dev-w1cmask);
  +qemu_free(pci_dev-written);
   qemu_free(pci_dev-used);
   }
   
  @@ -1002,6 +1004,8 @@ void pci_default_write_config(PCIDevice *d, uint32_t 
  addr, uint32_t val, int l)
   assert(!(wmask  w1cmask));
   d-config[addr + i] = (d-config[addr + i]  ~wmask) | (val  
  wmask);
   d-config[addr + i] = ~(val  w1cmask); /* W1C: Write 1 to Clear 
  */
  +d-written[addr + i] = val; /* record what is written for driver
  +   specific code */
   }
   if (ranges_overlap(addr, l, PCI_BASE_ADDRESS_0, 24) ||
   ranges_overlap(addr, l, PCI_ROM_ADDRESS, 4) ||
  @@ -1013,6 +1017,12 @@ void pci_default_write_config(PCIDevice *d, uint32_t 
  addr, uint32_t val, int l)
   pci_update_irq_disabled(d, was_irq_disabled);
   }
   
  +void pci_clear_written_write_config(PCIDevice *d,
  +uint32_t addr, uint32_t val, int l)
  +{
  +memset(d-written + addr, 0, l);
  +}
  +
   /***/
   /* generic PCI irq support */
   
  diff --git a/hw/pci.h b/hw/pci.h
  index eafa9f3..7097817 100644
  --- a/hw/pci.h
  +++ b/hw/pci.h
  @@ -132,6 +132,9 @@ struct PCIDevice {
   /* Used to implement RW1C(Write 1 to Clear) bytes */
   uint8_t *w1cmask;
   
  +/* Used to record what value is written */
  +uint8_t *written;
  +
   /* Used to allocate config space for capabilities. */
   uint8_t *used;
   
  @@ -200,6 +203,8 @@ uint32_t pci_default_read_config(PCIDevice *d,
uint32_t address, int len);
   void pci_default_write_config(PCIDevice *d,
 uint32_t address, uint32_t val, int len);
  +void pci_clear_written_write_config(PCIDevice *d,
  +uint32_t addr, uint32_t val, int l);
   void pci_device_save(PCIDevice *s, QEMUFile *f);
   int pci_device_load(PCIDevice *s, QEMUFile *f);
   
  -- 
  1.7.1.1
 

-- 
yamahata



[Qemu-devel] Re: [PATCH 8/9] Consolidate oom_check() functions

2010-10-18 Thread Jes Sorensen
On 10/16/10 21:02, Blue Swirl wrote:
 On Sat, Oct 16, 2010 at 4:04 PM,  jes.soren...@redhat.com wrote:
 From: Jes Sorensen jes.soren...@redhat.com

 This consolidates the duplicated oom_check() functions, as well as
 splitting them into OS dependant versions to avoid the #ifdef
 grossness that was present in the old osdep.c version.
 
 This would break user emulators:
   LINK  i386-linux-user/qemu-i386
 qemu-malloc.o: In function `qemu_realloc':
 /src/qemu/qemu-malloc.c:60: undefined reference to `qemu_oom_check'
 qemu-malloc.o: In function `qemu_malloc':
 /src/qemu/qemu-malloc.c:49: undefined reference to `qemu_oom_check'
 qemu-malloc.o: In function `qemu_mallocz':
 /src/qemu/qemu-malloc.c:70: undefined reference to `qemu_oom_check'
 collect2: ld returned 1 exit status

I'll have a look.

Thanks,
Jes




[Qemu-devel] Re: [PATCH v4 05/15] pci/bridge: fix pci_bridge_reset()

2010-10-18 Thread Isaku Yamahata
On Mon, Oct 18, 2010 at 09:08:09AM +0200, Michael S. Tsirkin wrote:

  The spec says the lower bits are read-only and they have its meaning.
 
 Yes. but my question is why even touch io base/io limit at all
 in this function?
 It looks like guest can not rely on these being 0 after reset.

Oh, now I'm seeing your point.
Then, I'll drop those lines and don't touch those registers
on reset at all.
-- 
yamahata



[Qemu-devel] [Bug 181561] Re: Hardy alpha [2-6] daily-live i386 don't boot

2010-10-18 Thread Bug Watch Updater
** Changed in: linux (Gentoo Linux)
   Status: Fix Released = Won't Fix

-- 
Hardy alpha [2-6] daily-live i386 don't boot
https://bugs.launchpad.net/bugs/181561
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in The Linux Kernel: Fix Released
Status in QEMU: Invalid
Status in “linux” package in Ubuntu: Fix Released
Status in “linux” package in Gentoo Linux: Won't Fix

Bug description:
Binary package hint: casper

Since hardy alpha2 i386 daily-live, the system don't boot.

Look at screenshot attached. This PC have seen dapper/feisty/gutsy livre cd 
booting well.

What kind of informations can i provide ?





[Qemu-devel] [PATCH v3 0/9] Re-factor osdep code + macro and brace fixes

2010-10-18 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Hi,

Here is another set of patches which tries to split up osdep.c further
into posix and win32 versions. It introduces oslib-{posix,win32}.c
files which are used for functions that are OS specific core library
functionality, like gettimeofday(), and which is used by both QEMU and
support applications like qemu-img. Other functions are moved to
os-{posix,win32}.c. In addtion there are a couple of minor fixes for
bad macro names.

In some cases braces were added to code when it was moved, to make it
compliant with the QEMU bracing rules.

v3 fixes the issues pointed out by Blue Swirl, notably it moves the
win32 ffs prototype to qemu-common.h which is consistent with it being
provided by strings.h for POSIX, and fixes linking of linux-user.

Cheers,
Jes

Jes Sorensen (9):
  Move QEMU OS dependant library functions to OS specific files
  Move osdep socket code to oslib-{posix,win32}.c
  qemu_pipe() is used only by POSIX code, so move to oslib-posix.c
  We only support eventfd under POSIX, move qemu_eventfd() to
os-posix.c
  Move qemu_gettimeofday() to OS specific files
  Do not redefine reserved key-words TRUE/FALSE
  Separate qemu_pidfile() into OS specific versions
  Consolidate oom_check() functions
  Remove unncessary includes

 Makefile   |6 +-
 Makefile.objs  |9 ++-
 Makefile.target|2 +-
 hw/bt-sdp.c|   20 ++--
 os-posix.c |   53 +++
 os-win32.c |   24 +
 osdep.c|  256 
 osdep.h|   15 ---
 oslib-posix.c  |  109 ++
 oslib-win32.c  |  121 +
 posix-aio-compat.c |1 +
 qemu-common.h  |6 ++
 qemu-img.c |1 +
 qemu-malloc.c  |   14 +---
 qemu-os-posix.h|3 +
 qemu-os-win32.h|8 ++
 qemu-tool.c|1 +
 17 files changed, 352 insertions(+), 297 deletions(-)
 create mode 100644 oslib-posix.c
 create mode 100644 oslib-win32.c

-- 
1.7.2.3




[Qemu-devel] [PATCH 2/9] Move osdep socket code to oslib-{posix, win32}.c

2010-10-18 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 osdep.c   |   38 --
 oslib-posix.c |   15 +++
 oslib-win32.c |   21 +
 3 files changed, 36 insertions(+), 38 deletions(-)

diff --git a/osdep.c b/osdep.c
index 581768a..902fce9 100644
--- a/osdep.c
+++ b/osdep.c
@@ -147,44 +147,6 @@ int qemu_gettimeofday(qemu_timeval *tp)
 #endif /* _WIN32 */
 
 
-#ifdef _WIN32
-void socket_set_nonblock(int fd)
-{
-unsigned long opt = 1;
-ioctlsocket(fd, FIONBIO, opt);
-}
-
-int inet_aton(const char *cp, struct in_addr *ia)
-{
-uint32_t addr = inet_addr(cp);
-if (addr == 0x)
-   return 0;
-ia-s_addr = addr;
-return 1;
-}
-
-void qemu_set_cloexec(int fd)
-{
-}
-
-#else
-
-void socket_set_nonblock(int fd)
-{
-int f;
-f = fcntl(fd, F_GETFL);
-fcntl(fd, F_SETFL, f | O_NONBLOCK);
-}
-
-void qemu_set_cloexec(int fd)
-{
-int f;
-f = fcntl(fd, F_GETFD);
-fcntl(fd, F_SETFD, f | FD_CLOEXEC);
-}
-
-#endif
-
 /*
  * Opens a file with FD_CLOEXEC set
  */
diff --git a/oslib-posix.c b/oslib-posix.c
index df97304..aebe3ac 100644
--- a/oslib-posix.c
+++ b/oslib-posix.c
@@ -29,6 +29,7 @@
 #include config-host.h
 #include sysemu.h
 #include trace.h
+#include qemu_socket.h
 
 #if !defined(_POSIX_C_SOURCE) || defined(__sun__)
 static void *oom_check(void *ptr)
@@ -72,3 +73,17 @@ void qemu_vfree(void *ptr)
 trace_qemu_vfree(ptr);
 free(ptr);
 }
+
+void socket_set_nonblock(int fd)
+{
+int f;
+f = fcntl(fd, F_GETFL);
+fcntl(fd, F_SETFL, f | O_NONBLOCK);
+}
+
+void qemu_set_cloexec(int fd)
+{
+int f;
+f = fcntl(fd, F_GETFD);
+fcntl(fd, F_SETFD, f | FD_CLOEXEC);
+}
diff --git a/oslib-win32.c b/oslib-win32.c
index 3b5245d..1ddd857 100644
--- a/oslib-win32.c
+++ b/oslib-win32.c
@@ -29,6 +29,7 @@
 #include config-host.h
 #include sysemu.h
 #include trace.h
+#include qemu_socket.h
 
 static void *oom_check(void *ptr)
 {
@@ -71,3 +72,23 @@ void qemu_vfree(void *ptr)
 trace_qemu_vfree(ptr);
 VirtualFree(ptr, 0, MEM_RELEASE);
 }
+
+void socket_set_nonblock(int fd)
+{
+unsigned long opt = 1;
+ioctlsocket(fd, FIONBIO, opt);
+}
+
+int inet_aton(const char *cp, struct in_addr *ia)
+{
+uint32_t addr = inet_addr(cp);
+if (addr == 0x) {
+   return 0;
+}
+ia-s_addr = addr;
+return 1;
+}
+
+void qemu_set_cloexec(int fd)
+{
+}
-- 
1.7.2.3




[Qemu-devel] [PATCH 1/9] Move QEMU OS dependant library functions to OS specific files

2010-10-18 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

This moves library functions used by both QEMU and the QEMU tools,
such as qemu-img, qemu-nbd etc. from osdep.c to oslib-{posix,win32}.c

In addition it introduces oslib-obj.y to the Makefile set to be
included by the various targets, instead of relying on these library
functions magically getting included via block-obj-y.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 Makefile  |6 ++--
 Makefile.objs |9 +-
 osdep.c   |   85 -
 oslib-posix.c |   74 +
 oslib-win32.c |   73 +
 5 files changed, 158 insertions(+), 89 deletions(-)
 create mode 100644 oslib-posix.c
 create mode 100644 oslib-win32.c

diff --git a/Makefile b/Makefile
index 252c817..0b3751d 100644
--- a/Makefile
+++ b/Makefile
@@ -129,11 +129,11 @@ version-obj-$(CONFIG_WIN32) += version.o
 qemu-img.o: qemu-img-cmds.h
 qemu-img.o qemu-tool.o qemu-nbd.o qemu-io.o: $(GENERATED_HEADERS)
 
-qemu-img$(EXESUF): qemu-img.o qemu-tool.o qemu-error.o $(trace-obj-y) 
$(block-obj-y) $(qobject-obj-y) $(version-obj-y)
+qemu-img$(EXESUF): qemu-img.o qemu-tool.o qemu-error.o $(oslib-obj-y) 
$(trace-obj-y) $(block-obj-y) $(qobject-obj-y) $(version-obj-y)
 
-qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o qemu-error.o $(trace-obj-y) 
$(block-obj-y) $(qobject-obj-y) $(version-obj-y)
+qemu-nbd$(EXESUF): qemu-nbd.o qemu-tool.o qemu-error.o $(oslib-obj-y) 
$(trace-obj-y) $(block-obj-y) $(qobject-obj-y) $(version-obj-y)
 
-qemu-io$(EXESUF): qemu-io.o cmd.o qemu-tool.o qemu-error.o $(trace-obj-y) 
$(block-obj-y) $(qobject-obj-y) $(version-obj-y)
+qemu-io$(EXESUF): qemu-io.o cmd.o qemu-tool.o qemu-error.o $(oslib-obj-y) 
$(trace-obj-y) $(block-obj-y) $(qobject-obj-y) $(version-obj-y)
 
 qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx
$(call quiet-command,sh $(SRC_PATH)/hxtool -h  $  $@,  GEN   $@)
diff --git a/Makefile.objs b/Makefile.objs
index 816194a..ec1a09a 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -5,10 +5,16 @@ qobject-obj-y += qjson.o json-lexer.o json-streamer.o 
json-parser.o
 qobject-obj-y += qerror.o
 
 ###
+# oslib-obj-y is code depending on the OS (win32 vs posix)
+oslib-obj-y = osdep.o
+oslib-obj-$(CONFIG_WIN32) += oslib-win32.o
+oslib-obj-$(CONFIG_POSIX) += oslib-posix.o
+
+###
 # block-obj-y is code used by both qemu system emulation and qemu-img
 
 block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o
-block-obj-y += nbd.o block.o aio.o aes.o osdep.o qemu-config.o
+block-obj-y += nbd.o block.o aio.o aes.o qemu-config.o
 block-obj-$(CONFIG_POSIX) += posix-aio-compat.o
 block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 
@@ -50,6 +56,7 @@ common-obj-y += $(net-obj-y)
 common-obj-y += $(qobject-obj-y)
 common-obj-$(CONFIG_LINUX) += $(fsdev-obj-$(CONFIG_LINUX))
 common-obj-y += readline.o console.o cursor.o async.o qemu-error.o
+common-obj-y += $(oslib-obj-y)
 common-obj-$(CONFIG_WIN32) += os-win32.o
 common-obj-$(CONFIG_POSIX) += os-posix.o
 
diff --git a/osdep.c b/osdep.c
index 2e05b21..581768a 100644
--- a/osdep.c
+++ b/osdep.c
@@ -61,91 +61,6 @@ extern int madvise(caddr_t, size_t, int);
 #include sysemu.h
 #include qemu_socket.h
 
-#if !defined(_POSIX_C_SOURCE) || defined(_WIN32) || defined(__sun__)
-static void *oom_check(void *ptr)
-{
-if (ptr == NULL) {
-#if defined(_WIN32)
-fprintf(stderr, Failed to allocate memory: %lu\n, GetLastError());
-#else
-fprintf(stderr, Failed to allocate memory: %s\n, strerror(errno));
-#endif
-abort();
-}
-return ptr;
-}
-#endif
-
-#if defined(_WIN32)
-void *qemu_memalign(size_t alignment, size_t size)
-{
-void *ptr;
-
-if (!size) {
-abort();
-}
-ptr = oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE));
-trace_qemu_memalign(alignment, size, ptr);
-return ptr;
-}
-
-void *qemu_vmalloc(size_t size)
-{
-void *ptr;
-
-/* FIXME: this is not exactly optimal solution since VirtualAlloc
-   has 64Kb granularity, but at least it guarantees us that the
-   memory is page aligned. */
-if (!size) {
-abort();
-}
-ptr = oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE));
-trace_qemu_vmalloc(size, ptr);
-return ptr;
-}
-
-void qemu_vfree(void *ptr)
-{
-trace_qemu_vfree(ptr);
-VirtualFree(ptr, 0, MEM_RELEASE);
-}
-
-#else
-
-void *qemu_memalign(size_t alignment, size_t size)
-{
-void *ptr;
-#if defined(_POSIX_C_SOURCE)  !defined(__sun__)
-int ret;
-ret = posix_memalign(ptr, alignment, size);
-if (ret != 0) {
-fprintf(stderr, Failed to allocate %zu B: %s\n,
-size, strerror(ret));
-abort();
-}
-#elif defined(CONFIG_BSD)
-ptr = oom_check(valloc(size));
-#else
-

[Qemu-devel] [PATCH 3/9] qemu_pipe() is used only by POSIX code, so move to oslib-posix.c

2010-10-18 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 osdep.c   |   22 --
 oslib-posix.c |   22 ++
 2 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/osdep.c b/osdep.c
index 902fce9..926c8ad 100644
--- a/osdep.c
+++ b/osdep.c
@@ -235,28 +235,6 @@ int qemu_eventfd(int fds[2])
 
 return qemu_pipe(fds);
 }
-
-/*
- * Creates a pipe with FD_CLOEXEC set on both file descriptors
- */
-int qemu_pipe(int pipefd[2])
-{
-int ret;
-
-#ifdef CONFIG_PIPE2
-ret = pipe2(pipefd, O_CLOEXEC);
-if (ret != -1 || errno != ENOSYS) {
-return ret;
-}
-#endif
-ret = pipe(pipefd);
-if (ret == 0) {
-qemu_set_cloexec(pipefd[0]);
-qemu_set_cloexec(pipefd[1]);
-}
-
-return ret;
-}
 #endif
 
 /*
diff --git a/oslib-posix.c b/oslib-posix.c
index aebe3ac..ad44b17 100644
--- a/oslib-posix.c
+++ b/oslib-posix.c
@@ -87,3 +87,25 @@ void qemu_set_cloexec(int fd)
 f = fcntl(fd, F_GETFD);
 fcntl(fd, F_SETFD, f | FD_CLOEXEC);
 }
+
+/*
+ * Creates a pipe with FD_CLOEXEC set on both file descriptors
+ */
+int qemu_pipe(int pipefd[2])
+{
+int ret;
+
+#ifdef CONFIG_PIPE2
+ret = pipe2(pipefd, O_CLOEXEC);
+if (ret != -1 || errno != ENOSYS) {
+return ret;
+}
+#endif
+ret = pipe(pipefd);
+if (ret == 0) {
+qemu_set_cloexec(pipefd[0]);
+qemu_set_cloexec(pipefd[1]);
+}
+
+return ret;
+}
-- 
1.7.2.3




[Qemu-devel] Re: [PATCH 5/9] Move qemu_gettimeofday() to OS specific files

2010-10-18 Thread Jes Sorensen
On 10/16/10 21:32, Blue Swirl wrote:
 On Sat, Oct 16, 2010 at 4:04 PM,  jes.soren...@redhat.com wrote:
 From: Jes Sorensen jes.soren...@redhat.com

 In addition add sysemu.h includes to file requiring a prototype for
 ffs()
 
 There are probably a lot more files which would need that:
 /src/qemu/hw/sd.c: In function 'sd_normal_command':
 /src/qemu/hw/sd.c:738:13: error: implicit declaration of function
 'ffs' [-Werror=implicit-function-declaration]
 /src/qemu/hw/max7310.c: In function 'max7310_tx':
 /src/qemu/hw/max7310.c:94:13: error: implicit declaration of function
 'ffs' [-Werror=implicit-function-declaration]
 /src/qemu/hw/unin_pci.c: In function 'unin_get_config_reg':
 /src/qemu/hw/unin_pci.c:101:9: error: implicit declaration of function
 'ffs' [-Werror=implicit-function-declaration]
 
 Perhaps the prototype should be added someplace else.

I guess we'll have to bite the bullet. I don't really like it, but I
moved it to qemu-common.h to be consistent with the POSIX code. POSIX
relies on ffs() to be provided by strings.h which we include in
qemu-common.h

Should build (I hope) in the next patch. I tried building arm-softmmu
here but it wouldn't build for me at all due to other things so I
couldn't test it.

Cheers,
Jes




[Qemu-devel] [PATCH 9/9] Remove unncessary includes

2010-10-18 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

No need to include stdlib.h for BSD as it is included by
qemu-common.h, windows.h is handled by sysemu.h and osdep.c no longer
needs malloc.h

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 osdep.c |8 
 1 files changed, 0 insertions(+), 8 deletions(-)

diff --git a/osdep.c b/osdep.c
index 0d48561..327583b 100644
--- a/osdep.c
+++ b/osdep.c
@@ -44,14 +44,6 @@
 extern int madvise(caddr_t, size_t, int);
 #endif
 
-#ifdef _WIN32
-#include windows.h
-#elif defined(CONFIG_BSD)
-#include stdlib.h
-#else
-#include malloc.h
-#endif
-
 #include qemu-common.h
 #include trace.h
 #include sysemu.h
-- 
1.7.2.3




[Qemu-devel] [PATCH 6/9] Do not redefine reserved key-words TRUE/FALSE

2010-10-18 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

TRUE/FALSE are generally reserved keywords and shouldn't be defined in
a driver like this. Rename the macros to SDP_TRUE and SDP_FALSE
respectively.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 hw/bt-sdp.c |   20 ++--
 1 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/hw/bt-sdp.c b/hw/bt-sdp.c
index cc0bf2f..cdf2d95 100644
--- a/hw/bt-sdp.c
+++ b/hw/bt-sdp.c
@@ -786,11 +786,11 @@ static void sdp_service_db_build(struct 
bt_l2cap_sdp_state_s *sdp,
 .type   = SDP_DTYPE_UUID | SDP_DSIZE_16,   \
 .value.uint = val, \
 },
-#define TRUE   {   \
+#define SDP_TRUE   {   \
 .type   = SDP_DTYPE_BOOL | SDP_DSIZE_1,\
 .value.uint = 1,   \
 },
-#define FALSE  {   \
+#define SDP_FALSE  {   \
 .type   = SDP_DTYPE_BOOL | SDP_DSIZE_1,\
 .value.uint = 0,   \
 },
@@ -842,8 +842,8 @@ SERVICE(hid,
 /* TODO: extract from l2cap_device-device.class[0] */
 ATTRIBUTE(DEVICE_SUBCLASS, UINT8(0x40))
 ATTRIBUTE(COUNTRY_CODE,UINT8(0x15))
-ATTRIBUTE(VIRTUAL_CABLE,   TRUE)
-ATTRIBUTE(RECONNECT_INITIATE,  FALSE)
+ATTRIBUTE(VIRTUAL_CABLE,   SDP_TRUE)
+ATTRIBUTE(RECONNECT_INITIATE,  SDP_FALSE)
 /* TODO: extract from hid-usbdev-report_desc */
 ATTRIBUTE(DESCRIPTOR_LIST, LIST(
 LIST(UINT8(0x22) ARRAY(
@@ -883,12 +883,12 @@ SERVICE(hid,
 ATTRIBUTE(LANG_ID_BASE_LIST,   LIST(
 LIST(UINT16(0x0409) UINT16(0x0100))
 ))
-ATTRIBUTE(SDP_DISABLE, FALSE)
-ATTRIBUTE(BATTERY_POWER,   TRUE)
-ATTRIBUTE(REMOTE_WAKEUP,   TRUE)
-ATTRIBUTE(BOOT_DEVICE, TRUE)   /* XXX: untested */
+ATTRIBUTE(SDP_DISABLE, SDP_FALSE)
+ATTRIBUTE(BATTERY_POWER,   SDP_TRUE)
+ATTRIBUTE(REMOTE_WAKEUP,   SDP_TRUE)
+ATTRIBUTE(BOOT_DEVICE, SDP_TRUE)   /* XXX: untested */
 ATTRIBUTE(SUPERVISION_TIMEOUT, UINT16(0x0c80))
-ATTRIBUTE(NORMALLY_CONNECTABLE,TRUE)
+ATTRIBUTE(NORMALLY_CONNECTABLE,SDP_TRUE)
 ATTRIBUTE(PROFILE_VERSION, UINT16(0x0100))
 )
 
@@ -936,7 +936,7 @@ SERVICE(pnp,
 /* Profile specific */
 ATTRIBUTE(SPECIFICATION_ID, UINT16(0x0100))
 ATTRIBUTE(VERSION, UINT16(0x0100))
-ATTRIBUTE(PRIMARY_RECORD,  TRUE)
+ATTRIBUTE(PRIMARY_RECORD,  SDP_TRUE)
 )
 
 static int bt_l2cap_sdp_new_ch(struct bt_l2cap_device_s *dev,
-- 
1.7.2.3




[Qemu-devel] [PATCH 4/9] We only support eventfd under POSIX, move qemu_eventfd() to os-posix.c

2010-10-18 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-posix.c |   32 
 osdep.c|   34 --
 2 files changed, 32 insertions(+), 34 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 6321e99..612b641 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -43,6 +43,10 @@
 #include sys/prctl.h
 #endif
 
+#ifdef CONFIG_EVENTFD
+#include sys/eventfd.h
+#endif
+
 static struct passwd *user_pwd;
 static const char *chroot_dir;
 static int daemonize;
@@ -329,3 +333,31 @@ void os_set_line_buffering(void)
 {
 setvbuf(stdout, NULL, _IOLBF, 0);
 }
+
+/*
+ * Creates an eventfd that looks like a pipe and has EFD_CLOEXEC set.
+ */
+int qemu_eventfd(int fds[2])
+{
+#ifdef CONFIG_EVENTFD
+int ret;
+
+ret = eventfd(0, 0);
+if (ret = 0) {
+fds[0] = ret;
+qemu_set_cloexec(ret);
+if ((fds[1] = dup(ret)) == -1) {
+close(ret);
+return -1;
+}
+qemu_set_cloexec(fds[1]);
+return 0;
+}
+
+if (errno != ENOSYS) {
+return -1;
+}
+#endif
+
+return qemu_pipe(fds);
+}
diff --git a/osdep.c b/osdep.c
index 926c8ad..cb12e5f 100644
--- a/osdep.c
+++ b/osdep.c
@@ -44,10 +44,6 @@
 extern int madvise(caddr_t, size_t, int);
 #endif
 
-#ifdef CONFIG_EVENTFD
-#include sys/eventfd.h
-#endif
-
 #ifdef _WIN32
 #include windows.h
 #elif defined(CONFIG_BSD)
@@ -207,36 +203,6 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t 
count)
 return total;
 }
 
-#ifndef _WIN32
-/*
- * Creates an eventfd that looks like a pipe and has EFD_CLOEXEC set.
- */
-int qemu_eventfd(int fds[2])
-{
-#ifdef CONFIG_EVENTFD
-int ret;
-
-ret = eventfd(0, 0);
-if (ret = 0) {
-fds[0] = ret;
-qemu_set_cloexec(ret);
-if ((fds[1] = dup(ret)) == -1) {
-close(ret);
-return -1;
-}
-qemu_set_cloexec(fds[1]);
-return 0;
-}
-
-if (errno != ENOSYS) {
-return -1;
-}
-#endif
-
-return qemu_pipe(fds);
-}
-#endif
-
 /*
  * Opens a socket with FD_CLOEXEC set
  */
-- 
1.7.2.3




[Qemu-devel] Re: [PATCH 1/3] Make kvm64 the default cpu model when kvm_enabled()

2010-10-18 Thread Roedel, Joerg
(Sorry for the late reply)

On Thu, Oct 07, 2010 at 08:48:06AM -0400, Anthony Liguori wrote:
 On 10/07/2010 03:42 AM, Roedel, Joerg wrote:
  On Wed, Oct 06, 2010 at 03:24:59PM -0400, Anthony Liguori wrote:
 
  +qemu_compat_version = machine-compat_version;
  +
 if (display_type == DT_NOGRAPHIC) {
 if (default_parallel)
 add_device_config(DEV_PARALLEL, null);
  -- 
  1.7.0.4
 
   
  Looks fine to me, given CPUs are not in qdev. Anthony?
 
 
  The idea is fine, but why not just add the default CPU to the machine
  description?
   
  If I remember correctly the reason was that the machine description was
  not accessible in the cpuid initialization path because it is a function
  local variable.
 
 Not tested at all but I think the attached patch addresses it in a 
 pretty nice way.
 
 There's a couple ways you could support your patch on top of this.  You 
 could add a kvm_cpu_model to the machine structure that gets defaulted 
 too if kvm_enabled().  You could also introduce a new KVM machine type 
 that gets defaulted to if no explicit machine is specified.

I had something similar in mind but then I realized that we need at
least a cpu_model and a cpu_model_kvm to distinguish between the TCG and
the KVM case.
Further the QEMUMachine data structure is used for all architectures in
QEMU and the model-names only make sense for x86. So I decided for the
comapt-version way (which doesn't mean I object against this one ;-) )

Joerg

 From d2370c88cef4b07d48ba3c4804e35ae2db8db7c0 Mon Sep 17 00:00:00 2001
 From: Anthony Liguori aligu...@us.ibm.com
 Date: Thu, 7 Oct 2010 07:43:42 -0500
 Subject: [PATCH] machine: make default cpu model part of machine structure
 
 Signed-off-by: Anthony Liguori aligu...@us.ibm.com
 
 diff --git a/hw/boards.h b/hw/boards.h
 index 6f0f0d7..8c6ef27 100644
 --- a/hw/boards.h
 +++ b/hw/boards.h
 @@ -16,6 +16,7 @@ typedef struct QEMUMachine {
  const char *name;
  const char *alias;
  const char *desc;
 +const char *cpu_model;
  QEMUMachineInitFunc *init;
  int use_scsi;
  int max_cpus;
 diff --git a/hw/pc.c b/hw/pc.c
 index 69b13bf..0826107 100644
 --- a/hw/pc.c
 +++ b/hw/pc.c
 @@ -866,14 +866,6 @@ void pc_cpus_init(const char *cpu_model)
  int i;
  
  /* init CPUs */
 -if (cpu_model == NULL) {
 -#ifdef TARGET_X86_64
 -cpu_model = qemu64;
 -#else
 -cpu_model = qemu32;
 -#endif
 -}
 -
  for(i = 0; i  smp_cpus; i++) {
  pc_new_cpu(cpu_model);
  }
 diff --git a/hw/pc_piix.c b/hw/pc_piix.c
 index 12359a7..919b4d6 100644
 --- a/hw/pc_piix.c
 +++ b/hw/pc_piix.c
 @@ -204,17 +204,22 @@ static void pc_init_isa(ram_addr_t ram_size,
  const char *initrd_filename,
  const char *cpu_model)
  {
 -if (cpu_model == NULL)
 -cpu_model = 486;
  pc_init1(ram_size, boot_device,
   kernel_filename, kernel_cmdline,
   initrd_filename, cpu_model, 0);
  }
  
 +#ifdef TARGET_X86_64
 +#define DEF_CPU_MODEL qemu64
 +#else
 +#define DEF_CPU_MODEL qemu32
 +#endif
 +
  static QEMUMachine pc_machine = {
  .name = pc-0.13,
  .alias = pc,
  .desc = Standard PC,
 +.cpu_model = DEF_CPU_MODEL,
  .init = pc_init_pci,
  .max_cpus = 255,
  .is_default = 1,
 @@ -223,6 +228,7 @@ static QEMUMachine pc_machine = {
  static QEMUMachine pc_machine_v0_12 = {
  .name = pc-0.12,
  .desc = Standard PC,
 +.cpu_model = DEF_CPU_MODEL,
  .init = pc_init_pci,
  .max_cpus = 255,
  .compat_props = (GlobalProperty[]) {
 @@ -242,6 +248,7 @@ static QEMUMachine pc_machine_v0_12 = {
  static QEMUMachine pc_machine_v0_11 = {
  .name = pc-0.11,
  .desc = Standard PC, qemu 0.11,
 +.cpu_model = DEF_CPU_MODEL,
  .init = pc_init_pci,
  .max_cpus = 255,
  .compat_props = (GlobalProperty[]) {
 @@ -277,6 +284,7 @@ static QEMUMachine pc_machine_v0_11 = {
  static QEMUMachine pc_machine_v0_10 = {
  .name = pc-0.10,
  .desc = Standard PC, qemu 0.10,
 +.cpu_model = DEF_CPU_MODEL,
  .init = pc_init_pci,
  .max_cpus = 255,
  .compat_props = (GlobalProperty[]) {
 @@ -324,6 +332,7 @@ static QEMUMachine pc_machine_v0_10 = {
  static QEMUMachine isapc_machine = {
  .name = isapc,
  .desc = ISA-only PC,
 +.cpu_model = 486,
  .init = pc_init_isa,
  .max_cpus = 1,
  };
 diff --git a/vl.c b/vl.c
 index df414ef..3a55cc8 100644
 --- a/vl.c
 +++ b/vl.c
 @@ -2904,6 +2904,10 @@ int main(int argc, char **argv, char **envp)
  }
  qemu_add_globals();
  
 +if (cpu_model == NULL) {
 +cpu_model = machine-cpu_model;
 +}
 +
  machine-init(ram_size, boot_devices,
kernel_filename, kernel_cmdline, initrd_filename, 
 cpu_model);
  
 -- 
 1.7.0.4
 


-- 
AMD Operating System Research Center

Advanced Micro Devices GmbH Einsteinring 24 85609 Dornach
General Managers: Alberto Bozzo, Andrew 

[Qemu-devel] [PATCH 7/9] Separate qemu_pidfile() into OS specific versions

2010-10-18 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 os-posix.c |   21 +
 os-win32.c |   24 
 osdep.c|   38 --
 3 files changed, 45 insertions(+), 38 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 612b641..38c29d1 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -361,3 +361,24 @@ int qemu_eventfd(int fds[2])
 
 return qemu_pipe(fds);
 }
+
+int qemu_create_pidfile(const char *filename)
+{
+char buffer[128];
+int len;
+int fd;
+
+fd = qemu_open(filename, O_RDWR | O_CREAT, 0600);
+if (fd == -1) {
+return -1;
+}
+if (lockf(fd, F_TLOCK, 0) == -1) {
+return -1;
+}
+len = snprintf(buffer, sizeof(buffer), %ld\n, (long)getpid());
+if (write(fd, buffer, len) != len) {
+return -1;
+}
+
+return 0;
+}
diff --git a/os-win32.c b/os-win32.c
index 3c6f50f..566d5e9 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -240,3 +240,27 @@ void os_pidfile_error(void)
 {
 fprintf(stderr, Could not acquire pid file: %s\n, strerror(errno));
 }
+
+int qemu_create_pidfile(const char *filename)
+{
+char buffer[128];
+int len;
+HANDLE file;
+OVERLAPPED overlap;
+BOOL ret;
+memset(overlap, 0, sizeof(overlap));
+
+file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL,
+ OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+
+if (file == INVALID_HANDLE_VALUE) {
+return -1;
+}
+len = snprintf(buffer, sizeof(buffer), %ld\n, (long)getpid());
+ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len,
+ overlap, NULL);
+if (ret == 0) {
+return -1;
+}
+return 0;
+}
diff --git a/osdep.c b/osdep.c
index b1664ac..0d48561 100644
--- a/osdep.c
+++ b/osdep.c
@@ -73,44 +73,6 @@ int qemu_madvise(void *addr, size_t len, int advice)
 #endif
 }
 
-int qemu_create_pidfile(const char *filename)
-{
-char buffer[128];
-int len;
-#ifndef _WIN32
-int fd;
-
-fd = qemu_open(filename, O_RDWR | O_CREAT, 0600);
-if (fd == -1)
-return -1;
-
-if (lockf(fd, F_TLOCK, 0) == -1)
-return -1;
-
-len = snprintf(buffer, sizeof(buffer), %ld\n, (long)getpid());
-if (write(fd, buffer, len) != len)
-return -1;
-#else
-HANDLE file;
-OVERLAPPED overlap;
-BOOL ret;
-memset(overlap, 0, sizeof(overlap));
-
-file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL,
- OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
-
-if (file == INVALID_HANDLE_VALUE)
-  return -1;
-
-len = snprintf(buffer, sizeof(buffer), %ld\n, (long)getpid());
-ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len,
- overlap, NULL);
-if (ret == 0)
-  return -1;
-#endif
-return 0;
-}
-
 
 /*
  * Opens a file with FD_CLOEXEC set
-- 
1.7.2.3




[Qemu-devel] [PATCH 5/9] Move qemu_gettimeofday() to OS specific files

2010-10-18 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 osdep.c|   31 ---
 osdep.h|   15 ---
 oslib-win32.c  |   27 +++
 posix-aio-compat.c |1 +
 qemu-common.h  |5 +
 qemu-img.c |1 +
 qemu-os-posix.h|3 +++
 qemu-os-win32.h|8 
 qemu-tool.c|1 +
 9 files changed, 46 insertions(+), 46 deletions(-)

diff --git a/osdep.c b/osdep.c
index cb12e5f..b1664ac 100644
--- a/osdep.c
+++ b/osdep.c
@@ -111,37 +111,6 @@ int qemu_create_pidfile(const char *filename)
 return 0;
 }
 
-#ifdef _WIN32
-
-/* mingw32 needs ffs for compilations without optimization. */
-int ffs(int i)
-{
-/* Use gcc's builtin ffs. */
-return __builtin_ffs(i);
-}
-
-/* Offset between 1/1/1601 and 1/1/1970 in 100 nanosec units */
-#define _W32_FT_OFFSET (1164447360ULL)
-
-int qemu_gettimeofday(qemu_timeval *tp)
-{
-  union {
-unsigned long long ns100; /*time since 1 Jan 1601 in 100ns units */
-FILETIME ft;
-  }  _now;
-
-  if(tp)
-{
-  GetSystemTimeAsFileTime (_now.ft);
-  tp-tv_usec=(long)((_now.ns100 / 10ULL) % 100ULL );
-  tp-tv_sec= (long)((_now.ns100 - _W32_FT_OFFSET) / 1000ULL);
-}
-  /* Always return 0 as per Open Group Base Specifications Issue 6.
- Do not set errno on error.  */
-  return 0;
-}
-#endif /* _WIN32 */
-
 
 /*
  * Opens a file with FD_CLOEXEC set
diff --git a/osdep.h b/osdep.h
index 6716281..8bd30d7 100644
--- a/osdep.h
+++ b/osdep.h
@@ -127,19 +127,4 @@ int qemu_madvise(void *addr, size_t len, int advice);
 
 int qemu_create_pidfile(const char *filename);
 
-#ifdef _WIN32
-int ffs(int i);
-
-int setenv(const char *name, const char *value, int overwrite);
-
-typedef struct {
-long tv_sec;
-long tv_usec;
-} qemu_timeval;
-int qemu_gettimeofday(qemu_timeval *tp);
-#else
-typedef struct timeval qemu_timeval;
-#define qemu_gettimeofday(tp) gettimeofday(tp, NULL);
-#endif /* !_WIN32 */
-
 #endif
diff --git a/oslib-win32.c b/oslib-win32.c
index 1ddd857..e03c472 100644
--- a/oslib-win32.c
+++ b/oslib-win32.c
@@ -92,3 +92,30 @@ int inet_aton(const char *cp, struct in_addr *ia)
 void qemu_set_cloexec(int fd)
 {
 }
+
+/* mingw32 needs ffs for compilations without optimization. */
+int ffs(int i)
+{
+/* Use gcc's builtin ffs. */
+return __builtin_ffs(i);
+}
+
+/* Offset between 1/1/1601 and 1/1/1970 in 100 nanosec units */
+#define _W32_FT_OFFSET (1164447360ULL)
+
+int qemu_gettimeofday(qemu_timeval *tp)
+{
+  union {
+unsigned long long ns100; /*time since 1 Jan 1601 in 100ns units */
+FILETIME ft;
+  }  _now;
+
+  if(tp) {
+  GetSystemTimeAsFileTime (_now.ft);
+  tp-tv_usec=(long)((_now.ns100 / 10ULL) % 100ULL );
+  tp-tv_sec= (long)((_now.ns100 - _W32_FT_OFFSET) / 1000ULL);
+  }
+  /* Always return 0 as per Open Group Base Specifications Issue 6.
+ Do not set errno on error.  */
+  return 0;
+}
diff --git a/posix-aio-compat.c b/posix-aio-compat.c
index 7b862b5..fa5494d 100644
--- a/posix-aio-compat.c
+++ b/posix-aio-compat.c
@@ -24,6 +24,7 @@
 
 #include qemu-queue.h
 #include osdep.h
+#include sysemu.h
 #include qemu-common.h
 #include trace.h
 #include block_int.h
diff --git a/qemu-common.h b/qemu-common.h
index 81aafa0..1f01a44 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -174,6 +174,11 @@ const char *path(const char *pathname);
 #define qemu_isascii(c)isascii((unsigned char)(c))
 #define qemu_toascii(c)toascii((unsigned char)(c))
 
+#ifdef _WIN32
+/* ffs() in oslib-win32.c for WIN32, strings.h for the rest of the world */
+int ffs(int i);
+#endif
+
 void *qemu_malloc(size_t size);
 void *qemu_realloc(void *ptr, size_t size);
 void *qemu_mallocz(size_t size);
diff --git a/qemu-img.c b/qemu-img.c
index 578b8eb..5b2bed3 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -24,6 +24,7 @@
 #include qemu-common.h
 #include qemu-option.h
 #include osdep.h
+#include sysemu.h
 #include block_int.h
 #include stdio.h
 
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index ed5c058..353f878 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -36,4 +36,7 @@ void os_setup_signal_handling(void);
 void os_daemonize(void);
 void os_setup_post(void);
 
+typedef struct timeval qemu_timeval;
+#define qemu_gettimeofday(tp) gettimeofday(tp, NULL)
+
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index c63778d..1a07e5e 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -52,4 +52,12 @@ static inline void os_set_proc_name(const char *dummy) {}
 # define EPROTONOSUPPORT EINVAL
 #endif
 
+int setenv(const char *name, const char *value, int overwrite);
+
+typedef struct {
+long tv_sec;
+long tv_usec;
+} qemu_timeval;
+int qemu_gettimeofday(qemu_timeval *tp);
+
 #endif
diff --git a/qemu-tool.c b/qemu-tool.c
index b39af86..2f3db30 100644
--- a/qemu-tool.c
+++ b/qemu-tool.c
@@ -15,6 +15,7 @@
 #include 

[Qemu-devel] [PATCH 8/9] Consolidate oom_check() functions

2010-10-18 Thread Jes . Sorensen
From: Jes Sorensen jes.soren...@redhat.com

This consolidates the duplicated oom_check() functions, as well as
splitting them into OS dependant versions to avoid the #ifdef
grossness that was present in the old osdep.c version.

Signed-off-by: Jes Sorensen jes.soren...@redhat.com
---
 Makefile.target |2 +-
 oslib-posix.c   |8 +++-
 oslib-win32.c   |6 +++---
 qemu-common.h   |1 +
 qemu-malloc.c   |   14 +++---
 5 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/Makefile.target b/Makefile.target
index c48cbcc..91e6e74 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -88,7 +88,7 @@ $(call set-vpath, 
$(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR
 QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user 
-I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR)
 obj-y = main.o syscall.o strace.o mmap.o signal.o thunk.o \
   elfload.o linuxload.o uaccess.o gdbstub.o cpu-uname.o \
-  qemu-malloc.o
+  qemu-malloc.o $(oslib-obj-y)
 
 obj-$(TARGET_HAS_BFLT) += flatload.o
 
diff --git a/oslib-posix.c b/oslib-posix.c
index ad44b17..6e9b0c3 100644
--- a/oslib-posix.c
+++ b/oslib-posix.c
@@ -31,8 +31,7 @@
 #include trace.h
 #include qemu_socket.h
 
-#if !defined(_POSIX_C_SOURCE) || defined(__sun__)
-static void *oom_check(void *ptr)
+void *qemu_oom_check(void *ptr)
 {
 if (ptr == NULL) {
 fprintf(stderr, Failed to allocate memory: %s\n, strerror(errno));
@@ -40,7 +39,6 @@ static void *oom_check(void *ptr)
 }
 return ptr;
 }
-#endif
 
 void *qemu_memalign(size_t alignment, size_t size)
 {
@@ -54,9 +52,9 @@ void *qemu_memalign(size_t alignment, size_t size)
 abort();
 }
 #elif defined(CONFIG_BSD)
-ptr = oom_check(valloc(size));
+ptr = qemu_oom_check(valloc(size));
 #else
-ptr = oom_check(memalign(alignment, size));
+ptr = qemu_oom_check(memalign(alignment, size));
 #endif
 trace_qemu_memalign(alignment, size, ptr);
 return ptr;
diff --git a/oslib-win32.c b/oslib-win32.c
index e03c472..ab29eae 100644
--- a/oslib-win32.c
+++ b/oslib-win32.c
@@ -31,7 +31,7 @@
 #include trace.h
 #include qemu_socket.h
 
-static void *oom_check(void *ptr)
+void *qemu_oom_check(void *ptr)
 {
 if (ptr == NULL) {
 fprintf(stderr, Failed to allocate memory: %lu\n, GetLastError());
@@ -47,7 +47,7 @@ void *qemu_memalign(size_t alignment, size_t size)
 if (!size) {
 abort();
 }
-ptr = oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE));
+ptr = qemu_oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE));
 trace_qemu_memalign(alignment, size, ptr);
 return ptr;
 }
@@ -62,7 +62,7 @@ void *qemu_vmalloc(size_t size)
 if (!size) {
 abort();
 }
-ptr = oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE));
+ptr = qemu_oom_check(VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE));
 trace_qemu_vmalloc(size, ptr);
 return ptr;
 }
diff --git a/qemu-common.h b/qemu-common.h
index 1f01a44..82fb59f 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -179,6 +179,7 @@ const char *path(const char *pathname);
 int ffs(int i);
 #endif
 
+void *qemu_oom_check(void *ptr);
 void *qemu_malloc(size_t size);
 void *qemu_realloc(void *ptr, size_t size);
 void *qemu_mallocz(size_t size);
diff --git a/qemu-malloc.c b/qemu-malloc.c
index ecffb67..28fb05a 100644
--- a/qemu-malloc.c
+++ b/qemu-malloc.c
@@ -25,14 +25,6 @@
 #include trace.h
 #include stdlib.h
 
-static void *oom_check(void *ptr)
-{
-if (ptr == NULL) {
-abort();
-}
-return ptr;
-}
-
 void qemu_free(void *ptr)
 {
 trace_qemu_free(ptr);
@@ -54,7 +46,7 @@ void *qemu_malloc(size_t size)
 if (!size  !allow_zero_malloc()) {
 abort();
 }
-ptr = oom_check(malloc(size ? size : 1));
+ptr = qemu_oom_check(malloc(size ? size : 1));
 trace_qemu_malloc(size, ptr);
 return ptr;
 }
@@ -65,7 +57,7 @@ void *qemu_realloc(void *ptr, size_t size)
 if (!size  !allow_zero_malloc()) {
 abort();
 }
-newptr = oom_check(realloc(ptr, size ? size : 1));
+newptr = qemu_oom_check(realloc(ptr, size ? size : 1));
 trace_qemu_realloc(ptr, size, newptr);
 return newptr;
 }
@@ -75,7 +67,7 @@ void *qemu_mallocz(size_t size)
 if (!size  !allow_zero_malloc()) {
 abort();
 }
-return oom_check(calloc(1, size ? size : 1));
+return qemu_oom_check(calloc(1, size ? size : 1));
 }
 
 char *qemu_strdup(const char *str)
-- 
1.7.2.3




[Qemu-devel] Re: [PATCH v3 0/9] Re-factor osdep code + macro and brace fixes

2010-10-18 Thread Paolo Bonzini

On 10/18/2010 10:15 AM, jes.soren...@redhat.com wrote:

From: Jes Sorensenjes.soren...@redhat.com

Hi,

Here is another set of patches which tries to split up osdep.c further
into posix and win32 versions. It introduces oslib-{posix,win32}.c
files which are used for functions that are OS specific core library
functionality, like gettimeofday(), and which is used by both QEMU and
support applications like qemu-img. Other functions are moved to
os-{posix,win32}.c. In addtion there are a couple of minor fixes for
bad macro names.

In some cases braces were added to code when it was moved, to make it
compliant with the QEMU bracing rules.

v3 fixes the issues pointed out by Blue Swirl, notably it moves the
win32 ffs prototype to qemu-common.h which is consistent with it being
provided by strings.h for POSIX, and fixes linking of linux-user.

Cheers,
Jes

Jes Sorensen (9):
   Move QEMU OS dependant library functions to OS specific files
   Move osdep socket code to oslib-{posix,win32}.c
   qemu_pipe() is used only by POSIX code, so move to oslib-posix.c
   We only support eventfd under POSIX, move qemu_eventfd() to
 os-posix.c
   Move qemu_gettimeofday() to OS specific files
   Do not redefine reserved key-words TRUE/FALSE
   Separate qemu_pidfile() into OS specific versions
   Consolidate oom_check() functions
   Remove unncessary includes

  Makefile   |6 +-
  Makefile.objs  |9 ++-
  Makefile.target|2 +-
  hw/bt-sdp.c|   20 ++--
  os-posix.c |   53 +++
  os-win32.c |   24 +
  osdep.c|  256 
  osdep.h|   15 ---
  oslib-posix.c  |  109 ++
  oslib-win32.c  |  121 +
  posix-aio-compat.c |1 +
  qemu-common.h  |6 ++
  qemu-img.c |1 +
  qemu-malloc.c  |   14 +---
  qemu-os-posix.h|3 +
  qemu-os-win32.h|8 ++
  qemu-tool.c|1 +
  17 files changed, 352 insertions(+), 297 deletions(-)
  create mode 100644 oslib-posix.c
  create mode 100644 oslib-win32.c



ACK

Paolo



[Qemu-devel] [PATCH 0/2] pciinit: fix overflow when bar allocation

2010-10-18 Thread Isaku Yamahata
This patch set fixes PCI bar allocation when bar overflow occured.
I checked if pmm_alloc facility can be used, but it doesn't suit for
pci bar allocation. So I resulted in new API, pci_region which
encapsulates region allocation and overflow checks.
The first patch introduces pci_region, and the second patch fixes
the overflow case with pci_region.

Isaku Yamahata (2):
  pci: introduce pci_region to manage pci io/memory/prefmemory regions.
  pciinit: use pci_region functions.

 Makefile |3 +-
 src/pci_region.c |   70 +++
 src/pciinit.c|  122 ++---
 src/util.h   |   15 +++
 4 files changed, 147 insertions(+), 63 deletions(-)
 create mode 100644 src/pci_region.c




[Qemu-devel] [PATCH 1/2] pci: introduce pci_region to manage pci io/memory/prefmemory regions.

2010-10-18 Thread Isaku Yamahata
This patch adds helper functions to manage pci area.

Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 Makefile |3 +-
 src/pci_region.c |   70 ++
 src/util.h   |   15 +++
 3 files changed, 87 insertions(+), 1 deletions(-)
 create mode 100644 src/pci_region.c

diff --git a/Makefile b/Makefile
index 9d412f1..1663a5d 100644
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,8 @@ SRCBOTH=misc.c pmm.c stacks.c output.c util.c block.c 
floppy.c ata.c mouse.c \
 SRC16=$(SRCBOTH) system.c disk.c font.c
 SRC32FLAT=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \
   acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \
-  lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c dev-i440fx.c
+  lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c dev-i440fx.c \
+  pci_region.c
 SRC32SEG=util.c output.c pci.c pcibios.c apm.c stacks.c
 
 cc-option = $(shell if test -z `$(1) $(2) -S -o /dev/null -xc \
diff --git a/src/pci_region.c b/src/pci_region.c
new file mode 100644
index 000..a4e71d9
--- /dev/null
+++ b/src/pci_region.c
@@ -0,0 +1,70 @@
+// helper functions to manage pci io/memory/prefetch memory region
+//
+// Copyright (C) 2009 Isaku Yamahata yamahata at valinux co jp
+//
+// This file may be distributed under the terms of the GNU LGPLv3 license.
+//
+//
+
+#include util.h
+
+#define PCI_REGION_DISABLED (-1)
+
+void pci_region_init(struct pci_region *r, u32 start, u32 end)
+{
+r-start = start;
+r-end = end;
+
+r-cur_end = start;
+}
+
+static u32 pci_region_alloc_align(struct pci_region *r, u32 size, u32 align)
+{
+if (r-cur_end == PCI_REGION_DISABLED) {
+return 0;
+}
+
+u32 s = ALIGN(r-cur_end, align);
+if (s  r-end || s  r-cur_end) {
+return 0;
+}
+u32 e = s + size;
+if (e  r-end || e  s) {
+return 0;
+}
+r-cur_end = e;
+return s;
+}
+
+u32 pci_region_alloc(struct pci_region *r, u32 size)
+{
+return pci_region_alloc_align(r, size, size);
+}
+
+u32 pci_region_align(struct pci_region *r, u32 align)
+{
+return pci_region_alloc_align(r, 0, align);
+}
+
+void pci_region_revert(struct pci_region *r, u32 addr)
+{
+r-cur_end = addr;
+}
+
+u32 pci_region_disable(struct pci_region *r)
+{
+return r-cur_end = PCI_REGION_DISABLED;
+}
+
+u32 pci_region_addr(const struct pci_region *r)
+{
+if (r-cur_end == PCI_REGION_DISABLED){
+return r-end;
+}
+return r-cur_end;
+}
+
+u32 pci_region_size(const struct pci_region *r)
+{
+return r-end - r-start;
+}
diff --git a/src/util.h b/src/util.h
index 5cc9f17..ecd1c16 100644
--- a/src/util.h
+++ b/src/util.h
@@ -344,6 +344,21 @@ void qemu_prep_reset(void);
 void smm_save_and_copy(void);
 void smm_relocate_and_restore(void);
 
+// pci_region.c
+struct pci_region {
+u32 start;
+u32 end;
+
+u32 cur_end;
+};
+void pci_region_init(struct pci_region *r, u32 start, u32 end);
+u32 pci_region_alloc(struct pci_region *r, u32 size);
+u32 pci_region_align(struct pci_region *r, u32 align);
+void pci_region_revert(struct pci_region *r, u32 addr);
+u32 pci_region_disable(struct pci_region *r);
+u32 pci_region_addr(const struct pci_region *r);
+u32 pci_region_size(const struct pci_region *r);
+
 // pciinit.c
 extern const u8 pci_irqs[4];
 void pci_bios_allocate_regions(u16 bdf, void *arg);
-- 
1.7.1.1




[Qemu-devel] [PATCH 2/2] pciinit: use pci_region functions.

2010-10-18 Thread Isaku Yamahata
This patch cleans up pci region allocation with pci_region.
Now it is aware of overflow.

Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
---
 src/pciinit.c |  122 -
 1 files changed, 60 insertions(+), 62 deletions(-)

diff --git a/src/pciinit.c b/src/pciinit.c
index 0346423..2a01aaa 100644
--- a/src/pciinit.c
+++ b/src/pciinit.c
@@ -17,9 +17,10 @@
 
 static void pci_bios_init_device_in_bus(int bus);
 
-static u32 pci_bios_io_addr;
-static u32 pci_bios_mem_addr;
-static u32 pci_bios_prefmem_addr;
+static struct pci_region pci_bios_io_region;
+static struct pci_region pci_bios_mem_region;
+static struct pci_region pci_bios_prefmem_region;
+
 /* host irqs corresponding to PCI irqs A-D */
 const u8 pci_irqs[4] = {
 10, 10, 11, 11
@@ -54,7 +55,7 @@ static void pci_set_io_region_addr(u16 bdf, int region_num, 
u32 addr)
  */
 static int pci_bios_allocate_region(u16 bdf, int region_num)
 {
-u32 *paddr;
+struct pci_region *r;
 u32 ofs = pci_bar(bdf, region_num);
 
 u32 old = pci_config_readl(bdf, ofs);
@@ -74,41 +75,34 @@ static int pci_bios_allocate_region(u16 bdf, int region_num)
 
 u32 size = (~(val  mask)) + 1;
 if (val != 0) {
+const char *type;
+const char *msg;
 if (val  PCI_BASE_ADDRESS_SPACE_IO) {
-paddr = pci_bios_io_addr;
-if (ALIGN(*paddr, size) + size = 64 * 1024) {
-dprintf(1,
-io region of (bdf 0x%x bar %d) can't be mapped.\n,
-bdf, region_num);
-size = 0;
-}
+r = pci_bios_io_region;
+type = io;
+msg = ;
 } else if ((val  PCI_BASE_ADDRESS_MEM_PREFETCH) 
- /* keep behaviour on bus = 0 */
- pci_bdf_to_bus(bdf) != 0 
- /* If pci_bios_prefmem_addr == 0, keep old behaviour */
- pci_bios_prefmem_addr != 0) {
-paddr = pci_bios_prefmem_addr;
-if (ALIGN(*paddr, size) + size = BUILD_PCIPREFMEM_END) {
-dprintf(1,
-prefmem region of (bdf 0x%x bar %d) can't be mapped. 
-decrease BUILD_PCIMEM_SIZE and recompile. size %x\n,
-bdf, region_num, BUILD_PCIPREFMEM_SIZE);
-size = 0;
-}
+   /* keep behaviour on bus = 0 */
+   pci_bdf_to_bus(bdf) != 0 
+   /* If pci_bios_prefmem_addr == 0, keep old behaviour */
+   pci_region_addr(pci_bios_prefmem_region) != 0) {
+r = pci_bios_prefmem_region;
+type = prefmem;
+msg = decrease BUILD_PCIMEM_SIZE and recompile. size %x;
 } else {
-paddr = pci_bios_mem_addr;
-if (ALIGN(*paddr, size) + size = BUILD_PCIMEM_END) {
-dprintf(1,
-mem region of (bdf 0x%x bar %d) can't be mapped. 
-increase BUILD_PCIMEM_SIZE and recompile. size %x\n,
-bdf, region_num, BUILD_PCIMEM_SIZE);
-size = 0;
-}
+r = pci_bios_mem_region;
+type = mem;
+msg = increase BUILD_PCIMEM_SIZE and recompile.;
 }
-if (size  0) {
-*paddr = ALIGN(*paddr, size);
-pci_set_io_region_addr(bdf, region_num, *paddr);
-*paddr += size;
+u32 addr = pci_region_alloc(r, size);
+if (addr  0) {
+pci_set_io_region_addr(bdf, region_num, addr);
+} else {
+size = 0;
+dprintf(1,
+%s region of (bdf 0x%x bar %d) can't be mapped. 
+%s size %x\n,
+type, bdf, region_num, msg, pci_region_size(r));
 }
 }
 
@@ -163,33 +157,34 @@ static void pci_bios_init_device_bridge(u16 bdf, void 
*arg)
 pci_bios_allocate_region(bdf, 1);
 pci_bios_allocate_region(bdf, PCI_ROM_SLOT);
 
-u32 io_old = pci_bios_io_addr;
-u32 mem_old = pci_bios_mem_addr;
-u32 prefmem_old = pci_bios_prefmem_addr;
+u32 io_old = pci_region_addr(pci_bios_io_region);
+u32 mem_old = pci_region_addr(pci_bios_mem_region);
+u32 prefmem_old = pci_region_addr(pci_bios_prefmem_region);
 
 /* IO BASE is assumed to be 16 bit */
-pci_bios_io_addr = ALIGN(pci_bios_io_addr, PCI_IO_ALIGN);
-pci_bios_mem_addr = ALIGN(pci_bios_mem_addr, PCI_MEMORY_ALIGN);
-pci_bios_prefmem_addr =
-ALIGN(pci_bios_prefmem_addr, PCI_PREF_MEMORY_ALIGN);
+if (pci_region_align(pci_bios_io_region, PCI_IO_ALIGN) == 0) {
+pci_region_disable(pci_bios_io_region);
+}
+if (pci_region_align(pci_bios_mem_region, PCI_MEMORY_ALIGN) == 0) {
+pci_region_disable(pci_bios_mem_region);
+}
+if (pci_region_align(pci_bios_prefmem_region,
+ PCI_PREF_MEMORY_ALIGN) == 0) {
+

[Qemu-devel] Re: [PATCH 0/2] pciinit: fix overflow when bar allocation

2010-10-18 Thread Michael S. Tsirkin
On Mon, Oct 18, 2010 at 06:34:21PM +0900, Isaku Yamahata wrote:
 This patch set fixes PCI bar allocation when bar overflow occured.
 I checked if pmm_alloc facility can be used, but it doesn't suit for
 pci bar allocation. So I resulted in new API, pci_region which
 encapsulates region allocation and overflow checks.
 The first patch introduces pci_region, and the second patch fixes
 the overflow case with pci_region.
 
 Isaku Yamahata (2):
   pci: introduce pci_region to manage pci io/memory/prefmemory regions.
   pciinit: use pci_region functions.
 
  Makefile |3 +-
  src/pci_region.c |   70 +++
  src/pciinit.c|  122 ++---
  src/util.h   |   15 +++
  4 files changed, 147 insertions(+), 63 deletions(-)
  create mode 100644 src/pci_region.c

Could you clarify what do you mean by bar overflow please?




[Qemu-devel] Re: [PATCH 1/2] pci: introduce pci_region to manage pci io/memory/prefmemory regions.

2010-10-18 Thread Michael S. Tsirkin
On Mon, Oct 18, 2010 at 06:34:22PM +0900, Isaku Yamahata wrote:
 This patch adds helper functions to manage pci area.
 
 Signed-off-by: Isaku Yamahata yamah...@valinux.co.jp
 ---
  Makefile |3 +-
  src/pci_region.c |   70 
 ++
  src/util.h   |   15 +++
  3 files changed, 87 insertions(+), 1 deletions(-)
  create mode 100644 src/pci_region.c
 
 diff --git a/Makefile b/Makefile
 index 9d412f1..1663a5d 100644
 --- a/Makefile
 +++ b/Makefile
 @@ -19,7 +19,8 @@ SRCBOTH=misc.c pmm.c stacks.c output.c util.c block.c 
 floppy.c ata.c mouse.c \
  SRC16=$(SRCBOTH) system.c disk.c font.c
  SRC32FLAT=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \
acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \
 -  lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c dev-i440fx.c
 +  lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c dev-i440fx.c \
 +  pci_region.c
  SRC32SEG=util.c output.c pci.c pcibios.c apm.c stacks.c
  
  cc-option = $(shell if test -z `$(1) $(2) -S -o /dev/null -xc \
 diff --git a/src/pci_region.c b/src/pci_region.c
 new file mode 100644
 index 000..a4e71d9
 --- /dev/null
 +++ b/src/pci_region.c
 @@ -0,0 +1,70 @@
 +// helper functions to manage pci io/memory/prefetch memory region
 +//
 +// Copyright (C) 2009 Isaku Yamahata yamahata at valinux co jp
 +//
 +// This file may be distributed under the terms of the GNU LGPLv3 license.
 +//
 +//
 +
 +#include util.h
 +
 +#define PCI_REGION_DISABLED (-1)
 +
 +void pci_region_init(struct pci_region *r, u32 start, u32 end)
 +{
 +r-start = start;
 +r-end = end;
 +
 +r-cur_end = start;
 +}
 +
 +static u32 pci_region_alloc_align(struct pci_region *r, u32 size, u32 align)
 +{
 +if (r-cur_end == PCI_REGION_DISABLED) {
 +return 0;
 +}

So is special value PCI_REGION_DISABLED or cur_end?

 +
 +u32 s = ALIGN(r-cur_end, align);
 +if (s  r-end || s  r-cur_end) {
 +return 0;
 +}
 +u32 e = s + size;
 +if (e  r-end || e  s) {
 +return 0;
 +}
 +r-cur_end = e;
 +return s;
 +}
 +
 +u32 pci_region_alloc(struct pci_region *r, u32 size)
 +{
 +return pci_region_alloc_align(r, size, size);
 +}
 +
 +u32 pci_region_align(struct pci_region *r, u32 align)
 +{
 +return pci_region_alloc_align(r, 0, align);
 +}
 +
 +void pci_region_revert(struct pci_region *r, u32 addr)
 +{
 +r-cur_end = addr;
 +}
 +
 +u32 pci_region_disable(struct pci_region *r)
 +{
 +return r-cur_end = PCI_REGION_DISABLED;
 +}
 +
 +u32 pci_region_addr(const struct pci_region *r)
 +{
 +if (r-cur_end == PCI_REGION_DISABLED){
 +return r-end;
 +}
 +return r-cur_end;
 +}
 +
 +u32 pci_region_size(const struct pci_region *r)
 +{
 +return r-end - r-start;
 +}
 diff --git a/src/util.h b/src/util.h
 index 5cc9f17..ecd1c16 100644
 --- a/src/util.h
 +++ b/src/util.h
 @@ -344,6 +344,21 @@ void qemu_prep_reset(void);
  void smm_save_and_copy(void);
  void smm_relocate_and_restore(void);
  
 +// pci_region.c
 +struct pci_region {
 +u32 start;
 +u32 end;
 +
 +u32 cur_end;
 +};
 +void pci_region_init(struct pci_region *r, u32 start, u32 end);
 +u32 pci_region_alloc(struct pci_region *r, u32 size);
 +u32 pci_region_align(struct pci_region *r, u32 align);
 +void pci_region_revert(struct pci_region *r, u32 addr);
 +u32 pci_region_disable(struct pci_region *r);
 +u32 pci_region_addr(const struct pci_region *r);
 +u32 pci_region_size(const struct pci_region *r);
 +

Please document structure fields here and functions in the .c file.

  // pciinit.c
  extern const u8 pci_irqs[4];
  void pci_bios_allocate_regions(u16 bdf, void *arg);
 -- 
 1.7.1.1



Re: [Qemu-devel] [PATCH 1/2] pci: Automatically patch PCI device id in PCI ROM

2010-10-18 Thread Gerd Hoffmann

  Hi,


+/* Don't patch a rom with wrong vendor id (might be changed if needed). */
+if (vendor_id != rom_vendor_id) {
+return;
+}


Yes, please drop that one.  If this is accepted I'd like to use this for
vga roms too, so we have to carry only two of them instead of four.


+if (device_id != rom_device_id) {
+/* Patch device id and checksum (at offset 6 for etherboot roms). */


Does this offset work for all roms?


  /* Add an option rom for the device */
  static int pci_add_option_rom(PCIDevice *pdev)
  {
@@ -1849,6 +1900,8 @@ static int pci_add_option_rom(PCIDevice *pdev)
  load_image(path, ptr);
  qemu_free(path);

+pci_patch_device_id(pdev, ptr, size);
+


I'd prefer this being opt-in per driver instead of being applied 
globally (and maybe also pass in a flag whenever a vendor mismatch is 
fine or not).


cheers,
  Gerd




Re: [Qemu-devel] [PATCH 1/2] pci: Automatically patch PCI device id in PCI ROM

2010-10-18 Thread Gerd Hoffmann

On 10/15/10 23:05, Anthony Liguori wrote:

On 10/15/2010 03:51 PM, Stefan Weil wrote:

PCI device with different device ids sometimes share
the same rom code. Only the device id and the checksum
differ in a boot rom for such devices.


BTW, SeaBIOS doesn't reject ROMs when they're loaded via rombar, only
when they're loaded via romfile.


SeaBIOS rejects them when loaded from the rom bar and doesn't reject 
them when loaded via fw_cfg.


Using the rom bar is the prefered way though, fw_cfg is only there for 
compatibility with older versions.



Maybe it's better to use fw_cfg to explicitly tell SeaBIOS to ignore the
PCI device id in the rom header for a certain device?


Patching the rom is fine IMHO.  Why create + use a separate 
communication path when we can use a much simpler approach?


cheers,
  Gerd




[Qemu-devel] Re: [PATCH] trace: improve info trace output

2010-10-18 Thread Stefan Hajnoczi
On Sun, Oct 17, 2010 at 08:05:45AM +, Blue Swirl wrote:
 Use PRI*64 to print full 64 bit data even on ILP32 hosts.
 
 Print also sixth tracepoint parameter.
 
 Cc: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
 Signed-off-by: Blue Swirl blauwir...@gmail.com
 ---
  simpletrace.c |6 --
  1 files changed, 4 insertions(+), 2 deletions(-)

Acked-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com



[Qemu-devel] Re: TODO item: guest programmable mac/vlan filtering with macvtap

2010-10-18 Thread Arnd Bergmann
On Friday 15 October 2010, Michael S. Tsirkin wrote:
 On Thu, Oct 14, 2010 at 11:40:52PM +0200, Dragos Tatulea wrote:
  Hi,
  
  I'm starting a  thread related to the TODO item mentioned in the
  subject. Currently still gathering info and trying to make kvm 
  macvtap play nicely together. I have used this [1] guide to set it up
  but qemu is still complaining about the PCI device address of the
  virtio-net-pci. Tried with latest qemu. Am I missing something here?
  
  [1] - http://virt.kernelnewbies.org/MacVTap
  
 
 It really should be:
  -net nic,model=virtio,netdev=foo -netdev tap,id=foo
 
 Created account but still could not edit
 the wiki. Arnd, know why that is? Could you correct qemu
 command line pls?

I also have lost write access to the wiki, no idea what happened there.
I started the page, but it subsequently became protected.

We never added support for the qemu command line directly, the
plan was to do that using helper scripts.

The only way to do it is to redirect both input and output
to the tap device, so you ned to do

-net nic,model=virtio,netdev=foo -netdev tap,id=foo,fd=3 3

when starting from bash.

Arnd



[Qemu-devel] Re: [PATCH] qemu-timer: move commonly used timer code to qemu-timer-common

2010-10-18 Thread Stefan Hajnoczi
On Sun, Oct 17, 2010 at 01:50:33PM +, Blue Swirl wrote:
 Move timer init functions to a new file, qemu-timer-common.c. Make other
 critical timer functions inlined to preserve performance in
 qemu-timer.c, also move muldiv64() (used by the inline functions)
 to qemu-timer.h.
 
 Adjust block/raw-posix.c and simpletrace.c to use get_clock() directly.
 Remove a similar/duplicate definition in qemu-tool.c.
 
 Adjust hw/omap_clk.c to include qemu-timer.h because muldiv64() is used
 there.
 
 After this change, tracing can be used also for user code and
 simpletrace on Win32.
 
 Cc: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
 Signed-off-by: Blue Swirl blauwir...@gmail.com
 ---
  Makefile|6 ++--
  Makefile.objs   |3 +-
  block/raw-posix.c   |   12 
  hw/omap_clk.c   |1 +
  qemu-common.h   |2 -
  qemu-timer-common.c |   62 ++
  qemu-timer.c|   73 --
  qemu-timer.h|   74 
 +++
  qemu-tool.c |7 -
  simpletrace.c   |   10 +-
  vl.c|   24 
  11 files changed, 150 insertions(+), 124 deletions(-)
  create mode 100644 qemu-timer-common.c

Acked-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com



Re: [Qemu-devel] [PATCH 1/3] Introduce threadlets

2010-10-18 Thread Arun R Bharadwaj
* Avi Kivity a...@redhat.com [2010-10-17 10:57:23]:

  On 10/14/2010 11:32 PM, Venkateswararao Jujjuri (JV) wrote:
 
   Blocking is somewhat against the spirit of the thing, no?  While I agree 
  that
   the current cancel API is hard to use correctly, blocking defeats the 
  purpose of
   the API.
 
 Are you proposing to add additional state in the return
 (canceled/running/not-canceled)
 and leave the synchronization part to the user?
 i.e not to provide any additional interface for the user to wait
 for the scheduled work to finish? Just trying to understand.
 
 I wasn't proposing anything since I don't have a good proposal.
 Adding a callback makes the whole thing an asynchronous design which
 threads are trying to avoid.  Blocking is bad.  Leaving it to the
 caller is hard to use correctly.
 
 Perhaps we can have a threadlet with barrier semantics.  You queue a
 piece of work which is guaranteed to execute after all previously
 submitted work (against the same queue) and before any consequently
 submitted work.
 
 -- 
 error compiling committee.c: too many arguments to function
 
 

I would suggest that we have 2 APIs - cancel_threadletwork (current
cancel implementation) and cancel_threadletwork_sync (waits for work
to complete). As of now there is no known user for
cancel_threadletwork_sync. So we can keep this as a TODO for later. I
can provide the APIs for both these so that when we have a user for
cancel_threadletwork_sync, we can go ahead and implement it.

-arun 



Re: [Qemu-devel] [PATCH 1/2] pci: Automatically patch PCI device id in PCI ROM

2010-10-18 Thread Stefan Weil

Am 18.10.2010 12:04, schrieb Gerd Hoffmann:

  Hi,

+/* Don't patch a rom with wrong vendor id (might be changed if 
needed). */

+if (vendor_id != rom_vendor_id) {
+return;
+}


Yes, please drop that one.  If this is accepted I'd like to use this for
vga roms too, so we have to carry only two of them instead of four.


+if (device_id != rom_device_id) {
+/* Patch device id and checksum (at offset 6 for etherboot 
roms). */


Does this offset work for all roms?



As far as I know there is no well-defined checksum offset.
The checksum is simply set by modifying any byte (which
normally should be unused).

Etherboot has some unused bytes at the beginning of rom data
and always uses the same offset 6.

For other roms which also don't use the byte at offset 6, this approach
will work, too. If they store code or vital data at that location,
we destroy that data, so it won't work.

The VGA bios roms have a sequence of several bytes of zero
starting at offset 6, so maybe this data is not important and
we may change the byte at offset 6, but that should be checked
before using this mechanism.




  /* Add an option rom for the device */
  static int pci_add_option_rom(PCIDevice *pdev)
  {
@@ -1849,6 +1900,8 @@ static int pci_add_option_rom(PCIDevice *pdev)
  load_image(path, ptr);
  qemu_free(path);

+pci_patch_device_id(pdev, ptr, size);
+


I'd prefer this being opt-in per driver instead of being applied 
globally (and maybe also pass in a flag whenever a vendor mismatch is 
fine or not).


cheers,
  Gerd


As long as the driver specifies the romfile name,
we get an implicitly defined behaviour: either the
rom matches and nothing special is done, or it doesn't
and the id(s) will be fixed.

So neither flag nor opt-in seems to be needed.





[Qemu-devel] LP#584139

2010-10-18 Thread Michael Tokarev
Can we fix this trivial bug please?
See:
 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=578846
 https://bugs.launchpad.net/qemu/+bug/584139

I switched qemu-kvm in debian to use qemu-keymaps package
(separately packaged keymaps), but it re-introduces
debian#578846.

Thanks!

/mjt



Re: [Qemu-devel] [PATCH 1/2] pci: Automatically patch PCI device id in PCI ROM

2010-10-18 Thread Gerd Hoffmann

  Hi,


As far as I know there is no well-defined checksum offset.
The checksum is simply set by modifying any byte (which
normally should be unused).

Etherboot has some unused bytes at the beginning of rom data
and always uses the same offset 6.


Ah, so you don't actually update the checksum but change some unused 
byte to make the checksum stay the same, right?



For other roms which also don't use the byte at offset 6, this approach
will work, too. If they store code or vital data at that location,
we destroy that data, so it won't work.

The VGA bios roms have a sequence of several bytes of zero
starting at offset 6, so maybe this data is not important and
we may change the byte at offset 6, but that should be checked
before using this mechanism.


From vgabios:

.org 0

vgabios_start:
.byte  0x55, 0xaa   /* BIOS signature */
.byte  0x40 /* BIOS extension length */

vgabios_entry_point:
  jmp vgabios_init_func

From seabios:

struct rom_header {
u16 signature;
u8 size;
u8 initVector[4];
u8 reserved[17];
u16 pcioffset;
u16 pnpoffset;
} PACKED;

Hmm.  So offset 6 is the last byte of initVector.  If (and only if) you 
happen to know that the jump instruction takes 3 bytes only it is save 
to modify the unused 4th byte.  Seems to be true for both vgabios and 
etherboot/gPXE.  We can't assume this in general, although it is quite 
likely given that there hardly would be anything but a 16bit jump.



As long as the driver specifies the romfile name,
we get an implicitly defined behaviour: either the
rom matches and nothing special is done, or it doesn't
and the id(s) will be fixed.



So neither flag nor opt-in seems to be needed.


When following this argumentation the vendor id sanity check shouldn't 
be there in the first place ;)


Note that romfile is a pci bus property, so it isn't fully under the 
drivers control because it can be overridden from the command line for 
every pci device.


cheers,
  Gerd



Re: [Qemu-devel] [PATCH 1/3] Introduce threadlets

2010-10-18 Thread Avi Kivity

 On 10/18/2010 12:47 PM, Arun R Bharadwaj wrote:

* Avi Kivitya...@redhat.com  [2010-10-17 10:57:23]:

   On 10/14/2010 11:32 PM, Venkateswararao Jujjuri (JV) wrote:
  
 Blocking is somewhat against the spirit of the thing, no?  While I 
agree that
 the current cancel API is hard to use correctly, blocking defeats the 
purpose of
 the API.
  
  Are you proposing to add additional state in the return
  (canceled/running/not-canceled)
  and leave the synchronization part to the user?
  i.e not to provide any additional interface for the user to wait
  for the scheduled work to finish? Just trying to understand.

  I wasn't proposing anything since I don't have a good proposal.
  Adding a callback makes the whole thing an asynchronous design which
  threads are trying to avoid.  Blocking is bad.  Leaving it to the
  caller is hard to use correctly.

  Perhaps we can have a threadlet with barrier semantics.  You queue a
  piece of work which is guaranteed to execute after all previously
  submitted work (against the same queue) and before any consequently
  submitted work.

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




I would suggest that we have 2 APIs - cancel_threadletwork (current
cancel implementation) and cancel_threadletwork_sync (waits for work
to complete). As of now there is no known user for
cancel_threadletwork_sync. So we can keep this as a TODO for later. I
can provide the APIs for both these so that when we have a user for
cancel_threadletwork_sync, we can go ahead and implement it.


I agree it's best not to implement c_t_s() now.  Using it implies a 
stall so we should discourage it.


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




[Qemu-devel] Re: [PATCH] apic: convert debug printf statements to tracepoints

2010-10-18 Thread Stefan Hajnoczi
Thanks for pointing out this problem with simpletrace.py.  There are two
issues:

1. The regular expression used by simpletrace.py to parse trace event
   declarations cannot cope with concatenated string literals.
2. Format strings must begin and end with double quotes.  This was previously
   undocumented but is necessary because cpp is not run over trace-events, so
   parsing the strings and portability macros is non-trivial.

The follow-up patches fix the regex, add documentation for the format string
double quotes requirement, and update your patch.

simpletrace.py should work for the coalesced apic trace events now.

Stefan




[Qemu-devel] [PATCH 2/3] trace: Format strings must begin/end with double quotes

2010-10-18 Thread Stefan Hajnoczi
Document the restriction that format strings must begin and end with
double quotes.  This is for easy parsing since we don't run cpp over
trace-events.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 docs/tracing.txt |5 -
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/docs/tracing.txt b/docs/tracing.txt
index 5504850..963c504 100644
--- a/docs/tracing.txt
+++ b/docs/tracing.txt
@@ -74,7 +74,10 @@ Trace events should use types as follows:
 
 Format strings should reflect the types defined in the trace event.  Take
 special care to use PRId64 and PRIu64 for int64_t and uint64_t types,
-respectively.  This ensures portability between 32- and 64-bit platforms.
+respectively.  This ensures portability between 32- and 64-bit platforms.  Note
+that format strings must begin and end with double quotes.  When using
+portability macros, ensure they are preceded and followed by double quotes:
+value %PRIx64.
 
 === Hints for adding new trace events ===
 
-- 
1.7.1




[Qemu-devel] [PATCH 3/3] apic: convert debug printf statements to tracepoints

2010-10-18 Thread Stefan Hajnoczi
From: Blue Swirl blauwir...@gmail.com

Replace debug printf statements with tracepoints.

Signed-off-by: Blue Swirl blauwir...@gmail.com
Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 hw/apic.c|   48 ++--
 trace-events |   12 
 2 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/hw/apic.c b/hw/apic.c
index d686b51..63d62c7 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -21,23 +21,7 @@
 #include qemu-timer.h
 #include host-utils.h
 #include sysbus.h
-
-//#define DEBUG_APIC
-//#define DEBUG_COALESCING
-
-#ifdef DEBUG_APIC
-#define DPRINTF(fmt, ...)   \
-do { printf(apic:  fmt , ## __VA_ARGS__); } while (0)
-#else
-#define DPRINTF(fmt, ...)
-#endif
-
-#ifdef DEBUG_COALESCING
-#define DPRINTF_C(fmt, ...) \
-do { printf(apic:  fmt , ## __VA_ARGS__); } while (0)
-#else
-#define DPRINTF_C(fmt, ...)
-#endif
+#include trace.h
 
 /* APIC Local Vector Table */
 #define APIC_LVT_TIMER   0
@@ -168,8 +152,8 @@ static void apic_local_deliver(APICState *s, int vector)
 uint32_t lvt = s-lvt[vector];
 int trigger_mode;
 
-DPRINTF(%s: vector %d delivery mode %d\n, __func__, vector,
-(lvt  8)  7);
+trace_apic_local_deliver(vector, (lvt  8)  7);
+
 if (lvt  APIC_LVT_MASKED)
 return;
 
@@ -300,9 +284,9 @@ void apic_deliver_irq(uint8_t dest, uint8_t dest_mode,
 {
 uint32_t deliver_bitmask[MAX_APIC_WORDS];
 
-DPRINTF(%s: dest %d dest_mode %d delivery_mode %d vector %d
- polarity %d trigger_mode %d\n, __func__, dest, dest_mode,
-delivery_mode, vector_num, polarity, trigger_mode);
+trace_apic_deliver_irq(dest, dest_mode, delivery_mode, vector_num,
+   polarity, trigger_mode);
+
 apic_get_delivery_bitmask(deliver_bitmask, dest, dest_mode);
 apic_bus_deliver(deliver_bitmask, delivery_mode, vector_num, polarity,
  trigger_mode);
@@ -312,7 +296,8 @@ void cpu_set_apic_base(DeviceState *d, uint64_t val)
 {
 APICState *s = DO_UPCAST(APICState, busdev.qdev, d);
 
-DPRINTF(cpu_set_apic_base: %016 PRIx64 \n, val);
+trace_cpu_set_apic_base(val);
+
 if (!s)
 return;
 s-apicbase = (val  0xf000) |
@@ -329,8 +314,8 @@ uint64_t cpu_get_apic_base(DeviceState *d)
 {
 APICState *s = DO_UPCAST(APICState, busdev.qdev, d);
 
-DPRINTF(cpu_get_apic_base: %016 PRIx64 \n,
-s ? (uint64_t)s-apicbase: 0);
+trace_cpu_get_apic_base(s ? (uint64_t)s-apicbase: 0);
+
 return s ? s-apicbase : 0;
 }
 
@@ -402,20 +387,23 @@ static void apic_update_irq(APICState *s)
 
 void apic_reset_irq_delivered(void)
 {
-DPRINTF_C(%s: old coalescing %d\n, __func__, apic_irq_delivered);
+trace_apic_reset_irq_delivered(apic_irq_delivered);
+
 apic_irq_delivered = 0;
 }
 
 int apic_get_irq_delivered(void)
 {
-DPRINTF_C(%s: returning coalescing %d\n, __func__, apic_irq_delivered);
+trace_apic_get_irq_delivered(apic_irq_delivered);
+
 return apic_irq_delivered;
 }
 
 static void apic_set_irq(APICState *s, int vector_num, int trigger_mode)
 {
 apic_irq_delivered += !get_bit(s-irr, vector_num);
-DPRINTF_C(%s: coalescing %d\n, __func__, apic_irq_delivered);
+
+trace_apic_set_irq(apic_irq_delivered);
 
 set_bit(s-irr, vector_num);
 if (trigger_mode)
@@ -769,7 +757,7 @@ static uint32_t apic_mem_readl(void *opaque, 
target_phys_addr_t addr)
 val = 0;
 break;
 }
-DPRINTF(read:  TARGET_FMT_plx  = %08x\n, addr, val);
+trace_apic_mem_readl(addr, val);
 return val;
 }
 
@@ -805,7 +793,7 @@ static void apic_mem_writel(void *opaque, 
target_phys_addr_t addr, uint32_t val)
 }
 s = DO_UPCAST(APICState, busdev.qdev, d);
 
-DPRINTF(write:  TARGET_FMT_plx  = %08x\n, addr, val);
+trace_apic_mem_writel(addr, val);
 
 switch(index) {
 case 0x02:
diff --git a/trace-events b/trace-events
index 4300178..7857bcb 100644
--- a/trace-events
+++ b/trace-events
@@ -69,3 +69,15 @@ disable cpu_out(unsigned int addr, unsigned int val) addr 
%#x value %u
 # balloon.c
 # Since requests are raised via monitor, not many tracepoints are needed.
 disable balloon_event(void *opaque, unsigned long addr) opaque %p addr %lu
+
+# hw/apic.c
+apic_local_deliver(int vector, uint32_t lvt) vector %d delivery mode %d
+apic_deliver_irq(uint8_t dest, uint8_t dest_mode, uint8_t delivery_mode, 
uint8_t vector_num, uint8_t polarity, uint8_t trigger_mode) dest %d dest_mode 
%d delivery_mode %d vector %d polarity %d trigger_mode %d
+cpu_set_apic_base(uint64_t val) %016PRIx64
+cpu_get_apic_base(uint64_t val) %016PRIx64
+apic_mem_readl(uint64_t addr, uint32_t val)  %PRIx64 = %08x
+apic_mem_writel(uint64_t addr, uint32_t val) %PRIx64 = %08x
+# coalescing
+apic_reset_irq_delivered(int apic_irq_delivered) old coalescing %d
+apic_get_irq_delivered(int apic_irq_delivered) returning coalescing %d

[Qemu-devel] [PATCH 1/3] trace: Relax trace-events parsing regex in simpletrace.py

2010-10-18 Thread Stefan Hajnoczi
The regular expression to parse trace event definitions assumed the
format string would be a simple double-quoted string.  However, we now
use PRI?64 for portability which splits string literals.  The regular
expression can disregard the format string entirely since simpletrace.py
never needs to use it.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 simpletrace.py |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/simpletrace.py b/simpletrace.py
index c2cf168..553a727 100755
--- a/simpletrace.py
+++ b/simpletrace.py
@@ -19,7 +19,7 @@ header_version  = 0
 
 trace_fmt = '='
 trace_len = struct.calcsize(trace_fmt)
-event_re  = re.compile(r'(disable\s+)?([a-zA-Z0-9_]+)\(([^)]*)\)\s+([^]*)')
+event_re  = re.compile(r'(disable\s+)?([a-zA-Z0-9_]+)\(([^)]*)\).*')
 
 def err(msg):
 sys.stderr.write(msg + '\n')
@@ -39,7 +39,7 @@ def parse_events(fobj):
 if m is None:
 continue
 
-disable, name, args, fmt = m.groups()
+disable, name, args = m.groups()
 events[event_num] = (name,) + get_argnames(args)
 event_num += 1
 return events
-- 
1.7.1




Re: [Qemu-devel] Changelog of qemu-0.13.0.tar.gz ?

2010-10-18 Thread Anthony Liguori

On 10/17/2010 11:58 PM, Sergei Steshenko wrote:

Hello,

though there is already

http://download.savannah.gnu.org/releases/qemu/qemu-0.13.0.tar.gz

available, I don't see its changelog on

http://wiki.qemu.org/Index.html
.

Is it expected to be this way ?
   


I haven't sent the announce yet (which will be coming very soon).

Regards,

Anthony Liguori


Thanks,
   Sergei.





   





[Qemu-devel] [PATCH] Fix bug in translation of REVSH

2010-10-18 Thread Johan Bengtsson
The translation of REVSH shifted the low byte 8 steps left before performing
an 8-bit sign extend, causing this part of the expression to alwas be 0.
The fix for this is either to extend before shifting or switch to a 16-bit
extend. I choose the former.

Signed-off-by: Johan Bengtsson teofrast...@gmail.com
---
 target-arm/translate.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/target-arm/translate.c b/target-arm/translate.c
index 652cac9..e2fa4df 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -253,8 +253,8 @@ static void gen_revsh(TCGv var)
 TCGv tmp = new_tmp();
 tcg_gen_shri_i32(tmp, var, 8);
 tcg_gen_andi_i32(tmp, tmp, 0x00ff);
-tcg_gen_shli_i32(var, var, 8);
 tcg_gen_ext8s_i32(var, var);
+tcg_gen_shli_i32(var, var, 8);
 tcg_gen_or_i32(var, var, tmp);
 dead_tmp(tmp);
 }
-- 
1.7.0.4




Re: [Qemu-devel] LP#584139

2010-10-18 Thread Anthony Liguori

On 10/18/2010 06:34 AM, Michael Tokarev wrote:

Can we fix this trivial bug please?
See:
  http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=578846
  https://bugs.launchpad.net/qemu/+bug/584139

I switched qemu-kvm in debian to use qemu-keymaps package
(separately packaged keymaps), but it re-introduces
debian#578846.

Thanks!
   


Can you send a patch to the mailing list with a Signed-off-by and an 
explanation of the change?


Regards,

Anthony Liguori


/mjt

   





[Qemu-devel] [PATCH] USB keyboard emulation key mapping error - debian#578846

2010-10-18 Thread Michael Tokarev
Brad Jorsch ano...@users.sourceforge.net writes ( 
http://bugs.debian.org/578846 ):

  The USB keyboard emulation's translation table in hw/usb-hid.c doesn't
  match the codes actually sent for the Logo (a.k.a. Windows) or Menu
  keys. This results in the guest OS not being able to receive these keys
  at all when the USB keyboard emulation is being used.

  In particular, both the keymap in /usr/share/kvm/keymaps/modifiers and
  the evdev table in x_keymap.c map these keys to 0xdb, 0xdc, and 0xdd,
  while usb_hid_usage_keys[] seems to be expecting them to be mapped to
  0x7d, 0x7e, and 0x7f.

  The attached patch seems to fix the problem, at least in my (limited)
  testing.

This indeed fixes the problem, which is indeed exist.

http://bugs.debian.org/578846
http://bugs.debian.org/600593 (cloned from the above against different pkg)
https://bugs.launchpad.net/qemu/+bug/584139

Signed-Off-By: Brad Jorsch ano...@users.sourceforge.net
Signed-Off-By: Michael Tokarev m...@tls.msk.ru

diff --git a/hw/usb-hid.c b/hw/usb-hid.c
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -401,3 +401,3 @@ static const uint8_t usb_hid_usage_keys[0x100] = {
 0x51, 0x4e, 0x49, 0x4c, 0x00, 0x00, 0x00, 0x00,
-0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0x00, 0x00, 0x00, 0xe3, 0xe7, 0x65, 0x00, 0x00,
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,



[Qemu-devel] [PATCH] add support for qed format

2010-10-18 Thread Stefan Hajnoczi
Note that 019 current fails for both qcow2 and qed due to an outdated
.out file.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 017   |2 +-
 018   |2 +-
 019   |2 +-
 020   |2 +-
 024   |4 ++--
 027   |2 +-
 028   |2 +-
 common|6 ++
 common.rc |3 ++-
 9 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/017 b/017
index d861961..29dd53f 100755
--- a/017
+++ b/017
@@ -40,7 +40,7 @@ trap _cleanup; exit \$status 0 1 2 3 15
 . ./common.pattern
 
 # Any format supporting backing files
-_supported_fmt qcow qcow2 vmdk
+_supported_fmt qcow qcow2 vmdk qed
 _supported_os Linux
 
 TEST_OFFSETS=0 4294967296
diff --git a/018 b/018
index 0a348fe..f155b49 100755
--- a/018
+++ b/018
@@ -40,7 +40,7 @@ trap _cleanup; exit \$status 0 1 2 3 15
 . ./common.pattern
 
 # Any format supporting backing files
-_supported_fmt qcow qcow2 vmdk
+_supported_fmt qcow qcow2 vmdk qed
 _supported_os Linux
 
 TEST_OFFSETS=0 4294967296
diff --git a/019 b/019
index 896b8d9..cce529a 100755
--- a/019
+++ b/019
@@ -44,7 +44,7 @@ trap _cleanup; exit \$status 0 1 2 3 15
 . ./common.pattern
 
 # Any format supporting backing files
-_supported_fmt qcow qcow2 vmdk
+_supported_fmt qcow qcow2 vmdk qed
 _supported_os Linux
 
 TEST_OFFSETS=0 4294967296
diff --git a/020 b/020
index 546e074..b065a53 100755
--- a/020
+++ b/020
@@ -42,7 +42,7 @@ trap _cleanup; exit \$status 0 1 2 3 15
 . ./common.pattern
 
 # Any format supporting backing files
-_supported_fmt qcow qcow2 vmdk
+_supported_fmt qcow qcow2 vmdk qed
 _supported_os Linux
 
 TEST_OFFSETS=0 4294967296
diff --git a/024 b/024
index 48680ca..ff6e984 100755
--- a/024
+++ b/024
@@ -41,8 +41,8 @@ trap _cleanup; exit \$status 0 1 2 3 15
 . ./common.filter
 . ./common.pattern
 
-# Currently only qcow2 supports rebasing
-_supported_fmt qcow2
+# Currently only qcow2 and qed support rebasing
+_supported_fmt qcow2 qed
 _supported_os Linux
 
 CLUSTER_SIZE=65536
diff --git a/027 b/027
index 67ecffc..543c48f 100755
--- a/027
+++ b/027
@@ -38,7 +38,7 @@ trap _cleanup; exit \$status 0 1 2 3 15
 . ./common.rc
 . ./common.filter
 
-_supported_fmt vmdk qcow qcow2
+_supported_fmt vmdk qcow qcow2 qed
 _supported_os Linux
 
 
diff --git a/028 b/028
index 0ca220e..cb8b255 100755
--- a/028
+++ b/028
@@ -44,7 +44,7 @@ trap _cleanup; exit \$status 0 1 2 3 15
 
 # Any format supporting backing files except vmdk and qcow which do not support
 # smaller backing files.
-_supported_fmt qcow2
+_supported_fmt qcow2 qed
 _supported_os Linux
 
 # Choose a size that is not necessarily a cluster size multiple for image
diff --git a/common b/common
index 988fd5e..d95ba4c 100644
--- a/common
+++ b/common
@@ -119,6 +119,7 @@ check options
 -cowtest cow
 -qcow   test qcow
 -qcow2  test qcow2
+-qedtest qed
 -vditest vdi
 -vpctest vpc
 -vmdk   test vmdk
@@ -158,6 +159,11 @@ testlist options
xpand=false
;;
 
+   -qed)
+   IMGFMT=qed
+   xpand=false
+   ;;
+
-vdi)
IMGFMT=vdi
xpand=false
diff --git a/common.rc b/common.rc
index da58f92..f2db92e 100644
--- a/common.rc
+++ b/common.rc
@@ -55,7 +55,7 @@ _make_test_img()
 # at least one argument (the image size) needs to be added
 local extra_img_options=$*
 
-if [ $IMGFMT = qcow2 -a -n $CLUSTER_SIZE ]; then
+if [ \( $IMGFMT = qcow2 -o $IMGFMT = qed \) -a -n $CLUSTER_SIZE 
]; then
 extra_img_options=-o cluster_size=$CLUSTER_SIZE $extra_img_options
 fi
 
@@ -65,6 +65,7 @@ _make_test_img()
sed -e s#$IMGFMT#IMGFMT#g | \
sed -e s# encryption=off##g | \
sed -e s# cluster_size=0##g | \
+   sed -e s# table_size=0##g | \
sed -e s# compat6=off##g | \
sed -e s# static=off##g
 }
-- 
1.7.1




Re: [Qemu-devel] [PATCH] add support for qed format

2010-10-18 Thread Stefan Hajnoczi
I forgot to add the [qemu-iotests] tag, sorry.  This applies to
Christoph's qemu-iotests suite at:

http://git.kernel.org/?p=linux/kernel/git/hch/qemu-iotests.git;a=summary

Stefan



Re: [Qemu-devel] [PATCH 1/2] pci: Automatically patch PCI device id in PCI ROM

2010-10-18 Thread Stefan Weil

Hi,

Am 18.10.2010 13:54, schrieb Gerd Hoffmann:

  Hi,


As far as I know there is no well-defined checksum offset.
The checksum is simply set by modifying any byte (which
normally should be unused).

Etherboot has some unused bytes at the beginning of rom data
and always uses the same offset 6.


Ah, so you don't actually update the checksum but change some unused 
byte to make the checksum stay the same, right?


Right. The sum of all bytes modulo 255 must be 0.
Any byte can be modified to achieve this.




For other roms which also don't use the byte at offset 6, this approach
will work, too. If they store code or vital data at that location,
we destroy that data, so it won't work.

The VGA bios roms have a sequence of several bytes of zero
starting at offset 6, so maybe this data is not important and
we may change the byte at offset 6, but that should be checked
before using this mechanism.


From vgabios:

.org 0

vgabios_start:
.byte  0x55, 0xaa/* BIOS signature */
.byte  0x40/* BIOS extension length */

vgabios_entry_point:
  jmp vgabios_init_func

From seabios:

struct rom_header {
u16 signature;
u8 size;
u8 initVector[4];
u8 reserved[17];
u16 pcioffset;
u16 pnpoffset;
} PACKED;

Hmm.  So offset 6 is the last byte of initVector.  If (and only if) 
you happen to know that the jump instruction takes 3 bytes only it is 
save to modify the unused 4th byte.  Seems to be true for both vgabios 
and etherboot/gPXE.  We can't assume this in general, although it is 
quite likely given that there hardly would be anything but a 16bit jump.


I agree. So it would work with vga bios, too.

It looks like vgabios uses the last byte to fix the checksum
(rom data ends with a sequence of 0xff, only last byte is different).





As long as the driver specifies the romfile name,
we get an implicitly defined behaviour: either the
rom matches and nothing special is done, or it doesn't
and the id(s) will be fixed.



So neither flag nor opt-in seems to be needed.


When following this argumentation the vendor id sanity check shouldn't 
be there in the first place ;)


The sanity check is simply there because I had no test case
which patches the vendor id. How could I test with vga bios?



Note that romfile is a pci bus property, so it isn't fully under the 
drivers control because it can be overridden from the command line for 
every pci device.


Maybe this is an argument why the driver should not include any flags
for id patching. A user who overrides the rom name from the command line
should know what she/he does.



cheers,
  Gerd




Regards,
Stefan




[Qemu-devel] [PATCH 0/1] ccid emulated card (v1, for usb-ccid v3)

2010-10-18 Thread Alon Levy
Meant to be applied after the usb-ccid v3 patch on the list.
Causes --enable-smartcard to depend on libcac_card, library for emulating
CAC compliant smart cards at http://cgit.freedesktop.org/~alon/cac_card/

hw/ccid-card-emulated.c: new device
Makefile.objs: add ccid-card-emulated.o if --enable-smartcard
configure: dependency on libcac_card if --enable-smartcard
hw/usb-ccid.c: added a TODO note
hw/ccid-card-passthru.c: removed does-nothing print method.

Alon Levy (1):
  add ccid-card-emulated device

 Makefile.objs   |2 +-
 configure   |   20 ++
 hw/ccid-card-emulated.c |  497 +++
 hw/ccid-card-passthru.c |6 -
 hw/usb-ccid.c   |2 +
 5 files changed, 520 insertions(+), 7 deletions(-)
 create mode 100644 hw/ccid-card-emulated.c

-- 
1.7.3.1




[Qemu-devel] [PATCH 1/1] add ccid-card-emulated device

2010-10-18 Thread Alon Levy
Signed-off-by: Alon Levy al...@redhat.com
---
 Makefile.objs   |2 +-
 configure   |   20 ++
 hw/ccid-card-emulated.c |  497 +++
 hw/ccid-card-passthru.c |6 -
 hw/usb-ccid.c   |2 +
 5 files changed, 520 insertions(+), 7 deletions(-)
 create mode 100644 hw/ccid-card-emulated.c

diff --git a/Makefile.objs b/Makefile.objs
index 3c4a880..ae12546 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -173,7 +173,7 @@ hw-obj-$(CONFIG_FDC) += fdc.o
 hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o
 hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o
 hw-obj-$(CONFIG_DMA) += dma.o
-hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o ccid-card-passthru.o
+hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o ccid-card-passthru.o 
ccid-card-emulated.o
 
 # PPC devices
 hw-obj-$(CONFIG_OPENPIC) += openpic.o
diff --git a/configure b/configure
index 4e05971..31700b0 100755
--- a/configure
+++ b/configure
@@ -2113,6 +2113,26 @@ EOF
   fi
 fi
 
+# check for libcaccard for smartcard support
+if test $smartcard != no ; then
+  cat  $TMPC  EOF
+#include vscard_common.h
+int main() { return 0; }
+EOF
+  smartcard_cflags=$($pkgconfig --cflags cac_card cac_card 2/dev/null)
+  smartcard_libs=$($pkgconfig --libs cac_card cac_card 2/dev/null)
+  if $pkgconfig --atleast-version=0.0.1 cac_card \
+ compile_prog $smartcard_cflags $smartcard_libs ; then
+smartcard=yes
+QEMU_CFLAGS=$QEMU_CFLAGS $smartcard_cflags
+  else
+if test smartcard = yes ; then
+  feature_not_found smartcard
+fi
+smartcard=no
+  fi
+fi
+
 ##
 
 ##
diff --git a/hw/ccid-card-emulated.c b/hw/ccid-card-emulated.c
new file mode 100644
index 000..e28d49c
--- /dev/null
+++ b/hw/ccid-card-emulated.c
@@ -0,0 +1,497 @@
+/*
+ * CCID Card Device. Emulated card.
+ *
+ * It can be used to provide access to the local hardware in a non exclusive
+ * way, or it can use certificates. It requires the usb-ccid bus.
+ *
+ * Usage 1: standard, mirror hardware reader+card:
+ * qemu .. -usb -device usb-ccid -device ccid-card-emulated
+ *
+ * Usage 2: use certificates, no hardware required
+ * one time: create the certificates:
+ *  for i in 1 2 3; do certutil -d /etc/pki/nssdb -x -t CT,CT,CT -S -s 
CN=user$i -n user$i; done 
+ * qemu .. -usb -device usb-ccid -device 
ccid-card-emulated,cert1=user1,cert2=user2,cert3=user3
+ *
+ * If you use a non default db for the certificates you can specify it using 
the db parameter.
+ *
+ *
+ * Copyright (c) 2010 Red Hat.
+ * Written by Alon Levy.
+ *
+ * This code is licenced under the LGPL.
+ */
+
+#include pthread.h
+#include eventt.h
+#include vevent.h
+#include vreader.h
+#include vcard_emul.h
+#include qemu-char.h
+#include monitor.h
+#include hw/ccid.h
+
+#define DPRINTF(lvl, fmt, ...) \
+do { if (lvl = debug) { printf(ccid-card-emul: %s:  fmt , __func__, ## 
__VA_ARGS__); } } while (0)
+
+static int debug = 0;
+
+#define EMULATED_DEV_NAME ccid-card-emulated
+
+#define BACKEND_NSS_EMULATED nss-emulated // the default
+#define BACKEND_CERTIFICATES certificates
+
+typedef struct EmulatedState EmulatedState;
+
+enum {
+EMUL_READER_INSERT = 0,
+EMUL_READER_REMOVE,
+EMUL_CARD_INSERT,
+EMUL_CARD_REMOVE,
+EMUL_GUEST_APDU,
+EMUL_RESPONSE_APDU,
+EMUL_ERROR,
+};
+
+static const char* emul_event_to_string(uint32_t emul_event)
+{
+switch (emul_event) {
+case EMUL_READER_INSERT: return EMUL_READER_INSERT;
+case EMUL_READER_REMOVE: return EMUL_READER_REMOVE;
+case EMUL_CARD_INSERT: return EMUL_CARD_INSERT;
+case EMUL_CARD_REMOVE: return EMUL_CARD_REMOVE;
+case EMUL_GUEST_APDU: return EMUL_GUEST_APDU;
+case EMUL_RESPONSE_APDU: return EMUL_RESPONSE_APDU;
+case EMUL_ERROR: return EMUL_ERROR;
+default:
+break;
+}
+return UNKNOWN;
+}
+
+typedef struct EmulEvent {
+QSIMPLEQ_ENTRY(EmulEvent) entry;
+union {
+struct {
+uint32_t type;
+} gen;
+struct {
+uint32_t type;
+uint64_t code;
+} error;
+struct {
+uint32_t type;
+uint32_t len;
+uint8_t data[];
+} data;
+} p;
+} EmulEvent;
+
+#define MAX_ATR_SIZE 40
+struct EmulatedState {
+CCIDCardState base;
+uint8_t  debug;
+char*backend;
+char*cert1;
+char*cert2;
+char*cert3;
+char*db;
+uint8_t  atr[MAX_ATR_SIZE];
+uint8_t  atr_length;
+QSIMPLEQ_HEAD(event_list, EmulEvent) event_list;
+pthread_mutex_t event_list_mutex;
+VReader *reader;
+QSIMPLEQ_HEAD(guest_apdu_list, EmulEvent) guest_apdu_list;
+pthread_mutex_t vreader_mutex; // and guest_apdu_list mutex
+pthread_mutex_t handle_apdu_mutex;
+pthread_cond_t handle_apdu_cond;
+int  pipe[2];
+int  quit_apdu_thread;
+pthread_mutex_t apdu_thread_quit_mutex;
+pthread_cond_t 

[Qemu-devel] [PATCH] Add support for async page fault to qemu

2010-10-18 Thread Gleb Natapov
Add save/restore of MSR for migration and cpuid bit.

Signed-off-by: Gleb Natapov g...@redhat.com
diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index bb09fd8..5d8c428 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -678,6 +678,9 @@ static int get_msr_entry(struct kvm_msr_entry *entry, 
CPUState *env)
 env-mcg_ctl = entry-data;
 break;
 #endif
+case MSR_KVM_ASYNC_PF_EN:
+env-async_pf_en_msr = entry-data;
+break;
 default:
 #ifdef KVM_CAP_MCE
 if (entry-index = MSR_MC0_CTL 
@@ -967,6 +970,7 @@ void kvm_arch_load_regs(CPUState *env, int level)
 }
 kvm_msr_entry_set(msrs[n++], MSR_KVM_SYSTEM_TIME, 
env-system_time_msr);
 kvm_msr_entry_set(msrs[n++], MSR_KVM_WALL_CLOCK, env-wall_clock_msr);
+kvm_msr_entry_set(msrs[n++], MSR_KVM_ASYNC_PF_EN, 
env-async_pf_en_msr);
 }
 #ifdef KVM_CAP_MCE
 if (env-mcg_cap) {
@@ -1186,6 +1190,7 @@ void kvm_arch_save_regs(CPUState *env)
 #endif
 msrs[n++].index = MSR_KVM_SYSTEM_TIME;
 msrs[n++].index = MSR_KVM_WALL_CLOCK;
+msrs[n++].index = MSR_KVM_ASYNC_PF_EN;
 
 #ifdef KVM_CAP_MCE
 if (env-mcg_cap) {
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 8b6efed..154b76b 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -669,6 +669,7 @@ typedef struct CPUX86State {
 #endif
 uint64_t system_time_msr;
 uint64_t wall_clock_msr;
+uint64_t async_pf_en_msr;
 
 uint64_t tsc;
 
@@ -923,7 +924,7 @@ CPUState *pc_new_cpu(const char *cpu_model);
 #define cpu_list_id x86_cpu_list
 #define cpudef_setup   x86_cpudef_setup
 
-#define CPU_SAVE_VERSION 12
+#define CPU_SAVE_VERSION 13
 
 /* MMU modes definitions */
 #define MMU_MODE0_SUFFIX _kernel
diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index d63fdcb..0ee1f88 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -73,7 +73,7 @@ static const char *ext3_feature_name[] = {
 };
 
 static const char *kvm_feature_name[] = {
-kvmclock, kvm_nopiodelay, kvm_mmu, NULL, NULL, NULL, NULL, NULL,
+kvmclock, kvm_nopiodelay, kvm_mmu, NULL, kvm_asyncpf, NULL, NULL, 
NULL,
 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index f4fc063..0eb1e90 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -151,6 +151,9 @@ struct kvm_para_features {
 #ifdef KVM_CAP_PV_MMU
 { KVM_CAP_PV_MMU, KVM_FEATURE_MMU_OP },
 #endif
+#ifdef KVM_CAP_ASYNC_PF
+{ KVM_CAP_ASYNC_PF, KVM_FEATURE_ASYNC_PF },
+#endif
 { -1, -1 }
 };
 
@@ -672,6 +675,7 @@ static int kvm_put_msrs(CPUState *env, int level)
 kvm_msr_entry_set(msrs[n++], MSR_KVM_SYSTEM_TIME,
   env-system_time_msr);
 kvm_msr_entry_set(msrs[n++], MSR_KVM_WALL_CLOCK, env-wall_clock_msr);
+kvm_msr_entry_set(msrs[n++], MSR_KVM_ASYNC_PF_EN, 
env-async_pf_en_msr);
 }
 
 msr_data.info.nmsrs = n;
@@ -880,6 +884,7 @@ static int kvm_get_msrs(CPUState *env)
 #endif
 msrs[n++].index = MSR_KVM_SYSTEM_TIME;
 msrs[n++].index = MSR_KVM_WALL_CLOCK;
+msrs[n++].index = MSR_KVM_ASYNC_PF_EN;
 
 msr_data.info.nmsrs = n;
 ret = kvm_vcpu_ioctl(env, KVM_GET_MSRS, msr_data);
@@ -926,6 +931,9 @@ static int kvm_get_msrs(CPUState *env)
 case MSR_VM_HSAVE_PA:
 env-vm_hsave = msrs[i].data;
 break;
+   case MSR_KVM_ASYNC_PF_EN:
+env-async_pf_en_msr = msrs[i].data;
+break;
 }
 }
 
diff --git a/target-i386/machine.c b/target-i386/machine.c
index 4398801..092c901 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -474,6 +474,9 @@ static const VMStateDescription vmstate_cpu = {
 VMSTATE_UINT64_V(xcr0, CPUState, 12),
 VMSTATE_UINT64_V(xstate_bv, CPUState, 12),
 VMSTATE_YMMH_REGS_VARS(ymmh_regs, CPUState, CPU_NB_REGS, 12),
+
+   /* KVM async pf msr */
+VMSTATE_UINT64_V(async_pf_en_msr, CPUState, 13),
 VMSTATE_END_OF_LIST()
 /* The above list is not sorted /wrt version numbers, watch out! */
 }
--
Gleb.



Re: [Qemu-devel] [PATCH 1/2] pci: Automatically patch PCI device id in PCI ROM

2010-10-18 Thread Gerd Hoffmann

  Hi,


When following this argumentation the vendor id sanity check shouldn't
be there in the first place ;)


The sanity check is simply there because I had no test case
which patches the vendor id. How could I test with vga bios?


No trivial way as the vgabios needs to be patched to handle that.

The vgabios searches for its hardware, right now the IDs are 
compile-time constants (same constants are compiled into the pci 
header).  Needs to be changed to lookup the ID at runtime in the pci header.


cheers,
  Gerd




[Qemu-devel] [PATCH] Add a DTrace tracing backend targetted for SystemTAP compatability

2010-10-18 Thread Daniel P. Berrange
This introduces a new tracing backend that targets the SystemTAP
implementation of DTrace userspace tracing. The core functionality
should be applicable and standard across any DTrace implementation
on Solaris, OS-X, *BSD, but the Makefile rules will likely need
some small additional changes to cope with OS specific build
requirements.

This backend builds a little differently from the other tracing
backends. Specifically there is no 'trace.c' file, because the
'dtrace' command line tool generates a '.o' file directly from
the dtrace probe definition file. The probe definition is usually
named with a '.d' extension but QEMU uses '.d' files for its
external makefile dependancy tracking, so this uses '.dtrace' as
the extension for the probe definition file.

The 'tracetool' program gains the ability to generate a trace.h
file for DTrace, and also to generate the trace.d file containing
the dtrace probe definition, and finally a qemu.stp file which is
a wrapper around the probe definition providing more convenient
access from SystemTAP scripts.

eg, instead of

  probe process(qemu).mark(qemu_malloc) {
printf(Malloc %d %p\n, $arg1, $arg2);
  }

The addition of qemu.stp to /usr/share/systemtap/tapset/
lets users write

  probe qemu.qemu_malloc {
printf(Malloc %d %p\n, size, ptr);
  }

* .gitignore: Ignore trace-dtrace.*
* Makefile: Extra rules for generating DTrace files
* Makefile.obj: Don't build trace.o for DTrace, use
  trace-dtrace.o generated by 'dtrace' instead
* tracetool: Support for generating DTrace/SystemTAP
  data files

Signed-off-by: Daniel P. Berrange berra...@redhat.com
---
 .gitignore|3 +
 Makefile  |   31 ++
 Makefile.objs |4 +
 tracetool |  175 -
 4 files changed, 211 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index a43e4d1..0d27afd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,9 @@ config-host.*
 config-target.*
 trace.h
 trace.c
+trace-dtrace.h
+trace-dtrace.dtrace
+qemu.stp
 *-timestamp
 *-softmmu
 *-darwin-user
diff --git a/Makefile b/Makefile
index 252c817..812b0d3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,9 @@
 # Makefile for QEMU.
 
 GENERATED_HEADERS = config-host.h trace.h
+ifeq ($(TRACE_BACKEND),dtrace)
+GENERATED_HEADERS += trace-dtrace.h
+endif
 
 ifneq ($(wildcard config-host.mak),)
 # Put the all: rule here so that config-host.mak can contain dependencies.
@@ -106,7 +109,11 @@ ui/vnc.o: QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
 
 bt-host.o: QEMU_CFLAGS += $(BLUEZ_CFLAGS)
 
+ifeq ($(TRACE_BACKEND),dtrace)
+trace.h: trace.h-timestamp trace-dtrace.h
+else
 trace.h: trace.h-timestamp
+endif
 trace.h-timestamp: $(SRC_PATH)/trace-events config-host.mak
$(call quiet-command,sh $(SRC_PATH)/tracetool --$(TRACE_BACKEND) -h  
$  $@,  GEN   trace.h)
@cmp -s $@ trace.h || cp $@ trace.h
@@ -118,6 +125,23 @@ trace.c-timestamp: $(SRC_PATH)/trace-events config-host.mak
 
 trace.o: trace.c $(GENERATED_HEADERS)
 
+trace-dtrace.h: trace-dtrace.dtrace
+   $(call quiet-command,dtrace -o $@ -h -s $,   GEN   trace-dtrace.h)
+
+# Normal practice is to name DTrace probe file with a '.d' extension
+# but that gets picked up by QEMU's Makefile as an external dependancy
+# rule file. So we use '.dtrace' instead
+trace-dtrace.dtrace: trace-dtrace.dtrace-timestamp
+trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events config-host.mak
+   $(call quiet-command,sh $(SRC_PATH)/tracetool --$(TRACE_BACKEND) -d  
$  $@,  GEN   trace-dtrace.dtrace)
+   @cmp -s $@ trace-dtrace.dtrace || cp $@ trace-dtrace.dtrace
+ifdef CONFIG_LINUX
+   $(call quiet-command,sh $(SRC_PATH)/tracetool --$(TRACE_BACKEND) -s  
$  qemu.stp,  GEN   qemu.stp)
+endif
+
+trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS)
+   $(call quiet-command,dtrace -o $@ -G -s $,   GEN trace-dtrace.o)
+
 simpletrace.o: simpletrace.c $(GENERATED_HEADERS)
 
 version.o: $(SRC_PATH)/version.rc config-host.mak
@@ -154,6 +178,7 @@ clean:
rm -f slirp/*.o slirp/*.d audio/*.o audio/*.d block/*.o block/*.d 
net/*.o net/*.d fsdev/*.o fsdev/*.d ui/*.o ui/*.d
rm -f qemu-img-cmds.h
rm -f trace.c trace.h trace.c-timestamp trace.h-timestamp
+   rm -f trace-dtrace.dtrace trace-dtrace.h trace-dtrace.h-timestamp 
qemu.stp
$(MAKE) -C tests clean
for d in $(ALL_SUBDIRS) libhw32 libhw64 libuser libdis libdis-user; do \
if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
@@ -214,6 +239,12 @@ ifneq ($(BLOBS),)
$(INSTALL_DATA) $(SRC_PATH)/pc-bios/$$x $(DESTDIR)$(datadir); 
\
done
 endif
+ifeq ($(TRACE_BACKEND),dtrace)
+ifdef CONFIG_LINUX
+   $(INSTALL_DIR) $(DESTDIR)$(datadir)/../systemtap/tapset
+   $(INSTALL_DATA) qemu.stp $(DESTDIR)$(datadir)/../systemtap/tapset
+endif
+endif
$(INSTALL_DIR) $(DESTDIR)$(datadir)/keymaps
set -e; for x in $(KEYMAPS); do \
$(INSTALL_DATA) 

Re: [Qemu-devel] [PATCH] Trivial fix for QMP/qmp-events.txt

2010-10-18 Thread Luiz Capitulino
On Thu, 14 Oct 2010 09:51:02 +0900
Hidetoshi Seto seto.hideto...@jp.fujitsu.com wrote:

 Fix example of STOP event that was just copy-and-pasted.
 
 Signed-off-by: Hidetoshi Seto seto.hideto...@jp.fujitsu.com

Applied to the QMP queue, thanks.

 ---
  QMP/qmp-events.txt |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
 
 diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt
 index 01ec85f..aa20210 100644
 --- a/QMP/qmp-events.txt
 +++ b/QMP/qmp-events.txt
 @@ -89,7 +89,7 @@ Data: None.
  
  Example:
  
 -{ event: SHUTDOWN,
 +{ event: STOP,
  timestamp: { seconds: 1267041730, microseconds: 281295 } }
  
  VNC_CONNECTED




Re: [Qemu-devel] [PATCH] Silence compiler warning in json test case

2010-10-18 Thread Luiz Capitulino
On Sat, 16 Oct 2010 19:42:43 +0200
Jan Kiszka jan.kis...@web.de wrote:

 Am 16.10.2010 18:28, Blue Swirl wrote:
  On Sat, Oct 16, 2010 at 12:37 AM, Paolo Bonzini pbonz...@redhat.com wrote:
  On 10/15/2010 07:41 PM, Blue Swirl wrote:
 
  Which functions are optimized away and which aren't?
 
  It's builtins only that are optimized away or otherwise inlined (printf,
  sprintf, etc.).  Other calls stay, together with side effects and clock
  cycles.
  
  Then the warning makes sense (slightly) and should remain on main QEMU side.
  
 
 From: Jan Kiszka jan.kis...@siemens.com
 
 This avoids
 
 error: zero-length gnu_printf format string
 
 Signed-off-by: Jan Kiszka jan.kis...@siemens.com

I've applied this one to the QMP queue, but of course that Blue can
push it if he wants to.

 ---
  check-qjson.c |4 +++-
  1 files changed, 3 insertions(+), 1 deletions(-)
 
 diff --git a/check-qjson.c b/check-qjson.c
 index 0b60e45..64fcdcb 100644
 --- a/check-qjson.c
 +++ b/check-qjson.c
 @@ -639,7 +639,9 @@ END_TEST
  
  START_TEST(empty_input)
  {
 -QObject *obj = qobject_from_json();
 +const char *empty = ;
 +
 +QObject *obj = qobject_from_json(empty);
  fail_unless(obj == NULL);
  }
  END_TEST
 




[Qemu-devel] Re: [Tracing][RFC v3 PATCH 0/2] QMP Query interfaces for tracing

2010-10-18 Thread Luiz Capitulino
On Mon, 18 Oct 2010 11:36:55 +0530
Prerna Saxena pre...@linux.vnet.ibm.com wrote:

 This patch set introduces two QMP interfaces for tracing :
 
 * query-trace: to list current contents of trace-buffer
 * query-trace-events : to list all available trace-events with their state.

This is in my to-review queue, but it's going to take a few days, because
I have to take a deeper look at the tracing feature to be able to review it.

Two initial questions:

 o This is labeled as an RFC, but you're versioning it. Should this be
   considered for inclusion?

 o Is this really useful w/o being able to set new traces?

 
 Changelog :
 ---
 Changes v2 - v3 :
 - Change declarations of st_print_trace_to_qlist() and 
 st_print_trace_events_to_qlist() to return QList*
 
 Changes v1 - v2 :
 - Add 'timestamp' field for query-trace output.
 - Misc cleanups.
 




Re: [Qemu-devel] Trace Logical memory

2010-10-18 Thread kenhcon bk
 Hi,I also investigate to implement trace target memory. Now i can trace logical address ( simulate ARM on i386) I focus on tcg_out_qemu_ld and tcg_out_qemu_st function to generate i386 code. But i found that , QEMU don't generate full memory access for loop ( it only generate for 1 TB on loop )How to generate full memory access address ?Do you know about this Lluis ?
About physical address  I found this topic on internethttp://vm-kernel.org/blog/2009/07/10/qemu-internal-part-2-softmmu/As it :1. addend = host_virtual_address – guest_virtual_address-host_virtual_address = addend + guest_virtual_address
2. host_virtual_address = phys_ram_base(qemu variable) + guest_physical_address – guest_physical_address_base(0 in MIPS) 
-- addend + guest_virtual_address = phys_ram_base(qemu variable) + guest_physical_address – guest_physical_address_base(0 in MIPS)In ARM  phys_ram_base(qemu variable) and guest_physical_address_base is const-- guest_physical_address belong to addend.But when i check in the source code , addend is difference each times i run qemu. what do you think about my method? right or wrong?Could you explain more about your idea to implement to trace guest physical addressThanksBest regardsHoàng Tùng 
  







  

[Qemu-devel] KVM call agenda for Oct 19

2010-10-18 Thread Juan Quintela

Please send in any agenda items you are interested in covering.

thanks,

Juan.



[Qemu-devel] Re: [PATCH] Add support for async page fault to qemu

2010-10-18 Thread Juan Quintela
Gleb Natapov g...@redhat.com wrote:
 Add save/restore of MSR for migration and cpuid bit.

It is there a way to test if async page faults are in use?
if so, we can add a subsection instead of changing the cpuversion.

I think that at some point we are going to need a bitmap that indicates
what MSR's have been used or something like that.

What do you think?

Later, Juan.




Re: [Qemu-devel] [PATCH 1/2] pci: Automatically patch PCI device id in PCI ROM

2010-10-18 Thread Gerd Hoffmann

On 10/18/10 15:30, Gerd Hoffmann wrote:

  Hi,


When following this argumentation the vendor id sanity check shouldn't
be there in the first place ;)


The sanity check is simply there because I had no test case
which patches the vendor id. How could I test with vga bios?


No trivial way as the vgabios needs to be patched to handle that.


patchrom branches available now:

http://cgit.freedesktop.org/~kraxel/vgabios/log/
http://cgit.freedesktop.org/spice/qemu/log/?h=patchrom

very short instructions:

(1) fetch+compile vgabios, copy new vgabios-pci binary
so qemu can find it.
(2) fetch qemu, apply/merge id patching, compile qemu
(3) both standard and vmware vga should happily work
with the same vgabios binary now, including vesa
graphic modes.

cheers,
  Gerd



[Qemu-devel] Re: [PATCH] Add support for async page fault to qemu

2010-10-18 Thread Avi Kivity

 On 10/18/2010 05:48 PM, Juan Quintela wrote:

Gleb Natapovg...@redhat.com  wrote:
  Add save/restore of MSR for migration and cpuid bit.

It is there a way to test if async page faults are in use?


Yes, msr != 0 - need a subsection.  Good idea.


if so, we can add a subsection instead of changing the cpuversion.

I think that at some point we are going to need a bitmap that indicates
what MSR's have been used or something like that.

What do you think?


We just need to check if an msr is different from its default value 
(which we can get by reading msrs immediately after the initial reset).


Currently the reset code assumes msr reset value is zero, that's wrong.

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




[Qemu-devel] [PATCH][block] qcow2: Support exact L1 table growth

2010-10-18 Thread Stefan Hajnoczi
The L1 table grow operation includes a size calculation that bumps up
the new L1 table size in order to anticipate the size needs of vmstate
data.  This helps reduce the number of times that the L1 table has to be
grown when vmstate data is appended.

This size overhead is not necessary during image creation,
bdrv_truncate(), or snapshot goto operations.  In fact, existing
qemu-iotests that exercise table growth are no longer able to trigger it
because image creation preallocates an L1 table that is too large after
changes to qcow_create2().

This patch keeps the size calculation but also adds exact growth for
callers that do not want to inflate the L1 table size unnecessarily.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 block/qcow2-cluster.c  |   25 -
 block/qcow2-snapshot.c |2 +-
 block/qcow2.c  |2 +-
 block/qcow2.h  |2 +-
 4 files changed, 19 insertions(+), 12 deletions(-)

Hi Kevin,
This patch fixes the qcow_create2() issue seen in qemu-iotests 026 with your
kevin.git/block branch.  The issue was that the L1 table size of new images is
inflated by qcow2_grow_l1_table().  This caused the differences in the test,
e.g. L1 table grow tests no longer worked because they couldn't force the table
to grow (it was already more than large enough).

If we use exact L1 growth in bdrv_truncate() then less image space is wasted
and the test passes again without changes to 026.out.

I think this patch is the way to go, not just to satisfy the test, but also
because we don't need to overallocate L1 tables to start with.

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index fb4224a..4f7dc59 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -28,7 +28,7 @@
 #include block_int.h
 #include block/qcow2.h
 
-int qcow2_grow_l1_table(BlockDriverState *bs, int min_size)
+int qcow2_grow_l1_table(BlockDriverState *bs, int min_size, bool exact_size)
 {
 BDRVQcowState *s = bs-opaque;
 int new_l1_size, new_l1_size2, ret, i;
@@ -36,15 +36,22 @@ int qcow2_grow_l1_table(BlockDriverState *bs, int min_size)
 int64_t new_l1_table_offset;
 uint8_t data[12];
 
-new_l1_size = s-l1_size;
-if (min_size = new_l1_size)
+if (min_size = s-l1_size)
 return 0;
-if (new_l1_size == 0) {
-new_l1_size = 1;
-}
-while (min_size  new_l1_size) {
-new_l1_size = (new_l1_size * 3 + 1) / 2;
+
+if (exact_size) {
+new_l1_size = min_size;
+} else {
+/* Bump size up to reduce the number of times we have to grow */
+new_l1_size = s-l1_size;
+if (new_l1_size == 0) {
+new_l1_size = 1;
+}
+while (min_size  new_l1_size) {
+new_l1_size = (new_l1_size * 3 + 1) / 2;
+}
 }
+
 #ifdef DEBUG_ALLOC2
 printf(grow l1_table from %d to %d\n, s-l1_size, new_l1_size);
 #endif
@@ -550,7 +557,7 @@ static int get_cluster_table(BlockDriverState *bs, uint64_t 
offset,
 
 l1_index = offset  (s-l2_bits + s-cluster_bits);
 if (l1_index = s-l1_size) {
-ret = qcow2_grow_l1_table(bs, l1_index + 1);
+ret = qcow2_grow_l1_table(bs, l1_index + 1, false);
 if (ret  0) {
 return ret;
 }
diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c
index 5539510..aacf357 100644
--- a/block/qcow2-snapshot.c
+++ b/block/qcow2-snapshot.c
@@ -327,7 +327,7 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char 
*snapshot_id)
 if (qcow2_update_snapshot_refcount(bs, s-l1_table_offset, s-l1_size, -1) 
 0)
 goto fail;
 
-if (qcow2_grow_l1_table(bs, sn-l1_size)  0)
+if (qcow2_grow_l1_table(bs, sn-l1_size, true)  0)
 goto fail;
 
 s-l1_size = sn-l1_size;
diff --git a/block/qcow2.c b/block/qcow2.c
index d5b7b1a..b816d87 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1061,7 +1061,7 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t 
offset)
 }
 
 new_l1_size = size_to_l1(s, offset);
-ret = qcow2_grow_l1_table(bs, new_l1_size);
+ret = qcow2_grow_l1_table(bs, new_l1_size, true);
 if (ret  0) {
 return ret;
 }
diff --git a/block/qcow2.h b/block/qcow2.h
index d1275cd..2d22e5e 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -188,7 +188,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
 int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res);
 
 /* qcow2-cluster.c functions */
-int qcow2_grow_l1_table(BlockDriverState *bs, int min_size);
+int qcow2_grow_l1_table(BlockDriverState *bs, int min_size, bool exact_size);
 void qcow2_l2_cache_reset(BlockDriverState *bs);
 int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset);
 void qcow2_encrypt_sectors(BDRVQcowState *s, int64_t sector_num,
-- 
1.7.1




[Qemu-devel] Re: [PATCH] Add support for async page fault to qemu

2010-10-18 Thread Gleb Natapov
On Mon, Oct 18, 2010 at 05:48:16PM +0200, Juan Quintela wrote:
 Gleb Natapov g...@redhat.com wrote:
  Add save/restore of MSR for migration and cpuid bit.
 
 It is there a way to test if async page faults are in use?
 if so, we can add a subsection instead of changing the cpuversion.
 
Yeah. Good idea. Forgot about our cool new subsection feature.

--
Gleb.



Re: Testing of russian keymap (was Re: [Qemu-devel] [PATCH] fix '/' and '|' on russian keymap)

2010-10-18 Thread Oleg Sadov
Sorry for delay with answer -- vacations time without e-mail account
access.

07/10/2010 08:38 +0400, Michael Tokarev wrote:
 06.10.2010 23:56, Eduardo Habkost wrote:
  
  Anybody using a russian keyboard layout who can test this change and
  confirm it works as expected?
 
 I can perform such a testing - in theory.  But in practice, I was never
 able to figure out this -k $lang stuff, -- neither in qemu nor in other
 apps like rdesktop and the like.
 
 What I usually do is to explicitly set en-us keyboard for applications
 that are too smart and tries to guess right keyboard from env.
 variables such as $LANG.

 The reason is that after specifying ru keyboard, I can't use latin
 chars anymore, and can type only using cyrillic.  Since cyrillic
 layout does not have any latin char, imagine how to type, say, a
 path name (even C: drive in windows).

 All modern OSes nowadays have a way to switch between keyboard layouts
 dynamically - this is done internally in the operating system.  So,
 basically, I've no idea what this -k $foo stuff is used for to start
 with ;)

 Care to explain please?  Oleg?  :)

I don't understand reasons for such locale-default keyboard settings for
qemu too, but may be it's useful for someone...

 Thanks!
 
 /mjt

Regards!
--Oleg




[Qemu-devel] [ANNOUNCE] Release 0.13.0 of QEMU

2010-10-18 Thread Anthony Liguori

The QEMU team is pleased to announce the availability of the 0.13.0 release.

This release consists of over 2,500 commits from 145 contributors.

Some major features were added in this release including:

 - vhost-net: kernel-accelerating network backend for virtio devices 
(using KVM)

 - qmp: significant improvements covering most monitor commands
 - vnc: introduction of new encodings that dramatically improve 
bandwidth (part of GSoC project)
 - ivshmem: new shared memory device allowing multiple guests to share 
a memory region

 - mips: introduction of fulong mini-pc
 - virtio-9p: introduction of a paravirtual file system passthrough 
mechanism

 - hpet: many enhancements
 - target-s390: support for s390 usermode emulation
 - many more features and bug fixes

It can be downloaded from Savannah at:

http://download.savannah.gnu.org/releases/qemu/qemu-0.13.0.tar.gz

For detailed Changelogs, please consult the revision history in git.

On behalf of the QEMU team, I'd like to thank everyone who contributed
to make this release happen!

A special note about QMP support in 0.13.0.  QMP is still considered 
experimental in 0.13.0.  There are no plans to change the protocol in an 
incompatible way but there are likely to be missing features.


Regards,

Anthony Liguori



Re: [Qemu-devel] [PATCH 1/2] pci: Automatically patch PCI device id in PCI ROM

2010-10-18 Thread Stefan Weil

Am 18.10.2010 17:50, schrieb Gerd Hoffmann:

On 10/18/10 15:30, Gerd Hoffmann wrote:

  Hi,


When following this argumentation the vendor id sanity check shouldn't
be there in the first place ;)


The sanity check is simply there because I had no test case
which patches the vendor id. How could I test with vga bios?


No trivial way as the vgabios needs to be patched to handle that.


patchrom branches available now:

http://cgit.freedesktop.org/~kraxel/vgabios/log/
http://cgit.freedesktop.org/spice/qemu/log/?h=patchrom

very short instructions:

(1) fetch+compile vgabios, copy new vgabios-pci binary
so qemu can find it.
(2) fetch qemu, apply/merge id patching, compile qemu
(3) both standard and vmware vga should happily work
with the same vgabios binary now, including vesa
graphic modes.

cheers,
  Gerd



Hi Gerd,

a new patch which also modifies the vendor id will follow
immediately. Perhaps you can try it with your modified vga bios.

Cheers,
Stefan




[Qemu-devel] [PATCH 1/2] pci: Automatically patch PCI vendor id and device id in PCI ROM

2010-10-18 Thread Stefan Weil
PCI devices with different vendor or device ids sometimes share
the same rom code. Only the ids and the checksum
differs in a boot rom for such devices.

The i825xx ethernet controller family is a typical example
which is implemented in hw/eepro100.c. It uses at least
3 different device ids, so normally 3 boot roms would be needed.

By automatically patching vendor id and device id (and the checksum)
in qemu, all emulated family members can share the same boot rom.

VGA bios roms are another example with different vendor and device ids.

v2:

* Patch also the vendor id (and remove the sanity check for vendor id).

Cc: Gerd Hoffmann kra...@redhat.com
Cc: Markus Armbruster arm...@redhat.com
Cc: Michael S. Tsirkin m...@redhat.com
Signed-off-by: Stefan Weil w...@mail.berlios.de
---
 hw/pci.c |   58 ++
 1 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 1280d4d..139eb24 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -1797,6 +1797,62 @@ static void pci_map_option_rom(PCIDevice *pdev, int 
region_num, pcibus_t addr, p
 cpu_register_physical_memory(addr, size, pdev-rom_offset);
 }
 
+/* Patch the PCI vendor and device ids in a PCI rom image if necessary.
+   This is needed for an option rom which is used for more than one device. */
+static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr, int size)
+{
+uint16_t vendor_id;
+uint16_t device_id;
+uint16_t rom_vendor_id;
+uint16_t rom_device_id;
+uint16_t rom_magic;
+uint16_t pcir_offset;
+uint8_t checksum;
+
+/* Words in rom data are little endian (like in PCI configuration),
+   so they can be read / written with pci_get_word / pci_set_word. */
+
+/* Only a valid rom will be patched. */
+rom_magic = pci_get_word(ptr);
+if (rom_magic != 0xaa55) {
+PCI_DPRINTF(Bad ROM magic %04x\n, rom_magic);
+return;
+}
+pcir_offset = pci_get_word(ptr + 0x18);
+if (pcir_offset + 8 = size || memcmp(ptr + pcir_offset, PCIR, 4)) {
+PCI_DPRINTF(Bad PCIR offset 0x%x or signature\n, pcir_offset);
+return;
+}
+
+vendor_id = pci_get_word(pdev-config + PCI_VENDOR_ID);
+device_id = pci_get_word(pdev-config + PCI_DEVICE_ID);
+rom_vendor_id = pci_get_word(ptr + pcir_offset + 4);
+rom_device_id = pci_get_word(ptr + pcir_offset + 6);
+
+PCI_DPRINTF(ROM id %04x%04x / PCI id %04x%04x\n,
+vendor_id, device_id, rom_vendor_id, rom_device_id);
+
+checksum = ptr[6];
+
+if (vendor_id != rom_vendor_id) {
+/* Patch vendor id and checksum (at offset 6 for etherboot roms). */
+checksum += (uint8_t)rom_vendor_id + (uint8_t)(rom_vendor_id  8);
+checksum -= (uint8_t)vendor_id + (uint8_t)(vendor_id  8);
+PCI_DPRINTF(ROM checksum %02x / %02x\n, ptr[6], checksum);
+ptr[6] = checksum;
+pci_set_word(ptr + pcir_offset + 4, vendor_id);
+}
+
+if (device_id != rom_device_id) {
+/* Patch device id and checksum (at offset 6 for etherboot roms). */
+checksum += (uint8_t)rom_device_id + (uint8_t)(rom_device_id  8);
+checksum -= (uint8_t)device_id + (uint8_t)(device_id  8);
+PCI_DPRINTF(ROM checksum %02x / %02x\n, ptr[6], checksum);
+ptr[6] = checksum;
+pci_set_word(ptr + pcir_offset + 6, device_id);
+}
+}
+
 /* Add an option rom for the device */
 static int pci_add_option_rom(PCIDevice *pdev)
 {
@@ -1849,6 +1905,8 @@ static int pci_add_option_rom(PCIDevice *pdev)
 load_image(path, ptr);
 qemu_free(path);
 
+pci_patch_ids(pdev, ptr, size);
+
 pci_register_bar(pdev, PCI_ROM_SLOT, size,
  0, pci_map_option_rom);
 
-- 
1.7.1




[Qemu-devel] Re: [PATCH 1/2] pci: Automatically patch PCI vendor id and device id in PCI ROM

2010-10-18 Thread Michael S. Tsirkin
On Mon, Oct 18, 2010 at 07:55:11PM +0200, Stefan Weil wrote:
 PCI devices with different vendor or device ids sometimes share
 the same rom code. Only the ids and the checksum
 differs in a boot rom for such devices.
 
 The i825xx ethernet controller family is a typical example
 which is implemented in hw/eepro100.c. It uses at least
 3 different device ids, so normally 3 boot roms would be needed.
 
 By automatically patching vendor id and device id (and the checksum)
 in qemu, all emulated family members can share the same boot rom.
 
 VGA bios roms are another example with different vendor and device ids.
 
 v2:
 
 * Patch also the vendor id (and remove the sanity check for vendor id).
 
 Cc: Gerd Hoffmann kra...@redhat.com
 Cc: Markus Armbruster arm...@redhat.com
 Cc: Michael S. Tsirkin m...@redhat.com
 Signed-off-by: Stefan Weil w...@mail.berlios.de
 ---
  hw/pci.c |   58 ++
  1 files changed, 58 insertions(+), 0 deletions(-)
 
 diff --git a/hw/pci.c b/hw/pci.c
 index 1280d4d..139eb24 100644
 --- a/hw/pci.c
 +++ b/hw/pci.c
 @@ -1797,6 +1797,62 @@ static void pci_map_option_rom(PCIDevice *pdev, int 
 region_num, pcibus_t addr, p
  cpu_register_physical_memory(addr, size, pdev-rom_offset);
  }
  
 +/* Patch the PCI vendor and device ids in a PCI rom image if necessary.
 +   This is needed for an option rom which is used for more than one device. 
 */
 +static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr, int size)

let's return an error code on malformed roms so management can detect errors?



[Qemu-devel] [PATCH] [virtio-9p] Add support to v9fs_string_alloc_printf() for handling %lu.

2010-10-18 Thread Venkateswararao Jujjuri (JV)
Signed-off-by: Venkateswararao Jujjuri jv...@linux.vnet.ibm.com
---
 hw/virtio-9p.c |   17 +
 1 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 3b2d49c..9575698 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -325,6 +325,14 @@ static int number_to_string(void *arg, char type)
 } while (num);
 break;
 }
+case 'U': {
+unsigned long num = *(unsigned long *)arg;
+do {
+ret++;
+num = num/10;
+} while (num);
+break;
+}
 default:
 printf(Number_to_string: Unknown number format\n);
 return -1;
@@ -342,6 +350,7 @@ v9fs_string_alloc_printf(char **strp, const char *fmt, 
va_list ap)
 int nr_args = 0;
 char *arg_char_ptr;
 unsigned int arg_uint;
+unsigned long arg_ulong;
 
 /* Find the number of %'s that denotes an argument */
 for (iter = strstr(iter, %); iter; iter = strstr(iter, %)) {
@@ -367,6 +376,14 @@ v9fs_string_alloc_printf(char **strp, const char *fmt, 
va_list ap)
 arg_uint = va_arg(ap2, unsigned int);
 len += number_to_string((void *)arg_uint, 'u');
 break;
+case 'l':
+if (*++iter == 'u') {
+arg_ulong = va_arg(ap2, unsigned long);
+len += number_to_string((void *)arg_ulong, 'U');
+} else {
+return -1;
+}
+break;
 case 's':
 arg_char_ptr = va_arg(ap2, char *);
 len += strlen(arg_char_ptr);
-- 
1.6.5.2




Re: [Qemu-devel] [PATCH] Don't call cpu_synchronize_state() from machine init.

2010-10-18 Thread Scott Wood
On Mon, Oct 04, 2010 at 04:15:58PM -0500, Scott Wood wrote:
 This will deadlock when the I/O thread is used, since the
 CPU thread is blocked waiting for qemu_system_ready.
 
 The synchronization is unnecessary since this is before
 cpu_synchronize_all_post_init().
 
 Signed-off-by: Scott Wood scottw...@freescale.com
 ---
  hw/ppc440_bamboo.c |2 --
  hw/ppce500_mpc8544ds.c |2 --
  2 files changed, 0 insertions(+), 4 deletions(-)

Any comment on/objection to this patch?

-Scott

 
 diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
 index 34ddf45..645e84f 100644
 --- a/hw/ppc440_bamboo.c
 +++ b/hw/ppc440_bamboo.c
 @@ -156,8 +156,6 @@ static void bamboo_init(ram_addr_t ram_size,
  exit(1);
  }
  
 -cpu_synchronize_state(env);
 -
  /* Set initial guest state. */
  env-gpr[1] = (1620) - 8;
  env-gpr[3] = FDT_ADDR;
 diff --git a/hw/ppce500_mpc8544ds.c b/hw/ppce500_mpc8544ds.c
 index 1422fad..f7e9465 100644
 --- a/hw/ppce500_mpc8544ds.c
 +++ b/hw/ppce500_mpc8544ds.c
 @@ -269,8 +269,6 @@ static void mpc8544ds_init(ram_addr_t ram_size,
  exit(1);
  }
  
 -cpu_synchronize_state(env);
 -
  /* Set initial guest state. */
  env-gpr[1] = (1620) - 8;
  env-gpr[3] = dt_base;
 -- 
 1.7.0.4
 
 




[Qemu-devel] Re: [PATCH 1/3] Make kvm64 the default cpu model when kvm_enabled()

2010-10-18 Thread Anthony Liguori

On 10/18/2010 03:22 AM, Roedel, Joerg wrote:

(Sorry for the late reply)

On Thu, Oct 07, 2010 at 08:48:06AM -0400, Anthony Liguori wrote:
   

On 10/07/2010 03:42 AM, Roedel, Joerg wrote:
 

On Wed, Oct 06, 2010 at 03:24:59PM -0400, Anthony Liguori wrote:

   

+qemu_compat_version = machine-compat_version;
+
if (display_type == DT_NOGRAPHIC) {
if (default_parallel)
add_device_config(DEV_PARALLEL, null);
--
1.7.0.4


 

Looks fine to me, given CPUs are not in qdev. Anthony?


   

The idea is fine, but why not just add the default CPU to the machine
description?

 

If I remember correctly the reason was that the machine description was
not accessible in the cpuid initialization path because it is a function
local variable.
   

Not tested at all but I think the attached patch addresses it in a
pretty nice way.

There's a couple ways you could support your patch on top of this.  You
could add a kvm_cpu_model to the machine structure that gets defaulted
too if kvm_enabled().  You could also introduce a new KVM machine type
that gets defaulted to if no explicit machine is specified.
 

I had something similar in mind but then I realized that we need at
least a cpu_model and a cpu_model_kvm to distinguish between the TCG and
the KVM case.
   


I would think that having different default machines for KVM and TCG 
would be a better solution.



Further the QEMUMachine data structure is used for all architectures in
QEMU and the model-names only make sense for x86.


SPARC uses cpu_model too FWIW.  I believe Blue Swirl has even discussed 
using a feature-format similar to how x86 does it for SPARC CPUs.


Regards,

Anthony Liguori


  So I decided for the
comapt-version way (which doesn't mean I object against this one ;-) )

Joerg

   

 From d2370c88cef4b07d48ba3c4804e35ae2db8db7c0 Mon Sep 17 00:00:00 2001
From: Anthony Liguorialigu...@us.ibm.com
Date: Thu, 7 Oct 2010 07:43:42 -0500
Subject: [PATCH] machine: make default cpu model part of machine structure

Signed-off-by: Anthony Liguorialigu...@us.ibm.com

diff --git a/hw/boards.h b/hw/boards.h
index 6f0f0d7..8c6ef27 100644
--- a/hw/boards.h
+++ b/hw/boards.h
@@ -16,6 +16,7 @@ typedef struct QEMUMachine {
  const char *name;
  const char *alias;
  const char *desc;
+const char *cpu_model;
  QEMUMachineInitFunc *init;
  int use_scsi;
  int max_cpus;
diff --git a/hw/pc.c b/hw/pc.c
index 69b13bf..0826107 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -866,14 +866,6 @@ void pc_cpus_init(const char *cpu_model)
  int i;

  /* init CPUs */
-if (cpu_model == NULL) {
-#ifdef TARGET_X86_64
-cpu_model = qemu64;
-#else
-cpu_model = qemu32;
-#endif
-}
-
  for(i = 0; i  smp_cpus; i++) {
  pc_new_cpu(cpu_model);
  }
diff --git a/hw/pc_piix.c b/hw/pc_piix.c
index 12359a7..919b4d6 100644
--- a/hw/pc_piix.c
+++ b/hw/pc_piix.c
@@ -204,17 +204,22 @@ static void pc_init_isa(ram_addr_t ram_size,
  const char *initrd_filename,
  const char *cpu_model)
  {
-if (cpu_model == NULL)
-cpu_model = 486;
  pc_init1(ram_size, boot_device,
   kernel_filename, kernel_cmdline,
   initrd_filename, cpu_model, 0);
  }

+#ifdef TARGET_X86_64
+#define DEF_CPU_MODEL qemu64
+#else
+#define DEF_CPU_MODEL qemu32
+#endif
+
  static QEMUMachine pc_machine = {
  .name = pc-0.13,
  .alias = pc,
  .desc = Standard PC,
+.cpu_model = DEF_CPU_MODEL,
  .init = pc_init_pci,
  .max_cpus = 255,
  .is_default = 1,
@@ -223,6 +228,7 @@ static QEMUMachine pc_machine = {
  static QEMUMachine pc_machine_v0_12 = {
  .name = pc-0.12,
  .desc = Standard PC,
+.cpu_model = DEF_CPU_MODEL,
  .init = pc_init_pci,
  .max_cpus = 255,
  .compat_props = (GlobalProperty[]) {
@@ -242,6 +248,7 @@ static QEMUMachine pc_machine_v0_12 = {
  static QEMUMachine pc_machine_v0_11 = {
  .name = pc-0.11,
  .desc = Standard PC, qemu 0.11,
+.cpu_model = DEF_CPU_MODEL,
  .init = pc_init_pci,
  .max_cpus = 255,
  .compat_props = (GlobalProperty[]) {
@@ -277,6 +284,7 @@ static QEMUMachine pc_machine_v0_11 = {
  static QEMUMachine pc_machine_v0_10 = {
  .name = pc-0.10,
  .desc = Standard PC, qemu 0.10,
+.cpu_model = DEF_CPU_MODEL,
  .init = pc_init_pci,
  .max_cpus = 255,
  .compat_props = (GlobalProperty[]) {
@@ -324,6 +332,7 @@ static QEMUMachine pc_machine_v0_10 = {
  static QEMUMachine isapc_machine = {
  .name = isapc,
  .desc = ISA-only PC,
+.cpu_model = 486,
  .init = pc_init_isa,
  .max_cpus = 1,
  };
diff --git a/vl.c b/vl.c
index df414ef..3a55cc8 100644
--- a/vl.c
+++ b/vl.c
@@ -2904,6 +2904,10 @@ int main(int argc, char **argv, char **envp)
  }
  qemu_add_globals();

+if (cpu_model == NULL) {
+cpu_model = machine-cpu_model;
+}
+
  

Re: [Qemu-devel] [PATCH 1/2] pci: Automatically patch PCI device id in PCI ROM

2010-10-18 Thread Anthony Liguori

On 10/18/2010 05:09 AM, Gerd Hoffmann wrote:

On 10/15/10 23:05, Anthony Liguori wrote:

On 10/15/2010 03:51 PM, Stefan Weil wrote:

PCI device with different device ids sometimes share
the same rom code. Only the device id and the checksum
differ in a boot rom for such devices.


BTW, SeaBIOS doesn't reject ROMs when they're loaded via rombar, only
when they're loaded via romfile.


SeaBIOS rejects them when loaded from the rom bar and doesn't reject 
them when loaded via fw_cfg.


What I meant was, rombar=0 in qdev.  Sometimes my fingers don't work the 
same way my brain does :-)


Using the rom bar is the prefered way though, fw_cfg is only there for 
compatibility with older versions.



Maybe it's better to use fw_cfg to explicitly tell SeaBIOS to ignore the
PCI device id in the rom header for a certain device?


Patching the rom is fine IMHO.  Why create + use a separate 
communication path when we can use a much simpler approach?


How does this interact with PCI device passthrough?

We clearly can't patch in that case whereas if we had a hint to SeaBIOS, 
it would still work.


Regards,

Anthony Liguori


cheers,
  Gerd






Re: [Qemu-devel] Re: [PATCH 1/2] pci: Automatically patch PCI vendor id and device id in PCI ROM

2010-10-18 Thread Anthony Liguori

On 10/18/2010 12:58 PM, Michael S. Tsirkin wrote:

On Mon, Oct 18, 2010 at 07:55:11PM +0200, Stefan Weil wrote:
   

PCI devices with different vendor or device ids sometimes share
the same rom code. Only the ids and the checksum
differs in a boot rom for such devices.

The i825xx ethernet controller family is a typical example
which is implemented in hw/eepro100.c. It uses at least
3 different device ids, so normally 3 boot roms would be needed.

By automatically patching vendor id and device id (and the checksum)
in qemu, all emulated family members can share the same boot rom.

VGA bios roms are another example with different vendor and device ids.

v2:

* Patch also the vendor id (and remove the sanity check for vendor id).

Cc: Gerd Hoffmannkra...@redhat.com
Cc: Markus Armbrusterarm...@redhat.com
Cc: Michael S. Tsirkinm...@redhat.com
Signed-off-by: Stefan Weilw...@mail.berlios.de
---
  hw/pci.c |   58 ++
  1 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 1280d4d..139eb24 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -1797,6 +1797,62 @@ static void pci_map_option_rom(PCIDevice *pdev, int 
region_num, pcibus_t addr, p
  cpu_register_physical_memory(addr, size, pdev-rom_offset);
  }

+/* Patch the PCI vendor and device ids in a PCI rom image if necessary.
+   This is needed for an option rom which is used for more than one device. */
+static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr, int size)
 

let's return an error code on malformed roms so management can detect errors?
   


A bad/missing PnP header does not mean it's an invalid ROM.

Regards,

Anthony Liguori





Re: [Qemu-devel] [PATCH 1/2] pci: Automatically patch PCI vendor id and device id in PCI ROM

2010-10-18 Thread Anthony Liguori

On 10/18/2010 12:55 PM, Stefan Weil wrote:

PCI devices with different vendor or device ids sometimes share
the same rom code. Only the ids and the checksum
differs in a boot rom for such devices.

The i825xx ethernet controller family is a typical example
which is implemented in hw/eepro100.c. It uses at least
3 different device ids, so normally 3 boot roms would be needed.

By automatically patching vendor id and device id (and the checksum)
in qemu, all emulated family members can share the same boot rom.

VGA bios roms are another example with different vendor and device ids.

v2:

* Patch also the vendor id (and remove the sanity check for vendor id).

Cc: Gerd Hoffmannkra...@redhat.com
Cc: Markus Armbrusterarm...@redhat.com
Cc: Michael S. Tsirkinm...@redhat.com
Signed-off-by: Stefan Weilw...@mail.berlios.de
   


I get very nervous about patching a ROM.  Who's to say that the ROM 
doesn't somehow depend on the contents of its header?  Maybe it has an 
internal CRC built into it or something like that.


Regards,

Anthony Liguori


---
  hw/pci.c |   58 ++
  1 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 1280d4d..139eb24 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -1797,6 +1797,62 @@ static void pci_map_option_rom(PCIDevice *pdev, int 
region_num, pcibus_t addr, p
  cpu_register_physical_memory(addr, size, pdev-rom_offset);
  }

+/* Patch the PCI vendor and device ids in a PCI rom image if necessary.
+   This is needed for an option rom which is used for more than one device. */
+static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr, int size)
+{
+uint16_t vendor_id;
+uint16_t device_id;
+uint16_t rom_vendor_id;
+uint16_t rom_device_id;
+uint16_t rom_magic;
+uint16_t pcir_offset;
+uint8_t checksum;
+
+/* Words in rom data are little endian (like in PCI configuration),
+   so they can be read / written with pci_get_word / pci_set_word. */
+
+/* Only a valid rom will be patched. */
+rom_magic = pci_get_word(ptr);
+if (rom_magic != 0xaa55) {
+PCI_DPRINTF(Bad ROM magic %04x\n, rom_magic);
+return;
+}
+pcir_offset = pci_get_word(ptr + 0x18);
+if (pcir_offset + 8= size || memcmp(ptr + pcir_offset, PCIR, 4)) {
+PCI_DPRINTF(Bad PCIR offset 0x%x or signature\n, pcir_offset);
+return;
+}
+
+vendor_id = pci_get_word(pdev-config + PCI_VENDOR_ID);
+device_id = pci_get_word(pdev-config + PCI_DEVICE_ID);
+rom_vendor_id = pci_get_word(ptr + pcir_offset + 4);
+rom_device_id = pci_get_word(ptr + pcir_offset + 6);
+
+PCI_DPRINTF(ROM id %04x%04x / PCI id %04x%04x\n,
+vendor_id, device_id, rom_vendor_id, rom_device_id);
+
+checksum = ptr[6];
+
+if (vendor_id != rom_vendor_id) {
+/* Patch vendor id and checksum (at offset 6 for etherboot roms). */
+checksum += (uint8_t)rom_vendor_id + (uint8_t)(rom_vendor_id  8);
+checksum -= (uint8_t)vendor_id + (uint8_t)(vendor_id  8);
+PCI_DPRINTF(ROM checksum %02x / %02x\n, ptr[6], checksum);
+ptr[6] = checksum;
+pci_set_word(ptr + pcir_offset + 4, vendor_id);
+}
+
+if (device_id != rom_device_id) {
+/* Patch device id and checksum (at offset 6 for etherboot roms). */
+checksum += (uint8_t)rom_device_id + (uint8_t)(rom_device_id  8);
+checksum -= (uint8_t)device_id + (uint8_t)(device_id  8);
+PCI_DPRINTF(ROM checksum %02x / %02x\n, ptr[6], checksum);
+ptr[6] = checksum;
+pci_set_word(ptr + pcir_offset + 6, device_id);
+}
+}
+
  /* Add an option rom for the device */
  static int pci_add_option_rom(PCIDevice *pdev)
  {
@@ -1849,6 +1905,8 @@ static int pci_add_option_rom(PCIDevice *pdev)
  load_image(path, ptr);
  qemu_free(path);

+pci_patch_ids(pdev, ptr, size);
+
  pci_register_bar(pdev, PCI_ROM_SLOT, size,
   0, pci_map_option_rom);

   





[Qemu-devel] Re: [PATCH] Don't call cpu_synchronize_state() from machine init.

2010-10-18 Thread Jan Kiszka
Am 18.10.2010 20:32, Scott Wood wrote:
 On Mon, Oct 04, 2010 at 04:15:58PM -0500, Scott Wood wrote:
 This will deadlock when the I/O thread is used, since the
 CPU thread is blocked waiting for qemu_system_ready.

 The synchronization is unnecessary since this is before
 cpu_synchronize_all_post_init().

 Signed-off-by: Scott Wood scottw...@freescale.com
 ---
  hw/ppc440_bamboo.c |2 --
  hw/ppce500_mpc8544ds.c |2 --
  2 files changed, 0 insertions(+), 4 deletions(-)
 
 Any comment on/objection to this patch?
 

Obviously correct, should get committed.

Acked-by: Jan Kiszka jan.kis...@siemens.com

Jan

 -Scott
 

 diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
 index 34ddf45..645e84f 100644
 --- a/hw/ppc440_bamboo.c
 +++ b/hw/ppc440_bamboo.c
 @@ -156,8 +156,6 @@ static void bamboo_init(ram_addr_t ram_size,
  exit(1);
  }
  
 -cpu_synchronize_state(env);
 -
  /* Set initial guest state. */
  env-gpr[1] = (1620) - 8;
  env-gpr[3] = FDT_ADDR;
 diff --git a/hw/ppce500_mpc8544ds.c b/hw/ppce500_mpc8544ds.c
 index 1422fad..f7e9465 100644
 --- a/hw/ppce500_mpc8544ds.c
 +++ b/hw/ppce500_mpc8544ds.c
 @@ -269,8 +269,6 @@ static void mpc8544ds_init(ram_addr_t ram_size,
  exit(1);
  }
  
 -cpu_synchronize_state(env);
 -
  /* Set initial guest state. */
  env-gpr[1] = (1620) - 8;
  env-gpr[3] = dt_base;
 -- 
 1.7.0.4


 
 
 




signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH 1/2] pci: Automatically patch PCI vendor id and device id in PCI ROM

2010-10-18 Thread Anthony Liguori

On 10/18/2010 01:44 PM, Anthony Liguori wrote:

On 10/18/2010 12:55 PM, Stefan Weil wrote:

PCI devices with different vendor or device ids sometimes share
the same rom code. Only the ids and the checksum
differs in a boot rom for such devices.

The i825xx ethernet controller family is a typical example
which is implemented in hw/eepro100.c. It uses at least
3 different device ids, so normally 3 boot roms would be needed.

By automatically patching vendor id and device id (and the checksum)
in qemu, all emulated family members can share the same boot rom.

VGA bios roms are another example with different vendor and device ids.

v2:

* Patch also the vendor id (and remove the sanity check for vendor id).

Cc: Gerd Hoffmannkra...@redhat.com
Cc: Markus Armbrusterarm...@redhat.com
Cc: Michael S. Tsirkinm...@redhat.com
Signed-off-by: Stefan Weilw...@mail.berlios.de


I get very nervous about patching a ROM.  Who's to say that the ROM 
doesn't somehow depend on the contents of its header?  Maybe it has an 
internal CRC built into it or something like that.


As part of PMM, ROMs typically reduce their size by decompressing and 
removing code or something of that nature and then rewrite themselves in 
scratch RAM.  The BIOS then copies the resulting ROM (using the ROM size 
in the base header as an indication of how much to copy) into the option 
ROM space.


So the likelihood of depending on the contents of the header seems 
non-trivial to me.


Regards,

Anthony Liguori


Regards,

Anthony Liguori


---
  hw/pci.c |   58 
++

  1 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 1280d4d..139eb24 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -1797,6 +1797,62 @@ static void pci_map_option_rom(PCIDevice 
*pdev, int region_num, pcibus_t addr, p

  cpu_register_physical_memory(addr, size, pdev-rom_offset);
  }

+/* Patch the PCI vendor and device ids in a PCI rom image if necessary.
+   This is needed for an option rom which is used for more than one 
device. */

+static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr, int size)
+{
+uint16_t vendor_id;
+uint16_t device_id;
+uint16_t rom_vendor_id;
+uint16_t rom_device_id;
+uint16_t rom_magic;
+uint16_t pcir_offset;
+uint8_t checksum;
+
+/* Words in rom data are little endian (like in PCI configuration),
+   so they can be read / written with pci_get_word / 
pci_set_word. */

+
+/* Only a valid rom will be patched. */
+rom_magic = pci_get_word(ptr);
+if (rom_magic != 0xaa55) {
+PCI_DPRINTF(Bad ROM magic %04x\n, rom_magic);
+return;
+}
+pcir_offset = pci_get_word(ptr + 0x18);
+if (pcir_offset + 8= size || memcmp(ptr + pcir_offset, PCIR, 
4)) {
+PCI_DPRINTF(Bad PCIR offset 0x%x or signature\n, 
pcir_offset);

+return;
+}
+
+vendor_id = pci_get_word(pdev-config + PCI_VENDOR_ID);
+device_id = pci_get_word(pdev-config + PCI_DEVICE_ID);
+rom_vendor_id = pci_get_word(ptr + pcir_offset + 4);
+rom_device_id = pci_get_word(ptr + pcir_offset + 6);
+
+PCI_DPRINTF(ROM id %04x%04x / PCI id %04x%04x\n,
+vendor_id, device_id, rom_vendor_id, rom_device_id);
+
+checksum = ptr[6];
+
+if (vendor_id != rom_vendor_id) {
+/* Patch vendor id and checksum (at offset 6 for etherboot 
roms). */
+checksum += (uint8_t)rom_vendor_id + 
(uint8_t)(rom_vendor_id  8);

+checksum -= (uint8_t)vendor_id + (uint8_t)(vendor_id  8);
+PCI_DPRINTF(ROM checksum %02x / %02x\n, ptr[6], checksum);
+ptr[6] = checksum;
+pci_set_word(ptr + pcir_offset + 4, vendor_id);
+}
+
+if (device_id != rom_device_id) {
+/* Patch device id and checksum (at offset 6 for etherboot 
roms). */
+checksum += (uint8_t)rom_device_id + 
(uint8_t)(rom_device_id  8);

+checksum -= (uint8_t)device_id + (uint8_t)(device_id  8);
+PCI_DPRINTF(ROM checksum %02x / %02x\n, ptr[6], checksum);
+ptr[6] = checksum;
+pci_set_word(ptr + pcir_offset + 6, device_id);
+}
+}
+
  /* Add an option rom for the device */
  static int pci_add_option_rom(PCIDevice *pdev)
  {
@@ -1849,6 +1905,8 @@ static int pci_add_option_rom(PCIDevice *pdev)
  load_image(path, ptr);
  qemu_free(path);

+pci_patch_ids(pdev, ptr, size);
+
  pci_register_bar(pdev, PCI_ROM_SLOT, size,
   0, pci_map_option_rom);









Re: Testing of russian keymap (was Re: [Qemu-devel] [PATCH] fix '/' and '|' on russian keymap)

2010-10-18 Thread Anthony Liguori

On 10/18/2010 12:30 PM, Oleg Sadov wrote:

I don't understand reasons for such locale-default keyboard settings for
qemu too, but may be it's useful for someone...
   


-k only exists to deal with crappy VNC clients.

If you use a good VNC client (like vinagre or virt-viewer) then you 
don't have to use -k.


Regards,

Anthony Liguori


Thanks!

/mjt
 

Regards!
--Oleg


   





Re: [Qemu-devel] Re: [PATCH 1/2] pci: Automatically patch PCI vendor id and device id in PCI ROM

2010-10-18 Thread Michael S. Tsirkin
On Mon, Oct 18, 2010 at 01:42:06PM -0500, Anthony Liguori wrote:
 +/* Patch the PCI vendor and device ids in a PCI rom image if necessary.
 +   This is needed for an option rom which is used for more than one 
 device. */
 +static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr, int size)
 let's return an error code on malformed roms so management can detect errors?
 
 A bad/missing PnP header does not mean it's an invalid ROM.

I don't see this as a generic capability - rather a specific
hack that helps reduce some duplication for eepro100 and friends.
As such, if we can't patch the id we know it's an invalid file.

-- 
MST



Re: [Qemu-devel] [PATCH 1/2] pci: Automatically patch PCI vendor id and device id in PCI ROM

2010-10-18 Thread Stefan Weil

Am 18.10.2010 20:53, schrieb Anthony Liguori:

On 10/18/2010 01:44 PM, Anthony Liguori wrote:

On 10/18/2010 12:55 PM, Stefan Weil wrote:

PCI devices with different vendor or device ids sometimes share
the same rom code. Only the ids and the checksum
differs in a boot rom for such devices.

The i825xx ethernet controller family is a typical example
which is implemented in hw/eepro100.c. It uses at least
3 different device ids, so normally 3 boot roms would be needed.

By automatically patching vendor id and device id (and the checksum)
in qemu, all emulated family members can share the same boot rom.

VGA bios roms are another example with different vendor and device ids.

v2:

* Patch also the vendor id (and remove the sanity check for vendor id).

Cc: Gerd Hoffmannkra...@redhat.com
Cc: Markus Armbrusterarm...@redhat.com
Cc: Michael S. Tsirkinm...@redhat.com
Signed-off-by: Stefan Weilw...@mail.berlios.de


I get very nervous about patching a ROM.  Who's to say that the ROM 
doesn't somehow depend on the contents of its header?  Maybe it has 
an internal CRC built into it or something like that.


As part of PMM, ROMs typically reduce their size by decompressing and 
removing code or something of that nature and then rewrite themselves 
in scratch RAM.  The BIOS then copies the resulting ROM (using the ROM 
size in the base header as an indication of how much to copy) into the 
option ROM space.


So the likelihood of depending on the contents of the header seems 
non-trivial to me.


Regards,

Anthony Liguori


[snip]

Etherboot uses compressed code and always fixes the checksum by modifying
the byte at relative address 6, so for etherboot there is no problem.
The etherboot distribution even includes a perl script which can be used
to patch vendor/device ids. I thought about using that script in QEMU's
make but then decided against this alternate solution.

VGA bios seems to work, too (practical test still is missing).

What could happen for other kinds of roms? Either there is nothing
to patch (the 99 % standard case), or they work, or they don't work.
QEMU must only make sure that patching of the supported roms
with supported devices work.

Regards,

Stefan Weil




Re: [Qemu-devel] Re: [PATCH 1/2] pci: Automatically patch PCI vendor id and device id in PCI ROM

2010-10-18 Thread Stefan Weil

Am 18.10.2010 21:03, schrieb Michael S. Tsirkin:

On Mon, Oct 18, 2010 at 01:42:06PM -0500, Anthony Liguori wrote:
+/* Patch the PCI vendor and device ids in a PCI rom image if 
necessary.
+ This is needed for an option rom which is used for more than one 
device. */

+static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr, int size)
let's return an error code on malformed roms so management can 
detect errors?


A bad/missing PnP header does not mean it's an invalid ROM.


I don't see this as a generic capability - rather a specific
hack that helps reduce some duplication for eepro100 and friends.
As such, if we can't patch the id we know it's an invalid file.


There is already some kind of error feedback: the rom will not work.
For etherboot roms, booting from network won't work.

This is a qemu internal error, so more error handling is not needed.

Users who configure a device with their own rom file don't
need an id patch, and their rom data will not be patched
because they normally specify a rom file with correct ids.
For the rare case where they configure a rom with a wrong
id, their rom data will be patched (something they don't expect)
or not modified because of the sanity checks (then the rom
is ignored by the bios).

Maybe a more perfect solution would only patch the preconfigured
rom files but not user configured files, but I don't think we
need this degree of perfection.

Regards,
Stefan




Re: [Qemu-devel] Re: [PATCH 1/2] pci: Automatically patch PCI vendor id and device id in PCI ROM

2010-10-18 Thread Anthony Liguori

On 10/18/2010 02:03 PM, Michael S. Tsirkin wrote:

On Mon, Oct 18, 2010 at 01:42:06PM -0500, Anthony Liguori wrote:
   

+/* Patch the PCI vendor and device ids in a PCI rom image if necessary.
+   This is needed for an option rom which is used for more than one device. */
+static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr, int size)
 

let's return an error code on malformed roms so management can detect errors?
   

A bad/missing PnP header does not mean it's an invalid ROM.
 

I don't see this as a generic capability - rather a specific
hack that helps reduce some duplication for eepro100 and friends.
As such, if we can't patch the id we know it's an invalid file.
   


This code is unconditional in the pci option rom loading path.

If it's restricted to a qdev property that's defaulted to enabled for 
the eepro cards, that would be a reasonable argument to make.


Regards,

Anthony Liguori





Re: [Qemu-devel] Re: [PATCH 1/2] pci: Automatically patch PCI vendor id and device id in PCI ROM

2010-10-18 Thread Anthony Liguori

On 10/18/2010 02:36 PM, Stefan Weil wrote:

Maybe a more perfect solution would only patch the preconfigured
rom files but not user configured files, but I don't think we
need this degree of perfection.


Generally speaking, patching third-party code is not something that we 
should get in the habit of doing unless we're very very sure that it's 
okay and we have as many checks in place as possible to avoid bad things 
from happening.


There are so many bad things that can happen.  If attempted to support 
attestation in QEMU and prepopulated a virtual TPM with checksums from 
the BIOS and ROMs, when the virtual BIOS attempts to measure itself if 
we've patched the ROM underneath of it, then the measurements will fail.


In the very least, if we go this route, it has to be an optional feature.

Regards,

Anthony Liguori


Regards,
Stefan






Re: [Qemu-devel] Hitting 29 NIC limit

2010-10-18 Thread H. Peter Anvin
On 10/14/2010 05:57 AM, Anthony Liguori wrote:
 
 I've always been sceptical of this.  When physical systems have a large 
 number of NICs, it's via multiple functions, not a bunch of PCI bridges.
 

Actually a lot of multiport PCI cards are in fact single or dual NICs
behind PCI bridges.

-hpa



[Qemu-devel] [PULL] virtio-9p patches - Request for pull

2010-10-18 Thread Venkateswararao Jujjuri (JV)
The following changes since commit 38cc9b607f85017b095793cab6c129bc9844f441:
  Jindrich Makovicka (1):
issue snd_pcm_start() when capturing audio

are available in the git repository at:

  git://repo.or.cz/qemu/aliguori/jvrao.git for-anthony

Aneesh Kumar K.V (2):
  virtio-9p: Use layered xattr approach
  virtio-9p: Support mapped posix acl

Harsh Prateek Bora (1):
  [virtio-9p] Qemu 9p commandline options validity checks

M. Mohan Kumar (3):
  [virto-9p] Implement TLOCK
  qemu-virtio9p: Implement TGETLOCK
  qemu-virtio-9p: Implement TREADLINK operation for 9p2000.L

Sanchit Garg (1):
  [virtio-9p] Use preadv/pwritev instead of readv/writev

Sripathi Kodi (1):
  [virtio-9p] open should not return EBADF

Venkateswararao Jujjuri (JV) (3):
  [virtio-9p] Introduce server side TFSYNC/RFSYNC for dotl
  [virtio-9p] Ignore O_DIRECT hint from client.
  [virtio-9p] Add support to v9fs_string_alloc_printf() for handling %lu.

 Makefile.objs |3 +-
 fsdev/qemu-fsdev.c|   48 +---
 hw/file-op-9p.h   |   16 ++-
 hw/virtio-9p-debug.c  |   46 +++
 hw/virtio-9p-local.c  |  135 +---
 hw/virtio-9p-posix-acl.c  |  140 
 hw/virtio-9p-xattr-user.c |  109 
 hw/virtio-9p-xattr.c  |  156 ++
 hw/virtio-9p-xattr.h  |  103 +++
 hw/virtio-9p.c|  314 +
 hw/virtio-9p.h|   61 +
 11 files changed, 925 insertions(+), 206 deletions(-)
 create mode 100644 hw/virtio-9p-posix-acl.c
 create mode 100644 hw/virtio-9p-xattr-user.c
 create mode 100644 hw/virtio-9p-xattr.c




[Qemu-devel] [PATCH 1/2] Add drive_get_by_id

2010-10-18 Thread Ryan Harper
Add a function to find a drive by id string.

Signed-off-by: Ryan Harper ry...@us.ibm.com
---
 blockdev.c |   12 
 blockdev.h |1 +
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index ff7602b..a00b3fa 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -75,6 +75,18 @@ DriveInfo *drive_get(BlockInterfaceType type, int bus, int 
unit)
 return NULL;
 }
 
+DriveInfo *drive_get_by_id(const char *id)
+{
+DriveInfo *dinfo;
+
+QTAILQ_FOREACH(dinfo, drives, next) {
+if (strcmp(id, dinfo-id))
+continue;
+return dinfo;
+}
+return NULL;
+}
+
 int drive_get_max_bus(BlockInterfaceType type)
 {
 int max_bus;
diff --git a/blockdev.h b/blockdev.h
index 653affc..19c6915 100644
--- a/blockdev.h
+++ b/blockdev.h
@@ -38,6 +38,7 @@ DriveInfo *drive_get(BlockInterfaceType type, int bus, int 
unit);
 int drive_get_max_bus(BlockInterfaceType type);
 void drive_uninit(DriveInfo *dinfo);
 DriveInfo *drive_get_by_blockdev(BlockDriverState *bs);
+DriveInfo *drive_get_by_id(const char *id);
 
 QemuOpts *drive_add(const char *file, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
 DriveInfo *drive_init(QemuOpts *arg, int default_to_scsi, int *fatal_error);
-- 
1.6.3.3




[Qemu-devel] [PATCH 0/2] Decouple block device removal from device removal

2010-10-18 Thread Ryan Harper
This patch series decouples the detachment of a block device from the removal
of the backing pci-device.  Removal of a hotplugged pci device requires the
guest to respond before qemu tears down the block device. In some cases, the
guest may not respond leaving the guest with continued access to the block
device.  

The new monitor command, drive_unplug, will revoke a guests access to the
block device independently of the removal of the pci device.

The first patch adds a new drive find method, the second patch implements the
monitor command and block layer changes.

Signed-off-by: Ryan Harper ry...@us.ibm.com



[Qemu-devel] [PATCH 2/2] Fix Block Hotplug race with drive_unplug()

2010-10-18 Thread Ryan Harper
Block hot unplug is racy since the guest is required to acknowlege the ACPI
unplug event; this may not happen synchronously with the device removal command

This series aims to close a gap where by mgmt applications that assume the
block resource has been removed without confirming that the guest has
acknowledged the removal may re-assign the underlying device to a second guest
leading to data leakage.

This series introduces a new montor command to decouple asynchornous device
removal from restricting guest access to a block device.  We do this by creating
a new monitor command drive_unplug which maps to a bdrv_unplug() command which
does a bdrv_flush() and bdrv_close().  Once complete, subsequent IO is rejected
from the device and the guest will get IO errors but continue to function.

A subsequent device removal command can be issued to remove the device, to which
the guest may or maynot respond, but as long as the unplugged bit is set, no IO
will be sumbitted.

Signed-off-by: Ryan Harper ry...@us.ibm.com
---
 block.c |6 ++
 block.h |1 +
 blockdev.c  |   26 ++
 blockdev.h  |1 +
 hmp-commands.hx |   15 +++
 5 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index a19374d..9fedb27 100644
--- a/block.c
+++ b/block.c
@@ -1328,6 +1328,12 @@ void bdrv_set_removable(BlockDriverState *bs, int 
removable)
 }
 }
 
+void bdrv_unplug(BlockDriverState *bs)
+{
+bdrv_flush(bs);
+bdrv_close(bs);
+}
+
 int bdrv_is_removable(BlockDriverState *bs)
 {
 return bs-removable;
diff --git a/block.h b/block.h
index 5f64380..732f63e 100644
--- a/block.h
+++ b/block.h
@@ -171,6 +171,7 @@ void bdrv_set_on_error(BlockDriverState *bs, 
BlockErrorAction on_read_error,
BlockErrorAction on_write_error);
 BlockErrorAction bdrv_get_on_error(BlockDriverState *bs, int is_read);
 void bdrv_set_removable(BlockDriverState *bs, int removable);
+void bdrv_unplug(BlockDriverState *bs);
 int bdrv_is_removable(BlockDriverState *bs);
 int bdrv_is_read_only(BlockDriverState *bs);
 int bdrv_is_sg(BlockDriverState *bs);
diff --git a/blockdev.c b/blockdev.c
index a00b3fa..da0b256 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -609,3 +609,29 @@ int do_change_block(Monitor *mon, const char *device,
 }
 return monitor_read_bdrv_key_start(mon, bs, NULL, NULL);
 }
+
+int do_drive_unplug(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+DriveInfo *dinfo;
+BlockDriverState *bs;
+const char *id;
+
+if (!qdict_haskey(qdict, id)) {
+qerror_report(QERR_MISSING_PARAMETER, id);
+return -1;
+}
+
+id = qdict_get_str(qdict, id);
+dinfo = drive_get_by_id(id);
+if (!dinfo) {
+qerror_report(QERR_DEVICE_NOT_FOUND, id);
+return -1;
+}
+
+/* mark block device unplugged */
+bs = dinfo-bdrv;
+bdrv_unplug(bs);
+
+return 0;
+}
+ 
diff --git a/blockdev.h b/blockdev.h
index 19c6915..ecb9ac8 100644
--- a/blockdev.h
+++ b/blockdev.h
@@ -52,5 +52,6 @@ int do_eject(Monitor *mon, const QDict *qdict, QObject 
**ret_data);
 int do_block_set_passwd(Monitor *mon, const QDict *qdict, QObject **ret_data);
 int do_change_block(Monitor *mon, const char *device,
 const char *filename, const char *fmt);
+int do_drive_unplug(Monitor *mon, const QDict *qdict, QObject **ret_data);
 
 #endif
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 81999aa..7a32a2e 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -68,6 +68,21 @@ Eject a removable medium (use -f to force it).
 ETEXI
 
 {
+.name   = drive_unplug,
+.args_type  = id:s,
+.params = device,
+.help   = unplug block device,
+.user_print = monitor_user_noop,
+.mhandler.cmd_new = do_drive_unplug,
+},
+
+STEXI
+...@item unplug @var{device}
+...@findex unplug
+Unplug block device.
+ETEXI
+
+{
 .name   = change,
 .args_type  = device:B,target:F,arg:s?,
 .params = device filename [format],
-- 
1.6.3.3




Re: [Qemu-devel] [PATCH 0/7] ATAPI CDROM passthrough v5

2010-10-18 Thread Alexander Graf

On 30.08.2009, at 02:14, Anthony Liguori wrote:

 Carl-Daniel Hailfinger wrote:
 The guest can also mess up other devices with the help of specially
 crafted firmware. So even if the user does not care about the effects on
 a particular device, a firmware upgrade might affect other devices
 (which are not used by Qemu in any way) as well.
 
 Please be more specific.  How is this any different than PCI passthrough with 
 VT-d or USB passthrough?
 
 As a result, this is
 essentially a break out of qemu or DoS the machine under certain
 conditions feature. If that particular side effect / feature is
 documented, users who read the documentation won't get any nasty surprises.
  
 
 A user will get a really nasty surprise if they think they can use a flag or 
 rely on QEMU to prevent a VM from doing something nasty with a device.  If 
 they have this feeling of security, they're likely to chmod the device to 
 allow unprivileged users to access it.
 
 But how a device handles ATAPI commands is totally up to the device.  If you 
 issue the wrong sequence, I'm sure there are devices out there that totally 
 hose themselves.  Are you absolutely confident that every ATAPI device out 
 there is completely safe against hostile code provided that you simply 
 prevent the FW update commands?  I'm certainly not.

Ping?


Alex




Re: [Qemu-devel] Snapshots ide0-hd0 issue

2010-10-18 Thread Ubuntu Explorer
Thanks for your help.

But, after commenting out snapshot option, I still cannot save the VM state
into the ide0-hd0 block device.

Here is some more information about the problem.

I am trying to do the following
a. info block
shows virtio, ide0-hd0
b. savevm snapshot_name
c. info snapshots
Shows snapshot_name under virtio
d. commit ide0-hd0
e. quit
f. Check timestamp of ide0 file - no change. ( I assume that qemu would
write something to this file)
g. restart qemu.
h. info snapshots
i. No snapshots in virtio

I will try to run qemu in gdb mode to see why commit is not committing the
changes to the ide0-hd0 block device.
But any other information will be helpful as well. I have googled a lot
without much luck.

Regards
UE.


On Mon, Oct 18, 2010 at 3:17 PM, Stefan Hajnoczi stefa...@gmail.com wrote:

 On Mon, Oct 18, 2010 at 12:37 AM, Ubuntu Explorer
 ubuntuexplo...@gmail.com wrote:
  I am trying to implement snapshot saving and loading from command line
 using
  qemu. I am using both the drive and disk options as follows.
  qemu exe \
  --disk path to disk file \
  ...other options \
  -drive file=path to drive file,
  index=0,media=disk,snapshot=on,if=ide,type=drive,cache=writethrough

 Remove snapshot=on.  See the documentation about -snapshot versus
 savevm snapshots:

 http://wiki.qemu.org/download/qemu-doc.html#vm_005fsnapshots

 When using the (unrelated) -snapshot option (Snapshot mode), you can
 always make VM snapshots, but they are deleted as soon as you exit
 QEMU.

 Stefan



Re: [Qemu-devel] [PATCH 0/7] ATAPI CDROM passthrough v5

2010-10-18 Thread Anthony Liguori

On 10/18/2010 06:29 PM, Alexander Graf wrote:

A user will get a really nasty surprise if they think they can use a flag or 
rely on QEMU to prevent a VM from doing something nasty with a device.  If they 
have this feeling of security, they're likely to chmod the device to allow 
unprivileged users to access it.

But how a device handles ATAPI commands is totally up to the device.  If you 
issue the wrong sequence, I'm sure there are devices out there that totally 
hose themselves.  Are you absolutely confident that every ATAPI device out 
there is completely safe against hostile code provided that you simply prevent 
the FW update commands?  I'm certainly not.
 

Ping?
   


Who are you pinging?

Regards,

Anthony Liguori


Alex


   





Re: [Qemu-devel] Snapshots ide0-hd0 issue

2010-10-18 Thread Ubuntu Explorer
I also read the following

VM snapshots currently have the following known limitations:
They cannot cope with removable devices if they are removed or inserted
after a snapshot is done.
A few device drivers still have incomplete snapshot support so their state
is not saved or restored properly (in particular USB).

I am using an ide0-hd0 device option with removable=0 and ro=0.
Are there any additional options to be set?
--


On Tue, Oct 19, 2010 at 8:51 AM, Ubuntu Explorer
ubuntuexplo...@gmail.comwrote:

 Thanks for your help.

 But, after commenting out snapshot option, I still cannot save the VM state
 into the ide0-hd0 block device.

 Here is some more information about the problem.

 I am trying to do the following
 a. info block
 shows virtio, ide0-hd0
 b. savevm snapshot_name
 c. info snapshots
 Shows snapshot_name under virtio
 d. commit ide0-hd0
 e. quit
 f. Check timestamp of ide0 file - no change. ( I assume that qemu would
 write something to this file)
 g. restart qemu.
 h. info snapshots
 i. No snapshots in virtio

 I will try to run qemu in gdb mode to see why commit is not committing the
 changes to the ide0-hd0 block device.
 But any other information will be helpful as well. I have googled a lot
 without much luck.

 Regards
 UE.


 On Mon, Oct 18, 2010 at 3:17 PM, Stefan Hajnoczi stefa...@gmail.comwrote:

 On Mon, Oct 18, 2010 at 12:37 AM, Ubuntu Explorer
 ubuntuexplo...@gmail.com wrote:
  I am trying to implement snapshot saving and loading from command line
 using
  qemu. I am using both the drive and disk options as follows.
  qemu exe \
  --disk path to disk file \
  ...other options \
  -drive file=path to drive file,
  index=0,media=disk,snapshot=on,if=ide,type=drive,cache=writethrough

 Remove snapshot=on.  See the documentation about -snapshot versus
 savevm snapshots:

 http://wiki.qemu.org/download/qemu-doc.html#vm_005fsnapshots

 When using the (unrelated) -snapshot option (Snapshot mode), you can
 always make VM snapshots, but they are deleted as soon as you exit
 QEMU.

 Stefan





Re: [Qemu-devel] Snapshots ide0-hd0 issue

2010-10-18 Thread Ubuntu Explorer
An additional note is that,

qemu-img snapshot -l snapshot_file

shows VM_Size = 0

Has anyone observed this issue before?

Regards
--

On Tue, Oct 19, 2010 at 9:18 AM, Ubuntu Explorer
ubuntuexplo...@gmail.comwrote:

 I also read the following

 VM snapshots currently have the following known limitations:
 They cannot cope with removable devices if they are removed or inserted
 after a snapshot is done.
 A few device drivers still have incomplete snapshot support so their state
 is not saved or restored properly (in particular USB).

 I am using an ide0-hd0 device option with removable=0 and ro=0.
 Are there any additional options to be set?
 --


 On Tue, Oct 19, 2010 at 8:51 AM, Ubuntu Explorer ubuntuexplo...@gmail.com
  wrote:

 Thanks for your help.

 But, after commenting out snapshot option, I still cannot save the VM
 state into the ide0-hd0 block device.

 Here is some more information about the problem.

 I am trying to do the following
 a. info block
 shows virtio, ide0-hd0
 b. savevm snapshot_name
 c. info snapshots
 Shows snapshot_name under virtio
 d. commit ide0-hd0
 e. quit
 f. Check timestamp of ide0 file - no change. ( I assume that qemu would
 write something to this file)
 g. restart qemu.
 h. info snapshots
 i. No snapshots in virtio

 I will try to run qemu in gdb mode to see why commit is not committing the
 changes to the ide0-hd0 block device.
 But any other information will be helpful as well. I have googled a lot
 without much luck.

 Regards
 UE.


 On Mon, Oct 18, 2010 at 3:17 PM, Stefan Hajnoczi stefa...@gmail.comwrote:

 On Mon, Oct 18, 2010 at 12:37 AM, Ubuntu Explorer
 ubuntuexplo...@gmail.com wrote:
  I am trying to implement snapshot saving and loading from command line
 using
  qemu. I am using both the drive and disk options as follows.
  qemu exe \
  --disk path to disk file \
  ...other options \
  -drive file=path to drive file,
  index=0,media=disk,snapshot=on,if=ide,type=drive,cache=writethrough

 Remove snapshot=on.  See the documentation about -snapshot versus
 savevm snapshots:

 http://wiki.qemu.org/download/qemu-doc.html#vm_005fsnapshots

 When using the (unrelated) -snapshot option (Snapshot mode), you can
 always make VM snapshots, but they are deleted as soon as you exit
 QEMU.

 Stefan






[Qemu-devel] Re: [SeaBIOS] [PATCH 1/2] pci: introduce pci_region to manage pci io/memory/prefmemory regions.

2010-10-18 Thread Isaku Yamahata
On Mon, Oct 18, 2010 at 11:55:08AM +0200, Michael S. Tsirkin wrote:
  +static u32 pci_region_alloc_align(struct pci_region *r, u32 size, u32 
  align)
  +{
  +if (r-cur_end == PCI_REGION_DISABLED) {
  +return 0;
  +}
 
 So is special value PCI_REGION_DISABLED or cur_end?

cur_end is in special state, and PCI_REGION_DISABLED was chosen
such that cur_end can't be PCI_REGION_DISABLED in normal case.
-- 
yamahata



Re: [Qemu-devel] Re: [PATCH 11/11] kvm, x86: broadcast mce depending on the cpu version

2010-10-18 Thread Hidetoshi Seto
(2010/10/15 22:30), Marcelo Tosatti wrote:
 On Fri, Oct 15, 2010 at 10:52:05AM +0900, Hidetoshi Seto wrote:
 (2010/10/15 10:06), Marcelo Tosatti wrote:
 On Thu, Oct 14, 2010 at 05:55:28PM +0900, Jin Dongming wrote:
 There is no reason why SRAO event received by the main thread
 is the only one that being broadcasted.

 According to the x86 ASDM vol.3A 15.10.4.1,
 MCE signal is broadcast on processor version 06H_EH or later.

 This change is required to handle SRAR in the guest.

 Signed-off-by: Hidetoshi Seto seto.hideto...@jp.fujitsu.com
 Tested-by: Jin Dongming jin.dongm...@np.css.fujitsu.com
 ---
  qemu-kvm.c |   63 
 +--
  1 files changed, 31 insertions(+), 32 deletions(-)

 Why is this necessary? _AO SIGBUS should be sent to all vcpu threads and
 main thread.

 Humm? If you are right, vcpu threads will receive same SRAO event twice,
 one is that received by itself and another is that received by main thread
 and forwarded by the broadcast.

 My understanding is (Jin, please correct me if something wrong):
  - _AO SIGBUS is sent to main thread only, and then SRAO event is
broadcasted to all vcpu threads.
  - _AR SIGBUS is sent to a vcpu thread that tried to touch the
unmapped poisoned page, and SRAR event is posted to the vcpu.

 One problem here is that SRAR is not broadcasted.
 The guest might observe the event differently, like some cpus
 don't enter machine check.
 
 Right.
 
 Please separate bug fixes from cleanups. Very nice, thanks. 

 Maybe this set is considered as 10 cleanups + 1 fix.
 I think this fix will be complicated one without preceding cleanups.
 
 Why? All you need is to broadcast from vcpu context.

No, it is not correct. What I really need is reliable QEMU and
maintainable source codes with open community.

Anyway, since I found it could be simpler than what I expected,
I rebased  2 functional change pieces in this set to today's
uq/master.

But these are not tested on the tree yet since I could not build
the uq/master due to many warnings on it (even without my fixes).

 Please do a minimal fix separately so it can be backported, and the
 cleanups can be done later once its merged upstream.

When it will be merged?


Thanks,
H.Seto





  1   2   >