Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2114869imu; Thu, 10 Jan 2019 08:31:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN478f01PXbA8mnY+IYHSJKsfHQPu+RXRHaSTj1kaMCqOoeMNDCVwVzCpU1eqLrHo3zalCtd X-Received: by 2002:a63:d208:: with SMTP id a8mr9782464pgg.77.1547137863659; Thu, 10 Jan 2019 08:31:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547137863; cv=none; d=google.com; s=arc-20160816; b=AHd6HCIatoK5vocNmNE2myQNgRQf0AvFCgdlyO451vMb/IQJxnyIpfBm+QzpM0vF3T i3ow6BZZj83Fxj0qUjAqThy/Y8u5auxJNgnMy6uX7EX5HAESQWIJ5FPrjjxmb1X8L8qz Sk0rDpEZTV02Z1cECt9BFvYECalkiUiXPME6atyvGLefsl26YLB8BaEZ9LFj8QfO1Kgx LRh4z7SuCMRz0lPY/ZxKqDEzyhDOSGBZdtstmsMXtjO40PrPtpBeHYwhISn+ZN0I7sRC yBKlO98IdNtd6uYzqEY2Rkd0zNjBjVjjViy3DzwluKallBglTj0tfP66xcVGAMnlj12z LntQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=6axZlb8FYLSVPidCGU22KjM4MHnrfC32wzypEoZ37Q4=; b=JLDfrwdUaNlNyfNU8Jd7iqVg3mkH1dTV6dgPCZ8+6rxwwKNGaQrHbgj5nKKd3vWkjG 90OB2uRXYAAARwqhI0YTztEGLSNsz5/o5W8xEcj8Jb5tDVgM9dv6V/N2RyGLOjwDcpxt DGXgfBmjXcsaujEeB1eZUCPV3EfVqf7Y/r3NLe1kPdopyL9tATya0eoKV+X7FqEJIyws zmHcq98SqNe24nNedHOiDD80nuKhrMtkzhawLcSCZZiAc5kOsG3XD2+eXLDg+xgaJOOw UStEdvBc9Kgj7uiMAtqhrd8DRk0ETD5i9YZvceilHlINNQBNwwC7It6aTn0q/GYapzwS MXcw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ce19si9371518plb.13.2019.01.10.08.30.48; Thu, 10 Jan 2019 08:31:03 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729329AbfAJQ2S (ORCPT + 99 others); Thu, 10 Jan 2019 11:28:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:9448 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727906AbfAJQ2Q (ORCPT ); Thu, 10 Jan 2019 11:28:16 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 84007C0BF2A2; Thu, 10 Jan 2019 16:28:15 +0000 (UTC) Received: from treble (ovpn-125-32.rdu2.redhat.com [10.10.125.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8254427C5B; Thu, 10 Jan 2019 16:28:12 +0000 (UTC) Date: Thu, 10 Jan 2019 10:28:10 -0600 From: Josh Poimboeuf To: Nadav Amit Cc: X86 ML , LKML , Ard Biesheuvel , Andy Lutomirski , Steven Rostedt , Peter Zijlstra , 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 Subject: Re: [PATCH v3 3/6] x86/static_call: Add out-of-line static call implementation Message-ID: <20190110162810.fgrmezgecvbekloe@treble> References: <30f0713894a415f13e0f0ea3d40595416db2f6d7.1547073843.git.jpoimboe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 10 Jan 2019 16:28:16 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 10, 2019 at 12:16:34AM +0000, Nadav Amit wrote: > > On Jan 9, 2019, at 2:59 PM, Josh Poimboeuf wrote: > > > > > > > + > > +void __ref arch_static_call_transform(void *site, void *tramp, void *func) > > +{ > > + s32 dest_relative; > > + unsigned char opcode; > > + void *(*poker)(void *, const void *, size_t); > > + void *insn = tramp; > > + > > + mutex_lock(&text_mutex); > > + > > + /* > > + * For x86-64, a 32-bit cross-modifying write to a call destination is > > + * safe as long as it's within a cache line. > > + */ > > + opcode = *(unsigned char *)insn; > > + if (opcode != 0xe8 && opcode != 0xe9) { > > + WARN_ONCE(1, "unexpected static call insn opcode 0x%x at %pS", > > + opcode, insn); > > + goto done; > > + } > > + > > + dest_relative = (long)(func) - (long)(insn + CALL_INSN_SIZE); > > + > > + poker = early_boot_irqs_disabled ? text_poke_early : text_poke; > > + poker(insn + 1, &dest_relative, sizeof(dest_relative)); > > + > > +done: > > + mutex_unlock(&text_mutex); > > +} > > +EXPORT_SYMBOL_GPL(arch_static_call_transform); > > Err… I was rewriting __jump_label_transform(), so if this code duplication can > be avoided, this would be great. > > (See https://lkml.org/lkml/2018/11/14/72 ) I don't see much code duplication, because __jump_label_transform() uses text_poke_bp(), whereas this uses text_poke(). It's true they both fall back to text_poke_early(), but I don't see any opportunities for sharing code there, unless we decide to go back to using breakpoints. -- Josh