Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp1822802pxy; Thu, 6 May 2021 17:20:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7RZcPZRLZOox4CpWG0x/bAXITHX6w6MgPQ/d6wGgmReF6SwPXHhtJTh6vw8a/QtRGtM13 X-Received: by 2002:a05:6402:cac:: with SMTP id cn12mr8447309edb.238.1620346849520; Thu, 06 May 2021 17:20:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620346849; cv=none; d=google.com; s=arc-20160816; b=wg0xHmtVtyCszWhGBiX4czoEJyevYItqLr00poR3lb1et206Z6MyJi2NztGy+NpVBr kzzlqmgZlEw8DksiYwXe775iDz4FUljY07oueOVnCgrA8SXlZxEftWGlUij+04ggUarn V3SJtzBhVbKcwnDmBPRvKGQoMKEsZ/d7Nj7JnBawtexfbbaYyvVjvLXspstUG3dLWQ0B 7/YTWb+XUVadXmFmXT2PoTrWfndorXhtD5U2P+jDYBZNIe2zRBwjk5h475ejm2SV2rBn zp8l1qPPj6N2X9rOKVc5zPPyf3jNlyTZJbHP7Pg8KSilT+H372IV3nDTUGP6xxF4TE/I GN6g== 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=kFfqEufoIQb0/o5iFIo5FIoTlMfJ/zwdMcpq4uS6qSs=; b=evmF2TSE9CkFx3gnqTdFwchz1oXmhanvyGujKIpad762Pk+TUt/blkMQHrEHI/YNsz lzjP2sfq8u2m7RitDPt7ysuUpZXeDEH9gW1RdnR+2NE5XW7kd0gS9HV0xOsYLXMz6Xcb 2zDLuL7GTYDLGfAkM/RmG99EM65nRjIrlib7Tg/Zpe6g/Hf9b/4ZgPirlnMqGZ7iocQ4 heUG8U/kiLY5puOx2QiZHMWkvAEoBcxlmBLOh18Wv/hGbIu8QmS+fdzMP9BAnwNAXJPS a4J/j/8xrR+VoTyw+VjuOVxmh8qB5LRqiRa/EeeebYjMVHZd7w3MfUTfBKz37Y4Ao11x HqYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=hq8qP9rm; 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 j23si4239435eje.99.2021.05.06.17.20.24; Thu, 06 May 2021 17:20:49 -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=casper.20170209 header.b=hq8qP9rm; 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 S235842AbhEFTo6 (ORCPT + 99 others); Thu, 6 May 2021 15:44:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235649AbhEFTox (ORCPT ); Thu, 6 May 2021 15:44:53 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06531C0613ED for ; Thu, 6 May 2021 12:43:54 -0700 (PDT) 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=kFfqEufoIQb0/o5iFIo5FIoTlMfJ/zwdMcpq4uS6qSs=; b=hq8qP9rmExfa7s3B5OVsv6VyQw EEvAGibZ2qBKj9IHdFFTttrGz2g3Dv3ZZdbrHeBuXH/zFTyVnXs6xxCnIB5+GD+MFqMy+z/rHXrOG K8FUn6jGRTSplDLkzTI7kQqC8yKl0AEjBQQeTZpddQnrEb6cc8I0L3cbInbgMjYXqCD6VX13fSnjv xHftAlcBtIPe+9jlbUK68qAr0K7IgFFZCswkCI9NQZyvHuRPuOZTeiS7U3LLV3NXwPoSxhrkCVFIq Rvf+QHlu1cx+8doYyDr9nP4AANGvrPwGA/oNTybPq+/tOzLHnEDG0UXkIIVfLxnswsk/8bvkJOkv3 atR8B9/Q==; 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 1lejtT-002ADI-VR; Thu, 06 May 2021 19:42:54 +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)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 296DF300391; Thu, 6 May 2021 21:42:39 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id DC65B20B96F96; Thu, 6 May 2021 21:42:38 +0200 (CEST) Message-ID: <20210506194158.216763632@infradead.org> User-Agent: quilt/0.66 Date: Thu, 06 May 2021 21:34:05 +0200 From: Peter Zijlstra To: x86@kernel.org, jpoimboe@redhat.com, jbaron@akamai.com, rostedt@goodmis.org, ardb@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org Subject: [PATCH 13/13] jump_label,x86: Allow short NOPs References: <20210506193352.719596001@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 Now that objtool is able to rewrite jump_label instructions, have the compiler emit a JMP, such that it can decide on the optimal encoding, and set jump_entry::key bit1 to indicate that objtool should rewrite the instruction to a matching NOP. For x86_64-allyesconfig this gives: jl\ NOP JMP short: 22997 124 long: 30874 90 IOW, we save (22997+124) * 3 bytes of kernel text in hotpaths. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/jump_label.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) --- a/arch/x86/include/asm/jump_label.h +++ b/arch/x86/include/asm/jump_label.h @@ -28,6 +28,22 @@ _ASM_PTR "%c0 + %c1 - .\n\t" \ ".popsection \n\t" +#ifdef CONFIG_STACK_VALIDATION + +static __always_inline bool arch_static_branch(struct static_key *key, bool branch) +{ + asm_volatile_goto("1:" + "jmp %l[l_yes] # objtool NOPs this \n\t" + JUMP_TABLE_ENTRY + : : "i" (key), "i" (2 | branch) : : l_yes); + + return false; +l_yes: + return true; +} + +#else + static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch) { asm_volatile_goto("1:" @@ -40,6 +56,8 @@ static __always_inline bool arch_static_ return true; } +#endif /* STACK_VALIDATION */ + static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch) { asm_volatile_goto("1:"