public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2] MdeModulePkg: Add a check for metadata size in NvmExpress Driver
@ 2022-03-03  5:06 Ma, Hua
  2022-03-03  6:42 ` Wu, Hao A
  0 siblings, 1 reply; 3+ messages in thread
From: Ma, Hua @ 2022-03-03  5:06 UTC (permalink / raw)
  To: devel; +Cc: jian.j.wang, gaoliming, hao.a.wu, ray.ni, Hua Ma

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3856

Currently this NvmeExpress Driver do not support metadata handling.
According to the NVME specs, metadata may be transferred to the host after
the logical block data. It can overrun the input buffer which may only
be the size of logical block data.

Add a check to return not support for the namespaces formatted with
metadata.

v2 changes:
 - Change debug log level from INFO to ERROR
 - Change to if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0)

v1: https://edk2.groups.io/g/devel/message/87242

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>

Signed-off-by: Hua Ma <hua.ma@intel.com>
---
 MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c   | 15 +++++++++++++++
 .../Bus/Pci/NvmExpressPei/NvmExpressPei.c         | 15 +++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
index 5a1eda8e8d..388583e4d5 100644
--- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
+++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
@@ -139,6 +139,21 @@ EnumerateNvmeDevNamespace (
 
     Flbas                   = NamespaceData->Flbas;
     LbaFmtIdx               = Flbas & 0xF;
+
+    //
+    // Currently this NVME driver only suport Metadata Size == 0
+    //
+    if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "NVME IDENTIFY NAMESPACE [%d] Ms(%d) is not supported.\n",
+        NamespaceId,
+        NamespaceData->LbaFormat[LbaFmtIdx].Ms
+        ));
+      Status = EFI_UNSUPPORTED;
+      goto Exit;
+    }
+
     Lbads                   = NamespaceData->LbaFormat[LbaFmtIdx].Lbads;
     Device->Media.BlockSize = (UINT32)1 << Lbads;
 
diff --git a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c
index f73053fc3f..e8a29f23c7 100644
--- a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c
+++ b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c
@@ -104,6 +104,21 @@ EnumerateNvmeDevNamespace (
   //
   Flbas     = NamespaceData->Flbas;
   LbaFmtIdx = Flbas & 0xF;
+
+  //
+  // Currently this NVME driver only suport Metadata Size == 0
+  //
+  if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "NVME IDENTIFY NAMESPACE [%d] Ms(%d) is not supported.\n",
+      NamespaceId,
+      NamespaceData->LbaFormat[LbaFmtIdx].Ms
+      ));
+    Status = EFI_UNSUPPORTED;
+    goto Exit;
+  }
+
   Lbads     = NamespaceData->LbaFormat[LbaFmtIdx].Lbads;
 
   NamespaceInfo->Media.InterfaceType  = MSG_NVME_NAMESPACE_DP;
-- 
2.32.0.windows.2


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

* Re: [PATCH v2] MdeModulePkg: Add a check for metadata size in NvmExpress Driver
  2022-03-03  5:06 [PATCH v2] MdeModulePkg: Add a check for metadata size in NvmExpress Driver Ma, Hua
@ 2022-03-03  6:42 ` Wu, Hao A
  2022-03-07  1:57   ` [edk2-devel] " Wu, Hao A
  0 siblings, 1 reply; 3+ messages in thread
From: Wu, Hao A @ 2022-03-03  6:42 UTC (permalink / raw)
  To: Ma, Hua, devel@edk2.groups.io; +Cc: Wang, Jian J, Gao, Liming, Ni, Ray

Reviewed-by: Hao A Wu <hao.a.wu@intel.com>

Best Regards,
Hao Wu

> -----Original Message-----
> From: Ma, Hua <hua.ma@intel.com>
> Sent: Thursday, March 3, 2022 1:06 PM
> To: devel@edk2.groups.io
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Wu, Hao A <hao.a.wu@intel.com>; Ni, Ray
> <ray.ni@intel.com>; Ma, Hua <hua.ma@intel.com>
> Subject: [PATCH v2] MdeModulePkg: Add a check for metadata size in
> NvmExpress Driver
> 
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3856
> 
> Currently this NvmeExpress Driver do not support metadata handling.
> According to the NVME specs, metadata may be transferred to the host after
> the logical block data. It can overrun the input buffer which may only
> be the size of logical block data.
> 
> Add a check to return not support for the namespaces formatted with
> metadata.
> 
> v2 changes:
>  - Change debug log level from INFO to ERROR
>  - Change to if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0)
> 
> v1: https://edk2.groups.io/g/devel/message/87242
> 
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> 
> Signed-off-by: Hua Ma <hua.ma@intel.com>
> ---
>  MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c   | 15
> +++++++++++++++
>  .../Bus/Pci/NvmExpressPei/NvmExpressPei.c         | 15 +++++++++++++++
>  2 files changed, 30 insertions(+)
> 
> diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
> b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
> index 5a1eda8e8d..388583e4d5 100644
> --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
> +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
> @@ -139,6 +139,21 @@ EnumerateNvmeDevNamespace (
> 
>      Flbas                   = NamespaceData->Flbas;
>      LbaFmtIdx               = Flbas & 0xF;
> +
> +    //
> +    // Currently this NVME driver only suport Metadata Size == 0
> +    //
> +    if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0) {
> +      DEBUG ((
> +        DEBUG_ERROR,
> +        "NVME IDENTIFY NAMESPACE [%d] Ms(%d) is not supported.\n",
> +        NamespaceId,
> +        NamespaceData->LbaFormat[LbaFmtIdx].Ms
> +        ));
> +      Status = EFI_UNSUPPORTED;
> +      goto Exit;
> +    }
> +
>      Lbads                   = NamespaceData->LbaFormat[LbaFmtIdx].Lbads;
>      Device->Media.BlockSize = (UINT32)1 << Lbads;
> 
> diff --git a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c
> b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c
> index f73053fc3f..e8a29f23c7 100644
> --- a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c
> +++ b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c
> @@ -104,6 +104,21 @@ EnumerateNvmeDevNamespace (
>    //
>    Flbas     = NamespaceData->Flbas;
>    LbaFmtIdx = Flbas & 0xF;
> +
> +  //
> +  // Currently this NVME driver only suport Metadata Size == 0
> +  //
> +  if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "NVME IDENTIFY NAMESPACE [%d] Ms(%d) is not supported.\n",
> +      NamespaceId,
> +      NamespaceData->LbaFormat[LbaFmtIdx].Ms
> +      ));
> +    Status = EFI_UNSUPPORTED;
> +    goto Exit;
> +  }
> +
>    Lbads     = NamespaceData->LbaFormat[LbaFmtIdx].Lbads;
> 
>    NamespaceInfo->Media.InterfaceType  = MSG_NVME_NAMESPACE_DP;
> --
> 2.32.0.windows.2


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

* Re: [edk2-devel] [PATCH v2] MdeModulePkg: Add a check for metadata size in NvmExpress Driver
  2022-03-03  6:42 ` Wu, Hao A
@ 2022-03-07  1:57   ` Wu, Hao A
  0 siblings, 0 replies; 3+ messages in thread
From: Wu, Hao A @ 2022-03-07  1:57 UTC (permalink / raw)
  To: devel@edk2.groups.io, Wu, Hao A, Ma, Hua
  Cc: Wang, Jian J, Gao, Liming, Ni, Ray

Pushed via:
PR - https://github.com/tianocore/edk2/pull/2592
Commit - https://github.com/tianocore/edk2/commit/79f2734e5a7bc2e5256eb0e599f45407855159c7

Best Regards,
Hao Wu

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Wu, Hao
> A
> Sent: Thursday, March 3, 2022 2:43 PM
> To: Ma, Hua <hua.ma@intel.com>; devel@edk2.groups.io
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming
> <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
> Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg: Add a check for
> metadata size in NvmExpress Driver
> 
> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
> 
> Best Regards,
> Hao Wu
> 
> > -----Original Message-----
> > From: Ma, Hua <hua.ma@intel.com>
> > Sent: Thursday, March 3, 2022 1:06 PM
> > To: devel@edk2.groups.io
> > Cc: Wang, Jian J <jian.j.wang@intel.com>; Gao, Liming
> > <gaoliming@byosoft.com.cn>; Wu, Hao A <hao.a.wu@intel.com>; Ni, Ray
> > <ray.ni@intel.com>; Ma, Hua <hua.ma@intel.com>
> > Subject: [PATCH v2] MdeModulePkg: Add a check for metadata size in
> > NvmExpress Driver
> >
> > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3856
> >
> > Currently this NvmeExpress Driver do not support metadata handling.
> > According to the NVME specs, metadata may be transferred to the host
> > after the logical block data. It can overrun the input buffer which
> > may only be the size of logical block data.
> >
> > Add a check to return not support for the namespaces formatted with
> > metadata.
> >
> > v2 changes:
> >  - Change debug log level from INFO to ERROR
> >  - Change to if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0)
> >
> > v1: https://edk2.groups.io/g/devel/message/87242
> >
> > Cc: Jian J Wang <jian.j.wang@intel.com>
> > Cc: Liming Gao <gaoliming@byosoft.com.cn>
> > Cc: Hao A Wu <hao.a.wu@intel.com>
> > Cc: Ray Ni <ray.ni@intel.com>
> >
> > Signed-off-by: Hua Ma <hua.ma@intel.com>
> > ---
> >  MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c   | 15
> > +++++++++++++++
> >  .../Bus/Pci/NvmExpressPei/NvmExpressPei.c         | 15 +++++++++++++++
> >  2 files changed, 30 insertions(+)
> >
> > diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
> > b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
> > index 5a1eda8e8d..388583e4d5 100644
> > --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
> > +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpress.c
> > @@ -139,6 +139,21 @@ EnumerateNvmeDevNamespace (
> >
> >      Flbas                   = NamespaceData->Flbas;
> >      LbaFmtIdx               = Flbas & 0xF;
> > +
> > +    //
> > +    // Currently this NVME driver only suport Metadata Size == 0
> > +    //
> > +    if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0) {
> > +      DEBUG ((
> > +        DEBUG_ERROR,
> > +        "NVME IDENTIFY NAMESPACE [%d] Ms(%d) is not supported.\n",
> > +        NamespaceId,
> > +        NamespaceData->LbaFormat[LbaFmtIdx].Ms
> > +        ));
> > +      Status = EFI_UNSUPPORTED;
> > +      goto Exit;
> > +    }
> > +
> >      Lbads                   = NamespaceData->LbaFormat[LbaFmtIdx].Lbads;
> >      Device->Media.BlockSize = (UINT32)1 << Lbads;
> >
> > diff --git a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c
> > b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c
> > index f73053fc3f..e8a29f23c7 100644
> > --- a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c
> > +++ b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPei.c
> > @@ -104,6 +104,21 @@ EnumerateNvmeDevNamespace (
> >    //
> >    Flbas     = NamespaceData->Flbas;
> >    LbaFmtIdx = Flbas & 0xF;
> > +
> > +  //
> > +  // Currently this NVME driver only suport Metadata Size == 0  //
> > + if (NamespaceData->LbaFormat[LbaFmtIdx].Ms != 0) {
> > +    DEBUG ((
> > +      DEBUG_ERROR,
> > +      "NVME IDENTIFY NAMESPACE [%d] Ms(%d) is not supported.\n",
> > +      NamespaceId,
> > +      NamespaceData->LbaFormat[LbaFmtIdx].Ms
> > +      ));
> > +    Status = EFI_UNSUPPORTED;
> > +    goto Exit;
> > +  }
> > +
> >    Lbads     = NamespaceData->LbaFormat[LbaFmtIdx].Lbads;
> >
> >    NamespaceInfo->Media.InterfaceType  = MSG_NVME_NAMESPACE_DP;
> > --
> > 2.32.0.windows.2
> 
> 
> 
> 
> 


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

end of thread, other threads:[~2022-03-07  1:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-03  5:06 [PATCH v2] MdeModulePkg: Add a check for metadata size in NvmExpress Driver Ma, Hua
2022-03-03  6:42 ` Wu, Hao A
2022-03-07  1:57   ` [edk2-devel] " Wu, Hao A

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox