Received: by 10.223.176.46 with SMTP id f43csp3982087wra; Tue, 23 Jan 2018 02:16:25 -0800 (PST) X-Google-Smtp-Source: AH8x227NX/xAUFKsyZx30I67LME530lKRxyXg7/Hpk3TSj+0rOxB6wmilQLAoaFJ0S2FRza7Y7Hw X-Received: by 2002:a17:902:6186:: with SMTP id u6-v6mr5057045plj.390.1516702585430; Tue, 23 Jan 2018 02:16:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516702585; cv=none; d=google.com; s=arc-20160816; b=NmEKlEB+t/CsBBC+ypUnKPCbrnQqlBU2l5+l+8bItaflgrYK9WkTcdkoNvkpvcPrzP 83AUChIabilTMmT6R0hgm7SoF810+QZpkaZlqahNc783CV71PptY5Jz4whYoaD0vbp7p QS/iYnrqqSL32jZufDYGdk8DzAC9rmch0mMLJSqItild5uAQz9eigjqrNmyTDYmXLwCv wmEDjbzkY/N1mxWpqHbcBfC4LJ8AKLIBsRrseET5TvXvbeD3qPxAPmpesKg3/DX/20IW Cwwgu4AVs0i2WWk6fxizxqHkml85CHZYUEqpffixDvDpON13wHqYd6KziBoL+BF+naO3 iUoA== 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:dkim-signature :arc-authentication-results; bh=l8OQe2NsaaAfhrA28JTv9gi6j5LeAZGmiZBdM1Tp9ds=; b=E/aeRppLWtV2obl70L3OP37RkhrI34SLh3ci8hAn8hj3eeP7Qs38DHFEZUpc2loFdR 7d6MhyE/ruqHUKwfxBlORjBItlpiJCUuj/xwhZKQ6XHLnCIKJmoxNck6rMqgZRj0kT5T rCiXbL/80Iqq2fVZDQAz0UwQYX690XZtRk8wYgvIOtJAi8mTEmtF6eogObZOoWbKHSVn owau779aDsHcJoADW/YYngyldeip6/L8jxyY/sGyVQXWuF9TxDCaEo/+XbhjCMMr6ZY4 wyZdJOOKtITxjqygcQnkfpstCSQpES106VDvCf4KvGR+S+m05dYAEkH07MAtZaNfIxYK ZILQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=tSWCePJd; 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 f3si14850015pgn.718.2018.01.23.02.16.10; Tue, 23 Jan 2018 02:16: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=@gmail.com header.s=20161025 header.b=tSWCePJd; 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 S1751355AbeAWKPk (ORCPT + 99 others); Tue, 23 Jan 2018 05:15:40 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:38723 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751233AbeAWKPi (ORCPT ); Tue, 23 Jan 2018 05:15:38 -0500 Received: by mail-wm0-f66.google.com with SMTP id 141so740293wme.3; Tue, 23 Jan 2018 02:15:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=l8OQe2NsaaAfhrA28JTv9gi6j5LeAZGmiZBdM1Tp9ds=; b=tSWCePJdr+SWis8Umf0A3UnH9+dLYYxx9ZWZS/qAXMZnHIYbsmnfdA+88uHO5SniEH WpEfb3bu77DzEENTfCCIxW6JP7uG0KTtQhAjPSph8fCEfRGap4Y5O44u+B1sFShwmvjo xd3Z1ETrlG/a7/esm8VsRlw3swfXul1+w7NlRH7vcMf3hVr2SOayXlZjJW9DAU9wpsif eYCEdAUF2LHQql/F4qi7a3TPUqqrIGCySb/J4UkfI0QNA6/xOgtHOyTH33N0YPzoO/TE QrgcyiA1KytcZQgnZUEpoxSD0Z/B7EL9XBsb4UtMOZo6ekLWSQfpEYlcdvL62ZNnBNNX Dagg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=l8OQe2NsaaAfhrA28JTv9gi6j5LeAZGmiZBdM1Tp9ds=; b=lVi8LfEAqgEaACpD/ilkpLMIXs55KV0pxkzqZu3yxnfuMZFBtLYhY7PIIsROQgl8tO 7JosYkEwguIpEnm11z4tYxUmVeu2hoRc87M6TnpSsr5E8k2IcVa9v6MA1OCN+8+MFrzd cSSm+JBt3lwDxdzKyeofczKD+zqUIPKmtj76kncXrliooi8YdLwv2oFiCovot377JzG5 I2qchecyMBdNuT4rKhTwx6qzU6rzdYWVrHdBFGJYO3+WSEeZm5dBMWfKq71kt1ksovwp Z8iL6Q1g+ZssZP5qKGxeOywBJPAkYx1ommpVcQiPk/yWsGIbmE7AseT+uEE68SQW9bDJ 8mgw== X-Gm-Message-State: AKwxytekozAtTZQHTaYzxsyqugcDD/9q67xWHGzeGWMtRIvGC8X6a2ZV spkB3PXWVEmFL5Ph9DCz8as= X-Received: by 10.28.168.8 with SMTP id r8mr1502086wme.157.1516702536641; Tue, 23 Jan 2018 02:15:36 -0800 (PST) Received: from gmail.com (2E8B0CD5.catv.pool.telekom.hu. [46.139.12.213]) by smtp.gmail.com with ESMTPSA id v75sm19184wrc.45.2018.01.23.02.15.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jan 2018 02:15:35 -0800 (PST) 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) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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