qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/nvme: fix narrowing conversion
@ 2022-04-12  8:59 Dmitry Tikhov
  2022-04-12 20:36 ` Klaus Jensen
  2022-04-18  6:13 ` Klaus Jensen
  0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Tikhov @ 2022-04-12  8:59 UTC (permalink / raw)
  To: qemu-devel; +Cc: kbusch, its, qemu-block

Since nlbas is of type int, it does not work with large namespace size
values, e.g., 9 TB size of file backing namespace and 8 byte metadata
with 4096 bytes lbasz gives negative nlbas value, which is later
promoted to negative int64_t type value and results in negative
ns->moff which breaks namespace

Signed-off-by: Dmitry Tikhov <ddtikhov@gmail.com>
---
 hw/nvme/ns.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c
index 324f53ea0c..af6504fad2 100644
--- a/hw/nvme/ns.c
+++ b/hw/nvme/ns.c
@@ -29,7 +29,8 @@ void nvme_ns_init_format(NvmeNamespace *ns)
 {
     NvmeIdNs *id_ns = &ns->id_ns;
     BlockDriverInfo bdi;
-    int npdg, nlbas, ret;
+    int npdg, ret;
+    int64_t nlbas;
 
     ns->lbaf = id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(id_ns->flbas)];
     ns->lbasz = 1 << ns->lbaf.ds;
@@ -42,7 +43,7 @@ void nvme_ns_init_format(NvmeNamespace *ns)
     id_ns->ncap = id_ns->nsze;
     id_ns->nuse = id_ns->ncap;
 
-    ns->moff = (int64_t)nlbas << ns->lbaf.ds;
+    ns->moff = nlbas << ns->lbaf.ds;
 
     npdg = ns->blkconf.discard_granularity / ns->lbasz;
 
-- 
2.35.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] hw/nvme: fix narrowing conversion
  2022-04-12  8:59 [PATCH] hw/nvme: fix narrowing conversion Dmitry Tikhov
@ 2022-04-12 20:36 ` Klaus Jensen
  2022-04-18  6:13 ` Klaus Jensen
  1 sibling, 0 replies; 3+ messages in thread
From: Klaus Jensen @ 2022-04-12 20:36 UTC (permalink / raw)
  To: Dmitry Tikhov; +Cc: kbusch, qemu-devel, qemu-block

[-- Attachment #1: Type: text/plain, Size: 1367 bytes --]

On Apr 12 11:59, Dmitry Tikhov wrote:
> Since nlbas is of type int, it does not work with large namespace size
> values, e.g., 9 TB size of file backing namespace and 8 byte metadata
> with 4096 bytes lbasz gives negative nlbas value, which is later
> promoted to negative int64_t type value and results in negative
> ns->moff which breaks namespace
> 
> Signed-off-by: Dmitry Tikhov <ddtikhov@gmail.com>
> ---
>  hw/nvme/ns.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c
> index 324f53ea0c..af6504fad2 100644
> --- a/hw/nvme/ns.c
> +++ b/hw/nvme/ns.c
> @@ -29,7 +29,8 @@ void nvme_ns_init_format(NvmeNamespace *ns)
>  {
>      NvmeIdNs *id_ns = &ns->id_ns;
>      BlockDriverInfo bdi;
> -    int npdg, nlbas, ret;
> +    int npdg, ret;
> +    int64_t nlbas;
>  
>      ns->lbaf = id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(id_ns->flbas)];
>      ns->lbasz = 1 << ns->lbaf.ds;
> @@ -42,7 +43,7 @@ void nvme_ns_init_format(NvmeNamespace *ns)
>      id_ns->ncap = id_ns->nsze;
>      id_ns->nuse = id_ns->ncap;
>  
> -    ns->moff = (int64_t)nlbas << ns->lbaf.ds;
> +    ns->moff = nlbas << ns->lbaf.ds;
>  
>      npdg = ns->blkconf.discard_granularity / ns->lbasz;
>  
> -- 
> 2.35.1
> 

Thanks Dmitry. Looks reasonable,

Reviewed-by: Klaus Jensen <k.jensen@samsung.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] hw/nvme: fix narrowing conversion
  2022-04-12  8:59 [PATCH] hw/nvme: fix narrowing conversion Dmitry Tikhov
  2022-04-12 20:36 ` Klaus Jensen
@ 2022-04-18  6:13 ` Klaus Jensen
  1 sibling, 0 replies; 3+ messages in thread
From: Klaus Jensen @ 2022-04-18  6:13 UTC (permalink / raw)
  To: Dmitry Tikhov; +Cc: kbusch, qemu-devel, qemu-block

[-- Attachment #1: Type: text/plain, Size: 1315 bytes --]

On Apr 12 11:59, Dmitry Tikhov wrote:
> Since nlbas is of type int, it does not work with large namespace size
> values, e.g., 9 TB size of file backing namespace and 8 byte metadata
> with 4096 bytes lbasz gives negative nlbas value, which is later
> promoted to negative int64_t type value and results in negative
> ns->moff which breaks namespace
> 
> Signed-off-by: Dmitry Tikhov <ddtikhov@gmail.com>
> ---
>  hw/nvme/ns.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/nvme/ns.c b/hw/nvme/ns.c
> index 324f53ea0c..af6504fad2 100644
> --- a/hw/nvme/ns.c
> +++ b/hw/nvme/ns.c
> @@ -29,7 +29,8 @@ void nvme_ns_init_format(NvmeNamespace *ns)
>  {
>      NvmeIdNs *id_ns = &ns->id_ns;
>      BlockDriverInfo bdi;
> -    int npdg, nlbas, ret;
> +    int npdg, ret;
> +    int64_t nlbas;
>  
>      ns->lbaf = id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(id_ns->flbas)];
>      ns->lbasz = 1 << ns->lbaf.ds;
> @@ -42,7 +43,7 @@ void nvme_ns_init_format(NvmeNamespace *ns)
>      id_ns->ncap = id_ns->nsze;
>      id_ns->nuse = id_ns->ncap;
>  
> -    ns->moff = (int64_t)nlbas << ns->lbaf.ds;
> +    ns->moff = nlbas << ns->lbaf.ds;
>  
>      npdg = ns->blkconf.discard_granularity / ns->lbasz;
>  
> -- 
> 2.35.1
> 

Thanks!

Applied to nvme-next.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-18  6:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-12  8:59 [PATCH] hw/nvme: fix narrowing conversion Dmitry Tikhov
2022-04-12 20:36 ` Klaus Jensen
2022-04-18  6:13 ` Klaus Jensen

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).