From patchwork Mon Feb 12 10:44:37 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: 199863 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2472029dyd; Mon, 12 Feb 2024 06:46:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXRM5O0ZCbGeABofBdPPC8jjJVwwlAeWTcKMLhVaqoTaeeTXKiurZ067YQB/uByRPe3olQIisTp6iFRAUyNDg+Rx5HBpQ== X-Google-Smtp-Source: AGHT+IGzc0IpMRHGt/KHNzLgRTZvN7wmd+kMBjL6FmY41lX/0W26grUAKwCINWoQbioKotrFNUBD X-Received: by 2002:a17:906:552:b0:a38:a174:1316 with SMTP id k18-20020a170906055200b00a38a1741316mr5660433eja.72.1707749196326; Mon, 12 Feb 2024 06:46:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707749196; cv=pass; d=google.com; s=arc-20160816; b=EUQSP+EQIu3vZ7VOL1wqlAlPV+x0ti6D+a5dIUVYNjoTZvFIcs/Q1hZNO9KGLBvJ/I DVFv9Wmb+zM4MPfT7J+y8BKkqd/2x5plTFvOYf4OwMNA5wu73hbFxtReh76uhTaiXm8I KlV3CoZQZyAvdm/5NX8b7B/E3Xw+j0M+bbdlIIQhLN6+IiL3mohDLOI7+5hgHWHHp1uD 3rB8I1doZ0Ml6KIc4DUHM+x1g6TDuQCrrQdOXQHbtStXA+tcC17AvQUMc0/5aOCVK3Xe SXhkKVH22Z0JBSEyMy4276K0XWL8bmt+EgDMlLryB85rGDcPOOe+O+kJNyUiJHulJvHO 96OQ== 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=D22QgflDCgBEPzKen67LG7jh59WhmG7jg7eBrnA8enY=; b=Wx1M0wkGATH828X1+U7+vpQG/w/CRXtr74MAJQMqWgbe8Fe7Oa7j9gb7rrNAFw7wXl 4xwYjHjvGofsafCj3PhC/aDoS0s70Yx+N13hBcHgJku+4zAEQKA7Qbc+LhQaK0z/x3f1 8R4EoYXT5DAt2nutD+yjKZCdyF8aBmzzCYf4g9JzpcZHLXc3KRyVLkpTVKCpc0n+haE/ pC41ECZrYQSYpN2JPJwsezUZHmMD1jf4+WGnHfDlQinbUzGPn+oVmU9YSl1OmcpahLcL FSqdXwnGaAfqr0wescU3ntXEnlUqnSCwVS7bucRXPtsZsg4rTKlx2eSmP9lYdi14Vwjx C1dw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Tylije1X; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61355-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61355-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCWWpRcKwDdymRG2GEOnQRkZ92hl3ZYvboE2OhqcbIWqpHw2js/4mSXuXxRIYLoRd/74WHkuTmSwRuStrukuEBwCfZxpgg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g2-20020a170906c18200b00a384f16e032si250257ejz.721.2024.02.12.06.46.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 06:46:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61355-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Tylije1X; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-61355-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61355-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 29A391F25819 for ; Mon, 12 Feb 2024 10:48:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 971803C063; Mon, 12 Feb 2024 10:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Tylije1X" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 418D03A8D0 for ; Mon, 12 Feb 2024 10:45:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734708; cv=none; b=YSZi1rH2xB9tw01CQu8Od2mJy4zrTI4Rj1kP+e+Y7D3MsznlO7pCIW+en6VjSv9iWsqkGwDocSDWs6rc5QZEF1IQgDDQNXGFv8owTIc41BIutmswbtV6D9TyGuBLQdhO0yUB4fH4LAaOt+NLVMHFh1fA7n/2Da3/GHF1ni5x+sw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707734708; c=relaxed/simple; bh=LcZSO2fCT5WaMkS6shCgOhCUo14EJT04WN8x+U0u+KI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZMOpwxd4BjbYZNq7ug6ElUwuewDh660RJP3dZxylFQFR032MvGskC0XSvkcMfGio/2KlEFVVEhonDLjsUnYFJW6OpTUKbmUbgJ8ZxI9hVS6QxhlbUUlAqXJJ9WWuPLR20SJ1fJXt/AYXxSDnbcs4pWmv71CX2UxEl4k5NSZiX+M= 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=Tylije1X; arc=none smtp.client-ip=192.198.163.17 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=1707734705; x=1739270705; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LcZSO2fCT5WaMkS6shCgOhCUo14EJT04WN8x+U0u+KI=; b=Tylije1XYbeDB2PsUKT2HT5vnHXUbWdGgPOLE367e5DegQFUY0tRDbqn PadWDmmQmoAgy5r2m7jfevRpJVwRZVleCtfBt4zs3CKPSF7JO/gSlkqqZ jR3gdhKXbDuZ6sXUCcJoMC6z5x10nuCtzbxHAnMjJW0vLO/YpZE+ClX9c X7lMSR0qwAoMCM12iVAX2yCbJLJOwwHN0mF6XgBddw13GpsKrtfHyLXO1 fT5iyyznsvBpBJObBE1FBeV7BULBcnQbiWCu0KZlbNFQLGH0NmEXIh2Pq TyjPGniXekkq+CHH7mpSZfTtK6JWPorr09RHKZ21K9mAtHobth5vy7U4x w==; X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="1585057" X-IronPort-AV: E=Sophos;i="6.05,263,1701158400"; d="scan'208";a="1585057" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 02:45:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10981"; a="935035599" X-IronPort-AV: E=Sophos;i="6.05,262,1701158400"; d="scan'208";a="935035599" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 12 Feb 2024 02:45:00 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id 2AEBC535; Mon, 12 Feb 2024 12:44:53 +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: [PATCHv7 05/16] x86/kexec: Keep CR4.MCE set during kexec for TDX guest Date: Mon, 12 Feb 2024 12:44:37 +0200 Message-ID: <20240212104448.2589568-6-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212104448.2589568-1-kirill.shutemov@linux.intel.com> References: <20240212104448.2589568-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: 1790704821521035810 X-GMAIL-MSGID: 1790704821521035810 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