OvmfPkg/MemEncryptSevLib: skip page state change for Mmio address
The SetMemoryEncDec() is used by the higher level routines to set or clear the page encryption mask for system RAM and Mmio address. When SEV-SNP is active, in addition to set/clear page mask it also updates the RMP table. The RMP table updates are required for the system RAM address and not the Mmio address. Add a new parameter in SetMemoryEncDec() to tell whether the specified address is Mmio. If its Mmio then skip the page state change in the RMP table. Cc: Michael Roth <michael.roth@amd.com> 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: Erdem Aktas <erdemaktas@google.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com> Acked-by: Jiewen Yao <Jiewen.yao@intel.com> Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
This commit is contained in:
		
				
					committed by
					
						
						mergify[bot]
					
				
			
			
				
	
			
			
			
						parent
						
							b928eb44d5
						
					
				
				
					commit
					b7b8872031
				
			@@ -671,6 +671,7 @@ Done:
 | 
				
			|||||||
  @param[in]  Mode                    Set or Clear mode
 | 
					  @param[in]  Mode                    Set or Clear mode
 | 
				
			||||||
  @param[in]  CacheFlush              Flush the caches before applying the
 | 
					  @param[in]  CacheFlush              Flush the caches before applying the
 | 
				
			||||||
                                      encryption mask
 | 
					                                      encryption mask
 | 
				
			||||||
 | 
					  @param[in]  Mmio                    The physical address specified is Mmio
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @retval RETURN_SUCCESS              The attributes were cleared for the
 | 
					  @retval RETURN_SUCCESS              The attributes were cleared for the
 | 
				
			||||||
                                      memory region.
 | 
					                                      memory region.
 | 
				
			||||||
@@ -686,7 +687,8 @@ SetMemoryEncDec (
 | 
				
			|||||||
  IN    PHYSICAL_ADDRESS  PhysicalAddress,
 | 
					  IN    PHYSICAL_ADDRESS  PhysicalAddress,
 | 
				
			||||||
  IN    UINTN             Length,
 | 
					  IN    UINTN             Length,
 | 
				
			||||||
  IN    MAP_RANGE_MODE    Mode,
 | 
					  IN    MAP_RANGE_MODE    Mode,
 | 
				
			||||||
  IN    BOOLEAN           CacheFlush
 | 
					  IN    BOOLEAN           CacheFlush,
 | 
				
			||||||
 | 
					  IN    BOOLEAN           Mmio
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  PAGE_MAP_AND_DIRECTORY_POINTER  *PageMapLevel4Entry;
 | 
					  PAGE_MAP_AND_DIRECTORY_POINTER  *PageMapLevel4Entry;
 | 
				
			||||||
@@ -709,14 +711,15 @@ SetMemoryEncDec (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  DEBUG ((
 | 
					  DEBUG ((
 | 
				
			||||||
    DEBUG_VERBOSE,
 | 
					    DEBUG_VERBOSE,
 | 
				
			||||||
    "%a:%a: Cr3Base=0x%Lx Physical=0x%Lx Length=0x%Lx Mode=%a CacheFlush=%u\n",
 | 
					    "%a:%a: Cr3Base=0x%Lx Physical=0x%Lx Length=0x%Lx Mode=%a CacheFlush=%u Mmio=%u\n",
 | 
				
			||||||
    gEfiCallerBaseName,
 | 
					    gEfiCallerBaseName,
 | 
				
			||||||
    __FUNCTION__,
 | 
					    __FUNCTION__,
 | 
				
			||||||
    Cr3BaseAddress,
 | 
					    Cr3BaseAddress,
 | 
				
			||||||
    PhysicalAddress,
 | 
					    PhysicalAddress,
 | 
				
			||||||
    (UINT64)Length,
 | 
					    (UINT64)Length,
 | 
				
			||||||
    (Mode == SetCBit) ? "Encrypt" : "Decrypt",
 | 
					    (Mode == SetCBit) ? "Encrypt" : "Decrypt",
 | 
				
			||||||
    (UINT32)CacheFlush
 | 
					    (UINT32)CacheFlush,
 | 
				
			||||||
 | 
					    (UINT32)Mmio
 | 
				
			||||||
    ));
 | 
					    ));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  //
 | 
					  //
 | 
				
			||||||
@@ -758,7 +761,7 @@ SetMemoryEncDec (
 | 
				
			|||||||
  //
 | 
					  //
 | 
				
			||||||
  // The InternalSetPageState() is used for setting the page state in the RMP table.
 | 
					  // The InternalSetPageState() is used for setting the page state in the RMP table.
 | 
				
			||||||
  //
 | 
					  //
 | 
				
			||||||
  if ((Mode == ClearCBit) && MemEncryptSevSnpIsEnabled ()) {
 | 
					  if (!Mmio && (Mode == ClearCBit) && MemEncryptSevSnpIsEnabled ()) {
 | 
				
			||||||
    InternalSetPageState (PhysicalAddress, EFI_SIZE_TO_PAGES (Length), SevSnpPageShared, FALSE);
 | 
					    InternalSetPageState (PhysicalAddress, EFI_SIZE_TO_PAGES (Length), SevSnpPageShared, FALSE);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -996,7 +999,8 @@ InternalMemEncryptSevSetMemoryDecrypted (
 | 
				
			|||||||
           PhysicalAddress,
 | 
					           PhysicalAddress,
 | 
				
			||||||
           Length,
 | 
					           Length,
 | 
				
			||||||
           ClearCBit,
 | 
					           ClearCBit,
 | 
				
			||||||
           TRUE
 | 
					           TRUE,
 | 
				
			||||||
 | 
					           FALSE
 | 
				
			||||||
           );
 | 
					           );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1029,7 +1033,8 @@ InternalMemEncryptSevSetMemoryEncrypted (
 | 
				
			|||||||
           PhysicalAddress,
 | 
					           PhysicalAddress,
 | 
				
			||||||
           Length,
 | 
					           Length,
 | 
				
			||||||
           SetCBit,
 | 
					           SetCBit,
 | 
				
			||||||
           TRUE
 | 
					           TRUE,
 | 
				
			||||||
 | 
					           FALSE
 | 
				
			||||||
           );
 | 
					           );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1062,6 +1067,7 @@ InternalMemEncryptSevClearMmioPageEncMask (
 | 
				
			|||||||
           PhysicalAddress,
 | 
					           PhysicalAddress,
 | 
				
			||||||
           Length,
 | 
					           Length,
 | 
				
			||||||
           ClearCBit,
 | 
					           ClearCBit,
 | 
				
			||||||
           FALSE
 | 
					           FALSE,
 | 
				
			||||||
 | 
					           TRUE
 | 
				
			||||||
           );
 | 
					           );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user