From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: lersek@redhat.com) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Wed, 10 Jul 2019 05:20:17 -0700 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74EFB3001467; Wed, 10 Jul 2019 12:20:16 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-117-153.ams2.redhat.com [10.36.117.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88BF7196FB; Wed, 10 Jul 2019 12:20:13 +0000 (UTC) Subject: Re: [edk2-devel] [PATCH V2 0/4] Fix race condition and add event protocol To: devel@edk2.groups.io, zhichao.gao@intel.com Cc: Jian J Wang , Hao A Wu , Ray Ni , Star Zeng , Liming gao , Sean Brogan , Michael Turner , Bret Barkelew , Michael D Kinney , Eric Dong , Leif Lindholm , Ard Biesheuvel References: <20190709083956.13024-1-zhichao.gao@intel.com> From: "Laszlo Ersek" Message-ID: Date: Wed, 10 Jul 2019 14:20:12 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190709083956.13024-1-zhichao.gao@intel.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 10 Jul 2019 12:20:16 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 07/09/19 10:39, Gao, Zhichao wrote: > V1: > There is a race condition in CoreWaitForEvent function: > If an interrupt happens between CheckEvent and gIdleLoopEvent, > there would be a event pending during cpu sleep. > So it is required to check the gEventPending with the interrupt > disabled. > Implement a gEfiCpu2ProtocolGuid to fix that. The protocol include > one interface to enable interrupt and put the cpu to sleep. > > Add a event protocol gEdkiiCommonEventProtocolGuid to support > all TPL event. It is require for PI drivers that use HW interrput. > > V2: > Move EnableInterruptsAndSleep to UefiCpuPkg/CpuDxe. It is inappropiate > to add it to MdePkg which should only contain code base on the UEFI spec. > Change the name gEfiCpu2ProtocolGuid to gEdkiiCpu2ProtocolGuid. Thanks for the CC. * On patch #2, I'll defer to Eric and Ray. * From the problem description, and from the final fix in patch #4, it seems like the issue (the race condition) applies to all edk2 architectures. Therefore I would suggest filing a TianoCore Feature Request BZ for "ArmPkg/Drivers/CpuDxe" as well, for producing gEdkiiCpu2ProtocolGuid. (CC'ing Leif and Ard.) (I do see that the patch series does not *require* the new protocol, so it's fine to implement the ARM/AARCH64 support separately, in my opinion.) Thanks Laszlo > Cc: Jian J Wang > Cc: Hao A Wu > cc: Ray Ni > Cc: Star Zeng > Cc: Liming gao > Cc: Sean Brogan > Cc: Michael Turner > Cc: Bret Barkelew > Cc: Michael D Kinney > Cc: Eric Dong > > Sean Brogan (3): > MdeModulePkg: Add gEdkiiCpu2ProtocolGuid and header file > UefiCpuPkg/CpuDxe: Implement Cpu2 protocol > MdeModulePkg/DxeMain: Implement common event protocol > > Zhichao Gao (1): > MdeModulePkg: Add gEdkiiCommonEventProtocolGuid for creating event > > MdeModulePkg/Core/Dxe/DxeMain.h | 64 ++++++++++- > MdeModulePkg/Core/Dxe/DxeMain.inf | 2 + > MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c | 22 ++++ > .../Core/Dxe/DxeMain/DxeProtocolNotify.c | 1 + > MdeModulePkg/Core/Dxe/Event/Event.c | 102 ++++++++++++++++-- > MdeModulePkg/Core/Dxe/Event/Event.h | 2 +- > MdeModulePkg/Include/Protocol/CommonEvent.h | 18 ++++ > MdeModulePkg/Include/Protocol/Cpu2.h | 43 ++++++++ > MdeModulePkg/MdeModulePkg.dec | 6 ++ > UefiCpuPkg/CpuDxe/CpuDxe.c | 38 +++++++ > UefiCpuPkg/CpuDxe/CpuDxe.h | 25 +++++ > UefiCpuPkg/CpuDxe/CpuDxe.inf | 3 + > .../CpuDxe/Ia32/EnableInterruptsAndSleep.c | 24 +++++ > .../CpuDxe/X64/EnableInterruptsAndSleep.nasm | 31 ++++++ > 14 files changed, 368 insertions(+), 13 deletions(-) > create mode 100644 MdeModulePkg/Include/Protocol/CommonEvent.h > create mode 100644 MdeModulePkg/Include/Protocol/Cpu2.h > create mode 100644 UefiCpuPkg/CpuDxe/Ia32/EnableInterruptsAndSleep.c > create mode 100644 UefiCpuPkg/CpuDxe/X64/EnableInterruptsAndSleep.nasm >