x86: invpcid support
PATCH v2 1/1 x86: invpcid support
Provide the functions needed for different modes. Add cpu_has_invpcid.
---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Juergen Gross <[email protected]>
--- xen/arch/x86/Rules.mk | 1 + xen/include/asm-x86/cpufeature.h | 1 + xen/include/asm-x86/invpcid.h | 70 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 xen/include/asm-x86/invpcid.h
xen/arch/x86/Rules.mk +1 -0
@@ -23,6 +23,7 @@ $(call as-option-add,CFLAGS,CC,"rdseed %eax",-DHAVE_GAS_RDSEED) $(call as-option-add,CFLAGS,CC,".equ \"x\"$$(comma)1", \ -U__OBJECT_LABEL__ -DHAVE_GAS_QUOTED_SYM \ '-D__OBJECT_LABEL__=$(subst $(BASEDIR)/,,$(CURDIR))/$$@') +$(call as-option-add,CFLAGS,CC,"invpcid (%rax)$$(comma)%rax",-DHAVE_AS_INVPCID) CFLAGS += -mno-red-zone -fpic -fno-asynchronous-unwind-tables
xen/include/asm-x86/cpufeature.h +1 -0
@@ -93,6 +93,7 @@#define cpu_has_avx2 boot_cpu_has(X86_FEATURE_AVX2)#define cpu_has_smep boot_cpu_has(X86_FEATURE_SMEP)#define cpu_has_bmi2 boot_cpu_has(X86_FEATURE_BMI2) +#define cpu_has_invpcid boot_cpu_has(X86_FEATURE_INVPCID)#define cpu_has_rtm boot_cpu_has(X86_FEATURE_RTM)#define cpu_has_fpu_sel (!boot_cpu_has(X86_FEATURE_NO_FPU_SEL))#define cpu_has_mpx boot_cpu_has(X86_FEATURE_MPX)
xen/include/asm-x86/invpcid.h new file +70 -0
70 lines not on this page · raw message
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 4 lines · Wei Liu
Provide the functions needed for different modes. Add
cpu_has_invpcid.Signed-off-by Wei Liu <[email protected]>Reviewed-by Juergen Gross <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 02.03.18 at 17:23, <[email protected]> wrote:
xen/include/asm-x86/invpcid.h new file +10
-0+static inline void invpcid (unsigned int pcid,unsigned long addr, +unsigned int type) +{ +struct { +uint64_t pcid:12 ; +uint64_t reserved:52 ; +uint64_t addr; + } desc = { .pcid = pcid, .addr = addr }; + + asm volatile (
xen/include/asm-x86/invpcid.h line 33
Quoted 10 lines
xen/include/asm-x86/invpcid.h new file +10
-0+#ifdef HAVE_AS_INVPCID +"invpcid %[desc], %q[type]" + : /* No output */ + : [desc] "m" (desc), [type] "r" (type) +#else + INVPCID_OPCODE MODRM_ECX_01 + : /* No output */ + : "a" (type), "c" (&desc) +#endif + : "memory" );
I can see why you need the memory clobber in the #else case (albeit even there it could be avoided by also properly specifying the input), but what is this good for in the #if case?
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 02.03.18 at 17:23, <[email protected]> wrote:
xen/include/asm-x86/invpcid.h new file +15
-0+static inline void invpcid (unsigned int pcid,unsigned long addr, +unsigned int type) +{ +struct { +uint64_t pcid:12 ; +uint64_t reserved:52 ; +uint64_t addr; + } desc = { .pcid = pcid, .addr = addr }; + + asm volatile ( +#ifdef HAVE_AS_INVPCID + "invpcid %[desc], %q[type]" + : /* No output */ + : [desc] "m" (desc), [type] "r" (type) +#else
Quoted 8 lines
xen/include/asm-x86/invpcid.h line 33
Quoted 5 lines
xen/include/asm-x86/invpcid.h new file +5
-0+ INVPCID_OPCODE MODRM_ECX_01 + : /* No output */ + : "a" (type), "c" (&desc) +#endif + : "memory" );I can see why you need the memory clobber in the #else case (albeit even there it could be avoided by also properly specifying the input), but what is this good for in the #if case?
This is a tlb flush operation. I don't think anything good will come from having other operations reordered around it.
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 02.03.18 at 18:01, <[email protected]> wrote:
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 02.03.18 at 17:23, <[email protected]> wrote:
xen/include/asm-x86/invpcid.h new file +15
-0+static inline void invpcid (unsigned int pcid,unsigned long addr, +unsigned int type) +{ +struct { +uint64_t pcid:12 ; +uint64_t reserved:52 ; +uint64_t addr; + } desc = { .pcid = pcid, .addr = addr }; + + asm volatile ( +#ifdef HAVE_AS_INVPCID + "invpcid %[desc], %q[type]" + : /* No output */ + : [desc] "m" (desc), [type] "r" (type) +#elseQuoted 8 lines
xen/include/asm-x86/invpcid.h line 33
Quoted 5 lines
xen/include/asm-x86/invpcid.h new file +5
-0+ INVPCID_OPCODE MODRM_ECX_01 + : /* No output */ + : "a" (type), "c" (&desc) +#endif + : "memory" );I can see why you need the memory clobber in the #else case (albeit even there it could be avoided by also properly specifying the input), but what is this good for in the #if case?
Quoted 2 lines
This is a tlb flush operation. I don't think anything good will come from having other operations reordered around it.
Well, the question is whose TLB it is that is being flushed. If we invalidate Xen mappings this way, then yes. But there may be cases down the road where the construct is used to only flush guest mappings, in which case the barrier seems pointless. But anyway - not a big deal for now. It's just that I recall that we had (or perhaps still have) quite a few too many such barriers.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 02.03.18 at 17:23, <[email protected]> wrote:
xen/include/asm-x86/invpcid.h new file +16
-0+static inline void invpcid (unsigned int pcid,unsigned long addr, +unsigned int type) +{ +struct { +uint64_t pcid:12 ; +uint64_t reserved:52 ; +uint64_t addr; + } desc = { .pcid = pcid, .addr = addr }; + + asm volatile ( +#ifdef HAVE_AS_INVPCID + "invpcid %[desc], %q[type]" + : /* No output */ + : [desc] "m" (desc), [type] "r" (type) +#else + INVPCID_OPCODE MODRM_ECX_01
Quoted 8 lines
xen/include/asm-x86/invpcid.h line 33
Quoted 4 lines
xen/include/asm-x86/invpcid.h new file +4
-0+ : /* No output */ + : "a" (type), "c" (&desc) +#endif + : "memory" );I can see why you need the memory clobber in the #else case (albeit even there it could be avoided by also properly specifying the input), but what is this good for in the #if case?
It is the same as why writing to CR3 requires a memory clobber. It is flushing TLB.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel