Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753229AbcLCRNA (ORCPT ); Sat, 3 Dec 2016 12:13:00 -0500 Received: from mail-vk0-f52.google.com ([209.85.213.52]:34503 "EHLO mail-vk0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750919AbcLCRM6 (ORCPT ); Sat, 3 Dec 2016 12:12:58 -0500 MIME-Version: 1.0 In-Reply-To: <20161203150258.vwr5zzco7ctgc4pe@pd.tnic> References: <0a21157c2233ba7d0781bbf07866b3f2d7e7c25d.1480638597.git.luto@kernel.org> <20161202180343.gehqor7lgtmzwqq3@pd.tnic> <20161202185008.tdziqrzi4a3axord@pd.tnic> <20161202192050.l5l3rcwems6hptub@pd.tnic> <20161202192844.elq2py3cxizjs2bx@pd.tnic> <20161203150258.vwr5zzco7ctgc4pe@pd.tnic> From: Andy Lutomirski Date: Sat, 3 Dec 2016 09:05:39 -0800 Message-ID: Subject: Re: [PATCH] x86/alternatives: Do not use sync_core() to serialize I$ To: Borislav Petkov Cc: Linus Torvalds , Andy Lutomirski , Peter Anvin , "the arch/x86 maintainers" , One Thousand Gnomes , "linux-kernel@vger.kernel.org" , Brian Gerst , Matthew Whitehead , Henrique de Moraes Holschuh , Peter Zijlstra , Andrew Cooper Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1279 Lines: 33 On Sat, Dec 3, 2016 at 7:02 AM, Borislav Petkov wrote: > On Fri, Dec 02, 2016 at 08:28:44PM +0100, Borislav Petkov wrote: >> Ah, it is called only from apply_alternatives() but sure, it is safer >> this way. Lemme do that and run it through the boxes to see whether >> anything catches fire. > > Looks good, ran it on a bunch of machines, two of them huge AMD and > Intel, 8-socket monsters. > > Here is a version with a commit message: > > --- > From: Borislav Petkov > Date: Fri, 2 Dec 2016 23:18:51 +0100 > Subject: [PATCH] x86/alternatives: Do not use sync_core() to serialize I$ > > We use sync_core() in the alternatives code to stop speculative > execution of prefetched instructions because we are potentially changing > them and don't want to execute stale bytes. > > What it does on most machines is call CPUID which is a serializing > instruction. And that's expensive. > > However, the instruction cache is serialized when we're on the local CPU > and are changing the data through the same virtual address. So then, we > don't need the serializing CPUID but a simple control flow change. Last > being accomplished with a CALL/RET which the noinline causes. > > So let's try it. I like it. Reviewed-by: Andy Lutomirski