From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>,
qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PULL 1/1] nvme: Limit blkshift to 12 (for 4 kB blocks)
Date: Tue, 30 Jul 2019 14:59:10 +0200 [thread overview]
Message-ID: <20190730125910.32060-2-mreitz@redhat.com> (raw)
In-Reply-To: <20190730125910.32060-1-mreitz@redhat.com>
Linux does not support blocks greater than 4 kB anyway, so we might as
well limit blkshift to 12 and thus save us from some potential trouble.
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Suggested-by: Maxim Levitsky <mlevitsk@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20190730114812.10493-1-mreitz@redhat.com
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Coverity: CID 1403771
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/nvme.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index c28755cc31..2c85713519 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -105,7 +105,7 @@ typedef struct {
uint64_t nsze; /* Namespace size reported by identify command */
int nsid; /* The namespace id to read/write data. */
- size_t blkshift;
+ int blkshift;
uint64_t max_transfer;
bool plugged;
@@ -420,7 +420,7 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp)
NvmeIdNs *idns;
NvmeLBAF *lbaf;
uint8_t *resp;
- int r, hwsect_size;
+ int r;
uint64_t iova;
NvmeCmd cmd = {
.opcode = NVME_ADM_CMD_IDENTIFY,
@@ -474,11 +474,11 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp)
goto out;
}
- hwsect_size = 1 << lbaf->ds;
-
- if (hwsect_size < BDRV_SECTOR_SIZE || hwsect_size > s->page_size) {
- error_setg(errp, "Namespace has unsupported block size (%d)",
- hwsect_size);
+ if (lbaf->ds < BDRV_SECTOR_BITS || lbaf->ds > 12 ||
+ (1 << lbaf->ds) > s->page_size)
+ {
+ error_setg(errp, "Namespace has unsupported block size (2^%d)",
+ lbaf->ds);
goto out;
}
@@ -804,16 +804,16 @@ static int64_t nvme_getlength(BlockDriverState *bs)
return s->nsze << s->blkshift;
}
-static int64_t nvme_get_blocksize(BlockDriverState *bs)
+static uint32_t nvme_get_blocksize(BlockDriverState *bs)
{
BDRVNVMeState *s = bs->opaque;
- assert(s->blkshift >= BDRV_SECTOR_BITS);
- return 1 << s->blkshift;
+ assert(s->blkshift >= BDRV_SECTOR_BITS && s->blkshift <= 12);
+ return UINT32_C(1) << s->blkshift;
}
static int nvme_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz)
{
- int64_t blocksize = nvme_get_blocksize(bs);
+ uint32_t blocksize = nvme_get_blocksize(bs);
bsz->phys = blocksize;
bsz->log = blocksize;
return 0;
--
2.21.0
next prev parent reply other threads:[~2019-07-30 13:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-30 12:59 [Qemu-devel] [PULL 0/1] Block patches for 4.1.0-rc3 Max Reitz
2019-07-30 12:59 ` Max Reitz [this message]
2019-07-30 16:00 ` Peter Maydell
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=20190730125910.32060-2-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--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).