[edk2-devel] [PATCH V2 0/4] Fix race condition and add event protocol

Gao, Zhichao posted 4 patches 18 weeks ago
Failed in applying to current master (apply log)
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

[edk2-devel] [PATCH V2 0/4] Fix race condition and add event protocol

Posted by Gao, Zhichao 18 weeks ago
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.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
cc: Ray Ni <ray.ni@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Liming gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Eric Dong <eric.dong@intel.com>

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

-- 
2.21.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43426): https://edk2.groups.io/g/devel/message/43426
Mute This Topic: https://groups.io/mt/32403448/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [PATCH V2 0/4] Fix race condition and add event protocol

Posted by Laszlo Ersek 17 weeks ago
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 <jian.j.wang@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> cc: Ray Ni <ray.ni@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Liming gao <liming.gao@intel.com>
> Cc: Sean Brogan <sean.brogan@microsoft.com>
> Cc: Michael Turner <Michael.Turner@microsoft.com>
> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> 
> 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
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#43478): https://edk2.groups.io/g/devel/message/43478
Mute This Topic: https://groups.io/mt/32403448/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-