From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web09.17699.1646032885667369347 for ; Sun, 27 Feb 2022 23:22:27 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=afBCLUpU; spf=pass (domain: intel.com, ip: 134.134.136.24, 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=1646032946; x=1677568946; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=groiRdo+TngrJpQC3hJTa5wIn1g+k+xns4QhlUTh47M=; b=afBCLUpUjMsolbT8zgdP1wAtalsc+gw3YBeV6EwTWyWTimCcgYqBLtbe UocXVzysPg79CHLO7e0O9WisC7i/z1slircagmnFiUiMX+GFp9HpTDi5V RhmEZr9RM5v1UgiVxlla0GxCqWrGXqo1pAg51eBEPBspWFuhfgt0p1RHN BL3U7Ln91XeVJkyEdTq2R+riSdTwAw8ASUClGlp/TP8XwrBw7GSjdAC/n vDA/T+7L2OLQm/3NudgpTjOraUam2fquUo2YwXQUt1ueJ7gOdwXI/8SAU 6CAqAnEof46y2q5DgAITzG/Hxifqh3OjgC1L6oxaeclA89u5Vr2nXDRLP g==; X-IronPort-AV: E=McAfee;i="6200,9189,10271"; a="252552971" X-IronPort-AV: E=Sophos;i="5.90,142,1643702400"; d="scan'208";a="252552971" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2022 23:22:26 -0800 X-IronPort-AV: E=Sophos;i="5.90,142,1643702400"; d="scan'208";a="534341152" Received: from mxu9-mobl1.ccr.corp.intel.com ([10.238.2.184]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2022 23:22:24 -0800 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 V7 22/37] OvmfPkg/Sec: Declare local variable as volatile in SecCoreStartupWithStack Date: Mon, 28 Feb 2022 15:20:54 +0800 Message-Id: <7f43f86687273eb4cabf6e1057783e13bdd7b99e.1646031164.git.min.m.xu@intel.com> X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: References: 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 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