Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1116374rdb; Fri, 22 Dec 2023 15:53:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFipJ5t6y6Lrcy3pAXykVlE5AEycrEv6WDW+fBnHJXB9TWcsysg34DRuWpC65q0qJJR7R7B X-Received: by 2002:a05:6a20:a126:b0:18c:ad4d:3469 with SMTP id q38-20020a056a20a12600b0018cad4d3469mr2630036pzk.53.1703289224393; Fri, 22 Dec 2023 15:53:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703289224; cv=none; d=google.com; s=arc-20160816; b=nMh6AZ2cxN+8m+rXSAvgw+JwnnHfH3mX3myh7ocaubohuLOqt/66pZ3CJL7Ot8wYfZ h2xi1Eewi9oCxTRdue9ozNb4wtyYOMjlxZIuoe17BbRMNE6EHgmQ4W3d3k65D8usnJny YQJtTPKL3GBpIy3vt5XtV/0nihs3LMWlPXwA/NsJ9knmRnMnAcJYfZoxpcisAMgt9bHj AgSkLDqJ3lJ3yNLuEpYFx4qLQHnNd8g+3+NUa3rElEZj8vwUoC1/1+jioZKNeC7RS+91 bMw9W1pXcs9t80ld3sJ40/xUHBbLTkWrXxbK4XDp/6tLRHcmO5a8aIC9woIuDIz1UkJ5 uFSQ== ARC-Message-Signature: i=1; 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=DN4WFGBj8flyOPox5eAEKxJIs3t9FOp9hVxQ7I/RLc4=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=uSixaM8Ut85sopprj7kQtz9nBJaEIRYcG1e/YpZxp2wkuD4ni6nVh7DqzYBRIwKnpK 5tvYZH14wvKIQa/1VD2sDiQWtY71wAfAW71MqtdUZdGTMKLfeBvkC+CFgTRvA+BVrs+Q LOIcukNK4JWHw0Y/rsyKRddK3J8OYXXmau+Unwy0+niLCZ7stvq0YPfTreJNCvz0DY1h Gavcuo3Oqf7SPXfX3mohkOaoqe6mwpWkVL/EfcHFJl/f2eiZcdwx/VH8eK5mZmSh7b/r FWjCt0IYGP8D4JIDA9+YOynFvEfOCUxGYMsFv+XhGPQWO70nANLhyKT2RxVp9O2qUTk5 1/MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZEn83f7G; spf=pass (google.com: domain of linux-kernel+bounces-10132-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10132-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 35-20020a631063000000b005cdab767081si3973574pgq.352.2023.12.22.15.53.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 15:53:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10132-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZEn83f7G; spf=pass (google.com: domain of linux-kernel+bounces-10132-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10132-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 0F1692858FB for ; Fri, 22 Dec 2023 23:53:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8949535F15; Fri, 22 Dec 2023 23:52:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZEn83f7G" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (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 6B8D33A8EF for ; Fri, 22 Dec 2023 23:52:27 +0000 (UTC) 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=1703289148; x=1734825148; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UdMMN4IJNx6JOqv+X+Ro6Zem59We9MEOFQRlHnVxlYc=; b=ZEn83f7Gmp117zxkDgsZIZcz1178pC6eWBlFjE/LScQ5AjCW5jcSyQEM TJEX7S5nbZOj3e6GqUmP83KwEJXuKpcjUrpyI05AuayYSktsOwBTDfmO/ 1M3PtAwF0mGQ3JexYbNlYcAVI/nbgb195NXpfn10QvzX/XKXYrTHIoHFF Ygb9eSyPcNJ34H/soTN0dQ5ASHpZRICX2Mql8+dcrjQxSWKkzWnba3Tfw rWtaRA1xbSZpaXKjR26pxShEPls6rN/3xHeT2A2T3ZC/m3VX1m7QsHzxR JnIv0SE949D8FW2/hN68b+ROOmlhc0Z9cF3YXrFePFJo2sxpvVbb4HZsQ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10932"; a="3414336" X-IronPort-AV: E=Sophos;i="6.04,297,1695711600"; d="scan'208";a="3414336" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 15:52:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10932"; a="726961489" X-IronPort-AV: E=Sophos;i="6.04,297,1695711600"; d="scan'208";a="726961489" Received: from jeroenke-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.35.180]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 15:52:21 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 17EA210A48A; Sat, 23 Dec 2023 02:52:12 +0300 (+03) 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: [PATCHv5 06/16] x86/kexec: Keep CR4.MCE set during kexec for TDX guest Date: Sat, 23 Dec 2023 02:51:58 +0300 Message-ID: <20231222235209.32143-7-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231222235209.32143-1-kirill.shutemov@linux.intel.com> References: <20231222235209.32143-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 Content-Transfer-Encoding: 8bit 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 -- 2.41.0