Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1753220pxm; Thu, 24 Feb 2022 08:44:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzXugwnNJH1znDFxNbaRYOwnRabLdYlfphfwnjuFDL+bi+Ad+4xhQAJr05UdKCVpTkPVF9Y X-Received: by 2002:a05:6a00:278d:b0:4e1:4534:8801 with SMTP id bd13-20020a056a00278d00b004e145348801mr3704814pfb.78.1645721070113; Thu, 24 Feb 2022 08:44:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645721070; cv=none; d=google.com; s=arc-20160816; b=per5BFDSDW2K0pZjEgoZDtzGoWak/nvPylctSBhGFg2ajG9FI1a7r+Hcea4j2Varrx bVs89QOZVmFB9oRhGwD256y+q4o1666oeveNfP80VoKnPUZrxSd4K17Lwe3CAuEWDq7B 65wsl2rc6Xx5lRh0+UViXf8vTAztimTPkfExIhj5keKKnIEQMFpvfCC+pkQGOx8dhpH5 iHWKXf4t1oZhM63eZTZSiVtZbqpcmftDWirGfUG/GXQ7W6Y0aYj5raaZLFFg9GOaAJck +41Lc7PkGiac+kZJ7ja/br5PyFtN6qg+4Z45uhmgB+4qFwG71L1Pn60H585I0Ur7MJVj O5Xg== 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 :dkim-signature; bh=Cf+fz4pt0OZooLGDuyShAAdqcvALA3uayk0CI+u2Gng=; b=foMUXM+CRbPCV4/dC0lHUH9T4GnHBtg1SbStq6hUzrE+5FF+CpuuLmlX7lMmtEsOmW tTexUnFOKw1gPhgLLR8NSsGpLDNedQZq0hZqNFtO8ihBlQv/CZUOXu3tQ/qL5MhZPNtF M9dY1Acp/2hmqhUiK+W/hRyfUtpJB8awhVEPefpTVpHqEaX1rUxD/9X3C3u2Y/C2mIrQ M1ROAbf5nAf/HH203xLMenrTQhj7mtnelpY99N8zWuCDP9BDcr1ToQuvf8EU8Cdff8+s MfRVvoSj6sgvAfttph013hJKrGtEqfy/Pp5e2LWyFgduw64yVXaRuTBA3VsOmT9GDvXC tvKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Er6PL2bl; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id i5si3015182pla.532.2022.02.24.08.44.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 08:44:30 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Er6PL2bl; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0AC012275BB; Thu, 24 Feb 2022 08:23:51 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236793AbiBXP7Y (ORCPT + 99 others); Thu, 24 Feb 2022 10:59:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236909AbiBXP5v (ORCPT ); Thu, 24 Feb 2022 10:57:51 -0500 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88BD91323E1 for ; Thu, 24 Feb 2022 07:57:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645718231; x=1677254231; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XeiDSHDhSk1ZAnWl9C35VO6F89iKjoQMuwzkA1dSo5A=; b=Er6PL2blp4iUxE6EwPpd4NFrnGEiaE1n18gruakgIwM6D5sZm+7gIWrx 0dki3wdfE+R7yfP0JsG2ZGS40+IR3bU9o1lwkNN02tZZQ9laHmwWfyaR4 XzWAxDgEdbNwAkcsamhTw2hQxeZ+pzYhvlSv3l5209A4swOoYAxSHSSY1 GbQPZK8XaCdXCZUVppdJPoO85hSlYOOCKmE/Sk73rrcqj38jZJMy7KVXf QDExb9YOCOI+YnkDi0MzcarALCrGy3XhrGa10rR2+TO5Pr4iVWRQBtc/4 e6OZF8cjWoEMpKHajTiw+U8RBzC0n8g8ycPzflcY0my2+g3sA2+ouQDEh g==; X-IronPort-AV: E=McAfee;i="6200,9189,10268"; a="315487722" X-IronPort-AV: E=Sophos;i="5.90,134,1643702400"; d="scan'208";a="315487722" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Feb 2022 07:56:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,134,1643702400"; d="scan'208";a="508914554" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 24 Feb 2022 07:56:32 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 55F9DB0F; Thu, 24 Feb 2022 17:56:35 +0200 (EET) From: "Kirill A. Shutemov" To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@intel.com, luto@kernel.org, peterz@infradead.org Cc: sathyanarayanan.kuppuswamy@linux.intel.com, aarcange@redhat.com, ak@linux.intel.com, dan.j.williams@intel.com, david@redhat.com, hpa@zytor.com, jgross@suse.com, jmattson@google.com, joro@8bytes.org, jpoimboe@redhat.com, knsathya@kernel.org, pbonzini@redhat.com, sdeep@vmware.com, seanjc@google.com, tony.luck@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, x86@kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv4 22/30] x86/boot: Set CR0.NE early and keep it set during the boot Date: Thu, 24 Feb 2022 18:56:22 +0300 Message-Id: <20220224155630.52734-23-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220224155630.52734-1-kirill.shutemov@linux.intel.com> References: <20220224155630.52734-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org TDX guest requires CR0.NE to be set. Clearing the bit triggers #GP(0). If CR0.NE is 0, the MS-DOS compatibility mode for handling floating-point exceptions is selected. In this mode, the software exception handler for floating-point exceptions is invoked externally using the processor’s FERR#, INTR, and IGNNE# pins. Using FERR# and IGNNE# to handle floating-point exception is deprecated. CR0.NE=0 also limits newer processors to operate with one logical processor active. Kernel uses CR0_STATE constant to initialize CR0. It has NE bit set. But during early boot kernel has more ad-hoc approach to setting bit in the register. Make CR0 initialization consistent, deriving the initial value of CR0 from CR0_STATE. Signed-off-by: Kirill A. Shutemov --- arch/x86/boot/compressed/head_64.S | 7 ++++--- arch/x86/realmode/rm/trampoline_64.S | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S index fd9441f40457..d0c3d33f3542 100644 --- a/arch/x86/boot/compressed/head_64.S +++ b/arch/x86/boot/compressed/head_64.S @@ -289,7 +289,7 @@ SYM_FUNC_START(startup_32) pushl %eax /* Enter paged protected Mode, activating Long Mode */ - movl $(X86_CR0_PG | X86_CR0_PE), %eax /* Enable Paging and Protected mode */ + movl $CR0_STATE, %eax movl %eax, %cr0 /* Jump from 32bit compatibility mode into 64bit mode. */ @@ -662,8 +662,9 @@ SYM_CODE_START(trampoline_32bit_src) pushl $__KERNEL_CS pushl %eax - /* Enable paging again */ - movl $(X86_CR0_PG | X86_CR0_PE), %eax + /* Enable paging again. */ + movl %cr0, %eax + btsl $X86_CR0_PG_BIT, %eax movl %eax, %cr0 lret diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S index ae112a91592f..d380f2d1fd23 100644 --- a/arch/x86/realmode/rm/trampoline_64.S +++ b/arch/x86/realmode/rm/trampoline_64.S @@ -70,7 +70,7 @@ SYM_CODE_START(trampoline_start) movw $__KERNEL_DS, %dx # Data segment descriptor # Enable protected mode - movl $X86_CR0_PE, %eax # protected mode (PE) bit + movl $(CR0_STATE & ~X86_CR0_PG), %eax movl %eax, %cr0 # into protected mode # flush prefetch and jump to startup_32 @@ -148,8 +148,8 @@ SYM_CODE_START(startup_32) movl $MSR_EFER, %ecx wrmsr - # Enable paging and in turn activate Long Mode - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax + # Enable paging and in turn activate Long Mode. + movl $CR0_STATE, %eax movl %eax, %cr0 /* @@ -169,7 +169,7 @@ SYM_CODE_START(pa_trampoline_compat) movl $rm_stack_end, %esp movw $__KERNEL_DS, %dx - movl $X86_CR0_PE, %eax + movl $(CR0_STATE & ~X86_CR0_PG), %eax movl %eax, %cr0 ljmpl $__KERNEL32_CS, $pa_startup_32 SYM_CODE_END(pa_trampoline_compat) -- 2.34.1