Page MenuHomeFreeBSD

bhyve: Appease warning about a potentially unaligned pointer.
ClosedPublic

Authored by jhb on Nov 23 2022, 11:16 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Sep 3, 2:00 AM
Unknown Object (File)
Wed, Aug 26, 6:33 AM
Unknown Object (File)
Sat, Aug 22, 5:31 PM
Unknown Object (File)
Sat, Aug 22, 5:30 PM
Unknown Object (File)
Sat, Aug 15, 6:56 AM
Unknown Object (File)
Aug 8 2026, 7:20 PM
Unknown Object (File)
Aug 8 2026, 5:38 PM
Unknown Object (File)
Aug 8 2026, 11:50 AM
Subscribers

Details

Summary

When initializing the device model for a PCI pass through device that
uses MSI-X, bhyve reads the MSI-X capability from the real device to
save a copy in the emulated PCI config space. It also saves a copy in
a local struct msixcap on the stack. Since struct msixcap is packed,
GCC complains that casting a pointer to the struct to a uint32_t
pointer may result in an unaligned pointer.

This path is not performance critical, so to appease the compiler,
simply change the pointer to a char * and use memcpy to copy the 4
bytes read in each iteration of the loop.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 48481
Build 45367: arc lint + arc unit

Event Timeline

jhb requested review of this revision.Nov 23 2022, 11:16 PM

I realize the person from illumos might have had a different fix for this, but I think this might be the cleanest of the options. I tried adding an __Alignas(4) on the local variable and that didn't appease GCC's warning here.

This revision is now accepted and ready to land.Nov 24 2022, 6:38 AM