Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3846277pxy; Mon, 26 Apr 2021 11:07:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwawxjGyxCbGAp7z/WRMUIVZbJS86bICs128ZnS+nZuKCU1rKfTf8ST7vYpFYJMHzRicMWG X-Received: by 2002:a05:6402:8d4:: with SMTP id d20mr22501859edz.49.1619460422064; Mon, 26 Apr 2021 11:07:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619460422; cv=none; d=google.com; s=arc-20160816; b=azm8k4nN0Vp28hlDej6tQMRjwaxmdJ0pRRra/9tXNkhYI98tsxY+fPZSTgPsUBIeEv 6XvD5YGzZeDUIXBOah+YLVyreiLbHI+5JO4gsIYm0kAYZ6ICrXaWxd3ZPaUpgZanh1mh PGEXPNPjWYJeG8x4z1P7rXtVANSGfXtejYzldnASafEYK6YAyqjC8My/O6sI4yXIWdV2 KYebpSVZIMY0Pokt191oMjgaYdy2+4ObqQL18oLmf5n8XAg8BVOr4LqhgyzMQJzxbk8u vpnmYxI8uXDD2dMNQlCkvKh8009NTNVjRHDDAkoilmUIOEfEgI7rPnsV2KxviwgX81Ky 4r0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=NTcY7B7HE/ncVSjxnTOu4hft09O3EscWXfqT8xYj9U4=; b=EywLmSMTD7EAYjAsH+IeBDgu+DAmP0VGNkoijNRas42BDhJg5PZqM00dl7SQIoJz+E hIejQK76mYWaCVmoupJFUNW6HVpIqbQ+pD+F8d0J3KCVPRaWQm58Pi+VBEBs6Koq6I/f b9YU8UX/4BkVI6ruGIBhovobueTKRU7ylhdHAHf7Cg9qGRImrg7fTPESkAvwBR1/OgFD RIF77ccyST3ojf/Q6/SbFFA0FIyb7Cb+Ftx0rYRR9V+xB23mTCMqE3v5tQPQNYYqB+sH q2UfTwQuuYBMVyk8jFePzM6yXfLfx495L5R4Vxh0N9k6PXZ89McQeYZ1sTFYqQBL7zfc A8JQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m8si442574edc.284.2021.04.26.11.06.38; Mon, 26 Apr 2021 11:07:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235313AbhDZSF3 (ORCPT + 99 others); Mon, 26 Apr 2021 14:05:29 -0400 Received: from mga04.intel.com ([192.55.52.120]:22343 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234474AbhDZSDn (ORCPT ); Mon, 26 Apr 2021 14:03:43 -0400 IronPort-SDR: fIROrAoqK/ocL4zbo3ZtGsxvp0cXSw45UCL4NFCEnbCPCLsMXKb6K2AvlIeN1DWFMjWmQuyWQL Z+Ivzedjl4AQ== X-IronPort-AV: E=McAfee;i="6200,9189,9966"; a="194263270" X-IronPort-AV: E=Sophos;i="5.82,252,1613462400"; d="scan'208";a="194263270" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2021 11:02:53 -0700 IronPort-SDR: s7Ljt5x1VjV5NI8/ghxs6X2a2LPGqQ3NFsIuvVGklPRrgM/DSq8GDiKXjHHxZL2UFiqqkKN3Fq D8K/2Ms7Oaog== X-IronPort-AV: E=Sophos;i="5.82,252,1613462400"; d="scan'208";a="447353424" Received: from ssumanpx-mobl.amr.corp.intel.com (HELO skuppusw-mobl5.amr.corp.intel.com) ([10.254.34.197]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2021 11:02:53 -0700 From: Kuppuswamy Sathyanarayanan To: Peter Zijlstra , Andy Lutomirski , Dave Hansen , Dan Williams , Tony Luck Cc: Andi Kleen , Kirill Shutemov , Kuppuswamy Sathyanarayanan , Raj Ashok , Sean Christopherson , linux-kernel@vger.kernel.org, Sean Christopherson , Kuppuswamy Sathyanarayanan Subject: [RFC v2 22/32] x86/boot: Avoid #VE during compressed boot for TDX platforms Date: Mon, 26 Apr 2021 11:01:49 -0700 Message-Id: <5765f65857a4d78fd3fb1cbe7c82a6d455b401c4.1619458733.git.sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Avoid operations which will inject #VE during compressed boot, which is obviously fatal for TDX platforms. Details are, 1. TDX module injects #VE if a TDX guest attempts to write EFER. So skip the WRMSR to set EFER.LME=1 if it's already set. TDX also forces EFER.LME=1, i.e. the branch will always be taken and thus the #VE avoided. 2. TDX module also injects a #VE if the guest attempts to clear CR0.NE. Ensure CR0.NE is set when loading CR0 during compressed boot. The Setting CR0.NE should be a nop on all CPUs that support 64-bit mode. Signed-off-by: Sean Christopherson Reviewed-by: Andi Kleen Signed-off-by: Kuppuswamy Sathyanarayanan --- arch/x86/boot/compressed/head_64.S | 5 +++-- arch/x86/boot/compressed/pgtable.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index e94874f4bbc1..37c2f37d4a0d 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -616,8 +616,9 @@ SYM_CODE_START(trampoline_32bit_src) movl $MSR_EFER, %ecx rdmsr btsl $_EFER_LME, %eax + jc 1f wrmsr - popl %edx +1: popl %edx popl %ecx /* Enable PAE and LA57 (if required) paging modes */ @@ -636,7 +637,7 @@ SYM_CODE_START(trampoline_32bit_src) pushl %eax /* Enable paging again */ - movl $(X86_CR0_PG | X86_CR0_PE), %eax + movl $(X86_CR0_PG | X86_CR0_NE | X86_CR0_PE), %eax movl %eax, %cr0 lret diff --git a/arch/x86/boot/compressed/pgtable.h b/arch/x86/boot/compressed/pgtable.h index 6ff7e81b5628..cc9b2529a086 100644 --- a/arch/x86/boot/compressed/pgtable.h +++ b/arch/x86/boot/compressed/pgtable.h @@ -6,7 +6,7 @@ #define TRAMPOLINE_32BIT_PGTABLE_OFFSET 0 #define TRAMPOLINE_32BIT_CODE_OFFSET PAGE_SIZE -#define TRAMPOLINE_32BIT_CODE_SIZE 0x70 +#define TRAMPOLINE_32BIT_CODE_SIZE 0x80 #define TRAMPOLINE_32BIT_STACK_END TRAMPOLINE_32BIT_SIZE -- 2.25.1