From: Aurelien Jarno <aurelien@aurel32.net>
To: Jan Kiszka <jan.kiszka@siemens.com>
Cc: qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] scsi: Dequeue requests before invoking completion callback
Date: Thu, 22 Jul 2010 14:16:16 +0200 [thread overview]
Message-ID: <20100722121616.GF2040@ohm.aurel32.net> (raw)
In-Reply-To: <4C3C5879.4070609@siemens.com>
On Tue, Jul 13, 2010 at 02:13:45PM +0200, Jan Kiszka wrote:
> The request completion callback of the LSI controller may start the next
> request that can use the same tag as the completed one. As the latter is
> still enqueued at that point, scsi_send_command will complain about the
> tag reuse and cancel the completed request. That will cause a double
> free later on when the completion path cleans up as well.
>
> Fix this by dequeuing the request before invoking the callback.
>
> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
> ---
>
> This should fix bug 595438.
>
> hw/scsi-bus.c | 12 +++++++++++-
> hw/scsi.h | 1 +
> 2 files changed, 12 insertions(+), 1 deletions(-)
Thanks, applied.
> diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
> index d69c74c..b860a09 100644
> --- a/hw/scsi-bus.c
> +++ b/hw/scsi-bus.c
> @@ -142,6 +142,7 @@ SCSIRequest *scsi_req_alloc(size_t size, SCSIDevice *d, uint32_t tag, uint32_t l
> req->tag = tag;
> req->lun = lun;
> req->status = -1;
> + req->enqueued = true;
> QTAILQ_INSERT_TAIL(&d->requests, req, next);
> return req;
> }
> @@ -158,9 +159,17 @@ SCSIRequest *scsi_req_find(SCSIDevice *d, uint32_t tag)
> return NULL;
> }
>
> +static void scsi_req_dequeue(SCSIRequest *req)
> +{
> + if (req->enqueued) {
> + QTAILQ_REMOVE(&req->dev->requests, req, next);
> + req->enqueued = false;
> + }
> +}
> +
> void scsi_req_free(SCSIRequest *req)
> {
> - QTAILQ_REMOVE(&req->dev->requests, req, next);
> + scsi_req_dequeue(req);
> qemu_free(req);
> }
>
> @@ -512,6 +521,7 @@ void scsi_req_print(SCSIRequest *req)
> void scsi_req_complete(SCSIRequest *req)
> {
> assert(req->status != -1);
> + scsi_req_dequeue(req);
> req->bus->complete(req->bus, SCSI_REASON_DONE,
> req->tag,
> req->status);
> diff --git a/hw/scsi.h b/hw/scsi.h
> index 4fbf1d5..cb06d6d 100644
> --- a/hw/scsi.h
> +++ b/hw/scsi.h
> @@ -43,6 +43,7 @@ typedef struct SCSIRequest {
> enum SCSIXferMode mode;
> } cmd;
> BlockDriverAIOCB *aiocb;
> + bool enqueued;
> QTAILQ_ENTRY(SCSIRequest) next;
> } SCSIRequest;
>
> --
> 1.7.1
>
>
--
Aurelien Jarno GPG: 1024D/F1BCDB73
aurelien@aurel32.net http://www.aurel32.net
prev parent reply other threads:[~2010-07-22 12:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-13 12:13 [Qemu-devel] [PATCH] scsi: Dequeue requests before invoking completion callback Jan Kiszka
2010-07-22 12:16 ` Aurelien Jarno [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100722121616.GF2040@ohm.aurel32.net \
--to=aurelien@aurel32.net \
--cc=jan.kiszka@siemens.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).