OvmfPkg/BaseMemEncryptSevLib: introduce MemEncryptSevClearMmioPageEncMask()
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3275 The MemEncryptSevClearMmioPageEncMask() helper can be used for clearing the memory encryption mask for the Mmio region. The MemEncryptSevClearMmioPageEncMask() is a simplified version of MemEncryptSevClearPageEncMask() -- it does not flush the caches after clearing the page encryption mask. Cc: James Bottomley <jejb@linux.ibm.com> Cc: Min Xu <min.m.xu@intel.com> Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Tom Lendacky <thomas.lendacky@amd.com> Cc: Jordan Justen <jordan.l.justen@intel.com> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org> Cc: Laszlo Ersek <lersek@redhat.com> Cc: Erdem Aktas <erdemaktas@google.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Brijesh Singh <brijesh.singh@amd.com> Message-Id: <20210519181949.6574-10-brijesh.singh@amd.com>
This commit is contained in:
		
				
					committed by
					
						
						mergify[bot]
					
				
			
			
				
	
			
			
			
						parent
						
							2b5b2ff04d
						
					
				
				
					commit
					901a9bfc3a
				
			@@ -203,4 +203,29 @@ MemEncryptSevGetAddressRangeState (
 | 
				
			|||||||
  IN UINTN                    Length
 | 
					  IN UINTN                    Length
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  This function clears memory encryption bit for the MMIO region specified by
 | 
				
			||||||
 | 
					  BaseAddress and NumPages.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @param[in]  Cr3BaseAddress          Cr3 Base Address (if zero then use
 | 
				
			||||||
 | 
					                                      current CR3)
 | 
				
			||||||
 | 
					  @param[in]  BaseAddress             The physical address that is the start
 | 
				
			||||||
 | 
					                                      address of a MMIO region.
 | 
				
			||||||
 | 
					  @param[in]  NumPages                The number of pages from start memory
 | 
				
			||||||
 | 
					                                      region.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @retval RETURN_SUCCESS              The attributes were cleared for the
 | 
				
			||||||
 | 
					                                      memory region.
 | 
				
			||||||
 | 
					  @retval RETURN_INVALID_PARAMETER    Number of pages is zero.
 | 
				
			||||||
 | 
					  @retval RETURN_UNSUPPORTED          Clearing the memory encryption attribute
 | 
				
			||||||
 | 
					                                      is not supported
 | 
				
			||||||
 | 
					**/
 | 
				
			||||||
 | 
					RETURN_STATUS
 | 
				
			||||||
 | 
					EFIAPI
 | 
				
			||||||
 | 
					MemEncryptSevClearMmioPageEncMask (
 | 
				
			||||||
 | 
					  IN PHYSICAL_ADDRESS         Cr3BaseAddress,
 | 
				
			||||||
 | 
					  IN PHYSICAL_ADDRESS         BaseAddress,
 | 
				
			||||||
 | 
					  IN UINTN                    NumPages
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // _MEM_ENCRYPT_SEV_LIB_H_
 | 
					#endif // _MEM_ENCRYPT_SEV_LIB_H_
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -111,3 +111,34 @@ MemEncryptSevGetAddressRangeState (
 | 
				
			|||||||
  //
 | 
					  //
 | 
				
			||||||
  return MemEncryptSevAddressRangeEncrypted;
 | 
					  return MemEncryptSevAddressRangeEncrypted;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  This function clears memory encryption bit for the MMIO region specified by
 | 
				
			||||||
 | 
					  BaseAddress and NumPages.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @param[in]  Cr3BaseAddress          Cr3 Base Address (if zero then use
 | 
				
			||||||
 | 
					                                      current CR3)
 | 
				
			||||||
 | 
					  @param[in]  BaseAddress             The physical address that is the start
 | 
				
			||||||
 | 
					                                      address of a MMIO region.
 | 
				
			||||||
 | 
					  @param[in]  NumPages                The number of pages from start memory
 | 
				
			||||||
 | 
					                                      region.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @retval RETURN_SUCCESS              The attributes were cleared for the
 | 
				
			||||||
 | 
					                                      memory region.
 | 
				
			||||||
 | 
					  @retval RETURN_INVALID_PARAMETER    Number of pages is zero.
 | 
				
			||||||
 | 
					  @retval RETURN_UNSUPPORTED          Clearing the memory encryption attribute
 | 
				
			||||||
 | 
					                                      is not supported
 | 
				
			||||||
 | 
					**/
 | 
				
			||||||
 | 
					RETURN_STATUS
 | 
				
			||||||
 | 
					EFIAPI
 | 
				
			||||||
 | 
					MemEncryptSevClearMmioPageEncMask (
 | 
				
			||||||
 | 
					  IN PHYSICAL_ADDRESS         Cr3BaseAddress,
 | 
				
			||||||
 | 
					  IN PHYSICAL_ADDRESS         BaseAddress,
 | 
				
			||||||
 | 
					  IN UINTN                    NumPages
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  //
 | 
				
			||||||
 | 
					  // Memory encryption bit is not accessible in 32-bit mode
 | 
				
			||||||
 | 
					  //
 | 
				
			||||||
 | 
					  return RETURN_UNSUPPORTED;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -118,3 +118,36 @@ MemEncryptSevGetAddressRangeState (
 | 
				
			|||||||
           Length
 | 
					           Length
 | 
				
			||||||
           );
 | 
					           );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  This function clears memory encryption bit for the mmio region specified by
 | 
				
			||||||
 | 
					  BaseAddress and NumPages.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @param[in]  Cr3BaseAddress          Cr3 Base Address (if zero then use
 | 
				
			||||||
 | 
					                                      current CR3)
 | 
				
			||||||
 | 
					  @param[in]  BaseAddress             The physical address that is the start
 | 
				
			||||||
 | 
					                                      address of a mmio region.
 | 
				
			||||||
 | 
					  @param[in]  NumPages                The number of pages from start memory
 | 
				
			||||||
 | 
					                                      region.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @retval RETURN_SUCCESS              The attributes were cleared for the
 | 
				
			||||||
 | 
					                                      memory region.
 | 
				
			||||||
 | 
					  @retval RETURN_INVALID_PARAMETER    Number of pages is zero.
 | 
				
			||||||
 | 
					  @retval RETURN_UNSUPPORTED          Clearing the memory encryption attribute
 | 
				
			||||||
 | 
					                                      is not supported
 | 
				
			||||||
 | 
					**/
 | 
				
			||||||
 | 
					RETURN_STATUS
 | 
				
			||||||
 | 
					EFIAPI
 | 
				
			||||||
 | 
					MemEncryptSevClearMmioPageEncMask (
 | 
				
			||||||
 | 
					  IN PHYSICAL_ADDRESS         Cr3BaseAddress,
 | 
				
			||||||
 | 
					  IN PHYSICAL_ADDRESS         BaseAddress,
 | 
				
			||||||
 | 
					  IN UINTN                    NumPages
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  return InternalMemEncryptSevClearMmioPageEncMask (
 | 
				
			||||||
 | 
					           Cr3BaseAddress,
 | 
				
			||||||
 | 
					           BaseAddress,
 | 
				
			||||||
 | 
					           EFI_PAGES_TO_SIZE (NumPages)
 | 
				
			||||||
 | 
					           );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -891,3 +891,36 @@ InternalMemEncryptSevSetMemoryEncrypted (
 | 
				
			|||||||
           Flush
 | 
					           Flush
 | 
				
			||||||
           );
 | 
					           );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  This function clears memory encryption bit for the MMIO region specified by
 | 
				
			||||||
 | 
					  PhysicalAddress and Length.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @param[in]  Cr3BaseAddress          Cr3 Base Address (if zero then use
 | 
				
			||||||
 | 
					                                      current CR3)
 | 
				
			||||||
 | 
					  @param[in]  PhysicalAddress         The physical address that is the start
 | 
				
			||||||
 | 
					                                      address of a MMIO region.
 | 
				
			||||||
 | 
					  @param[in]  Length                  The length of memory region
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @retval RETURN_SUCCESS              The attributes were cleared for the
 | 
				
			||||||
 | 
					                                      memory region.
 | 
				
			||||||
 | 
					  @retval RETURN_INVALID_PARAMETER    Length is zero.
 | 
				
			||||||
 | 
					  @retval RETURN_UNSUPPORTED          Clearing the memory encyrption attribute
 | 
				
			||||||
 | 
					                                      is not supported
 | 
				
			||||||
 | 
					**/
 | 
				
			||||||
 | 
					RETURN_STATUS
 | 
				
			||||||
 | 
					EFIAPI
 | 
				
			||||||
 | 
					InternalMemEncryptSevClearMmioPageEncMask (
 | 
				
			||||||
 | 
					  IN  PHYSICAL_ADDRESS        Cr3BaseAddress,
 | 
				
			||||||
 | 
					  IN  PHYSICAL_ADDRESS        PhysicalAddress,
 | 
				
			||||||
 | 
					  IN  UINTN                   Length
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  return SetMemoryEncDec (
 | 
				
			||||||
 | 
					           Cr3BaseAddress,
 | 
				
			||||||
 | 
					           PhysicalAddress,
 | 
				
			||||||
 | 
					           Length,
 | 
				
			||||||
 | 
					           ClearCBit,
 | 
				
			||||||
 | 
					           FALSE
 | 
				
			||||||
 | 
					           );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -98,3 +98,33 @@ InternalMemEncryptSevSetMemoryEncrypted (
 | 
				
			|||||||
  //
 | 
					  //
 | 
				
			||||||
  return RETURN_UNSUPPORTED;
 | 
					  return RETURN_UNSUPPORTED;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  This function clears memory encryption bit for the MMIO region specified by
 | 
				
			||||||
 | 
					  PhysicalAddress and Length.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @param[in]  Cr3BaseAddress          Cr3 Base Address (if zero then use
 | 
				
			||||||
 | 
					                                      current CR3)
 | 
				
			||||||
 | 
					  @param[in]  PhysicalAddress         The physical address that is the start
 | 
				
			||||||
 | 
					                                      address of a MMIO region.
 | 
				
			||||||
 | 
					  @param[in]  Length                  The length of memory region
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @retval RETURN_SUCCESS              The attributes were cleared for the
 | 
				
			||||||
 | 
					                                      memory region.
 | 
				
			||||||
 | 
					  @retval RETURN_INVALID_PARAMETER    Length is zero.
 | 
				
			||||||
 | 
					  @retval RETURN_UNSUPPORTED          Clearing the memory encyrption attribute
 | 
				
			||||||
 | 
					                                      is not supported
 | 
				
			||||||
 | 
					**/
 | 
				
			||||||
 | 
					RETURN_STATUS
 | 
				
			||||||
 | 
					EFIAPI
 | 
				
			||||||
 | 
					InternalMemEncryptSevClearMmioPageEncMask (
 | 
				
			||||||
 | 
					  IN  PHYSICAL_ADDRESS        Cr3BaseAddress,
 | 
				
			||||||
 | 
					  IN  PHYSICAL_ADDRESS        PhysicalAddress,
 | 
				
			||||||
 | 
					  IN  UINTN                   Length
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  //
 | 
				
			||||||
 | 
					  // This function is not available during SEC.
 | 
				
			||||||
 | 
					  //
 | 
				
			||||||
 | 
					  return RETURN_UNSUPPORTED;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -126,4 +126,27 @@ InternalMemEncryptSevGetAddressRangeState (
 | 
				
			|||||||
  IN UINTN                    Length
 | 
					  IN UINTN                    Length
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					  This function clears memory encryption bit for the MMIO region specified by
 | 
				
			||||||
 | 
					  PhysicalAddress and Length.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @param[in]  Cr3BaseAddress          Cr3 Base Address (if zero then use
 | 
				
			||||||
 | 
					                                      current CR3)
 | 
				
			||||||
 | 
					  @param[in]  PhysicalAddress         The physical address that is the start
 | 
				
			||||||
 | 
					                                      address of a MMIO region.
 | 
				
			||||||
 | 
					  @param[in]  Length                  The length of memory region
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @retval RETURN_SUCCESS              The attributes were cleared for the
 | 
				
			||||||
 | 
					                                      memory region.
 | 
				
			||||||
 | 
					  @retval RETURN_INVALID_PARAMETER    Length is zero.
 | 
				
			||||||
 | 
					  @retval RETURN_UNSUPPORTED          Clearing the memory encyrption attribute
 | 
				
			||||||
 | 
					                                      is not supported
 | 
				
			||||||
 | 
					**/
 | 
				
			||||||
 | 
					RETURN_STATUS
 | 
				
			||||||
 | 
					EFIAPI
 | 
				
			||||||
 | 
					InternalMemEncryptSevClearMmioPageEncMask (
 | 
				
			||||||
 | 
					  IN  PHYSICAL_ADDRESS        Cr3BaseAddress,
 | 
				
			||||||
 | 
					  IN  PHYSICAL_ADDRESS        PhysicalAddress,
 | 
				
			||||||
 | 
					  IN  UINTN                   Length
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user