diff mbox series

[edk2,2/3] ArmPkg/UncachedMemoryAllocationLib: use CWG value to align pool allocations

Message ID 1488283992-32104-2-git-send-email-ard.biesheuvel@linaro.org
State Accepted
Commit 25549bda46c581271a303840fb266539c00ede71
Headers show
Series [edk2,1/3] ArmPkg/UncachedMemoryAllocationLib: restore mapping attributes after free | expand

Commit Message

Ard Biesheuvel Feb. 28, 2017, 12:13 p.m. UTC
Uncached pool allocations are aligned to the data cache line length under
the assumption that this is sufficient to prevent cache maintenance from
corrupting adjacent allocations. However, the value to use in such cases
is architecturally called the Cache Writeback Granule (CWG), which is
essentially the maximum Dcache line length rather than the minimum.

Note that this is mostly a cosmetical fix, given that the pool allocation
is turned into a page allocation later, and rounded up accordingly.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.7.4

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

Comments

Leif Lindholm March 7, 2017, 4:49 p.m. UTC | #1
On Tue, Feb 28, 2017 at 12:13:11PM +0000, Ard Biesheuvel wrote:
> Uncached pool allocations are aligned to the data cache line length under

> the assumption that this is sufficient to prevent cache maintenance from

> corrupting adjacent allocations. However, the value to use in such cases

> is architecturally called the Cache Writeback Granule (CWG), which is

> essentially the maximum Dcache line length rather than the minimum.

> 

> Note that this is mostly a cosmetical fix, given that the pool allocation

> is turned into a page allocation later, and rounded up accordingly.

> 

> Contributed-under: TianoCore Contribution Agreement 1.0

> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>


Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>


> ---

>  ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

> 

> diff --git a/ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c b/ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c

> index cd13a7da92e0..0d8abad23433 100644

> --- a/ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c

> +++ b/ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c

> @@ -545,7 +545,7 @@ UncachedInternalAllocatePool (

>    IN UINTN            AllocationSize

>    )

>  {

> -  UINTN CacheLineLength = ArmDataCacheLineLength ();

> +  UINTN CacheLineLength = ArmCacheWritebackGranule ();

>    return UncachedInternalAllocateAlignedPool (MemoryType, AllocationSize, CacheLineLength);

>  }

>  

> -- 

> 2.7.4

> 

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

Patch

diff --git a/ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c b/ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c
index cd13a7da92e0..0d8abad23433 100644
--- a/ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c
+++ b/ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.c
@@ -545,7 +545,7 @@  UncachedInternalAllocatePool (
   IN UINTN            AllocationSize
   )
 {
-  UINTN CacheLineLength = ArmDataCacheLineLength ();
+  UINTN CacheLineLength = ArmCacheWritebackGranule ();
   return UncachedInternalAllocateAlignedPool (MemoryType, AllocationSize, CacheLineLength);
 }