public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: "Wu, Hao A" <hao.a.wu@intel.com>,
	Laszlo Ersek <lersek@redhat.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Ni, Ruiyu" <ruiyu.ni@intel.com>,
	"Kinney, Michael D" <michael.d.kinney@intel.com>,
	"Yao, Jiewen" <jiewen.yao@intel.com>,
	"Zeng, Star" <star.zeng@intel.com>,
	"Gao, Liming" <liming.gao@intel.com>
Subject: Re: [PATCH v1 1/1] MdeModulePkg/NvmExpressPei: Refine data buffer & len check in PassThru
Date: Tue, 13 Nov 2018 13:03:35 +0100	[thread overview]
Message-ID: <46e725b7-0de5-ffba-9fcd-bce2f89e0f67@redhat.com> (raw)
In-Reply-To: <B80AF82E9BFB8E4FBD8C89DA810C6A093C84C502@SHSMSX104.ccr.corp.intel.com>

On 13/11/18 2:02, Wu, Hao A wrote:
>> -----Original Message-----
>> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Laszlo
>> Ersek
>> Sent: Monday, November 12, 2018 6:15 PM
>> To: Wu, Hao A; edk2-devel@lists.01.org
>> Cc: Ni, Ruiyu; Gao, Liming; Yao, Jiewen; Kinney, Michael D; Zeng, Star
>> Subject: Re: [edk2] [PATCH v1 1/1] MdeModulePkg/NvmExpressPei: Refine data
>> buffer & len check in PassThru
>>
>> On 11/12/18 02:34, Hao Wu wrote:
>>> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1142
>>>
>>> The fix is similar to commit ebb6c7633bca47fcd5b460a67e18e4a717ea91cc.
>>> We found that a similar fix should be applied to the NVMe PEI driver as
>>> well. Hence, this one is for the PEI counterpart driver.
>>>
>>> According to the the NVM Express spec Revision 1.1, for some commands
>>> (like Get/Set Feature Command, Figure 89 & 90 of the spec), the Memory
>>> Buffer maybe optional although the command opcode indicates there is a
>>> data transfer between host & controller (Get/Set Feature Command, Figure
>>> 38 of the spec).
>>>
>>> Hence, this commit refine the checks for the 'TransferLength' and
>>> 'TransferBuffer' field of the
>>> EDKII_PEI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET structure to
>> address this
>>> issue.
>>
>> I agree that this change qualifies as a bugfix for the hard feature
>> freeze. From that perspective, without checking any technical details:
>>
>> Acked-by: Laszlo Ersek <lersek@redhat.com>

I checked NVM Express spec Revision 1.3c.

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

>>
>> *However*, please clean up the description in the bugzilla (BZ#1142). In
>> the bugzilla, both the title and the initial description say that the
>> check is "unnecessar" / "not necessary".
>>
>> If the problem were only that the check was "superfluous", then this
>> patch would *not* qualify as a bugfix. Because, there would be *no bug*.
>> And a patch to remove a superfluous (and otherwise harmless) check would
>> be called a "cleanup", or a "trivial optimization".
>>
>> Instead, the check is *wrong*. It breaks valid behavior. That's why
>> there is a bug, and that's why the patch is a bugfix.
>>
>> Please be clear about this distinction, and update the BZ.
> 
> Thanks Laszlo,
> 
> I have updated the description of BZ 1142 to better reflect the issue.
> 
> Best Regards,
> Hao Wu
> 
>>
>> Thanks
>> Laszlo
>>
>>>
>>> Cc: Andrew Fish <afish@apple.com>
>>> Cc: Laszlo Ersek <lersek@redhat.com>
>>> Cc: Leif Lindholm <leif.lindholm@linaro.org>
>>> Cc: Michael D Kinney <michael.d.kinney@intel.com>
>>> Cc: Liming Gao <liming.gao@intel.com>
>>> Cc: Ruiyu Ni <ruiyu.ni@intel.com>
>>> Cc: Jiewen Yao <Jiewen.yao@intel.com>
>>> Cc: Star Zeng <star.zeng@intel.com>
>>> Contributed-under: TianoCore Contribution Agreement 1.1
>>> Signed-off-by: Hao Wu <hao.a.wu@intel.com>
>>> ---
>>>   MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiPassThru.c | 33
>> +++++++++++---------
>>>   1 file changed, 18 insertions(+), 15 deletions(-)
>>>
>>> diff --git a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiPassThru.c
>> b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiPassThru.c
>>> index 81ad01b7ee..ddcfe03998 100644
>>> --- a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiPassThru.c
>>> +++ b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiPassThru.c
>>> @@ -442,7 +442,8 @@ NvmePassThru (
>>>     // specific addresses.
>>>     //
>>>     if ((Sq->Opc & (BIT0 | BIT1)) != 0) {
>>> -    if ((Packet->TransferLength == 0) || (Packet->TransferBuffer == NULL)) {
>>> +    if (((Packet->TransferLength != 0) && (Packet->TransferBuffer == NULL))
>> ||
>>> +        ((Packet->TransferLength == 0) && (Packet->TransferBuffer != NULL)))
>> {
>>>         return EFI_INVALID_PARAMETER;
>>>       }
>>>
>>> @@ -468,21 +469,23 @@ NvmePassThru (
>>>           MapOp = EdkiiIoMmuOperationBusMasterWrite;
>>>         }
>>>
>>> -      MapLength = Packet->TransferLength;
>>> -      Status = IoMmuMap (
>>> -                 MapOp,
>>> -                 Packet->TransferBuffer,
>>> -                 &MapLength,
>>> -                 &PhyAddr,
>>> -                 &MapData
>>> -                 );
>>> -      if (EFI_ERROR (Status) || (MapLength != Packet->TransferLength)) {
>>> -        Status = EFI_OUT_OF_RESOURCES;
>>> -        DEBUG ((DEBUG_ERROR, "%a: Fail to map data buffer.\n",
>> __FUNCTION__));
>>> -        goto Exit;
>>> -      }
>>> +      if ((Packet->TransferLength != 0) && (Packet->TransferBuffer != NULL)) {
>>> +        MapLength = Packet->TransferLength;
>>> +        Status = IoMmuMap (
>>> +                   MapOp,
>>> +                   Packet->TransferBuffer,
>>> +                   &MapLength,
>>> +                   &PhyAddr,
>>> +                   &MapData
>>> +                   );
>>> +        if (EFI_ERROR (Status) || (MapLength != Packet->TransferLength)) {
>>> +          Status = EFI_OUT_OF_RESOURCES;
>>> +          DEBUG ((DEBUG_ERROR, "%a: Fail to map data buffer.\n",
>> __FUNCTION__));
>>> +          goto Exit;
>>> +        }
>>>
>>> -      Sq->Prp[0] = PhyAddr;
>>> +        Sq->Prp[0] = PhyAddr;
>>> +      }
>>>
>>>         if((Packet->MetadataLength != 0) && (Packet->MetadataBuffer != NULL))
>> {
>>>           MapLength = Packet->MetadataLength;
>>>
>>
>> _______________________________________________
>> edk2-devel mailing list
>> edk2-devel@lists.01.org
>> https://lists.01.org/mailman/listinfo/edk2-devel
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
> 


  parent reply	other threads:[~2018-11-13 12:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-12  1:34 [PATCH v1 0/1] [Nvme] Sync fix ebb6c76 from DXE to PEI counterpart Hao Wu
2018-11-12  1:34 ` [PATCH v1 1/1] MdeModulePkg/NvmExpressPei: Refine data buffer & len check in PassThru Hao Wu
2018-11-12 10:14   ` Laszlo Ersek
     [not found]     ` <B80AF82E9BFB8E4FBD8C89DA810C6A093C84C502@SHSMSX104.ccr.corp.intel.com>
2018-11-13 12:03       ` Philippe Mathieu-Daudé [this message]
2018-11-12  6:13 ` [PATCH v1 0/1] [Nvme] Sync fix ebb6c76 from DXE to PEI counterpart Zeng, Star

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=46e725b7-0de5-ffba-9fcd-bce2f89e0f67@redhat.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