Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752335AbeADRku (ORCPT + 1 other); Thu, 4 Jan 2018 12:40:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56150 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751294AbeADRkr (ORCPT ); Thu, 4 Jan 2018 12:40:47 -0500 Date: Thu, 4 Jan 2018 18:40:45 +0100 From: Andrea Arcangeli To: Alan Cox Cc: Paolo Bonzini , Andrew Cooper , "Woodhouse, David" , "pavel@ucw.cz" , "tim.c.chen@linux.intel.com" , "linux-kernel@vger.kernel.org" , "torvalds@linux-foundation.org" , "tglx@linutronix.de" , "andi@firstfloor.org" , "dave.hansen@intel.com" , "gregkh@linux-foundation.org" Subject: Re: Avoid speculative indirect calls in kernel Message-ID: <20180104174045.GH13348@redhat.com> References: <20180103230934.15788-1-andi@firstfloor.org> <20180104114231.GB1702@amd> <1515066469.12987.112.camel@amazon.co.uk> <94b12025-b27c-04d2-8726-c07a3af6b265@redhat.com> <7a3584c6-0c00-d807-5130-13d1f4b34102@citrix.com> <20180104162541.GD13348@redhat.com> <20180104170442.710aa4c4@alans-desktop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180104170442.710aa4c4@alans-desktop> User-Agent: Mutt/1.9.2 (2017-12-15) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 04 Jan 2018 17:40:47 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Hi Alan, On Thu, Jan 04, 2018 at 05:04:42PM +0000, Alan Cox wrote: > > If you run lots of syscalls ibrs 1 ibpb 1 is much faster. If you do > > infrequent syscalls computing a lot in kernel like I/O with large > > buffers getting copied, ibrs 0 ibpb 2 is much faster than ibrs 1 ibpb > > 1 (on those microcodes where ibrs 1 reduces performance a lot, not all > > microcodes implementing SPEC_CTRL are inefficient like that). > > Have you looked at whether you can measure activity and switch > automatically between the two (or by task). It seems silly to leave > something the machine can accurately assess toa human ? We didn't but it'd be definitely reasonable to investigate and it's a good idea for those CPUs where the updated microcode has to shutdown way more than just indirect branch prediction speculation to achieve the ibrs 1 semantics. If the workload changes from frequent syscalls to reasonably large read/writes and less frequent syscalls or lots of interrupts in idle CPUs, it would work well to switch between ibrs 1 ibpb 1 and ibpb 2 ibrs 0 automatically. As long as the pattern keeps repeating for a while... that is the question ;). Thanks! Andrea