diff options
author | John Baldwin <jhb@FreeBSD.org> | 2022-11-29 01:10:07 +0000 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2023-01-26 20:24:09 +0000 |
commit | cee36581281d4b3ce67e14dd16178d9543b5b64f (patch) | |
tree | 8e1693118314f06e2e192bab55f6f4175f9b3601 | |
parent | f995c129a52788c97fb1caa02fc0bd53c31ef3d4 (diff) | |
download | src-cee36581281d4b3ce67e14dd16178d9543b5b64f.tar.gz src-cee36581281d4b3ce67e14dd16178d9543b5b64f.zip |
bhyve: Appease warning about a potentially unaligned pointer.
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.
Reviewed by: corvink, bz, markj
Differential Revision: https://reviews.freebsd.org/D37490
(cherry picked from commit 32b21dd2719f87811b66deeeb513acf7067f8fac)
-rw-r--r-- | usr.sbin/bhyve/pci_passthru.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c index 049b49b67c60..285874f3925d 100644 --- a/usr.sbin/bhyve/pci_passthru.c +++ b/usr.sbin/bhyve/pci_passthru.c @@ -212,7 +212,7 @@ cfginitmsi(struct passthru_softc *sc) struct pcisel sel; struct pci_devinst *pi; struct msixcap msixcap; - uint32_t *msixcap_ptr; + char *msixcap_ptr; pi = sc->psc_pi; sel = sc->psc_sel; @@ -249,15 +249,15 @@ cfginitmsi(struct passthru_softc *sc) */ sc->psc_msix.capoff = ptr; caplen = 12; - msixcap_ptr = (uint32_t*) &msixcap; + msixcap_ptr = (char *)&msixcap; capptr = ptr; while (caplen > 0) { u32 = read_config(&sel, capptr, 4); - *msixcap_ptr = u32; + memcpy(msixcap_ptr, &u32, 4); pci_set_cfgdata32(pi, capptr, u32); caplen -= 4; capptr += 4; - msixcap_ptr++; + msixcap_ptr += 4; } } ptr = read_config(&sel, ptr + PCICAP_NEXTPTR, 1); |