Received: by 2002:ab2:6f44:0:b0:1fd:c486:4f03 with SMTP id l4csp42965lqq; Wed, 12 Jun 2024 16:06:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVUdqE4DyXxnlTkXZiuewpF6RELybLvSPt8BVQ34FoTu00hm8N2buiWsM8xIxEp6QwC/qTvHReGJv82SbmaetQt+K1VKfd8PexYK5RAdQ== X-Google-Smtp-Source: AGHT+IHEwhkGERxwlzkqCuILZglUVhyzxA/QBavRnnqhV1E2EyLdl/koPS9n+T1xEVmwLSToNHhG X-Received: by 2002:a05:620a:1aa9:b0:796:50d6:39b1 with SMTP id af79cd13be357-797f60beea8mr398951385a.60.1718233580788; Wed, 12 Jun 2024 16:06:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718233580; cv=pass; d=google.com; s=arc-20160816; b=0O1E9XNtpetwNjI1yqbe0tznx+k0XFPFNcOFbWQpmzBi4vPWUCTfB0VCdgoNuPF63q Q/z5vI9IInvelhDW7/je0YoOK4Vw6M805H+WmBGk7Se5LpcIvTOTrZr+QK+pk3DXxj4m +IVB2f1QyUF5nVR5XEUmYNd4WvhsQ60rB+FxB3mFqo8USRu9/tJpzC0cjOmB99qNDJY+ xXORY5dxltYgQTicvbYiqKDxr2NWgqc26CX9GlIgXC0qLE0L0DhGoTmiBQ5g4j298BDu GCIwVL1LZOT/SeYa7AoGN/cer2kPZsQxEHek/t9Q4TvseobE2O/bdd+DNC4MLbkrVjBP qYmw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=nBdu/p+rPedbbedDDyqmAgiBRsCiRDycnW5wqxTyACs=; fh=4y/7y4vtCBKhOJDtB27zF4KKnrJ4hqQEW3a2A+ivWEc=; b=b4QKxP1H3JhgHIY38Gc+bKPdXU0+iGiUJC972Yb0m3FOJzn5/ojpEG+frSJyIGlT3K 7gl23WxqKI3Igphpxz9veXRb4SHht0UMc74eOeHvkOgTjeOurrJAA+NtHpUgm8vZwg+8 rAhah6xNITk+YxV0A/7L9lopkObYmFyTgqf1RwRC0eVjjKDqG00L0zy0dDBqtozeskkc xF+NUWdmdKPECYh7E3B0LSzQxJ9+r1m0Os0VTk7R3kVootlHezTaX5fYw6Eokh9j6XrG B8p0Prir1Tub3aOsJEPibiJaIxZGSTxDz/tSsw/Eg1mx6ZziryfRyZk5s9pDH8inZlhZ 496w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@citrix.com header.s=google header.b=arGK1znU; arc=pass (i=1 spf=pass spfdomain=cloud.com dkim=pass dkdomain=citrix.com dmarc=pass fromdomain=citrix.com); spf=pass (google.com: domain of linux-kernel+bounces-212348-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212348-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=citrix.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 af79cd13be357-798abd106d3si9456785a.424.2024.06.12.16.06.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 16:06:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212348-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=@citrix.com header.s=google header.b=arGK1znU; arc=pass (i=1 spf=pass spfdomain=cloud.com dkim=pass dkdomain=citrix.com dmarc=pass fromdomain=citrix.com); spf=pass (google.com: domain of linux-kernel+bounces-212348-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212348-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=citrix.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 6BB0B1C213C2 for ; Wed, 12 Jun 2024 23:06:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 25A3112CD8B; Wed, 12 Jun 2024 23:06:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="arGK1znU" Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12990129E64 for ; Wed, 12 Jun 2024 23:06:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718233574; cv=none; b=iD7krHHs4tkNuiDANt1lUPPMjfMdIeIVPbKRg0Hcq1Zaj1zeWNBzrRoqQVAY558IF9cex61BJCC0BfN5Ajjylij64Wf7OrjQ/y+ybV/EoMcQ8p42sz0LFNxcl1Q02DP/cdmPS1JjQ6mFfQ/ygGr/gsSt/iYEIq68skISeH6fzzw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718233574; c=relaxed/simple; bh=JQbugJA8jcGelVyE2M9ReTkk0J62dOaLR16rY0Fg4OM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=u2rE59Ac+PngGopkhWU7n1DfeXIXg66+Cbp4rgba7Wf9qoNtuvcWBQ8yanTkVDuQUI6fjQJmcYJ4QG9xCx3SVfRshJGfOfdvdH1ypnqqh64UWt5kKQvwrLxp46sWLw/7/TzrIgBeFxs2nc43UhO7YTuavaPqc8+8ygBa43jfHSw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=citrix.com; spf=pass smtp.mailfrom=cloud.com; dkim=pass (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b=arGK1znU; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=citrix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cloud.com Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-42165f6645fso4434695e9.2 for ; Wed, 12 Jun 2024 16:06:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1718233569; x=1718838369; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=nBdu/p+rPedbbedDDyqmAgiBRsCiRDycnW5wqxTyACs=; b=arGK1znUQSC1tQKxmkgpkNYy5op5s+O5g9QDhzlsho+Nad+qRV6ZsE26Lv8ZY6Ft30 CmfCZxBEqTckzbCxbPe3neSctVfY/QQ69/i33nKJDVSSB2HyiRsQKuDryu3ZVEtVlY5s Gbd0oyvgPjVO6xoZOALi0bPgx9G5z0XzewQ34= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718233569; x=1718838369; h=content-transfer-encoding:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=nBdu/p+rPedbbedDDyqmAgiBRsCiRDycnW5wqxTyACs=; b=K/rVLAAU/VQqAAIP9Op2YLdIbAjmYUaNNqrJuyb3u1SuTDKLA+2d8CPyeJuoc3mUa+ pTVOU0Qbw+LGUZYDnZO8d19AbawP+FAKl7qlaVZWNlfDCmyFNhPWBMs270CDnDFvkm2W 7N8AQhIKDlcMMx699kZ8Blokx3Mo41GuEeRX0jJvibzlqOf6tMDQ7/KiemkpBJ10RJpV 83xxIhHk00uuNnKXOCiqhZ++wjzxAUfk23nWUGJZrIF8/ECsiNriHSB8w+4fDN97W2SE OSYiu7Hp5Aj53DGc2m1wAWCdLjHAm6Qdx4Hwf1d7jRAd+5n2nyMA+JoryWmbB0AXbvZB 9LIg== X-Forwarded-Encrypted: i=1; AJvYcCV/Wu81StWQmAflnsDqJ/rjygbiOH9R1/EtxxnnLL7e8P2WeGRfqXavm+rGWCJ6B8hCm31wygQby3Rq3rEKl5MnxbDsncEyrdm/sFRo X-Gm-Message-State: AOJu0YxdCgNyo+SBHWx23A2MM+AfG0JsWO79GpBLZ42dedEKvUR5Z7wt xmsFT6MyswBGKHm8vYQwYslzVe77OJng235L8Ewo5z1diOo+ogpdFlq0b2EORnA= X-Received: by 2002:a05:600c:45cc:b0:421:21d2:abf5 with SMTP id 5b1f17b1804b1-422865acc67mr27498415e9.31.1718233569336; Wed, 12 Jun 2024 16:06:09 -0700 (PDT) Received: from [192.168.1.10] (host-92-26-98-202.as13285.net. [92.26.98.202]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f641a64bsm2618385e9.46.2024.06.12.16.06.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Jun 2024 16:06:08 -0700 (PDT) Message-ID: Date: Thu, 13 Jun 2024 00:06:07 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCHv11 05/19] x86/relocate_kernel: Use named labels for less confusion To: "Kirill A. Shutemov" , "H. Peter Anvin" Cc: Borislav Petkov , Nikolay Borisov , Thomas Gleixner , Ingo Molnar , Dave Hansen , x86@kernel.org, "Rafael J. Wysocki" , Peter Zijlstra , Adrian Hunter , Kuppuswamy Sathyanarayanan , Elena Reshetova , Jun Nakajima , Rick Edgecombe , Tom Lendacky , "Kalra, Ashish" , Sean Christopherson , "Huang, Kai" , Ard Biesheuvel , Baoquan He , "K. Y. Srinivasan" , Haiyang Zhang , kexec@lists.infradead.org, linux-hyperv@vger.kernel.org, linux-acpi@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org References: <20240528095522.509667-1-kirill.shutemov@linux.intel.com> <20240528095522.509667-6-kirill.shutemov@linux.intel.com> <1e1d1aea-7346-4022-9f5f-402d171adfda@suse.com> <748d3b70-60b4-44e0-bd81-9117f1ab699d@zytor.com> <20240604091503.GQZl7bF14qTSAjqUhN@fat_crate.local> <5c8b3ee9-64c2-4ff3-9cca-ba2672b9635e@zytor.com> Content-Language: en-GB From: Andrew Cooper Autocrypt: addr=andrew.cooper3@citrix.com; keydata= xsFNBFLhNn8BEADVhE+Hb8i0GV6mihnnr/uiQQdPF8kUoFzCOPXkf7jQ5sLYeJa0cQi6Penp VtiFYznTairnVsN5J+ujSTIb+OlMSJUWV4opS7WVNnxHbFTPYZVQ3erv7NKc2iVizCRZ2Kxn srM1oPXWRic8BIAdYOKOloF2300SL/bIpeD+x7h3w9B/qez7nOin5NzkxgFoaUeIal12pXSR Q354FKFoy6Vh96gc4VRqte3jw8mPuJQpfws+Pb+swvSf/i1q1+1I4jsRQQh2m6OTADHIqg2E ofTYAEh7R5HfPx0EXoEDMdRjOeKn8+vvkAwhviWXTHlG3R1QkbE5M/oywnZ83udJmi+lxjJ5 YhQ5IzomvJ16H0Bq+TLyVLO/VRksp1VR9HxCzItLNCS8PdpYYz5TC204ViycobYU65WMpzWe LFAGn8jSS25XIpqv0Y9k87dLbctKKA14Ifw2kq5OIVu2FuX+3i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ePdFLfhKyRdSXuvY3AHJd4CP 4JzW0Bzq/WXY3XMOzUTYApGQpnUpdOmuQSfpV9MQO+/jo7r6yPbxT7CwRS5dcQPzUiuHLK9i nvjREdh84qycnx0/6dDroYhp0DFv4udxuAvt1h4wGwTPRQZerSm4xaYegEFusyhbZrI0U9tJ B8WrhBLXDiYlyJT6zOV2yZFuW47VrLsjYnHwn27hmxTC/7tvG3euCklmkn9Sl9IAKFu29RSo d5bD8kMSCYsTqtTfT6W4A3qHGvIDta3ptLYpIAOD2sY3GYq2nf3Bbzx81wZK14JdDDHUX2Rs 6+ahAA== In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/06/2024 10:22 am, Kirill A. Shutemov wrote: > On Tue, Jun 11, 2024 at 11:26:17AM -0700, H. Peter Anvin wrote: >> On 6/4/24 08:21, Kirill A. Shutemov wrote: >>> From b45fe48092abad2612c2bafbb199e4de80c99545 Mon Sep 17 00:00:00 2001 >>> From: "Kirill A. Shutemov" >>> Date: Fri, 10 Feb 2023 12:53:11 +0300 >>> Subject: [PATCHv11.1 06/19] x86/kexec: Keep CR4.MCE set during kexec for TDX guest >>> >>> TDX guests run with MCA enabled (CR4.MCE=1b) from the very start. If >>> that bit is cleared during CR4 register reprogramming during boot or >>> kexec flows, a #VE exception will be raised which the guest kernel >>> cannot handle it. >>> >>> Therefore, make sure the CR4.MCE setting is preserved over kexec too and >>> avoid raising any #VEs. >>> >>> The change doesn't affect non-TDX-guest environments. >>> >>> Signed-off-by: Kirill A. Shutemov >>> --- >>> arch/x86/kernel/relocate_kernel_64.S | 17 ++++++++++------- >>> 1 file changed, 10 insertions(+), 7 deletions(-) >>> >>> diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S >>> index 085eef5c3904..9c2cf70c5f54 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,14 +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, if it was enabled before. >>> + * Clearing MCE might not be allowed in TDX guests, depending on setup. >>> + * >>> + * Use R13 that contains the original CR4 value, read in relocate_kernel(). >>> + * PAE is always set in the original CR4. >>> */ >>> - movl $X86_CR4_PAE, %eax >>> - testq $X86_CR4_LA57, %r13 >>> - jz .Lno_la57 >>> - orl $X86_CR4_LA57, %eax >>> -.Lno_la57: >>> - >>> - movq %rax, %cr4 >>> + andl $(X86_CR4_PAE | X86_CR4_LA57), %r13d >>> + ALTERNATIVE "", __stringify(orl $X86_CR4_MCE, %r13d), X86_FEATURE_TDX_GUEST >>> + movq %r13, %cr4 >> If this is the case, I don't really see a reason to clear MCE per se as I'm >> guessing a machine check here will be fatal anyway? It just changes the >> method of death. > Andrew had a strong opinion on method of death here. > > https://lore.kernel.org/all/1144340e-dd95-ee3b-dabb-579f9a65b3c7@citrix.com Not sure if I intended it to come across that strongly, but given a choice, the !CR4.MCE death is cleaner because at least you're not interpreting garbage and trying to use it as a valid IDT. ~Andrew