Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1911802lqe; Tue, 9 Apr 2024 04:31:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXmDpSf4iVgWx1s/Z+Q4ohVEiNp27fy+eXF7xJhlfLxi0npc3xwwTEXqLQaE/jlMealSrpoJxJMDIOHPKMD24qLqYtkxX1JDdJbkaVyFw== X-Google-Smtp-Source: AGHT+IF33ZmawjDiryjmhnkHhJ1f3KXt0NdKs3zxaqK0wu5G9yoAYy46nUJFG1fA8ZbTb42EFnYq X-Received: by 2002:a25:69d2:0:b0:dcf:3580:8bc3 with SMTP id e201-20020a2569d2000000b00dcf35808bc3mr9761958ybc.23.1712662273630; Tue, 09 Apr 2024 04:31:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712662273; cv=pass; d=google.com; s=arc-20160816; b=DGaT6oNrH5CiRDXVWThwVd3GTdN+OR7HsxNpm5kV3eRcr69Nh4OYf5vaTHx4aaS5Tc XxbjKJoyN+jVHWGnKptlp7TlG55I7kQXD43IakkMypRIHKIMT+lr8LKVqeswjpOofbha KrIW9XvzMbT3aNGAL+wVhuMjzwNyFW/CU5dc7wU+SyJcaeqjR1hUOH//s525W1FYeKC2 3Dk/eLDqVvFmtelRULsPBdXTdrQyRocv1wFPSh5sAzkgpatpmkVUPYyLwSkK6DM2qen7 m1IcZRSYqOe070w7+uyXlCVowd760AVBdZ0L0fJyoYTY8cOrvFrQXQSCC0b0VShD6wZS ijdA== 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=yDpEp1dkoUdV7tg89VNCC5vZMyinWi1CelICvkbUubI=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=hn+P2b6PyD7ieDBvFNk2lgTQPg+dU5Cdim8j9dwRkqWM+FSvLO87YMimgd1OyQesrA +S1VlOUZQ8Y/8+cNThPf5n0kyWu4tj3AEgOOVTO5mhnpi556O21FavIF+r3Ri7bf85LX ZyK/pFNVinY0wEBC7CNG64gCQ8SbNqY+n+80RSCa8Ct0lbiLQpoW2DQelIl6iEUDfD5Y A2kkbMZp/RENHWzP7RiFsoP8NwR0K/S5fxMU2h7FCS9Vm+754myXU9MFMW2tkwvOZoDo HKOAx8qH6pysikyeAw0o5GAMCH3HmyBI904AhYfFBUbqdxVBWHhKlTUFmQGoDA4Nog8H 016w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ae1dSzXS; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-136752-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136752-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c13-20020a0cf2cd000000b006968dedd3a3si10107448qvm.333.2024.04.09.04.31.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 04:31:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136752-linux.lists.archive=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=ae1dSzXS; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-136752-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136752-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 259CE1C2394D for ; Tue, 9 Apr 2024 11:31:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 29F6012D74E; Tue, 9 Apr 2024 11:30:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ae1dSzXS" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 96DDA129E80 for ; Tue, 9 Apr 2024 11:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712662230; cv=none; b=FUUvb2zzX3enpVUcf4muYIdXjmgNoZDqn+qTZaRHV1K0JTDUepX/MKf3EAEmmdo4GC0wWVplPQwi+s5ZHeSiinnh/7Uc8eGQ3fdowMukStq8tO0OJsIH+tZrRZwCIgptrBE90WcFnpj2qRfb0Dziguf4lYwwRrfwTPShZ4RgBuE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712662230; c=relaxed/simple; bh=jhoSJK9vAOf7tdZhp/qhOuJmkQkVmgSEyhKVV1fOBC8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DiHU/oCDriAlMirMUZoRMO+53qSMRtr498DxIPM9CXACSyUZIkEr1j9AOysH+9Ls6bZ95CS19heXbiNnltNbyZPOsl0p5m5DnRLl0FJRMSBhDyU1ytwA/PO5LuzlWtjYXtBo13C3/6l76JMQiUIdTcXE4SJTKrXA4dAH+QIsZFI= 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=ae1dSzXS; arc=none smtp.client-ip=198.175.65.9 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=1712662229; x=1744198229; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jhoSJK9vAOf7tdZhp/qhOuJmkQkVmgSEyhKVV1fOBC8=; b=ae1dSzXS8PI4Jp2RcZPBh9UIV2MDySjgM/HlBW6D+q6CKSRBgPp8kmaf KHTy5wS8BQc8qFMhNWKBY4Fxsuo6EMM6Tgk9VoZg4UW04S5AA+nrwVF30 QL/1gjI0L4qL+Ie6yZqBfBopXX1EFzmG9TZTEiIMrrQx2DqSYB0z2+/Ci DiXS5ifM8yaNHSun8eZQttgMANuQ57r+snbNu//oK21BeW8xzy3ShdvJC liEyHkO7SSA4HW24cAtjyzG9H4KY2xxkeg65SBd4QX/q72Fou4Qnhv+Px jHZdzPfW2Omj/0tugqWCS6M1XXznl49Dl+VEhxuuNGOI2OMvfGlsfNzVv g==; X-CSE-ConnectionGUID: htZmv5kFSGK73oCF7CX9Jg== X-CSE-MsgGUID: cC71c1hFSM2JoQK/5iaTnQ== X-IronPort-AV: E=McAfee;i="6600,9927,11038"; a="30460357" X-IronPort-AV: E=Sophos;i="6.07,189,1708416000"; d="scan'208";a="30460357" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Apr 2024 04:30:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11038"; a="937093327" X-IronPort-AV: E=Sophos;i="6.07,189,1708416000"; d="scan'208";a="937093327" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 09 Apr 2024 04:30:23 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id A9B078D1; Tue, 9 Apr 2024 14:30:17 +0300 (EEST) 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: [PATCHv10 05/18] x86/kexec: Keep CR4.MCE set during kexec for TDX guest Date: Tue, 9 Apr 2024 14:29:57 +0300 Message-ID: <20240409113010.465412-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240409113010.465412-1-kirill.shutemov@linux.intel.com> References: <20240409113010.465412-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 Depending on setup, TDX guests might be 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 --- arch/x86/kernel/relocate_kernel_64.S | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S index 56cab1bb25f5..8e2037d78a1f 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,11 +147,17 @@ 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, if it was enabled before. + * Clearing MCE might not allowed in TDX guests, depending on setup. */ movl $X86_CR4_PAE, %eax testq $X86_CR4_LA57, %r13 jz 1f orl $X86_CR4_LA57, %eax +1: + testq $X86_CR4_MCE, %r13 + jz 1f + ALTERNATIVE "", __stringify(orl $X86_CR4_MCE, %eax), X86_FEATURE_TDX_GUEST 1: movq %rax, %cr4 -- 2.43.0