Re: [Qemu-devel] [PATCH 0/3] linux-user: Implement setxattr/getxattr/removexattr syscalls

2011-09-02 Thread Riku Voipio
Hi,

On Wed, Aug 17, 2011 at 02:30:53PM -0700, An-Cheng Huang wrote:
 On Tue, Aug 09, 2011 at 12:30:52PM -0700, An-Cheng Huang wrote:
  These patches implement the setxattr, getxattr, and removexattr syscalls.
  Since libattr uses indirect syscalls for these, the fix for the indirect
  syscall handling on MIPS is needed for these to work.
  
  An-Cheng Huang (3):
linux-user: Fix MIPS indirect syscall handling
linux-user: Verify MIPS syscall arguments
linux-user: Implement setxattr/getxattr/removexattr syscalls
  
   linux-user/main.c|   24 -
   linux-user/syscall.c |   54 
  +++--
   2 files changed, 69 insertions(+), 9 deletions(-)

 Ping?

Thanks for your patches. Sorry that I haven't had the time to look at them yet, 
I hope
to get it done by monday ( together with the other pending linux-user patches).

Riku




Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-02 Thread Paolo Bonzini

On 09/02/2011 02:11 AM, David Gibson wrote:

  Why not limit the change to ppc then?


  Because the bug is masked by the x86 memory model, but it is still
  there even there conceptually.  It is not really true that x86 does
  not need memory barriers, though it doesn't in this case:

  
http://bartoszmilewski.wordpress.com/2008/11/05/who-ordered-memory-fences-on-an-x86/

Not to mention that pcc is not the only non-x86 architecture.  I don't
know all their storage models off hand, but the point is that there is
a required order to these writes, so there should be a memory barrier.


Indeed, I interpreted Michael's question more as why not limit the 
change to non-x86.  I think we should cater to all memory models except 
perhaps the Alpha's.


Paolo



[Qemu-devel] target_phys_addr_t vs ram_addr_t

2011-09-02 Thread Sinha, Ani
Hi Folks :

I am trying to write a virtio driver and towards this end I am looking at
the qemu code. I am a little confused about a few things. Unfortunately,
the few comments in the code does not make it clear for me. So I am
wondering if any kind person on this mailing list would be able to help.

First off, what is the difference between target_phys_addr_t and
ram_addr_t? I believe the former is a virtual address within the guest but
what is the later? The comment says address in ram (different from
physical address) but is this the virtual address or the physical
address? Is this for guest or for host?

Secondly, in function cpu_physical_memory_map(), why is the length
parameter an address? If I look at the function virtqueue_map_sg(), the
sg.iov_len is defined as type size_t, which sounds like right. However,
this value is assigned to variable len which is of type
target_phys_addr_t. Is len an address or just a scalar value?

Lastly, in qemu_ram_ptr_length(), what is the length value? What does it
signify?

One more thing. It would really help guys like me if someone can add
comments regarding the various apis, what they do and what the parameters
mean in the code. I thought I'd suggest.

I am not in the mailing list. So please do a reply-all when responding.

Thanks in advance for help,
Ani



The information contained in this message may be privileged
and confidential and protected from disclosure. If the reader
of this message is not the intended recipient, or an employee
or agent responsible for delivering this message to the
intended recipient, you are hereby notified that any reproduction,
dissemination or distribution of this communication is strictly
prohibited. If you have received this communication in error,
please notify us immediately by replying to the message and
deleting it from your computer. Thank you. Tellabs





Re: [Qemu-devel] [PATCH] virtio: Make memory barriers be memory barriers

2011-09-02 Thread Paolo Bonzini

On 09/02/2011 02:08 AM, David Gibson wrote:



  Signed-off-by: Alexey Kardashevskiya...@ozlabs.ru
  Signed-off-by: David Gibsonda...@gibson.dropbear.id.au


  It will most definitely break OpenBSD, but anyway:

Uh, why?


They use an ancient compiler because they do not want to use GPLv3.  I 
thought it was 4.1.something but actually it is 4.2.1, so it should work.


Paolo



Re: [Qemu-devel] [PATCH 0/3] usb-musb: make qdev-aware

2011-09-02 Thread Juha.Riihimaki
How to you test musb?

Unfortunately I don't have any test cases which actively use the musb,
so I settle for testing an n810 image (and a beagle image in my omap3
tree) and confirming that the init part of things still works ok.
(I'm not entirely happy with this but init is really all we're changing
with these patches so we should be ok...)

Riku/Juha -- do you have any musb test images/command lines?

With an existing n810 image I guess you can test USB networking by adding
-usb -net user,vlan=0 -net nic,model=usb,vlan=0 -usbdevice net -redir
tcp:2022::22 to qemu command line parameters. In the guest, launch X
terminal and command sudo gainroot followed by udhcpc. You should now
be able to ssh to the guest from the host with ssh -p 2022
root@localhost. Would this be sufficient for your needs?


Cheers,
Juha




Re: [Qemu-devel] [PATCH 1/4] Probe for libcheck by default.

2011-09-02 Thread Gerd Hoffmann

On 09/01/11 21:37, Anthony Liguori wrote:

On 09/01/2011 10:42 AM, Gerd Hoffmann wrote:

Probe for libcheck and build checks (if found) by default.
Can be explicitly disabled using --disable-check-utests.

Signed-off-by: Gerd Hoffmannkra...@redhat.com
---
configure | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)


I think we should convert the check tests to gtest, and then have make
check use gtester and gtester-report generate a single report of all of
the test cases.


I wouldn't object, that is *way* beyond the scope of this little patch 
series though.



We could then have build bot run make check and post the output.


Running make check in buildbot is indeed the motivation to do this ;)


I don't
want to end up with a bunch of non gtest unit tests...


This patch series doesn't add any.  It just adds some build system glue 
so make check runs the existing stuff.


cheers,
  Gerd




Re: [Qemu-devel] [PATCH 0/3] usb-musb: make qdev-aware

2011-09-02 Thread Gerd Hoffmann

On 09/02/11 09:03, juha.riihim...@nokia.com wrote:

How to you test musb?


Unfortunately I don't have any test cases which actively use the musb,
so I settle for testing an n810 image (and a beagle image in my omap3
tree) and confirming that the init part of things still works ok.
(I'm not entirely happy with this but init is really all we're changing
with these patches so we should be ok...)

Riku/Juha -- do you have any musb test images/command lines?


With an existing n810 image I guess you can test USB networking by adding
-usb -net user,vlan=0 -net nic,model=usb,vlan=0 -usbdevice net -redir
tcp:2022::22 to qemu command line parameters. In the guest, launch X
terminal and command sudo gainroot followed by udhcpc. You should now
be able to ssh to the guest from the host with ssh -p 2022
root@localhost. Would this be sufficient for your needs?


For starters just qemu-system-arm -M n810 is better than nothing, this 
does at least make sure it doesn't blow up somewhere when creating the 
device tree.


Booting an image and operating some usb device is even better.  Are n810 
images are freely available for download somewhere?  Failing that, is it 
possible to just install some linux distro (say debian) on the virtual 
n810 or another arm device which has a musb controller?


thanks,
  Gerd



Re: [Qemu-devel] [PATCH 0/3] usb-musb: make qdev-aware

2011-09-02 Thread Riku Voipio
On Fri, Sep 02, 2011 at 09:50:44AM +0200, Gerd Hoffmann wrote:
 On 09/02/11 09:03, juha.riihim...@nokia.com wrote:
 How to you test musb?

 Unfortunately I don't have any test cases which actively use the musb,
 so I settle for testing an n810 image (and a beagle image in my omap3
 tree) and confirming that the init part of things still works ok.
 (I'm not entirely happy with this but init is really all we're changing
 with these patches so we should be ok...)

 Riku/Juha -- do you have any musb test images/command lines?

 With an existing n810 image I guess you can test USB networking by adding
 -usb -net user,vlan=0 -net nic,model=usb,vlan=0 -usbdevice net -redir
 tcp:2022::22 to qemu command line parameters. In the guest, launch X
 terminal and command sudo gainroot followed by udhcpc. You should now
 be able to ssh to the guest from the host with ssh -p 2022
 root@localhost. Would this be sufficient for your needs?

 For starters just qemu-system-arm -M n810 is better than nothing, this  
 does at least make sure it doesn't blow up somewhere when creating the  
 device tree.

 Booting an image and operating some usb device is even better.  Are n810  
 images are freely available for download somewhere?  Failing that, is it  
 possible to just install some linux distro (say debian) on the virtual  
 n810 or another arm device which has a musb controller?

n800/n810 qemu images based on official are not redistributable, as
they carry propiertary software. Instructions howto convert a firmare
to qemu image exist, but to get your hands on a firmware you need to
know a n800/n810 serial number:

http://marcin.juszkiewicz.com.pl/2008/04/11/nokia-n800-emulation/
http://www.rkeene.org/projects/info/wiki/106

Marcin might have a poky image still somehere thou?

Riku



Re: [Qemu-devel] [PATCH 3/3] async: Allow nested qemu_bh_poll calls

2011-09-02 Thread Stefan Hajnoczi
On Thu, Sep 1, 2011 at 3:31 PM, Kevin Wolf kw...@redhat.com wrote:
 qemu may segfault when a BH handler first deletes a BH and then (possibly
 indirectly) calls a nested qemu_bh_poll(). This is because the inner instance
 frees the BH and deletes it from the list that the outer one processes.

 This patch deletes BHs only in the outermost qemu_bh_poll instance.

 Commit 7887f620 already tried to achieve the same, but it assumed that the BH
 handler would only delete its own BH. With a nested qemu_bh_poll(), this isn't
 guaranteed, so that commit wasn't enough. Hope this one fixes it for real.

 Signed-off-by: Kevin Wolf kw...@redhat.com
 ---
  async.c |   24 
  1 files changed, 16 insertions(+), 8 deletions(-)

Seems okay as a fix.

Stefan



Re: [Qemu-devel] [PATCH 01/10] Add stub functions for PCI device models to do PCI DMA

2011-09-02 Thread Avi Kivity

On 09/01/2011 07:32 PM, Anthony Liguori wrote:

True. But I still think it's the right thing.

We can't really pass a MemoryRegion as the source address, since there
is no per-device MemoryRegion.



Couldn't the PCI bus expose 255 MemoryRegions though? 


What would those mean?  A MemoryRegion is something that can respond to 
reads and writes.


It could still use the pci_address_space I think since that should 
include RAM too, right?




No.

In fact, initially, you could have a 
pci_bus_get_device_memory_region(bus, dev) that just returns 
pci_address_space().


You just need the memory_st[bwl] functions I think.



Maybe we need a different type of object here - MemoryClient or something.

--
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.




Re: [Qemu-devel] [PATCH 01/10] Add stub functions for PCI device models to do PCI DMA

2011-09-02 Thread Avi Kivity

On 09/01/2011 07:05 PM, Anthony Liguori wrote:


The challenge is what you do about something like ne2k where the core 
chipset can either be a PCI device or an ISA device.  You would have 
to implement a wrapper around pci_dma_rw() in order to turn it into 
cpu_physical_memory_rw when doing ISA.


btw, ISA DMA is very different, no?  You program a dma controller to 
copy memory from the device to RAM (or vice versa); the device never 
initiates a transaction IIRC.


--
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.




Re: [Qemu-devel] [PATCH 0/3] usb-musb: make qdev-aware

2011-09-02 Thread Marcin Juszkiewicz
W dniu 02.09.2011 10:00, Riku Voipio pisze:
 n800/n810 qemu images based on official are not redistributable, as
 they carry propiertary software. Instructions howto convert a firmare
 to qemu image exist, but to get your hands on a firmware you need to
 know a n800/n810 serial number:
 
 http://marcin.juszkiewicz.com.pl/2008/04/11/nokia-n800-emulation/
 http://www.rkeene.org/projects/info/wiki/106
 
 Marcin might have a poky image still somehere thou?

http://narcissus.angstrom-distribution.org/ can generate jffs2/ubifs
images for n8x0 (select nokia800 from machine selector). You will need a
copy of config mtd partition from working n8x0 (at least it was needed
when I was playing with it) with “no-lifeguard-reset” flag set.

http://marcin.juszkiewicz.com.pl/2008/08/01/nokia-n8x0-emulation-part-ii/ is
second part of my story with running Maemo on n8x0.

I remember fun during Berlin Maemo Summit where I presented this working
but was not allowed (by Intel) to show working BT emulation cause it was
not yet cleaned by 'legal' who will have copyright for this code.



Re: [Qemu-devel] [PATCH] build: sort objects to remove duplicates for link

2011-09-02 Thread Stefan Hajnoczi
2011/9/1 Michael Roth mdr...@linux.vnet.ibm.com:
 On 09/01/2011 01:54 PM, Anthony Liguori wrote:

 On 08/25/2011 03:18 AM, Stefan Hajnoczi wrote:

 Avoid duplicate object files during the link. There are legitimate
 cases where a link command-line would include duplicate object files
 because two independent subsystems both depend on common infrastructure.

 Use GNU make's $(sort) function to remove duplicate object files from
 the link command-line.

 Signed-off-by: Stefan Hajnoczistefa...@linux.vnet.ibm.com

 Applied. Thanks.


 Don't think it'll hurt to have both, but [PATCH 01/15] build: Fix linkage
 of QEMU_PROG from Stefan's tracing pull request has the more elegant fix
 for this.

Agreed, it doesn't hurt to take this one but the $^ fix is nicer and
already merged.

Anthony: Do you want to revert this patch?  It's not necessary.

Stefan



Re: [Qemu-devel] [PATCH 0/3] usb-musb: make qdev-aware

2011-09-02 Thread Peter Maydell
On 2 September 2011 08:50, Gerd Hoffmann kra...@redhat.com wrote:
 For starters just qemu-system-arm -M n810 is better than nothing, this
 does at least make sure it doesn't blow up somewhere when creating the
 device tree.

NB that the n810 machine doesn't create the usb device unless you
pass -usb on the command line so you need tat to be able to test
the init code.

-- PMM



Re: [Qemu-devel] [PULL 00/15] Tracing patches

2011-09-02 Thread Stefan Hajnoczi
On Thu, Sep 1, 2011 at 8:08 PM, Anthony Liguori aligu...@us.ibm.com wrote:
 On 09/01/2011 03:06 AM, Stefan Hajnoczi wrote:

 The following changes since commit
 f0fb8b7180fdcf536ea635a0720e1496110ecb3b:

   Merge branch 'omap-for-upstream' of
 git://git.linaro.org/people/pmaydell/qemu-arm into pm (2011-08-29 23:59:06
 +0200)

 are available in the git repository at:

   ssh://repo.or.cz/srv/git/qemu/stefanha.git tracing

 Pulled.  Thanks.

Your email was 14 hours ago but I don't see the commits in qemu.git.  Any ideas?

Stefan



Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access

2011-09-02 Thread Daniel P. Berrange
On Thu, Sep 01, 2011 at 08:34:35PM -0500, Anthony Liguori wrote:
 On 09/01/2011 02:35 PM, Luiz Capitulino wrote:
 Sometimes, when having lots of VMs running on a RHEV host and the user
 attempts to close a SPICE window, libvirt will get corrupted json from
 QEMU.
 
 After some investigation, I found out that the problem is that different
 SPICE threads are calling monitor functions (such as
 monitor_protocol_event()) in parallel which causes concurrent access
 to the monitor's internal buffer outbuf[].
 
 This fixes the problem by protecting accesses to outbuf[] with a mutex.
 
 Honestly speaking, I'm not completely sure this the best thing to do
 because the monitor itself and other qemu subsystems are not thread safe,
 so having subsystems like SPICE assuming the contrary seems a bit
 catastrophic to me...
 
 Anyways, this commit fixes the problem at hand.
 
 Nack.
 
 This is absolutely a Spice bug.  Spice should not be calling into
 QEMU code from multiple threads.  It should only call into QEMU code
 while it's holding the qemu_mutex.
 
 The right way to fix this is probably to make all of the
 SpiceCoreInterface callbacks simply write to a file descriptor which
 can then wake up QEMU to do the operation on behalf of it.   It's
 ugly but the libspice interface is far too tied to QEMU internals in
 the first place which is the root of the problem.

This feels like a rather short-term approach to fixing the problem
to me. As QEMU becomes increasingly multi-threaded, there is high
liklihood that we'll get other code in QEMU which wants to use the
monitor from multiple threads. The monitor code in QEMU is fairly
well isolated  thus comparatively easy to make threadsafe, so I
don't see why we wouldn't want todo that  avoid any chance of this
type of problem recurring in the future.

IMHO, fixing SPICE is not fixing the bug at all, it is just removing
the trigger of the bug in the monitor.

Regards,
Daniel



[Qemu-devel] [PATCH 03/18] usb-host: fix halted endpoints

2011-09-02 Thread Gerd Hoffmann
Two fixes for the price of one ;)

First, reinitialize the endpoint table after device reset.
This is needed anyway as the reset might have switched interfaces.
It also clears the endpoint halted state.

Second the CLEAR_HALT ioctl wants a unsigned int passed in as
argument, not uint8_t.

This gets my usb sd card reader (sandisk micromate) going.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 usb-linux.c |7 ---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 12e8772..344af22 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -143,6 +143,7 @@ static int parse_filter(const char *spec, struct 
USBAutoFilter *f);
 static void usb_host_auto_check(void *unused);
 static int usb_host_read_file(char *line, size_t line_size,
 const char *device_file, const char *device_name);
+static int usb_linux_update_endp_table(USBHostDevice *s);
 
 static struct endp_data *get_endp(USBHostDevice *s, int ep)
 {
@@ -512,6 +513,7 @@ static void usb_host_handle_reset(USBDevice *dev)
 ioctl(s-fd, USBDEVFS_RESET);
 
 usb_host_claim_interfaces(s, s-configuration);
+usb_linux_update_endp_table(s);
 }
 
 static void usb_host_handle_destroy(USBDevice *dev)
@@ -523,8 +525,6 @@ static void usb_host_handle_destroy(USBDevice *dev)
 qemu_remove_exit_notifier(s-exit);
 }
 
-static int usb_linux_update_endp_table(USBHostDevice *s);
-
 /* iso data is special, we need to keep enough urbs in flight to make sure
that the controller never runs out of them, otherwise the device will
likely suffer a buffer underrun / overrun. */
@@ -732,7 +732,8 @@ static int usb_host_handle_data(USBDevice *dev, USBPacket 
*p)
 }
 
 if (is_halted(s, p-devep)) {
-ret = ioctl(s-fd, USBDEVFS_CLEAR_HALT, ep);
+unsigned int arg = ep;
+ret = ioctl(s-fd, USBDEVFS_CLEAR_HALT, arg);
 if (ret  0) {
 perror(USBDEVFS_CLEAR_HALT);
 trace_usb_host_req_complete(s-bus_num, s-addr, USB_RET_NAK);
-- 
1.7.1




[Qemu-devel] [PATCH 02/18] usb-host: reapurb error report fix

2011-09-02 Thread Gerd Hoffmann
Don't report errors on devices which are in disconnected
and closing state.
---
 usb-linux.c |8 +---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 4e4df61..12e8772 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -312,9 +312,11 @@ static void async_complete(void *opaque)
 }
 return;
 }
-if (errno == ENODEV  !s-closing) {
-trace_usb_host_disconnect(s-bus_num, s-addr);
-do_disconnect(s);
+if (errno == ENODEV) {
+if (!s-closing) {
+trace_usb_host_disconnect(s-bus_num, s-addr);
+do_disconnect(s);
+}
 return;
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH 01/18] usb-host: start tracing support

2011-09-02 Thread Gerd Hoffmann
Add a bunch of trace points to usb-linux.c  Drop a bunch of DPRINTK's in
favor of the trace points.  Also cleanup error reporting a bit while being
at it.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 trace-events |   24 +++
 usb-linux.c  |   73 ++
 2 files changed, 72 insertions(+), 25 deletions(-)

diff --git a/trace-events b/trace-events
index f08d6d0..f48cb85 100644
--- a/trace-events
+++ b/trace-events
@@ -243,6 +243,30 @@ disable usb_set_config(int addr, int config, int ret) dev 
%d, config %d, ret %d
 disable usb_clear_device_feature(int addr, int feature, int ret) dev %d, 
feature %d, ret %d
 disable usb_set_device_feature(int addr, int feature, int ret) dev %d, 
feature %d, ret %d
 
+# usb-linux.c
+disable usb_host_open_started(int bus, int addr) dev %d:%d
+disable usb_host_open_success(int bus, int addr) dev %d:%d
+disable usb_host_open_failure(int bus, int addr) dev %d:%d
+disable usb_host_disconnect(int bus, int addr) dev %d:%d
+disable usb_host_close(int bus, int addr) dev %d:%d
+disable usb_host_set_address(int bus, int addr, int config) dev %d:%d, 
address %d
+disable usb_host_set_config(int bus, int addr, int config) dev %d:%d, config 
%d
+disable usb_host_set_interface(int bus, int addr, int interface, int alt) dev 
%d:%d, interface %d, alt %d
+disable usb_host_claim_interfaces(int bus, int addr, int config, int nif) dev 
%d:%d, config %d, nif %d
+disable usb_host_release_interfaces(int bus, int addr) dev %d:%d
+disable usb_host_req_control(int bus, int addr, int req, int value, int index) 
dev %d:%d, req 0x%x, value %d, index %d
+disable usb_host_req_data(int bus, int addr, int in, int ep, int size) dev 
%d:%d, in %d, ep %d, size %d
+disable usb_host_req_complete(int bus, int addr, int status) dev %d:%d, 
status %d
+disable usb_host_urb_submit(int bus, int addr, void *aurb, int length, int 
more) dev %d:%d, aurb %p, length %d, more %d
+disable usb_host_urb_complete(int bus, int addr, void *aurb, int status, int 
length, int more) dev %d:%d, aurb %p, status %d, length %d, more %d
+disable usb_host_ep_set_halt(int bus, int addr, int ep) dev %d:%d, ep %d
+disable usb_host_ep_clear_halt(int bus, int addr, int ep) dev %d:%d, ep %d
+disable usb_host_ep_start_iso(int bus, int addr, int ep) dev %d:%d, ep %d
+disable usb_host_ep_stop_iso(int bus, int addr, int ep) dev %d:%d, ep %d
+disable usb_host_reset(int bus, int addr) dev %d:%d
+disable usb_host_auto_scan_enabled(void)
+disable usb_host_auto_scan_disabled(void)
+
 # hw/scsi-bus.c
 disable scsi_req_alloc(int target, int lun, int tag) target %d lun %d tag %d
 disable scsi_req_data(int target, int lun, int tag, int len) target %d lun %d 
tag %d len %d
diff --git a/usb-linux.c b/usb-linux.c
index 2e20f8e..4e4df61 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -34,6 +34,7 @@
 #include qemu-timer.h
 #include monitor.h
 #include sysemu.h
+#include trace.h
 
 #include dirent.h
 #include sys/ioctl.h
@@ -165,11 +166,13 @@ static int is_halted(USBHostDevice *s, int ep)
 
 static void clear_halt(USBHostDevice *s, int ep)
 {
+trace_usb_host_ep_clear_halt(s-bus_num, s-addr, ep);
 get_endp(s, ep)-halted = 0;
 }
 
 static void set_halt(USBHostDevice *s, int ep)
 {
+trace_usb_host_ep_set_halt(s-bus_num, s-addr, ep);
 get_endp(s, ep)-halted = 1;
 }
 
@@ -180,12 +183,15 @@ static int is_iso_started(USBHostDevice *s, int ep)
 
 static void clear_iso_started(USBHostDevice *s, int ep)
 {
+trace_usb_host_ep_stop_iso(s-bus_num, s-addr, ep);
 get_endp(s, ep)-iso_started = 0;
 }
 
 static void set_iso_started(USBHostDevice *s, int ep)
 {
 struct endp_data *e = get_endp(s, ep);
+
+trace_usb_host_ep_start_iso(s-bus_num, s-addr, ep);
 if (!e-iso_started) {
 e-iso_started = 1;
 e-inflight = 0;
@@ -285,8 +291,6 @@ static void async_free(AsyncURB *aurb)
 
 static void do_disconnect(USBHostDevice *s)
 {
-printf(husb: device %d.%d disconnected\n,
-   s-bus_num, s-addr);
 usb_host_close(s);
 usb_host_auto_check(NULL);
 }
@@ -309,11 +313,12 @@ static void async_complete(void *opaque)
 return;
 }
 if (errno == ENODEV  !s-closing) {
+trace_usb_host_disconnect(s-bus_num, s-addr);
 do_disconnect(s);
 return;
 }
 
-DPRINTF(husb: async. reap urb failed errno %d\n, errno);
+perror(USBDEVFS_REAPURBNDELAY);
 return;
 }
 
@@ -337,6 +342,8 @@ static void async_complete(void *opaque)
 }
 
 p = aurb-packet;
+trace_usb_host_urb_complete(s-bus_num, s-addr, aurb, 
aurb-urb.status,
+aurb-urb.actual_length, aurb-more);
 
 if (p) {
 switch (aurb-urb.status) {
@@ -355,8 +362,10 @@ static void async_complete(void *opaque)
 }
 
 if (aurb-urb.type == USBDEVFS_URB_TYPE_CONTROL) {
+

[Qemu-devel] [PATCH 15/18] usb-host: tag as unmigratable

2011-09-02 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 usb-linux.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 7995178..390bcd3 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -1354,10 +1354,16 @@ out:
 return 0;
 }
 
+static const VMStateDescription vmstate_usb_host = {
+.name = usb-host,
+.unmigratable = 1,
+};
+
 static struct USBDeviceInfo usb_host_dev_info = {
 .product_desc   = USB Host Device,
 .qdev.name  = usb-host,
 .qdev.size  = sizeof(USBHostDevice),
+.qdev.vmsd  = vmstate_usb_host,
 .init   = usb_host_initfn,
 .handle_packet  = usb_generic_handle_packet,
 .cancel_packet  = usb_host_async_cancel,
-- 
1.7.1




[Qemu-devel] [PATCH 18/18] usb-musb: Add reset function

2011-09-02 Thread Gerd Hoffmann
From: Juha Riihimäki juha.riihim...@nokia.com

Add a separate reset function musb_reset() to the usb-musb interface,
so that users who implement a reset function can also reset usb-musb.
Use this in tusb6010.

Signed-off-by: Juha Riihimäki juha.riihim...@nokia.com
[Riku Voipio: Fixes and restructuring patchset]
Signed-off-by: Riku Voipio riku.voi...@iki.fi
[Peter Maydell: More fixes and cleanups for upstream submission]
Signed-off-by:  Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/tusb6010.c |1 +
 hw/usb-musb.c |   24 ++--
 hw/usb.h  |1 +
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/hw/tusb6010.c b/hw/tusb6010.c
index 57fe804..ce7c81f 100644
--- a/hw/tusb6010.c
+++ b/hw/tusb6010.c
@@ -771,6 +771,7 @@ static void tusb6010_reset(DeviceState *dev)
 for (i = 0; i  15; i++) {
 s-rx_config[i] = s-tx_config[i] = 0;
 }
+musb_reset(s-musb);
 }
 
 static int tusb6010_init(SysBusDevice *dev)
diff --git a/hw/usb-musb.c b/hw/usb-musb.c
index 640037f..01e2e7c 100644
--- a/hw/usb-musb.c
+++ b/hw/usb-musb.c
@@ -340,16 +340,12 @@ struct MUSBState {
 MUSBEndPoint ep[16];
 };
 
-struct MUSBState *musb_init(DeviceState *parent_device, int gpio_base)
+void musb_reset(MUSBState *s)
 {
-MUSBState *s = g_malloc0(sizeof(*s));
 int i;
 
-for (i = 0; i  musb_irq_max; i++) {
-s-irqs[i] = qdev_get_gpio_in(parent_device, gpio_base + i);
-}
-
 s-faddr = 0x00;
+s-devctl = 0;
 s-power = MGC_M_POWER_HSENAB;
 s-tx_intr = 0x;
 s-rx_intr = 0x;
@@ -359,6 +355,10 @@ struct MUSBState *musb_init(DeviceState *parent_device, 
int gpio_base)
 s-mask = 0x06;
 s-idx = 0;
 
+s-setup_len = 0;
+s-session = 0;
+memset(s-buf, 0, sizeof(s-buf));
+
 /* TODO: _DW */
 s-ep[0].config = MGC_M_CONFIGDATA_SOFTCONE | MGC_M_CONFIGDATA_DYNFIFO;
 for (i = 0; i  16; i ++) {
@@ -370,6 +370,18 @@ struct MUSBState *musb_init(DeviceState *parent_device, 
int gpio_base)
 usb_packet_init(s-ep[i].packey[0].p);
 usb_packet_init(s-ep[i].packey[1].p);
 }
+}
+
+struct MUSBState *musb_init(DeviceState *parent_device, int gpio_base)
+{
+MUSBState *s = g_malloc0(sizeof(*s));
+int i;
+
+for (i = 0; i  musb_irq_max; i++) {
+s-irqs[i] = qdev_get_gpio_in(parent_device, gpio_base + i);
+}
+
+musb_reset(s);
 
 usb_bus_new(s-bus, musb_bus_ops, parent_device);
 usb_register_port(s-bus, s-port, s, 0, musb_port_ops,
diff --git a/hw/usb.h b/hw/usb.h
index 55c061e..c08d469 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -344,6 +344,7 @@ enum musb_irq_source_e {
 
 typedef struct MUSBState MUSBState;
 MUSBState *musb_init(DeviceState *parent_device, int gpio_base);
+void musb_reset(MUSBState *s);
 uint32_t musb_core_intr_get(MUSBState *s);
 void musb_core_intr_clear(MUSBState *s, uint32_t mask);
 void musb_set_size(MUSBState *s, int epnum, int size, int is_tx);
-- 
1.7.1




[Qemu-devel] [STABLE PULL] usb bugfixes

2011-09-02 Thread Gerd Hoffmann
  Hi,

These are the bugfixes for stable cherry-picked from
master's usb patch queue.

please pull,
  Gerd

The following changes since commit 76e4e1d23711750f777333654f13cf6baf8d01f1:

  Update version to 0.15.0 (2011-08-08 13:27:32 -0500)

are available in the git repository at:
  git://git.kraxel.org/qemu usb.25.stable

Gerd Hoffmann (7):
  usb-host: reapurb error report fix
  usb-host: fix halted endpoints
  usb-host: fix configuration tracking.
  usb-host: endpoint table fixup
  usb-ehci: handle siTDs
  usb: fix use after free
  usb: claim port at device initialization time.

 hw/usb-bus.c  |  110 +--
 hw/usb-ehci.c |   65 +++---
 hw/usb-hub.c  |   12 +---
 hw/usb-ohci.c |4 +-
 hw/usb-uhci.c |   11 ++-
 hw/usb.c  |   37 
 hw/usb.h  |5 +-
 trace-events  |7 ++
 usb-linux.c   |  273 +++--
 9 files changed, 282 insertions(+), 242 deletions(-)



[Qemu-devel] [PATCH 1/7] usb-host: reapurb error report fix

2011-09-02 Thread Gerd Hoffmann
Don't report errors on devices which are in disconnected
and closing state.
(cherry picked from commit 3d09d54e57b92aaaba8d4e8c0d1c9901f1a56c7f)

Conflicts:

usb-linux.c
---
 usb-linux.c |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 53cc5fc..7d8a103 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -308,8 +308,10 @@ static void async_complete(void *opaque)
 }
 return;
 }
-if (errno == ENODEV  !s-closing) {
-do_disconnect(s);
+if (errno == ENODEV) {
+if (!s-closing) {
+do_disconnect(s);
+}
 return;
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH 7/7] usb: claim port at device initialization time.

2011-09-02 Thread Gerd Hoffmann
This patch makes qemu assign a port when creating the device, not when
attaching it.  For most usb devices this isn't a noticable difference
because they are in attached state all the time.

The change affects usb-host devices which live in detached state while
the real device is unplugged from the host.  They have a fixed port
assigned all the time now instead of getting grabbing one on attach and
releasing it at detach, i.e. they stop floating around at the usb bus.

The change also allows to simplify usb-hub.  It doesn't need the
handle_attach() callback any more to configure the downstream ports.
This can be done at device initialitation time now.  The changed
initialization order (first grab upstream port, then register downstream
ports) also fixes some icky corner cases.  For example it is not possible
any more to plug the hub into one of its own downstream ports.

The usb host adapters must care too.  USBPort-dev being non-NULL
doesn't imply any more the device is in attached state.  The host
adapters must additionally check the USBPort-dev-attached flag.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
(cherry picked from commit 763917c9b6d5a6126530d8e52324e653e594c521)
---
 hw/usb-bus.c  |  110 +
 hw/usb-ehci.c |   22 ++--
 hw/usb-hub.c  |   12 +--
 hw/usb-ohci.c |4 +-
 hw/usb-uhci.c |   11 +++---
 hw/usb.c  |   35 --
 hw/usb.h  |5 ++-
 trace-events  |6 +++
 8 files changed, 110 insertions(+), 95 deletions(-)

diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index f1dd55e..d384426 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -3,6 +3,7 @@
 #include qdev.h
 #include sysemu.h
 #include monitor.h
+#include trace.h
 
 static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent);
 
@@ -73,9 +74,13 @@ static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
 dev-info = info;
 dev-auto_attach = 1;
 QLIST_INIT(dev-strings);
-rc = dev-info-init(dev);
-if (rc == 0  dev-auto_attach)
+rc = usb_claim_port(dev);
+if (rc == 0) {
+rc = dev-info-init(dev);
+}
+if (rc == 0  dev-auto_attach) {
 rc = usb_device_attach(dev);
+}
 return rc;
 }
 
@@ -89,6 +94,9 @@ static int usb_qdev_exit(DeviceState *qdev)
 if (dev-info-handle_destroy) {
 dev-info-handle_destroy(dev);
 }
+if (dev-port) {
+usb_release_port(dev);
+}
 return 0;
 }
 
@@ -205,21 +213,13 @@ void usb_unregister_port(USBBus *bus, USBPort *port)
 bus-nfree--;
 }
 
-static int do_attach(USBDevice *dev)
+int usb_claim_port(USBDevice *dev)
 {
 USBBus *bus = usb_bus_from_device(dev);
 USBPort *port;
 
-if (dev-attached) {
-error_report(Error: tried to attach usb device %s twice\n,
-dev-product_desc);
-return -1;
-}
-if (bus-nfree == 0) {
-error_report(Error: tried to attach usb device %s to a bus with no 
free ports\n,
-dev-product_desc);
-return -1;
-}
+assert(dev-port == NULL);
+
 if (dev-port_path) {
 QTAILQ_FOREACH(port, bus-free, next) {
 if (strcmp(port-path, dev-port_path) == 0) {
@@ -227,68 +227,86 @@ static int do_attach(USBDevice *dev)
 }
 }
 if (port == NULL) {
-error_report(Error: usb port %s (bus %s) not found\n,
-dev-port_path, bus-qbus.name);
+error_report(Error: usb port %s (bus %s) not found (in use?)\n,
+ dev-port_path, bus-qbus.name);
 return -1;
 }
 } else {
+if (bus-nfree == 1  strcmp(dev-qdev.info-name, usb-hub) != 0) {
+/* Create a new hub and chain it on */
+usb_create_simple(bus, usb-hub);
+}
+if (bus-nfree == 0) {
+error_report(Error: tried to attach usb device %s to a bus 
+ with no free ports\n, dev-product_desc);
+return -1;
+}
 port = QTAILQ_FIRST(bus-free);
 }
-if (!(port-speedmask  dev-speedmask)) {
-error_report(Warning: speed mismatch trying to attach usb device %s 
to bus %s\n,
-dev-product_desc, bus-qbus.name);
-return -1;
-}
+trace_usb_port_claim(bus-busnr, port-path);
 
-dev-attached++;
 QTAILQ_REMOVE(bus-free, port, next);
 bus-nfree--;
 
-usb_attach(port, dev);
+dev-port = port;
+port-dev = dev;
 
 QTAILQ_INSERT_TAIL(bus-used, port, next);
 bus-nused++;
-
 return 0;
 }
 
-int usb_device_attach(USBDevice *dev)
+void usb_release_port(USBDevice *dev)
 {
 USBBus *bus = usb_bus_from_device(dev);
+USBPort *port = dev-port;
 
-if (bus-nfree == 1  dev-port_path == NULL) {
-/* Create a new hub and chain it on
-   (unless a physical port location is specified). */
-usb_create_simple(bus, usb-hub);
-}
-return do_attach(dev);
+assert(port != NULL);
+

Re: [Qemu-devel] [PATCH v2 07/45] ide: Use a table to declare which drive kinds accept each command

2011-09-02 Thread Kevin Wolf
Am 03.08.2011 18:53, schrieb Blue Swirl:
 On Wed, Aug 3, 2011 at 1:07 PM, Markus Armbruster arm...@redhat.com wrote:
 No functional change.

 It would be nice to have handler functions in the table, like commit
 e1a064f9 did for ATAPI.  Left for another day.

 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  hw/ide/core.c |  104 
 +++--
  1 files changed, 79 insertions(+), 25 deletions(-)

 diff --git a/hw/ide/core.c b/hw/ide/core.c
 index 1c4dc2f..a25c175 100644
 --- a/hw/ide/core.c
 +++ b/hw/ide/core.c
 @@ -876,6 +876,77 @@ void ide_ioport_write(void *opaque, uint32_t addr, 
 uint32_t val)
 }
  }

 +#define HD_OK (1u  IDE_HD)
 +#define CD_OK (1u  IDE_CD)
 +#define CFA_OK (1u  IDE_CFATA)
 +#define HD_CFA_OK (HD_OK | CFA_OK)
 +#define ALL_OK (HD_OK | CD_OK | CFA_OK)
 +
 +/* See ACS-2 T13/2015-D Table B.2 Command codes */
 +uint8_t ide_cmd_table[0x100] = {
 
 Missing 'static'.

And const, while we're at it.

 +/* NOP not implemented, mandatory for CD */
 +[CFA_REQ_EXT_ERROR_CODE]= CFA_OK,
 +[WIN_DSM]   = ALL_OK,
 +[WIN_DEVICE_RESET]  = CD_OK,
 +[WIN_RECAL] = ALL_OK,
 +[WIN_READ]  = ALL_OK,
 +[WIN_READ_ONCE] = ALL_OK,
 +[WIN_READ_EXT]  = ALL_OK,
 +[WIN_READDMA_EXT]   = ALL_OK,
 +[WIN_READ_NATIVE_MAX_EXT]   = ALL_OK,
 +[WIN_MULTREAD_EXT]  = ALL_OK,
 +[WIN_WRITE] = ALL_OK,
 +[WIN_WRITE_ONCE]= ALL_OK,
 +[WIN_WRITE_EXT] = ALL_OK,
 +[WIN_WRITEDMA_EXT]  = ALL_OK,
 +[CFA_WRITE_SECT_WO_ERASE]   = ALL_OK,
 +[WIN_MULTWRITE_EXT] = ALL_OK,
 +[WIN_WRITE_VERIFY]  = ALL_OK,
 +[WIN_VERIFY]= ALL_OK,
 +[WIN_VERIFY_ONCE]   = ALL_OK,
 +[WIN_VERIFY_EXT]= ALL_OK,
 +[WIN_SEEK]  = HD_CFA_OK,
 +[CFA_TRANSLATE_SECTOR]  = CFA_OK,
 +[WIN_DIAGNOSE]  = ALL_OK,
 +[WIN_SPECIFY]   = ALL_OK,
 +[WIN_STANDBYNOW2]   = ALL_OK,
 +[WIN_IDLEIMMEDIATE2]= ALL_OK,
 +[WIN_STANDBY2]  = ALL_OK,
 +[WIN_SETIDLE2]  = ALL_OK,
 +[WIN_CHECKPOWERMODE2]   = ALL_OK,
 +[WIN_SLEEPNOW2] = ALL_OK,
 +[WIN_PACKETCMD] = CD_OK,
 +[WIN_PIDENTIFY] = CD_OK,
 +[WIN_SMART] = HD_CFA_OK,
 +[CFA_ACCESS_METADATA_STORAGE]   = CFA_OK,
 +[CFA_ERASE_SECTORS] = CFA_OK,
 +[WIN_MULTREAD]  = ALL_OK,
 +[WIN_MULTWRITE] = ALL_OK,
 +[WIN_SETMULT]   = ALL_OK,
 +[WIN_READDMA]   = ALL_OK,
 +[WIN_READDMA_ONCE]  = ALL_OK,
 +[WIN_WRITEDMA]  = ALL_OK,
 +[WIN_WRITEDMA_ONCE] = ALL_OK,
 +[CFA_WRITE_MULTI_WO_ERASE]  = ALL_OK,
 +[WIN_STANDBYNOW1]   = ALL_OK,
 +[WIN_IDLEIMMEDIATE] = ALL_OK,
 +[WIN_STANDBY]   = ALL_OK,
 +[WIN_SETIDLE1]  = ALL_OK,
 +[WIN_CHECKPOWERMODE1]   = ALL_OK,
 +[WIN_SLEEPNOW1] = ALL_OK,
 +[WIN_FLUSH_CACHE]   = ALL_OK,
 +[WIN_FLUSH_CACHE_EXT]   = ALL_OK,
 +[WIN_IDENTIFY]  = ALL_OK,
 +[WIN_SETFEATURES]   = ALL_OK,
 +[IBM_SENSE_CONDITION]   = CFA_OK,
 +[CFA_WEAR_LEVEL]= CFA_OK,
 +[WIN_READ_NATIVE_MAX]   = ALL_OK,
 +};
 +
 +static bool ide_cmd_permitted(IDEState *s, uint32_t cmd)
 +{
 +return cmd = 0xff  (ide_cmd_table[cmd]  (1u  s-drive_kind));
 +}

Doesn't cmd  ARRAY_SIZE(ide_cmd_table) better describe what you want?

Kevin



[Qemu-devel] [PULL] usb patch queue

2011-09-02 Thread Gerd Hoffmann
  Hi,

This is the current use patch queue with the following changes:

  * musb improvements (qdev windup)
  * fix ehci emulation for FreeBSD guests.
  * a bunch if usb-host fixes.
  * misc minir tweaks.

please pull,
  Gerd

Gerd Hoffmann (15):
  usb-host: start tracing support
  usb-host: reapurb error report fix
  usb-host: fix halted endpoints
  usb-host: limit open retries
  usb-host: fix configuration tracking.
  usb-host: claim port
  usb-host: endpoint table fixup
  usb-ehci: handle siTDs
  usb-host: constify port
  usb-host: parse port in /proc/bus/usb/devices scan
  usb: fix use after free
  usb-ccid: switch to USBDesc*
  usb-ccid: remote wakeup support
  usb: claim port at device initialization time.
  usb-host: tag as unmigratable

Juha Riihimäki (1):
  usb-musb: Add reset function

Peter Maydell (2):
  usb: Remove leading underscores from __musb_irq_max
  usb-musb: Take a DeviceState* in init function

 hw/tusb6010.c |   11 +-
 hw/usb-bus.c  |  110 --
 hw/usb-ccid.c |  248 +++-
 hw/usb-desc.h |2 +-
 hw/usb-ehci.c |   65 +++--
 hw/usb-hub.c  |   12 +--
 hw/usb-musb.c |   26 +++-
 hw/usb-ohci.c |4 +-
 hw/usb-uhci.c |   11 +-
 hw/usb.c  |   37 +++---
 hw/usb.h  |   11 +-
 trace-events  |   32 
 usb-linux.c   |  448 ++---
 13 files changed, 561 insertions(+), 456 deletions(-)

The following changes since commit 625f9e1f54cd78ee98ac22030da527c9a1cc9d2b:

  Merge remote-tracking branch 'stefanha/trivial-patches' into staging 
(2011-09-01 13:57:19 -0500)

are available in the git repository at:

  git://git.kraxel.org/qemu usb.25

Gerd Hoffmann (15):
  usb-host: start tracing support
  usb-host: reapurb error report fix
  usb-host: fix halted endpoints
  usb-host: limit open retries
  usb-host: fix configuration tracking.
  usb-host: claim port
  usb-host: endpoint table fixup
  usb-ehci: handle siTDs
  usb-host: constify port
  usb-host: parse port in /proc/bus/usb/devices scan
  usb: fix use after free
  usb-ccid: switch to USBDesc*
  usb-ccid: remote wakeup support
  usb: claim port at device initialization time.
  usb-host: tag as unmigratable

Juha Riihimäki (1):
  usb-musb: Add reset function

Peter Maydell (2):
  usb: Remove leading underscores from __musb_irq_max
  usb-musb: Take a DeviceState* in init function

 hw/tusb6010.c |   11 +-
 hw/usb-bus.c  |  110 --
 hw/usb-ccid.c |  248 +++-
 hw/usb-desc.h |2 +-
 hw/usb-ehci.c |   65 +++--
 hw/usb-hub.c  |   12 +--
 hw/usb-musb.c |   26 +++-
 hw/usb-ohci.c |4 +-
 hw/usb-uhci.c |   11 +-
 hw/usb.c  |   37 +++---
 hw/usb.h  |   11 +-
 trace-events  |   32 
 usb-linux.c   |  448 ++---
 13 files changed, 561 insertions(+), 456 deletions(-)



Re: [Qemu-devel] [Qemu-trivial] [PATCH] x86: fix daa opcode for al register values higher than 0xf9

2011-09-02 Thread Stefan Hajnoczi
On Tue, Aug 30, 2011 at 10:00:55AM +0300, Boris Figovsky wrote:
 The second if statement should consider the original al register value,
 and not the new one.
 
 Signed-off-by: Boris Figovsky boris.figov...@ravellosystems.com
 ---
  target-i386/op_helper.c |6 +++---
  1 files changed, 3 insertions(+), 3 deletions(-)

Thanks, applied to the trivial patches tree:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/trivial-patches

Stefan



Re: [Qemu-devel] [PATCH] libcacard: use INSTALL_DATA for data

2011-09-02 Thread Stefan Hajnoczi
On Mon, Aug 22, 2011 at 01:34:57PM -0400, Brad wrote:
 On Sat, Aug 13, 2011 at 05:23:57PM -0400, Brad wrote:
  libcacard: use INSTALL_DATA for data
  
  Signed-off-by: Brad Smith b...@comstyle.com
  
  ---
   libcacard/Makefile |2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)
  
  diff --git a/libcacard/Makefile b/libcacard/Makefile
  index 5cd7594..fe9747a 100644
  --- a/libcacard/Makefile
  +++ b/libcacard/Makefile
  @@ -54,7 +54,7 @@ install-libcacard: libcacard.pc libcacard.la vscclient
  $(INSTALL_DIR) $(DESTDIR)$(libcacard_includedir)
  $(INSTALL_DIR) $(DESTDIR)$(bindir)
  libtool --mode=install $(INSTALL_PROG) vscclient $(DESTDIR)$(bindir)
  -   libtool --mode=install $(INSTALL_PROG) libcacard.la 
  $(DESTDIR)$(libdir)
  +   libtool --mode=install $(INSTALL_DATA) libcacard.la 
  $(DESTDIR)$(libdir)
  libtool --mode=install $(INSTALL_DATA) libcacard.pc 
  $(DESTDIR)$(libdir)/pkgconfig
  for inc in *.h; do \
  libtool --mode=install $(INSTALL_DATA) 
  $(libcacard_srcpath)/$$inc $(DESTDIR)$(libcacard_includedir); \
  -- 
  1.7.6
 
 An updated diff against up to date master.
 
 
 libcacard: use INSTALL_DATA for data
 
 Signed-off-by: Brad Smith b...@comstyle.com
 
 ---
  libcacard/Makefile |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

Thanks, applied to the trivial patches tree:
http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/trivial-patches

Stefan



[Qemu-devel] [PATCH 04/18] usb-host: limit open retries

2011-09-02 Thread Gerd Hoffmann
Limit the number of times qemu tries to open host devices to three.
Reset error counter when the device goes away, after un-plugging and
re-plugging the device qemu will try again three times.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 usb-linux.c |   13 -
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 344af22..36d25d7 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -132,6 +132,7 @@ typedef struct USBHostDevice {
 int addr;
 char port[MAX_PORTLEN];
 struct USBAutoFilter match;
+int seen, errcount;
 
 QTAILQ_ENTRY(USBHostDevice) next;
 } USBHostDevice;
@@ -1769,6 +1770,10 @@ static int usb_host_auto_scan(void *opaque, int bus_num, 
int addr, char *port,
 continue;
 }
 /* We got a match */
+s-seen++;
+if (s-errcount = 3) {
+return 0;
+}
 
 /* Already attached ? */
 if (s-fd != -1) {
@@ -1776,7 +1781,9 @@ static int usb_host_auto_scan(void *opaque, int bus_num, 
int addr, char *port,
 }
 DPRINTF(husb: auto open: bus_num %d addr %d\n, bus_num, addr);
 
-usb_host_open(s, bus_num, addr, port, product_name, speed);
+if (usb_host_open(s, bus_num, addr, port, product_name, speed)  0) {
+s-errcount++;
+}
 break;
 }
 
@@ -1794,6 +1801,10 @@ static void usb_host_auto_check(void *unused)
 if (s-fd == -1) {
 unconnected++;
 }
+if (s-seen == 0) {
+s-errcount = 0;
+}
+s-seen = 0;
 }
 
 if (unconnected == 0) {
-- 
1.7.1




[Qemu-devel] [PATCH 3/3] libcacard: use INSTALL_DATA for data

2011-09-02 Thread Stefan Hajnoczi
From: Brad Smith b...@comstyle.com

Signed-off-by: Brad Smith b...@comstyle.com
Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 libcacard/Makefile |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libcacard/Makefile b/libcacard/Makefile
index bf052bc..81d9eb5 100644
--- a/libcacard/Makefile
+++ b/libcacard/Makefile
@@ -56,7 +56,7 @@ install-libcacard: libcacard.pc libcacard.la vscclient
$(INSTALL_DIR) $(DESTDIR)$(libcacard_includedir)
$(INSTALL_DIR) $(DESTDIR)$(bindir)
$(LIBTOOL) --mode=install $(INSTALL_PROG) vscclient 
$(DESTDIR)$(bindir)
-   $(LIBTOOL) --mode=install $(INSTALL_PROG) libcacard.la 
$(DESTDIR)$(libdir)
+   $(LIBTOOL) --mode=install $(INSTALL_DATA) libcacard.la 
$(DESTDIR)$(libdir)
$(LIBTOOL) --mode=install $(INSTALL_DATA) libcacard.pc 
$(DESTDIR)$(libdir)/pkgconfig
for inc in *.h; do \
$(LIBTOOL) --mode=install $(INSTALL_DATA) 
$(libcacard_srcpath)/$$inc $(DESTDIR)$(libcacard_includedir); \
-- 
1.7.5.4




[Qemu-devel] [PATCH 2/3] x86: fix daa opcode for al register values higher than 0xf9

2011-09-02 Thread Stefan Hajnoczi
From: Boris Figovsky boris.figov...@ravellosystems.com

The second if statement should consider the original al register value,
and not the new one.

Signed-off-by: Boris Figovsky boris.figov...@ravellosystems.com
Reviewed-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 target-i386/op_helper.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c
index 1bbc3b5..1fc248f 100644
--- a/target-i386/op_helper.c
+++ b/target-i386/op_helper.c
@@ -1970,20 +1970,20 @@ void helper_aas(void)
 
 void helper_daa(void)
 {
-int al, af, cf;
+int old_al, al, af, cf;
 int eflags;
 
 eflags = helper_cc_compute_all(CC_OP);
 cf = eflags  CC_C;
 af = eflags  CC_A;
-al = EAX  0xff;
+old_al = al = EAX  0xff;
 
 eflags = 0;
 if (((al  0x0f)  9 ) || af) {
 al = (al + 6)  0xff;
 eflags |= CC_A;
 }
-if ((al  0x9f) || cf) {
+if ((old_al  0x99) || cf) {
 al = (al + 0x60)  0xff;
 eflags |= CC_C;
 }
-- 
1.7.5.4




[Qemu-devel] [PATCH 1/3] sh4: Fix potential crash in debug code

2011-09-02 Thread Stefan Hajnoczi
From: Stefan Weil w...@mail.berlios.de

cppcheck reports this error:

qemu/hw/sh_intc.c:390: error: Possible null pointer dereference:
 s - otherwise it is redundant to check if s is null at line 385

If s were NULL, the printf() statement would crash.
Setting braces fixes this bug.

Signed-off-by: Stefan Weil w...@mail.berlios.de
Reviewed-by: Andreas Färber andreas.faer...@web.de
Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
 hw/sh_intc.c |9 +
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/hw/sh_intc.c b/hw/sh_intc.c
index ecb46e5..e07424f 100644
--- a/hw/sh_intc.c
+++ b/hw/sh_intc.c
@@ -382,13 +382,14 @@ void sh_intc_register_sources(struct intc_desc *desc,
 
sh_intc_register_source(desc, vect-enum_id, groups, nr_groups);
s = sh_intc_source(desc, vect-enum_id);
-   if (s)
-   s-vect = vect-vect;
+if (s) {
+s-vect = vect-vect;
 
 #ifdef DEBUG_INTC_SOURCES
-   printf(sh_intc: registered source %d - 0x%04x (%d/%d)\n,
-  vect-enum_id, s-vect, s-enable_count, s-enable_max);
+printf(sh_intc: registered source %d - 0x%04x (%d/%d)\n,
+   vect-enum_id, s-vect, s-enable_count, s-enable_max);
 #endif
+}
 }
 
 if (groups) {
-- 
1.7.5.4




[Qemu-devel] [PULL 0/3] Trivial patches for Auguest 25 to September 2 2011

2011-09-02 Thread Stefan Hajnoczi
The following changes since commit 625f9e1f54cd78ee98ac22030da527c9a1cc9d2b:

  Merge remote-tracking branch 'stefanha/trivial-patches' into staging 
(2011-09-01 13:57:19 -0500)

are available in the git repository at:

  ssh://repo.or.cz/srv/git/qemu/stefanha.git trivial-patches

Boris Figovsky (1):
  x86: fix daa opcode for al register values higher than 0xf9

Brad Smith (1):
  libcacard: use INSTALL_DATA for data

Stefan Weil (1):
  sh4: Fix potential crash in debug code

 hw/sh_intc.c|9 +
 libcacard/Makefile  |2 +-
 target-i386/op_helper.c |6 +++---
 3 files changed, 9 insertions(+), 8 deletions(-)



Re: [Qemu-devel] [PATCH v2 09/45] ide/atapi: Clean up misleading name in cmd_start_stop_unit()

2011-09-02 Thread Kevin Wolf
Am 03.08.2011 15:07, schrieb Markus Armbruster:
 eject is misleading; it means eject when start is clear, but
 load when start is set.  Rename to loej, because that's how MMC-5
 calls it, in section 6.40.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  hw/ide/atapi.c |8 
  1 files changed, 4 insertions(+), 4 deletions(-)
 
 diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
 index fe2fb0b..17fbef8 100644
 --- a/hw/ide/atapi.c
 +++ b/hw/ide/atapi.c
 @@ -892,11 +892,11 @@ static void cmd_seek(IDEState *s, uint8_t* buf)
  
  static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)
  {
 -int start, eject, sense, err = 0;
 -start = buf[4]  1;
 -eject = (buf[4]  1)  1;
 +int sense, err = 0;
 +bool start = buf[4]  1;
 +bool loej = buf[4]  2;
  
 -if (eject) {
 +if (loej) {
  err = bdrv_eject(s-bs, !start);
  }
  

eject has the advantage that I immediately know that it's something to
do with the tray. loej on the other hand is a sequence of four random
characters. Maybe add a comment?

Kevin



Re: [Qemu-devel] [PATCH v2 10/45] ide/atapi: Track tray open/close state

2011-09-02 Thread Kevin Wolf
Am 03.08.2011 15:07, schrieb Markus Armbruster:
 We already track it in BlockDriverState since commit 4be9762a.  As
 discussed in that commit's message, we should track it in the device
 device models instead, because it's device state.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  hw/ide/atapi.c|6 +-
  hw/ide/internal.h |1 +
  2 files changed, 6 insertions(+), 1 deletions(-)
 
 diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
 index 17fbef8..96f7c31 100644
 --- a/hw/ide/atapi.c
 +++ b/hw/ide/atapi.c
 @@ -510,7 +510,7 @@ static unsigned int event_status_media(IDEState *s,
  uint8_t event_code, media_status;
  
  media_status = 0;
 -if (s-bs-tray_open) {
 +if (s-tray_open) {
  media_status = MS_TRAY_OPEN;
  } else if (bdrv_is_inserted(s-bs)) {
  media_status = MS_MEDIA_PRESENT;
 @@ -915,6 +915,10 @@ static void cmd_start_stop_unit(IDEState *s, uint8_t* 
 buf)
  ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT);
  break;
  }
 +
 +if (loej  !err) {
 +s-tray_open = !start;
 +}
  }
  
  static void cmd_mechanism_status(IDEState *s, uint8_t* buf)
 diff --git a/hw/ide/internal.h b/hw/ide/internal.h
 index 46e84fa..cd8e977 100644
 --- a/hw/ide/internal.h
 +++ b/hw/ide/internal.h
 @@ -442,6 +442,7 @@ struct IDEState {
  struct unreported_events events;
  uint8_t sense_key;
  uint8_t asc;
 +bool tray_open;
  uint8_t cdrom_changed;
  int packet_transfer_size;
  int elementary_transfer_size;

Probably needs to be migrated.

Kevin



Re: [Qemu-devel] [PATCH 0/3] usb-musb: make qdev-aware

2011-09-02 Thread Peter Maydell
On 2 September 2011 08:50, Gerd Hoffmann kra...@redhat.com wrote:
 Booting an image and operating some usb device is even better.

Incidentally, if anybody has both (1) an image/config that connects
a keyboard via usb-musb and (2) a copy of the MUSB hardware spec
they will be able to test and fix the bug that musb_port_ops doesn't
implement the wakeup callback. Sadly I have neither :-(

-- PMM



[Qemu-devel] [PATCH 5/7] usb-ehci: handle siTDs

2011-09-02 Thread Gerd Hoffmann
This patch adds code to do minimal siTD handling, which is basically
just following the next pointer.  This is good enougth to handle the
inactive siTDs used by FreeBSD.  Active siTDs are skipped too as we
don't have split transfer support in qemu, additionally a warning is
printed.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
(cherry picked from commit c57f5348b0c95b46b98b9ddb48b059b29c178452)
---
 hw/usb-ehci.c |   43 ++-
 trace-events  |1 +
 2 files changed, 43 insertions(+), 1 deletions(-)

diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c
index a4758f9..3ea4c72 100644
--- a/hw/usb-ehci.c
+++ b/hw/usb-ehci.c
@@ -148,6 +148,7 @@ typedef enum {
 EST_FETCHENTRY,
 EST_FETCHQH,
 EST_FETCHITD,
+EST_FETCHSITD,
 EST_ADVANCEQUEUE,
 EST_FETCHQTD,
 EST_EXECUTE,
@@ -645,6 +646,13 @@ static void ehci_trace_itd(EHCIState *s, 
target_phys_addr_t addr, EHCIitd *itd)
get_field(itd-bufptr[0], ITD_BUFPTR_DEVADDR));
 }
 
+static void ehci_trace_sitd(EHCIState *s, target_phys_addr_t addr,
+EHCIsitd *sitd)
+{
+trace_usb_ehci_sitd(addr, sitd-next,
+(bool)(sitd-results  SITD_RESULTS_ACTIVE));
+}
+
 /* queue management */
 
 static EHCIQueue *ehci_alloc_queue(EHCIState *ehci, int async)
@@ -1613,8 +1621,13 @@ static int ehci_state_fetchentry(EHCIState *ehci, int 
async)
 again = 1;
 break;
 
+case NLPTR_TYPE_STITD:
+ehci_set_state(ehci, async, EST_FETCHSITD);
+again = 1;
+break;
+
 default:
-// TODO: handle siTD and FSTN types
+/* TODO: handle FSTN type */
 fprintf(stderr, FETCHENTRY: entry at %X is of type %d 
 which is not supported yet\n, entry, NLPTR_TYPE_GET(entry));
 return -1;
@@ -1730,6 +1743,30 @@ static int ehci_state_fetchitd(EHCIState *ehci, int 
async)
 return 1;
 }
 
+static int ehci_state_fetchsitd(EHCIState *ehci, int async)
+{
+uint32_t entry;
+EHCIsitd sitd;
+
+assert(!async);
+entry = ehci_get_fetch_addr(ehci, async);
+
+get_dwords(NLPTR_GET(entry), (uint32_t *)sitd,
+   sizeof(EHCIsitd)  2);
+ehci_trace_sitd(ehci, entry, sitd);
+
+if (!(sitd.results  SITD_RESULTS_ACTIVE)) {
+/* siTD is not active, nothing to do */;
+} else {
+/* TODO: split transfers are not implemented */
+fprintf(stderr, WARNING: Skipping active siTD\n);
+}
+
+ehci_set_fetch_addr(ehci, async, sitd.next);
+ehci_set_state(ehci, async, EST_FETCHENTRY);
+return 1;
+}
+
 /* Section 4.10.2 - paragraph 3 */
 static int ehci_state_advqueue(EHCIQueue *q, int async)
 {
@@ -2005,6 +2042,10 @@ static void ehci_advance_state(EHCIState *ehci,
 again = ehci_state_fetchitd(ehci, async);
 break;
 
+case EST_FETCHSITD:
+again = ehci_state_fetchsitd(ehci, async);
+break;
+
 case EST_ADVANCEQUEUE:
 again = ehci_state_advqueue(q, async);
 break;
diff --git a/trace-events b/trace-events
index 713f042..e6f8c37 100644
--- a/trace-events
+++ b/trace-events
@@ -223,6 +223,7 @@ disable usb_ehci_qtd_ptrs(void *q, uint32_t addr, uint32_t 
nxt, uint32_t altnext
 disable usb_ehci_qtd_fields(uint32_t addr, int tbytes, int cpage, int cerr, 
int pid) QTD @ %08x - tbytes %d, cpage %d, cerr %d, pid %d
 disable usb_ehci_qtd_bits(uint32_t addr, int ioc, int active, int halt, int 
babble, int xacterr) QTD @ %08x - ioc %d, active %d, halt %d, babble %d, 
xacterr %d
 disable usb_ehci_itd(uint32_t addr, uint32_t nxt, uint32_t mplen, uint32_t 
mult, uint32_t ep, uint32_t devaddr) ITD @ %08x: next %08x - mplen %d, mult 
%d, ep %d, dev %d
+disable usb_ehci_sitd(uint32_t addr, uint32_t nxt, uint32_t active) ITD @ 
%08x: next %08x - active %d
 disable usb_ehci_port_attach(uint32_t port, const char *device) attach port 
#%d - %s
 disable usb_ehci_port_detach(uint32_t port) detach port #%d
 disable usb_ehci_port_reset(uint32_t port, int enable) reset port #%d - %d
-- 
1.7.1




[Qemu-devel] [PATCH 4/7] usb-host: endpoint table fixup

2011-09-02 Thread Gerd Hoffmann
USB Devices can have up to 15 IN and 15 OUT endpoints, not 15 endpoints
total.  Move from one array to two arrays (one IN, one OUT) to maintain
the endpoint state.
(cherry picked from commit 07d4920d2bca19c64827a226b0afdfe8c7f1e3f0)

Conflicts:

usb-linux.c
---
 usb-linux.c |  178 +-
 1 files changed, 101 insertions(+), 77 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 74f1a0b..c1c2349 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -123,7 +123,8 @@ typedef struct USBHostDevice {
 uint32_t  iso_urb_count;
 Notifier  exit;
 
-struct endp_data endp_table[MAX_ENDPOINTS];
+struct endp_data ep_in[MAX_ENDPOINTS];
+struct endp_data ep_out[MAX_ENDPOINTS];
 QLIST_HEAD(, AsyncURB) aurbs;
 
 /* Host side address */
@@ -144,94 +145,101 @@ static int usb_host_read_file(char *line, size_t 
line_size,
 const char *device_file, const char *device_name);
 static int usb_linux_update_endp_table(USBHostDevice *s);
 
-static struct endp_data *get_endp(USBHostDevice *s, int ep)
+static struct endp_data *get_endp(USBHostDevice *s, int pid, int ep)
 {
-return s-endp_table + ep - 1;
+struct endp_data *eps = pid == USB_TOKEN_IN ? s-ep_in : s-ep_out;
+assert(pid == USB_TOKEN_IN || pid == USB_TOKEN_OUT);
+assert(ep  0  ep = MAX_ENDPOINTS);
+return eps + ep - 1;
 }
 
-static int is_isoc(USBHostDevice *s, int ep)
+static int is_isoc(USBHostDevice *s, int pid, int ep)
 {
-return get_endp(s, ep)-type == USBDEVFS_URB_TYPE_ISO;
+return get_endp(s, pid, ep)-type == USBDEVFS_URB_TYPE_ISO;
 }
 
-static int is_valid(USBHostDevice *s, int ep)
+static int is_valid(USBHostDevice *s, int pid, int ep)
 {
-return get_endp(s, ep)-type != INVALID_EP_TYPE;
+return get_endp(s, pid, ep)-type != INVALID_EP_TYPE;
 }
 
-static int is_halted(USBHostDevice *s, int ep)
+static int is_halted(USBHostDevice *s, int pid, int ep)
 {
-return get_endp(s, ep)-halted;
+return get_endp(s, pid, ep)-halted;
 }
 
-static void clear_halt(USBHostDevice *s, int ep)
+static void clear_halt(USBHostDevice *s, int pid, int ep)
 {
-get_endp(s, ep)-halted = 0;
+get_endp(s, pid, ep)-halted = 0;
 }
 
-static void set_halt(USBHostDevice *s, int ep)
+static void set_halt(USBHostDevice *s, int pid, int ep)
 {
-get_endp(s, ep)-halted = 1;
+if (ep != 0) {
+get_endp(s, pid, ep)-halted = 1;
+}
 }
 
-static int is_iso_started(USBHostDevice *s, int ep)
+static int is_iso_started(USBHostDevice *s, int pid, int ep)
 {
-return get_endp(s, ep)-iso_started;
+return get_endp(s, pid, ep)-iso_started;
 }
 
-static void clear_iso_started(USBHostDevice *s, int ep)
+static void clear_iso_started(USBHostDevice *s, int pid, int ep)
 {
-get_endp(s, ep)-iso_started = 0;
+get_endp(s, pid, ep)-iso_started = 0;
 }
 
-static void set_iso_started(USBHostDevice *s, int ep)
+static void set_iso_started(USBHostDevice *s, int pid, int ep)
 {
-struct endp_data *e = get_endp(s, ep);
+struct endp_data *e = get_endp(s, pid, ep);
+
 if (!e-iso_started) {
 e-iso_started = 1;
 e-inflight = 0;
 }
 }
 
-static int change_iso_inflight(USBHostDevice *s, int ep, int value)
+static int change_iso_inflight(USBHostDevice *s, int pid, int ep, int value)
 {
-struct endp_data *e = get_endp(s, ep);
+struct endp_data *e = get_endp(s, pid, ep);
 
 e-inflight += value;
 return e-inflight;
 }
 
-static void set_iso_urb(USBHostDevice *s, int ep, AsyncURB *iso_urb)
+static void set_iso_urb(USBHostDevice *s, int pid, int ep, AsyncURB *iso_urb)
 {
-get_endp(s, ep)-iso_urb = iso_urb;
+get_endp(s, pid, ep)-iso_urb = iso_urb;
 }
 
-static AsyncURB *get_iso_urb(USBHostDevice *s, int ep)
+static AsyncURB *get_iso_urb(USBHostDevice *s, int pid, int ep)
 {
-return get_endp(s, ep)-iso_urb;
+return get_endp(s, pid, ep)-iso_urb;
 }
 
-static void set_iso_urb_idx(USBHostDevice *s, int ep, int i)
+static void set_iso_urb_idx(USBHostDevice *s, int pid, int ep, int i)
 {
-get_endp(s, ep)-iso_urb_idx = i;
+get_endp(s, pid, ep)-iso_urb_idx = i;
 }
 
-static int get_iso_urb_idx(USBHostDevice *s, int ep)
+static int get_iso_urb_idx(USBHostDevice *s, int pid, int ep)
 {
-return get_endp(s, ep)-iso_urb_idx;
+return get_endp(s, pid, ep)-iso_urb_idx;
 }
 
-static void set_iso_buffer_used(USBHostDevice *s, int ep, int i)
+static void set_iso_buffer_used(USBHostDevice *s, int pid, int ep, int i)
 {
-get_endp(s, ep)-iso_buffer_used = i;
+get_endp(s, pid, ep)-iso_buffer_used = i;
 }
 
-static int get_iso_buffer_used(USBHostDevice *s, int ep)
+static int get_iso_buffer_used(USBHostDevice *s, int pid, int ep)
 {
-return get_endp(s, ep)-iso_buffer_used;
+return get_endp(s, pid, ep)-iso_buffer_used;
 }
 
-static void set_max_packet_size(USBHostDevice *s, int ep, uint8_t *descriptor)
+static void set_max_packet_size(USBHostDevice *s, int pid, int ep,
+

[Qemu-devel] [PATCH 17/18] usb-musb: Take a DeviceState* in init function

2011-09-02 Thread Gerd Hoffmann
From: Peter Maydell peter.mayd...@linaro.org

Initialise usb-musb by passing it a DeviceState* and the offset of the
IRQs in its gpio array, rather than a plain pointer to an irq array.
This is simpler for callers and also allows us to pass in a valid parent
to usb_bus_new(), so the USB bus actually appears in the qdev tree.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/tusb6010.c |8 +---
 hw/usb-musb.c |   10 ++
 hw/usb.h  |2 +-
 3 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/hw/tusb6010.c b/hw/tusb6010.c
index 78814f1..57fe804 100644
--- a/hw/tusb6010.c
+++ b/hw/tusb6010.c
@@ -776,8 +776,6 @@ static void tusb6010_reset(DeviceState *dev)
 static int tusb6010_init(SysBusDevice *dev)
 {
 TUSBState *s = FROM_SYSBUS(TUSBState, dev);
-qemu_irq *musb_irqs;
-int i;
 s-otg_timer = qemu_new_timer_ns(vm_clock, tusb_otg_tick, s);
 s-pwr_timer = qemu_new_timer_ns(vm_clock, tusb_power_tick, s);
 memory_region_init_io(s-iomem[1], tusb_async_ops, s, tusb-async,
@@ -786,11 +784,7 @@ static int tusb6010_init(SysBusDevice *dev)
 sysbus_init_mmio_region(dev, s-iomem[1]);
 sysbus_init_irq(dev, s-irq);
 qdev_init_gpio_in(dev-qdev, tusb6010_irq, musb_irq_max + 1);
-musb_irqs = g_new0(qemu_irq, musb_irq_max);
-for (i = 0; i  musb_irq_max; i++) {
-musb_irqs[i] = qdev_get_gpio_in(dev-qdev, i + 1);
-}
-s-musb = musb_init(musb_irqs);
+s-musb = musb_init(dev-qdev, 1);
 return 0;
 }
 
diff --git a/hw/usb-musb.c b/hw/usb-musb.c
index 799fa6e..640037f 100644
--- a/hw/usb-musb.c
+++ b/hw/usb-musb.c
@@ -314,7 +314,7 @@ struct MUSBEndPoint {
 };
 
 struct MUSBState {
-qemu_irq *irqs;
+qemu_irq irqs[musb_irq_max];
 USBBus bus;
 USBPort port;
 
@@ -340,12 +340,14 @@ struct MUSBState {
 MUSBEndPoint ep[16];
 };
 
-struct MUSBState *musb_init(qemu_irq *irqs)
+struct MUSBState *musb_init(DeviceState *parent_device, int gpio_base)
 {
 MUSBState *s = g_malloc0(sizeof(*s));
 int i;
 
-s-irqs = irqs;
+for (i = 0; i  musb_irq_max; i++) {
+s-irqs[i] = qdev_get_gpio_in(parent_device, gpio_base + i);
+}
 
 s-faddr = 0x00;
 s-power = MGC_M_POWER_HSENAB;
@@ -369,7 +371,7 @@ struct MUSBState *musb_init(qemu_irq *irqs)
 usb_packet_init(s-ep[i].packey[1].p);
 }
 
-usb_bus_new(s-bus, musb_bus_ops, NULL /* FIXME */);
+usb_bus_new(s-bus, musb_bus_ops, parent_device);
 usb_register_port(s-bus, s-port, s, 0, musb_port_ops,
   USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);
 
diff --git a/hw/usb.h b/hw/usb.h
index e251e61..55c061e 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -343,7 +343,7 @@ enum musb_irq_source_e {
 };
 
 typedef struct MUSBState MUSBState;
-MUSBState *musb_init(qemu_irq *irqs);
+MUSBState *musb_init(DeviceState *parent_device, int gpio_base);
 uint32_t musb_core_intr_get(MUSBState *s);
 void musb_core_intr_clear(MUSBState *s, uint32_t mask);
 void musb_set_size(MUSBState *s, int epnum, int size, int is_tx);
-- 
1.7.1




[Qemu-devel] [PATCH 6/7] usb: fix use after free

2011-09-02 Thread Gerd Hoffmann
The -complete() callback might have released the USBPacket (uhci
actually does), so we must not touch it after the callback returns.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
(cherry picked from commit 722d89396b6ccb49cd9d3aafd991ae01c8a30744)
---
 hw/usb.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/usb.c b/hw/usb.c
index 27a983c..b44e997 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -334,8 +334,8 @@ void usb_packet_complete(USBDevice *dev, USBPacket *p)
 {
 /* Note: p-owner != dev is possible in case dev is a hub */
 assert(p-owner != NULL);
-dev-port-ops-complete(dev-port, p);
 p-owner = NULL;
+dev-port-ops-complete(dev-port, p);
 }
 
 /* Cancel an active packet.  The packed must have been deferred by
-- 
1.7.1




[Qemu-devel] [PATCH 11/18] usb: fix use after free

2011-09-02 Thread Gerd Hoffmann
The -complete() callback might have released the USBPacket (uhci
actually does), so we must not touch it after the callback returns.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/usb.c b/hw/usb.c
index 685e775..a091e4e 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -338,8 +338,8 @@ void usb_packet_complete(USBDevice *dev, USBPacket *p)
 {
 /* Note: p-owner != dev is possible in case dev is a hub */
 assert(p-owner != NULL);
-dev-port-ops-complete(dev-port, p);
 p-owner = NULL;
+dev-port-ops-complete(dev-port, p);
 }
 
 /* Cancel an active packet.  The packed must have been deferred by
-- 
1.7.1




Re: [Qemu-devel] [PATCH] libcacard: use INSTALL_DATA for data

2011-09-02 Thread Alon Levy
On Fri, Sep 02, 2011 at 11:10:32AM +0100, Stefan Hajnoczi wrote:
 On Mon, Aug 22, 2011 at 01:34:57PM -0400, Brad wrote:
  On Sat, Aug 13, 2011 at 05:23:57PM -0400, Brad wrote:
   libcacard: use INSTALL_DATA for data
   
   Signed-off-by: Brad Smith b...@comstyle.com
   
   ---
libcacard/Makefile |2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
   
   diff --git a/libcacard/Makefile b/libcacard/Makefile
   index 5cd7594..fe9747a 100644
   --- a/libcacard/Makefile
   +++ b/libcacard/Makefile
   @@ -54,7 +54,7 @@ install-libcacard: libcacard.pc libcacard.la vscclient
 $(INSTALL_DIR) $(DESTDIR)$(libcacard_includedir)
 $(INSTALL_DIR) $(DESTDIR)$(bindir)
 libtool --mode=install $(INSTALL_PROG) vscclient $(DESTDIR)$(bindir)
   - libtool --mode=install $(INSTALL_PROG) libcacard.la 
   $(DESTDIR)$(libdir)
   + libtool --mode=install $(INSTALL_DATA) libcacard.la 
   $(DESTDIR)$(libdir)
 libtool --mode=install $(INSTALL_DATA) libcacard.pc 
   $(DESTDIR)$(libdir)/pkgconfig
 for inc in *.h; do \
 libtool --mode=install $(INSTALL_DATA) 
   $(libcacard_srcpath)/$$inc $(DESTDIR)$(libcacard_includedir); \
   -- 
   1.7.6
  
  An updated diff against up to date master.
  
  
  libcacard: use INSTALL_DATA for data
  
  Signed-off-by: Brad Smith b...@comstyle.com
  
  ---
   libcacard/Makefile |2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)
 
 Thanks, applied to the trivial patches tree:
 http://repo.or.cz/w/qemu/stefanha.git/shortlog/refs/heads/trivial-patches
 
Thanks, my bad for not doing a pull request.

 Stefan
 



Re: [Qemu-devel] [PATCH v2 11/45] scsi-disk: Factor out scsi_disk_emulate_start_stop()

2011-09-02 Thread Kevin Wolf
Am 03.08.2011 15:07, schrieb Markus Armbruster:
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  hw/scsi-disk.c |   17 +
  1 files changed, 13 insertions(+), 4 deletions(-)
 
 diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
 index fa198f9..d549cb7 100644
 --- a/hw/scsi-disk.c
 +++ b/hw/scsi-disk.c
 @@ -820,6 +820,18 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, 
 uint8_t *outbuf)
  return toclen;
  }
  
 +static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
 +{
 +SCSIRequest *req = r-req;
 +SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req-dev);
 +bool start = req-cmd.buf[4]  1;
 +bool loej = req-cmd.buf[4]  2;
 +
 +if (s-qdev.type == TYPE_ROM  loej) {
 +bdrv_eject(s-bs, !start);
 +}
 +}
 +
  static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
  {
  SCSIRequest *req = r-req;
 @@ -873,10 +885,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, 
 uint8_t *outbuf)
  goto illegal_request;
  break;
  case START_STOP:
 -if (s-qdev.type == TYPE_ROM  (req-cmd.buf[4]  2)) {
 -/* load/eject medium */

So here we actually had the comment before. Can we retain it?

Kevin



[Qemu-devel] [PATCH 14/18] usb: claim port at device initialization time.

2011-09-02 Thread Gerd Hoffmann
This patch makes qemu assign a port when creating the device, not when
attaching it.  For most usb devices this isn't a noticable difference
because they are in attached state all the time.

The change affects usb-host devices which live in detached state while
the real device is unplugged from the host.  They have a fixed port
assigned all the time now instead of getting grabbing one on attach and
releasing it at detach, i.e. they stop floating around at the usb bus.

The change also allows to simplify usb-hub.  It doesn't need the
handle_attach() callback any more to configure the downstream ports.
This can be done at device initialitation time now.  The changed
initialization order (first grab upstream port, then register downstream
ports) also fixes some icky corner cases.  For example it is not possible
any more to plug the hub into one of its own downstream ports.

The usb host adapters must care too.  USBPort-dev being non-NULL
doesn't imply any more the device is in attached state.  The host
adapters must additionally check the USBPort-dev-attached flag.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-bus.c  |  110 +
 hw/usb-ehci.c |   22 ++--
 hw/usb-hub.c  |   12 +--
 hw/usb-ohci.c |4 +-
 hw/usb-uhci.c |   11 +++---
 hw/usb.c  |   35 --
 hw/usb.h  |5 ++-
 trace-events  |6 +++
 8 files changed, 110 insertions(+), 95 deletions(-)

diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index c0bbc7c..93f640d 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -3,6 +3,7 @@
 #include qdev.h
 #include sysemu.h
 #include monitor.h
+#include trace.h
 
 static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent);
 
@@ -73,9 +74,13 @@ static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
 dev-info = info;
 dev-auto_attach = 1;
 QLIST_INIT(dev-strings);
-rc = dev-info-init(dev);
-if (rc == 0  dev-auto_attach)
+rc = usb_claim_port(dev);
+if (rc == 0) {
+rc = dev-info-init(dev);
+}
+if (rc == 0  dev-auto_attach) {
 rc = usb_device_attach(dev);
+}
 return rc;
 }
 
@@ -89,6 +94,9 @@ static int usb_qdev_exit(DeviceState *qdev)
 if (dev-info-handle_destroy) {
 dev-info-handle_destroy(dev);
 }
+if (dev-port) {
+usb_release_port(dev);
+}
 return 0;
 }
 
@@ -205,21 +213,13 @@ void usb_unregister_port(USBBus *bus, USBPort *port)
 bus-nfree--;
 }
 
-static int do_attach(USBDevice *dev)
+int usb_claim_port(USBDevice *dev)
 {
 USBBus *bus = usb_bus_from_device(dev);
 USBPort *port;
 
-if (dev-attached) {
-error_report(Error: tried to attach usb device %s twice\n,
-dev-product_desc);
-return -1;
-}
-if (bus-nfree == 0) {
-error_report(Error: tried to attach usb device %s to a bus with no 
free ports\n,
-dev-product_desc);
-return -1;
-}
+assert(dev-port == NULL);
+
 if (dev-port_path) {
 QTAILQ_FOREACH(port, bus-free, next) {
 if (strcmp(port-path, dev-port_path) == 0) {
@@ -227,68 +227,86 @@ static int do_attach(USBDevice *dev)
 }
 }
 if (port == NULL) {
-error_report(Error: usb port %s (bus %s) not found\n,
-dev-port_path, bus-qbus.name);
+error_report(Error: usb port %s (bus %s) not found (in use?)\n,
+ dev-port_path, bus-qbus.name);
 return -1;
 }
 } else {
+if (bus-nfree == 1  strcmp(dev-qdev.info-name, usb-hub) != 0) {
+/* Create a new hub and chain it on */
+usb_create_simple(bus, usb-hub);
+}
+if (bus-nfree == 0) {
+error_report(Error: tried to attach usb device %s to a bus 
+ with no free ports\n, dev-product_desc);
+return -1;
+}
 port = QTAILQ_FIRST(bus-free);
 }
-if (!(port-speedmask  dev-speedmask)) {
-error_report(Warning: speed mismatch trying to attach usb device %s 
to bus %s\n,
-dev-product_desc, bus-qbus.name);
-return -1;
-}
+trace_usb_port_claim(bus-busnr, port-path);
 
-dev-attached++;
 QTAILQ_REMOVE(bus-free, port, next);
 bus-nfree--;
 
-usb_attach(port, dev);
+dev-port = port;
+port-dev = dev;
 
 QTAILQ_INSERT_TAIL(bus-used, port, next);
 bus-nused++;
-
 return 0;
 }
 
-int usb_device_attach(USBDevice *dev)
+void usb_release_port(USBDevice *dev)
 {
 USBBus *bus = usb_bus_from_device(dev);
+USBPort *port = dev-port;
 
-if (bus-nfree == 1  dev-port_path == NULL) {
-/* Create a new hub and chain it on
-   (unless a physical port location is specified). */
-usb_create_simple(bus, usb-hub);
-}
-return do_attach(dev);
+assert(port != NULL);
+trace_usb_port_release(bus-busnr, port-path);
+
+

[Qemu-devel] [PATCH 10/18] usb-host: parse port in /proc/bus/usb/devices scan

2011-09-02 Thread Gerd Hoffmann
Unfortunaly this is limited to root ports.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 usb-linux.c |   14 --
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index ef29a76..7995178 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -1483,7 +1483,8 @@ static int usb_host_scan_dev(void *opaque, USBScanFunc 
*func)
 FILE *f = NULL;
 char line[1024];
 char buf[1024];
-int bus_num, addr, speed, device_count, class_id, product_id, vendor_id;
+int bus_num, addr, speed, device_count;
+int class_id, product_id, vendor_id, port;
 char product_name[512];
 int ret = 0;
 
@@ -1521,6 +1522,10 @@ static int usb_host_scan_dev(void *opaque, USBScanFunc 
*func)
 goto fail;
 }
 bus_num = atoi(buf);
+if (get_tag_value(buf, sizeof(buf), line, Port=,  )  0) {
+goto fail;
+}
+port = atoi(buf);
 if (get_tag_value(buf, sizeof(buf), line, Dev#=,  )  0) {
 goto fail;
 }
@@ -1566,7 +1571,12 @@ static int usb_host_scan_dev(void *opaque, USBScanFunc 
*func)
 }
 if (device_count  (vendor_id || product_id)) {
 /* Add the last device.  */
-ret = func(opaque, bus_num, addr, 0, class_id, vendor_id,
+if (port  0) {
+snprintf(buf, sizeof(buf), %d, port);
+} else {
+snprintf(buf, sizeof(buf), ?);
+}
+ret = func(opaque, bus_num, addr, buf, class_id, vendor_id,
product_id, product_name, speed);
 }
  the_end:
-- 
1.7.1




[Qemu-devel] [PATCH 07/18] usb-host: endpoint table fixup

2011-09-02 Thread Gerd Hoffmann
USB Devices can have up to 15 IN and 15 OUT endpoints, not 15 endpoints
total.  Move from one array to two arrays (one IN, one OUT) to maintain
the endpoint state.
---
 usb-linux.c |  179 +--
 1 files changed, 101 insertions(+), 78 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index ce0eadd..6490582 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -125,7 +125,8 @@ typedef struct USBHostDevice {
 uint32_t  iso_urb_count;
 Notifier  exit;
 
-struct endp_data endp_table[MAX_ENDPOINTS];
+struct endp_data ep_in[MAX_ENDPOINTS];
+struct endp_data ep_out[MAX_ENDPOINTS];
 QLIST_HEAD(, AsyncURB) aurbs;
 
 /* Host side address */
@@ -147,52 +148,57 @@ static int usb_host_read_file(char *line, size_t 
line_size,
 const char *device_file, const char *device_name);
 static int usb_linux_update_endp_table(USBHostDevice *s);
 
-static struct endp_data *get_endp(USBHostDevice *s, int ep)
+static struct endp_data *get_endp(USBHostDevice *s, int pid, int ep)
 {
-return s-endp_table + ep - 1;
+struct endp_data *eps = pid == USB_TOKEN_IN ? s-ep_in : s-ep_out;
+assert(pid == USB_TOKEN_IN || pid == USB_TOKEN_OUT);
+assert(ep  0  ep = MAX_ENDPOINTS);
+return eps + ep - 1;
 }
 
-static int is_isoc(USBHostDevice *s, int ep)
+static int is_isoc(USBHostDevice *s, int pid, int ep)
 {
-return get_endp(s, ep)-type == USBDEVFS_URB_TYPE_ISO;
+return get_endp(s, pid, ep)-type == USBDEVFS_URB_TYPE_ISO;
 }
 
-static int is_valid(USBHostDevice *s, int ep)
+static int is_valid(USBHostDevice *s, int pid, int ep)
 {
-return get_endp(s, ep)-type != INVALID_EP_TYPE;
+return get_endp(s, pid, ep)-type != INVALID_EP_TYPE;
 }
 
-static int is_halted(USBHostDevice *s, int ep)
+static int is_halted(USBHostDevice *s, int pid, int ep)
 {
-return get_endp(s, ep)-halted;
+return get_endp(s, pid, ep)-halted;
 }
 
-static void clear_halt(USBHostDevice *s, int ep)
+static void clear_halt(USBHostDevice *s, int pid, int ep)
 {
 trace_usb_host_ep_clear_halt(s-bus_num, s-addr, ep);
-get_endp(s, ep)-halted = 0;
+get_endp(s, pid, ep)-halted = 0;
 }
 
-static void set_halt(USBHostDevice *s, int ep)
+static void set_halt(USBHostDevice *s, int pid, int ep)
 {
-trace_usb_host_ep_set_halt(s-bus_num, s-addr, ep);
-get_endp(s, ep)-halted = 1;
+if (ep != 0) {
+trace_usb_host_ep_set_halt(s-bus_num, s-addr, ep);
+get_endp(s, pid, ep)-halted = 1;
+}
 }
 
-static int is_iso_started(USBHostDevice *s, int ep)
+static int is_iso_started(USBHostDevice *s, int pid, int ep)
 {
-return get_endp(s, ep)-iso_started;
+return get_endp(s, pid, ep)-iso_started;
 }
 
-static void clear_iso_started(USBHostDevice *s, int ep)
+static void clear_iso_started(USBHostDevice *s, int pid, int ep)
 {
 trace_usb_host_ep_stop_iso(s-bus_num, s-addr, ep);
-get_endp(s, ep)-iso_started = 0;
+get_endp(s, pid, ep)-iso_started = 0;
 }
 
-static void set_iso_started(USBHostDevice *s, int ep)
+static void set_iso_started(USBHostDevice *s, int pid, int ep)
 {
-struct endp_data *e = get_endp(s, ep);
+struct endp_data *e = get_endp(s, pid, ep);
 
 trace_usb_host_ep_start_iso(s-bus_num, s-addr, ep);
 if (!e-iso_started) {
@@ -201,45 +207,46 @@ static void set_iso_started(USBHostDevice *s, int ep)
 }
 }
 
-static int change_iso_inflight(USBHostDevice *s, int ep, int value)
+static int change_iso_inflight(USBHostDevice *s, int pid, int ep, int value)
 {
-struct endp_data *e = get_endp(s, ep);
+struct endp_data *e = get_endp(s, pid, ep);
 
 e-inflight += value;
 return e-inflight;
 }
 
-static void set_iso_urb(USBHostDevice *s, int ep, AsyncURB *iso_urb)
+static void set_iso_urb(USBHostDevice *s, int pid, int ep, AsyncURB *iso_urb)
 {
-get_endp(s, ep)-iso_urb = iso_urb;
+get_endp(s, pid, ep)-iso_urb = iso_urb;
 }
 
-static AsyncURB *get_iso_urb(USBHostDevice *s, int ep)
+static AsyncURB *get_iso_urb(USBHostDevice *s, int pid, int ep)
 {
-return get_endp(s, ep)-iso_urb;
+return get_endp(s, pid, ep)-iso_urb;
 }
 
-static void set_iso_urb_idx(USBHostDevice *s, int ep, int i)
+static void set_iso_urb_idx(USBHostDevice *s, int pid, int ep, int i)
 {
-get_endp(s, ep)-iso_urb_idx = i;
+get_endp(s, pid, ep)-iso_urb_idx = i;
 }
 
-static int get_iso_urb_idx(USBHostDevice *s, int ep)
+static int get_iso_urb_idx(USBHostDevice *s, int pid, int ep)
 {
-return get_endp(s, ep)-iso_urb_idx;
+return get_endp(s, pid, ep)-iso_urb_idx;
 }
 
-static void set_iso_buffer_used(USBHostDevice *s, int ep, int i)
+static void set_iso_buffer_used(USBHostDevice *s, int pid, int ep, int i)
 {
-get_endp(s, ep)-iso_buffer_used = i;
+get_endp(s, pid, ep)-iso_buffer_used = i;
 }
 
-static int get_iso_buffer_used(USBHostDevice *s, int ep)
+static int get_iso_buffer_used(USBHostDevice *s, int pid, int ep)
 {
-return get_endp(s, ep)-iso_buffer_used;
+

[Qemu-devel] [PATCH 08/18] usb-ehci: handle siTDs

2011-09-02 Thread Gerd Hoffmann
This patch adds code to do minimal siTD handling, which is basically
just following the next pointer.  This is good enougth to handle the
inactive siTDs used by FreeBSD.  Active siTDs are skipped too as we
don't have split transfer support in qemu, additionally a warning is
printed.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-ehci.c |   43 ++-
 trace-events  |1 +
 2 files changed, 43 insertions(+), 1 deletions(-)

diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c
index 47a7fb9..d8ef0cb 100644
--- a/hw/usb-ehci.c
+++ b/hw/usb-ehci.c
@@ -149,6 +149,7 @@ typedef enum {
 EST_FETCHENTRY,
 EST_FETCHQH,
 EST_FETCHITD,
+EST_FETCHSITD,
 EST_ADVANCEQUEUE,
 EST_FETCHQTD,
 EST_EXECUTE,
@@ -646,6 +647,13 @@ static void ehci_trace_itd(EHCIState *s, 
target_phys_addr_t addr, EHCIitd *itd)
get_field(itd-bufptr[0], ITD_BUFPTR_DEVADDR));
 }
 
+static void ehci_trace_sitd(EHCIState *s, target_phys_addr_t addr,
+EHCIsitd *sitd)
+{
+trace_usb_ehci_sitd(addr, sitd-next,
+(bool)(sitd-results  SITD_RESULTS_ACTIVE));
+}
+
 /* queue management */
 
 static EHCIQueue *ehci_alloc_queue(EHCIState *ehci, int async)
@@ -1584,8 +1592,13 @@ static int ehci_state_fetchentry(EHCIState *ehci, int 
async)
 again = 1;
 break;
 
+case NLPTR_TYPE_STITD:
+ehci_set_state(ehci, async, EST_FETCHSITD);
+again = 1;
+break;
+
 default:
-// TODO: handle siTD and FSTN types
+/* TODO: handle FSTN type */
 fprintf(stderr, FETCHENTRY: entry at %X is of type %d 
 which is not supported yet\n, entry, NLPTR_TYPE_GET(entry));
 return -1;
@@ -1701,6 +1714,30 @@ static int ehci_state_fetchitd(EHCIState *ehci, int 
async)
 return 1;
 }
 
+static int ehci_state_fetchsitd(EHCIState *ehci, int async)
+{
+uint32_t entry;
+EHCIsitd sitd;
+
+assert(!async);
+entry = ehci_get_fetch_addr(ehci, async);
+
+get_dwords(NLPTR_GET(entry), (uint32_t *)sitd,
+   sizeof(EHCIsitd)  2);
+ehci_trace_sitd(ehci, entry, sitd);
+
+if (!(sitd.results  SITD_RESULTS_ACTIVE)) {
+/* siTD is not active, nothing to do */;
+} else {
+/* TODO: split transfers are not implemented */
+fprintf(stderr, WARNING: Skipping active siTD\n);
+}
+
+ehci_set_fetch_addr(ehci, async, sitd.next);
+ehci_set_state(ehci, async, EST_FETCHENTRY);
+return 1;
+}
+
 /* Section 4.10.2 - paragraph 3 */
 static int ehci_state_advqueue(EHCIQueue *q, int async)
 {
@@ -1976,6 +2013,10 @@ static void ehci_advance_state(EHCIState *ehci,
 again = ehci_state_fetchitd(ehci, async);
 break;
 
+case EST_FETCHSITD:
+again = ehci_state_fetchsitd(ehci, async);
+break;
+
 case EST_ADVANCEQUEUE:
 again = ehci_state_advqueue(q, async);
 break;
diff --git a/trace-events b/trace-events
index 5535e56..d4628a9 100644
--- a/trace-events
+++ b/trace-events
@@ -226,6 +226,7 @@ disable usb_ehci_qtd_ptrs(void *q, uint32_t addr, uint32_t 
nxt, uint32_t altnext
 disable usb_ehci_qtd_fields(uint32_t addr, int tbytes, int cpage, int cerr, 
int pid) QTD @ %08x - tbytes %d, cpage %d, cerr %d, pid %d
 disable usb_ehci_qtd_bits(uint32_t addr, int ioc, int active, int halt, int 
babble, int xacterr) QTD @ %08x - ioc %d, active %d, halt %d, babble %d, 
xacterr %d
 disable usb_ehci_itd(uint32_t addr, uint32_t nxt, uint32_t mplen, uint32_t 
mult, uint32_t ep, uint32_t devaddr) ITD @ %08x: next %08x - mplen %d, mult 
%d, ep %d, dev %d
+disable usb_ehci_sitd(uint32_t addr, uint32_t nxt, uint32_t active) ITD @ 
%08x: next %08x - active %d
 disable usb_ehci_port_attach(uint32_t port, const char *device) attach port 
#%d - %s
 disable usb_ehci_port_detach(uint32_t port) detach port #%d
 disable usb_ehci_port_reset(uint32_t port, int enable) reset port #%d - %d
-- 
1.7.1




Re: [Qemu-devel] [PATCH v2 15/45] ide/atapi: Track tray locked state

2011-09-02 Thread Kevin Wolf
Am 03.08.2011 15:07, schrieb Markus Armbruster:
 We already track it in BlockDriverState.  Just like tray open/close
 state, we should track it in the device models instead, because it's
 device state.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  hw/ide/atapi.c|4 +++-
  hw/ide/internal.h |1 +
  2 files changed, 4 insertions(+), 1 deletions(-)
 
 diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
 index 08e1a7a..237657f 100644
 --- a/hw/ide/atapi.c
 +++ b/hw/ide/atapi.c
 @@ -777,8 +777,9 @@ static void cmd_mode_sense(IDEState *s, uint8_t *buf)
  buf[12] = 0x71;
  buf[13] = 3  5;
  buf[14] = (1  0) | (1  3) | (1  5);
 -if (bdrv_is_locked(s-bs))
 +if (s-tray_locked) {
  buf[6] |= 1  1;
 +}
  buf[15] = 0x00;
  cpu_to_ube16(buf[16], 706);
  buf[18] = 0;
 @@ -820,6 +821,7 @@ static void cmd_test_unit_ready(IDEState *s, uint8_t *buf)
  
  static void cmd_prevent_allow_medium_removal(IDEState *s, uint8_t* buf)
  {
 +s-tray_locked = buf[4]  1;
  bdrv_set_locked(s-bs, buf[4]  1);
  ide_atapi_cmd_ok(s);
  }
 diff --git a/hw/ide/internal.h b/hw/ide/internal.h
 index cd8e977..3e56b45 100644
 --- a/hw/ide/internal.h
 +++ b/hw/ide/internal.h
 @@ -443,6 +443,7 @@ struct IDEState {
  uint8_t sense_key;
  uint8_t asc;
  bool tray_open;
 +bool tray_locked;
  uint8_t cdrom_changed;
  int packet_transfer_size;
  int elementary_transfer_size;

Same as tray open/close status: Needs to be migrated.

Kevin



[Qemu-devel] [PATCH 06/18] usb-host: claim port

2011-09-02 Thread Gerd Hoffmann
When configured to pass through a specific host port (using hostbus and
hostport properties), try to claim the port if supported by the kernel.
That will avoid any kernel drivers binding to devices plugged into that
port.  It will not stop any userspace apps (such as usb_modeswitch)
access the device via usbfs though.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 trace-events |1 +
 usb-linux.c  |   57 +
 2 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/trace-events b/trace-events
index f48cb85..5535e56 100644
--- a/trace-events
+++ b/trace-events
@@ -266,6 +266,7 @@ disable usb_host_ep_stop_iso(int bus, int addr, int ep) 
dev %d:%d, ep %d
 disable usb_host_reset(int bus, int addr) dev %d:%d
 disable usb_host_auto_scan_enabled(void)
 disable usb_host_auto_scan_disabled(void)
+disable usb_host_claim_port(int bus, int hub, int port) bus %d, hub addr %d, 
port %d
 
 # hw/scsi-bus.c
 disable scsi_req_alloc(int target, int lun, int tag) target %d lun %d tag %d
diff --git a/usb-linux.c b/usb-linux.c
index a903023..ce0eadd 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -115,6 +115,7 @@ struct USBAutoFilter {
 typedef struct USBHostDevice {
 USBDevice dev;
 int   fd;
+int   hub_fd;
 
 uint8_t   descr[8192];
 int   descr_len;
@@ -525,6 +526,9 @@ static void usb_host_handle_destroy(USBDevice *dev)
 USBHostDevice *s = (USBHostDevice *)dev;
 
 usb_host_close(s);
+if (s-hub_fd != -1) {
+close(s-hub_fd);
+}
 QTAILQ_REMOVE(hostdevs, s, next);
 qemu_remove_exit_notifier(s-exit);
 }
@@ -1266,10 +1270,63 @@ static int usb_host_initfn(USBDevice *dev)
 
 dev-auto_attach = 0;
 s-fd = -1;
+s-hub_fd = -1;
+
 QTAILQ_INSERT_TAIL(hostdevs, s, next);
 s-exit.notify = usb_host_exit_notifier;
 qemu_add_exit_notifier(s-exit);
 usb_host_auto_check(NULL);
+
+#ifdef USBDEVFS_CLAIM_PORT
+if (s-match.bus_num != 0  s-match.port != NULL) {
+char *h, hub_name[64], line[1024];
+int hub_addr, portnr, ret;
+
+snprintf(hub_name, sizeof(hub_name), %d-%s,
+ s-match.bus_num, s-match.port);
+
+/* try strip off last .$portnr to get hub */
+h = strrchr(hub_name, '.');
+if (h != NULL) {
+portnr = atoi(h+1);
+*h = '\0';
+} else {
+/* no dot in there - it is the root hub */
+snprintf(hub_name, sizeof(hub_name), usb%d,
+ s-match.bus_num);
+portnr = atoi(s-match.port);
+}
+
+if (!usb_host_read_file(line, sizeof(line), devnum,
+hub_name)) {
+goto out;
+}
+if (sscanf(line, %d, hub_addr) != 1) {
+goto out;
+}
+
+if (!usb_host_device_path) {
+goto out;
+}
+snprintf(line, sizeof(line), %s/%03d/%03d,
+ usb_host_device_path, s-match.bus_num, hub_addr);
+s-hub_fd = open(line, O_RDWR | O_NONBLOCK);
+if (s-hub_fd  0) {
+goto out;
+}
+
+ret = ioctl(s-hub_fd, USBDEVFS_CLAIM_PORT, portnr);
+if (ret  0) {
+close(s-hub_fd);
+s-hub_fd = -1;
+goto out;
+}
+
+trace_usb_host_claim_port(s-match.bus_num, hub_addr, portnr);
+}
+out:
+#endif
+
 return 0;
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH 13/18] usb-ccid: remote wakeup support

2011-09-02 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-ccid.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/hw/usb-ccid.c b/hw/usb-ccid.c
index 4f0b347..3f794d4 100644
--- a/hw/usb-ccid.c
+++ b/hw/usb-ccid.c
@@ -447,7 +447,7 @@ static const USBDescDevice desc_device = {
 {
 .bNumInterfaces= 1,
 .bConfigurationValue   = 1,
-.bmAttributes  = 0x80,
+.bmAttributes  = 0xa0,
 .bMaxPower = 50,
 .nif = 1,
 .ifs = desc_iface0,
@@ -811,6 +811,7 @@ static void ccid_on_slot_change(USBCCIDState *s, bool full)
 s-bmSlotICCState |= SLOT_0_CHANGED_MASK;
 }
 s-notify_slot_change = true;
+usb_wakeup(s-dev);
 }
 
 static void ccid_write_data_block_error(
-- 
1.7.1




[Qemu-devel] [PATCH 2/7] usb-host: fix halted endpoints

2011-09-02 Thread Gerd Hoffmann
Two fixes for the price of one ;)

First, reinitialize the endpoint table after device reset.
This is needed anyway as the reset might have switched interfaces.
It also clears the endpoint halted state.

Second the CLEAR_HALT ioctl wants a unsigned int passed in as
argument, not uint8_t.

This gets my usb sd card reader (sandisk micromate) going.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
(cherry picked from commit a8b44be4da11ba57ab3219a55eecbc422663c9b3)
---
 usb-linux.c |7 ---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 7d8a103..1d0ccf8 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -142,6 +142,7 @@ static int parse_filter(const char *spec, struct 
USBAutoFilter *f);
 static void usb_host_auto_check(void *unused);
 static int usb_host_read_file(char *line, size_t line_size,
 const char *device_file, const char *device_name);
+static int usb_linux_update_endp_table(USBHostDevice *s);
 
 static struct endp_data *get_endp(USBHostDevice *s, int ep)
 {
@@ -509,6 +510,7 @@ static void usb_host_handle_reset(USBDevice *dev)
 ioctl(s-fd, USBDEVFS_RESET);
 
 usb_host_claim_interfaces(s, s-configuration);
+usb_linux_update_endp_table(s);
 }
 
 static void usb_host_handle_destroy(USBDevice *dev)
@@ -520,8 +522,6 @@ static void usb_host_handle_destroy(USBDevice *dev)
 qemu_remove_exit_notifier(s-exit);
 }
 
-static int usb_linux_update_endp_table(USBHostDevice *s);
-
 /* iso data is special, we need to keep enough urbs in flight to make sure
that the controller never runs out of them, otherwise the device will
likely suffer a buffer underrun / overrun. */
@@ -723,7 +723,8 @@ static int usb_host_handle_data(USBDevice *dev, USBPacket 
*p)
 }
 
 if (is_halted(s, p-devep)) {
-ret = ioctl(s-fd, USBDEVFS_CLEAR_HALT, ep);
+unsigned int arg = ep;
+ret = ioctl(s-fd, USBDEVFS_CLEAR_HALT, arg);
 if (ret  0) {
 DPRINTF(husb: failed to clear halt. ep 0x%x errno %d\n,
ep, errno);
-- 
1.7.1




[Qemu-devel] [PATCH 12/18] usb-ccid: switch to USBDesc*

2011-09-02 Thread Gerd Hoffmann
Switch the smard card emulation to use the USBDesc*
structs for the usb descriptors.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-ccid.c |  247 +++--
 hw/usb-desc.h |2 +-
 2 files changed, 84 insertions(+), 165 deletions(-)

diff --git a/hw/usb-ccid.c b/hw/usb-ccid.c
index 66aeb21..4f0b347 100644
--- a/hw/usb-ccid.c
+++ b/hw/usb-ccid.c
@@ -37,6 +37,7 @@
 #include qemu-common.h
 #include qemu-error.h
 #include usb.h
+#include usb-desc.h
 #include monitor.h
 
 #include hw/ccid.h
@@ -306,56 +307,7 @@ typedef struct USBCCIDState {
  *   0dc3:1004 Athena Smartcard Solutions, Inc.
  */
 
-static const uint8_t qemu_ccid_dev_descriptor[] = {
-0x12,   /*  u8 bLength; */
-USB_DT_DEVICE, /*  u8 bDescriptorType; Device */
-0x10, 0x01, /*  u16 bcdUSB; v1.1 */
-
-0x00,   /*  u8  bDeviceClass; */
-0x00,   /*  u8  bDeviceSubClass; */
-0x00,   /*  u8  bDeviceProtocol; [ low/full speeds only ] */
-0x40,   /*  u8  bMaxPacketSize0; 8 Bytes (valid: 8,16,32,64) */
-
-/* Vendor and product id are arbitrary.  */
-/*  u16 idVendor  */
-CCID_VENDOR_ID  0xff, CCID_VENDOR_ID  8,
-/*  u16 idProduct */
-CCID_PRODUCT_ID  0xff, CCID_PRODUCT_ID  8,
-/*  u16 bcdDevice */
-CCID_DEVICE_VERSION  0xff, CCID_DEVICE_VERSION  8,
-0x01,   /*  u8  iManufacturer; */
-0x02,   /*  u8  iProduct; */
-0x03,   /*  u8  iSerialNumber; */
-0x01,   /*  u8  bNumConfigurations; */
-};
-
-static const uint8_t qemu_ccid_config_descriptor[] = {
-
-/* one configuration */
-0x09,   /* u8  bLength; */
-USB_DT_CONFIG, /* u8  bDescriptorType; Configuration */
-0x5d, 0x00, /* u16 wTotalLength; 9+9+54+7+7+7 */
-0x01,   /* u8  bNumInterfaces; (1) */
-0x01,   /* u8  bConfigurationValue; */
-0x00,   /* u8  iConfiguration; */
-0xe0,   /* u8  bmAttributes;
- Bit 7: must be set,
- 6: Self-powered,
- 5: Remote wakeup,
- 4..0: resvd */
-100/2,  /* u8  MaxPower; 50 == 100mA */
-
-/* one interface */
-0x09,   /* u8  if_bLength; */
-USB_DT_INTERFACE, /* u8  if_bDescriptorType; Interface */
-0x00,   /* u8  if_bInterfaceNumber; */
-0x00,   /* u8  if_bAlternateSetting; */
-0x03,   /* u8  if_bNumEndpoints; */
-0x0b,   /* u8  if_bInterfaceClass; Smart Card Device Class */
-0x00,   /* u8  if_bInterfaceSubClass; Subclass code */
-0x00,   /* u8  if_bInterfaceProtocol; Protocol code */
-0x04,   /* u8  if_iInterface; Index of string descriptor */
-
+static const uint8_t qemu_ccid_descriptor[] = {
 /* Smart Card Device Class Descriptor */
 0x36,   /* u8  bLength; */
 0x21,   /* u8  bDescriptorType; Functional */
@@ -439,38 +391,81 @@ static const uint8_t qemu_ccid_config_descriptor[] = {
  *  02h PIN Modification
  */
 0x01,   /* u8  bMaxCCIDBusySlots; */
+};
 
-/* Interrupt-IN endpoint */
-0x07,   /* u8  ep_bLength; */
-/* u8  ep_bDescriptorType; Endpoint */
-USB_DT_ENDPOINT,
-/* u8  ep_bEndpointAddress; IN Endpoint 1 */
-0x80 | CCID_INT_IN_EP,
-0x03,   /* u8  ep_bmAttributes; Interrupt */
-/* u16 ep_wMaxPacketSize; */
-CCID_MAX_PACKET_SIZE  0xff, (CCID_MAX_PACKET_SIZE  8),
-0xff,   /* u8  ep_bInterval; */
-
-/* Bulk-In endpoint */
-0x07,   /* u8  ep_bLength; */
-/* u8  ep_bDescriptorType; Endpoint */
-USB_DT_ENDPOINT,
-/* u8  ep_bEndpointAddress; IN Endpoint 2 */
-0x80 | CCID_BULK_IN_EP,
-0x02,   /* u8  ep_bmAttributes; Bulk */
-0x40, 0x00, /* u16 ep_wMaxPacketSize; */
-0x00,   /* u8  ep_bInterval; */
-
-/* Bulk-Out endpoint */
-0x07,   /* u8  ep_bLength; */
-/* u8  ep_bDescriptorType; Endpoint */
-USB_DT_ENDPOINT,
-/* u8  ep_bEndpointAddress; OUT Endpoint 3 */
-CCID_BULK_OUT_EP,
-0x02,   /* u8  ep_bmAttributes; Bulk */
-0x40, 0x00, /* u16 ep_wMaxPacketSize; */
-0x00,   /* u8  ep_bInterval; */
+enum {
+STR_MANUFACTURER = 1,
+STR_PRODUCT,
+STR_SERIALNUMBER,
+STR_INTERFACE,
+};
 
+static const USBDescStrings desc_strings = {
+[STR_MANUFACTURER]  = QEMU  QEMU_VERSION,
+[STR_PRODUCT]   = QEMU USB CCID,
+[STR_SERIALNUMBER]  = 1,
+[STR_INTERFACE] = CCID Interface,
+};
+
+static const USBDescIface 

[Qemu-devel] [PATCH 16/18] usb: Remove leading underscores from __musb_irq_max

2011-09-02 Thread Gerd Hoffmann
From: Peter Maydell peter.mayd...@linaro.org

Identifiers with double leading underscore are reserved, so rename
__musb_irq_max so we don't encroach on reserved namespace.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/tusb6010.c |6 +++---
 hw/usb.h  |3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/hw/tusb6010.c b/hw/tusb6010.c
index de6ffc6..78814f1 100644
--- a/hw/tusb6010.c
+++ b/hw/tusb6010.c
@@ -785,9 +785,9 @@ static int tusb6010_init(SysBusDevice *dev)
 sysbus_init_mmio_region(dev, s-iomem[0]);
 sysbus_init_mmio_region(dev, s-iomem[1]);
 sysbus_init_irq(dev, s-irq);
-qdev_init_gpio_in(dev-qdev, tusb6010_irq, __musb_irq_max + 1);
-musb_irqs = g_new0(qemu_irq, __musb_irq_max);
-for (i = 0; i  __musb_irq_max; i++) {
+qdev_init_gpio_in(dev-qdev, tusb6010_irq, musb_irq_max + 1);
+musb_irqs = g_new0(qemu_irq, musb_irq_max);
+for (i = 0; i  musb_irq_max; i++) {
 musb_irqs[i] = qdev_get_gpio_in(dev-qdev, i + 1);
 }
 s-musb = musb_init(musb_irqs);
diff --git a/hw/usb.h b/hw/usb.h
index 73479d6..e251e61 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -338,7 +338,8 @@ enum musb_irq_source_e {
 musb_irq_tx,
 musb_set_vbus,
 musb_set_session,
-__musb_irq_max,
+/* Add new interrupts here */
+musb_irq_max, /* total number of interrupts defined */
 };
 
 typedef struct MUSBState MUSBState;
-- 
1.7.1




[Qemu-devel] [PATCH 3/7] usb-host: fix configuration tracking.

2011-09-02 Thread Gerd Hoffmann
It is perfectly fine to leave the usb device in unconfigured state
(USBHostDevice-configuration == 0).  Just do that and wait for the
guest to explicitly set a configuration.  This is closer to what real
hardware does and it also simplifies the device initialization.  There
is no need to figure how the device is configured on the host.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
(cherry picked from commit b2d7c159824b5cf6af797e8bf52243fcbb42395a)
---
 usb-linux.c |   82 +-
 1 files changed, 19 insertions(+), 63 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 1d0ccf8..74f1a0b 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -397,8 +397,11 @@ static int usb_host_claim_interfaces(USBHostDevice *dev, 
int configuration)
 int interface, nb_interfaces;
 int ret, i;
 
-if (configuration == 0) /* address state - ignore */
+if (configuration == 0) { /* address state - ignore */
+dev-ninterfaces   = 0;
+dev-configuration = 0;
 return 1;
+}
 
 DPRINTF(husb: claiming interfaces. config %d\n, configuration);
 
@@ -423,7 +426,7 @@ static int usb_host_claim_interfaces(USBHostDevice *dev, 
int configuration)
 
 printf(husb: config #%d need %d\n, dev-descr[i + 5], configuration);
 
-if (configuration  0 || configuration == dev-descr[i + 5]) {
+if (configuration == dev-descr[i + 5]) {
 configuration = dev-descr[i + 5];
 break;
 }
@@ -509,7 +512,7 @@ static void usb_host_handle_reset(USBDevice *dev)
 
 ioctl(s-fd, USBDEVFS_RESET);
 
-usb_host_claim_interfaces(s, s-configuration);
+usb_host_claim_interfaces(s, 0);
 usb_linux_update_endp_table(s);
 }
 
@@ -810,6 +813,7 @@ static int usb_host_set_config(USBHostDevice *s, int config)
 return ctrl_error();
 }
 usb_host_claim_interfaces(s, config);
+usb_linux_update_endp_table(s);
 return 0;
 }
 
@@ -913,51 +917,6 @@ static int usb_host_handle_control(USBDevice *dev, 
USBPacket *p,
 return USB_RET_ASYNC;
 }
 
-static int usb_linux_get_configuration(USBHostDevice *s)
-{
-uint8_t configuration;
-struct usb_ctrltransfer ct;
-int ret;
-
-if (usb_fs_type == USB_FS_SYS) {
-char device_name[32], line[1024];
-int configuration;
-
-sprintf(device_name, %d-%s, s-bus_num, s-port);
-
-if (!usb_host_read_file(line, sizeof(line), bConfigurationValue,
-device_name)) {
-goto usbdevfs;
-}
-if (sscanf(line, %d, configuration) != 1) {
-goto usbdevfs;
-}
-return configuration;
-}
-
-usbdevfs:
-ct.bRequestType = USB_DIR_IN;
-ct.bRequest = USB_REQ_GET_CONFIGURATION;
-ct.wValue = 0;
-ct.wIndex = 0;
-ct.wLength = 1;
-ct.data = configuration;
-ct.timeout = 50;
-
-ret = ioctl(s-fd, USBDEVFS_CONTROL, ct);
-if (ret  0) {
-perror(usb_linux_get_configuration);
-return -1;
-}
-
-/* in address state */
-if (configuration == 0) {
-return -1;
-}
-
-return configuration;
-}
-
 static uint8_t usb_linux_get_alt_setting(USBHostDevice *s,
 uint8_t configuration, uint8_t interface)
 {
@@ -1003,16 +962,16 @@ usbdevfs:
 static int usb_linux_update_endp_table(USBHostDevice *s)
 {
 uint8_t *descriptors;
-uint8_t devep, type, configuration, alt_interface;
+uint8_t devep, type, alt_interface;
 int interface, length, i;
 
 for (i = 0; i  MAX_ENDPOINTS; i++)
 s-endp_table[i].type = INVALID_EP_TYPE;
 
-i = usb_linux_get_configuration(s);
-if (i  0)
-return 1;
-configuration = i;
+if (s-configuration == 0) {
+/* not configured yet -- leave all endpoints disabled */
+return 0;
+}
 
 /* get the desired configuration, interface, and endpoint descriptors
  * from device description */
@@ -1021,8 +980,9 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
 i = 0;
 
 if (descriptors[i + 1] != USB_DT_CONFIG ||
-descriptors[i + 5] != configuration) {
-DPRINTF(invalid descriptor data - configuration\n);
+descriptors[i + 5] != s-configuration) {
+fprintf(stderr, invalid descriptor data - configuration %d\n,
+s-configuration);
 return 1;
 }
 i += descriptors[i];
@@ -1036,7 +996,8 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
 }
 
 interface = descriptors[i + 2];
-alt_interface = usb_linux_get_alt_setting(s, configuration, interface);
+alt_interface = usb_linux_get_alt_setting(s, s-configuration,
+  interface);
 
 /* the current interface descriptor is the active interface
  * and has endpoints */
@@ -1175,13 +1136,8 @@ static int usb_host_open(USBHostDevice *dev, int bus_num,
 #endif
 
 
-/*
- * Initial configuration is -1 which makes 

[Qemu-devel] [PATCH 05/18] usb-host: fix configuration tracking.

2011-09-02 Thread Gerd Hoffmann
It is perfectly fine to leave the usb device in unconfigured state
(USBHostDevice-configuration == 0).  Just do that and wait for the
guest to explicitly set a configuration.  This is closer to what real
hardware does and it also simplifies the device initialization.  There
is no need to figure how the device is configured on the host.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 usb-linux.c |   82 +-
 1 files changed, 19 insertions(+), 63 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 36d25d7..a903023 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -407,8 +407,11 @@ static int usb_host_claim_interfaces(USBHostDevice *dev, 
int configuration)
 int interface, nb_interfaces;
 int ret, i;
 
-if (configuration == 0) /* address state - ignore */
+if (configuration == 0) { /* address state - ignore */
+dev-ninterfaces   = 0;
+dev-configuration = 0;
 return 1;
+}
 
 DPRINTF(husb: claiming interfaces. config %d\n, configuration);
 
@@ -433,7 +436,7 @@ static int usb_host_claim_interfaces(USBHostDevice *dev, 
int configuration)
 
 DPRINTF(husb: config #%d need %d\n, dev-descr[i + 5], 
configuration);
 
-if (configuration  0 || configuration == dev-descr[i + 5]) {
+if (configuration == dev-descr[i + 5]) {
 configuration = dev-descr[i + 5];
 break;
 }
@@ -513,7 +516,7 @@ static void usb_host_handle_reset(USBDevice *dev)
 
 ioctl(s-fd, USBDEVFS_RESET);
 
-usb_host_claim_interfaces(s, s-configuration);
+usb_host_claim_interfaces(s, 0);
 usb_linux_update_endp_table(s);
 }
 
@@ -835,6 +838,7 @@ static int usb_host_set_config(USBHostDevice *s, int config)
 return ctrl_error();
 }
 usb_host_claim_interfaces(s, config);
+usb_linux_update_endp_table(s);
 return 0;
 }
 
@@ -941,51 +945,6 @@ static int usb_host_handle_control(USBDevice *dev, 
USBPacket *p,
 return USB_RET_ASYNC;
 }
 
-static int usb_linux_get_configuration(USBHostDevice *s)
-{
-uint8_t configuration;
-struct usb_ctrltransfer ct;
-int ret;
-
-if (usb_fs_type == USB_FS_SYS) {
-char device_name[32], line[1024];
-int configuration;
-
-sprintf(device_name, %d-%s, s-bus_num, s-port);
-
-if (!usb_host_read_file(line, sizeof(line), bConfigurationValue,
-device_name)) {
-goto usbdevfs;
-}
-if (sscanf(line, %d, configuration) != 1) {
-goto usbdevfs;
-}
-return configuration;
-}
-
-usbdevfs:
-ct.bRequestType = USB_DIR_IN;
-ct.bRequest = USB_REQ_GET_CONFIGURATION;
-ct.wValue = 0;
-ct.wIndex = 0;
-ct.wLength = 1;
-ct.data = configuration;
-ct.timeout = 50;
-
-ret = ioctl(s-fd, USBDEVFS_CONTROL, ct);
-if (ret  0) {
-perror(usb_linux_get_configuration);
-return -1;
-}
-
-/* in address state */
-if (configuration == 0) {
-return -1;
-}
-
-return configuration;
-}
-
 static uint8_t usb_linux_get_alt_setting(USBHostDevice *s,
 uint8_t configuration, uint8_t interface)
 {
@@ -1031,16 +990,16 @@ usbdevfs:
 static int usb_linux_update_endp_table(USBHostDevice *s)
 {
 uint8_t *descriptors;
-uint8_t devep, type, configuration, alt_interface;
+uint8_t devep, type, alt_interface;
 int interface, length, i;
 
 for (i = 0; i  MAX_ENDPOINTS; i++)
 s-endp_table[i].type = INVALID_EP_TYPE;
 
-i = usb_linux_get_configuration(s);
-if (i  0)
-return 1;
-configuration = i;
+if (s-configuration == 0) {
+/* not configured yet -- leave all endpoints disabled */
+return 0;
+}
 
 /* get the desired configuration, interface, and endpoint descriptors
  * from device description */
@@ -1049,8 +1008,9 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
 i = 0;
 
 if (descriptors[i + 1] != USB_DT_CONFIG ||
-descriptors[i + 5] != configuration) {
-DPRINTF(invalid descriptor data - configuration\n);
+descriptors[i + 5] != s-configuration) {
+fprintf(stderr, invalid descriptor data - configuration %d\n,
+s-configuration);
 return 1;
 }
 i += descriptors[i];
@@ -1064,7 +1024,8 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
 }
 
 interface = descriptors[i + 2];
-alt_interface = usb_linux_get_alt_setting(s, configuration, interface);
+alt_interface = usb_linux_get_alt_setting(s, s-configuration,
+  interface);
 
 /* the current interface descriptor is the active interface
  * and has endpoints */
@@ -1204,13 +1165,8 @@ static int usb_host_open(USBHostDevice *dev, int bus_num,
 #endif
 
 
-/*
- * Initial configuration is -1 which makes us claim first
- * available config. We used to start with 1, 

Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access

2011-09-02 Thread Jan Kiszka
On 2011-09-02 11:41, Daniel P. Berrange wrote:
 On Thu, Sep 01, 2011 at 08:34:35PM -0500, Anthony Liguori wrote:
 On 09/01/2011 02:35 PM, Luiz Capitulino wrote:
 Sometimes, when having lots of VMs running on a RHEV host and the user
 attempts to close a SPICE window, libvirt will get corrupted json from
 QEMU.

 After some investigation, I found out that the problem is that different
 SPICE threads are calling monitor functions (such as
 monitor_protocol_event()) in parallel which causes concurrent access
 to the monitor's internal buffer outbuf[].

 This fixes the problem by protecting accesses to outbuf[] with a mutex.

 Honestly speaking, I'm not completely sure this the best thing to do
 because the monitor itself and other qemu subsystems are not thread safe,
 so having subsystems like SPICE assuming the contrary seems a bit
 catastrophic to me...

 Anyways, this commit fixes the problem at hand.

 Nack.

 This is absolutely a Spice bug.  Spice should not be calling into
 QEMU code from multiple threads.  It should only call into QEMU code
 while it's holding the qemu_mutex.

 The right way to fix this is probably to make all of the
 SpiceCoreInterface callbacks simply write to a file descriptor which
 can then wake up QEMU to do the operation on behalf of it.   It's
 ugly but the libspice interface is far too tied to QEMU internals in
 the first place which is the root of the problem.
 
 This feels like a rather short-term approach to fixing the problem
 to me. As QEMU becomes increasingly multi-threaded, there is high
 liklihood that we'll get other code in QEMU which wants to use the
 monitor from multiple threads. The monitor code in QEMU is fairly
 well isolated  thus comparatively easy to make threadsafe, so I

As pointed out before, this assumption is not correct.

 don't see why we wouldn't want todo that  avoid any chance of this
 type of problem recurring in the future.
 
 IMHO, fixing SPICE is not fixing the bug at all, it is just removing
 the trigger of the bug in the monitor.

Until we have officially thread-safe subsystems, SPICE must take the
qemu_global_mutex before calling core services. This patch does not make
the monitor thread-safe as it does not address indirectly called services.

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux



Re: [Qemu-devel] [PATCH v2 19/45] block: Rename bdrv_set_locked() to bdrv_lock_medium()

2011-09-02 Thread Kevin Wolf
Am 03.08.2011 15:07, schrieb Markus Armbruster:
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  block.c   |8 
  block.h   |2 +-
  block/raw-posix.c |8 
  block/raw.c   |6 +++---
  block_int.h   |2 +-
  hw/ide/atapi.c|2 +-
  hw/scsi-disk.c|2 +-
  trace-events  |2 +-
  8 files changed, 16 insertions(+), 16 deletions(-)
 
 diff --git a/block.c b/block.c
 index 3a8a4e6..10c1b1a 100644
 --- a/block.c
 +++ b/block.c
 @@ -3037,14 +3037,14 @@ void bdrv_eject(BlockDriverState *bs, int eject_flag)
   * Lock or unlock the media (if it is locked, the user won't be able
   * to eject it manually).
   */
 -void bdrv_set_locked(BlockDriverState *bs, int locked)
 +void bdrv_lock_medium(BlockDriverState *bs, int locked)

Make locked a bool while we're changing the signature everywhere?

Kevin



[Qemu-devel] [PATCH 09/18] usb-host: constify port

2011-09-02 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 usb-linux.c |   13 -
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/usb-linux.c b/usb-linux.c
index 6490582..ef29a76 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -54,7 +54,7 @@ struct usb_ctrltransfer {
 void *data;
 };
 
-typedef int USBScanFunc(void *opaque, int bus_num, int addr, char *port,
+typedef int USBScanFunc(void *opaque, int bus_num, int addr, const char *port,
 int class_id, int vendor_id, int product_id,
 const char *product_name, int speed);
 
@@ -1141,7 +1141,8 @@ static int usb_linux_full_speed_compat(USBHostDevice *dev)
 }
 
 static int usb_host_open(USBHostDevice *dev, int bus_num,
-int addr, char *port, const char *prod_name, int speed)
+ int addr, const char *port,
+ const char *prod_name, int speed)
 {
 int fd = -1, ret;
 char buf[1024];
@@ -1774,7 +1775,8 @@ static int usb_host_scan(void *opaque, USBScanFunc *func)
 
 static QEMUTimer *usb_auto_timer;
 
-static int usb_host_auto_scan(void *opaque, int bus_num, int addr, char *port,
+static int usb_host_auto_scan(void *opaque, int bus_num,
+  int addr, const char *port,
   int class_id, int vendor_id, int product_id,
   const char *product_name, int speed)
 {
@@ -1948,7 +1950,8 @@ static const char *usb_class_str(uint8_t class)
 return p-class_name;
 }
 
-static void usb_info_device(Monitor *mon, int bus_num, int addr, char *port,
+static void usb_info_device(Monitor *mon, int bus_num,
+int addr, const char *port,
 int class_id, int vendor_id, int product_id,
 const char *product_name,
 int speed)
@@ -1989,7 +1992,7 @@ static void usb_info_device(Monitor *mon, int bus_num, 
int addr, char *port,
 }
 
 static int usb_host_info_device(void *opaque, int bus_num, int addr,
-char *path, int class_id,
+const char *path, int class_id,
 int vendor_id, int product_id,
 const char *product_name,
 int speed)
-- 
1.7.1




[Qemu-devel] [PATCH] usb-storage: fix NULL pointer dereference.

2011-09-02 Thread Gerd Hoffmann
When a usb packet is canceled we need to check whenever we actually have
a scsi request in flight before we try to cancel it.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-msd.c |5 -
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 591405b..b74c46e 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -315,7 +315,10 @@ static int usb_msd_handle_control(USBDevice *dev, 
USBPacket *p,
 static void usb_msd_cancel_io(USBDevice *dev, USBPacket *p)
 {
 MSDState *s = DO_UPCAST(MSDState, dev, dev);
-scsi_req_cancel(s-req);
+
+if (s-req) {
+scsi_req_cancel(s-req);
+}
 }
 
 static int usb_msd_handle_data(USBDevice *dev, USBPacket *p)
-- 
1.7.1




Re: [Qemu-devel] [PATCH v2 22/45] ide/atapi: Avoid physical/virtual tray state mismatch

2011-09-02 Thread Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
 When ide-cd is backed by a physical drive, we want the physical tray
 match the virtual one.  To that end, we call bdrv_eject() on guest's
 load/eject, and bdrv_lock_medium() on guest's prevent/allow removal.
 But we don't set the initial state on device model init.  Fix that.
 
 While there, also unlock on device model exit.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  hw/ide/core.c |4 
  hw/ide/qdev.c |   18 ++
  2 files changed, 22 insertions(+), 0 deletions(-)
 
 diff --git a/hw/ide/core.c b/hw/ide/core.c
 index 5bcc857..d8b1d43 100644
 --- a/hw/ide/core.c
 +++ b/hw/ide/core.c
 @@ -1839,6 +1839,10 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, 
 IDEDriveKind kind,
  
  ide_reset(s);
  bdrv_set_removable(bs, s-drive_kind == IDE_CD);
 +if (s-drive_kind == IDE_CD) {
 +bdrv_lock_medium(bs, s-tray_locked);
 +bdrv_eject(bs, s-tray_open);
 +}
  return 0;
  }
  
 diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
 index 3b7b306..bc2f426 100644
 --- a/hw/ide/qdev.c
 +++ b/hw/ide/qdev.c
 @@ -182,6 +182,12 @@ static int ide_cd_initfn(IDEDevice *dev)
  return ide_dev_initfn(dev, IDE_CD);
  }
  
 +static int ide_cd_exitfn(IDEDevice *dev)
 +{
 +bdrv_lock_medium(dev-conf.bs, 0);
 +return 0;
 +}
 +
  static int ide_drive_initfn(IDEDevice *dev)
  {
  DriveInfo *dinfo = drive_get_by_blockdev(dev-conf.bs);
 @@ -189,6 +195,16 @@ static int ide_drive_initfn(IDEDevice *dev)
  return ide_dev_initfn(dev, dinfo-media_cd ? IDE_CD : IDE_HD);
  }
  
 +static int ide_drive_exitfn(IDEDevice *dev)
 +{
 +DriveInfo *dinfo = drive_get_by_blockdev(dev-conf.bs);
 +
 +if (dinfo-media_cd) {
 +return ide_cd_exitfn(dev);
 +}

Is dinfo-media_cd guaranteed to be the same as s-drive_kind? I
wouldn't have expected this to be true at least since the introduction
of ide-hd/cd.

Kevin



Re: [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration

2011-09-02 Thread Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
 Use a subsection, so that migration to older version still works,
 provided the tray is closed and unlocked.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com

Ah, here is the migration part. The state wasn't migrated before, so not
doing it in patch 10 doesn't break anything. I would still prefer to add
migration in the same patch that adds the fields.

You could just move the subsection itself and keep the post_load part
here if it doesn't fit naturally in one of the other patches of the series.

On another note, have our subsections been fixed meanwhile? If not,
increasing the version number instead might be the right choice. Paolo?

Kevin



Re: [Qemu-devel] [PATCH v2 27/45] scsi-disk: Preserve tray state on migration

2011-09-02 Thread Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
 Breaks migration of qdevs scsi-cd and legacy scsi-disk to older
 versions.  We normally use subsections to avoid that.  Not possible
 here, because we don't have a section to begin with.  Too bad.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com

A more logical approach would be to add migration support to SCSI first.
I guess adding .unmigratable = 1 makes more sense at the moment.

Kevin



Re: [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration

2011-09-02 Thread Paolo Bonzini

On 09/02/2011 02:20 PM, Kevin Wolf wrote:

Ah, here is the migration part. The state wasn't migrated before, so not
doing it in patch 10 doesn't break anything. I would still prefer to add
migration in the same patch that adds the fields.

You could just move the subsection itself and keep the post_load part
here if it doesn't fit naturally in one of the other patches of the series.

On another note, have our subsections been fixed meanwhile? If not,
increasing the version number instead might be the right choice. Paolo?


No, they haven't, but there's hope they will before 1.0.

Paolo



Re: [Qemu-devel] [PATCH v2 37/45] block: Show whether the guest ejected the medium in info block

2011-09-02 Thread Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
 Need to ask the device, so this requires new BlockDevOps member
 is_medium_ejected().
 
 Signed-off-by: Markus Armbruster arm...@redhat.com

I find the name confusing. medium is ejected seems to mean tray is
open. It isn't obvious that tray is closed, but no medium is inserted
is not medium is ejected.

Why not call it tray_open like in the devices?

Kevin



Re: [Qemu-devel] [PATCH v2 41/45] block: New bdrv_set_buffer_alignment()

2011-09-02 Thread Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
 Device models should be able to set it without an unclean include of
 block_int.h.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  block.c |6 --
  block.h |1 +
  hw/ide/core.c   |2 +-
  hw/scsi-disk.c  |2 +-
  hw/virtio-blk.c |3 +--
  5 files changed, 8 insertions(+), 6 deletions(-)
 
 diff --git a/block.c b/block.c
 index fed0c16..67d9429 100644
 --- a/block.c
 +++ b/block.c
 @@ -453,7 +453,6 @@ static int bdrv_open_common(BlockDriverState *bs, const 
 char *filename,
  bs-encrypted = 0;
  bs-valid_key = 0;
  bs-open_flags = flags;
 -/* buffer_alignment defaulted to 512, drivers can change this value */
  bs-buffer_alignment = 512;

This comment is still right.

Kevin



Re: [Qemu-devel] [PATCH v2 42/45] block: Reset buffer alignment on detach

2011-09-02 Thread Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
 BlockDriverState member buffer_alignment is initially 512.  The device
 model may set them, with bdrv_set_buffer_alignment().  If the device
 model gets detached (hot unplug), the device's alignment is left
 behind.  Only okay because device hot unplug automatically destroys
 the BlockDriverState.  But that's a questionable feature, best not to
 rely on it.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com

Hm, I'm not sure about this... Maybe instead of doing it on open and
detach, which is a strange combination, the right thing would be to do
it on attach?

Kevin



Re: [Qemu-devel] pseries machine updates

2011-09-02 Thread Alexander Graf

On 09/01/2011 03:45 AM, David Gibson wrote:

On Wed, Aug 31, 2011 at 11:17:13AM +0200, Alexander Graf wrote:

On 11.08.2011, at 02:39, David Gibson wrote:


On Wed, Aug 10, 2011 at 05:16:35PM +0200, Alexander Graf wrote:

On 08/04/2011 09:02 AM, David Gibson wrote:

Hi Alex,

Here's another batch of assorted updates for the pseries machine.

Looks pretty nice. Please update patch 2/6 with the bug you found
and the whitespace problems. I'll put the others into my tree
already.

Here's the updated 2/6

 From e5b9ba608d4814a46f256337bbf60b94fdc2c5d9 Mon Sep 17 00:00:00 2001
From: Ben Herrenschmidtb...@kernel.crashing.org
Date: Thu, 4 Aug 2011 16:56:41 +1000
Subject: [PATCH] Implement POWER7's CFAR in TCG

This patch implements support for the CFAR SPR on POWER7 (Come From
Address Register), which snapshots the PC value at the time of a branch or
an rfid.  The latest powerpc-next kernel also catches it and can show it in
xmon or in the signal frames.

This works well enough to let recent kernels boot (which otherwise oops
on the CFAR access).  It hasn't been tested enough to be confident that the
CFAR values are actually accurate, but one thing at a time.

Signed-off-by: Ben Herrenschmidtb...@kernel.crashing.org
Signed-off-by: David Gibsonda...@gibson.dropbear.id.au

agraf@lychee:/home/agraf/release/qemu  git pw am 109480
ERROR: code indent should never use tabs
#107: FILE: target-ppc/translate.c:162:
+^I^I^I^I  offsetof(CPUState, cfar), cfar);$

ERROR: code indent should never use tabs
#174: FILE: target-ppc/translate.c:9289:
+^Icpu_fprintf(f,  CFAR  TARGET_FMT_lx\n, env-cfar);$

Blah.  Fixed now, I'll try to get BenH to use the emacs magic to stop
it putting tabs in.


WARNING: space prohibited between function name and open parenthesis '('
#199: FILE: target-ppc/translate_init.c:134:
+static void spr_read_cfar (void *opaque, int gprn, int sprn)

WARNING: space prohibited between function name and open parenthesis '('
#204: FILE: target-ppc/translate_init.c:139:
+static void spr_write_cfar (void *opaque, int sprn, int gprn)

Well, these are deliberate, on the grounds that matching the
surrounding functions seemed more important than matching the global
style guidelines.

Revised patch below

 From b35b94ea867550faf99fc553b661739551c9bb8b Mon Sep 17 00:00:00 2001
From: Ben Herrenschmidtb...@kernel.crashing.org
Date: Thu, 4 Aug 2011 16:56:41 +1000
Subject: [PATCH] Implement POWER7's CFAR in TCG

This patch implements support for the CFAR SPR on POWER7 (Come From
Address Register), which snapshots the PC value at the time of a branch or
an rfid.  The latest powerpc-next kernel also catches it and can show it in
xmon or in the signal frames.

This works well enough to let recent kernels boot (which otherwise oops
on the CFAR access).  It hasn't been tested enough to be confident that the
CFAR values are actually accurate, but one thing at a time.

Signed-off-by: Ben Herrenschmidtb...@kernel.crashing.org
Signed-off-by: David Gibsonda...@gibson.dropbear.id.au
---
  target-ppc/cpu.h|8 
  target-ppc/translate.c  |   28 
  target-ppc/translate_init.c |   23 ++-
  3 files changed, 58 insertions(+), 1 deletions(-)


Thanks, applied. Please resend patches as full patches though. Patchwork 
doesn't deal too well with updated inline patches.



Alex




Re: [Qemu-devel] [PATCH v2 44/45] block: New change_media_cb() parameter load

2011-09-02 Thread Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
 To let device models distinguish between eject and load.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  block.c|   12 ++--
  block.h|3 ++-
  hw/fdc.c   |2 +-
  hw/ide/core.c  |2 +-
  hw/scsi-disk.c |2 +-
  hw/sd.c|2 +-
  6 files changed, 12 insertions(+), 11 deletions(-)
 
 diff --git a/block.c b/block.c
 index b0e54ef..1bd67dd 100644
 --- a/block.c
 +++ b/block.c
 @@ -44,7 +44,7 @@
  #include windows.h
  #endif
  
 -static void bdrv_dev_change_media_cb(BlockDriverState *bs);
 +static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load);
  static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs,
  int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
  BlockDriverCompletionFunc *cb, void *opaque);
 @@ -661,7 +661,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, 
 int flags,
  }
  
  if (!bdrv_key_required(bs)) {
 -bdrv_dev_change_media_cb(bs);
 +bdrv_dev_change_media_cb(bs, true);
  }
  
  return 0;
 @@ -697,7 +697,7 @@ void bdrv_close(BlockDriverState *bs)
  bdrv_close(bs-file);
  }
  
 -bdrv_dev_change_media_cb(bs);
 +bdrv_dev_change_media_cb(bs, false);
  }
  }
  
 @@ -780,10 +780,10 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const 
 BlockDevOps *ops,
  }
  }
  
 -static void bdrv_dev_change_media_cb(BlockDriverState *bs)
 +static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load)
  {
  if (bs-dev_ops  bs-dev_ops-change_media_cb) {
 -bs-dev_ops-change_media_cb(bs-dev_opaque);
 +bs-dev_ops-change_media_cb(bs-dev_opaque, load);
  }
  }
  
 @@ -1634,7 +1634,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key)
  } else if (!bs-valid_key) {
  bs-valid_key = 1;
  /* call the change callback now, we skipped it on open */
 -bdrv_dev_change_media_cb(bs);
 +bdrv_dev_change_media_cb(bs, 1);

s/1/true/

Kevin



Re: [Qemu-devel] [PATCH 2/2] pseries: Implement hcall-bulk hypervisor interface

2011-09-02 Thread Alexander Graf

On 09/01/2011 03:50 AM, David Gibson wrote:

On Wed, Aug 31, 2011 at 11:22:18AM +0200, Alexander Graf wrote:

On 11.08.2011, at 04:36, David Gibson wrote:

[snip]

+#define H_BULK_REMOVE_TYPE 0xc000ULL
+#define   H_BULK_REMOVE_REQUEST0x4000ULL
+#define   H_BULK_REMOVE_RESPONSE   0x8000ULL
+#define   H_BULK_REMOVE_END0xc000ULL
+#define H_BULK_REMOVE_CODE 0x3000ULL
+#define   H_BULK_REMOVE_SUCCESS0xULL
+#define   H_BULK_REMOVE_NOT_FOUND  0x1000ULL
+#define   H_BULK_REMOVE_PARM   0x2000ULL
+#define   H_BULK_REMOVE_HW 0x3000ULL
+#define H_BULK_REMOVE_RC   0x0c00ULL
+#define H_BULK_REMOVE_FLAGS0x0300ULL
+#define   H_BULK_REMOVE_ABSOLUTE   0xULL
+#define   H_BULK_REMOVE_ANDCOND0x0100ULL
+#define   H_BULK_REMOVE_AVPN   0x0200ULL
+#define H_BULK_REMOVE_PTEX 0x00ffULL

indenting looks broken.

Nope, that's intended.  The unindented ones are the field masks in the
parameter, the intended ones are the defined values for the
corresponding field.


Interesting :). Makes sense now that you explain it - looked awkward at 
first.



+
+static target_ulong h_bulk_remove(CPUState *env, sPAPREnvironment *spapr,
+  target_ulong opcode, target_ulong *args)
+{
+int i;
+
+for (i = 0; i  4; i++) {
+target_ulong *tsh =args[i*2];
+target_ulong tsl = args[i*2 + 1];

Mind to replace all those magic numbers by something more verbose?

So, all those == 2.  I can replace the 4 with something I guess, but
changing the 2 would just be silly - that code is just taking the
arguments a pair at a time.


Yup. Thanks! Applied.


Alex




Re: [Qemu-devel] [PATCH v2 00/45] Block layer cleanup fixes

2011-09-02 Thread Kevin Wolf
Am 03.08.2011 15:07, schrieb Markus Armbruster:
 This patch series looks bigger than it is.  All the patches are small
 and hopefully easy to review.
 
 Objectives:
 
 * Push BlockDriverState members locked, tray_open, media_changed into
   device models, where they belong.
 
 * BlockDriverState member removable is a confusing mess, replace it.
 
 * Improve eject -f.
 
 Also clean up minor messes as they get in the way.
 
 It is based on Kevin's block branch f08df41b.
 
 Part I: Preliminaries
 PATCH 01-03: Work on block layer interface for device models
 
 Part II: Move tray state to device models
 PATCH 04-10 IDE tray open/closed
 PATCH 11-12 SCSI tray open/closed
 PATCH 13-14 block layer kill tray_open
 PATCH 15-16 IDE  SCSI tray lock
 PATCH 17-19 block layer kill locked
 PATCH 20-24 IDE  SCSI tray bug fixes
 PATCH 25-27 IDE  SCSI migrate tray state
 PATCH 28-30 block layer  fdc media_changed
 
 Part III: Replace removable
 PATCH 31-34 clean up inappopriate uses of removable
 PATCH 35-36 replace remaining users
 
 Part IV: Miscellaneous
 PATCH 37cover tray open/closed in info block
 PATCH 38-43 Reduce unclean use of block_int.h
 PATCH 44-45 Improve eject -f
 
 Naturally, I want all parts applied.  But I did my best to make
 applying only a prefix workable, too.

Thanks, applied some patches to the block branch. Waiting for v3 for the
rest.

I didn't pick them only from the start of the series, but considered any
patch that looked good and didn't seem to depend on other patches. This
means that some patches may be applied in a different order now, but I'm
relatively sure that it doesn't break things.

Kevin



Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access

2011-09-02 Thread Gerd Hoffmann

  Hi,


After some investigation, I found out that the problem is that different
SPICE threads are calling monitor functions (such as
monitor_protocol_event()) in parallel which causes concurrent access
to the monitor's internal buffer outbuf[].


[ adding spice-list to Cc, see qemu-devel for the rest of the thread ]

spice isn't supposed to do that.

/me just added a assert in channel_event() and saw it trigger in display 
channel disconnects.


#0  0x003ceba32a45 in raise () from /lib64/libc.so.6
#1  0x003ceba34225 in abort () from /lib64/libc.so.6
#2  0x003ceba2b9d5 in __assert_fail () from /lib64/libc.so.6
#3  0x00503759 in channel_event (event=3, info=0x35e9340)
at /home/kraxel/projects/qemu/ui/spice-core.c:223
#4  0x7f9a77a9921b in reds_channel_event (s=0x35e92c0) at reds.c:400
#5  reds_stream_free (s=0x35e92c0) at reds.c:4981
#6  0x7f9a77aac8b0 in red_disconnect_channel 
(channel=0x7f9a24069a80) at red_worker.c:8489
#7  0x7f9a77ab53a8 in handle_dev_input (listener=0x7f9a3211ab20, 
events=value optimized out)

at red_worker.c:10062
#8  0x7f9a77ab436d in red_worker_main (arg=value optimized out) at 
red_worker.c:10304

#9  0x003cec2077e1 in start_thread () from /lib64/libpthread.so.0
#10 0x003cebae68ed in clone () from /lib64/libc.so.6

IMHO spice server should handle the display channel tear-down in the 
dispatcher instead of the worker thread.  Alon?



Anyways, this commit fixes the problem at hand.


Not really.  channel_event() itself isn't thread-safe too, it does 
unlocked list operations which can also blow up when called from 
different threads.


A patch like the attached (warning: untested) should do as quickdirty 
fix for stable.  But IMO we really should fix spice instead.


cheers,
  Gerd

From 7496e573ff6085d3c42d7e65b72c85fd2a7b4a78 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann kra...@redhat.com
Date: Fri, 2 Sep 2011 15:03:28 +0200
Subject: [PATCH] spice: workaround a spice server bug.

---
 ui/spice-core.c |   21 -
 1 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/ui/spice-core.c b/ui/spice-core.c
index dba11f0..c99cdc5 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -19,6 +19,7 @@
 #include spice-experimental.h
 
 #include netdb.h
+#include pthread.h
 
 #include qemu-common.h
 #include qemu-spice.h
@@ -44,6 +45,8 @@ static char *auth_passwd;
 static time_t auth_expires = TIME_MAX;
 int using_spice = 0;
 
+static pthread_t me;
+
 struct SpiceTimer {
 QEMUTimer *timer;
 QTAILQ_ENTRY(SpiceTimer) next;
@@ -216,6 +219,8 @@ static void channel_event(int event, SpiceChannelEventInfo 
*info)
 };
 QDict *server, *client;
 QObject *data;
+bool need_lock = !pthread_equal(me, pthread_self());
+static int first = 1;
 
 client = qdict_new();
 add_addr_info(client, info-paddr, info-plen);
@@ -223,6 +228,14 @@ static void channel_event(int event, SpiceChannelEventInfo 
*info)
 server = qdict_new();
 add_addr_info(server, info-laddr, info-llen);
 
+if (need_lock) {
+qemu_mutex_lock_iothread();
+if (first) {
+fprintf(stderr, You are using a broken spice-server version\n);
+first = 0;
+}
+}
+
 if (event == SPICE_CHANNEL_EVENT_INITIALIZED) {
 qdict_put(server, auth, qstring_from_str(auth));
 add_channel_info(client, info);
@@ -236,6 +249,10 @@ static void channel_event(int event, SpiceChannelEventInfo 
*info)
   QOBJECT(client), QOBJECT(server));
 monitor_protocol_event(qevent[event], data);
 qobject_decref(data);
+
+if (need_lock) {
+qemu_mutex_unlock_iothread();
+}
 }
 
 #else /* SPICE_INTERFACE_CORE_MINOR = 3 */
@@ -482,7 +499,9 @@ void qemu_spice_init(void)
 spice_image_compression_t compression;
 spice_wan_compression_t wan_compr;
 
-if (!opts) {
+me = pthread_self();
+
+   if (!opts) {
 return;
 }
 port = qemu_opt_get_number(opts, port, 0);
-- 
1.7.1



Re: [Qemu-devel] [PATCH] main: force enabling of I/O thread

2011-09-02 Thread Mark Cave-Ayland

On 01/09/11 19:31, Andreas Färber wrote:


If there aren't known issues, then I want to remove the non-I/O thread
code. git history is still there for anyone that wants to test w/o it.


My problem is that at HEAD *none* of the i386,ppc,sparc guests that used
to work about a month ago boot *at all* on my Darwin/ppc64 host.


At the moment, SPARC/PPC in HEAD invokes a crashing bug in OpenBIOS 
because of this commit:


commit c7b488721d6aafe32994ac63f8d690ae6d4729fa
Author: Paolo Bonzini pbonz...@redhat.com
Date:   Wed Aug 3 10:49:18 2011 +0200

scsi: report unit attention on reset

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Anthony Liguori aligu...@us.ibm.com

Blue (CC) committed an appropriate fix to OpenBIOS SVN as r1047 but 
hasn't yet updated the binaries in git which is why the crash still 
exists. Not sure about the i386 part, although a brief test on a PPC64 
Mac running Linux boots the linux-0.2.img.bz2 test image fine here.



ATB,

Mark.

--
Mark Cave-Ayland - Senior Technical Architect
PostgreSQL - PostGIS
Sirius Corporation plc - control through freedom
http://www.siriusit.co.uk
t: +44 870 608 0063

Sirius Labs: http://www.siriusit.co.uk/labs



Re: [Qemu-devel] [PATCH 1/3] rbd: fix leak in failure path

2011-09-02 Thread Stefan Hajnoczi
On Tue, Aug 23, 2011 at 5:28 PM, Sage Weil s...@newdream.net wrote:
 Fix leak of s-snap when rados_create fails.

 Reported-by: Stefan Hajnoczi stefa...@gmail.com
 Signed-off-by: Sage Weil s...@newdream.net
 ---
  block/rbd.c |    9 +
  1 files changed, 5 insertions(+), 4 deletions(-)

 diff --git a/block/rbd.c b/block/rbd.c
 index d5659cd..52b79fa 100644
 --- a/block/rbd.c
 +++ b/block/rbd.c
 @@ -393,10 +393,6 @@ static int qemu_rbd_open(BlockDriverState *bs, const 
 char *filename, int flags)
                            conf, sizeof(conf))  0) {
         return -EINVAL;
     }
 -    s-snap = NULL;
 -    if (snap_buf[0] != '\0') {
 -        s-snap = qemu_strdup(snap_buf);
 -    }

     r = rados_create(s-cluster, NULL);
     if (r  0) {
 @@ -404,6 +400,11 @@ static int qemu_rbd_open(BlockDriverState *bs, const 
 char *filename, int flags)
         return r;
     }

 +    s-snap = NULL;
 +    if (snap_buf[0] != '\0') {
 +        s-snap = qemu_strdup(snap_buf);
 +    }
 +
     if (strstr(conf, conf=) == NULL) {
         r = rados_conf_read_file(s-cluster, NULL);
         if (r  0) {

I think s-snap is still leaked when any other error return in this
function is taken.

Stefan



Re: [Qemu-devel] [PATCH 2/3] rbd: allow client id to be specified in config string

2011-09-02 Thread Stefan Hajnoczi
On Tue, Aug 23, 2011 at 5:28 PM, Sage Weil s...@newdream.net wrote:
 Allow the client id to be specified in the config string via 'id=' so that
 users can control who they authenticate as.  Currently they are stuck with
 the default ('admin').  This is necessary for anyone using authentication
 in their environment.

 Signed-off-by: Sage Weil s...@newdream.net
 ---
  block/rbd.c |   52 
  1 files changed, 44 insertions(+), 8 deletions(-)

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



Re: [Qemu-devel] [PATCH 3/3] rbd: clean up, fix style

2011-09-02 Thread Stefan Hajnoczi
On Tue, Aug 23, 2011 at 5:28 PM, Sage Weil s...@newdream.net wrote:
 No assignment in condition.  Remove duplicate ret  0 check.

 Signed-off-by: Sage Weil s...@newdream.net
 ---
  block/rbd.c |   17 -
  1 files changed, 8 insertions(+), 9 deletions(-)

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



Re: [Qemu-devel] [PATCH 0/3] usb-musb: make qdev-aware

2011-09-02 Thread Gerd Hoffmann

  Hi,


http://narcissus.angstrom-distribution.org/ can generate jffs2/ubifs
images for n8x0 (select nokia800 from machine selector). You will need a
copy of config mtd partition from working n8x0 (at least it was needed
when I was playing with it) with “no-lifeguard-reset” flag set.


Got a tarball.  Passing the zImage in there to qemu via -kernel works. 
I see it boot @ sdl, with the boot messages flying by quickly. 
Redirecting the console to a terminal seems not to work, at least not 
via '-nographic -append console=ttyS0'


When passing in something via -mtdblock I can see lots of error messages 
about bad eraseblocks.  I guess this is where the config mtd partition 
will be needed?


thanks,
  Gerd




Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access

2011-09-02 Thread Luiz Capitulino
On Fri, 02 Sep 2011 15:39:03 +0200
Gerd Hoffmann kra...@redhat.com wrote:

Hi,
 
  After some investigation, I found out that the problem is that different
  SPICE threads are calling monitor functions (such as
  monitor_protocol_event()) in parallel which causes concurrent access
  to the monitor's internal buffer outbuf[].
 
 [ adding spice-list to Cc, see qemu-devel for the rest of the thread ]
 
 spice isn't supposed to do that.
 
 /me just added a assert in channel_event() and saw it trigger in display 
 channel disconnects.
 
 #0  0x003ceba32a45 in raise () from /lib64/libc.so.6
 #1  0x003ceba34225 in abort () from /lib64/libc.so.6
 #2  0x003ceba2b9d5 in __assert_fail () from /lib64/libc.so.6
 #3  0x00503759 in channel_event (event=3, info=0x35e9340)
  at /home/kraxel/projects/qemu/ui/spice-core.c:223
 #4  0x7f9a77a9921b in reds_channel_event (s=0x35e92c0) at reds.c:400
 #5  reds_stream_free (s=0x35e92c0) at reds.c:4981
 #6  0x7f9a77aac8b0 in red_disconnect_channel 
 (channel=0x7f9a24069a80) at red_worker.c:8489
 #7  0x7f9a77ab53a8 in handle_dev_input (listener=0x7f9a3211ab20, 
 events=value optimized out)
  at red_worker.c:10062
 #8  0x7f9a77ab436d in red_worker_main (arg=value optimized out) at 
 red_worker.c:10304
 #9  0x003cec2077e1 in start_thread () from /lib64/libpthread.so.0
 #10 0x003cebae68ed in clone () from /lib64/libc.so.6
 
 IMHO spice server should handle the display channel tear-down in the 
 dispatcher instead of the worker thread.  Alon?
 
  Anyways, this commit fixes the problem at hand.
 
 Not really.  channel_event() itself isn't thread-safe too, it does 
 unlocked list operations which can also blow up when called from 
 different threads.

I thought my patch was at least a candidate for stable, but after this
thread I'm convinced the problem should be fixed in spice instead.

 
 A patch like the attached (warning: untested) should do as quickdirty 
 fix for stable.  But IMO we really should fix spice instead.
 
 cheers,
Gerd
 




Re: [Qemu-devel] [PATCH 3/8] RunState: Add additional states

2011-09-02 Thread Luiz Capitulino
On Thu, 01 Sep 2011 22:58:51 +0200
Jan Kiszka jan.kis...@web.de wrote:

 On 2011-09-01 20:39, Luiz Capitulino wrote:
  On Thu, 01 Sep 2011 20:30:57 +0200
  Jan Kiszka jan.kis...@siemens.com wrote:
  
  On 2011-09-01 20:12, Luiz Capitulino wrote:
  Currently, only vm_start() and vm_stop() change the VM state.
  That's, the state is only changed when starting or stopping the VM.
 
  This commit adds the runstate_set() function, which makes it possible
  to also do state transitions when the VM is stopped or running.
 
  Additional states are also added and the current state is stored.
 
  Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
  ---
   cpus.c  |1 +
   migration.c |8 +++-
   sysemu.h|   10 +-
   vl.c|   20 
   4 files changed, 37 insertions(+), 2 deletions(-)
 
 
  ...
 
  diff --git a/vl.c b/vl.c
  index f0b56a4..59f71fc 100644
  --- a/vl.c
  +++ b/vl.c
  @@ -321,6 +321,22 @@ static int default_driver_check(QemuOpts *opts, void 
  *opaque)
   }
   
   /***/
  +/* QEMU state */
  +
  +static RunState current_run_state = RSTATE_NO_STATE;
  +
  +bool runstate_check(RunState state)
  +{
  +return current_run_state == state;
  +}
  +
  +void runstate_set(RunState state)
  +{
  +assert(state  RSTATE_MAX);
  +current_run_state = state;
 
  I still think this should check for valid state transitions instead of
  blindly accepting what the caller passes in.
  
  I thought your comment where more like a future enhancement than
  a request for change.
 
 I think we want this now to document at a central place which
 transitions are valid and which not. State machines without such checks
 break sooner or later, subtly.

Ok, I'll do it.

Do you have any suggestion on the preferred way to document it?
Should I use english or try some ascii art?

 
  
  What to do if the transition is invalid? abort()?
 
 Yes.
 
 Jan
 




Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access

2011-09-02 Thread Anthony Liguori

On 09/02/2011 08:39 AM, Gerd Hoffmann wrote:

Hi,


After some investigation, I found out that the problem is that different
SPICE threads are calling monitor functions (such as
monitor_protocol_event()) in parallel which causes concurrent access
to the monitor's internal buffer outbuf[].


[ adding spice-list to Cc, see qemu-devel for the rest of the thread ]

spice isn't supposed to do that.

/me just added a assert in channel_event() and saw it trigger in display
channel disconnects.

#0 0x003ceba32a45 in raise () from /lib64/libc.so.6
#1 0x003ceba34225 in abort () from /lib64/libc.so.6
#2 0x003ceba2b9d5 in __assert_fail () from /lib64/libc.so.6
#3 0x00503759 in channel_event (event=3, info=0x35e9340)
at /home/kraxel/projects/qemu/ui/spice-core.c:223
#4 0x7f9a77a9921b in reds_channel_event (s=0x35e92c0) at reds.c:400
#5 reds_stream_free (s=0x35e92c0) at reds.c:4981
#6 0x7f9a77aac8b0 in red_disconnect_channel (channel=0x7f9a24069a80)
at red_worker.c:8489
#7 0x7f9a77ab53a8 in handle_dev_input (listener=0x7f9a3211ab20,
events=value optimized out)
at red_worker.c:10062
#8 0x7f9a77ab436d in red_worker_main (arg=value optimized out) at
red_worker.c:10304
#9 0x003cec2077e1 in start_thread () from /lib64/libpthread.so.0
#10 0x003cebae68ed in clone () from /lib64/libc.so.6

IMHO spice server should handle the display channel tear-down in the
dispatcher instead of the worker thread. Alon?


Anyways, this commit fixes the problem at hand.


Not really. channel_event() itself isn't thread-safe too, it does
unlocked list operations which can also blow up when called from
different threads.

A patch like the attached (warning: untested) should do as quickdirty
fix for stable. But IMO we really should fix spice instead.


I agree.  I'm not sure I like the idea of still calling QEMU code 
without holding the mutex (even the QObject code).


Can you just use a bottom half to defer this work to the I/O thread? 
Bottom half scheduling has to be signal safe which means it will also be 
thread safe.


Regards,

Anthony Liguori



cheers,
Gerd






Re: [Qemu-devel] emulated ARM performance vs real processor ?

2011-09-02 Thread David Gilbert
On 1 September 2011 08:32, Julien Heyman bidsom...@gmail.com wrote:
 Hi,

 I was wondering if anyone had some data regarding the relative performance
 of any given ARM board emulated in QEMU versus the real thing. Yes, I do
 know this depends a lot on the host PC running qemu, but some
 ballpark/example figures would help. Say, I emulate a 400 Mhz ARM9 processor
 on a Core2Duo laptop @ 2 Ghz, what kind of performance/timing ratio should I
 expect, one way or the other ? For example, for boot time.
 I have no idea whether the overhead of emulation is over-compensated by the
 huge processing power of the host compared to the real HW target, and by
 which factor.

Comparing performance is always a bit tricky, and I've not really got
a solid set of benchmarks
ready to run to try it but to give some numbers:

1) Boot times
   Comparing the Linaro 11.08 ubuntu desktop images, time to boot to desktop

   Real Panda board (dual core A9 at 1GHz, 1GB RAM, running off SD
card) - 2minutes to desktop
   QEMU vexpress (2xA9 core, 1GB RAM, emulated sd card, running on a
Core2 Duo T9400 2.53GHz laptop) - 3minutes to desktop

   (The times are scarily close to exact minutes - timeout somewhere?)
   Now, QEMU system mode only ever uses one host core when emulating
multiple cores, so there is a factor 2 disadvantage there, but
on the plus side the memory bandwidth of the host and the disk speed
is probably much higher than the Panda.

2) Simple md5sum benchmark
   As a really simple benchmark the test:

time (dd if=/dev/zero bs=1024k count=1000 | md5sum)

Panda board 14.5s real, 10.7 user, 3.8s system
Emulated Overo board (single A8 processor on same laptop as above)
- 41s real, 24.7s user, 16.4s system
User mode emulated - 14.2s real, 14s user, 0.5s system
Native on x86 host - 3.2s real, 2.5s user, 1.2s system

So, that's two sets of pretty bogus dummy simple benchmarks!

I suppose one observation is that the boot time isn't that bad
compared to the real (different) hardware, the user mode emulation
was comparable to the Panda, but the system emulation on a simple test
seems a lot slower.

These things will vary wildly depending what your benchmark is; but as
a summary I'd say that the ARM system mode emulation is
fast enough to use interactively but CPU wise is noticeably slower
than user mode emulation.

Dave



Re: [Qemu-devel] [PATCH] main: force enabling of I/O thread

2011-09-02 Thread Anthony Liguori

On 09/01/2011 01:31 PM, Andreas Färber wrote:

Am 30.08.2011 um 21:28 schrieb Anthony Liguori:


On 08/30/2011 01:45 PM, Andreas Färber wrote:

Am 30.08.2011 um 00:42 schrieb Jan Kiszka:


What about making --enable-io-thread default as an intermediate step?
That would leave --disable-io-thread as temporary workaround until all
issues are fixed. The latter could generate a big fat warning that this
mode will be removed before 1.0.


Yes please, that proposal sounds much better.

If http://wiki.qemu.org/Planning/1.0 is still up-to-date, we have about
six weeks to make I/O thread work everywhere.


I'm not a big fan of just flipping the configure flag. There is other
work being held up by disable-io-thread like the timer conversion.

If there aren't known issues, then I want to remove the non-I/O thread
code. git history is still there for anyone that wants to test w/o it.


My problem is that at HEAD *none* of the i386,ppc,sparc guests that used
to work about a month ago boot *at all* on my Darwin/ppc64 host.

Might be TCG, might be the new MemoryRegion API, might be (non-)I/O
thread. Means a lot of git history testing despite little time. An
ultimatum to make things even worse doesn't really help there... ;)


For a platform to be supported, it needs to be actively maintained and 
fixed.  If there aren't enough folks testing/fixing Darwin/ppc64, then 
it's not a platform we can reasonable support :-/


Regards,

Anthony Liguori



Andreas





Re: [Qemu-devel] [PATCH 3/8] RunState: Add additional states

2011-09-02 Thread Jan Kiszka
On 2011-09-02 16:28, Luiz Capitulino wrote:
 On Thu, 01 Sep 2011 22:58:51 +0200
 Jan Kiszka jan.kis...@web.de wrote:
 
 On 2011-09-01 20:39, Luiz Capitulino wrote:
 On Thu, 01 Sep 2011 20:30:57 +0200
 Jan Kiszka jan.kis...@siemens.com wrote:

 On 2011-09-01 20:12, Luiz Capitulino wrote:
 Currently, only vm_start() and vm_stop() change the VM state.
 That's, the state is only changed when starting or stopping the VM.

 This commit adds the runstate_set() function, which makes it possible
 to also do state transitions when the VM is stopped or running.

 Additional states are also added and the current state is stored.

 Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
 ---
  cpus.c  |1 +
  migration.c |8 +++-
  sysemu.h|   10 +-
  vl.c|   20 
  4 files changed, 37 insertions(+), 2 deletions(-)


 ...

 diff --git a/vl.c b/vl.c
 index f0b56a4..59f71fc 100644
 --- a/vl.c
 +++ b/vl.c
 @@ -321,6 +321,22 @@ static int default_driver_check(QemuOpts *opts, void 
 *opaque)
  }
  
  /***/
 +/* QEMU state */
 +
 +static RunState current_run_state = RSTATE_NO_STATE;
 +
 +bool runstate_check(RunState state)
 +{
 +return current_run_state == state;
 +}
 +
 +void runstate_set(RunState state)
 +{
 +assert(state  RSTATE_MAX);
 +current_run_state = state;

 I still think this should check for valid state transitions instead of
 blindly accepting what the caller passes in.

 I thought your comment where more like a future enhancement than
 a request for change.

 I think we want this now to document at a central place which
 transitions are valid and which not. State machines without such checks
 break sooner or later, subtly.
 
 Ok, I'll do it.
 
 Do you have any suggestion on the preferred way to document it?
 Should I use english or try some ascii art?

My idea is programmatic:

void runstate_set(RunState new_state)
{
switch (current_state) {
case X:
/* potential comment on why only X-Y or ... is valid */
if (new_state == Y || ...) {
break;
} else {
abort();
}

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux



Re: [Qemu-devel] [PATCH 3/8] RunState: Add additional states

2011-09-02 Thread Luiz Capitulino
On Fri, 02 Sep 2011 16:32:25 +0200
Jan Kiszka jan.kis...@siemens.com wrote:

 On 2011-09-02 16:28, Luiz Capitulino wrote:
  On Thu, 01 Sep 2011 22:58:51 +0200
  Jan Kiszka jan.kis...@web.de wrote:
  
  On 2011-09-01 20:39, Luiz Capitulino wrote:
  On Thu, 01 Sep 2011 20:30:57 +0200
  Jan Kiszka jan.kis...@siemens.com wrote:
 
  On 2011-09-01 20:12, Luiz Capitulino wrote:
  Currently, only vm_start() and vm_stop() change the VM state.
  That's, the state is only changed when starting or stopping the VM.
 
  This commit adds the runstate_set() function, which makes it possible
  to also do state transitions when the VM is stopped or running.
 
  Additional states are also added and the current state is stored.
 
  Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
  ---
   cpus.c  |1 +
   migration.c |8 +++-
   sysemu.h|   10 +-
   vl.c|   20 
   4 files changed, 37 insertions(+), 2 deletions(-)
 
 
  ...
 
  diff --git a/vl.c b/vl.c
  index f0b56a4..59f71fc 100644
  --- a/vl.c
  +++ b/vl.c
  @@ -321,6 +321,22 @@ static int default_driver_check(QemuOpts *opts, 
  void *opaque)
   }
   
   /***/
  +/* QEMU state */
  +
  +static RunState current_run_state = RSTATE_NO_STATE;
  +
  +bool runstate_check(RunState state)
  +{
  +return current_run_state == state;
  +}
  +
  +void runstate_set(RunState state)
  +{
  +assert(state  RSTATE_MAX);
  +current_run_state = state;
 
  I still think this should check for valid state transitions instead of
  blindly accepting what the caller passes in.
 
  I thought your comment where more like a future enhancement than
  a request for change.
 
  I think we want this now to document at a central place which
  transitions are valid and which not. State machines without such checks
  break sooner or later, subtly.
  
  Ok, I'll do it.
  
  Do you have any suggestion on the preferred way to document it?
  Should I use english or try some ascii art?
 
 My idea is programmatic:
 
 void runstate_set(RunState new_state)
 {
   switch (current_state) {
   case X:
   /* potential comment on why only X-Y or ... is valid */
   if (new_state == Y || ...) {
   break;
   } else {
   abort();
   }

Ah, ok. I was thinking in having some fancy graph as documentation,
but let's do the simpler way then.



Re: [Qemu-devel] [PATCH] main: force enabling of I/O thread

2011-09-02 Thread Paolo Bonzini

On 09/02/2011 04:31 PM, Anthony Liguori wrote:

For a platform to be supported, it needs to be actively maintained and
fixed.  If there aren't enough folks testing/fixing Darwin/ppc64, then
it's not a platform we can reasonable support :-/


I agree unfortunately.  I think personally that Darwin is important (at 
least Darwin/VNC, I care zero about Cocoa and SDL) because it keeps us 
honest and avoids introducing unwanted Linux-isms.  But if even Windows 
turns out to work better than Darwin, that is not a good sign.


Still, Andreas, please do try to get a report of how iothread works on 
Darwin with VNC graphics.


Paolo



Re: [Qemu-devel] [PATCH v2 07/45] ide: Use a table to declare which drive kinds accept each command

2011-09-02 Thread Markus Armbruster
Kevin Wolf kw...@redhat.com writes:

 Am 03.08.2011 18:53, schrieb Blue Swirl:
 On Wed, Aug 3, 2011 at 1:07 PM, Markus Armbruster arm...@redhat.com wrote:
 No functional change.

 It would be nice to have handler functions in the table, like commit
 e1a064f9 did for ATAPI.  Left for another day.

 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  hw/ide/core.c |  104 
 +++--
  1 files changed, 79 insertions(+), 25 deletions(-)

 diff --git a/hw/ide/core.c b/hw/ide/core.c
 index 1c4dc2f..a25c175 100644
 --- a/hw/ide/core.c
 +++ b/hw/ide/core.c
 @@ -876,6 +876,77 @@ void ide_ioport_write(void *opaque, uint32_t addr, 
 uint32_t val)
 }
  }

 +#define HD_OK (1u  IDE_HD)
 +#define CD_OK (1u  IDE_CD)
 +#define CFA_OK (1u  IDE_CFATA)
 +#define HD_CFA_OK (HD_OK | CFA_OK)
 +#define ALL_OK (HD_OK | CD_OK | CFA_OK)
 +
 +/* See ACS-2 T13/2015-D Table B.2 Command codes */
 +uint8_t ide_cmd_table[0x100] = {
 
 Missing 'static'.

 And const, while we're at it.

Yes.

 +/* NOP not implemented, mandatory for CD */
 +[CFA_REQ_EXT_ERROR_CODE]= CFA_OK,
 +[WIN_DSM]   = ALL_OK,
 +[WIN_DEVICE_RESET]  = CD_OK,
 +[WIN_RECAL] = ALL_OK,
 +[WIN_READ]  = ALL_OK,
 +[WIN_READ_ONCE] = ALL_OK,
 +[WIN_READ_EXT]  = ALL_OK,
 +[WIN_READDMA_EXT]   = ALL_OK,
 +[WIN_READ_NATIVE_MAX_EXT]   = ALL_OK,
 +[WIN_MULTREAD_EXT]  = ALL_OK,
 +[WIN_WRITE] = ALL_OK,
 +[WIN_WRITE_ONCE]= ALL_OK,
 +[WIN_WRITE_EXT] = ALL_OK,
 +[WIN_WRITEDMA_EXT]  = ALL_OK,
 +[CFA_WRITE_SECT_WO_ERASE]   = ALL_OK,
 +[WIN_MULTWRITE_EXT] = ALL_OK,
 +[WIN_WRITE_VERIFY]  = ALL_OK,
 +[WIN_VERIFY]= ALL_OK,
 +[WIN_VERIFY_ONCE]   = ALL_OK,
 +[WIN_VERIFY_EXT]= ALL_OK,
 +[WIN_SEEK]  = HD_CFA_OK,
 +[CFA_TRANSLATE_SECTOR]  = CFA_OK,
 +[WIN_DIAGNOSE]  = ALL_OK,
 +[WIN_SPECIFY]   = ALL_OK,
 +[WIN_STANDBYNOW2]   = ALL_OK,
 +[WIN_IDLEIMMEDIATE2]= ALL_OK,
 +[WIN_STANDBY2]  = ALL_OK,
 +[WIN_SETIDLE2]  = ALL_OK,
 +[WIN_CHECKPOWERMODE2]   = ALL_OK,
 +[WIN_SLEEPNOW2] = ALL_OK,
 +[WIN_PACKETCMD] = CD_OK,
 +[WIN_PIDENTIFY] = CD_OK,
 +[WIN_SMART] = HD_CFA_OK,
 +[CFA_ACCESS_METADATA_STORAGE]   = CFA_OK,
 +[CFA_ERASE_SECTORS] = CFA_OK,
 +[WIN_MULTREAD]  = ALL_OK,
 +[WIN_MULTWRITE] = ALL_OK,
 +[WIN_SETMULT]   = ALL_OK,
 +[WIN_READDMA]   = ALL_OK,
 +[WIN_READDMA_ONCE]  = ALL_OK,
 +[WIN_WRITEDMA]  = ALL_OK,
 +[WIN_WRITEDMA_ONCE] = ALL_OK,
 +[CFA_WRITE_MULTI_WO_ERASE]  = ALL_OK,
 +[WIN_STANDBYNOW1]   = ALL_OK,
 +[WIN_IDLEIMMEDIATE] = ALL_OK,
 +[WIN_STANDBY]   = ALL_OK,
 +[WIN_SETIDLE1]  = ALL_OK,
 +[WIN_CHECKPOWERMODE1]   = ALL_OK,
 +[WIN_SLEEPNOW1] = ALL_OK,
 +[WIN_FLUSH_CACHE]   = ALL_OK,
 +[WIN_FLUSH_CACHE_EXT]   = ALL_OK,
 +[WIN_IDENTIFY]  = ALL_OK,
 +[WIN_SETFEATURES]   = ALL_OK,
 +[IBM_SENSE_CONDITION]   = CFA_OK,
 +[CFA_WEAR_LEVEL]= CFA_OK,
 +[WIN_READ_NATIVE_MAX]   = ALL_OK,
 +};
 +
 +static bool ide_cmd_permitted(IDEState *s, uint32_t cmd)
 +{
 +return cmd = 0xff  (ide_cmd_table[cmd]  (1u  s-drive_kind));
 +}

 Doesn't cmd  ARRAY_SIZE(ide_cmd_table) better describe what you want?

Since I touch this patch anyway, I'll do this your way.



Re: [Qemu-devel] [PATCH v2 09/45] ide/atapi: Clean up misleading name in cmd_start_stop_unit()

2011-09-02 Thread Markus Armbruster
Kevin Wolf kw...@redhat.com writes:

 Am 03.08.2011 15:07, schrieb Markus Armbruster:
 eject is misleading; it means eject when start is clear, but
 load when start is set.  Rename to loej, because that's how MMC-5
 calls it, in section 6.40.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  hw/ide/atapi.c |8 
  1 files changed, 4 insertions(+), 4 deletions(-)
 
 diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
 index fe2fb0b..17fbef8 100644
 --- a/hw/ide/atapi.c
 +++ b/hw/ide/atapi.c
 @@ -892,11 +892,11 @@ static void cmd_seek(IDEState *s, uint8_t* buf)
  
  static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)
  {
 -int start, eject, sense, err = 0;
 -start = buf[4]  1;
 -eject = (buf[4]  1)  1;
 +int sense, err = 0;
 +bool start = buf[4]  1;
 +bool loej = buf[4]  2;
  
 -if (eject) {
 +if (loej) {
  err = bdrv_eject(s-bs, !start);
  }
  

 eject has the advantage that I immediately know that it's something to
 do with the tray. loej on the other hand is a sequence of four random
 characters. Maybe add a comment?

The name loej comes from MMC-5.  I can add a comment to its
definition.



Re: [Qemu-devel] [PATCH v2 10/45] ide/atapi: Track tray open/close state

2011-09-02 Thread Markus Armbruster
Kevin Wolf kw...@redhat.com writes:

 Am 03.08.2011 15:07, schrieb Markus Armbruster:
 We already track it in BlockDriverState since commit 4be9762a.  As
 discussed in that commit's message, we should track it in the device
 device models instead, because it's device state.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  hw/ide/atapi.c|6 +-
  hw/ide/internal.h |1 +
  2 files changed, 6 insertions(+), 1 deletions(-)
 
 diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
 index 17fbef8..96f7c31 100644
 --- a/hw/ide/atapi.c
 +++ b/hw/ide/atapi.c
 @@ -510,7 +510,7 @@ static unsigned int event_status_media(IDEState *s,
  uint8_t event_code, media_status;
  
  media_status = 0;
 -if (s-bs-tray_open) {
 +if (s-tray_open) {
  media_status = MS_TRAY_OPEN;
  } else if (bdrv_is_inserted(s-bs)) {
  media_status = MS_MEDIA_PRESENT;
 @@ -915,6 +915,10 @@ static void cmd_start_stop_unit(IDEState *s, uint8_t* 
 buf)
  ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT);
  break;
  }
 +
 +if (loej  !err) {
 +s-tray_open = !start;
 +}
  }
  
  static void cmd_mechanism_status(IDEState *s, uint8_t* buf)
 diff --git a/hw/ide/internal.h b/hw/ide/internal.h
 index 46e84fa..cd8e977 100644
 --- a/hw/ide/internal.h
 +++ b/hw/ide/internal.h
 @@ -442,6 +442,7 @@ struct IDEState {
  struct unreported_events events;
  uint8_t sense_key;
  uint8_t asc;
 +bool tray_open;
  uint8_t cdrom_changed;
  int packet_transfer_size;
  int elementary_transfer_size;

 Probably needs to be migrated.

Correct, but I chose to fix that separately, in PATCH 27/45.  Note that
this patch neither breaks nor fixes anything.  It just prepares the
ground for fixes.



Re: [Qemu-devel] [PATCH v2 11/45] scsi-disk: Factor out scsi_disk_emulate_start_stop()

2011-09-02 Thread Markus Armbruster
Kevin Wolf kw...@redhat.com writes:

 Am 03.08.2011 15:07, schrieb Markus Armbruster:
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  hw/scsi-disk.c |   17 +
  1 files changed, 13 insertions(+), 4 deletions(-)
 
 diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
 index fa198f9..d549cb7 100644
 --- a/hw/scsi-disk.c
 +++ b/hw/scsi-disk.c
 @@ -820,6 +820,18 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, 
 uint8_t *outbuf)
  return toclen;
  }
  
 +static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
 +{
 +SCSIRequest *req = r-req;
 +SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req-dev);
 +bool start = req-cmd.buf[4]  1;
 +bool loej = req-cmd.buf[4]  2;
 +
 +if (s-qdev.type == TYPE_ROM  loej) {
 +bdrv_eject(s-bs, !start);
 +}
 +}
 +
  static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
  {
  SCSIRequest *req = r-req;
 @@ -873,10 +885,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, 
 uint8_t *outbuf)
  goto illegal_request;
  break;
  case START_STOP:
 -if (s-qdev.type == TYPE_ROM  (req-cmd.buf[4]  2)) {
 -/* load/eject medium */

 So here we actually had the comment before. Can we retain it?

We never had it in atapi.c, actually.

The fact that my scsi_disk_emulate_command() is very similar to
atapi.c's cmd_start_stop_unit() is no accident.  Whatever comment I'll
add to atapi.c, I'll add here, too.



Re: [Qemu-devel] [PATCH] build: sort objects to remove duplicates for link

2011-09-02 Thread Anthony Liguori

On 09/02/2011 03:42 AM, Stefan Hajnoczi wrote:

2011/9/1 Michael Rothmdr...@linux.vnet.ibm.com:

On 09/01/2011 01:54 PM, Anthony Liguori wrote:


On 08/25/2011 03:18 AM, Stefan Hajnoczi wrote:


Avoid duplicate object files during the link. There are legitimate
cases where a link command-line would include duplicate object files
because two independent subsystems both depend on common infrastructure.

Use GNU make's $(sort) function to remove duplicate object files from
the link command-line.

Signed-off-by: Stefan Hajnoczistefa...@linux.vnet.ibm.com


Applied. Thanks.



Don't think it'll hurt to have both, but [PATCH 01/15] build: Fix linkage
of QEMU_PROG from Stefan's tracing pull request has the more elegant fix
for this.


Agreed, it doesn't hurt to take this one but the $^ fix is nicer and
already merged.

Anthony: Do you want to revert this patch?  It's not necessary.


If someone wants to send a patch, I can apply it, but I don't see the 
motivation to revert.


Regards,

Anthony Liguori


Stefan







Re: [Qemu-devel] [PATCH v2 15/45] ide/atapi: Track tray locked state

2011-09-02 Thread Markus Armbruster
Kevin Wolf kw...@redhat.com writes:

 Am 03.08.2011 15:07, schrieb Markus Armbruster:
 We already track it in BlockDriverState.  Just like tray open/close
 state, we should track it in the device models instead, because it's
 device state.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  hw/ide/atapi.c|4 +++-
  hw/ide/internal.h |1 +
  2 files changed, 4 insertions(+), 1 deletions(-)
 
 diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
 index 08e1a7a..237657f 100644
 --- a/hw/ide/atapi.c
 +++ b/hw/ide/atapi.c
 @@ -777,8 +777,9 @@ static void cmd_mode_sense(IDEState *s, uint8_t *buf)
  buf[12] = 0x71;
  buf[13] = 3  5;
  buf[14] = (1  0) | (1  3) | (1  5);
 -if (bdrv_is_locked(s-bs))
 +if (s-tray_locked) {
  buf[6] |= 1  1;
 +}
  buf[15] = 0x00;
  cpu_to_ube16(buf[16], 706);
  buf[18] = 0;
 @@ -820,6 +821,7 @@ static void cmd_test_unit_ready(IDEState *s, uint8_t 
 *buf)
  
  static void cmd_prevent_allow_medium_removal(IDEState *s, uint8_t* buf)
  {
 +s-tray_locked = buf[4]  1;
  bdrv_set_locked(s-bs, buf[4]  1);
  ide_atapi_cmd_ok(s);
  }
 diff --git a/hw/ide/internal.h b/hw/ide/internal.h
 index cd8e977..3e56b45 100644
 --- a/hw/ide/internal.h
 +++ b/hw/ide/internal.h
 @@ -443,6 +443,7 @@ struct IDEState {
  uint8_t sense_key;
  uint8_t asc;
  bool tray_open;
 +bool tray_locked;
  uint8_t cdrom_changed;
  int packet_transfer_size;
  int elementary_transfer_size;

 Same as tray open/close status: Needs to be migrated.

Correct, but I chose to fix that separately, in PATCH 26/45.  Note that
this patch neither breaks nor fixes anything.  It just prepares the
ground for fixes.



Re: [Qemu-devel] [PULL 00/15] Tracing patches

2011-09-02 Thread Anthony Liguori

On 09/02/2011 04:39 AM, Stefan Hajnoczi wrote:

On Thu, Sep 1, 2011 at 8:08 PM, Anthony Liguorialigu...@us.ibm.com  wrote:

On 09/01/2011 03:06 AM, Stefan Hajnoczi wrote:


The following changes since commit
f0fb8b7180fdcf536ea635a0720e1496110ecb3b:

   Merge branch 'omap-for-upstream' of
git://git.linaro.org/people/pmaydell/qemu-arm into pm (2011-08-29 23:59:06
+0200)

are available in the git repository at:

   ssh://repo.or.cz/srv/git/qemu/stefanha.git tracing


Pulled.  Thanks.


Your email was 14 hours ago but I don't see the commits in qemu.git.  Any ideas?


$ git log origin/master

commit 625f9e1f54cd78ee98ac22030da527c9a1cc9d2b
Merge: a952c57 2542bfd
Author: Anthony Liguori aligu...@us.ibm.com
Date:   Thu Sep 1 13:57:19 2011 -0500

Merge remote-tracking branch 'stefanha/trivial-patches' into staging

Not sure why you don't see it.  Did you not fetch?

Regards,

Anthony Liguori


Stefan







Re: [Qemu-devel] [PATCH v2 19/45] block: Rename bdrv_set_locked() to bdrv_lock_medium()

2011-09-02 Thread Markus Armbruster
Kevin Wolf kw...@redhat.com writes:

 Am 03.08.2011 15:07, schrieb Markus Armbruster:
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  block.c   |8 
  block.h   |2 +-
  block/raw-posix.c |8 
  block/raw.c   |6 +++---
  block_int.h   |2 +-
  hw/ide/atapi.c|2 +-
  hw/scsi-disk.c|2 +-
  trace-events  |2 +-
  8 files changed, 16 insertions(+), 16 deletions(-)
 
 diff --git a/block.c b/block.c
 index 3a8a4e6..10c1b1a 100644
 --- a/block.c
 +++ b/block.c
 @@ -3037,14 +3037,14 @@ void bdrv_eject(BlockDriverState *bs, int eject_flag)
   * Lock or unlock the media (if it is locked, the user won't be able
   * to eject it manually).
   */
 -void bdrv_set_locked(BlockDriverState *bs, int locked)
 +void bdrv_lock_medium(BlockDriverState *bs, int locked)

 Make locked a bool while we're changing the signature everywhere?

Good idea.



Re: [Qemu-devel] [PULL 00/15] Tracing patches

2011-09-02 Thread Anthony Liguori

On 09/02/2011 09:54 AM, Anthony Liguori wrote:

On 09/02/2011 04:39 AM, Stefan Hajnoczi wrote:

On Thu, Sep 1, 2011 at 8:08 PM, Anthony Liguorialigu...@us.ibm.com
wrote:

On 09/01/2011 03:06 AM, Stefan Hajnoczi wrote:


The following changes since commit
f0fb8b7180fdcf536ea635a0720e1496110ecb3b:

Merge branch 'omap-for-upstream' of
git://git.linaro.org/people/pmaydell/qemu-arm into pm (2011-08-29
23:59:06
+0200)

are available in the git repository at:

ssh://repo.or.cz/srv/git/qemu/stefanha.git tracing


Pulled. Thanks.


Your email was 14 hours ago but I don't see the commits in qemu.git.
Any ideas?


$ git log origin/master

commit 625f9e1f54cd78ee98ac22030da527c9a1cc9d2b
Merge: a952c57 2542bfd
Author: Anthony Liguori aligu...@us.ibm.com
Date: Thu Sep 1 13:57:19 2011 -0500

Merge remote-tracking branch 'stefanha/trivial-patches' into staging

Not sure why you don't see it. Did you not fetch?


Er, muscle memory.  I just assumed this was a trivial patch request. 
Sorry about that.


Regards,

Anthony Liguori



Regards,

Anthony Liguori


Stefan











Re: [Qemu-devel] QEMU online guest disk resize wrt host block devices

2011-09-02 Thread Daniel P. Berrange
On Thu, Sep 01, 2011 at 05:55:43PM +0200, Christoph Hellwig wrote:
 Please try the attached (untested) patch:

Yes, this patch worked succesfully with the following test case:

  $ dd if=/dev/zero of=loop.img bs=1M seek=100 count=0
  $ losetup -f loop.img

  $ ./x86_64-softmmu/qemu-system-x86_64 -hda /dev/loop0 -monitor stdio
  (qemu) info block
  ide0-hd0: removable=0 file=/dev/loop0 sectors=204800 ro=0 drv=raw encrypted=0
  ide1-cd0: removable=1 locked=0 [not inserted]
  floppy0: removable=1 locked=0 [not inserted]
  sd0: removable=1 locked=0 [not inserted]


  $ dd if=/dev/zero of=loop.img bs=1M seek=200 count=0
  $ losetup -c /dev/loop0 


  (qemu) block_resize ide0-hd0 200
  (qemu) info block
  ide0-hd0: removable=0 file=/dev/loop0 sectors=409600 ro=0 drv=raw encrypted=0
  ide1-cd0: removable=1 locked=0 [not inserted]
  floppy0: removable=1 locked=0 [not inserted]
  sd0: removable=1 locked=0 [not inserted]

Regards,
Daniel

 Index: qemu/block/raw-posix.c
 ===
 --- qemu.orig/block/raw-posix.c   2011-09-01 17:37:42.579651525 +0200
 +++ qemu/block/raw-posix.c2011-09-01 17:43:28.882967337 +0200
 @@ -645,10 +645,23 @@ static void raw_close(BlockDriverState *
  static int raw_truncate(BlockDriverState *bs, int64_t offset)
  {
  BDRVRawState *s = bs-opaque;
 -if (s-type != FTYPE_FILE)
 -return -ENOTSUP;
 -if (ftruncate(s-fd, offset)  0)
 +struct stat st;
 +
 +if (fstat(s-fd, st))
  return -errno;
 +
 +if (S_ISREG(st.st_mode)) {
 +if (ftruncate(s-fd, offset)  0)
 +return -errno;
 +} else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
 +   if (offset  raw_getlength(bs)) {
 +   return -EINVAL;
 +   }
 +   return 0;
 +
 +} else {
 +return -ENOTSUP;
 +}
  return 0;
  }
  
 @@ -1167,6 +1180,7 @@ static BlockDriver bdrv_host_device = {
  
  .bdrv_read  = raw_read,
  .bdrv_write = raw_write,
 +.bdrv_truncate = raw_truncate,
  .bdrv_getlength  = raw_getlength,
  .bdrv_get_allocated_file_size
  = raw_get_allocated_file_size,
 @@ -1288,6 +1302,7 @@ static BlockDriver bdrv_host_floppy = {
  
  .bdrv_read  = raw_read,
  .bdrv_write = raw_write,
 +.bdrv_truncate = raw_truncate,
  .bdrv_getlength  = raw_getlength,
  .bdrv_get_allocated_file_size
  = raw_get_allocated_file_size,
 @@ -1389,6 +1404,7 @@ static BlockDriver bdrv_host_cdrom = {
  
  .bdrv_read  = raw_read,
  .bdrv_write = raw_write,
 +.bdrv_truncate = raw_truncate,
  .bdrv_getlength = raw_getlength,
  .bdrv_get_allocated_file_size
  = raw_get_allocated_file_size,
 @@ -1510,6 +1526,7 @@ static BlockDriver bdrv_host_cdrom = {
  
  .bdrv_read  = raw_read,
  .bdrv_write = raw_write,
 +.bdrv_truncate = raw_truncate,
  .bdrv_getlength = raw_getlength,
  .bdrv_get_allocated_file_size
  = raw_get_allocated_file_size,



[Qemu-devel] [PATCH] Display sector count in 'info block' output

2011-09-02 Thread Daniel P. Berrange
From: Daniel P. Berrange d...@berrange.com

To aid in knowing whether a 'block_resize' was succesful, display
the sector count in the 'info block' output

Signed-off-by: Daniel P. Berrange d...@berrange.com
---
 block.c |6 --
 qmp-commands.hx |1 +
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index 03a21d8..fdb0665 100644
--- a/block.c
+++ b/block.c
@@ -1844,6 +1844,7 @@ static void bdrv_print_dict(QObject *obj, void *opaque)
 
 monitor_printf(mon,  file=);
 monitor_print_filename(mon, qdict_get_str(qdict, file));
+monitor_printf(mon,  sectors=% PRId64, qdict_get_int(qdict, 
sectors));
 if (qdict_haskey(qdict, backing_file)) {
 monitor_printf(mon,  backing_file=);
 monitor_print_filename(mon, qdict_get_str(qdict, backing_file));
@@ -1884,10 +1885,11 @@ void bdrv_info(Monitor *mon, QObject **ret_data)
 QDict *bs_dict = qobject_to_qdict(bs_obj);
 
 obj = qobject_from_jsonf({ 'file': %s, 'ro': %i, 'drv': %s, 
- 'encrypted': %i },
+ 'encrypted': %i, 'sectors': % PRId64  
},
  bs-filename, bs-read_only,
  bs-drv-format_name,
- bdrv_is_encrypted(bs));
+ bdrv_is_encrypted(bs),
+ bs-total_sectors);
 if (bs-backing_file[0] != '\0') {
 QDict *qdict = qobject_to_qdict(obj);
 qdict_put(qdict, backing_file,
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 27cc66e..07a20ff 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1134,6 +1134,7 @@ Each json-object contain the following:
 - inserted: only present if the device is inserted, it is a json-object
containing the following:
  - file: device file name (json-string)
+ - sectors: total sector count (json-int)
  - ro: true if read-only, false otherwise (json-bool)
  - drv: driver format name (json-string)
  - Possible values: blkdebug, bochs, cloop, cow, dmg,
-- 
1.7.6




Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access

2011-09-02 Thread Gerd Hoffmann

  Hi,


A patch like the attached (warning: untested) should do as quickdirty
fix for stable. But IMO we really should fix spice instead.


I agree. I'm not sure I like the idea of still calling QEMU code without
holding the mutex (even the QObject code).


I though just creating the objects isn't an issue, but if you disagree 
we can just move up the lock to the head of the function.



Can you just use a bottom half to defer this work to the I/O thread?
Bottom half scheduling has to be signal safe which means it will also be
thread safe.


Not that straight forward as I would have to pass arguments to the 
bottom half.


cheers,
  Gerd




Re: [Qemu-devel] [PATCH v2 22/45] ide/atapi: Avoid physical/virtual tray state mismatch

2011-09-02 Thread Markus Armbruster
Kevin Wolf kw...@redhat.com writes:

 Am 03.08.2011 15:08, schrieb Markus Armbruster:
 When ide-cd is backed by a physical drive, we want the physical tray
 match the virtual one.  To that end, we call bdrv_eject() on guest's
 load/eject, and bdrv_lock_medium() on guest's prevent/allow removal.
 But we don't set the initial state on device model init.  Fix that.
 
 While there, also unlock on device model exit.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  hw/ide/core.c |4 
  hw/ide/qdev.c |   18 ++
  2 files changed, 22 insertions(+), 0 deletions(-)
 
 diff --git a/hw/ide/core.c b/hw/ide/core.c
 index 5bcc857..d8b1d43 100644
 --- a/hw/ide/core.c
 +++ b/hw/ide/core.c
 @@ -1839,6 +1839,10 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, 
 IDEDriveKind kind,
  
  ide_reset(s);
  bdrv_set_removable(bs, s-drive_kind == IDE_CD);
 +if (s-drive_kind == IDE_CD) {
 +bdrv_lock_medium(bs, s-tray_locked);
 +bdrv_eject(bs, s-tray_open);
 +}
  return 0;
  }
  
 diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
 index 3b7b306..bc2f426 100644
 --- a/hw/ide/qdev.c
 +++ b/hw/ide/qdev.c
 @@ -182,6 +182,12 @@ static int ide_cd_initfn(IDEDevice *dev)
  return ide_dev_initfn(dev, IDE_CD);
  }
  
 +static int ide_cd_exitfn(IDEDevice *dev)
 +{
 +bdrv_lock_medium(dev-conf.bs, 0);
 +return 0;
 +}
 +
  static int ide_drive_initfn(IDEDevice *dev)
  {
  DriveInfo *dinfo = drive_get_by_blockdev(dev-conf.bs);
 @@ -189,6 +195,16 @@ static int ide_drive_initfn(IDEDevice *dev)
  return ide_dev_initfn(dev, dinfo-media_cd ? IDE_CD : IDE_HD);
  }
  
 +static int ide_drive_exitfn(IDEDevice *dev)
 +{
 +DriveInfo *dinfo = drive_get_by_blockdev(dev-conf.bs);
 +
 +if (dinfo-media_cd) {
 +return ide_cd_exitfn(dev);
 +}

 Is dinfo-media_cd guaranteed to be the same as s-drive_kind? I
 wouldn't have expected this to be true at least since the introduction
 of ide-hd/cd.

I'm afraid you're right.  Now I need to find a way from IDEDevice to
IDEState.  These IDE data structures are sick...



[Qemu-devel] [PATCH] server: don't call reds_stream_free from worker thread context

2011-09-02 Thread Gerd Hoffmann
reds_stream_free() may call the channel_event callback which is not
supposed to be callsed from worker thread context.  This patch moves
the reds_stream_free call for the display channel from the worker to
the dispatcher to fix this issue.

[ Note: not tested yet, against 0.8 branch, sending out for review 
comments nevertheless ]

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 server/red_dispatcher.c |5 +
 server/red_worker.c |3 +--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/server/red_dispatcher.c b/server/red_dispatcher.c
index f74b13e..801a575 100644
--- a/server/red_dispatcher.c
+++ b/server/red_dispatcher.c
@@ -51,6 +51,7 @@ struct RedDispatcher {
 int y_res;
 int use_hardware_cursor;
 RedDispatcher *next;
+RedsStream *stream;
 RedWorkerMessage async_message;
 pthread_mutex_t  async_lock;
 QXLDevSurfaceCreate surface_create;
@@ -81,6 +82,7 @@ static void red_dispatcher_set_peer(Channel *channel, 
RedsStream *stream, int mi
 
 red_printf();
 dispatcher = (RedDispatcher *)channel-data;
+dispatcher-stream = stream;
 RedWorkerMessage message = RED_WORKER_MESSAGE_DISPLAY_CONNECT;
 write_message(dispatcher-channel, message);
 send_data(dispatcher-channel, stream, sizeof(RedsStream *));
@@ -93,6 +95,9 @@ static void red_dispatcher_shutdown_peer(Channel *channel)
 red_printf();
 RedWorkerMessage message = RED_WORKER_MESSAGE_DISPLAY_DISCONNECT;
 write_message(dispatcher-channel, message);
+read_message(dispatcher-channel, message);
+ASSERT(message == RED_WORKER_MESSAGE_READY);
+reds_stream_free(dispatcher-stream);
 }
 
 static void red_dispatcher_migrate(Channel *channel)
diff --git a/server/red_worker.c b/server/red_worker.c
index 5f07803..f77b0f2 100644
--- a/server/red_worker.c
+++ b/server/red_worker.c
@@ -8486,8 +8486,6 @@ static void red_disconnect_channel(RedChannel *channel)
 {
 channel_release_res(channel);
 red_pipe_clear(channel);
-reds_stream_free(channel-stream);
-channel-stream = NULL;
 channel-send_data.blocked = FALSE;
 channel-send_data.size = channel-send_data.pos = 0;
 spice_marshaller_reset(channel-send_data.marshaller);
@@ -10060,6 +10058,7 @@ static void handle_dev_input(EventListener *listener, 
uint32_t events)
 case RED_WORKER_MESSAGE_CURSOR_DISCONNECT:
 red_printf(cursor disconnect);
 red_disconnect_cursor((RedChannel *)worker-cursor_channel);
+write_ready = 1;
 break;
 case RED_WORKER_MESSAGE_CURSOR_MIGRATE:
 red_printf(cursor migrate);
-- 
1.7.1




Re: [Qemu-devel] [PATCH] monitor: Protect outbuf from concurrent access

2011-09-02 Thread Anthony Liguori

On 09/02/2011 10:18 AM, Gerd Hoffmann wrote:

Hi,


A patch like the attached (warning: untested) should do as quickdirty
fix for stable. But IMO we really should fix spice instead.


I agree. I'm not sure I like the idea of still calling QEMU code without
holding the mutex (even the QObject code).


I though just creating the objects isn't an issue, but if you disagree
we can just move up the lock to the head of the function.


What I fear is that Spice will assume something is thread safe, but then 
someone will make a change that makes the subsystem non-reentrant.


I'd rather that we have very clear rules about what's thread safe and 
not thread safe.  If you want to audit the QObject subsystem, declare it 
thread safe, and document it as such, that would be okay.  But it needs 
to be systematic, not ad-hoc.


Regards,

Anthony Liguori




Can you just use a bottom half to defer this work to the I/O thread?
Bottom half scheduling has to be signal safe which means it will also be
thread safe.


Not that straight forward as I would have to pass arguments to the
bottom half.

cheers,
Gerd







Re: [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration

2011-09-02 Thread Markus Armbruster
Kevin Wolf kw...@redhat.com writes:

 Am 03.08.2011 15:08, schrieb Markus Armbruster:
 Use a subsection, so that migration to older version still works,
 provided the tray is closed and unlocked.
 
 Signed-off-by: Markus Armbruster arm...@redhat.com

 Ah, here is the migration part. The state wasn't migrated before, so not
 doing it in patch 10 doesn't break anything. I would still prefer to add
 migration in the same patch that adds the fields.

 You could just move the subsection itself and keep the post_load part
 here if it doesn't fit naturally in one of the other patches of the series.

I don't get this part, I'm afraid.

 On another note, have our subsections been fixed meanwhile? If not,
 increasing the version number instead might be the right choice. Paolo?

 Kevin



  1   2   >