From: Hao Wu <hao.a.wu@intel.com>
To: edk2-devel@lists.01.org, feng.tian@intel.com
Cc: Hao Wu <hao.a.wu@intel.com>
Subject: [PATCH 5/7] MdeModulePkg NvmExpressDxe: Add buffer alignment check in PassThru API
Date: Mon, 29 Aug 2016 10:42:25 +0800 [thread overview]
Message-ID: <1472438547-9368-6-git-send-email-hao.a.wu@intel.com> (raw)
In-Reply-To: <1472438547-9368-1-git-send-email-hao.a.wu@intel.com>
According to the UEFI spec, the 'TransferBuffer' and 'MetadataBuffer' used
in a data transfer should be aligned on the boundary specified by the
IoAlign field in the EFI_NVM_EXPRESS_PASS_THRU_MODE structure.
This commit adds this check to follow the spec.
Cc: Feng Tian <feng.tian@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
---
.../Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c | 55 +++++++++++++---------
1 file changed, 34 insertions(+), 21 deletions(-)
diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c
index ec7507e..6b29260 100644
--- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c
+++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c
@@ -357,27 +357,28 @@ NvmExpressPassThru (
IN EFI_EVENT Event OPTIONAL
)
{
- NVME_CONTROLLER_PRIVATE_DATA *Private;
- EFI_STATUS Status;
- EFI_PCI_IO_PROTOCOL *PciIo;
- NVME_SQ *Sq;
- NVME_CQ *Cq;
- UINT16 QueueId;
- UINT32 Bytes;
- UINT16 Offset;
- EFI_EVENT TimerEvent;
- EFI_PCI_IO_PROTOCOL_OPERATION Flag;
- EFI_PHYSICAL_ADDRESS PhyAddr;
- VOID *MapData;
- VOID *MapMeta;
- VOID *MapPrpList;
- UINTN MapLength;
- UINT64 *Prp;
- VOID *PrpListHost;
- UINTN PrpListNo;
- UINT32 Data;
- NVME_PASS_THRU_ASYNC_REQ *AsyncRequest;
- EFI_TPL OldTpl;
+ NVME_CONTROLLER_PRIVATE_DATA *Private;
+ EFI_STATUS Status;
+ EFI_PCI_IO_PROTOCOL *PciIo;
+ NVME_SQ *Sq;
+ NVME_CQ *Cq;
+ UINT16 QueueId;
+ UINT32 Bytes;
+ UINT16 Offset;
+ EFI_EVENT TimerEvent;
+ EFI_PCI_IO_PROTOCOL_OPERATION Flag;
+ EFI_PHYSICAL_ADDRESS PhyAddr;
+ VOID *MapData;
+ VOID *MapMeta;
+ VOID *MapPrpList;
+ UINTN MapLength;
+ UINT64 *Prp;
+ VOID *PrpListHost;
+ UINTN PrpListNo;
+ UINT32 IoAlign;
+ UINT32 Data;
+ NVME_PASS_THRU_ASYNC_REQ *AsyncRequest;
+ EFI_TPL OldTpl;
//
// check the data fields in Packet parameter.
@@ -394,6 +395,18 @@ NvmExpressPassThru (
return EFI_INVALID_PARAMETER;
}
+ //
+ // Buffer alignment check for TransferBuffer & MetadataBuffer.
+ //
+ IoAlign = This->Mode->IoAlign;
+ if (IoAlign > 0 && (((UINTN) Packet->TransferBuffer & (IoAlign - 1)) != 0)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (IoAlign > 0 && (((UINTN) Packet->MetadataBuffer & (IoAlign - 1)) != 0)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
Private = NVME_CONTROLLER_PRIVATE_DATA_FROM_PASS_THRU (This);
PciIo = Private->PciIo;
MapData = NULL;
--
1.9.5.msysgit.0
next prev parent reply other threads:[~2016-08-29 2:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-29 2:42 [PATCH 0/7] Fix some bugs in NvmExpressDxe driver Hao Wu
2016-08-29 2:42 ` [PATCH 1/7] MdeModulePkg NvmExpressDxe: Avoid crashing 'Mode' during OpenProtocol Hao Wu
2016-08-29 2:42 ` [PATCH 2/7] MdeModulePkg NvmExpressDxe: Refine BuildDevicePath API to follow spec Hao Wu
2016-08-29 2:42 ` [PATCH 3/7] MdeModulePkg NvmExpressDxe: Refine GetNameSpace " Hao Wu
2016-08-29 2:42 ` [PATCH 4/7] MdeModulePkg NvmExpressDxe: Refine GetNextNamespace " Hao Wu
2016-08-29 2:42 ` Hao Wu [this message]
2016-08-29 2:42 ` [PATCH 6/7] MdeModulePkg NvmExpressDxe: Add check on the attributes of NVME controller Hao Wu
2016-08-29 2:42 ` [PATCH 7/7] MdeModulePkg NvmExpressDxe: Add check for command packet in PassThru Hao Wu
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=1472438547-9368-6-git-send-email-hao.a.wu@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