qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Kit Westneat <kit.westneat@gmail.com>, qemu-devel@nongnu.org
Subject: Re: [PATCH] hw/scsi: Fix sector translation bug in scsi_unmap_complete_noio
Date: Fri, 21 May 2021 17:20:23 +0200	[thread overview]
Message-ID: <56fc3bb8-d6fd-c038-2bcf-8288a5bbacab@redhat.com> (raw)
In-Reply-To: <20210521142829.326217-1-kit.westneat@gmail.com>

On 21/05/21 16:28, Kit Westneat wrote:
> 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>
> ---
>   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));
> 

Queued, thanks!

If you want to produce a testcase for tests/qtest/virtio-scsi-test.c, I 
won't complain.

Paolo



  reply	other threads:[~2021-05-21 15:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-21 14:28 [PATCH] hw/scsi: Fix sector translation bug in scsi_unmap_complete_noio Kit Westneat
2021-05-21 15:20 ` Paolo Bonzini [this message]
2021-05-24 18:30   ` Kit Westneat

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=56fc3bb8-d6fd-c038-2bcf-8288a5bbacab@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kit.westneat@gmail.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).