Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752144AbcDBUWE (ORCPT ); Sat, 2 Apr 2016 16:22:04 -0400 Received: from mail-ob0-f178.google.com ([209.85.214.178]:33712 "EHLO mail-ob0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751051AbcDBUWC (ORCPT ); Sat, 2 Apr 2016 16:22:02 -0400 MIME-Version: 1.0 In-Reply-To: References: From: Andy Lutomirski Date: Sat, 2 Apr 2016 13:21:41 -0700 Message-ID: Subject: Re: [PATCH] x86: Add a turbo mode sysctl To: Thomas Gleixner Cc: Andy Lutomirski , X86 ML , Borislav Petkov , "linux-kernel@vger.kernel.org" , Linux API 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: 1611 Lines: 50 On Fri, Apr 1, 2016 at 9:10 AM, Thomas Gleixner wrote: > On Fri, 1 Apr 2016, Andy Lutomirski wrote: >> +static void update_local_turbo_mode(void *dummy) >> +{ >> + unsigned long cr0 = read_cr0(); >> + >> + /* >> + * KVM doesn't properly handle CD. >> + * >> + * XXX: this may interact poorly with CPU hotplug. > > Please cc these crazy folks who cleanup the hotplug mess so they can put it on > their todo list. > >> + */ >> + >> + if (turbo_mode) >> + write_cr0(cr0 & ~X86_CR0_CD); >> + else >> + write_cr0(cr0 | X86_CR0_CD); > > I think proper turbo mode disable requires ~(X86_CR0_CD | X86_CR0_NW) I thought that made no difference on family 6 and P4 and was actively dangerous (disabled coherency) before. At least, that's what the table of caching modes and the footnote seems to say. > >> +static void update_turbo_mode(void) >> +{ >> + on_each_cpu(update_local_turbo_mode, NULL, 1); >> + >> + if (!turbo_mode) >> + wbinvd(); > > You really want to do wbinvd() on each cpu to make sure that each cpu gets out > of that turbo thing. Nah, this is an explicit optimization to de-turboize as quickly as possible: "The instruction then issues a special-function bus cycle that directs external caches to also write back modified data and another bus cycle to indicate that the external caches should be invalidated." I think we should merge this patch and add a special-case so that calling unlink on turbo_mode sets it to zero. Then people who rm -rf / will brick their systems more slowly :) --Andy