Message ID | 20231205004510.27164-7-kirill.shutemov@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3133840vqy; Mon, 4 Dec 2023 16:46:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/GWBjiba0D74Kj1PnQYgC65MoHfNNKhjYdMaQU2zeGm6Hwg4xeWi8KYeFqQ/3ldKd6GLX X-Received: by 2002:a05:6358:a5e:b0:170:17eb:377c with SMTP id 30-20020a0563580a5e00b0017017eb377cmr4165510rwb.36.1701737188296; Mon, 04 Dec 2023 16:46:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701737188; cv=none; d=google.com; s=arc-20160816; b=NQ8zbinSzo1t/je15rY8vQVKLJ2JHKOT9OJH0AifNWD0ibB+lnbLFi62fUNB1IDQuo s1xEMsGx8AoG7WevvgK5ak3IXVT8AlUaoJZE0qJ05yG5RzuMVBm48lfF1ACK7+zXCxNz CX0JcIEe8lB2dM7zw39NWfPzlDBjHNmezONfc0I19YroC7dzyhHnCpqbuHCDE9lDzhtp ZTxQssh4LJTIwBKrQBzpwdxrVJXkFxCHl6mZQ/DRhwF99ASS8xBzVqEqZlxdfcjl5CIh E7+KChFZH/3645SBEesjk2RWYSgtdifYhGJHLNKJZa4X/FW+GViJVhCdwYFX0vB88o76 qL2A== 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=kzdVNUOIUQb5nbNceDWwNKCkDI+wYcQTHHY/dNwObBM=; fh=OvJRnOqsMTm9XoNmEwebcqh9Ud7yh1CTeKAP84ols98=; b=s7zypAu+cRDjQTVbfXzxeLKS8llmZZNirczZytxxIHTzqHUmhZm0oF1G3xoAhsxZPV mspAU1c9h2Z19NXxfVzCvMUfJ0fVvxAX5xIiLEHgbLli+FY3usLVUmjdo6iF1+9UXyNP Awi3f8X7og0yMqiYRUGJH65uC90Xm3whu/6NeGCeOFWev/CaBAJJLs4lMBIxIN8rV3ic H2rPgAtDHY0vGCNOyTL2jtWb7OjJ9pLBoDxNLYYeHVp6Ioxra47uDCryyQp/aXekzfDe RplTsMwLvzMIChWgOn1V8mX40QyYMMGK86QXpi18LBL2jl+PM8zNzKVBUYHtsCULM1YY h32Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Qb2rTBYq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id f10-20020a056a0022ca00b006cddd78a8f1si8768905pfj.27.2023.12.04.16.46.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 16:46:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Qb2rTBYq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id ECCE48050006; Mon, 4 Dec 2023 16:46:18 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234895AbjLEAqC (ORCPT <rfc822;chrisfriedt@gmail.com> + 99 others); Mon, 4 Dec 2023 19:46:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343632AbjLEAp2 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 4 Dec 2023 19:45:28 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD0D2A4 for <linux-kernel@vger.kernel.org>; Mon, 4 Dec 2023 16:45:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701737134; x=1733273134; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wYs3fU4C0jZd+PnKZxc0e8e/KDE7b/5Kd3uwb7sJ62o=; b=Qb2rTBYqT1YCgBPpUKZffe+VXslh7ruFlAP0N7wHYiza4djqc0gwNBa7 5rJV836ZOyxlgYWcqULyqj+61zpDSKDk4E8K2xWEHP1OyOZTH83Luu+iu g5V2vJRDPyS7w3jqkCBmjVPwlI4Zp/xwyohmzWAfpZ+meYfqP6piTJrKc 7LKMt+3wZJGpqNvAOY/58/qshBeVEuLwCl+6UwhICz6zFN2cy/a/IKAvx pYHaQoDcy3grocjYsfFN+J0DKVSxAvgdfNiA0t84rQm9u2A+DRHsi4Udu v39zl6ZQ+Oq3Kskx+jaPI56/g3dCFp/nSOlTLnwxZ1v6MLe+AADFtvBiW Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="392688656" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="392688656" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 16:45:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="888704402" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="888704402" Received: from abijaz-mobl2.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.61.240]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 16:45:29 -0800 Received: by box.shutemov.name (Postfix, from userid 1000) id 67CE110A446; Tue, 5 Dec 2023 03:45:20 +0300 (+03) From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> To: Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>, Dave Hansen <dave.hansen@linux.intel.com>, x86@kernel.org Cc: "Rafael J. Wysocki" <rafael@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Adrian Hunter <adrian.hunter@intel.com>, Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>, Elena Reshetova <elena.reshetova@intel.com>, Jun Nakajima <jun.nakajima@intel.com>, Rick Edgecombe <rick.p.edgecombe@intel.com>, Tom Lendacky <thomas.lendacky@amd.com>, "Kalra, Ashish" <ashish.kalra@amd.com>, Sean Christopherson <seanjc@google.com>, "Huang, Kai" <kai.huang@intel.com>, Baoquan He <bhe@redhat.com>, kexec@lists.infradead.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> Subject: [PATCHv4 06/14] x86/kexec: Keep CR4.MCE set during kexec for TDX guest Date: Tue, 5 Dec 2023 03:45:02 +0300 Message-ID: <20231205004510.27164-7-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231205004510.27164-1-kirill.shutemov@linux.intel.com> References: <20231205004510.27164-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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 04 Dec 2023 16:46:19 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784400773945703994 X-GMAIL-MSGID: 1784400773945703994 |
Series |
x86/tdx: Add kexec support
|
|
Commit Message
Kirill A. Shutemov
Dec. 5, 2023, 12:45 a.m. UTC
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 <kirill.shutemov@linux.intel.com> Reviewed-by: Kai Huang <kai.huang@intel.com> --- arch/x86/kernel/relocate_kernel_64.S | 3 +++ 1 file changed, 3 insertions(+)
Comments
On Tue, 2023-12-05 at 03:45 +0300, Kirill A. Shutemov wrote: > 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 <kirill.shutemov@linux.intel.com> > Reviewed-by: Kai Huang <kai.huang@intel.com> > --- > arch/x86/kernel/relocate_kernel_64.S | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S > index 56cab1bb25f5..cd6a53667c6b 100644 > --- a/arch/x86/kernel/relocate_kernel_64.S > +++ b/arch/x86/kernel/relocate_kernel_64.S > @@ -145,12 +145,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 Nit: It seems <asm/alternative.h> isn't included in relocate_kernel_64.S. Maybe it's better to do it explicitly. Maybe even better to explicitly include <linux/stringify.h> too, but I see <asm/alternative.h> already does that.
On Tue, Dec 05, 2023 at 11:58:45PM +0000, Huang, Kai wrote: > On Tue, 2023-12-05 at 03:45 +0300, Kirill A. Shutemov wrote: > > 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 <kirill.shutemov@linux.intel.com> > > Reviewed-by: Kai Huang <kai.huang@intel.com> > > --- > > arch/x86/kernel/relocate_kernel_64.S | 3 +++ > > 1 file changed, 3 insertions(+) > > > > diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S > > index 56cab1bb25f5..cd6a53667c6b 100644 > > --- a/arch/x86/kernel/relocate_kernel_64.S > > +++ b/arch/x86/kernel/relocate_kernel_64.S > > @@ -145,12 +145,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 > > Nit: > > It seems <asm/alternative.h> isn't included in relocate_kernel_64.S. Maybe it's > better to do it explicitly. > > Maybe even better to explicitly include <linux/stringify.h> too, but I see > <asm/alternative.h> already does that. Okay, I will add both.
diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S index 56cab1bb25f5..cd6a53667c6b 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -145,12 +145,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