From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 15A97AC1291 for ; Fri, 2 Feb 2024 10:37:32 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=M6TvO2MxL5ksoj0eKhQWJJ4A4QQHvoPVb2HYxSmowyQ=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1706870251; v=1; b=Zx4DR3OFgP80czQHiVXDeYLRAjEGF9UjiblUVrsEYAXfhSawx2TitMCyzTWZN2tBI6IQ3DHS 0s2JZv5csBVwmFIN98buk8ldMqGY8ZIIMswjXbKv9DQPWXZP5ebR583k5W2RtPGPIxwW35iWdU+ +EMzFG83O+Hfg3xTdTzbQpOE= X-Received: by 127.0.0.2 with SMTP id DJxoYY7687511xCC65hRE9ha; Fri, 02 Feb 2024 02:37:31 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web11.19934.1706870251070267013 for ; Fri, 02 Feb 2024 02:37:31 -0800 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-688-OKUUrEMIMrKI4nO1RZrMMg-1; Fri, 02 Feb 2024 05:37:28 -0500 X-MC-Unique: OKUUrEMIMrKI4nO1RZrMMg-1 X-Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6377B106D100; Fri, 2 Feb 2024 10:37:28 +0000 (UTC) X-Received: from [10.39.192.34] (unknown [10.39.192.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 40CD624E4; Fri, 2 Feb 2024 10:37:27 +0000 (UTC) Message-ID: Date: Fri, 2 Feb 2024 11:37:05 +0100 MIME-Version: 1.0 Subject: Re: [edk2-devel] [PATCH v1 2/2] UefiCpuPkg/PiSmmCpuDxeSmm: Check BspIndex first before lock cmpxchg To: devel@edk2.groups.io, jiaxin.wu@intel.com Cc: Ray Ni , Eric Dong , Zeng Star , Gerd Hoffmann , Rahul Kumar References: <20240201112001.14416-1-jiaxin.wu@intel.com> <20240201112001.14416-3-jiaxin.wu@intel.com> From: "Laszlo Ersek" In-Reply-To: <20240201112001.14416-3-jiaxin.wu@intel.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lersek@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: R2Fn4M6P3vsOQF1bVDTPuXuux7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=Zx4DR3OF; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io On 2/1/24 12:20, Wu, Jiaxin wrote: > This patch is to check BspIndex first before lock cmpxchg operation. > It's the optimization to lower the resource contention caused by the > atomic compare exchange operation, so as to improve the SMI > performance for BSP election. >=20 > Cc: Ray Ni > Cc: Laszlo Ersek > Cc: Eric Dong > Cc: Zeng Star > Cc: Gerd Hoffmann > Cc: Rahul Kumar > Signed-off-by: Jiaxin Wu > --- > UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) >=20 > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuD= xeSmm/MpService.c > index e988ce0542..479024d294 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c > @@ -1652,15 +1652,17 @@ SmiRendezvous ( > } > } else { > // > // Platform hook fails to determine, use default BSP electio= n method > // > - InterlockedCompareExchange32 ( > - (UINT32 *)&mSmmMpSyncData->BspIndex, > - (UINT32)-1, > - (UINT32)CpuIndex > - ); > + if (mSmmMpSyncData->BspIndex =3D=3D (UINT32)-1) { > + InterlockedCompareExchange32 ( > + (UINT32 *)&mSmmMpSyncData->BspIndex, > + (UINT32)-1, > + (UINT32)CpuIndex > + ); > + } > } > } > } > =20 > // This patch makes me uncomfortable. I understand what it intends to do, and the intent is not wrong, but we're again treating "volatile UINT32" as atomic, and non-reorderable against the InterlockedCompareExchange32(). This kind of "optimization" is what people write cautionary tales about, later. It would be nice to see a semi-formal *proof* that this cannot backfire. Either way: I'm not trying to block the patch. If Ray is happy with it, I don't object. OVMF implements PlatformSmmBspElection() in "OvmfPkg/Library/SmmCpuPlatformHookLibQemu/SmmCpuPlatformHookLibQemu.c", always returning EFI_SUCCESS [*], so the code that is being modified here cannot be reached in OVMF. [*] commit 43df61878d94 ("OvmfPkg: enable SMM Monarch Election in PiSmmCpuDxeSmm", 2020-03-04) Laszlo -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115036): https://edk2.groups.io/g/devel/message/115036 Mute This Topic: https://groups.io/mt/104094808/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-