On Thu, May 20, 2021 at 01:09:19PM +0200, Philippe Mathieu-Daudé wrote: > { > VRingMemoryRegionCaches *caches = vring_get_region_caches(vq); > hwaddr pa = offsetof(VRingAvail, flags); > + MemTxAttrs attrs = { .aligned = 1 }; > + MemTxResult res; > > if (!caches) { > *val = 0; > return true; > } > > - *val = virtio_lduw_phys_cached_with_attrs(vq->vdev, &caches->avail, pa); > + *val = virtio_lduw_phys_cached_with_attrs(vq->vdev, &caches->avail, > + pa, attrs, &res); > + if (res == MEMTX_UNALIGNED_ERROR) { > + qemu_log_mask(LOG_GUEST_ERROR, > + "virtio: vring flag address 0x%" HWADDR_PRIX " " > + "is not aligned\n", pa); > + return false; > + } Performance-critical code paths could validate the cache and offset ahead of time to avoid taking the more expensive code path that checks MemTxAttrs. The guest driver configures the vring addresses by writing to virtio-pci/virtio-mmio registers. The alignment check can be performed at that time (while/before creating the cache). Stefan