From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web10.11022.1620731792246360189 for ; Tue, 11 May 2021 04:16:32 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FFmn7uEY; spf=pass (domain: redhat.com, ip: 216.205.24.124, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620731791; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QCkXQIAJFKjyGXCL4YtwAIbAeBI3ZZwJrKUWkghF27g=; b=FFmn7uEYOXoaNX5SEcJ62MF/Fcd9dVFUqitDr48GGnGobhhBEfW8BoEFbbRF/Ww6TL1A0/ DAfTo8jUqN2dcVEMnJfFo9phG2d2o+1+tKsOlnfycO1RrWf5eUNYux2/v4VGgEWfUjpTrd HF0nPR88aohRiG0sZiS5XWvDx1B4cWs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-435-fB0Tk6ZwN0Ck5y4YBs7tLA-1; Tue, 11 May 2021 07:16:28 -0400 X-MC-Unique: fB0Tk6ZwN0Ck5y4YBs7tLA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0D36ECC62C; Tue, 11 May 2021 11:16:26 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-112-233.ams2.redhat.com [10.36.112.233]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFB431037F24; Tue, 11 May 2021 11:16:21 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH 09/13] OvmfPkg/BaseMemEncryptSevLib: introduce MemEncryptSevClearMmioPageEncMask() To: devel@edk2.groups.io, brijesh.singh@amd.com Cc: James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Erdem Aktas References: <20210507203838.23706-1-brijesh.singh@amd.com> <20210507203838.23706-10-brijesh.singh@amd.com> From: "Laszlo Ersek" Message-ID: <61775788-57c1-db37-d6b1-2c2668567138@redhat.com> Date: Tue, 11 May 2021 13:16:20 +0200 MIME-Version: 1.0 In-Reply-To: <20210507203838.23706-10-brijesh.singh@amd.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 05/07/21 22:38, Brijesh Singh wrote: > 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 simplifies version of (1) s/simplifies/simplified/ Reviewed-by: Laszlo Ersek Thanks Laszlo > MemEncryptSevClearPageEncMask() -- it does not flush the caches after > clearing the page encryption mask. > > Cc: James Bottomley > Cc: Min Xu > Cc: Jiewen Yao > Cc: Tom Lendacky > Cc: Jordan Justen > Cc: Ard Biesheuvel > Cc: Laszlo Ersek > Cc: Erdem Aktas > Signed-off-by: Brijesh Singh > --- > OvmfPkg/Include/Library/MemEncryptSevLib.h | 25 ++++++++++++++ > .../BaseMemEncryptSevLib/X64/VirtualMemory.h | 23 +++++++++++++ > .../Ia32/MemEncryptSevLib.c | 31 +++++++++++++++++ > .../X64/MemEncryptSevLib.c | 33 +++++++++++++++++++ > .../X64/PeiDxeVirtualMemory.c | 33 +++++++++++++++++++ > 5 files changed, 145 insertions(+) > > diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/Library/MemEncryptSevLib.h > index 99f15a7d1271..b91490d5d44d 100644 > --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h > +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h > @@ -203,4 +203,29 @@ MemEncryptSevGetAddressRangeState ( > 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_ > diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h > index fe2a0b2826cd..8dc39e647b90 100644 > --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h > +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h > @@ -126,4 +126,27 @@ InternalMemEncryptSevGetAddressRangeState ( > 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 > diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c b/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c > index 12a5bf495bd7..169d3118e44f 100644 > --- a/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c > +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c > @@ -111,3 +111,34 @@ MemEncryptSevGetAddressRangeState ( > // > 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; > +} > diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c > index 4fea6a6be0ac..a2bf698bcde7 100644 > --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c > +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c > @@ -118,3 +118,36 @@ MemEncryptSevGetAddressRangeState ( > 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) > + ); > + > +} > diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c > index d3455e812bd1..a18d336a8789 100644 > --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c > +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c > @@ -891,3 +891,36 @@ InternalMemEncryptSevSetMemoryEncrypted ( > 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 > + ); > +} >