From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D4ABB1A1E7B for ; Sun, 28 Aug 2016 19:42:48 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP; 28 Aug 2016 19:42:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,594,1464678000"; d="scan'208";a="1021563602" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.34]) by orsmga001.jf.intel.com with ESMTP; 28 Aug 2016 19:42:48 -0700 From: Hao Wu To: edk2-devel@lists.01.org, feng.tian@intel.com Cc: Hao Wu Date: Mon, 29 Aug 2016 10:42:25 +0800 Message-Id: <1472438547-9368-6-git-send-email-hao.a.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1472438547-9368-1-git-send-email-hao.a.wu@intel.com> References: <1472438547-9368-1-git-send-email-hao.a.wu@intel.com> Subject: [PATCH 5/7] MdeModulePkg NvmExpressDxe: Add buffer alignment check in PassThru API X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Aug 2016 02:42:49 -0000 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 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu --- .../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