Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp558700imm; Wed, 4 Jul 2018 01:51:06 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeRKI3UqfGtZqrSPvsQTG7SLSxf5dujNFlgmIzPR4PDpQO/MaHRAzKA6q9/ziSnbyboVL8N X-Received: by 2002:a62:121a:: with SMTP id a26-v6mr1268892pfj.104.1530694266374; Wed, 04 Jul 2018 01:51:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530694266; cv=none; d=google.com; s=arc-20160816; b=1BUv+KQVM/QbQT4j0kBRuHsDF5BBDMYdh1TXWIuulQB/erlctk+wSu9I9u5SCi0w/J xbwovcEE0CoeQtYJ8D3Ebt9vMMuZrixR0/wyeCZjXp/5L/tiSSGQjDdItvbGDDEtR0iO TrMSYmVYbgxkthr+eSSiGYZxrqmkO0mNp4QyZcbqIYHU4gBNvp2jKkrU2Xb2frxrRDZi F9RmKv6aWRkhd8yBQwxjoB1P2t01lCglKEfB/t3yVPMlt0DvpkWfKjHRhPOAzJpK0Y9Q o7DpGzK/zBMpAeF+xoRVb7OcUPg+loerFQ92heF3TjLrNuWHlS78pibfkBm7HFY8MteW ZDhw== 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=M1aOkY2jCGShbnQ5ru42X1vKhP8RBUu9Xpv7sHiBZ68=; b=vw7VsJP4JMbI2FBDRorwGpeNBeyqnwBicnib9tul61015Dh7y5S8XG6vmYqK8r5NjX oi3EYGSTl4tyNmMeH0RxhdoWpMmCMHRjEAq4Mc0r6Yg75gn2meATi6SPSoVj93bZZg43 K/yvauOLQ6AXQdShAfUczyQBsY4+cc90V0nuYjQr+uzjCi3HKY/zjQmK4CERl2nsFqtU 7+BrSKUv8a/f0VtDjFoWVPM2/yMoudouOpdo1ITm3MfVSqm3b2cBq5FScKGN42Z5tiO6 t5JB1toevvlkdZYgF2JGC2ZxPohQBthUfQXKTS25TYJ0ZpCwepm0flen1PCgUpFSyWWQ WrVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qkm0j6Hp; 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 w6-v6si2854560pgb.61.2018.07.04.01.50.51; Wed, 04 Jul 2018 01:51:06 -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=Qkm0j6Hp; 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 S933987AbeGDIuH (ORCPT + 99 others); Wed, 4 Jul 2018 04:50:07 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:35919 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932439AbeGDIuD (ORCPT ); Wed, 4 Jul 2018 04:50:03 -0400 Received: by mail-it0-f68.google.com with SMTP id j185-v6so6689421ite.1 for ; Wed, 04 Jul 2018 01:50:03 -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=M1aOkY2jCGShbnQ5ru42X1vKhP8RBUu9Xpv7sHiBZ68=; b=Qkm0j6HpdcMRTN9HHevtD1wR9lQJOfYdvjdH69KshKCNaMSEJ8VG1cp2PKNdJCTruV SNYrkJkPbdocpRzVC82n8EOicHu95MqH+fyArfPJNYwXPDQ1MOY1gBmWHXYG4VfRGF/D u75ImyaTjjHRoD6k9+xnjgX64P7uH2DZe6HQA= 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=M1aOkY2jCGShbnQ5ru42X1vKhP8RBUu9Xpv7sHiBZ68=; b=DAWju+LYRjUAz+I68v4AD/sA3E2alXW/JTjb4doALSQtuH/gOvrPTGnxbZwc2hNWFC 6aQaFDZmWR/dxd7SZERxjzeLRFgH1MevCr7O6bgjkOSU0HapnnBjfhKPDNgsd6mflBX/ wqSgEFRyXjMnFptUI6oOf+Vay5XhMsiHBZcZmm03HHkqtS8Afp6jVu3MjJVyx4tRYYHz qEaXIcXRxDrXTD9QGmF1r1A3hmemq3NqE76uQMzUjQ9TxL8fG/csnwf86OKcGovFcMs/ 4I+Ll7oplZRHFQb8lxdqax8a7ii/VaOLyDg2Jqj3uFOA6VbYEFf9tJ6c3DH/SRKicf/E O/YQ== X-Gm-Message-State: APt69E1NxaVjTo+jKF74+eVfS0mlCvG1n3+7qDLiLqGqYYNLR92ouC6i y919bhgxKzlBCz7+kD5X6bdtjoTM3zKP4i46xlOM5g== X-Received: by 2002:a24:6196:: with SMTP id s144-v6mr1076117itc.68.1530694202716; Wed, 04 Jul 2018 01:50:02 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:bbc7:0:0:0:0:0 with HTTP; Wed, 4 Jul 2018 01:50:02 -0700 (PDT) In-Reply-To: <20180704075923.GF3701@osiris> References: <20180702181145.4799-1-ard.biesheuvel@linaro.org> <20180704075923.GF3701@osiris> From: Ard Biesheuvel Date: Wed, 4 Jul 2018 10:50:02 +0200 Message-ID: Subject: Re: [PATCH v2 0/8] add support for relative references in jump tables To: Heiko Carstens Cc: linux-arm-kernel , Linux Kernel Mailing List , linux-s390 , linux-arch@vger.kernel.org, Arnd Bergmann , Kees Cook , Will Deacon , Thomas Gleixner , Catalin Marinas , Ingo Molnar , Steven Rostedt , Martin Schwidefsky , Jessica Yu , Peter Zijlstra 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 4 July 2018 at 09:59, Heiko Carstens wrote: > On Mon, Jul 02, 2018 at 08:11:37PM +0200, Ard Biesheuvel wrote: >> This series implements support for emitting the data structures associated >> with jump tables as 32-bit relative references instead of absolute >> references, which take up more space on builds that target 64-bit >> architectures, or implement self relocation [or both]. >> >> This series enables it for arm64 and x86, although other architectures >> might benefit as well. > > Hello Ard, > > feel free to add the patch below which adds support for s390 to your series. > Thanks, I will incorporate it into v3 and beyond. >> Changes since v1: >> - change the relative reference to the static key to a 64-bit wide one on 64 >> bit architectures; this is necessary on arm64, which allows modules to >> reside anywhere within a 4 GB window covering the core kernel text, which >> means a 32-bit signed quantity with its +/- 2 GB range is insufficient. >> Note that x86_64 changes are in preparation that widen the relocation >> range as well (using the PIE linker), so I assumed that the same change >> is appropriate for x86 as well. > > FWIW, kernel modules on s390 are since ages more than 2GB away from the > core kernel text. So this is required for s390 as well. > OK, good to know. -- Ard. > From 77d87236f3d5474f33c25534d8ba2c7c54c88c55 Mon Sep 17 00:00:00 2001 > From: Heiko Carstens > Date: Wed, 4 Jul 2018 09:13:37 +0200 > Subject: [PATCH] s390/jump_label: switch to relative references > > Signed-off-by: Heiko Carstens > --- > arch/s390/Kconfig | 1 + > arch/s390/include/asm/jump_label.h | 40 +++++++++++++++----------------------- > arch/s390/kernel/jump_label.c | 11 ++++++----- > 3 files changed, 23 insertions(+), 29 deletions(-) > > diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig > index baed39772c84..0349fb06a2ec 100644 > --- a/arch/s390/Kconfig > +++ b/arch/s390/Kconfig > @@ -121,6 +121,7 @@ config S390 > select HAVE_ALIGNED_STRUCT_PAGE if SLUB > select HAVE_ARCH_AUDITSYSCALL > select HAVE_ARCH_JUMP_LABEL > + select HAVE_ARCH_JUMP_LABEL_RELATIVE > select CPU_NO_EFFICIENT_FFS if !HAVE_MARCH_Z9_109_FEATURES > select HAVE_ARCH_SECCOMP_FILTER > select HAVE_ARCH_SOFT_DIRTY > diff --git a/arch/s390/include/asm/jump_label.h b/arch/s390/include/asm/jump_label.h > index 40f651292aa7..e2d3e6c43395 100644 > --- a/arch/s390/include/asm/jump_label.h > +++ b/arch/s390/include/asm/jump_label.h > @@ -14,41 +14,33 @@ > * We use a brcl 0,2 instruction for jump labels at compile time so it > * can be easily distinguished from a hotpatch generated instruction. > */ > -static __always_inline bool arch_static_branch(struct static_key *key, bool branch) > +static inline bool arch_static_branch(struct static_key *key, bool branch) > { > - asm_volatile_goto("0: brcl 0,"__stringify(JUMP_LABEL_NOP_OFFSET)"\n" > - ".pushsection __jump_table, \"aw\"\n" > - ".balign 8\n" > - ".quad 0b, %l[label], %0\n" > - ".popsection\n" > - : : "X" (&((char *)key)[branch]) : : label); > - > + asm_volatile_goto("0: brcl 0,"__stringify(JUMP_LABEL_NOP_OFFSET)"\n" > + ".pushsection __jump_table,\"aw\"\n" > + ".balign 8\n" > + ".long 0b-.,%l[label]-.\n" > + ".quad %0-.\n" > + ".popsection\n" > + : : "X" (&((char *)key)[branch]) : : label); > return false; > label: > return true; > } > > -static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch) > +static inline bool arch_static_branch_jump(struct static_key *key, bool branch) > { > - asm_volatile_goto("0: brcl 15, %l[label]\n" > - ".pushsection __jump_table, \"aw\"\n" > - ".balign 8\n" > - ".quad 0b, %l[label], %0\n" > - ".popsection\n" > - : : "X" (&((char *)key)[branch]) : : label); > - > + asm_volatile_goto("0: brcl 15,%l[label]\n" > + ".pushsection __jump_table,\"aw\"\n" > + ".balign 8\n" > + ".long 0b-.,%l[label]-.\n" > + ".quad %0-.\n" > + ".popsection\n" > + : : "X" (&((char *)key)[branch]) : : label); > return false; > label: > return true; > } > > -typedef unsigned long jump_label_t; > - > -struct jump_entry { > - jump_label_t code; > - jump_label_t target; > - jump_label_t key; > -}; > - > #endif /* __ASSEMBLY__ */ > #endif > diff --git a/arch/s390/kernel/jump_label.c b/arch/s390/kernel/jump_label.c > index 43f8430fb67d..50a1798604a8 100644 > --- a/arch/s390/kernel/jump_label.c > +++ b/arch/s390/kernel/jump_label.c > @@ -33,13 +33,13 @@ static void jump_label_make_branch(struct jump_entry *entry, struct insn *insn) > { > /* brcl 15,offset */ > insn->opcode = 0xc0f4; > - insn->offset = (entry->target - entry->code) >> 1; > + insn->offset = (jump_entry_target(entry) - jump_entry_code(entry)) >> 1; > } > > static void jump_label_bug(struct jump_entry *entry, struct insn *expected, > struct insn *new) > { > - unsigned char *ipc = (unsigned char *)entry->code; > + unsigned char *ipc = (unsigned char *)jump_entry_code(entry); > unsigned char *ipe = (unsigned char *)expected; > unsigned char *ipn = (unsigned char *)new; > > @@ -59,6 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry, > enum jump_label_type type, > int init) > { > + void *code = (void *)jump_entry_code(entry); > struct insn old, new; > > if (type == JUMP_LABEL_JMP) { > @@ -69,13 +70,13 @@ static void __jump_label_transform(struct jump_entry *entry, > jump_label_make_nop(entry, &new); > } > if (init) { > - if (memcmp((void *)entry->code, &orignop, sizeof(orignop))) > + if (memcmp(code, &orignop, sizeof(orignop))) > jump_label_bug(entry, &orignop, &new); > } else { > - if (memcmp((void *)entry->code, &old, sizeof(old))) > + if (memcmp(code, &old, sizeof(old))) > jump_label_bug(entry, &old, &new); > } > - s390_kernel_write((void *)entry->code, &new, sizeof(new)); > + s390_kernel_write(code, &new, sizeof(new)); > } > > static int __sm_arch_jump_label_transform(void *data) > -- > 2.16.4 >