public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: "Ni, Ruiyu" <ruiyu.ni@Intel.com>
Cc: edk2-devel@lists.01.org
Subject: Re: [PATCH] UefiCpuPkg/MpInitLib: AP uses memory preceding IDT to store CpuMpData
Date: Wed, 27 Jun 2018 14:00:06 +0200	[thread overview]
Message-ID: <efba1052-8196-ad9d-d89d-b8e2ea73a245@redhat.com> (raw)
In-Reply-To: <aa0a2d5f-d3e9-f001-4d20-380d7b623a5e@Intel.com>

On 06/27/18 08:00, Ni, Ruiyu wrote:
> 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?

Roughly, I figured that we could set the pre-IDT pointer on the BSP,
*before* starting up the APs, to a mapping table. The mapping table
would consist of two columns, the first containing the APIC ID (of each
CPU), the second containing AP-specific pointer values. Then, after
starting up the APs, each AP could locate its own row (based on APIC ID)
in the table, and the context pointer that belongs to it.

But, this is likely not useful, as we want to expose just the same one
pointer value to all APs together.

> 
>>
>> - 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:)

It might take the most code, but I guess it would be the simplest to
reason about. No data sharing --> no locking necessary, and no races
possible.

Anyway, I saw your v2 (just the subject, and your note that we should
ignore v2 for now). I'll stay tuned for v3.

Meta-question: some of your emails are apparently addressed to the list
only, and not CC'd to people who commented earlier on the thread. Did
you drop CCs deliberately, or is it some kind of mail agent glitch?

Thanks!
Laszlo


  reply	other threads:[~2018-06-27 12:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-25  2:54 [PATCH] UefiCpuPkg/MpInitLib: AP uses memory preceding IDT to store CpuMpData Ruiyu Ni
2018-06-25 16:01 ` Laszlo Ersek
2018-06-25 17:01   ` Laszlo Ersek
2018-06-26  7:50     ` Ni, Ruiyu
2018-06-26 12:52       ` Laszlo Ersek
2018-06-26 17:06 ` Laszlo Ersek
2018-06-26 17:20   ` Andrew Fish
2018-06-26 18:57     ` Laszlo Ersek
2018-06-27  6:00       ` Ni, Ruiyu
2018-06-27 12:00         ` Laszlo Ersek [this message]
2018-06-29  9:36           ` Ni, Ruiyu
2018-06-27  5:06     ` Ni, Ruiyu
2018-06-27  4:50   ` Ni, Ruiyu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=efba1052-8196-ad9d-d89d-b8e2ea73a245@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox