public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH v2 2/2] UefiCpuPkg/CpuMpPei: Don't write CR3 in ConvertMemoryPageToNotPresent
@ 2024-01-17  6:22 Zhiguang Liu
  2024-01-17 10:24 ` Laszlo Ersek
  0 siblings, 1 reply; 3+ messages in thread
From: Zhiguang Liu @ 2024-01-17  6:22 UTC (permalink / raw)
  To: devel; +Cc: Zhiguang Liu, Ray Ni, Laszlo Ersek, Rahul Kumar, Gerd Hoffmann

The purpose of writing CR3 in ConvertMemoryPageToNotPresent is just
to flush TLB, because CR3 won't be changed in function
ConvertMemoryPageToNotPresent.
After ConvertMemoryPageToNotPresent, there is always a flush TLB
function. Also, because ConvertMemoryPageToNotPresent in called in a
loop, to improve performance, there is no need to flush TLB
inside ConvertMemoryPageToNotPresent. Just flushing TLB after the loop
is enough.

Cc: Ray Ni <ray.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
---
 UefiCpuPkg/CpuMpPei/CpuPaging.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/UefiCpuPkg/CpuMpPei/CpuPaging.c b/UefiCpuPkg/CpuMpPei/CpuPaging.c
index 15c7015fb8..b923d9b502 100644
--- a/UefiCpuPkg/CpuMpPei/CpuPaging.c
+++ b/UefiCpuPkg/CpuMpPei/CpuPaging.c
@@ -76,7 +76,8 @@ AllocatePageTableMemory (
 
 /**
   This function modifies the page attributes for the memory region specified
-  by BaseAddress and Length to not present.
+  by BaseAddress and Length to not present. This function only change page
+  table, but not flush TLB. Caller have the responsbility to flush TLB.
 
   Caller should make sure BaseAddress and Length is at page boundary.
 
@@ -167,7 +168,6 @@ ConvertMemoryPageToNotPresent (
   }
 
   ASSERT_EFI_ERROR (Status);
-  AsmWriteCr3 (PageTable);
   return Status;
 }
 
-- 
2.31.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113929): https://edk2.groups.io/g/devel/message/113929
Mute This Topic: https://groups.io/mt/103781133/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] [PATCH v2 2/2] UefiCpuPkg/CpuMpPei: Don't write CR3 in ConvertMemoryPageToNotPresent
  2024-01-17  6:22 [edk2-devel] [PATCH v2 2/2] UefiCpuPkg/CpuMpPei: Don't write CR3 in ConvertMemoryPageToNotPresent Zhiguang Liu
@ 2024-01-17 10:24 ` Laszlo Ersek
  2024-01-18  5:11   ` Ni, Ray
  0 siblings, 1 reply; 3+ messages in thread
From: Laszlo Ersek @ 2024-01-17 10:24 UTC (permalink / raw)
  To: devel, zhiguang.liu; +Cc: Ray Ni, Rahul Kumar, Gerd Hoffmann

On 1/17/24 07:22, Zhiguang Liu wrote:
> The purpose of writing CR3 in ConvertMemoryPageToNotPresent is just
> to flush TLB, because CR3 won't be changed in function
> ConvertMemoryPageToNotPresent.
> After ConvertMemoryPageToNotPresent, there is always a flush TLB
> function. Also, because ConvertMemoryPageToNotPresent in called in a
> loop, to improve performance, there is no need to flush TLB
> inside ConvertMemoryPageToNotPresent. Just flushing TLB after the loop
> is enough.
> 
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
> ---
>  UefiCpuPkg/CpuMpPei/CpuPaging.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/UefiCpuPkg/CpuMpPei/CpuPaging.c b/UefiCpuPkg/CpuMpPei/CpuPaging.c
> index 15c7015fb8..b923d9b502 100644
> --- a/UefiCpuPkg/CpuMpPei/CpuPaging.c
> +++ b/UefiCpuPkg/CpuMpPei/CpuPaging.c
> @@ -76,7 +76,8 @@ AllocatePageTableMemory (
>  
>  /**
>    This function modifies the page attributes for the memory region specified
> -  by BaseAddress and Length to not present.
> +  by BaseAddress and Length to not present. This function only change page
> +  table, but not flush TLB. Caller have the responsbility to flush TLB.
>  
>    Caller should make sure BaseAddress and Length is at page boundary.
>  
> @@ -167,7 +168,6 @@ ConvertMemoryPageToNotPresent (
>    }
>  
>    ASSERT_EFI_ERROR (Status);
> -  AsmWriteCr3 (PageTable);
>    return Status;
>  }
>  

Reviewed-by: Laszlo Ersek <lersek@redhat.com>



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113946): https://edk2.groups.io/g/devel/message/113946
Mute This Topic: https://groups.io/mt/103781133/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] [PATCH v2 2/2] UefiCpuPkg/CpuMpPei: Don't write CR3 in ConvertMemoryPageToNotPresent
  2024-01-17 10:24 ` Laszlo Ersek
@ 2024-01-18  5:11   ` Ni, Ray
  0 siblings, 0 replies; 3+ messages in thread
From: Ni, Ray @ 2024-01-18  5:11 UTC (permalink / raw)
  To: Laszlo Ersek, devel@edk2.groups.io, Liu, Zhiguang
  Cc: Kumar, Rahul R, Gerd Hoffmann

Reviewed-by: Ray Ni <Ray.ni@intel.com>

Thanks,
Ray
> -----Original Message-----
> From: Laszlo Ersek <lersek@redhat.com>
> Sent: Wednesday, January 17, 2024 6:24 PM
> To: devel@edk2.groups.io; Liu, Zhiguang <zhiguang.liu@intel.com>
> Cc: Ni, Ray <ray.ni@intel.com>; Kumar, Rahul R <rahul.r.kumar@intel.com>;
> Gerd Hoffmann <kraxel@redhat.com>
> Subject: Re: [edk2-devel] [PATCH v2 2/2] UefiCpuPkg/CpuMpPei: Don't write
> CR3 in ConvertMemoryPageToNotPresent
> 
> On 1/17/24 07:22, Zhiguang Liu wrote:
> > The purpose of writing CR3 in ConvertMemoryPageToNotPresent is just
> > to flush TLB, because CR3 won't be changed in function
> > ConvertMemoryPageToNotPresent.
> > After ConvertMemoryPageToNotPresent, there is always a flush TLB
> > function. Also, because ConvertMemoryPageToNotPresent in called in a
> > loop, to improve performance, there is no need to flush TLB
> > inside ConvertMemoryPageToNotPresent. Just flushing TLB after the loop
> > is enough.
> >
> > Cc: Ray Ni <ray.ni@intel.com>
> > Cc: Laszlo Ersek <lersek@redhat.com>
> > Cc: Rahul Kumar <rahul1.kumar@intel.com>
> > Cc: Gerd Hoffmann <kraxel@redhat.com>
> > Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
> > ---
> >  UefiCpuPkg/CpuMpPei/CpuPaging.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/UefiCpuPkg/CpuMpPei/CpuPaging.c
> b/UefiCpuPkg/CpuMpPei/CpuPaging.c
> > index 15c7015fb8..b923d9b502 100644
> > --- a/UefiCpuPkg/CpuMpPei/CpuPaging.c
> > +++ b/UefiCpuPkg/CpuMpPei/CpuPaging.c
> > @@ -76,7 +76,8 @@ AllocatePageTableMemory (
> >
> >  /**
> >    This function modifies the page attributes for the memory region
> specified
> > -  by BaseAddress and Length to not present.
> > +  by BaseAddress and Length to not present. This function only change
> page
> > +  table, but not flush TLB. Caller have the responsbility to flush TLB.
> >
> >    Caller should make sure BaseAddress and Length is at page boundary.
> >
> > @@ -167,7 +168,6 @@ ConvertMemoryPageToNotPresent (
> >    }
> >
> >    ASSERT_EFI_ERROR (Status);
> > -  AsmWriteCr3 (PageTable);
> >    return Status;
> >  }
> >
> 
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#113985): https://edk2.groups.io/g/devel/message/113985
Mute This Topic: https://groups.io/mt/103781133/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-18  5:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-17  6:22 [edk2-devel] [PATCH v2 2/2] UefiCpuPkg/CpuMpPei: Don't write CR3 in ConvertMemoryPageToNotPresent Zhiguang Liu
2024-01-17 10:24 ` Laszlo Ersek
2024-01-18  5:11   ` Ni, Ray

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox