Re: [tip:x86/mm] x86/mm: Add INVPCID helpers

From: Michael Matz
Date: Wed Feb 10 2016 - 08:48:12 EST


Hi,

On Wed, 10 Feb 2016, Borislav Petkov wrote:

> --- a/arch/x86/include/asm/tlbflush.h
> +++ b/arch/x86/include/asm/tlbflush.h
> @@ -23,7 +23,7 @@ static inline void __invpcid(unsigned long pcid, unsigned long addr,
> * invpcid (%rcx), %rax in long mode.
> */
> asm volatile (".byte 0x66, 0x0f, 0x38, 0x82, 0x01"
> - : : "m" (desc), "a" (type), "c" (desc) : "memory");
> + : : "m" (*desc), "a" (type), "c" (desc) : "memory");

That still doesn't do what you want. Arrays in C are funny. *desc is
exactly equivalent to desc[0], _not_ to the whole array, indeed there's no
C syntax to name an lvalue of array type in normal expressions. You need
to jump through hoops for this:

"m" (*(struct {unsigned long x[2];} *)desc)

It'd probably be easier to simply declare the descriptor as a struct,
rather than an array, then the original syntax would have been mostly
correct:

struct {u64 d[2];} desc = { pcid, addr };
asm ... "m" (desc), "c" (&desc)


Ciao,
Michael.