From nobody Sun May 19 10:01:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+98506+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+98506+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1673645461; cv=none; d=zohomail.com; s=zohoarc; b=CtbXR1TdT5eiiF6FM8jQHGbW9WOBeez8mx1rp/74hj8nPAZFlDiTXUplEwBive505+eOzADjU16If/1c0Ta/9+1cJRI+9DiEOnaMHFBLJZYJz3Q2Idn+1scUkjw+XfQi3l/Mo2Rnt2jmGNM78tCXYrq3/mqx2OI9tY+00ia1ckQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673645461; h=Content-Type:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=vk2SyehEV5hVVqs6Bh9xJDxw+6MQOucoSQ/n9lwDpi0=; b=MaYPPkFPOg0CqXCwFrGhYlCvx03RCwEsASVDhWJomCsKiJEkkhvWfk23UoPJF0/BfAnLv+R0jQn08BttDMokKtvOoMh4Ct4q7ZCud1e89ZgwTwluYpqJl8d1YJWCZ0StR5gmXV3LJYgpVm1NOCySX+eej8YdyzPaZDXhcOIDyjA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+98506+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1673645461256230.7900710499838; Fri, 13 Jan 2023 13:31:01 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id sqdvYY1788612xAQBTYVpG4F; Fri, 13 Jan 2023 13:31:00 -0800 X-Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) by mx.groups.io with SMTP id smtpd.web10.101587.1673645459736455499 for ; Fri, 13 Jan 2023 13:30:59 -0800 X-Received: by mail-pf1-f201.google.com with SMTP id ay33-20020a056a00302100b00586ad46edf9so9296871pfb.20 for ; Fri, 13 Jan 2023 13:30:59 -0800 (PST) X-Gm-Message-State: 8W8EW9AcEAwv7P7Fu6ibP8U1x1787277AA= X-Google-Smtp-Source: AMrXdXs19Hm7YNsIlOoPtjAfoKNdOI6m9CNlFDVidToplU+VfsIec2tRsOeip86nZJFq2LUjUmGdzLv1DyEmSZeWjA== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a17:90b:4ac5:b0:229:36cd:4ab8 with SMTP id mh5-20020a17090b4ac500b0022936cd4ab8mr227511pjb.114.1673645459173; Fri, 13 Jan 2023 13:30:59 -0800 (PST) Date: Fri, 13 Jan 2023 21:29:26 +0000 Mime-Version: 1.0 Message-ID: <20230113212926.2904735-1-dionnaglaze@google.com> Subject: [edk2-devel] [PATCH v2] x86/efi: Safely enable unaccepted memory in UEFI From: "Dionna Glaze via groups.io" To: linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, x86@kernel.org Cc: jiewen.yao@intel.com, devel@edk2.groups.io, Dionna Glaze , Ard Biescheuvel , "Min M. Xu" , Gerd Hoffmann , James Bottomley , Tom Lendacky , Erdem Aktas , "Kirill A. Shutemov" , Dave Hansen Precedence: Bulk List-Unsubscribe: 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,dionnaglaze@google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1673645460; bh=HBQMm0g24ePNNsF2z2dTyOAmJMnCZSdAlC6ws3tYl5Q=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=PunjYtGIheCccHSqHxmjXTIlm90io2qXRhzOdgngXeVxSqs5ZN9LnWpIZ+YKbS7s5NL DdiTQtyyMDvjYIFbkTsJeMxhShT6hsEX65KHzkNDy4X6jsQ6XWn4xQvLwvNC9Yh3aIBcF +3+2JG7R9Hz6CnPPCphmWWe/XZF8ofvAFq8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1673645463004100002 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch depends on Kirill A. Shutemov's series [PATCHv8 00/14] mm, x86/cc: Implement support for unaccepted memory The UEFI v2.9 specification includes a new memory type to be used in environments where the OS must accept memory that is provided from its host. Before the introduction of this memory type, all memory was accepted eagerly in the firmware. In order for the firmware to safely stop accepting memory on the OS's behalf, the OS must affirmatively indicate support to the firmware. Enabling unaccepted memory requires calling a 0-argument enablement protocol before ExitBootServices. This call is only made if the kernel is compiled with UNACCEPTED_MEMORY=3Dy The naming of the protocol guid is dependent on the standardization of the protocol, which is being discussed. Acceptance is contingent on the kernel community's approval. Cc: Ard Biescheuvel Cc: "Min M. Xu" Cc: Gerd Hoffmann Cc: James Bottomley Cc: Tom Lendacky Cc: Jiewen Yao Cc: Erdem Aktas Cc: "Kirill A. Shutemov" Cc: Dave Hansen Signed-off-by: Dionna Glaze --- drivers/firmware/efi/libstub/x86-stub.c | 37 +++++++++++++++++++++++++ include/linux/efi.h | 1 + 2 files changed, 38 insertions(+) diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi= /libstub/x86-stub.c index a0bfd31358ba..abf31e5ade55 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -26,6 +26,17 @@ const efi_dxe_services_table_t *efi_dxe_table; u32 image_offset __section(".data"); static efi_loaded_image_t *image =3D NULL; =20 +typedef union memory_acceptance_protocol memory_acceptance_protocol_t; +union memory_acceptance_protocol { + struct { + efi_status_t (__efiapi *allow_unaccepted_memory)( + memory_acceptance_protocol_t *); + }; + struct { + u32 allow_unaccepted_memory; + } mixed_mode; +}; + static efi_status_t preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **= __rom) { @@ -310,6 +321,30 @@ setup_memory_protection(unsigned long image_base, unsi= gned long image_size) #endif } =20 + +static void setup_unaccepted_memory(void) +{ + efi_guid_t mem_acceptance_proto =3D EFI_MEMORY_ACCEPTANCE_PROTOCOL_GUID; + memory_acceptance_protocol_t *proto; + efi_status_t status; + + if (!IS_ENABLED(CONFIG_UNACCEPTED_MEMORY)) + return; + + /* + * Enable unaccepted memory before calling exit boot services in order + * for the UEFI to not accept all memory on EBS. + */ + status =3D efi_bs_call(locate_protocol, &mem_acceptance_proto, NULL, + (void **)&proto); + if (status !=3D EFI_SUCCESS) + return; + + status =3D efi_call_proto(proto, allow_unaccepted_memory); + if (status !=3D EFI_SUCCESS) + efi_err("Memory acceptance protocol failed\n"); +} + static const efi_char16_t apple[] =3D L"Apple"; =20 static void setup_quirks(struct boot_params *boot_params, @@ -899,6 +934,8 @@ asmlinkage unsigned long efi_main(efi_handle_t handle, =20 setup_quirks(boot_params, bzimage_addr, buffer_end - buffer_start); =20 + setup_unaccepted_memory(); + status =3D exit_boot(boot_params, handle); if (status !=3D EFI_SUCCESS) { efi_err("exit_boot() failed!\n"); diff --git a/include/linux/efi.h b/include/linux/efi.h index 4b27519143f5..bfc0e4f2aba5 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -391,6 +391,7 @@ void efi_native_runtime_setup(void); #define EFI_RT_PROPERTIES_TABLE_GUID EFI_GUID(0xeb66918a, 0x7eef, 0x402a,= 0x84, 0x2e, 0x93, 0x1d, 0x21, 0xc3, 0x8a, 0xe9) #define EFI_DXE_SERVICES_TABLE_GUID EFI_GUID(0x05ad34ba, 0x6f02, 0x4214, = 0x95, 0x2e, 0x4d, 0xa0, 0x39, 0x8e, 0x2b, 0xb9) #define EFI_SMBIOS_PROTOCOL_GUID EFI_GUID(0x03583ff6, 0xcb36, 0x4940, 0x= 94, 0x7e, 0xb9, 0xb3, 0x9f, 0x4a, 0xfa, 0xf7) +#define EFI_MEMORY_ACCEPTANCE_PROTOCOL_GUID EFI_GUID(0xc5a010fe, 0x38a7, 0= x4531, 0x8a, 0x4a, 0x05, 0x00, 0xd2, 0xfd, 0x16, 0x49) =20 #define EFI_IMAGE_SECURITY_DATABASE_GUID EFI_GUID(0xd719b2cb, 0x3d3a, 0x45= 96, 0xa3, 0xbc, 0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f) #define EFI_SHIM_LOCK_GUID EFI_GUID(0x605dab50, 0xe046, 0x4300, 0xab, 0= xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23) --=20 2.39.0.314.g84b9a713c41-goog -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#98506): https://edk2.groups.io/g/devel/message/98506 Mute This Topic: https://groups.io/mt/96256524/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-