From patchwork Wed Sep 19 06:51:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 147028 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp344010ljw; Tue, 18 Sep 2018 23:52:50 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbvPg66kVcuKy7VdtFz8NmKX/j7cfhqd93YeVxv43LQ/pCaPGPoDOz/XI5xVI2ySkWZzl6W X-Received: by 2002:a63:2a0b:: with SMTP id q11-v6mr27875892pgq.36.1537339970336; Tue, 18 Sep 2018 23:52:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537339970; cv=none; d=google.com; s=arc-20160816; b=qdhh+Z6fYMBVerp96OPu8h2LZAoJgR08YYiKiHFru7o8ouFgyqupjsG1bND4Oc+ZzZ Kwg3zKYBMDTUxJagUov3zu5QVVnMbfvhFfHbQgRntbiHWQsdKzS2huIPnqGcQCUnOqer dXqN/jRtdwnqy9oTymNcHoBOPzBnrcjcUfj0GdlP7aBR6rhBISsw/y32lT3eZw2iEQzN vfJsyUqaWCJXj7XDzKu2SAHutx/0w32WIK94HB13dFV9WyLlBIWyncfsoJJ3s4G0DUUd ioPcqYMKJ76ACICTHTbguiO5aE3km1pFsnOkdKH6nKNQzUXTCRRy5kl+Qblpw5sxt1WH Gysg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=iA34PvoXnv/5jnydRzA1GyetmcM2pytY3HL8SIbi1DA=; b=sfNGtQ0AArO+dT4B/eKcpdsMGsfAmW5xlBPd8wSsOG7Qzi8SBokolypgpUCX3FEJ+P fMTH6iEVmebIcbZBx8kvZfc40tf2lp3qNrP6jk5o3jZHnvJUaytNzCF/K+KFIdpFyPtD PgyWjhzHJRT9KSXtQfC33/NUZ0t2Qp3N7WxlhmEnRY9WsEZxnOZvWqvxj1Mom1L/oTBc 5TbnzTD0in7kSSMWnnP79AJhS8eDnx1JUehiBK5OFsu6Dg+y51sna4NC7jJwTXPeGmCC x24P8ME+Sk+wj56ZYGDBw7zcxGjekFFtzEsqwhwowb0BmVUUbodOZTNI+XOT/+kTULOK PDzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hX3BTpM6; 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 p3-v6si20138736pld.329.2018.09.18.23.52.50; Tue, 18 Sep 2018 23:52:50 -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=hX3BTpM6; 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 S1731157AbeISM3R (ORCPT + 32 others); Wed, 19 Sep 2018 08:29:17 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:53974 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731142AbeISM3Q (ORCPT ); Wed, 19 Sep 2018 08:29:16 -0400 Received: by mail-it0-f66.google.com with SMTP id p79-v6so6840240itp.3 for ; Tue, 18 Sep 2018 23:52:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iA34PvoXnv/5jnydRzA1GyetmcM2pytY3HL8SIbi1DA=; b=hX3BTpM6OFVDYHhbaduRyiEvKVa1h5kwWbYpjAoXCspqeB/8w7+LnC7RvhgfoKauDh K/qeYeiNjLC3g0sGJS48hHaypqf2IsTsjQVJVmwnZUT1yHVeaa9UqpQsRT936/9JiXi2 dZmpGMvJAVhcNCShHhhW5p2Y0X6JZN8AwlEvA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iA34PvoXnv/5jnydRzA1GyetmcM2pytY3HL8SIbi1DA=; b=f8yyqeeYKsk0RMmS6I2YwgVs8ffLW746d7DXyLYqmKyWsM4vpR9CYZZc9/Y5etG+Kh VUqxCDEAOoMdFH2CB3NgBvVumXmiZMmNpL7kwAwuUSMA4x+Ag/wxfq5SlYPbyyVsuIdM hUHZlQy4C3/inWzNoy+9OqR3STSTdETATDIHtbZgk+IwHE7JKfQkNp/Fmj0/x07kmehx lJQoatDYho9Tv0a7BGZl84sgOq72DLizd9+ao1wmGxPfEYda8qWlVd4uGh0LPL9NqwNz j4xKVcGaCVOL1CfvFqTmd2O/5OfrjEvqko4n/UvYL2TLjIDiPzoKTI+6ZqmzkItVG3/h 7iJA== X-Gm-Message-State: APzg51CYVLE+La4WgtntG5gP0lfOo1z1EYznJ9nMenWR7kcuvsdPLPch 37dOI2ehW5wA1E5d11nmj4+3xTKwDj1iFQ== X-Received: by 2002:a24:cf06:: with SMTP id y6-v6mr19881811itf.5.1537339966590; Tue, 18 Sep 2018 23:52:46 -0700 (PDT) Received: from localhost.localdomain ([209.82.80.116]) by smtp.gmail.com with ESMTPSA id x68-v6sm7939477ita.2.2018.09.18.23.52.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Sep 2018 23:52:45 -0700 (PDT) From: Ard Biesheuvel To: linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org, Ard Biesheuvel , Arnd Bergmann , Heiko Carstens , Kees Cook , Will Deacon , Thomas Gleixner , Catalin Marinas , Ingo Molnar , Steven Rostedt , Martin Schwidefsky , Jessica Yu , Peter Zijlstra Subject: [PATCH v3 9/9] s390/jump_label: switch to relative references Date: Tue, 18 Sep 2018 23:51:44 -0700 Message-Id: <20180919065144.25010-10-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180919065144.25010-1-ard.biesheuvel@linaro.org> References: <20180919065144.25010-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Heiko Carstens Enable support for relative references in jump_label entries. Signed-off-by: Heiko Carstens Signed-off-by: Ard Biesheuvel --- 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(-) -- 2.17.1 diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index 9a9c7a6fe925..12dc4c1af96c 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -120,6 +120,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)