Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp7354837imm; Thu, 28 Jun 2018 02:16:18 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKVKRI9ZvSQwUu8aZu16KjY+DlnLKCTNyIcSijJ3tK6scxacc3SDgp0IHKVmCTjNo6T5hYA X-Received: by 2002:a17:902:5a0c:: with SMTP id q12-v6mr9577870pli.300.1530177377956; Thu, 28 Jun 2018 02:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530177377; cv=none; d=google.com; s=arc-20160816; b=j8JFeAda9zdK5++v+rx56M0LU9OHr4WEltp3Gp5BVJLVqAsnNKx6Mx4uxt/5idUV2P 8WDyPdKvZKG1WklQDACohAIDwyZj7mZf31v87xAHwNnUileAhN6fw04630MFcc7+moD9 +nflWgM4NzjQHFG8CjaZWFolvIS5Yg+qffFm8vLDFIoP3g3WMvDl47aFQgTpOg1HS7L+ m7W7iKOVvVSu4fFRjRxehjITBl6EodzNicgI+28LGan48iybJD7lXDz+p5aKDGaU/PVR uI1QBaqn00QqwDWvzp/kyU8YJnTzdwSXs56mAMa2iYVK+/EFc6zAkQt3b4fDb2xLqfc2 l+zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=+b2x6NOJBsTNfvowLR9oKe4yv1rod5vlgXxyu1++zv4=; b=IztcoyeR/BpGSpePLroPM8NY13GFXjUljOoD7hzpfpsM2nlWgYOty5w+Vhq+aHCYCv sdoGKKO9xwnpoSE78rzOPMRv1qL4e2VDVAdUvl+JYCD6VuPwmLNw1B4mimDSnPV7122z x8wo7bfUs4HyZKtfvqYOQITloKPFR5W/oM9XcYPaaCvqSOurSXqkOQ5bEwRIGx+GGFT7 tIicGVb0BQDa/8urh4pKMnHvvnIa5E7sSU02Bkvhlmc8FIlmXbsbDJwgn3q5dxCjkKkN rpEOj3Ywx99mjwqAihmBxhw9g5/s+VtGNs30pOOwvfqjLVP0G6nnBlktkiJgX6wzFYjE L9Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gTkftz5z; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m1-v6si5686103pgb.373.2018.06.28.02.16.00; Thu, 28 Jun 2018 02:16:17 -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=pass header.i=@linaro.org header.s=google header.b=gTkftz5z; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964904AbeF1JOg (ORCPT + 99 others); Thu, 28 Jun 2018 05:14:36 -0400 Received: from mail-io0-f193.google.com ([209.85.223.193]:32897 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964784AbeF1JOf (ORCPT ); Thu, 28 Jun 2018 05:14:35 -0400 Received: by mail-io0-f193.google.com with SMTP id d185-v6so4563449ioe.0 for ; Thu, 28 Jun 2018 02:14:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=+b2x6NOJBsTNfvowLR9oKe4yv1rod5vlgXxyu1++zv4=; b=gTkftz5zzxu7wYw+g9BQNSAwnpJZChf33asjRh3ZzEwZJrP46b6b9IeniFa2OH2OPj nw3FdKp/OkusxYgFfnEz+dRAeN4AmXw5NKl5TwrfqRjdfAKrjZdHTvKMv5bx4fhaxrdd aeSUTS03E+HUYehRa22V0I7oTNWcYX0HlFUnc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=+b2x6NOJBsTNfvowLR9oKe4yv1rod5vlgXxyu1++zv4=; b=e9oJCsNZZ24QxQxedQdv2WYRwOtUbt4wAS5L8t4eGpKsp2kUbd13SNlQFOWCwxzf1H aY0jf6jWbRgbQedxp0ark0uJ9lBvO74pFlKxlPOyNq7WlJMBaBU8oJdk2ag0XIc9/vgF opdFX3En56AOeTYusOeI+oGvI/CKGK+rqYWeginnONLvFfod1R1H99xNYW49eEPt0awv ngs70gSKN5Iuko6M9vupddgPGmqQhEWaDYiaE3txskHsYCdocIyrwq7XOzgGd/TkLfUH Akn2OcjE1Rlp5XaJyZgjA1d7zS0zQsvl7gOkSffPdgYCz/XdQpfxxRC2PeXghAVGdgMg hMUg== X-Gm-Message-State: APt69E0MEouIdPh6ZUYnODoUnHApbS0mdMgSPNYJXtc8opd2Ez84yhXK kRrXwDMq4tMxQsVi6b4DXubul2vTzMyXfXom8xqzKDKl X-Received: by 2002:a6b:dd0b:: with SMTP id f11-v6mr7750956ioc.173.1530177274936; Thu, 28 Jun 2018 02:14:34 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:bbc7:0:0:0:0:0 with HTTP; Thu, 28 Jun 2018 02:14:34 -0700 (PDT) In-Reply-To: <20180628091135.GB2494@hirez.programming.kicks-ass.net> References: <20180627160604.8154-1-ard.biesheuvel@linaro.org> <20180627160604.8154-5-ard.biesheuvel@linaro.org> <20180628091135.GB2494@hirez.programming.kicks-ass.net> From: Ard Biesheuvel Date: Thu, 28 Jun 2018 11:14:34 +0200 Message-ID: Subject: Re: [PATCH 4/5] x86: jump_label: switch to jump_entry accessors To: Peter Zijlstra Cc: Linux Kernel Mailing List , linux-arm-kernel , "the arch/x86 maintainers" , Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , Arnd Bergmann , Steven Rostedt Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 28 June 2018 at 11:11, Peter Zijlstra wrote: > 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? > Sure, I will incorporate that for v2. > > --- 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,