RE: [PATCH v2 0/5] iommu/vt-d: Ensure memory ordering in context & root entry updates
From: Tian, Kevin
Date: Tue Jan 06 2026 - 02:49:03 EST
> From: Jason Gunthorpe <jgg@xxxxxxxx>
> Sent: Tuesday, January 6, 2026 8:14 AM
>
> On Mon, Jan 05, 2026 at 09:05:36PM +0100, Dmytro Maluka wrote:
> > > and WRITE_ONCE is pointless if the HW is promising not to
> > > read it due to non-present.
> >
> > As long as we use a barrier. And IIUC vice versa, if we use WRITE_ONCE
> > for any updates, a barrier is not necessary (on x86). And WRITE_ONCE for
> > any updates (for PASID entries) is what was already done before this
> > series.
>
> That is an x86 ism and it shouldn't be needlessly leaked into drivers.
yeah WRITE_ONCE() is not by definition to guarantee the ordering between
CPU and device.
lots of READ_ONCE()/WRITE_ONCE() in existing code are meaningless,
as 1) between CPUs there is already lock protection; 2) between CPU and
device it requires dma_wmb() to guarantee the order.
> As this is not performance it should have the portable flow:
>
> WRITE_ONCE(non-present)
> dma_wmb()
> <cmd to flush caches>
>
> [..]
> <writes to the entry>
>
> dma_wmb()
> WRITE_ONCE(present)
>
> So, it seems to me like all you need here is the one line to add the
> dma_wmb() prior to setting present.
+1