From patchwork Tue Feb 27 18:16:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 207396 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2922128dyb; Tue, 27 Feb 2024 11:35:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUCVXsgfb0wlL3GZm6VKwpLfR1TXRkdHYaxSFywnPNmI5/Kmb87Si6eIhbuuohf7KW5W1mB3lfUbchJUuaZwT4xOMIgTg== X-Google-Smtp-Source: AGHT+IGk219ANcOlZN41YODrVVt8Ici1gtdcbvY+aQb/CKbAVcJO020hKcfiYcpQFiCoRRaBbCFG X-Received: by 2002:ac8:4888:0:b0:42e:6eac:12e8 with SMTP id i8-20020ac84888000000b0042e6eac12e8mr11105699qtq.0.1709062526271; Tue, 27 Feb 2024 11:35:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709062526; cv=pass; d=google.com; s=arc-20160816; b=kLcaA2cG5Xxwzhpr23m3PVzNFjTwExN2QmmMR0eGAQlY8DjuMb1Rme0ZRHT8vRQ1sl gbAN40zGtssQl0GHFYEKSiNFDfHoBZP8HqiZvFsr6FULovHX3h61Hjcb2Ye4kulvnDmP zoAXPeLMAvjtVaDBwgBrfQomS1BUrcfnTXNcLd+KiVJySrmr1IIOkgqkyrfVsGIzBI86 jbdbN0tjscteFzOFCNnPJwlLIRm1aMc64K4UhNdrnx8nGwGFWku8evOTemJcFMU4CWWQ zA3NdIWHWgcZJMDvKoISPeDa6m+V1DSbHtvSoDGKlmDCyy5hCsy+oTC+0WtwmdUJd4FA gIBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=5nY5/kk8s6fYr//Cj2FkdJCG5YE9u6hL2PBs6U9nryU=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=Wa+lBkL8+4sebuwdZQtAerTm0RJZlftboG+RGBplqXQd7NGjeo2PowBevg6DU/OBeb Ia9RV3nAwjGwkdROYOOLuAR4QU4wXIlc1hFtFeKiXmxgHUcy/JjPiBDu5LCyIAgW95zQ srjOtMrMJrx1V2RFhcqMMfAB1LPheak4BBOKuMs2cfSYxFphhDpWL0btDx9wB27tiHI9 mDhHBVfDtQD1pOPUCGQ5fyitx8BqdfhRnCXzvTD/lEDbKiXWchEO8vWjncqmqGR4Fhbg qIXNpF5uN0iEa/2pwTJrDN2HDVXPl5MTiJK/S6cfy6ZTsyIqTY0ngCrPzzR2DykixYFS OGlQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DWzC+Ykj; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83813-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83813-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d22-20020ac85356000000b0042e78cfc501si7193393qto.544.2024.02.27.11.35.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 11:35:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83813-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=DWzC+Ykj; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-83813-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83813-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 46F811C25834 for ; Tue, 27 Feb 2024 18:18:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7EF3514DFFD; Tue, 27 Feb 2024 18:17:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="DWzC+Ykj" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 2BD97149019 for ; Tue, 27 Feb 2024 18:16:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057821; cv=none; b=DtW1xHS810Lih68blssaGuienhlNrfDgcnYSuzNw1njIjAmHgi/IvWk0FKN2jZ4lmJCGfx88zjaZ8zlmMZUcq2aUSeQDA2GMLknvdAJmyJ85BVXnRW+SD6sfGX4F1YLjGakE6MqfI5pl+k4YzoLOSYpe6oeXDaEWpjsrKGHmEgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709057821; c=relaxed/simple; bh=LcZSO2fCT5WaMkS6shCgOhCUo14EJT04WN8x+U0u+KI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J0hTb4D1nrdnjgLl1LPEb/Sf6eXp61TkcSjTxhL93WunbJ1iW+rToAc8Pvq0qUTMXqqEzt5QPZu6CCvIEENxV1WfsDPlldOTJLWK+8AZD3fEr1/a0CN7PhIDUC5gamDwCMaODJjF4Mz46JYJyNx7Ohw+vVnP0OpjS7osD4RLZSE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.helo=mgamail.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=DWzC+Ykj; arc=none smtp.client-ip=192.198.163.8 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.helo=mgamail.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709057819; x=1740593819; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LcZSO2fCT5WaMkS6shCgOhCUo14EJT04WN8x+U0u+KI=; b=DWzC+Ykja44apzKIOzANZucSoRvPq0hGEgOLhi3HZ8EH8rAw7APbleNY WA5Td4TPsZ7NewP+rCa8s4hPsClPk1BOVK76nepvFYJvLtTP5xZ+1+Q9m AlIyQL+3HJAWoQJHShmDoryAYC7NuPIsHIo/UvorrfQNXTbMxnxsaeyus s5IBYcdaTDYg0WTjHISURIQOrzaAhXAeQ6XZNRTdhv+u+qieLK6APBYrw RWA609DKFgTSlRalPGxsKFWO449QVihZCrbFBd0gLbIgo5EAEpDmn80a2 YpRbsO+2fFQgTpTaABEfobHTiyZOJ8YxXCKTUCYPtzm56LFwYAdfzOL7O g==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="20966093" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="20966093" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 10:16:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032725" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032725" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 10:16:26 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 7AAD94C5; Tue, 27 Feb 2024 20:16:19 +0200 (EET) From: "Kirill A. Shutemov" To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "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, "Kirill A. Shutemov" Subject: [PATCHv8 05/16] x86/kexec: Keep CR4.MCE set during kexec for TDX guest Date: Tue, 27 Feb 2024 20:16:05 +0200 Message-ID: <20240227181616.3032032-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227181616.3032032-1-kirill.shutemov@linux.intel.com> References: <20240227181616.3032032-1-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792081947539409020 X-GMAIL-MSGID: 1792081947539409020 TDX guests are not allowed to clear CR4.MCE. Attempt to clear it leads to #VE. Use alternatives to keep the flag during kexec for TDX guests. The change doesn't affect non-TDX-guest environments. Signed-off-by: Kirill A. Shutemov Reviewed-by: Kai Huang --- arch/x86/kernel/relocate_kernel_64.S | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S index 56cab1bb25f5..e144bcf60cbe 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,12 +147,15 @@ 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. Clearing MCE is not allowed + * in TDX guests. */ movl $X86_CR4_PAE, %eax testq $X86_CR4_LA57, %r13 jz 1f orl $X86_CR4_LA57, %eax 1: + ALTERNATIVE "", __stringify(orl $X86_CR4_MCE, %eax), X86_FEATURE_TDX_GUEST movq %rax, %cr4 jmp 1f