Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp7346795imm; Thu, 28 Jun 2018 02:06:19 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfDMKU6enuZ2l1tadZeTOamKPSH5/41Z3hXgZUvnNsZHzWir1tlWOYVmgVRL0qBynkjV2ME X-Received: by 2002:a62:1f8c:: with SMTP id l12-v6mr545564pfj.143.1530176779240; Thu, 28 Jun 2018 02:06:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530176779; cv=none; d=google.com; s=arc-20160816; b=DgerdfxtkCHGavK1U+U8jjMbBbxqjD9HSN7K/cDehqEY7k0mHvZkeV1+nfNQ+sYk+n 6ZfMW9VXvj+QNw3M87ZvBFuJJMsb74njuqgAMCPgUDEdr2Xo9rd/MOHzR6nNQtAN4CHK 2APZczJOSYfi3K9TpZR9B0HgQLJqA7NpLccLsEc7MJPSHJgVBF7PmKYNPTteTpJlUwaL aTNoi3mce0atMGnb5Ie4KG/xR80Q34Z8vmzIPhjek3ReKBaD3WO/hv662F+FxPaFfFKL KLMj3ULYYOgAEtV9LrxVaN05PN/2h48qTJHUJdPeVgtulo95tw2dV0TLoxcgkJRi/Xxt kmKQ== 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=WQZwzbg5n+ULun/r8CQNaXQY+FTDClMScJzvEeplxYE=; b=Jm/0FXZXG3YQs8lENeNwixOZJUmunq1uzj1DOkTCQ2m6dprHnA0a7wwVGbM2HuDBTS TeVDv/8yHIzXE7nYHTDuWcbsG9Av5JWO46LRC4AGjDU4xu3b3Bw9X+WUpxqZWbYtUTqh Uch2mH0uVAduFW4VcOnhCiDCtKCEqIU5lNnVmWvJIsVznjent6ui5YyvSGt7E0Xf7t9s Q/StVjSysmhn0fJ/1yGyEkftIBoWU2KYFoj6yOF3rLpWUs/8nJYyLQ1E4kkSBTt+pqYb gykZZBWJta6LkquGgIaaX9rQSYEB7HxhaTDd8XnOchcYqWRJjBcqhs5FJiu79r25XCB3 RRxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KgcK8N6i; 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 15-v6si3215313pfq.172.2018.06.28.02.06.01; Thu, 28 Jun 2018 02:06:19 -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=KgcK8N6i; 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 S934676AbeF1JEs (ORCPT + 99 others); Thu, 28 Jun 2018 05:04:48 -0400 Received: from mail-it0-f65.google.com ([209.85.214.65]:36591 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932262AbeF1JEq (ORCPT ); Thu, 28 Jun 2018 05:04:46 -0400 Received: by mail-it0-f65.google.com with SMTP id j135-v6so11462292itj.1 for ; Thu, 28 Jun 2018 02:04:46 -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=WQZwzbg5n+ULun/r8CQNaXQY+FTDClMScJzvEeplxYE=; b=KgcK8N6izdDlWb3xJU12NM3OVwiVMaixIVpeN7ggD1iaYjFB4O1c8YK0t6uVuhacKl Z9dO8/Te0Bw7VA3oNBOfSVbKv/tfDAHpqN6yHGIP34M7gIY3BVyArGl1+5RrTFb999uK 7FKa/rOQLgpDbIlHq58OyoMcCpMUBSv4sh6FA= 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=WQZwzbg5n+ULun/r8CQNaXQY+FTDClMScJzvEeplxYE=; b=e0IBfE5l//uLWjJetqUaEk6TqRRnYAty8zFAYoZBUHp00CSMZSI/W5W2NdLVJnwjxL dl85+iplrbYu1+hvzHdcCIx1S6OWjcnErMCh7X3toGZG+O/5H0SwvrRvRFdOJUbDGCJM Tc9yLI9B2INwj4zGuWtr+TQSwUR5EzoiH47WTNAIhy3y7eqHc6nNB18E/ivG5VTnfUKQ YPKYoQo/iCRLQIXLhdFWLv2KosrNJAi1Bj0vdw11KSfTiWUQmVFWOh9MiHdFn6vDDCov pbECAKClK61T4ezia7S70bp+1ZKIG8qLzf2TQ8naI3X1L5IFkMnImAhhegDopgwo34+A yS4Q== X-Gm-Message-State: APt69E07xVA3clJWO3hObb9tsfKzDfm9VTkkU31RVbgCrp6ZSz3vwd/r 2bQMrXCZ1twK6qPD/NY1mRbtqdAhAyGmBLo7l+KyMg== X-Received: by 2002:a24:6196:: with SMTP id s144-v6mr7745802itc.68.1530176685940; Thu, 28 Jun 2018 02:04:45 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:bbc7:0:0:0:0:0 with HTTP; Thu, 28 Jun 2018 02:04:45 -0700 (PDT) In-Reply-To: References: <20180627160604.8154-1-ard.biesheuvel@linaro.org> <20180627160604.8154-3-ard.biesheuvel@linaro.org> <20180628085003.GA2494@hirez.programming.kicks-ass.net> From: Ard Biesheuvel Date: Thu, 28 Jun 2018 11:04:45 +0200 Message-ID: Subject: Re: [PATCH 2/5] kernel/jump_label: implement generic support for relative references 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:02, Ard Biesheuvel wrote: > On 28 June 2018 at 10:50, Peter Zijlstra wrote: >> On Wed, Jun 27, 2018 at 06:06:01PM +0200, Ard Biesheuvel wrote: >>> diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h >>> index 86ec0652d3b1..aa203dffe72c 100644 >>> --- a/include/linux/jump_label.h >>> +++ b/include/linux/jump_label.h >>> @@ -121,6 +121,32 @@ struct static_key { >>> #include >>> >>> #ifndef __ASSEMBLY__ >>> +#ifdef CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE >>> + >>> +struct jump_entry { >>> + int code; >>> + int target; >>> + int key; >>> +}; >> >> I much prefer you use 'u32' there. >> > > Actually, they are signed so that would be s32. But yeah, I can change that. > >> >>> +static void jump_label_swap(void *a, void *b, int size) >>> +{ >>> + long delta = (unsigned long)a - (unsigned long)b; >>> + struct jump_entry *jea = a; >>> + struct jump_entry *jeb = b; >>> + struct jump_entry tmp = *jea; >>> + >>> + jea->code = jeb->code - delta; >>> + jea->target = jeb->target - delta; >>> + jea->key = jeb->key - delta; >>> + >>> + jeb->code = tmp.code + delta; >>> + jeb->target = tmp.target + delta; >>> + jeb->key = tmp.key + delta; >>> +} >>> + >>> static void >>> jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop) >>> { >>> @@ -56,7 +72,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop) >>> >>> size = (((unsigned long)stop - (unsigned long)start) >>> / sizeof(struct jump_entry)); >>> - sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL); >>> + sort(start, size, sizeof(struct jump_entry), jump_label_cmp, >>> + IS_ENABLED(CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE) ? jump_label_swap >>> + : NULL); >>> } >> >> That will result in jump_label_swap being an unused symbol for some >> compile options. >> > > No, and isn't that the point of IS_ENABLED()? The compiler sees a > reference to jump_label_swap(), so it won't complain about it being > unused. > >> Would it not be much nicer to write that like: >> >> static void jump_label_swap(void *a, void *b, int size) >> { >> struct jump_entry *jea = a, *jeb = b; >> >> #ifdef CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE >> long delta = a - b; >> >> jea->code += delta; >> jea->target += delta; >> jea->key += delta; >> >> jeb->code -= delta; >> jeb->target -= delta; >> jeb->key -= delta; >> #else >> >> swap(*jea, *jeb); >> } >> >> And then unconditionally use jump_label_swap(). > > Meh. I thought IS_ENABLED() was preferred over #ifdef, no? That way, > the compiler always sees the code, and simply discards it without > complaining if it ends up left unused. ... and it means the sort() routine will unconditionally perform an indirect function call even if the arch does not require it.