public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Wu, Jiaxin" <jiaxin.wu@intel.com>
To: Laszlo Ersek <lersek@redhat.com>, "Ni, Ray" <ray.ni@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "Dong, Eric" <eric.dong@intel.com>,
	"Zeng, Star" <star.zeng@intel.com>,
	Gerd Hoffmann <kraxel@redhat.com>,
	"Kumar, Rahul R" <rahul.r.kumar@intel.com>
Subject: Re: [edk2-devel] [PATCH v1 1/2] UefiCpuPkg/PiSmmCpuDxeSmm: Execute CET and XD check only on BSP
Date: Sun, 4 Feb 2024 00:50:14 +0000	[thread overview]
Message-ID: <MN0PR11MB6158637F542BDBF38A1F3D30FE402@MN0PR11MB6158.namprd11.prod.outlook.com> (raw)
In-Reply-To: <342b703f-0807-ceb1-78ba-443cc2833ee4@redhat.com>

> > I originally thought CheckFeatureSupported() when running in parallel when
> SMM base relocation is done in PEI
> > might corrupt the global variables.
> 
> That was / is my concern as well. That's why I asked Jiaxin if
> CheckFeatureSupported() was executed concurrently by multiple processors.
> 

Yes, Laszlo, CheckFeatureSupported is executed in parallel by multiple processors.


> > But then I realized the function only perform variable modification from
> TRUE to FALSE.
> > So even the code runs in parallel, it should be safe.
> 
> I too noticed that those transitions are all TRUE->FALSE, and (IIRC) all
> the variables are just BOOLEANs (so 1 byte).
> 
> Still, I don't like that (to be clear, I don't even like the pre-patch
> state):
> 
> - The global variables are not even marked volatile.
> - We don't use any locking, like interlocked exchange.
> - We do other things than just "mBoolean = FALSE": we patch instructions
> in the SMI assembly code, too.
> 
> All in all -- as long as this function can indeed run on multiple
> processors at the same time --, I think it would be much *cleaner* to:
> 
> - split the BSP-only functionality off of CheckFeatureSupported() --
> more importantly, off of SmmInitHandler. All that feature testing could
> be done in "single-threaded" code, could it not?
> 

I doubt the change to split the functionality check off of the SmmInitHandler. SmmInitHandler is called in SMI. I'm are not 100% sure the CET & XD & BTS features are same in non-smm & smm environment. If we move out of the smm environment, it might be have potential issue. Stay in SMI is more safe change.


> - if we need to check some feature on each processor in separation, and
> then build a big conjunction of those results in the end, then I find it
> better if the implementation actually follows this logic. Let the
> processors store their results in separate BOOLEAN elements of an array,
> and let the BSP go over the array once the APs have settled.
> 

I also thought of that way to handle the BTS feature since it's the only feature need check on each processor. That is the good way to handle the global variable might be corrupted by the multiple modification. but as Ray explained, the function only perform variable modification from TRUE to FALSE. So even the code runs in parallel, it's safe. That's the reason why I keep the original logic. 

> Minimally, at least document why the current lock-less but concurrent
> approach is safe!
> 

I agree. We can document in code comment. I will refine the patch to include this. 

Thanks,
Jiaxin


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115076): https://edk2.groups.io/g/devel/message/115076
Mute This Topic: https://groups.io/mt/104094806/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  reply	other threads:[~2024-02-04  0:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-01 11:19 [edk2-devel] [PATCH v1 0/2] SMM CPU Optimization for SMM Init & SMI Process Wu, Jiaxin
2024-02-01 11:20 ` [edk2-devel] [PATCH v1 1/2] UefiCpuPkg/PiSmmCpuDxeSmm: Execute CET and XD check only on BSP Wu, Jiaxin
2024-02-02  6:03   ` Ni, Ray
2024-02-02  6:35     ` Wu, Jiaxin
2024-02-02 14:05     ` Laszlo Ersek
2024-02-04  0:50       ` Wu, Jiaxin [this message]
2024-02-02 10:47   ` Laszlo Ersek
2024-02-01 11:20 ` [edk2-devel] [PATCH v1 2/2] UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock cmpxchg Wu, Jiaxin
2024-02-01 18:20   ` Michael D Kinney
2024-02-02  6:33     ` Wu, Jiaxin
2024-02-02 10:37   ` Laszlo Ersek
2024-02-06  1:40     ` Ni, Ray
2024-02-06 12:46       ` Laszlo Ersek
2024-02-20  3:41         ` Wu, Jiaxin
2024-02-20 16:21           ` Laszlo Ersek
2024-02-19  7:12     ` Ni, Ray

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=MN0PR11MB6158637F542BDBF38A1F3D30FE402@MN0PR11MB6158.namprd11.prod.outlook.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