[edk2-devel] [PATCH V2] IntelSiliconPkg/IntelVTdDxe: Do global invalidation before boot

Gao, Zhichao posted 1 patch 4 years, 11 months ago
Failed in applying to current master (apply log)
.../Feature/VTd/IntelVTdDxe/DmaProtection.c   | 13 +++++++-
.../Feature/VTd/IntelVTdDxe/DmaProtection.h   | 32 ++++++++++++++++++-
2 files changed, 43 insertions(+), 2 deletions(-)
[edk2-devel] [PATCH V2] IntelSiliconPkg/IntelVTdDxe: Do global invalidation before boot
Posted by Gao, Zhichao 4 years, 11 months ago
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1547

V2:
Abandon V1.
Do global invalidation of context-cache and IOTLB at
ExitBootServices.

V1:
Only doing IOTLB invalidation would cause a BSOD
'DRIVER_VERIFIER_DMA_VIOLATION' while changing the second
level page entry's attributes. So always do the global
invalidation of context-cache and IOTLB.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rangasai V Chaganty <rangasai.v.chaganty@intel.com>
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
---
 .../Feature/VTd/IntelVTdDxe/DmaProtection.c   | 13 +++++++-
 .../Feature/VTd/IntelVTdDxe/DmaProtection.h   | 32 ++++++++++++++++++-
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.c b/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.c
index f221e45938..956ebb2d3d 100644
--- a/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.c
+++ b/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.c
@@ -1,6 +1,6 @@
 /** @file
 
-  Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -581,9 +581,20 @@ OnExitBootServices (
   IN VOID                                    *Context
   )
 {
+  UINTN   VtdIndex;
+
   DEBUG ((DEBUG_INFO, "Vtd OnExitBootServices\n"));
   DumpVtdRegsAll ();
 
+  DEBUG ((DEBUG_INFO, "Invalidate all\n"));
+  for (VtdIndex = 0; VtdIndex < mVtdUnitNumber; VtdIndex++) {
+    FlushWriteBuffer (VtdIndex);
+
+    InvalidateContextCache (VtdIndex);
+
+    InvalidateIOTLB (VtdIndex);
+  }
+
   if ((PcdGet8(PcdVTdPolicyPropertyMask) & BIT1) == 0) {
     DisableDmar ();
     DumpVtdRegsAll ();
diff --git a/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.h b/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.h
index 72426d23c3..a3331db8f7 100644
--- a/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.h
+++ b/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.h
@@ -1,6 +1,6 @@
 /** @file
 
-  Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -168,6 +168,36 @@ DisableDmar (
   VOID
   );
 
+/**
+  Flush VTd engine write buffer.
+
+  @param[in]  VtdIndex          The index used to identify a VTd engine.
+**/
+VOID
+FlushWriteBuffer (
+  IN UINTN  VtdIndex
+  );
+
+/**
+  Invalidate VTd context cache.
+
+  @param[in]  VtdIndex          The index used to identify a VTd engine.
+**/
+EFI_STATUS
+InvalidateContextCache (
+  IN UINTN  VtdIndex
+  );
+
+/**
+  Invalidate VTd IOTLB.
+
+  @param[in]  VtdIndex          The index used to identify a VTd engine.
+**/
+EFI_STATUS
+InvalidateIOTLB (
+  IN UINTN  VtdIndex
+  );
+
 /**
   Invalid VTd global IOTLB.
 
-- 
2.21.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#40236): https://edk2.groups.io/g/devel/message/40236
Mute This Topic: https://groups.io/mt/31551351/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH V2] IntelSiliconPkg/IntelVTdDxe: Do global invalidation before boot
Posted by Yao, Jiewen 4 years, 11 months ago
Reviewed-by: Jiewen.yao@intel.com

> -----Original Message-----
> From: Gao, Zhichao
> Sent: Wednesday, May 8, 2019 8:34 PM
> To: devel@edk2.groups.io
> Cc: Yao, Jiewen <jiewen.yao@intel.com>; Chiu, Chasel
> <chasel.chiu@intel.com>; Ni, Ray <ray.ni@intel.com>; Chaganty, Rangasai V
> <rangasai.v.chaganty@intel.com>
> Subject: [PATCH V2] IntelSiliconPkg/IntelVTdDxe: Do global invalidation
> before boot
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1547
> 
> V2:
> Abandon V1.
> Do global invalidation of context-cache and IOTLB at
> ExitBootServices.
> 
> V1:
> Only doing IOTLB invalidation would cause a BSOD
> 'DRIVER_VERIFIER_DMA_VIOLATION' while changing the second
> level page entry's attributes. So always do the global
> invalidation of context-cache and IOTLB.
> 
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Chasel Chiu <chasel.chiu@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Rangasai V Chaganty <rangasai.v.chaganty@intel.com>
> Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
> ---
>  .../Feature/VTd/IntelVTdDxe/DmaProtection.c   | 13 +++++++-
>  .../Feature/VTd/IntelVTdDxe/DmaProtection.h   | 32
> ++++++++++++++++++-
>  2 files changed, 43 insertions(+), 2 deletions(-)
> 
> diff --git a/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.c
> b/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.c
> index f221e45938..956ebb2d3d 100644
> --- a/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.c
> +++ b/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.c
> @@ -1,6 +1,6 @@
>  /** @file
> 
> -  Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -581,9 +581,20 @@ OnExitBootServices (
>    IN VOID                                    *Context
>    )
>  {
> +  UINTN   VtdIndex;
> +
>    DEBUG ((DEBUG_INFO, "Vtd OnExitBootServices\n"));
>    DumpVtdRegsAll ();
> 
> +  DEBUG ((DEBUG_INFO, "Invalidate all\n"));
> +  for (VtdIndex = 0; VtdIndex < mVtdUnitNumber; VtdIndex++) {
> +    FlushWriteBuffer (VtdIndex);
> +
> +    InvalidateContextCache (VtdIndex);
> +
> +    InvalidateIOTLB (VtdIndex);
> +  }
> +
>    if ((PcdGet8(PcdVTdPolicyPropertyMask) & BIT1) == 0) {
>      DisableDmar ();
>      DumpVtdRegsAll ();
> diff --git a/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.h
> b/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.h
> index 72426d23c3..a3331db8f7 100644
> --- a/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.h
> +++ b/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.h
> @@ -1,6 +1,6 @@
>  /** @file
> 
> -  Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -168,6 +168,36 @@ DisableDmar (
>    VOID
>    );
> 
> +/**
> +  Flush VTd engine write buffer.
> +
> +  @param[in]  VtdIndex          The index used to identify a VTd
> engine.
> +**/
> +VOID
> +FlushWriteBuffer (
> +  IN UINTN  VtdIndex
> +  );
> +
> +/**
> +  Invalidate VTd context cache.
> +
> +  @param[in]  VtdIndex          The index used to identify a VTd
> engine.
> +**/
> +EFI_STATUS
> +InvalidateContextCache (
> +  IN UINTN  VtdIndex
> +  );
> +
> +/**
> +  Invalidate VTd IOTLB.
> +
> +  @param[in]  VtdIndex          The index used to identify a VTd
> engine.
> +**/
> +EFI_STATUS
> +InvalidateIOTLB (
> +  IN UINTN  VtdIndex
> +  );
> +
>  /**
>    Invalid VTd global IOTLB.
> 
> --
> 2.21.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#40238): https://edk2.groups.io/g/devel/message/40238
Mute This Topic: https://groups.io/mt/31551351/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH V2] IntelSiliconPkg/IntelVTdDxe: Do global invalidation before boot
Posted by Chiu, Chasel 4 years, 11 months ago
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>

> -----Original Message-----
> From: Gao, Zhichao
> Sent: Thursday, May 9, 2019 11:34 AM
> To: devel@edk2.groups.io
> Cc: Yao, Jiewen <jiewen.yao@intel.com>; Chiu, Chasel <chasel.chiu@intel.com>;
> Ni, Ray <ray.ni@intel.com>; Chaganty, Rangasai V
> <rangasai.v.chaganty@intel.com>
> Subject: [PATCH V2] IntelSiliconPkg/IntelVTdDxe: Do global invalidation before
> boot
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1547
> 
> V2:
> Abandon V1.
> Do global invalidation of context-cache and IOTLB at ExitBootServices.
> 
> V1:
> Only doing IOTLB invalidation would cause a BSOD
> 'DRIVER_VERIFIER_DMA_VIOLATION' while changing the second level page
> entry's attributes. So always do the global invalidation of context-cache and
> IOTLB.
> 
> Cc: Jiewen Yao <jiewen.yao@intel.com>
> Cc: Chasel Chiu <chasel.chiu@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Rangasai V Chaganty <rangasai.v.chaganty@intel.com>
> Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
> ---
>  .../Feature/VTd/IntelVTdDxe/DmaProtection.c   | 13 +++++++-
>  .../Feature/VTd/IntelVTdDxe/DmaProtection.h   | 32 ++++++++++++++++++-
>  2 files changed, 43 insertions(+), 2 deletions(-)
> 
> diff --git a/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.c
> b/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.c
> index f221e45938..956ebb2d3d 100644
> --- a/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.c
> +++ b/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.c
> @@ -1,6 +1,6 @@
>  /** @file
> 
> -  Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2017 - 2019, Intel Corporation. All rights
> + reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -581,9 +581,20 @@ OnExitBootServices (
>    IN VOID                                    *Context
>    )
>  {
> +  UINTN   VtdIndex;
> +
>    DEBUG ((DEBUG_INFO, "Vtd OnExitBootServices\n"));
>    DumpVtdRegsAll ();
> 
> +  DEBUG ((DEBUG_INFO, "Invalidate all\n"));  for (VtdIndex = 0;
> + VtdIndex < mVtdUnitNumber; VtdIndex++) {
> +    FlushWriteBuffer (VtdIndex);
> +
> +    InvalidateContextCache (VtdIndex);
> +
> +    InvalidateIOTLB (VtdIndex);
> +  }
> +
>    if ((PcdGet8(PcdVTdPolicyPropertyMask) & BIT1) == 0) {
>      DisableDmar ();
>      DumpVtdRegsAll ();
> diff --git a/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.h
> b/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.h
> index 72426d23c3..a3331db8f7 100644
> --- a/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.h
> +++ b/IntelSiliconPkg/Feature/VTd/IntelVTdDxe/DmaProtection.h
> @@ -1,6 +1,6 @@
>  /** @file
> 
> -  Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2017 - 2019, Intel Corporation. All rights
> + reserved.<BR>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
> 
>  **/
> @@ -168,6 +168,36 @@ DisableDmar (
>    VOID
>    );
> 
> +/**
> +  Flush VTd engine write buffer.
> +
> +  @param[in]  VtdIndex          The index used to identify a VTd engine.
> +**/
> +VOID
> +FlushWriteBuffer (
> +  IN UINTN  VtdIndex
> +  );
> +
> +/**
> +  Invalidate VTd context cache.
> +
> +  @param[in]  VtdIndex          The index used to identify a VTd engine.
> +**/
> +EFI_STATUS
> +InvalidateContextCache (
> +  IN UINTN  VtdIndex
> +  );
> +
> +/**
> +  Invalidate VTd IOTLB.
> +
> +  @param[in]  VtdIndex          The index used to identify a VTd engine.
> +**/
> +EFI_STATUS
> +InvalidateIOTLB (
> +  IN UINTN  VtdIndex
> +  );
> +
>  /**
>    Invalid VTd global IOTLB.
> 
> --
> 2.21.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#40263): https://edk2.groups.io/g/devel/message/40263
Mute This Topic: https://groups.io/mt/31551351/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-