From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x227Pr//AYoQNmS/hVigeDGem1rG9pCEnCcHns9R4+bTC5hfC3CVt1kXHz7yX3FXnSYbFt5KW ARC-Seal: i=1; a=rsa-sha256; t=1516721585; cv=none; d=google.com; s=arc-20160816; b=mognPqgNjxEox1+Z5Tkh1JujrwXMCbQC0v1YeLW99CfjkOGVm0nD6pfOI+Dr2CXq9P 9MeG9TAwfJfPjnti9RCjsg8tMqz76w2EDc0zY3i6onixHI5eht5qEN6kCPgfPtomOBVr IS3wDjExby5pNO4eYyR5MRu/DH/ydgpcUekCXbwM1b5TasM0vJMzUgaVDMPbFE5jfyF9 Ww5FHcuKSVcm0uqGeqz17zcp/ryYoun02vzZeiPsmx7tKe8hV3PXcEI6RftU+m2Swout BJxG9GZ6d0xm210jnqAGbg5WLsLxQ7vgGwR9pAGd5YwTckjbAvCVkXtvKKTflWUsrrFH Wo2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature:arc-authentication-results; bh=4CmBtgdDIJ6TU9t4PwXfYr7FLiFUkgAnyobgfsRh5L4=; b=rmlAhm8d9cfadYF+ddkJqLUacM6Hit8YxZaBDvlFO+yxoVySVK6VelQE/rciWvWPSS HBxJW1PyzOIPyO4rrykKHOflBlVbLNnKxRLXJnKyKD87P+KKyfObDMreWpwZ67E3uURQ Jd72hKTzDfm52JdEUmcv/OUhVWtlpMpeBTGG9tArecslRjPrv/zpLFEDk2IsVSEWliV7 Qw+vaO9VffwQZxl6fWclCipc+XFggQmHSrUo8miU5n0aDUs3G3xNCia7MN1C/njel5UV VFLQDP7ns0JbbVz/49GUbtGHSjmQ0Nl8lEKw9yNB6t//UJBP5HwWwoRDFORjJZEQ/JBj mH6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=ChEsp/Es; spf=pass (google.com: best guess record for domain of peterz@infradead.org designates 205.233.59.134 as permitted sender) smtp.mailfrom=peterz@infradead.org Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=ChEsp/Es; spf=pass (google.com: best guess record for domain of peterz@infradead.org designates 205.233.59.134 as permitted sender) smtp.mailfrom=peterz@infradead.org Message-Id: <20180123152638.217996936@infradead.org> User-Agent: quilt/0.63-1 Date: Tue, 23 Jan 2018 16:25:43 +0100 From: Peter Zijlstra To: David Woodhouse , Thomas Gleixner , Josh Poimboeuf Cc: linux-kernel@vger.kernel.org, Dave Hansen , Ashok Raj , Tim Chen , Andy Lutomirski , Linus Torvalds , Greg KH , Andrea Arcangeli , Andi Kleen , Arjan Van De Ven , Dan Williams , Paolo Bonzini , Jun Nakajima , Asit Mallick , Jason Baron , Peter Zijlstra Subject: [PATCH 04/24] x86,nospec: Annotate indirect calls/jumps References: <20180123152539.374360046@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=peterz-retpoline-annotate-nospec.patch X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1590397853592913916?= X-GMAIL-MSGID: =?utf-8?q?1590397853592913916?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: Annotate the indirect calls/jumps in the CALL_NOSPEC/JUMP_NOSPEC alternatives. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/nospec-branch.h | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -67,6 +67,18 @@ .endm /* + * This should be used immediately before an indirect jump/call. It tells + * objtool the subsequent indirect jump/call is vouched safe for retpoline + * builds. + */ +.macro ANNOTATE_RETPOLINE_SAFE + .Lannotate_\@: + .pushsection .discard.retpoline_safe + _ASM_PTR .Lannotate_\@ + .popsection +.endm + +/* * These are the bare retpoline primitives for indirect jmp and call. * Do not use these directly; they only exist to make the ALTERNATIVE * invocation below less ugly. @@ -102,9 +114,9 @@ .macro JMP_NOSPEC reg:req #ifdef CONFIG_RETPOLINE ANNOTATE_NOSPEC_ALTERNATIVE - ALTERNATIVE_2 __stringify(jmp *\reg), \ + ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *\reg), \ __stringify(RETPOLINE_JMP \reg), X86_FEATURE_RETPOLINE, \ - __stringify(lfence; jmp *\reg), X86_FEATURE_RETPOLINE_AMD + __stringify(lfence; ANNOTATE_RETPOLINE_SAFE; jmp *\reg), X86_FEATURE_RETPOLINE_AMD #else jmp *\reg #endif @@ -113,9 +125,9 @@ .macro CALL_NOSPEC reg:req #ifdef CONFIG_RETPOLINE ANNOTATE_NOSPEC_ALTERNATIVE - ALTERNATIVE_2 __stringify(call *\reg), \ + ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; call *\reg), \ __stringify(RETPOLINE_CALL \reg), X86_FEATURE_RETPOLINE,\ - __stringify(lfence; call *\reg), X86_FEATURE_RETPOLINE_AMD + __stringify(lfence; ANNOTATE_RETPOLINE_SAFE; call *\reg), X86_FEATURE_RETPOLINE_AMD #else call *\reg #endif @@ -143,6 +155,12 @@ ".long 999b - .\n\t" \ ".popsection\n\t" +#define ANNOTATE_RETPOLINE_SAFE \ + "999:\n\t" \ + ".pushsection .discard.retpoline_safe\n\t" \ + _ASM_PTR " 999b\n\t" \ + ".popsection\n\t" + #if defined(CONFIG_X86_64) && defined(RETPOLINE) /* @@ -152,6 +170,7 @@ # define CALL_NOSPEC \ ANNOTATE_NOSPEC_ALTERNATIVE \ ALTERNATIVE( \ + ANNOTATE_RETPOLINE_SAFE \ "call *%[thunk_target]\n", \ "call __x86_indirect_thunk_%V[thunk_target]\n", \ X86_FEATURE_RETPOLINE)