Received: by 2002:a05:6a10:144:0:0:0:0 with SMTP id 4csp917953pxw; Sat, 9 Apr 2022 05:10:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJysnI4E8CuJx9MmndkijI+iGpUoBbRCm+Qb7+/lx7uuDSECOmdGBejapTLXGRkWXGsyMMIQ X-Received: by 2002:a17:906:9c83:b0:6df:839a:a6d0 with SMTP id fj3-20020a1709069c8300b006df839aa6d0mr22329760ejc.419.1649506208411; Sat, 09 Apr 2022 05:10:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649506208; cv=none; d=google.com; s=arc-20160816; b=ojsUpz4yez2mhgOQYKV4MOBeuVsdE+NbJVtyu0rrkkYSveSnaqC+fz3ISyDW4xMpbI cP6m/vf47Xtj4+tCvrhgHuu02N4AH5rh4oUh/4HVyseEYWv6w7uhA0n+xWGUCLfk0zvG UC1CN7rP+Iy7FRDZiFkxYqCQOrxZyQf2a/9vffwGsHX51Yk0hmGxkOvYEpfNYsScja4b tpSSbOwbklWgbTRyzZClwpdWB0Xa3a9JUroc4W1YETUUsibmnn5XAKEOaoukyXsDH8UJ 5OIUF3btCvuRUrORiYRhbaIquo0TTEZ5KUKjCxY24Y+qyAX/gDrBsDRL8ncZXSKlOvWy NE7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=zDfjRGJ9h+IZTBXzdZNOuYDOmeMLDkLHoWBasGont0M=; b=1F/Wh70UmaSVG4zIpP6IUzA1uO6MghCKyWBBnzFtvmAYbgGxiqfthqlnwYSlMe+Hc1 jKcB5JCo2s2UiZGnBnKc8Zi+2Lih0nEB/G2kLEuw1N/dZln/SIFwyiIqRnsA8HFkNrYl ewd2BIKIhiAZi5cW4XlTMQ3UxkLN3pJ1oVHzvuwpPlNVLaqWaQkoV4DReTHikam3CnLh YG9QbydC3yh6eRhZNx9/fok6v8mJ/FlASrLKABEWnCi/GcFr160suqDICew5NVHjSu37 MQfp+VuKhk1Ep8uyOSZ9BBAln++A6ivsj5787vd9FrY2e3ubvvrTNV0nK530N88Oy6ny xEvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GoNQnDWt; dkim=neutral (no key) header.i=@linutronix.de header.b=mIuWvVAR; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d15-20020a50cf4f000000b00418c2b5be4fsi2470931edk.305.2022.04.09.05.09.43; Sat, 09 Apr 2022 05:10:08 -0700 (PDT) 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=@linutronix.de header.s=2020 header.b=GoNQnDWt; dkim=neutral (no key) header.i=@linutronix.de header.b=mIuWvVAR; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240316AbiDIBaI (ORCPT + 99 others); Fri, 8 Apr 2022 21:30:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240260AbiDIB3c (ORCPT ); Fri, 8 Apr 2022 21:29:32 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E2E2107826; Fri, 8 Apr 2022 18:27:27 -0700 (PDT) Date: Sat, 09 Apr 2022 01:27:24 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1649467645; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zDfjRGJ9h+IZTBXzdZNOuYDOmeMLDkLHoWBasGont0M=; b=GoNQnDWtKkLhM7K+Xq8BiNCtQxNRAaXbJAtNRq/QqiiimSXbZAUIepivNypwGFlbtD2SER ZHLrZ8DP6nrgvUZxNJveBkSJ0hZgQ9RGMuv1btOv4sk8nSkd3loB7IvpdeEBxNPwbXVTcQ X0KolVyIxuJPOYUpMyd4mSpTRtuhXYN5VPwRVgaNkcPYLRbpa2Ddaaml29DBvl9U6o7Ln1 Z3SgkZZBzqzGK3FbvUDODw+khPT2ogagiCfmV2tRjxlZOjyT/60GXLbZoJpk/X3q4OSyrJ tslmed2N8RgKvF6z/SN5DaiU1LTfzX/jp9iKhDDsh8vxpFxYQXZbwk5dBwXNbw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1649467645; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zDfjRGJ9h+IZTBXzdZNOuYDOmeMLDkLHoWBasGont0M=; b=mIuWvVAR3Zgofq7aplia86wFmjhit0RQk1IPjLy4ZraSyFuwsvgBn9kEytRjLVDlIktWZz P2ju86DAT33qNWDw== From: "tip-bot2 for Kirill A. Shutemov" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/tdx] x86/boot: Set CR0.NE early and keep it set during the boot Cc: "Kirill A. Shutemov" , Dave Hansen , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220405232939.73860-23-kirill.shutemov@linux.intel.com> References: <20220405232939.73860-23-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Message-ID: <164946764478.4207.12214298960833507949.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,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 The following commit has been merged into the x86/tdx branch of tip: Commit-ID: 9cf30606405f37b68ee1c0f6846253313c077088 Gitweb: https://git.kernel.org/tip/9cf30606405f37b68ee1c0f6846253313c0= 77088 Author: Kirill A. Shutemov AuthorDate: Wed, 06 Apr 2022 02:29:31 +03:00 Committer: Dave Hansen CommitterDate: Thu, 07 Apr 2022 08:27:53 -07:00 x86/boot: Set CR0.NE early and keep it set during the boot 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=E2=80=99s FERR#, INTR, and IGNNE# pins. Using FERR# and IGNNE# to handle floating-point exception is deprecated. CR0.NE=3D0 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. During some of this ad-hoc manipulation, CR0.NE is cleared. This causes a #GP in TDX guests and makes it die in early boot. Make CR0 initialization consistent, deriving the initial value of CR0 from CR0_STATE. Since CR0_STATE always has CR0.NE=3D1, this ensures that CR0.NE is never 0 and avoids the #GP. Signed-off-by: Kirill A. Shutemov Signed-off-by: Dave Hansen Reviewed-by: Dave Hansen Reviewed-by: Thomas Gleixner Link: https://lkml.kernel.org/r/20220405232939.73860-23-kirill.shutemov@linux= .intel.com --- 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/he= ad_64.S index dea9530..7b5d362 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 =20 /* 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 =20 /* Jump from 32bit compatibility mode into 64bit mode. */ @@ -661,8 +661,9 @@ SYM_CODE_START(trampoline_32bit_src) pushl $__KERNEL_CS pushl %eax =20 - /* 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 =20 lret diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/tram= poline_64.S index ae112a9..d380f2d 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 =20 # 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 =20 # flush prefetch and jump to startup_32 @@ -148,8 +148,8 @@ SYM_CODE_START(startup_32) movl $MSR_EFER, %ecx wrmsr =20 - # 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 =20 /* @@ -169,7 +169,7 @@ SYM_CODE_START(pa_trampoline_compat) movl $rm_stack_end, %esp movw $__KERNEL_DS, %dx =20 - 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)