From patchwork Wed Jan 24 12:55:46 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: 191585 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2553:b0:103:945f:af90 with SMTP id p19csp1019007dyi; Wed, 24 Jan 2024 06:20:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IFqWr4jyT7GZF5C1JeNizEkpJYc6xNwmvIOyNUzx6P19Y8Z1RnCtdwy2JomuUcfKdQ9/SmD X-Received: by 2002:a05:6871:8ab:b0:214:b4b1:c43e with SMTP id r43-20020a05687108ab00b00214b4b1c43emr647270oaq.87.1706106028404; Wed, 24 Jan 2024 06:20:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706106028; cv=pass; d=google.com; s=arc-20160816; b=fvsAI+UkE69ilXax20PiqmsBBri+92oHx0PNOT3ZVjb3N37yEqKDx4psVTvI1OACHf f7I9a95dnvThoJ8tZeB4PTpkiGE+NoqZvOcAGunK+453+faGUjTlT5EYmvpeqF6QzEh6 UEjfWo4vFVYEZvMRWgtev+CdKl3dmdLAwHf3k2YKoCn2qJJRlrgGljEW9a1bueVDmllG vPF1n0ePRDWMg0G/apY7nkt7s0vTCYJdeJmaj2VPY1V3a9imz21SClD0c8AfJt/sj8AF lG3pYX0f8LQvM+3orWk/vy8WR3obtZmWya1tW+SRIinIYDlnqRHlIydmBDj4oDKX5HJC 9BvQ== 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=cHhF1aa+hSe5dNNC8/GmOckeZpisQPnrA4h08EHQ1b8df7Ai3wSEH6dlgC06jrd4N1 qHeyWDYOY49D/tWob/MsxWRauBJPTlFnKH+FWD5OwZe3FH98nj4kZhqMj5vXnTtye69O x2lOd9yyb3PpPFSt9nmRlbkXLmi4esHyZIX9BHUFGAkGkydYClqVT2v7cB7MO4lyamFW kMq5jzctwN6i+hodocNFtjMDs4SKm4UHQJzufvhuleNia99NPVM2q7cFxRqQM+GGomSZ Q9K1N+pxY5jiMBxlV5Q9BwcylPc22EDFXXwF+VrjdkA54DHoe+JuLeVhma9FjYFdfUXi p45w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Htu9OG+i; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-37042-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37042-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. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a21-20020a0ca995000000b0068196a55b2csi9369135qvb.132.2024.01.24.06.20.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 06:20:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37042-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Htu9OG+i; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-37042-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37042-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 A5BF11C28382 for ; Wed, 24 Jan 2024 13:02:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E7DAF77F1C; Wed, 24 Jan 2024 13:00:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Htu9OG+i" Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) (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 7773577647 for ; Wed, 24 Jan 2024 13:00:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=134.134.136.31 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706101238; cv=none; b=A6WX5dcKOnjEiXcUNZEI/qobk4g/ug3pBarSOHj9pxhu2mv5jDO8/Q7niMC9Ozv76uClhwEuYP+zXLGdDMLOkx5NsLIMRbLEiFrpFaorUX+u/9sKd+QkSDyPsVI+gEmQM6QJovf8Ou4K3kuDMxP45cpG0RN2/uXEhaUBVwh+Q5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706101238; c=relaxed/simple; bh=LcZSO2fCT5WaMkS6shCgOhCUo14EJT04WN8x+U0u+KI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kCLXuaZdIM+fl2Ss5pg2743aXvgUDO0EbVJrtDUJ4py2Zi4pRHLiEPOcIkYKmBtZdijyOxSgSI5U8bCnN5Ak7C47yPmou68saZiIwCMvPy0a7xwOFQ1rwy2677aawXkzS5l5sEc7Rrq6n4JbqhXzZ+gn3VrcwGagQr1oDEhIABY= 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=Htu9OG+i; arc=none smtp.client-ip=134.134.136.31 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=1706101236; x=1737637236; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LcZSO2fCT5WaMkS6shCgOhCUo14EJT04WN8x+U0u+KI=; b=Htu9OG+ikgK27I6Zk/fFbTLy6xe8OT6DO3OgzGyynoiHkxlGvyUNt9v9 vYyv4uXwqmI+ExRSkJUz8qv8nK4snZmvaX9dhlyaudJMSMdE+V2RpXBra y3dkb8LKSCQwOUsq2R8TgA2P3LhJ5ohL9valE6EStKj3xfcb0uQzNu0EA L2EI9J130wwLtk4oybdBWXV75k8r4bO/x5YgIl4vYnV08N+BIuLMiKoCV uiUHZy7USy7WUs7bjwZYcC2JHA9+u18tKWEjmGqqIt1OvDTfu+WliaHaj i7vnhhgBTlX9XpV93w/LaZ8Sljbv57T7mmjcmPJOrjjGYqjHN0zDgxbRf w==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="466111464" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="466111464" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jan 2024 05:00:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="735924337" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="735924337" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 24 Jan 2024 05:00:30 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 4F2D86B7; Wed, 24 Jan 2024 14:56:02 +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: [PATCHv6 05/16] x86/kexec: Keep CR4.MCE set during kexec for TDX guest Date: Wed, 24 Jan 2024 14:55:46 +0200 Message-ID: <20240124125557.493675-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124125557.493675-1-kirill.shutemov@linux.intel.com> References: <20240124125557.493675-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: 1788981834515993396 X-GMAIL-MSGID: 1788981834515993396 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