All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] iommu/vt-d: Ensure memory ordering in context & root entry updates
@ 2025-12-27 17:57 Dmytro Maluka
  2025-12-27 17:57 ` [PATCH v2 1/5] iommu/vt-d: Sanitize set bits in pasid_set_bits() Dmytro Maluka
                   ` (5 more replies)
  0 siblings, 6 replies; 23+ messages in thread
From: Dmytro Maluka @ 2025-12-27 17:57 UTC (permalink / raw)
  To: David Woodhouse, Lu Baolu, iommu
  Cc: Joerg Roedel, Will Deacon, Robin Murphy, linux-kernel,
	Vineeth Pillai (Google), Aashish Sharma, Grzegorz Jaszczyk,
	Chuanxiao Dong, Kevin Tian, Dmytro Maluka

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/

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(-)

-- 
2.47.3


^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2026-01-09  6:32 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-27 17:57 [PATCH v2 0/5] iommu/vt-d: Ensure memory ordering in context & root entry updates Dmytro Maluka
2025-12-27 17:57 ` [PATCH v2 1/5] iommu/vt-d: Sanitize set bits in pasid_set_bits() Dmytro Maluka
2025-12-27 17:57 ` [PATCH v2 2/5] iommu/vt-d: Generalize pasid_set_bits() Dmytro Maluka
2025-12-27 17:57 ` [PATCH v2 3/5] iommu/vt-d: Ensure memory ordering in context entry updates Dmytro Maluka
2025-12-27 17:57 ` [PATCH v2 4/5] iommu/vt-d: Use smp_wmb() before setting context/pasid present bit Dmytro Maluka
2025-12-27 17:57 ` [PATCH v2 5/5] iommu/vt-d: Use WRITE_ONCE for setting root table entries Dmytro Maluka
2026-01-05 18:12 ` [PATCH v2 0/5] iommu/vt-d: Ensure memory ordering in context & root entry updates Jason Gunthorpe
2026-01-05 18:54   ` Dmytro Maluka
2026-01-05 19:14     ` Jason Gunthorpe
2026-01-05 20:05       ` Dmytro Maluka
2026-01-06  0:14         ` Jason Gunthorpe
2026-01-06  7:48           ` Tian, Kevin
2026-01-06 14:40             ` Dmytro Maluka
2026-01-08  2:22               ` Tian, Kevin
2026-01-06 13:51           ` Dmytro Maluka
2026-01-06 14:23             ` Jason Gunthorpe
2026-01-06 15:50               ` Dmytro Maluka
2026-01-06 16:45                 ` Jason Gunthorpe
2026-01-06 17:14                   ` Dmytro Maluka
2026-01-08  2:09                 ` Tian, Kevin
2026-01-09  6:32                   ` Baolu Lu
     [not found]                 ` <BN9PR11MB5276FB0F465DBFB4EE4D742B8C85A@BN9PR11MB5276.namprd11.prod.outlook.com>
2026-01-08  7:00                   ` Tian, Kevin
2026-01-06  3:37   ` Baolu Lu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.