Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3544421imm; Mon, 8 Oct 2018 05:54:21 -0700 (PDT) X-Google-Smtp-Source: ACcGV61fk57SBNWw1XbrGtCRy1rR8pvrLVLyWgGYq2BkpqMAb0jK+Gb3ZqxK1bqOo1kBliZxFdmf X-Received: by 2002:a17:902:b784:: with SMTP id e4-v6mr23854174pls.284.1539003261936; Mon, 08 Oct 2018 05:54:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539003261; cv=none; d=google.com; s=arc-20160816; b=s9zW3HfzarPW5Vx4bOf+a+WbsF5uOqgCniqJnArCFUIPnI5r4LkkXb8ySS5/pa9Ilh PSNi/RQwuBdGbBp6l4Hyr5p2ZgdBxORDqdcqvq2rcpijfbnJUHLGxCaXjT58D2cUbeNw O7YfKUIZbN7r/ZifsVCX24KHfeXW92rhrtdSK78HGxWVnkajSvkPwIiia87fnN5rSbNZ E2edGExvQlzxhNGhbzNAbxXF2g1aRn9B+dFsi4TtvUkhvAyo5jMdw2T8T/QRFjFOBG/a e6ULCnWjQOuMYnqSwipBFwLrMxUSHo3eMeP8vFiytpyGw680Wzwtm55v6HkcRUIOVkIW ZX8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=68UtzaRIpckevxaNeObcFuARuSYJwA5WyPkzlpnEFzU=; b=SO6GhARs8hb5+cXV0aUPFbDqIzp3Hxy+QnSEVlZBuveZMmrl0zCFBXBATdRegS8AOu ZVthSlaHInJnA/x6hG5B1/E4PofLvBEf7/GEmjdvRzn+ixt5i22K87uKreZOiSP4Rueh iGknhvANQUG8Ik4iVn4UPDtQeVUaO3q7PYOdx2dTEy88VlSi5fRcYlkB+3F/i3P8b4f4 w8goGwmafeco1mxvshObnGfxouQJJqV7ajxOT7BaYLrtpByAbnNXGJLeYRwWnOOWlU+Y wUkX2P530t1ow4DCYQOvrO9mXPHWVDMBUWXMt6RAjFibHxA+ImOt8k1sn5f5wHJggbwW +TJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 204-v6si19928130pfx.155.2018.10.08.05.54.06; Mon, 08 Oct 2018 05:54:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726668AbeJHUFS (ORCPT + 99 others); Mon, 8 Oct 2018 16:05:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35864 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725893AbeJHUFS (ORCPT ); Mon, 8 Oct 2018 16:05:18 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2709D3084258; Mon, 8 Oct 2018 12:53:43 +0000 (UTC) Received: from f28server.default (ovpn-116-135.phx2.redhat.com [10.3.116.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE3EE61D3F; Mon, 8 Oct 2018 12:53:33 +0000 (UTC) From: Daniel Bristot de Oliveira To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Greg Kroah-Hartman , Pavel Tatashin , Masami Hiramatsu , "Steven Rostedt (VMware)" , Zhou Chengming , Jiri Kosina , Josh Poimboeuf , "Peter Zijlstra (Intel)" , Chris von Recklinghausen , Jason Baron , Scott Wood , Marcelo Tosatti , Clark Williams Subject: [RFC PATCH 3/6] x86/jump_label: Move checking code away from __jump_label_transform() Date: Mon, 8 Oct 2018 14:53:02 +0200 Message-Id: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 08 Oct 2018 12:53:43 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch creates two new functions, __jump_label_enabling_check() and __jump_label_disabling_check(), to make the respective check before updating a jump_entry. 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: Pavel Tatashin Cc: Masami Hiramatsu Cc: "Steven Rostedt (VMware)" Cc: Zhou Chengming 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 | 88 ++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 35 deletions(-) diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c index eeea935e9bb5..a11d836d9aaa 100644 --- a/arch/x86/kernel/jump_label.c +++ b/arch/x86/kernel/jump_label.c @@ -37,57 +37,75 @@ static void bug_at(unsigned char *ip, int line) BUG(); } +static inline void __jump_label_enabling_check(struct jump_entry *entry, + enum jump_label_type type, + int init) +{ + const unsigned char default_nop[] = { STATIC_KEY_INIT_NOP }; + const unsigned char *ideal_nop = ideal_nops[NOP_ATOMIC5]; + + if (init) { + /* + * Jump label is enabled for the first time. + * So we expect a default_nop... + */ + if (unlikely(memcmp((void *)entry->code, default_nop, 5) + != 0)) + bug_at((void *)entry->code, __LINE__); + } else { + /* + * ...otherwise expect an ideal_nop. Otherwise + * something went horribly wrong. + */ + if (unlikely(memcmp((void *)entry->code, ideal_nop, 5) + != 0)) + bug_at((void *)entry->code, __LINE__); + } +} + +static inline void __jump_label_disabling_check(struct jump_entry *entry, + enum jump_label_type type, + int init) +{ + union jump_code_union code; + const unsigned char default_nop[] = { STATIC_KEY_INIT_NOP }; + + /* + * We are disabling this jump label. If it is not what + * we think it is, then something must have gone wrong. + * If this is the first initialization call, then we + * are converting the default nop to the ideal nop. + */ + if (init) { + if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0)) + bug_at((void *)entry->code, __LINE__); + } else { + code.jump = 0xe9; + code.offset = entry->target - + (entry->code + JUMP_LABEL_NOP_SIZE); + if (unlikely(memcmp((void *)entry->code, &code, 5) != 0)) + bug_at((void *)entry->code, __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 code; - const unsigned char default_nop[] = { STATIC_KEY_INIT_NOP }; - const unsigned char *ideal_nop = ideal_nops[NOP_ATOMIC5]; if (early_boot_irqs_disabled) poker = text_poke_early; if (type == JUMP_LABEL_JMP) { - if (init) { - /* - * Jump label is enabled for the first time. - * So we expect a default_nop... - */ - if (unlikely(memcmp((void *)entry->code, default_nop, 5) - != 0)) - bug_at((void *)entry->code, __LINE__); - } else { - /* - * ...otherwise expect an ideal_nop. Otherwise - * something went horribly wrong. - */ - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5) - != 0)) - bug_at((void *)entry->code, __LINE__); - } + __jump_label_enabling_check(entry, type, init); code.jump = 0xe9; code.offset = entry->target - (entry->code + JUMP_LABEL_NOP_SIZE); } else { - /* - * We are disabling this jump label. If it is not what - * we think it is, then something must have gone wrong. - * If this is the first initialization call, then we - * are converting the default nop to the ideal nop. - */ - if (init) { - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0)) - bug_at((void *)entry->code, __LINE__); - } else { - code.jump = 0xe9; - code.offset = entry->target - - (entry->code + JUMP_LABEL_NOP_SIZE); - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0)) - bug_at((void *)entry->code, __LINE__); - } + __jump_label_disabling_check(entry, type, init); memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE); } -- 2.17.1