From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 329DA2194D3B9 for ; Tue, 23 Oct 2018 01:52:21 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Oct 2018 01:52:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,415,1534834800"; d="scan'208";a="83699040" Received: from ray-dev.ccr.corp.intel.com (HELO [10.239.9.11]) ([10.239.9.11]) by orsmga008.jf.intel.com with ESMTP; 23 Oct 2018 01:52:20 -0700 To: Hao Wu , edk2-devel@lists.01.org Cc: Jiewen Yao , Star Zeng References: <20181018064200.2068-1-hao.a.wu@intel.com> <20181018064200.2068-4-hao.a.wu@intel.com> From: "Ni, Ruiyu" Message-ID: <5774f193-fc94-a08c-9093-932363b648f2@Intel.com> Date: Tue, 23 Oct 2018 16:53:35 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181018064200.2068-4-hao.a.wu@intel.com> Subject: Re: [PATCH v1 3/3] MdeModulePkg/NvmExpressDxe: Refine PassThru IO queue creation behavior X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Oct 2018 08:52:22 -0000 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit On 10/18/2018 2:42 PM, Hao Wu wrote: > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1260 > > For the PassThru() service of NVM Express Pass Through Protocol, the > current implementation (function NvmExpressPassThru()) will only use the > IO Completion/Submission queues created internally by this driver during > the controller initialization process. Any other IO queues created will > not be consumed. > > So the value is little to accept external IO Completion/Submission queue > creation request. This commit will refine the behavior of function > NvmExpressPassThru(), it will only accept driver internal IO queue > creation commands and will return "EFI_UNSUPPORTED" for external ones. > > Cc: Jiewen Yao > Cc: Ruiyu Ni > Cc: Star Zeng > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Hao Wu > --- > MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c | 42 ++++++++++++++++---- > 1 file changed, 34 insertions(+), 8 deletions(-) > > diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c > index c52e960771..0c550bd52c 100644 > --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c > +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c > @@ -476,6 +476,7 @@ NvmExpressPassThru ( > UINT32 Data; > NVME_PASS_THRU_ASYNC_REQ *AsyncRequest; > EFI_TPL OldTpl; > + UINT32 CrIoQid; > > // > // check the data fields in Packet parameter. > @@ -587,14 +588,39 @@ NvmExpressPassThru ( > } > > Sq->Prp[0] = (UINT64)(UINTN)Packet->TransferBuffer; > - // > - // If the NVMe cmd has data in or out, then mapping the user buffer to the PCI controller specific addresses. > - // Note here we don't handle data buffer for CreateIOSubmitionQueue and CreateIOCompletionQueue cmds because > - // these two cmds are special which requires their data buffer must support simultaneous access by both the > - // processor and a PCI Bus Master. It's caller's responsbility to ensure this. > - // > - if (((Sq->Opc & (BIT0 | BIT1)) != 0) && > - !((Packet->QueueType == NVME_ADMIN_QUEUE) && ((Sq->Opc == NVME_ADMIN_CRIOCQ_CMD) || (Sq->Opc == NVME_ADMIN_CRIOSQ_CMD)))) { > + if ((Packet->QueueType == NVME_ADMIN_QUEUE) && > + ((Sq->Opc == NVME_ADMIN_CRIOCQ_CMD) || (Sq->Opc == NVME_ADMIN_CRIOSQ_CMD))) { > + // > + // Command Dword 10 should be valid for CreateIOCompletionQueue and > + // CreateIOSubmissionQueue commands. > + // > + if (!(Packet->NvmeCmd->Flags & CDW10_VALID)) { > + return EFI_INVALID_PARAMETER; > + } > + > + // > + // Bits 15:0 of Command Dword 10 is the Queue Identifier (QID) for > + // CreateIOCompletionQueue and CreateIOSubmissionQueue commands. > + // > + CrIoQid = Packet->NvmeCmd->Cdw10 & 0xFFFF; > + > + // > + // Currently, we only use the IO Completion/Submission queues created internally > + // by this driver during controller initialization. Any other IO queues created > + // will not be consumed here. The value is little to accept external IO queue > + // creation requests, so here we will return EFI_UNSUPPORTED for external IO > + // queue creation request. > + // > + if ((CrIoQid >= NVME_MAX_QUEUES) || > + ((Sq->Opc == NVME_ADMIN_CRIOCQ_CMD) && (Packet->TransferBuffer != Private->CqBufferPciAddr[CrIoQid])) || > + ((Sq->Opc == NVME_ADMIN_CRIOSQ_CMD) && (Packet->TransferBuffer != Private->SqBufferPciAddr[CrIoQid]))) { > + DEBUG ((DEBUG_ERROR, "NvmExpressPassThru: Does not support external IO queues creation request.\n")); > + return EFI_UNSUPPORTED; > + } Does the above check is to make sure only accept IO queues creation request from NvmeCreateIoCompletionQueue() and NvmeCreateIoSubmissionQueue()? The check is very complex and unnecessary IMO. If we introduce a boolean field like CreateQueue in the Private structure and set it to TRUE when calling PassThru() from the above two internal functions, the above check can be replaced with only one line check: if (Private->CreateQueue) It does introduce a "dirty" flag in Private structure, but the above complex check can be avoided. What's your opinion? > + } else if ((Sq->Opc & (BIT0 | BIT1)) != 0) { > + // > + // If the NVMe cmd has data in or out, then mapping the user buffer to the PCI controller specific addresses. > + // > if (((Packet->TransferLength != 0) && (Packet->TransferBuffer == NULL)) || > ((Packet->TransferLength == 0) && (Packet->TransferBuffer != NULL))) { > return EFI_INVALID_PARAMETER; > -- Thanks, Ray