x86/ept: flush cache when modifying PTEs and sharing page tables
authorRoger Pau Monné <roger.pau@citrix.com>
Tue, 7 Jul 2020 13:24:55 +0000 (15:24 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 7 Jul 2020 13:24:55 +0000 (15:24 +0200)
commite6ddf4a1bd8ab88f6fec83a57d64e9bbc8cca9b8
tree2f450a40b25cbd301b23b8ed76802fa9e3966b12
parentf2bc74c120bdb25446684c5375d1cc51d4702da4
x86/ept: flush cache when modifying PTEs and sharing page tables

Modifications made to the page tables by EPT code need to be written
to memory when the page tables are shared with the IOMMU, as Intel
IOMMUs can be non-coherent and thus require changes to be written to
memory in order to be visible to the IOMMU.

In order to achieve this make sure data is written back to memory
after writing an EPT entry when the recalc bit is not set in
atomic_write_ept_entry. If such bit is set, the entry will be
adjusted and atomic_write_ept_entry will be called a second time
without the recalc bit set. Note that when splitting a super page the
new tables resulting of the split should also be written back.

Failure to do so can allow devices behind the IOMMU access to the
stale super page, or cause coherency issues as changes made by the
processor to the page tables are not visible to the IOMMU.

This allows to remove the VT-d specific iommu_pte_flush helper, since
the cache write back is now performed by atomic_write_ept_entry, and
hence iommu_iotlb_flush can be used to flush the IOMMU TLB. The newly
used method (iommu_iotlb_flush) can result in less flushes, since it
might sometimes be called rightly with 0 flags, in which case it
becomes a no-op.

This is part of XSA-321.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
master commit: c23274fd0412381bd75068ebc9f8f8c90a4be748
master date: 2020-07-07 14:40:11 +0200
xen/arch/x86/mm/p2m-ept.c
xen/drivers/passthrough/vtd/iommu.c
xen/include/asm-x86/iommu.h