On Sun, Jun 14, 2026 at 09:45:51AM -0700, Richard Henderson wrote:
> On 6/14/26 08:13, Michael S. Tsirkin wrote:
> > Yes, I think it does work because we use -fno-strict-aliasing.
> > For bigger sizes we'll need packed because the addresses
> > could be unaligned.
> ...
> > For most host/guest pairs things simply work even for unaligned.
> >
> > And yes, guest drivers do do this.
> >
> > On classical pci, there are no transactions as such and
> > an unaligned access will be split anyway.
>
> I'm saying, if you're talking about pass-through to real devices, that won't
> work. For instance, AArch64 will trap unaligned accesses to Device memory.
Presumably, AArch64 drivers don't do unaligned at all then?
> You need to actually handle unaligned. Perhaps something like
>
> /* Find unit to fit size and alignment of dst */
> uintptr_t test = (uintptr_t)dst | size;
> uintptr_t lsb = test & -test;
>
> switch (lsb) {
> case 1: // loop over uint8_t
> case 2: // loop over uint16_t
> case 4: // loop over uint32_t
> default: // loop over uint64_t
> }
>
> with the expectation that normally we'll have aligned addresses and size
> such that the loop will iterate once.
>
>
> r~
And ifdef for arches without unaligned support?
--
MST