On 2/22/24 02:49, Laszlo Ersek wrote: > (commenting once more, to explain the actual reason:) > > On 2/21/24 11:24, Gerd Hoffmann wrote: >> On Wed, Feb 21, 2024 at 03:48:25AM +0000, Ni, Ray wrote: >>>> >>>> + MaxCpusPerHob = (MAX_UINT16 - sizeof (EFI_HOB_GUID_TYPE) - sizeof >>>> (MP_HAND_OFF)) / sizeof (PROCESSOR_HAND_OFF); >>> >>> Above formula assumes the maximum HOB length could be 0xFFFF. >> >> Which is IMHO correct. > > It is not correct: > >> >>> But actually the maximum HOB length could be only 0xFFF8 because >>> PeiCore::PeiCreateHob() contains following logic: >>> >>> if (0x10000 - Length <= 0x7) { >>> return EFI_INVALID_PARAMETER; >>> } >> >> That Length is the *data* size, the HOB header is not included.
sorry, I meant to insert here: no; "Length" at this location does include everything, except the padding. The BuildGuidHob() library function takes a data length, and calculates the total HOB length, by adding 24 bytes, for the EFI_HOB_GUID_TYPE header. InternalPeiCreateHob() (also in "MdePkg/Library/PeiHobLib/HobLib.c") already takes the total HOB length, and passes it on to the CreateHob() PEI service -- which Ray quotes above. The total HOB length cannot exceed 0xFFF8 (due to the rounding up, for Itanium's sake), so the GUID HOB data length cannot exceed (0xFFF8-sizeof(EFI_HOB_GUID_TYPE)). Laszlo >> >> The "- sizeof (EFI_HOB_GUID_TYPE)" in the formula above accounts the >> space needed for HOB header and GUID. > > Yes, but the problem is not that we need the extra space for > EFI_HOB_GUID_TYPE (24 bytes) -- we need the extra space for padding / > alignment. > > This is what the PI spec says (v1.8, section "III-4.5.2 HOB Construction > Rules"): > > HOB construction must obey the following rules: > > [...] > > 4. All HOBs must be multiples of 8 bytes in length. This requirement > meets the alignment restrictions of the ItaniumĀ® processor family. > > [...] > > And if your total *desired* HOB length exceeds 0xFFF8 (i.e., it falls in > [0xFFF9..0xFFFF]), then the required upwards rounding produces 0x1_0000. > But that rounded-up value cannot be expressed in > "EFI_HOB_GENERIC_HEADER.HobLength" -- a UINT16 field. > > In short, you've got Itanium to thank for this. :) > > Laszlo -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115772): https://edk2.groups.io/g/devel/message/115772 Mute This Topic: https://groups.io/mt/104472313/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-