Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp2125803pxb; Sat, 19 Feb 2022 03:00:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+Ern9V+9ZVaom10BoztNf4nlHCq/bckrjJnsQPfVnOVg0+W7g3JCHNj6mwJgH74GZtt1C X-Received: by 2002:a17:907:8186:b0:6d0:33e6:b4c8 with SMTP id iy6-20020a170907818600b006d033e6b4c8mr9513829ejc.724.1645268423127; Sat, 19 Feb 2022 03:00:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645268423; cv=none; d=google.com; s=arc-20160816; b=be2zoSCuP5DIw8CQuDkPb5iy5DkgC1D0giFYDcDWjD1ILYfg7xy40xlkuzYXawVmIl 4EH+2uExBzMM9SM1zMqs77cl08z+A/UG0rfPIijjA9JSS10gqWhuOzxg65Aa2GiBflYK yqS69QOh6JmHCRXMUreE2Pyjk/U0AzjdFXDOsCXLd7zdkCa1JmWAOEYDfMF5sOSE75hN NzNDp571A42SZaes/8rYUz7i127q0WRsLn1q5Zc3HH5wYyjk9GTgGfJW1ptpH44eTZ+H esU1H5uOWGZ7rmBhBnqn2kM779uc8cUEMAOz+YN/mXqIyTClS0J2aJETXFiKP3lrtDO6 Ke7Q== 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=u7yobfals8GsH85avPnqP/+AnxV1UmCOfG/MizGKvdvYdQXk/bxnokwaGRrVj0pZhC dYNVGbF7R0nxDv18ELZfFRqB413WbDBh16+5IwOtLbJnfRcwpeCsK0sstgEA9H7OkKc6 byTYilnzNTq6Z5YGCKIFgY8vAcJPG6HsTewA5PNtQnqq22dUmvmTI6iHb1Ls6jQZNbY3 hXU/LB41WtKxcnWrySxekJrLIq+Xupfj5dgzO8b6nKTU23EYwxmO/tyiag/a8m+C8WfW RDoF7fryO07NPKZx1uDm/jNIxpNAj37V5gRwYC4wkzfoZiTb8bbhtoX+PjrRwrz7MqXb mv+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="ec/x21q4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f20si1761377edc.256.2022.02.19.02.59.59; Sat, 19 Feb 2022 03:00:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="ec/x21q4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237904AbiBRQTd (ORCPT + 99 others); Fri, 18 Feb 2022 11:19:33 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:44144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237716AbiBRQSC (ORCPT ); Fri, 18 Feb 2022 11:18:02 -0500 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CFFF3A5F1 for ; Fri, 18 Feb 2022 08:17:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645201065; x=1676737065; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XeiDSHDhSk1ZAnWl9C35VO6F89iKjoQMuwzkA1dSo5A=; b=ec/x21q49yR3xXkV1rg+h7mSQbDHlXh3ZTDnWULLt4M7FJ0x9NZw59bc 6m3SwFiYbCTkseE1yTX8Roz/nhwR3WF0aNpJaxkLV0+AnLsBVf0BcpRwL QV9pULGkexFE9riqt1ZH7ofV0QwOEBX3aW3v+W1ECTk2ZXABnsLMR3AFL eJEa+uMMTm1PC3pk0ht89ySNMxQi/Gj44XvcWxDsbWDV2P7MF74ekIMa3 p1dlUiA/eKiOwqR/lr46y61w9g89OgrbqiOv2kwC5yyhiDSuVpjSCaN6c Yic2421eBG63NbhiTJzQ0MZLk8W3vUWt8hsDSYRZMKAyjOkcAPJe6rlWn A==; X-IronPort-AV: E=McAfee;i="6200,9189,10261"; a="275753730" X-IronPort-AV: E=Sophos;i="5.88,379,1635231600"; d="scan'208";a="275753730" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Feb 2022 08:17:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,379,1635231600"; d="scan'208";a="605590602" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP; 18 Feb 2022 08:17:20 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 2F36CD50; Fri, 18 Feb 2022 18:17:23 +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, x86@kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv3 23/32] x86/boot: Set CR0.NE early and keep it set during the boot Date: Fri, 18 Feb 2022 19:17:09 +0300 Message-Id: <20220218161718.67148-24-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220218161718.67148-1-kirill.shutemov@linux.intel.com> References: <20220218161718.67148-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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham 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