From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by mx.groups.io with SMTP id smtpd.web12.5266.1622188279045326011 for ; Fri, 28 May 2021 00:51:19 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@google.com header.s=20161025 header.b=WZRlgER/; spf=pass (domain: google.com, ip: 209.85.210.173, mailfrom: erdemaktas@google.com) Received: by mail-pf1-f173.google.com with SMTP id d78so2605457pfd.10 for ; Fri, 28 May 2021 00:51:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=g4UmcmpY5DHsekZmNitKB5Q7OU5I2trLE+B3psQZLpM=; b=WZRlgER/dqxeSs2fqavjw7KfKXan4tEdzTcm8J6pj75OoIV84UQe60LlkvqmwRNHZu cQBowo6lmny3fI3C0wzTWxcRfmZGNFwRC2e0KFMj9NyrKxRM24NA0W0Grzn+kIrbtsPn gJx6kpMTQ75XJ69xX0h1gX6zhv7wgR0TCiezbehnTCQCoFSHp4ToTkPtQBv5Lvx8Mf5Y aaizPU2/FEZLbg8tAxlRdMnLdD5TUgigOL96MXivCHklrt6jSPiI/byUR8hBogEk0CQ1 mk7FvjcBGmZh61zMhLUKEURpTGdHtrCYMR+7K59l0OQiKcyNbphYT9APgt/oan4UVpYl 8r0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=g4UmcmpY5DHsekZmNitKB5Q7OU5I2trLE+B3psQZLpM=; b=k+/qaWQWHJz39Cx6dw8judGqUgqfc6t+mcnj/+/fkq0T63X7DDk8mK48+Rf2ePerzh mMNZQuT+xjklNlpJjJ+ERAwlnpoUpMJgKSmsvWC9qDySsGXEVHgHlbAHMbtbr0b2wEI3 PqhBxcTcv8rXLg6wVESc5nRu+ugvhLWAX9RvNW/qTOnUKUWQtEfmvjBetCoHdmHT3Z65 9LTOvqUmErOBLMjdg6IXiyA8dz1ek3hXuXS7bl/LH8g5LSBHFy5qx49ivXwCRI/glaFb maZL9bXjDOEt8bB2vnn8OrbCWPFAVdUxqF+ybyYsB8y2+L4kHeOjm63YcLHvq7xU/xC7 M+CA== X-Gm-Message-State: AOAM533tGX1f+WpU+RXFhQY7M7qA5319/6UYKDY4iPgz3mTk2scNZ5wx E7LwY3s9DkDwn04vhQOS2gfr9YImbM/FxPCt4JmRog== X-Google-Smtp-Source: ABdhPJwewm2GLKhKOaD8UDzRSKh51oXXiOVa8oerI0u94EU6eXmqhvYwKE0Wd8vWg0MTAbO/D43P/D1nJEO7Yz8d3Uc= X-Received: by 2002:a63:7a0f:: with SMTP id v15mr7677776pgc.100.1622188278254; Fri, 28 May 2021 00:51:18 -0700 (PDT) MIME-Version: 1.0 References: <20210519181949.6574-1-brijesh.singh@amd.com> <20210519181949.6574-10-brijesh.singh@amd.com> In-Reply-To: <20210519181949.6574-10-brijesh.singh@amd.com> From: "Erdem Aktas" Date: Fri, 28 May 2021 00:51:07 -0700 Message-ID: Subject: Re: [PATCH v3 09/13] OvmfPkg/BaseMemEncryptSevLib: introduce MemEncryptSevClearMmioPageEncMask() To: Brijesh Singh Cc: devel@edk2.groups.io, James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Laszlo Ersek Content-Type: text/plain; charset="UTF-8" > + @param[in] BaseAddress The physical address that is the start > + address of a MMIO region. Based on the code, what I understand is that the address parameters should be "guest virtual address", not the physical address. But in this patch, all the address parameters are named as PhysicalAddress. Is this intentional? -Erdem On Wed, May 19, 2021 at 11:20 AM 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 simplified version of > 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 > Reviewed-by: Laszlo Ersek > 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 +++++++++++++++++++ > .../X64/SecVirtualMemory.c | 30 +++++++++++++++++ > 6 files changed, 175 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 > + ); > +} > diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecVirtualMemory.c b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecVirtualMemory.c > index bca5e3febb1b..e0d3a15e8503 100644 > --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecVirtualMemory.c > +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecVirtualMemory.c > @@ -98,3 +98,33 @@ InternalMemEncryptSevSetMemoryEncrypted ( > // > 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; > +} > -- > 2.17.1 >