From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 4C542D80CF6 for ; Wed, 21 Feb 2024 22:22:18 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=7Niz/+SiLM4QDMtTra5TNwHSOhgkoxGZ4uz+Y0HzrhU=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1708554136; v=1; b=UVbzNZYQ/cIXPkDW6jvnXxGsl5KhUDlxlTf9vLlARrqCauQdlKv52xEouJNFdlLKGPUTQY8y 6cMW12mru5lsglF8yXEx0q3mRLNBfe2TMY9ae8xkQOwGcKSQO/2190oghKJGWpYXgH44PHW13QS bNUo6UeWuAgsGEVAhrKOJb54= X-Received: by 127.0.0.2 with SMTP id 0OzwYY7687511xFT0Z8z40e1; Wed, 21 Feb 2024 14:22:16 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) by mx.groups.io with SMTP id smtpd.web10.3347.1708478718957299010 for ; Tue, 20 Feb 2024 17:25:19 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10990"; a="2485439" X-IronPort-AV: E=Sophos;i="6.06,174,1705392000"; d="scan'208";a="2485439" X-Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Feb 2024 17:25:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,174,1705392000"; d="scan'208";a="5269593" X-Received: from zhouji3x-z238.sh.intel.com (HELO zj3-desktop.ccr.corp.intel.com) ([10.239.152.99]) by orviesa007.jf.intel.com with ESMTP; 20 Feb 2024 17:25:17 -0800 From: Zhou Jianfeng To: devel@edk2.groups.io Cc: Zhou Jianfeng , Ray Ni , Laszlo Ersek , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH] UefiCpuPkg: add volatile qualifier to page table related variable Date: Wed, 21 Feb 2024 09:25:13 +0800 Message-Id: <20240221012513.27453-1-jianfeng.zhou@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,jianfeng.zhou@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 1TqhhTwZBuk6TFq5E85zy9ukx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=UVbzNZYQ; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none) 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 Cc: Ray Ni Cc: Laszlo Ersek Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c b/UefiCpu= Pkg/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=0D )=0D {=0D - IA32_PTE_4K LocalPte4K;=0D + volatile IA32_PTE_4K LocalPte4K;=0D =0D LocalPte4K.Uint64 =3D Pte4K->Uint64;=0D if (Mask->Bits.PageTableBaseAddressLow || Mask->Bits.PageTableBaseAddres= sHigh) {=0D @@ -78,7 +78,7 @@ PageTableLibSetPte4K ( }=0D =0D if (Pte4K->Uint64 !=3D LocalPte4K.Uint64) {=0D - Pte4K->Uint64 =3D LocalPte4K.Uint64;=0D + *(volatile UINT64 *)&(Pte4K->Uint64) =3D LocalPte4K.Uint64;=0D }=0D }=0D =0D @@ -100,7 +100,7 @@ PageTableLibSetPleB ( IN IA32_MAP_ATTRIBUTE *Mask=0D )=0D {=0D - IA32_PAGE_LEAF_ENTRY_BIG_PAGESIZE LocalPleB;=0D + volatile IA32_PAGE_LEAF_ENTRY_BIG_PAGESIZE LocalPleB;=0D =0D LocalPleB.Uint64 =3D PleB->Uint64;=0D if (Mask->Bits.PageTableBaseAddressLow || Mask->Bits.PageTableBaseAddres= sHigh) {=0D @@ -154,7 +154,7 @@ PageTableLibSetPleB ( }=0D =0D if (PleB->Uint64 !=3D LocalPleB.Uint64) {=0D - PleB->Uint64 =3D LocalPleB.Uint64;=0D + *(volatile UINT64 *)&(PleB->Uint64) =3D LocalPleB.Uint64;=0D }=0D }=0D =0D @@ -200,7 +200,7 @@ PageTableLibSetPnle ( IN IA32_MAP_ATTRIBUTE *Mask=0D )=0D {=0D - IA32_PAGE_NON_LEAF_ENTRY LocalPnle;=0D + volatile IA32_PAGE_NON_LEAF_ENTRY LocalPnle;=0D =0D LocalPnle.Uint64 =3D Pnle->Uint64;=0D if (Mask->Bits.Present) {=0D @@ -231,7 +231,7 @@ PageTableLibSetPnle ( LocalPnle.Bits.WriteThrough =3D 0;=0D LocalPnle.Bits.CacheDisabled =3D 0;=0D if (Pnle->Uint64 !=3D LocalPnle.Uint64) {=0D - Pnle->Uint64 =3D LocalPnle.Uint64;=0D + *(volatile UINT64 *)&(Pnle->Uint64) =3D LocalPnle.Uint64;=0D }=0D }=0D =0D -- 2.31.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115747): https://edk2.groups.io/g/devel/message/115747 Mute This Topic: https://groups.io/mt/104483610/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-