From: Laszlo Ersek <lersek@redhat.com>
To: Brijesh Singh <brijesh.singh@amd.com>, edk2-devel@lists.01.org
Cc: Jordan Justen <jordan.l.justen@intel.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: Re: [PATCH v2 3/4] Ovmfpkg/VirtioScsiDxe: map virtio-scsi request and response buffers
Date: Thu, 31 Aug 2017 15:49:26 +0200 [thread overview]
Message-ID: <885cf87f-eab8-a429-cf40-eb6905d8378e@redhat.com> (raw)
In-Reply-To: <3e3e8174-616d-8f34-7682-02f6e492fb24@redhat.com>
On 08/31/17 15:23, Laszlo Ersek wrote:
> On 08/30/17 22:45, Brijesh Singh wrote:
>> @@ -492,10 +645,50 @@ VirtioScsiPassThru (
>> //
>> if (VirtioFlush (Dev->VirtIo, VIRTIO_SCSI_REQUEST_QUEUE, &Dev->Ring,
>> &Indices, NULL) != EFI_SUCCESS) {
>> - return ReportHostAdapterError (Packet);
>> + Status = ReportHostAdapterError (Packet);
>> + goto UnmapResponseBuffer;
>> }
>>
>> - return ParseResponse (Packet, &Response);
>> + Status = ParseResponse (Packet, Response);
>> +
>> + //
>> + // If virtio request was successful and it was a CPU read request then we
>> + // have used an intermediate buffer. Copy the data from intermediate buffer
>> + // to the final buffer.
>> + //
>> + if (!EFI_ERROR (Status) && (Packet->InTransferLength > 0)) {
>> + CopyMem (Packet->InDataBuffer, InDataBuffer, Packet->InTransferLength);
>> + }
>
> (7) The comment is exactly right, but the condition that you check
> after is incorrect.
>
> The right thing to do is to call CopyMem() *unconditionally*.
>
> Namely, at this point we are past ParseResponse(). As I wrote before,
> ParseResponse() updates the Packet->... fields in every case, even if
> it reports an EFI_STATUS that is different from EFI_SUCCESS. And
> whatever we expose to the caller through "Packet->InTransferLength"
> *must* be reflected in "Packet->InDataBuffer" regardless of return
> status.
>
> Therefore the Status check must be dropped. And then we need not check
> (Packet->InTransferLength>0) either, because the CopyMem() will deal
> with it internally.
>
> Think of it like this: the "worst" that can happen, on error, is that
> "Packet->InTransferLength" is unchanged from its "input" value, and we
> overwrite the caller's "Packet->InDataBuffer" entirely. What is the
> data we are going to put there? It's all zeroes, from your
>
> ZeroMem (InDataBuffer, Packet->InTransferLength);
>
> higher up.
>
> So, again, this CopyMem() needs to be unconditional -- as the comment
> says, if the *virtio* request was successful (== we talked to the
> virtio-scsi adapter), then we have to copy the data, even if the
> *SCSI* request produced an error status in ParseResponse.
I have to correct myself a little bit -- although I think you would have
caught me anyway :) --, namely we should keep the "if", but the
condition should be:
InDataBuffer != NULL
Admittedly, it is likely that none of the CopyMem() implementations
would have problems with a NULL "SourceBuffer", if "Length" was zero.
Nonetheless, the interface contract in
MdePkg/Include/Library/BaseMemoryLib.h
does not mark SourceBuffer OPTIONAL -- neither does the UEFI spec, for
the similar gBS->CopyMem() boot service --, for the case when Length==0,
so we should do an explicit check:
if (InDataBuffer != NULL) {
CopyMem (Packet->InDataBuffer, InDataBuffer, Packet->InTransferLength);
}
Thank you,
Laszlo
next prev parent reply other threads:[~2017-08-31 13:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-30 20:44 [PATCH v2 0/4] OvmfPkg/VirtioScsiDxe: map host address to device address Brijesh Singh
2017-08-30 20:45 ` [PATCH v2 1/4] OvmfPkg/VirtioScsiDxe: map VRING using VirtioRingMap() Brijesh Singh
2017-08-30 20:45 ` [PATCH v2 2/4] OvmfPkg/VirtioScsiDxe: add helper to create a fake host adapter error Brijesh Singh
2017-08-31 11:19 ` Laszlo Ersek
2017-08-30 20:45 ` [PATCH v2 3/4] Ovmfpkg/VirtioScsiDxe: map virtio-scsi request and response buffers Brijesh Singh
2017-08-31 13:23 ` Laszlo Ersek
2017-08-31 13:49 ` Laszlo Ersek [this message]
2017-08-31 14:44 ` Brijesh Singh
2017-08-30 20:45 ` [PATCH v2 4/4] OvmfPkg/VirtioScsiDxe: negotiate VIRTIO_F_IOMMU_PLATFORM Brijesh Singh
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=885cf87f-eab8-a429-cf40-eb6905d8378e@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