[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAFULd4aGDM5ySO-PeOH0+_U89mnqYqQ7v+U0ZsMode3bxs_X7w@mail.gmail.com>
Date: Wed, 13 Nov 2024 15:14:09 +0100
From: Uros Bizjak <ubizjak@...il.com>
To: Jason Gunthorpe <jgg@...dia.com>
Cc: Arnd Bergmann <arnd@...db.de>, Suravee Suthikulpanit <suravee.suthikulpanit@....com>,
linux-kernel@...r.kernel.org, iommu@...ts.linux.dev,
Joerg Roedel <joro@...tes.org>, Robin Murphy <robin.murphy@....com>, vasant.hegde@....com,
Linux-Arch <linux-arch@...r.kernel.org>, Kevin Tian <kevin.tian@...el.com>, jon.grimm@....com,
santosh.shukla@....com, pandoh@...gle.com, kumaranand@...gle.com
Subject: Re: [PATCH v10 05/10] iommu/amd: Introduce helper function to update
256-bit DTE
On Wed, Nov 13, 2024 at 3:09 PM Jason Gunthorpe <jgg@...dia.com> 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@...dia.com> 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.
Powered by blists - more mailing lists