x86: invpcid support
PATCH 1/1 x86: invpcid support
Provide the functions needed for different modes. And cpu_has_invpcid.
---
This is useful for Juergen's XPTI improvement series.
--- xen/arch/x86/Rules.mk | 1 + xen/include/asm-x86/cpufeature.h | 1 + xen/include/asm-x86/invpcid.h | 75 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 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-insn-check,CFLAGS,CC,"invpcid (%rax)$$(comma)%rax",-DHAVE_GAS_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 +75 -0
75 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 21 lines · Wei Liu
Provide the functions needed for different modes. And
cpu_has_invpcid.Signed-off-by Wei Liu <[email protected]>---
This is useful for Juergen's XPTI improvement series.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 | 75 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 xen/include/asm-x86/invpcid.hxen/arch/x86/Rules.mk +0
-0
xen/arch/x86/Rules.mk $(call as-option-add,CFLAGS,CC,"rdseed %eax",-DHAVE_GAS_RDSEED) · line 26
Quoted 4 lines
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-insn-check,CFLAGS,CC,"invpcid (%rax)$$(comma)%rax",-DHAVE_GAS_INVPCID)
Actually, now that we have Clang 6 integrated assembler support, these defines really should be s/GAS/AS/.
Could I trouble someone to global replace across the codebase?
Quoted 26 lines
xen/arch/x86/Rules.mk +0
-0CFLAGS += -mno-red-zone -fpic -fno-asynchronous-unwind-tablesxen/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 +5
-0@@ -0,0 +1,75 @@ +#ifndef _ASM_X86_INVPCID_H_ +#define _ASM_X86_INVPCID_H_ + +#include <xen/types.h> +
xen/include/asm-x86/invpcid.h line 15
Quoted 10 lines
xen/include/asm-x86/invpcid.h new file +10
-0+#define INVPCID_TYPE_INDIV_ADDR 0 +#define INVPCID_TYPE_SINGLE_CTXT 1 +#define INVPCID_TYPE_ALL_INCL_GLOBAL 2 +#define INVPCID_TYPE_ALL_NON_GLOBAL 3 + +struct invpcid_desc { +uint64_t pcid:12 ; +uint64_t reserved:52 ; +uint64_t addr; +};
Thinking about it, this could be hidden inside invpcid. We've got no use for it outside of the wrapper.
xen/include/asm-x86/invpcid.h line 21
Quoted 6 lines
xen/include/asm-x86/invpcid.h new file +6
-0+ +#define INVPCID_OPCODE ".byte 0x66, 0x0f, 0x38, 0x82\n" +#define MODRM_ECX_01 ".byte 0x01\n" + +static inline void invpcid (unsigned long pcid,unsigned long addr, +unsigned long type)
pcid and type can drop to just unsigned int.
Otherwise, LGTM. Depending on the GAS=>AS transformation, all of these issue could be fixed on commit.
~Andrew
Quoted 44 lines
xen/include/asm-x86/invpcid.h new file +44
-0+{ + struct invpcid_desc desc = { .pcid = pcid, .addr = addr }; + + asm volatile ( +#ifdef HAVE_GAS_INVPCID + "invpcid %[desc], %[type]" +#else + INVPCID_OPCODE MODRM_ECX_01 +#endif + : +#ifdef HAVE_GAS_INVPCID + : [desc] "m" (desc), [type] "r" (type) +#else + : "a" (type), "c" (&desc) +#endif + : "memory" ); +} + +/* Flush all mappings for a given PCID and addr, not including globals */ +static inline void invpcid_flush_one(unsigned long pcid, + unsigned long addr) +{ + invpcid(pcid, addr, INVPCID_TYPE_INDIV_ADDR); +} + +/* Flush all mappings for a given PCID, not including globals */ +static inline void invpcid_flush_single_context(unsigned long pcid) +{ + invpcid(pcid, 0, INVPCID_TYPE_SINGLE_CTXT); +} + +/* Flush all mappings, including globals, for all PCIDs */ +static inline void invpcid_flush_all(void) +{ + invpcid(0, 0, INVPCID_TYPE_ALL_INCL_GLOBAL); +} + +/* Flush all mappings for all PCIDs, excluding globals */ +static inline void invpcid_flush_all_nonglobals(void) +{ + invpcid(0, 0, INVPCID_TYPE_ALL_NON_GLOBAL); +} + +#endif /* _ASM_X86_INVPCID_H_ */
xen/include/asm-x86/invpcid.h line 75
Quoted 10 lines
xen/include/asm-x86/invpcid.h new file +10
-0+ +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 30 lines · Andrew Cooper
Quoted 21 lines · Wei Liu
Provide the functions needed for different modes. And
cpu_has_invpcid.Signed-off-by Wei Liu <[email protected]>---
This is useful for Juergen's XPTI improvement series.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 | 75 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 xen/include/asm-x86/invpcid.hxen/arch/x86/Rules.mk +0
-0xen/arch/x86/Rules.mk $(call as-option-add,CFLAGS,CC,"rdseed %eax",-DHAVE_GAS_RDSEED) · line 26
Quoted 4 lines
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-insn-check,CFLAGS,CC,"invpcid (%rax)$$(comma)%rax",-DHAVE_GAS_INVPCID)Actually, now that we have Clang 6 integrated assembler support, these defines really should be s/GAS/AS/.
Quoted 1 line
Could I trouble someone to global replace across the codebase?
Sure I can do that.
Quoted 32 lines
Quoted 32 lines
xen/arch/x86/Rules.mk +0
-0CFLAGS += -mno-red-zone -fpic -fno-asynchronous-unwind-tablesxen/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 +10
-0@@ -0,0 +1,75 @@ +#ifndef _ASM_X86_INVPCID_H_ +#define _ASM_X86_INVPCID_H_ + +#include <xen/types.h> + +#define INVPCID_TYPE_INDIV_ADDR 0 +#define INVPCID_TYPE_SINGLE_CTXT 1 +#define INVPCID_TYPE_ALL_INCL_GLOBAL 2 +#define INVPCID_TYPE_ALL_NON_GLOBAL 3 +
Quoted 8 lines
xen/include/asm-x86/invpcid.h line 15
Quoted 5 lines
xen/include/asm-x86/invpcid.h new file +5
-0+struct invpcid_desc { +uint64_t pcid:12 ; +uint64_t reserved:52 ; +uint64_t addr; +};Thinking about it, this could be hidden inside invpcid. We've got no use for it outside of the wrapper.
That's right.
Quoted 10 lines
xen/include/asm-x86/invpcid.h line 21
Quoted 7 lines
xen/include/asm-x86/invpcid.h new file +6
-0+ +#define INVPCID_OPCODE ".byte 0x66, 0x0f, 0x38, 0x82\n" +#define MODRM_ECX_01 ".byte 0x01\n" + +static inline void invpcid (unsigned long pcid,unsigned long addr, +unsigned long type)pcid and type can drop to just unsigned int.
Quoted 3 lines
Otherwise, LGTM. Depending on the GAS=>AS transformation, all of these issue could be fixed on commit.
We can change GAS to AS here in this patch and I will submit a patch to s/GAS/AS/g on top of this patch.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 21 lines · Wei Liu
Provide the functions needed for different modes. And
cpu_has_invpcid.Signed-off-by Wei Liu <[email protected]>---
This is useful for Juergen's XPTI improvement series.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 | 75 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 xen/include/asm-x86/invpcid.hxen/arch/x86/Rules.mk +0
-0
xen/arch/x86/Rules.mk $(call as-option-add,CFLAGS,CC,"rdseed %eax",-DHAVE_GAS_RDSEED) · line 26
Quoted 4 lines
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-insn-check,CFLAGS,CC,"invpcid (%rax)$$(comma)%rax",-DHAVE_GAS_INVPCID)
Ah, and this also needs to be replaced with as-option-add.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 59 lines · Wei Liu
Provide the functions needed for different modes. And
cpu_has_invpcid.Signed-off-by Wei Liu <[email protected]>---
This is useful for Juergen's XPTI improvement series.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 | 75 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 xen/include/asm-x86/invpcid.hxen/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-insn-check,CFLAGS,CC,"invpcid (%rax)$$(comma)%rax",-DHAVE_GAS_INVPCID) CFLAGS += -mno-red-zone -fpic -fno-asynchronous-unwind-tablesxen/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 +13
-0@@ -0,0 +1,75 @@ +#ifndef _ASM_X86_INVPCID_H_ +#define _ASM_X86_INVPCID_H_ + +#include <xen/types.h> + +#define INVPCID_TYPE_INDIV_ADDR 0 +#define INVPCID_TYPE_SINGLE_CTXT 1 +#define INVPCID_TYPE_ALL_INCL_GLOBAL 2 +#define INVPCID_TYPE_ALL_NON_GLOBAL 3 + +struct invpcid_desc { + uint64_t pcid:12; + uint64_t reserved:52;
xen/include/asm-x86/invpcid.h line 23
Quoted 10 lines
xen/include/asm-x86/invpcid.h new file +10
-0+uint64_t addr; +}; + +#define INVPCID_OPCODE ".byte 0x66, 0x0f, 0x38, 0x82\n" +#define MODRM_ECX_01 ".byte 0x01\n" + +static inline void invpcid (unsigned long pcid,unsigned long addr, +unsigned long type) +{ +struct invpcid_desc desc = { .pcid = pcid, .addr = addr };
As Andrew already wrote: define the structure just here.
Quoted 4 lines
xen/include/asm-x86/invpcid.h new file +4
-0+ + asm volatile ( +#ifdef HAVE_GAS_INVPCID +"invpcid %[desc], %[type]"
xen/include/asm-x86/invpcid.h line 37
Quoted 10 lines
xen/include/asm-x86/invpcid.h new file +10
-0+#else +INVPCID_OPCODE MODRM_ECX_01 +#endif + : +#ifdef HAVE_GAS_INVPCID + : [desc] "m" (desc), [type] "r" (type) +#else + : "a" (type), "c" (&desc) +#endif + : "memory" );
I think this is hard to read. I'd spare one #ifdef and have rather a redundant ":".
With those remarks addressed you can add my:
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel