From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 69E2E941934 for ; Wed, 6 Dec 2023 12:51:24 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=IXbF5QiHESOOC1AwW9/P9775bfIK37kNTYqXsUE2ipc=; c=relaxed/simple; d=groups.io; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Disposition; s=20140610; t=1701867083; v=1; b=hGpbwEAGFqQiipxYSL+YHf018bzkcp+hvvkiDvYiuN1V0WtrpMJq7YojVv+dYB9hF+Ik4ZuL FP6+pikRIwb3cTeK9e4mUBdQFpj0fq0359ubLRduRz0qZ12C9nOo4+/h7352ip8a/CsEzj+IERS nToFaDyTCK6lvNRS9yFfYmK0= X-Received: by 127.0.0.2 with SMTP id c3IyYY7687511xLFun1inl4J; Wed, 06 Dec 2023 04:51:23 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web11.30485.1701867082272766665 for ; Wed, 06 Dec 2023 04:51:22 -0800 X-Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-332-tUWlih1nPSmXuRBrJFMrJQ-1; Wed, 06 Dec 2023 07:51:17 -0500 X-MC-Unique: tUWlih1nPSmXuRBrJFMrJQ-1 X-Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F33E838130BB; Wed, 6 Dec 2023 12:51:16 +0000 (UTC) X-Received: from dobby.home.kraxel.org (unknown [10.39.194.62]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 90CA02166B35; Wed, 6 Dec 2023 12:51:16 +0000 (UTC) X-Received: by dobby.home.kraxel.org (Postfix, from userid 1000) id C80DB7A2C9; Wed, 6 Dec 2023 13:51:10 +0100 (CET) Date: Wed, 6 Dec 2023 13:51:10 +0100 From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Ard Biesheuvel , =?utf-8?B?TO+/vXN6bO+/vSDvv71yc2Vr?= , Oliver Steffen , Alexander Graf Subject: Re: [edk2-devel] [PATCH] ArmVirtPkg: Allow EFI memory attributes protocol to be disabled Message-ID: References: <20231204095215.1053032-1-ardb@google.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kraxel@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: f0anPclLpQcOOCirzFXmF1SNx7686176AA= Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=hGpbwEAG; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io > > We can disable the protocol via this method but how would you set it > > to =n by default? > > if (Status != EFI_SUCCESS) > // opt/org.tiabocode/MemAttrProtocol not present on the qemu cmdline > MemAttrProtocol = ThisBuildsDefault > } FYI: Below is what I'll add to the fedora builds. Rough plan: Keep this until we have a fixed shim.efi and release media with that (hopefully Fedora 40 next spring). At that point flip default to TRUE and keep it that way for a year or two. Then drop the patch. take care, Gerd ------------------------------- cut here ---------------------------- >From c174197c65d2346f519418ded2e645d57423be41 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Wed, 6 Dec 2023 13:00:53 +0100 Subject: [PATCH 1/1] ArmVirtPkg: add runtime option to enable/disable MemoryAttributesProtocol Based on a patch by Ard Biesheuvel Usage: qemu-system-aarch64 $args \ -fw_cfg name=opt/org.tianocore/MemAttrProtocol,string=y Default to 'n' (disabled) for now. Signed-off-by: Gerd Hoffmann --- .../PlatformBootManagerLib.inf | 2 + .../PlatformBootManagerLib/PlatformBm.c | 69 +++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf index 997eb1a4429f..facd81a5d036 100644 --- a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf @@ -46,6 +46,7 @@ [LibraryClasses] PcdLib PlatformBmPrintScLib QemuBootOrderLib + QemuFwCfgSimpleParserLib QemuLoadImageLib ReportStatusCodeLib TpmPlatformHierarchyLib @@ -73,5 +74,6 @@ [Guids] [Protocols] gEfiFirmwareVolume2ProtocolGuid gEfiGraphicsOutputProtocolGuid + gEfiMemoryAttributeProtocolGuid gEfiPciRootBridgeIoProtocolGuid gVirtioDeviceProtocolGuid diff --git a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c b/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c index 85c01351b09d..a50b9aec0f2c 100644 --- a/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c +++ b/ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBm.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -1111,6 +1112,49 @@ PlatformBootManagerBeforeConsole ( FilterAndProcess (&gEfiPciIoProtocolGuid, IsVirtioPciSerial, SetupVirtioSerial); } +/** + Uninstall the EFI memory attribute protocol if it exists. +**/ +STATIC +VOID +UninstallEfiMemoryAttributesProtocol ( + VOID + ) +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + UINTN Size; + VOID *MemoryAttributeProtocol; + + Size = sizeof (Handle); + Status = gBS->LocateHandle ( + ByProtocol, + &gEfiMemoryAttributeProtocolGuid, + NULL, + &Size, + &Handle + ); + + if (EFI_ERROR (Status)) { + ASSERT (Status == EFI_NOT_FOUND); + return; + } + + Status = gBS->HandleProtocol ( + Handle, + &gEfiMemoryAttributeProtocolGuid, + &MemoryAttributeProtocol + ); + ASSERT_EFI_ERROR (Status); + + Status = gBS->UninstallProtocolInterface ( + Handle, + &gEfiMemoryAttributeProtocolGuid, + MemoryAttributeProtocol + ); + ASSERT_EFI_ERROR (Status); +} + /** Do the platform specific action after the console is ready Possible things that can be done in PlatformBootManagerAfterConsole: @@ -1129,12 +1173,37 @@ PlatformBootManagerAfterConsole ( ) { RETURN_STATUS Status; + BOOLEAN MemAttrProtocol; // // Show the splash screen. // BootLogoEnableLogo (); + // + // Work around shim's terminally broken use of the EFI memory attributes + // protocol, by just uninstalling it when requested on the QEMU command line. + // + Status = QemuFwCfgParseBool ( + "opt/org.tianocore/MemAttrProtocol", + &MemAttrProtocol + ); + if (RETURN_ERROR (Status)) { + // default + MemAttrProtocol = FALSE; + } + + DEBUG (( + DEBUG_ERROR, + "%a: MemAttrProtocol = %a\n", + __func__, + MemAttrProtocol ? "yes" : "no" + )); + + if (!MemAttrProtocol) { + UninstallEfiMemoryAttributesProtocol (); + } + // // Process QEMU's -kernel command line option. The kernel booted this way // will receive ACPI tables: in PlatformBootManagerBeforeConsole(), we -- 2.43.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#112122): https://edk2.groups.io/g/devel/message/112122 Mute This Topic: https://groups.io/mt/102967690/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-