objtool,x86_64,paravirt: Add pv_ops[] support
Subsystems (7)
[email protected]
maintainerRFC PATCH 1/1 objtool,x86_64,paravirt: Add pv_ops[] support
Thomas wanted paramuck vs noinstr, here goes. Very rough, very nasty, mostly works.
It requires call sites are the normal indirect call, and not mangled retpoison (slow_down_io() had those), it also requires pv_ops[] assignments are single instructions and not laundered through some pointless intermediate helper (hyperv).
It doesn't warn when you get any of that wrong.
But if you have it all lined up right, it will warn about noinstr violations due to paramuck:
$ ./objtool check -afl ../../defconfig-build/vmlinux.o
../../defconfig-build/vmlinux.o: warning: objtool: xen_pv_evtchn_do_upcall()+0x69: return with instrumentation enabled
../../defconfig-build/vmlinux.o: warning: objtool: exc_double_fault()+0x15: call pv_ops[48] from noinstr
../../defconfig-build/vmlinux.o: warning: objtool: pv_op[48]: xen_read_cr2
../../defconfig-build/vmlinux.o: warning: objtool: exc_double_fault()+0x15: call to {dynamic}() leaves .noinstr.text section
../../defconfig-build/vmlinux.o: warning: objtool: exc_debug()+0x29: call pv_ops[4] from noinstr
../../defconfig-build/vmlinux.o: warning: objtool: pv_op[4]: native_get_debugreg
../../defconfig-build/vmlinux.o: warning: objtool: exc_debug()+0x29: call to {dynamic}() leaves .noinstr.text section
../../defconfig-build/vmlinux.o: warning: objtool: noist_exc_debug()+0x26: call pv_ops[4] from noinstr
../../defconfig-build/vmlinux.o: warning: objtool: pv_op[4]: native_get_debugreg
../../defconfig-build/vmlinux.o: warning: objtool: noist_exc_debug()+0x26: call to {dynamic}() leaves .noinstr.text section
../../defconfig-build/vmlinux.o: warning: objtool: exc_nmi()+0x3a: call pv_ops[48] from noinstr
../../defconfig-build/vmlinux.o: warning: objtool: pv_op[48]: xen_read_cr2
../../defconfig-build/vmlinux.o: warning: objtool: exc_nmi()+0x3a: call to {dynamic}() leaves .noinstr.text section
../../defconfig-build/vmlinux.o: warning: objtool: mce_setup()+0x80: call pv_ops[25] from noinstr
../../defconfig-build/vmlinux.o: warning: objtool: pv_op[25]: native_cpuid
../../defconfig-build/vmlinux.o: warning: objtool: mce_setup()+0x80: call to {dynamic}() leaves .noinstr.text section
../../defconfig-build/vmlinux.o: warning: objtool: do_machine_check()+0x46: call to mce_rdmsrl() leaves .noinstr.text section
../../defconfig-build/vmlinux.o: warning: objtool: exc_machine_check()+0x24: call pv_ops[4] from noinstr
../../defconfig-build/vmlinux.o: warning: objtool: pv_op[4]: native_get_debugreg
../../defconfig-build/vmlinux.o: warning: objtool: exc_machine_check()+0x24: call to {dynamic}() leaves .noinstr.text section
../../defconfig-build/vmlinux.o: warning: objtool: noist_exc_machine_check()+0x24: call pv_ops[4] from noinstr
../../defconfig-build/vmlinux.o: warning: objtool: pv_op[4]: native_get_debugreg
../../defconfig-build/vmlinux.o: warning: objtool: noist_exc_machine_check()+0x24: call to {dynamic}() leaves .noinstr.text section
../../defconfig-build/vmlinux.o: warning: objtool: exc_page_fault()+0xe: call pv_ops[48] from noinstr
../../defconfig-build/vmlinux.o: warning: objtool: pv_op[48]: xen_read_cr2
../../defconfig-build/vmlinux.o: warning: objtool: exc_page_fault()+0xe: call to {dynamic}() leaves .noinstr.text section
../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0xf17: call pv_ops[32] from noinstr
../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0x12f1: call pv_ops[35] from noinstr
../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0xf5a: call pv_ops[32] from noinstr
../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0x1002: call pv_ops[32] from noinstr
../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0x1186: call pv_ops[32] from noinstr
../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0x12ba: call pv_ops[32] from noinstr
../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0x12a7: call pv_ops[32] from noinstr
../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0x124c: call pv_ops[32] from noinstr
../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0x14f0: call pv_ops[32] from noinstr
../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0x1683: call pv_ops[32] from noinstr[ funny that, WTH does x86_64 have IRET pv_ops... ]
--- arch/x86/include/asm/paravirt.h | 8 +-- arch/x86/kernel/cpu/mshyperv.c | 7 --- drivers/clocksource/hyperv_timer.c | 7 +++ include/asm-generic/mshyperv.h | 1 - lib/Kconfig.debug | 2 +- tools/objtool/Makefile | 2 +- tools/objtool/arch.h | 2 +- tools/objtool/arch/x86/decode.c | 30 ++++++++- tools/objtool/builtin-check.c | 10 +-- tools/objtool/builtin-orc.c | 10 +-- tools/objtool/check.c | 126 ++++++++++++++++++++++++++++++++++--- tools/objtool/elf.h | 1 + tools/objtool/objtool.c | 46 ++++++++++++++ tools/objtool/objtool.h | 9 +++ 14 files changed, 218 insertions(+), 43 deletions(-)
arch/x86/include/asm/paravirt.h +4 -4
@@ -39,11 +39,11 @@ static inline u64 paravirt_steal_clock(int cpu)/* The paravirtualized I/O functions */ static inline void slow_down_io (void ) { - pv_ops.cpu.io_delay (); +PVOP_VCALL0 (cpu.io_delay);#ifdef REALLY_SLOW_IO - pv_ops.cpu.io_delay (); - pv_ops.cpu.io_delay (); - pv_ops.cpu.io_delay (); +PVOP_VCALL0 (cpu.io_delay); +PVOP_VCALL0 (cpu.io_delay); +PVOP_VCALL0 (cpu.io_delay);#endif }
arch/x86/kernel/cpu/mshyperv.c +0 -7
@@ -361,13 +361,6 @@ static void __init ms_hyperv_init_platform(void)#endif } -void hv_setup_sched_clock (void *sched_clock) -{ -#ifdef CONFIG_PARAVIRT - pv_ops.time.sched_clock = sched_clock; -#endif -} -const __initconst struct hypervisor_x86 x86_hyper_ms_hyperv = { .name ="Microsoft Hyper-V" , .detect = ms_hyperv_platform,
drivers/clocksource/hyperv_timer.c +7 -0
@@ -418,6 +418,13 @@ static struct clocksource hyperv_cs_msr = { .flags = CLOCK_SOURCE_IS_CONTINUOUS, }; +static __always_inline void hv_setup_sched_clock(void *sched_clock) +{ +#ifdef CONFIG_PARAVIRT + pv_ops.time.sched_clock = sched_clock; +#endif +} +static bool __init hv_init_tsc_clocksource (void ) {u64 tsc_msr;
include/asm-generic/mshyperv.h +0 -1
@@ -168,7 +168,6 @@ void hyperv_report_panic_msg(phys_addr_t pa, size_t size);bool hv_is_hyperv_initialized (void );bool hv_is_hibernation_supported (void );void hyperv_cleanup (void ); -void hv_setup_sched_clock (void *sched_clock);#else /* CONFIG_HYPERV */ static inline bool hv_is_hyperv_initialized (void ) {return false; }static inline bool hv_is_hibernation_supported (void ) {return false; }
lib/Kconfig.debug +1 -1
@@ -399,7 +399,7 @@ config STACK_VALIDATION config VMLINUX_VALIDATION bool - depends on STACK_VALIDATION && DEBUG_ENTRY && !PARAVIRT + depends on STACK_VALIDATION && DEBUG_ENTRY default y config DEBUG_FORCE_WEAK_PER_CPU
tools/objtool/Makefile +1 -1
@@ -38,7 +38,7 @@ INCLUDES := -I$(srctree)/tools/include \ -I$(srctree)/tools/arch/$(SRCARCH)/include \ -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS) +CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -ggdb3 $(INCLUDES) $(LIBELF_FLAGS) LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) # Allow old libelf to be used:
tools/objtool/arch.h +1 -1
@@ -72,7 +72,7 @@ struct instruction;void arch_initial_func_cfi_state (struct cfi_init_state *state); -int arch_decode_instruction(const struct elf *elf, const struct section *sec, +int arch_decode_instruction(struct objtool_file *file, const struct section *sec, unsigned long offset, unsigned int maxlen, unsigned int *len, enum insn_type *type, unsigned long *immediate,
tools/objtool/arch/x86/decode.c +29 -1
@@ -15,6 +15,7 @@#include "../../elf.h" #include "../../arch.h" #include "../../warn.h" +#include "../../objtool.h" static unsigned char op_to_cfi_reg[][2 ] = { {CFI_AX ,CFI_R8 },
@@ -82,12 +83,13 @@ unsigned long arch_jump_destination(struct instruction *insn)return -1 ; \ else for (list_add_tail(&op->list, ops_list); op; op = NULL) -int arch_decode_instruction (const struct elf *elf,const struct section *sec, +int arch_decode_instruction (struct objtool_file *file,const struct section *sec,unsigned long offset,unsigned int maxlen,unsigned int *len,enum insn_type *type,unsigned long *immediate,struct list_head *ops_list) { +const struct elf *elf = file->elf;struct insn insn;int x86_64, sign; unsigned char op1, op2, rex = 0, rex_b = 0, rex_r = 0, rex_w = 0,
@@ -469,6 +471,32 @@ int arch_decode_instruction(const struct elf *elf, const struct section *sec, *type =INSN_RETURN ;break ; +case 0xc7 :/* mov imm, r/m */ +if (insn.length ==3 +4 +4 && !strcmp (sec->name,".init.text" )) { +// if (rex == 48 && modrm == 0x05) { /* movq $imm32, disp32(%rip) */ +struct reloc *imm, *disp; +struct symbol *func; + + imm =find_reloc_by_dest (elf, (void *)sec, offset+3 ); + disp =find_reloc_by_dest (elf, (void *)sec, offset+7 ); + +if (imm && !strcmp (imm->sym->name,"pv_ops" )) { +int idx = (imm->addend +sizeof (void *)) /sizeof (void *); + + func = disp->sym; +if (disp->sym->type ==STT_SECTION ) { + func =find_symbol_by_offset (disp->sym->sec, disp->addend); +if (!func) { +WARN ("FAIL %s+%d" , disp->sym->name, disp->addend); +return -1 ; + } + } + +file_pv_add (file, idx, func); + } + } +break ; +case 0xcf :/* iret */ /* * Handle sync_core(), which has an IRET to self.
tools/objtool/builtin-check.c +1 -9
@@ -40,18 +40,10 @@ const struct option check_options[] = {int cmd_check (int argc,const char **argv) { -const char *objname, *s; - argc =parse_options (argc, argv, check_options, check_usage,0 );if (argc !=1 )usage_with_options (check_usage, check_options); - objname = argv[0 ]; - - s =strstr (objname,"vmlinux.o" ); -if (s && !s[9 ]) - vmlinux = true; - -return check (objname, false); +return check (argv[0 ], false); }
tools/objtool/builtin-orc.c +2 -8
@@ -24,8 +24,6 @@ static const char *orc_usage[] = {int cmd_orc (int argc,const char **argv) { -const char *objname; - argc--; argv++;if (argc <=0 )usage_with_options (orc_usage, check_options);
@@ -35,18 +33,14 @@ int cmd_orc(int argc, const char **argv)if (argc !=1 )usage_with_options (orc_usage, check_options); - objname = argv[0 ]; - -return check (objname, true); +return check (argv[0 ], true); }if (!strcmp (argv[0 ],"dump" )) {if (argc !=2 )usage_with_options (orc_usage, check_options); - objname = argv[1 ]; - -return orc_dump (objname); +return orc_dump (argv[1 ]); }usage_with_options (orc_usage, check_options);
tools/objtool/check.c +116 -10
204 lines not on this page · raw message
tools/objtool/elf.h +1 -0
@@ -56,6 +56,7 @@ struct symbol {unsigned int len;struct symbol *pfunc, *cfunc, *alias;bool uaccess_safe; +struct list_head pv_target; };struct reloc {
tools/objtool/objtool.c +46 -0
56 lines not on this page · raw message
tools/objtool/objtool.h +9 -0
@@ -12,13 +12,22 @@#include "elf.h" +struct pv_state { +bool clean; +struct list_head targets; +}; +struct objtool_file {struct elf *elf;struct list_head insn_list; DECLARE_HASHTABLE(insn_hash, 20);bool ignore_unreachables, c_file, hints, rodata; + +struct pv_state *pv_ops; }; +void file_pv_add (struct objtool_file *file,int idx,struct symbol *func); +int check (const char *objname,bool orc);int orc_dump (const char *objname);int create_orc (struct objtool_file *file);
Quoted 10 lines · On Mon, Aug 3, 2020 at 7:33 AM <[email protected]> wrote:
Thomas wanted paramuck vs noinstr, here goes. Very rough, very nasty, mostly works.
It requires call sites are the normal indirect call, and not mangled retpoison (
slow_down_io()had those), it also requires pv_ops[] assignments are single instructions and not laundered through some pointless intermediate helper (hyperv).
Quoted 4 lines
It doesn't warn when you get any of that wrong.
But if you have it all lined up right, it will warn about noinstr violations due to paramuck:
I certainly agree that pv_ops is mucky, but could you expound on precisely what this patch actually does? On a very quick read-through, I'm guessing you're complaining about any call to pv_ops in a noinstr section? But maybe this is only calls to pv_ops that aren't themselves noinstr?
[email protected]
maintainerQuoted 13 lines · Andy Lutomirski
Quoted 12 lines · On Mon, Aug 3, 2020 at 7:33 AM <[email protected]> wrote:
Thomas wanted paramuck vs noinstr, here goes. Very rough, very nasty, mostly works.
It requires call sites are the normal indirect call, and not mangled retpoison (
slow_down_io()had those), it also requires pv_ops[] assignments are single instructions and not laundered through some pointless intermediate helper (hyperv).It doesn't warn when you get any of that wrong.
Quoted 8 lines
Quoted 2 lines
But if you have it all lined up right, it will warn about noinstr violations due to paramuck:
I certainly agree that
pv_opsis mucky, but could you expound on precisely what this patch actually does? On a very quick read-through, I'm guessing you're complaining about any call topv_opsin a noinstr section? But maybe this is only calls topv_opsthat aren't themselves noinstr?
Yeah, it makes sure that any pv_op called from noinstr are to a noinstr function.
The example here:
../../defconfig-build/vmlinux.o: warning: objtool: exc_double_fault()+0x15: call pv_ops[48] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: pv_op[48]: xen_read_cr2 ../../defconfig-build/vmlinux.o: warning: objtool: exc_double_fault()+0x15: call to {dynamic}() leaves .noinstr.text section
complains about exc_double_fault(), a noinstr function, calling to xen_read_cr2(), a regular function.
Basically, for every pv_ops[] entry, it compiles a list of assigned functions, and when there's a noinstr call, it makes sure all functions assigned to that pv_op are noinstr.
From: [email protected] Sent: Monday, August 3, 2020 7:33 AM
Quoted 144 lines
Thomas wanted paramuck vs noinstr, here goes. Very rough, very nasty, mostly works.
It requires call sites are the normal indirect call, and not mangled retpoison (
slow_down_io()had those), it also requires pv_ops[] assignments are single instructions and not laundered through some pointless intermediate helper (hyperv).It doesn't warn when you get any of that wrong.
But if you have it all lined up right, it will warn about noinstr violations due to paramuck:
$ ./objtool check -afl ../../defconfig-build/vmlinux.o ../../defconfig-build/vmlinux.o: warning: objtool: xen_pv_evtchn_do_upcall()+0x69: return with instrumentation enabled ../../defconfig-build/vmlinux.o: warning: objtool: exc_double_fault()+0x15: call pv_ops[48] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: pv_op[48]: xen_read_cr2 ../../defconfig-build/vmlinux.o: warning: objtool: exc_double_fault()+0x15: call to {dynamic}() leaves .noinstr.text section ../../defconfig-build/vmlinux.o: warning: objtool: exc_debug()+0x29: call pv_ops[4] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: pv_op[4]: native_get_debugreg ../../defconfig-build/vmlinux.o: warning: objtool: exc_debug()+0x29: call to {dynamic}() leaves .noinstr.text section ../../defconfig-build/vmlinux.o: warning: objtool: noist_exc_debug()+0x26: call pv_ops[4] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: pv_op[4]: native_get_debugreg ../../defconfig-build/vmlinux.o: warning: objtool: noist_exc_debug()+0x26: call to {dynamic}() leaves .noinstr.text section ../../defconfig-build/vmlinux.o: warning: objtool: exc_nmi()+0x3a: call pv_ops[48] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: pv_op[48]: xen_read_cr2 ../../defconfig-build/vmlinux.o: warning: objtool: exc_nmi()+0x3a: call to {dynamic}() leaves .noinstr.text section ../../defconfig-build/vmlinux.o: warning: objtool: mce_setup()+0x80: call pv_ops[25] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: pv_op[25]: native_cpuid ../../defconfig-build/vmlinux.o: warning: objtool: mce_setup()+0x80: call to {dynamic}() leaves .noinstr.text section ../../defconfig-build/vmlinux.o: warning: objtool: do_machine_check()+0x46: call to mce_rdmsrl() leaves .noinstr.text section ../../defconfig-build/vmlinux.o: warning: objtool: exc_machine_check()+0x24: call pv_ops[4] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: pv_op[4]: native_get_debugreg ../../defconfig-build/vmlinux.o: warning: objtool: exc_machine_check()+0x24: call to {dynamic}() leaves .noinstr.text section ../../defconfig-build/vmlinux.o: warning: objtool: noist_exc_machine_check()+0x24: call pv_ops[4] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: pv_op[4]: native_get_debugreg ../../defconfig-build/vmlinux.o: warning: objtool: noist_exc_machine_check()+0x24: call to {dynamic}() leaves .noinstr.text section ../../defconfig-build/vmlinux.o: warning: objtool: exc_page_fault()+0xe: call pv_ops[48] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: pv_op[48]: xen_read_cr2 ../../defconfig-build/vmlinux.o: warning: objtool: exc_page_fault()+0xe: call to {dynamic}() leaves .noinstr.text section ../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0xf17: call pv_ops[32] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0x12f1: call pv_ops[35] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0xf5a: call pv_ops[32] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0x1002: call pv_ops[32] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0x1186: call pv_ops[32] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0x12ba: call pv_ops[32] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0x12a7: call pv_ops[32] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0x124c: call pv_ops[32] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0x14f0: call pv_ops[32] from noinstr ../../defconfig-build/vmlinux.o: warning: objtool: .entry.text+0x1683: call pv_ops[32] from noinstr[ funny that, WTH does
x86_64have IRETpv_ops... ]Requested-by Thomas Gleixner <[email protected]>Signed-off-by Peter Zijlstra (Intel) <[email protected]>--- arch/x86/include/asm/paravirt.h | 8 +-- arch/x86/kernel/cpu/mshyperv.c | 7 --- drivers/clocksource/hyperv_timer.c | 7 +++ include/asm-generic/mshyperv.h | 1 - lib/Kconfig.debug | 2 +- tools/objtool/Makefile | 2 +- tools/objtool/arch.h | 2 +- tools/objtool/arch/x86/decode.c | 30 ++++++++- tools/objtool/builtin-check.c | 10 +-- tools/objtool/builtin-orc.c | 10 +-- tools/objtool/check.c | 126 ++++++++++++++++++++++++++++++++++--- tools/objtool/elf.h | 1 + tools/objtool/objtool.c | 46 ++++++++++++++ tools/objtool/objtool.h | 9 +++ 14 files changed, 218 insertions(+), 43 deletions(-)arch/x86/include/asm/paravirt.h +4
-4@@ -39,11 +39,11 @@ static inline u64 paravirt_steal_clock(int cpu)/* The paravirtualized I/O functions */ static inline void slow_down_io (void ) { - pv_ops.cpu.io_delay (); +PVOP_VCALL0 (cpu.io_delay);#ifdef REALLY_SLOW_IO - pv_ops.cpu.io_delay (); - pv_ops.cpu.io_delay (); - pv_ops.cpu.io_delay (); +PVOP_VCALL0 (cpu.io_delay); +PVOP_VCALL0 (cpu.io_delay); +PVOP_VCALL0 (cpu.io_delay);#endif }arch/x86/kernel/cpu/mshyperv.c +0
-7@@ -361,13 +361,6 @@ static void __init ms_hyperv_init_platform(void)#endif } -void hv_setup_sched_clock (void *sched_clock) -{ -#ifdef CONFIG_PARAVIRT - pv_ops.time.sched_clock = sched_clock; -#endif -} -const __initconst struct hypervisor_x86 x86_hyper_ms_hyperv = { .name ="Microsoft Hyper-V" , .detect = ms_hyperv_platform,drivers/clocksource/hyperv_timer.c +0
-0
drivers/clocksource/hyperv_timer.c static struct clocksource hyperv_cs_msr = { · line 427
Quoted 10 lines
drivers/clocksource/hyperv_timer.c +7
-0@@ -418,6 +418,13 @@ static struct clocksource hyperv_cs_msr = { .flags = CLOCK_SOURCE_IS_CONTINUOUS, }; +static __always_inline void hv_setup_sched_clock(void *sched_clock) +{ +#ifdef CONFIG_PARAVIRT + pv_ops.time.sched_clock = sched_clock; +#endif +} +
Moving this function to hyperv_timer.c is problematic because we want hyperv_timer.c to be architecture independent. We're in the process of supporting Linux guests running on Hyper-V on ARM64, and there's a different implementation of hv_setup_sched_clock() on ARM64.
Michael
Quoted 15 lines
drivers/clocksource/hyperv_timer.c +0
-0static bool __init hv_init_tsc_clocksource (void ) {u64 tsc_msr;include/asm-generic/mshyperv.h +0
-1@@ -168,7 +168,6 @@ void hyperv_report_panic_msg(phys_addr_t pa, size_t size);bool hv_is_hyperv_initialized (void );bool hv_is_hibernation_supported (void );void hyperv_cleanup (void ); -void hv_setup_sched_clock (void *sched_clock);#else /* CONFIG_HYPERV */ static inline bool hv_is_hyperv_initialized (void ) {return false; }static inline bool hv_is_hibernation_supported (void ) {return false; }
[email protected]
maintainerQuoted 6 lines · Michael Kelley
From: [email protected] Sent: Monday, August 3, 2020 7:33 AM
Quoted 4 lines
It requires call sites are the normal indirect call, and not mangled retpoison (
slow_down_io()had those), it also requires pv_ops[] assignments are single instructions and not laundered through some pointless intermediate helper (hyperv).
^^^
Quoted 8 lines
Quoted 8 lines
drivers/clocksource/hyperv_timer.c +0
-0@@ -418,6 +418,13 @@ static struct clocksource hyperv_cs_msr = { .flags = CLOCK_SOURCE_IS_CONTINUOUS, };
Quoted 12 lines
drivers/clocksource/hyperv_timer.c static struct clocksource hyperv_cs_msr = { · line 427
Quoted 7 lines
drivers/clocksource/hyperv_timer.c +7
-0+static __always_inline void hv_setup_sched_clock(void *sched_clock) +{ +#ifdef CONFIG_PARAVIRT + pv_ops.time.sched_clock = sched_clock; +#endif +} +Moving this function to
hyperv_timer.cis problematic because we wanthyperv_timer.cto be architecture independent. We're in the process of supporting Linux guests running on Hyper-V on ARM64, and there's a different implementation ofhv_setup_sched_clock()on ARM64.
Then stick it in a header or something. The important part is that the compiler generates:
4b737: 48 c7 05 00 00 00 00 movq $0x0,0x0(%rip) # 4b742 <hv_init_clocksource+0x4d>
4b73e: 00 00 00 00
4b73a: R_X86_64_PC32 pv_ops 4b73e: R_X86_64_32S .text+0x827880
Where:
96378: 0000000000827880 32 FUNC LOCAL DEFAULT 4 read_hv_sched_clock_msr
Otherwise objtool cannot find the assignment and you get to keep the pieces.