From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: john.e.lofgren@intel.com) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by groups.io with SMTP; Mon, 09 Sep 2019 11:40:55 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Sep 2019 11:40:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,486,1559545200"; d="scan'208";a="178435771" Received: from jelofgre-desk.amr.corp.intel.com ([10.78.26.249]) by orsmga008.jf.intel.com with ESMTP; 09 Sep 2019 11:40:54 -0700 From: "John E Lofgren" To: devel@edk2.groups.io Subject: [Patch V2] UefiCpuPkg/CpuExceptionHandlerLib: Fix #AC split lock Date: Mon, 9 Sep 2019 11:40:39 -0700 Message-Id: <20190909184039.1648-1-john.e.lofgren@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2150 V2 changes: Add xchg 16 bit instructions to handle sgdt and sidt base 63:48 bits and 47:32 bits. Add comment to explain why xchg 64bit isnt being used Fix #AC split lock's caused by seperating base and limit from sgdt and sidt by changing xchg operands to 32-bit to stop from crossing cacheline. Signed-off-by: John E Lofgren --- UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm index 4db1a09f28..7b7642b290 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm @@ -180,21 +180,29 @@ HasErrorCode: push qword [rbp + 24] ;; UINT64 Gdtr[2], Idtr[2]; + ; sidt and sgdt saves 10 bytes to memory, 8 bytes = base and 2 bytes = limit. + ; To avoid #AC split lock when separating base and limit into their + ; own separate 64 bit memory, we can’t use 64 bit xchg since base [63:48] bits + ; may cross the cache line. xor rax, rax push rax push rax sidt [rsp] - xchg rax, [rsp + 2] - xchg rax, [rsp] - xchg rax, [rsp + 8] + xchg eax, [rsp + 2] + xchg eax, [rsp] + xchg eax, [rsp + 8] + xchg ax, [rsp + 6] + xchg ax, [rsp + 4] xor rax, rax push rax push rax sgdt [rsp] - xchg rax, [rsp + 2] - xchg rax, [rsp] - xchg rax, [rsp + 8] + xchg eax, [rsp + 2] + xchg eax, [rsp] + xchg eax, [rsp + 8] + xchg ax, [rsp + 6] + xchg ax, [rsp + 4] ;; UINT64 Ldtr, Tr; xor rax, rax -- 2.16.2.windows.1