Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp8966503ybi; Fri, 7 Jun 2019 00:53:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqwlsZirW+q7HnaxsmkO/S16CCSQO3Y0OzmR+KonZ4oSh0s935f2+lKgGJjasDYoQ5p/ZypD X-Received: by 2002:a62:f20b:: with SMTP id m11mr4769194pfh.125.1559894028078; Fri, 07 Jun 2019 00:53:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559894028; cv=none; d=google.com; s=arc-20160816; b=zVwiEIMpyJUtCUXxqsuT8k43nXBqlgzOrvMvzeNQtWwKgAWx/JPHrX9Lum8PdgYlaS tlMX/EU432FCSeaqBKk8XjbhgHb0+8/fmkUo1HOyWvdQu3xaf4RKYR0AGEb6hXCaIi9F Af3DyEUQiZT+9DJioeWYDKQaj27auGylwdAcO0xYmYCO0Chq2bytjl5QOQNSRAIA6AAZ +Mk629dZPaHPjMqGEPE6rnEsT5m8SCARx6vfNhBRoqsNJo9uR3YgxbLG9BFQcO1L4Fnn maBrKhpG3DAxLmCgURpNShQ4uhtElXfO79YhqAC4/zze6IXmitMTMYOEe9XPnCYhxE65 pIzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=GBY9HIsc/LiAhnx9uxnnLp8QINF+RjloUyNvbrGc+DY=; b=yvphzbDqVH2bULcM9YudIKS4Q8FJ2TA6z7Z5Nmq41vJ8zvNuRzvQjfdKsa+RNwCUOI EYHh5n7orCMmCAh8S7GWHwFdMNpOxS8xccKC3mW/Yh/c8nOXiXOWNH8CUipvtRbkdf5W 3X1W+5YcXyJIWxCWnGzbKd8YdsPx42cxh7AFEqz/OdMOVrjYEzmP/G5hijlA0Q7BENrW Eu9RdMgHj3k/HrdpuQZznpW89YwbUgR5QBoj3XOosuuffFFplnA7hBLe23bHeHO2GljX MkF5PiKolavBmi71IuzIvEDAD72IR+uNKjH7RHvTvbSHTD7xCvMBEylCpyH/Yq52T4EY zW/w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a69si1200797pla.178.2019.06.07.00.53.31; Fri, 07 Jun 2019 00:53:48 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727904AbfFGHvL convert rfc822-to-8bit (ORCPT + 99 others); Fri, 7 Jun 2019 03:51:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:57634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726668AbfFGHvK (ORCPT ); Fri, 7 Jun 2019 03:51:10 -0400 Received: from oasis.local.home (unknown [95.87.249.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1DDA9208C3; Fri, 7 Jun 2019 07:51:04 +0000 (UTC) Date: Fri, 7 Jun 2019 03:51:00 -0400 From: Steven Rostedt To: Nadav Amit Cc: Peter Zijlstra , the arch/x86 maintainers , LKML , Ard Biesheuvel , Andy Lutomirski , Ingo Molnar , Thomas Gleixner , Linus Torvalds , Masami Hiramatsu , Jason Baron , Jiri Kosina , David Laight , Borislav Petkov , Julia Cartwright , Jessica Yu , "H. Peter Anvin" , Rasmus Villemoes , Edward Cree , Daniel Bristot de Oliveira , Josh Poimboeuf Subject: Re: [PATCH 12/15] x86/static_call: Add out-of-line static call implementation Message-ID: <20190607035100.3cd49d4c@oasis.local.home> In-Reply-To: <37C2FB32-3437-48CB-954D-05F683B7D80B@vmware.com> References: <20190605130753.327195108@infradead.org> <20190605131945.254721704@infradead.org> <37C2FB32-3437-48CB-954D-05F683B7D80B@vmware.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 7 Jun 2019 06:13:58 +0000 Nadav Amit wrote: > > On Jun 5, 2019, at 6:08 AM, Peter Zijlstra wrote: > > > > From: Josh Poimboeuf > > > > Add the x86 out-of-line static call implementation. For each key, a > > permanent trampoline is created which is the destination for all static > > calls for the given key. The trampoline has a direct jump which gets > > patched by static_call_update() when the destination function changes. > > > > Cc: x86@kernel.org > > Cc: Steven Rostedt > > Cc: Julia Cartwright > > Cc: Ingo Molnar > > Cc: Ard Biesheuvel > > Cc: Jason Baron > > Cc: Linus Torvalds > > Cc: Jiri Kosina > > Cc: Thomas Gleixner > > Cc: Masami Hiramatsu > > Cc: Borislav Petkov > > Cc: David Laight > > Cc: Jessica Yu > > Cc: Andy Lutomirski > > Cc: "H. Peter Anvin" > > Signed-off-by: Josh Poimboeuf > > Signed-off-by: Peter Zijlstra (Intel) > > Link: https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Flkml.kernel.org%2Fr%2F00b08f2194e80241decbf206624b6580b9b8855b.1543200841.git.jpoimboe%40redhat.com&data=02%7C01%7Cnamit%40vmware.com%7C13bc03381930464a018e08d6e9b8f90e%7Cb39138ca3cee4b4aa4d6cd83d9dd62f0%7C0%7C0%7C636953378007810030&sdata=UnHEUYEYV3FBSZj667lZYzGKRov%2B1PdAjAnM%2BqOz3Ns%3D&reserved=0 > > --- > > arch/x86/Kconfig | 1 > > arch/x86/include/asm/static_call.h | 28 +++++++++++++++++++++++++++ > > arch/x86/kernel/Makefile | 1 > > arch/x86/kernel/static_call.c | 38 +++++++++++++++++++++++++++++++++++++ > > 4 files changed, 68 insertions(+) > > create mode 100644 arch/x86/include/asm/static_call.h > > create mode 100644 arch/x86/kernel/static_call.c > > > > --- a/arch/x86/Kconfig > > +++ b/arch/x86/Kconfig > > @@ -198,6 +198,7 @@ config X86 > > select HAVE_FUNCTION_ARG_ACCESS_API > > select HAVE_STACKPROTECTOR if CC_HAS_SANE_STACKPROTECTOR > > select HAVE_STACK_VALIDATION if X86_64 > > + select HAVE_STATIC_CALL > > select HAVE_RSEQ > > select HAVE_SYSCALL_TRACEPOINTS > > select HAVE_UNSTABLE_SCHED_CLOCK > > --- /dev/null > > +++ b/arch/x86/include/asm/static_call.h > > @@ -0,0 +1,28 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +#ifndef _ASM_STATIC_CALL_H > > +#define _ASM_STATIC_CALL_H > > + > > +/* > > + * Manually construct a 5-byte direct JMP to prevent the assembler from > > + * optimizing it into a 2-byte JMP. > > + */ > > +#define __ARCH_STATIC_CALL_JMP_LABEL(key) ".L" __stringify(key ## _after_jmp) > > +#define __ARCH_STATIC_CALL_TRAMP_JMP(key, func) \ > > + ".byte 0xe9 \n" \ > > + ".long " #func " - " __ARCH_STATIC_CALL_JMP_LABEL(key) "\n" \ > > + __ARCH_STATIC_CALL_JMP_LABEL(key) ":" > > + > > +/* > > + * This is a permanent trampoline which does a direct jump to the function. > > + * The direct jump get patched by static_call_update(). > > + */ > > +#define ARCH_DEFINE_STATIC_CALL_TRAMP(key, func) \ > > + asm(".pushsection .text, \"ax\" \n" \ > > + ".align 4 \n" \ > > + ".globl " STATIC_CALL_TRAMP_STR(key) " \n" \ > > + ".type " STATIC_CALL_TRAMP_STR(key) ", @function \n" \ > > + STATIC_CALL_TRAMP_STR(key) ": \n" \ > > + __ARCH_STATIC_CALL_TRAMP_JMP(key, func) " \n" \ > > + ".popsection \n") > > + > > +#endif /* _ASM_STATIC_CALL_H */ > > --- a/arch/x86/kernel/Makefile > > +++ b/arch/x86/kernel/Makefile > > @@ -63,6 +63,7 @@ obj-y += tsc.o tsc_msr.o io_delay.o rt > > obj-y += pci-iommu_table.o > > obj-y += resource.o > > obj-y += irqflags.o > > +obj-y += static_call.o > > > > obj-y += process.o > > obj-y += fpu/ > > --- /dev/null > > +++ b/arch/x86/kernel/static_call.c > > @@ -0,0 +1,38 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#define CALL_INSN_SIZE 5 > > + > > +void arch_static_call_transform(void *site, void *tramp, void *func) > > +{ > > + unsigned char opcodes[CALL_INSN_SIZE]; > > + unsigned char insn_opcode; > > + unsigned long insn; > > + s32 dest_relative; > > + > > + mutex_lock(&text_mutex); > > + > > + insn = (unsigned long)tramp; > > + > > + insn_opcode = *(unsigned char *)insn; > > + if (insn_opcode != 0xE9) { > > + WARN_ONCE(1, "unexpected static call insn opcode 0x%x at %pS", > > + insn_opcode, (void *)insn); > > + goto unlock; > > This might happen if a kprobe is installed on the call, no? > > I don’t know if you want to be more gentle handling of this case (or perhaps > modify can_probe() to prevent such a case). > Perhaps it is better to block kprobes from attaching to a static call. Or have it use the static call directly as it does with ftrace. But that would probably be much more work. -- Steve