Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2692231rwl; Mon, 27 Mar 2023 04:05:46 -0700 (PDT) X-Google-Smtp-Source: AKy350bFg/p0kpFfrg/7Qx1telYqYbj4Fktf2vV0Ld7J7LulLWrdaOgWr0I2XXvluMdNS/wP+259 X-Received: by 2002:a17:907:c304:b0:931:b34:4172 with SMTP id tl4-20020a170907c30400b009310b344172mr13128654ejc.3.1679915145806; Mon, 27 Mar 2023 04:05:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679915145; cv=none; d=google.com; s=arc-20160816; b=FKEwKd9BW2ph5zJbf5CaT+UVQZ44cX9+n4QWUnbl0M7wB28U6DLDSLjbpI8yVP6/eV qnaMOUZu7LOG5jd16/ok5UbnF/9DKEstsU3K/B5xM2ddRbJ+FC2d1fUKfT/ZgrgWUsEl anDWUIVqPc0DParUTrRygOxsRzU9LJvEyDlQn5IhYj/ei8nMx9iwHHBv7JzQ4xaVe7fo 0Z6uUmpc41A0pRiNTv7+LRJCeLtoSol31826jdr7MntMU0MrJaOWZT5E3uy18XkFaM7q C9aRRNjoE6f+c2O49xX1W6OYn4G0kaDg+gBOB7qCWIftLbcIYYIUWbgNiCV8qN8k0DVO lB0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature:dkim-signature; bh=PlZnDrcoAzOg901ZQvqNUg/0TK1Smj7F72AYZPUYd6w=; b=ov1UYaF/fTGCyzvhbD1jlOqbeuqkuvpNgDh2p845L80ycBRlaT7+lulqe6dzhkY+qw nuEckVjOX0xcUBh7z2mt58tR4sGNG/mjAzt1i4VF1H8bD0iysjAbUK7aRNq8sc9ryzaK Hzywwo1r25Uf4+VZ1/QMsK5uIVZaXSaZesZNfDvFMJOh2g6WHALd3oLl6cuMKGobMCZS FcWUwG7XF9JlGhGGPbbRTTvjm7GORkNWtmlOEdNMH9fb3evAj0iTM2G10O18KSVpZQJj 6dTsyZtLfdxmL2cwaUe0XFQ1EqdAJIgDlB1sOcytHFKpfCspwEnhJLzpU0VHpssbnd4q JMzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov.name header.s=fm3 header.b=XX8mibLJ; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=fkqiXJ9O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ty20-20020a170907c71400b009334c541c5bsi20861590ejc.102.2023.03.27.04.05.20; Mon, 27 Mar 2023 04:05:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@shutemov.name header.s=fm3 header.b=XX8mibLJ; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=fkqiXJ9O; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231986AbjC0Kz2 (ORCPT + 99 others); Mon, 27 Mar 2023 06:55:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230020AbjC0Kz1 (ORCPT ); Mon, 27 Mar 2023 06:55:27 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF2553C14 for ; Mon, 27 Mar 2023 03:55:24 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 5E6795C006D; Mon, 27 Mar 2023 06:55:22 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 27 Mar 2023 06:55:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov.name; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1679914522; x= 1680000922; bh=PlZnDrcoAzOg901ZQvqNUg/0TK1Smj7F72AYZPUYd6w=; b=X X8mibLJriKAFFyjK5XKJ0lFDhq7FN4vag8rwmWdAtJxzFz1olPVIDG6zq7v48Lwx uyi6O7y+HhiGeVbZgz0zbuIDIJgNr3TYLKJUI+roC+0042NABidpaRVaN+bf09wY NhM8WaiAHapcyYggFykqQXKJyjzbf64EDfJAp69w4bjkda0Z12A8DsXSViCnxjWG +hObCSzqVlESXpIZnVLKjB8U7sUG2QXt6AxPt2uhbT+/CxdfX81PWGL7NgtLshp2 j/mlAMWbyRTpReqgE19+akhSwn25/tmi7GPSA+CiuzmZc0ncqka24fkO3hoijpHS eZk/cyWk8bNhi01rOcJ9A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1679914522; x=1680000922; bh=PlZnDrcoAzOg9 01ZQvqNUg/0TK1Smj7F72AYZPUYd6w=; b=fkqiXJ9OpGW2dbYJKk+wLeuscsO3Q DGH8z1G8WOUGiSTGAiG6I0dkRa82tH25JQuXZogrwOtDC6vqA0hoOZn5SHOTMD/I i/J2Ub3FchOgJdSRCOlv2NpTnxXT2pB1TxltXwd6DECxAUR1qgktJ53LP8LLVOP0 8FlYG1ervcoeii8emWpIFGdjanXR81xyvZOq+zDr22Y0de5lp8iPupKsiTOkiiqO YygHmtJPHtVhCbaDa7APfxOxAzGIHEKe9EyFQGHt7R45CAofZMQVDYbz5BJiLdx8 wOw0pmPsB+akCKUhJXyIrtdthu2bi4CD1D9KFRMwIEKPaCRcl6h3LYXyQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehvddgfeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdttddttddtvdenucfhrhhomhepfdfmihhr ihhllhcutedrucfuhhhuthgvmhhovhdfuceokhhirhhilhhlsehshhhuthgvmhhovhdrnh grmhgvqeenucggtffrrghtthgvrhhnpefffeevkefhffeghfeifeffjeehjeffheeujeeh ieekveevhfejleevveejtdeuvdenucffohhmrghinhepieegrdhssgenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehkihhrihhllhesshhhuhht vghmohhvrdhnrghmvg X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 27 Mar 2023 06:55:21 -0400 (EDT) Received: by box.shutemov.name (Postfix, from userid 1000) id 97E21109BD6; Mon, 27 Mar 2023 13:55:18 +0300 (+03) Date: Mon, 27 Mar 2023 13:55:18 +0300 From: "Kirill A. Shutemov" To: Dave Hansen Cc: "Kirill A. Shutemov" , Dave Hansen , Borislav Petkov , Thomas Gleixner , Ingo Molnar , x86@kernel.org, Eric Biederman , kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Andrew Cooper Subject: Re: [PATCH] x86: Disable kexec for TDX guests Message-ID: <20230327105518.zuswpklvyvz72u6i@box.shutemov.name> References: <20230325160128.21857-1-kirill.shutemov@linux.intel.com> <20230325192524.wetlbycbcsxc4plk@box> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 26, 2023 at 10:01:23AM -0700, Dave Hansen wrote: > > I guess we can go this path if you are fine with taking CR4.MCE and shared > > memory reverting patches (they require some rework, but I can get them > > into shape quickly). After that we can forbid kexec on machines with MADT > > if nr_cpus > 1. > > This goes back to what I asked before: is anyone actually going to *use* > a single-processor system that wants to kexec()? If not, let's not > waste the time to introduce code that is just going to bitrot. Just > mark it broken and move on with life. > > I'm also a _bit_ curious what the implications of the CR4.MCE > preservation are. IIRC, systems are quite a bit less stable when > CR4.MCE==0. So, maybe there are some benefits to leaving it set during > kexec() for everyone. Hm. I thought the opposite: keeping MCE set brings more risks. Andrew had feedback on the patch: Async events, including NMIs, cannot be taken between this point and the target having set itself up into it's intended operating mode. During this period you get all kinds of fun with type confusion in the IDT/TSS and/or not having a safe stack to service the event. I tend to agree with him, but maybe I miss bigger picture. Based on that I adjusted the patch to only affect TDX guests: From edbef5f1e6c31929ae1249c58b29c38f86e676c0 Mon Sep 17 00:00:00 2001 From: "Kirill A. Shutemov" Date: Fri, 10 Feb 2023 12:53:11 +0300 Subject: [PATCH] x86/kexec: Keep CR4.MCE during kexec for TDX guest 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 environments. Signed-off-by: Kirill A. Shutemov --- arch/x86/kernel/relocate_kernel_64.S | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S index 4a73351f87f8..9e83a638a2b8 100644 --- a/arch/x86/kernel/relocate_kernel_64.S +++ b/arch/x86/kernel/relocate_kernel_64.S @@ -145,8 +145,11 @@ 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 + ALTERNATIVE "movl "$X86_CR4_PAE", %eax", \ + "movl "$(X86_CR4_PAE | X86_CR4_MCE)", %eax", X86_FEATURE_TDX_GUEST testq $X86_CR4_LA57, %r13 jz 1f orl $X86_CR4_LA57, %eax -- Kiryl Shutsemau / Kirill A. Shutemov