Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp7352619imm; Thu, 28 Jun 2018 02:13:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKGz57l0pvrN4sdBkz+7HfGa2QHk9auIyR2hDIZqBlyYtylyonTceS/iGXrmkjyh/rdOJVq X-Received: by 2002:a65:5884:: with SMTP id d4-v6mr8015623pgu.292.1530177202349; Thu, 28 Jun 2018 02:13:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530177202; cv=none; d=google.com; s=arc-20160816; b=uR+8bWv7g6qZAUJOFcqI5jyUJt/DLMKWt/fmn++9McoXiaAwEk9auWrnazwnYrUMOR dIJQhRv6LgKtWvyAN3CtNJ2ih0ndkxLpHvL/GH9a3NRJHEwJpuW+5G7h68nN47ac5ZLr odkcnjJEhrYFqIQIb+u+vkxUwWwGjbP3XOK5U8OwgQNAe2vVDojpoeHOAbWnO3DlIwy6 B6+Sr8bEPih/LPeL9keqaF+dVpQNohCsUlnQx5esaOUYxz1k0c2r28zby5FWwDxiwzyl ku3ISzP15/8qapn9O+u4sRnK4tITgKPSVGszvD4/DjFPnNGa7T9WdEkAiT1OSzxO1Z1P B4Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=a9/zy8wUhy0hrwfcr07rf+vNg9Ora18LP1Ff82f3yb8=; b=GxFOu/TzH7WWfr8tdLFsuIJALwVAfLo8otboowXevSgV4abNyVF0VlMtdIrUzwS1DF jnTEzlj6fpl+2QBPPai2pDDTpFLxUU/4i0QfvtzPXdG76GPuHzfi3XPZ7rBH4oQh7oQl 3ixA+st99ltpwCGSSM8yEUE1hB4xIbaYwTbwHeNadcu9zLojY+VHjTnm2VLZsdYDIACF btw1WEsOHoeNSywkPNT99S5KW0AiDnAHrNEt7PtHgr5kpEPYL6wBYn5CEztJCg1ODD1T I9Zw6p2qrcf8uMmuSFoyOMM9Tl3gYiDJL52QnBvOkkID6fLisjHWKf5FimzoyqOcjomZ cbtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=YZp+sSX1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s3-v6si6258121plb.394.2018.06.28.02.13.05; Thu, 28 Jun 2018 02:13:22 -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; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=YZp+sSX1; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934877AbeF1JLu (ORCPT + 99 others); Thu, 28 Jun 2018 05:11:50 -0400 Received: from merlin.infradead.org ([205.233.59.134]:52806 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933121AbeF1JLr (ORCPT ); Thu, 28 Jun 2018 05:11:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=a9/zy8wUhy0hrwfcr07rf+vNg9Ora18LP1Ff82f3yb8=; b=YZp+sSX1v06oPQ0z4rHlZpPOa Qv1L9TnOVFxrkwWz/4V4zaWlxeQaLvp8AIhnc6z52bNa7pPjyaca/ME+zD0dybh5OTUmAH0EAFZy6 kYduZcMJU0opygsCwOf2j89OyIpMmQKDoqq168zRMuyozE4VnrBJ9x2xUNc1kbN4jrU8gQo+3C6QR qZwsLas7DV3kzKommHU5/9J/8/53J/siKZc2i3GrWonMy8F1juY9TlIgI3iylMPwDpOX8uhdGJ07E PzIXmMGLjSCHp6ePdvuY2hBdquvN0VLBef/TezsujBR5lCU1KjqyGUJnDSS0KuunnAz+23XUXhx82 7QhGWrGrQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fYSxl-0002rw-A6; Thu, 28 Jun 2018 09:11:40 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E16BB2029764D; Thu, 28 Jun 2018 11:11:35 +0200 (CEST) Date: Thu, 28 Jun 2018 11:11:35 +0200 From: Peter Zijlstra To: Ard Biesheuvel Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org, Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , Arnd Bergmann , Steven Rostedt Subject: Re: [PATCH 4/5] x86: jump_label: switch to jump_entry accessors Message-ID: <20180628091135.GB2494@hirez.programming.kicks-ass.net> References: <20180627160604.8154-1-ard.biesheuvel@linaro.org> <20180627160604.8154-5-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180627160604.8154-5-ard.biesheuvel@linaro.org> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 27, 2018 at 06:06:03PM +0200, Ard Biesheuvel wrote: > In preparation of switching x86 to use place-relative references for > the code, target and key members of struct jump_entry, replace direct > references to the struct members with invocations of the new accessors. > This will allow us to make the switch by modifying the accessors only. > > Signed-off-by: Ard Biesheuvel That just makes horrible code worse.. can't we do something like so instead? --- a/arch/x86/kernel/jump_label.c +++ b/arch/x86/kernel/jump_label.c @@ -42,52 +42,37 @@ static void __jump_label_transform(struc void *(*poker)(void *, const void *, size_t), int init) { - union jump_code_union code; + union jump_code_union jmp = { + { .jump = 0xe9, + .offset = jump_entry_target(entry) - + (jump_entry_code(entry) + JUMP_LABEL_NOP_SIZE), } + }; const unsigned char default_nop[] = { STATIC_KEY_INIT_NOP }; const unsigned char *ideal_nop = ideal_nops[NOP_ATOMIC5]; + const unsigned char *expect, *code; + int line; 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__); + expect = default_nop; line = __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__); + expect = ideal_nop; line = __LINE__; } - code.jump = 0xe9; - code.offset = entry->target - - (entry->code + JUMP_LABEL_NOP_SIZE); + code = &jmp.code; } 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__); + expect = default_nop; line = __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__); + expect = &jmp.code; line = __LINE__; } - memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE); + + 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. * @@ -96,11 +81,13 @@ static void __jump_label_transform(struc * always nop being the 'currently valid' instruction * */ - if (poker) - (*poker)((void *)entry->code, &code, JUMP_LABEL_NOP_SIZE); - else - text_poke_bp((void *)entry->code, &code, JUMP_LABEL_NOP_SIZE, - (void *)entry->code + JUMP_LABEL_NOP_SIZE); + if (poker) { + (*poker)((void *)jump_entry_code(entry), &code, JUMP_LABEL_NOP_SIZE); + return; + } + + text_poke_bp((void *)jump_entry_code(entry), &code, JUMP_LABEL_NOP_SIZE, + (void *)jump_entry_code(entry) + JUMP_LABEL_NOP_SIZE); } void arch_jump_label_transform(struct jump_entry *entry,