Re: [PATCH v10 05/10] iommu/amd: Introduce helper function to update 256-bit DTE
From: Uros Bizjak
Date: Wed Nov 13 2024 - 09:14:36 EST
On Wed, Nov 13, 2024 at 3:09 PM Jason Gunthorpe <jgg@xxxxxxxxxx> wrote:
>
> On Wed, Nov 13, 2024 at 03:06:05PM +0100, Uros Bizjak wrote:
> > On Wed, Nov 13, 2024 at 2:20 PM Jason Gunthorpe <jgg@xxxxxxxxxx> wrote:
> > >
> > > On Wed, Nov 13, 2024 at 01:50:14PM +0100, Arnd Bergmann wrote:
> > > > On Wed, Nov 13, 2024, at 13:03, Suravee Suthikulpanit wrote:
> > > > >
> > > > > +static void write_dte_upper128(struct dev_table_entry *ptr, struct
> > > > > dev_table_entry *new)
> > > > > +{
> > > > > + struct dev_table_entry old = {};
> > > > > +
> > > > > + old.data128[1] = __READ_ONCE(ptr->data128[1]);
> > > >
> > > > The __READ_ONCE() in place of READ_ONCE() does make this a
> > > > lot simpler. After seeing how it is used though, I wonder if
> > > > this should just be an open-coded volatile pointer access
> > > > to avoid complicating __unqual_scalar_typeof() further.
> > >
> > > I've been skeptical we even need the READ_ONCE. This is all under a
> > > lock, what is READ_ONCE even protecting against? It is safe to double
> > > read.
> >
> > Even without atomicity guarantee, __READ_ONCE() still prevents the
> > compiler from performing unwanted optimizations (please see the first
> > comment in include/asm-generic/rwonce.h) and unwanted reordering of
> > reads and writes when this function is inlined. This macro does cast
> > the read to volatile, but IMO it is much more readable to use
> > __READ_ONCE() than volatile qualifier.
>
> Yes it does, but please explain to me what "unwanted reordering" is
> allowed here?
It is a static function that will be inlined by the compiler
somewhere, so "unwanted reordering" depends on where it will be
inlined. *IF* it will be called from safe code, then this limitation
for the compiler can be lifted.
Uros.