From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: ARC-Seal: i=1; a=rsa-sha256; t=1516702537; cv=none; d=google.com; s=arc-20160816; b=s/BFI3SWNuZLsLMlE4LgW10BD7YdYVxthYKQfxg1/DkYf+CXxJpda8ZZjAky+/IDI3 mAv60hwo48fKhpdDlyqbVffvrPEew9bbDgIaM3fV2he7GzJuamhdnRbtIdIdSe2hT0bo UPUmrCrAbqjv3fd61eONTho76mUG5ceUIPVTONOvEz6Z57O7g/l2l+Oh8+33JNw8rma9 08PtlS9utvf2z0NQa6y6Nku/8EJDXMbVr24Y1GYXU/Hrv88U+Odta2ikBd63BUmxeiGW DyydEqspByYAiGSY+FkMoCiPA0UkQABNNP4kiC6SrpHJwZq2BnKAQwMqXWTyk4oKMnNQ 5F2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:sender:dkim-signature:arc-authentication-results; bh=l8OQe2NsaaAfhrA28JTv9gi6j5LeAZGmiZBdM1Tp9ds=; b=tvXmGL6UCep+f8Hdz7SZ+XJwqFZbG/CJwIvDhI7QAgEwbW8X5FY6yMh/iIjSAXa07w HCMXQqsXGbyFajDHbUZQDPFO8WSrJhYA0n3B963LNbBe3nL3UkGccK7S4z4hM53+QCh6 5tdLro28SR+r/HY5408CNKGSptN7etm7SHNY527BQZNROhV4+Phc4hZ1wscKx2c4zWIP +WFWmnVRf+XFwMkM7ssIVRCrXlf0KyhbUjoUi8G/k1MzrJFGAaqkgIsMIbZbCQ5RYHMs 8BPSDLpLkyA2RIZW1xmcjPczLNPGVtaO43V+Riw0eS2XL6ulTLMkYh+CIu8MBYXMi/GD EWqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tSWCePJd; spf=pass (google.com: domain of mingo.kernel.org@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mingo.kernel.org@gmail.com Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=tSWCePJd; spf=pass (google.com: domain of mingo.kernel.org@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mingo.kernel.org@gmail.com X-Google-Smtp-Source: AH8x227h1+2+b3bgRN+Hu+B9pkYOY0D0EX4SnhQ/oFv1dAOI2sI3jRiSTqYvdQSAxbcb1LpfwN3LAw== Sender: Ingo Molnar Date: Tue, 23 Jan 2018 11:15:32 +0100 From: Ingo Molnar To: David Woodhouse Cc: Linus Torvalds , KarimAllah Ahmed , Linux Kernel Mailing List , Andi Kleen , Andrea Arcangeli , Andy Lutomirski , Arjan van de Ven , Ashok Raj , Asit Mallick , Borislav Petkov , Dan Williams , Dave Hansen , Greg Kroah-Hartman , "H . Peter Anvin" , Ingo Molnar , Janakarajan Natarajan , Joerg Roedel , Jun Nakajima , Laura Abbott , Masami Hiramatsu , Paolo Bonzini , Peter Zijlstra , Radim =?utf-8?B?S3LEjW3DocWZ?= , Thomas Gleixner , Tim Chen , Tom Lendacky , KVM list , the arch/x86 maintainers , Arjan Van De Ven Subject: Re: [RFC 09/10] x86/enter: Create macros to restrict/unrestrict Indirect Branch Speculation Message-ID: <20180123101532.obioudsu3ecm4rez@gmail.com> References: <1516476182-5153-10-git-send-email-karahmed@amazon.de> <1516566497.9814.78.camel@infradead.org> <1516572013.9814.109.camel@infradead.org> <1516638426.9521.20.camel@infradead.org> <20180123072930.soz25cyky3u4hpgv@gmail.com> <20180123075358.nztpyxympwfkyi2a@gmail.com> <1516699832.9521.123.camel@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1516699832.9521.123.camel@infradead.org> User-Agent: NeoMutt/20170609 (1.8.3) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1590140582166248265?= X-GMAIL-MSGID: =?utf-8?q?1590377879237723950?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: * David Woodhouse wrote: > On Tue, 2018-01-23 at 08:53 +0100, Ingo Molnar wrote: > > > > The patch below demonstrates the principle, it forcibly enables dynamic ftrace  > > patching (CONFIG_DYNAMIC_FTRACE=y et al) and turns mcount/__fentry__ into a RET: > > > >   ffffffff81a01a40 <__fentry__>: > >   ffffffff81a01a40:       c3                      retq    > > > > This would have to be extended with (very simple) call stack depth tracking (just  > > 3 more instructions would do in the fast path I believe) and a suitable SkyLake  > > workaround (and also has to play nice with the ftrace callbacks). > > > > On non-SkyLake the overhead would be 0 cycles. > > The overhead of forcing CONFIG_DYNAMIC_FTRACE=y is precisely zero > cycles? That seems a little optimistic. ;) The overhead of the quick hack patch I sent to show what exact code I mean is obviously not zero. The overhead of using my proposed solution, to utilize the function call callback that CONFIG_DYNAMIC_FTRACE=y provides, is exactly zero on non-SkyLake systems where the callback is patched out, on typical Linux distros. The callback is widely enabled on distro kernels: Fedora: CONFIG_DYNAMIC_FTRACE=y Ubuntu: CONFIG_DYNAMIC_FTRACE=y OpenSuse (default flavor): CONFIG_DYNAMIC_FTRACE=y BTW., the reason this is enabled on all distro kernels is because the overhead is a single patched-in NOP instruction in the function epilogue, when tracing is disabled. So it's not even a CALL+RET - it's a patched in NOP. Thanks, Ingo From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ingo Molnar Subject: Re: [RFC 09/10] x86/enter: Create macros to restrict/unrestrict Indirect Branch Speculation Date: Tue, 23 Jan 2018 11:15:32 +0100 Message-ID: <20180123101532.obioudsu3ecm4rez@gmail.com> References: <1516476182-5153-10-git-send-email-karahmed@amazon.de> <1516566497.9814.78.camel@infradead.org> <1516572013.9814.109.camel@infradead.org> <1516638426.9521.20.camel@infradead.org> <20180123072930.soz25cyky3u4hpgv@gmail.com> <20180123075358.nztpyxympwfkyi2a@gmail.com> <1516699832.9521.123.camel@infradead.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Cc: Linus Torvalds , KarimAllah Ahmed , Linux Kernel Mailing List , Andi Kleen , Andrea Arcangeli , Andy Lutomirski , Arjan van de Ven , Ashok Raj , Asit Mallick , Borislav Petkov , Dan Williams , Dave Hansen , Greg Kroah-Hartman , "H . Peter Anvin" , Ingo Molnar , Janakarajan Natarajan , Joerg Roedel , Jun Nakajima , Laura Abbott , To: David Woodhouse Return-path: Content-Disposition: inline In-Reply-To: <1516699832.9521.123.camel@infradead.org> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org * David Woodhouse wrote: > On Tue, 2018-01-23 at 08:53 +0100, Ingo Molnar wrote: > > > > The patch below demonstrates the principle, it forcibly enables dynamic ftrace  > > patching (CONFIG_DYNAMIC_FTRACE=y et al) and turns mcount/__fentry__ into a RET: > > > >   ffffffff81a01a40 <__fentry__>: > >   ffffffff81a01a40:       c3                      retq    > > > > This would have to be extended with (very simple) call stack depth tracking (just  > > 3 more instructions would do in the fast path I believe) and a suitable SkyLake  > > workaround (and also has to play nice with the ftrace callbacks). > > > > On non-SkyLake the overhead would be 0 cycles. > > The overhead of forcing CONFIG_DYNAMIC_FTRACE=y is precisely zero > cycles? That seems a little optimistic. ;) The overhead of the quick hack patch I sent to show what exact code I mean is obviously not zero. The overhead of using my proposed solution, to utilize the function call callback that CONFIG_DYNAMIC_FTRACE=y provides, is exactly zero on non-SkyLake systems where the callback is patched out, on typical Linux distros. The callback is widely enabled on distro kernels: Fedora: CONFIG_DYNAMIC_FTRACE=y Ubuntu: CONFIG_DYNAMIC_FTRACE=y OpenSuse (default flavor): CONFIG_DYNAMIC_FTRACE=y BTW., the reason this is enabled on all distro kernels is because the overhead is a single patched-in NOP instruction in the function epilogue, when tracing is disabled. So it's not even a CALL+RET - it's a patched in NOP. Thanks, Ingo