Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2157030lqz; Tue, 2 Apr 2024 08:46:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWD3SdMhd8q9QNt1p0C8q/YLILOnP41prt2EhRCuPvudSZIKr2SBHCm5bvp6IODx0Rq0lBezGXpHZOUCK84ISOOB42EWFcyC38MZa13mQ== X-Google-Smtp-Source: AGHT+IEhDvuAN/WQtn8XrzZZqAYf31cdHKV71hXOiIgBaF5h/eLiLjvFxw5PPQiO+/VHUa/U/lmi X-Received: by 2002:a17:906:7b4a:b0:a4e:1449:5148 with SMTP id n10-20020a1709067b4a00b00a4e14495148mr7810811ejo.14.1712072773406; Tue, 02 Apr 2024 08:46:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712072773; cv=pass; d=google.com; s=arc-20160816; b=gY4/M67bLEC09AyC9+15dklkVwlg5tAQlaI0MRasbT0KLrpUFbL0GKFLEyoE+gy1bO o+N/PuizGSu+cEFwRh2GzfDZ8aFMBMUjS7rmthYdGjqi2Ct+NBnWgfGRyCFplslUWnO1 IEZKd6kJKW3IlHLm/Vr2WCaqQxBE+d7VALb73IGpGLJfcC9IVvDS6/y9SHMra7JSG4Rg H+0nAeZPVd3SpFQTaSNDTUPw7zDPB245oDsH51iyQRWMeQ30xMM4VcuDYsyI8UXtu2zl 8sicROs7PQHe0kNoFmU1OJEpG8Kr3LkohdstzTtlXxFtX7iz1n03hRjjgfttd367caSg mhYw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=k4h99Uq/4frD5rpYCqYsHBNcu9UF62xffUHFS84Y7t4=; fh=HCRqudk9hiz/L+aQEnjhh/59pXX18/0ZO5lqjHfp4b8=; b=HvYJBwsCQz3M7DmVdJs0f5/4eM9NxvSymkbiD5VtTnQqK2uCv5D1aNW2Ec/5syzunn eFMp+mbfgTNIdve+yuaOlbCjveagO6GZMHeDQawjDN93VA0sJ9w+wjSnu6UWpbkPk2Mr EsDZpzZbH7OY++HEjdvmgL4V4RAUDgUNJY+InikbkFPjCICAYLOgfDEAmKtZkHiGycIZ p/IpWBQ/8XK6RrcGJ6NUxPMl8yG5zT4jX8ewuBOi3BSV3I8Z1BDNI8zttWVg0quHSz+x H8UYlJfQQs93RuFKjymMmyq7/xw5mm8CpLb9BDMV+sCdrWJeCrBij/wcYTdTPZZgbNqR wWxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PktuTijw; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-128271-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128271-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id kl23-20020a170907995700b00a46b86b1fb8si5579041ejc.884.2024.04.02.08.46.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 08:46:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-128271-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PktuTijw; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-128271-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128271-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B86291F2571C for ; Tue, 2 Apr 2024 15:46:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E54413E6B8; Tue, 2 Apr 2024 15:42:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="PktuTijw" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E241E13AD33 for ; Tue, 2 Apr 2024 15:42:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712072557; cv=none; b=KRwHjr42KtJrj7Ja5HvgNqZywonb4DH97qeyZQRF2u2qb906ecO0Hl9/aZy4PPHyscah50HyUgFbEfCDvXLmxBE5FYa2ly3G0wPTFmXe5H6zbn0QnfHb7nncP0B05uJVb1s6s+nVcBcGKWR/dEUCiSvDZPjqjlImzRfn8M8YNSk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712072557; c=relaxed/simple; bh=RZamI5f8/aC7oIQVbalM1Cimf9G3hUXqlyz/JLjpQQQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NCpyP0LMiDDA7X7s7f87/wrOUc20QA2onzecRZST8PvZdpmxVdUyOYjXIxlwlIXaoz1U6EsqFGgBt1ct9cSmlM28IYaJiK+mz3g4Z0ogiXc20dJfd0rOKLRdUe7R4XVHb19uYet1XphkqDpOaxa2SUIeTB7ppZpkFQVNjIldfTw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=PktuTijw; arc=none smtp.client-ip=192.198.163.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712072556; x=1743608556; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=RZamI5f8/aC7oIQVbalM1Cimf9G3hUXqlyz/JLjpQQQ=; b=PktuTijwDsjPaZW6tsNQHDAPJcw8+RKGbZbK8a7jE9jrV9fj0+BFQeL9 dZCJ2lL7N+6OutZv8B9SEd1gZSkCx1tAbfXjsDeZ4oenja3fFzoetmlvl eDKVKMWB+2ybpHGg9Yt7pnGqx5Syd+0TCn3w985VAqbA8k+FIHg4TOLnv jvLgR/Jbk9SF8eMAeIA2ds6HMLmMHvkMGgx6M+rToWpd6mqU1MyJZdwBM mTJUY95gT0VO2Z5uEdOaECClmA9UMFpWPGEtBca+A+V4+V3f/7dFvmojy roRr1NmYeiofZr/QppYrDV5YMkjFclWzq7jjTjLMx1ZaQXYUWi9gAoGHz A==; X-CSE-ConnectionGUID: cX8Cy9f5Si280igoXM7n5w== X-CSE-MsgGUID: bb9q9hDyRJ+zNiZGf7x8zg== X-IronPort-AV: E=McAfee;i="6600,9927,11032"; a="17870104" X-IronPort-AV: E=Sophos;i="6.07,175,1708416000"; d="scan'208";a="17870104" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2024 08:42:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11032"; a="937083654" X-IronPort-AV: E=Sophos;i="6.07,175,1708416000"; d="scan'208";a="937083654" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 02 Apr 2024 08:42:25 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id A10101C5; Tue, 2 Apr 2024 18:42:23 +0300 (EEST) Date: Tue, 2 Apr 2024 18:42:23 +0300 From: "Kirill A. Shutemov" To: Xiaoyao Li Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , "Kalra, Ashish" , Sean Christopherson , "Huang, Kai" , Baoquan He , kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCHv9 05/17] x86/kexec: Keep CR4.MCE set during kexec for TDX guest Message-ID: References: <20240325103911.2651793-1-kirill.shutemov@linux.intel.com> <20240325103911.2651793-6-kirill.shutemov@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Fri, Mar 29, 2024 at 06:48:21PM +0200, Kirill A. Shutemov wrote: > On Fri, Mar 29, 2024 at 11:21:32PM +0800, Xiaoyao Li wrote: > > On 3/25/2024 6:38 PM, Kirill A. Shutemov wrote: > > > TDX guests are not allowed to clear CR4.MCE. Attempt to clear it leads > > > to #VE. > > > > Will we consider making it more safe and compatible for future to guard > > against X86_FEATURE_MCE as well? > > > > If in the future, MCE becomes configurable for TD guest, then CR4.MCE might > > not be fixed1. > > Good point. > > I guess we can leave it clear if it was clear. This should be easy > enough. But we might want to clear even if was set if clearing is allowed. > > It would require some kind of indication that clearing MCE is fine. We > don't have such indication yet. Not sure we can reasonably future-proof > the code at this point. > > But let me think more. I think I will go with the variant below. diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S index 56cab1bb25f5..8e2037d78a1f 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -5,6 +5,8 @@ */ #include +#include +#include #include #include #include @@ -145,11 +147,17 @@ SYM_CODE_START_LOCAL_NOALIGN(identity_mapped) * Set cr4 to a known state: * - physical address extension enabled * - 5-level paging, if it was enabled before + * - Machine check exception on TDX guest, if it was enabled before. + * Clearing MCE might not allowed in TDX guests, depending on setup. */ movl $X86_CR4_PAE, %eax testq $X86_CR4_LA57, %r13 jz 1f orl $X86_CR4_LA57, %eax +1: + testq $X86_CR4_MCE, %r13 + jz 1f + ALTERNATIVE "", __stringify(orl $X86_CR4_MCE, %eax), X86_FEATURE_TDX_GUEST 1: movq %rax, %cr4 -- Kiryl Shutsemau / Kirill A. Shutemov