[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f9fb5f02ffe74118934d6cf08a1cc9f0@AcuMS.aculab.com>
Date: Thu, 24 Sep 2020 13:27:33 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Borislav Petkov' <bp@...en8.de>, Dave Jiang <dave.jiang@...el.com>
CC: "vkoul@...nel.org" <vkoul@...nel.org>,
"tglx@...utronix.de" <tglx@...utronix.de>,
"mingo@...hat.com" <mingo@...hat.com>,
"dan.j.williams@...el.com" <dan.j.williams@...el.com>,
"tony.luck@...el.com" <tony.luck@...el.com>,
"jing.lin@...el.com" <jing.lin@...el.com>,
"ashok.raj@...el.com" <ashok.raj@...el.com>,
"sanjay.k.kumar@...el.com" <sanjay.k.kumar@...el.com>,
"fenghua.yu@...el.com" <fenghua.yu@...el.com>,
"kevin.tian@...el.com" <kevin.tian@...el.com>,
"dmaengine@...r.kernel.org" <dmaengine@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
Michael Matz <matz@...e.de>
Subject: RE: [PATCH v5 1/5] x86/asm: Carve out a generic movdir64b() helper
for general usage
From: Borislav Petkov
> Sent: 24 September 2020 14:08
>
> On Wed, Sep 23, 2020 at 04:10:43PM -0700, Dave Jiang wrote:
> > +/* The dst parameter must be 64-bytes aligned */
> > +static inline void movdir64b(void *dst, const void *src)
> > +{
> > + /*
> > + * Note that this isn't an "on-stack copy", just definition of "dst"
> > + * as a pointer to 64-bytes of stuff that is going to be overwritten.
> > + * In the MOVDIR64B case that may be needed as you can use the
> > + * MOVDIR64B instruction to copy arbitrary memory around. This trick
> > + * lets the compiler know how much gets clobbered.
> > + */
> > + volatile struct { char _[64]; } *__dst = dst;
> > +
> > + /* MOVDIR64B [rdx], rax */
> > + asm volatile(".byte 0x66, 0x0f, 0x38, 0xf8, 0x02"
> > + :
> > + : "m" (*(struct { char _[64];} **)src), "a" (__dst)
> > + : "memory");
> > +}
>
> Ok, Micha and I hashed it out on IRC, here's what you do. Please keep
> the comments too because we will forget soon again.
>
> static inline void movdir64b(void *__dst, const void *src)
> {
> struct { char _[64]; } *__src = src;
> struct { char _[64]; } *__dst = dst;
>
> /*
> * MOVDIR64B %(rdx), rax.
> *
> * Both __src and __dst must be memory constraints in order to tell the
> * compiler that no other memory accesses should be reordered around
> * this one.
> *
> * Also, both must be supplied as lvalues because this tells
> * the compiler what the object is (its size) the instruction accesses.
> * I.e., not the pointers but what they point, thus the deref'ing '*'.
> */
> asm volatile(".byte 0x66, 0x0f, 0x38, 0xf8, 0x02"
> : "+m" (*__dst)
> : "m" (*__src), "a" (__dst), "d" (__src));
> }
Doesn't look wrong now.
I'd still paint it a slightly different colour :-)
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists