From patchwork Tue Feb 27 21:24:40 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: 207553 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3051143dyb; Tue, 27 Feb 2024 16:31:49 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV/0zT9hINmjI5EcIjcKJ73ycpXQi+v1kCxswCNEXn5sjfBM/N64qNqPwoRHDne2OwK8fTJcGJymvOlUglBjkAAjIUtZQ== X-Google-Smtp-Source: AGHT+IGnJnBQMl5m2GIHp7NT0+XTdUvEy9qf6pkDKC2PYUDWyN8IP6p9oOYipPnkk+YP36/wAzV2 X-Received: by 2002:a05:651c:1a0b:b0:2d2:9460:142d with SMTP id by11-20020a05651c1a0b00b002d29460142dmr3194818ljb.14.1709080309128; Tue, 27 Feb 2024 16:31:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709080309; cv=pass; d=google.com; s=arc-20160816; b=i3WCw2QZsWLkF5Aj7IhZS6nFpfSl5Wq0tb0m43o/SnpKIC5nQqzGcYGKyPaGrVyX/4 GSz0jwPAJrDrR5pbAbsF2FkJeqj/PIWSu7niKVpVd01JC72r49AAancn+UFcPYD6Ex8G NcXHuzlQWGVpj6BACtr92BNparbPFbZjBNweimTh5kqG1jqV/wGO07byY2qTIcraZS9u kWkB/784FhoPqk0LbQ54ZYl7HAZi18Tg1kE02AK6jSTq06Q08z+DWi5FYMe9c60LAAqH Alj8vEGLUgi+TGJOwc/mAxCFX37164hv57ag9q7Ax1JCeCly3670oDMvP7KJmdMV/EAO sTbg== 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=+2yLDzWdEmtXDBblHO+SFqFiqLHLcrHt29f82nLCxQ4=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=RVeytW5eeNLmWnuQIaKQXzr41Nmm8k4wJmIgCM0jgZJsbRjhzGao6V8Aeadmy9Zge7 ETCzJVWy0C9NXV+uibG2y9V2bCNMttygPJAguAbzN6ngXl4C3xl+Ol9QzPVdupY/ObaB 60vP+h/2mlNcGxoR4aVqGmBo1pW7L8fYs7TKmzNM4imrxHQ/sq6CaW0TjHxwv16l3gQX J9pW3bZaj96KcIAhS0N2eFJy5c/8CpLJ5k8fHSqrLmRLlSsSatQi6DQwrMubaom9irkb gdqvTN7Br54iMppw6mrO5OQpUjBiI/AhAsmIaENS33HKFEaYZDvZIjtzUrWGayufGqjT 7gJA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AObOYmFc; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84037-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84037-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id s3-20020a056402520300b005664532906fsi817181edd.271.2024.02.27.16.31.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 16:31:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84037-ouuuleilei=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=AObOYmFc; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-84037-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84037-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 am.mirrors.kernel.org (Postfix) with ESMTPS id B09C71F2C956 for ; Tue, 27 Feb 2024 21:26:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D36B41586F5; Tue, 27 Feb 2024 21:25:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AObOYmFc" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) (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 AA4CC154448 for ; Tue, 27 Feb 2024 21:25:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069111; cv=none; b=QpszwVNiZquGMOIXcaJGmyFqXF7PTctFqgNIRI+gEecdG1ss+damF27x9WfCukMRlxc8X06iH3QIONfniLCH2RtTyvOsRjTtHaPlZ08RER47j7QRRASr0TGZa+4krQ+aupCYjfIacBgEkf6XWrHxa/DowIZPNj09sK5AugZSRQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709069111; c=relaxed/simple; bh=7jFuowaz0Vw+N4idIIhc+R9JJKXqB88Qml6sO/pIcmM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b9KAZAUxxmsUjBik2CkDO/2Anw8aPs81OQaO8rja2LKH/T2ZVj52rHWq8JGZ2ftj0h5GPyFHEW8eFCW6L1gaBgK1bX5rqltuBOmkU1/aM3+U413kkTv6r+PBh4WagcxZkjDqXq+RcwYcgrWCn796jLH7tft9xk63hIq2YVyp/ac= 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=AObOYmFc; arc=none smtp.client-ip=198.175.65.16 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=1709069110; x=1740605110; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7jFuowaz0Vw+N4idIIhc+R9JJKXqB88Qml6sO/pIcmM=; b=AObOYmFcs9hV2WrODGvUKGY6Fc02Vb+Dis7jv415V/3Mnw/bd6zckV1X Y3rEkUzWZ1Tqp+6WCOsAq14U5POLZMKeT4nOZ45Gw3N1nNvJIPJ5BHozL ++Ai9s91ZPPAIN5gGPoo5q8w6sUDN2ZahhAp7Q0mQjxAZH4n1MxZ/rLpE EIntPuUZTfifaEYzj4I1Dy9JDvn06jg9Ztz648CdYncRa6NidEwPcl0rp SOYt7VO8/10zoE2ivsCeSbqxKaZBP9CMGaPRoGPZfE+kfPQGKgRBTyUeC Or0OLAGETakqzKa3p8Nu6wOwZu1JcTtZT1MSIgkrksKOAeD1hO/5xkfhs w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="3566990" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="3566990" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 13:25:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="937032906" X-IronPort-AV: E=Sophos;i="6.06,188,1705392000"; d="scan'208";a="937032906" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 27 Feb 2024 13:25:02 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 1E0E85F5; Tue, 27 Feb 2024 23:24:56 +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/17] x86/kexec: Keep CR4.MCE set during kexec for TDX guest Date: Tue, 27 Feb 2024 23:24:40 +0200 Message-ID: <20240227212452.3228893-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227212452.3228893-1-kirill.shutemov@linux.intel.com> References: <20240227212452.3228893-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: 1792100594315670245 X-GMAIL-MSGID: 1792100594315670245 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 Reviewed-by: Thomas Gleixner --- 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