Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1092639rdb; Fri, 20 Oct 2023 08:14:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDhCM6sEdl2rREeVF9/7yN1JylTTYhNsQ/x83Uj0astXJGTkFDZuivUyMCa4MX1TF+fIgB X-Received: by 2002:a05:6871:b24:b0:1ea:746d:1703 with SMTP id fq36-20020a0568710b2400b001ea746d1703mr2440618oab.7.1697814847960; Fri, 20 Oct 2023 08:14:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697814847; cv=none; d=google.com; s=arc-20160816; b=yXdl/uA9X0CcQihraYoDb3mHZ//37q4TzS/ZKhKTIBvgDe2g2MN+/xKQEAB1AvxgbX 3d+CwS1V9V4CkoawtfVFn9seD1WLIm63VK2Uj9rrxf32jQX5+5z3jvF/Ald7+uVr1Yvj 0P8D3wpIDaZxItCo/6qA9uPnNpvN2CrVQSPQUcKnLh93oece8Dh0JR77gJyPgYQ8qcv7 Ge7dO9uTZ5P2iczrcbxfU99APY2xuHScrWW2hbxTc1vIsormCltuQdvmG3GbdO/gUmlV jEIp2wdnI9XoL1xbPgCjePskyKnytAh4tr/qz1W5SMaPlxdDATUFyCrnBQL+cKQBW+hl Z8hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jif1ziLT7c511a0O426hkyoGuiqyqgCP8fPSYzvFlss=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=ffNcRWPYbpCHeWPjtozdXzrDzHJFziprWVFlo7Ouv/02c6ZP6n3D0C/t+KvLs0uv2W 76L7mFUNxGoYFWNaiDCJGAAFuUiiVmAWie1UD4lI6/XfmvAUU/L5gqNX7tlmDomau4L2 J78cBw9lGyeYymmLZzJaW9VMrCIjV7WPBf7Hr5qQbb0N2ER5NrzJmNS1fwjXAyu0PJsM ZzZfmPi2I3BqeQmdTyySg9u8uI6PXSag6B5EXO6oC1dkHExO581JehBTJQ6/kd1Ls7Hy NriE7IP8GINmtGAdzYXQBtK80fljsTX64vGW20gdtgNEH0bZ4KmzFfOOJSj2wLzrgvYY 4zEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VzmNRa0L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id ck22-20020a056a02091600b00573f885c4easi2071469pgb.753.2023.10.20.08.14.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 08:14:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=VzmNRa0L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id BB25A82D254F; Fri, 20 Oct 2023 08:14:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377708AbjJTPN6 (ORCPT + 99 others); Fri, 20 Oct 2023 11:13:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377728AbjJTPNj (ORCPT ); Fri, 20 Oct 2023 11:13:39 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF637D63 for ; Fri, 20 Oct 2023 08:13:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697814804; x=1729350804; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EufwntLcxHa17lX7vkyRAITUbajJMYhr8ams+J+dhGY=; b=VzmNRa0LR2Ki07ZSrSHGzAEPkUHG25J0v3Ro+3WP5ni/MFatYeuZ8Jb1 pI+xZxa2YrJybgDeYkWlpY6GPHWwE/uo2lb1+AFfmPcZRaKaI0HHfgYtf dY223lfKQJUUvfIFrEe8CnVCmMnry7L0/lc8Nl2tM8WSPECTLnenbtVh6 Llx5qDfJSyHbRCLwdfkzTdQtQ6K/5heMzvhA4LrMnCtUr9LngcYfQ8iGe yDSj/Czt1YLy+2QyjW2vck0c0BK9pAWjSzSyqA8wYlfPhjg5LheaeM+d2 637zrrqNVSCVAk/BZgB4VoISLU+zUcBpGYmqnjPskxpfjuvTlARdXeNB5 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10869"; a="366742888" X-IronPort-AV: E=Sophos;i="6.03,239,1694761200"; d="scan'208";a="366742888" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2023 08:13:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10869"; a="1004634219" X-IronPort-AV: E=Sophos;i="6.03,239,1694761200"; d="scan'208";a="1004634219" Received: from dgutows1-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.249.39.237]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2023 08:12:56 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 1C68810A297; Fri, 20 Oct 2023 18:12:45 +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: [PATCHv2 05/13] x86/kexec: Keep CR4.MCE set during kexec for TDX guest Date: Fri, 20 Oct 2023 18:12:34 +0300 Message-ID: <20231020151242.1814-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231020151242.1814-1-kirill.shutemov@linux.intel.com> References: <20231020151242.1814-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 20 Oct 2023 08:14:05 -0700 (PDT) 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..bea89814b48e 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -145,11 +145,16 @@ 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 "jmp 1f", "", X86_FEATURE_TDX_GUEST + orl $X86_CR4_MCE, %eax 1: movq %rax, %cr4 -- 2.41.0