From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751463AbdHaON3 (ORCPT ); Thu, 31 Aug 2017 10:13:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55646 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750990AbdHaON2 (ORCPT ); Thu, 31 Aug 2017 10:13:28 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DC026267C1 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jpoimboe@redhat.com From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , Andy Lutomirski , Linus Torvalds , Alexander Potapenko , Dmitriy Vyukov , Matthias Kaehlcke , Arnd Bergmann , Peter Zijlstra Subject: [RFC PATCH 0/4] x86/asm: Add ASM_CALL() macro for inline asms with call instructions Date: Thu, 31 Aug 2017 09:11:16 -0500 Message-Id: X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 31 Aug 2017 14:13:28 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Making this RFC because I'm not sure if there's a better solution (like maybe trying to convince the clang folks to support the undocumented GCC syntax for this). Opinions and better ideas welcome. For inline asm statements which have a "call" instruction, we have to set the stack pointer as a constraint to convince GCC to ensure the frame pointer is set up first: register void *__sp asm(_ASM_SP); asm("call foo" : "+r" (__sp)) Clang doesn't have a known way to do the same thing. Doing the sp constraint thing causes it to corrupt the stack pointer. Patch 4/4 adds a wrapper around such inline asm statements. Before: register void *__sp asm(_ASM_SP); asm("call foo" : outputs, "+r" (__sp) : inputs : clobbers); After: ASM_CALL("call foo", outputs, inputs, clobbers); A limitation of the wrapper is that it doesn't support positional operand names ("%0") and constraints ("0" (foo)). The benefits of the wrapper are: - Allows clang-built kernels to boot. - Removes the stack pointer constraint with CONFIG_FRAME_POINTER=n (which may soon become the default). - Will make it easy to handle if we ever get a documented way to do this. NOTE: Patch 4/4 triggers a bug in the sparse preprocessor which causes the kbuild robot to complain. I've reported the bug to the sparse mailing list. Josh Poimboeuf (4): x86/paravirt: Fix output constraint macro names x86/asm: Convert some inline asm positional operands to named operands x86/asm: Make alternative macro interfaces more clear and consistent x86/asm: Use ASM_CALL() macro for inline asm statements with call instructions arch/x86/include/asm/alternative.h | 72 ++++------- arch/x86/include/asm/apic.h | 7 +- arch/x86/include/asm/arch_hweight.h | 14 +- arch/x86/include/asm/atomic64_32.h | 101 +++++++++------ arch/x86/include/asm/cmpxchg_32.h | 20 +-- arch/x86/include/asm/mshyperv.h | 51 ++++---- arch/x86/include/asm/page_64.h | 6 +- arch/x86/include/asm/paravirt_types.h | 86 ++++++------- arch/x86/include/asm/percpu.h | 13 +- arch/x86/include/asm/preempt.h | 15 +-- arch/x86/include/asm/processor.h | 41 +++--- arch/x86/include/asm/rwsem.h | 155 ++++++++++++----------- arch/x86/include/asm/special_insns.h | 7 +- arch/x86/include/asm/uaccess.h | 24 ++-- arch/x86/include/asm/uaccess_64.h | 16 +-- arch/x86/include/asm/xen/hypercall.h | 59 +++++---- arch/x86/kvm/emulate.c | 9 +- arch/x86/kvm/vmx.c | 17 +-- arch/x86/mm/fault.c | 13 +- include/linux/compiler-clang.h | 2 + include/linux/compiler-gcc.h | 19 +++ include/linux/compiler.h | 34 +++++ tools/objtool/Documentation/stack-validation.txt | 19 +-- 23 files changed, 427 insertions(+), 373 deletions(-) -- 2.13.5