iommu/vt-d: Ensure memory ordering in context & root entry updates
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v2 Latest5 patches 17 repliesIn review
- v12 patches 4 repliesSuperseded
Changes in v2 from the cover letter
- Sanitize bits to not exceed the mask (suggested by Baolu)
- Reuse pasid_set_bits() for context entries as well (rename it to entry_set_bits())
- Add extra barrier in *_set_present() (suggested by Baolu)
Patches in v2 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/5 | iommu/vt-d: Sanitize set bits in pasid_set_bits()drivers/ | +3 | 0 replies | |
| 2/5 | iommu/vt-d: Generalize pasid_set_bits()drivers/ drivers/ | +26 | 0 replies | |
| 3/5 | iommu/vt-d: Ensure memory ordering in context entry updatesdrivers/ drivers/ | +16 | 0 replies | |
| 4/5 | iommu/vt-d: Use smp_wmb() before setting context/pasid present bitdrivers/ drivers/ | +16 | 0 replies | |
| 5/5 | iommu/vt-d: Use WRITE_ONCE for setting root table entriesdrivers/ | +1 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.
Cover letter [PATCH v2 0/5] iommu/vt-d: Ensure memory ordering in context & root entry updates
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/[email protected]/
v1 -> v2:
- Sanitize bits to not exceed the mask (suggested by Baolu)
- Reuse pasid_set_bits() for context entries as well (rename it to entry_set_bits())
- Add extra barrier in *_set_present() (suggested by Baolu)
Dmytro Maluka (5):
iommu/vt-d: Sanitize set bits in pasid_set_bits() iommu/vt-d: Generalize pasid_set_bits()
iommu/vt-d: Ensure memory ordering in context entry updates iommu/vt-d: Use smp_wmb() before setting context/pasid present bit iommu/vt-d: Use WRITE_ONCE for setting root table entries
drivers/iommu/intel/iommu.c | 2 +- drivers/iommu/intel/iommu.h | 49 +++++++++++++++++++++++++------------ drivers/iommu/intel/pasid.c | 3 ++- drivers/iommu/intel/pasid.h | 46 +++++++++++++++++----------------- 4 files changed, 59 insertions(+), 41 deletions(-)
Signature · 1 line
2.47.3