Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753491AbeAFOlR (ORCPT + 1 other); Sat, 6 Jan 2018 09:41:17 -0500 Received: from mail-qk0-f195.google.com ([209.85.220.195]:33581 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753261AbeAFOlP (ORCPT ); Sat, 6 Jan 2018 09:41:15 -0500 X-Google-Smtp-Source: ACJfBoumqP7y1/aInbUAy+VmASrFtxlUGE8StUZ30WsD/um8ovRnE2ZSZumBwzqY0bc5CMUqNfMYug== Date: Sat, 6 Jan 2018 09:41:11 -0500 From: Konrad Rzeszutek Wilk To: Tim Chen Cc: Thomas Gleixner , Andy Lutomirski , Linus Torvalds , Greg KH , Dave Hansen , Andrea Arcangeli , Andi Kleen , Arjan Van De Ven , David Woodhouse , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 4/8] x86/spec_ctrl: Add sysctl knobs to enable/disable SPEC_CTRL feature Message-ID: <20180106144110.GA2592@localhost.localdomain> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On Fri, Jan 05, 2018 at 06:12:19PM -0800, Tim Chen wrote: > From: Tim Chen > From: Andrea Arcangeli > > There are 2 ways to control IBRS > > 1. At boot time > noibrs kernel boot parameter will disable IBRS usage > > Otherwise if the above parameters are not specified, the system > will enable ibrs and ibpb usage if the cpu supports it. > > 2. At run time > echo 0 > /sys/kernel/debug/x86/ibrs_enabled will turn off IBRS > echo 1 > /sys/kernel/debug/x86/ibrs_enabled will turn on IBRS in kernel > echo 2 > /sys/kernel/debug/x86/ibrs_enabled will turn on IBRS in both userspace and kernel > > The implementation was updated with input and suggestions from Andrea Arcangeli. > > Signed-off-by: Tim Chen > --- > arch/x86/entry/calling.h | 42 ++++++++-- > arch/x86/include/asm/spec_ctrl.h | 15 ++++ > arch/x86/kernel/cpu/Makefile | 1 + > arch/x86/kernel/cpu/scattered.c | 2 + > arch/x86/kernel/cpu/spec_ctrl.c | 160 +++++++++++++++++++++++++++++++++++++++ > 5 files changed, 214 insertions(+), 6 deletions(-) > create mode 100644 arch/x86/include/asm/spec_ctrl.h > create mode 100644 arch/x86/kernel/cpu/spec_ctrl.c > > diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h > index 09c870d..6b65d47 100644 > --- a/arch/x86/entry/calling.h > +++ b/arch/x86/entry/calling.h > @@ -373,35 +373,55 @@ For 32-bit we have the following conventions - kernel is built with > .endm > > .macro ENABLE_IBRS > - ALTERNATIVE "jmp .Lskip_\@", "", X86_FEATURE_SPEC_CTRL > + testl $1, dynamic_ibrs > + jz .Lskip_\@ > + > PUSH_MSR_REGS > WRMSR_ASM $MSR_IA32_SPEC_CTRL, $SPEC_CTRL_FEATURE_ENABLE_IBRS > POP_MSR_REGS > + jmp .Ldone_\@ > + > .Lskip_\@: > + lfence > +.Ldone_\@: > .endm > > .macro DISABLE_IBRS > - ALTERNATIVE "jmp .Lskip_\@", "", X86_FEATURE_SPEC_CTRL > + testl $1, dynamic_ibrs On every system call we end up hammering on this 'dynamic_ibrs' variable. And it looks like it can be flipped via the IPI mechanism. Would it make sense for this to be per-cpu?