qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH repost] ahci: fix win7 hang on boot
@ 2013-10-28 19:01 Michael S. Tsirkin
  2013-10-29 11:52 ` Kevin Wolf
  2013-10-31 11:32 ` Paolo Bonzini
  0 siblings, 2 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2013-10-28 19:01 UTC (permalink / raw)
  To: qemu-devel
  Cc: Kevin Wolf, Paolo Bonzini, Andreas Färber, Anthony Liguori,
	agraf

From: Alexander Graf <agraf@suse.de>

When AHCI executes an asynchronous IDE command, it checked DRDY without
checking either DRQ or BSY.  This sometimes caused interrupt to be sent
before command is actually completed.

This resulted in a race condition: if guest then managed to access the
device before command has completed, it would hang waiting for an
interrupt.
This was observed with windows 7 guests.

To fix, check for DRQ or BSY in additiona to DRDY, if set,
the command is asynchronous so delay the interrupt until
asynchronous done callback is invoked.

Reported-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

---
 hw/ide/ahci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index a8be62c..fbea9e8 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -961,7 +961,8 @@ static int handle_cmd(AHCIState *s, int port, int slot)
         /* We're ready to process the command in FIS byte 2. */
         ide_exec_cmd(&s->dev[port].port, cmd_fis[2]);
 
-        if (s->dev[port].port.ifs[0].status & READY_STAT) {
+        if ((s->dev[port].port.ifs[0].status & (READY_STAT|DRQ_STAT|BUSY_STAT)) ==
+            READY_STAT) {
             ahci_write_fis_d2h(&s->dev[port], cmd_fis);
         }
     }
-- 
MST

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH repost] ahci: fix win7 hang on boot
  2013-10-28 19:01 [Qemu-devel] [PATCH repost] ahci: fix win7 hang on boot Michael S. Tsirkin
@ 2013-10-29 11:52 ` Kevin Wolf
  2013-10-31 11:32 ` Paolo Bonzini
  1 sibling, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2013-10-29 11:52 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Paolo Bonzini, agraf, qemu-devel, Anthony Liguori,
	Andreas Färber

Am 28.10.2013 um 20:01 hat Michael S. Tsirkin geschrieben:
> From: Alexander Graf <agraf@suse.de>
> 
> When AHCI executes an asynchronous IDE command, it checked DRDY without
> checking either DRQ or BSY.  This sometimes caused interrupt to be sent
> before command is actually completed.
> 
> This resulted in a race condition: if guest then managed to access the
> device before command has completed, it would hang waiting for an
> interrupt.
> This was observed with windows 7 guests.
> 
> To fix, check for DRQ or BSY in additiona to DRDY, if set,
> the command is asynchronous so delay the interrupt until
> asynchronous done callback is invoked.
> 
> Reported-by: Michael S. Tsirkin <mst@redhat.com>
> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> Tested-by: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

Thanks, applied to the block branch.

Kevin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH repost] ahci: fix win7 hang on boot
  2013-10-28 19:01 [Qemu-devel] [PATCH repost] ahci: fix win7 hang on boot Michael S. Tsirkin
  2013-10-29 11:52 ` Kevin Wolf
@ 2013-10-31 11:32 ` Paolo Bonzini
  2013-10-31 11:37   ` Michael S. Tsirkin
  1 sibling, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2013-10-31 11:32 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Kevin Wolf, agraf, qemu-devel, Anthony Liguori,
	Andreas Färber

Il 28/10/2013 20:01, Michael S. Tsirkin ha scritto:
> From: Alexander Graf <agraf@suse.de>
> 
> When AHCI executes an asynchronous IDE command, it checked DRDY without
> checking either DRQ or BSY.  This sometimes caused interrupt to be sent
> before command is actually completed.
> 
> This resulted in a race condition: if guest then managed to access the
> device before command has completed, it would hang waiting for an
> interrupt.
> This was observed with windows 7 guests.
> 
> To fix, check for DRQ or BSY in additiona to DRDY, if set,
> the command is asynchronous so delay the interrupt until
> asynchronous done callback is invoked.
> 
> Reported-by: Michael S. Tsirkin <mst@redhat.com>
> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> Tested-by: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> 
> ---
>  hw/ide/ahci.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
> index a8be62c..fbea9e8 100644
> --- a/hw/ide/ahci.c
> +++ b/hw/ide/ahci.c
> @@ -961,7 +961,8 @@ static int handle_cmd(AHCIState *s, int port, int slot)
>          /* We're ready to process the command in FIS byte 2. */
>          ide_exec_cmd(&s->dev[port].port, cmd_fis[2]);
>  
> -        if (s->dev[port].port.ifs[0].status & READY_STAT) {
> +        if ((s->dev[port].port.ifs[0].status & (READY_STAT|DRQ_STAT|BUSY_STAT)) ==
> +            READY_STAT) {
>              ahci_write_fis_d2h(&s->dev[port], cmd_fis);
>          }
>      }
> 

While the patch fixes the symptom, I think it is only a bandaid.

There is no reason why the async_cmd_done should be restricted to
asynchronous commands.  If synchronous commands are made to go through
the async_cmd_done callback, you'll automatically get the D2H FIS
written for all commands.

It's good for 1.7, but let's revisit it for 1.8.

Paolo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH repost] ahci: fix win7 hang on boot
  2013-10-31 11:32 ` Paolo Bonzini
@ 2013-10-31 11:37   ` Michael S. Tsirkin
  0 siblings, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2013-10-31 11:37 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Kevin Wolf, agraf, qemu-devel, Anthony Liguori,
	Andreas Färber

On Thu, Oct 31, 2013 at 12:32:12PM +0100, Paolo Bonzini wrote:
> Il 28/10/2013 20:01, Michael S. Tsirkin ha scritto:
> > From: Alexander Graf <agraf@suse.de>
> > 
> > When AHCI executes an asynchronous IDE command, it checked DRDY without
> > checking either DRQ or BSY.  This sometimes caused interrupt to be sent
> > before command is actually completed.
> > 
> > This resulted in a race condition: if guest then managed to access the
> > device before command has completed, it would hang waiting for an
> > interrupt.
> > This was observed with windows 7 guests.
> > 
> > To fix, check for DRQ or BSY in additiona to DRDY, if set,
> > the command is asynchronous so delay the interrupt until
> > asynchronous done callback is invoked.
> > 
> > Reported-by: Michael S. Tsirkin <mst@redhat.com>
> > Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
> > Tested-by: Michael S. Tsirkin <mst@redhat.com>
> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > 
> > ---
> >  hw/ide/ahci.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
> > index a8be62c..fbea9e8 100644
> > --- a/hw/ide/ahci.c
> > +++ b/hw/ide/ahci.c
> > @@ -961,7 +961,8 @@ static int handle_cmd(AHCIState *s, int port, int slot)
> >          /* We're ready to process the command in FIS byte 2. */
> >          ide_exec_cmd(&s->dev[port].port, cmd_fis[2]);
> >  
> > -        if (s->dev[port].port.ifs[0].status & READY_STAT) {
> > +        if ((s->dev[port].port.ifs[0].status & (READY_STAT|DRQ_STAT|BUSY_STAT)) ==
> > +            READY_STAT) {
> >              ahci_write_fis_d2h(&s->dev[port], cmd_fis);
> >          }
> >      }
> > 
> 
> While the patch fixes the symptom, I think it is only a bandaid.
> 
> There is no reason why the async_cmd_done should be restricted to
> asynchronous commands.  If synchronous commands are made to go through
> the async_cmd_done callback, you'll automatically get the D2H FIS
> written for all commands.

I suggested this to Kevin offline but he prefers it like this.

> It's good for 1.7, but let's revisit it for 1.8.
> 
> Paolo

Fine with me.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-10-31 11:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-28 19:01 [Qemu-devel] [PATCH repost] ahci: fix win7 hang on boot Michael S. Tsirkin
2013-10-29 11:52 ` Kevin Wolf
2013-10-31 11:32 ` Paolo Bonzini
2013-10-31 11:37   ` Michael S. Tsirkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).