From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web11.19719.1661396118095781814 for ; Wed, 24 Aug 2022 19:55:22 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=S894nHqy; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: zhiguang.liu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661396122; x=1692932122; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3+ZMIsIkJoBm3+kNz/XLTaqFWviS15jNp7yGBcuidI4=; b=S894nHqyVXVfslGrM8KVYcAum5bRv1JqRwCUoHMRcc+PrII7S4AU0mrq y4oaVqfewCXxAy8n+tZ2qdUz8bey9TfCltd1+BHEVie7X13Fv2mOmhrTt AwQ0wsWj0qewX/BC0UJo2gzypBmqQY2PbeGR3VCPjtnhgt0k+IZyNGaVr uyPxXvxZetAY1sa2SSA3fDZKv3cpgaW3xNT1VKlcYhaIvzQmpz1kR6xeZ BxfOI1B3oqXekJssW8KbKpHk0hoAOdXy75WEdxNQhWhGi9LiNu4Z+dlIY H7x9vCQYuKpqAnXJeC7h38tY6E+gUTbypaE/0uSAbCuEiUBLcNmPrxPOs w==; X-IronPort-AV: E=McAfee;i="6500,9779,10449"; a="355855725" X-IronPort-AV: E=Sophos;i="5.93,262,1654585200"; d="scan'208";a="355855725" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2022 19:55:22 -0700 X-IronPort-AV: E=Sophos;i="5.93,262,1654585200"; d="scan'208";a="670782645" Received: from shwdesfp01.ccr.corp.intel.com ([10.239.158.151]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Aug 2022 19:55:20 -0700 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Zhiguang Liu , Eric Dong , Ray Ni , Rahul Kumar Subject: [PATCH] UefiCpuPkg/MpInitLib: Fix potential issue when IDT table is at above 4G Date: Thu, 25 Aug 2022 10:55:04 +0800 Message-Id: <20220825025506.2323-2-zhiguang.liu@intel.com> X-Mailer: git-send-email 2.31.1.windows.1 In-Reply-To: <20220825025506.2323-1-zhiguang.liu@intel.com> References: <20220825025506.2323-1-zhiguang.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Currently, when waking up AP, IDT table of AP will be set in 16 bit code, and assume the IDT table base is 32 bit. However, the IDT table is created by BSP. Issue will happen if the BSP allocates memory above 4G for BSP's IDT table. Moreover, even the IDT table location is below 4G, the handler function inside the IDT table is 64 bit, and it won't take effect until CPU transfers to 64 bit long mode. There is no benefit to set IDT table in such an early phase. To avoid such issue, this patch moves the LIDT instruction into 64 bit code. Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Signed-off-by: Zhiguang Liu --- UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm index 1daaa72b1e..cd95b03da8 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm @@ -64,9 +64,6 @@ BITS 16 mov si, MP_CPU_EXCHANGE_INFO_FIELD (GdtrProfile) o32 lgdt [cs:si] - mov si, MP_CPU_EXCHANGE_INFO_FIELD (IdtrProfile) -o32 lidt [cs:si] - ; ; Switch to protected mode ; @@ -154,6 +151,11 @@ BITS 64 LongModeStart: mov esi, ebx + + ; Set IDT table at the start of 64 bit code + lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (IdtrProfile)] + lidt [edi] + lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (InitFlag)] cmp qword [edi], 1 ; ApInitConfig jnz GetApicId -- 2.31.1.windows.1