Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3027765imu; Thu, 29 Nov 2018 14:16:04 -0800 (PST) X-Google-Smtp-Source: AFSGD/VmYe+WzxR0WzbvdsQTClJfkmRfPEppueM+HtvzFQAtWoW6F8LufMnFx16oPkcsPFj1TtvQ X-Received: by 2002:a17:902:162:: with SMTP id 89-v6mr3185736plb.293.1543529764465; Thu, 29 Nov 2018 14:16:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543529764; cv=none; d=google.com; s=arc-20160816; b=jCYFjUE0U5diB75c2YQJJ6YeErb1qDQ8YIN8me804trYb7CwOi1llvZI/YB+8h8BwJ KQIICdRgtkevdqtKcT3vNjY9GmAw4WhfOauz4m/GX8zk8X7PNjQBvP+zcraD1GercOJ3 KQq8Yt3rM9pl+n1jAr53TP62wmBhTONOQVxJcfKmlbNKb/VLr+VUPmKM1xyHUqJB5o1j UdzsB1rinzczcprAadq2dimS099G+TGnvuRJgpWXJKRrm9/KuySxNL81jNylZaWqja2p BybdMm0kXZKUXYteNPEUZ2OnJaImXBYVoyT/fHHoK5sIXz99vbkm6N/8TWco4t0rb8/h KSRg== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=O4qa1S7HFw0DS+KMB2iuzgBEAdBa+1Mw4XspNSTKRvo=; b=BPSv2WdJcZPpa+mksFfOkE9UAs5klrmdre5SpDyS3ATh/yYyKg59oiw15ADh1tGnbN 2gf97CdtHRCbkEuN655hf6aEgrwEMQsakMiA3CvtJJBTeR3NsKfsLqHb76XxBmffqX1E upM5xpTivdLaW12R6G5CwrAZUVkPcn7uUg5D7O8DgWlSH5QVrjj8teyewCU2kyGgJpSw LOQV09rgRCWNfx87+bHLwp76d9E6Anzfzm1bHX1QbhlZ3dCDHFwb23FrwF7l7TTG1CK1 COmaZww5DTvnI5zqe8jhgXqcmoa3ZQka2776FBJsiPrvjtBtAgCF2svoqNQ+Wp6K5IvQ g+6A== 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 j20si2977771pgg.162.2018.11.29.14.15.50; Thu, 29 Nov 2018 14:16:04 -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 S1727054AbeK3JVy (ORCPT + 99 others); Fri, 30 Nov 2018 04:21:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58596 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726963AbeK3JVt (ORCPT ); Fri, 30 Nov 2018 04:21:49 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 20817DC8F4; Thu, 29 Nov 2018 22:14:51 +0000 (UTC) Received: from treble (ovpn-123-4.rdu2.redhat.com [10.10.123.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 312CC1712C; Thu, 29 Nov 2018 22:14:48 +0000 (UTC) Date: Thu, 29 Nov 2018 16:14:46 -0600 From: Josh Poimboeuf To: Peter Zijlstra Cc: Andy Lutomirski , Andy Lutomirski , X86 ML , LKML , Ard Biesheuvel , Steven Rostedt , Ingo Molnar , Thomas Gleixner , Linus Torvalds , Masami Hiramatsu , Jason Baron , Jiri Kosina , David Laight , Borislav Petkov , julia@ni.com, jeyu@kernel.org, "H. Peter Anvin" Subject: Re: [PATCH v2 4/4] x86/static_call: Add inline static call implementation for x86-64 Message-ID: <20181129221446.qb7znvt7zprlbz77@treble> References: <20181127084330.GX2113@hirez.programming.kicks-ass.net> <20181129094210.GC2131@hirez.programming.kicks-ass.net> <20181129143853.GO2131@hirez.programming.kicks-ass.net> <20181129163342.tp5wlfcyiazwwyoh@treble> <20181129164914.GA9027@hirez.programming.kicks-ass.net> <0FDA053D-7ADC-4F42-AEA5-99DA155FCED0@amacapital.net> <20181129171050.iio53bw67fbiwzud@treble> <20181129220148.GD11632@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20181129220148.GD11632@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 29 Nov 2018 22:14:51 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 29, 2018 at 11:01:48PM +0100, Peter Zijlstra wrote: > On Thu, Nov 29, 2018 at 11:10:50AM -0600, Josh Poimboeuf wrote: > > On Thu, Nov 29, 2018 at 08:59:31AM -0800, Andy Lutomirski wrote: > > > > (like pointing IP at a stub that retpolines to the target by reading > > > the function pointer, a la the unoptimizable version), then okay, I > > > guess, with only a small amount of grumbling. > > > > I tried that in v2, but Peter pointed out it's racy: > > > > https://lkml.kernel.org/r/20181126160217.GR2113@hirez.programming.kicks-ass.net > > Ah, but that is because it is a global shared trampoline. > > Each static_call has it's own trampoline; which currently reads > something like: > > RETPOLINE_SAFE > JMP *key > > which you then 'defuse' by writing an UD2 on. _However_, if you write > that trampoline like: > > 1: RETPOLINE_SAFE > JMP *key > 2: CALL_NOSPEC *key > RET > > and have the text_poke_bp() handler jump to 2 (a location you'll never > reach when you enter at 1), it will in fact work I think. The trampoline > is never modified and not shared between different static_call's. But after returning from the function to the trampoline, how does it return from the trampoline to the call site? At that point there is no return address on the stack. -- Josh