From ea263bc472eb89dd8696df3f910e299f3f22526b Mon Sep 17 00:00:00 2001 From: Nicolas Viennot Date: Fri, 17 Jul 2020 02:39:52 +0000 Subject: [PATCH] compel: x86 parasite_service entry point simplification We don't need to push 0 on the stack. This seems to be a remnant of the initial commit of 2011 that had a `pushq $0`. The 16 bytes %rsp alignment was added with commit 2a0cea29 in 2012. This is no longer necessary as we already guarantee that %rsp is 16 bytes aligned. A BUG_ON() is added to enforce this guarantee. Signed-off-by: Nicolas Viennot --- compel/arch/x86/plugins/std/parasite-head.S | 12 ++---------- compel/src/lib/infect.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/compel/arch/x86/plugins/std/parasite-head.S b/compel/arch/x86/plugins/std/parasite-head.S index 2225568b9..4fb38d1f1 100644 --- a/compel/arch/x86/plugins/std/parasite-head.S +++ b/compel/arch/x86/plugins/std/parasite-head.S @@ -6,14 +6,6 @@ # error 64-bit parasite should compile with CONFIG_X86_64 #endif -.macro PARASITE_ENTRY num - subq $16, %rsp - andq $~15, %rsp - pushq $\num - movq %rsp, %rbp - call parasite_service -.endm - #ifdef CONFIG_COMPAT .code32 ENTRY(__export_parasite_head_start_compat) @@ -21,7 +13,7 @@ ENTRY(__export_parasite_head_start_compat) jmp $__USER_CS,$1f 1: .code64 - PARASITE_ENTRY 0 + call parasite_service pushq $__USER32_CS xor %r11, %r11 movl $2f, %r11d @@ -43,6 +35,6 @@ END(__export_parasite_head_start_compat) #endif ENTRY(__export_parasite_head_start) - PARASITE_ENTRY 0 + call parasite_service int $0x03 END(__export_parasite_head_start) diff --git a/compel/src/lib/infect.c b/compel/src/lib/infect.c index 78fe1f1a6..da02d1744 100644 --- a/compel/src/lib/infect.c +++ b/compel/src/lib/infect.c @@ -948,6 +948,17 @@ int compel_infect(struct parasite_ctl *ctl, unsigned long nr_threads, unsigned l p += PARASITE_STACK_SIZE; ctl->rstack = ctl->remote_map + p; + /* + * x86-64 ABI requires a 16 bytes aligned stack. + * It is already the case as RESTORE_STACK_SIGFRAME is a multiple of + * 64, and PARASITE_STACK_SIZE is 0x4000. + */ + if ((unsigned long)ctl->rstack & (16-1)) { + pr_err("BUG: stack is not 16 bytes aligned: %p\n", ctl->rstack); + ctl->rstack = (void *)round_down((unsigned long)ctl->rstack, 16); + } + + if (nr_threads > 1) { p += PARASITE_STACK_SIZE; ctl->r_thread_stack = ctl->remote_map + p;