From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28CF2C43387 for ; Fri, 21 Dec 2018 10:27:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EF58E2176F for ; Fri, 21 Dec 2018 10:27:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389561AbeLUK15 (ORCPT ); Fri, 21 Dec 2018 05:27:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47070 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389541AbeLUK14 (ORCPT ); Fri, 21 Dec 2018 05:27:56 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BD39D7FDE4; Fri, 21 Dec 2018 10:27:55 +0000 (UTC) Received: from f28server.default (ovpn-116-118.phx2.redhat.com [10.3.116.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9377A61527; Fri, 21 Dec 2018 10:27:52 +0000 (UTC) From: Daniel Bristot de Oliveira To: linux-kernel@vger.kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Greg Kroah-Hartman , Masami Hiramatsu , "Steven Rostedt (VMware)" , Jiri Kosina , Josh Poimboeuf , "Peter Zijlstra (Intel)" , Chris von Recklinghausen , Jason Baron , Scott Wood , Marcelo Tosatti , Clark Williams , x86@kernel.org Subject: [PATCH V3 3/9] x86/jump_label: Move checking code away from __jump_label_transform() Date: Fri, 21 Dec 2018 11:27:28 +0100 Message-Id: <296d5a75c4aee4a957ee7923127c0604903f9daa.1545228276.git.bristot@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 21 Dec 2018 10:27:55 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move the check of the current code, before updating an entry, to specialized functions. No changes in the method, only code relocation. Signed-off-by: Daniel Bristot de Oliveira Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: "H. Peter Anvin" Cc: Greg Kroah-Hartman Cc: Masami Hiramatsu Cc: "Steven Rostedt (VMware)" Cc: Jiri Kosina Cc: Josh Poimboeuf Cc: "Peter Zijlstra (Intel)" Cc: Chris von Recklinghausen Cc: Jason Baron Cc: Scott Wood Cc: Marcelo Tosatti Cc: Clark Williams Cc: x86@kernel.org Cc: linux-kernel@vger.kernel.org --- arch/x86/kernel/jump_label.c | 60 +++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c index aac0c1f7e354..7894080bd02f 100644 --- a/arch/x86/kernel/jump_label.c +++ b/arch/x86/kernel/jump_label.c @@ -37,16 +37,53 @@ static void bug_at(unsigned char *ip, int line) BUG(); } +static inline void __jump_label_trans_check_enable(struct jump_entry *entry, + enum jump_label_type type, + const unsigned char *ideal_nop, + int init) +{ + const unsigned char default_nop[] = { STATIC_KEY_INIT_NOP }; + const void *expect; + int line; + + if (init) { + expect = default_nop; line = __LINE__; + } else { + expect = ideal_nop; line = __LINE__; + } + + if (memcmp((void *)jump_entry_code(entry), expect, JUMP_LABEL_NOP_SIZE)) + bug_at((void *)jump_entry_code(entry), line); +} + +static inline void __jump_label_trans_check_disable(struct jump_entry *entry, + enum jump_label_type type, + union jump_code_union *jmp, + int init) +{ + const unsigned char default_nop[] = { STATIC_KEY_INIT_NOP }; + const void *expect; + int line; + + if (init) { + expect = default_nop; line = __LINE__; + } else { + expect = jmp->code; line = __LINE__; + } + + if (memcmp((void *)jump_entry_code(entry), expect, JUMP_LABEL_NOP_SIZE)) + bug_at((void *)jump_entry_code(entry), line); +} + + static void __ref __jump_label_transform(struct jump_entry *entry, enum jump_label_type type, void *(*poker)(void *, const void *, size_t), int init) { union jump_code_union jmp; - const unsigned char default_nop[] = { STATIC_KEY_INIT_NOP }; const unsigned char *ideal_nop = ideal_nops[NOP_ATOMIC5]; - const void *expect, *code; - int line; + const void *code; jmp.jump = 0xe9; jmp.offset = jump_entry_target(entry) - @@ -56,26 +93,13 @@ static void __ref __jump_label_transform(struct jump_entry *entry, poker = text_poke_early; if (type == JUMP_LABEL_JMP) { - if (init) { - expect = default_nop; line = __LINE__; - } else { - expect = ideal_nop; line = __LINE__; - } - + __jump_label_trans_check_enable(entry, type, ideal_nop, init); code = &jmp.code; } else { - if (init) { - expect = default_nop; line = __LINE__; - } else { - expect = &jmp.code; line = __LINE__; - } - + __jump_label_trans_check_disable(entry, type, &jmp, init); code = ideal_nop; } - if (memcmp((void *)jump_entry_code(entry), expect, JUMP_LABEL_NOP_SIZE)) - bug_at((void *)jump_entry_code(entry), line); - /* * Make text_poke_bp() a default fallback poker. * -- 2.17.1