From: Dmytro Maluka <dmaluka@chromium.org>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: David Woodhouse <dwmw2@infradead.org>,
Lu Baolu <baolu.lu@linux.intel.com>,
iommu@lists.linux.dev, Joerg Roedel <joro@8bytes.org>,
Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
linux-kernel@vger.kernel.org,
"Vineeth Pillai (Google)" <vineeth@bitbyteword.org>,
Aashish Sharma <aashish@aashishsharma.net>,
Grzegorz Jaszczyk <jaszczyk@chromium.org>,
Chuanxiao Dong <chuanxiao.dong@intel.com>,
Kevin Tian <kevin.tian@intel.com>
Subject: Re: [PATCH v2 0/5] iommu/vt-d: Ensure memory ordering in context & root entry updates
Date: Mon, 5 Jan 2026 19:54:53 +0100 [thread overview]
Message-ID: <aVwI_SHHGPl0xndu@google.com> (raw)
In-Reply-To: <20260105181200.GH125261@ziepe.ca>
On Mon, Jan 05, 2026 at 02:12:00PM -0400, Jason Gunthorpe wrote:
> On Sat, Dec 27, 2025 at 06:57:23PM +0100, Dmytro Maluka wrote:
> > 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.
>
> The PASID entries should not be manipulated 'livel' in a haphazard way
> like this in the first place!
>
> Like AMD and ARM build the new PASID entry on the stack and then it
> should be copied to the DMA'able memory in a way that is consistent
> with the HW's atomicity granual, paying attention not to 'tear' it.
As I understand, the "consistent with the HW's atomicity granual, paying
attention not to 'tear' it" part is already fulfilled for PASID entries
(and with this series, for context entries as well):
static inline void pasid_set_bits(u64 *ptr, u64 mask, u64 bits)
{
u64 old;
old = READ_ONCE(*ptr);
WRITE_ONCE(*ptr, (old & ~mask) | bits);
}
I've been assuming it's ok to manipulate other bits in place as long as
we take care to only do that while the present bit it cleared (i.e.
while the entry is ignored by hardware)?
So IIUC the only problem with this approach is the redundancy: we do
this READ_ONCE+WRITE_ONCE for each invididual field in a PASID entry.
So while I agree it would be more more natural to build whole entries,
and the existing way looks strange and not the most efficient, I'm
wondering if it is causing any actual correctness issues (apart from
those addressed by this series).
> This manipulate-in-place is just asking for trouble, and can never
> support replace or full viommu requirements.. :\
>
> So while it is perhaps an improvement to do this work, it would be
> better to fix the root cause issue if someone has time..
>
> Jason
next prev parent reply other threads:[~2026-01-05 18:55 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aVwI_SHHGPl0xndu@google.com \
--to=dmaluka@chromium.org \
--cc=aashish@aashishsharma.net \
--cc=baolu.lu@linux.intel.com \
--cc=chuanxiao.dong@intel.com \
--cc=dwmw2@infradead.org \
--cc=iommu@lists.linux.dev \
--cc=jaszczyk@chromium.org \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=vineeth@bitbyteword.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.