From patchwork Wed Jun 27 16:06:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10492171 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BE7C960386 for ; Wed, 27 Jun 2018 16:07:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC00A2911C for ; Wed, 27 Jun 2018 16:07:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF6C329513; Wed, 27 Jun 2018 16:07:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8534F2911C for ; Wed, 27 Jun 2018 16:07:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=rcqWNlh81EajlPZ/+XnIJfKvY5btz9aurYbJHblVIdY=; b=rP6tAOVVelTwTfKv2/pdgLHglH 30gT17YpF/fCSWXisRgM6A72Fur2BD5dh/zEpFZ8OMMTR7dxuWwmILxDXtNHzAdMlsFhGtR37+uYm e0gC12q0Tg3BFLUuJm6GajDQ+evYeg1OcxQkkUcd6p5cAZa4Lr3AYwPBGrhbVLypPWLpSwY14DgGS q4yj7GtSWTAU5C8wFCWiNfiYXNWnjaedwLIwIh3nCUZFAvfpHlftGhTne0dQhi6xvDjsjaTmdNcmd eCyWs7BOe2tYWmTDdpAWaS+FACFVdkEnewc86EUq2R7Psv+/D5jrkKbYmHScqvmsGijrA6yHoI/zd yinaNj5g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fYCyk-0000qB-1F; Wed, 27 Jun 2018 16:07:34 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fYCxe-0000Bw-7Z for linux-arm-kernel@lists.infradead.org; Wed, 27 Jun 2018 16:06:35 +0000 Received: by mail-wm0-x244.google.com with SMTP id l15-v6so18434161wmc.1 for ; Wed, 27 Jun 2018 09:06:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3yRjPsLxkB46VvOLi+86pNrf3CoOWXbFse0Dmkmvc3s=; b=dJd/8Yyxskiuc9hVUV5Gfebg3Y4+xz/jCiFF1KxcKQSG52XBlC+lTLyMk2p8oPrGG3 KmsT5bX8P+tY1kJZmQGtm6EgEYtf29u8fShb3/iUI1R2lnezr+6CZn00weWsHco3D7F/ +LKJ4oW6Qi4mWcz25rt1dZmJvl26KrnPeURcI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3yRjPsLxkB46VvOLi+86pNrf3CoOWXbFse0Dmkmvc3s=; b=pJfZXkEXpxy0w8Jo/pGF3fGJn9tLIIQY+C1SLEFEoDCcFkETpJzbL1lQ07RaI4a53X sZrTW1hyYeVYM28MEWCWph9n3/tVUsDWupdWxDIVl2uj1hbUbFEkHJ4+WMnFxs7FTnLQ q55ChfVS08S1trITxg4pLgKTOJk+WYmZuJ1faVkuZI9A5hWuuZhb3dLTOymgVS36Kiwm VLB5fNN+tJbl4l1EotuHiR9h0iH1menqL9SNhJ/Hz8UjzcjzHnwgrumjEW0ev5RnMFn7 J+YljJK0fclPpE1HFrypDoDsxm4OpWKgl9gg7SBGT8ruNTjr521nyo/RGHxhm1fpn/Wj dceg== X-Gm-Message-State: APt69E34hiwv3CCUHl1iZhSZLDEmNT7LIC3jQHu8fIwj4hIA06Kh2ehC tUCHNcI4AFXA9dQ22QGtGyVBGw== X-Google-Smtp-Source: AAOMgpf9G7gd1KRY4fu3ItjJD1auo+SpbRqj/+tvzT9A7b9mjDeeZTM8FVH+1gtaxsvatqK82e2nkQ== X-Received: by 2002:a1c:9c4c:: with SMTP id f73-v6mr5286896wme.141.1530115574543; Wed, 27 Jun 2018 09:06:14 -0700 (PDT) Received: from rev02.home ([2a01:cb1d:112:6f00:4d04:66e:dea8:5b23]) by smtp.gmail.com with ESMTPSA id s2-v6sm7055000wrn.75.2018.06.27.09.06.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Jun 2018 09:06:13 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org Subject: [PATCH 5/5] x86/kernel: jump_table: use relative references Date: Wed, 27 Jun 2018 18:06:04 +0200 Message-Id: <20180627160604.8154-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180627160604.8154-1-ard.biesheuvel@linaro.org> References: <20180627160604.8154-1-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180627_090626_882484_072D3A45 X-CRM114-Status: GOOD ( 14.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , Ard Biesheuvel , Peter Zijlstra , Catalin Marinas , Will Deacon , Steven Rostedt , Ingo Molnar , Thomas Gleixner MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Similar to the arm64 case, 64-bit x86 can benefit from using 32-bit relative references rather than 64-bit absolute ones when emitting struct jump_entry instances. Not only does this reduce the memory footprint of the entries themselves by 50%, it also removes the need for carrying relocation metadata on relocatable builds (i.e., for KASLR) which saves a fair chunk of .init space as well (although the savings are not as dramatic as on arm64) Signed-off-by: Ard Biesheuvel --- arch/x86/Kconfig | 1 + arch/x86/include/asm/jump_label.h | 28 ++++++-------------- tools/objtool/special.c | 4 +-- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index e10a3542db7e..dd71258ec1cc 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -118,6 +118,7 @@ config X86 select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_HUGE_VMAP if X86_64 || X86_PAE select HAVE_ARCH_JUMP_LABEL + select HAVE_ARCH_JUMP_LABEL_RELATIVE select HAVE_ARCH_KASAN if X86_64 select HAVE_ARCH_KGDB select HAVE_ARCH_MMAP_RND_BITS if MMU diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_label.h index 8c0de4282659..d0f1f25b41d5 100644 --- a/arch/x86/include/asm/jump_label.h +++ b/arch/x86/include/asm/jump_label.h @@ -36,8 +36,8 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran asm_volatile_goto("1:" ".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t" ".pushsection __jump_table, \"aw\" \n\t" - _ASM_ALIGN "\n\t" - _ASM_PTR "1b, %l[l_yes], %c0 + %c1 \n\t" + ".balign 4\n\t" + ".long 1b - ., %l[l_yes] - ., %c0 + %c1 - .\n\t" ".popsection \n\t" : : "i" (key), "i" (branch) : : l_yes); @@ -52,8 +52,8 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool ".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t" "2:\n\t" ".pushsection __jump_table, \"aw\" \n\t" - _ASM_ALIGN "\n\t" - _ASM_PTR "1b, %l[l_yes], %c0 + %c1 \n\t" + ".balign 4\n\t" + ".long 1b - ., %l[l_yes] - ., %c0 + %c1 - .\n\t" ".popsection \n\t" : : "i" (key), "i" (branch) : : l_yes); @@ -62,18 +62,6 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool return true; } -#ifdef CONFIG_X86_64 -typedef u64 jump_label_t; -#else -typedef u32 jump_label_t; -#endif - -struct jump_entry { - jump_label_t code; - jump_label_t target; - jump_label_t key; -}; - #else /* __ASSEMBLY__ */ .macro STATIC_JUMP_IF_TRUE target, key, def @@ -87,8 +75,8 @@ struct jump_entry { .byte STATIC_KEY_INIT_NOP .endif .pushsection __jump_table, "aw" - _ASM_ALIGN - _ASM_PTR .Lstatic_jump_\@, \target, \key + .balign 4 + .long .Lstatic_jump_\@ - ., \target - ., \key - . .popsection .endm @@ -103,8 +91,8 @@ struct jump_entry { .Lstatic_jump_after_\@: .endif .pushsection __jump_table, "aw" - _ASM_ALIGN - _ASM_PTR .Lstatic_jump_\@, \target, \key + 1 + .balign 4 + .long .Lstatic_jump_\@ - ., \target - ., \key + 1 - . .popsection .endm diff --git a/tools/objtool/special.c b/tools/objtool/special.c index 84f001d52322..98ae55b39037 100644 --- a/tools/objtool/special.c +++ b/tools/objtool/special.c @@ -30,9 +30,9 @@ #define EX_ORIG_OFFSET 0 #define EX_NEW_OFFSET 4 -#define JUMP_ENTRY_SIZE 24 +#define JUMP_ENTRY_SIZE 12 #define JUMP_ORIG_OFFSET 0 -#define JUMP_NEW_OFFSET 8 +#define JUMP_NEW_OFFSET 4 #define ALT_ENTRY_SIZE 13 #define ALT_ORIG_OFFSET 0