From nobody Tue May 21 12:23:28 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+98500+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+98500+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1673629892; cv=none; d=zohomail.com; s=zohoarc; b=RVl3V2etWGLFORe6NpQTEs7FHdQgN+pssLYQu1oiJ5ojYKxwWI7Ojv232DYYuUVfigKHpKurjvYxU3rxmOLzHSgjY5+nGocRtyroLqZg6R6D+EbIlg5686COjRyNXWexJ4fbdw7dHggpdIgqJkcN74uJkTCxeInNiOGsmKiVrLs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673629892; h=Content-Type:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=/XaLKYi9b6D/nBobYTOdGGASUwaLmxLPWgIceNojes4=; b=GEvN/WrHdiJpMLLOoZmAaomMyZ9zlC+3XBdQn5zvtAmNK8t2hdk1iuKOTGkQyLxONCX+jVQBpPJCwUQRPZPzDAyT/lAe7omH++Ljo4FkcuEk3d87HrEpOYtIpfj7eyklOblAEzuS0wy6ix+IMkxW69Atwb8+J1C8oaIsnoY9Dqk= 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+98500+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 167362989261366.04722300537912; Fri, 13 Jan 2023 09:11:32 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8rZKYY1788612xAfNAZlzyPH; Fri, 13 Jan 2023 09:11:31 -0800 X-Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by mx.groups.io with SMTP id smtpd.web10.93723.1673629891170952913 for ; Fri, 13 Jan 2023 09:11:31 -0800 X-Received: by mail-pl1-f201.google.com with SMTP id p14-20020a170902e74e00b00192f6d0600eso15150645plf.3 for ; Fri, 13 Jan 2023 09:11:31 -0800 (PST) X-Gm-Message-State: x3RxNX1eSygSm5P5SoppM4kex1787277AA= X-Google-Smtp-Source: AMrXdXtKasX1PdRXC4WdHMsgiEEyZVDhbpa6g9L0RJqjLicaSyJDaLuwX745uoV56aX9kO2valnZ9cProxQdP6TkuA== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2ee6]) (user=dionnaglaze job=sendgmr) by 2002:a62:6d47:0:b0:581:1417:6ce6 with SMTP id i68-20020a626d47000000b0058114176ce6mr4915820pfc.58.1673629890428; Fri, 13 Jan 2023 09:11:30 -0800 (PST) Date: Fri, 13 Jan 2023 17:11:25 +0000 Mime-Version: 1.0 Message-ID: <20230113171125.2846306-1-dionnaglaze@google.com> Subject: [edk2-devel] [PATCH] x86/efi: Safely enable unaccepted memory in UEFI From: "Dionna Glaze via groups.io" To: linux-kernel@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=1673629891; bh=u9e6D9rSj44k+9KaJ2XGgDXklyuqVzjU3VP8VDqf//o=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=obQjJZmzZiz7EIq50h26fdfuW8BXrpBLZYBr4OCtCcmL0+qvO8leL+yw0G4sLjUEMkQ vi3vb1YLASzuiKB7z/TGUqX1GrB0/BFOzesQnvRbXBuzxaIQUcoPo9W47st3f/6UgclJD 29+xmSiDpw9CYxXqN5xlLFdh/oVkhsyN0I4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1673629892966100001 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 | 36 +++++++++++++++++++++++++ include/linux/efi.h | 1 + 2 files changed, 37 insertions(+) diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi= /libstub/x86-stub.c index a0bfd31358ba..5e9ebfbb49e6 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 +union memory_acceptance_protocol { + struct { + efi_status_t (__efiapi *allow_unaccepted_memory)( + union memory_acceptance_protocol *); + }; + struct { + u32 allow_unaccepted_memory; + } mixed_mode; +}; +typedef union memory_acceptance_protocol memory_acceptance_protocol_t; + static efi_status_t preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **= __rom) { @@ -310,6 +321,29 @@ setup_memory_protection(unsigned long image_base, unsi= gned long image_size) #endif } =20 + +static void setup_unaccepted_memory(void) +{ +#ifdef CONFIG_UNACCEPTED_MEMORY + efi_guid_t mem_acceptance_proto =3D EFI_MEMORY_ACCEPTANCE_PROTOCOL_GUID; + memory_acceptance_protocol_t *proto; + efi_status_t status; + + /* + * 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"); +#endif +} + static const efi_char16_t apple[] =3D L"Apple"; =20 static void setup_quirks(struct boot_params *boot_params, @@ -899,6 +933,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 (#98500): https://edk2.groups.io/g/devel/message/98500 Mute This Topic: https://groups.io/mt/96250536/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-