Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3015439imu; Thu, 29 Nov 2018 14:04:25 -0800 (PST) X-Google-Smtp-Source: AFSGD/WGPfbVtNcTLNzHfBSh+gDNA+hvocHt+vgwamC65S//WbRExPZWDRLRazXQolwlmj/b02EI X-Received: by 2002:a17:902:e01:: with SMTP id 1-v6mr3031879plw.251.1543529065801; Thu, 29 Nov 2018 14:04:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543529065; cv=none; d=google.com; s=arc-20160816; b=ppLg7KsG8DOoOT7mEsLqbzh5sKZ857+8tccD76MXw0YAOTiIwSW/QgkeqbMJeiJEBM ZnWelrKSLDwpAsRGL4vSMntg24NV+asx0seIB77Pr2ND5ohicRvwBUeq0g0YQBkWjRgm 6LA8oor7csQ4NF5b1rPKEhjTOBClWvxGE+s1PQF0vqJBsyz/rzxh7u+5lbTLBTMOACAU sfaIvEURe14qwXFXlI58Ke95VFctCE6aEArtMe7bpO+QiMKtD9wPwjQa07m77dtpvwBu IbKlfEL7u88fjLY3t5xwqZzJaFuSxECvKGwasqW8PGDnLd6N67Ge2CL+QjSNPMKYbsJ+ eP9Q== 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:dkim-signature; bh=nnUFPnghpca8In58LsdPdpVcgQqunkEM/siKs1BTDsk=; b=EV3/da17BqNfE3wVJlfLW2nVeDlBei2ECo+Go5DNHPyesT59duJl/lhkUPfFhvmd2L 538uJJ4JsnWEBMzL2heq5MlDWOzF1p53yibYE44qTi8ociRVApP3d6+vNlGDF9iE1AK3 r0enYWe6tr4YKHcfr41smqx3P03cLV/8F9Yzr9ZGDUNZNX+e47c/oykCkcVZp9IzBGY6 jOgXFdEje64I4QIQpeIAT0pnBkeqsieQv9Z5UuZG/0BLyI9N9LfPTKpl0CCt/R/XG51x t8ndyZ7gz+AkufGH8lIo89Zib7dFPSN8IPru1lBCAH18vifrmvBslUdmeoBnsHHIQiSq Jyow== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=CigctvPC; 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 t64si2934064pgd.202.2018.11.29.14.04.10; Thu, 29 Nov 2018 14:04:25 -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; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=CigctvPC; 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 S1726425AbeK3JJG (ORCPT + 99 others); Fri, 30 Nov 2018 04:09:06 -0500 Received: from merlin.infradead.org ([205.233.59.134]:54552 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726344AbeK3JJG (ORCPT ); Fri, 30 Nov 2018 04:09:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=nnUFPnghpca8In58LsdPdpVcgQqunkEM/siKs1BTDsk=; b=CigctvPCzWin4tqwwoEXk034G jjb128xluho8bbNR8oi6Ncp2L+UG3+YpG2uB5yNo4qSnCuHmxZwlhLS7wPECWuhnx+NGRr92r9N1q cL8bNvhHHrKlfvZ3x8fSZX+nGbDUbfao6yY+6zq4C8AkOhV+Y0RNSrUMVnftiQNCGGeH5NBYmcUOp UwWyduW7WfZqu5GRlvcFa7018168nxbuwwWsiLEeERYbaZIWolBSB7zcyKjH4NCATYmuk8WYcf1lG aJbPAflQDTK+HBoXnrHAwtZYKVAA9Gf8XREtaWts95xHhpZdC7ODFUET0Qo15oa5I87dsfqrMD3is I8FApzxvw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSUNb-0005vp-5w; Thu, 29 Nov 2018 22:01:51 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 51F6E2029FD58; Thu, 29 Nov 2018 23:01:48 +0100 (CET) Date: Thu, 29 Nov 2018 23:01:48 +0100 From: Peter Zijlstra To: Josh Poimboeuf 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: <20181129220148.GD11632@hirez.programming.kicks-ass.net> References: <20181126212628.4apztfazichxnt7r@treble> <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181129171050.iio53bw67fbiwzud@treble> User-Agent: Mutt/1.10.1 (2018-07-13) 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: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.