Reviewed-by: Ray Ni <[email protected]> Thanks, Ray > -----Original Message----- > From: Zhou, Jianfeng <[email protected]> > Sent: Wednesday, February 21, 2024 9:25 AM > To: [email protected] > Cc: Zhou, Jianfeng <[email protected]>; Ni, Ray <[email protected]>; > Laszlo Ersek <[email protected]>; Kumar, Rahul R > <[email protected]>; Gerd Hoffmann <[email protected]> > Subject: [PATCH] UefiCpuPkg: add volatile qualifier to page table related > variable > > Add volatile qualifier to page table related variable to prevent > compiler from optimizing away the variables which may lead to > unexpected result. > > Signed-off-by: Zhou Jianfeng <[email protected]> > Cc: Ray Ni <[email protected]> > Cc: Laszlo Ersek <[email protected]> > Cc: Rahul Kumar <[email protected]> > Cc: Gerd Hoffmann <[email protected]> > --- > UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c | 12 > ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c > b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c > index 2ea40666cc..5cf6e8fea0 100644 > --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c > +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c > @@ -26,7 +26,7 @@ PageTableLibSetPte4K ( > IN IA32_MAP_ATTRIBUTE *Mask > > ) > > { > > - IA32_PTE_4K LocalPte4K; > > + volatile IA32_PTE_4K LocalPte4K; > > > > LocalPte4K.Uint64 = Pte4K->Uint64; > > if (Mask->Bits.PageTableBaseAddressLow || > Mask->Bits.PageTableBaseAddressHigh) { > > @@ -78,7 +78,7 @@ PageTableLibSetPte4K ( > } > > > > if (Pte4K->Uint64 != LocalPte4K.Uint64) { > > - Pte4K->Uint64 = LocalPte4K.Uint64; > > + *(volatile UINT64 *)&(Pte4K->Uint64) = LocalPte4K.Uint64; > > } > > } > > > > @@ -100,7 +100,7 @@ PageTableLibSetPleB ( > IN IA32_MAP_ATTRIBUTE *Mask > > ) > > { > > - IA32_PAGE_LEAF_ENTRY_BIG_PAGESIZE LocalPleB; > > + volatile IA32_PAGE_LEAF_ENTRY_BIG_PAGESIZE LocalPleB; > > > > LocalPleB.Uint64 = PleB->Uint64; > > if (Mask->Bits.PageTableBaseAddressLow || > Mask->Bits.PageTableBaseAddressHigh) { > > @@ -154,7 +154,7 @@ PageTableLibSetPleB ( > } > > > > if (PleB->Uint64 != LocalPleB.Uint64) { > > - PleB->Uint64 = LocalPleB.Uint64; > > + *(volatile UINT64 *)&(PleB->Uint64) = LocalPleB.Uint64; > > } > > } > > > > @@ -200,7 +200,7 @@ PageTableLibSetPnle ( > IN IA32_MAP_ATTRIBUTE *Mask > > ) > > { > > - IA32_PAGE_NON_LEAF_ENTRY LocalPnle; > > + volatile IA32_PAGE_NON_LEAF_ENTRY LocalPnle; > > > > LocalPnle.Uint64 = Pnle->Uint64; > > if (Mask->Bits.Present) { > > @@ -231,7 +231,7 @@ PageTableLibSetPnle ( > LocalPnle.Bits.WriteThrough = 0; > > LocalPnle.Bits.CacheDisabled = 0; > > if (Pnle->Uint64 != LocalPnle.Uint64) { > > - Pnle->Uint64 = LocalPnle.Uint64; > > + *(volatile UINT64 *)&(Pnle->Uint64) = LocalPnle.Uint64; > > } > > } > > > > -- > 2.31.1.windows.1
-=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115712): https://edk2.groups.io/g/devel/message/115712 Mute This Topic: https://groups.io/mt/104483610/21656 Group Owner: [email protected] Unsubscribe: https://edk2.groups.io/g/devel/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
