Page MenuHomeFreeBSD

efivar: Use memcmp instead of uuid_ functions to compare
ClosedPublic

Authored by imp on Fri, Apr 25, 7:33 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, May 1, 6:25 PM
Unknown Object (File)
Tue, Apr 29, 2:01 PM
Unknown Object (File)
Sun, Apr 27, 8:33 AM
Unknown Object (File)
Sun, Apr 27, 12:08 AM
Unknown Object (File)
Sat, Apr 26, 10:57 PM
Unknown Object (File)
Sat, Apr 26, 8:33 PM
Subscribers
None

Details

Summary

In these cases, memcmp is a perfectly fine substitute for the uuid
functions. We don't need checking to make sure the uuids are good, we
know the pointers are non-ULL, etc. memcmp will reduce the number of
places we need to know these are actually UUIDs, or similar.

Sponsored by: Netflix

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

imp requested review of this revision.Fri, Apr 25, 7:33 PM
imp created this revision.

What is the actual reason behind the change? Because IMO it is not quite good: the main assumption which is not explicitly written out in the summary is that struct uuid does not have any padding.
That said, if you do not need the service of uuid_compare(), we have the bare uuid_equal() which does just memcmp().

In D50033#1141033, @kib wrote:

What is the actual reason behind the change? Because IMO it is not quite good: the main assumption which is not explicitly written out in the summary is that struct uuid does not have any padding.
That said, if you do not need the service of uuid_compare(), we have the bare uuid_equal() which does just memcmp().

The actual reason? UEFI and EDK2 define EFI_GUID. This is a structure whose textual representation is the same as UUIDs, as defined in the RFC, that are implemented with uuid_t and assorted functions. However, although sizeof(uuid_t) and sizeof(EFI_GUID) are the same, and the same text encodes to the same binary bytes, EFI_GUID has different elements than UUID so that initializers are different. To try to share more code with EDK2 and to migrate key parts of our EFI API to be the same as EDK2, I stumbled on this issue. I thought I'd make it not matter, but can add the size assertion somewhere, which would communicate that as well.

I think that I'll add a couple of additional patches to this series that takes it a step or two further so we do everything with efi_guid_t (which is our convenient spelling of EFI_GUID) and hide any uuid 'punning' to a couple of helper routines. That will help with typesafe casing requests from another review.

In D50033#1141293, @imp wrote:
In D50033#1141033, @kib wrote:

What is the actual reason behind the change? Because IMO it is not quite good: the main assumption which is not explicitly written out in the summary is that struct uuid does not have any padding.
That said, if you do not need the service of uuid_compare(), we have the bare uuid_equal() which does just memcmp().

The actual reason? UEFI and EDK2 define EFI_GUID. This is a structure whose textual representation is the same as UUIDs, as defined in the RFC, that are implemented with uuid_t and assorted functions. However, although sizeof(uuid_t) and sizeof(EFI_GUID) are the same, and the same text encodes to the same binary bytes, EFI_GUID has different elements than UUID so that initializers are different. To try to share more code with EDK2 and to migrate key parts of our EFI API to be the same as EDK2, I stumbled on this issue. I thought I'd make it not matter, but can add the size assertion somewhere, which would communicate that as well.

I think that I'll add a couple of additional patches to this series that takes it a step or two further so we do everything with efi_guid_t (which is our convenient spelling of EFI_GUID) and hide any uuid 'punning' to a couple of helper routines. That will help with typesafe casing requests from another review.

Ok. And it is all contained in libefivar and efibootmgr, right? Then it might be easier to read the final diff instead of steps.

This revision was not accepted when it landed; it landed in state Needs Review.Thu, May 1, 6:06 PM
This revision was automatically updated to reflect the committed changes.