From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id B85DBD8119E for ; Fri, 31 May 2024 10:14:50 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=DumGJIwbLsg26ArduGTLiUXwMU9FFp6rrIa7MyXyHUY=; c=relaxed/simple; d=groups.io; h=MIME-version:Subject:From:In-reply-to:Date:Cc:Message-id:References:To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-type; s=20240206; t=1717150490; v=1; b=O59SpljRmtEw6JieDD5+641rvjKIf6b5AtuRG8mmOutC4V0R6INSoJyWLHeQPvBts8QFHHsT W+2CpwJ6M5L6E/tUvxoZZo9Hvca7JGC2zVVy8oYQffa5PTsUNb2CweD4214w2m4+CNgAVSp1acf OqIGbEuFeCYg8pYnpI+gt6W+LlLOO9R0ph9dQAWH6rQ/U3f0zXSrcxrgUxu2sHvISXGqyQB8lRU 8Xb2Orzcv6PRJR+sUZ7KKP9Ki/YLidbkIu0qel5ZqDE8YYPsma8rB4mHgYoPWEFK4ZH0AzY+TJP wSMD7tGgf28R/N7I7ZLKlMYLSUxJz+rWalE5N0BfwfZ9Q== X-Received: by 127.0.0.2 with SMTP id yOPsYY7687511x4vWw6T4iQX; Fri, 31 May 2024 03:14:49 -0700 X-Received: from rn-mailsvcp-mx-lapp02.apple.com (rn-mailsvcp-mx-lapp02.apple.com [17.179.253.23]) by mx.groups.io with SMTP id smtpd.web10.8254.1717150488598717489 for ; Fri, 31 May 2024 03:14:48 -0700 X-Received: from ma-mailsvcp-mta-lapp02.corp.apple.com (ma-mailsvcp-mta-lapp02.corp.apple.com [10.226.18.134]) by rn-mailsvcp-mx-lapp02.rno.apple.com (Oracle Communications Messaging Server 8.1.0.23.20230328 64bit (built Mar 28 2023)) with ESMTPS id <0SEC00RQ4HSNG510@rn-mailsvcp-mx-lapp02.rno.apple.com> for devel@edk2.groups.io; Fri, 31 May 2024 03:14:48 -0700 (PDT) X-Received: from st47p01nt-mmpp01.apple.com (st47p01nt-mmpp01.apple.com [10.170.123.67]) by ma-mailsvcp-mta-lapp02.corp.apple.com (Oracle Communications Messaging Server 8.1.0.23.20230328 64bit (built Mar 28 2023)) with ESMTPS id <0SEC00KHBHSNWJ30@ma-mailsvcp-mta-lapp02.corp.apple.com>; Fri, 31 May 2024 03:14:47 -0700 (PDT) X-Received: from process_milters-daemon.st47p01nt-mmpp01.apple.com by st47p01nt-mmpp01.apple.com (Oracle Communications Messaging Server 8.1.0.23.20230328 64bit (built Mar 28 2023)) id <0SEC17D00HSL5Y00@st47p01nt-mmpp01.apple.com>; Fri, 31 May 2024 10:14:46 +0000 (GMT) X-Va-A: X-Va-T-CD: f900b3001c7ef03eb53e4f1f41858654 X-Va-E-CD: 565d08fc96bfb0973ef5be270ccdb446 X-Va-R-CD: 4f6064923a0e64b50d125a364eb00a3c X-Va-ID: 62346b73-f0c0-443e-ab70-b5e53dac5b97 X-Va-CD: 0 X-V-A: X-V-T-CD: f900b3001c7ef03eb53e4f1f41858654 X-V-E-CD: 565d08fc96bfb0973ef5be270ccdb446 X-V-R-CD: 4f6064923a0e64b50d125a364eb00a3c X-V-ID: 3f9affc7-28a6-4a41-8355-a2b3b40aeb27 X-V-CD: 0 X-Received: from smtpclient.apple (unknown [17.235.85.100]) by st47p01nt-mmpp01.apple.com (Oracle Communications Messaging Server 8.1.0.23.20230328 64bit (built Mar 28 2023)) with ESMTPSA id <0SEC16Y0EHSL7600@st47p01nt-mmpp01.apple.com>; Fri, 31 May 2024 10:14:45 +0000 (GMT) MIME-version: 1.0 (Mac OS X Mail 16.0 \(3774.300.61.1.2\)) Subject: Re: [edk2-devel] Is DEBUG output function safe for MP case? From: "Andrew Fish via groups.io" X-Priority: 3 In-reply-to: <17D48A6E78A3E42F.21428@groups.io> Date: Fri, 31 May 2024 05:14:34 -0500 Cc: fanjianfeng@byosoft.com.cn, yoshinoyatoko Message-id: <4B16E760-53C0-4CF1-852F-16DD8DAA965D@apple.com> References: <2d8e2935.5b57.18fcd506481.Coremail.yoshinoyatoko@163.com> <2024053114334025493514@byosoft.com.cn> <17D48A6E78A3E42F.21428@groups.io> To: edk2-devel-groups-io , Andrew Fish 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 Resent-Date: Fri, 31 May 2024 03:14:48 -0700 Resent-From: afish@apple.com Reply-To: devel@edk2.groups.io,afish@apple.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: rVWfTVxUyPNFpfyo6u1lvwjjx7686176AA= Content-type: multipart/alternative; boundary="Apple-Mail=_50BCCEAF-BA41-41A8-85A8-107C55B628F5" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=O59SpljR; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=pass (policy=none) header.from=groups.io --Apple-Mail=_50BCCEAF-BA41-41A8-85A8-107C55B628F5 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 There is also one extra caveat about UEFI runtime that I forgot to mention.= There is no way to share the hardware between UEFI and the OS, so UEFI rea= lly needs dedicated hardware. Thanks, Andrew Fish PS This makes me think of a Windows story from the 1990=E2=80=99s when Wind= ows added Plug-and-Play for serial to detect modems. A factory updated Wind= ows on a PC that controlled a CnC machine and the modem auto detect AT comm= ands got sent to the CnC machine, and this told the CnC machine to start dr= illing holes in the CnC machine. =20 > On May 31, 2024, at 4:59=E2=80=AFAM, Andrew Fish via groups.io wrote: >=20 > I think the generic answer is no DEBUG() is not guaranteed to be MP safe.= =20 >=20 > Jeff is pointing out in the edk2 your platform build can control what lib= raries are used to implement DEBUG(), so you might be able to make it work = in your case.=20 >=20 > Base libs are libraries that don=E2=80=99t depend on other things so they= have a much better chance of working but they will have at least 2 issue: > 1) The are not MP safe so the output could get intermixed and things coul= d get lost as multiple agents try to to write to the UART in parallel > 2) A Base lib that goes after a x86 IO port has a chance of working at ru= ntime, but an ARM UART driver that uses an MMIO address is not going to wor= k as the that MMIO range would need a virtual mapping and a Base lib is not= going to request that. >=20 > You can search for instances of the DebugLib (that implements DEBUG) by g= repping the inf files.=20 >=20 > /Volumes/Case/edk2(master)>git grep DebugLib -- \*.inf | grep LIBRARY_CLA= SS | grep DXE_RUNTIME_DRIVER > ArmPkg/Library/SemiHostingDebugLib/SemiHostingDebugLib.inf:19: LIBRARY_C= LASS =3D DebugLib|BASE SEC DXE_CORE DXE_DRIVER DXE_RUNTIME= _DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER > ArmVirtPkg/Library/DebugLibFdtPL011Uart/DxeRuntimeDebugLibFdtPL011Uart.in= f:23: LIBRARY_CLASS =3D DebugLib|DXE_RUNTIME_DRIVER > MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportS= tatusCode.inf:19: LIBRARY_CLASS =3D DebugLib|DXE_CORE DXE= _DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER SMM_CORE PEIM SEC PEI_CORE UEFI_A= PPLICATION UEFI_DRIVER MM_STANDALONE > MdePkg/Library/DxeRuntimeDebugLibSerialPort/DxeRuntimeDebugLibSerialPort.= inf:22: LIBRARY_CLASS =3D DebugLib|DXE_RUNTIME_DRIVER > MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf:22: LIBRARY_CLA= SS =3D DebugLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEF= I_APPLICATION UEFI_DRIVER > MdePkg/Library/UefiDebugLibDebugPortProtocol/UefiDebugLibDebugPortProtoco= l.inf:22: LIBRARY_CLASS =3D DebugLib|DXE_CORE DXE_DRIVER = DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER > MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf:22: LIBRARY_CLA= SS =3D DebugLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEF= I_APPLICATION UEFI_DRIVER > OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.inf:19: LI= BRARY_CLASS =3D DebugLib|PEI_CORE PEIM DXE_CORE DXE_DRIVER= DXE_RUNTIME_DRIVER SMM_CORE DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION >=20 > Note: DXE_RUNTIME_DRIVE may not imply the the DEBUG works at running, and= it may only support DEBUG print a Boot Services time. But if you look at t= he list you will see some of the libs are designed to used at runtime. So t= hat should imply they deal with virtual address mapping and locks.=20 >=20 > Thanks, >=20 > Andrew Fish >=20 >> On May 31, 2024, at 1:33=E2=80=AFAM, Jeff Fan via groups.io wrote: >>=20 >> AP cannot run any UEFI Service. Please make sure AP code use base-typed = DebugLib instance (Such as BaseDebugLibSerialport.inf from MdePkg) >>=20 >>=20 >> fanjianfeng@byosoft.com.cn >> =20 >> =E5=8F=91=E4=BB=B6=E4=BA=BA=EF=BC=9A Yoshinoya >> =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4=EF=BC=9A 2024-05-31 14:22 >> =E6=94=B6=E4=BB=B6=E4=BA=BA=EF=BC=9A devel@edk2.groups.io >> =E4=B8=BB=E9=A2=98=EF=BC=9A [edk2-devel] Is DEBUG output function safe f= or MP case? >> Hello >> I ask for help for debug output in multi-core case. >>=20 >> Is the current DEBUG marco safe for AP Cores to output message? >> If the output message is too long, it takes too much time, will it cause= some abnormal exception? >>=20 >> Thanks >=20 >=20 -=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 (#119410): https://edk2.groups.io/g/devel/message/119410 Mute This Topic: https://groups.io/mt/106405152/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- --Apple-Mail=_50BCCEAF-BA41-41A8-85A8-107C55B628F5 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 There is also one extra caveat ab= out UEFI runtime that I forgot to mention. There is no way to share the har= dware between UEFI and the OS, so UEFI really needs dedicated hardware.
Thanks,

Andrew Fish

=
PS This makes me think of a Windows story from the 1990=E2=80=99= s when Windows added Plug-and-Play for serial to detect modems. A factory u= pdated Windows on a PC that controlled a CnC machine and the modem auto det= ect AT commands got sent to the CnC machine, and this told the CnC machine = to start drilling holes in the CnC machine.  

On May 31, 2024, at= 4:59=E2=80=AFAM, Andrew Fish via groups.io <afish=3Dapple.com@groups.io= > wrote:

I think the generic answer is no DEBUG() is not guaranteed to be MP saf= e. 


Base libs are libraries that don=E2=80=99t depend on other thin= gs so they have a much better chance of working but they will have at least= 2 issue:
1) The are not MP safe so the outp= ut could get intermixed and things could get lost as multiple agents try to= to write to the UART in parallel
2) A Base = lib that goes after a x86 IO port has a chance of working at runtime, but a= n ARM UART driver that uses an MMIO address is not going to work as the tha= t MMIO range would need a virtual mapping and a Base lib is not going to re= quest that.

You can search for instances of the DebugLib (that implements DEBUG) by= grepping the inf files. 

/Volumes/Case/edk2(maste= r)>git grep DebugLib -- \*.inf | grep LIBRARY_CLASS |= grep DXE_RUNTIME_DRIVER
ArmPkg/Library/SemiHostingDebugLib/SemiHostingDebugLi= b.inf:19:  LIBRARY_CLASS            &nbs= p;     =3D DebugLib|BASE SEC DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIV= ER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
ArmVirtPkg/Library/DebugLibFdtP= L011Uart/DxeRuntimeDebugLibFdtPL011Uart.inf:23:  LIBRARY_CLASS  = =3D DebugLib|DXE_RUNTIME_DRIVER
MdeModulePkg/Library/PeiDxeDebugLibReportStatu= sCode/PeiDxeDebugLibReportStatusCode.inf:19:  LIBRARY_CLASS  &nbs= p;               =3D DebugLib|DXE_CORE D= XE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER SMM_CORE PEIM SEC PEI_CORE UEFI= _APPLICATION UEFI_DRIVER MM_STANDALONE
MdePkg/Library/DxeRuntimeDebugLibSerial= Port/DxeRuntimeDebugLibSerialPort.inf:22:  LIBRARY_CLASS    =               =3D DebugLib|DXE_RUNTIME_D= RIVER
MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf:22:  LIBRA= RY_CLASS                  =3D = DebugLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVE= R
M= dePkg/Library/UefiDebugLibDebugPortProtocol/UefiDebugLibDebugPortProtocol.i= nf:22:  LIBRARY_CLASS              =     =3D DebugLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPL= ICATION UEFI_DRIVER
MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf:2= 2:  LIBRARY_CLASS              &nbs= p;   =3D DebugLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICAT= ION UEFI_DRIVER
OvmfPkg/Library/PlatformDebugLibIoPort/PlatformDebugLibIoPort.= inf:19:  LIBRARY_CLASS             =     =3D DebugLib|PEI_CORE PEIM DXE_CORE DXE_DRIVER DXE_RUNTIME_D= RIVER SMM_CORE DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION

Note: DXE_RUN= TIME_DRIVE may not imply the the DEBUG works at running, and it may only su= pport DEBUG print a Boot Services time. But if you look at the list you wil= l see some of the libs are designed to used at runtime. So that should impl= y they deal with virtual address mapping and locks. 

Thanks,

Andrew Fish

On May 31, 2024, at 1:33=E2=80=AFAM, Jeff Fan via gr= oups.io <fanjianfeng=3Dbyosoft.com.cn@groups.io> wrote:

AP cannot run any UEFI Service. Please make sure= AP code use base-typed DebugLib instance (Such as BaseDebugLibSerialport.i= nf from MdePkg)


 
=E5=8F=91=E4=BB=B6= =E4=BA=BA=EF=BC=9A Yoshin= oya
=E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4=EF=BC=9A = ;2024-05-31 14:22
=E6=94=B6=E4=BB=B6=E4=BA=BA=EF=BC=9A devel@edk2.groups.io
=E4=B8=BB=E9=A2=98=EF=BC=9A [edk2-devel] Is DEBUG output= function safe for MP case?
Hello
I ask for help for debug output in multi-core case.

Is the current DEBUG ma= rco safe for AP Cores to output message?
I= f the output message is too long, it takes too much time, will it cause som= e abnormal exception?

Thanks


_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#119410) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--Apple-Mail=_50BCCEAF-BA41-41A8-85A8-107C55B628F5--