ArmPkg/CpuDxe: Correct EFI_MEMORY_RO usage
Current Arm CpuDxe driver uses EFI_MEMORY_WP for write protection, according to UEFI spec, we should use EFI_MEMORY_RO for write protection. The EFI_MEMORY_WP is the cache attribute instead of memory attribute. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jiewen Yao <jiewen.yao@intel.com> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
This commit is contained in:
		
				
					committed by
					
						 Ard Biesheuvel
						Ard Biesheuvel
					
				
			
			
				
	
			
			
			
						parent
						
							df73df138d
						
					
				
				
					commit
					b7a09b71b6
				
			| @@ -3,6 +3,7 @@ | |||||||
| Copyright (c) 2009, Hewlett-Packard Company. All rights reserved.<BR> | Copyright (c) 2009, Hewlett-Packard Company. All rights reserved.<BR> | ||||||
| Portions copyright (c) 2010, Apple Inc. All rights reserved.<BR> | Portions copyright (c) 2010, Apple Inc. All rights reserved.<BR> | ||||||
| Portions copyright (c) 2011-2013, ARM Ltd. All rights reserved.<BR> | Portions copyright (c) 2011-2013, ARM Ltd. All rights reserved.<BR> | ||||||
|  | Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> | ||||||
|  |  | ||||||
| This program and the accompanying materials | This program and the accompanying materials | ||||||
| are licensed and made available under the terms and conditions of the BSD License | are licensed and made available under the terms and conditions of the BSD License | ||||||
| @@ -224,7 +225,7 @@ EfiAttributeToArmAttribute ( | |||||||
|   ArmAttributes |= TT_AF; |   ArmAttributes |= TT_AF; | ||||||
|  |  | ||||||
|   // Determine protection attributes |   // Determine protection attributes | ||||||
|   if (EfiAttributes & EFI_MEMORY_WP) { |   if (EfiAttributes & EFI_MEMORY_RO) { | ||||||
|     ArmAttributes |= TT_AP_RO_RO; |     ArmAttributes |= TT_AP_RO_RO; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ | |||||||
| Copyright (c) 2009, Hewlett-Packard Company. All rights reserved.<BR> | Copyright (c) 2009, Hewlett-Packard Company. All rights reserved.<BR> | ||||||
| Portions copyright (c) 2010, Apple Inc. All rights reserved.<BR> | Portions copyright (c) 2010, Apple Inc. All rights reserved.<BR> | ||||||
| Portions copyright (c) 2013, ARM Ltd. All rights reserved.<BR> | Portions copyright (c) 2013, ARM Ltd. All rights reserved.<BR> | ||||||
|  | Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> | ||||||
|  |  | ||||||
| This program and the accompanying materials | This program and the accompanying materials | ||||||
| are licensed and made available under the terms and conditions of the BSD License | are licensed and made available under the terms and conditions of the BSD License | ||||||
| @@ -62,7 +63,7 @@ SectionToGcdAttributes ( | |||||||
|   // determine protection attributes |   // determine protection attributes | ||||||
|   switch(SectionAttributes & TT_DESCRIPTOR_SECTION_AP_MASK) { |   switch(SectionAttributes & TT_DESCRIPTOR_SECTION_AP_MASK) { | ||||||
|     case TT_DESCRIPTOR_SECTION_AP_NO_NO: // no read, no write |     case TT_DESCRIPTOR_SECTION_AP_NO_NO: // no read, no write | ||||||
|       //*GcdAttributes |= EFI_MEMORY_WP | EFI_MEMORY_RP; |       //*GcdAttributes |= EFI_MEMORY_RO | EFI_MEMORY_RP; | ||||||
|       break; |       break; | ||||||
|  |  | ||||||
|     case TT_DESCRIPTOR_SECTION_AP_RW_NO: |     case TT_DESCRIPTOR_SECTION_AP_RW_NO: | ||||||
| @@ -73,7 +74,7 @@ SectionToGcdAttributes ( | |||||||
|     // read only cases map to write-protect |     // read only cases map to write-protect | ||||||
|     case TT_DESCRIPTOR_SECTION_AP_RO_NO: |     case TT_DESCRIPTOR_SECTION_AP_RO_NO: | ||||||
|     case TT_DESCRIPTOR_SECTION_AP_RO_RO: |     case TT_DESCRIPTOR_SECTION_AP_RO_RO: | ||||||
|       *GcdAttributes |= EFI_MEMORY_WP; |       *GcdAttributes |= EFI_MEMORY_RO; | ||||||
|       break; |       break; | ||||||
|  |  | ||||||
|     default: |     default: | ||||||
| @@ -126,7 +127,7 @@ PageToGcdAttributes ( | |||||||
|   // determine protection attributes |   // determine protection attributes | ||||||
|   switch(PageAttributes & TT_DESCRIPTOR_PAGE_AP_MASK) { |   switch(PageAttributes & TT_DESCRIPTOR_PAGE_AP_MASK) { | ||||||
|     case TT_DESCRIPTOR_PAGE_AP_NO_NO: // no read, no write |     case TT_DESCRIPTOR_PAGE_AP_NO_NO: // no read, no write | ||||||
|       //*GcdAttributes |= EFI_MEMORY_WP | EFI_MEMORY_RP; |       //*GcdAttributes |= EFI_MEMORY_RO | EFI_MEMORY_RP; | ||||||
|       break; |       break; | ||||||
|  |  | ||||||
|     case TT_DESCRIPTOR_PAGE_AP_RW_NO: |     case TT_DESCRIPTOR_PAGE_AP_RW_NO: | ||||||
| @@ -137,7 +138,7 @@ PageToGcdAttributes ( | |||||||
|     // read only cases map to write-protect |     // read only cases map to write-protect | ||||||
|     case TT_DESCRIPTOR_PAGE_AP_RO_NO: |     case TT_DESCRIPTOR_PAGE_AP_RO_NO: | ||||||
|     case TT_DESCRIPTOR_PAGE_AP_RO_RO: |     case TT_DESCRIPTOR_PAGE_AP_RO_RO: | ||||||
|       *GcdAttributes |= EFI_MEMORY_WP; |       *GcdAttributes |= EFI_MEMORY_RO; | ||||||
|       break; |       break; | ||||||
|  |  | ||||||
|     default: |     default: | ||||||
| @@ -730,9 +731,6 @@ EfiAttributeToArmAttribute ( | |||||||
|       ArmAttributes = TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC; // TEX [2:0] = 001, C=1, B=1 |       ArmAttributes = TT_DESCRIPTOR_SECTION_CACHE_POLICY_WRITE_BACK_ALLOC; // TEX [2:0] = 001, C=1, B=1 | ||||||
|       break; |       break; | ||||||
|  |  | ||||||
|     case EFI_MEMORY_WP: |  | ||||||
|     case EFI_MEMORY_XP: |  | ||||||
|     case EFI_MEMORY_RP: |  | ||||||
|     case EFI_MEMORY_UCE: |     case EFI_MEMORY_UCE: | ||||||
|     default: |     default: | ||||||
|       // Cannot be implemented UEFI definition unclear for ARM |       // Cannot be implemented UEFI definition unclear for ARM | ||||||
| @@ -743,7 +741,7 @@ EfiAttributeToArmAttribute ( | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Determine protection attributes |   // Determine protection attributes | ||||||
|   if (EfiAttributes & EFI_MEMORY_WP) { |   if (EfiAttributes & EFI_MEMORY_RO) { | ||||||
|     ArmAttributes |= TT_DESCRIPTOR_SECTION_AP_RO_RO; |     ArmAttributes |= TT_DESCRIPTOR_SECTION_AP_RO_RO; | ||||||
|   } else { |   } else { | ||||||
|     ArmAttributes |= TT_DESCRIPTOR_SECTION_AP_RW_RW; |     ArmAttributes |= TT_DESCRIPTOR_SECTION_AP_RW_RW; | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| /** @file | /** @file | ||||||
| * | * | ||||||
| *  Copyright (c) 2013, ARM Limited. All rights reserved. | *  Copyright (c) 2013, ARM Limited. All rights reserved. | ||||||
|  | *  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> | ||||||
| * | * | ||||||
| *  This program and the accompanying materials | *  This program and the accompanying materials | ||||||
| *  are licensed and made available under the terms and conditions of the BSD License | *  are licensed and made available under the terms and conditions of the BSD License | ||||||
| @@ -236,7 +237,7 @@ CpuConvertPagesToUncachedVirtualAddress ( | |||||||
|   // be the PCI address. Code should always use the CPU address, and we will or in VirtualMask |   // be the PCI address. Code should always use the CPU address, and we will or in VirtualMask | ||||||
|   // to that address. |   // to that address. | ||||||
|   // |   // | ||||||
|   Status = SetMemoryAttributes (Address, Length, EFI_MEMORY_WP, 0); |   Status = SetMemoryAttributes (Address, Length, EFI_MEMORY_RO, 0); | ||||||
|   if (!EFI_ERROR (Status)) { |   if (!EFI_ERROR (Status)) { | ||||||
|     Status = SetMemoryAttributes (Address | VirtualMask, Length, EFI_MEMORY_UC, VirtualMask); |     Status = SetMemoryAttributes (Address | VirtualMask, Length, EFI_MEMORY_UC, VirtualMask); | ||||||
|   } |   } | ||||||
| @@ -264,7 +265,7 @@ CpuReconvertPages ( | |||||||
|   // |   // | ||||||
|   // Unmap the aliased Address |   // Unmap the aliased Address | ||||||
|   // |   // | ||||||
|   Status = SetMemoryAttributes (Address | VirtualMask, Length, EFI_MEMORY_WP, 0); |   Status = SetMemoryAttributes (Address | VirtualMask, Length, EFI_MEMORY_RO, 0); | ||||||
|   if (!EFI_ERROR (Status)) { |   if (!EFI_ERROR (Status)) { | ||||||
|     // |     // | ||||||
|     // Restore atttributes |     // Restore atttributes | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ | |||||||
| * | * | ||||||
| *  Copyright (c) 2011-2014, ARM Limited. All rights reserved. | *  Copyright (c) 2011-2014, ARM Limited. All rights reserved. | ||||||
| *  Copyright (c) 2016, Linaro Limited. All rights reserved. | *  Copyright (c) 2016, Linaro Limited. All rights reserved. | ||||||
|  | *  Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> | ||||||
| * | * | ||||||
| *  This program and the accompanying materials | *  This program and the accompanying materials | ||||||
| *  are licensed and made available under the terms and conditions of the BSD License | *  are licensed and made available under the terms and conditions of the BSD License | ||||||
| @@ -89,7 +90,7 @@ PageAttributeToGcdAttribute ( | |||||||
|   // Determine protection attributes |   // Determine protection attributes | ||||||
|   if (((PageAttributes & TT_AP_MASK) == TT_AP_NO_RO) || ((PageAttributes & TT_AP_MASK) == TT_AP_RO_RO)) { |   if (((PageAttributes & TT_AP_MASK) == TT_AP_NO_RO) || ((PageAttributes & TT_AP_MASK) == TT_AP_RO_RO)) { | ||||||
|     // Read only cases map to write-protect |     // Read only cases map to write-protect | ||||||
|     GcdAttributes |= EFI_MEMORY_WP; |     GcdAttributes |= EFI_MEMORY_RO; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Process eXecute Never attribute |   // Process eXecute Never attribute | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user