x86: major paravirt cleanup
Subsystems (16)
Juergen Gross
maintainerv7 cover x86: major paravirt cleanup
This is a major cleanup of the paravirt infrastructure aiming at eliminating all custom code patching via paravirt patching.
This is achieved by using ALTERNATIVE instead, leading to the ability to give objtool access to the patched in instructions.
In order to remove most of the 32-bit special handling from pvops the time related operations are switched to use static_call() instead.
At the end of this series all paravirt patching has to do is to replace indirect calls with direct ones. In a further step this could be switched to static_call(), too.
Changes in V7:
- dropped patch 3, as already applied on tip tree
- new patch 3 (patches 1 and 7 have been added to V6 late)
- addressed comments by Boris
Changes in V6:
- switched back to "not" bit in feature value for "not feature"
- other minor comments addressed
Changes in V5:
- patches 1-5 of V4 dropped, as already applied
- new patches 1+3
- fixed patch 2
- split V4 patch 8 into patches 4+5
- use flag byte instead of negative feature bit for "not feature"
Changes in V4:
- fixed several build failures
- removed objtool patch, as objtool patches are in tip now
- added patch 1 for making usage of static_call easier
- even more cleanup
Changes in V3:
- added patches 7 and 12
- addressed all comments
Changes in V2:
- added patches 5-12
Juergen Gross (14):
x86/alternative: merge include files
static_call: move struct static_call_key definition to
static_call_types.h
static_call: add function to query current function x86/paravirt: switch time pvops functions to use static_call() x86/alternative: support not-feature x86/alternative: support ALTERNATIVE_TERNARY x86/alternative: don't open code ALTERNATIVE_TERNARY() in
_static_cpu_has()
x86: add new features for paravirt patching x86/paravirt: remove no longer needed 32-bit pvops cruft x86/paravirt: simplify paravirt macros
x86/paravirt: switch iret pvops to ALTERNATIVE x86/paravirt: add new macros PVOP_ALT* supporting pvops in
ALTERNATIVEs
x86/paravirt: switch functions with custom code to ALTERNATIVE x86/paravirt: have only one paravirt patch function
arch/arm/include/asm/paravirt.h | 14 +- arch/arm/kernel/paravirt.c | 9 +- arch/arm64/include/asm/paravirt.h | 14 +- arch/arm64/kernel/paravirt.c | 13 +- arch/x86/Kconfig | 1 + arch/x86/entry/entry_32.S | 6 +- arch/x86/entry/entry_64.S | 2 +- arch/x86/entry/vdso/vdso32/system_call.S | 2 +- arch/x86/include/asm/alternative-asm.h | 114 ------------ arch/x86/include/asm/alternative.h | 126 +++++++++++++- arch/x86/include/asm/cpufeature.h | 41 +---- arch/x86/include/asm/cpufeatures.h | 2 + arch/x86/include/asm/irqflags.h | 7 +- arch/x86/include/asm/mshyperv.h | 2 +- arch/x86/include/asm/nospec-branch.h | 1 - arch/x86/include/asm/paravirt.h | 167 ++++++++---------- arch/x86/include/asm/paravirt_types.h | 210 +++++++++-------------- arch/x86/include/asm/smap.h | 5 +- arch/x86/kernel/Makefile | 3 +- arch/x86/kernel/alternative.c | 52 +++++- arch/x86/kernel/asm-offsets.c | 7 - arch/x86/kernel/cpu/vmware.c | 5 +- arch/x86/kernel/kvm.c | 2 +- arch/x86/kernel/kvmclock.c | 2 +- arch/x86/kernel/paravirt-spinlocks.c | 9 + arch/x86/kernel/paravirt.c | 75 ++------ arch/x86/kernel/paravirt_patch.c | 99 ----------- arch/x86/kernel/tsc.c | 3 +- arch/x86/lib/atomic64_386_32.S | 2 +- arch/x86/lib/atomic64_cx8_32.S | 2 +- arch/x86/lib/copy_page_64.S | 2 +- arch/x86/lib/copy_user_64.S | 2 +- arch/x86/lib/memcpy_64.S | 2 +- arch/x86/lib/memmove_64.S | 2 +- arch/x86/lib/memset_64.S | 2 +- arch/x86/lib/retpoline.S | 2 +- arch/x86/xen/enlighten_pv.c | 4 +- arch/x86/xen/time.c | 26 +-- drivers/xen/time.c | 3 +- include/linux/static_call.h | 26 +-- include/linux/static_call_types.h | 18 ++ tools/include/linux/static_call_types.h | 18 ++ 42 files changed, 473 insertions(+), 631 deletions(-) delete mode 100644 arch/x86/include/asm/alternative-asm.h delete mode 100644 arch/x86/kernel/paravirt_patch.c
Signature · 6 lines
2.26.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Juergen Gross
maintainerPATCH v7 1/14 x86/alternative: merge include files
Merge arch/x86/include/asm/alternative-asm.h into arch/x86/include/asm/alternative.h in order to make it easier to use common definitions later.
---
V6:
- new patch
V7:
- moved to begin of series (Boris Petkov)
--- arch/x86/entry/entry_32.S | 2 +- arch/x86/entry/vdso/vdso32/system_call.S | 2 +- arch/x86/include/asm/alternative-asm.h | 114 ----------------------- arch/x86/include/asm/alternative.h | 112 +++++++++++++++++++++- arch/x86/include/asm/nospec-branch.h | 1 - arch/x86/include/asm/smap.h | 5 +- arch/x86/lib/atomic64_386_32.S | 2 +- arch/x86/lib/atomic64_cx8_32.S | 2 +- arch/x86/lib/copy_page_64.S | 2 +- arch/x86/lib/copy_user_64.S | 2 +- arch/x86/lib/memcpy_64.S | 2 +- arch/x86/lib/memmove_64.S | 2 +- arch/x86/lib/memset_64.S | 2 +- arch/x86/lib/retpoline.S | 2 +- 14 files changed, 120 insertions(+), 132 deletions(-) delete mode 100644 arch/x86/include/asm/alternative-asm.h
arch/x86/entry/entry_32.S +1 -1
@@ -40,7 +40,7 @@ #include <asm/processor-flags.h> #include <asm/irq_vectors.h> #include <asm/cpufeatures.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> #include <asm/asm.h> #include <asm/smap.h> #include <asm/frame.h>
arch/x86/entry/vdso/vdso32/system_call.S +1 -1
@@ -6,7 +6,7 @@ #include <linux/linkage.h> #include <asm/dwarf2.h> #include <asm/cpufeatures.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> .text .globl __kernel_vsyscall
arch/x86/include/asm/alternative-asm.h deleted +0 -114
114 lines not on this page · raw message
arch/x86/include/asm/alternative.h +109 -3
128 lines not on this page · raw message
arch/x86/include/asm/nospec-branch.h +0 -1
@@ -7,7 +7,6 @@#include <linux/objtool.h> #include <asm/alternative.h> -#include <asm/alternative-asm.h> #include <asm/cpufeatures.h> #include <asm/msr-index.h> #include <asm/unwind_hints.h>
arch/x86/include/asm/smap.h +1 -4
@@ -11,6 +11,7 @@#include <asm/nops.h> #include <asm/cpufeatures.h> +#include <asm/alternative.h> /* "Raw" instruction opcodes */ #define __ASM_CLAC ".byte 0x0f,0x01,0xca"
@@ -18,8 +19,6 @@#ifdef __ASSEMBLY__ -#include <asm/alternative-asm.h> -#ifdef CONFIG_X86_SMAP #define ASM_CLAC \
@@ -37,8 +36,6 @@#else /* __ASSEMBLY__ */ -#include <asm/alternative.h> -#ifdef CONFIG_X86_SMAP static __always_inline void clac(void)
arch/x86/lib/atomic64_386_32.S +1 -1
@@ -6,7 +6,7 @@ */ #include <linux/linkage.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> /* if you want SMP support, implement these with real spinlocks */ .macro LOCK reg
arch/x86/lib/atomic64_cx8_32.S +1 -1
@@ -6,7 +6,7 @@ */ #include <linux/linkage.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> .macro read64 reg movl %ebx, %eax
arch/x86/lib/copy_page_64.S +1 -1
@@ -3,7 +3,7 @@ #include <linux/linkage.h> #include <asm/cpufeatures.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> #include <asm/export.h> /*
arch/x86/lib/copy_user_64.S +1 -1
@@ -11,7 +11,7 @@ #include <asm/asm-offsets.h> #include <asm/thread_info.h> #include <asm/cpufeatures.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> #include <asm/asm.h> #include <asm/smap.h> #include <asm/export.h>
arch/x86/lib/memcpy_64.S +1 -1
@@ -4,7 +4,7 @@ #include <linux/linkage.h> #include <asm/errno.h> #include <asm/cpufeatures.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> #include <asm/export.h> .pushsection .noinstr.text, "ax"
arch/x86/lib/memmove_64.S +1 -1
@@ -8,7 +8,7 @@ */ #include <linux/linkage.h> #include <asm/cpufeatures.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> #include <asm/export.h> #undef memmove
arch/x86/lib/memset_64.S +1 -1
@@ -3,7 +3,7 @@ #include <linux/linkage.h> #include <asm/cpufeatures.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> #include <asm/export.h> /*
arch/x86/lib/retpoline.S +1 -1
@@ -4,7 +4,7 @@ #include <linux/linkage.h> #include <asm/dwarf2.h> #include <asm/cpufeatures.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> #include <asm/export.h> #include <asm/nospec-branch.h> #include <asm/unwind_hints.h>
Signature · 1 line
2.26.2
[tip: x86/alternatives] x86/alternative: Merge include files
The following commit has been merged into the x86/alternatives branch of tip:
The following commit has been merged into the x86/alternatives branch of tip:
Commit-ID: 5e21a3ecad1500e35b46701e7f3f232e15d78e69 Gitweb: https://git.kernel.org/tip/5e21a3ecad1500e35b46701e7f3f232e15d78e69 Author: Juergen Gross <[email protected]> AuthorDate: Thu, 11 Mar 2021 15:23:06 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 11 Mar 2021 15:58:02 +01:00
x86/alternative: Merge include files
Merge arch/x86/include/asm/alternative-asm.h into arch/x86/include/asm/alternative.h in order to make it easier to use common definitions later.
--- arch/x86/entry/entry_32.S | 2 +- arch/x86/entry/vdso/vdso32/system_call.S | 2 +- arch/x86/include/asm/alternative-asm.h | 114 +---------------------- arch/x86/include/asm/alternative.h | 112 +++++++++++++++++++++- arch/x86/include/asm/nospec-branch.h | 1 +- arch/x86/include/asm/smap.h | 5 +- arch/x86/lib/atomic64_386_32.S | 2 +- arch/x86/lib/atomic64_cx8_32.S | 2 +- arch/x86/lib/copy_page_64.S | 2 +- arch/x86/lib/copy_user_64.S | 2 +- arch/x86/lib/memcpy_64.S | 2 +- arch/x86/lib/memmove_64.S | 2 +- arch/x86/lib/memset_64.S | 2 +- arch/x86/lib/retpoline.S | 2 +- 14 files changed, 120 insertions(+), 132 deletions(-) delete mode 100644 arch/x86/include/asm/alternative-asm.h
arch/x86/entry/entry_32.S +1 -1
@@ -40,7 +40,7 @@ #include <asm/processor-flags.h> #include <asm/irq_vectors.h> #include <asm/cpufeatures.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> #include <asm/asm.h> #include <asm/smap.h> #include <asm/frame.h>
arch/x86/entry/vdso/vdso32/system_call.S +1 -1
@@ -6,7 +6,7 @@ #include <linux/linkage.h> #include <asm/dwarf2.h> #include <asm/cpufeatures.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> .text .globl __kernel_vsyscall
arch/x86/include/asm/alternative-asm.h deleted +0 -114
114 lines not on this page · raw message
arch/x86/include/asm/alternative.h +109 -3
128 lines not on this page · raw message
arch/x86/include/asm/nospec-branch.h +0 -1
@@ -7,7 +7,6 @@#include <linux/objtool.h> #include <asm/alternative.h> -#include <asm/alternative-asm.h> #include <asm/cpufeatures.h> #include <asm/msr-index.h> #include <asm/unwind_hints.h>
arch/x86/include/asm/smap.h +1 -4
@@ -11,6 +11,7 @@#include <asm/nops.h> #include <asm/cpufeatures.h> +#include <asm/alternative.h> /* "Raw" instruction opcodes */ #define __ASM_CLAC ".byte 0x0f,0x01,0xca"
@@ -18,8 +19,6 @@#ifdef __ASSEMBLY__ -#include <asm/alternative-asm.h> -#ifdef CONFIG_X86_SMAP #define ASM_CLAC \
@@ -37,8 +36,6 @@#else /* __ASSEMBLY__ */ -#include <asm/alternative.h> -#ifdef CONFIG_X86_SMAP static __always_inline void clac(void)
arch/x86/lib/atomic64_386_32.S +1 -1
@@ -6,7 +6,7 @@ */ #include <linux/linkage.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> /* if you want SMP support, implement these with real spinlocks */ .macro LOCK reg
arch/x86/lib/atomic64_cx8_32.S +1 -1
@@ -6,7 +6,7 @@ */ #include <linux/linkage.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> .macro read64 reg movl %ebx, %eax
arch/x86/lib/copy_page_64.S +1 -1
@@ -3,7 +3,7 @@ #include <linux/linkage.h> #include <asm/cpufeatures.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> #include <asm/export.h> /*
arch/x86/lib/copy_user_64.S +1 -1
@@ -11,7 +11,7 @@ #include <asm/asm-offsets.h> #include <asm/thread_info.h> #include <asm/cpufeatures.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> #include <asm/asm.h> #include <asm/smap.h> #include <asm/export.h>
arch/x86/lib/memcpy_64.S +1 -1
@@ -4,7 +4,7 @@ #include <linux/linkage.h> #include <asm/errno.h> #include <asm/cpufeatures.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> #include <asm/export.h> .pushsection .noinstr.text, "ax"
arch/x86/lib/memmove_64.S +1 -1
@@ -8,7 +8,7 @@ */ #include <linux/linkage.h> #include <asm/cpufeatures.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> #include <asm/export.h> #undef memmove
arch/x86/lib/memset_64.S +1 -1
@@ -3,7 +3,7 @@ #include <linux/linkage.h> #include <asm/cpufeatures.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> #include <asm/export.h> /*
arch/x86/lib/retpoline.S +1 -1
@@ -4,7 +4,7 @@ #include <linux/linkage.h> #include <asm/dwarf2.h> #include <asm/cpufeatures.h> -#include <asm/alternative-asm.h> +#include <asm/alternative.h> #include <asm/export.h> #include <asm/nospec-branch.h> #include <asm/unwind_hints.h>
Juergen Gross
maintainerPATCH v7 2/14 static_call: move struct static_call_key definition to static_call_types.h
In reply to Juergen GrossHaving the definition of static_call() in static_call_types.h makes no sense as long struct static_call_key isn't defined there, as the generic implementation of static_call() is referencing this structure.
So move the definition of struct static_call_key to static_call_types.h.
---
V5:
- new patch
--- include/linux/static_call.h | 18 ------------------ include/linux/static_call_types.h | 18 ++++++++++++++++++ tools/include/linux/static_call_types.h | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 18 deletions(-)
include/linux/static_call.h +0 -18
@@ -128,16 +128,6 @@ struct static_call_mod {struct static_call_site *sites; }; -struct static_call_key { -void *func; -union { -/* bit 0: 0 = mods, 1 = sites */ -unsigned long type; -struct static_call_mod *mods; -struct static_call_site *sites; - }; -}; -/* For finding the key associated with a trampoline */ struct static_call_tramp_key {s32 tramp;
@@ -187,10 +177,6 @@ extern long __static_call_return0(void);static inline int static_call_init (void ) {return 0 ; } -struct static_call_key { -void *func; -}; -#define __DEFINE_STATIC_CALL (name, _func, _func_init) \ DECLARE_STATIC_CALL(name, _func); \ struct static_call_key STATIC_CALL_KEY(name) = { \
@@ -243,10 +229,6 @@ static inline long __static_call_return0(void)static inline int static_call_init (void ) {return 0 ; } -struct static_call_key { -void *func; -}; -static inline long __static_call_return0 (void ) {return 0 ;
include/linux/static_call_types.h +18 -0
@@ -58,11 +58,25 @@ struct static_call_site {__raw_static_call (name); \ }) +struct static_call_key { +void *func; +union { +/* bit 0: 0 = mods, 1 = sites */ +unsigned long type; +struct static_call_mod *mods; +struct static_call_site *sites; + }; +}; +#else /* !CONFIG_HAVE_STATIC_CALL_INLINE */ #define __STATIC_CALL_ADDRESSABLE (name)#define __static_call (name) __raw_static_call(name) +struct static_call_key { +void *func; +}; +#endif /* CONFIG_HAVE_STATIC_CALL_INLINE */ #ifdef MODULE
@@ -77,6 +91,10 @@ struct static_call_site {#else +struct static_call_key { +void *func; +}; +#define static_call (name) \ ((typeof(STATIC_CALL_TRAMP(name))*)(STATIC_CALL_KEY(name).func))
tools/include/linux/static_call_types.h +18 -0
@@ -58,11 +58,25 @@ struct static_call_site {__raw_static_call (name); \ }) +struct static_call_key { +void *func; +union { +/* bit 0: 0 = mods, 1 = sites */ +unsigned long type; +struct static_call_mod *mods; +struct static_call_site *sites; + }; +}; +#else /* !CONFIG_HAVE_STATIC_CALL_INLINE */ #define __STATIC_CALL_ADDRESSABLE (name)#define __static_call (name) __raw_static_call(name) +struct static_call_key { +void *func; +}; +#endif /* CONFIG_HAVE_STATIC_CALL_INLINE */ #ifdef MODULE
@@ -77,6 +91,10 @@ struct static_call_site {#else +struct static_call_key { +void *func; +}; +#define static_call (name) \ ((typeof(STATIC_CALL_TRAMP(name))*)(STATIC_CALL_KEY(name).func))
Signature · 1 line
2.26.2
[tip: x86/alternatives] static_call: Move struct static_call_key definition to static_call_types.h
The following commit has been merged into the x86/alternatives branch of tip:
The following commit has been merged into the x86/alternatives branch of tip:
Commit-ID: b046664872dd78a8bebe3d5f3bb9da9baa93f5ca Gitweb: https://git.kernel.org/tip/b046664872dd78a8bebe3d5f3bb9da9baa93f5ca Author: Juergen Gross <[email protected]> AuthorDate: Thu, 11 Mar 2021 15:23:07 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 11 Mar 2021 16:04:39 +01:00
static_call: Move struct static_call_key definition to static_call_types.h
Having the definition of static_call() in static_call_types.h makes no sense as long struct static_call_key isn't defined there, as the generic implementation of static_call() is referencing this structure.
So move the definition of struct static_call_key to static_call_types.h.
--- include/linux/static_call.h | 18 ------------------ include/linux/static_call_types.h | 18 ++++++++++++++++++ tools/include/linux/static_call_types.h | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 18 deletions(-)
include/linux/static_call.h +0 -18
@@ -128,16 +128,6 @@ struct static_call_mod {struct static_call_site *sites; }; -struct static_call_key { -void *func; -union { -/* bit 0: 0 = mods, 1 = sites */ -unsigned long type; -struct static_call_mod *mods; -struct static_call_site *sites; - }; -}; -/* For finding the key associated with a trampoline */ struct static_call_tramp_key {s32 tramp;
@@ -187,10 +177,6 @@ extern long __static_call_return0(void);static inline int static_call_init (void ) {return 0 ; } -struct static_call_key { -void *func; -}; -#define __DEFINE_STATIC_CALL (name, _func, _func_init) \ DECLARE_STATIC_CALL(name, _func); \ struct static_call_key STATIC_CALL_KEY(name) = { \
@@ -243,10 +229,6 @@ static inline long __static_call_return0(void)static inline int static_call_init (void ) {return 0 ; } -struct static_call_key { -void *func; -}; -static inline long __static_call_return0 (void ) {return 0 ;
include/linux/static_call_types.h +18 -0
@@ -58,11 +58,25 @@ struct static_call_site {__raw_static_call (name); \ }) +struct static_call_key { +void *func; +union { +/* bit 0: 0 = mods, 1 = sites */ +unsigned long type; +struct static_call_mod *mods; +struct static_call_site *sites; + }; +}; +#else /* !CONFIG_HAVE_STATIC_CALL_INLINE */ #define __STATIC_CALL_ADDRESSABLE (name)#define __static_call (name) __raw_static_call(name) +struct static_call_key { +void *func; +}; +#endif /* CONFIG_HAVE_STATIC_CALL_INLINE */ #ifdef MODULE
@@ -77,6 +91,10 @@ struct static_call_site {#else +struct static_call_key { +void *func; +}; +#define static_call (name) \ ((typeof(STATIC_CALL_TRAMP(name))*)(STATIC_CALL_KEY(name).func))
tools/include/linux/static_call_types.h +18 -0
@@ -58,11 +58,25 @@ struct static_call_site {__raw_static_call (name); \ }) +struct static_call_key { +void *func; +union { +/* bit 0: 0 = mods, 1 = sites */ +unsigned long type; +struct static_call_mod *mods; +struct static_call_site *sites; + }; +}; +#else /* !CONFIG_HAVE_STATIC_CALL_INLINE */ #define __STATIC_CALL_ADDRESSABLE (name)#define __static_call (name) __raw_static_call(name) +struct static_call_key { +void *func; +}; +#endif /* CONFIG_HAVE_STATIC_CALL_INLINE */ #ifdef MODULE
@@ -77,6 +91,10 @@ struct static_call_site {#else +struct static_call_key { +void *func; +}; +#define static_call (name) \ ((typeof(STATIC_CALL_TRAMP(name))*)(STATIC_CALL_KEY(name).func))
Juergen Gross
maintainerPATCH v7 3/14 static_call: add function to query current function
In reply to Juergen GrossSome users of paravirtualized functions need to query which function has been specified in a pv_ops vector element. In order to be able to switch such paravirtualized functions to static_calls instead, there needs to be a function to query the function which will be called via static_call().
---
V7:
- new patch
--- include/linux/static_call.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/linux/static_call.h +8 -0
@@ -20,6 +20,7 @@* static_call(name)(args...); * static_call_cond(name)(args...); * static_call_update(name, func); +* static_call_query(name); * * Usage example: *
@@ -91,6 +92,10 @@* * which will include the required value tests to avoid NULL-pointer * dereferences. +* +* To query which function is currently set to be called, use: +* +* func = static_call_query(name); */ #include <linux/types.h>
@@ -118,6 +123,8 @@ extern void arch_static_call_transform(void *site, void *tramp, void *func, bool STATIC_CALL_TRAMP_ADDR(name), func); \ }) +#define static_call_query (name) (READ_ONCE(STATIC_CALL_KEY(name).func)) +#ifdef CONFIG_HAVE_STATIC_CALL_INLINE extern int __init static_call_init (void );
@@ -191,6 +198,7 @@ static inline int static_call_init(void) { return 0; } }; \ ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name) +#define static_call_cond (name) (void)__static_call(name) static inline
Signature · 1 line
2.26.2
[tip: x86/alternatives] static_call: Add function to query current function
The following commit has been merged into the x86/alternatives branch of tip:
The following commit has been merged into the x86/alternatives branch of tip:
Commit-ID: 6ea312d95e0226b306bb4b8ee3a0727d880378cb Gitweb: https://git.kernel.org/tip/6ea312d95e0226b306bb4b8ee3a0727d880378cb Author: Juergen Gross <[email protected]> AuthorDate: Thu, 11 Mar 2021 15:23:08 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 11 Mar 2021 16:12:33 +01:00
static_call: Add function to query current function
Some users of paravirtualized functions need to query which function has been specified in a pv_ops vector element. In order to be able to switch such paravirtualized functions to static_calls instead, there needs to be a function to query the function which will be called via static_call().
--- include/linux/static_call.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/linux/static_call.h +8 -0
@@ -20,6 +20,7 @@* static_call(name)(args...); * static_call_cond(name)(args...); * static_call_update(name, func); +* static_call_query(name); * * Usage example: *
@@ -91,6 +92,10 @@* * which will include the required value tests to avoid NULL-pointer * dereferences. +* +* To query which function is currently set to be called, use: +* +* func = static_call_query(name); */ #include <linux/types.h>
@@ -118,6 +123,8 @@ extern void arch_static_call_transform(void *site, void *tramp, void *func, bool STATIC_CALL_TRAMP_ADDR(name), func); \ }) +#define static_call_query (name) (READ_ONCE(STATIC_CALL_KEY(name).func)) +#ifdef CONFIG_HAVE_STATIC_CALL_INLINE extern int __init static_call_init (void );
@@ -191,6 +198,7 @@ static inline int static_call_init(void) { return 0; } }; \ ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name) +#define static_call_cond (name) (void)__static_call(name) static inline
Juergen Gross
maintainerPATCH v7 4/14 x86/paravirt: switch time pvops functions to use static_call()
In reply to Juergen GrossThe time pvops functions are the only ones left which might be used in 32-bit mode and which return a 64-bit value.
Switch them to use the static_call() mechanism instead of pvops, as this allows quite some simplification of the pvops implementation.
---
V4:
- drop paravirt_time.h again
- don't move Hyper-V code (Michael Kelley)
V5:
- drop no longer needed Hyper-V modification (Michael Kelley)
- switch Arm and Arm64 to static_call(), too (kernel test robot) V6:
- factor out common parts in Xen pv/pvh initialization (Boris Petkov) V7:
- use new function static_call_query()
--- arch/arm/include/asm/paravirt.h | 14 +++++--------- arch/arm/kernel/paravirt.c | 9 +++++++-- arch/arm64/include/asm/paravirt.h | 14 +++++--------- arch/arm64/kernel/paravirt.c | 13 +++++++++---- arch/x86/Kconfig | 1 + arch/x86/include/asm/mshyperv.h | 2 +- arch/x86/include/asm/paravirt.h | 15 ++++++++++++--- arch/x86/include/asm/paravirt_types.h | 6 ------ arch/x86/kernel/cpu/vmware.c | 5 +++-- arch/x86/kernel/kvm.c | 2 +- arch/x86/kernel/kvmclock.c | 2 +- arch/x86/kernel/paravirt.c | 13 +++++++++---- arch/x86/kernel/tsc.c | 3 ++- arch/x86/xen/time.c | 26 +++++++++++++------------- drivers/xen/time.c | 3 ++- 15 files changed, 71 insertions(+), 57 deletions(-)
arch/arm/include/asm/paravirt.h +5 -9
@@ -3,23 +3,19 @@#define _ASM_ARM_PARAVIRT_H#ifdef CONFIG_PARAVIRT +#include <linux/static_call_types.h> +struct static_key ;extern struct static_key paravirt_steal_enabled;extern struct static_key paravirt_steal_rq_enabled; -struct pv_time_ops { -unsigned long long (*steal_clock)(int cpu); -}; - -struct paravirt_patch_template { -struct pv_time_ops time; -}; +u64 dummy_steal_clock (int cpu); -extern struct paravirt_patch_template pv_ops; +DECLARE_STATIC_CALL (pv_steal_clock, dummy_steal_clock);static inline u64 paravirt_steal_clock (int cpu) { -return pv_ops.time.steal_clock (cpu); +return static_call (pv_steal_clock)(cpu); }#endif
arch/arm/kernel/paravirt.c +7 -2
@@ -9,10 +9,15 @@#include <linux/export.h> #include <linux/jump_label.h> #include <linux/types.h> +#include <linux/static_call.h> #include <asm/paravirt.h> struct static_key paravirt_steal_enabled;struct static_key paravirt_steal_rq_enabled; -struct paravirt_patch_template pv_ops; -EXPORT_SYMBOL_GPL (pv_ops); +static u64 native_steal_clock (int cpu) +{ +return 0 ; +} + +DEFINE_STATIC_CALL (pv_steal_clock, native_steal_clock);
arch/arm64/include/asm/paravirt.h +5 -9
@@ -3,23 +3,19 @@#define _ASM_ARM64_PARAVIRT_H#ifdef CONFIG_PARAVIRT +#include <linux/static_call_types.h> +struct static_key ;extern struct static_key paravirt_steal_enabled;extern struct static_key paravirt_steal_rq_enabled; -struct pv_time_ops { -unsigned long long (*steal_clock)(int cpu); -}; - -struct paravirt_patch_template { -struct pv_time_ops time; -}; +u64 dummy_steal_clock (int cpu); -extern struct paravirt_patch_template pv_ops; +DECLARE_STATIC_CALL (pv_steal_clock, dummy_steal_clock);static inline u64 paravirt_steal_clock (int cpu) { -return pv_ops.time.steal_clock (cpu); +return static_call (pv_steal_clock)(cpu); }int __init pv_time_init (void );
arch/arm64/kernel/paravirt.c +9 -4
@@ -18,6 +18,7 @@#include <linux/reboot.h> #include <linux/slab.h> #include <linux/types.h> +#include <linux/static_call.h> #include <asm/paravirt.h> #include <asm/pvclock-abi.h>
@@ -26,8 +27,12 @@struct static_key paravirt_steal_enabled;struct static_key paravirt_steal_rq_enabled; -struct paravirt_patch_template pv_ops; -EXPORT_SYMBOL_GPL (pv_ops); +static u64 native_steal_clock (int cpu) +{ +return 0 ; +} + +DEFINE_STATIC_CALL (pv_steal_clock, native_steal_clock);struct pv_time_stolen_time_region {struct pvclock_vcpu_stolen_time *kaddr;
@@ -45,7 +50,7 @@ static int __init parse_no_stealacc(char *arg)early_param ("no-steal-acc" , parse_no_stealacc);/* return stolen time in ns by asking the hypervisor */ -static u64 pv_steal_clock (int cpu) +static u64 para_steal_clock (int cpu) {struct pv_time_stolen_time_region *reg;
@@ -150,7 +155,7 @@ int __init pv_time_init(void)if (ret)return ret; - pv_ops.time.steal_clock = pv_steal_clock; +static_call_update (pv_steal_clock, para_steal_clock);static_key_slow_inc (¶virt_steal_enabled);if (steal_acc)
arch/x86/Kconfig +1 -0
@@ -777,6 +777,7 @@ if HYPERVISOR_GUEST config PARAVIRT bool "Enable paravirtualization code" + depends on HAVE_STATIC_CALL help This changes the kernel so it can modify itself when it is run under a hypervisor, potentially improving performance significantly
arch/x86/include/asm/mshyperv.h +1 -1
@@ -63,7 +63,7 @@ typedef int (*hyperv_fill_flush_list_func)( static __always_inline void hv_setup_sched_clock(void *sched_clock) {#ifdef CONFIG_PARAVIRT - pv_ops.time.sched_clock = sched_clock; +paravirt_set_sched_clock (sched_clock);#endif }
arch/x86/include/asm/paravirt.h +12 -3
@@ -15,11 +15,20 @@#include <linux/bug.h> #include <linux/types.h> #include <linux/cpumask.h> +#include <linux/static_call_types.h> #include <asm/frame.h> -static inline unsigned long long paravirt_sched_clock (void ) +u64 dummy_steal_clock (int cpu); +u64 dummy_sched_clock (void ); + +DECLARE_STATIC_CALL (pv_steal_clock, dummy_steal_clock); +DECLARE_STATIC_CALL (pv_sched_clock, dummy_sched_clock); + +void paravirt_set_sched_clock (u64 (*func)(void )); + +static inline u64 paravirt_sched_clock (void ) { - return PVOP_CALL0(unsigned long long, time.sched_clock); +return static_call (pv_sched_clock)(); }struct static_key ;
@@ -33,7 +42,7 @@ bool pv_is_native_vcpu_is_preempted(void);static inline u64 paravirt_steal_clock (int cpu) { -return PVOP_CALL1 (u64, time.steal_clock, cpu); +return static_call (pv_steal_clock)(cpu); }/* The paravirtualized I/O functions */
arch/x86/include/asm/paravirt_types.h +0 -6
@@ -95,11 +95,6 @@ struct pv_lazy_ops { } __no_randomize_layout;#endif -struct pv_time_ops { -unsigned long long (*sched_clock)(void ); -unsigned long long (*steal_clock)(int cpu); -} __no_randomize_layout; -struct pv_cpu_ops {/* hooks for various privileged instructions */ void (*io_delay)(void );
@@ -291,7 +286,6 @@ struct pv_lock_ops {* what to patch. */ struct paravirt_patch_template {struct pv_init_ops init; -struct pv_time_ops time;struct pv_cpu_ops cpu;struct pv_irq_ops irq;struct pv_mmu_ops mmu;
arch/x86/kernel/cpu/vmware.c +3 -2
@@ -27,6 +27,7 @@#include <linux/clocksource.h> #include <linux/cpu.h> #include <linux/reboot.h> +#include <linux/static_call.h> #include <asm/div64.h> #include <asm/x86_init.h> #include <asm/hypervisor.h>
@@ -336,11 +337,11 @@ static void __init vmware_paravirt_ops_setup(void)vmware_cyc2ns_setup ();if (vmw_sched_clock) - pv_ops.time.sched_clock = vmware_sched_clock; +paravirt_set_sched_clock (vmware_sched_clock);if (vmware_is_stealclock_available ()) { has_steal_clock = true; - pv_ops.time.steal_clock = vmware_steal_clock; +static_call_update (pv_steal_clock, vmware_steal_clock);/* We use reboot notifier only to disable steal clock */ register_reboot_notifier (&vmware_pv_reboot_nb);
arch/x86/kernel/kvm.c +1 -1
@@ -650,7 +650,7 @@ static void __init kvm_guest_init(void)if (kvm_para_has_feature (KVM_FEATURE_STEAL_TIME )) { has_steal_clock =1 ; - pv_ops.time.steal_clock = kvm_steal_clock; +static_call_update (pv_steal_clock, kvm_steal_clock); }if (pv_tlb_flush_supported ()) {
arch/x86/kernel/kvmclock.c +1 -1
@@ -106,7 +106,7 @@ static inline void kvm_sched_clock_init(bool stable)if (!stable)clear_sched_clock_stable (); kvm_sched_clock_offset =kvm_clock_read (); - pv_ops.time.sched_clock = kvm_sched_clock_read; +paravirt_set_sched_clock (kvm_sched_clock_read);pr_info ("kvm-clock: using sched offset of %llu cycles" , kvm_sched_clock_offset);
arch/x86/kernel/paravirt.c +9 -4
@@ -14,6 +14,7 @@#include <linux/highmem.h> #include <linux/kprobes.h> #include <linux/pgtable.h> +#include <linux/static_call.h> #include <asm/bug.h> #include <asm/paravirt.h>
@@ -167,6 +168,14 @@ static u64 native_steal_clock(int cpu)return 0 ; } +DEFINE_STATIC_CALL (pv_steal_clock, native_steal_clock); +DEFINE_STATIC_CALL (pv_sched_clock, native_sched_clock); + +void paravirt_set_sched_clock (u64 (*func)(void )) +{ +static_call_update (pv_sched_clock, func); +} +/* These are in entry.S */ extern void native_iret (void );
@@ -272,10 +281,6 @@ struct paravirt_patch_template pv_ops = {/* Init ops. */ .init.patch = native_patch, -/* Time ops. */ - .time.sched_clock = native_sched_clock, - .time.steal_clock = native_steal_clock, -/* Cpu ops. */ .cpu.io_delay = native_io_delay,
arch/x86/kernel/tsc.c +2 -1
@@ -14,6 +14,7 @@#include <linux/percpu.h> #include <linux/timex.h> #include <linux/static_key.h> +#include <linux/static_call.h> #include <asm/hpet.h> #include <asm/timer.h>
@@ -254,7 +255,7 @@ unsigned long long sched_clock(void)bool using_native_sched_clock (void ) { -return pv_ops.time.sched_clock == native_sched_clock; +return static_call_query (pv_sched_clock) == native_sched_clock; }#else unsigned long long
arch/x86/xen/time.c +13 -13
@@ -379,11 +379,6 @@ void xen_timer_resume(void) } } -static const struct pv_time_ops xen_time_ops__initconst = { - .sched_clock = xen_sched_clock, - .steal_clock = xen_steal_clock, -}; -static struct pvclock_vsyscall_time_info *xen_clock__read_mostly ;static u64 xen_clock_value_saved;
@@ -525,17 +520,24 @@ static void __init xen_time_init(void)pvclock_gtod_register_notifier (&xen_pvclock_gtod_notifier); } -void __init xen_init_time_ops (void ) +static void __init xen_init_time_common (void ) { xen_sched_clock_offset =xen_clocksource_read (); - pv_ops.time = xen_time_ops; +static_call_update (pv_steal_clock, xen_steal_clock); +paravirt_set_sched_clock (xen_sched_clock); + + x86_platform.calibrate_tsc = xen_tsc_khz; + x86_platform.get_wallclock = xen_get_wallclock; +} + +void __init xen_init_time_ops (void ) +{ +xen_init_time_common (); x86_init.timers.timer_init = xen_time_init; x86_init.timers.setup_percpu_clockev = x86_init_noop; x86_cpuinit.setup_percpu_clockev = x86_init_noop; - x86_platform.calibrate_tsc = xen_tsc_khz; - x86_platform.get_wallclock = xen_get_wallclock;/* Dom0 uses the native method to set the hardware RTC. */ if (!xen_initial_domain ()) x86_platform.set_wallclock = xen_set_wallclock;
@@ -569,13 +571,11 @@ void __init xen_hvm_init_time_ops(void) return; } - xen_sched_clock_offset =xen_clocksource_read (); - pv_ops.time = xen_time_ops; +xen_init_time_common (); + x86_init.timers.setup_percpu_clockev = xen_time_init; x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents; - x86_platform.calibrate_tsc = xen_tsc_khz; - x86_platform.get_wallclock = xen_get_wallclock; x86_platform.set_wallclock = xen_set_wallclock; }#endif
drivers/xen/time.c +2 -1
@@ -7,6 +7,7 @@#include <linux/math64.h> #include <linux/gfp.h> #include <linux/slab.h> +#include <linux/static_call.h> #include <asm/paravirt.h> #include <asm/xen/hypervisor.h>
@@ -175,7 +176,7 @@ void __init xen_time_setup_guest(void) xen_runstate_remote = !HYPERVISOR_vm_assist (VMASST_CMD_enable, VMASST_TYPE_runstate_update_flag); - pv_ops.time.steal_clock = xen_steal_clock; +static_call_update (pv_steal_clock, xen_steal_clock);static_key_slow_inc (¶virt_steal_enabled);if (xen_runstate_remote)
Signature · 6 lines
2.26.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
[tip: x86/alternatives] x86/paravirt: Switch time pvops functions to use static_call()
The following commit has been merged into the x86/alternatives branch of tip:
The following commit has been merged into the x86/alternatives branch of tip:
Commit-ID: a0e2bf7cb7006b5a58ee81f4da4fe575875f2781 Gitweb: https://git.kernel.org/tip/a0e2bf7cb7006b5a58ee81f4da4fe575875f2781 Author: Juergen Gross <[email protected]> AuthorDate: Thu, 11 Mar 2021 15:23:09 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 11 Mar 2021 16:17:52 +01:00
x86/paravirt: Switch time pvops functions to use static_call()
The time pvops functions are the only ones left which might be used in 32-bit mode and which return a 64-bit value.
Switch them to use the static_call() mechanism instead of pvops, as this allows quite some simplification of the pvops implementation.
--- arch/arm/include/asm/paravirt.h | 14 +++++--------- arch/arm/kernel/paravirt.c | 9 +++++++-- arch/arm64/include/asm/paravirt.h | 14 +++++--------- arch/arm64/kernel/paravirt.c | 13 +++++++++---- arch/x86/Kconfig | 1 +- arch/x86/include/asm/mshyperv.h | 2 +- arch/x86/include/asm/paravirt.h | 15 ++++++++++++--- arch/x86/include/asm/paravirt_types.h | 6 +------ arch/x86/kernel/cpu/vmware.c | 5 +++-- arch/x86/kernel/kvm.c | 2 +- arch/x86/kernel/kvmclock.c | 2 +- arch/x86/kernel/paravirt.c | 13 +++++++++---- arch/x86/kernel/tsc.c | 3 ++- arch/x86/xen/time.c | 26 +++++++++++++------------- drivers/xen/time.c | 3 ++- 15 files changed, 71 insertions(+), 57 deletions(-)
arch/arm/include/asm/paravirt.h +5 -9
@@ -3,23 +3,19 @@#define _ASM_ARM_PARAVIRT_H#ifdef CONFIG_PARAVIRT +#include <linux/static_call_types.h> +struct static_key ;extern struct static_key paravirt_steal_enabled;extern struct static_key paravirt_steal_rq_enabled; -struct pv_time_ops { -unsigned long long (*steal_clock)(int cpu); -}; - -struct paravirt_patch_template { -struct pv_time_ops time; -}; +u64 dummy_steal_clock (int cpu); -extern struct paravirt_patch_template pv_ops; +DECLARE_STATIC_CALL (pv_steal_clock, dummy_steal_clock);static inline u64 paravirt_steal_clock (int cpu) { -return pv_ops.time.steal_clock (cpu); +return static_call (pv_steal_clock)(cpu); }#endif
arch/arm/kernel/paravirt.c +7 -2
@@ -9,10 +9,15 @@#include <linux/export.h> #include <linux/jump_label.h> #include <linux/types.h> +#include <linux/static_call.h> #include <asm/paravirt.h> struct static_key paravirt_steal_enabled;struct static_key paravirt_steal_rq_enabled; -struct paravirt_patch_template pv_ops; -EXPORT_SYMBOL_GPL (pv_ops); +static u64 native_steal_clock (int cpu) +{ +return 0 ; +} + +DEFINE_STATIC_CALL (pv_steal_clock, native_steal_clock);
arch/arm64/include/asm/paravirt.h +5 -9
@@ -3,23 +3,19 @@#define _ASM_ARM64_PARAVIRT_H#ifdef CONFIG_PARAVIRT +#include <linux/static_call_types.h> +struct static_key ;extern struct static_key paravirt_steal_enabled;extern struct static_key paravirt_steal_rq_enabled; -struct pv_time_ops { -unsigned long long (*steal_clock)(int cpu); -}; - -struct paravirt_patch_template { -struct pv_time_ops time; -}; +u64 dummy_steal_clock (int cpu); -extern struct paravirt_patch_template pv_ops; +DECLARE_STATIC_CALL (pv_steal_clock, dummy_steal_clock);static inline u64 paravirt_steal_clock (int cpu) { -return pv_ops.time.steal_clock (cpu); +return static_call (pv_steal_clock)(cpu); }int __init pv_time_init (void );
arch/arm64/kernel/paravirt.c +9 -4
@@ -18,6 +18,7 @@#include <linux/reboot.h> #include <linux/slab.h> #include <linux/types.h> +#include <linux/static_call.h> #include <asm/paravirt.h> #include <asm/pvclock-abi.h>
@@ -26,8 +27,12 @@struct static_key paravirt_steal_enabled;struct static_key paravirt_steal_rq_enabled; -struct paravirt_patch_template pv_ops; -EXPORT_SYMBOL_GPL (pv_ops); +static u64 native_steal_clock (int cpu) +{ +return 0 ; +} + +DEFINE_STATIC_CALL (pv_steal_clock, native_steal_clock);struct pv_time_stolen_time_region {struct pvclock_vcpu_stolen_time *kaddr;
@@ -45,7 +50,7 @@ static int __init parse_no_stealacc(char *arg)early_param ("no-steal-acc" , parse_no_stealacc);/* return stolen time in ns by asking the hypervisor */ -static u64 pv_steal_clock (int cpu) +static u64 para_steal_clock (int cpu) {struct pv_time_stolen_time_region *reg;
@@ -150,7 +155,7 @@ int __init pv_time_init(void)if (ret)return ret; - pv_ops.time.steal_clock = pv_steal_clock; +static_call_update (pv_steal_clock, para_steal_clock);static_key_slow_inc (¶virt_steal_enabled);if (steal_acc)
arch/x86/Kconfig +1 -0
@@ -777,6 +777,7 @@ if HYPERVISOR_GUEST config PARAVIRT bool "Enable paravirtualization code" + depends on HAVE_STATIC_CALL help This changes the kernel so it can modify itself when it is run under a hypervisor, potentially improving performance significantly
arch/x86/include/asm/mshyperv.h +1 -1
@@ -63,7 +63,7 @@ typedef int (*hyperv_fill_flush_list_func)( static __always_inline void hv_setup_sched_clock(void *sched_clock) {#ifdef CONFIG_PARAVIRT - pv_ops.time.sched_clock = sched_clock; +paravirt_set_sched_clock (sched_clock);#endif }
arch/x86/include/asm/paravirt.h +12 -3
@@ -15,11 +15,20 @@#include <linux/bug.h> #include <linux/types.h> #include <linux/cpumask.h> +#include <linux/static_call_types.h> #include <asm/frame.h> -static inline unsigned long long paravirt_sched_clock (void ) +u64 dummy_steal_clock (int cpu); +u64 dummy_sched_clock (void ); + +DECLARE_STATIC_CALL (pv_steal_clock, dummy_steal_clock); +DECLARE_STATIC_CALL (pv_sched_clock, dummy_sched_clock); + +void paravirt_set_sched_clock (u64 (*func)(void )); + +static inline u64 paravirt_sched_clock (void ) { - return PVOP_CALL0(unsigned long long, time.sched_clock); +return static_call (pv_sched_clock)(); }struct static_key ;
@@ -33,7 +42,7 @@ bool pv_is_native_vcpu_is_preempted(void);static inline u64 paravirt_steal_clock (int cpu) { -return PVOP_CALL1 (u64, time.steal_clock, cpu); +return static_call (pv_steal_clock)(cpu); }/* The paravirtualized I/O functions */
arch/x86/include/asm/paravirt_types.h +0 -6
@@ -95,11 +95,6 @@ struct pv_lazy_ops { } __no_randomize_layout;#endif -struct pv_time_ops { -unsigned long long (*sched_clock)(void ); -unsigned long long (*steal_clock)(int cpu); -} __no_randomize_layout; -struct pv_cpu_ops {/* hooks for various privileged instructions */ void (*io_delay)(void );
@@ -291,7 +286,6 @@ struct pv_lock_ops {* what to patch. */ struct paravirt_patch_template {struct pv_init_ops init; -struct pv_time_ops time;struct pv_cpu_ops cpu;struct pv_irq_ops irq;struct pv_mmu_ops mmu;
arch/x86/kernel/cpu/vmware.c +3 -2
@@ -27,6 +27,7 @@#include <linux/clocksource.h> #include <linux/cpu.h> #include <linux/reboot.h> +#include <linux/static_call.h> #include <asm/div64.h> #include <asm/x86_init.h> #include <asm/hypervisor.h>
@@ -336,11 +337,11 @@ static void __init vmware_paravirt_ops_setup(void)vmware_cyc2ns_setup ();if (vmw_sched_clock) - pv_ops.time.sched_clock = vmware_sched_clock; +paravirt_set_sched_clock (vmware_sched_clock);if (vmware_is_stealclock_available ()) { has_steal_clock = true; - pv_ops.time.steal_clock = vmware_steal_clock; +static_call_update (pv_steal_clock, vmware_steal_clock);/* We use reboot notifier only to disable steal clock */ register_reboot_notifier (&vmware_pv_reboot_nb);
arch/x86/kernel/kvm.c +1 -1
@@ -650,7 +650,7 @@ static void __init kvm_guest_init(void)if (kvm_para_has_feature (KVM_FEATURE_STEAL_TIME )) { has_steal_clock =1 ; - pv_ops.time.steal_clock = kvm_steal_clock; +static_call_update (pv_steal_clock, kvm_steal_clock); }if (pv_tlb_flush_supported ()) {
arch/x86/kernel/kvmclock.c +1 -1
@@ -106,7 +106,7 @@ static inline void kvm_sched_clock_init(bool stable)if (!stable)clear_sched_clock_stable (); kvm_sched_clock_offset =kvm_clock_read (); - pv_ops.time.sched_clock = kvm_sched_clock_read; +paravirt_set_sched_clock (kvm_sched_clock_read);pr_info ("kvm-clock: using sched offset of %llu cycles" , kvm_sched_clock_offset);
arch/x86/kernel/paravirt.c +9 -4
@@ -14,6 +14,7 @@#include <linux/highmem.h> #include <linux/kprobes.h> #include <linux/pgtable.h> +#include <linux/static_call.h> #include <asm/bug.h> #include <asm/paravirt.h>
@@ -167,6 +168,14 @@ static u64 native_steal_clock(int cpu)return 0 ; } +DEFINE_STATIC_CALL (pv_steal_clock, native_steal_clock); +DEFINE_STATIC_CALL (pv_sched_clock, native_sched_clock); + +void paravirt_set_sched_clock (u64 (*func)(void )) +{ +static_call_update (pv_sched_clock, func); +} +/* These are in entry.S */ extern void native_iret (void );
@@ -272,10 +281,6 @@ struct paravirt_patch_template pv_ops = {/* Init ops. */ .init.patch = native_patch, -/* Time ops. */ - .time.sched_clock = native_sched_clock, - .time.steal_clock = native_steal_clock, -/* Cpu ops. */ .cpu.io_delay = native_io_delay,
arch/x86/kernel/tsc.c +2 -1
@@ -14,6 +14,7 @@#include <linux/percpu.h> #include <linux/timex.h> #include <linux/static_key.h> +#include <linux/static_call.h> #include <asm/hpet.h> #include <asm/timer.h>
@@ -254,7 +255,7 @@ unsigned long long sched_clock(void)bool using_native_sched_clock (void ) { -return pv_ops.time.sched_clock == native_sched_clock; +return static_call_query (pv_sched_clock) == native_sched_clock; }#else unsigned long long
arch/x86/xen/time.c +13 -13
@@ -379,11 +379,6 @@ void xen_timer_resume(void) } } -static const struct pv_time_ops xen_time_ops__initconst = { - .sched_clock = xen_sched_clock, - .steal_clock = xen_steal_clock, -}; -static struct pvclock_vsyscall_time_info *xen_clock__read_mostly ;static u64 xen_clock_value_saved;
@@ -525,17 +520,24 @@ static void __init xen_time_init(void)pvclock_gtod_register_notifier (&xen_pvclock_gtod_notifier); } -void __init xen_init_time_ops (void ) +static void __init xen_init_time_common (void ) { xen_sched_clock_offset =xen_clocksource_read (); - pv_ops.time = xen_time_ops; +static_call_update (pv_steal_clock, xen_steal_clock); +paravirt_set_sched_clock (xen_sched_clock); + + x86_platform.calibrate_tsc = xen_tsc_khz; + x86_platform.get_wallclock = xen_get_wallclock; +} + +void __init xen_init_time_ops (void ) +{ +xen_init_time_common (); x86_init.timers.timer_init = xen_time_init; x86_init.timers.setup_percpu_clockev = x86_init_noop; x86_cpuinit.setup_percpu_clockev = x86_init_noop; - x86_platform.calibrate_tsc = xen_tsc_khz; - x86_platform.get_wallclock = xen_get_wallclock;/* Dom0 uses the native method to set the hardware RTC. */ if (!xen_initial_domain ()) x86_platform.set_wallclock = xen_set_wallclock;
@@ -569,13 +571,11 @@ void __init xen_hvm_init_time_ops(void) return; } - xen_sched_clock_offset =xen_clocksource_read (); - pv_ops.time = xen_time_ops; +xen_init_time_common (); + x86_init.timers.setup_percpu_clockev = xen_time_init; x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents; - x86_platform.calibrate_tsc = xen_tsc_khz; - x86_platform.get_wallclock = xen_get_wallclock; x86_platform.set_wallclock = xen_set_wallclock; }#endif
drivers/xen/time.c +2 -1
@@ -7,6 +7,7 @@#include <linux/math64.h> #include <linux/gfp.h> #include <linux/slab.h> +#include <linux/static_call.h> #include <asm/paravirt.h> #include <asm/xen/hypervisor.h>
@@ -175,7 +176,7 @@ void __init xen_time_setup_guest(void) xen_runstate_remote = !HYPERVISOR_vm_assist (VMASST_CMD_enable, VMASST_TYPE_runstate_update_flag); - pv_ops.time.steal_clock = xen_steal_clock; +static_call_update (pv_steal_clock, xen_steal_clock);static_key_slow_inc (¶virt_steal_enabled);if (xen_runstate_remote)
Juergen Gross
maintainerPATCH v7 5/14 x86/alternative: support not-feature
In reply to Juergen GrossAdd support for alternative patching for the case a feature is not present on the current cpu.
For users of ALTERNATIVE() and friends an inverted feature is specified by applying the ALT_NOT() macro to it, e.g.:
ALTERNATIVE(old, new, ALT_NOT(feature))
---
V5:
- split off from next patch
- reworked to use flag byte (Boris Petkov)
V6:
- rework again to not use flag byte (Boris Petkov) V7:
- minor tweaks: move defines up, comment wording (Boris Petkov)
--- arch/x86/include/asm/alternative.h | 3 +++ arch/x86/kernel/alternative.c | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-)
arch/x86/include/asm/alternative.h +3 -0
@@ -6,6 +6,9 @@#include <linux/stringify.h> #include <asm/asm.h> +#define ALTINSTR_FLAG_INV (1 << 15) +#define ALT_NOT (feat) ((feat) | ALTINSTR_FLAG_INV) +#ifndef __ASSEMBLY__#include <linux/stddef.h>
arch/x86/kernel/alternative.c +15 -5
@@ -388,21 +388,31 @@ void __init_or_module noinline apply_alternatives(struct alt_instr *start,*/ for (a = start; a < end; a++) {int insn_buff_sz =0 ; +/* Mask away "NOT" flag bit for feature to test. */ +u16 feature = a->cpuid & ~ALTINSTR_FLAG_INV ; instr = (u8 *)&a->instr_offset + a->instr_offset; replacement = (u8 *)&a->repl_offset + a->repl_offset;BUG_ON (a->instrlen >sizeof (insn_buff)); -BUG_ON (a->cpuid >= (NCAPINTS +NBUGINTS ) *32 ); -if (!boot_cpu_has (a->cpuid)) { +BUG_ON (feature >= (NCAPINTS +NBUGINTS ) *32 ); + +/* +* Patch if either: +* - feature is present +* - feature not present but ALTINSTR_FLAG_INV is set to mean, +* patch if feature is *NOT* present. +*/ +if (!boot_cpu_has (feature) == !(a->cpuid &ALTINSTR_FLAG_INV )) {if (a->padlen >1 )optimize_nops (a, instr);continue ; } -DPRINTK ("feat: %d*32+%d, old: (%pS (%px) len: %d), repl: (%px, len: %d), pad: %d" , - a->cpuid >>5 , - a->cpuid &0x1f , +DPRINTK ("feat: %s%d*32+%d, old: (%pS (%px) len: %d), repl: (%px, len: %d), pad: %d" , + (a->cpuid &ALTINSTR_FLAG_INV ) ?"!" :"" , + feature >>5 , + feature &0x1f , instr, instr, a->instrlen, replacement, a->replacementlen, a->padlen);
Signature · 1 line
2.26.2
[tip: x86/alternatives] x86/alternative: Support not-feature
The following commit has been merged into the x86/alternatives branch of tip:
The following commit has been merged into the x86/alternatives branch of tip:
Commit-ID: dda7bb76484978316bb412a353789ebc5901de36 Gitweb: https://git.kernel.org/tip/dda7bb76484978316bb412a353789ebc5901de36 Author: Juergen Gross <[email protected]> AuthorDate: Thu, 11 Mar 2021 15:23:10 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 11 Mar 2021 16:44:01 +01:00
x86/alternative: Support not-feature
Add support for alternative patching for the case a feature is not present on the current CPU. For users of ALTERNATIVE() and friends, an inverted feature is specified by applying the ALT_NOT() macro to it, e.g.:
ALTERNATIVE(old, new, ALT_NOT(feature));
Committer note:
The decision to encode the NOT-bit in the feature bit itself is because a future change which would make objtool generate such alternative calls, would keep the code in objtool itself fairly simple.
Also, this allows for the alternative macros to support the NOT feature without having to change them.
Finally, the u16 cpuid member encoding the X86_FEATURE_ flags is not an ABI so if more bits are needed, cpuid itself can be enlarged or a flags field can be added to struct alt_instr after having considered the size growth in either cases.
--- arch/x86/include/asm/alternative.h | 3 +++ arch/x86/kernel/alternative.c | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-)
arch/x86/include/asm/alternative.h +3 -0
@@ -6,6 +6,9 @@#include <linux/stringify.h> #include <asm/asm.h> +#define ALTINSTR_FLAG_INV (1 << 15) +#define ALT_NOT (feat) ((feat) | ALTINSTR_FLAG_INV) +#ifndef __ASSEMBLY__#include <linux/stddef.h>
arch/x86/kernel/alternative.c +15 -5
@@ -388,21 +388,31 @@ void __init_or_module noinline apply_alternatives(struct alt_instr *start,*/ for (a = start; a < end; a++) {int insn_buff_sz =0 ; +/* Mask away "NOT" flag bit for feature to test. */ +u16 feature = a->cpuid & ~ALTINSTR_FLAG_INV ; instr = (u8 *)&a->instr_offset + a->instr_offset; replacement = (u8 *)&a->repl_offset + a->repl_offset;BUG_ON (a->instrlen >sizeof (insn_buff)); -BUG_ON (a->cpuid >= (NCAPINTS +NBUGINTS ) *32 ); -if (!boot_cpu_has (a->cpuid)) { +BUG_ON (feature >= (NCAPINTS +NBUGINTS ) *32 ); + +/* +* Patch if either: +* - feature is present +* - feature not present but ALTINSTR_FLAG_INV is set to mean, +* patch if feature is *NOT* present. +*/ +if (!boot_cpu_has (feature) == !(a->cpuid &ALTINSTR_FLAG_INV )) {if (a->padlen >1 )optimize_nops (a, instr);continue ; } -DPRINTK ("feat: %d*32+%d, old: (%pS (%px) len: %d), repl: (%px, len: %d), pad: %d" , - a->cpuid >>5 , - a->cpuid &0x1f , +DPRINTK ("feat: %s%d*32+%d, old: (%pS (%px) len: %d), repl: (%px, len: %d), pad: %d" , + (a->cpuid &ALTINSTR_FLAG_INV ) ?"!" :"" , + feature >>5 , + feature &0x1f , instr, instr, a->instrlen, replacement, a->replacementlen, a->padlen);
Juergen Gross
maintainerPATCH v7 6/14 x86/alternative: support ALTERNATIVE_TERNARY
In reply to Juergen GrossAdd ALTERNATIVE_TERNARY support for replacing an initial instruction with either of two instructions depending on a feature:
ALTERNATIVE_TERNARY "default_instr", FEATURE_NR,
"feature_on_instr", "feature_off_instr"
which will start with "default_instr" and at patch time will, depending on FEATURE_NR being set or not, patch that with either "feature_on_instr" or "feature_off_instr".
---
V3:
- new patch
V4:
- use X86_FEATURE_ALWAYS instead of negated feature (Boris Petkov)
- unfortunately this isn't enough to get rid of the "not feature" support, as this is needed in the patch "x86/paravirt: switch functions with custom code to ALTERNATIVE", too
V5:
- carve out the "not feature" part
V7:
- rename parameter names (Boris Petkov)
--- arch/x86/include/asm/alternative.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/x86/include/asm/alternative.h +11 -0
@@ -179,6 +179,10 @@ static inline int alternatives_text_reserved(void *start, void *end) ALTINSTR_REPLACEMENT(newinstr2, 2) \ ".popsection\n" +#define ALTERNATIVE_TERNARY (oldinstr, feature, newinstr_yes, newinstr_no) \ + ALTERNATIVE_2(oldinstr, newinstr_no, X86_FEATURE_ALWAYS, \ + newinstr_yes, feature) +#define ALTERNATIVE_3 (oldinsn, newinsn1, feat1, newinsn2, feat2, newinsn3, feat3) \ OLDINSTR_3(oldinsn, 1, 2, 3) \ ".pushsection .altinstructions,\"a\"\n" \
@@ -210,6 +214,9 @@ static inline int alternatives_text_reserved(void *start, void *end)#define alternative_2 (oldinstr, newinstr1, feature1, newinstr2, feature2) \ asm_inline volatile(ALTERNATIVE_2(oldinstr, newinstr1, feature1, newinstr2, feature2) ::: "memory") +#define alternative_ternary (oldinstr, feature, newinstr_yes, newinstr_no) \ + asm_inline volatile(ALTERNATIVE_TERNARY(oldinstr, feature, newinstr_yes, newinstr_no) ::: "memory") +/* * Alternative inline assembly with input. *
@@ -380,6 +387,10 @@ static inline int alternatives_text_reserved(void *start, void *end) .popsection .endm +#define ALTERNATIVE_TERNARY (oldinstr, feature, newinstr_yes, newinstr_no) \ + ALTERNATIVE_2 oldinstr, newinstr_no, X86_FEATURE_ALWAYS, \ + newinstr_yes, feature +#endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_ALTERNATIVE_H */
Signature · 1 line
2.26.2
[tip: x86/alternatives] x86/alternative: Support ALTERNATIVE_TERNARY
The following commit has been merged into the x86/alternatives branch of tip:
The following commit has been merged into the x86/alternatives branch of tip:
Commit-ID: e208b3c4a9748b2c17aa09ba663b5096ccf82dce Gitweb: https://git.kernel.org/tip/e208b3c4a9748b2c17aa09ba663b5096ccf82dce Author: Juergen Gross <[email protected]> AuthorDate: Thu, 11 Mar 2021 15:23:11 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 11 Mar 2021 16:57:31 +01:00
x86/alternative: Support ALTERNATIVE_TERNARY
Add ALTERNATIVE_TERNARY support for replacing an initial instruction with either of two instructions depending on a feature:
ALTERNATIVE_TERNARY "default_instr", FEATURE_NR,
"feature_on_instr", "feature_off_instr"
which will start with "default_instr" and at patch time will, depending on FEATURE_NR being set or not, patch that with either "feature_on_instr" or "feature_off_instr".
[ bp: Add comment ontop. ]
--- arch/x86/include/asm/alternative.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/x86/include/asm/alternative.h +13 -0
@@ -179,6 +179,11 @@ static inline int alternatives_text_reserved(void *start, void *end) ALTINSTR_REPLACEMENT(newinstr2, 2) \".popsection\n" +/* If @feature is set, patch in @newinstr_yes, otherwise @newinstr_no. */ +#define ALTERNATIVE_TERNARY (oldinstr, feature, newinstr_yes, newinstr_no) \ + ALTERNATIVE_2(oldinstr, newinstr_no, X86_FEATURE_ALWAYS, \ + newinstr_yes, feature) +#define ALTERNATIVE_3 (oldinsn, newinsn1, feat1, newinsn2, feat2, newinsn3, feat3) \ OLDINSTR_3(oldinsn, 1, 2, 3) \ ".pushsection .altinstructions,\"a\"\n" \
@@ -210,6 +215,9 @@ static inline int alternatives_text_reserved(void *start, void *end)#define alternative_2 (oldinstr, newinstr1, feature1, newinstr2, feature2) \ asm_inline volatile(ALTERNATIVE_2(oldinstr, newinstr1, feature1, newinstr2, feature2) ::: "memory") +#define alternative_ternary (oldinstr, feature, newinstr_yes, newinstr_no) \ + asm_inline volatile(ALTERNATIVE_TERNARY(oldinstr, feature, newinstr_yes, newinstr_no) ::: "memory") +/* * Alternative inline assembly with input. *
@@ -380,6 +388,11 @@ static inline int alternatives_text_reserved(void *start, void *end) .popsection .endm +/* If @feature is set, patch in @newinstr_yes, otherwise @newinstr_no. */ +#define ALTERNATIVE_TERNARY (oldinstr, feature, newinstr_yes, newinstr_no) \ + ALTERNATIVE_2 oldinstr, newinstr_no, X86_FEATURE_ALWAYS, \ + newinstr_yes, feature +#endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_ALTERNATIVE_H */
Juergen Gross
maintainerPATCH v7 7/14 x86/alternative: don't open code ALTERNATIVE_TERNARY() in _static_cpu_has()
In reply to Juergen Gross_static_cpu_has() contains a completely open coded version of ALTERNATIVE_TERNARY(). Replace that with the macro instead.
---
V6:
- new patch
V7:
- moved patch earlier in series (Boris Petkov)
--- arch/x86/include/asm/cpufeature.h | 41 +++++++------------------------ 1 file changed, 9 insertions(+), 32 deletions(-)
arch/x86/include/asm/cpufeature.h +9 -32
@@ -8,6 +8,7 @@#include <asm/asm.h> #include <linux/bitops.h> +#include <asm/alternative.h> enum cpuid_leafs {
@@ -175,39 +176,15 @@ extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit);*/ static __always_inline bool _static_cpu_has(u16 bit) { -asm_volatile_goto ("1: jmp 6f\n" -"2:\n" -".skip -(((5f-4f) - (2b-1b)) > 0) * " -"((5f-4f) - (2b-1b)),0x90\n" -"3:\n" -".section .altinstructions,\"a\"\n" -" .long 1b - .\n" /* src offset */ -" .long 4f - .\n" /* repl offset */ -" .word %P[always]\n" /* always replace */ -" .byte 3b - 1b\n" /* src len */ -" .byte 5f - 4f\n" /* repl len */ -" .byte 3b - 2b\n" /* pad len */ -".previous\n" -".section .altinstr_replacement,\"ax\"\n" -"4: jmp %l[t_no]\n" -"5:\n" -".previous\n" -".section .altinstructions,\"a\"\n" -" .long 1b - .\n" /* src offset */ -" .long 0\n" /* no replacement */ -" .word %P[feature]\n" /* feature bit */ -" .byte 3b - 1b\n" /* src len */ -" .byte 0\n" /* repl len */ -" .byte 0\n" /* pad len */ -".previous\n" -".section .altinstr_aux,\"ax\"\n" -"6:\n" -" testb %[bitnum],%[cap_byte]\n" -" jnz %l[t_yes]\n" -" jmp %l[t_no]\n" -".previous\n" +asm_volatile_goto ( + ALTERNATIVE_TERNARY("jmp 6f", %P[feature], "", "jmp %l[t_no]") + ".section .altinstr_aux,\"ax\"\n" + "6:\n" + " testb %[bitnum],%[cap_byte]\n" + " jnz %l[t_yes]\n" + " jmp %l[t_no]\n" + ".previous\n" : : [feature] "i" (bit), - [always] "i" (X86_FEATURE_ALWAYS), [bitnum] "i" (1 << (bit & 7)), [cap_byte] "m" (((const char *)boot_cpu_data.x86_capability)[bit >> 3]) : : t_yes, t_no);
Signature · 1 line
2.26.2
[tip: x86/alternatives] x86/alternative: Use ALTERNATIVE_TERNARY() in _static_cpu_has()
The following commit has been merged into the x86/alternatives branch of tip:
The following commit has been merged into the x86/alternatives branch of tip:
Commit-ID: 2fe2a2c7a97c9bc32acc79154b75e754280f7867 Gitweb: https://git.kernel.org/tip/2fe2a2c7a97c9bc32acc79154b75e754280f7867 Author: Juergen Gross <[email protected]> AuthorDate: Thu, 11 Mar 2021 15:23:12 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 11 Mar 2021 19:33:43 +01:00
x86/alternative: Use ALTERNATIVE_TERNARY() in _static_cpu_has()
_static_cpu_has() contains a completely open coded version of ALTERNATIVE_TERNARY(). Replace that with the macro instead.
--- arch/x86/include/asm/cpufeature.h | 41 ++++++------------------------ 1 file changed, 9 insertions(+), 32 deletions(-)
arch/x86/include/asm/cpufeature.h +9 -32
@@ -8,6 +8,7 @@#include <asm/asm.h> #include <linux/bitops.h> +#include <asm/alternative.h> enum cpuid_leafs {
@@ -175,39 +176,15 @@ extern void clear_cpu_cap(struct cpuinfo_x86 *c, unsigned int bit);*/ static __always_inline bool _static_cpu_has(u16 bit) { -asm_volatile_goto ("1: jmp 6f\n" -"2:\n" -".skip -(((5f-4f) - (2b-1b)) > 0) * " -"((5f-4f) - (2b-1b)),0x90\n" -"3:\n" -".section .altinstructions,\"a\"\n" -" .long 1b - .\n" /* src offset */ -" .long 4f - .\n" /* repl offset */ -" .word %P[always]\n" /* always replace */ -" .byte 3b - 1b\n" /* src len */ -" .byte 5f - 4f\n" /* repl len */ -" .byte 3b - 2b\n" /* pad len */ -".previous\n" -".section .altinstr_replacement,\"ax\"\n" -"4: jmp %l[t_no]\n" -"5:\n" -".previous\n" -".section .altinstructions,\"a\"\n" -" .long 1b - .\n" /* src offset */ -" .long 0\n" /* no replacement */ -" .word %P[feature]\n" /* feature bit */ -" .byte 3b - 1b\n" /* src len */ -" .byte 0\n" /* repl len */ -" .byte 0\n" /* pad len */ -".previous\n" -".section .altinstr_aux,\"ax\"\n" -"6:\n" -" testb %[bitnum],%[cap_byte]\n" -" jnz %l[t_yes]\n" -" jmp %l[t_no]\n" -".previous\n" +asm_volatile_goto ( + ALTERNATIVE_TERNARY("jmp 6f", %P[feature], "", "jmp %l[t_no]") + ".section .altinstr_aux,\"ax\"\n" + "6:\n" + " testb %[bitnum],%[cap_byte]\n" + " jnz %l[t_yes]\n" + " jmp %l[t_no]\n" + ".previous\n" : : [feature] "i" (bit), - [always] "i" (X86_FEATURE_ALWAYS), [bitnum] "i" (1 << (bit & 7)), [cap_byte] "m" (((const char *)boot_cpu_data.x86_capability)[bit >> 3]) : : t_yes, t_no);
Juergen Gross
maintainerPATCH v7 8/14 x86: add new features for paravirt patching
In reply to Juergen GrossFor being able to switch paravirt patching from special cased custom code sequences to ALTERNATIVE handling some X86_FEATURE_* are needed as new features. This enables to have the standard indirect pv call as the default code and to patch that with the non-Xen custom code sequence via ALTERNATIVE patching later.
Make sure paravirt patching is performed before alternative patching.
---
V3:
- add comment (Boris Petkov)
- no negative features (Boris Petkov)
V4:
- move paravirt_set_cap() to paravirt-spinlocks.c
--- arch/x86/include/asm/cpufeatures.h | 2 ++ arch/x86/include/asm/paravirt.h | 10 ++++++++++ arch/x86/kernel/alternative.c | 30 ++++++++++++++++++++++++++-- arch/x86/kernel/paravirt-spinlocks.c | 9 +++++++++ 4 files changed, 49 insertions(+), 2 deletions(-)
arch/x86/include/asm/cpufeatures.h +2 -0
@@ -236,6 +236,8 @@#define X86_FEATURE_EPT_AD ( 8*32+17)/* Intel Extended Page Table access-dirty bit */ #define X86_FEATURE_VMCALL ( 8*32+18)/* "" Hypervisor supports the VMCALL instruction */ #define X86_FEATURE_VMW_VMMCALL ( 8*32+19)/* "" VMware prefers VMMCALL hypercall instruction */ +#define X86_FEATURE_PVUNLOCK ( 8*32+20)/* "" PV unlock function */ +#define X86_FEATURE_VCPUPREEMPT ( 8*32+21)/* "" PV vcpu_is_preempted function */ /* Intel-defined CPU features, CPUID level 0x00000007:0 (EBX), word 9 */ #define X86_FEATURE_FSGSBASE ( 9*32+ 0)/* RDFSBASE, WRFSBASE, RDGSBASE, WRGSBASE instructions*/
arch/x86/include/asm/paravirt.h +10 -0
@@ -45,6 +45,10 @@ static inline u64 paravirt_steal_clock(int cpu)return static_call (pv_steal_clock)(cpu); } +#ifdef CONFIG_PARAVIRT_SPINLOCKS +void __init paravirt_set_cap (void ); +#endif +/* The paravirtualized I/O functions */ static inline void slow_down_io (void ) {
@@ -809,5 +813,11 @@ static inline void paravirt_arch_exit_mmap(struct mm_struct *mm) { }#endif + +#ifndef CONFIG_PARAVIRT_SPINLOCKS +static inline void paravirt_set_cap (void ) +{ +} +#endif #endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_PARAVIRT_H */
arch/x86/kernel/alternative.c +28 -2
@@ -28,6 +28,7 @@#include <asm/insn.h> #include <asm/io.h> #include <asm/fixmap.h> +#include <asm/paravirt.h> int __read_mostly alternatives_patched;
@@ -733,6 +734,33 @@ void __init alternative_instructions(void)* patching. */ +/* +* Paravirt patching and alternative patching can be combined to +* replace a function call with a short direct code sequence (e.g. +* by setting a constant return value instead of doing that in an +* external function). +* In order to make this work the following sequence is required: +* 1. set (artificial) features depending on used paravirt +* functions which can later influence alternative patching +* 2. apply paravirt patching (generally replacing an indirect +* function call with a direct one) +* 3. apply alternative patching (e.g. replacing a direct function +* call with a custom code sequence) +* Doing paravirt patching after alternative patching would clobber +* the optimization of the custom code with a function call again. +*/ +paravirt_set_cap (); + +/* +* First patch paravirt functions, such that we overwrite the indirect +* call with the direct call. +*/ +apply_paravirt (__parainstructions, __parainstructions_end); + +/* +* Then patch alternatives, such that those paravirt calls that are in +* alternatives can be overwritten by their immediate fragments. +*/ apply_alternatives (__alt_instructions, __alt_instructions_end);#ifdef CONFIG_SMP
@@ -751,8 +779,6 @@ void __init alternative_instructions(void) }#endif -apply_paravirt (__parainstructions, __parainstructions_end); -restart_nmi (); alternatives_patched =1 ; }
arch/x86/kernel/paravirt-spinlocks.c +9 -0
@@ -32,3 +32,12 @@ bool pv_is_native_vcpu_is_preempted(void)return pv_ops.lock.vcpu_is_preempted.func == __raw_callee_save___native_vcpu_is_preempted; } + +void __init paravirt_set_cap (void ) +{ +if (!pv_is_native_spin_unlock ()) +setup_force_cpu_cap (X86_FEATURE_PVUNLOCK ); + +if (!pv_is_native_vcpu_is_preempted ()) +setup_force_cpu_cap (X86_FEATURE_VCPUPREEMPT ); +}
Signature · 6 lines
2.26.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
[tip: x86/alternatives] x86/paravirt: Add new features for paravirt patching
The following commit has been merged into the x86/alternatives branch of tip:
The following commit has been merged into the x86/alternatives branch of tip:
Commit-ID: 4e6292114c741221479046515b1aa8145cf1e3f6 Gitweb: https://git.kernel.org/tip/4e6292114c741221479046515b1aa8145cf1e3f6 Author: Juergen Gross <[email protected]> AuthorDate: Thu, 11 Mar 2021 15:23:13 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 11 Mar 2021 19:51:49 +01:00
x86/paravirt: Add new features for paravirt patching
For being able to switch paravirt patching from special cased custom code sequences to ALTERNATIVE handling some X86_FEATURE_* are needed as new features. This enables to have the standard indirect pv call as the default code and to patch that with the non-Xen custom code sequence via ALTERNATIVE patching later.
Make sure paravirt patching is performed before alternatives patching.
--- arch/x86/include/asm/cpufeatures.h | 2 ++- arch/x86/include/asm/paravirt.h | 10 +++++++++- arch/x86/kernel/alternative.c | 30 +++++++++++++++++++++++++-- arch/x86/kernel/paravirt-spinlocks.c | 9 ++++++++- 4 files changed, 49 insertions(+), 2 deletions(-)
arch/x86/include/asm/cpufeatures.h +2 -0
@@ -236,6 +236,8 @@#define X86_FEATURE_EPT_AD ( 8*32+17)/* Intel Extended Page Table access-dirty bit */ #define X86_FEATURE_VMCALL ( 8*32+18)/* "" Hypervisor supports the VMCALL instruction */ #define X86_FEATURE_VMW_VMMCALL ( 8*32+19)/* "" VMware prefers VMMCALL hypercall instruction */ +#define X86_FEATURE_PVUNLOCK ( 8*32+20)/* "" PV unlock function */ +#define X86_FEATURE_VCPUPREEMPT ( 8*32+21)/* "" PV vcpu_is_preempted function */ /* Intel-defined CPU features, CPUID level 0x00000007:0 (EBX), word 9 */ #define X86_FEATURE_FSGSBASE ( 9*32+ 0)/* RDFSBASE, WRFSBASE, RDGSBASE, WRGSBASE instructions*/
arch/x86/include/asm/paravirt.h +10 -0
@@ -45,6 +45,10 @@ static inline u64 paravirt_steal_clock(int cpu)return static_call (pv_steal_clock)(cpu); } +#ifdef CONFIG_PARAVIRT_SPINLOCKS +void __init paravirt_set_cap (void ); +#endif +/* The paravirtualized I/O functions */ static inline void slow_down_io (void ) {
@@ -809,5 +813,11 @@ static inline void paravirt_arch_exit_mmap(struct mm_struct *mm) { }#endif + +#ifndef CONFIG_PARAVIRT_SPINLOCKS +static inline void paravirt_set_cap (void ) +{ +} +#endif #endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_PARAVIRT_H */
arch/x86/kernel/alternative.c +28 -2
@@ -28,6 +28,7 @@#include <asm/insn.h> #include <asm/io.h> #include <asm/fixmap.h> +#include <asm/paravirt.h> int __read_mostly alternatives_patched;
@@ -733,6 +734,33 @@ void __init alternative_instructions(void)* patching. */ +/* +* Paravirt patching and alternative patching can be combined to +* replace a function call with a short direct code sequence (e.g. +* by setting a constant return value instead of doing that in an +* external function). +* In order to make this work the following sequence is required: +* 1. set (artificial) features depending on used paravirt +* functions which can later influence alternative patching +* 2. apply paravirt patching (generally replacing an indirect +* function call with a direct one) +* 3. apply alternative patching (e.g. replacing a direct function +* call with a custom code sequence) +* Doing paravirt patching after alternative patching would clobber +* the optimization of the custom code with a function call again. +*/ +paravirt_set_cap (); + +/* +* First patch paravirt functions, such that we overwrite the indirect +* call with the direct call. +*/ +apply_paravirt (__parainstructions, __parainstructions_end); + +/* +* Then patch alternatives, such that those paravirt calls that are in +* alternatives can be overwritten by their immediate fragments. +*/ apply_alternatives (__alt_instructions, __alt_instructions_end);#ifdef CONFIG_SMP
@@ -751,8 +779,6 @@ void __init alternative_instructions(void) }#endif -apply_paravirt (__parainstructions, __parainstructions_end); -restart_nmi (); alternatives_patched =1 ; }
arch/x86/kernel/paravirt-spinlocks.c +9 -0
@@ -32,3 +32,12 @@ bool pv_is_native_vcpu_is_preempted(void)return pv_ops.lock.vcpu_is_preempted.func == __raw_callee_save___native_vcpu_is_preempted; } + +void __init paravirt_set_cap (void ) +{ +if (!pv_is_native_spin_unlock ()) +setup_force_cpu_cap (X86_FEATURE_PVUNLOCK ); + +if (!pv_is_native_vcpu_is_preempted ()) +setup_force_cpu_cap (X86_FEATURE_VCPUPREEMPT ); +}
Juergen Gross
maintainerPATCH v7 9/14 x86/paravirt: remove no longer needed 32-bit pvops cruft
In reply to Juergen GrossPVOP_VCALL4() is only used for Xen PV, while PVOP_CALL4() isn't used at all. Keep PVOP_CALL4() for 64 bits due to symmetry reasons.
This allows to remove the 32-bit definitions of those macros leading to a substantial simplification of the paravirt macros, as those were the only ones needing non-empty "pre" and "post" parameters.
PVOP_CALLEE2() and PVOP_VCALLEE2() are used nowhere, so remove them.
Another no longer needed case is special handling of return types larger than unsigned long. Replace that with a BUILD_BUG_ON().
DISABLE_INTERRUPTS() is used in 32-bit code only, so it can just be replaced by cli.
INTERRUPT_RETURN in 32-bit code can be replaced by iret.
ENABLE_INTERRUPTS is used nowhere, so it can be removed.
--- arch/x86/entry/entry_32.S | 4 +- arch/x86/include/asm/irqflags.h | 5 -- arch/x86/include/asm/paravirt.h | 35 +------- arch/x86/include/asm/paravirt_types.h | 112 ++++++++------------------ arch/x86/kernel/asm-offsets.c | 2 - 5 files changed, 35 insertions(+), 123 deletions(-)
arch/x86/entry/entry_32.S +2 -2
@@ -430,7 +430,7 @@ * will soon execute iret and the tracer was already set to * the irqstate after the IRET: */ - DISABLE_INTERRUPTS(CLBR_ANY) + cli lss (%esp), %esp /* switch to espfix segment */ .Lend_\@: #endif /* CONFIG_X86_ESPFIX32 */
@@ -1077,7 +1077,7 @@ restore_all_switch_stack: * when returning from IPI handler and when returning from * scheduler to user-space. */ - INTERRUPT_RETURN + iret .section .fixup, "ax" SYM_CODE_START(asm_iret_error)
arch/x86/include/asm/irqflags.h +0 -5
@@ -109,9 +109,6 @@ static __always_inline unsigned long arch_local_irq_save(void) }#else -#define ENABLE_INTERRUPTS (x) sti -#define DISABLE_INTERRUPTS (x) cli -#ifdef CONFIG_X86_64 #ifdef CONFIG_DEBUG_ENTRY #define SAVE_FLAGS (x) pushfq; popq %rax
@@ -119,8 +116,6 @@ static __always_inline unsigned long arch_local_irq_save(void)#define INTERRUPT_RETURN jmp native_iret -#else -#define INTERRUPT_RETURN iret#endif #endif /* __ASSEMBLY__ */
arch/x86/include/asm/paravirt.h +1 -34
@@ -719,6 +719,7 @@ extern void default_banner(void); .if ((~(set)) & mask); pop %reg; .endif#ifdef CONFIG_X86_64 +#ifdef CONFIG_PARAVIRT_XXL #define PV_SAVE_REGS (set) \ COND_PUSH(set, CLBR_RAX, rax); \
@@ -744,46 +745,12 @@ extern void default_banner(void);#define PARA_PATCH (off) ((off) / 8)#define PARA_SITE (ptype, ops) _PVSITE(ptype, ops, .quad, 8)#define PARA_INDIRECT (addr) *addr(%rip) -#else -#define PV_SAVE_REGS (set) \ - COND_PUSH(set, CLBR_EAX, eax); \ - COND_PUSH(set, CLBR_EDI, edi); \ - COND_PUSH(set, CLBR_ECX, ecx); \ - COND_PUSH(set, CLBR_EDX, edx) -#define PV_RESTORE_REGS (set) \ - COND_POP(set, CLBR_EDX, edx); \ - COND_POP(set, CLBR_ECX, ecx); \ - COND_POP(set, CLBR_EDI, edi); \ - COND_POP(set, CLBR_EAX, eax) - -#define PARA_PATCH (off) ((off) / 4) -#define PARA_SITE (ptype, ops) _PVSITE(ptype, ops, .long, 4) -#define PARA_INDIRECT (addr) *%cs:addr -#endif -#ifdef CONFIG_PARAVIRT_XXL #define INTERRUPT_RETURN \ PARA_SITE(PARA_PATCH(PV_CPU_iret), \ ANNOTATE_RETPOLINE_SAFE; \ jmp PARA_INDIRECT(pv_ops+PV_CPU_iret);) -#define DISABLE_INTERRUPTS (clobbers) \ - PARA_SITE(PARA_PATCH(PV_IRQ_irq_disable), \ - PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \ - ANNOTATE_RETPOLINE_SAFE; \ - call PARA_INDIRECT(pv_ops+PV_IRQ_irq_disable); \ - PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);) - -#define ENABLE_INTERRUPTS (clobbers) \ - PARA_SITE(PARA_PATCH(PV_IRQ_irq_enable), \ - PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \ - ANNOTATE_RETPOLINE_SAFE; \ - call PARA_INDIRECT(pv_ops+PV_IRQ_irq_enable); \ - PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);) -#endif - -#ifdef CONFIG_X86_64 -#ifdef CONFIG_PARAVIRT_XXL #ifdef CONFIG_DEBUG_ENTRY #define SAVE_FLAGS (clobbers) \ PARA_SITE(PARA_PATCH(PV_IRQ_save_fl), \
arch/x86/include/asm/paravirt_types.h +32 -80
171 lines not on this page · raw message
arch/x86/kernel/asm-offsets.c +0 -2
@@ -63,8 +63,6 @@ static void __used common(void)#ifdef CONFIG_PARAVIRT_XXL BLANK (); -OFFSET (PV_IRQ_irq_disable, paravirt_patch_template, irq.irq_disable); -OFFSET (PV_IRQ_irq_enable, paravirt_patch_template, irq.irq_enable);OFFSET (PV_CPU_iret, paravirt_patch_template, cpu.iret);#endif
Signature · 6 lines
2.26.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
[tip: x86/alternatives] x86/paravirt: Remove no longer needed 32-bit pvops cruft
The following commit has been merged into the x86/alternatives branch of tip:
The following commit has been merged into the x86/alternatives branch of tip:
Commit-ID: 33634e42e38be61f320183dfc264b9caba292d4e Gitweb: https://git.kernel.org/tip/33634e42e38be61f320183dfc264b9caba292d4e Author: Juergen Gross <[email protected]> AuthorDate: Thu, 11 Mar 2021 15:23:14 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 11 Mar 2021 19:51:55 +01:00
x86/paravirt: Remove no longer needed 32-bit pvops cruft
PVOP_VCALL4() is only used for Xen PV, while PVOP_CALL4() isn't used at all. Keep PVOP_CALL4() for 64 bits due to symmetry reasons.
This allows to remove the 32-bit definitions of those macros leading to a substantial simplification of the paravirt macros, as those were the only ones needing non-empty "pre" and "post" parameters.
PVOP_CALLEE2() and PVOP_VCALLEE2() are used nowhere, so remove them.
Another no longer needed case is special handling of return types larger than unsigned long. Replace that with a BUILD_BUG_ON().
DISABLE_INTERRUPTS() is used in 32-bit code only, so it can just be replaced by cli.
INTERRUPT_RETURN in 32-bit code can be replaced by iret.
ENABLE_INTERRUPTS is used nowhere, so it can be removed.
--- arch/x86/entry/entry_32.S | 4 +- arch/x86/include/asm/irqflags.h | 5 +- arch/x86/include/asm/paravirt.h | 35 +-------- arch/x86/include/asm/paravirt_types.h | 112 +++++++------------------ arch/x86/kernel/asm-offsets.c | 2 +- 5 files changed, 35 insertions(+), 123 deletions(-)
arch/x86/entry/entry_32.S +2 -2
@@ -430,7 +430,7 @@ * will soon execute iret and the tracer was already set to * the irqstate after the IRET: */ - DISABLE_INTERRUPTS(CLBR_ANY) + cli lss (%esp), %esp /* switch to espfix segment */ .Lend_\@: #endif /* CONFIG_X86_ESPFIX32 */
@@ -1077,7 +1077,7 @@ restore_all_switch_stack: * when returning from IPI handler and when returning from * scheduler to user-space. */ - INTERRUPT_RETURN + iret .section .fixup, "ax" SYM_CODE_START(asm_iret_error)
arch/x86/include/asm/irqflags.h +0 -5
@@ -109,9 +109,6 @@ static __always_inline unsigned long arch_local_irq_save(void) }#else -#define ENABLE_INTERRUPTS (x) sti -#define DISABLE_INTERRUPTS (x) cli -#ifdef CONFIG_X86_64 #ifdef CONFIG_DEBUG_ENTRY #define SAVE_FLAGS (x) pushfq; popq %rax
@@ -119,8 +116,6 @@ static __always_inline unsigned long arch_local_irq_save(void)#define INTERRUPT_RETURN jmp native_iret -#else -#define INTERRUPT_RETURN iret#endif #endif /* __ASSEMBLY__ */
arch/x86/include/asm/paravirt.h +1 -34
@@ -719,6 +719,7 @@ extern void default_banner(void); .if ((~(set)) & mask); pop %reg; .endif#ifdef CONFIG_X86_64 +#ifdef CONFIG_PARAVIRT_XXL #define PV_SAVE_REGS (set) \ COND_PUSH(set, CLBR_RAX, rax); \
@@ -744,46 +745,12 @@ extern void default_banner(void);#define PARA_PATCH (off) ((off) / 8)#define PARA_SITE (ptype, ops) _PVSITE(ptype, ops, .quad, 8)#define PARA_INDIRECT (addr) *addr(%rip) -#else -#define PV_SAVE_REGS (set) \ - COND_PUSH(set, CLBR_EAX, eax); \ - COND_PUSH(set, CLBR_EDI, edi); \ - COND_PUSH(set, CLBR_ECX, ecx); \ - COND_PUSH(set, CLBR_EDX, edx) -#define PV_RESTORE_REGS (set) \ - COND_POP(set, CLBR_EDX, edx); \ - COND_POP(set, CLBR_ECX, ecx); \ - COND_POP(set, CLBR_EDI, edi); \ - COND_POP(set, CLBR_EAX, eax) - -#define PARA_PATCH (off) ((off) / 4) -#define PARA_SITE (ptype, ops) _PVSITE(ptype, ops, .long, 4) -#define PARA_INDIRECT (addr) *%cs:addr -#endif -#ifdef CONFIG_PARAVIRT_XXL #define INTERRUPT_RETURN \ PARA_SITE(PARA_PATCH(PV_CPU_iret), \ ANNOTATE_RETPOLINE_SAFE; \ jmp PARA_INDIRECT(pv_ops+PV_CPU_iret);) -#define DISABLE_INTERRUPTS (clobbers) \ - PARA_SITE(PARA_PATCH(PV_IRQ_irq_disable), \ - PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \ - ANNOTATE_RETPOLINE_SAFE; \ - call PARA_INDIRECT(pv_ops+PV_IRQ_irq_disable); \ - PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);) - -#define ENABLE_INTERRUPTS (clobbers) \ - PARA_SITE(PARA_PATCH(PV_IRQ_irq_enable), \ - PV_SAVE_REGS(clobbers | CLBR_CALLEE_SAVE); \ - ANNOTATE_RETPOLINE_SAFE; \ - call PARA_INDIRECT(pv_ops+PV_IRQ_irq_enable); \ - PV_RESTORE_REGS(clobbers | CLBR_CALLEE_SAVE);) -#endif - -#ifdef CONFIG_X86_64 -#ifdef CONFIG_PARAVIRT_XXL #ifdef CONFIG_DEBUG_ENTRY #define SAVE_FLAGS (clobbers) \ PARA_SITE(PARA_PATCH(PV_IRQ_save_fl), \
arch/x86/include/asm/paravirt_types.h +32 -80
171 lines not on this page · raw message
arch/x86/kernel/asm-offsets.c +0 -2
@@ -63,8 +63,6 @@ static void __used common(void)#ifdef CONFIG_PARAVIRT_XXL BLANK (); -OFFSET (PV_IRQ_irq_disable, paravirt_patch_template, irq.irq_disable); -OFFSET (PV_IRQ_irq_enable, paravirt_patch_template, irq.irq_enable);OFFSET (PV_CPU_iret, paravirt_patch_template, cpu.iret);#endif
Juergen Gross
maintainerPATCH v7 10/14 x86/paravirt: simplify paravirt macros
In reply to Juergen GrossThe central pvops call macros ____PVOP_CALL() and ____PVOP_VCALL() are looking very similar now.
The main differences are using PVOP_VCALL_ARGS or PVOP_CALL_ARGS, which are identical, and the return value handling.
So drop PVOP_VCALL_ARGS and instead of ____PVOP_VCALL() just use (void)____PVOP_CALL(long, ...).
Note that it isn't easily possible to just redefine ____PVOP_VCALL() to use ____PVOP_CALL() instead, as this would require further hiding of commas in macro parameters.
---
V3:
- new patch
V4:
- fix build warnings with clang (kernel test robot)
--- arch/x86/include/asm/paravirt_types.h | 41 ++++++++------------------- 1 file changed, 12 insertions(+), 29 deletions(-)
arch/x86/include/asm/paravirt_types.h +12 -29
@@ -408,11 +408,9 @@ int paravirt_disable_iospace(void);* makes sure the incoming and outgoing types are always correct. */ #ifdef CONFIG_X86_32 -#define PVOP_VCALL_ARGS \ +#define PVOP_CALL_ARGS \ unsigned long __eax = __eax, __edx = __edx, __ecx = __ecx; -#define PVOP_CALL_ARGS PVOP_VCALL_ARGS -#define PVOP_CALL_ARG1 (x) "a" ((unsigned long)(x))#define PVOP_CALL_ARG2 (x) "d" ((unsigned long)(x))#define PVOP_CALL_ARG3 (x) "c" ((unsigned long)(x))
@@ -428,12 +426,10 @@ int paravirt_disable_iospace(void);#define VEXTRA_CLOBBERS #else /* CONFIG_X86_64 */ /* [re]ax isn't an arg, but the return val */ -#define PVOP_VCALL_ARGS \ +#define PVOP_CALL_ARGS \ unsigned long __edi = __edi, __esi = __esi, \ __edx = __edx, __ecx = __ecx, __eax = __eax; -#define PVOP_CALL_ARGS PVOP_VCALL_ARGS -#define PVOP_CALL_ARG1 (x) "D" ((unsigned long)(x))#define PVOP_CALL_ARG2 (x) "S" ((unsigned long)(x))#define PVOP_CALL_ARG3 (x) "d" ((unsigned long)(x))
@@ -458,59 +454,46 @@ int paravirt_disable_iospace(void);#define PVOP_TEST_NULL (op) ((void)pv_ops.op)#endif -#define PVOP_RETMASK (rettype) \ +#define PVOP_RETVAL (rettype) \ ({ unsigned long __mask = ~0UL; \ + BUILD_BUG_ON(sizeof(rettype) > sizeof(unsigned long)); \ switch (sizeof(rettype)) { \ case 1: __mask = 0xffUL; break; \ case 2: __mask = 0xffffUL; break; \ case 4: __mask = 0xffffffffUL; break; \ default: break; \ } \ - __mask; \ + __mask & __eax; \ }) -#define ____PVOP_CALL (rettype, op, clbr, call_clbr, extra_clbr, ...) \ +#define ____PVOP_CALL (ret, op, clbr, call_clbr, extra_clbr, ...) \ ({ \ PVOP_CALL_ARGS; \ PVOP_TEST_NULL(op); \ - BUILD_BUG_ON(sizeof(rettype) > sizeof(unsigned long)); \ asm volatile(paravirt_alt(PARAVIRT_CALL) \ : call_clbr, ASM_CALL_CONSTRAINT \ : paravirt_type(op), \ paravirt_clobber(clbr), \ ##__VA_ARGS__ \ : "memory", "cc" extra_clbr); \ - (rettype)(__eax & PVOP_RETMASK(rettype)); \ + ret; \ })#define __PVOP_CALL (rettype, op, ...) \ - ____PVOP_CALL(rettype, op, CLBR_ANY, PVOP_CALL_CLOBBERS, \ - EXTRA_CLOBBERS, ##__VA_ARGS__) + ____PVOP_CALL(PVOP_RETVAL(rettype), op, CLBR_ANY, \ + PVOP_CALL_CLOBBERS, EXTRA_CLOBBERS, ##__VA_ARGS__)#define __PVOP_CALLEESAVE (rettype, op, ...) \ - ____PVOP_CALL(rettype, op.func, CLBR_RET_REG, \ + ____PVOP_CALL(PVOP_RETVAL(rettype), op.func, CLBR_RET_REG, \ PVOP_CALLEE_CLOBBERS, , ##__VA_ARGS__) - -#define ____PVOP_VCALL (op, clbr, call_clbr, extra_clbr, ...) \ - ({ \ - PVOP_VCALL_ARGS; \ - PVOP_TEST_NULL(op); \ - asm volatile(paravirt_alt(PARAVIRT_CALL) \ - : call_clbr, ASM_CALL_CONSTRAINT \ - : paravirt_type(op), \ - paravirt_clobber(clbr), \ - ##__VA_ARGS__ \ - : "memory", "cc" extra_clbr); \ - }) -#define __PVOP_VCALL (op, ...) \ - ____PVOP_VCALL(op, CLBR_ANY, PVOP_VCALL_CLOBBERS, \ + (void)____PVOP_CALL(, op, CLBR_ANY, PVOP_VCALL_CLOBBERS, \ VEXTRA_CLOBBERS, ##__VA_ARGS__)#define __PVOP_VCALLEESAVE (op, ...) \ - ____PVOP_VCALL(op.func, CLBR_RET_REG, \ + (void)____PVOP_CALL(, op.func, CLBR_RET_REG, \ PVOP_VCALLEE_CLOBBERS, , ##__VA_ARGS__)
Signature · 6 lines
2.26.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
[tip: x86/alternatives] x86/paravirt: Simplify paravirt macros
The following commit has been merged into the x86/alternatives branch of tip:
The following commit has been merged into the x86/alternatives branch of tip:
Commit-ID: 0b8d366a942fd48a83dfa728e9f8a8d8b20e735f Gitweb: https://git.kernel.org/tip/0b8d366a942fd48a83dfa728e9f8a8d8b20e735f Author: Juergen Gross <[email protected]> AuthorDate: Thu, 11 Mar 2021 15:23:15 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 11 Mar 2021 19:52:52 +01:00
x86/paravirt: Simplify paravirt macros
The central pvops call macros ____PVOP_CALL() and ____PVOP_VCALL() are looking very similar now.
The main differences are using PVOP_VCALL_ARGS or PVOP_CALL_ARGS, which are identical, and the return value handling.
So drop PVOP_VCALL_ARGS and instead of ____PVOP_VCALL() just use (void)____PVOP_CALL(long, ...).
Note that it isn't easily possible to just redefine ____PVOP_VCALL() to use ____PVOP_CALL() instead, as this would require further hiding of commas in macro parameters.
--- arch/x86/include/asm/paravirt_types.h | 41 +++++++------------------- 1 file changed, 12 insertions(+), 29 deletions(-)
arch/x86/include/asm/paravirt_types.h +12 -29
@@ -408,11 +408,9 @@ int paravirt_disable_iospace(void);* makes sure the incoming and outgoing types are always correct. */ #ifdef CONFIG_X86_32 -#define PVOP_VCALL_ARGS \ +#define PVOP_CALL_ARGS \ unsigned long __eax = __eax, __edx = __edx, __ecx = __ecx; -#define PVOP_CALL_ARGS PVOP_VCALL_ARGS -#define PVOP_CALL_ARG1 (x) "a" ((unsigned long)(x))#define PVOP_CALL_ARG2 (x) "d" ((unsigned long)(x))#define PVOP_CALL_ARG3 (x) "c" ((unsigned long)(x))
@@ -428,12 +426,10 @@ int paravirt_disable_iospace(void);#define VEXTRA_CLOBBERS #else /* CONFIG_X86_64 */ /* [re]ax isn't an arg, but the return val */ -#define PVOP_VCALL_ARGS \ +#define PVOP_CALL_ARGS \ unsigned long __edi = __edi, __esi = __esi, \ __edx = __edx, __ecx = __ecx, __eax = __eax; -#define PVOP_CALL_ARGS PVOP_VCALL_ARGS -#define PVOP_CALL_ARG1 (x) "D" ((unsigned long)(x))#define PVOP_CALL_ARG2 (x) "S" ((unsigned long)(x))#define PVOP_CALL_ARG3 (x) "d" ((unsigned long)(x))
@@ -458,59 +454,46 @@ int paravirt_disable_iospace(void);#define PVOP_TEST_NULL (op) ((void)pv_ops.op)#endif -#define PVOP_RETMASK (rettype) \ +#define PVOP_RETVAL (rettype) \ ({ unsigned long __mask = ~0UL; \ + BUILD_BUG_ON(sizeof(rettype) > sizeof(unsigned long)); \ switch (sizeof(rettype)) { \ case 1: __mask = 0xffUL; break; \ case 2: __mask = 0xffffUL; break; \ case 4: __mask = 0xffffffffUL; break; \ default: break; \ } \ - __mask; \ + __mask & __eax; \ }) -#define ____PVOP_CALL (rettype, op, clbr, call_clbr, extra_clbr, ...) \ +#define ____PVOP_CALL (ret, op, clbr, call_clbr, extra_clbr, ...) \ ({ \ PVOP_CALL_ARGS; \ PVOP_TEST_NULL(op); \ - BUILD_BUG_ON(sizeof(rettype) > sizeof(unsigned long)); \ asm volatile(paravirt_alt(PARAVIRT_CALL) \ : call_clbr, ASM_CALL_CONSTRAINT \ : paravirt_type(op), \ paravirt_clobber(clbr), \ ##__VA_ARGS__ \ : "memory", "cc" extra_clbr); \ - (rettype)(__eax & PVOP_RETMASK(rettype)); \ + ret; \ })#define __PVOP_CALL (rettype, op, ...) \ - ____PVOP_CALL(rettype, op, CLBR_ANY, PVOP_CALL_CLOBBERS, \ - EXTRA_CLOBBERS, ##__VA_ARGS__) + ____PVOP_CALL(PVOP_RETVAL(rettype), op, CLBR_ANY, \ + PVOP_CALL_CLOBBERS, EXTRA_CLOBBERS, ##__VA_ARGS__)#define __PVOP_CALLEESAVE (rettype, op, ...) \ - ____PVOP_CALL(rettype, op.func, CLBR_RET_REG, \ + ____PVOP_CALL(PVOP_RETVAL(rettype), op.func, CLBR_RET_REG, \ PVOP_CALLEE_CLOBBERS, , ##__VA_ARGS__) - -#define ____PVOP_VCALL (op, clbr, call_clbr, extra_clbr, ...) \ - ({ \ - PVOP_VCALL_ARGS; \ - PVOP_TEST_NULL(op); \ - asm volatile(paravirt_alt(PARAVIRT_CALL) \ - : call_clbr, ASM_CALL_CONSTRAINT \ - : paravirt_type(op), \ - paravirt_clobber(clbr), \ - ##__VA_ARGS__ \ - : "memory", "cc" extra_clbr); \ - }) -#define __PVOP_VCALL (op, ...) \ - ____PVOP_VCALL(op, CLBR_ANY, PVOP_VCALL_CLOBBERS, \ + (void)____PVOP_CALL(, op, CLBR_ANY, PVOP_VCALL_CLOBBERS, \ VEXTRA_CLOBBERS, ##__VA_ARGS__)#define __PVOP_VCALLEESAVE (op, ...) \ - ____PVOP_VCALL(op.func, CLBR_RET_REG, \ + (void)____PVOP_CALL(, op.func, CLBR_RET_REG, \ PVOP_VCALLEE_CLOBBERS, , ##__VA_ARGS__)
Juergen Gross
maintainerPATCH v7 11/14 x86/paravirt: switch iret pvops to ALTERNATIVE
In reply to Juergen GrossThe iret paravirt op is rather special as it is using a jmp instead of a call instruction. Switch it to ALTERNATIVE.
---
V3:
- use ALTERNATIVE_TERNARY
--- arch/x86/include/asm/paravirt.h | 6 +++--- arch/x86/include/asm/paravirt_types.h | 5 +---- arch/x86/kernel/asm-offsets.c | 5 ----- arch/x86/kernel/paravirt.c | 26 ++------------------------ arch/x86/xen/enlighten_pv.c | 3 +-- 5 files changed, 7 insertions(+), 38 deletions(-)
arch/x86/include/asm/paravirt.h +3 -3
@@ -747,9 +747,9 @@ extern void default_banner(void);#define PARA_INDIRECT (addr) *addr(%rip)#define INTERRUPT_RETURN \ - PARA_SITE(PARA_PATCH(PV_CPU_iret), \ - ANNOTATE_RETPOLINE_SAFE; \ - jmp PARA_INDIRECT(pv_ops+PV_CPU_iret);) + ANNOTATE_RETPOLINE_SAFE; \ + ALTERNATIVE_TERNARY("jmp *paravirt_iret(%rip);", \ + X86_FEATURE_XENPV, "jmp xen_iret;", "jmp native_iret;")#ifdef CONFIG_DEBUG_ENTRY #define SAVE_FLAGS (clobbers) \
arch/x86/include/asm/paravirt_types.h +1 -4
@@ -151,10 +151,6 @@ struct pv_cpu_ops {u64 (*read_pmc)(int counter); -/* Normal iret. Jump to this with the standard iret stack -frame set up. */ -void (*iret)(void ); -void (*start_context_switch)(struct task_struct *prev);void (*end_context_switch)(struct task_struct *next);#endif
@@ -294,6 +290,7 @@ struct paravirt_patch_template {extern struct pv_info pv_info;extern struct paravirt_patch_template pv_ops; +extern void (*paravirt_iret)(void );#define PARAVIRT_PATCH (x) \ (offsetof(struct paravirt_patch_template, x) / sizeof(void *))
arch/x86/kernel/asm-offsets.c +0 -5
@@ -61,11 +61,6 @@ static void __used common(void)OFFSET (IA32_RT_SIGFRAME_sigcontext, rt_sigframe_ia32, uc.uc_mcontext);#endif -#ifdef CONFIG_PARAVIRT_XXL -BLANK (); -OFFSET (PV_CPU_iret, paravirt_patch_template, cpu.iret); -#endif -#ifdef CONFIG_XEN BLANK ();OFFSET (XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
arch/x86/kernel/paravirt.c +2 -24
@@ -86,25 +86,6 @@ u64 notrace _paravirt_ident_64(u64 x) {return x; } - -static unsigned paravirt_patch_jmp (void *insn_buff,const void *target, -unsigned long addr,unsigned len) -{ -struct branch *b = insn_buff; -unsigned long delta = (unsigned long )target - (addr+5 ); - -if (len <5 ) { -#ifdef CONFIG_RETPOLINE -WARN_ONCE (1 ,"Failing to patch indirect JMP in %ps\n" , (void *)addr); -#endif -return len;/* call too long for patch site */ - } - - b->opcode =0xe9 ;/* jmp */ - b->delta = delta; - -return 5 ; -}#endif DEFINE_STATIC_KEY_TRUE (virt_spin_lock_key);
@@ -136,9 +117,6 @@ unsigned paravirt_patch_default(u8 type, void *insn_buff, else if (opfunc == _paravirt_ident_64) ret =paravirt_patch_ident_64 (insn_buff, len); - else if (type == PARAVIRT_PATCH(cpu.iret)) -/* If operation requires a jmp, then jmp */ - ret =paravirt_patch_jmp (insn_buff, opfunc, addr, len);#endif else/* Otherwise call the function. */
@@ -313,8 +291,6 @@ struct paravirt_patch_template pv_ops = { .cpu.load_sp0 = native_load_sp0, - .cpu.iret = native_iret, - #ifdef CONFIG_X86_IOPL_IOPERM .cpu.invalidate_io_bitmap = native_tss_invalidate_io_bitmap, .cpu.update_io_bitmap = native_tss_update_io_bitmap,
@@ -419,6 +395,8 @@ struct paravirt_patch_template pv_ops = {NOKPROBE_SYMBOL (native_get_debugreg);NOKPROBE_SYMBOL (native_set_debugreg);NOKPROBE_SYMBOL (native_load_idt); + +void (*paravirt_iret)(void ) = native_iret;#endif EXPORT_SYMBOL (pv_ops);
arch/x86/xen/enlighten_pv.c +1 -2
@@ -1070,8 +1070,6 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = { .read_pmc = xen_read_pmc, - .iret = xen_iret, - .load_tr_desc = paravirt_nop, .set_ldt = xen_set_ldt, .load_gdt = xen_load_gdt,
@@ -1235,6 +1233,7 @@ asmlinkage __visible void __init xen_start_kernel(void) pv_info = xen_info; pv_ops.init.patch = paravirt_patch_default; pv_ops.cpu = xen_cpu_ops; + paravirt_iret = xen_iret;xen_init_irq_ops ();/*
Signature · 6 lines
2.26.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
[tip: x86/alternatives] x86/paravirt: Switch iret pvops to ALTERNATIVE
The following commit has been merged into the x86/alternatives branch of tip:
The following commit has been merged into the x86/alternatives branch of tip:
Commit-ID: ae755b5a45482b5de4d96d6f35823076af77445e Gitweb: https://git.kernel.org/tip/ae755b5a45482b5de4d96d6f35823076af77445e Author: Juergen Gross <[email protected]> AuthorDate: Thu, 11 Mar 2021 15:23:16 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 11 Mar 2021 19:58:54 +01:00
x86/paravirt: Switch iret pvops to ALTERNATIVE
The iret paravirt op is rather special as it is using a jmp instead of a call instruction. Switch it to ALTERNATIVE.
--- arch/x86/include/asm/paravirt.h | 6 +++--- arch/x86/include/asm/paravirt_types.h | 5 +---- arch/x86/kernel/asm-offsets.c | 5 +----- arch/x86/kernel/paravirt.c | 26 ++------------------------ arch/x86/xen/enlighten_pv.c | 3 +-- 5 files changed, 7 insertions(+), 38 deletions(-)
arch/x86/include/asm/paravirt.h +3 -3
@@ -747,9 +747,9 @@ extern void default_banner(void);#define PARA_INDIRECT (addr) *addr(%rip)#define INTERRUPT_RETURN \ - PARA_SITE(PARA_PATCH(PV_CPU_iret), \ - ANNOTATE_RETPOLINE_SAFE; \ - jmp PARA_INDIRECT(pv_ops+PV_CPU_iret);) + ANNOTATE_RETPOLINE_SAFE; \ + ALTERNATIVE_TERNARY("jmp *paravirt_iret(%rip);", \ + X86_FEATURE_XENPV, "jmp xen_iret;", "jmp native_iret;")#ifdef CONFIG_DEBUG_ENTRY #define SAVE_FLAGS (clobbers) \
arch/x86/include/asm/paravirt_types.h +1 -4
@@ -151,10 +151,6 @@ struct pv_cpu_ops {u64 (*read_pmc)(int counter); -/* Normal iret. Jump to this with the standard iret stack -frame set up. */ -void (*iret)(void ); -void (*start_context_switch)(struct task_struct *prev);void (*end_context_switch)(struct task_struct *next);#endif
@@ -294,6 +290,7 @@ struct paravirt_patch_template {extern struct pv_info pv_info;extern struct paravirt_patch_template pv_ops; +extern void (*paravirt_iret)(void );#define PARAVIRT_PATCH (x) \ (offsetof(struct paravirt_patch_template, x) / sizeof(void *))
arch/x86/kernel/asm-offsets.c +0 -5
@@ -61,11 +61,6 @@ static void __used common(void)OFFSET (IA32_RT_SIGFRAME_sigcontext, rt_sigframe_ia32, uc.uc_mcontext);#endif -#ifdef CONFIG_PARAVIRT_XXL -BLANK (); -OFFSET (PV_CPU_iret, paravirt_patch_template, cpu.iret); -#endif -#ifdef CONFIG_XEN BLANK ();OFFSET (XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
arch/x86/kernel/paravirt.c +2 -24
@@ -86,25 +86,6 @@ u64 notrace _paravirt_ident_64(u64 x) {return x; } - -static unsigned paravirt_patch_jmp (void *insn_buff,const void *target, -unsigned long addr,unsigned len) -{ -struct branch *b = insn_buff; -unsigned long delta = (unsigned long )target - (addr+5 ); - -if (len <5 ) { -#ifdef CONFIG_RETPOLINE -WARN_ONCE (1 ,"Failing to patch indirect JMP in %ps\n" , (void *)addr); -#endif -return len;/* call too long for patch site */ - } - - b->opcode =0xe9 ;/* jmp */ - b->delta = delta; - -return 5 ; -}#endif DEFINE_STATIC_KEY_TRUE (virt_spin_lock_key);
@@ -136,9 +117,6 @@ unsigned paravirt_patch_default(u8 type, void *insn_buff, else if (opfunc == _paravirt_ident_64) ret =paravirt_patch_ident_64 (insn_buff, len); - else if (type == PARAVIRT_PATCH(cpu.iret)) -/* If operation requires a jmp, then jmp */ - ret =paravirt_patch_jmp (insn_buff, opfunc, addr, len);#endif else/* Otherwise call the function. */
@@ -313,8 +291,6 @@ struct paravirt_patch_template pv_ops = { .cpu.load_sp0 = native_load_sp0, - .cpu.iret = native_iret, - #ifdef CONFIG_X86_IOPL_IOPERM .cpu.invalidate_io_bitmap = native_tss_invalidate_io_bitmap, .cpu.update_io_bitmap = native_tss_update_io_bitmap,
@@ -419,6 +395,8 @@ struct paravirt_patch_template pv_ops = {NOKPROBE_SYMBOL (native_get_debugreg);NOKPROBE_SYMBOL (native_set_debugreg);NOKPROBE_SYMBOL (native_load_idt); + +void (*paravirt_iret)(void ) = native_iret;#endif EXPORT_SYMBOL (pv_ops);
arch/x86/xen/enlighten_pv.c +1 -2
@@ -1070,8 +1070,6 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = { .read_pmc = xen_read_pmc, - .iret = xen_iret, - .load_tr_desc = paravirt_nop, .set_ldt = xen_set_ldt, .load_gdt = xen_load_gdt,
@@ -1235,6 +1233,7 @@ asmlinkage __visible void __init xen_start_kernel(void) pv_info = xen_info; pv_ops.init.patch = paravirt_patch_default; pv_ops.cpu = xen_cpu_ops; + paravirt_iret = xen_iret;xen_init_irq_ops ();/*
Juergen Gross
maintainerPATCH v7 12/14 x86/paravirt: add new macros PVOP_ALT* supporting pvops in ALTERNATIVEs
In reply to Juergen GrossInstead of using paravirt patching for custom code sequences add support for using ALTERNATIVE handling combined with paravirt call patching.
---
V3:
- drop ____PVOP_ALT_VCALL() macro
--- arch/x86/include/asm/paravirt_types.h | 49 ++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-)
arch/x86/include/asm/paravirt_types.h +48 -1
@@ -477,44 +477,91 @@ int paravirt_disable_iospace(void); ret; \ }) +#define ____PVOP_ALT_CALL (ret, op, alt, cond, clbr, call_clbr, \ + extra_clbr, ...) \ + ({ \ + PVOP_CALL_ARGS; \ + PVOP_TEST_NULL(op); \ + asm volatile(ALTERNATIVE(paravirt_alt(PARAVIRT_CALL), \ + alt, cond) \ + : call_clbr, ASM_CALL_CONSTRAINT \ + : paravirt_type(op), \ + paravirt_clobber(clbr), \ + ##__VA_ARGS__ \ + : "memory", "cc" extra_clbr); \ + ret; \ + }) +#define __PVOP_CALL (rettype, op, ...) \ ____PVOP_CALL(PVOP_RETVAL(rettype), op, CLBR_ANY, \ PVOP_CALL_CLOBBERS, EXTRA_CLOBBERS, ##__VA_ARGS__) +#define __PVOP_ALT_CALL (rettype, op, alt, cond, ...) \ + ____PVOP_ALT_CALL(PVOP_RETVAL(rettype), op, alt, cond, CLBR_ANY,\ + PVOP_CALL_CLOBBERS, EXTRA_CLOBBERS, \ + ##__VA_ARGS__) +#define __PVOP_CALLEESAVE (rettype, op, ...) \ ____PVOP_CALL(PVOP_RETVAL(rettype), op.func, CLBR_RET_REG, \ PVOP_CALLEE_CLOBBERS, , ##__VA_ARGS__) +#define __PVOP_ALT_CALLEESAVE (rettype, op, alt, cond, ...) \ + ____PVOP_ALT_CALL(PVOP_RETVAL(rettype), op.func, alt, cond, \ + CLBR_RET_REG, PVOP_CALLEE_CLOBBERS, , ##__VA_ARGS__) + +#define __PVOP_VCALL (op, ...) \ (void)____PVOP_CALL(, op, CLBR_ANY, PVOP_VCALL_CLOBBERS, \ VEXTRA_CLOBBERS, ##__VA_ARGS__) +#define __PVOP_ALT_VCALL (op, alt, cond, ...) \ + (void)____PVOP_ALT_CALL(, op, alt, cond, CLBR_ANY, \ + PVOP_VCALL_CLOBBERS, VEXTRA_CLOBBERS, \ + ##__VA_ARGS__) +#define __PVOP_VCALLEESAVE (op, ...) \ (void)____PVOP_CALL(, op.func, CLBR_RET_REG, \ - PVOP_VCALLEE_CLOBBERS, , ##__VA_ARGS__) + PVOP_VCALLEE_CLOBBERS, , ##__VA_ARGS__) +#define __PVOP_ALT_VCALLEESAVE (op, alt, cond, ...) \ + (void)____PVOP_ALT_CALL(, op.func, alt, cond, CLBR_RET_REG, \ + PVOP_VCALLEE_CLOBBERS, , ##__VA_ARGS__)#define PVOP_CALL0 (rettype, op) \ __PVOP_CALL(rettype, op)#define PVOP_VCALL0 (op) \ __PVOP_VCALL(op) +#define PVOP_ALT_CALL0 (rettype, op, alt, cond) \ + __PVOP_ALT_CALL(rettype, op, alt, cond) +#define PVOP_ALT_VCALL0 (op, alt, cond) \ + __PVOP_ALT_VCALL(op, alt, cond)#define PVOP_CALLEE0 (rettype, op) \ __PVOP_CALLEESAVE(rettype, op)#define PVOP_VCALLEE0 (op) \ __PVOP_VCALLEESAVE(op) +#define PVOP_ALT_CALLEE0 (rettype, op, alt, cond) \ + __PVOP_ALT_CALLEESAVE(rettype, op, alt, cond) +#define PVOP_ALT_VCALLEE0 (op, alt, cond) \ + __PVOP_ALT_VCALLEESAVE(op, alt, cond)#define PVOP_CALL1 (rettype, op, arg1) \ __PVOP_CALL(rettype, op, PVOP_CALL_ARG1(arg1))#define PVOP_VCALL1 (op, arg1) \ __PVOP_VCALL(op, PVOP_CALL_ARG1(arg1)) +#define PVOP_ALT_VCALL1 (op, arg1, alt, cond) \ + __PVOP_ALT_VCALL(op, alt, cond, PVOP_CALL_ARG1(arg1))#define PVOP_CALLEE1 (rettype, op, arg1) \ __PVOP_CALLEESAVE(rettype, op, PVOP_CALL_ARG1(arg1))#define PVOP_VCALLEE1 (op, arg1) \ __PVOP_VCALLEESAVE(op, PVOP_CALL_ARG1(arg1)) +#define PVOP_ALT_CALLEE1 (rettype, op, arg1, alt, cond) \ + __PVOP_ALT_CALLEESAVE(rettype, op, alt, cond, PVOP_CALL_ARG1(arg1)) +#define PVOP_ALT_VCALLEE1 (op, arg1, alt, cond) \ + __PVOP_ALT_VCALLEESAVE(op, alt, cond, PVOP_CALL_ARG1(arg1))#define PVOP_CALL2 (rettype, op, arg1, arg2) \
Signature · 6 lines
2.26.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
[tip: x86/alternatives] x86/paravirt: Add new PVOP_ALT* macros to support pvops in ALTERNATIVEs
The following commit has been merged into the x86/alternatives branch of tip:
The following commit has been merged into the x86/alternatives branch of tip:
Commit-ID: 00aa3193ab7a04b25bb8c68e377815696eb5bf56 Gitweb: https://git.kernel.org/tip/00aa3193ab7a04b25bb8c68e377815696eb5bf56 Author: Juergen Gross <[email protected]> AuthorDate: Thu, 11 Mar 2021 15:23:17 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 11 Mar 2021 20:05:44 +01:00
x86/paravirt: Add new PVOP_ALT* macros to support pvops in ALTERNATIVEs
Instead of using paravirt patching for custom code sequences add support for using ALTERNATIVE handling combined with paravirt call patching.
--- arch/x86/include/asm/paravirt_types.h | 49 +++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-)
arch/x86/include/asm/paravirt_types.h +48 -1
@@ -477,44 +477,91 @@ int paravirt_disable_iospace(void); ret; \ }) +#define ____PVOP_ALT_CALL (ret, op, alt, cond, clbr, call_clbr, \ + extra_clbr, ...) \ + ({ \ + PVOP_CALL_ARGS; \ + PVOP_TEST_NULL(op); \ + asm volatile(ALTERNATIVE(paravirt_alt(PARAVIRT_CALL), \ + alt, cond) \ + : call_clbr, ASM_CALL_CONSTRAINT \ + : paravirt_type(op), \ + paravirt_clobber(clbr), \ + ##__VA_ARGS__ \ + : "memory", "cc" extra_clbr); \ + ret; \ + }) +#define __PVOP_CALL (rettype, op, ...) \ ____PVOP_CALL(PVOP_RETVAL(rettype), op, CLBR_ANY, \ PVOP_CALL_CLOBBERS, EXTRA_CLOBBERS, ##__VA_ARGS__) +#define __PVOP_ALT_CALL (rettype, op, alt, cond, ...) \ + ____PVOP_ALT_CALL(PVOP_RETVAL(rettype), op, alt, cond, CLBR_ANY,\ + PVOP_CALL_CLOBBERS, EXTRA_CLOBBERS, \ + ##__VA_ARGS__) +#define __PVOP_CALLEESAVE (rettype, op, ...) \ ____PVOP_CALL(PVOP_RETVAL(rettype), op.func, CLBR_RET_REG, \ PVOP_CALLEE_CLOBBERS, , ##__VA_ARGS__) +#define __PVOP_ALT_CALLEESAVE (rettype, op, alt, cond, ...) \ + ____PVOP_ALT_CALL(PVOP_RETVAL(rettype), op.func, alt, cond, \ + CLBR_RET_REG, PVOP_CALLEE_CLOBBERS, , ##__VA_ARGS__) + +#define __PVOP_VCALL (op, ...) \ (void)____PVOP_CALL(, op, CLBR_ANY, PVOP_VCALL_CLOBBERS, \ VEXTRA_CLOBBERS, ##__VA_ARGS__) +#define __PVOP_ALT_VCALL (op, alt, cond, ...) \ + (void)____PVOP_ALT_CALL(, op, alt, cond, CLBR_ANY, \ + PVOP_VCALL_CLOBBERS, VEXTRA_CLOBBERS, \ + ##__VA_ARGS__) +#define __PVOP_VCALLEESAVE (op, ...) \ (void)____PVOP_CALL(, op.func, CLBR_RET_REG, \ - PVOP_VCALLEE_CLOBBERS, , ##__VA_ARGS__) + PVOP_VCALLEE_CLOBBERS, , ##__VA_ARGS__) +#define __PVOP_ALT_VCALLEESAVE (op, alt, cond, ...) \ + (void)____PVOP_ALT_CALL(, op.func, alt, cond, CLBR_RET_REG, \ + PVOP_VCALLEE_CLOBBERS, , ##__VA_ARGS__)#define PVOP_CALL0 (rettype, op) \ __PVOP_CALL(rettype, op)#define PVOP_VCALL0 (op) \ __PVOP_VCALL(op) +#define PVOP_ALT_CALL0 (rettype, op, alt, cond) \ + __PVOP_ALT_CALL(rettype, op, alt, cond) +#define PVOP_ALT_VCALL0 (op, alt, cond) \ + __PVOP_ALT_VCALL(op, alt, cond)#define PVOP_CALLEE0 (rettype, op) \ __PVOP_CALLEESAVE(rettype, op)#define PVOP_VCALLEE0 (op) \ __PVOP_VCALLEESAVE(op) +#define PVOP_ALT_CALLEE0 (rettype, op, alt, cond) \ + __PVOP_ALT_CALLEESAVE(rettype, op, alt, cond) +#define PVOP_ALT_VCALLEE0 (op, alt, cond) \ + __PVOP_ALT_VCALLEESAVE(op, alt, cond)#define PVOP_CALL1 (rettype, op, arg1) \ __PVOP_CALL(rettype, op, PVOP_CALL_ARG1(arg1))#define PVOP_VCALL1 (op, arg1) \ __PVOP_VCALL(op, PVOP_CALL_ARG1(arg1)) +#define PVOP_ALT_VCALL1 (op, arg1, alt, cond) \ + __PVOP_ALT_VCALL(op, alt, cond, PVOP_CALL_ARG1(arg1))#define PVOP_CALLEE1 (rettype, op, arg1) \ __PVOP_CALLEESAVE(rettype, op, PVOP_CALL_ARG1(arg1))#define PVOP_VCALLEE1 (op, arg1) \ __PVOP_VCALLEESAVE(op, PVOP_CALL_ARG1(arg1)) +#define PVOP_ALT_CALLEE1 (rettype, op, arg1, alt, cond) \ + __PVOP_ALT_CALLEESAVE(rettype, op, alt, cond, PVOP_CALL_ARG1(arg1)) +#define PVOP_ALT_VCALLEE1 (op, arg1, alt, cond) \ + __PVOP_ALT_VCALLEESAVE(op, alt, cond, PVOP_CALL_ARG1(arg1))#define PVOP_CALL2 (rettype, op, arg1, arg2) \
Juergen Gross
maintainerPATCH v7 13/14 x86/paravirt: switch functions with custom code to ALTERNATIVE
In reply to Juergen GrossInstead of using paravirt patching for custom code sequences use ALTERNATIVE for the functions with custom code replacements.
Instead of patching an ud2 instruction for unpopulated vector entries into the caller site, use a simple function just calling BUG() as a replacement.
Simplify the register defines for assembler paravirt calling, as there isn't much usage left.
---
V4:
- fixed SAVE_FLAGS() (kernel test robot)
- added assembler paravirt cleanup
--- arch/x86/entry/entry_64.S | 2 +- arch/x86/include/asm/irqflags.h | 2 +- arch/x86/include/asm/paravirt.h | 101 +++++++++++++------------- arch/x86/include/asm/paravirt_types.h | 6 -- arch/x86/kernel/paravirt.c | 16 ++-- arch/x86/kernel/paravirt_patch.c | 88 ---------------------- 6 files changed, 58 insertions(+), 157 deletions(-)
arch/x86/entry/entry_64.S +1 -1
@@ -305,7 +305,7 @@ SYM_CODE_END(ret_from_fork) .macro DEBUG_ENTRY_ASSERT_IRQS_OFF #ifdef CONFIG_DEBUG_ENTRY pushq %rax - SAVE_FLAGS(CLBR_RAX) + SAVE_FLAGS testl $X86_EFLAGS_IF, %eax jz .Lokay_\@ ud2
arch/x86/include/asm/irqflags.h +1 -1
@@ -111,7 +111,7 @@ static __always_inline unsigned long arch_local_irq_save(void)#ifdef CONFIG_X86_64 #ifdef CONFIG_DEBUG_ENTRY -#define SAVE_FLAGS (x) pushfq; popq %rax +#define SAVE_FLAGS pushfq; popq %rax#endif #define INTERRUPT_RETURN jmp native_iret
arch/x86/include/asm/paravirt.h +50 -51
216 lines not on this page · raw message
arch/x86/include/asm/paravirt_types.h +0 -6
@@ -3,7 +3,6 @@#define _ASM_X86_PARAVIRT_TYPES_H/* Bitmask of what can be clobbered: usually at least eax. */ -#define CLBR_NONE 0#define CLBR_EAX (1 << 0)#define CLBR_ECX (1 << 1)#define CLBR_EDX (1 << 2)
@@ -15,7 +14,6 @@#define CLBR_ARG_REGS (CLBR_EAX | CLBR_EDX | CLBR_ECX)#define CLBR_RET_REG (CLBR_EAX | CLBR_EDX) -#define CLBR_SCRATCH (0)#else #define CLBR_RAX CLBR_EAX#define CLBR_RCX CLBR_ECX
@@ -32,12 +30,9 @@#define CLBR_ARG_REGS (CLBR_RDI | CLBR_RSI | CLBR_RDX | \ CLBR_RCX | CLBR_R8 | CLBR_R9)#define CLBR_RET_REG (CLBR_RAX) -#define CLBR_SCRATCH (CLBR_R10 | CLBR_R11)#endif /* X86_64 */ -#define CLBR_CALLEE_SAVE ((CLBR_ARG_REGS | CLBR_SCRATCH) & ~CLBR_RET_REG) -#ifndef __ASSEMBLY__#include <asm/desc_defs.h>
@@ -322,7 +317,6 @@ extern void (*paravirt_iret)(void);/* Simple instruction patching code. */ #define NATIVE_LABEL (a,x,b) "\n\t.globl " a #x "_" #b "\n" a #x "_" #b ":\n\t" -unsigned paravirt_patch_ident_64 (void *insn_buff,unsigned len);unsigned paravirt_patch_default (u8 type,void *insn_buff,unsigned long addr,unsigned len);unsigned paravirt_patch_insns (void *insn_buff,unsigned len,const char *start,const char *end);
arch/x86/kernel/paravirt.c +6 -10
@@ -53,7 +53,10 @@ void __init default_banner(void) }/* Undefined instruction for dealing with missing ops pointers. */ -static const unsigned char ud2a[] = {0x0f ,0x0b }; +static void paravirt_BUG (void ) +{ +BUG (); +}struct branch {unsigned char opcode;
@@ -107,17 +110,10 @@ unsigned paravirt_patch_default(u8 type, void *insn_buff,unsigned ret;if (opfunc ==NULL ) -/* If there's no function, patch it with a ud2a (BUG) */ - ret =paravirt_patch_insns (insn_buff, len, ud2a, ud2a+sizeof (ud2a)); +/* If there's no function, patch it with paravirt_BUG() */ + ret =paravirt_patch_call (insn_buff, paravirt_BUG, addr, len);else if (opfunc == _paravirt_nop) ret =0 ; - -#ifdef CONFIG_PARAVIRT_XXL -/* identity functions just return their single argument */ - else if (opfunc == _paravirt_ident_64) - ret =paravirt_patch_ident_64 (insn_buff, len); - -#endif else /* Otherwise call the function. */ ret =paravirt_patch_call (insn_buff, opfunc, addr, len);
arch/x86/kernel/paravirt_patch.c +0 -88
96 lines not on this page · raw message
Signature · 6 lines
2.26.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
[tip: x86/alternatives] x86/paravirt: Switch functions with custom code to ALTERNATIVE
The following commit has been merged into the x86/alternatives branch of tip:
The following commit has been merged into the x86/alternatives branch of tip:
Commit-ID: fafe5e74229fd3f425e3cbfc68b90e615aa6d62f Gitweb: https://git.kernel.org/tip/fafe5e74229fd3f425e3cbfc68b90e615aa6d62f Author: Juergen Gross <[email protected]> AuthorDate: Thu, 11 Mar 2021 15:23:18 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 11 Mar 2021 20:07:01 +01:00
x86/paravirt: Switch functions with custom code to ALTERNATIVE
Instead of using paravirt patching for custom code sequences use ALTERNATIVE for the functions with custom code replacements.
Instead of patching an ud2 instruction for unpopulated vector entries into the caller site, use a simple function just calling BUG() as a replacement.
Simplify the register defines for assembler paravirt calling, as there isn't much usage left.
--- arch/x86/entry/entry_64.S | 2 +- arch/x86/include/asm/irqflags.h | 2 +- arch/x86/include/asm/paravirt.h | 101 ++++++++++++------------- arch/x86/include/asm/paravirt_types.h | 6 +- arch/x86/kernel/paravirt.c | 16 +--- arch/x86/kernel/paravirt_patch.c | 88 +---------------------- 6 files changed, 58 insertions(+), 157 deletions(-)
arch/x86/entry/entry_64.S +1 -1
@@ -305,7 +305,7 @@ SYM_CODE_END(ret_from_fork) .macro DEBUG_ENTRY_ASSERT_IRQS_OFF #ifdef CONFIG_DEBUG_ENTRY pushq %rax - SAVE_FLAGS(CLBR_RAX) + SAVE_FLAGS testl $X86_EFLAGS_IF, %eax jz .Lokay_\@ ud2
arch/x86/include/asm/irqflags.h +1 -1
@@ -111,7 +111,7 @@ static __always_inline unsigned long arch_local_irq_save(void)#ifdef CONFIG_X86_64 #ifdef CONFIG_DEBUG_ENTRY -#define SAVE_FLAGS (x) pushfq; popq %rax +#define SAVE_FLAGS pushfq; popq %rax#endif #define INTERRUPT_RETURN jmp native_iret
arch/x86/include/asm/paravirt.h +50 -51
216 lines not on this page · raw message
arch/x86/include/asm/paravirt_types.h +0 -6
@@ -3,7 +3,6 @@#define _ASM_X86_PARAVIRT_TYPES_H/* Bitmask of what can be clobbered: usually at least eax. */ -#define CLBR_NONE 0#define CLBR_EAX (1 << 0)#define CLBR_ECX (1 << 1)#define CLBR_EDX (1 << 2)
@@ -15,7 +14,6 @@#define CLBR_ARG_REGS (CLBR_EAX | CLBR_EDX | CLBR_ECX)#define CLBR_RET_REG (CLBR_EAX | CLBR_EDX) -#define CLBR_SCRATCH (0)#else #define CLBR_RAX CLBR_EAX#define CLBR_RCX CLBR_ECX
@@ -32,12 +30,9 @@#define CLBR_ARG_REGS (CLBR_RDI | CLBR_RSI | CLBR_RDX | \ CLBR_RCX | CLBR_R8 | CLBR_R9)#define CLBR_RET_REG (CLBR_RAX) -#define CLBR_SCRATCH (CLBR_R10 | CLBR_R11)#endif /* X86_64 */ -#define CLBR_CALLEE_SAVE ((CLBR_ARG_REGS | CLBR_SCRATCH) & ~CLBR_RET_REG) -#ifndef __ASSEMBLY__#include <asm/desc_defs.h>
@@ -322,7 +317,6 @@ extern void (*paravirt_iret)(void);/* Simple instruction patching code. */ #define NATIVE_LABEL (a,x,b) "\n\t.globl " a #x "_" #b "\n" a #x "_" #b ":\n\t" -unsigned paravirt_patch_ident_64 (void *insn_buff,unsigned len);unsigned paravirt_patch_default (u8 type,void *insn_buff,unsigned long addr,unsigned len);unsigned paravirt_patch_insns (void *insn_buff,unsigned len,const char *start,const char *end);
arch/x86/kernel/paravirt.c +6 -10
@@ -53,7 +53,10 @@ void __init default_banner(void) }/* Undefined instruction for dealing with missing ops pointers. */ -static const unsigned char ud2a[] = {0x0f ,0x0b }; +static void paravirt_BUG (void ) +{ +BUG (); +}struct branch {unsigned char opcode;
@@ -107,17 +110,10 @@ unsigned paravirt_patch_default(u8 type, void *insn_buff,unsigned ret;if (opfunc ==NULL ) -/* If there's no function, patch it with a ud2a (BUG) */ - ret =paravirt_patch_insns (insn_buff, len, ud2a, ud2a+sizeof (ud2a)); +/* If there's no function, patch it with paravirt_BUG() */ + ret =paravirt_patch_call (insn_buff, paravirt_BUG, addr, len);else if (opfunc == _paravirt_nop) ret =0 ; - -#ifdef CONFIG_PARAVIRT_XXL -/* identity functions just return their single argument */ - else if (opfunc == _paravirt_ident_64) - ret =paravirt_patch_ident_64 (insn_buff, len); - -#endif else /* Otherwise call the function. */ ret =paravirt_patch_call (insn_buff, opfunc, addr, len);
arch/x86/kernel/paravirt_patch.c +0 -88
96 lines not on this page · raw message
Juergen Gross
maintainerPATCH v7 14/14 x86/paravirt: have only one paravirt patch function
In reply to Juergen GrossThere is no need any longer to have different paravirt patch functions for native and Xen. Eliminate native_patch() and rename paravirt_patch_default() to paravirt_patch().
---
V3:
- remove paravirt_patch_insns() (kernel test robot)
--- arch/x86/include/asm/paravirt_types.h | 19 +------------------ arch/x86/kernel/Makefile | 3 +-- arch/x86/kernel/alternative.c | 2 +- arch/x86/kernel/paravirt.c | 20 ++------------------ arch/x86/kernel/paravirt_patch.c | 11 ----------- arch/x86/xen/enlighten_pv.c | 1 - 6 files changed, 5 insertions(+), 51 deletions(-) delete mode 100644 arch/x86/kernel/paravirt_patch.c
arch/x86/include/asm/paravirt_types.h +1 -18
@@ -68,19 +68,6 @@ struct pv_info {const char *name; }; -struct pv_init_ops { -/* -* Patch may replace one of the defined code sequences with -* arbitrary code, subject to the same register constraints. -* This generally means the code is not free to clobber any -* registers other than EAX. The patch function should return -* the number of bytes of code generated, as we nop pad the -* rest in generic code. -*/ -unsigned (*patch)(u8 type,void *insn_buff, -unsigned long addr,unsigned len); -} __no_randomize_layout; -#ifdef CONFIG_PARAVIRT_XXL struct pv_lazy_ops {/* Set deferred update mode, used for batching operations. */
@@ -276,7 +263,6 @@ struct pv_lock_ops {* number for each function using the offset which we use to indicate * what to patch. */ struct paravirt_patch_template { -struct pv_init_ops init;struct pv_cpu_ops cpu;struct pv_irq_ops irq;struct pv_mmu_ops mmu;
@@ -317,10 +303,7 @@ extern void (*paravirt_iret)(void);/* Simple instruction patching code. */ #define NATIVE_LABEL (a,x,b) "\n\t.globl " a #x "_" #b "\n" a #x "_" #b ":\n\t" -unsigned paravirt_patch_default (u8 type,void *insn_buff,unsigned long addr,unsigned len); -unsigned paravirt_patch_insns (void *insn_buff,unsigned len,const char *start,const char *end); - -unsigned native_patch (u8 type,void *insn_buff,unsigned long addr,unsigned len); +unsigned int paravirt_patch (u8 type,void *insn_buff,unsigned long addr,unsigned int len);int paravirt_disable_iospace (void );
arch/x86/kernel/Makefile +1 -2
@@ -35,7 +35,6 @@ KASAN_SANITIZE_sev-es.o := n KCSAN_SANITIZE := n OBJECT_FILES_NON_STANDARD_test_nx.o := y -OBJECT_FILES_NON_STANDARD_paravirt_patch.o := y ifdef CONFIG_FRAME_POINTER OBJECT_FILES_NON_STANDARD_ftrace_$(BITS).o := y
@@ -121,7 +120,7 @@ obj-$(CONFIG_AMD_NB) += amd_nb.o obj-$(CONFIG_DEBUG_NMI_SELFTEST) += nmi_selftest.o obj-$(CONFIG_KVM_GUEST) += kvm.o kvmclock.o -obj-$(CONFIG_PARAVIRT) += paravirt.o paravirt_patch.o +obj-$(CONFIG_PARAVIRT) += paravirt.o obj-$(CONFIG_PARAVIRT_SPINLOCKS)+= paravirt-spinlocks.o obj-$(CONFIG_PARAVIRT_CLOCK) += pvclock.o obj-$(CONFIG_X86_PMEM_LEGACY_DEVICE) += pmem.o
arch/x86/kernel/alternative.c +1 -1
@@ -616,7 +616,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,BUG_ON (p->len >MAX_PATCH_LEN );/* prep the buffer with the original instructions */ memcpy (insn_buff, p->instr, p->len); - used = pv_ops.init.patch (p->type, insn_buff, (unsigned long )p->instr, p->len); + used =paravirt_patch (p->type, insn_buff, (unsigned long )p->instr, p->len);BUG_ON (used > p->len);
arch/x86/kernel/paravirt.c +2 -18
@@ -99,8 +99,8 @@ void __init native_pv_lock_init(void)static_branch_disable (&virt_spin_lock_key); } -unsigned paravirt_patch_default (u8 type,void *insn_buff, -unsigned long addr,unsigned len) +unsigned int paravirt_patch (u8 type,void *insn_buff,unsigned long addr, +unsigned int len) {/* * Neat trick to map patch type back to the call within the
@@ -121,19 +121,6 @@ unsigned paravirt_patch_default(u8 type, void *insn_buff,return ret; } -unsigned paravirt_patch_insns (void *insn_buff,unsigned len, -const char *start,const char *end) -{ -unsigned insn_len = end - start; - -/* Alternative instruction is too large for the patch site and we cannot continue: */ -BUG_ON (insn_len > len || start ==NULL ); - -memcpy (insn_buff, start, insn_len); - -return insn_len; -} -struct static_key paravirt_steal_enabled;struct static_key paravirt_steal_rq_enabled;
@@ -252,9 +239,6 @@ struct pv_info pv_info = {#define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)struct paravirt_patch_template pv_ops = { -/* Init ops. */ - .init.patch = native_patch, -/* Cpu ops. */ .cpu.io_delay = native_io_delay,
arch/x86/kernel/paravirt_patch.c deleted +0 -11
@@ -1,11 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include <linux/stringify.h> - -#include <asm/paravirt.h> -#include <asm/asm-offsets.h> - -unsigned int native_patch (u8 type,void *insn_buff,unsigned long addr, -unsigned int len) -{ -return paravirt_patch_default (type, insn_buff, addr, len); -}
arch/x86/xen/enlighten_pv.c +0 -1
@@ -1231,7 +1231,6 @@ asmlinkage __visible void __init xen_start_kernel(void)/* Install Xen paravirt ops */ pv_info = xen_info; - pv_ops.init.patch = paravirt_patch_default; pv_ops.cpu = xen_cpu_ops; paravirt_iret = xen_iret;xen_init_irq_ops ();
Signature · 6 lines
2.26.2 _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
[tip: x86/alternatives] x86/paravirt: Have only one paravirt patch function
The following commit has been merged into the x86/alternatives branch of tip:
The following commit has been merged into the x86/alternatives branch of tip:
Commit-ID: 054ac8ad5ebe4a69e1f0e842483821ddbe560121 Gitweb: https://git.kernel.org/tip/054ac8ad5ebe4a69e1f0e842483821ddbe560121 Author: Juergen Gross <[email protected]> AuthorDate: Thu, 11 Mar 2021 15:23:19 +01:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Thu, 11 Mar 2021 20:11:09 +01:00
x86/paravirt: Have only one paravirt patch function
There is no need any longer to have different paravirt patch functions for native and Xen. Eliminate native_patch() and rename paravirt_patch_default() to paravirt_patch().
--- arch/x86/include/asm/paravirt_types.h | 19 +------------------ arch/x86/kernel/Makefile | 3 +-- arch/x86/kernel/alternative.c | 2 +- arch/x86/kernel/paravirt.c | 20 ++------------------ arch/x86/kernel/paravirt_patch.c | 11 ----------- arch/x86/xen/enlighten_pv.c | 1 - 6 files changed, 5 insertions(+), 51 deletions(-) delete mode 100644 arch/x86/kernel/paravirt_patch.c
arch/x86/include/asm/paravirt_types.h +1 -18
@@ -68,19 +68,6 @@ struct pv_info {const char *name; }; -struct pv_init_ops { -/* -* Patch may replace one of the defined code sequences with -* arbitrary code, subject to the same register constraints. -* This generally means the code is not free to clobber any -* registers other than EAX. The patch function should return -* the number of bytes of code generated, as we nop pad the -* rest in generic code. -*/ -unsigned (*patch)(u8 type,void *insn_buff, -unsigned long addr,unsigned len); -} __no_randomize_layout; -#ifdef CONFIG_PARAVIRT_XXL struct pv_lazy_ops {/* Set deferred update mode, used for batching operations. */
@@ -276,7 +263,6 @@ struct pv_lock_ops {* number for each function using the offset which we use to indicate * what to patch. */ struct paravirt_patch_template { -struct pv_init_ops init;struct pv_cpu_ops cpu;struct pv_irq_ops irq;struct pv_mmu_ops mmu;
@@ -317,10 +303,7 @@ extern void (*paravirt_iret)(void);/* Simple instruction patching code. */ #define NATIVE_LABEL (a,x,b) "\n\t.globl " a #x "_" #b "\n" a #x "_" #b ":\n\t" -unsigned paravirt_patch_default (u8 type,void *insn_buff,unsigned long addr,unsigned len); -unsigned paravirt_patch_insns (void *insn_buff,unsigned len,const char *start,const char *end); - -unsigned native_patch (u8 type,void *insn_buff,unsigned long addr,unsigned len); +unsigned int paravirt_patch (u8 type,void *insn_buff,unsigned long addr,unsigned int len);int paravirt_disable_iospace (void );
arch/x86/kernel/Makefile +1 -2
@@ -35,7 +35,6 @@ KASAN_SANITIZE_sev-es.o := n KCSAN_SANITIZE := n OBJECT_FILES_NON_STANDARD_test_nx.o := y -OBJECT_FILES_NON_STANDARD_paravirt_patch.o := y ifdef CONFIG_FRAME_POINTER OBJECT_FILES_NON_STANDARD_ftrace_$(BITS).o := y
@@ -121,7 +120,7 @@ obj-$(CONFIG_AMD_NB) += amd_nb.o obj-$(CONFIG_DEBUG_NMI_SELFTEST) += nmi_selftest.o obj-$(CONFIG_KVM_GUEST) += kvm.o kvmclock.o -obj-$(CONFIG_PARAVIRT) += paravirt.o paravirt_patch.o +obj-$(CONFIG_PARAVIRT) += paravirt.o obj-$(CONFIG_PARAVIRT_SPINLOCKS)+= paravirt-spinlocks.o obj-$(CONFIG_PARAVIRT_CLOCK) += pvclock.o obj-$(CONFIG_X86_PMEM_LEGACY_DEVICE) += pmem.o
arch/x86/kernel/alternative.c +1 -1
@@ -616,7 +616,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,BUG_ON (p->len >MAX_PATCH_LEN );/* prep the buffer with the original instructions */ memcpy (insn_buff, p->instr, p->len); - used = pv_ops.init.patch (p->type, insn_buff, (unsigned long )p->instr, p->len); + used =paravirt_patch (p->type, insn_buff, (unsigned long )p->instr, p->len);BUG_ON (used > p->len);
arch/x86/kernel/paravirt.c +2 -18
@@ -99,8 +99,8 @@ void __init native_pv_lock_init(void)static_branch_disable (&virt_spin_lock_key); } -unsigned paravirt_patch_default (u8 type,void *insn_buff, -unsigned long addr,unsigned len) +unsigned int paravirt_patch (u8 type,void *insn_buff,unsigned long addr, +unsigned int len) {/* * Neat trick to map patch type back to the call within the
@@ -121,19 +121,6 @@ unsigned paravirt_patch_default(u8 type, void *insn_buff,return ret; } -unsigned paravirt_patch_insns (void *insn_buff,unsigned len, -const char *start,const char *end) -{ -unsigned insn_len = end - start; - -/* Alternative instruction is too large for the patch site and we cannot continue: */ -BUG_ON (insn_len > len || start ==NULL ); - -memcpy (insn_buff, start, insn_len); - -return insn_len; -} -struct static_key paravirt_steal_enabled;struct static_key paravirt_steal_rq_enabled;
@@ -252,9 +239,6 @@ struct pv_info pv_info = {#define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)struct paravirt_patch_template pv_ops = { -/* Init ops. */ - .init.patch = native_patch, -/* Cpu ops. */ .cpu.io_delay = native_io_delay,
arch/x86/kernel/paravirt_patch.c deleted +0 -11
@@ -1,11 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include <linux/stringify.h> - -#include <asm/paravirt.h> -#include <asm/asm-offsets.h> - -unsigned int native_patch (u8 type,void *insn_buff,unsigned long addr, -unsigned int len) -{ -return paravirt_patch_default (type, insn_buff, addr, len); -}
arch/x86/xen/enlighten_pv.c +0 -1
@@ -1231,7 +1231,6 @@ asmlinkage __visible void __init xen_start_kernel(void)/* Install Xen paravirt ops */ pv_info = xen_info; - pv_ops.init.patch = paravirt_patch_default; pv_ops.cpu = xen_cpu_ops; paravirt_iret = xen_iret;xen_init_irq_ops ();