On 02/10/18 11:12, Jan Beulich wrote:
> In a number of cases the targets of indirect calls get determined once
> at boot time. In such cases we can replace those calls with direct ones
> via our alternative instruction patching mechanism.
>
> Some of the targets (in particular the hvm_funcs ones) get established
> only in pre-SMP initcalls, making necessary a second passs through the
> alternative patching code. Therefore some adjustments beyond the
> recognition of the new special pattern are necessary there.
>
> Note that patching such sites more than once is not supported (and the
> supplied macros also don't provide any means to do so).
>
> Signed-off-by: Jan Beulich <jbeul...@suse.com>

Reviewing just the code generation at this point.

See the Linux source code for ASM_CALL_CONSTRAINT.  There is a potential
code generation issue if you've got a call instruction inside an asm
block if you don't list the stack pointer as a clobbered output.

Next, with Clang, there seems to be some a bug causing the function
pointer to be spilled onto the stack

ffff82d08026e990 <foo2>:
ffff82d08026e990:       50                      push   %rax
ffff82d08026e991:       48 8b 05 40 bc 20 00    mov    0x20bc40(%rip),%rax      
  # ffff82d08047a5d8 <hvm_funcs+0x130>
ffff82d08026e998:       48 89 04 24             mov    %rax,(%rsp)
ffff82d08026e99c:       ff 15 36 bc 20 00       callq  *0x20bc36(%rip)        # 
ffff82d08047a5d8 <hvm_funcs+0x130>
ffff82d08026e9a2:       31 c0                   xor    %eax,%eax
ffff82d08026e9a4:       59                      pop    %rcx
ffff82d08026e9a5:       c3                      retq   
ffff82d08026e9a6:       66 2e 0f 1f 84 00 00    nopw   %cs:0x0(%rax,%rax,1)
ffff82d08026e9ad:       00 00 00 


I'm not quite sure what is going on here, and the binary does boot, but
the code gen is definitely not correct.  Given this and the GCC bugs
you've found leading to the NO_ARG infrastructure, how about dropping
all the compatibility hacks, and making the infrastructure fall back to
a regular compiler-inserted function pointer call?

I think it is entirely reasonable to require people wanting to use this
optimised infrastructure to be using new-enough compilers, and it would
avoid the need to carry compatibility hacks for broken compilers.

Next, the ASM'd calls aren't SYSV-ABI compliant.

extern void bar(void);

int foo1(void)
{
    hvm_funcs.wbinvd_intercept();
    return 0;
}

int foo2(void)
{
    alternative_vcall(hvm_funcs.wbinvd_intercept);
    return 0;
}

int bar1(void)
{
    bar();
    return 0;
}

ffff82d08026e1e0 <foo1>:
ffff82d08026e1e0:       48 83 ec 08             sub    $0x8,%rsp
ffff82d08026e1e4:       48 8b 05 c5 49 1d 00    mov    0x1d49c5(%rip),%rax      
  # ffff82d080442bb0 <hvm_funcs+0x130>
ffff82d08026e1eb:       e8 30 2d 0f 00          callq  ffff82d080360f20 
<__x86_indirect_thunk_rax>
ffff82d08026e1f0:       31 c0                   xor    %eax,%eax
ffff82d08026e1f2:       48 83 c4 08             add    $0x8,%rsp
ffff82d08026e1f6:       c3                      retq   
ffff82d08026e1f7:       66 0f 1f 84 00 00 00    nopw   0x0(%rax,%rax,1)
ffff82d08026e1fe:       00 00 

ffff82d08026e200 <foo2>:
ffff82d08026e200:       ff 15 aa 49 1d 00       callq  *0x1d49aa(%rip)        # 
ffff82d080442bb0 <hvm_funcs+0x130>
ffff82d08026e206:       31 c0                   xor    %eax,%eax
ffff82d08026e208:       c3                      retq   
ffff82d08026e209:       0f 1f 80 00 00 00 00    nopl   0x0(%rax)

ffff82d08026e210 <bar1>:
ffff82d08026e210:       48 83 ec 08             sub    $0x8,%rsp
ffff82d08026e214:       e8 17 18 01 00          callq  ffff82d08027fa30 <bar>
ffff82d08026e219:       31 c0                   xor    %eax,%eax
ffff82d08026e21b:       48 83 c4 08             add    $0x8,%rsp
ffff82d08026e21f:       c3                      retq   

foo2 which uses alternative_vcall() should be subtracting 8 from the
stack pointer before the emitted call instruction.  I can't find any set
of constraints which causes the stack to be set up correctly.

Finally, this series doesn't link with the default Debian toolchain.

andrewcoop@andrewcoop:/local/xen.git/xen$ ld --version
GNU ld (GNU Binutils for Debian) 2.25

andrewcoop@andrewcoop:/local/xen.git/xen$ make -s build -j8 
XEN_TARGET_ARCH=x86_64 KCONFIG_CONFIG=.config-release
 __  __            _  _    _ ____                     _        _     _      
 \ \/ /___ _ __   | || |  / |___ \    _   _ _ __  ___| |_ __ _| |__ | | ___ 
  \  // _ \ '_ \  | || |_ | | __) |__| | | | '_ \/ __| __/ _` | '_ \| |/ _ \
  /  \  __/ | | | |__   _|| |/ __/|__| |_| | | | \__ \ || (_| | |_) | |  __/
 /_/\_\___|_| |_|    |_|(_)_|_____|   \__,_|_| |_|___/\__\__,_|_.__/|_|\___|
                                                                            
prelink.o:(.debug_aranges+0x3c94): relocation truncated to fit: R_X86_64_32 
against `.debug_info'
prelink.o:(.debug_info+0x225fa): relocation truncated to fit: R_X86_64_32 
against `.debug_str'
prelink.o:(.debug_info+0x22b57): relocation truncated to fit: R_X86_64_32 
against `.debug_str'
prelink.o:(.debug_info+0x1b92da): relocation truncated to fit: R_X86_64_32 
against `.debug_str'
prelink.o:(.debug_info+0x21e976): relocation truncated to fit: R_X86_64_32 
against `.debug_str'
prelink.o:(.debug_info+0x21ec31): relocation truncated to fit: R_X86_64_32 
against `.debug_str'
prelink.o:(.debug_info+0x21f03b): relocation truncated to fit: R_X86_64_32 
against `.debug_str'
prelink.o:(.debug_info+0x2b2ac3): relocation truncated to fit: R_X86_64_32 
against `.debug_loc'
prelink.o:(.debug_info+0x2b37f6): relocation truncated to fit: R_X86_64_32 
against `.debug_str'
prelink.o:(.debug_info+0x448fab): relocation truncated to fit: R_X86_64_32 
against `.debug_str'
prelink.o:(.debug_info+0x44b856): additional relocation overflows omitted from 
the output
ld: prelink.o: access beyond end of merged section (6617683)
ld: prelink.o: access beyond end of merged section (6617630)
ld: prelink.o: access beyond end of merged section (6617579)
ld: prelink.o: access beyond end of merged section (6617558)
ld: prelink.o: access beyond end of merged section (6617544)
ld: prelink.o: access beyond end of merged section (6617605)
ld: prelink.o: access beyond end of merged section (6617718)
ld: prelink.o: access beyond end of merged section (6617570)
ld: prelink.o: access beyond end of merged section (6617665)
ld: prelink.o: access beyond end of merged section (6617671)
ld: prelink.o: access beyond end of merged section (6617624)
ld: prelink.o: access beyond end of merged section (6617748)
ld: prelink.o: access beyond end of merged section (6617771)
ld: prelink.o: access beyond end of merged section (6617592)
ld: prelink.o: access beyond end of merged section (6617635)
ld: prelink.o: access beyond end of merged section (6617652)
ld: prelink.o: access beyond end of merged section (6617766)
ld: prelink.o: access beyond end of merged section (6617742)
ld: prelink.o(.debug_info+0xc962ed): reloc against `.debug_loc': error 2
Makefile:134: recipe for target '/local/xen.git/xen/xen-syms' failed
make[2]: *** [/local/xen.git/xen/xen-syms] Error 1
make[2]: *** Waiting for unfinished jobs....
/local/xen.git/xen/.xen.efi.0s.S: Assembler messages:
/local/xen.git/xen/.xen.efi.0s.S:21: Warning: value 0x7d2f80000544 truncated to 
0x80000544
/local/xen.git/xen/.xen.efi.0s.S:22: Warning: value 0x7d2f800008dc truncated to 
0x800008dc
/local/xen.git/xen/.xen.efi.0s.S:23: Warning: value 0x7d2f800008de truncated to 
0x800008de
/local/xen.git/xen/.xen.efi.0s.S:24: Warning: value 0x7d2f800008e3 truncated to 
0x800008e3
/local/xen.git/xen/.xen.efi.0s.S:25: Warning: value 0x7d2f80001086 truncated to 
0x80001086
/local/xen.git/xen/.xen.efi.0s.S:26: Warning: value 0x7d2f8000108a truncated to 
0x8000108a
/local/xen.git/xen/.xen.efi.0s.S:27: Warning: value 0x7d2f8000108e truncated to 
0x8000108e
/local/xen.git/xen/.xen.efi.0s.S:28: Warning: value 0x7d2f800010dc truncated to 
0x800010dc
/local/xen.git/xen/.xen.efi.0s.S:29: Warning: value 0x7d2f80001172 truncated to 
0x80001172
/local/xen.git/xen/.xen.efi.1s.S: Assembler messages:
/local/xen.git/xen/.xen.efi.1s.S:21: Warning: value 0x7d2f80000544 truncated to 
0x80000544
/local/xen.git/xen/.xen.efi.1s.S:22: Warning: value 0x7d2f800008dc truncated to 
0x800008dc
/local/xen.git/xen/.xen.efi.1s.S:23: Warning: value 0x7d2f800008de truncated to 
0x800008de
/local/xen.git/xen/.xen.efi.1s.S:24: Warning: value 0x7d2f800008e3 truncated to 
0x800008e3
/local/xen.git/xen/.xen.efi.1s.S:25: Warning: value 0x7d2f80001086 truncated to 
0x80001086
/local/xen.git/xen/.xen.efi.1s.S:26: Warning: value 0x7d2f8000108a truncated to 
0x8000108a
/local/xen.git/xen/.xen.efi.1s.S:27: Warning: value 0x7d2f8000108e truncated to 
0x8000108e
/local/xen.git/xen/.xen.efi.1s.S:28: Warning: value 0x7d2f800010dc truncated to 
0x800010dc
/local/xen.git/xen/.xen.efi.1s.S:29: Warning: value 0x7d2f80001172 truncated to 
0x80001172
Makefile:136: recipe for target '/local/xen.git/xen/xen' failed
make[1]: *** [/local/xen.git/xen/xen] Error 2
Makefile:45: recipe for target 'build' failed
make: *** [build] Error 2

Using LD 2.30 built from source is fine, but I'm not sure exactly what
is going on here.

~Andrew
#
# Automatically generated file; DO NOT EDIT.
# Xen/x86 4.12-unstable Configuration
#
CONFIG_X86_64=y
CONFIG_X86=y
CONFIG_ARCH_DEFCONFIG="arch/x86/configs/x86_64_defconfig"

#
# Architecture Features
#
CONFIG_NR_CPUS=256
CONFIG_PV=y
CONFIG_PV_LINEAR_PT=y
CONFIG_HVM=y
CONFIG_SHADOW_PAGING=y
# CONFIG_BIGMEM is not set
# CONFIG_HVM_FEP is not set
CONFIG_TBOOT=y
CONFIG_XEN_GUEST=y
CONFIG_PVH_GUEST=y
CONFIG_PV_SHIM=y
# CONFIG_PV_SHIM_EXCLUSIVE is not set

#
# Common Features
#
CONFIG_COMPAT=y
CONFIG_CORE_PARKING=y
CONFIG_HAS_ALTERNATIVE=y
CONFIG_HAS_EX_TABLE=y
CONFIG_MEM_ACCESS_ALWAYS_ON=y
CONFIG_MEM_ACCESS=y
CONFIG_HAS_MEM_PAGING=y
CONFIG_HAS_MEM_SHARING=y
CONFIG_HAS_PDX=y
CONFIG_HAS_UBSAN=y
CONFIG_HAS_KEXEC=y
CONFIG_HAS_GDBSX=y
CONFIG_HAS_IOPORTS=y
CONFIG_NEEDS_LIBELF=y
CONFIG_KEXEC=y
CONFIG_TMEM=y
CONFIG_XENOPROF=y
# CONFIG_XSM is not set

#
# Schedulers
#
CONFIG_SCHED_CREDIT=y
CONFIG_SCHED_CREDIT2=y
CONFIG_SCHED_RTDS=y
CONFIG_SCHED_ARINC653=y
CONFIG_SCHED_NULL=y
CONFIG_SCHED_CREDIT_DEFAULT=y
# CONFIG_SCHED_CREDIT2_DEFAULT is not set
# CONFIG_SCHED_RTDS_DEFAULT is not set
# CONFIG_SCHED_ARINC653_DEFAULT is not set
# CONFIG_SCHED_NULL_DEFAULT is not set
CONFIG_SCHED_DEFAULT="credit"
CONFIG_CRYPTO=y
CONFIG_LIVEPATCH=y
CONFIG_FAST_SYMBOL_LOOKUP=y
CONFIG_CMDLINE=""

#
# Device Drivers
#
CONFIG_ACPI=y
CONFIG_ACPI_LEGACY_TABLES_LOOKUP=y
CONFIG_NUMA=y
CONFIG_HAS_NS16550=y
CONFIG_HAS_EHCI=y
CONFIG_HAS_CPUFREQ=y
CONFIG_HAS_PASSTHROUGH=y
CONFIG_HAS_PCI=y
CONFIG_VIDEO=y
CONFIG_VGA=y
CONFIG_HAS_VPCI=y

#
# Deprecated Functionality
#
# CONFIG_PV_LDT_PAGING is not set
CONFIG_DEFCONFIG_LIST="arch/x86/configs/x86_64_defconfig"
CONFIG_ARCH_SUPPORTS_INT128=y

#
# Debugging Options
#
# CONFIG_DEBUG is not set
# CONFIG_CRASH_DEBUG is not set
CONFIG_DEBUG_INFO=y
# CONFIG_FRAME_POINTER is not set
# CONFIG_LOCK_PROFILE is not set
# CONFIG_PERF_COUNTERS is not set
# CONFIG_VERBOSE_DEBUG is not set
# CONFIG_SCRUB_DEBUG is not set
# CONFIG_UBSAN is not set
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reply via email to