[edk2] [PATCH v3 20/23] OvmfPkg/VirtioRngDxe: negotiate VIRITO_F_IOMMU_PLATFORM

Brijesh Singh posted 21 patches 7 years, 4 months ago
[edk2] [PATCH v3 20/23] OvmfPkg/VirtioRngDxe: negotiate VIRITO_F_IOMMU_PLATFORM
Posted by Brijesh Singh 7 years, 4 months ago
In previous patches, we have implemented IOMMU-like member functions in
VIRTIO_DEVICE_PROTOCOL to translate the physical address to bus address
and virtio drivers are updated to use those member functions. We do not
need to do anything special when VIRTIO_F_IOMMU_PLATFORM bit is present
hence treat it in parallel with VIRTIO_F_VERSION_1.

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
---
 OvmfPkg/VirtioRngDxe/VirtioRng.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/OvmfPkg/VirtioRngDxe/VirtioRng.c b/OvmfPkg/VirtioRngDxe/VirtioRng.c
index 59f32d343179..32512d882f7d 100644
--- a/OvmfPkg/VirtioRngDxe/VirtioRng.c
+++ b/OvmfPkg/VirtioRngDxe/VirtioRng.c
@@ -278,7 +278,7 @@ VirtioRngInit (
     goto Failed;
   }
 
-  Features &= VIRTIO_F_VERSION_1;
+  Features &= VIRTIO_F_VERSION_1 | VIRTIO_F_IOMMU_PLATFORM;
 
   //
   // In virtio-1.0, feature negotiation is expected to complete before queue
@@ -359,7 +359,7 @@ VirtioRngInit (
   // step 5 -- Report understood features and guest-tuneables.
   //
   if (Dev->VirtIo->Revision < VIRTIO_SPEC_REVISION (1, 0, 0)) {
-    Features &= ~(UINT64)VIRTIO_F_VERSION_1;
+    Features &= ~(UINT64)VIRTIO_F_VERSION_1 | VIRTIO_F_IOMMU_PLATFORM;
     Status = Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features);
     if (EFI_ERROR (Status)) {
       goto UnmapQueue;
-- 
2.7.4

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH v3 20/23] OvmfPkg/VirtioRngDxe: negotiate VIRITO_F_IOMMU_PLATFORM
Posted by Laszlo Ersek 7 years, 4 months ago
(1) Please replace "VIRITO_F_IOMMU_PLATFORM" with
"VIRTIO_F_IOMMU_PLATFORM" in the subjects of the remaining patches
(including this one).

On 08/23/17 14:22, Brijesh Singh wrote:
> In previous patches, we have implemented IOMMU-like member functions in
> VIRTIO_DEVICE_PROTOCOL to translate the physical address to bus address
> and virtio drivers are updated to use those member functions. We do not
> need to do anything special when VIRTIO_F_IOMMU_PLATFORM bit is present
> hence treat it in parallel with VIRTIO_F_VERSION_1.
> 
> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Cc: Jordan Justen <jordan.l.justen@intel.com>
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
> ---
>  OvmfPkg/VirtioRngDxe/VirtioRng.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/OvmfPkg/VirtioRngDxe/VirtioRng.c b/OvmfPkg/VirtioRngDxe/VirtioRng.c
> index 59f32d343179..32512d882f7d 100644
> --- a/OvmfPkg/VirtioRngDxe/VirtioRng.c
> +++ b/OvmfPkg/VirtioRngDxe/VirtioRng.c
> @@ -278,7 +278,7 @@ VirtioRngInit (
>      goto Failed;
>    }
>  
> -  Features &= VIRTIO_F_VERSION_1;
> +  Features &= VIRTIO_F_VERSION_1 | VIRTIO_F_IOMMU_PLATFORM;
>  
>    //
>    // In virtio-1.0, feature negotiation is expected to complete before queue
> @@ -359,7 +359,7 @@ VirtioRngInit (
>    // step 5 -- Report understood features and guest-tuneables.
>    //
>    if (Dev->VirtIo->Revision < VIRTIO_SPEC_REVISION (1, 0, 0)) {
> -    Features &= ~(UINT64)VIRTIO_F_VERSION_1;
> +    Features &= ~(UINT64)VIRTIO_F_VERSION_1 | VIRTIO_F_IOMMU_PLATFORM;

While all of the VIRTIO_F_VERSION_1 locations in this driver are covered
now, this change is invalid:

The bitwise-complement operator "~" has stronger binding than the
bitwise-or operator "|". The cast operator "(type)" also binds more
strongly than the bitwise-or operator "|".

The purpose of the above assignment is to clear both of the listed bits.
Therefore,

(2) parentheses are necessary tightly around the bitwise-or operator,
like I suggested in
<http://mid.mail-archive.com/82cb5dda-f02d-9e38-c47e-3723184dea08@redhat.com>,
point (4):

    Features &= ~(UINT64)(VIRTIO_F_VERSION_1 | VIRTIO_F_IOMMU_PLATFORM);

I think this comment too applies to the rest of the patches.

Thanks,
Laszlo

>      Status = Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features);
>      if (EFI_ERROR (Status)) {
>        goto UnmapQueue;
> 

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH v3 20/23] OvmfPkg/VirtioRngDxe: negotiate VIRITO_F_IOMMU_PLATFORM
Posted by Brijesh Singh 7 years, 4 months ago

On 8/23/17 6:21 PM, Laszlo Ersek wrote:
> (1) Please replace "VIRITO_F_IOMMU_PLATFORM" with
> "VIRTIO_F_IOMMU_PLATFORM" in the subjects of the remaining patches
> (including this one).

I will fix it in v4.

> On 08/23/17 14:22, Brijesh Singh wrote:
>> In previous patches, we have implemented IOMMU-like member functions in
>> VIRTIO_DEVICE_PROTOCOL to translate the physical address to bus address
>> and virtio drivers are updated to use those member functions. We do not
>> need to do anything special when VIRTIO_F_IOMMU_PLATFORM bit is present
>> hence treat it in parallel with VIRTIO_F_VERSION_1.
>>
>> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>> Cc: Jordan Justen <jordan.l.justen@intel.com>
>> Cc: Tom Lendacky <thomas.lendacky@amd.com>
>> Cc: Laszlo Ersek <lersek@redhat.com>
>> Contributed-under: TianoCore Contribution Agreement 1.1
>> Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
>> ---
>>  OvmfPkg/VirtioRngDxe/VirtioRng.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/OvmfPkg/VirtioRngDxe/VirtioRng.c b/OvmfPkg/VirtioRngDxe/VirtioRng.c
>> index 59f32d343179..32512d882f7d 100644
>> --- a/OvmfPkg/VirtioRngDxe/VirtioRng.c
>> +++ b/OvmfPkg/VirtioRngDxe/VirtioRng.c
>> @@ -278,7 +278,7 @@ VirtioRngInit (
>>      goto Failed;
>>    }
>>  
>> -  Features &= VIRTIO_F_VERSION_1;
>> +  Features &= VIRTIO_F_VERSION_1 | VIRTIO_F_IOMMU_PLATFORM;
>>  
>>    //
>>    // In virtio-1.0, feature negotiation is expected to complete before queue
>> @@ -359,7 +359,7 @@ VirtioRngInit (
>>    // step 5 -- Report understood features and guest-tuneables.
>>    //
>>    if (Dev->VirtIo->Revision < VIRTIO_SPEC_REVISION (1, 0, 0)) {
>> -    Features &= ~(UINT64)VIRTIO_F_VERSION_1;
>> +    Features &= ~(UINT64)VIRTIO_F_VERSION_1 | VIRTIO_F_IOMMU_PLATFORM;
> While all of the VIRTIO_F_VERSION_1 locations in this driver are covered
> now, this change is invalid:
>
> The bitwise-complement operator "~" has stronger binding than the
> bitwise-or operator "|". The cast operator "(type)" also binds more
> strongly than the bitwise-or operator "|".
>
> The purpose of the above assignment is to clear both of the listed bits.
> Therefore,
>
> (2) parentheses are necessary tightly around the bitwise-or operator,
> like I suggested in
> <http://mid.mail-archive.com/82cb5dda-f02d-9e38-c47e-3723184dea08@redhat.com>,
> point (4):
>
>     Features &= ~(UINT64)(VIRTIO_F_VERSION_1 | VIRTIO_F_IOMMU_PLATFORM);

Agreed, thanks. I will fix it in v4.

> I think this comment too applies to the rest of the patches.
>
> Thanks,
> Laszlo
>
>>      Status = Dev->VirtIo->SetGuestFeatures (Dev->VirtIo, Features);
>>      if (EFI_ERROR (Status)) {
>>        goto UnmapQueue;
>>

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel