Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7481180pxb; Thu, 18 Feb 2021 11:09:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJyO+d/QGKy1xBansay/rJM3NS6TEzXhj6gUH3dnTGvkEO02jUKx/Xlx3RIVHimFEq44GttO X-Received: by 2002:a17:906:f195:: with SMTP id gs21mr5429779ejb.225.1613675362617; Thu, 18 Feb 2021 11:09:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613675362; cv=none; d=google.com; s=arc-20160816; b=TytVM/DgMod6dYW+vqmeJaFDcsAB21YpRmc9gAzwC2gMvfpVs/PGV36205H2C3jvVP 9izWvteA6QC8jVqXgtr4pREo77nYyIpU+a4i/d9u2d4ORGfAsiGe+QiBYEl2ZQP3397Q gQe4TgYSZ8DxFbfaJX3hyiqrum4I8RXfP2TLz/1IrKbvAkeOyctRXZ9Kl4aG7iugZ/MA sxinthu3MhBZu5epjRuJBur5yeuyh+NehjwfYD3KLYuuGIUEJa5JjYc6aucZwc8a9pSI nmFEClitO6vZhGQV1alAaRAGE0R1btfVzLRMwwA9h+yEEyfYS81jgZGv9XZ4x3vMeGmv crww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=YEInAX1TNsWLHLuKB9znbZuL4BCWo/ES66gUmiHDjkc=; b=RlRYNA9muRKCbx+3evebdBinvFpPu32XrpDGHOXNb9p0GXN9NFKBMxUdD+TfVSCAwY qrFl7kfJ+4UZSMGbxQU6oyIPDEI+EfxAZAAYJhr819qAOSFiJ7FfK4cNOuVnsMg0MdME W1sm6QuTfqz2fMItv5CRDKvpWlsSB1nBvEvs4SBo8llqjAODY7Ov0Tutu83Y9WzVousZ /B6ADK03m1plhZnjMXQFwlwIBfXn3NaYanvc+y+hztKZgHSPTt2g71PYNKFAGhG1465h TgY8y4Ajt1VZFJ7F7KwvLbP2VzVJ55pxR0ww4L4N5K8e60YxTQKY44gU9HBEbgl7JVhJ P/KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="vn4N/Tpp"; 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 q3si4880062ejb.681.2021.02.18.11.08.45; Thu, 18 Feb 2021 11:09:22 -0800 (PST) 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=casper.20170209 header.b="vn4N/Tpp"; 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 S233728AbhBRTFb (ORCPT + 99 others); Thu, 18 Feb 2021 14:05:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234137AbhBRR3N (ORCPT ); Thu, 18 Feb 2021 12:29:13 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 758B2C061574 for ; Thu, 18 Feb 2021 09:28:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=YEInAX1TNsWLHLuKB9znbZuL4BCWo/ES66gUmiHDjkc=; b=vn4N/Tppv+FbRAmhhWqjTcOvoA wdDHNQFzXedToiTfjwwcv5aBXR76AydbTEBvLsjlbbhpePgajlyyZPtV6F01P9zqgl4XsOZ6MEB6G 6swu9ssKyosBfRoLW/gMUZjSzpJQwrBMljGB1RL8TPxJcxYSK8Q44TVLx1sMjrZQkqlLhX0BXhpud yBVJHy7nwxLIv3FPwuDucRq6mAFpyfRUea1e/8BH24mz20rU7nc10MCqi09zK3YJUPjn8RyzGhcyX F0DpHMVH4xIFcmLd4xIJsZ99Nau2B8TP4KJiu7efpiaGQ9ROqownDL0lh7c3hUaAAvSqPvrb18SDe sZLIFNTg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lCn3U-001uKA-BM; Thu, 18 Feb 2021 17:25:49 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id BA0B2305C22; Thu, 18 Feb 2021 18:25:29 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 98515202549DD; Thu, 18 Feb 2021 18:25:29 +0100 (CET) Message-ID: <20210218172151.942060087@infradead.org> User-Agent: quilt/0.66 Date: Thu, 18 Feb 2021 17:59:40 +0100 From: Peter Zijlstra To: x86@kernel.org, tony.luck@intel.com, pjt@google.com Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, r.marek@assembler.cz, jpoimboe@redhat.com, jikos@kernel.org Subject: [RFC][PATCH 2/2] x86/retpoline: Compress retpolines References: <20210218165938.213678824@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org By using int3 as a speculation fence instead of lfence, we can shrink the longest alternative to just 15 bytes: 0: e8 05 00 00 00 callq a <.altinstr_replacement+0xa> 5: f3 90 pause 7: cc int3 8: eb fb jmp 5 <.altinstr_replacement+0x5> a: 48 89 04 24 mov %rax,(%rsp) e: c3 retq This means we can change the alignment from 32 to 16 bytes and get 4 retpolines per cacheline, $I win. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/lib/retpoline.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/arch/x86/lib/retpoline.S +++ b/arch/x86/lib/retpoline.S @@ -16,7 +16,7 @@ .Lspec_trap_\@: UNWIND_HINT_EMPTY pause - lfence + int3 jmp .Lspec_trap_\@ .Ldo_rop_\@: mov %\reg, (%_ASM_SP) @@ -27,7 +27,7 @@ .macro THUNK reg .section .text.__x86.indirect_thunk - .align 32 + .align 16 SYM_FUNC_START(__x86_indirect_thunk_\reg) ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), \