> The device drops a domain's mappings together with its last endpoint, so
> the first endpoint attaching to a domain has to replay them. The driver
> published that endpoint only after the replay (nr_endpoints++, without a
> lock), while viommu_map_pages() used the same counter, also without a
> lock, to decide whether to queue its own MAP or leave it to the replay. A
> map_pages() landing after the replay's walk had passed its range and
> before the counter was bumped was therefore queued by nobody: the mapping
> stayed in the driver's tree and never reached the device, silently, until
> the domain was detached and attached again - DMA to it faults in the
> meantime.
> 
> Publish the endpoint first, with the decision moved into
> viommu_add_mapping() under mappings_lock so that it cannot race the
> insert, and let the replay pick up the rest. A mapping that such a race
> sends while the replay walks it is on the device twice, which the spec says
> [ ... ]
> change the device ends with exactly the mappings the driver believes in,
> in every run.
> 
> Fixes: edcd69ab9a32 ("iommu: Add virtio-iommu driver")
> Signed-off-by: Anlai Lu <[email protected]>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=1


Reply via email to