From nobody Thu Sep 19 00:59:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1721643550; cv=none; d=zohomail.com; s=zohoarc; b=hOcH+SJq2b6ChvLzeDDWUFCVP2beI74UDFEYt5T0py4ayaucVdFXgqmZN7HSLVu/vp2g1Jnfs9LkodqyUwngYzIOAxfwCXneMkD0CeMs3AFNHsnSptvUsUH3E/b3TB66o0GB5/JThvrG6mbLnvYKW0WjlR+KTLtaM5A6EvBh0Aw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1721643550; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3j2YYKC1Ck9c5srCq004lFLgpbvA/qrQWTg9Ql7DWDc=; b=GW0jBSEbfP6F2IHUykfqu5GX6+MHLwaX9bMCIGiiarMDlhGiDXzLhPbB484Bf7Jfo18XUYpXegZWpD50hVaA6Rtq9D2msmeprxam/GWnE0YRB+HJtU5r37kzoKGhDp9CdyYvYtK8rkpcgnXo1qlwSG+c13yRzqM3akzOoedTn8E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1721643550749115.85813388963368; Mon, 22 Jul 2024 03:19:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.761607.1171609 (Exim 4.92) (envelope-from ) id 1sVq86-0001ag-10; Mon, 22 Jul 2024 10:18:54 +0000 Received: by outflank-mailman (output) from mailman id 761607.1171609; Mon, 22 Jul 2024 10:18:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sVq85-0001aZ-SZ; Mon, 22 Jul 2024 10:18:53 +0000 Received: by outflank-mailman (input) for mailman id 761607; Mon, 22 Jul 2024 10:18:52 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sVq84-0001Ys-Jx for xen-devel@lists.xenproject.org; Mon, 22 Jul 2024 10:18:52 +0000 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [2a00:1450:4864:20::52d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id c9dbf107-4813-11ef-8776-851b0ebba9a2; Mon, 22 Jul 2024 12:18:50 +0200 (CEST) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-5a167b9df7eso3683921a12.3 for ; Mon, 22 Jul 2024 03:18:50 -0700 (PDT) Received: from andrewcoop.eng.citrite.net ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7a3c7e3f58sm407102766b.91.2024.07.22.03.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jul 2024 03:18:42 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: c9dbf107-4813-11ef-8776-851b0ebba9a2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1721643529; x=1722248329; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3j2YYKC1Ck9c5srCq004lFLgpbvA/qrQWTg9Ql7DWDc=; b=GKDmbwc6Bd0CuBlZimRy1HrIpGk/haKllvw7EXAP13D8B6yu2TBf7azhC/WxMeEmp5 lPipjfEKhxbJUE+V9wu5PpB0YPeh9zTiwIZK/6oEESZcBTJehSBEObTkDRefXc2UWbqS rO5J+BuCZ++ebsNzXU9Uzj4mHZpC3pPgATvfw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721643529; x=1722248329; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3j2YYKC1Ck9c5srCq004lFLgpbvA/qrQWTg9Ql7DWDc=; b=vtN9g6pybvLWuaMJK0d4pf3xikdMT+V4xwec75s0Z5e4LholWoWqMXjyO2zHk5MPEm MV0tEX/xqmxfv7DxKh3h+qho7zNtV3HKIhJofHQvy9ac2DQaZ8f4p0zkWYQ/GjI9tg2n ikU2UczItI71JQZQf7hIjtYBln4bw3WjBiRkdbjEYlpL/43Ls6mxQkYQu0q6gvs1H57t 8PUFnJEGl6/feESiwVws3HsDZ2Bgl3izwMZrsl8SpOWe5xVLNsSMWrZ+ldZfUZ83VMAe pDIWcZAcRs6z37e6qX+RZFVXwAj13IbfBT5dIKng2ShSl1bbTeub65F3cP/IRobTh2iV /2mg== X-Gm-Message-State: AOJu0YwSttl5OkAIJd2tnwXYeExKFTbfIiqjBymlZsIRDc39dFmvk9OE 9FYbW7a1u7R8AqGg+9Db0FSTmJRUV5T6FPrVV7JTJmaOXKSEeJyoyivx2VvCstqxxDymR9Frmph 5 X-Google-Smtp-Source: AGHT+IFn7ltR/9GzXqf7x3jcra6jNQrGQnLhLEu7CKDQT/pKgI9IFR603+hOujlOOJ5eaQcqNZggMg== X-Received: by 2002:a17:906:dc8f:b0:a6f:392d:51a9 with SMTP id a640c23a62f3a-a7a4bfe6b79mr464451166b.14.1721643523821; Mon, 22 Jul 2024 03:18:43 -0700 (PDT) From: Andrew Cooper To: Xen-devel Cc: Andrew Cooper , Gene Bright , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , "Daniel P . Smith" , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Alejandro Vallejo Subject: [PATCH 2/2] x86/efi: Unlock NX if necessary Date: Mon, 22 Jul 2024 11:18:38 +0100 Message-Id: <20240722101838.3946983-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240722101838.3946983-1-andrew.cooper3@citrix.com> References: <20240722101838.3946983-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1721643552865116600 EFI systems can run with NX disabled, as has been discovered on a Broadwell Supermicro X10SRM-TF system. Prior to commit fc3090a47b21 ("x86/boot: Clear XD_DISABLE from the early bo= ot path"), the logic to unlock NX was common to all boot paths, but that commit moved it out of the native-EFI booth path. Have the EFI path attempt to unlock NX, rather than just blindly refusing to boot when CONFIG_REQUIRE_NX is active. Fixes: fc3090a47b21 ("x86/boot: Clear XD_DISABLE from the early boot path") Link: https://xcp-ng.org/forum/post/80520 Reported-by: Gene Bright Signed-off-by: Andrew Cooper Acked-by: Andrew Cooper Acked-by: Marek Marczykowski-G=C3=B3recki Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Daniel P. Smith CC: Marek Marczykowski-G=C3=B3recki CC: Alejandro Vallejo CC: Gene Bright Note. Entirely speculative coding, based only on the forum report. --- xen/arch/x86/efi/efi-boot.h | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 4e4be7174751..158350aa14e4 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -736,13 +736,33 @@ static void __init efi_arch_handle_module(const struc= t file *file, efi_bs->FreePool(ptr); } =20 +static bool __init intel_unlock_nx(void) +{ + uint64_t val, disable; + + rdmsrl(MSR_IA32_MISC_ENABLE, val); + + disable =3D val & MSR_IA32_MISC_ENABLE_XD_DISABLE; + + if ( !disable ) + return false; + + wrmsrl(MSR_IA32_MISC_ENABLE, val & ~disable); + trampoline_misc_enable_off |=3D disable; + + return true; +} + static void __init efi_arch_cpu(void) { - uint32_t eax; + uint32_t eax, ebx, ecx, edx; uint32_t *caps =3D boot_cpu_data.x86_capability; =20 boot_tsc_stamp =3D rdtsc(); =20 + cpuid(0, &eax, &ebx, &ecx, &edx); + boot_cpu_data.x86_vendor =3D x86_cpuid_lookup_vendor(ebx, ecx, edx); + caps[FEATURESET_1c] =3D cpuid_ecx(1); =20 eax =3D cpuid_eax(0x80000000U); @@ -752,10 +772,17 @@ static void __init efi_arch_cpu(void) caps[FEATURESET_e1d] =3D cpuid_edx(0x80000001U); =20 /* - * This check purposefully doesn't use cpu_has_nx because + * These checks purposefully doesn't use cpu_has_nx because * cpu_has_nx bypasses the boot_cpu_data read if Xen was compiled - * with CONFIG_REQUIRE_NX + * with CONFIG_REQUIRE_NX. + * + * If NX isn't available, it might be hidden. Try to reactivate it. */ + if ( !boot_cpu_has(X86_FEATURE_NX) && + boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_INTEL && + intel_unlock_nx() ) + caps[FEATURESET_e1d] =3D cpuid_edx(0x80000001U); + if ( IS_ENABLED(CONFIG_REQUIRE_NX) && !boot_cpu_has(X86_FEATURE_NX) ) blexit(L"This build of Xen requires NX support"); --=20 2.39.2