[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 21/31] scsi-disk: Fix crash if request is invaild
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL v2 21/31] scsi-disk: Fix crash if request is invaild or disk is no medium |
Date: |
Mon, 11 Mar 2019 17:55:25 +0100 |
From: Zhengui Li <address@hidden>
Qemu will crash with the assertion error that "assert(r->req.aiocb !=
NULL)" in scsi_read_complete if request is invaild or disk is no medium.
The error is below:
qemu-kvm: hw/scsi/scsi_disk.c:299: scsi_read_complete: Assertion
`r->req.aiocb != NULL' failed.
This patch add a funtion scsi_read_complete_noio to fix it.
Signed-off-by: Zhengui Li <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/scsi/scsi-disk.c | 37 ++++++++++++++++++++++++-------------
1 file changed, 24 insertions(+), 13 deletions(-)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index d4e83ae..e7e865a 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -296,22 +296,15 @@ static void scsi_dma_complete(void *opaque, int ret)
aio_context_release(blk_get_aio_context(s->qdev.conf.blk));
}
-static void scsi_read_complete(void * opaque, int ret)
+static void scsi_read_complete_noio(SCSIDiskReq *r, int ret)
{
- SCSIDiskReq *r = (SCSIDiskReq *)opaque;
- SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
- int n;
+ uint32_t n;
- assert(r->req.aiocb != NULL);
- r->req.aiocb = NULL;
- aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk));
- if (scsi_disk_req_check_error(r, ret, true)) {
+ assert(r->req.aiocb == NULL);
+ if (scsi_disk_req_check_error(r, ret, false)) {
goto done;
}
- block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct);
- trace_scsi_disk_read_complete(r->req.tag, r->qiov.size);
-
n = r->qiov.size / 512;
r->sector += n;
r->sector_count -= n;
@@ -319,6 +312,24 @@ static void scsi_read_complete(void * opaque, int ret)
done:
scsi_req_unref(&r->req);
+}
+
+static void scsi_read_complete(void *opaque, int ret)
+{
+ SCSIDiskReq *r = (SCSIDiskReq *)opaque;
+ SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
+
+ assert(r->req.aiocb != NULL);
+ r->req.aiocb = NULL;
+
+ aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk));
+ if (ret < 0) {
+ block_acct_failed(blk_get_stats(s->qdev.conf.blk), &r->acct);
+ } else {
+ block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct);
+ trace_scsi_disk_read_complete(r->req.tag, r->qiov.size);
+ }
+ scsi_read_complete_noio(r, ret);
aio_context_release(blk_get_aio_context(s->qdev.conf.blk));
}
@@ -395,12 +406,12 @@ static void scsi_read_data(SCSIRequest *req)
scsi_req_ref(&r->req);
if (r->req.cmd.mode == SCSI_XFER_TO_DEV) {
trace_scsi_disk_read_data_invalid();
- scsi_read_complete(r, -EINVAL);
+ scsi_read_complete_noio(r, -EINVAL);
return;
}
if (!blk_is_available(req->dev->conf.blk)) {
- scsi_read_complete(r, -ENOMEDIUM);
+ scsi_read_complete_noio(r, -ENOMEDIUM);
return;
}
--
1.8.3.1
- [Qemu-devel] [PULL v2 11/31] virtio-scsi: Fix build with gcc 9, (continued)
- [Qemu-devel] [PULL v2 11/31] virtio-scsi: Fix build with gcc 9, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 15/31] build: get rid of target-obj-y, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 12/31] lsi: implement basic SBCL functionality, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 09/31] target-i386: add kvm stubs to user-mode emulators, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 13/31] lsi: check if SIGP bit is already set in Wait reselect, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 14/31] update copyright notice, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 16/31] build: remove unnecessary assignments from Makefile.target, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 17/31] build: clean trace/generated-helpers.c, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 19/31] oslib-posix: Ignore fcntl("/dev/null", F_SETFL, O_NONBLOCK) failure, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 18/31] accel: Allow to build QEMU without TCG or KVM support, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 21/31] scsi-disk: Fix crash if request is invaild or disk is no medium,
Paolo Bonzini <=
- [Qemu-devel] [PULL v2 22/31] lsi: use ldn_le_p()/stn_le_p(), Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 25/31] lsi: use SCSI phase names instead of numbers in trace, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 20/31] configure: Disable W^X on OpenBSD, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 23/31] lsi: use enum type for s->waiting, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 24/31] lsi: use enum type for s->msg_action, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 26/31] lsi: return dfifo value, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 28/31] exec.c: refactor function flatview_add_to_dispatch(), Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 31/31] qemugdb: fix licensing, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 27/31] lsi: 810/895A are always little endian, Paolo Bonzini, 2019/03/11
- [Qemu-devel] [PULL v2 30/31] chardev: add support for authorization for TLS clients, Paolo Bonzini, 2019/03/11