Re: [edk2] [PATCH 1/1] BaseTools: Roll back code modify by commit 9e47e6f90880
Reviewed-by: Liming Gao Because some platform has been broken, I will push this patch soon. > -Original Message- > From: Feng, YunhuaX > Sent: Friday, October 26, 2018 2:08 PM > To: edk2-devel@lists.01.org > Cc: Zhu, Yonghong ; Gao, Liming > Subject: [PATCH 1/1] BaseTools: Roll back code modify by commit 9e47e6f90880 > > Roll back code modify by commit 9e47e6f90880, > if ForceRebase not False or True, the GenFv command not need add parameter > > Cc: Liming Gao > Cc: Yonghong Zhu > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Yunhua Feng > --- > BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py > b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py > index e867693d7c..ea61f723a7 100644 > --- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py > +++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py > @@ -572,13 +572,13 @@ class GenFdsGlobalVariable: > > Cmd = ["GenFv"] > if BaseAddress: > Cmd += ("-r", BaseAddress) > > -if not ForceRebase: > +if ForceRebase == False: > Cmd += ("-F", "FALSE") > -else: > +elif ForceRebase == True: > Cmd += ("-F", "TRUE") > > if Capsule: > Cmd.append("-c") > if Dump: > -- > 2.12.2.windows.2 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH 1/1] BaseTools: Roll back code modify by commit 9e47e6f90880
Roll back code modify by commit 9e47e6f90880, if ForceRebase not False or True, the GenFv command not need add parameter Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng --- BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py index e867693d7c..ea61f723a7 100644 --- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py +++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py @@ -572,13 +572,13 @@ class GenFdsGlobalVariable: Cmd = ["GenFv"] if BaseAddress: Cmd += ("-r", BaseAddress) -if not ForceRebase: +if ForceRebase == False: Cmd += ("-F", "FALSE") -else: +elif ForceRebase == True: Cmd += ("-F", "TRUE") if Capsule: Cmd.append("-c") if Dump: -- 2.12.2.windows.2 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH V2 2/4] MdeModulePkg EhciDxe: Extract new EhciInsertAsyncIntTransfer function
V2: Add the missing "gBS->FreePool (Data);". REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274 Extract new EhciInsertAsyncIntTransfer function from EhcAsyncInterruptTransfer. It is code preparation for following patch, no essential functional change. Cc: Ruiyu Ni Cc: Hao Wu Cc: Jian J Wang Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng --- MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c | 25 +-- MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c | 77 MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.h | 36 ++- 3 files changed, 113 insertions(+), 25 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c index 50b5598df4fb..5569f4f9618b 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c @@ -997,7 +997,6 @@ EhcAsyncInterruptTransfer ( URB *Urb; EFI_TPL OldTpl; EFI_STATUS Status; - UINT8 *Data; // // Validate parameters @@ -1046,16 +1045,7 @@ EhcAsyncInterruptTransfer ( EhcAckAllInterrupt (Ehc); - Data = AllocatePool (DataLength); - - if (Data == NULL) { -DEBUG ((EFI_D_ERROR, "EhcAsyncInterruptTransfer: failed to allocate buffer\n")); - -Status = EFI_OUT_OF_RESOURCES; -goto ON_EXIT; - } - - Urb = EhcCreateUrb ( + Urb = EhciInsertAsyncIntTransfer ( Ehc, DeviceAddress, EndPointAddress, @@ -1063,9 +1053,6 @@ EhcAsyncInterruptTransfer ( *DataToggle, MaximumPacketLength, Translator, - EHC_INT_TRANSFER_ASYNC, - NULL, - Data, DataLength, CallBackFunction, Context, @@ -1073,20 +1060,10 @@ EhcAsyncInterruptTransfer ( ); if (Urb == NULL) { -DEBUG ((EFI_D_ERROR, "EhcAsyncInterruptTransfer: failed to create URB\n")); - -gBS->FreePool (Data); Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } - // - // New asynchronous transfer must inserted to the head. - // Check the comments in EhcMoniteAsyncRequests - // - EhcLinkQhToPeriod (Ehc, Urb->Qh); - InsertHeadList (&Ehc->AsyncIntTransfers, &Urb->UrbList); - ON_EXIT: Ehc->PciIo->Flush (Ehc->PciIo); gBS->RestoreTPL (OldTpl); diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c index 168280be81d7..2d202d439d1c 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c @@ -814,6 +814,83 @@ EhciDelAllAsyncIntTransfers ( } } +/** + Insert a single asynchronous interrupt transfer for + the device and endpoint. + + @param Ehc The EHCI device. + @param DevAddr The device address. + @param EpAddrEndpoint addrress & its direction. + @param DevSpeed The device speed. + @param ToggleInitial data toggle to use. + @param MaxPacket The max packet length of the endpoint. + @param Hub The transaction translator to use. + @param Data The user data to transfer. + @param DataLen The length of data buffer. + @param Callback The function to call when data is transferred. + @param Context The context to the callback. + @param Interval The interval for interrupt transfer. + + @return Created URB or NULL. + +**/ +URB * +EhciInsertAsyncIntTransfer ( + IN USB2_HC_DEV*Ehc, + IN UINT8 DevAddr, + IN UINT8 EpAddr, + IN UINT8 DevSpeed, + IN UINT8 Toggle, + IN UINTN MaxPacket, + IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Hub, + IN UINTN DataLen, + IN EFI_ASYNC_USB_TRANSFER_CALLBACKCallback, + IN VOID *Context, + IN UINTN Interval + ) +{ + VOID *Data; + URB *Urb; + + Data = AllocatePool (DataLen); + + if (Data == NULL) { +DEBUG ((DEBUG_ERROR, "%a: failed to allocate buffer\n", __FUNCTION__)); +return NULL; + } + + Urb = EhcCreateUrb ( + Ehc, + DevAddr, + EpAddr, + DevSpeed, + Toggle, + MaxPacket, + Hub, + EHC_INT_TRANSFER_ASYNC, + NULL, + Data, + DataLen, + Callback, + Context, + Interval + ); + + if (Urb == NULL) { +DEBUG ((DEBUG_ERROR, "%a: failed to create URB\n", __FUNCTION__)); +gBS->FreePool (Data); +return NULL; + } + + // + // New asynchronous transfer must inserted to the head. + // Check the comments in EhcMoniteAsyncRequests + // + EhcLinkQhToPeriod (Ehc, Urb->Qh); + InsertHeadList (&Ehc->AsyncIntTransfers, &Urb->UrbList); + + return Urb; +} /** Flush
[edk2] [PATCH V2 4/4] MdeModulePkg EhciDxe: Use common buffer for AsyncInterruptTransfer
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274 In current code, EhcMonitorAsyncRequests (timer handler) will do unmap and map operations for AsyncIntTransfers to "Flush data from PCI controller specific address to mapped system memory address". EhcMonitorAsyncRequests EhcFlushAsyncIntMap PciIo->Unmap IoMmu->SetAttribute PciIo->Map IoMmu->SetAttribute This may impact the boot performance. Since the data buffer for EhcMonitorAsyncRequests is internal buffer, we can allocate common buffer by PciIo->AllocateBuffer and map the buffer with EfiPciIoOperationBusMasterCommonBuffer, then the unmap and map operations can be removed. /// /// Provides both read and write access to system memory by /// both the processor and a bus master. The buffer is coherent /// from both the processor's and the bus master's point of view. /// EfiPciIoOperationBusMasterCommonBuffer, Test done: USB KB works normally. USB disk read/write works normally. Cc: Ruiyu Ni Cc: Hao Wu Cc: Jian J Wang Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Ruiyu Ni --- MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c | 3 ++ MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c | 78 +--- MdeModulePkg/Bus/Pci/EhciDxe/EhciUrb.c | 38 ++-- MdeModulePkg/Bus/Pci/EhciDxe/EhciUrb.h | 33 -- 4 files changed, 57 insertions(+), 95 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c index 5569f4f9618b..764eeda58ba1 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c @@ -763,6 +763,7 @@ EhcControlTransfer ( Translator, EHC_CTRL_TRANSFER, Request, + FALSE, Data, *DataLength, NULL, @@ -906,6 +907,7 @@ EhcBulkTransfer ( Translator, EHC_BULK_TRANSFER, NULL, + FALSE, Data[0], *DataLength, NULL, @@ -1163,6 +1165,7 @@ EhcSyncInterruptTransfer ( Translator, EHC_INT_TRANSFER_SYNC, NULL, + FALSE, Data, *DataLength, NULL, diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c index 2d202d439d1c..f1edcf20e342 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c @@ -778,7 +778,6 @@ EhciDelAsyncIntTransfer ( EhcUnlinkQhFromPeriod (Ehc, Urb->Qh); RemoveEntryList (&Urb->UrbList); - gBS->FreePool (Urb->Data); EhcFreeUrb (Ehc, Urb); return EFI_SUCCESS; } @@ -809,7 +808,6 @@ EhciDelAllAsyncIntTransfers ( EhcUnlinkQhFromPeriod (Ehc, Urb->Qh); RemoveEntryList (&Urb->UrbList); -gBS->FreePool (Urb->Data); EhcFreeUrb (Ehc, Urb); } } @@ -849,16 +847,8 @@ EhciInsertAsyncIntTransfer ( IN UINTN Interval ) { - VOID *Data; URB *Urb; - Data = AllocatePool (DataLen); - - if (Data == NULL) { -DEBUG ((DEBUG_ERROR, "%a: failed to allocate buffer\n", __FUNCTION__)); -return NULL; - } - Urb = EhcCreateUrb ( Ehc, DevAddr, @@ -869,7 +859,8 @@ EhciInsertAsyncIntTransfer ( Hub, EHC_INT_TRANSFER_ASYNC, NULL, - Data, + TRUE, + NULL, DataLen, Callback, Context, @@ -878,7 +869,6 @@ EhciInsertAsyncIntTransfer ( if (Urb == NULL) { DEBUG ((DEBUG_ERROR, "%a: failed to create URB\n", __FUNCTION__)); -gBS->FreePool (Data); return NULL; } @@ -893,60 +883,6 @@ EhciInsertAsyncIntTransfer ( } /** - Flush data from PCI controller specific address to mapped system - memory address. - - @param EhcThe EHCI device. - @param UrbThe URB to unmap. - - @retval EFI_SUCCESSSuccess to flush data to mapped system memory. - @retval EFI_DEVICE_ERROR Fail to flush data to mapped system memory. - -**/ -EFI_STATUS -EhcFlushAsyncIntMap ( - IN USB2_HC_DEV *Ehc, - IN URB *Urb - ) -{ - EFI_STATUSStatus; - EFI_PHYSICAL_ADDRESS PhyAddr; - EFI_PCI_IO_PROTOCOL_OPERATION MapOp; - EFI_PCI_IO_PROTOCOL *PciIo; - UINTN Len; - VOID *Map; - - PciIo = Ehc->PciIo; - Len = Urb->DataLen; - - if (Urb->Ep.Direction == EfiUsbDataIn) { -MapOp = EfiPciIoOperationBusMasterWrite; - } else { -MapOp = EfiPciIoOperationBusMasterRead; - } - - Status = PciIo->Unmap (PciIo, Urb->DataMap); - if (EFI_ERROR (Status)) { -goto ON_ERROR; - } - - Urb->DataMap = NULL; - - Status = PciIo->Map (PciIo, MapOp, Urb->Data, &Len, &PhyAddr, &Map); - if (EFI_ERROR (Status) || (Len != Urb->DataLen)) { -goto ON_ERROR; - } - - Urb->DataPhy = (VOID *) ((UINTN) PhyAddr); - Urb->D
[edk2] [PATCH V2 0/4] Remove unnecessary Map/Unmap in XhciDxe/EhciDxe for AsyncInterruptTransfer
V2: Thanks for Ray's feedback. Add the missing "FreePool (Data);". Remove the unnecessary indentation change. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274 Please refer to the log message of each commit for more details. Cc: Ruiyu Ni Cc: Hao Wu Cc: Jian J Wang Cc: Jiewen Yao Star Zeng (4): MdeModulePkg XhciDxe: Extract new XhciInsertAsyncIntTransfer function MdeModulePkg EhciDxe: Extract new EhciInsertAsyncIntTransfer function MdeModulePkg XhciDxe: Use common buffer for AsyncInterruptTransfer MdeModulePkg EhciDxe: Use common buffer for AsyncInterruptTransfer MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c | 28 + MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c | 115 ++- MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.h | 36 +- MdeModulePkg/Bus/Pci/EhciDxe/EhciUrb.c | 38 ++- MdeModulePkg/Bus/Pci/EhciDxe/EhciUrb.h | 33 +++--- MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 19 +--- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 188 ++- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h | 55 +++-- 8 files changed, 302 insertions(+), 210 deletions(-) -- 2.7.0.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH V2 3/4] MdeModulePkg XhciDxe: Use common buffer for AsyncInterruptTransfer
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274 In current code, XhcMonitorAsyncRequests (timer handler) will do unmap and map operations for AsyncIntTransfers to "Flush data from PCI controller specific address to mapped system memory address". XhcMonitorAsyncRequests XhcFlushAsyncIntMap PciIo->Unmap IoMmu->SetAttribute PciIo->Map IoMmu->SetAttribute This may impact the boot performance. Since the data buffer for XhcMonitorAsyncRequests is internal buffer, we can allocate common buffer by PciIo->AllocateBuffer and map the buffer with EfiPciIoOperationBusMasterCommonBuffer, then the unmap and map operations can be removed. /// /// Provides both read and write access to system memory by /// both the processor and a bus master. The buffer is coherent /// from both the processor's and the bus master's point of view. /// EfiPciIoOperationBusMasterCommonBuffer, Test done: USB KB works normally. USB disk read/write works normally. Cc: Ruiyu Ni Cc: Hao Wu Cc: Jian J Wang Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Ruiyu Ni --- MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 1 + MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 141 +++ MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h | 27 +++--- 3 files changed, 67 insertions(+), 102 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c index 7f64f9c7c982..64855a4c158c 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c @@ -769,6 +769,7 @@ XhcTransfer ( MaximumPacketLength, Type, Request, + FALSE, Data, *DataLength, NULL, diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c index 75959ae08363..d03a6681ce0d 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c @@ -118,17 +118,18 @@ ON_EXIT: /** Create a new URB for a new transaction. - @param Xhc The XHCI Instance - @param BusAddr The logical device address assigned by UsbBus driver - @param EpAddrEndpoint addrress - @param DevSpeed The device speed - @param MaxPacket The max packet length of the endpoint - @param Type The transaction type - @param Request The standard USB request for control transfer - @param Data The user data to transfer - @param DataLen The length of data buffer - @param Callback The function to call when data is transferred - @param Context The context to the callback + @param Xhc The XHCI Instance + @param BusAddr The logical device address assigned by UsbBus driver + @param EpAddrEndpoint addrress + @param DevSpeed The device speed + @param MaxPacket The max packet length of the endpoint + @param Type The transaction type + @param Request The standard USB request for control transfer + @param AllocateCommonBuffer Indicate whether need to allocate common buffer for data transfer + @param Data The user data to transfer, NULL if AllocateCommonBuffer is TRUE + @param DataLen The length of data buffer + @param Callback The function to call when data is transferred + @param Context The context to the callback @return Created URB or NULL @@ -142,6 +143,7 @@ XhcCreateUrb ( IN UINTN MaxPacket, IN UINTN Type, IN EFI_USB_DEVICE_REQUEST *Request, + IN BOOLEANAllocateCommonBuffer, IN VOID *Data, IN UINTN DataLen, IN EFI_ASYNC_USB_TRANSFER_CALLBACKCallback, @@ -169,8 +171,24 @@ XhcCreateUrb ( Ep->Type = Type; Urb->Request = Request; + if (AllocateCommonBuffer) { +ASSERT (Data == NULL); +Status = Xhc->PciIo->AllocateBuffer ( + Xhc->PciIo, + AllocateAnyPages, + EfiBootServicesData, + EFI_SIZE_TO_PAGES (DataLen), + &Data, + 0 + ); +if (EFI_ERROR (Status) || (Data == NULL)) { + FreePool (Urb); + return NULL; +} + } Urb->Data = Data; Urb->DataLen = DataLen; + Urb->AllocateCommonBuffer = AllocateCommonBuffer; Urb->Callback = Callback; Urb->Context = Context; @@ -178,6 +196,11 @@ XhcCreateUrb ( ASSERT_EFI_ERROR (Status); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "XhcCreateUrb: XhcCreateTransferTrb Failed, Status = %r\n", Status)); +Xhc->PciIo->FreeBuffer ( + Xhc->PciIo, + EFI_SIZE_TO_PAGES (Urb->DataLen), +
[edk2] [PATCH V2 1/4] MdeModulePkg XhciDxe: Extract new XhciInsertAsyncIntTransfer function
V2: Add the missing "FreePool (Data);". Remove the unnecessary indentation change. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274 Extract new XhciInsertAsyncIntTransfer function from XhcAsyncInterruptTransfer. It is code preparation for following patch, no essential functional change. Cc: Ruiyu Ni Cc: Hao Wu Cc: Jian J Wang Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng --- MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 18 + MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 65 MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h | 28 ++ 3 files changed, 94 insertions(+), 17 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c index f1c60bef01c0..7f64f9c7c982 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c @@ -1346,7 +1346,6 @@ XhcAsyncInterruptTransfer ( EFI_STATUS Status; UINT8 SlotId; UINT8 Index; - UINT8 *Data; EFI_TPL OldTpl; // @@ -1413,36 +1412,21 @@ XhcAsyncInterruptTransfer ( goto ON_EXIT; } - Data = AllocateZeroPool (DataLength); - - if (Data == NULL) { -DEBUG ((EFI_D_ERROR, "XhcAsyncInterruptTransfer: failed to allocate buffer\n")); -Status = EFI_OUT_OF_RESOURCES; -goto ON_EXIT; - } - - Urb = XhcCreateUrb ( + Urb = XhciInsertAsyncIntTransfer ( Xhc, DeviceAddress, EndPointAddress, DeviceSpeed, MaximumPacketLength, - XHC_INT_TRANSFER_ASYNC, - NULL, - Data, DataLength, CallBackFunction, Context ); - if (Urb == NULL) { -DEBUG ((EFI_D_ERROR, "XhcAsyncInterruptTransfer: failed to create URB\n")); -FreePool (Data); Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } - InsertHeadList (&Xhc->AsyncIntTransfers, &Urb->UrbList); // // Ring the doorbell // diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c index 166c44bf5e66..75959ae08363 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c @@ -1411,6 +1411,71 @@ XhciDelAllAsyncIntTransfers ( } /** + Insert a single asynchronous interrupt transfer for + the device and endpoint. + + @param XhcThe XHCI Instance + @param BusAddrThe logical device address assigned by UsbBus driver + @param EpAddr Endpoint addrress + @param DevSpeed The device speed + @param MaxPacket The max packet length of the endpoint + @param DataLenThe length of data buffer + @param Callback The function to call when data is transferred + @param ContextThe context to the callback + + @return Created URB or NULL + +**/ +URB * +XhciInsertAsyncIntTransfer ( + IN USB_XHCI_INSTANCE *Xhc, + IN UINT8 BusAddr, + IN UINT8 EpAddr, + IN UINT8 DevSpeed, + IN UINTN MaxPacket, + IN UINTN DataLen, + IN EFI_ASYNC_USB_TRANSFER_CALLBACKCallback, + IN VOID *Context + ) +{ + VOID *Data; + URB *Urb; + + Data = AllocateZeroPool (DataLen); + if (Data == NULL) { +DEBUG ((DEBUG_ERROR, "%a: failed to allocate buffer\n", __FUNCTION__)); +return NULL; + } + + Urb = XhcCreateUrb ( + Xhc, + BusAddr, + EpAddr, + DevSpeed, + MaxPacket, + XHC_INT_TRANSFER_ASYNC, + NULL, + Data, + DataLen, + Callback, + Context + ); + if (Urb == NULL) { +DEBUG ((DEBUG_ERROR, "%a: failed to create URB\n", __FUNCTION__)); +FreePool (Data); +return NULL; + } + + // + // New asynchronous transfer must inserted to the head. + // Check the comments in XhcMoniteAsyncRequests + // + InsertHeadList (&Xhc->AsyncIntTransfers, &Urb->UrbList); + + return Urb; +} + +/** Update the queue head for next round of asynchronous transfer @param Xhc The XHCI Instance. diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h index 097408828a1f..cd1403f2842a 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h @@ -853,6 +853,34 @@ XhciDelAllAsyncIntTransfers ( ); /** + Insert a single asynchronous interrupt transfer for + the device and endpoint. + + @param XhcThe XHCI Instance + @param BusAddrThe logical device address assigned by UsbBus driver + @param EpAddr Endpoint addrress + @param DevSpeed The device speed + @param MaxPacket The max packet length of the endpoint + @param DataLenThe length of data buffer + @p
Re: [edk2] [PATCH 4/4] MdeModulePkg EhciDxe: Use common buffer for AsyncInterruptTransfer
On 10/25/2018 6:58 PM, Star Zeng wrote: REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274 In current code, EhcMonitorAsyncRequests (timer handler) will do unmap and map operations for AsyncIntTransfers to "Flush data from PCI controller specific address to mapped system memory address". EhcMonitorAsyncRequests EhcFlushAsyncIntMap PciIo->Unmap IoMmu->SetAttribute PciIo->Map IoMmu->SetAttribute This may impact the boot performance. Since the data buffer for EhcMonitorAsyncRequests is internal buffer, we can allocate common buffer by PciIo->AllocateBuffer and map the buffer with EfiPciIoOperationBusMasterCommonBuffer, then the unmap and map operations can be removed. /// /// Provides both read and write access to system memory by /// both the processor and a bus master. The buffer is coherent /// from both the processor's and the bus master's point of view. /// EfiPciIoOperationBusMasterCommonBuffer, Test done: USB KB works normally. USB disk read/write works normally. Cc: Ruiyu Ni Cc: Hao Wu Cc: Jian J Wang Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng --- MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c | 3 ++ MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c | 77 +--- MdeModulePkg/Bus/Pci/EhciDxe/EhciUrb.c | 38 ++-- MdeModulePkg/Bus/Pci/EhciDxe/EhciUrb.h | 33 +++--- 4 files changed, 57 insertions(+), 94 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c index 5569f4f9618b..764eeda58ba1 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c @@ -763,6 +763,7 @@ EhcControlTransfer ( Translator, EHC_CTRL_TRANSFER, Request, + FALSE, Data, *DataLength, NULL, @@ -906,6 +907,7 @@ EhcBulkTransfer ( Translator, EHC_BULK_TRANSFER, NULL, + FALSE, Data[0], *DataLength, NULL, @@ -1163,6 +1165,7 @@ EhcSyncInterruptTransfer ( Translator, EHC_INT_TRANSFER_SYNC, NULL, + FALSE, Data, *DataLength, NULL, diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c index d38340e49c8d..f1edcf20e342 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c @@ -778,7 +778,6 @@ EhciDelAsyncIntTransfer ( EhcUnlinkQhFromPeriod (Ehc, Urb->Qh); RemoveEntryList (&Urb->UrbList); - gBS->FreePool (Urb->Data); EhcFreeUrb (Ehc, Urb); return EFI_SUCCESS; } @@ -809,7 +808,6 @@ EhciDelAllAsyncIntTransfers ( EhcUnlinkQhFromPeriod (Ehc, Urb->Qh); RemoveEntryList (&Urb->UrbList); -gBS->FreePool (Urb->Data); EhcFreeUrb (Ehc, Urb); } } @@ -849,16 +847,8 @@ EhciInsertAsyncIntTransfer ( IN UINTN Interval ) { - VOID *Data; URB *Urb; - Data = AllocatePool (DataLen); - - if (Data == NULL) { -DEBUG ((DEBUG_ERROR, "%a: failed to allocate buffer\n", __FUNCTION__)); -return NULL; - } - Urb = EhcCreateUrb ( Ehc, DevAddr, @@ -869,7 +859,8 @@ EhciInsertAsyncIntTransfer ( Hub, EHC_INT_TRANSFER_ASYNC, NULL, - Data, + TRUE, + NULL, DataLen, Callback, Context, @@ -892,60 +883,6 @@ EhciInsertAsyncIntTransfer ( } /** - Flush data from PCI controller specific address to mapped system - memory address. - - @param EhcThe EHCI device. - @param UrbThe URB to unmap. - - @retval EFI_SUCCESSSuccess to flush data to mapped system memory. - @retval EFI_DEVICE_ERROR Fail to flush data to mapped system memory. - -**/ -EFI_STATUS -EhcFlushAsyncIntMap ( - IN USB2_HC_DEV *Ehc, - IN URB *Urb - ) -{ - EFI_STATUSStatus; - EFI_PHYSICAL_ADDRESS PhyAddr; - EFI_PCI_IO_PROTOCOL_OPERATION MapOp; - EFI_PCI_IO_PROTOCOL *PciIo; - UINTN Len; - VOID *Map; - - PciIo = Ehc->PciIo; - Len = Urb->DataLen; - - if (Urb->Ep.Direction == EfiUsbDataIn) { -MapOp = EfiPciIoOperationBusMasterWrite; - } else { -MapOp = EfiPciIoOperationBusMasterRead; - } - - Status = PciIo->Unmap (PciIo, Urb->DataMap); - if (EFI_ERROR (Status)) { -goto ON_ERROR; - } - - Urb->DataMap = NULL; - - Status = PciIo->Map (PciIo, MapOp, Urb->Data, &Len, &PhyAddr, &Map); - if (EFI_ERROR (Status) || (Len != Urb->DataLen)) { -goto ON_ERROR; - } - - Urb->DataPhy = (VOID *) ((UINTN) PhyAddr); - Urb->DataMap = Map; - return EFI_SUCCESS; - -ON_ERROR: - return EFI_DEVICE_ERROR; -} - - -/** Update the queue head
Re: [edk2] [Patch 0/2] Mtftp: Correct the total received and saved block number.
Series Reviewed-by: Ye Ting -Original Message- From: Wu, Jiaxin Sent: Thursday, October 25, 2018 4:56 PM To: edk2-devel@lists.01.org Cc: Ye, Ting ; Fu, Siyuan ; Wu, Jiaxin Subject: [Patch 0/2] Mtftp: Correct the total received and saved block number. The block returned from Mtftp4RemoveBlockNum is not the total received and saved block number if it works in passive (Slave) mode. The issue was exposed by the EMS test. Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Wu Jiaxin Jiaxin Wu (2): MdeModulePke/Mtftp4Dxe: Correct the total received and saved block number. NetworkPkg/Mtftp6Dxe: Correct the total received and saved block number. .../Universal/Network/Mtftp4Dxe/Mtftp4Impl.h | 6 +- .../Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c | 16 +++- .../Universal/Network/Mtftp4Dxe/Mtftp4Support.c | 10 +- .../Universal/Network/Mtftp4Dxe/Mtftp4Support.h | 6 +++--- .../Universal/Network/Mtftp4Dxe/Mtftp4Wrq.c | 6 +++--- NetworkPkg/Mtftp6Dxe/Mtftp6Impl.h| 6 +- NetworkPkg/Mtftp6Dxe/Mtftp6Rrq.c | 16 +++- NetworkPkg/Mtftp6Dxe/Mtftp6Support.c | 10 +- NetworkPkg/Mtftp6Dxe/Mtftp6Support.h | 8 NetworkPkg/Mtftp6Dxe/Mtftp6Wrq.c | 6 +++--- 10 files changed, 55 insertions(+), 35 deletions(-) -- 2.17.1.windows.2 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 3/4] MdeModulePkg XhciDxe: Use common buffer for AsyncInterruptTransfer
On 10/25/2018 6:58 PM, Star Zeng wrote: REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274 In current code, XhcMonitorAsyncRequests (timer handler) will do unmap and map operations for AsyncIntTransfers to "Flush data from PCI controller specific address to mapped system memory address". XhcMonitorAsyncRequests XhcFlushAsyncIntMap PciIo->Unmap IoMmu->SetAttribute PciIo->Map IoMmu->SetAttribute This may impact the boot performance. Since the data buffer for XhcMonitorAsyncRequests is internal buffer, we can allocate common buffer by PciIo->AllocateBuffer and map the buffer with EfiPciIoOperationBusMasterCommonBuffer, then the unmap and map operations can be removed. /// /// Provides both read and write access to system memory by /// both the processor and a bus master. The buffer is coherent /// from both the processor's and the bus master's point of view. /// EfiPciIoOperationBusMasterCommonBuffer, Test done: USB KB works normally. USB disk read/write works normally. Cc: Ruiyu Ni Cc: Hao Wu Cc: Jian J Wang Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng --- MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 1 + MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 134 +++ MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h | 27 --- 3 files changed, 64 insertions(+), 98 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c index 7f64f9c7c982..64855a4c158c 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c @@ -769,6 +769,7 @@ XhcTransfer ( MaximumPacketLength, Type, Request, + FALSE, Data, *DataLength, NULL, diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c index 2d7c08dc5bfa..d03a6681ce0d 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c @@ -118,17 +118,18 @@ ON_EXIT: /** Create a new URB for a new transaction. - @param Xhc The XHCI Instance - @param BusAddr The logical device address assigned by UsbBus driver - @param EpAddrEndpoint addrress - @param DevSpeed The device speed - @param MaxPacket The max packet length of the endpoint - @param Type The transaction type - @param Request The standard USB request for control transfer - @param Data The user data to transfer - @param DataLen The length of data buffer - @param Callback The function to call when data is transferred - @param Context The context to the callback + @param Xhc The XHCI Instance + @param BusAddr The logical device address assigned by UsbBus driver + @param EpAddrEndpoint addrress + @param DevSpeed The device speed + @param MaxPacket The max packet length of the endpoint + @param Type The transaction type + @param Request The standard USB request for control transfer + @param AllocateCommonBuffer Indicate whether need to allocate common buffer for data transfer + @param Data The user data to transfer, NULL if AllocateCommonBuffer is TRUE + @param DataLen The length of data buffer + @param Callback The function to call when data is transferred + @param Context The context to the callback @return Created URB or NULL @@ -142,6 +143,7 @@ XhcCreateUrb ( IN UINTN MaxPacket, IN UINTN Type, IN EFI_USB_DEVICE_REQUEST *Request, + IN BOOLEANAllocateCommonBuffer, IN VOID *Data, IN UINTN DataLen, IN EFI_ASYNC_USB_TRANSFER_CALLBACKCallback, @@ -169,8 +171,24 @@ XhcCreateUrb ( Ep->Type = Type; Urb->Request = Request; + if (AllocateCommonBuffer) { +ASSERT (Data == NULL); +Status = Xhc->PciIo->AllocateBuffer ( + Xhc->PciIo, + AllocateAnyPages, + EfiBootServicesData, + EFI_SIZE_TO_PAGES (DataLen), + &Data, + 0 + ); +if (EFI_ERROR (Status) || (Data == NULL)) { + FreePool (Urb); + return NULL; +} + } Urb->Data = Data; Urb->DataLen = DataLen; + Urb->AllocateCommonBuffer = AllocateCommonBuffer; Urb->Callback = Callback; Urb->Context = Context; @@ -178,6 +196,11 @@ XhcCreateUrb ( ASSERT_EFI_ERROR (Status); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "XhcCreateUrb: XhcCreateTransferTrb Failed, Status = %r\n", Status)); +Xhc->PciIo->FreeBuffer ( + Xhc->PciIo, +
Re: [edk2] [PATCH] MdeModulePkg/Core: fix an IA32 build failure
Reviewed-by: Star Zeng -Original Message- From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] Sent: Friday, October 26, 2018 12:54 PM To: edk2-devel@lists.01.org Cc: Gao, Liming ; Zeng, Star Subject: [edk2] [PATCH] MdeModulePkg/Core: fix an IA32 build failure REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1277 The failure is caused by data type conversion between UINTN and UINT64, which is checked in at 63ebde8ef6d4ff497d054ccc010904ecd4441198. Cc: Star Zeng Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c index 449a022658..521e0d7b2a 100644 --- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c +++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c @@ -463,7 +463,7 @@ IsGuardPage ( IN EFI_PHYSICAL_ADDRESSAddress ) { - UINTN BitMap; + UINT64BitMap; // // There must be at least one guarded page before and/or after given @@ -1368,7 +1368,7 @@ GuardAllFreedPages ( UINT64Address; UINT64GuardPage; INTN Level; - UINTN BitIndex; + UINT64BitIndex; UINTN GuardPageNumber; if (mGuardedMemoryMap == 0 || @@ -1475,12 +1475,12 @@ MergeGuardPages ( } Bitmap = 0; - Pages = EFI_SIZE_TO_PAGES (MaxAddress - MemoryMapEntry->PhysicalStart); - Pages -= MemoryMapEntry->NumberOfPages; + Pages = EFI_SIZE_TO_PAGES ((UINTN)(MaxAddress - MemoryMapEntry->PhysicalStart)); + Pages -= (INTN)MemoryMapEntry->NumberOfPages; while (Pages > 0) { if (Bitmap == 0) { EndAddress = MemoryMapEntry->PhysicalStart + - EFI_PAGES_TO_SIZE (MemoryMapEntry->NumberOfPages); + EFI_PAGES_TO_SIZE ((UINTN)MemoryMapEntry->NumberOfPages); Bitmap = GetGuardedMemoryBits (EndAddress, GUARDED_HEAP_MAP_ENTRY_BITS); } -- 2.19.0.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 1/4] MdeModulePkg XhciDxe: Extract new XhciInsertAsyncIntTransfer function
On 2018/10/26 12:57, Ni, Ruiyu wrote: On 10/25/2018 6:58 PM, Star Zeng wrote: REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274 Extract new XhciInsertAsyncIntTransfer function from XhcAsyncInterruptTransfer. It is code preparation for following patch, no essential functional change. Cc: Ruiyu Ni Cc: Hao Wu Cc: Jian J Wang Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng --- MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 18 +--- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 74 +--- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h | 28 3 files changed, 98 insertions(+), 22 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c index f1c60bef01c0..7f64f9c7c982 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c @@ -1346,7 +1346,6 @@ XhcAsyncInterruptTransfer ( EFI_STATUS Status; UINT8 SlotId; UINT8 Index; - UINT8 *Data; EFI_TPL OldTpl; // @@ -1413,36 +1412,21 @@ XhcAsyncInterruptTransfer ( goto ON_EXIT; } - Data = AllocateZeroPool (DataLength); - - if (Data == NULL) { - DEBUG ((EFI_D_ERROR, "XhcAsyncInterruptTransfer: failed to allocate buffer\n")); - Status = EFI_OUT_OF_RESOURCES; - goto ON_EXIT; - } - - Urb = XhcCreateUrb ( + Urb = XhciInsertAsyncIntTransfer ( Xhc, DeviceAddress, EndPointAddress, DeviceSpeed, MaximumPacketLength, - XHC_INT_TRANSFER_ASYNC, - NULL, - Data, DataLength, CallBackFunction, Context ); - if (Urb == NULL) { - DEBUG ((EFI_D_ERROR, "XhcAsyncInterruptTransfer: failed to create URB\n")); - FreePool (Data); Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } - InsertHeadList (&Xhc->AsyncIntTransfers, &Urb->UrbList); // // Ring the doorbell // diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c index 166c44bf5e66..2d7c08dc5bfa 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c @@ -264,11 +264,11 @@ XhcCreateTransferTrb ( // No need to remap. // if ((Urb->Data != NULL) && (Urb->DataMap == NULL)) { - if (((UINT8) (Urb->Ep.Direction)) == EfiUsbDataIn) { - MapOp = EfiPciIoOperationBusMasterWrite; - } else { - MapOp = EfiPciIoOperationBusMasterRead; - } + if (((UINT8) (Urb->Ep.Direction)) == EfiUsbDataIn) { + MapOp = EfiPciIoOperationBusMasterWrite; + } else { + MapOp = EfiPciIoOperationBusMasterRead; + } Unnecessary change, right? Yes, it happened when I was splitting the patches. It should be no change here. Thanks, Star Len = Urb->DataLen; Status = Xhc->PciIo->Map (Xhc->PciIo, MapOp, Urb->Data, &Len, &PhyAddr, &Map); @@ -1411,6 +1411,70 @@ XhciDelAllAsyncIntTransfers ( } /** + Insert a single asynchronous interrupt transfer for + the device and endpoint. + + @param Xhc The XHCI Instance + @param BusAddr The logical device address assigned by UsbBus driver + @param EpAddr Endpoint addrress + @param DevSpeed The device speed + @param MaxPacket The max packet length of the endpoint + @param DataLen The length of data buffer + @param Callback The function to call when data is transferred + @param Context The context to the callback + + @return Created URB or NULL + +**/ +URB * +XhciInsertAsyncIntTransfer ( + IN USB_XHCI_INSTANCE *Xhc, + IN UINT8 BusAddr, + IN UINT8 EpAddr, + IN UINT8 DevSpeed, + IN UINTN MaxPacket, + IN UINTN DataLen, + IN EFI_ASYNC_USB_TRANSFER_CALLBACK Callback, + IN VOID *Context + ) +{ + VOID *Data; + URB *Urb; + + Data = AllocateZeroPool (DataLen); + if (Data == NULL) { + DEBUG ((DEBUG_ERROR, "%a: failed to allocate buffer\n", __FUNCTION__)); + return NULL; + } + + Urb = XhcCreateUrb ( + Xhc, + BusAddr, + EpAddr, + DevSpeed, + MaxPacket, + XHC_INT_TRANSFER_ASYNC, + NULL, + Data, + DataLen, + Callback, + Context + ); + if (Urb == NULL) { + DEBUG ((DEBUG_ERROR, "%a: failed to create URB\n", __FUNCTION__)); FreePool (Data) is needed. + return NULL; + } + + // + // New asynchronous transfer must inserted to the head. + // Check the comments in XhcMoniteAsyncRequests + // + InsertHeadList (&Xhc->AsyncIntTransfers, &Urb->UrbList); + + return Urb; +} + +/** Update the queue head for next round
Re: [edk2] [Patch] MdeModulePkg: Specify SmmLockBoxPeiLib library instance for IA32/X64 arch
BaseTools collects PCD information in early phase in order to prepare StrucutrePcd value. At this point, it doesn't know whether the library inf is used or not. So, it checks PCD from all INF files listed in DSC/FDF. This is a behavior change. I don't realize that the unused library INF SmmLockBoxPeiLib is listed in common arch. So, BaseTools behavior change causes the build break in MdeModulePkg EBC Arch. Because this change causes the real impact, we will update this change to keep the original behavior. Then, start new topic on check the unused INF files in DSC/FDF. Thanks Liming > -Original Message- > From: Zeng, Star > Sent: Friday, October 26, 2018 12:29 PM > To: Gao, Liming ; edk2-devel@lists.01.org > Cc: Zeng, Star > Subject: RE: [edk2] [Patch] MdeModulePkg: Specify SmmLockBoxPeiLib library > instance for IA32/X64 arch > > Liming, > > I saw MdeModulePkg only builds > MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf at > EBC arch. > You mean even the *unused* library INF files will be considered? Why? Sorry I > am still confused. > > Thanks, > Star > -Original Message- > From: Gao, Liming > Sent: Friday, October 26, 2018 11:43 AM > To: Zeng, Star ; edk2-devel@lists.01.org > Subject: RE: [edk2] [Patch] MdeModulePkg: Specify SmmLockBoxPeiLib library > instance for IA32/X64 arch > > Star: > Yes. BaseTools commit 51d17bb7b0da0d9c9e91c226f1982d7020f43795 will collect > PCD information from all INF files list in DSC/FDF. > But before, only the used library INF files are considered. This change is to > decide which PCD is really used, then generate the structure > PCD value in the early phase. With this change, SmmLockBoxPeiLib library > instance can't be used for EBC arch. This patch fixes it. > > Thanks > Liming > > -Original Message- > > From: Zeng, Star > > Sent: Friday, October 26, 2018 11:29 AM > > To: Gao, Liming ; edk2-devel@lists.01.org > > Cc: Zeng, Star > > Subject: Re: [edk2] [Patch] MdeModulePkg: Specify SmmLockBoxPeiLib > > library instance for IA32/X64 arch > > > > On 2018/10/26 9:57, Liming Gao wrote: > > > SmmLockBoxPeiLib.inf depends on PcdDxeIplSwitchToLongMode. But, this > > > PCD is defined in MdeModulePkg.dec for IA32 and X64 only. > > > > Could we explain more in the commit log about why this change is not > > needed before but required now? > > > > Thanks, > > Star > > > > > > Contributed-under: TianoCore Contribution Agreement 1.1 > > > Signed-off-by: Liming Gao > > > Cc: Star Zeng > > > --- > > > MdeModulePkg/MdeModulePkg.dsc | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/MdeModulePkg/MdeModulePkg.dsc > > > b/MdeModulePkg/MdeModulePkg.dsc index 2465d39..e88516d 100644 > > > --- a/MdeModulePkg/MdeModulePkg.dsc > > > +++ b/MdeModulePkg/MdeModulePkg.dsc > > > @@ -120,6 +120,8 @@ > > > HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf > > > > > > MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf > > > > > > ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/Pe > > > iExtractGuidedSectionLib.inf > > > + > > > +[LibraryClasses.IA32.PEIM, LibraryClasses.X64.PEIM] > > > > > > LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib.inf > > > > > > [LibraryClasses.common.DXE_CORE] > > > ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 1/4] MdeModulePkg XhciDxe: Extract new XhciInsertAsyncIntTransfer function
On 2018/10/26 12:57, Ni, Ruiyu wrote: On 10/25/2018 6:58 PM, Star Zeng wrote: REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274 Extract new XhciInsertAsyncIntTransfer function from XhcAsyncInterruptTransfer. It is code preparation for following patch, no essential functional change. Cc: Ruiyu Ni Cc: Hao Wu Cc: Jian J Wang Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng --- MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 18 +--- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 74 +--- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h | 28 3 files changed, 98 insertions(+), 22 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c index f1c60bef01c0..7f64f9c7c982 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c @@ -1346,7 +1346,6 @@ XhcAsyncInterruptTransfer ( EFI_STATUS Status; UINT8 SlotId; UINT8 Index; - UINT8 *Data; EFI_TPL OldTpl; // @@ -1413,36 +1412,21 @@ XhcAsyncInterruptTransfer ( goto ON_EXIT; } - Data = AllocateZeroPool (DataLength); - - if (Data == NULL) { - DEBUG ((EFI_D_ERROR, "XhcAsyncInterruptTransfer: failed to allocate buffer\n")); - Status = EFI_OUT_OF_RESOURCES; - goto ON_EXIT; - } - - Urb = XhcCreateUrb ( + Urb = XhciInsertAsyncIntTransfer ( Xhc, DeviceAddress, EndPointAddress, DeviceSpeed, MaximumPacketLength, - XHC_INT_TRANSFER_ASYNC, - NULL, - Data, DataLength, CallBackFunction, Context ); - if (Urb == NULL) { - DEBUG ((EFI_D_ERROR, "XhcAsyncInterruptTransfer: failed to create URB\n")); - FreePool (Data); Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } - InsertHeadList (&Xhc->AsyncIntTransfers, &Urb->UrbList); // // Ring the doorbell // diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c index 166c44bf5e66..2d7c08dc5bfa 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c @@ -264,11 +264,11 @@ XhcCreateTransferTrb ( // No need to remap. // if ((Urb->Data != NULL) && (Urb->DataMap == NULL)) { - if (((UINT8) (Urb->Ep.Direction)) == EfiUsbDataIn) { - MapOp = EfiPciIoOperationBusMasterWrite; - } else { - MapOp = EfiPciIoOperationBusMasterRead; - } + if (((UINT8) (Urb->Ep.Direction)) == EfiUsbDataIn) { + MapOp = EfiPciIoOperationBusMasterWrite; + } else { + MapOp = EfiPciIoOperationBusMasterRead; + } Unnecessary change, right? Len = Urb->DataLen; Status = Xhc->PciIo->Map (Xhc->PciIo, MapOp, Urb->Data, &Len, &PhyAddr, &Map); @@ -1411,6 +1411,70 @@ XhciDelAllAsyncIntTransfers ( } /** + Insert a single asynchronous interrupt transfer for + the device and endpoint. + + @param Xhc The XHCI Instance + @param BusAddr The logical device address assigned by UsbBus driver + @param EpAddr Endpoint addrress + @param DevSpeed The device speed + @param MaxPacket The max packet length of the endpoint + @param DataLen The length of data buffer + @param Callback The function to call when data is transferred + @param Context The context to the callback + + @return Created URB or NULL + +**/ +URB * +XhciInsertAsyncIntTransfer ( + IN USB_XHCI_INSTANCE *Xhc, + IN UINT8 BusAddr, + IN UINT8 EpAddr, + IN UINT8 DevSpeed, + IN UINTN MaxPacket, + IN UINTN DataLen, + IN EFI_ASYNC_USB_TRANSFER_CALLBACK Callback, + IN VOID *Context + ) +{ + VOID *Data; + URB *Urb; + + Data = AllocateZeroPool (DataLen); + if (Data == NULL) { + DEBUG ((DEBUG_ERROR, "%a: failed to allocate buffer\n", __FUNCTION__)); + return NULL; + } + + Urb = XhcCreateUrb ( + Xhc, + BusAddr, + EpAddr, + DevSpeed, + MaxPacket, + XHC_INT_TRANSFER_ASYNC, + NULL, + Data, + DataLen, + Callback, + Context + ); + if (Urb == NULL) { + DEBUG ((DEBUG_ERROR, "%a: failed to create URB\n", __FUNCTION__)); FreePool (Data) is needed. Oh yes, although the final code after this patch series does not need it, but this patch needs it. I need add it, same for patch 2. Thanks for catching it. :) Thanks, Star + return NULL; + } + + // + // New asynchronous transfer must inserted to the head. + // Check the comments in XhcMoniteAsyncRequests + // + InsertHeadList (&Xhc->AsyncIntTransfers, &U
Re: [edk2] [PATCH 2/4] MdeModulePkg EhciDxe: Extract new EhciInsertAsyncIntTransfer function
On 10/25/2018 6:58 PM, Star Zeng wrote: REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274 Extract new EhciInsertAsyncIntTransfer function from EhcAsyncInterruptTransfer. It is code preparation for following patch, no essential functional change. Cc: Ruiyu Ni Cc: Hao Wu Cc: Jian J Wang Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng --- MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c | 25 +-- MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c | 76 MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.h | 36 ++- 3 files changed, 112 insertions(+), 25 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c index 50b5598df4fb..5569f4f9618b 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c @@ -997,7 +997,6 @@ EhcAsyncInterruptTransfer ( URB *Urb; EFI_TPL OldTpl; EFI_STATUS Status; - UINT8 *Data; // // Validate parameters @@ -1046,16 +1045,7 @@ EhcAsyncInterruptTransfer ( EhcAckAllInterrupt (Ehc); - Data = AllocatePool (DataLength); - - if (Data == NULL) { -DEBUG ((EFI_D_ERROR, "EhcAsyncInterruptTransfer: failed to allocate buffer\n")); - -Status = EFI_OUT_OF_RESOURCES; -goto ON_EXIT; - } - - Urb = EhcCreateUrb ( + Urb = EhciInsertAsyncIntTransfer ( Ehc, DeviceAddress, EndPointAddress, @@ -1063,9 +1053,6 @@ EhcAsyncInterruptTransfer ( *DataToggle, MaximumPacketLength, Translator, - EHC_INT_TRANSFER_ASYNC, - NULL, - Data, DataLength, CallBackFunction, Context, @@ -1073,20 +1060,10 @@ EhcAsyncInterruptTransfer ( ); if (Urb == NULL) { -DEBUG ((EFI_D_ERROR, "EhcAsyncInterruptTransfer: failed to create URB\n")); - -gBS->FreePool (Data); Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } - // - // New asynchronous transfer must inserted to the head. - // Check the comments in EhcMoniteAsyncRequests - // - EhcLinkQhToPeriod (Ehc, Urb->Qh); - InsertHeadList (&Ehc->AsyncIntTransfers, &Urb->UrbList); - ON_EXIT: Ehc->PciIo->Flush (Ehc->PciIo); gBS->RestoreTPL (OldTpl); diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c index 168280be81d7..d38340e49c8d 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c @@ -814,6 +814,82 @@ EhciDelAllAsyncIntTransfers ( } } +/** + Insert a single asynchronous interrupt transfer for + the device and endpoint. + + @param Ehc The EHCI device. + @param DevAddr The device address. + @param EpAddrEndpoint addrress & its direction. + @param DevSpeed The device speed. + @param ToggleInitial data toggle to use. + @param MaxPacket The max packet length of the endpoint. + @param Hub The transaction translator to use. + @param Data The user data to transfer. + @param DataLen The length of data buffer. + @param Callback The function to call when data is transferred. + @param Context The context to the callback. + @param Interval The interval for interrupt transfer. + + @return Created URB or NULL. + +**/ +URB * +EhciInsertAsyncIntTransfer ( + IN USB2_HC_DEV*Ehc, + IN UINT8 DevAddr, + IN UINT8 EpAddr, + IN UINT8 DevSpeed, + IN UINT8 Toggle, + IN UINTN MaxPacket, + IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Hub, + IN UINTN DataLen, + IN EFI_ASYNC_USB_TRANSFER_CALLBACKCallback, + IN VOID *Context, + IN UINTN Interval + ) +{ + VOID *Data; + URB *Urb; + + Data = AllocatePool (DataLen); + + if (Data == NULL) { +DEBUG ((DEBUG_ERROR, "%a: failed to allocate buffer\n", __FUNCTION__)); +return NULL; + } + + Urb = EhcCreateUrb ( + Ehc, + DevAddr, + EpAddr, + DevSpeed, + Toggle, + MaxPacket, + Hub, + EHC_INT_TRANSFER_ASYNC, + NULL, + Data, + DataLen, + Callback, + Context, + Interval + ); + + if (Urb == NULL) { +DEBUG ((DEBUG_ERROR, "%a: failed to create URB\n", __FUNCTION__)); FreePool (Data)? +return NULL; + } + + // + // New asynchronous transfer must inserted to the head. + // Check the comments in EhcMoniteAsyncRequests + // + EhcLinkQhToPeriod (Ehc, Urb->Qh); + InsertHeadList (&Ehc->AsyncIntTransfers, &Urb->UrbList); + + r
Re: [edk2] [PATCH 1/4] MdeModulePkg XhciDxe: Extract new XhciInsertAsyncIntTransfer function
On 10/25/2018 6:58 PM, Star Zeng wrote: REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274 Extract new XhciInsertAsyncIntTransfer function from XhcAsyncInterruptTransfer. It is code preparation for following patch, no essential functional change. Cc: Ruiyu Ni Cc: Hao Wu Cc: Jian J Wang Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng --- MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 18 +--- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 74 +--- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h | 28 3 files changed, 98 insertions(+), 22 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c index f1c60bef01c0..7f64f9c7c982 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c @@ -1346,7 +1346,6 @@ XhcAsyncInterruptTransfer ( EFI_STATUS Status; UINT8 SlotId; UINT8 Index; - UINT8 *Data; EFI_TPL OldTpl; // @@ -1413,36 +1412,21 @@ XhcAsyncInterruptTransfer ( goto ON_EXIT; } - Data = AllocateZeroPool (DataLength); - - if (Data == NULL) { -DEBUG ((EFI_D_ERROR, "XhcAsyncInterruptTransfer: failed to allocate buffer\n")); -Status = EFI_OUT_OF_RESOURCES; -goto ON_EXIT; - } - - Urb = XhcCreateUrb ( + Urb = XhciInsertAsyncIntTransfer ( Xhc, DeviceAddress, EndPointAddress, DeviceSpeed, MaximumPacketLength, - XHC_INT_TRANSFER_ASYNC, - NULL, - Data, DataLength, CallBackFunction, Context ); - if (Urb == NULL) { -DEBUG ((EFI_D_ERROR, "XhcAsyncInterruptTransfer: failed to create URB\n")); -FreePool (Data); Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } - InsertHeadList (&Xhc->AsyncIntTransfers, &Urb->UrbList); // // Ring the doorbell // diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c index 166c44bf5e66..2d7c08dc5bfa 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c @@ -264,11 +264,11 @@ XhcCreateTransferTrb ( // No need to remap. // if ((Urb->Data != NULL) && (Urb->DataMap == NULL)) { -if (((UINT8) (Urb->Ep.Direction)) == EfiUsbDataIn) { - MapOp = EfiPciIoOperationBusMasterWrite; -} else { - MapOp = EfiPciIoOperationBusMasterRead; -} + if (((UINT8) (Urb->Ep.Direction)) == EfiUsbDataIn) { +MapOp = EfiPciIoOperationBusMasterWrite; + } else { +MapOp = EfiPciIoOperationBusMasterRead; + } Unnecessary change, right? Len = Urb->DataLen; Status = Xhc->PciIo->Map (Xhc->PciIo, MapOp, Urb->Data, &Len, &PhyAddr, &Map); @@ -1411,6 +1411,70 @@ XhciDelAllAsyncIntTransfers ( } /** + Insert a single asynchronous interrupt transfer for + the device and endpoint. + + @param XhcThe XHCI Instance + @param BusAddrThe logical device address assigned by UsbBus driver + @param EpAddr Endpoint addrress + @param DevSpeed The device speed + @param MaxPacket The max packet length of the endpoint + @param DataLenThe length of data buffer + @param Callback The function to call when data is transferred + @param ContextThe context to the callback + + @return Created URB or NULL + +**/ +URB * +XhciInsertAsyncIntTransfer ( + IN USB_XHCI_INSTANCE *Xhc, + IN UINT8 BusAddr, + IN UINT8 EpAddr, + IN UINT8 DevSpeed, + IN UINTN MaxPacket, + IN UINTN DataLen, + IN EFI_ASYNC_USB_TRANSFER_CALLBACKCallback, + IN VOID *Context + ) +{ + VOID *Data; + URB *Urb; + + Data = AllocateZeroPool (DataLen); + if (Data == NULL) { +DEBUG ((DEBUG_ERROR, "%a: failed to allocate buffer\n", __FUNCTION__)); +return NULL; + } + + Urb = XhcCreateUrb ( + Xhc, + BusAddr, + EpAddr, + DevSpeed, + MaxPacket, + XHC_INT_TRANSFER_ASYNC, + NULL, + Data, + DataLen, + Callback, + Context + ); + if (Urb == NULL) { +DEBUG ((DEBUG_ERROR, "%a: failed to create URB\n", __FUNCTION__)); FreePool (Data) is needed. +return NULL; + } + + // + // New asynchronous transfer must inserted to the head. + // Check the comments in XhcMoniteAsyncRequests + // + InsertHeadList (&Xhc->AsyncIntTransfers, &Urb->UrbList); + + return Urb; +} + +/** Update the queue head for next round of asynchronous transfer @param Xhc The XHCI Instance. diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h b/MdeMo
[edk2] [PATCH] MdeModulePkg/Core: fix an IA32 build failure
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1277 The failure is caused by data type conversion between UINTN and UINT64, which is checked in at 63ebde8ef6d4ff497d054ccc010904ecd4441198. Cc: Star Zeng Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c index 449a022658..521e0d7b2a 100644 --- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c +++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c @@ -463,7 +463,7 @@ IsGuardPage ( IN EFI_PHYSICAL_ADDRESSAddress ) { - UINTN BitMap; + UINT64BitMap; // // There must be at least one guarded page before and/or after given @@ -1368,7 +1368,7 @@ GuardAllFreedPages ( UINT64Address; UINT64GuardPage; INTN Level; - UINTN BitIndex; + UINT64BitIndex; UINTN GuardPageNumber; if (mGuardedMemoryMap == 0 || @@ -1475,12 +1475,12 @@ MergeGuardPages ( } Bitmap = 0; - Pages = EFI_SIZE_TO_PAGES (MaxAddress - MemoryMapEntry->PhysicalStart); - Pages -= MemoryMapEntry->NumberOfPages; + Pages = EFI_SIZE_TO_PAGES ((UINTN)(MaxAddress - MemoryMapEntry->PhysicalStart)); + Pages -= (INTN)MemoryMapEntry->NumberOfPages; while (Pages > 0) { if (Bitmap == 0) { EndAddress = MemoryMapEntry->PhysicalStart + - EFI_PAGES_TO_SIZE (MemoryMapEntry->NumberOfPages); + EFI_PAGES_TO_SIZE ((UINTN)MemoryMapEntry->NumberOfPages); Bitmap = GetGuardedMemoryBits (EndAddress, GUARDED_HEAP_MAP_ENTRY_BITS); } -- 2.19.0.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] MdeModulePkg: Specify SmmLockBoxPeiLib library instance for IA32/X64 arch
Liming, I saw MdeModulePkg only builds MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf at EBC arch. You mean even the *unused* library INF files will be considered? Why? Sorry I am still confused. Thanks, Star -Original Message- From: Gao, Liming Sent: Friday, October 26, 2018 11:43 AM To: Zeng, Star ; edk2-devel@lists.01.org Subject: RE: [edk2] [Patch] MdeModulePkg: Specify SmmLockBoxPeiLib library instance for IA32/X64 arch Star: Yes. BaseTools commit 51d17bb7b0da0d9c9e91c226f1982d7020f43795 will collect PCD information from all INF files list in DSC/FDF. But before, only the used library INF files are considered. This change is to decide which PCD is really used, then generate the structure PCD value in the early phase. With this change, SmmLockBoxPeiLib library instance can't be used for EBC arch. This patch fixes it. Thanks Liming > -Original Message- > From: Zeng, Star > Sent: Friday, October 26, 2018 11:29 AM > To: Gao, Liming ; edk2-devel@lists.01.org > Cc: Zeng, Star > Subject: Re: [edk2] [Patch] MdeModulePkg: Specify SmmLockBoxPeiLib > library instance for IA32/X64 arch > > On 2018/10/26 9:57, Liming Gao wrote: > > SmmLockBoxPeiLib.inf depends on PcdDxeIplSwitchToLongMode. But, this > > PCD is defined in MdeModulePkg.dec for IA32 and X64 only. > > Could we explain more in the commit log about why this change is not > needed before but required now? > > Thanks, > Star > > > > Contributed-under: TianoCore Contribution Agreement 1.1 > > Signed-off-by: Liming Gao > > Cc: Star Zeng > > --- > > MdeModulePkg/MdeModulePkg.dsc | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/MdeModulePkg/MdeModulePkg.dsc > > b/MdeModulePkg/MdeModulePkg.dsc index 2465d39..e88516d 100644 > > --- a/MdeModulePkg/MdeModulePkg.dsc > > +++ b/MdeModulePkg/MdeModulePkg.dsc > > @@ -120,6 +120,8 @@ > > HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf > > > > MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf > > > > ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/Pe > > iExtractGuidedSectionLib.inf > > + > > +[LibraryClasses.IA32.PEIM, LibraryClasses.X64.PEIM] > > > > LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib.inf > > > > [LibraryClasses.common.DXE_CORE] > > ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] UefiCpuPkg/RegisterCpuFeaturesLib: Support combo CPU feature style.
Reviewed-by: Ruiyu Ni > -Original Message- > From: Dong, Eric > Sent: Thursday, October 25, 2018 2:50 PM > To: edk2-devel@lists.01.org > Cc: Ni, Ruiyu ; Laszlo Ersek > Subject: [Patch] UefiCpuPkg/RegisterCpuFeaturesLib: Support combo CPU > feature style. > > Current code assume only one dependence (before or after) for one feature. > Enhance code logic to support feature has two dependence (before and after) > type. > > Cc: Ruiyu Ni > Cc: Laszlo Ersek > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Eric Dong > --- > .../RegisterCpuFeaturesLib/CpuFeaturesInitialize.c | 5 +- > .../RegisterCpuFeaturesLib/RegisterCpuFeatures.h | 8 +- > .../RegisterCpuFeaturesLib.c | 99 > -- > 3 files changed, 45 insertions(+), 67 deletions(-) > > diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c > b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c > index 173f2edbea..bc372a338f 100644 > --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c > +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/CpuFeaturesInitialize.c > @@ -671,10 +671,11 @@ AnalysisProcessorFeatures ( > // If feature has dependence with the next feature (ONLY care > core/package dependency). > // and feature initialize succeed, add sync semaphere here. > // > -BeforeDep = DetectFeatureScope (CpuFeatureInOrder, TRUE); > if (NextCpuFeatureInOrder != NULL) { > - AfterDep = DetectFeatureScope (NextCpuFeatureInOrder, FALSE); > + BeforeDep = DetectFeatureScope (CpuFeatureInOrder, TRUE, > NextCpuFeatureInOrder->FeatureMask); > + AfterDep = DetectFeatureScope (NextCpuFeatureInOrder, FALSE, > + CpuFeatureInOrder->FeatureMask); > } else { > + BeforeDep = DetectFeatureScope (CpuFeatureInOrder, TRUE, > + NULL); >AfterDep = NoneDepType; > } > // > diff --git a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeatures.h > b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeatures.h > index 42a3f91fbf..b5fe8fbce1 100644 > --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeatures.h > +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeatures.h > @@ -193,15 +193,17 @@ DumpCpuFeature ( > /** >Return feature dependence result. > > - @param[in] CpuFeaturePointer to CPU feature. > - @param[in] BeforeCheck before dependence or after. > + @param[in] CpuFeaturePointer to CPU feature. > + @param[in] BeforeCheck before dependence or after. > + @param[in] NextCpuFeatureMaskPointer to next CPU feature Mask. > >@retval return the dependence result. > **/ > CPU_FEATURE_DEPENDENCE_TYPE > DetectFeatureScope ( >IN CPU_FEATURES_ENTRY *CpuFeature, > - IN BOOLEANBefore > + IN BOOLEANBefore, > + IN CHAR8 *NextCpuFeatureMask >); > > /** > diff --git > a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c > b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c > index b6e108b8ad..9a66bc49ff 100644 > --- a/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c > +++ b/UefiCpuPkg/Library/RegisterCpuFeaturesLib/RegisterCpuFeaturesLib.c > @@ -115,90 +115,69 @@ IsBitMaskMatchCheck ( > /** >Return feature dependence result. > > - @param[in] CpuFeaturePointer to CPU feature. > - @param[in] BeforeCheck before dependence or after. > + @param[in] CpuFeaturePointer to CPU feature. > + @param[in] BeforeCheck before dependence or after. > + @param[in] NextCpuFeatureMaskPointer to next CPU feature Mask. > >@retval return the dependence result. > **/ > CPU_FEATURE_DEPENDENCE_TYPE > DetectFeatureScope ( >IN CPU_FEATURES_ENTRY *CpuFeature, > - IN BOOLEANBefore > + IN BOOLEANBefore, > + IN CHAR8 *NextCpuFeatureMask >) > { > + // > + // if need to check before type dependence but the feature after > + current feature is not // exist, means this before type dependence not > valid, > just return NoneDepType. > + // Just like Feature A has a dependence of feature B, but Feature B > + not installed, so // Feature A maybe insert to the last entry of the > + list. In this case, for below code, // Featrure A has depend of > + feature B, but it is the last entry of the list, so the // > + NextCpuFeatureMask is NULL, so the dependence for feature A here is useless > and code // just return NoneDepType. > + // > + if (NextCpuFeatureMask == NULL) { > +return NoneDepType; > + } > + >if (Before) { > -if (CpuFeature->PackageBeforeFeatureBitMask != NULL) { > +if ((CpuFeature->PackageBeforeFeatureBitMask != NULL) && > +IsBitMaskMatchCheck (Ne
Re: [edk2] [Patch] MdeModulePkg RegularExpressionDxe: Remove unknown build option for XCODE
Star: This option is not the default option. To pass GCC build, GCC tool chain adds it. XCODE tool chain doesn't require it, it is not listed for XCODE. Thanks Liming > -Original Message- > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Zeng, > Star > Sent: Friday, October 26, 2018 11:27 AM > To: Gao, Liming ; edk2-devel@lists.01.org > Cc: Zeng, Star > Subject: Re: [edk2] [Patch] MdeModulePkg RegularExpressionDxe: Remove unknown > build option for XCODE > > On 2018/10/26 10:33, Liming Gao wrote: > > This patch makes RegularExpressionDxe pass XCODE5 build. > > > > Contributed-under: TianoCore Contribution Agreement 1.1 > > Signed-off-by: Liming Gao > > Cc: Star Zeng > > --- > > MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf | 4 > > > > 1 file changed, 4 insertions(+) > > > > diff --git > > a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf > b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf > > index df54716..7ccab57 100644 > > --- a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf > > +++ b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf > > @@ -112,3 +112,7 @@ > > > > # Oniguruma: tag_end in parse_callout_of_name > > GCC:*_*_*_CC_FLAGS = -Wno-error=maybe-uninitialized > > + > > + # Not add -Wno-error=maybe-uninitialized option for XCODE > > Use "Eliminate" instead of "Not add" here? :) > > Anyway, Reviewed-by: Star Zeng . > > Thanks, > Star > > > + # XCODE doesn't know this option > > + XCODE:*_*_*_CC_FLAGS = > > > > ___ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] MdeModulePkg: Specify SmmLockBoxPeiLib library instance for IA32/X64 arch
Star: Yes. BaseTools commit 51d17bb7b0da0d9c9e91c226f1982d7020f43795 will collect PCD information from all INF files list in DSC/FDF. But before, only the used library INF files are considered. This change is to decide which PCD is really used, then generate the structure PCD value in the early phase. With this change, SmmLockBoxPeiLib library instance can't be used for EBC arch. This patch fixes it. Thanks Liming > -Original Message- > From: Zeng, Star > Sent: Friday, October 26, 2018 11:29 AM > To: Gao, Liming ; edk2-devel@lists.01.org > Cc: Zeng, Star > Subject: Re: [edk2] [Patch] MdeModulePkg: Specify SmmLockBoxPeiLib library > instance for IA32/X64 arch > > On 2018/10/26 9:57, Liming Gao wrote: > > SmmLockBoxPeiLib.inf depends on PcdDxeIplSwitchToLongMode. But, this PCD is > > defined in MdeModulePkg.dec for IA32 and X64 only. > > Could we explain more in the commit log about why this change is not > needed before but required now? > > Thanks, > Star > > > > Contributed-under: TianoCore Contribution Agreement 1.1 > > Signed-off-by: Liming Gao > > Cc: Star Zeng > > --- > > MdeModulePkg/MdeModulePkg.dsc | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc > > index 2465d39..e88516d 100644 > > --- a/MdeModulePkg/MdeModulePkg.dsc > > +++ b/MdeModulePkg/MdeModulePkg.dsc > > @@ -120,6 +120,8 @@ > > HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf > > > > MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf > > > > ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf > > + > > +[LibraryClasses.IA32.PEIM, LibraryClasses.X64.PEIM] > > LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib.inf > > > > [LibraryClasses.common.DXE_CORE] > > ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] MdeModulePkg: Specify SmmLockBoxPeiLib library instance for IA32/X64 arch
On 2018/10/26 9:57, Liming Gao wrote: SmmLockBoxPeiLib.inf depends on PcdDxeIplSwitchToLongMode. But, this PCD is defined in MdeModulePkg.dec for IA32 and X64 only. Could we explain more in the commit log about why this change is not needed before but required now? Thanks, Star Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao Cc: Star Zeng --- MdeModulePkg/MdeModulePkg.dsc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 2465d39..e88516d 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -120,6 +120,8 @@ HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf + +[LibraryClasses.IA32.PEIM, LibraryClasses.X64.PEIM] LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib.inf [LibraryClasses.common.DXE_CORE] ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] MdeModulePkg RegularExpressionDxe: Remove unknown build option for XCODE
On 2018/10/26 10:33, Liming Gao wrote: This patch makes RegularExpressionDxe pass XCODE5 build. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao Cc: Star Zeng --- MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf | 4 1 file changed, 4 insertions(+) diff --git a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf index df54716..7ccab57 100644 --- a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf +++ b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf @@ -112,3 +112,7 @@ # Oniguruma: tag_end in parse_callout_of_name GCC:*_*_*_CC_FLAGS = -Wno-error=maybe-uninitialized + + # Not add -Wno-error=maybe-uninitialized option for XCODE Use "Eliminate" instead of "Not add" here? :) Anyway, Reviewed-by: Star Zeng . Thanks, Star + # XCODE doesn't know this option + XCODE:*_*_*_CC_FLAGS = ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] IntelFsp2Pkg: Fix GCC49/XCODE build failure
Reviewed-by: jiewen@intel.com > -Original Message- > From: Chiu, Chasel > Sent: Friday, October 26, 2018 11:19 AM > To: edk2-devel@lists.01.org > Cc: Yao, Jiewen ; Desimone, Nathaniel L > ; Chiu, Chasel > Subject: [PATCH] IntelFsp2Pkg: Fix GCC49/XCODE build failure > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1276 > > Fixed potentially uninitialized variable build failure > caused by commit: b1cc6f672f3b924cdb190e5b92db3b47f46a8911 > > Test: Verified on internal platform and boots successfully. > > Cc: Jiewen Yao > Cc: Desimone Nathaniel L > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Chasel Chiu > --- > IntelFsp2Pkg/FspSecCore/SecMain.c | 5 ++--- > 1 file changed, 2 insertions(+), 3 deletions(-) > > diff --git a/IntelFsp2Pkg/FspSecCore/SecMain.c > b/IntelFsp2Pkg/FspSecCore/SecMain.c > index ddbfc4fcdf..f319c68cc5 100644 > --- a/IntelFsp2Pkg/FspSecCore/SecMain.c > +++ b/IntelFsp2Pkg/FspSecCore/SecMain.c > @@ -107,13 +107,12 @@ SecStartup ( > } > IdtSize = sizeof (IdtTableInStack.IdtTable); >} else { > -if (IdtDescriptor.Limit + 1 > sizeof (IdtTableInStack.IdtTable)) { > +IdtSize = IdtDescriptor.Limit + 1; > +if (IdtSize > sizeof (IdtTableInStack.IdtTable)) { >// >// ERROR: IDT table size from boot loader is larger than FSP can > support, DeadLoop here! >// >CpuDeadLoop(); > -} else { > - IdtSize = IdtDescriptor.Limit + 1; > } > CopyMem ((VOID *) (UINTN) &IdtTableInStack.IdtTable, (VOID *) > IdtDescriptor.Base, IdtSize); >} > -- > 2.13.3.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH] IntelFsp2Pkg: Fix GCC49/XCODE build failure
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1276 Fixed potentially uninitialized variable build failure caused by commit: b1cc6f672f3b924cdb190e5b92db3b47f46a8911 Test: Verified on internal platform and boots successfully. Cc: Jiewen Yao Cc: Desimone Nathaniel L Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Chasel Chiu --- IntelFsp2Pkg/FspSecCore/SecMain.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/IntelFsp2Pkg/FspSecCore/SecMain.c b/IntelFsp2Pkg/FspSecCore/SecMain.c index ddbfc4fcdf..f319c68cc5 100644 --- a/IntelFsp2Pkg/FspSecCore/SecMain.c +++ b/IntelFsp2Pkg/FspSecCore/SecMain.c @@ -107,13 +107,12 @@ SecStartup ( } IdtSize = sizeof (IdtTableInStack.IdtTable); } else { -if (IdtDescriptor.Limit + 1 > sizeof (IdtTableInStack.IdtTable)) { +IdtSize = IdtDescriptor.Limit + 1; +if (IdtSize > sizeof (IdtTableInStack.IdtTable)) { // // ERROR: IDT table size from boot loader is larger than FSP can support, DeadLoop here! // CpuDeadLoop(); -} else { - IdtSize = IdtDescriptor.Limit + 1; } CopyMem ((VOID *) (UINTN) &IdtTableInStack.IdtTable, (VOID *) IdtDescriptor.Base, IdtSize); } -- 2.13.3.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 1/1] BaseTools: Use VENDOR_DEVICE_PATH structure for Debug Port device path
Reviewed-by: Yonghong Zhu Best Regards, Zhu Yonghong -Original Message- From: Feng, YunhuaX Sent: Thursday, October 25, 2018 2:00 PM To: edk2-devel@lists.01.org Cc: Zhu, Yonghong ; Gao, Liming Subject: [PATCH 1/1] BaseTools: Use VENDOR_DEVICE_PATH structure for Debug Port device path Copy code from Commit 9343d0a1cd09544686b14dba5b428d7bc811f6b9 Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng --- BaseTools/Source/C/DevicePath/DevicePath.c | 2 +- BaseTools/Source/C/DevicePath/DevicePathFromText.c | 6 +++--- BaseTools/Source/C/Include/Protocol/DevicePath.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/BaseTools/Source/C/DevicePath/DevicePath.c b/BaseTools/Source/C/DevicePath/DevicePath.c index 956bbffb5f..356f5f7e24 100644 --- a/BaseTools/Source/C/DevicePath/DevicePath.c +++ b/BaseTools/Source/C/DevicePath/DevicePath.c @@ -23,11 +23,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. // Utility version information // #define UTILITY_MAJOR_VERSION 0 #define UTILITY_MINOR_VERSION 1 -EFI_GUID gEfiDebugPortDevicePathGuid = DEVICE_PATH_MESSAGING_DEBUGPORT; +EFI_GUID gEfiDebugPortProtocolGuid = DEVICE_PATH_MESSAGING_DEBUGPORT; EFI_GUID gEfiPcAnsiGuid = EFI_PC_ANSI_GUID; EFI_GUID gEfiVT100Guid = EFI_VT_100_GUID; EFI_GUID gEfiVT100PlusGuid = EFI_VT_100_PLUS_GUID; EFI_GUID gEfiVTUTF8Guid = EFI_VT_UTF8_GUID; EFI_GUID gEfiUartDevicePathGuid = EFI_UART_DEVICE_PATH_GUID; diff --git a/BaseTools/Source/C/DevicePath/DevicePathFromText.c b/BaseTools/Source/C/DevicePath/DevicePathFromText.c index bb74e2e170..2647a2020c 100644 --- a/BaseTools/Source/C/DevicePath/DevicePathFromText.c +++ b/BaseTools/Source/C/DevicePath/DevicePathFromText.c @@ -1601,19 +1601,19 @@ DevPathFromTextEmmc ( EFI_DEVICE_PATH_PROTOCOL * DevPathFromTextDebugPort ( CHAR16 *TextDeviceNode ) { - VENDOR_DEFINED_MESSAGING_DEVICE_PATH *Vend; + VENDOR_DEVICE_PATH *Vend; - Vend = (VENDOR_DEFINED_MESSAGING_DEVICE_PATH *) CreateDeviceNode ( + Vend = (VENDOR_DEVICE_PATH *) CreateDeviceNode ( MESSAGING_DEVICE_PATH, MSG_VENDOR_DP, (UINT16) sizeof (VENDOR_DEFINED_MESSAGING_DEVICE_PATH) ); - CopyGuid (&Vend->Guid, &gEfiDebugPortDevicePathGuid); + CopyGuid (&Vend->Guid, &gEfiDebugPortProtocolGuid); return (EFI_DEVICE_PATH_PROTOCOL *) Vend; } /** diff --git a/BaseTools/Source/C/Include/Protocol/DevicePath.h b/BaseTools/Source/C/Include/Protocol/DevicePath.h index 68bb37e479..0295582cbd 100644 --- a/BaseTools/Source/C/Include/Protocol/DevicePath.h +++ b/BaseTools/Source/C/Include/Protocol/DevicePath.h @@ -1378,11 +1378,11 @@ extern EFI_GUID gEfiDebugPortVariableGuid; // // DebugPort device path definitions... // #define DEVICE_PATH_MESSAGING_DEBUGPORT EFI_DEBUGPORT_PROTOCOL_GUID -extern EFI_GUID gEfiDebugPortDevicePathGuid; +extern EFI_GUID gEfiDebugPortProtocolGuid; typedef struct { EFI_DEVICE_PATH_PROTOCOL Header; EFI_GUID Guid; } DEBUGPORT_DEVICE_PATH; -- 2.12.2.windows.2 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 0/2] MdeModulePkg/UsbBusPei: validate HW data before using
Reviewed-by: Star Zeng As I know, you did Recovery test with USB disk for these patches. I think you can add the test information into the commit message of patches. Thanks, Star -Original Message- From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Ruiyu Ni Sent: Thursday, October 25, 2018 6:11 PM To: edk2-devel@lists.01.org Subject: [edk2] [PATCH 0/2] MdeModulePkg/UsbBusPei: validate HW data before using The patches sync the similar fixes to UsbBusDxe to UsbBusPei. Ruiyu Ni (2): MdeModulePkg/UsbBusPei: Fix out-of-bound read access to descriptors MdeModulePkg/UsbBusPei: Reject descriptor whose length is bad MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c | 93 +++- MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h | 11 2 files changed, 67 insertions(+), 37 deletions(-) -- 2.16.1.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 1/1] BaseTools: Fix BPDG tool print traceback info issue
Reviewed-by: Yonghong Zhu Best Regards, Zhu Yonghong -Original Message- From: Feng, YunhuaX Sent: Thursday, October 25, 2018 1:51 PM To: edk2-devel@lists.01.org Cc: Zhu, Yonghong ; Gao, Liming Subject: [PATCH 1/1] BaseTools: Fix BPDG tool print traceback info issue Fix BPDG tool print traceback info issue and remove abundant code Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng --- BaseTools/Source/Python/BPDG/BPDG.py | 5 - BaseTools/Source/Python/Common/VpdInfoFile.py | 5 ++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/BaseTools/Source/Python/BPDG/BPDG.py b/BaseTools/Source/Python/BPDG/BPDG.py index 2ec1516c0a..c30e062a69 100644 --- a/BaseTools/Source/Python/BPDG/BPDG.py +++ b/BaseTools/Source/Python/BPDG/BPDG.py @@ -151,11 +151,14 @@ def StartBpdg(InputFileName, MapFileName, VpdFileName, Force): GenVPD.GenerateVpdFile(MapFileName, VpdFileName) EdkLogger.info("- Vpd pcd fixed done! -") if __name__ == '__main__': -r = main() +try: +r = main() +except FatalError as e: +r = e ## 0-127 is a safe return range, and 1 is a standard default error if r < 0 or r > 127: r = 1 sys.exit(r) diff --git a/BaseTools/Source/Python/Common/VpdInfoFile.py b/BaseTools/Source/Python/Common/VpdInfoFile.py index 0485bf482e..2fb8e66fe9 100644 --- a/BaseTools/Source/Python/Common/VpdInfoFile.py +++ b/BaseTools/Source/Python/Common/VpdInfoFile.py @@ -252,11 +252,10 @@ def CallExtenalBPDGTool(ToolPath, VpdFileName): print(out) while PopenObject.returncode is None : PopenObject.wait() if PopenObject.returncode != 0: -if PopenObject.returncode != 0: -EdkLogger.debug(EdkLogger.DEBUG_1, "Fail to call BPDG tool", str(error)) -EdkLogger.error("BPDG", BuildToolError.COMMAND_FAILURE, "Fail to execute BPDG tool with exit code: %d, the error message is: \n %s" % \ +EdkLogger.debug(EdkLogger.DEBUG_1, "Fail to call BPDG tool", str(error)) +EdkLogger.error("BPDG", BuildToolError.COMMAND_FAILURE, "Fail + to execute BPDG tool with exit code: %d, the error message is: \n %s" + % \ (PopenObject.returncode, str(error))) return PopenObject.returncode -- 2.12.2.windows.2 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [Patch] MdeModulePkg RegularExpressionDxe: Remove unknown build option for XCODE
This patch makes RegularExpressionDxe pass XCODE5 build. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao Cc: Star Zeng --- MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf | 4 1 file changed, 4 insertions(+) diff --git a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf index df54716..7ccab57 100644 --- a/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf +++ b/MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf @@ -112,3 +112,7 @@ # Oniguruma: tag_end in parse_callout_of_name GCC:*_*_*_CC_FLAGS = -Wno-error=maybe-uninitialized + + # Not add -Wno-error=maybe-uninitialized option for XCODE + # XCODE doesn't know this option + XCODE:*_*_*_CC_FLAGS = -- 2.10.0.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [patch 0/2] MdeModulePkg/HiiDatabaseDxe: Make sure database update behaviors are atomic
Reviewed-by: Liming Gao > -Original Message- > From: Bi, Dandan > Sent: Friday, October 12, 2018 7:26 PM > To: edk2-devel@lists.01.org > Cc: Gao, Liming ; Dong, Eric > Subject: [patch 0/2] MdeModulePkg/HiiDatabaseDxe: Make sure database update > behaviors are atomic > > The main purpose of this task is to make sure the operations > that update the HiiDatabase atomic the avoid the potential > risk that the one update operation with higher TPL may interrupt > another. > > Patch 1 is to reorgnize the existing code logic and make it's > easy to add EfiAcquireLock/EfiReleaseLock function in patch 2. > > Patch 2 is to add EfiAcquireLock/EfiReleaseLock function to > make sure the HiiDatabse update operations atomic. > > Cc: Liming Gao > Cc: Eric Dong > Dandan Bi (2): > MdeModulePkg/HiiDB: Reorganize codes of exporting HII settings > MdeModulePkg/HiiDB: Make sure database update behaviors are atomic > > .../Universal/HiiDatabaseDxe/Database.c | 128 -- > .../Universal/HiiDatabaseDxe/HiiDatabase.h| 8 +- > .../HiiDatabaseDxe/HiiDatabaseEntry.c | 3 +- > MdeModulePkg/Universal/HiiDatabaseDxe/Image.c | 12 ++ > .../Universal/HiiDatabaseDxe/String.c | 9 ++ > 5 files changed, 112 insertions(+), 48 deletions(-) > > -- > 2.18.0.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [Patch] MdeModulePkg: Specify SmmLockBoxPeiLib library instance for IA32/X64 arch
SmmLockBoxPeiLib.inf depends on PcdDxeIplSwitchToLongMode. But, this PCD is defined in MdeModulePkg.dec for IA32 and X64 only. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Liming Gao Cc: Star Zeng --- MdeModulePkg/MdeModulePkg.dsc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 2465d39..e88516d 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -120,6 +120,8 @@ HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf + +[LibraryClasses.IA32.PEIM, LibraryClasses.X64.PEIM] LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib.inf [LibraryClasses.common.DXE_CORE] -- 2.10.0.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] BaseTools:Not miss the full assign value of FixedAtBuild structure PCD
Reviewed-by: Bob Feng -Original Message- From: Zhao, ZhiqiangX Sent: Wednesday, October 24, 2018 9:01 PM To: edk2-devel@lists.01.org Cc: Zhao, ZhiqiangX ; Gao, Liming ; Zhu, Yonghong ; Feng, Bob C Subject: [PATCH] BaseTools:Not miss the full assign value of FixedAtBuild structure PCD For structure PCD, if it is a FixedAtBuild PCD, the full assign value in dsc file should not be missed when updating the structure PCD value. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: ZhiqiangX Zhao Cc: Liming Gao Cc: Yonghong Zhu Cc: Bob Feng --- BaseTools/Source/Python/Workspace/DscBuildData.py | 28 +-- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py index b0e88a93ce..e24daa63b6 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -1420,6 +1420,7 @@ class DscBuildData(PlatformBuildClassObject): SkuIds = self.SkuIds self.SkuIdMgr.AvailableSkuIdSet.update({TAB_DEFAULT:0}) DefaultStores = {storename for pcdobj in AllPcds.values() for skuobj in pcdobj.SkuInfoList.values() for storename in skuobj.DefaultStoreDict} +DefaultStores.add(TAB_DEFAULT_STORES_DEFAULT) S_PcdSet = [] # Find out all possible PCD candidates for self._Arch @@ -1589,7 +1590,7 @@ class DscBuildData(PlatformBuildClassObject): # AvailableSkuIdSet = copy.copy(self.SkuIds) -PcdDict = tdict(True, 3) +PcdDict = tdict(True, 4) PcdSet = set() # Find out all possible PCD candidates for self._Arch RecordList = self._RawData[Type, self._Arch] @@ -1600,10 +1601,9 @@ class DscBuildData(PlatformBuildClassObject): if SkuName not in AvailableSkuIdSet: EdkLogger.error('build ', PARAMETER_INVALID, 'Sku %s is not defined in [SkuIds] section' % SkuName, File=self.MetaFile, Line=Dummy5) -if SkuName in (self.SkuIdMgr.SystemSkuId, TAB_DEFAULT, TAB_COMMON): -if "." not in TokenSpaceGuid: -PcdSet.add((PcdCName, TokenSpaceGuid, SkuName, Dummy5)) -PcdDict[Arch, PcdCName, TokenSpaceGuid, SkuName] = Setting +if "." not in TokenSpaceGuid: +PcdSet.add((PcdCName, TokenSpaceGuid, SkuName, Dummy5)) +PcdDict[Arch, PcdCName, TokenSpaceGuid, SkuName] = Setting for PcdCName, TokenSpaceGuid, SkuName, Dummy4 in PcdSet: Setting = PcdDict[self._Arch, PcdCName, TokenSpaceGuid, SkuName] @@ -1646,10 +1646,11 @@ class DscBuildData(PlatformBuildClassObject): False, None, IsDsc=True) - -if self.SkuIdMgr.SystemSkuId not in Pcds[PcdCName, TokenSpaceGuid].DscRawValue: -Pcds[PcdCName, TokenSpaceGuid].DscRawValue[self.SkuIdMgr.SystemSkuId] = {} -Pcds[PcdCName, TokenSpaceGuid].DscRawValue[self.SkuIdMgr.SystemSkuId][TAB_DEFAULT_STORES_DEFAULT] = PcdValue +for SkuName in PcdValueDict[PcdCName, TokenSpaceGuid]: +Settings = PcdValueDict[PcdCName, TokenSpaceGuid][SkuName] +if SkuName not in Pcds[PcdCName, TokenSpaceGuid].DscRawValue: +Pcds[PcdCName, TokenSpaceGuid].DscRawValue[SkuName] = {} +Pcds[PcdCName, + TokenSpaceGuid].DscRawValue[SkuName][TAB_DEFAULT_STORES_DEFAULT] = + Settings[0] return Pcds def GetStructurePcdMaxSize(self, str_pcd): @@ -1884,10 +1885,13 @@ class DscBuildData(PlatformBuildClassObject): CApp = CApp + "// SkuName: %s, DefaultStoreName: %s \n" % (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT) inherit_OverrideValues = Pcd.SkuOverrideValues[SkuName] -if (SkuName, DefaultStoreName) == (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT): -pcddefaultvalue = Pcd.DefaultFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT) if Pcd.DefaultFromDSC else None +if Pcd.Type in PCD_DYNAMIC_TYPE_SET or Pcd.Type in PCD_DYNAMIC_EX_TYPE_SET: +if (SkuName, DefaultStoreName) == (TAB_DEFAULT, TAB_DEFAULT_STORES_DEFAULT): +pcddefaultvalue = Pcd.DefaultFromDSC.get(TAB_DEFAULT, {}).get(TAB_DEFAULT_STORES_DEFAULT) if Pcd.DefaultFromDSC else None +else: +pcddefaultvalue = Pcd.DscRawValue.get(SkuName, + {}).get(DefaultStoreName) else: -pcddefaultvalue = Pcd.DscRawValue.get(SkuName, {}).get(DefaultStoreName) +pcddefaultvalue = Pcd.DscRawValue.get(SkuName, + {}).get(TAB_DEFAULT_STORES_DEFAULT) for FieldList in [pcddefaultvalue, inherit_OverrideValues.get(DefaultStoreName)]: if not FieldList: c
Re: [edk2] [Patch] SecurityPkg/Include/Library/TcgStorageOpalLib.h: Update Pyrite spec revision.
Reviewed-by: Hao Wu Best Regards, Hao Wu > -Original Message- > From: Dong, Eric > Sent: Friday, October 26, 2018 9:15 AM > To: edk2-devel@lists.01.org > Cc: Wu, Hao A > Subject: [Patch] SecurityPkg/Include/Library/TcgStorageOpalLib.h: Update > Pyrite spec revision. > > Pyrite 2.0 spec has been published, update the spec link info for this file. > > Cc: Hao Wu > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Eric Dong > --- > SecurityPkg/Include/Library/TcgStorageOpalLib.h | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/SecurityPkg/Include/Library/TcgStorageOpalLib.h > b/SecurityPkg/Include/Library/TcgStorageOpalLib.h > index 33f8fee183..ef882d5301 100644 > --- a/SecurityPkg/Include/Library/TcgStorageOpalLib.h > +++ b/SecurityPkg/Include/Library/TcgStorageOpalLib.h > @@ -4,8 +4,8 @@ >(TCG Storage Architecture Core Specification, Version 2.01, Revision 1.00, >https://trustedcomputinggroup.org/tcg-storage-architecture-core- > specification/ > > - Storage Work Group Storage Security Subsystem Class: Pyrite, Version 1.00 > Final, Revision 1.00, > - https://trustedcomputinggroup.org/tcg-storage-security-subsystem-class- > pyrite/ > + Storage Work Group Storage Security Subsystem Class: Pyrite, Specification > Version 2.00, Revision 1.00, > + https://trustedcomputinggroup.org/resource/tcg-storage-security- > subsystem-class-pyrite/ > >Storage Work Group Storage Security Subsystem Class: Opal, Version 2.01 > Final, Revision 1.00, >https://trustedcomputinggroup.org/storage-work-group-storage-security- > subsystem-class-opal/ > -- > 2.15.0.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH v4 6/6] MdeModulePkg/Core: add freed-memory guard feature
Sure. Thanks. Regards, Jian > -Original Message- > From: Zeng, Star > Sent: Friday, October 26, 2018 9:19 AM > To: Wang, Jian J ; edk2-devel@lists.01.org > Cc: Kinney, Michael D ; Ni, Ruiyu > ; Yao, Jiewen ; Laszlo Ersek > ; Zeng, Star > Subject: Re: [edk2] [PATCH v4 6/6] MdeModulePkg/Core: add freed-memory > guard feature > > On 2018/10/25 15:18, Jian J Wang wrote: > >> v4 changes: > >> a. replace hard-coded memory attributes with the value got from > >> CoreGetMemorySpaceDescriptor() > >> b. remove the enclosure of CoreAcquireGcdMemoryLock() and > >> CoreReleaseGcdMemoryLock() around CoreAddRange() > > > > Freed-memory guard is used to detect UAF (Use-After-Free) memory issue > > which is illegal access to memory which has been freed. The principle > > behind is similar to heap guard feature, that is we'll turn all pool > > Remember to use "pool/page heap guard feature" instead of "heap guard > feature" here. No need to send new patch series for it. > > Thanks, > Star > > > memory allocation to page allocation and mark them to be not-present > > once they are freed. > > > > This also implies that, once a page is allocated and freed, it cannot > > be re-allocated. This will bring another issue, which is that there's > > risk that memory space will be used out. To address it, the memory > > service add logic to put part (at most 64 pages a time) of freed pages > > back into page pool, so that the memory service can still have memory > > to allocate, when all memory space have been allocated once. This is > > called memory promotion. The promoted pages are always from the eldest > > pages which haven been freed. > > > > This feature brings another problem is that memory map descriptors will > > be increased enormously (200+ -> 2000+). One of change in this patch > > is to update MergeMemoryMap() in file PropertiesTable.c to allow merge > > freed pages back into the memory map. Now the number can stay at around > > 510. > > > > Cc: Star Zeng > > Cc: Michael D Kinney > > Cc: Jiewen Yao > > Cc: Ruiyu Ni > > Cc: Laszlo Ersek > > Contributed-under: TianoCore Contribution Agreement 1.1 > > Signed-off-by: Jian J Wang > > --- > > MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 409 > +- > > MdeModulePkg/Core/Dxe/Mem/HeapGuard.h | 65 +++- > > MdeModulePkg/Core/Dxe/Mem/Page.c | 42 ++- > > MdeModulePkg/Core/Dxe/Mem/Pool.c | 23 +- > > MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 2 +- > > MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c | 18 +- > > 6 files changed, 525 insertions(+), 34 deletions(-) > > > > diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c > b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c > > index 663f969c0d..449a022658 100644 > > --- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c > > +++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c > > @@ -44,6 +44,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED UINTN > mLevelShift[GUARDED_HEAP_MAP_TABLE_DEPTH] > > GLOBAL_REMOVE_IF_UNREFERENCED UINTN > mLevelMask[GUARDED_HEAP_MAP_TABLE_DEPTH] > > = GUARDED_HEAP_MAP_TABLE_DEPTH_MASKS; > > > > +// > > +// Used for promoting freed but not used pages. > > +// > > +GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS > mLastPromotedPage = BASE_4GB; > > + > > /** > > Set corresponding bits in bitmap table to 1 according to the address. > > > > @@ -379,7 +384,7 @@ ClearGuardedMemoryBits ( > > > > @return An integer containing the guarded memory bitmap. > > **/ > > -UINTN > > +UINT64 > > GetGuardedMemoryBits ( > > IN EFI_PHYSICAL_ADDRESSAddress, > > IN UINTN NumberOfPages > > @@ -387,7 +392,7 @@ GetGuardedMemoryBits ( > > { > > UINT64*BitMap; > > UINTN Bits; > > - UINTN Result; > > + UINT64Result; > > UINTN Shift; > > UINTN BitsToUnitEnd; > > > > @@ -660,15 +665,16 @@ IsPageTypeToGuard ( > > /** > > Check to see if the heap guard is enabled for page and/or pool > > allocation. > > > > + @param[in] GuardType Specify the sub-type(s) of Heap Guard. > > + > > @return TRUE/FALSE. > > **/ > > BOOLEAN > > IsHeapGuardEnabled ( > > - VOID > > + UINT8 GuardType > > ) > > { > > - return IsMemoryTypeToGuard (EfiMaxMemoryType, AllocateAnyPages, > > - GUARD_HEAP_TYPE_POOL|GUARD_HEAP_TYPE_PAGE); > > + return IsMemoryTypeToGuard (EfiMaxMemoryType, AllocateAnyPages, > GuardType); > > } > > > > /** > > @@ -1203,6 +1209,380 @@ SetAllGuardPages ( > > } > > } > > > > +/** > > + Find the address of top-most guarded free page. > > + > > + @param[out] AddressStart address of top-most guarded free page. > > + > > + @return VOID. > > +**/ > > +VOID > > +GetLastGuardedFreePageAddress ( > > + OUT EFI_PHYSICAL_ADDRESS *Address > > + ) > > +{ > > + EFI_PHYSICAL_ADDRESSAddressGranularity; > > + EFI_PHYSICAL_ADDR
Re: [edk2] [PATCH v4 5/6] MdeModulePkg/Core: prevent re-acquire GCD memory lock
Sorry missing that one. I'll update it. Thanks for the comments. Regards, Jian > -Original Message- > From: Zeng, Star > Sent: Friday, October 26, 2018 9:18 AM > To: Wang, Jian J ; edk2-devel boun...@lists.01.org>; edk2-devel@lists.01.org > Cc: Kinney, Michael D ; Ni, Ruiyu > ; Yao, Jiewen ; Laszlo Ersek > ; Zeng, Star > Subject: Re: [edk2] [PATCH v4 5/6] MdeModulePkg/Core: prevent re-acquire > GCD memory lock > > On 2018/10/25 15:20, Wang, Jian J wrote: > > Sorry, forgot to update commit message: > > > >> This issue is hidden in current code but exposed by introduction > >> of freed-memory guard feature due to the fact that the feature > >> will turn all pool allocation to page allocation. > >> > >> The solution is moving the memory allocation in CoreGetMemorySpaceMap() > >> to be out of the GCD memory map lock. > > > > Regards, > > Jian > > > > > >> -Original Message- > >> From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] > >> Sent: Thursday, October 25, 2018 3:18 PM > >> To: edk2-devel@lists.01.org > >> Cc: Kinney, Michael D ; Ni, Ruiyu > >> ; Yao, Jiewen ; Zeng, Star > >> ; Laszlo Ersek > >> Subject: [edk2] [PATCH v4 5/6] MdeModulePkg/Core: prevent re-acquire GCD > >> memory lock > >> > >>> v4 changes: > >>> a. add more comments from Laszlo > >> > >> This issue is hidden in current code but exposed by introduction > >> of freed-memory guard feature due to the fact that the feature > >> will turn all pool allocation to page allocation. > >> > >> The solution is move the memory allocation in CoreGetMemorySpaceMap() > >> and CoreGetIoSpaceMap() to be out of the GCD memory map lock. > >> > >> CoreDumpGcdMemorySpaceMap() > >> => CoreGetMemorySpaceMap() > >> => CoreAcquireGcdMemoryLock () * > >> AllocatePool() > >> => InternalAllocatePool() > >> => CoreAllocatePool() > >> => CoreAllocatePoolI() > >> => CoreAllocatePoolPagesI() > >> => CoreAllocatePoolPages() > >> => FindFreePages() > >> => PromoteMemoryResource() > >> => CoreAcquireGcdMemoryLock() ** > >> > >> Cc: Star Zeng > >> Cc: Michael D Kinney > >> Cc: Jiewen Yao > >> Cc: Ruiyu Ni > >> Cc: Laszlo Ersek > >> Contributed-under: TianoCore Contribution Agreement 1.1 > >> Signed-off-by: Jian J Wang > >> --- > >> MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 87 > +- > >> --- > >> 1 file changed, 62 insertions(+), 25 deletions(-) > >> > >> diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c > >> b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c > >> index d9c65a8045..f99d6bb933 100644 > >> --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c > >> +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c > >> @@ -1691,10 +1691,10 @@ CoreGetMemorySpaceMap ( > >> OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR **MemorySpaceMap > >> ) > >> { > >> - EFI_STATUS Status; > >> LIST_ENTRY *Link; > >> EFI_GCD_MAP_ENTRY*Entry; > >> EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Descriptor; > >> + UINTNDescriptorCount; > >> > >> // > >> // Make sure parameters are valid > >> @@ -1706,38 +1706,75 @@ CoreGetMemorySpaceMap ( > >> return EFI_INVALID_PARAMETER; > >> } > >> > >> - CoreAcquireGcdMemoryLock (); > >> + *NumberOfDescriptors = 0; > >> + *MemorySpaceMap = NULL; > >> > >> // > >> - // Count the number of descriptors > >> + // Take the lock, for entering the loop with the lock held. > >> // > >> - *NumberOfDescriptors = CoreCountGcdMapEntry > (&mGcdMemorySpaceMap); > >> + CoreAcquireGcdMemoryLock (); > >> + while (TRUE) { > >> +// > >> +// Count the number of descriptors. It might be done more than once > > How about using "Count the descriptors" here? No need to send new patch > series for it. > > >> because > >> +// there's code which has to be running outside the GCD lock. > > I have given comment for this line at V3 series. > How about using "AllocatePool() calling code below" instead of "there's > code" to be more specific? > > Thanks, > Star > > >> +// > >> +DescriptorCount = CoreCountGcdMapEntry (&mGcdMemorySpaceMap); > >> +if (DescriptorCount == *NumberOfDescriptors) { > >> + // > >> + // Fill in the MemorySpaceMap if no memory space map change. > >> + // > >> + Descriptor = *MemorySpaceMap; > >> + Link = mGcdMemorySpaceMap.ForwardLink; > >> + while (Link != &mGcdMemorySpaceMap) { > >> +Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, > EFI_GCD_MAP_SIGNATURE); > >> +BuildMemoryDescriptor (Descriptor, Entry); > >> +Descriptor++; > >> +Link = Link->ForwardLink; > >> + } > >> + // > >> + // We're done; exit the loop with the lock held. > >> + // > >> + break; > >> +} > >> > >> - // > >> - // Allocate the MemorySpaceMap > >> - // > >> - *MemorySpaceMap = AllocatePool (*NumberOfDescriptors * sizeof > >> (EFI_GCD_MEMORY_SPACE_DESCRIPTOR)); > >> - if (*MemorySpaceMap == NULL) { > >> -Status = EFI_OUT_OF_R
Re: [edk2] [PATCH v4 6/6] MdeModulePkg/Core: add freed-memory guard feature
On 2018/10/25 15:18, Jian J Wang wrote: v4 changes: a. replace hard-coded memory attributes with the value got from CoreGetMemorySpaceDescriptor() b. remove the enclosure of CoreAcquireGcdMemoryLock() and CoreReleaseGcdMemoryLock() around CoreAddRange() Freed-memory guard is used to detect UAF (Use-After-Free) memory issue which is illegal access to memory which has been freed. The principle behind is similar to heap guard feature, that is we'll turn all pool Remember to use "pool/page heap guard feature" instead of "heap guard feature" here. No need to send new patch series for it. Thanks, Star memory allocation to page allocation and mark them to be not-present once they are freed. This also implies that, once a page is allocated and freed, it cannot be re-allocated. This will bring another issue, which is that there's risk that memory space will be used out. To address it, the memory service add logic to put part (at most 64 pages a time) of freed pages back into page pool, so that the memory service can still have memory to allocate, when all memory space have been allocated once. This is called memory promotion. The promoted pages are always from the eldest pages which haven been freed. This feature brings another problem is that memory map descriptors will be increased enormously (200+ -> 2000+). One of change in this patch is to update MergeMemoryMap() in file PropertiesTable.c to allow merge freed pages back into the memory map. Now the number can stay at around 510. Cc: Star Zeng Cc: Michael D Kinney Cc: Jiewen Yao Cc: Ruiyu Ni Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 409 +- MdeModulePkg/Core/Dxe/Mem/HeapGuard.h | 65 +++- MdeModulePkg/Core/Dxe/Mem/Page.c | 42 ++- MdeModulePkg/Core/Dxe/Mem/Pool.c | 23 +- MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 2 +- MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c | 18 +- 6 files changed, 525 insertions(+), 34 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c index 663f969c0d..449a022658 100644 --- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c +++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c @@ -44,6 +44,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED UINTN mLevelShift[GUARDED_HEAP_MAP_TABLE_DEPTH] GLOBAL_REMOVE_IF_UNREFERENCED UINTN mLevelMask[GUARDED_HEAP_MAP_TABLE_DEPTH] = GUARDED_HEAP_MAP_TABLE_DEPTH_MASKS; +// +// Used for promoting freed but not used pages. +// +GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS mLastPromotedPage = BASE_4GB; + /** Set corresponding bits in bitmap table to 1 according to the address. @@ -379,7 +384,7 @@ ClearGuardedMemoryBits ( @return An integer containing the guarded memory bitmap. **/ -UINTN +UINT64 GetGuardedMemoryBits ( IN EFI_PHYSICAL_ADDRESSAddress, IN UINTN NumberOfPages @@ -387,7 +392,7 @@ GetGuardedMemoryBits ( { UINT64*BitMap; UINTN Bits; - UINTN Result; + UINT64Result; UINTN Shift; UINTN BitsToUnitEnd; @@ -660,15 +665,16 @@ IsPageTypeToGuard ( /** Check to see if the heap guard is enabled for page and/or pool allocation. + @param[in] GuardType Specify the sub-type(s) of Heap Guard. + @return TRUE/FALSE. **/ BOOLEAN IsHeapGuardEnabled ( - VOID + UINT8 GuardType ) { - return IsMemoryTypeToGuard (EfiMaxMemoryType, AllocateAnyPages, - GUARD_HEAP_TYPE_POOL|GUARD_HEAP_TYPE_PAGE); + return IsMemoryTypeToGuard (EfiMaxMemoryType, AllocateAnyPages, GuardType); } /** @@ -1203,6 +1209,380 @@ SetAllGuardPages ( } } +/** + Find the address of top-most guarded free page. + + @param[out] AddressStart address of top-most guarded free page. + + @return VOID. +**/ +VOID +GetLastGuardedFreePageAddress ( + OUT EFI_PHYSICAL_ADDRESS *Address + ) +{ + EFI_PHYSICAL_ADDRESSAddressGranularity; + EFI_PHYSICAL_ADDRESSBaseAddress; + UINTN Level; + UINT64 Map; + INTNIndex; + + ASSERT (mMapLevel >= 1); + + BaseAddress = 0; + Map = mGuardedMemoryMap; + for (Level = GUARDED_HEAP_MAP_TABLE_DEPTH - mMapLevel; + Level < GUARDED_HEAP_MAP_TABLE_DEPTH; + ++Level) { +AddressGranularity = LShiftU64 (1, mLevelShift[Level]); + +// +// Find the non-NULL entry at largest index. +// +for (Index = (INTN)mLevelMask[Level]; Index >= 0 ; --Index) { + if (((UINT64 *)(UINTN)Map)[Index] != 0) { +BaseAddress += MultU64x32 (AddressGranularity, (UINT32)Index); +Map = ((UINT64 *)(UINTN)Map)[Index]; +break; + } +} + } + + // + // Find the non-zero MSB then get the page address. + // + w
Re: [edk2] [PATCH v4 5/6] MdeModulePkg/Core: prevent re-acquire GCD memory lock
On 2018/10/25 15:20, Wang, Jian J wrote: Sorry, forgot to update commit message: This issue is hidden in current code but exposed by introduction of freed-memory guard feature due to the fact that the feature will turn all pool allocation to page allocation. The solution is moving the memory allocation in CoreGetMemorySpaceMap() to be out of the GCD memory map lock. Regards, Jian -Original Message- From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] Sent: Thursday, October 25, 2018 3:18 PM To: edk2-devel@lists.01.org Cc: Kinney, Michael D ; Ni, Ruiyu ; Yao, Jiewen ; Zeng, Star ; Laszlo Ersek Subject: [edk2] [PATCH v4 5/6] MdeModulePkg/Core: prevent re-acquire GCD memory lock v4 changes: a. add more comments from Laszlo This issue is hidden in current code but exposed by introduction of freed-memory guard feature due to the fact that the feature will turn all pool allocation to page allocation. The solution is move the memory allocation in CoreGetMemorySpaceMap() and CoreGetIoSpaceMap() to be out of the GCD memory map lock. CoreDumpGcdMemorySpaceMap() => CoreGetMemorySpaceMap() => CoreAcquireGcdMemoryLock () * AllocatePool() => InternalAllocatePool() => CoreAllocatePool() => CoreAllocatePoolI() => CoreAllocatePoolPagesI() => CoreAllocatePoolPages() => FindFreePages() => PromoteMemoryResource() => CoreAcquireGcdMemoryLock() ** Cc: Star Zeng Cc: Michael D Kinney Cc: Jiewen Yao Cc: Ruiyu Ni Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 87 +- --- 1 file changed, 62 insertions(+), 25 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index d9c65a8045..f99d6bb933 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -1691,10 +1691,10 @@ CoreGetMemorySpaceMap ( OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR **MemorySpaceMap ) { - EFI_STATUS Status; LIST_ENTRY *Link; EFI_GCD_MAP_ENTRY*Entry; EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Descriptor; + UINTNDescriptorCount; // // Make sure parameters are valid @@ -1706,38 +1706,75 @@ CoreGetMemorySpaceMap ( return EFI_INVALID_PARAMETER; } - CoreAcquireGcdMemoryLock (); + *NumberOfDescriptors = 0; + *MemorySpaceMap = NULL; // - // Count the number of descriptors + // Take the lock, for entering the loop with the lock held. // - *NumberOfDescriptors = CoreCountGcdMapEntry (&mGcdMemorySpaceMap); + CoreAcquireGcdMemoryLock (); + while (TRUE) { +// +// Count the number of descriptors. It might be done more than once How about using "Count the descriptors" here? No need to send new patch series for it. because +// there's code which has to be running outside the GCD lock. I have given comment for this line at V3 series. How about using "AllocatePool() calling code below" instead of "there's code" to be more specific? Thanks, Star +// +DescriptorCount = CoreCountGcdMapEntry (&mGcdMemorySpaceMap); +if (DescriptorCount == *NumberOfDescriptors) { + // + // Fill in the MemorySpaceMap if no memory space map change. + // + Descriptor = *MemorySpaceMap; + Link = mGcdMemorySpaceMap.ForwardLink; + while (Link != &mGcdMemorySpaceMap) { +Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE); +BuildMemoryDescriptor (Descriptor, Entry); +Descriptor++; +Link = Link->ForwardLink; + } + // + // We're done; exit the loop with the lock held. + // + break; +} - // - // Allocate the MemorySpaceMap - // - *MemorySpaceMap = AllocatePool (*NumberOfDescriptors * sizeof (EFI_GCD_MEMORY_SPACE_DESCRIPTOR)); - if (*MemorySpaceMap == NULL) { -Status = EFI_OUT_OF_RESOURCES; -goto Done; - } +// +// Release the lock before memory allocation, because it might cause +// GCD lock conflict in one of calling path in AllocatPool(). +// +CoreReleaseGcdMemoryLock (); + +// +// Allocate memory to store the MemorySpaceMap. Note it might be already +// allocated if there's map descriptor change during memory allocation at +// last time. +// +if (*MemorySpaceMap != NULL) { + FreePool (*MemorySpaceMap); +} +*MemorySpaceMap = AllocatePool (DescriptorCount * +sizeof (EFI_GCD_MEMORY_SPACE_DESCRIPTOR)); +if (*MemorySpaceMap == NULL) { + *NumberOfDescriptors = 0; + return EFI_OUT_OF_RESOURCES; +} + +// +// Save the descriptor count got before for another round of check to make +// sure we won't miss any, since we have code running outside the GCD lock. +// +*NumberOfDescriptors = DescriptorCount; +// +// Re-acquire the lock, for the next iteration. +
Re: [edk2] [PATCH v4 0/6] Introduce freed-memory guard feature
On 2018/10/25 15:17, Jian J Wang wrote: v4 changes: Updated per comments from Star. Please refer to individual patch file for details (#2/5/6) Minor comments to patch 5 and 6, please see the individual feedback. With them addressed, Reviewed-by: Star Zeng to patch 1, 2, 5 and 6. And remember to add RB from Laszlo, I think at least you can add RB from Laszlo for patch 1, maybe patch 2 about MdeModulePkg change. Thanks, Star Freed-memory guard is a new feauture used to detect UAF (Use-After-Free) memory issue. Tests: a. Feature basic unit/functionality test b. OVMF regression test Jian J Wang (6): MdeModulePkg: cleanup Heap Guard pool/page type PCD documentation MdeModulePkg: introduce UEFI freed-memory guard bit in HeapGuard PCD UefiCpuPkg/CpuDxe: consider freed-memory guard in non-stop mode UefiCpuPkg/CpuDxe: prevent recursive calling of InitializePageTablePool MdeModulePkg/Core: prevent re-acquire GCD memory lock MdeModulePkg/Core: add freed-memory guard feature MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 87 -- MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 409 +- MdeModulePkg/Core/Dxe/Mem/HeapGuard.h | 65 +++- MdeModulePkg/Core/Dxe/Mem/Page.c | 42 ++- MdeModulePkg/Core/Dxe/Mem/Pool.c | 23 +- MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 2 +- MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c | 18 +- MdeModulePkg/MdeModulePkg.dec | 20 +- MdeModulePkg/MdeModulePkg.uni | 16 +- UefiCpuPkg/CpuDxe/CpuDxe.h| 2 +- UefiCpuPkg/CpuDxe/CpuPageTable.c | 23 +- 11 files changed, 637 insertions(+), 70 deletions(-) ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [Patch] SecurityPkg/Include/Library/TcgStorageOpalLib.h: Update Pyrite spec revision.
Pyrite 2.0 spec has been published, update the spec link info for this file. Cc: Hao Wu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Eric Dong --- SecurityPkg/Include/Library/TcgStorageOpalLib.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SecurityPkg/Include/Library/TcgStorageOpalLib.h b/SecurityPkg/Include/Library/TcgStorageOpalLib.h index 33f8fee183..ef882d5301 100644 --- a/SecurityPkg/Include/Library/TcgStorageOpalLib.h +++ b/SecurityPkg/Include/Library/TcgStorageOpalLib.h @@ -4,8 +4,8 @@ (TCG Storage Architecture Core Specification, Version 2.01, Revision 1.00, https://trustedcomputinggroup.org/tcg-storage-architecture-core-specification/ - Storage Work Group Storage Security Subsystem Class: Pyrite, Version 1.00 Final, Revision 1.00, - https://trustedcomputinggroup.org/tcg-storage-security-subsystem-class-pyrite/ + Storage Work Group Storage Security Subsystem Class: Pyrite, Specification Version 2.00, Revision 1.00, + https://trustedcomputinggroup.org/resource/tcg-storage-security-subsystem-class-pyrite/ Storage Work Group Storage Security Subsystem Class: Opal, Version 2.01 Final, Revision 1.00, https://trustedcomputinggroup.org/storage-work-group-storage-security-subsystem-class-opal/ -- 2.15.0.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] CryptoPkg/BaseCryptLib: Fix potential integer overflow issue.
Reviewed-by: Ye Ting -Original Message- From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Long Qin Sent: Wednesday, October 24, 2018 9:22 PM To: edk2-devel@lists.01.org Cc: Ye, Ting Subject: [edk2] [PATCH] CryptoPkg/BaseCryptLib: Fix potential integer overflow issue. The LookupFreeMemRegion() in RuntimeMemAllocate.c is used to look-up free memory region for runtime resource allocation, which was designed to support runtime authenticated variable service. The direct offset subtractions in this function may bring possible integer overflow issue. This patch is to add the extra parameter checks to remove this possible overflow risk. Cc: Ye Ting Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Long Qin --- .../Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c| 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c b/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c index 463f2bf855..92bb9ddccd 100644 --- a/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c +++ b/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c @@ -2,7 +2,7 @@ Light-weight Memory Management Routines for OpenSSL-based Crypto Library at Runtime Phase. -Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved. +Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -141,6 +141,12 @@ LookupFreeMemRegion ( StartPageIndex = RT_SIZE_TO_PAGES (mRTPageTable->LastEmptyPageOffset); ReqPages = RT_SIZE_TO_PAGES (AllocationSize); + if (ReqPages > mRTPageTable->PageCount) { +// +// No enough region for object allocation. +// +return (UINTN)(-1); + } // // Look up the free memory region with in current memory map table. @@ -176,6 +182,12 @@ LookupFreeMemRegion ( // Look up the free memory region from the beginning of the memory table // until the StartCursorOffset // + if (ReqPages > StartPageIndex) { +// +// No enough region for object allocation. +// +return (UINTN)(-1); + } for (Index = 0; Index < (StartPageIndex - ReqPages); ) { // // Check Consecutive ReqPages Pages. -- 2.16.1.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH v4 4/6] UefiCpuPkg/CpuDxe: prevent recursive calling of InitializePageTablePool
Reviewed-by: Eric Dong > -Original Message- > From: Wang, Jian J > Sent: Thursday, October 25, 2018 3:18 PM > To: edk2-devel@lists.01.org > Cc: Dong, Eric ; Laszlo Ersek ; > Zeng, Star ; Kinney, Michael D > ; Yao, Jiewen ; Ni, > Ruiyu > Subject: [PATCH v4 4/6] UefiCpuPkg/CpuDxe: prevent recursive calling of > InitializePageTablePool > > > v4 changes: none > > The freed-memory guard feature will cause an recursive calling of > InitializePageTablePool(). This is due to a fact that > AllocateAlignedPages() is used to allocate page table pool memory. > This function will most likely call gBS->FreePages to free unaligned pages and > then cause another round of page attributes change, like below (freed pages > will be always marked not-present if freed-memory guard is enabled) > >FreePages() <===| > => CpuSetMemoryAttributes()| > => | > => InitializePageTablePool() | > => AllocateAlignedPages() | > => FreePages() | > > The solution is add a global variable as a lock in page table pool allocation > function and fail any other requests if it has not been done. > > Since this issue will only happen if free-memory guard is enabled, it won't > affect CpuSetMemoryAttributes() in default build of a BIOS. > > If free-memory guard is enabled, it only affect the pages (failed to mark > them as not-present) freed in AllocateAlignedPages(). > > Since those freed pages haven't been used yet (their addresses not yet > exposed to code outside AllocateAlignedPages), it won't compromise the > freed-memory guard feature. > > This change will just fail the CpuSetMemoryAttributes() called from > FreePages() but it won't fail the FreePages(). So the error status won't be > propagated upper layer of code. > > Cc: Eric Dong > Cc: Laszlo Ersek > Cc: Star Zeng > Cc: Michael D Kinney > Cc: Jiewen Yao > Cc: Ruiyu Ni > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Jian J Wang > --- > UefiCpuPkg/CpuDxe/CpuPageTable.c | 23 +-- > 1 file changed, 21 insertions(+), 2 deletions(-) > > diff --git a/UefiCpuPkg/CpuDxe/CpuPageTable.c > b/UefiCpuPkg/CpuDxe/CpuPageTable.c > index 33e8ee2d2c..4bee8c7772 100644 > --- a/UefiCpuPkg/CpuDxe/CpuPageTable.c > +++ b/UefiCpuPkg/CpuDxe/CpuPageTable.c > @@ -100,6 +100,7 @@ PAGE_ATTRIBUTE_TABLE mPageAttributeTable[] = { }; > > PAGE_TABLE_POOL *mPageTablePool = NULL; > +BOOLEAN mPageTablePoolLock = FALSE; > PAGE_TABLE_LIB_PAGING_CONTEXT mPagingContext; > EFI_SMM_BASE2_PROTOCOL*mSmmBase2 = NULL; > > @@ -1046,6 +1047,16 @@ InitializePageTablePool ( >VOID *Buffer; >BOOLEAN IsModified; > > + // > + // Do not allow re-entrance. > + // > + if (mPageTablePoolLock) { > +return FALSE; > + } > + > + mPageTablePoolLock = TRUE; > + IsModified = FALSE; > + >// >// Always reserve at least PAGE_TABLE_POOL_UNIT_PAGES, including one > page for >// header. > @@ -1056,9 +1067,15 @@ InitializePageTablePool ( >Buffer = AllocateAlignedPages (PoolPages, > PAGE_TABLE_POOL_ALIGNMENT); >if (Buffer == NULL) { > DEBUG ((DEBUG_ERROR, "ERROR: Out of aligned pages\r\n")); > -return FALSE; > +goto Done; >} > > + DEBUG (( > +DEBUG_INFO, > +"Paging: added %lu pages to page table pool\r\n", > +(UINT64)PoolPages > +)); > + >// >// Link all pools into a list for easier track later. >// > @@ -1092,7 +1109,9 @@ InitializePageTablePool ( > ); >ASSERT (IsModified == TRUE); > > - return TRUE; > +Done: > + mPageTablePoolLock = FALSE; > + return IsModified; > } > > /** > -- > 2.16.2.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH v4 3/6] UefiCpuPkg/CpuDxe: consider freed-memory guard in non-stop mode
Reviewed-by: Eric Dong > -Original Message- > From: Wang, Jian J > Sent: Thursday, October 25, 2018 3:18 PM > To: edk2-devel@lists.01.org > Cc: Dong, Eric ; Laszlo Ersek ; > Zeng, Star ; Kinney, Michael D > ; Yao, Jiewen ; Ni, > Ruiyu > Subject: [PATCH v4 3/6] UefiCpuPkg/CpuDxe: consider freed-memory guard > in non-stop mode > > > v4 changes: none > > Non-stop mode was introduced / explained in commit 8f2613628acf > ("MdeModulePkg/MdeModulePkg.dec: add new settings for PCDs", 2018- > 08-30). > > The macro HEAP_GUARD_NONSTOP_MODE was added to CpuDxe in commit > dcc026217fdc ("UefiCpuPkg/CpuDxe: implement non-stop mode for uefi", > 2018-08-30). > > Another instance of the macro HEAP_GUARD_NONSTOP_MODE was added > to PiSmmCpuDxeSmm -- with BIT1|BIT0 replaced with BIT3|BIT2 -- in commit > 09afd9a42a7f ("UefiCpuPkg/PiSmmCpuDxeSmm: implement non-stop mode > for SMM", 2018-08-30) > > Since the freed-memory guard is for UEFI-only. This patch only updates > HEAP_GUARD_NONSTOP_MODE in "UefiCpuPkg/CpuDxe/CpuDxe.h" (add > BIT4). > > Cc: Eric Dong > Cc: Laszlo Ersek > Cc: Star Zeng > Cc: Michael D Kinney > Cc: Jiewen Yao > Cc: Ruiyu Ni > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Jian J Wang > --- > UefiCpuPkg/CpuDxe/CpuDxe.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.h b/UefiCpuPkg/CpuDxe/CpuDxe.h > index 064ea05bba..3183a3f7f4 100644 > --- a/UefiCpuPkg/CpuDxe/CpuDxe.h > +++ b/UefiCpuPkg/CpuDxe/CpuDxe.h > @@ -58,7 +58,7 @@ > ) > > #define HEAP_GUARD_NONSTOP_MODE \ > -((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT6|BIT1|BIT0)) > BIT6) > +((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT6|BIT4|BIT1|BIT0)) > > + BIT6) > > #define NULL_DETECTION_NONSTOP_MODE \ > ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT6|BIT0)) > > BIT6) > -- > 2.16.2.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch 1/2 V2] BaseTools: Add $(INC)-like support when compiling .nasm files
Reviewed-by: Jaben Carsey > -Original Message- > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of > Yonghong Zhu > Sent: Thursday, October 25, 2018 8:05 AM > To: edk2-devel@lists.01.org > Cc: Gao, Liming > Subject: [edk2] [Patch 1/2 V2] BaseTools: Add $(INC)-like support when > compiling .nasm files > > From: zhijufan > > current edk2\BaseTools\Conf\build_rule.template, the compile of nasm > source files does not have the $(INC) support. > > The '-I' option only includes the directory of the nasm source file > (${s_path}(+)). Hence, it will be impossible for nasm files to include > files outside of the nasm source file directory. > > As a comparison, the compile of both .s and .asm have $(INC) support > in their compile commands. > > Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=1085 > Cc: Liming Gao > Cc: Yonghong Zhu > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Zhiju.Fan > --- > BaseTools/Source/Python/AutoGen/GenMake.py | 13 - > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py > b/BaseTools/Source/Python/AutoGen/GenMake.py > index b4377ee..f754f03 100644 > --- a/BaseTools/Source/Python/AutoGen/GenMake.py > +++ b/BaseTools/Source/Python/AutoGen/GenMake.py > @@ -165,11 +165,11 @@ class BuildFile(object): > _INCLUDE_CMD_ = { > "nmake" : '!INCLUDE', > "gmake" : "include" > } > > -_INC_FLAG_ = {TAB_COMPILER_MSFT : "/I", "GCC" : "-I", "INTEL" : "-I", > "RVCT" : "-I"} > +_INC_FLAG_ = {TAB_COMPILER_MSFT : "/I", "GCC" : "-I", "INTEL" : "-I", > "RVCT" : "-I", "NASM" : "-I"} > > ## Constructor of BuildFile > # > # @param AutoGenObject Object of AutoGen class > # > @@ -594,10 +594,21 @@ cleanlib: > "macro_name" : "INC", > "source_file" : > IncludePathList > } > ) > FileMacroList.append(FileMacro) > +for File in self.FileCache.keys(): > +if not str(File).endswith('.nasm'): > +continue > +IncludePathList = [] > +for P in MyAgo.IncludePathList: > +IncludePath = self._INC_FLAG_['NASM'] + self.PlaceMacro(P, > self.Macros) > +if not P.endswith('\\'): > +IncludePath += '\\' > +IncludePathList.append(IncludePath) > + > FileMacroList.append(self._FILE_MACRO_TEMPLATE.Replace({"macro_nam > e": "NASM_INC", "source_file": IncludePathList})) > +break > > # Generate macros used to represent files containing list of input > files > for ListFileMacro in self.ListFileMacros: > ListFileName = os.path.join(MyAgo.OutputDir, "%s.lst" % > ListFileMacro.lower()[:len(ListFileMacro) - 5]) > FileMacroList.append("%s = %s" % (ListFileMacro, ListFileName)) > -- > 2.6.1.windows.1 > > ___ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH v2] CryptoPkg/BaseCryptLib: Fix potential integer overflow issue.
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1275 The LookupFreeMemRegion() in RuntimeMemAllocate.c is used to look-up free memory region for runtime resource allocation, which was designed to support runtime authenticated variable service. The ReqPages in this function is the required pages to be allocated, which depends on the malloc() call in internal OpenSSL routines. The direct offset subtractions on ReqPages may bring possible integer overflow issue. This patch is to add the extra parameter checks to remove this possible overflow risk. Cc: Ye Ting Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Long Qin --- .../Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c| 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c b/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c index 463f2bf855..92bb9ddccd 100644 --- a/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c +++ b/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c @@ -2,7 +2,7 @@ Light-weight Memory Management Routines for OpenSSL-based Crypto Library at Runtime Phase. -Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved. +Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -141,6 +141,12 @@ LookupFreeMemRegion ( StartPageIndex = RT_SIZE_TO_PAGES (mRTPageTable->LastEmptyPageOffset); ReqPages = RT_SIZE_TO_PAGES (AllocationSize); + if (ReqPages > mRTPageTable->PageCount) { +// +// No enough region for object allocation. +// +return (UINTN)(-1); + } // // Look up the free memory region with in current memory map table. @@ -176,6 +182,12 @@ LookupFreeMemRegion ( // Look up the free memory region from the beginning of the memory table // until the StartCursorOffset // + if (ReqPages > StartPageIndex) { +// +// No enough region for object allocation. +// +return (UINTN)(-1); + } for (Index = 0; Index < (StartPageIndex - ReqPages); ) { // // Check Consecutive ReqPages Pages. -- 2.16.1.windows.2 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [Patch 2/2 V2] BaseTools: Update nasm file build rule to support $(INC)
From: zhijufan Update the build rule to: "$(NASM)" -I${s_path}(+) $(NASM_INC)(+) $(NASM_FLAGS) -o $dst ${d_path}(+)${s_base}.iii Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan --- BaseTools/Conf/build_rule.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BaseTools/Conf/build_rule.template b/BaseTools/Conf/build_rule.template index ed54a55..8ac46c5 100755 --- a/BaseTools/Conf/build_rule.template +++ b/BaseTools/Conf/build_rule.template @@ -223,11 +223,11 @@ $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj "$(PP)" $(PP_FLAGS) $(INC) ${src} > ${d_path}(+)${s_base}.i Trim --trim-long --source-code -o ${d_path}(+)${s_base}.iii ${d_path}(+)${s_base}.i -"$(NASM)" -I${s_path}(+) $(NASM_FLAGS) -o $dst ${d_path}(+)${s_base}.iii +"$(NASM)" -I${s_path}(+) $(NASM_INC)(+) $(NASM_FLAGS) -o $dst ${d_path}(+)${s_base}.iii [Device-Tree-Source-File] ?.dts -- 2.6.1.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [Patch 0/2 V2] Update .nasm to support $(INC)-like support
V2: 1. remove FileMacro variable 2. Make sure the NASM_INC file path have '\' in the end Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=1085 Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan zhijufan (2): BaseTools: Add $(INC)-like support when compiling .nasm files BaseTools: Update nasm file build rule to support $(INC) BaseTools/Conf/build_rule.template | 2 +- BaseTools/Source/Python/AutoGen/GenMake.py | 14 +- 2 files changed, 14 insertions(+), 2 deletions(-) -- 2.6.1.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [Patch 1/2 V2] BaseTools: Add $(INC)-like support when compiling .nasm files
From: zhijufan current edk2\BaseTools\Conf\build_rule.template, the compile of nasm source files does not have the $(INC) support. The '-I' option only includes the directory of the nasm source file (${s_path}(+)). Hence, it will be impossible for nasm files to include files outside of the nasm source file directory. As a comparison, the compile of both .s and .asm have $(INC) support in their compile commands. Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=1085 Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan --- BaseTools/Source/Python/AutoGen/GenMake.py | 13 - 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py index b4377ee..f754f03 100644 --- a/BaseTools/Source/Python/AutoGen/GenMake.py +++ b/BaseTools/Source/Python/AutoGen/GenMake.py @@ -165,11 +165,11 @@ class BuildFile(object): _INCLUDE_CMD_ = { "nmake" : '!INCLUDE', "gmake" : "include" } -_INC_FLAG_ = {TAB_COMPILER_MSFT : "/I", "GCC" : "-I", "INTEL" : "-I", "RVCT" : "-I"} +_INC_FLAG_ = {TAB_COMPILER_MSFT : "/I", "GCC" : "-I", "INTEL" : "-I", "RVCT" : "-I", "NASM" : "-I"} ## Constructor of BuildFile # # @param AutoGenObject Object of AutoGen class # @@ -594,10 +594,21 @@ cleanlib: "macro_name" : "INC", "source_file" : IncludePathList } ) FileMacroList.append(FileMacro) +for File in self.FileCache.keys(): +if not str(File).endswith('.nasm'): +continue +IncludePathList = [] +for P in MyAgo.IncludePathList: +IncludePath = self._INC_FLAG_['NASM'] + self.PlaceMacro(P, self.Macros) +if not P.endswith('\\'): +IncludePath += '\\' +IncludePathList.append(IncludePath) + FileMacroList.append(self._FILE_MACRO_TEMPLATE.Replace({"macro_name": "NASM_INC", "source_file": IncludePathList})) +break # Generate macros used to represent files containing list of input files for ListFileMacro in self.ListFileMacros: ListFileName = os.path.join(MyAgo.OutputDir, "%s.lst" % ListFileMacro.lower()[:len(ListFileMacro) - 5]) FileMacroList.append("%s = %s" % (ListFileMacro, ListFileName)) -- 2.6.1.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch 1/2] BaseTools: Add $(INC)-like support when compiling .nasm files
Yes, I agree. I will help to update a V2. Best Regards, Zhu Yonghong -Original Message- From: Carsey, Jaben Sent: Thursday, October 25, 2018 10:20 PM To: Zhu, Yonghong ; edk2-devel@lists.01.org Cc: Gao, Liming Subject: RE: [edk2] [Patch 1/2] BaseTools: Add $(INC)-like support when compiling .nasm files > -Original Message- > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of > Yonghong Zhu > Sent: Thursday, October 25, 2018 12:38 AM > To: edk2-devel@lists.01.org > Cc: Gao, Liming > Subject: [edk2] [Patch 1/2] BaseTools: Add $(INC)-like support when > compiling .nasm files > > From: zhijufan > > current edk2\BaseTools\Conf\build_rule.template, the compile of nasm > source files does not have the $(INC) support. > > The '-I' option only includes the directory of the nasm source file > (${s_path}(+)). Hence, it will be impossible for nasm files to include > files outside of the nasm source file directory. > > As a comparison, the compile of both .s and .asm have $(INC) support > in their compile commands. > > Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=1085 > Cc: Liming Gao > Cc: Yonghong Zhu > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Zhiju.Fan > --- > BaseTools/Source/Python/AutoGen/GenMake.py | 14 +- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py > b/BaseTools/Source/Python/AutoGen/GenMake.py > index d94d8f9..8860d50 100644 > --- a/BaseTools/Source/Python/AutoGen/GenMake.py > +++ b/BaseTools/Source/Python/AutoGen/GenMake.py > @@ -165,11 +165,11 @@ class BuildFile(object): > _INCLUDE_CMD_ = { > "nmake" : '!INCLUDE', > "gmake" : "include" > } > > -_INC_FLAG_ = {TAB_COMPILER_MSFT : "/I", "GCC" : "-I", "INTEL" : "-I", > "RVCT" : "-I"} > +_INC_FLAG_ = {TAB_COMPILER_MSFT : "/I", "GCC" : "-I", "INTEL" : > + "-I", > "RVCT" : "-I", "NASM" : "-I"} > > ## Constructor of BuildFile > # > # @param AutoGenObject Object of AutoGen class > # > @@ -594,10 +594,22 @@ cleanlib: > "macro_name" : "INC", > "source_file" : > IncludePathList > } > ) > FileMacroList.append(FileMacro) > +for File in self.FileCache.keys(): > +if not str(File).endswith('.nasm'): > +continue > +FileMacro = "" > +IncludePathList = [] > +for P in MyAgo.IncludePathList: > +IncludePathList.append(self._INC_FLAG_['NASM'] + > self.PlaceMacro(P, self.Macros)) > +if FileBuildRule.INC_LIST_MACRO in self.ListFileMacros: > + > self.ListFileMacros[FileBuildRule.INC_LIST_MACRO].append(self._INC_FLA > G > _['NASM'] + P) > +FileMacro += > self._FILE_MACRO_TEMPLATE.Replace({"macro_name": "NASM_INC", > "source_file": IncludePathList}) Why do we use += on FileMacro here? Seems like = will be fine. We can also skip initializing the FileMacro since it's only ever assigned here. > +FileMacroList.append(FileMacro) > +break > > # Generate macros used to represent files containing list of input > files > for ListFileMacro in self.ListFileMacros: > ListFileName = os.path.join(MyAgo.OutputDir, "%s.lst" % > ListFileMacro.lower()[:len(ListFileMacro) - 5]) > FileMacroList.append("%s = %s" % (ListFileMacro, > ListFileName)) > -- > 2.6.1.windows.1 > > ___ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch 1/2] BaseTools: Add $(INC)-like support when compiling .nasm files
> -Original Message- > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of > Yonghong Zhu > Sent: Thursday, October 25, 2018 12:38 AM > To: edk2-devel@lists.01.org > Cc: Gao, Liming > Subject: [edk2] [Patch 1/2] BaseTools: Add $(INC)-like support when > compiling .nasm files > > From: zhijufan > > current edk2\BaseTools\Conf\build_rule.template, the compile of nasm > source files does not have the $(INC) support. > > The '-I' option only includes the directory of the nasm source file > (${s_path}(+)). Hence, it will be impossible for nasm files to include > files outside of the nasm source file directory. > > As a comparison, the compile of both .s and .asm have $(INC) support > in their compile commands. > > Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=1085 > Cc: Liming Gao > Cc: Yonghong Zhu > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Zhiju.Fan > --- > BaseTools/Source/Python/AutoGen/GenMake.py | 14 +- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py > b/BaseTools/Source/Python/AutoGen/GenMake.py > index d94d8f9..8860d50 100644 > --- a/BaseTools/Source/Python/AutoGen/GenMake.py > +++ b/BaseTools/Source/Python/AutoGen/GenMake.py > @@ -165,11 +165,11 @@ class BuildFile(object): > _INCLUDE_CMD_ = { > "nmake" : '!INCLUDE', > "gmake" : "include" > } > > -_INC_FLAG_ = {TAB_COMPILER_MSFT : "/I", "GCC" : "-I", "INTEL" : "-I", > "RVCT" : "-I"} > +_INC_FLAG_ = {TAB_COMPILER_MSFT : "/I", "GCC" : "-I", "INTEL" : "-I", > "RVCT" : "-I", "NASM" : "-I"} > > ## Constructor of BuildFile > # > # @param AutoGenObject Object of AutoGen class > # > @@ -594,10 +594,22 @@ cleanlib: > "macro_name" : "INC", > "source_file" : > IncludePathList > } > ) > FileMacroList.append(FileMacro) > +for File in self.FileCache.keys(): > +if not str(File).endswith('.nasm'): > +continue > +FileMacro = "" > +IncludePathList = [] > +for P in MyAgo.IncludePathList: > +IncludePathList.append(self._INC_FLAG_['NASM'] + > self.PlaceMacro(P, self.Macros)) > +if FileBuildRule.INC_LIST_MACRO in self.ListFileMacros: > + > self.ListFileMacros[FileBuildRule.INC_LIST_MACRO].append(self._INC_FLAG > _['NASM'] + P) > +FileMacro += > self._FILE_MACRO_TEMPLATE.Replace({"macro_name": "NASM_INC", > "source_file": IncludePathList}) Why do we use += on FileMacro here? Seems like = will be fine. We can also skip initializing the FileMacro since it's only ever assigned here. > +FileMacroList.append(FileMacro) > +break > > # Generate macros used to represent files containing list of input > files > for ListFileMacro in self.ListFileMacros: > ListFileName = os.path.join(MyAgo.OutputDir, "%s.lst" % > ListFileMacro.lower()[:len(ListFileMacro) - 5]) > FileMacroList.append("%s = %s" % (ListFileMacro, ListFileName)) > -- > 2.6.1.windows.1 > > ___ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch v3 6/6] BaseTools/GenFds: create and use new variable in FdfParser
Reviewed-by: Bob Feng -Original Message- From: Carsey, Jaben Sent: Wednesday, October 24, 2018 1:29 AM To: edk2-devel@lists.01.org Cc: Feng, Bob C ; Zhu, Yonghong ; Gao, Liming Subject: [Patch v3 6/6] BaseTools/GenFds: create and use new variable in FdfParser replace lots of '}' and "}" with a shared new consistent variable. Cc: Bob Feng Cc: Yonghong Zhu Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/GenFds/FdfParser.py | 45 ++-- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py index d954c0b40b3b..bf6e0bd2286c 100644 --- a/BaseTools/Source/Python/GenFds/FdfParser.py +++ b/BaseTools/Source/Python/GenFds/FdfParser.py @@ -65,8 +65,9 @@ T_CHAR_TAB = '\t' T_CHAR_DOUBLE_QUOTE = '\"' T_CHAR_SINGLE_QUOTE = '\'' T_CHAR_STAR = '*' +T_CHAR_BRACE_R = '}' -SEPARATORS = {TAB_EQUAL_SPLIT, TAB_VALUE_SPLIT, TAB_COMMA_SPLIT, '{', '}'} +SEPARATORS = {TAB_EQUAL_SPLIT, TAB_VALUE_SPLIT, TAB_COMMA_SPLIT, '{', +T_CHAR_BRACE_R} ALIGNMENTS = {"Auto", "8", "16", "32", "64", "128", "512", "1K", "4K", "32K", "64K", "128K", "256K", "512K", "1M", "2M", "4M", "8M", "16M"} ALIGNMENT_NOAUTO = ALIGNMENTS - {"Auto"} @@ -2021,7 +2022,7 @@ class FdfParser: DataString += self._Token DataString += TAB_COMMA_SPLIT -if not self._IsToken("}"): +if not self._IsToken(T_CHAR_BRACE_R): raise Warning.ExpectedCurlyClose(self.FileName, self.CurrentLineNumber) DataString = DataString.rstrip(TAB_COMMA_SPLIT) @@ -2061,7 +2062,7 @@ class FdfParser: DataString += self._Token DataString += TAB_COMMA_SPLIT -if not self._IsToken("}"): +if not self._IsToken(T_CHAR_BRACE_R): raise Warning.ExpectedCurlyClose(self.FileName, self.CurrentLineNumber) DataString = DataString.rstrip(TAB_COMMA_SPLIT) @@ -2330,10 +2331,10 @@ class FdfParser: DataString += self._Token DataString += TAB_COMMA_SPLIT -if not self._IsToken("}"): +if not self._IsToken(T_CHAR_BRACE_R): raise Warning.ExpectedCurlyClose(self.FileName, self.CurrentLineNumber) -if not self._IsToken("}"): +if not self._IsToken(T_CHAR_BRACE_R): raise Warning.ExpectedCurlyClose(self.FileName, self.CurrentLineNumber) DataString = DataString.rstrip(TAB_COMMA_SPLIT) @@ -2348,7 +2349,7 @@ class FdfParser: FvObj.FvExtEntryData.append(self._Token) -if not self._IsToken("}"): +if not self._IsToken(T_CHAR_BRACE_R): raise Warning.ExpectedCurlyClose(self.FileName, self.CurrentLineNumber) return True @@ -2384,7 +2385,7 @@ class FdfParser: if not IsInf and not IsFile: break -if not self._IsToken("}"): +if not self._IsToken(T_CHAR_BRACE_R): raise Warning.ExpectedCurlyClose(self.FileName, self.CurrentLineNumber) FvObj.AprioriSectionList.append(AprSectionObj) @@ -2659,7 +2660,7 @@ class FdfParser: FfsFileObj.FileName = self._Token.replace('$(SPACE)', ' ') self._VerifyFile(FfsFileObj.FileName) -if not self._IsToken("}"): +if not self._IsToken(T_CHAR_BRACE_R): raise Warning.ExpectedCurlyClose(self.FileName, self.CurrentLineNumber) ## _GetRAWData() method @@ -2684,7 +2685,7 @@ class FdfParser: raise Warning.Expected("Filename value", self.FileName, self.CurrentLineNumber) FileName = self._Token.replace('$(SPACE)', ' ') -if FileName == '}': +if FileName == T_CHAR_BRACE_R: self._UndoToken() raise Warning.Expected("Filename value", self.FileName, self.CurrentLineNumber) @@ -2693,7 +2694,7 @@ class FdfParser: FfsFileObj.FileName.append(File.Path) FfsFileObj.SubAlignment.append(AlignValue) -if self._IsToken("}"): +if self._IsToken(T_CHAR_BRACE_R): self._UndoToken() break @@ -2865,7 +2866,7 @@ class FdfParser: if not IsInf and not IsFile: break -if not self._IsToken("}"): +if not self._IsToken(T_CHAR_BRACE_R): raise Warning.ExpectedCurlyClose(self.FileName, self.CurrentLineNumber) FvImageSectionObj = FvImageSection() @@ -2890,10 +2891,10 @@ class FdfParser: raise Warning.ExpectedEquals(self.FileName, self.CurrentLineNumber) if not self._IsToken("{"): raise Warning.ExpectedCurlyOpen(self.FileName, self.CurrentLineNumber) -
Re: [edk2] [Patch] FDF spec: Add PI1.5 standalone SMM support in FDF file
Reviewed-by: Liming Gao > -Original Message- > From: Zhu, Yonghong > Sent: Thursday, October 25, 2018 8:42 PM > To: edk2-devel@lists.01.org > Cc: Gao, Liming ; Kinney, Michael D > ; Shaw, Kevin W ; > Cohen; Eugene > Subject: [Patch] FDF spec: Add PI1.5 standalone SMM support in FDF file > > V2: Update it to MM_CORE_STANDALONE and MM_STANDALONE > > Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=551 > Cc: Liming Gao > Cc: Michael Kinney > Cc: Kevin W Shaw > Cc: Cohen, Eugene > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Yonghong Zhu > --- > 1_introduction/12_terms.md| 9 + > 2_fdf_design_discussion/25_[fv]_sections.md | 6 +- > 3_edk_ii_fdf_file_format/32_fdf_definition.md | 1 + > 3_edk_ii_fdf_file_format/36_[fv]_sections.md | 19 --- > 3_edk_ii_fdf_file_format/37_[capsule]_sections.md | 22 ++ > 3_edk_ii_fdf_file_format/39_[rule]_sections.md| 22 +- > README.md | 1 + > 7 files changed, 51 insertions(+), 29 deletions(-) > > diff --git a/1_introduction/12_terms.md b/1_introduction/12_terms.md > index af33faa..abb857b 100644 > --- a/1_introduction/12_terms.md > +++ b/1_introduction/12_terms.md > @@ -1,9 +1,9 @@ > 2.6.1.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH] CryptoPkg/BaseCryptLib: Fix potential integer overflow issue.
Thanks, Laszlo. From: Laszlo Ersek [mailto:ler...@redhat.com] Sent: Thursday, October 25, 2018 12:59 AM To: Long, Qin ; edk2-devel@lists.01.org Cc: Ye, Ting Subject: Re: [edk2] [PATCH] CryptoPkg/BaseCryptLib: Fix potential integer overflow issue. On 10/24/18 15:22, Long Qin wrote: > The LookupFreeMemRegion() in RuntimeMemAllocate.c is used to look-up > free memory region for runtime resource allocation, which was designed > to support runtime authenticated variable service. > The direct offset subtractions in this function may bring possible > integer overflow issue. > > This patch is to add the extra parameter checks to remove this possible > overflow risk. > > Cc: Ye Ting mailto:ting...@intel.com>> > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Long Qin mailto:qin.l...@intel.com>> > --- > .../Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c| 14 > +- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c > b/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c > index 463f2bf855..92bb9ddccd 100644 > --- a/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c > +++ b/CryptoPkg/Library/BaseCryptLib/SysCall/RuntimeMemAllocation.c > @@ -2,7 +2,7 @@ >Light-weight Memory Management Routines for OpenSSL-based Crypto >Library at Runtime Phase. > > -Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved. > +Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved. > This program and the accompanying materials > are licensed and made available under the terms and conditions of the BSD > License > which accompanies this distribution. The full text of the license may be > found at > @@ -141,6 +141,12 @@ LookupFreeMemRegion ( > >StartPageIndex = RT_SIZE_TO_PAGES (mRTPageTable->LastEmptyPageOffset); >ReqPages = RT_SIZE_TO_PAGES (AllocationSize); > + if (ReqPages > mRTPageTable->PageCount) { > +// > +// No enough region for object allocation. > +// > +return (UINTN)(-1); > + } > >// >// Look up the free memory region with in current memory map table. > @@ -176,6 +182,12 @@ LookupFreeMemRegion ( >// Look up the free memory region from the beginning of the memory table >// until the StartCursorOffset >// > + if (ReqPages > StartPageIndex) { > +// > +// No enough region for object allocation. > +// > +return (UINTN)(-1); > + } >for (Index = 0; Index < (StartPageIndex - ReqPages); ) { > // > // Check Consecutive ReqPages Pages. > As far as I can see, "RuntimeCryptLib.inf" (where this file is used) is only linked into runtime DXE modules -- not SMM modules. That means this issue is not a security bug, because runtime DXE modules can be overwritten by the OS anyway. (They reside in normal RAM.) Can you please confirm? [qlong] Yes, this library instance is only linked into runtime DXE driver, not SMM. It was designed to provide the runtime authentication / verification support (for variable service) in early implementation (non-SMM variable driver). But the memory used in runtime dxe modules will not overwritten since It was marked as “EfiRuntimeServicesData”. The RuntimeCryptLib applied one light-weight memory management routines to meet the internal memory allocation / free usage when openssl handle PKCS7 verification. The possible integer overflow issue was found from code review. Yes, I think it’s low risk since most runtime variable service was updated to use smm solution. Nonetheless, it would be nice to explain in the commit message, what exactly "ReqPages" depends on. [qlong] ReqPages is one variable to describe the required pages for memory allocation (from the malloc() call in OpenSSL codes when handling pkcs7 verification). It’s hard to state the specific dependency (which include the PKCS7 data and some openssl internal data structure). If needed, please file a BZ as well. (I'm not saying it's required, but you might want to consider it, and reference it in the commit message.) [qlong] Sure. It make sense. And create one: https://bugzilla.tianocore.org/show_bug.cgi?id=1275 Thanks Laszlo ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 1/2] ShellPkg-Shell App: Provide fully-qualified path to shell scripts
On Thursday, October 25, 2018 12:48 AM ruiyu...@intel.com wrote: >On 10/25/2018 12:35 AM, jim.dai...@dell.com wrote: >> Add a function to return the fully-qualified version of some path. >> >> ... >> +CHAR16* >> +EFIAPI >> +FullyQualifyPath( >> + IN OUTCHAR16 **Path >This API assumes *Path is allocated in heap which may bring unnecessary >restriction. How about we accept a CONST CHAR16 * Path, quality and >return a new allocated string? >The parameter can be "IN CONST CHAR16 *Path". In the context it is currently used, *Path is allocated in heap. But, it might be better to handle other types of input too. >> + if (StrStr(*Path, L":") == NULL) { > >Do we need to handle path like "fs0:a.txt"? >In Windows, it is expanded to + a.txt. Good catch. >> +*Path = FullyQualifiedPath; > >We can just return the FullQualifiedPath without changing Path. Agreed. >Thanks, >Ray I'll take a cut at version 2 soon. Regards, Jim ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH v2 0/4] SdMmcOverride extension
Hi Hao, Were you able to find time for evaluating my patchset? Best regards, Marcin pt., 12 paź 2018 o 14:50 Marcin Wojtas napisał(a): > > pt., 12 paź 2018 o 14:48 Wu, Hao A napisał(a): > > > > > -Original Message- > > > From: Marcin Wojtas [mailto:m...@semihalf.com] > > > Sent: Friday, October 12, 2018 1:33 PM > > > To: Wu, Hao A > > > Cc: edk2-devel-01; Tian, Feng; Kinney, Michael D; Gao, Liming; Leif > > > Lindholm; > > > Ard Biesheuvel; nad...@marvell.com; j...@semihalf.com; Tomasz Michalec > > > Subject: Re: [PATCH v2 0/4] SdMmcOverride extension > > > > > > Hi Hao, > > > > > > pt., 12 paź 2018 o 07:25 Wu, Hao A napisał(a): > > > > > > > > Hi Marcin, > > > > > > > > Please grant me some time for this series. > > > > > > > > Since I found that the extension of the SdMmc override protocol (mainly > > > > the 3rd and 4th patch of the series) may have something overlaps with a > > > > (internal) request to configure the driver strength parameter and > > > > operating > > > > clock frequency of the SD/EMMC devices. > > > > > > > > For the (driver strength/operating freq) customize, we already have a > > > > proposal on the way. So I am wondering if you could grant me some time > > > to > > > > investigate whether both the cases can be addressed together based on > > > your > > > > proposed patch. > > > > > > > > > > Sure. I'm only wondering if it's not best to collect all remarks and > > > maybe update to v3 both edk2 and edk2-platforms sides (so far the > > > issues have been not critical, such as typos, parameters' names, > > > etc.). In the meantime you would be able to validate if the solution > > > is sufficient for you as well. What do you think? When do you expect > > > to be able to look at it vs your internal requirements more deeply? > > > > > > Best regards, > > > Marcin > > > > I think you can hold the new version of the patch if the feedbacks do not > > lead to considerable changes. At this moment, I can barely take time for > > the evaluation. I think I will be able to fully shift to this in about 2 > > weeks. Does it sound acceptable to you with regard to the urgency level > > for the series? > > > > I will try my best to move up the process. Sorry again for the possible > > delay. > > I will proceed with other remaining items for my platforms and allow > myself to ping you about status around end of October :) > > Best regards, > Marcin > > > > > > > > > > > > > Thanks in advance. > > > > > > > > Best Regards, > > > > Hao Wu > > > > > > > > > > > > > -Original Message- > > > > > From: Marcin Wojtas [mailto:m...@semihalf.com] > > > > > Sent: Friday, October 05, 2018 9:25 PM > > > > > To: edk2-devel@lists.01.org > > > > > Cc: Tian, Feng; Kinney, Michael D; Gao, Liming; > > > > > leif.lindh...@linaro.org; > > > Wu, > > > > > Hao A; ard.biesheu...@linaro.org; nad...@marvell.com; > > > > > m...@semihalf.com; j...@semihalf.com; t...@semihalf.com > > > > > Subject: [PATCH v2 0/4] SdMmcOverride extension > > > > > > > > > > Hi, > > > > > > > > > > This is the second version of the patchset. Initial one was > > > > > interleaved with the fixes, which after split got already merged. > > > > > The biggest change is - resigning from the new callbacks > > > > > and extending parameter lists of both NotifyPhase and Capability > > > > > routines. > > > > > > > > > > Patches are available in the github: > > > > > https://github.com/MarvellEmbeddedProcessors/edk2-open- > > > > > platform/commits/sdmmc-override-upstream-r20181005 > > > > > > > > > > Please note that extending SdMmcOverride protocol was impacting > > > > > so far the only user of it (Synquacer controller). In paralel > > > > > edk2-platforms patchset, a patch can be found: > > > > > ("Silicon/SynQuacer/PlatformDxe: adjust to updated SdMmcOverride") > > > > > which immunizes for above and future extensions of the protocol: > > > > > https://github.com/MarvellEmbeddedProcessors/edk2-open- > > > > > platform/commits/xenon-upstream-r20181005 > > > > > > > > > > I'm looking forward to the comments and remarks. > > > > > > > > > > Best regards, > > > > > Marcin > > > > > > > > > > Changelog: > > > > > v1 -> v2 > > > > > * Rebase onto newest master > > > > > * 1/4 [new patch] - preparation for extending NotifyPhase > > > > > * 2/4 - UhsSignaling as a part of NotifyPhase > > > > > * 3/4 - SwitchClockFreqPost as a part of NotifyPhase > > > > > * 4/4 - Allow updating BaseClkFreq via Capability instead of the > > > > > independent callback. > > > > > > > > > > Marcin Wojtas (2): > > > > > MdeModulePkg/SdMmcPciHcDxe: Add an optional parameter in > > > > > NotifyPhase > > > > > MdeModulePkg/SdMmcPciHcDxe: Allow overriding base clock frequency > > > > > > > > > > Tomasz Michalec (2): > > > > > MdeModulePkg/SdMmcPciHcDxe: Add UhsSignaling to SdMmcOverride > > > > > protocol > > > > > MdeModulePkg/SdMmcPciHcDxe: Add SwitchClockFreqPost to > > > > > SdMmcOverride > > > > > > > > > > MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/S
[edk2] [Patch] FDF spec: Add PI1.5 standalone SMM support in FDF file
V2: Update it to MM_CORE_STANDALONE and MM_STANDALONE Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=551 Cc: Liming Gao Cc: Michael Kinney Cc: Kevin W Shaw Cc: Cohen, Eugene Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yonghong Zhu --- 1_introduction/12_terms.md| 9 + 2_fdf_design_discussion/25_[fv]_sections.md | 6 +- 3_edk_ii_fdf_file_format/32_fdf_definition.md | 1 + 3_edk_ii_fdf_file_format/36_[fv]_sections.md | 19 --- 3_edk_ii_fdf_file_format/37_[capsule]_sections.md | 22 ++ 3_edk_ii_fdf_file_format/39_[rule]_sections.md| 22 +- README.md | 1 + 7 files changed, 51 insertions(+), 29 deletions(-) diff --git a/1_introduction/12_terms.md b/1_introduction/12_terms.md index af33faa..abb857b 100644 --- a/1_introduction/12_terms.md +++ b/1_introduction/12_terms.md @@ -1,9 +1,9 @@
Re: [edk2] [PATCH v2] BaseTools: Allow multiple PciDeviceId in Fdf OptionROM override
Reviewed-by: Yonghong Zhu Best Regards, Zhu Yonghong -Original Message- From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Tomas Pilar (tpilar) Sent: Wednesday, October 24, 2018 7:43 PM To: edk2-devel@lists.01.org Subject: [edk2] [PATCH v2] BaseTools: Allow multiple PciDeviceId in Fdf OptionROM override Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Tomas Pilar --- BaseTools/Source/Python/GenFds/FdfParser.py | 12 +--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py index 63687e98bb..8f53fbeb55 100644 --- a/BaseTools/Source/Python/GenFds/FdfParser.py +++ b/BaseTools/Source/Python/GenFds/FdfParser.py @@ -1,3 +1,4 @@ + ## @file # parse FDF file # @@ -4469,10 +4470,15 @@ class FdfParser: if self.__IsKeyword( "PCI_DEVICE_ID"): if not self.__IsToken( "="): raise Warning("expected '='", self.FileName, self.CurrentLineNumber) -if not self.__GetNextHexNumber(): -raise Warning("expected Hex device id", self.FileName, self.CurrentLineNumber) -Overrides.PciDeviceId = self.__Token +# Get a list of PCI IDs +Overrides.PciDeviceId = "" + +while (self.__GetNextHexNumber()): +Overrides.PciDeviceId = "{} {}".format(Overrides.PciDeviceId, self.__Token) + +if not Overrides.PciDeviceId: +raise Warning("expected one or more Hex device ids", self.FileName, self.CurrentLineNumber) continue if self.__IsKeyword( "PCI_REVISION"): -- 2.17.2 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch v3 0/6] BaseTools/GenFds: cleanup GenFds
Reviewed-by: Yonghong Zhu Best Regards, Zhu Yonghong -Original Message- From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Jaben Carsey Sent: Wednesday, October 24, 2018 1:29 AM To: edk2-devel@lists.01.org Subject: [edk2] [Patch v3 0/6] BaseTools/GenFds: cleanup GenFds Cleanup to many files for GenFds. No command line visible changes are included. 1) refactor imports to reduce namespace clutter. 2) refactor to use existing sharable objects (and create a few new) 3) eliminate shadowing of names 4) remove double underscored private methods for PEP8 5) eliminate unused code/parameters/variables 6) add standard warnings and use them for common code changes from v1: 1) do not shadow CapsuleFV. 2) rebase on master changes from v2: 1) do not delete duplicate function calls. 2) add ".lower()" for GUID string comparison. 3) rebase on master Jaben Carsey (6): BaseTools/GenFds: cleanup GenFds BaseTools/GenFds: change objects to sets Basetools/GenFds: refactor class FV BaseTools/GenFds: remove MacroDict parameter BaseTools/GenFds: refactor FdfParser warnings BaseTools/GenFds: create and use new variable in FdfParser BaseTools/Source/Python/CommonDataClass/FdfClass.py| 73 - BaseTools/Source/Python/Eot/EotMain.py | 372 +- BaseTools/Source/Python/GenFds/AprioriSection.py | 45 +- BaseTools/Source/Python/GenFds/Capsule.py | 26 +- BaseTools/Source/Python/GenFds/CapsuleData.py |1 - BaseTools/Source/Python/GenFds/CompressSection.py |4 +- BaseTools/Source/Python/GenFds/DataSection.py |4 +- BaseTools/Source/Python/GenFds/DepexSection.py |5 +- BaseTools/Source/Python/GenFds/EfiSection.py | 16 +- BaseTools/Source/Python/GenFds/FdfParser.py| 3780 ++-- BaseTools/Source/Python/GenFds/Ffs.py | 82 +- BaseTools/Source/Python/GenFds/FfsFileStatement.py | 37 +- BaseTools/Source/Python/GenFds/FfsInfStatement.py | 10 +- BaseTools/Source/Python/GenFds/Fv.py | 54 +- BaseTools/Source/Python/GenFds/FvImageSection.py |6 +- BaseTools/Source/Python/GenFds/GenFds.py | 160 +- BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py | 208 +- BaseTools/Source/Python/GenFds/GuidSection.py |4 +- BaseTools/Source/Python/GenFds/OptionRom.py|6 +- BaseTools/Source/Python/GenFds/Region.py | 12 +- BaseTools/Source/Python/GenFds/UiSection.py|4 +- BaseTools/Source/Python/GenFds/VerSection.py | 16 +- BaseTools/Source/Python/GenFds/Vtf.py | 48 +- BaseTools/Source/Python/build/BuildReport.py |5 +- 24 files changed, 2576 insertions(+), 2402 deletions(-) -- 2.16.2.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH 4/4] MdeModulePkg EhciDxe: Use common buffer for AsyncInterruptTransfer
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274 In current code, EhcMonitorAsyncRequests (timer handler) will do unmap and map operations for AsyncIntTransfers to "Flush data from PCI controller specific address to mapped system memory address". EhcMonitorAsyncRequests EhcFlushAsyncIntMap PciIo->Unmap IoMmu->SetAttribute PciIo->Map IoMmu->SetAttribute This may impact the boot performance. Since the data buffer for EhcMonitorAsyncRequests is internal buffer, we can allocate common buffer by PciIo->AllocateBuffer and map the buffer with EfiPciIoOperationBusMasterCommonBuffer, then the unmap and map operations can be removed. /// /// Provides both read and write access to system memory by /// both the processor and a bus master. The buffer is coherent /// from both the processor's and the bus master's point of view. /// EfiPciIoOperationBusMasterCommonBuffer, Test done: USB KB works normally. USB disk read/write works normally. Cc: Ruiyu Ni Cc: Hao Wu Cc: Jian J Wang Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng --- MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c | 3 ++ MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c | 77 +--- MdeModulePkg/Bus/Pci/EhciDxe/EhciUrb.c | 38 ++-- MdeModulePkg/Bus/Pci/EhciDxe/EhciUrb.h | 33 +++--- 4 files changed, 57 insertions(+), 94 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c index 5569f4f9618b..764eeda58ba1 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c @@ -763,6 +763,7 @@ EhcControlTransfer ( Translator, EHC_CTRL_TRANSFER, Request, + FALSE, Data, *DataLength, NULL, @@ -906,6 +907,7 @@ EhcBulkTransfer ( Translator, EHC_BULK_TRANSFER, NULL, + FALSE, Data[0], *DataLength, NULL, @@ -1163,6 +1165,7 @@ EhcSyncInterruptTransfer ( Translator, EHC_INT_TRANSFER_SYNC, NULL, + FALSE, Data, *DataLength, NULL, diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c index d38340e49c8d..f1edcf20e342 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c @@ -778,7 +778,6 @@ EhciDelAsyncIntTransfer ( EhcUnlinkQhFromPeriod (Ehc, Urb->Qh); RemoveEntryList (&Urb->UrbList); - gBS->FreePool (Urb->Data); EhcFreeUrb (Ehc, Urb); return EFI_SUCCESS; } @@ -809,7 +808,6 @@ EhciDelAllAsyncIntTransfers ( EhcUnlinkQhFromPeriod (Ehc, Urb->Qh); RemoveEntryList (&Urb->UrbList); -gBS->FreePool (Urb->Data); EhcFreeUrb (Ehc, Urb); } } @@ -849,16 +847,8 @@ EhciInsertAsyncIntTransfer ( IN UINTN Interval ) { - VOID *Data; URB *Urb; - Data = AllocatePool (DataLen); - - if (Data == NULL) { -DEBUG ((DEBUG_ERROR, "%a: failed to allocate buffer\n", __FUNCTION__)); -return NULL; - } - Urb = EhcCreateUrb ( Ehc, DevAddr, @@ -869,7 +859,8 @@ EhciInsertAsyncIntTransfer ( Hub, EHC_INT_TRANSFER_ASYNC, NULL, - Data, + TRUE, + NULL, DataLen, Callback, Context, @@ -892,60 +883,6 @@ EhciInsertAsyncIntTransfer ( } /** - Flush data from PCI controller specific address to mapped system - memory address. - - @param EhcThe EHCI device. - @param UrbThe URB to unmap. - - @retval EFI_SUCCESSSuccess to flush data to mapped system memory. - @retval EFI_DEVICE_ERROR Fail to flush data to mapped system memory. - -**/ -EFI_STATUS -EhcFlushAsyncIntMap ( - IN USB2_HC_DEV *Ehc, - IN URB *Urb - ) -{ - EFI_STATUSStatus; - EFI_PHYSICAL_ADDRESS PhyAddr; - EFI_PCI_IO_PROTOCOL_OPERATION MapOp; - EFI_PCI_IO_PROTOCOL *PciIo; - UINTN Len; - VOID *Map; - - PciIo = Ehc->PciIo; - Len = Urb->DataLen; - - if (Urb->Ep.Direction == EfiUsbDataIn) { -MapOp = EfiPciIoOperationBusMasterWrite; - } else { -MapOp = EfiPciIoOperationBusMasterRead; - } - - Status = PciIo->Unmap (PciIo, Urb->DataMap); - if (EFI_ERROR (Status)) { -goto ON_ERROR; - } - - Urb->DataMap = NULL; - - Status = PciIo->Map (PciIo, MapOp, Urb->Data, &Len, &PhyAddr, &Map); - if (EFI_ERROR (Status) || (Len != Urb->DataLen)) { -goto ON_ERROR; - } - - Urb->DataPhy = (VOID *) ((UINTN) PhyAddr); - Urb->DataMap = Map; - return EFI_SUCCESS; - -ON_ERROR: - return EFI_DEVICE_ERROR; -} - - -/** Update the queue head for next round of asynchronous transfer. @param Ehc The EHCI device. @@ -1050,7
[edk2] [PATCH 1/4] MdeModulePkg XhciDxe: Extract new XhciInsertAsyncIntTransfer function
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274 Extract new XhciInsertAsyncIntTransfer function from XhcAsyncInterruptTransfer. It is code preparation for following patch, no essential functional change. Cc: Ruiyu Ni Cc: Hao Wu Cc: Jian J Wang Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng --- MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 18 +--- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 74 +--- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h | 28 3 files changed, 98 insertions(+), 22 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c index f1c60bef01c0..7f64f9c7c982 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c @@ -1346,7 +1346,6 @@ XhcAsyncInterruptTransfer ( EFI_STATUS Status; UINT8 SlotId; UINT8 Index; - UINT8 *Data; EFI_TPL OldTpl; // @@ -1413,36 +1412,21 @@ XhcAsyncInterruptTransfer ( goto ON_EXIT; } - Data = AllocateZeroPool (DataLength); - - if (Data == NULL) { -DEBUG ((EFI_D_ERROR, "XhcAsyncInterruptTransfer: failed to allocate buffer\n")); -Status = EFI_OUT_OF_RESOURCES; -goto ON_EXIT; - } - - Urb = XhcCreateUrb ( + Urb = XhciInsertAsyncIntTransfer ( Xhc, DeviceAddress, EndPointAddress, DeviceSpeed, MaximumPacketLength, - XHC_INT_TRANSFER_ASYNC, - NULL, - Data, DataLength, CallBackFunction, Context ); - if (Urb == NULL) { -DEBUG ((EFI_D_ERROR, "XhcAsyncInterruptTransfer: failed to create URB\n")); -FreePool (Data); Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } - InsertHeadList (&Xhc->AsyncIntTransfers, &Urb->UrbList); // // Ring the doorbell // diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c index 166c44bf5e66..2d7c08dc5bfa 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c @@ -264,11 +264,11 @@ XhcCreateTransferTrb ( // No need to remap. // if ((Urb->Data != NULL) && (Urb->DataMap == NULL)) { -if (((UINT8) (Urb->Ep.Direction)) == EfiUsbDataIn) { - MapOp = EfiPciIoOperationBusMasterWrite; -} else { - MapOp = EfiPciIoOperationBusMasterRead; -} + if (((UINT8) (Urb->Ep.Direction)) == EfiUsbDataIn) { +MapOp = EfiPciIoOperationBusMasterWrite; + } else { +MapOp = EfiPciIoOperationBusMasterRead; + } Len = Urb->DataLen; Status = Xhc->PciIo->Map (Xhc->PciIo, MapOp, Urb->Data, &Len, &PhyAddr, &Map); @@ -1411,6 +1411,70 @@ XhciDelAllAsyncIntTransfers ( } /** + Insert a single asynchronous interrupt transfer for + the device and endpoint. + + @param XhcThe XHCI Instance + @param BusAddrThe logical device address assigned by UsbBus driver + @param EpAddr Endpoint addrress + @param DevSpeed The device speed + @param MaxPacket The max packet length of the endpoint + @param DataLenThe length of data buffer + @param Callback The function to call when data is transferred + @param ContextThe context to the callback + + @return Created URB or NULL + +**/ +URB * +XhciInsertAsyncIntTransfer ( + IN USB_XHCI_INSTANCE *Xhc, + IN UINT8 BusAddr, + IN UINT8 EpAddr, + IN UINT8 DevSpeed, + IN UINTN MaxPacket, + IN UINTN DataLen, + IN EFI_ASYNC_USB_TRANSFER_CALLBACKCallback, + IN VOID *Context + ) +{ + VOID *Data; + URB *Urb; + + Data = AllocateZeroPool (DataLen); + if (Data == NULL) { +DEBUG ((DEBUG_ERROR, "%a: failed to allocate buffer\n", __FUNCTION__)); +return NULL; + } + + Urb = XhcCreateUrb ( + Xhc, + BusAddr, + EpAddr, + DevSpeed, + MaxPacket, + XHC_INT_TRANSFER_ASYNC, + NULL, + Data, + DataLen, + Callback, + Context + ); + if (Urb == NULL) { +DEBUG ((DEBUG_ERROR, "%a: failed to create URB\n", __FUNCTION__)); +return NULL; + } + + // + // New asynchronous transfer must inserted to the head. + // Check the comments in XhcMoniteAsyncRequests + // + InsertHeadList (&Xhc->AsyncIntTransfers, &Urb->UrbList); + + return Urb; +} + +/** Update the queue head for next round of asynchronous transfer @param Xhc The XHCI Instance. diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h index 097408828a1f..cd1403f2842a 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h +++ b/MdeModulePkg/Bus/Pci/X
[edk2] [PATCH 0/4] Remove unnecessary Map/Unmap in XhciDxe/EhciDxe for AsyncInterruptTransfer
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274 Please refer to the log message of each commit for more details. Cc: Ruiyu Ni Cc: Hao Wu Cc: Jian J Wang Cc: Jiewen Yao Star Zeng (4): MdeModulePkg XhciDxe: Extract new XhciInsertAsyncIntTransfer function MdeModulePkg EhciDxe: Extract new EhciInsertAsyncIntTransfer function MdeModulePkg XhciDxe: Use common buffer for AsyncInterruptTransfer MdeModulePkg EhciDxe: Use common buffer for AsyncInterruptTransfer MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c | 28 + MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c | 115 ++- MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.h | 36 +- MdeModulePkg/Bus/Pci/EhciDxe/EhciUrb.c | 38 ++- MdeModulePkg/Bus/Pci/EhciDxe/EhciUrb.h | 33 +++--- MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 19 +--- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 188 ++- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h | 55 +++-- 8 files changed, 302 insertions(+), 210 deletions(-) -- 2.7.0.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH 3/4] MdeModulePkg XhciDxe: Use common buffer for AsyncInterruptTransfer
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274 In current code, XhcMonitorAsyncRequests (timer handler) will do unmap and map operations for AsyncIntTransfers to "Flush data from PCI controller specific address to mapped system memory address". XhcMonitorAsyncRequests XhcFlushAsyncIntMap PciIo->Unmap IoMmu->SetAttribute PciIo->Map IoMmu->SetAttribute This may impact the boot performance. Since the data buffer for XhcMonitorAsyncRequests is internal buffer, we can allocate common buffer by PciIo->AllocateBuffer and map the buffer with EfiPciIoOperationBusMasterCommonBuffer, then the unmap and map operations can be removed. /// /// Provides both read and write access to system memory by /// both the processor and a bus master. The buffer is coherent /// from both the processor's and the bus master's point of view. /// EfiPciIoOperationBusMasterCommonBuffer, Test done: USB KB works normally. USB disk read/write works normally. Cc: Ruiyu Ni Cc: Hao Wu Cc: Jian J Wang Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng --- MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 1 + MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 134 +++ MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h | 27 --- 3 files changed, 64 insertions(+), 98 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c index 7f64f9c7c982..64855a4c158c 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c @@ -769,6 +769,7 @@ XhcTransfer ( MaximumPacketLength, Type, Request, + FALSE, Data, *DataLength, NULL, diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c index 2d7c08dc5bfa..d03a6681ce0d 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c @@ -118,17 +118,18 @@ ON_EXIT: /** Create a new URB for a new transaction. - @param Xhc The XHCI Instance - @param BusAddr The logical device address assigned by UsbBus driver - @param EpAddrEndpoint addrress - @param DevSpeed The device speed - @param MaxPacket The max packet length of the endpoint - @param Type The transaction type - @param Request The standard USB request for control transfer - @param Data The user data to transfer - @param DataLen The length of data buffer - @param Callback The function to call when data is transferred - @param Context The context to the callback + @param Xhc The XHCI Instance + @param BusAddr The logical device address assigned by UsbBus driver + @param EpAddrEndpoint addrress + @param DevSpeed The device speed + @param MaxPacket The max packet length of the endpoint + @param Type The transaction type + @param Request The standard USB request for control transfer + @param AllocateCommonBuffer Indicate whether need to allocate common buffer for data transfer + @param Data The user data to transfer, NULL if AllocateCommonBuffer is TRUE + @param DataLen The length of data buffer + @param Callback The function to call when data is transferred + @param Context The context to the callback @return Created URB or NULL @@ -142,6 +143,7 @@ XhcCreateUrb ( IN UINTN MaxPacket, IN UINTN Type, IN EFI_USB_DEVICE_REQUEST *Request, + IN BOOLEANAllocateCommonBuffer, IN VOID *Data, IN UINTN DataLen, IN EFI_ASYNC_USB_TRANSFER_CALLBACKCallback, @@ -169,8 +171,24 @@ XhcCreateUrb ( Ep->Type = Type; Urb->Request = Request; + if (AllocateCommonBuffer) { +ASSERT (Data == NULL); +Status = Xhc->PciIo->AllocateBuffer ( + Xhc->PciIo, + AllocateAnyPages, + EfiBootServicesData, + EFI_SIZE_TO_PAGES (DataLen), + &Data, + 0 + ); +if (EFI_ERROR (Status) || (Data == NULL)) { + FreePool (Urb); + return NULL; +} + } Urb->Data = Data; Urb->DataLen = DataLen; + Urb->AllocateCommonBuffer = AllocateCommonBuffer; Urb->Callback = Callback; Urb->Context = Context; @@ -178,6 +196,11 @@ XhcCreateUrb ( ASSERT_EFI_ERROR (Status); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "XhcCreateUrb: XhcCreateTransferTrb Failed, Status = %r\n", Status)); +Xhc->PciIo->FreeBuffer ( + Xhc->PciIo, + EFI_SIZE_TO_PAGES (Urb->DataLen), + Urb->Data +
[edk2] [PATCH 2/4] MdeModulePkg EhciDxe: Extract new EhciInsertAsyncIntTransfer function
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274 Extract new EhciInsertAsyncIntTransfer function from EhcAsyncInterruptTransfer. It is code preparation for following patch, no essential functional change. Cc: Ruiyu Ni Cc: Hao Wu Cc: Jian J Wang Cc: Jiewen Yao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng --- MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c | 25 +-- MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c | 76 MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.h | 36 ++- 3 files changed, 112 insertions(+), 25 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c index 50b5598df4fb..5569f4f9618b 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c @@ -997,7 +997,6 @@ EhcAsyncInterruptTransfer ( URB *Urb; EFI_TPL OldTpl; EFI_STATUS Status; - UINT8 *Data; // // Validate parameters @@ -1046,16 +1045,7 @@ EhcAsyncInterruptTransfer ( EhcAckAllInterrupt (Ehc); - Data = AllocatePool (DataLength); - - if (Data == NULL) { -DEBUG ((EFI_D_ERROR, "EhcAsyncInterruptTransfer: failed to allocate buffer\n")); - -Status = EFI_OUT_OF_RESOURCES; -goto ON_EXIT; - } - - Urb = EhcCreateUrb ( + Urb = EhciInsertAsyncIntTransfer ( Ehc, DeviceAddress, EndPointAddress, @@ -1063,9 +1053,6 @@ EhcAsyncInterruptTransfer ( *DataToggle, MaximumPacketLength, Translator, - EHC_INT_TRANSFER_ASYNC, - NULL, - Data, DataLength, CallBackFunction, Context, @@ -1073,20 +1060,10 @@ EhcAsyncInterruptTransfer ( ); if (Urb == NULL) { -DEBUG ((EFI_D_ERROR, "EhcAsyncInterruptTransfer: failed to create URB\n")); - -gBS->FreePool (Data); Status = EFI_OUT_OF_RESOURCES; goto ON_EXIT; } - // - // New asynchronous transfer must inserted to the head. - // Check the comments in EhcMoniteAsyncRequests - // - EhcLinkQhToPeriod (Ehc, Urb->Qh); - InsertHeadList (&Ehc->AsyncIntTransfers, &Urb->UrbList); - ON_EXIT: Ehc->PciIo->Flush (Ehc->PciIo); gBS->RestoreTPL (OldTpl); diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c index 168280be81d7..d38340e49c8d 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/EhciSched.c @@ -814,6 +814,82 @@ EhciDelAllAsyncIntTransfers ( } } +/** + Insert a single asynchronous interrupt transfer for + the device and endpoint. + + @param Ehc The EHCI device. + @param DevAddr The device address. + @param EpAddrEndpoint addrress & its direction. + @param DevSpeed The device speed. + @param ToggleInitial data toggle to use. + @param MaxPacket The max packet length of the endpoint. + @param Hub The transaction translator to use. + @param Data The user data to transfer. + @param DataLen The length of data buffer. + @param Callback The function to call when data is transferred. + @param Context The context to the callback. + @param Interval The interval for interrupt transfer. + + @return Created URB or NULL. + +**/ +URB * +EhciInsertAsyncIntTransfer ( + IN USB2_HC_DEV*Ehc, + IN UINT8 DevAddr, + IN UINT8 EpAddr, + IN UINT8 DevSpeed, + IN UINT8 Toggle, + IN UINTN MaxPacket, + IN EFI_USB2_HC_TRANSACTION_TRANSLATOR *Hub, + IN UINTN DataLen, + IN EFI_ASYNC_USB_TRANSFER_CALLBACKCallback, + IN VOID *Context, + IN UINTN Interval + ) +{ + VOID *Data; + URB *Urb; + + Data = AllocatePool (DataLen); + + if (Data == NULL) { +DEBUG ((DEBUG_ERROR, "%a: failed to allocate buffer\n", __FUNCTION__)); +return NULL; + } + + Urb = EhcCreateUrb ( + Ehc, + DevAddr, + EpAddr, + DevSpeed, + Toggle, + MaxPacket, + Hub, + EHC_INT_TRANSFER_ASYNC, + NULL, + Data, + DataLen, + Callback, + Context, + Interval + ); + + if (Urb == NULL) { +DEBUG ((DEBUG_ERROR, "%a: failed to create URB\n", __FUNCTION__)); +return NULL; + } + + // + // New asynchronous transfer must inserted to the head. + // Check the comments in EhcMoniteAsyncRequests + // + EhcLinkQhToPeriod (Ehc, Urb->Qh); + InsertHeadList (&Ehc->AsyncIntTransfers, &Urb->UrbList); + + return Urb; +} /** Flush data from PCI controller specific address to mapped system diff --git a/M
[edk2] [PATCH 0/2] MdeModulePkg/UsbBusPei: validate HW data before using
The patches sync the similar fixes to UsbBusDxe to UsbBusPei. Ruiyu Ni (2): MdeModulePkg/UsbBusPei: Fix out-of-bound read access to descriptors MdeModulePkg/UsbBusPei: Reject descriptor whose length is bad MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c | 93 +++- MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h | 11 2 files changed, 67 insertions(+), 37 deletions(-) -- 2.16.1.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH 1/2] MdeModulePkg/UsbBusPei: Fix out-of-bound read access to descriptors
Today's implementation reads the Type/Length field in the USB descriptors data without checking whether the offset to read is beyond the data boundary. The patch fixes this issue by syncing the fix in commit 4c034bf62cbc1f3c5f4b5df25de97f0f528132b2 *MdeModulePkg/UsbBus: Fix out-of-bound read access to descriptors ParsedBytes in UsbBusPei.GetExpectedDescriptor() is different from Consumed in UsbBusDxe.UsbCreateDesc(). ParsedBytes is the offset of found descriptor while Consumed is offset of next descriptor of found one. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Star Zeng Cc: Jiewen Yao --- MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c | 79 +--- MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h | 11 + 2 files changed, 53 insertions(+), 37 deletions(-) diff --git a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c index 10d5232e59..86734f2f73 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c +++ b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c @@ -940,59 +940,64 @@ GetExpectedDescriptor ( OUT UINTN *ParsedBytes ) { - UINT16 DescriptorHeader; - UINT8 Len; - UINT8 *Ptr; - UINTN Parsed; + USB_DESC_HEAD *Head; + UINTN Offset; - Parsed = 0; - Ptr = Buffer; + // + // Total length is too small that cannot hold the single descriptor header plus data. + // + if (Length <= sizeof (USB_DESC_HEAD)) { +DEBUG ((DEBUG_ERROR, "GetExpectedDescriptor: met mal-format descriptor, total length = %d!\n", Length)); +return EFI_DEVICE_ERROR; + } - while (TRUE) { + // + // All the descriptor has a common LTV (Length, Type, Value) + // format. Skip the descriptor that isn't of this Type + // + Offset = 0; + Head = (USB_DESC_HEAD *)Buffer; + while (Offset < Length - sizeof (USB_DESC_HEAD)) { // -// Buffer length should not less than Desc length +// Above condition make sure Head->Len and Head->Type are safe to access // -if (Length < DescLength) { - return EFI_DEVICE_ERROR; -} - -DescriptorHeader = (UINT16) (*Ptr + ((*(Ptr + 1)) << 8)); - -Len = Buffer[0]; +Head = (USB_DESC_HEAD *)&Buffer[Offset]; -// -// Check to see if it is a start of expected descriptor -// -if (DescriptorHeader == ((DescType << 8) | DescLength)) { - break; +if (Head->Len == 0) { + DEBUG ((DEBUG_ERROR, "GetExpectedDescriptor: met mal-format descriptor, Head->Len = 0!\n")); + return EFI_DEVICE_ERROR; } -if ((UINT8) (DescriptorHeader >> 8) == DescType) { - if (Len > DescLength) { -return EFI_DEVICE_ERROR; - } -} // -// Descriptor length should be at least 2 -// and should not exceed the buffer length +// Make sure no overflow when adding Head->Len to Offset. // -if (Len < 2) { +if (Head->Len > MAX_UINTN - Offset) { + DEBUG ((DEBUG_ERROR, "GetExpectedDescriptor: met mal-format descriptor, Head->Len = %d!\n", Head->Len)); return EFI_DEVICE_ERROR; } -if (Len > Length) { - return EFI_DEVICE_ERROR; +if (Head->Type == DescType) { + break; } -// -// Skip this mismatch descriptor -// -Length -= Len; -Ptr += Len; -Parsed += Len; + +Offset += Head->Len; + } + + // + // Head->Len is invalid resulting data beyond boundary, or + // Descriptor cannot be found: No such type. + // + if (Length < Offset) { +DEBUG ((DEBUG_ERROR, "GetExpectedDescriptor: met mal-format descriptor, Offset/Len = %d/%d!\n", Offset, Length)); +return EFI_DEVICE_ERROR; } - *ParsedBytes = Parsed; + if ((Head->Type != DescType) || (Head->Len < DescLength)) { +DEBUG ((DEBUG_ERROR, "GetExpectedDescriptor: descriptor cannot be found, Header(T/L) = %d/%d!\n", Head->Type, Head->Len)); +return EFI_DEVICE_ERROR; + } + *ParsedBytes = Offset; return EFI_SUCCESS; } diff --git a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h index 1610974537..14565deb46 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h +++ b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.h @@ -33,6 +33,17 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include +// +// A common header for usb standard descriptor. +// Each stand descriptor has a length and type. +// +#pragma pack(1) +typedef struct { + UINT8 Len; + UINT8 Type; +} USB_DESC_HEAD; +#pragma pack() + #define MAX_INTERFACE 8 #define MAX_ENDPOINT 16 -- 2.16.1.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH 2/2] MdeModulePkg/UsbBusPei: Reject descriptor whose length is bad
Today's implementation doesn't check whether the length of descriptor is valid before using it. The patch fixes this issue by syncing the similar fix to UsbBusDxe. 70c3c2370a2aefe71cf0f6c1a1e063f7d74e1d79 *MdeModulePkg/UsbBus: Reject descriptor whose length is bad Additionally the patch also rejects the data when length is larger than sizeof (PeiUsbDevice->ConfigurationData). Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Star Zeng Cc: Jiewen Yao --- MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c | 14 ++ 1 file changed, 14 insertions(+) diff --git a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c index 86734f2f73..c31247abfe 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c +++ b/MdeModulePkg/Bus/Usb/UsbBusPei/UsbPeim.c @@ -816,6 +816,20 @@ PeiUsbGetAllConfiguration ( ConfigDesc= (EFI_USB_CONFIG_DESCRIPTOR *) PeiUsbDevice->ConfigurationData; ConfigDescLength = ConfigDesc->TotalLength; + // + // Reject if TotalLength even cannot cover itself. + // + if (ConfigDescLength < OFFSET_OF (EFI_USB_CONFIG_DESCRIPTOR, TotalLength) + sizeof (ConfigDesc->TotalLength)) { +return EFI_DEVICE_ERROR; + } + + // + // Reject if TotalLength exceeds the PeiUsbDevice->ConfigurationData. + // + if (ConfigDescLength > sizeof (PeiUsbDevice->ConfigurationData)) { +return EFI_DEVICE_ERROR; + } + // // Then we get the total descriptors for this configuration // -- 2.16.1.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [Patch 1/2] MdeModulePke/Mtftp4Dxe: Correct the total received and saved block number.
The block returned from Mtftp4RemoveBlockNum is not the total received and saved block number if it works in passive (Slave) mode. The issue was exposed by the EMS test. Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Wu Jiaxin --- .../Universal/Network/Mtftp4Dxe/Mtftp4Impl.h | 6 +- .../Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c | 16 +++- .../Universal/Network/Mtftp4Dxe/Mtftp4Support.c | 10 +- .../Universal/Network/Mtftp4Dxe/Mtftp4Support.h | 6 +++--- .../Universal/Network/Mtftp4Dxe/Mtftp4Wrq.c | 6 +++--- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.h b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.h index de304f4e70..be2f8af6e4 100644 --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.h +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Impl.h @@ -124,13 +124,17 @@ struct _MTFTP4_PROTOCOL { LIST_ENTRYBlocks; UINT16WindowSize; // - // Record the total received block number and the already acked block number. + // Record the total received and saved block number. // UINT64TotalBlock; + + // + // Record the acked block number. + // UINT64AckedBlock; // // The server's communication end point: IP and two ports. one for // initial request, one for its selected port. diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c index fedf1cde46..6960e322a5 100644 --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c @@ -152,10 +152,11 @@ Mtftp4RrqSaveBlock ( EFI_MTFTP4_TOKEN *Token; EFI_STATUSStatus; UINT16Block; UINT64Start; UINT32DataLen; + UINT64BlockCounter; BOOLEAN Completed; Completed = FALSE; Token = Instance->Token; Block = NTOHS (Packet->Data.Block); @@ -172,14 +173,14 @@ Mtftp4RrqSaveBlock ( // // Remove this block number from the file hole. If Mtftp4RemoveBlockNum // returns EFI_NOT_FOUND, the block has been saved, don't save it again. // Note that : For bigger files, allowing the block counter to roll over - // to accept transfers of unlimited size. So TotalBlock is memorised as + // to accept transfers of unlimited size. So BlockCounter is memorised as // continuous block counter. // - Status = Mtftp4RemoveBlockNum (&Instance->Blocks, Block, Completed, &Instance->TotalBlock); + Status = Mtftp4RemoveBlockNum (&Instance->Blocks, Block, Completed, &BlockCounter); if (Status == EFI_NOT_FOUND) { return EFI_SUCCESS; } else if (EFI_ERROR (Status)) { return Status; @@ -198,11 +199,11 @@ Mtftp4RrqSaveBlock ( return EFI_ABORTED; } } if (Token->Buffer != NULL) { - Start = MultU64x32 (Instance->TotalBlock - 1, Instance->BlkSize); + Start = MultU64x32 (BlockCounter - 1, Instance->BlkSize); if (Start + DataLen <= Token->BufferSize) { CopyMem ((UINT8 *) Token->Buffer + Start, Packet->Data.Data, DataLen); // @@ -269,13 +270,13 @@ Mtftp4RrqHandleData ( Expected= Mtftp4GetNextBlockNum (&Instance->Blocks); ASSERT (Expected >= 0); // - // If we are active and received an unexpected packet, transmit + // If we are active (Master) and received an unexpected packet, transmit // the ACK for the block we received, then restart receiving the - // expected one. If we are passive, save the block. + // expected one. If we are passive (Slave), save the block. // if (Instance->Master && (Expected != BlockNum)) { // // If Expected is 0, (UINT16) (Expected - 1) is also the expected Ack number (65535). // @@ -286,10 +287,15 @@ Mtftp4RrqHandleData ( if (EFI_ERROR (Status)) { return Status; } + // + // Record the total received and saved block number. + // + Instance->TotalBlock ++; + // // Reset the passive client's timer whenever it received a // valid data packet. // if (!Instance->Master) { diff --git a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c index 71fd979b3a..5e282e9c4b 100644 --- a/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c +++ b/MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.c @@ -156,12 +156,12 @@ Mtftp4SetLastBlockNum ( /** Remove the block number from the block range list. @param Head The block range list to remove from @param Num The block number to remove - @param Completed Whether Num is the last block number - @param TotalBlockThe continuous block number in all + @param Completed
[edk2] [Patch 2/2] NetworkPkg/Mtftp6Dxe: Correct the total received and saved block number.
The block returned from Mtftp6RemoveBlockNum is not the total received and saved block number if it works in passive (Slave) mode. The issue was exposed by the EMS test. Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Wu Jiaxin --- NetworkPkg/Mtftp6Dxe/Mtftp6Impl.h| 6 +- NetworkPkg/Mtftp6Dxe/Mtftp6Rrq.c | 16 +++- NetworkPkg/Mtftp6Dxe/Mtftp6Support.c | 10 +- NetworkPkg/Mtftp6Dxe/Mtftp6Support.h | 8 NetworkPkg/Mtftp6Dxe/Mtftp6Wrq.c | 6 +++--- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/NetworkPkg/Mtftp6Dxe/Mtftp6Impl.h b/NetworkPkg/Mtftp6Dxe/Mtftp6Impl.h index cf1b6abacc..57f4cb6f5d 100644 --- a/NetworkPkg/Mtftp6Dxe/Mtftp6Impl.h +++ b/NetworkPkg/Mtftp6Dxe/Mtftp6Impl.h @@ -81,13 +81,17 @@ struct _MTFTP6_INSTANCE { UINT16Operation; UINT16WindowSize; // - // Record the total received block number and the already acked block number. + // Record the total received and saved block number. // UINT64TotalBlock; + + // + // Record the acked block number. + // UINT64AckedBlock; EFI_IPv6_ADDRESS ServerIp; UINT16ServerCmdPort; UINT16ServerDataPort; diff --git a/NetworkPkg/Mtftp6Dxe/Mtftp6Rrq.c b/NetworkPkg/Mtftp6Dxe/Mtftp6Rrq.c index 1f685b2bfe..d60b26f652 100644 --- a/NetworkPkg/Mtftp6Dxe/Mtftp6Rrq.c +++ b/NetworkPkg/Mtftp6Dxe/Mtftp6Rrq.c @@ -100,10 +100,11 @@ Mtftp6RrqSaveBlock ( EFI_MTFTP6_TOKEN *Token; EFI_STATUSStatus; UINT16Block; UINT64Start; UINT32DataLen; + UINT64BlockCounter; BOOLEAN Completed; Completed = FALSE; Token = Instance->Token; Block = NTOHS (Packet->Data.Block); @@ -120,14 +121,14 @@ Mtftp6RrqSaveBlock ( // // Remove this block number from the file hole. If Mtftp6RemoveBlockNum // returns EFI_NOT_FOUND, the block has been saved, don't save it again. // Note that : For bigger files, allowing the block counter to roll over - // to accept transfers of unlimited size. So TotalBlock is memorised as + // to accept transfers of unlimited size. So BlockCounter is memorised as // continuous block counter. // - Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &Instance->TotalBlock); + Status = Mtftp6RemoveBlockNum (&Instance->BlkList, Block, Completed, &BlockCounter); if (Status == EFI_NOT_FOUND) { return EFI_SUCCESS; } else if (EFI_ERROR (Status)) { return Status; @@ -159,11 +160,11 @@ Mtftp6RrqSaveBlock ( } } if (Token->Buffer != NULL) { -Start = MultU64x32 (Instance->TotalBlock - 1, Instance->BlkSize); +Start = MultU64x32 (BlockCounter - 1, Instance->BlkSize); if (Start + DataLen <= Token->BufferSize) { CopyMem ((UINT8 *) Token->Buffer + Start, Packet->Data.Data, DataLen); // // Update the file size when received the last block // @@ -236,13 +237,13 @@ Mtftp6RrqHandleData ( Expected = Mtftp6GetNextBlockNum (&Instance->BlkList); ASSERT (Expected >= 0); // - // If we are active and received an unexpected packet, transmit + // If we are active (Master) and received an unexpected packet, transmit // the ACK for the block we received, then restart receiving the - // expected one. If we are passive, save the block. + // expected one. If we are passive (Slave), save the block. // if (Instance->IsMaster && (Expected != BlockNum)) { // // Free the received packet before send new packet in ReceiveNotify, // since the udpio might need to be reconfigured. @@ -260,10 +261,15 @@ Mtftp6RrqHandleData ( if (EFI_ERROR (Status)) { return Status; } + // + // Record the total received and saved block number. + // + Instance->TotalBlock ++; + // // Reset the passive client's timer whenever it received a valid data packet. // if (!Instance->IsMaster) { Instance->PacketToLive = Instance->Timeout * 2; diff --git a/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c b/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c index 275272b89e..f03216afb7 100644 --- a/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c +++ b/NetworkPkg/Mtftp6Dxe/Mtftp6Support.c @@ -156,12 +156,12 @@ Mtftp6SetLastBlockNum ( /** Remove the block number from the block range list. @param[in] Head The block range list to remove from. @param[in] NumThe block number to remove. - @param[in] Completed Whether Num is the last block number - @param[out] TotalBlock The continuous block number in all + @param[in] Completed Whether Num is the last block number. + @param[out] BlockCounter The continuous block counter instead of the v
[edk2] [Patch 0/2] Mtftp: Correct the total received and saved block number.
The block returned from Mtftp4RemoveBlockNum is not the total received and saved block number if it works in passive (Slave) mode. The issue was exposed by the EMS test. Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Wu Jiaxin Jiaxin Wu (2): MdeModulePke/Mtftp4Dxe: Correct the total received and saved block number. NetworkPkg/Mtftp6Dxe: Correct the total received and saved block number. .../Universal/Network/Mtftp4Dxe/Mtftp4Impl.h | 6 +- .../Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c | 16 +++- .../Universal/Network/Mtftp4Dxe/Mtftp4Support.c | 10 +- .../Universal/Network/Mtftp4Dxe/Mtftp4Support.h | 6 +++--- .../Universal/Network/Mtftp4Dxe/Mtftp4Wrq.c | 6 +++--- NetworkPkg/Mtftp6Dxe/Mtftp6Impl.h| 6 +- NetworkPkg/Mtftp6Dxe/Mtftp6Rrq.c | 16 +++- NetworkPkg/Mtftp6Dxe/Mtftp6Support.c | 10 +- NetworkPkg/Mtftp6Dxe/Mtftp6Support.h | 8 NetworkPkg/Mtftp6Dxe/Mtftp6Wrq.c | 6 +++--- 10 files changed, 55 insertions(+), 35 deletions(-) -- 2.17.1.windows.2 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [Patch 2/2] BaseTools: Update nasm file build rule to support $(INC)
From: zhijufan Update the build rule to: "$(NASM)" -I${s_path}(+) $(NASM_INC)(+) $(NASM_FLAGS) -o $dst ${d_path}(+)${s_base}.iii Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan --- BaseTools/Conf/build_rule.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BaseTools/Conf/build_rule.template b/BaseTools/Conf/build_rule.template index ed54a55..7c4b9e6 100755 --- a/BaseTools/Conf/build_rule.template +++ b/BaseTools/Conf/build_rule.template @@ -223,11 +223,11 @@ $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.obj "$(PP)" $(PP_FLAGS) $(INC) ${src} > ${d_path}(+)${s_base}.i Trim --trim-long --source-code -o ${d_path}(+)${s_base}.iii ${d_path}(+)${s_base}.i -"$(NASM)" -I${s_path}(+) $(NASM_FLAGS) -o $dst ${d_path}(+)${s_base}.iii +"$(NASM)" -I${s_path}(+) $(NASM_INC)(+) $(NASM_FLAGS) -o $dst ${d_path}(+)${s_base}.iii [Device-Tree-Source-File] ?.dts -- 2.6.1.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [Patch 1/2] BaseTools: Add $(INC)-like support when compiling .nasm files
From: zhijufan current edk2\BaseTools\Conf\build_rule.template, the compile of nasm source files does not have the $(INC) support. The '-I' option only includes the directory of the nasm source file (${s_path}(+)). Hence, it will be impossible for nasm files to include files outside of the nasm source file directory. As a comparison, the compile of both .s and .asm have $(INC) support in their compile commands. Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=1085 Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan --- BaseTools/Source/Python/AutoGen/GenMake.py | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py index d94d8f9..8860d50 100644 --- a/BaseTools/Source/Python/AutoGen/GenMake.py +++ b/BaseTools/Source/Python/AutoGen/GenMake.py @@ -165,11 +165,11 @@ class BuildFile(object): _INCLUDE_CMD_ = { "nmake" : '!INCLUDE', "gmake" : "include" } -_INC_FLAG_ = {TAB_COMPILER_MSFT : "/I", "GCC" : "-I", "INTEL" : "-I", "RVCT" : "-I"} +_INC_FLAG_ = {TAB_COMPILER_MSFT : "/I", "GCC" : "-I", "INTEL" : "-I", "RVCT" : "-I", "NASM" : "-I"} ## Constructor of BuildFile # # @param AutoGenObject Object of AutoGen class # @@ -594,10 +594,22 @@ cleanlib: "macro_name" : "INC", "source_file" : IncludePathList } ) FileMacroList.append(FileMacro) +for File in self.FileCache.keys(): +if not str(File).endswith('.nasm'): +continue +FileMacro = "" +IncludePathList = [] +for P in MyAgo.IncludePathList: +IncludePathList.append(self._INC_FLAG_['NASM'] + self.PlaceMacro(P, self.Macros)) +if FileBuildRule.INC_LIST_MACRO in self.ListFileMacros: + self.ListFileMacros[FileBuildRule.INC_LIST_MACRO].append(self._INC_FLAG_['NASM'] + P) +FileMacro += self._FILE_MACRO_TEMPLATE.Replace({"macro_name": "NASM_INC", "source_file": IncludePathList}) +FileMacroList.append(FileMacro) +break # Generate macros used to represent files containing list of input files for ListFileMacro in self.ListFileMacros: ListFileName = os.path.join(MyAgo.OutputDir, "%s.lst" % ListFileMacro.lower()[:len(ListFileMacro) - 5]) FileMacroList.append("%s = %s" % (ListFileMacro, ListFileName)) -- 2.6.1.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [Patch 0/2] Update .nasm to support $(INC)-like support
Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=1085 Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Zhiju.Fan zhijufan (2): BaseTools: Add $(INC)-like support when compiling .nasm files BaseTools: Update nasm file build rule to support $(INC) BaseTools/Conf/build_rule.template | 2 +- BaseTools/Source/Python/AutoGen/GenMake.py | 14 +- 2 files changed, 14 insertions(+), 2 deletions(-) -- 2.6.1.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH v2] IntelFsp2Pkg: FSP should not override IDT
Reviewed-by: jiewen@intel.com > -Original Message- > From: Chiu, Chasel > Sent: Tuesday, October 23, 2018 5:34 PM > To: edk2-devel@lists.01.org > Cc: Yao, Jiewen ; Desimone, Nathaniel L > ; Chiu, Chasel > Subject: [PATCH v2] IntelFsp2Pkg: FSP should not override IDT > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1265 > > FSP should not override IDT table when it is initialized > by boot loader. IDT should be re-initialized in FSP only > when it is invalid. > To mitigate temporary memory usage a PCD > PcdFspMaxInterruptSupported created for platform to decide > how many interrupts the FSP IDT table can support. > > Test: Verified on internal platform and boots successfully. > > Cc: Jiewen Yao > Cc: Desimone Nathaniel L > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Chasel Chiu > --- > IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf | 1 + > IntelFsp2Pkg/FspSecCore/SecMain.c | 24 > +++- > IntelFsp2Pkg/FspSecCore/SecMain.h | 6 ++ > IntelFsp2Pkg/IntelFsp2Pkg.dec | 4 > 4 files changed, 26 insertions(+), 9 deletions(-) > > diff --git a/IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf > b/IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf > index c61af10b8a..dafe6f5993 100644 > --- a/IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf > +++ b/IntelFsp2Pkg/FspSecCore/FspSecCoreM.inf > @@ -62,6 +62,7 @@ >gIntelFsp2PkgTokenSpaceGuid.PcdTemporaryRamSize ## > CONSUMES >gIntelFsp2PkgTokenSpaceGuid.PcdFspTemporaryRamSize ## > CONSUMES >gIntelFsp2PkgTokenSpaceGuid.PcdFspHeapSizePercentage ## > CONSUMES > + gIntelFsp2PkgTokenSpaceGuid.PcdFspMaxInterruptSupported ## > CONSUMES > > [Ppis] >gEfiTemporaryRamSupportPpiGuid > ## PRODUCES > diff --git a/IntelFsp2Pkg/FspSecCore/SecMain.c > b/IntelFsp2Pkg/FspSecCore/SecMain.c > index 37fd4dfdeb..ddbfc4fcdf 100644 > --- a/IntelFsp2Pkg/FspSecCore/SecMain.c > +++ b/IntelFsp2Pkg/FspSecCore/SecMain.c > @@ -70,6 +70,7 @@ SecStartup ( >UINT32 Index; >FSP_GLOBAL_DATA PeiFspData; >UINT64 ExceptionHandler; > + UINTN IdtSize; > >// >// Process all libraries constructor function linked to SecCore. > @@ -98,13 +99,26 @@ SecStartup ( >// | | >// |---|> TempRamBase >IdtTableInStack.PeiService = NULL; > - ExceptionHandler = FspGetExceptionHandler(mIdtEntryTemplate); > - for (Index = 0; Index < SEC_IDT_ENTRY_COUNT; Index ++) { > -CopyMem ((VOID*)&IdtTableInStack.IdtTable[Index], > (VOID*)&ExceptionHandler, sizeof (UINT64)); > + AsmReadIdtr (&IdtDescriptor); > + if ((IdtDescriptor.Base == 0) && (IdtDescriptor.Limit == 0x)) { > +ExceptionHandler = FspGetExceptionHandler(mIdtEntryTemplate); > +for (Index = 0; Index < FixedPcdGet8(PcdFspMaxInterruptSupported); > Index ++) { > + CopyMem ((VOID*)&IdtTableInStack.IdtTable[Index], > (VOID*)&ExceptionHandler, sizeof (UINT64)); > +} > +IdtSize = sizeof (IdtTableInStack.IdtTable); > + } else { > +if (IdtDescriptor.Limit + 1 > sizeof (IdtTableInStack.IdtTable)) { > + // > + // ERROR: IDT table size from boot loader is larger than FSP can > support, DeadLoop here! > + // > + CpuDeadLoop(); > +} else { > + IdtSize = IdtDescriptor.Limit + 1; > +} > +CopyMem ((VOID *) (UINTN) &IdtTableInStack.IdtTable, (VOID *) > IdtDescriptor.Base, IdtSize); >} > - >IdtDescriptor.Base = (UINTN) &IdtTableInStack.IdtTable; > - IdtDescriptor.Limit = (UINT16)(sizeof (IdtTableInStack.IdtTable) - 1); > + IdtDescriptor.Limit = (UINT16)(IdtSize - 1); > >AsmWriteIdtr (&IdtDescriptor); > > diff --git a/IntelFsp2Pkg/FspSecCore/SecMain.h > b/IntelFsp2Pkg/FspSecCore/SecMain.h > index 291bc5ca5c..19ac2fbfc1 100644 > --- a/IntelFsp2Pkg/FspSecCore/SecMain.h > +++ b/IntelFsp2Pkg/FspSecCore/SecMain.h > @@ -1,6 +1,6 @@ > /** @file > > - Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved. > + Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved. >This program and the accompanying materials >are licensed and made available under the terms and conditions of the > BSD License >which accompanies this distribution. The full text of the license may be > found at > @@ -29,8 +29,6 @@ > #include > #include > > -#define SEC_IDT_ENTRY_COUNT34 > - > typedef VOID (*PEI_CORE_ENTRY) ( \ >IN CONST EFI_SEC_PEI_HAND_OFF*SecCoreData, \ >IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList \ > @@ -38,7 +36,7 @@ typedef VOID (*PEI_CORE_ENTRY) ( \ > > typedef struct _SEC_IDT_TABLE { >EFI_PEI_SERVICES *PeiService; > - UINT64IdtTable[SEC_IDT_ENTRY_COUNT]; > + UINT64IdtTable[FixedPcdGet8 > (PcdFspMaxInterruptSupported)]; > } SEC_IDT_TABLE; > > /** > diff --git a/IntelFsp2Pkg/IntelFsp2Pkg.dec b/IntelFsp2Pkg/IntelFsp2Pkg.dec > index 5b037d65e2..50496241da 100644 > -
[edk2] [PATCH v1 0/1] StandaloneMM: Update permissions for Standalone MM drivers memory area
Patch to update the memory attributes of the region where StandaloneMM drivers are loaded. Based on the review comments from Ard, this code has now been moved under StandaloneMmPkg directory. This patch needs to be applied on top of the following patch series - "ArmPkg related changes for StandaloneMM package". Sughosh Ganu (1): StandaloneMM: Update permissions for Standalone MM drivers memory area ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.inf => StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/StandaloneMmPeCoffExtraActionLib.inf | 19 +- StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/StandaloneMmPeCoffExtraActionLib.c | 222 2 files changed, 234 insertions(+), 7 deletions(-) copy ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.inf => StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/StandaloneMmPeCoffExtraActionLib.inf (72%) create mode 100644 StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/StandaloneMmPeCoffExtraActionLib.c -- 2.7.4 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH v1 1/1] StandaloneMM: Update permissions for Standalone MM drivers memory area
The StandaloneMM image executes in S-EL0 on reference Arm platforms and is deployed by the trusted firmware as BL32 image. Memory for the Standalone MM drivers is marked as RW+XN initially, allowing the drivers to be loaded into the memory. Once loaded, the memory attributes need to be changed to RO+XN for rodata sections and RO+X for code sections. Achieve this through the extra action 'UpdatePeCoffPermissions' to request the privileged firmware in EL3 to update the permissions. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Sughosh Ganu --- ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.inf => StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/StandaloneMmPeCoffExtraActionLib.inf | 19 +- StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/StandaloneMmPeCoffExtraActionLib.c | 222 2 files changed, 234 insertions(+), 7 deletions(-) diff --git a/ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.inf b/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/StandaloneMmPeCoffExtraActionLib.inf similarity index 72% copy from ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.inf copy to StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/StandaloneMmPeCoffExtraActionLib.inf index 3be0237a3689..f9a1afaac0c5 100644 --- a/ArmPkg/Library/RvdPeCoffExtraActionLib/RvdPeCoffExtraActionLib.inf +++ b/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/StandaloneMmPeCoffExtraActionLib.inf @@ -16,9 +16,9 @@ #**/ [Defines] - INF_VERSION= 0x00010005 - BASE_NAME = RvdUnixPeCoffExtraActionLib - FILE_GUID = 5EDEB7E7-EA55-4E92-8216-335AC98A3B11 + INF_VERSION= 0x0001000A + BASE_NAME = StandaloneMmPeCoffExtraActionLib + FILE_GUID = 8B40543B-9588-48F8-840C-5A60E6DB1B03 MODULE_TYPE= BASE VERSION_STRING = 1.0 LIBRARY_CLASS = PeCoffExtraActionLib @@ -30,12 +30,17 @@ [Defines] # [Sources.common] - RvdPeCoffExtraActionLib.c + StandaloneMmPeCoffExtraActionLib.c [Packages] - MdePkg/MdePkg.dec ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + StandaloneMmPkg/StandaloneMmPkg.dec + +[FeaturePcd] + gStandaloneMmPkgTokenSpaceGuid.PcdStandaloneMmEnable [LibraryClasses] - DebugLib - SemihostLib + ArmMmuLib +# DebugLib + PcdLib diff --git a/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/StandaloneMmPeCoffExtraActionLib.c b/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/StandaloneMmPeCoffExtraActionLib.c new file mode 100644 index ..1c9fec201916 --- /dev/null +++ b/StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActionLib/StandaloneMmPeCoffExtraActionLib.c @@ -0,0 +1,222 @@ +/**@file + +Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved. +Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved. +Portions copyright (c) 2011 - 2018, ARM Ltd. All rights reserved. + +This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +typedef RETURN_STATUS (*REGION_PERMISSION_UPDATE_FUNC) ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64Length + ); + +STATIC +RETURN_STATUS +UpdatePeCoffPermissions ( + IN CONST PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, + IN REGION_PERMISSION_UPDATE_FUNC NoExecUpdater, + IN REGION_PERMISSION_UPDATE_FUNC ReadOnlyUpdater + ) +{ + RETURN_STATUS Status; + EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; + EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData; + UINTN Size; + UINTN ReadSize; + UINT32SectionHeaderOffset; + UINTN NumberOfSections; + UINTN Index; + EFI_IMAGE_SECTION_HEADER SectionHeader; + PE_COFF_LOADER_IMAGE_CONTEXT TmpContext; + EFI_PHYSICAL_ADDRESS Base; + + // + // We need to copy ImageContext since PeCoffLoaderGetImageInfo () + // will mangle the ImageAddress field + // + CopyMem (&TmpContext, ImageContext, sizeof (TmpContext)); + + if (TmpContext.PeCoffHeaderOffset == 0) { +Status = PeCoffLoaderGetImageInfo (&TmpContext); +if (RETURN_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, +"%a: PeCoffLoaderGetImageI
[edk2] [PATCH v3 5/6] ArmPkg/ArmMmuLib: Add MMU Library suitable for use in S-EL0.
From: Achin Gupta The Standalone MM environment runs in S-EL0 in AArch64 on ARM Standard Platforms. Privileged firmware e.g. ARM Trusted Firmware sets up its architectural context including the initial translation tables for the S-EL1/EL0 translation regime. The MM environment will still request ARM TF to change the memory attributes of memory regions during initialization. The Standalone MM image is a FV that encapsulates the MM foundation and drivers. These are PE-COFF images with data and text segments. To initialise the MM environment, Arm Trusted Firmware has to create translation tables with sane default attributes for the memory occupied by the FV. This library sends SVCs to ARM Trusted Firmware to request memory permissions change for data and text segments. This patch adds a simple MMU library suitable for execution in S-EL0 and requesting memory permissions change operations from Arm Trusted Firmware. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Sughosh Ganu --- ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuStandaloneMmCoreLib.c | 204 1 file changed, 204 insertions(+) diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuStandaloneMmCoreLib.c b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuStandaloneMmCoreLib.c new file mode 100644 index ..ee0a80349051 --- /dev/null +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuStandaloneMmCoreLib.c @@ -0,0 +1,204 @@ +/** @file +* File managing the MMU for ARMv8 architecture in S-EL0 +* +* Copyright (c) 2017 - 2018, ARM Limited. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +#include +#include +#include + +#include +#include +#include +#include +#include + +EFI_STATUS +GetMemoryPermissions ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + OUT UINT32*MemoryAttributes + ) +{ + ARM_SVC_ARGS GetMemoryPermissionsSvcArgs = {0}; + + GetMemoryPermissionsSvcArgs.Arg0 = ARM_SVC_ID_SP_GET_MEM_ATTRIBUTES_AARCH64; + GetMemoryPermissionsSvcArgs.Arg1 = BaseAddress; + GetMemoryPermissionsSvcArgs.Arg2 = 0; + GetMemoryPermissionsSvcArgs.Arg3 = 0; + + ArmCallSvc (&GetMemoryPermissionsSvcArgs); + if (GetMemoryPermissionsSvcArgs.Arg0 == ARM_SVC_SPM_RET_INVALID_PARAMS) { +*MemoryAttributes = 0; +return EFI_INVALID_PARAMETER; + } + + *MemoryAttributes = GetMemoryPermissionsSvcArgs.Arg0; + return EFI_SUCCESS; +} + +EFI_STATUS +RequestMemoryPermissionChange ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64Length, + IN UINTN Permissions + ) +{ + EFI_STATUSStatus; + ARM_SVC_ARGS ChangeMemoryPermissionsSvcArgs = {0}; + + ChangeMemoryPermissionsSvcArgs.Arg0 = ARM_SVC_ID_SP_SET_MEM_ATTRIBUTES_AARCH64; + ChangeMemoryPermissionsSvcArgs.Arg1 = BaseAddress; + ChangeMemoryPermissionsSvcArgs.Arg2 = EFI_SIZE_TO_PAGES(Length); + ChangeMemoryPermissionsSvcArgs.Arg3 = Permissions; + + ArmCallSvc (&ChangeMemoryPermissionsSvcArgs); + + Status = ChangeMemoryPermissionsSvcArgs.Arg0; + + switch (Status) { + case ARM_SVC_SPM_RET_SUCCESS: +Status = EFI_SUCCESS; +break; + + case ARM_SVC_SPM_RET_NOT_SUPPORTED: +Status = EFI_UNSUPPORTED; +break; + + case ARM_SVC_SPM_RET_INVALID_PARAMS: +Status = EFI_INVALID_PARAMETER; +break; + + case ARM_SVC_SPM_RET_DENIED: +Status = EFI_ACCESS_DENIED; +break; + + case ARM_SVC_SPM_RET_NO_MEMORY: +Status = EFI_BAD_BUFFER_SIZE; +break; + + default: +Status = EFI_ACCESS_DENIED; +ASSERT (0); + } + + return Status; +} + +EFI_STATUS +ArmSetMemoryRegionNoExec ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64Length + ) +{ + EFI_STATUSStatus; + UINT32 MemoryAttributes; + UINT32 CodePermission; + + Status = GetMemoryPermissions (BaseAddress, &MemoryAttributes); + if (Status != EFI_INVALID_PARAMETER) { +CodePermission = SET_MEM_ATTR_CODE_PERM_XN << SET_MEM_ATTR_CODE_PERM_SHIFT; +return RequestMemoryPermissionChange ( + BaseAddress, + Length, + MemoryAttributes | CodePermission + ); + } + return EFI_INVALID_PARAMETER; +} + +EFI_STATUS +ArmClearMemoryRegionNoExec ( + IN EFI_PHYSICAL_ADDRESS BaseAddress, + IN UINT64Length + ) +{ + EFI_STATUSStatus; + UINT32 MemoryAttributes; + UINT32 CodePermission; + + Status = GetMemoryPermissions (BaseAddress, &MemoryAttributes); + if (Status != EFI_INVALID_PARAMETER) { +CodePermission = SET_MEM_ATTR_CODE_PERM_XN << SET_MEM_ATTR_CODE_PERM_SHIFT; +return RequestMemoryPermi
[edk2] [PATCH v3 6/6] ArmPkg/ArmMmuLib: Add MMU library inf file suitable for use in S-EL0.
From: Achin Gupta This patch adds the definitions, sources, packages and library classes needed to compile and link MMU Library suitable for use in S-EL0. Currently, this is used only during the Standalone MM Core initialization and hence defined as MM_CORE_STANDALONE Module. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Sughosh Ganu --- ArmPkg/Library/ArmMmuLib/{ArmMmuPeiLib.inf => ArmMmuStandaloneMmCoreLib.inf} | 23 +--- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/ArmPkg/Library/ArmMmuLib/ArmMmuPeiLib.inf b/ArmPkg/Library/ArmMmuLib/ArmMmuStandaloneMmCoreLib.inf similarity index 51% copy from ArmPkg/Library/ArmMmuLib/ArmMmuPeiLib.inf copy to ArmPkg/Library/ArmMmuLib/ArmMmuStandaloneMmCoreLib.inf index ecf13f790734..9f5593d3f6c8 100644 --- a/ArmPkg/Library/ArmMmuLib/ArmMmuPeiLib.inf +++ b/ArmPkg/Library/ArmMmuLib/ArmMmuStandaloneMmCoreLib.inf @@ -1,6 +1,6 @@ #/** @file # -# Copyright (c) 2016 Linaro Ltd. All rights reserved. +# Copyright (c) 2017 - 2018, ARM Limited. All rights reserved. # # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -13,22 +13,20 @@ #**/ [Defines] - INF_VERSION= 0x00010005 - BASE_NAME = ArmMmuPeiLib - FILE_GUID = b50d8d53-1ad1-44ea-9e69-8c89d4a6d08b - MODULE_TYPE= PEIM + INF_VERSION= 0x0001001A + BASE_NAME = ArmMmuStandaloneMmCoreLib + FILE_GUID = da8f0232-fb14-42f0-922c-63104d2c70bd + MODULE_TYPE= MM_CORE_STANDALONE VERSION_STRING = 1.0 - LIBRARY_CLASS = ArmMmuLib|PEIM - CONSTRUCTOR= ArmMmuPeiLibConstructor + LIBRARY_CLASS = ArmMmuStandaloneMmCoreLib|MM_CORE_STANDALONE + PI_SPECIFICATION_VERSION = 0x00010032 + CONSTRUCTOR= ArmMmuStandaloneMmCoreLibConstructor [Sources.AARCH64] - AArch64/ArmMmuLibCore.c - AArch64/ArmMmuPeiLibConstructor.c - AArch64/ArmMmuLibReplaceEntry.S + AArch64/ArmMmuStandaloneMmCoreLib.c [Packages] ArmPkg/ArmPkg.dec - EmbeddedPkg/EmbeddedPkg.dec MdePkg/MdePkg.dec [LibraryClasses] @@ -36,5 +34,4 @@ [LibraryClasses] CacheMaintenanceLib MemoryAllocationLib -[Pcd.AARCH64] - gEmbeddedTokenSpaceGuid.PcdPrePiCpuMemorySize + -- 2.7.4 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH v3 2/6] ArmPkg/Drivers: Add EFI_MM_COMMUNICATION_PROTOCOL DXE driver.
From: Achin Gupta PI v1.5 Specification Volume 4 defines Management Mode Core Interface and defines EFI_MM_COMMUNICATION_PROTOCOL. This protocol provides a means of communicating between drivers outside of MM and MMI handlers inside of MM. This patch implements the EFI_MM_COMMUNICATION_PROTOCOL DXE runtime driver for AARCH64 platforms. It uses SMCs allocated from the standard SMC range defined in DEN0060A_ARM_MM_Interface_Specification.pdf to communicate with the standalone MM environment in the secure world. This patch also adds the MM Communication driver (.inf) file to define entry point for this driver and other compile related information the driver needs. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Sughosh Ganu --- ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf | 56 +++ ArmPkg/Drivers/MmCommunicationDxe/MmCommunicate.h | 28 ++ ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c | 395 3 files changed, 479 insertions(+) diff --git a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf new file mode 100644 index ..88beafa39c05 --- /dev/null +++ b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf @@ -0,0 +1,56 @@ +#/** @file +# +# DXE MM Communicate driver +# +# Copyright (c) 2016 - 2018, ARM Limited. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/ + +[Defines] + INF_VERSION= 0x0001001A + BASE_NAME = ArmMmCommunication + FILE_GUID = 09EE81D3-F15E-43F4-85B4-CB9873DA5D6B + MODULE_TYPE= DXE_RUNTIME_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT= MmCommunicationInitialize + +# +# The following is for reference only and not required by +# build tools +# +# VALID_ARCHITECTURES= AARCH64 +# + +[Sources.AARCH64] + MmCommunication.c + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + ArmLib + ArmSmcLib + BaseMemoryLib + DebugLib + DxeServicesTableLib + HobLib + UefiDriverEntryPoint + +[Protocols] + gEfiMmCommunicationProtocolGuid ## PRODUCES + +[Pcd.common] + gArmTokenSpaceGuid.PcdMmBufferBase + gArmTokenSpaceGuid.PcdMmBufferSize + +[Depex] + gEfiCpuArchProtocolGuid diff --git a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunicate.h b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunicate.h new file mode 100644 index ..0bf1c8d4ca0e --- /dev/null +++ b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunicate.h @@ -0,0 +1,28 @@ +/** @file + + Copyright (c) 2016-2018, ARM Limited. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#if !defined _MM_COMMUNICATE_H_ +#define _MM_COMMUNICATE_H_ + +#define MM_MAJOR_VER_MASK0xEFFF +#define MM_MINOR_VER_MASK0x +#define MM_MAJOR_VER_SHIFT 16 + +#define MM_MAJOR_VER(x) (((x) & MM_MAJOR_VER_MASK) >> MM_MAJOR_VER_SHIFT) +#define MM_MINOR_VER(x) ((x) & MM_MINOR_VER_MASK) + +#define MM_CALLER_MAJOR_VER 0x1UL +#define MM_CALLER_MINOR_VER 0x0 + +#endif /* _MM_COMMUNICATE_H_ */ diff --git a/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c new file mode 100644 index ..487db00c2a87 --- /dev/null +++ b/ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c @@ -0,0 +1,395 @@ +/** @file + + Copyright (c) 2016-2018, ARM Limited. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include "MmCommunicate.h" + +// +// Address, Length of the pre-allocated buffer for communication with the secure +// world. +// +STATIC ARM_MEM
[edk2] [PATCH v3 4/6] ArmPkg/Include: Add MM interface SVC return codes.
From: Achin Gupta This patch adds the Management Mode(MM) - Secure Partition Manager(SPM) SVC return codes. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Sughosh Ganu --- ArmPkg/Include/IndustryStandard/ArmMmSvc.h | 7 +++ 1 file changed, 7 insertions(+) diff --git a/ArmPkg/Include/IndustryStandard/ArmMmSvc.h b/ArmPkg/Include/IndustryStandard/ArmMmSvc.h index 81b4654fa5dd..a64b9ec23c4b 100644 --- a/ArmPkg/Include/IndustryStandard/ArmMmSvc.h +++ b/ArmPkg/Include/IndustryStandard/ArmMmSvc.h @@ -40,4 +40,11 @@ c_perm) & SET_MEM_ATTR_CODE_PERM_MASK) << SET_MEM_ATTR_CODE_PERM_SHIFT) | \ (( (d_perm) & SET_MEM_ATTR_DATA_PERM_MASK) << SET_MEM_ATTR_DATA_PERM_SHIFT)) +/* MM SVC Return error codes */ +#define ARM_SVC_SPM_RET_SUCCESS 0 +#define ARM_SVC_SPM_RET_NOT_SUPPORTED-1 +#define ARM_SVC_SPM_RET_INVALID_PARAMS -2 +#define ARM_SVC_SPM_RET_DENIED -3 +#define ARM_SVC_SPM_RET_NO_MEMORY-5 + #endif -- 2.7.4 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH v3 1/6] ArmPkg: Add PCDs needed for MM communication driver.
From: Achin Gupta This patch defines PCDs to describe the base address and size of communication buffer between normal world (uefi) and standalone MM environment in the secure world. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Sughosh Ganu --- ArmPkg/ArmPkg.dec | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec index 84e57a0bf01c..0db7aa9d301c 100644 --- a/ArmPkg/ArmPkg.dec +++ b/ArmPkg/ArmPkg.dec @@ -240,6 +240,9 @@ [PcdsFixedAtBuild.common, PcdsDynamic.common, PcdsPatchableInModule.common] gArmTokenSpaceGuid.PcdSystemMemoryBase|0|UINT64|0x0029 gArmTokenSpaceGuid.PcdSystemMemorySize|0|UINT64|0x002A + gArmTokenSpaceGuid.PcdMmBufferBase|0|UINT64|0x0045 + gArmTokenSpaceGuid.PcdMmBufferSize|0|UINT64|0x0046 + [PcdsFixedAtBuild.common, PcdsDynamic.common] # # ARM Architectural Timer -- 2.7.4 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH v3 3/6] ArmPkg/Include: Fix the SPM version SVC ID
The MM_VERSION SMC call uses SMC32 calling convention. Fix the macro to reflect the correct value. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Sughosh Ganu --- ArmPkg/Include/IndustryStandard/ArmMmSvc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ArmPkg/Include/IndustryStandard/ArmMmSvc.h b/ArmPkg/Include/IndustryStandard/ArmMmSvc.h index 4c7b6c338627..81b4654fa5dd 100644 --- a/ArmPkg/Include/IndustryStandard/ArmMmSvc.h +++ b/ArmPkg/Include/IndustryStandard/ArmMmSvc.h @@ -20,7 +20,7 @@ * delegated events and request the Secure partition manager to perform * privileged operations on its behalf. */ -#define ARM_SVC_ID_SPM_VERSION_AARCH64 0xC460 +#define ARM_SVC_ID_SPM_VERSION_AARCH32 0x8460 #define ARM_SVC_ID_SP_EVENT_COMPLETE_AARCH64 0xC461 #define ARM_SVC_ID_SP_GET_MEM_ATTRIBUTES_AARCH64 0xC464 #define ARM_SVC_ID_SP_SET_MEM_ATTRIBUTES_AARCH64 0xC465 -- 2.7.4 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH v3 0/6] ArmPkg related changes for StandaloneMM package
The following patch series adds support for Management Mode related changes for aarch64 based platforms. Changes since v2: Based on review comments from Ard, moved the memory attribute updation changes out of DebugPeCoffExtraActionLib into an extra action library added in StandaloneMM package. The patch for setting the memory attributes, now under StandaloneMmPkg directory, will be submitted separately from this series. Achin Gupta (5): ArmPkg: Add PCDs needed for MM communication driver. ArmPkg/Drivers: Add EFI_MM_COMMUNICATION_PROTOCOL DXE driver. ArmPkg/Include: Add MM interface SVC return codes. ArmPkg/ArmMmuLib: Add MMU Library suitable for use in S-EL0. ArmPkg/ArmMmuLib: Add MMU library inf file suitable for use in S-EL0. Sughosh Ganu (1): ArmPkg/Include: Fix the SPM version SVC ID ArmPkg/ArmPkg.dec| 3 + ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf| 56 +++ ArmPkg/Library/ArmMmuLib/{ArmMmuPeiLib.inf => ArmMmuStandaloneMmCoreLib.inf} | 23 +- ArmPkg/Drivers/MmCommunicationDxe/MmCommunicate.h| 28 ++ ArmPkg/Include/IndustryStandard/ArmMmSvc.h | 9 +- ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c | 395 ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuStandaloneMmCoreLib.c | 204 ++ 7 files changed, 704 insertions(+), 14 deletions(-) create mode 100644 ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.inf copy ArmPkg/Library/ArmMmuLib/{ArmMmuPeiLib.inf => ArmMmuStandaloneMmCoreLib.inf} (51%) create mode 100644 ArmPkg/Drivers/MmCommunicationDxe/MmCommunicate.h create mode 100644 ArmPkg/Drivers/MmCommunicationDxe/MmCommunication.c create mode 100644 ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuStandaloneMmCoreLib.c -- 2.7.4 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] FDF Spec: Add the $(PCD) usage in the [FD] section
Reviewed-by: Liming Gao > -Original Message- > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of > Yonghong Zhu > Sent: Monday, October 22, 2018 3:49 PM > To: edk2-devel@lists.01.org > Cc: Kinney, Michael D ; Shaw, Kevin W > ; Gao, Liming > Subject: [edk2] [Patch] FDF Spec: Add the $(PCD) usage in the [FD] section > > current code support to use $(PCD) in the [FD] section, and lots of > platform FDF file already used this usage, so we update the FDF spec > first to align with code to reduce the incompatible change for > firmware developer. > > Cc: Liming Gao > Cc: Michael Kinney > Cc: Kevin W Shaw > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Yonghong Zhu > --- > 2_fdf_design_discussion/24_[fd]_sections.md | 2 +- > 3_edk_ii_fdf_file_format/35_[fd]_sections.md | 4 ++-- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/2_fdf_design_discussion/24_[fd]_sections.md > b/2_fdf_design_discussion/24_[fd]_sections.md > index e532041..67e478e 100644 > --- a/2_fdf_design_discussion/24_[fd]_sections.md > +++ b/2_fdf_design_discussion/24_[fd]_sections.md > @@ -162,11 +162,11 @@ For a PCD that has a datum type of `VOID`*, the data > can be a Unicode string, > as in `L"text"`, a valid C data array (it must be either a C format GUID or a > hex byte array), as in `{0x20, 0x01, 0x50, 0x00, 0x32, 0xFF, 0x00, 0xAA, > {0xFF, 0xF0, 0x00, 0x00, 0x00}}.` > For other PCD datum types, the value may be a boolean or a hex value, as in > `0x000F,` with a value that is consistent with the PCD's datum type. > > -The value may also be a macro or it may be computed, using arithmetic > +The value may also be a macro or `$(PCD)` or it may be computed, using > arithmetic > operations, arithmetic expressions and or logical expressions. The value > portion of the `SET` statement, when using any of these computations are > in-fix > expressions that are evaluated left to right, with items within parenthesis > evaluated before the outer expressions are evaluated. Use of parenthesis is > encouraged to remove ambiguity. > diff --git a/3_edk_ii_fdf_file_format/35_[fd]_sections.md > b/3_edk_ii_fdf_file_format/35_[fd]_sections.md > index f0003e7..e46fd7b 100644 > --- a/3_edk_ii_fdf_file_format/35_[fd]_sections.md > +++ b/3_edk_ii_fdf_file_format/35_[fd]_sections.md > @@ -150,13 +150,13 @@ The `FvUiName` must be specified in a `[FV]` section > header defined in this the > file. > > **_PcdValue_** > > The PCD Value may be a specific numeric value, an array of numeric bytes, a > -GUID, a quoted string, an L quoted string (representing a unicode string), an > +GUID, a quoted string, an `L` quoted string (representing a unicode string), > an > arithmetic expression, a logic expression or a macro from a previously > defined > -macro statement. > +macro statement or a `$(PCD) format. > > **_Expression_** > > Refer to the EDK II Expression Syntax Specification for more information. > > -- > 2.6.1.windows.1 > > ___ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] BaseTools: Fix VPD PCD Sub-section display bug
Reviewed-by: Liming Gao > -Original Message- > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of > Yonghong Zhu > Sent: Tuesday, October 23, 2018 7:10 PM > To: edk2-devel@lists.01.org > Subject: [edk2] [Patch] BaseTools: Fix VPD PCD Sub-section display bug > > original we get the VPD PCD items from the VPDGuid.map file in the FV > output folder. but this logic doesn't work when 1) there only have > single non Default SKU, 2) there have multiple SKU with same value. > Now we change it to get the really VPD Pcd items that already display > in the PCD section of the report. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Yonghong Zhu > --- > BaseTools/Source/Python/build/BuildReport.py | 46 > ++-- > 1 file changed, 17 insertions(+), 29 deletions(-) > > diff --git a/BaseTools/Source/Python/build/BuildReport.py > b/BaseTools/Source/Python/build/BuildReport.py > index de8f0fb..ea98ef7 100644 > --- a/BaseTools/Source/Python/build/BuildReport.py > +++ b/BaseTools/Source/Python/build/BuildReport.py > @@ -124,10 +124,13 @@ gDriverTypeMap = { >} > > ## The look up table of the supported opcode in the dependency expression > binaries > gOpCodeList = ["BEFORE", "AFTER", "PUSH", "AND", "OR", "NOT", "TRUE", > "FALSE", "END", "SOR"] > > +## Save VPD Pcd > +VPDPcdList = [] > + > ## > # Writes a string to the file object. > # > # This function writes a string to the file object and a new line is appended > # afterwards. It may optionally wraps the string for better readability. > @@ -1399,10 +1402,13 @@ class PcdReport(object): > FileWrite(File, ' %-*s : %6s %10s = %s' % > (self.MaxLen, ' ', TypeName, '(' + Pcd.DatumType + > ')', Value)) > else: > FileWrite(File, ' %-*s : %6s %10s %10s = > %s' % (self.MaxLen, ' ', TypeName, '(' + > Pcd.DatumType + ')', '(' + SkuIdName + ')', Value)) > if TypeName in ('DYNVPD', 'DEXVPD'): > FileWrite(File, '%*s' % (self.MaxLen + 4, > SkuInfo.VpdOffset)) > +VPDPcdItem = (Pcd.TokenSpaceGuidCName + '.' + > PcdTokenCName, SkuIdName, SkuInfo.VpdOffset, > Pcd.MaxDatumSize, SkuInfo.DefaultValue) > +if VPDPcdItem not in VPDPcdList: > +VPDPcdList.append(VPDPcdItem) > if IsStructure: > FiledOverrideFlag = False > OverrideValues = Pcd.SkuOverrideValues[Sku] > if OverrideValues: > Keys = OverrideValues.keys() > @@ -2015,39 +2021,18 @@ class FdReport(object): > self.FdName = Fd.FdUiName > self.BaseAddress = Fd.BaseAddress > self.Size = Fd.Size > self.FdRegionList = [FdRegionReport(FdRegion, Wa) for FdRegion in > Fd.RegionList] > self.FvPath = os.path.join(Wa.BuildDir, TAB_FV_DIRECTORY) > -self.VpdFilePath = os.path.join(self.FvPath, "%s.map" % > Wa.Platform.VpdToolGuid) > self.VPDBaseAddress = 0 > self.VPDSize = 0 > -self.VPDInfoList = [] > for index, FdRegion in enumerate(Fd.RegionList): > if str(FdRegion.RegionType) is 'FILE' and > Wa.Platform.VpdToolGuid in str(FdRegion.RegionDataList): > self.VPDBaseAddress = self.FdRegionList[index].BaseAddress > self.VPDSize = self.FdRegionList[index].Size > break > > -if os.path.isfile(self.VpdFilePath): > -fd = open(self.VpdFilePath, "r") > -Lines = fd.readlines() > -for Line in Lines: > -Line = Line.strip() > -if len(Line) == 0 or Line.startswith("#"): > -continue > -try: > -PcdName, SkuId, Offset, Size, Value = > Line.split("#")[0].split("|") > -PcdName, SkuId, Offset, Size, Value = PcdName.strip(), > SkuId.strip(), Offset.strip(), Size.strip(), Value.strip() > -if Offset.lower().startswith('0x'): > -Offset = '0x%08X' % (int(Offset, 16) + > self.VPDBaseAddress) > -else: > -Offset = '0x%08X' % (int(Offset, 10) + > self.VPDBaseAddress) > -self.VPDInfoList.append("%s | %s | %s | %s | %s" % > (PcdName, SkuId, Offset, Size, Value)) > -except: > -EdkLogger.error("BuildReport", CODE_ERROR, "Fail to > parse VPD information file %s" % self.VpdFilePath) > -fd.close() > - > ## > # Generate report for the firmware device. > # > # This function generates report for the firmware device. > # > @@ -2063,27 +2048,30 @@ class FdReport(object): > if len(self.FdRegionList) > 0: > FileWrite(File, gSectionSep) > f
Re: [edk2] [Patch] BaseTools: list .nasm include inc files as its dependency
Reviewed-by: Liming Gao > -Original Message- > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of > Yonghong Zhu > Sent: Wednesday, October 24, 2018 3:38 PM > To: edk2-devel@lists.01.org > Cc: Gao, Liming > Subject: [edk2] [Patch] BaseTools: list .nasm include inc files as its > dependency > > From: zhijufan > > .nasm source file may include some header files. > header file should be listed in Makefile as .nasm source file > dependency. > But now, BaseTools doesn't find them and list them in Makefile. > This is a missing, because original ASM file supports it. > > Cc: Liming Gao > Cc: Yonghong Zhu > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Zhiju.Fan > Signed-off-by: Yonghong Zhu > --- > BaseTools/Source/Python/AutoGen/GenMake.py | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py > b/BaseTools/Source/Python/AutoGen/GenMake.py > index b4377ee..d94d8f9 100644 > --- a/BaseTools/Source/Python/AutoGen/GenMake.py > +++ b/BaseTools/Source/Python/AutoGen/GenMake.py > @@ -28,11 +28,11 @@ from .BuildEngine import * > import Common.GlobalData as GlobalData > from collections import OrderedDict > from Common.DataType import TAB_COMPILER_MSFT > > ## Regular expression for finding header file inclusions > -gIncludePattern = re.compile(r"^[ \t]*#?[ \t]*include(?:[ > \t]*(?:\\(?:\r\n|\r|\n))*[ \t]*)*(?:\(?[\"<]?[ \t]*)([-\w.\\/() > \t]+)(?:[ \t]*[\">]?\)?)", re.MULTILINE | re.UNICODE | re.IGNORECASE) > +gIncludePattern = re.compile(r"^[ \t]*[#%]?[ \t]*include(?:[ > \t]*(?:\\(?:\r\n|\r|\n))*[ \t]*)*(?:\(?[\"<]?[ \t]*)([-\w.\\/() > \t]+)(?:[ \t]*[\">]?\)?)", re.MULTILINE | re.UNICODE | re.IGNORECASE) > > ## Regular expression for matching macro used in header file inclusion > gMacroPattern = re.compile("([_A-Z][_A-Z0-9]*)[ \t]*\((.+)\)", re.UNICODE) > > gIsFileMap = {} > -- > 2.6.1.windows.1 > > ___ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH v4 5/6] MdeModulePkg/Core: prevent re-acquire GCD memory lock
Sorry, forgot to update commit message: > This issue is hidden in current code but exposed by introduction > of freed-memory guard feature due to the fact that the feature > will turn all pool allocation to page allocation. > > The solution is moving the memory allocation in CoreGetMemorySpaceMap() > to be out of the GCD memory map lock. Regards, Jian > -Original Message- > From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] > Sent: Thursday, October 25, 2018 3:18 PM > To: edk2-devel@lists.01.org > Cc: Kinney, Michael D ; Ni, Ruiyu > ; Yao, Jiewen ; Zeng, Star > ; Laszlo Ersek > Subject: [edk2] [PATCH v4 5/6] MdeModulePkg/Core: prevent re-acquire GCD > memory lock > > > v4 changes: > > a. add more comments from Laszlo > > This issue is hidden in current code but exposed by introduction > of freed-memory guard feature due to the fact that the feature > will turn all pool allocation to page allocation. > > The solution is move the memory allocation in CoreGetMemorySpaceMap() > and CoreGetIoSpaceMap() to be out of the GCD memory map lock. > >CoreDumpGcdMemorySpaceMap() > => CoreGetMemorySpaceMap() > => CoreAcquireGcdMemoryLock () * >AllocatePool() > => InternalAllocatePool() > => CoreAllocatePool() > => CoreAllocatePoolI() > => CoreAllocatePoolPagesI() > => CoreAllocatePoolPages() > => FindFreePages() > => PromoteMemoryResource() > => CoreAcquireGcdMemoryLock() ** > > Cc: Star Zeng > Cc: Michael D Kinney > Cc: Jiewen Yao > Cc: Ruiyu Ni > Cc: Laszlo Ersek > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Jian J Wang > --- > MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 87 +- > --- > 1 file changed, 62 insertions(+), 25 deletions(-) > > diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c > b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c > index d9c65a8045..f99d6bb933 100644 > --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c > +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c > @@ -1691,10 +1691,10 @@ CoreGetMemorySpaceMap ( >OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR **MemorySpaceMap >) > { > - EFI_STATUS Status; >LIST_ENTRY *Link; >EFI_GCD_MAP_ENTRY*Entry; >EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Descriptor; > + UINTNDescriptorCount; > >// >// Make sure parameters are valid > @@ -1706,38 +1706,75 @@ CoreGetMemorySpaceMap ( > return EFI_INVALID_PARAMETER; >} > > - CoreAcquireGcdMemoryLock (); > + *NumberOfDescriptors = 0; > + *MemorySpaceMap = NULL; > >// > - // Count the number of descriptors > + // Take the lock, for entering the loop with the lock held. >// > - *NumberOfDescriptors = CoreCountGcdMapEntry (&mGcdMemorySpaceMap); > + CoreAcquireGcdMemoryLock (); > + while (TRUE) { > +// > +// Count the number of descriptors. It might be done more than once > because > +// there's code which has to be running outside the GCD lock. > +// > +DescriptorCount = CoreCountGcdMapEntry (&mGcdMemorySpaceMap); > +if (DescriptorCount == *NumberOfDescriptors) { > + // > + // Fill in the MemorySpaceMap if no memory space map change. > + // > + Descriptor = *MemorySpaceMap; > + Link = mGcdMemorySpaceMap.ForwardLink; > + while (Link != &mGcdMemorySpaceMap) { > +Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE); > +BuildMemoryDescriptor (Descriptor, Entry); > +Descriptor++; > +Link = Link->ForwardLink; > + } > + // > + // We're done; exit the loop with the lock held. > + // > + break; > +} > > - // > - // Allocate the MemorySpaceMap > - // > - *MemorySpaceMap = AllocatePool (*NumberOfDescriptors * sizeof > (EFI_GCD_MEMORY_SPACE_DESCRIPTOR)); > - if (*MemorySpaceMap == NULL) { > -Status = EFI_OUT_OF_RESOURCES; > -goto Done; > - } > +// > +// Release the lock before memory allocation, because it might cause > +// GCD lock conflict in one of calling path in AllocatPool(). > +// > +CoreReleaseGcdMemoryLock (); > + > +// > +// Allocate memory to store the MemorySpaceMap. Note it might be already > +// allocated if there's map descriptor change during memory allocation at > +// last time. > +// > +if (*MemorySpaceMap != NULL) { > + FreePool (*MemorySpaceMap); > +} > > +*MemorySpaceMap = AllocatePool (DescriptorCount * > +sizeof > (EFI_GCD_MEMORY_SPACE_DESCRIPTOR)); > +if (*MemorySpaceMap == NULL) { > + *NumberOfDescriptors = 0; > + return EFI_OUT_OF_RESOURCES; > +} > + > +// > +// Save the descriptor count got before for another round of check to > make > +// sure we won't miss any, since we have code running outside the GCD > lock. > +// > +*NumberOfDescriptors = DescriptorCount; > +// > +// Re-acquire the lock, for the next iteration. > +// > +CoreAcquir
[edk2] [PATCH v4 5/6] MdeModulePkg/Core: prevent re-acquire GCD memory lock
> v4 changes: > a. add more comments from Laszlo This issue is hidden in current code but exposed by introduction of freed-memory guard feature due to the fact that the feature will turn all pool allocation to page allocation. The solution is move the memory allocation in CoreGetMemorySpaceMap() and CoreGetIoSpaceMap() to be out of the GCD memory map lock. CoreDumpGcdMemorySpaceMap() => CoreGetMemorySpaceMap() => CoreAcquireGcdMemoryLock () * AllocatePool() => InternalAllocatePool() => CoreAllocatePool() => CoreAllocatePoolI() => CoreAllocatePoolPagesI() => CoreAllocatePoolPages() => FindFreePages() => PromoteMemoryResource() => CoreAcquireGcdMemoryLock() ** Cc: Star Zeng Cc: Michael D Kinney Cc: Jiewen Yao Cc: Ruiyu Ni Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 87 + 1 file changed, 62 insertions(+), 25 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index d9c65a8045..f99d6bb933 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -1691,10 +1691,10 @@ CoreGetMemorySpaceMap ( OUT EFI_GCD_MEMORY_SPACE_DESCRIPTOR **MemorySpaceMap ) { - EFI_STATUS Status; LIST_ENTRY *Link; EFI_GCD_MAP_ENTRY*Entry; EFI_GCD_MEMORY_SPACE_DESCRIPTOR *Descriptor; + UINTNDescriptorCount; // // Make sure parameters are valid @@ -1706,38 +1706,75 @@ CoreGetMemorySpaceMap ( return EFI_INVALID_PARAMETER; } - CoreAcquireGcdMemoryLock (); + *NumberOfDescriptors = 0; + *MemorySpaceMap = NULL; // - // Count the number of descriptors + // Take the lock, for entering the loop with the lock held. // - *NumberOfDescriptors = CoreCountGcdMapEntry (&mGcdMemorySpaceMap); + CoreAcquireGcdMemoryLock (); + while (TRUE) { +// +// Count the number of descriptors. It might be done more than once because +// there's code which has to be running outside the GCD lock. +// +DescriptorCount = CoreCountGcdMapEntry (&mGcdMemorySpaceMap); +if (DescriptorCount == *NumberOfDescriptors) { + // + // Fill in the MemorySpaceMap if no memory space map change. + // + Descriptor = *MemorySpaceMap; + Link = mGcdMemorySpaceMap.ForwardLink; + while (Link != &mGcdMemorySpaceMap) { +Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE); +BuildMemoryDescriptor (Descriptor, Entry); +Descriptor++; +Link = Link->ForwardLink; + } + // + // We're done; exit the loop with the lock held. + // + break; +} - // - // Allocate the MemorySpaceMap - // - *MemorySpaceMap = AllocatePool (*NumberOfDescriptors * sizeof (EFI_GCD_MEMORY_SPACE_DESCRIPTOR)); - if (*MemorySpaceMap == NULL) { -Status = EFI_OUT_OF_RESOURCES; -goto Done; - } +// +// Release the lock before memory allocation, because it might cause +// GCD lock conflict in one of calling path in AllocatPool(). +// +CoreReleaseGcdMemoryLock (); + +// +// Allocate memory to store the MemorySpaceMap. Note it might be already +// allocated if there's map descriptor change during memory allocation at +// last time. +// +if (*MemorySpaceMap != NULL) { + FreePool (*MemorySpaceMap); +} +*MemorySpaceMap = AllocatePool (DescriptorCount * +sizeof (EFI_GCD_MEMORY_SPACE_DESCRIPTOR)); +if (*MemorySpaceMap == NULL) { + *NumberOfDescriptors = 0; + return EFI_OUT_OF_RESOURCES; +} + +// +// Save the descriptor count got before for another round of check to make +// sure we won't miss any, since we have code running outside the GCD lock. +// +*NumberOfDescriptors = DescriptorCount; +// +// Re-acquire the lock, for the next iteration. +// +CoreAcquireGcdMemoryLock (); + } // - // Fill in the MemorySpaceMap + // We exited the loop with the lock held, release it. // - Descriptor = *MemorySpaceMap; - Link = mGcdMemorySpaceMap.ForwardLink; - while (Link != &mGcdMemorySpaceMap) { -Entry = CR (Link, EFI_GCD_MAP_ENTRY, Link, EFI_GCD_MAP_SIGNATURE); -BuildMemoryDescriptor (Descriptor, Entry); -Descriptor++; -Link = Link->ForwardLink; - } - Status = EFI_SUCCESS; - -Done: CoreReleaseGcdMemoryLock (); - return Status; + + return EFI_SUCCESS; } -- 2.16.2.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH v4 4/6] UefiCpuPkg/CpuDxe: prevent recursive calling of InitializePageTablePool
> v4 changes: none The freed-memory guard feature will cause an recursive calling of InitializePageTablePool(). This is due to a fact that AllocateAlignedPages() is used to allocate page table pool memory. This function will most likely call gBS->FreePages to free unaligned pages and then cause another round of page attributes change, like below (freed pages will be always marked not-present if freed-memory guard is enabled) FreePages() <===| => CpuSetMemoryAttributes()| => | => InitializePageTablePool() | => AllocateAlignedPages() | => FreePages() | The solution is add a global variable as a lock in page table pool allocation function and fail any other requests if it has not been done. Since this issue will only happen if free-memory guard is enabled, it won't affect CpuSetMemoryAttributes() in default build of a BIOS. If free-memory guard is enabled, it only affect the pages (failed to mark them as not-present) freed in AllocateAlignedPages(). Since those freed pages haven't been used yet (their addresses not yet exposed to code outside AllocateAlignedPages), it won't compromise the freed-memory guard feature. This change will just fail the CpuSetMemoryAttributes() called from FreePages() but it won't fail the FreePages(). So the error status won't be propagated upper layer of code. Cc: Eric Dong Cc: Laszlo Ersek Cc: Star Zeng Cc: Michael D Kinney Cc: Jiewen Yao Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- UefiCpuPkg/CpuDxe/CpuPageTable.c | 23 +-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/CpuDxe/CpuPageTable.c b/UefiCpuPkg/CpuDxe/CpuPageTable.c index 33e8ee2d2c..4bee8c7772 100644 --- a/UefiCpuPkg/CpuDxe/CpuPageTable.c +++ b/UefiCpuPkg/CpuDxe/CpuPageTable.c @@ -100,6 +100,7 @@ PAGE_ATTRIBUTE_TABLE mPageAttributeTable[] = { }; PAGE_TABLE_POOL *mPageTablePool = NULL; +BOOLEAN mPageTablePoolLock = FALSE; PAGE_TABLE_LIB_PAGING_CONTEXT mPagingContext; EFI_SMM_BASE2_PROTOCOL*mSmmBase2 = NULL; @@ -1046,6 +1047,16 @@ InitializePageTablePool ( VOID *Buffer; BOOLEAN IsModified; + // + // Do not allow re-entrance. + // + if (mPageTablePoolLock) { +return FALSE; + } + + mPageTablePoolLock = TRUE; + IsModified = FALSE; + // // Always reserve at least PAGE_TABLE_POOL_UNIT_PAGES, including one page for // header. @@ -1056,9 +1067,15 @@ InitializePageTablePool ( Buffer = AllocateAlignedPages (PoolPages, PAGE_TABLE_POOL_ALIGNMENT); if (Buffer == NULL) { DEBUG ((DEBUG_ERROR, "ERROR: Out of aligned pages\r\n")); -return FALSE; +goto Done; } + DEBUG (( +DEBUG_INFO, +"Paging: added %lu pages to page table pool\r\n", +(UINT64)PoolPages +)); + // // Link all pools into a list for easier track later. // @@ -1092,7 +1109,9 @@ InitializePageTablePool ( ); ASSERT (IsModified == TRUE); - return TRUE; +Done: + mPageTablePoolLock = FALSE; + return IsModified; } /** -- 2.16.2.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH v4 6/6] MdeModulePkg/Core: add freed-memory guard feature
> v4 changes: > a. replace hard-coded memory attributes with the value got from >CoreGetMemorySpaceDescriptor() > b. remove the enclosure of CoreAcquireGcdMemoryLock() and >CoreReleaseGcdMemoryLock() around CoreAddRange() Freed-memory guard is used to detect UAF (Use-After-Free) memory issue which is illegal access to memory which has been freed. The principle behind is similar to heap guard feature, that is we'll turn all pool memory allocation to page allocation and mark them to be not-present once they are freed. This also implies that, once a page is allocated and freed, it cannot be re-allocated. This will bring another issue, which is that there's risk that memory space will be used out. To address it, the memory service add logic to put part (at most 64 pages a time) of freed pages back into page pool, so that the memory service can still have memory to allocate, when all memory space have been allocated once. This is called memory promotion. The promoted pages are always from the eldest pages which haven been freed. This feature brings another problem is that memory map descriptors will be increased enormously (200+ -> 2000+). One of change in this patch is to update MergeMemoryMap() in file PropertiesTable.c to allow merge freed pages back into the memory map. Now the number can stay at around 510. Cc: Star Zeng Cc: Michael D Kinney Cc: Jiewen Yao Cc: Ruiyu Ni Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 409 +- MdeModulePkg/Core/Dxe/Mem/HeapGuard.h | 65 +++- MdeModulePkg/Core/Dxe/Mem/Page.c | 42 ++- MdeModulePkg/Core/Dxe/Mem/Pool.c | 23 +- MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 2 +- MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c | 18 +- 6 files changed, 525 insertions(+), 34 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c index 663f969c0d..449a022658 100644 --- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c +++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c @@ -44,6 +44,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED UINTN mLevelShift[GUARDED_HEAP_MAP_TABLE_DEPTH] GLOBAL_REMOVE_IF_UNREFERENCED UINTN mLevelMask[GUARDED_HEAP_MAP_TABLE_DEPTH] = GUARDED_HEAP_MAP_TABLE_DEPTH_MASKS; +// +// Used for promoting freed but not used pages. +// +GLOBAL_REMOVE_IF_UNREFERENCED EFI_PHYSICAL_ADDRESS mLastPromotedPage = BASE_4GB; + /** Set corresponding bits in bitmap table to 1 according to the address. @@ -379,7 +384,7 @@ ClearGuardedMemoryBits ( @return An integer containing the guarded memory bitmap. **/ -UINTN +UINT64 GetGuardedMemoryBits ( IN EFI_PHYSICAL_ADDRESSAddress, IN UINTN NumberOfPages @@ -387,7 +392,7 @@ GetGuardedMemoryBits ( { UINT64*BitMap; UINTN Bits; - UINTN Result; + UINT64Result; UINTN Shift; UINTN BitsToUnitEnd; @@ -660,15 +665,16 @@ IsPageTypeToGuard ( /** Check to see if the heap guard is enabled for page and/or pool allocation. + @param[in] GuardType Specify the sub-type(s) of Heap Guard. + @return TRUE/FALSE. **/ BOOLEAN IsHeapGuardEnabled ( - VOID + UINT8 GuardType ) { - return IsMemoryTypeToGuard (EfiMaxMemoryType, AllocateAnyPages, - GUARD_HEAP_TYPE_POOL|GUARD_HEAP_TYPE_PAGE); + return IsMemoryTypeToGuard (EfiMaxMemoryType, AllocateAnyPages, GuardType); } /** @@ -1203,6 +1209,380 @@ SetAllGuardPages ( } } +/** + Find the address of top-most guarded free page. + + @param[out] AddressStart address of top-most guarded free page. + + @return VOID. +**/ +VOID +GetLastGuardedFreePageAddress ( + OUT EFI_PHYSICAL_ADDRESS *Address + ) +{ + EFI_PHYSICAL_ADDRESSAddressGranularity; + EFI_PHYSICAL_ADDRESSBaseAddress; + UINTN Level; + UINT64 Map; + INTNIndex; + + ASSERT (mMapLevel >= 1); + + BaseAddress = 0; + Map = mGuardedMemoryMap; + for (Level = GUARDED_HEAP_MAP_TABLE_DEPTH - mMapLevel; + Level < GUARDED_HEAP_MAP_TABLE_DEPTH; + ++Level) { +AddressGranularity = LShiftU64 (1, mLevelShift[Level]); + +// +// Find the non-NULL entry at largest index. +// +for (Index = (INTN)mLevelMask[Level]; Index >= 0 ; --Index) { + if (((UINT64 *)(UINTN)Map)[Index] != 0) { +BaseAddress += MultU64x32 (AddressGranularity, (UINT32)Index); +Map = ((UINT64 *)(UINTN)Map)[Index]; +break; + } +} + } + + // + // Find the non-zero MSB then get the page address. + // + while (Map != 0) { +Map = RShiftU64 (Map, 1); +BaseAddress += EFI_PAGES_TO_SIZE (1); + } + + *Address = BaseAddress; +} + +/** + Record freed pages. + + @param[in] BaseAddress Base address of just freed pages. +
[edk2] [PATCH v4 3/6] UefiCpuPkg/CpuDxe: consider freed-memory guard in non-stop mode
> v4 changes: none Non-stop mode was introduced / explained in commit 8f2613628acf ("MdeModulePkg/MdeModulePkg.dec: add new settings for PCDs", 2018-08-30). The macro HEAP_GUARD_NONSTOP_MODE was added to CpuDxe in commit dcc026217fdc ("UefiCpuPkg/CpuDxe: implement non-stop mode for uefi", 2018-08-30). Another instance of the macro HEAP_GUARD_NONSTOP_MODE was added to PiSmmCpuDxeSmm -- with BIT1|BIT0 replaced with BIT3|BIT2 -- in commit 09afd9a42a7f ("UefiCpuPkg/PiSmmCpuDxeSmm: implement non-stop mode for SMM", 2018-08-30) Since the freed-memory guard is for UEFI-only. This patch only updates HEAP_GUARD_NONSTOP_MODE in "UefiCpuPkg/CpuDxe/CpuDxe.h" (add BIT4). Cc: Eric Dong Cc: Laszlo Ersek Cc: Star Zeng Cc: Michael D Kinney Cc: Jiewen Yao Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- UefiCpuPkg/CpuDxe/CpuDxe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.h b/UefiCpuPkg/CpuDxe/CpuDxe.h index 064ea05bba..3183a3f7f4 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.h +++ b/UefiCpuPkg/CpuDxe/CpuDxe.h @@ -58,7 +58,7 @@ ) #define HEAP_GUARD_NONSTOP_MODE \ -((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT6|BIT1|BIT0)) > BIT6) +((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT6|BIT4|BIT1|BIT0)) > BIT6) #define NULL_DETECTION_NONSTOP_MODE \ ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & (BIT6|BIT0)) > BIT6) -- 2.16.2.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH v4 2/6] MdeModulePkg: introduce UEFI freed-memory guard bit in HeapGuard PCD
> v4 changes: > a. refine PCD description of PcdHeapGuardPropertyMask UAF (Use-After-Free) memory issue is kind of illegal access to memory which has been freed. It can be detected by a new freed-memory guard enforced onto freed memory. BIT4 of following PCD is used to enable the freed-memory guard feature. gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask Please note this feature is for debug purpose and should not be enabled in product BIOS, and cannot be enabled with pool/page heap guard at the same time. It's disabled by default. Cc: Star Zeng Cc: Michael D Kinney Cc: Jiewen Yao Cc: Ruiyu Ni Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- MdeModulePkg/MdeModulePkg.dec | 16 MdeModulePkg/MdeModulePkg.uni | 14 ++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 2009dbc5fd..428eeeb670 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -1011,14 +1011,22 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPoolType|0x0|UINT64|0x30001053 ## This mask is to control Heap Guard behavior. - # Note that due to the limit of pool memory implementation and the alignment - # requirement of UEFI spec, BIT7 is a try-best setting which cannot guarantee - # that the returned pool is exactly adjacent to head guard page or tail guard - # page. + # + # Note: + # a) Heap Guard is for debug purpose and should not be enabled in product + # BIOS. + # b) Due to the limit of pool memory implementation and the alignment + # requirement of UEFI spec, BIT7 is a try-best setting which cannot + # guarantee that the returned pool is exactly adjacent to head guard + # page or tail guard page. + # c) UEFI freed-memory guard and UEFI pool/page guard cannot be enabled + # at the same time. + # # BIT0 - Enable UEFI page guard. # BIT1 - Enable UEFI pool guard. # BIT2 - Enable SMM page guard. # BIT3 - Enable SMM pool guard. + # BIT4 - Enable UEFI freed-memory guard (Use-After-Free memory detection). # BIT6 - Enable non-stop mode. # BIT7 - The direction of Guard Page for Pool Guard. # 0 - The returned pool is near the tail guard page. diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni index 9d2e473fa9..5fa7a6ae30 100644 --- a/MdeModulePkg/MdeModulePkg.uni +++ b/MdeModulePkg/MdeModulePkg.uni @@ -1224,14 +1224,20 @@ #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdHeapGuardPropertyMask_PROMPT #language en-US "The Heap Guard feature mask" #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdHeapGuardPropertyMask_HELP #language en-US "This mask is to control Heap Guard behavior.\n" - "Note that due to the limit of pool memory implementation and the alignment\n" - "requirement of UEFI spec, BIT7 is a try-best setting which cannot guarantee\n" - "that the returned pool is exactly adjacent to head guard page or tail guard\n" - "page.\n" + " Note:\n" + " a) Heap Guard is for debug purpose and should not be enabled in product" + " BIOS.\n" + " b) Due to the limit of pool memory implementation and the alignment" + " requirement of UEFI spec, BIT7 is a try-best setting which cannot" + " guarantee that the returned pool is exactly adjacent to head guard" + " page or tail guard page.\n" + " c) UEFI freed-memory guard and UEFI pool/page guard cannot be enabled" + " at the same time.\n" " BIT0 - Enable UEFI page guard.\n" " BIT1
[edk2] [PATCH v4 1/6] MdeModulePkg: cleanup Heap Guard pool/page type PCD documentation
> v4 changes: none This cleanup is meant for avoiding misuse of newly introduced BIT4 (UAF detection) of PCD PcdHeapGuardPropertyMask, because it applies to all types of physical memory. In another words, PcdHeapGuardPoolType and PcdHeapGuardPageType don't have effect to the BIT4 of PcdHeapGuardPropertyMask. Cc: Star Zeng Cc: Michael D Kinney Cc: Jiewen Yao Cc: Ruiyu Ni Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jian J Wang --- MdeModulePkg/MdeModulePkg.dec | 4 MdeModulePkg/MdeModulePkg.uni | 2 ++ 2 files changed, 6 insertions(+) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 6037504fa7..2009dbc5fd 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -955,6 +955,8 @@ # free pages for all of them. The page allocation for the type related to # cleared bits keeps the same as ususal. # + # This PCD is only valid if BIT0 and/or BIT2 are set in PcdHeapGuardPropertyMask. + # # Below is bit mask for this PCD: (Order is same as UEFI spec) # EfiReservedMemoryType 0x0001 # EfiLoaderCode 0x0002 @@ -984,6 +986,8 @@ # if there's enough free memory for all of them. The pool allocation for the # type related to cleared bits keeps the same as ususal. # + # This PCD is only valid if BIT1 and/or BIT3 are set in PcdHeapGuardPropertyMask. + # # Below is bit mask for this PCD: (Order is same as UEFI spec) # EfiReservedMemoryType 0x0001 # EfiLoaderCode 0x0002 diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni index a6bcb627cf..9d2e473fa9 100644 --- a/MdeModulePkg/MdeModulePkg.uni +++ b/MdeModulePkg/MdeModulePkg.uni @@ -1171,6 +1171,7 @@ " before and after corresponding type of pages allocated if there's enough\n" " free pages for all of them. The page allocation for the type related to\n" " cleared bits keeps the same as ususal.\n\n" + " This PCD is only valid if BIT0 and/or BIT2 are set in PcdHeapGuardPropertyMask.\n\n" " Below is bit mask for this PCD: (Order is same as UEFI spec)\n" " EfiReservedMemoryType 0x0001\n" " EfiLoaderCode 0x0002\n" @@ -1198,6 +1199,7 @@ " before and after corresponding type of pages which the allocated pool occupies,\n" " if there's enough free memory for all of them. The pool allocation for the\n" " type related to cleared bits keeps the same as ususal.\n\n" + " This PCD is only valid if BIT1 and/or BIT3 are set in PcdHeapGuardPropertyMask.\n\n" " Below is bit mask for this PCD: (Order is same as UEFI spec)\n" " EfiReservedMemoryType 0x0001\n" " EfiLoaderCode 0x0002\n" -- 2.16.2.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel
[edk2] [PATCH v4 0/6] Introduce freed-memory guard feature
> v4 changes: > Updated per comments from Star. Please refer to individual patch > file for details (#2/5/6) Freed-memory guard is a new feauture used to detect UAF (Use-After-Free) memory issue. Tests: a. Feature basic unit/functionality test b. OVMF regression test Jian J Wang (6): MdeModulePkg: cleanup Heap Guard pool/page type PCD documentation MdeModulePkg: introduce UEFI freed-memory guard bit in HeapGuard PCD UefiCpuPkg/CpuDxe: consider freed-memory guard in non-stop mode UefiCpuPkg/CpuDxe: prevent recursive calling of InitializePageTablePool MdeModulePkg/Core: prevent re-acquire GCD memory lock MdeModulePkg/Core: add freed-memory guard feature MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 87 -- MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 409 +- MdeModulePkg/Core/Dxe/Mem/HeapGuard.h | 65 +++- MdeModulePkg/Core/Dxe/Mem/Page.c | 42 ++- MdeModulePkg/Core/Dxe/Mem/Pool.c | 23 +- MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 2 +- MdeModulePkg/Core/Dxe/Misc/PropertiesTable.c | 18 +- MdeModulePkg/MdeModulePkg.dec | 20 +- MdeModulePkg/MdeModulePkg.uni | 16 +- UefiCpuPkg/CpuDxe/CpuDxe.h| 2 +- UefiCpuPkg/CpuDxe/CpuPageTable.c | 23 +- 11 files changed, 637 insertions(+), 70 deletions(-) -- 2.16.2.windows.1 ___ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel