[PATCH 0/2] iommu/vt-d: Ensure memory ordering in context & root entry updates

Dmytro Maluka posted 2 patches 1 month, 2 weeks ago
drivers/iommu/intel/iommu.c |  2 +-
drivers/iommu/intel/iommu.h | 37 +++++++++++++++++++++----------------
drivers/iommu/intel/pasid.c |  3 ++-
3 files changed, 24 insertions(+), 18 deletions(-)
[PATCH 0/2] iommu/vt-d: Ensure memory ordering in context & root entry updates
Posted by Dmytro Maluka 1 month, 2 weeks ago
As discussed in [1], we don't currently prevent the compiler from
reordering memory writes when updating context entries, which is
potentially dangerous, as it may cause setting the present bit (i.e.
enabling DMA translation for the given device) before finishing setting
up other bits in the context entry (and thus creating a time window when
a DMA from the device may result in an unpredicted behavior).

Fix this in the same way as how this is already addressed for PASID
entries, i.e. by using READ_ONCE/WRITE_ONCE in the helpers used for
setting individual bits in context entries, so that memory writes done
by those helpers are ordered in relation to each other (plus, prevent
load/store tearing and so on).

While at it, similarly paranoidally fix updating root entries as well:
use WRITE_ONCE to make sure that the present bit is set atomically
together with the context table address bits, not before them.

[1] https://lore.kernel.org/all/aTG7gc7I5wExai3S@google.com/

Dmytro Maluka (2):
  iommu/vt-d: Ensure memory ordering in context entry updates
  iommu/vt-d: Use WRITE_ONCE for setting root table entries

 drivers/iommu/intel/iommu.c |  2 +-
 drivers/iommu/intel/iommu.h | 37 +++++++++++++++++++++----------------
 drivers/iommu/intel/pasid.c |  3 ++-
 3 files changed, 24 insertions(+), 18 deletions(-)

-- 
2.47.3