From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 19458202E53DC for ; Tue, 26 Jun 2018 23:01:00 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jun 2018 23:00:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,278,1526367600"; d="scan'208";a="235930390" Received: from ray-dev.ccr.corp.intel.com (HELO [10.239.9.4]) ([10.239.9.4]) by orsmga005.jf.intel.com with ESMTP; 26 Jun 2018 23:00:36 -0700 To: edk2-devel@lists.01.org References: <20180625025402.201636-1-ruiyu.ni@intel.com> <4DFBB17A-3FCF-448D-B8F0-C4D66A33CF9F@apple.com> From: "Ni, Ruiyu" Message-ID: Date: Wed, 27 Jun 2018 14:00:57 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Subject: Re: [PATCH] UefiCpuPkg/MpInitLib: AP uses memory preceding IDT to store CpuMpData X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Jun 2018 06:01:00 -0000 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit On 6/27/2018 2:57 AM, Laszlo Ersek wrote: > Second, even assuming that PushCpuMpData() and PopCpuMpData() are > atomic, the order in which APs complete the AP procedure is not > deterministic, and it need not be the exact reverse of the entry order. > We may have the following order, for example: > > - AP 1 writes CpuMpData, and saves the original PEI services pointer on > its stack, > - AP 2 writes CpuMpData, and saves the same CpuMpData value (originally > written by AP 1) on its stack, > - AP 1 completes the AP procedure and restores the original PEI services > pointer from its stack, > - AP 2 completes the AP procedure, and overwrites the PEI services > pointer, with the CpuMpData value from its stack, that was originally > written by AP 1. > Thanks for the analysis. It's a stupid bug that I should be aware of. That can also explain why I cannot reproduce it. It's random. > Assuming I (remotely) understand what's going on, I'd (vaguely) suggest > three alternatives: > > - instead of the idea captured in this patch, we should use an APIC ID > search similar to the one done initially in "MpFuncs.nasm", Don't understand. Can you kindly explain more? > > - or else, we should stick with the current idea, but use atomic > compare-and-swap operations, so that the original PEI services pointer > value be restored ultimately, at the least, I like this idea. Will generate the V2 patch. > > - or else (possibly the simplest fix), allocate a separate IDT for each > AP, including the UINTN that precedes the (now AP-specific) IDT. This > means that the PEI services pointer*location* would be separate for > each AP, and no contention would occur. I think it's the most complicated fix:) -- Thanks, Ray