nvme: Limit blkshift to 12 (for 4 kB blocks)
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>
This commit is contained in:
parent
6e9a6cbe7d
commit
1120407bdf
22
block/nvme.c
22
block/nvme.c
@ -105,7 +105,7 @@ typedef struct {
|
|||||||
|
|
||||||
uint64_t nsze; /* Namespace size reported by identify command */
|
uint64_t nsze; /* Namespace size reported by identify command */
|
||||||
int nsid; /* The namespace id to read/write data. */
|
int nsid; /* The namespace id to read/write data. */
|
||||||
size_t blkshift;
|
int blkshift;
|
||||||
|
|
||||||
uint64_t max_transfer;
|
uint64_t max_transfer;
|
||||||
bool plugged;
|
bool plugged;
|
||||||
@ -420,7 +420,7 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp)
|
|||||||
NvmeIdNs *idns;
|
NvmeIdNs *idns;
|
||||||
NvmeLBAF *lbaf;
|
NvmeLBAF *lbaf;
|
||||||
uint8_t *resp;
|
uint8_t *resp;
|
||||||
int r, hwsect_size;
|
int r;
|
||||||
uint64_t iova;
|
uint64_t iova;
|
||||||
NvmeCmd cmd = {
|
NvmeCmd cmd = {
|
||||||
.opcode = NVME_ADM_CMD_IDENTIFY,
|
.opcode = NVME_ADM_CMD_IDENTIFY,
|
||||||
@ -474,11 +474,11 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
hwsect_size = 1 << lbaf->ds;
|
if (lbaf->ds < BDRV_SECTOR_BITS || lbaf->ds > 12 ||
|
||||||
|
(1 << lbaf->ds) > s->page_size)
|
||||||
if (hwsect_size < BDRV_SECTOR_SIZE || hwsect_size > s->page_size) {
|
{
|
||||||
error_setg(errp, "Namespace has unsupported block size (%d)",
|
error_setg(errp, "Namespace has unsupported block size (2^%d)",
|
||||||
hwsect_size);
|
lbaf->ds);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -804,16 +804,16 @@ static int64_t nvme_getlength(BlockDriverState *bs)
|
|||||||
return s->nsze << s->blkshift;
|
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;
|
BDRVNVMeState *s = bs->opaque;
|
||||||
assert(s->blkshift >= BDRV_SECTOR_BITS);
|
assert(s->blkshift >= BDRV_SECTOR_BITS && s->blkshift <= 12);
|
||||||
return 1 << s->blkshift;
|
return UINT32_C(1) << s->blkshift;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nvme_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz)
|
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->phys = blocksize;
|
||||||
bsz->log = blocksize;
|
bsz->log = blocksize;
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user