From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web09.4779.1648080680578717265 for ; Wed, 23 Mar 2022 17:12:23 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=ChCP3JjM; spf=pass (domain: intel.com, ip: 134.134.136.65, mailfrom: min.m.xu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648080743; x=1679616743; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NlWAyY85OIreNwrk6LOjEXb+p+ET2Oz35QjZfq1w614=; b=ChCP3JjMrpgf4yUjK6U8yXjEOgLyOiyocegZyNdKxUTJ0/IZ1PcE/Hea KCkin9J+uct+n8lsTEFUj3KuKLBxbVjYIi2/yKhwsZE3iRW/P0C92OxeL 6FqOsqHO238kyfKcPulUBCWAxIKa8Mk8J7TqBm2IPQXZDcSpj0jR3dj16 OCZCh8tBqTkd05Fc0HTgJkSd0KTKS0XUptRKhEyXo7gYBnmWsy2iV4Ns5 bzGA7Vz3BSr8w4xMOl4zfRbs2kKqvAEauClC6PaykuZLLuR5Iy1VZV5kZ XnSnde9Xm6jNi0mcXzOA6AYmfV1Ncq7HVNS4O0i0MRcgcX62O8CQ5091G g==; X-IronPort-AV: E=McAfee;i="6200,9189,10295"; a="258207674" X-IronPort-AV: E=Sophos;i="5.90,205,1643702400"; d="scan'208";a="258207674" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2022 17:12:23 -0700 X-IronPort-AV: E=Sophos;i="5.90,205,1643702400"; d="scan'208";a="649651434" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.255.31.90]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2022 17:12:20 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min Xu , Ard Biesheuvel , Jordan Justen , Brijesh Singh , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky , Gerd Hoffmann Subject: [PATCH V10 32/47] OvmfPkg/Sec: Declare local variable as volatile in SecCoreStartupWithStack Date: Thu, 24 Mar 2022 08:10:18 +0800 Message-Id: <20220324001033.1169-33-min.m.xu@intel.com> X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: <20220324001033.1169-1-min.m.xu@intel.com> References: <20220324001033.1169-1-min.m.xu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429 Declare the local variables in SecCoreStartupWithStack that actually move the data elements as volatile to prevent the optimizer from replacing this function with the intrinsic memcpy(). Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Gerd Hoffmann Acked-by: Gerd Hoffmann Signed-off-by: Min Xu --- OvmfPkg/Sec/SecMain.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index 2c5561661ef3..02520e25ab9a 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -757,12 +757,17 @@ SecCoreStartupWithStack ( // IdtTableInStack.PeiService = NULL; for (Index = 0; Index < SEC_IDT_ENTRY_COUNT; Index++) { - UINT8 *Src; - UINT8 *Dst; - UINTN Byte; + // + // Declare the local variables that actually move the data elements as + // volatile to prevent the optimizer from replacing this function with + // the intrinsic memcpy() + // + CONST UINT8 *Src; + volatile UINT8 *Dst; + UINTN Byte; - Src = (UINT8 *)&mIdtEntryTemplate; - Dst = (UINT8 *)&IdtTableInStack.IdtTable[Index]; + Src = (CONST UINT8 *)&mIdtEntryTemplate; + Dst = (volatile UINT8 *)&IdtTableInStack.IdtTable[Index]; for (Byte = 0; Byte < sizeof (mIdtEntryTemplate); Byte++) { Dst[Byte] = Src[Byte]; } -- 2.29.2.windows.2