Re: [PATCH v10 05/10] iommu/amd: Introduce helper function to update 256-bit DTE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Uros.





[Index of Archives]     [Linux Kernel]     [Kernel Newbies]     [x86 Platform Driver]     [Netdev]     [Linux Wireless]     [Netfilter]     [Bugtraq]     [Linux Filesystems]     [Yosemite Discussion]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]

  Powered by Linux