From patchwork Thu Jun 28 09:11:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 10493365 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 9F17A60230 for ; Thu, 28 Jun 2018 09:11:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C23D29D9D for ; Thu, 28 Jun 2018 09:11:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7FCF229DA1; Thu, 28 Jun 2018 09:11:53 +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 2AAD429D9D for ; Thu, 28 Jun 2018 09:11:53 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=//3q5bIFlL2ObuXSxnwwHXTBvYmb4mGWymu8oVmeUpI=; b=spcLcX2sbpe/7U P8RLJyv1ERxE5yX9M1I4TRJg4ngvK7VS3pPpi60NfBLe3ht4dvV7ddT+Emd+5tGjkOVgCQQRumEYA 0RL8kUmtHZJX71frKALKJ/msfHPnu9tkQXhJT6xHB+kLS9DB3lYLD6vdYwX7BynqOnagJRlFwTuqa iTmeacGASEWTP6dykAVc+C7d5ByTPYtdMOrkCIuCymy1hodZSHgy5G+uWW7/55gEqvuVB2Lp/1QpJ LCfLqnH0ZQDVkkxymZ48zpesuu7W7dAKcRbFoV7f4HDU5yGlSYLLWNMDu5+uQjVnFICfNLRlnE4Cr sP8kxxAjI6fWQBkccLCg==; 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 1fYSxt-0008Uh-JF; Thu, 28 Jun 2018 09:11:45 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fYSxr-0008UG-6Z for linux-arm-kernel@bombadil.infradead.org; Thu, 28 Jun 2018 09:11:43 +0000 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 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-Disposition: inline In-Reply-To: <20180627160604.8154-5-ard.biesheuvel@linaro.org> User-Agent: Mutt/1.10.0 (2018-05-17) 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 , Catalin Marinas , x86@kernel.org, Will Deacon , linux-kernel@vger.kernel.org, Steven Rostedt , Ingo Molnar , Thomas Gleixner , linux-arm-kernel@lists.infradead.org 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 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,