AMD/IOMMU: update live PTEs atomically
authorJan Beulich <jbeulich@suse.com>
Tue, 20 Oct 2020 12:22:52 +0000 (14:22 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 20 Oct 2020 12:22:52 +0000 (14:22 +0200)
commit3b055121c5410e2c3105d6d06aa24ca0d58868cd
tree6732c3d38ad034d0868e312d317d03c1bded907a
parent73f62c7380edf07469581a3049aba98abd63b275
AMD/IOMMU: update live PTEs atomically

Updating a live PTE bitfield by bitfield risks the compiler re-ordering
the individual updates as well as splitting individual updates into
multiple memory writes. Construct the new entry fully in a local
variable, do the check to determine the flushing needs on the thus
established new entry, and then write the new entry by a single insn.

Similarly using memset() to clear a PTE is unsafe, as the order of
writes the function does is, at least in principle, undefined.

This is part of XSA-347.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Paul Durrant <paul@xen.org>
xen/drivers/passthrough/amd/iommu_map.c