Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1427544pxb; Tue, 26 Oct 2021 08:50:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJcArlerMERQVNWWWL0GruERz2p05rU8AgcCzkRPNygP6awmILjdjWXvxswmAYDUdzGX3/ X-Received: by 2002:a63:8f5a:: with SMTP id r26mr12895094pgn.50.1635263409165; Tue, 26 Oct 2021 08:50:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635263409; cv=none; d=google.com; s=arc-20160816; b=XDLH8fQrs2xcZAHaZQB2ZVdgpS5YuqI0+UGRq6W3DxD3IjM56dCqPiS4+LlecHmYGl rENnLyOXLoR+WuW7X4EIiMYVTbZ0mbIyerqa0DkTd/qbluAznUizsZEb5VybySIukkrb 4iD3m93sMrSXqLT9M3iiri13MzGltTFbL0Hd0hFlLRy6eGGLUieUESJU4gg8P1J5OL9E glYOz5PSku5O0/pcePsXpCPWw5C0PCAqWokFYQ67ZJkGmH73FLVl8HErcnmymFhQz/Yo bF7fLasycfgIpBZC7rRdOUO7tDV6ogHJGgVoBqgZiWdR+2hA0Sk2f4RXEGOL3ya/+QE3 reFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:user-agent:message-id :dkim-signature; bh=XxknQUF5RAR+Y8Cwm798ztoeVs35pawGpR1E3DNaP58=; b=N7hzGwD0iSX/fy3sxBXTIfUbXkUkNGRIULt9eYbN38XL9kVsu3VIdh5oojUuQtvCdJ d6KgSA1W33XWduVvVeW06F0FtgNiJA0Sj2b1JlmAuNfSDSbUlndDMTRwMbgwR8sbP6VP BlelxVDQsCx66mOjGCPSsTr/GBBFS5Mz5cp3DHTn+kdO9hCF3MCS54+7tZ/lYx2MyOUi hPbswPHx4uDQJlPkoXsjX89CP2VaLW+dQ+JJblyuJw5+pP/vyqFPWG2FF7OG+rN/duzT 3bIW2YrE94n3s4vpsglbmtfCXm9vIuDeECRQ564drbFHn/xkuySP2NtlZqWg6qjSwvcn RS0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=GzXb9WtN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u18si14331045plg.438.2021.10.26.08.49.56; Tue, 26 Oct 2021 08:50:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=GzXb9WtN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235694AbhJZMH4 (ORCPT + 99 others); Tue, 26 Oct 2021 08:07:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235626AbhJZMHt (ORCPT ); Tue, 26 Oct 2021 08:07:49 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33CCCC061745; Tue, 26 Oct 2021 05:05:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Subject:Cc:To:From:Date:Message-ID: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To:References; bh=XxknQUF5RAR+Y8Cwm798ztoeVs35pawGpR1E3DNaP58=; b=GzXb9WtNssAVj2aa3fm04AYWI1 Uco3DTB+WVJQJKAn4GXBrANyEM6kXMINqLfWagDPlZ2dWyig3RuJm0X4yYvLsFcjIGFcGOI2g8xup IqREnJ2Gc9dm166uFUs58SQrLzX6yGbaLDYV3k6sHGy/276nwYE5GDFdWkRDnzKlhPbTbXXi1SqhP RKRLokgIfOkn5vcsHD3LbV9/TAFG/KSZsmDnwsgvS8iRid/t3nwZp3gyp63vYxcTxXFyWZQhIMLX+ mVnvC70mrmOjvANDoU1rsbYbcezMhTveSbv0WbDvRGWEM7rAW8ObO+R9nxuNCtp0sXvJ46qRPqN0v pPqL9rcw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfLCd-00CM0u-9D; Tue, 26 Oct 2021 12:05:15 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 21E963002AE; Tue, 26 Oct 2021 14:05:14 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id EF16C25E57E54; Tue, 26 Oct 2021 14:05:13 +0200 (CEST) Message-ID: <20211026120132.613201817@infradead.org> User-Agent: quilt/0.66 Date: Tue, 26 Oct 2021 14:01:32 +0200 From: Peter Zijlstra To: x86@kernel.org, jpoimboe@redhat.com, andrew.cooper3@citrix.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, alexei.starovoitov@gmail.com, ndesaulniers@google.com, bpf@vger.kernel.org Subject: [PATCH v3 00/16] x86: Rewrite the retpoline rewrite logic Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, These patches rewrite the way retpolines are rewritten. Currently objtool emits alternative entries for most retpoline calls. However trying to extend that led to trouble (ELF files are horrid). Therefore completely overhaul this and have objtool emit a .retpoline_sites section that lists all compiler generated retpoline thunk calls. Then the kernel can do with them as it pleases. Notably it will: - rewrite them to indirect instructions for !RETPOLINE - rewrite them to lfence; indirect; for RETPOLINE_AMD, where size allows (boo clang!) Specifically, the !RETPOLINE case can now also deal with the clang-special conditional-indirect-tail-call: Jcc __x86_indirect_thunk_\reg. Finally, also update the x86 BPF jit to catch up to recent times and do these same things. All this should help improve performance by removing an indirection. Patches can (soon) be found here: git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git objtool/core Changes since v2: - rewrite the __x86_indirect_thunk_array[] stuff again - rewrite the retpoline,amd rewrite logic, it now also supports rewriting the Jcc case, if the original instruction is long enough, but more importantly, it's simpler code. - bpf label simplification patch - random assorted cleanups - actually managed to get bpf selftests working --- arch/um/kernel/um_arch.c | 4 + arch/x86/include/asm/GEN-for-each-reg.h | 14 ++- arch/x86/include/asm/alternative.h | 1 + arch/x86/include/asm/asm-prototypes.h | 18 --- arch/x86/include/asm/nospec-branch.h | 72 ++--------- arch/x86/kernel/alternative.c | 189 ++++++++++++++++++++++++++++- arch/x86/kernel/cpu/bugs.c | 7 -- arch/x86/kernel/module.c | 9 +- arch/x86/kernel/vmlinux.lds.S | 14 +++ arch/x86/lib/retpoline.S | 56 ++------- arch/x86/net/bpf_jit_comp.c | 160 +++++++++--------------- arch/x86/net/bpf_jit_comp32.c | 22 +++- tools/objtool/arch/x86/decode.c | 120 ------------------ tools/objtool/check.c | 208 ++++++++++++++++++++++---------- tools/objtool/elf.c | 84 ------------- tools/objtool/include/objtool/check.h | 1 - tools/objtool/include/objtool/elf.h | 6 +- tools/objtool/special.c | 8 -- 18 files changed, 472 insertions(+), 521 deletions(-)