public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ma, Hua" <hua.ma@intel.com>
To: devel@edk2.groups.io
Cc: jian.j.wang@intel.com, gaoliming@byosoft.com.cn,
	hao.a.wu@intel.com, ray.ni@intel.com, Hua Ma <hua.ma@intel.com>
Subject: [PATCH v1] MdeModulePkg: Add a check for metadata size in NvmExpress Driver
Date: Thu,  3 Mar 2022 10:06:16 +0800	[thread overview]
Message-ID: <f96e2ab0785fabf37484819f325477e19fbdc8c1.1646272828.git.hua.ma@intel.com> (raw)

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.

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..46b7dcba20 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) {
+      DEBUG ((
+        DEBUG_INFO,
+        "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..6e27950648 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) {
+    DEBUG ((
+      DEBUG_INFO,
+      "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


             reply	other threads:[~2022-03-03  2:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-03  2:06 Ma, Hua [this message]
2022-03-03  2:19 ` [edk2-devel] [PATCH v1] MdeModulePkg: Add a check for metadata size in NvmExpress Driver Wu, Hao A

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-list 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=f96e2ab0785fabf37484819f325477e19fbdc8c1.1646272828.git.hua.ma@intel.com \
    --to=devel@edk2.groups.io \
    /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