From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E84FC43461 for ; Mon, 31 Aug 2020 08:58:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2508E206F0 for ; Mon, 31 Aug 2020 08:58:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728255AbgHaI6U (ORCPT ); Mon, 31 Aug 2020 04:58:20 -0400 Received: from 8bytes.org ([81.169.241.247]:40058 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727810AbgHaI6S (ORCPT ); Mon, 31 Aug 2020 04:58:18 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id 4F673310; Mon, 31 Aug 2020 10:58:13 +0200 (CEST) Date: Mon, 31 Aug 2020 10:58:10 +0200 From: Joerg Roedel To: Borislav Petkov Cc: x86@kernel.org, Joerg Roedel , hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Sean Christopherson , Martin Radev , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: Re: [PATCH v6 38/76] x86/head/64: Set CR4.FSGSBASE early Message-ID: <20200831085810.GA13507@8bytes.org> References: <20200824085511.7553-1-joro@8bytes.org> <20200824085511.7553-39-joro@8bytes.org> <20200829155525.GB29091@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200829155525.GB29091@zn.tnic> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 29, 2020 at 05:55:25PM +0200, Borislav Petkov wrote: > On Mon, Aug 24, 2020 at 10:54:33AM +0200, Joerg Roedel wrote: > > From: Joerg Roedel > > > > Early exception handling will use rd/wrgsbase in paranoid_entry/exit. > > Enable the feature to avoid #UD exceptions on boot APs. > > > > Signed-off-by: Joerg Roedel > > Link: https://lore.kernel.org/r/20200724160336.5435-38-joro@8bytes.org > > --- > > arch/x86/kernel/head_64.S | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S > > index 08412f308de3..4622940134a5 100644 > > --- a/arch/x86/kernel/head_64.S > > +++ b/arch/x86/kernel/head_64.S > > @@ -153,6 +153,13 @@ SYM_CODE_START(secondary_startup_64) > > orl $X86_CR4_LA57, %ecx > > 1: > > #endif > > + > > + ALTERNATIVE "jmp .Lstartup_write_cr4", "", X86_FEATURE_FSGSBASE > > + > > + /* Early exception handling uses FSGSBASE on APs */ > > + orl $X86_CR4_FSGSBASE, %ecx > > How is this supposed to work? > > Alternatives haven't run that early yet and that piece of code looks > like this: > > ffffffff81000067: eb 06 jmp ffffffff8100006f > ffffffff81000069: 81 c9 00 00 01 00 or $0x10000,%ecx > ffffffff8100006f: 0f 22 e1 mov %rcx,%cr4 > > so we'll never set X86_CR4_FSGSBASE during early boot. This is not needed on the boot CPU, but only on secondary CPUs. When those are brought up the alternatives have been patches already. The commit message should probably be more clear about that, I will fix that. The CR4 bit also can't be set unconditionally here on the boot CPU, because at that point the kernel does not know whether the CPU has support for the fsgsbase instructions. Regards, Joerg