[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 27/28] hw/scsi: Fix sector translation bug in scsi_unmap_complete_
From: |
Paolo Bonzini |
Subject: |
[PULL 27/28] hw/scsi: Fix sector translation bug in scsi_unmap_complete_noio |
Date: |
Mon, 24 May 2021 18:41:30 +0200 |
From: Kit Westneat <kit.westneat@gmail.com>
check_lba_range expects sectors to be expressed in original qdev blocksize, but
scsi_unmap_complete_noio was translating them to 512 block sizes, which was
causing sense errors in the larger LBAs in devices using a 4k block size.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/345
Signed-off-by: Kit Westneat <kit.westneat@gmail.com>
Message-Id: <20210521142829.326217-1-kit.westneat@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi/scsi-disk.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 3580e7ee61..e8a547dbb7 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -1582,6 +1582,7 @@ invalid_field:
scsi_check_condition(r, SENSE_CODE(INVALID_FIELD));
}
+/* sector_num and nb_sectors expected to be in qdev blocksize */
static inline bool check_lba_range(SCSIDiskState *s,
uint64_t sector_num, uint32_t nb_sectors)
{
@@ -1614,11 +1615,12 @@ static void scsi_unmap_complete_noio(UnmapCBData *data,
int ret)
assert(r->req.aiocb == NULL);
if (data->count > 0) {
- r->sector = ldq_be_p(&data->inbuf[0])
- * (s->qdev.blocksize / BDRV_SECTOR_SIZE);
- r->sector_count = (ldl_be_p(&data->inbuf[8]) & 0xffffffffULL)
- * (s->qdev.blocksize / BDRV_SECTOR_SIZE);
- if (!check_lba_range(s, r->sector, r->sector_count)) {
+ uint64_t sector_num = ldq_be_p(&data->inbuf[0]);
+ uint32_t nb_sectors = ldl_be_p(&data->inbuf[8]) & 0xffffffffULL;
+ r->sector = sector_num * (s->qdev.blocksize / BDRV_SECTOR_SIZE);
+ r->sector_count = nb_sectors * (s->qdev.blocksize / BDRV_SECTOR_SIZE);
+
+ if (!check_lba_range(s, sector_num, nb_sectors)) {
block_acct_invalid(blk_get_stats(s->qdev.conf.blk),
BLOCK_ACCT_UNMAP);
scsi_check_condition(r, SENSE_CODE(LBA_OUT_OF_RANGE));
--
2.31.1
- [PULL 13/28] KVM: Provide helper to sync dirty bitmap from slot to ramblock, (continued)
- [PULL 13/28] KVM: Provide helper to sync dirty bitmap from slot to ramblock, Paolo Bonzini, 2021/05/24
- [PULL 02/28] configure: check for submodules if --with-git-submodules=ignore, Paolo Bonzini, 2021/05/24
- [PULL 09/28] memory: Introduce log_sync_global() to memory listener, Paolo Bonzini, 2021/05/24
- [PULL 01/28] configure: Only clone softfloat-3 repositories if TCG is enabled, Paolo Bonzini, 2021/05/24
- [PULL 22/28] replication: move include out of root directory, Paolo Bonzini, 2021/05/24
- [PULL 19/28] tests/qtest/fuzz: Fix build failure, Paolo Bonzini, 2021/05/24
- [PULL 18/28] KVM: Dirty ring support, Paolo Bonzini, 2021/05/24
- [PULL 20/28] meson: Set implicit_include_directories to false, Paolo Bonzini, 2021/05/24
- [PULL 25/28] doc: Add notes about -mon option mode=control argument., Paolo Bonzini, 2021/05/24
- [PULL 07/28] qtest: add a QOM object for qtest, Paolo Bonzini, 2021/05/24
- [PULL 27/28] hw/scsi: Fix sector translation bug in scsi_unmap_complete_noio,
Paolo Bonzini <=
- [PULL 26/28] configure: Avoid error messages about missing *-config-*.h files, Paolo Bonzini, 2021/05/24
- [PULL 28/28] gitlab-ci: use --meson=git for CFI jobs, Paolo Bonzini, 2021/05/24
- [PULL 17/28] KVM: Disable manual dirty log when dirty ring enabled, Paolo Bonzini, 2021/05/24
- [PULL 05/28] i386/cpu: Expose AVX_VNNI instruction to guest, Paolo Bonzini, 2021/05/24
- [PULL 14/28] KVM: Simplify dirty log sync in kvm_set_phys_mem, Paolo Bonzini, 2021/05/24
- [PULL 15/28] KVM: Cache kvm slot dirty bitmap size, Paolo Bonzini, 2021/05/24
- [PULL 24/28] qemu-config: load modules when instantiating option groups, Paolo Bonzini, 2021/05/24
- [PULL 16/28] KVM: Add dirty-ring-size property, Paolo Bonzini, 2021/05/24
- [PULL 23/28] vl: allow not specifying size in -m when using -M memory-backend, Paolo Bonzini, 2021/05/24
- [PULL 12/28] KVM: Provide helper to get kvm dirty log, Paolo Bonzini, 2021/05/24