From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 79D5C210F30D1 for ; Thu, 16 Aug 2018 05:33:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B423B401EF05; Thu, 16 Aug 2018 12:33:58 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-198.rdu2.redhat.com [10.10.120.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D86816877; Thu, 16 Aug 2018 12:33:57 +0000 (UTC) To: "Wu, Hao A" , "edk2-devel@lists.01.org" Cc: "Yao, Jiewen" , "Dong, Eric" References: <20180810014348.32036-1-hao.a.wu@intel.com> <140b21ca-6bdf-af12-4f3f-d403ecd2f69e@redhat.com> From: Laszlo Ersek Message-ID: Date: Thu, 16 Aug 2018 14:33:57 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 16 Aug 2018 12:33:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 16 Aug 2018 12:33:58 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: Re: [PATCH 0/2] UefiCpuPkg: Add RSB stuffing before rsm instruction X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Aug 2018 12:33:59 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 08/16/18 05:07, Wu, Hao A wrote: >> -----Original Message----- >> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Laszlo >> Ersek >> Sent: Friday, August 10, 2018 11:06 PM >> (2) If I understand correctly, the same pattern is used everywhere -- a >> loop body is executed 32 times, and in the loop body, we jump (via >> subroutine calls) twice, and each call is followed by a "trap" for >> speculative execution. At the end of the loop, we forcefully unwind the >> stack, and then we proceed to RSM. >> >> I think this should be implemented with a lot less code duplication. >> NASM supports macros with labels that are local to macro *invocation* >> (not macro *definition*); please see the %%skip example here: >> >> https://www.nasm.us/doc/nasmdoc4.html >> 4.3.2 Macro-Local Labels >> >> In addition, it should be possible to pass parameters to macros, such as: >> - the register to use as counter (eax vs. rax), >> - the stack pointer to restore (esp vs. rsp), >> - the size of a stack frame (4 vs. 8) >> >> Using all those tools, it should be possible to define the macro only >> once, in a UefiCpuPkg-level ".inc" file (for example, >> "UefiCpuPkg/Include/StuffRsb.inc"), and then only invoke the macro near >> all 10 RSM instructions: > > Yes. Extracting the common logic to a INC file is a good idea. > > However, I found that when compiling .NASM files, the current build rule > does not support including files other than the .NASM file directory. > So including a package-level INC file is not supported at this moment. > > I have filed a Bugzilla for adding $(INC)-like support when compiling > .NASM files: > > https://bugzilla.tianocore.org/show_bug.cgi?id=1085 > > After some discussion with the BaseTools owners, some investigation is > needed for the above support. Hence, I plan to perform a 2-stage change > when extracting the common RSB stuffing logics to INC file: > > 1. Duplicate the INC file and place them together with the NASM files that > uses the RSB stuffing logics. > > 2. After NASM compiling support the $(INC)-like feature, propose another > patch to remove those duplicated INC files and create one under > UefiCpuPkg/Include/. > > Please help to share your thought on this. Thanks in advance. Sounds good to me. This approach still eliminates as much code duplication as it is possible at the current level of BaseTools support. Also we'll have a reminder (a BZ) for completing the unification. Thanks! Laszlo