From patchwork Fri Dec 20 11:22:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 852585 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 2BEF01C07E4 for ; Fri, 20 Dec 2024 11:22:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693761; cv=none; b=ALmiLoVoKCVAN5UpHAS4p2Z/UGxgzGzghReTnhQ06zkgGKtZMYhWs0V49Ooe5toyx6ZR2l2gPZ5YVcMVrv0Zzg/TufrarRrHiiI3VDr8tSI/a3c8PuFWYmvIlvu51MkJlel1bbK4kqB6YQhxv4+iwmtc6ol1rzZ27KKYgiSIdOs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693761; c=relaxed/simple; bh=aIauqGBYHpW4ez5NfIDLYO5bWWI87u7AWHcSTVi1nKM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OpMgjWmLTCmgay2tHj3IjhgfdEJt8VTyI63lUPgPW41lfCOuZQ0lrHU6hyCix77MtyxeiaCDAsE+Akem15bHWgdkC4wQbudFNoyr/yHV634rwdcy1TFpPmIGlD0/QmsecUBKbwpP2wGpy3921LAJ7TsE/27q1F5umccU5EPUlyI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Z63j0k5M; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Z63j0k5M" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-43631d8d9c7so10200175e9.1 for ; Fri, 20 Dec 2024 03:22:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734693758; x=1735298558; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=G4YTq/ftOlxzsFyBK5qpik8kRgidp3qaC0bsdTEKQfI=; b=Z63j0k5MRKPRnKB855cF0osTjU+cQLYfjz8awGx/5S8yUeOZ871wp/iQYsepTV+D7u FESBFzUnj3+ZiAwbppt/YW2HIUNlZRuv9SqwtDHKLI//OCYlaTgiekrH0tcKHPHc8IJK kncWxnhOYEXJfDiUE9P1Yn9vmieJDv5OhUs5BO1/e39zjQlKwARFbgHPYAVaJ5TFqGcs AlBE00gUo/8jfjQqWO4oTI5i/f7PdhE73ivAMh45jY+MCoVdcS6UVqXMEr+5b6CtjCit 3AWQkUZqHrypqn+F9/q9HZ1DMn5df2SzZbwpkqctLOHFH02UlO8Gi6GISAegFhF7009K AWqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734693758; x=1735298558; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=G4YTq/ftOlxzsFyBK5qpik8kRgidp3qaC0bsdTEKQfI=; b=fU9CqmHP6+MgQ8A2K/lJM3sU6/w+/jf93F7Cg3i1FpTvDklE7ujtO3eeauqvXURWSE ce8jZe9ZqhqA/JFwik6rrrAVVrTP7/f/KTTYGGvTEXIetpBw/BuCTdech5hVXGOXMhJH x9hpn2D+jp3W47dFfCvO1jUJk6zKmrKlG7ZS3Jmovi1AEAZ8O5oJr8xqGps1S5BnhKPK Eo6QhptxlSOIb3zB0vlw2Ou3TIajBBIVFCQZ4hN5DFTfDHDufvXUP/jm11XH006LHPF2 OFbmblQHDHMi5lN6dMFE6O9rwI4GDV1lvN1tH37ltQCvjMYTqThc2C71x5xWQbH+u8rx bVQQ== X-Gm-Message-State: AOJu0Yw4FwI46iMU1qU4pL73rh6BE8hRApZQa8euUaIIwqol1ZDfn2sl oAMahizI2ooh2VADrnZ7oCjuhvT7B1oZkvuBQlhoyiv/25XGkTWsLNd58JvRl58bkmRJL+Gf19w V9qHazp6/sx8lR1rFc/dfY/eQ1ACgyek1Yyvj/Wnalm0vrWjvrnhpUK+TZ+oZLY4wpr8xAxyws2 gXUeW2ArD9VDJsVQjaQeeo6/+R5A== X-Google-Smtp-Source: AGHT+IEFIi4SExocJjw8kszjhCQw70qFejd1sU8fWDynz2b6RMGHYdSgLx1AafOwUuQhZpTI//tUZJaS X-Received: from wmbjj16.prod.google.com ([2002:a05:600c:6a10:b0:434:e9fe:f913]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3b8c:b0:434:ff08:202e with SMTP id 5b1f17b1804b1-436699ff9famr20916095e9.8.1734693758603; Fri, 20 Dec 2024 03:22:38 -0800 (PST) Date: Fri, 20 Dec 2024 12:22:16 +0100 In-Reply-To: <20241220112214.2598872-9-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220112214.2598872-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=6232; i=ardb@kernel.org; h=from:subject; bh=cMbTqyf6fcVFSGOV1gvDHpolf1J3659U3OaWiXwGbLI=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT01ONP46G6h5UVddxZM8VPZ1L0k90xTVue95YYxeqGtg c0ZdUEdpSwMYhwMsmKKLAKz/77beXqiVK3zLFmYOaxMIEMYuDgFYCIHxBh+s/8+VDZdZuvPlDiJ B13pp9/GT3l3KSzNLLA700DqcOjNUIa/oj8bC14ej7XfYPF4q1BbP0/EylObXM+Khuo4xkz8zT6 PBQA= X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220112214.2598872-10-ardb+git@google.com> Subject: [PATCH 1/7] x86/efistub: Drop long obsolete UGA support From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel From: Ard Biesheuvel UGA is the EFI graphical output protocol that preceded GOP, and has been long obsolete. Drop support for it from the x86 implementation of the EFI stub - other architectures never bothered to implement it (save for ia64) Signed-off-by: Ard Biesheuvel --- arch/x86/platform/efi/efi.c | 2 - drivers/firmware/efi/libstub/x86-stub.c | 90 -------------------- include/linux/efi.h | 2 - 3 files changed, 94 deletions(-) diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c index a7ff189421c3..41fc2254f007 100644 --- a/arch/x86/platform/efi/efi.c +++ b/arch/x86/platform/efi/efi.c @@ -60,7 +60,6 @@ static unsigned long efi_runtime, efi_nr_tables; unsigned long efi_fw_vendor, efi_config_table; static const efi_config_table_type_t arch_tables[] __initconst = { - {UGA_IO_PROTOCOL_GUID, &uga_phys, "UGA" }, #ifdef CONFIG_X86_UV {UV_SYSTEM_TABLE_GUID, &uv_systab_phys, "UVsystab" }, #endif @@ -72,7 +71,6 @@ static const unsigned long * const efi_tables[] = { &efi.acpi20, &efi.smbios, &efi.smbios3, - &uga_phys, #ifdef CONFIG_X86_UV &uv_systab_phys, #endif diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index 188c8000d245..0c51d8307000 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -405,96 +405,13 @@ static void setup_quirks(struct boot_params *boot_params) } } -/* - * See if we have Universal Graphics Adapter (UGA) protocol - */ -static efi_status_t -setup_uga(struct screen_info *si, efi_guid_t *uga_proto, unsigned long size) -{ - efi_status_t status; - u32 width, height; - void **uga_handle = NULL; - efi_uga_draw_protocol_t *uga = NULL, *first_uga; - efi_handle_t handle; - int i; - - status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size, - (void **)&uga_handle); - if (status != EFI_SUCCESS) - return status; - - status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, - uga_proto, NULL, &size, uga_handle); - if (status != EFI_SUCCESS) - goto free_handle; - - height = 0; - width = 0; - - first_uga = NULL; - for_each_efi_handle(handle, uga_handle, size, i) { - efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID; - u32 w, h, depth, refresh; - void *pciio; - - status = efi_bs_call(handle_protocol, handle, uga_proto, - (void **)&uga); - if (status != EFI_SUCCESS) - continue; - - pciio = NULL; - efi_bs_call(handle_protocol, handle, &pciio_proto, &pciio); - - status = efi_call_proto(uga, get_mode, &w, &h, &depth, &refresh); - if (status == EFI_SUCCESS && (!first_uga || pciio)) { - width = w; - height = h; - - /* - * Once we've found a UGA supporting PCIIO, - * don't bother looking any further. - */ - if (pciio) - break; - - first_uga = uga; - } - } - - if (!width && !height) - goto free_handle; - - /* EFI framebuffer */ - si->orig_video_isVGA = VIDEO_TYPE_EFI; - - si->lfb_depth = 32; - si->lfb_width = width; - si->lfb_height = height; - - si->red_size = 8; - si->red_pos = 16; - si->green_size = 8; - si->green_pos = 8; - si->blue_size = 8; - si->blue_pos = 0; - si->rsvd_size = 8; - si->rsvd_pos = 24; - -free_handle: - efi_bs_call(free_pool, uga_handle); - - return status; -} - static void setup_graphics(struct boot_params *boot_params) { efi_guid_t graphics_proto = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; struct screen_info *si; - efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID; efi_status_t status; unsigned long size; void **gop_handle = NULL; - void **uga_handle = NULL; si = &boot_params->screen_info; memset(si, 0, sizeof(*si)); @@ -505,13 +422,6 @@ static void setup_graphics(struct boot_params *boot_params) if (status == EFI_BUFFER_TOO_SMALL) status = efi_setup_gop(si, &graphics_proto, size); - if (status != EFI_SUCCESS) { - size = 0; - status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, - &uga_proto, NULL, &size, uga_handle); - if (status == EFI_BUFFER_TOO_SMALL) - setup_uga(si, &uga_proto, size); - } } diff --git a/include/linux/efi.h b/include/linux/efi.h index e5815867aba9..234200469146 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -363,7 +363,6 @@ void efi_native_runtime_setup(void); #define ACPI_20_TABLE_GUID EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81) #define SMBIOS_TABLE_GUID EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d) #define SMBIOS3_TABLE_GUID EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c, 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94) -#define UGA_IO_PROTOCOL_GUID EFI_GUID(0x61a4d49e, 0x6f68, 0x4f1b, 0xb9, 0x22, 0xa8, 0x6e, 0xed, 0x0b, 0x07, 0xa2) #define EFI_GLOBAL_VARIABLE_GUID EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c) #define UV_SYSTEM_TABLE_GUID EFI_GUID(0x3b13a7d4, 0x633e, 0x11dd, 0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93) #define LINUX_EFI_CRASH_GUID EFI_GUID(0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0) @@ -373,7 +372,6 @@ void efi_native_runtime_setup(void); #define EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID EFI_GUID(0x8b843e20, 0x8132, 0x4852, 0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c) #define EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID EFI_GUID(0x05c99a21, 0xc70f, 0x4ad2, 0x8a, 0x5f, 0x35, 0xdf, 0x33, 0x43, 0xf5, 0x1e) #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a) -#define EFI_UGA_PROTOCOL_GUID EFI_GUID(0x982c298b, 0xf4fa, 0x41cb, 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39) #define EFI_PCI_IO_PROTOCOL_GUID EFI_GUID(0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x02, 0x9a) #define EFI_FILE_INFO_ID EFI_GUID(0x09576e92, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b) #define EFI_SYSTEM_RESOURCE_TABLE_GUID EFI_GUID(0xb122a263, 0x3661, 0x4f68, 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80) From patchwork Fri Dec 20 11:22:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 853006 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 194EE1C4A38 for ; Fri, 20 Dec 2024 11:22:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693765; cv=none; b=JQRQ9bEQApGg5iXBcbhip0gvRpISj7BG67XH5yJi1lCLpAdUMMwGQ7DPPKcdPM3XrLrJH+jY5WUPXLHdcnTkBBlAoNsE7XqlVfVboF0U/9ujAHs1qc9lqu94nOD7dbDX7PIOGozgodHf6x/syL+cf0eDR7tA/3RxOsBTKakpYEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693765; c=relaxed/simple; bh=yjKDfnWFkEuDhw362m3wgv7Ngw+SdWNENil+UmGcXVs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=s9dsm1s7ds32t1LwlBF9VANjHBBY+mhpPTu60HhCzEoE1SPFaScvVjys9F8DAQtCBHlZOCOgYjRlvCPiGLRP1JS9Xmj22W5+LHAd7wdzfSvBhZEfUIrjct2cciZKWrBfXWCpJTO/tA+M2nxJtU0vtaVm6Unw/nkWXZeuwIztbLc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=q/2nIDpT; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="q/2nIDpT" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4361d4e8359so15614915e9.3 for ; Fri, 20 Dec 2024 03:22:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734693760; x=1735298560; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6YYXdY4bN82dG0pvzgxsem1o3f0Ml+EYY91hq0XrqIE=; b=q/2nIDpTe6APAW4FJPuobzwo3R88HCNkllCAfxg3hSPHxf9dkbn6cMwKvmrNB9dZjI VbyRh9EZfT5POuxrAYKhDZNk3kKMvySeuqfovTW7euDDZqzN+1qNQIBqelbS0CTF9UAp H4mMmIAvu5RJYWT84bwlJ3VcGhTFffu9ue5ErHwBC19+0mc2A2zLYnHOeXswroVW9TuW kUVHCHtxFRJO43O63jaLekAQxwi/KKDpvvPmlXlatCl6CWxtOEz5jp92VmxrvlVlKM4/ fZ4JK+5QHSW5pyqaQWY1fFNeJEjKrJks2OkU6lsgsZeGdYK2Y3Wd/oawBUO35m4Uk5ow bOjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734693760; x=1735298560; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6YYXdY4bN82dG0pvzgxsem1o3f0Ml+EYY91hq0XrqIE=; b=eGlDwyXkseZr5FuJMeF6JK+y5RTTgArFgtrJRhtr6N0CEf3zZsreScaY1b8JCeX7ao OrtjD/2aHmLBCv87zClO9wSVb9D7axR9rjoAEqeJdx3X8PPCnXR3gUNOot1lqykNdLlc hDE+U7zGWppTUyrUk+X5MfMBxowYOhXQoYwu0Qhu+FwBmQ/h4ha6MPdOlDsSS+45ge0S 7AXxMAJsZ8sX3EzY2Hu9GA3JImM1Qt73gHp99VFpeqJi2kEz60s0/MCt8RMuZDmcXThW GwBOwVuZUDgTb4m/pvUxMIY2M8XnKHQcTSBGyl6pB1h9VbweVRFpoPx4US2OGi6MX3J1 OBIg== X-Gm-Message-State: AOJu0Yyo3bkVYRXAk0e2EO9mUjZBqmxlqecvDJ4W6wIgtvCq2VQqGZu5 SAMkSTH8xzp0JTbGEFYz75AbLYFcSr3g0aYfSx1ZY8aGzOoghkVtWBFZXEzFNVjjslDxrsSbNE1 MSfjPd7ZO7c8gwTKSZkMR5P9B5qzJeoVPVbZsQ+tL3qvK+QE9kjcEIEv04bFVhtyJx30wJNkzgc Aj+YtjU0gg/pexhoazpYR6aTeE2A== X-Google-Smtp-Source: AGHT+IEPtd6fv8n48QLQArvWtpQjRGaa1iszuXudfaVHD/pL8rJJFKuWgJzijdPiBSgexJW7kzhFRQ8s X-Received: from wmqb1.prod.google.com ([2002:a05:600c:4e01:b0:434:ef30:4be3]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:35d2:b0:435:d22:9c9e with SMTP id 5b1f17b1804b1-43668646335mr21268535e9.19.1734693760586; Fri, 20 Dec 2024 03:22:40 -0800 (PST) Date: Fri, 20 Dec 2024 12:22:17 +0100 In-Reply-To: <20241220112214.2598872-9-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220112214.2598872-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=4129; i=ardb@kernel.org; h=from:subject; bh=cg25M7jhCCiFzPMmRlAcGna2O6HkPSkC46Z5HoI87BA=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT01OOt0W3/L5lCLSsW9HtkP5tgVXBeXtls1dU28L8/Ch KOnns7sKGVhEONgkBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABOxmc7wP4kje8/G8++OSllx y7CVP53lYuxa1WiSfs1ia8X0iusHOxn+1x2a+WNqe9v3d7dt37FPn3H54PoAOd8TSwK/BB/ab+7 FzAIA X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220112214.2598872-11-ardb+git@google.com> Subject: [PATCH 2/7] efi/libstub: Use C99-style for loop to traverse handle buffer From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel From: Ard Biesheuvel Tweak the for_each_efi_handle() macro in order to avoid the need on the part of the caller to provide a loop counter variable. Also move efi_get_handle_num() to the callers, so that each occurrence can be replaced with the actual number returned by the simplified LocateHandleBuffer API. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efistub.h | 9 ++++----- drivers/firmware/efi/libstub/gop.c | 3 +-- drivers/firmware/efi/libstub/pci.c | 5 ++--- drivers/firmware/efi/libstub/x86-stub.c | 3 +-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index d0989e072b2b..c321735eb237 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -123,11 +123,10 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, #define efi_get_handle_num(size) \ ((size) / (efi_is_native() ? sizeof(efi_handle_t) : sizeof(u32))) -#define for_each_efi_handle(handle, array, size, i) \ - for (i = 0; \ - i < efi_get_handle_num(size) && \ - ((handle = efi_get_handle_at((array), i)) || true); \ - i++) +#define for_each_efi_handle(handle, array, num) \ + for (int __i = 0; __i < (num) && \ + ((handle = efi_get_handle_at((array), __i)) || true); \ + __i++) static inline void efi_set_u64_split(u64 data, u32 *lo, u32 *hi) diff --git a/drivers/firmware/efi/libstub/gop.c b/drivers/firmware/efi/libstub/gop.c index ea5da307d542..8eef63c48288 100644 --- a/drivers/firmware/efi/libstub/gop.c +++ b/drivers/firmware/efi/libstub/gop.c @@ -466,11 +466,10 @@ find_gop(efi_guid_t *proto, unsigned long size, void **handles) { efi_graphics_output_protocol_t *first_gop; efi_handle_t h; - int i; first_gop = NULL; - for_each_efi_handle(h, handles, size, i) { + for_each_efi_handle(h, handles, efi_get_handle_num(size)) { efi_status_t status; efi_graphics_output_protocol_t *gop; diff --git a/drivers/firmware/efi/libstub/pci.c b/drivers/firmware/efi/libstub/pci.c index 99fb25d2bcf5..b0ba372c26c5 100644 --- a/drivers/firmware/efi/libstub/pci.c +++ b/drivers/firmware/efi/libstub/pci.c @@ -21,7 +21,6 @@ void efi_pci_disable_bridge_busmaster(void) efi_handle_t handle; efi_status_t status; u16 class, command; - int i; status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, &pci_proto, NULL, &pci_handle_size, NULL); @@ -46,7 +45,7 @@ void efi_pci_disable_bridge_busmaster(void) goto free_handle; } - for_each_efi_handle(handle, pci_handle, pci_handle_size, i) { + for_each_efi_handle(handle, pci_handle, efi_get_handle_num(pci_handle_size)) { efi_pci_io_protocol_t *pci; unsigned long segment_nr, bus_nr, device_nr, func_nr; @@ -82,7 +81,7 @@ void efi_pci_disable_bridge_busmaster(void) efi_bs_call(disconnect_controller, handle, NULL, NULL); } - for_each_efi_handle(handle, pci_handle, pci_handle_size, i) { + for_each_efi_handle(handle, pci_handle, efi_get_handle_num(pci_handle_size)) { efi_pci_io_protocol_t *pci; status = efi_bs_call(handle_protocol, handle, &pci_proto, diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index 0c51d8307000..71173471faf6 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -124,7 +124,6 @@ static void setup_efi_pci(struct boot_params *params) unsigned long size = 0; struct setup_data *data; efi_handle_t h; - int i; status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, &pci_proto, NULL, &size, pci_handle); @@ -150,7 +149,7 @@ static void setup_efi_pci(struct boot_params *params) while (data && data->next) data = (struct setup_data *)(unsigned long)data->next; - for_each_efi_handle(h, pci_handle, size, i) { + for_each_efi_handle(h, pci_handle, efi_get_handle_num(size)) { efi_pci_io_protocol_t *pci = NULL; struct pci_setup_rom *rom; From patchwork Fri Dec 20 11:22:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 852584 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (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 78EDD1C5CCA for ; Fri, 20 Dec 2024 11:22:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693766; cv=none; b=XNBwO0+ZU9y/C2Ic1NcC9nkgGqP86eejilcfFOJ/h6G8phvzfhVS1B8T0R0+ZlZvsZSbHE3RTqvU4lfdc3XCkBVnno/fK84R0O821tVI0NVzisAC2GyZjqFlYd2+5RiSH3R0LoZzhCllQvhOqLWOm5aGzEybTe3AitXXCOAb21M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693766; c=relaxed/simple; bh=0KQw1DNiKBnqryYgDBurqGjOmCFqhEOFJLSA0mjA9yk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=PNCXqOvaW9bpMWEM3oe3FjIKYSV9StQL9yYNIKGyQb5sEcBLQacGm0H7A6tUCMVdL63inirH2TT2iboowB15B/JQMasJcuBafWKQxSnWcmKbVKgMIeSaioH5y2vdWLSHWdcBUC7j56mzEe4ws3tniu1Hsogdo7LtQXVo5YI5ZQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rYENQi76; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rYENQi76" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-3860bc1d4f1so1079197f8f.2 for ; Fri, 20 Dec 2024 03:22:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734693763; x=1735298563; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=cNSJ8HGXQNdXuP3+AktVsISDb7HTO/BmfoYSJrTO9ls=; b=rYENQi764ppB9qdKmb3cVHJwbk9CS5trZZssQlYrh6SIw2yp8PCImG1R+Z9a/5Xfoc 9QivdlG4h1pIQcV3N8RyWfl74nLIF4hDXPWqrBr+ZkYZ4cMIQBNmMlDUw8TqbPM5oU7j gYTmk3ioxFL4HcBwGolh7i5y1e8+CiqwYFPcfPtMQPwksNvWrPWEnnqwCaeNBbfgDJto Rzd8A4ykPeVYwteBPAa2P17TkGha6Pbl5qD3aYN08epGQx16nlbz+LlXDM+b04S0GUut 6St6KNq6hv+oHY/enJLEo9mgUGdKjG9x/Yx9sklm4XJrWO3oFCCbITKBmrfEhWe0zPZE 0dLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734693763; x=1735298563; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cNSJ8HGXQNdXuP3+AktVsISDb7HTO/BmfoYSJrTO9ls=; b=PnjXdN9nWgkBu6v4iZ/aUywzYVxN720mcVEmomRqYIDKranTPCcASp68x3W2cFLmX2 JgkmBXph6NkWLm2GitxyRTcZ/3yXSXKI/3NKErFyJbWQ6L68MKFUMSAnT+g5SMmIMYlA yMYR9/gsyGKo3e7arpWU6bJZpWlcTSCMMwkmUg/jVTQt8W51e+BliC3iyR4svyA6y0z1 vy/T9LEJ2TliY+ahA8CqQ9iZunuE2oF5ViqoXZB1EZxhJIp//vlCMJIrNZnJswV3rtXB iZdx4tZekz56wcxhU9iGI6fdVe9Wwshhl5zspBaQgJAR2sqcO478SMHmVwxn/sz6CYkU 00sQ== X-Gm-Message-State: AOJu0YxR8VdtGY0itIC2vtaPmPXsTKdfIlth3GvsW6pu6UF5pnfaYybt DcJl5LqMkKrQ9cgXfWXAE4bbzpWr6IhL09LBS+pvtgF4mRvql078ZDYlKF76WFmLQroGPmglNUA 1iwRE0rCirGHN6M4v9jW0XPuHcDN1G4FbI/AfcJNcC+XGGyep71d7RQ5Ksq48alBIuRZlJBadrK 6hfRAxEwN2kzS6/Jn59DY5+2vtmQ== X-Google-Smtp-Source: AGHT+IF8zUGLe6aA2WdSo/5UrRsQij4BJK0HhPCJwGp9RoMVXlZcaAC1wTrHc2l53LJ8kJfl0nK1b59/ X-Received: from wmbjj20.prod.google.com ([2002:a05:600c:6a14:b0:434:fc6f:e8c3]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:598d:0:b0:385:fa3d:1988 with SMTP id ffacd0b85a97d-38a221e2f07mr2467165f8f.8.1734693762878; Fri, 20 Dec 2024 03:22:42 -0800 (PST) Date: Fri, 20 Dec 2024 12:22:18 +0100 In-Reply-To: <20241220112214.2598872-9-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220112214.2598872-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=7976; i=ardb@kernel.org; h=from:subject; bh=rYysZblB1Mm5gOU2h843vOCeOHNVXYgW6tmjcsWmdn4=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT01OKdZpLkvZuGDufPfx9nHCtw4YLRe0ru3vV+PWW7zh 4tsL/I6SlkYxDgYZMUUWQRm/3238/REqVrnWbIwc1iZQIYwcHEKwEQ0ExgZ1mW/9uJOZp4wS+K2 /MOjMZ8WZrzzdom/e/L5qTszXn2eP4Xhf2nXgi9Cvpc7pjXVHbqlLKl2zyx66jFRkV99wVoyBjb 7eAA= X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220112214.2598872-12-ardb+git@google.com> Subject: [PATCH 3/7] efi/libstub: Simplify GOP handling code From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel From: Ard Biesheuvel Use the LocateHandleBuffer() API and a __free() function to simplify the logic that allocates a handle buffer to iterate over all GOP protocols in the EFI database. Signed-off-by: Ard Biesheuvel --- arch/x86/include/asm/efi.h | 3 ++ drivers/firmware/efi/libstub/efi-stub.c | 28 ++++------ drivers/firmware/efi/libstub/efistub.h | 7 +-- drivers/firmware/efi/libstub/gop.c | 57 +++++++------------- drivers/firmware/efi/libstub/x86-stub.c | 17 +----- 5 files changed, 38 insertions(+), 74 deletions(-) diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h index 521aad70e41b..f227a70ac91f 100644 --- a/arch/x86/include/asm/efi.h +++ b/arch/x86/include/asm/efi.h @@ -250,6 +250,9 @@ static inline u32 efi64_convert_status(efi_status_t status) #define __efi64_argmap_allocate_pool(type, size, buffer) \ ((type), (size), efi64_zero_upper(buffer)) +#define __efi64_argmap_locate_handle_buffer(type, proto, key, num, buf) \ + ((type), (proto), (key), efi64_zero_upper(num), efi64_zero_upper(buf)) + #define __efi64_argmap_create_event(type, tpl, f, c, event) \ ((type), (tpl), (f), (c), efi64_zero_upper(event)) diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c index 382b54f40603..90e06a6b1a45 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -10,6 +10,7 @@ */ #include +#include #include #include "efistub.h" @@ -53,25 +54,16 @@ void __weak free_screen_info(struct screen_info *si) static struct screen_info *setup_graphics(void) { - efi_guid_t gop_proto = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; - efi_status_t status; - unsigned long size; - void **gop_handle = NULL; - struct screen_info *si = NULL; + struct screen_info *si, tmp = {}; - size = 0; - status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, - &gop_proto, NULL, &size, gop_handle); - if (status == EFI_BUFFER_TOO_SMALL) { - si = alloc_screen_info(); - if (!si) - return NULL; - status = efi_setup_gop(si, &gop_proto, size); - if (status != EFI_SUCCESS) { - free_screen_info(si); - return NULL; - } - } + if (efi_setup_gop(&tmp) != EFI_SUCCESS) + return NULL; + + si = alloc_screen_info(); + if (!si) + return NULL; + + *si = tmp; return si; } diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index c321735eb237..a7c24f0a2e5e 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -314,7 +314,9 @@ union efi_boot_services { void *close_protocol; void *open_protocol_information; void *protocols_per_handle; - void *locate_handle_buffer; + efi_status_t (__efiapi *locate_handle_buffer)(int, efi_guid_t *, + void *, unsigned long *, + efi_handle_t *); efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *, void **); efi_status_t (__efiapi *install_multiple_protocol_interfaces)(efi_handle_t *, ...); @@ -1083,8 +1085,7 @@ efi_status_t efi_parse_options(char const *cmdline); void efi_parse_option_graphics(char *option); -efi_status_t efi_setup_gop(struct screen_info *si, efi_guid_t *proto, - unsigned long size); +efi_status_t efi_setup_gop(struct screen_info *si); efi_status_t handle_cmdline_files(efi_loaded_image_t *image, const efi_char16_t *optstr, diff --git a/drivers/firmware/efi/libstub/gop.c b/drivers/firmware/efi/libstub/gop.c index 8eef63c48288..fce28488c76c 100644 --- a/drivers/firmware/efi/libstub/gop.c +++ b/drivers/firmware/efi/libstub/gop.c @@ -461,25 +461,25 @@ setup_pixel_info(struct screen_info *si, u32 pixels_per_scan_line, } } -static efi_graphics_output_protocol_t * -find_gop(efi_guid_t *proto, unsigned long size, void **handles) +static efi_graphics_output_protocol_t *find_gop(unsigned long num, + const efi_handle_t handles[]) { efi_graphics_output_protocol_t *first_gop; efi_handle_t h; first_gop = NULL; - for_each_efi_handle(h, handles, efi_get_handle_num(size)) { + for_each_efi_handle(h, handles, num) { efi_status_t status; efi_graphics_output_protocol_t *gop; efi_graphics_output_protocol_mode_t *mode; efi_graphics_output_mode_info_t *info; - - efi_guid_t conout_proto = EFI_CONSOLE_OUT_DEVICE_GUID; void *dummy = NULL; - status = efi_bs_call(handle_protocol, h, proto, (void **)&gop); + status = efi_bs_call(handle_protocol, h, + &EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, + (void **)&gop); if (status != EFI_SUCCESS) continue; @@ -499,7 +499,8 @@ find_gop(efi_guid_t *proto, unsigned long size, void **handles) * Once we've found a GOP supporting ConOut, * don't bother looking any further. */ - status = efi_bs_call(handle_protocol, h, &conout_proto, &dummy); + status = efi_bs_call(handle_protocol, h, + &EFI_CONSOLE_OUT_DEVICE_GUID, &dummy); if (status == EFI_SUCCESS) return gop; @@ -510,16 +511,22 @@ find_gop(efi_guid_t *proto, unsigned long size, void **handles) return first_gop; } -static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto, - unsigned long size, void **handles) +efi_status_t efi_setup_gop(struct screen_info *si) { - efi_graphics_output_protocol_t *gop; + efi_handle_t *handles __free(efi_pool) = NULL; efi_graphics_output_protocol_mode_t *mode; efi_graphics_output_mode_info_t *info; + efi_graphics_output_protocol_t *gop; + efi_status_t status; + unsigned long num; - gop = find_gop(proto, size, handles); + status = efi_bs_call(locate_handle_buffer, EFI_LOCATE_BY_PROTOCOL, + &EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID, NULL, &num, + (void **)&handles); + if (status != EFI_SUCCESS) + return status; - /* Did we find any GOPs? */ + gop = find_gop(num, handles); if (!gop) return EFI_NOT_FOUND; @@ -551,29 +558,3 @@ static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto, return EFI_SUCCESS; } - -/* - * See if we have Graphics Output Protocol - */ -efi_status_t efi_setup_gop(struct screen_info *si, efi_guid_t *proto, - unsigned long size) -{ - efi_status_t status; - void **gop_handle = NULL; - - status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size, - (void **)&gop_handle); - if (status != EFI_SUCCESS) - return status; - - status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, proto, NULL, - &size, gop_handle); - if (status != EFI_SUCCESS) - goto free_handle; - - status = setup_gop(si, proto, size, gop_handle); - -free_handle: - efi_bs_call(free_pool, gop_handle); - return status; -} diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index 71173471faf6..53da6b5be739 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -406,24 +406,11 @@ static void setup_quirks(struct boot_params *boot_params) static void setup_graphics(struct boot_params *boot_params) { - efi_guid_t graphics_proto = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; - struct screen_info *si; - efi_status_t status; - unsigned long size; - void **gop_handle = NULL; - - si = &boot_params->screen_info; - memset(si, 0, sizeof(*si)); - - size = 0; - status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, - &graphics_proto, NULL, &size, gop_handle); - if (status == EFI_BUFFER_TOO_SMALL) - status = efi_setup_gop(si, &graphics_proto, size); + struct screen_info *si = memset(&boot_params->screen_info, 0, sizeof(*si)); + efi_setup_gop(si); } - static void __noreturn efi_exit(efi_handle_t handle, efi_status_t status) { efi_bs_call(exit, handle, status, 0, NULL); From patchwork Fri Dec 20 11:22:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 853005 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (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 40D8B1C5F11 for ; Fri, 20 Dec 2024 11:22:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693768; cv=none; b=u3bGXnxsENb6eLgqNfjfHFh19e9aXO2E3CzkUJla8LpZCafl8Wwvd/w7P0FfDQpQ/Bif71ZmrZxv3WYOVFPqpmcRYCrQxUaBkS61reV75QKxH9r84ktRYcrsaaPTIYtAxdXH1+H8on+mfqsjqgz/UAiTIjv/l1j68iTcI4wsr88= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693768; c=relaxed/simple; bh=SGrSiYKH1Bc7AsR64Qp4yCfTjgTd1Def+HVGEElIkAE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AISi6w2dKtuH7kn/avXq+Uxf3eHFtAj6PBbvcpgFUQ/4v6+05vp4aX4/+AV5/zQ++H8pNVl4oTDbiANn9NsBQaKf0TAUovYroFyIYdPvoOBRq9dPOcWkfeyxWx/xWA3jp8HsEuIQggEUpJledHx2NWwWZzptiujG4C/LwvJN4pU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Q0Gx189z; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Q0Gx189z" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4361eb83f46so14084185e9.3 for ; Fri, 20 Dec 2024 03:22:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734693765; x=1735298565; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=KivZZf0CGt5YZd1N5rZVDN/3bZWGDmqhLF0VCWNrGlI=; b=Q0Gx189zFX12xNCOP/UbaQycAJiNiZ2jkRn/VYyRkLrKPq35hmL+fduAjXW/NTPkRA 3yCMKSjb7CWMjfdy2i+A26ty+NJ6NuZe+ZH6byNlZgmz6HOHqqfbbhlx3XAervWsbQu2 oOg2X7qG1WiocgX/oBul4OuTrMgYtuh9kZAZ31ntc4VScrCu5wqikqRAbvbxld1uuBqL b8Z+q1MR7sV2uv4S1IkwpLeW7o6bJOJct9IJGCSF4+Sh+AQrB+zJfhz2IT5ug01yGuEb k1XueW7+n2SYI8C8PSSkzLO7EVVezHIA59hGWF+fOEVsnTDs/Vw2wNoPS5aYbhdDjSCi n8Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734693765; x=1735298565; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KivZZf0CGt5YZd1N5rZVDN/3bZWGDmqhLF0VCWNrGlI=; b=I70DSiRcTs46NfrhjzCTwUPlYqanVOk2qQyG83Ko7PhzO7dY42kCb6VpfW/unD61XX lnYUxZxT1CO6TGy4fJDOR6pKoWbiZ/73cuGWQvuNQfZYv7XX8NF9xo19uxo473FG/IhO VU+pYRaSEEGWRXhoilW2WDYQmJGvELNxxNycEqTrYB1aaiI3akeC4Xl/8zBFXGY6JuYp Clk0VMr1MPEjD7njNAxCc+vFSewbGXW9rFuV6SlLV48QnF+mjKaHJOQpS7vZsS18W604 h7/MbhNU99SSBmBDm/WMtXzNJMwMLj8BXewck6+v9lHHa0cWRlamygKM5qZGKKDkbv7Q LRnA== X-Gm-Message-State: AOJu0YyoGhcXAxMfoN4RSIHJkcRKBqvMXfxJRRTnIYa1SfRnIv+qH+C6 8fWXIsLKzMMXyJlqBd9DhvL3qJfLdfliSLJNrn3Nf/jPjybh7ns9IUqvQEzlWJtY03EP+1F0eEs 9Ouz4JqpTeNYQUTcWjHUGrmHuDIMmMRoNOydQzAndTHMrdNYZPWU6qV4WPtz4P0lsHoOMA9YfY6 cRtLOj1qPNpd2u2y6xZ2e6n8UnGQ== X-Google-Smtp-Source: AGHT+IHC2StE8w43211zdACLPVBjHL2cKB1h4Sdbs6jqqq4BEWyOvYApZkjHXnA7nXifadO5sC+79YM5 X-Received: from wmbay20.prod.google.com ([2002:a05:600c:1e14:b0:436:1995:1888]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:294c:b0:436:51bb:7a53 with SMTP id 5b1f17b1804b1-43668643ba9mr22260165e9.12.1734693764897; Fri, 20 Dec 2024 03:22:44 -0800 (PST) Date: Fri, 20 Dec 2024 12:22:19 +0100 In-Reply-To: <20241220112214.2598872-9-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220112214.2598872-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=10137; i=ardb@kernel.org; h=from:subject; bh=Ic6NiX9fQ6lT7lNuflzIZfufNkdIR4/g+eMpwHkmBdc=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT01ODfiYuCGtftmZ942vuz2cdP/xeusj0hMTtz4cra2Z dPG6CdTO0pZGMQ4GGTFFFkEZv99t/P0RKla51myMHNYmUCGMHBxCsBETuczMsyuMvhQYLVNZkng 8h3p2t47ndYyWW+vfvjt1stfE5/Jrq5l+Kce9Hnd05LQCMFDj97+/BPu+1BffzHbrRuJ678u/BM suZIXAA== X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220112214.2598872-13-ardb+git@google.com> Subject: [PATCH 4/7] efi/libstub: Refactor and cleanup GOP resolution picker code From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel From: Ard Biesheuvel The EFI stub implements various ways of setting the resolution of the EFI framebuffer at boot, which duplicate a lot of boilerplate for iterating over the supported modes and extracting the resolution and color depth. Refactor this into a single helper that takes a callback, and use it for the 'auto', 'list' and 'res' selection methods. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/gop.c | 265 ++++++++------------ 1 file changed, 103 insertions(+), 162 deletions(-) diff --git a/drivers/firmware/efi/libstub/gop.c b/drivers/firmware/efi/libstub/gop.c index fce28488c76c..1e1ec0113904 100644 --- a/drivers/firmware/efi/libstub/gop.c +++ b/drivers/firmware/efi/libstub/gop.c @@ -133,13 +133,11 @@ void efi_parse_option_graphics(char *option) static u32 choose_mode_modenum(efi_graphics_output_protocol_t *gop) { - efi_status_t status; - + efi_graphics_output_mode_info_t *info __free(efi_pool) = NULL; efi_graphics_output_protocol_mode_t *mode; - efi_graphics_output_mode_info_t *info; unsigned long info_size; - u32 max_mode, cur_mode; + efi_status_t status; int pf; mode = efi_table_attr(gop, mode); @@ -154,17 +152,13 @@ static u32 choose_mode_modenum(efi_graphics_output_protocol_t *gop) return cur_mode; } - status = efi_call_proto(gop, query_mode, cmdline.mode, - &info_size, &info); + status = efi_call_proto(gop, query_mode, cmdline.mode, &info_size, &info); if (status != EFI_SUCCESS) { efi_err("Couldn't get mode information\n"); return cur_mode; } pf = info->pixel_format; - - efi_bs_call(free_pool, info); - if (pf == PIXEL_BLT_ONLY || pf >= PIXEL_FORMAT_MAX) { efi_err("Invalid PixelFormat\n"); return cur_mode; @@ -173,6 +167,28 @@ static u32 choose_mode_modenum(efi_graphics_output_protocol_t *gop) return cmdline.mode; } +static u32 choose_mode(efi_graphics_output_protocol_t *gop, + bool (*match)(const efi_graphics_output_mode_info_t *, u32, void *), + void *ctx) +{ + efi_graphics_output_protocol_mode_t *mode = efi_table_attr(gop, mode); + u32 max_mode = efi_table_attr(mode, max_mode); + + for (u32 m = 0; m < max_mode; m++) { + efi_graphics_output_mode_info_t *info __free(efi_pool) = NULL; + unsigned long info_size; + efi_status_t status; + + status = efi_call_proto(gop, query_mode, m, &info_size, &info); + if (status != EFI_SUCCESS) + continue; + + if (match(info, m, ctx)) + return m; + } + return (unsigned long)ctx; +} + static u8 pixel_bpp(int pixel_format, efi_pixel_bitmask_t pixel_info) { if (pixel_format == PIXEL_BIT_MASK) { @@ -185,192 +201,117 @@ static u8 pixel_bpp(int pixel_format, efi_pixel_bitmask_t pixel_info) return 32; } -static u32 choose_mode_res(efi_graphics_output_protocol_t *gop) +static bool match_res(const efi_graphics_output_mode_info_t *info, u32 mode, void *ctx) { - efi_status_t status; + efi_pixel_bitmask_t pi = info->pixel_information; + int pf = info->pixel_format; - efi_graphics_output_protocol_mode_t *mode; - efi_graphics_output_mode_info_t *info; - unsigned long info_size; - - u32 max_mode, cur_mode; - int pf; - efi_pixel_bitmask_t pi; - u32 m, w, h; + if (pf == PIXEL_BLT_ONLY || pf >= PIXEL_FORMAT_MAX) + return false; - mode = efi_table_attr(gop, mode); + return cmdline.res.width == info->horizontal_resolution && + cmdline.res.height == info->vertical_resolution && + (cmdline.res.format < 0 || cmdline.res.format == pf) && + (!cmdline.res.depth || cmdline.res.depth == pixel_bpp(pf, pi)); +} - cur_mode = efi_table_attr(mode, mode); - info = efi_table_attr(mode, info); - pf = info->pixel_format; - pi = info->pixel_information; - w = info->horizontal_resolution; - h = info->vertical_resolution; +static u32 choose_mode_res(efi_graphics_output_protocol_t *gop) +{ + efi_graphics_output_protocol_mode_t *mode = efi_table_attr(gop, mode); + unsigned long cur_mode = efi_table_attr(mode, mode); - if (w == cmdline.res.width && h == cmdline.res.height && - (cmdline.res.format < 0 || cmdline.res.format == pf) && - (!cmdline.res.depth || cmdline.res.depth == pixel_bpp(pf, pi))) + if (match_res(efi_table_attr(mode, info), cur_mode, NULL)) return cur_mode; - max_mode = efi_table_attr(mode, max_mode); - - for (m = 0; m < max_mode; m++) { - if (m == cur_mode) - continue; - - status = efi_call_proto(gop, query_mode, m, - &info_size, &info); - if (status != EFI_SUCCESS) - continue; + return choose_mode(gop, match_res, (void *)cur_mode); +} - pf = info->pixel_format; - pi = info->pixel_information; - w = info->horizontal_resolution; - h = info->vertical_resolution; +struct match { + u32 mode; + u32 area; + u8 depth; +}; - efi_bs_call(free_pool, info); +static bool match_auto(const efi_graphics_output_mode_info_t *info, u32 mode, void *ctx) +{ + u32 area = info->horizontal_resolution * info->vertical_resolution; + efi_pixel_bitmask_t pi = info->pixel_information; + int pf = info->pixel_format; + u8 depth = pixel_bpp(pf, pi); + struct match *m = ctx; - if (pf == PIXEL_BLT_ONLY || pf >= PIXEL_FORMAT_MAX) - continue; - if (w == cmdline.res.width && h == cmdline.res.height && - (cmdline.res.format < 0 || cmdline.res.format == pf) && - (!cmdline.res.depth || cmdline.res.depth == pixel_bpp(pf, pi))) - return m; - } + if (pf == PIXEL_BLT_ONLY || pf >= PIXEL_FORMAT_MAX) + return false; - efi_err("Couldn't find requested mode\n"); + if (area > m->area || (area == m->area && depth > m->depth)) + *m = (struct match){ mode, area, depth }; - return cur_mode; + return false; } static u32 choose_mode_auto(efi_graphics_output_protocol_t *gop) { - efi_status_t status; + struct match match = {}; - efi_graphics_output_protocol_mode_t *mode; - efi_graphics_output_mode_info_t *info; - unsigned long info_size; + choose_mode(gop, match_auto, &match); - u32 max_mode, cur_mode, best_mode, area; - u8 depth; - int pf; - efi_pixel_bitmask_t pi; - u32 m, w, h, a; - u8 d; - - mode = efi_table_attr(gop, mode); - - cur_mode = efi_table_attr(mode, mode); - max_mode = efi_table_attr(mode, max_mode); - - info = efi_table_attr(mode, info); - - pf = info->pixel_format; - pi = info->pixel_information; - w = info->horizontal_resolution; - h = info->vertical_resolution; - - best_mode = cur_mode; - area = w * h; - depth = pixel_bpp(pf, pi); - - for (m = 0; m < max_mode; m++) { - if (m == cur_mode) - continue; - - status = efi_call_proto(gop, query_mode, m, - &info_size, &info); - if (status != EFI_SUCCESS) - continue; + return match.mode; +} - pf = info->pixel_format; - pi = info->pixel_information; - w = info->horizontal_resolution; - h = info->vertical_resolution; +static bool match_list(const efi_graphics_output_mode_info_t *info, u32 mode, void *ctx) +{ + efi_pixel_bitmask_t pi = info->pixel_information; + u32 cur_mode = (unsigned long)ctx; + int pf = info->pixel_format; + const char *dstr; + bool valid; + u8 depth; - efi_bs_call(free_pool, info); + valid = !(pf == PIXEL_BLT_ONLY || pf >= PIXEL_FORMAT_MAX); - if (pf == PIXEL_BLT_ONLY || pf >= PIXEL_FORMAT_MAX) - continue; - a = w * h; - if (a < area) - continue; - d = pixel_bpp(pf, pi); - if (a > area || d > depth) { - best_mode = m; - area = a; - depth = d; - } + switch (pf) { + case PIXEL_RGB_RESERVED_8BIT_PER_COLOR: + dstr = "rgb"; + break; + case PIXEL_BGR_RESERVED_8BIT_PER_COLOR: + dstr = "bgr"; + break; + case PIXEL_BIT_MASK: + dstr = ""; + depth = pixel_bpp(pf, pi); + break; + case PIXEL_BLT_ONLY: + dstr = "blt"; + break; + default: + dstr = "xxx"; + break; } - return best_mode; + efi_printk("Mode %3u %c%c: Resolution %ux%u-%s%.0hhu\n", + mode, + (mode == cur_mode) ? '*' : ' ', + !valid ? '-' : ' ', + info->horizontal_resolution, + info->vertical_resolution, + dstr, depth); + + return false; } static u32 choose_mode_list(efi_graphics_output_protocol_t *gop) { - efi_status_t status; - - efi_graphics_output_protocol_mode_t *mode; - efi_graphics_output_mode_info_t *info; - unsigned long info_size; - - u32 max_mode, cur_mode; - int pf; - efi_pixel_bitmask_t pi; - u32 m, w, h; - u8 d; - const char *dstr; - bool valid; + efi_graphics_output_protocol_mode_t *mode = efi_table_attr(gop, mode); + unsigned long cur_mode = efi_table_attr(mode, mode); + u32 max_mode = efi_table_attr(mode, max_mode); efi_input_key_t key; - - mode = efi_table_attr(gop, mode); - - cur_mode = efi_table_attr(mode, mode); - max_mode = efi_table_attr(mode, max_mode); + efi_status_t status; efi_printk("Available graphics modes are 0-%u\n", max_mode-1); efi_puts(" * = current mode\n" " - = unusable mode\n"); - for (m = 0; m < max_mode; m++) { - status = efi_call_proto(gop, query_mode, m, - &info_size, &info); - if (status != EFI_SUCCESS) - continue; - pf = info->pixel_format; - pi = info->pixel_information; - w = info->horizontal_resolution; - h = info->vertical_resolution; - - efi_bs_call(free_pool, info); - - valid = !(pf == PIXEL_BLT_ONLY || pf >= PIXEL_FORMAT_MAX); - d = 0; - switch (pf) { - case PIXEL_RGB_RESERVED_8BIT_PER_COLOR: - dstr = "rgb"; - break; - case PIXEL_BGR_RESERVED_8BIT_PER_COLOR: - dstr = "bgr"; - break; - case PIXEL_BIT_MASK: - dstr = ""; - d = pixel_bpp(pf, pi); - break; - case PIXEL_BLT_ONLY: - dstr = "blt"; - break; - default: - dstr = "xxx"; - break; - } - - efi_printk("Mode %3u %c%c: Resolution %ux%u-%s%.0hhu\n", - m, - m == cur_mode ? '*' : ' ', - !valid ? '-' : ' ', - w, h, dstr, d); - } + choose_mode(gop, match_list, (void *)cur_mode); efi_puts("\nPress any key to continue (or wait 10 seconds)\n"); status = efi_wait_for_key(10 * EFI_USEC_PER_SEC, &key); From patchwork Fri Dec 20 11:22:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 852583 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 68E981C5F2D for ; Fri, 20 Dec 2024 11:22:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693770; cv=none; b=tHiQrv/zODY+JgWfVTm0898oExJo8KS3XXuJz4pQ88kqQNd5AVsjEqMUnASYFGoYoVo7shUS7cUw0yVl9OCckUuSEGAQjIzW2DmI/pMFPsQWFQ2OBG/OreqtxdI90RNuGFuNLwH/EPE53N15xehykWLIEeE/Spo5oRWmnOU99qo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693770; c=relaxed/simple; bh=jQFPnAR/lQIH41XKJNrgOYB+xxnzwuDMJoLacFjQ9Rg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ow02vIC2bamVpyQAR3Q+Xav/nxOgHYovr10BTYUUfzLAOYlASX8EQzljEsd6vvMBi8mSQwPxyZKjjMib5WuJ15mU/MOfv7fBorT9JGSrynmZ90bC4hI3CDj70mPPgKB/KfH1B2MqyG+P0DEBEoxy0ZKgwB9FJOVhLDSV02GGgeI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Lthm7nYl; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Lthm7nYl" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-43651b1ba8aso14023185e9.1 for ; Fri, 20 Dec 2024 03:22:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734693767; x=1735298567; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4ZdfudFQMgX/SPnuBiPXL83yln9iyupuULighNWJ+Tk=; b=Lthm7nYlaizzC5fYhDMLy5wq/qv6kgIrADGeewIxg5NXyjM8MJM552lHyHZd4fIgzp xS8PDxCZ5ifQ9rN4zSduix085J1pomssYh/HcZyeXw5TOT9hQmIP/G7Ohc+B2SbDCKRM 2+gt25aMJgIChJeJMG5PBbsz8pfMlRdtHxR1LH6ING6EzeRi7yU3LdNigQoprdGUFdP+ bZz+q5ANdcYDsX6Q5uPtY7yTiSJzeFkQmAm+KDPUW7pLSY9O8FB1kdVxkWo0HuScgYk3 k6/bFRLwOQ6vHOzkLZiW04I3vU0Eh5L2L08+z8uylCHPOCQZnsIu1mpl778HNHpOB4qE OuKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734693767; x=1735298567; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4ZdfudFQMgX/SPnuBiPXL83yln9iyupuULighNWJ+Tk=; b=gykesMGGsThssugoz1GjLsszflPTSITM5WCsBY74kUptffOxYsIX5OT/S72hE90pm2 gXK8rHmxeVKQmJtZ452WUkcu9wDrU51DRWrz7aK82AftY2PXqBt1XLglKP05XaEfXE+n ZZ90PWaSllTMhBSNnX8gj8YjIF3SqcOMvCDtMaM60k1j2FI91DDzYcdwrZOg9HH9DVKY cMYqefHVqfT9tDXg/fZyZCTUFg3EGtKb4YqowsgCFQ0D4ZJ+wUs1v/24XcBlSY2R+m7N JSqOlMUGFZGfKg11HqMbSev2IZ5wQwhkJFeWPrE5iOQm52xsEsGc375d6wgDnWhSmjTS 3kSg== X-Gm-Message-State: AOJu0Yzjcw5TlSVsKC12njYYPShdrs+c2DZrZRrPO/ESJtZgHIF8xCD5 JvqU9uYDGsGtnDpFG88ZvQWayL6PzRO0ZH3NQpH+oAJ5wS7C0z8zv9oHKZ2fUosX2jOXqEo4t3Z sjyhxU5GIVSInQ3nfT0OuULwcEFAmufwGAg6yf/DDtv2cAqZk5tSGs+6g7i9b8YkLaksOH6BN5D 6PkKXRREZ+8LnmhnoLwNc7VdI6lw== X-Google-Smtp-Source: AGHT+IHImMIL/xdHSaYtb96ILTwp8HE90q+uERYMRCTtZuhOxoziiMyV2AhqGsbIAkkH0hOTaJxgqEkG X-Received: from wmbjn12.prod.google.com ([2002:a05:600c:6b0c:b0:435:4bd2:1dcd]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4f0d:b0:432:cbe5:4f09 with SMTP id 5b1f17b1804b1-43671247b46mr135995e9.4.1734693766818; Fri, 20 Dec 2024 03:22:46 -0800 (PST) Date: Fri, 20 Dec 2024 12:22:20 +0100 In-Reply-To: <20241220112214.2598872-9-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220112214.2598872-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=4607; i=ardb@kernel.org; h=from:subject; bh=/nPnk008oitHG0r/EWed5C0pBvsJuMEBmFXGRgsWLSY=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT01OO+93t8LRY/mx0t1/z/ZcN/bTHdNtaiz7r95X93/f RT+UCLbUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACbys5GRYa9ydezH/SHZuUny nZcesfR/jRU6fMW0btNbWR6vyXqTnRn+ypbIHJf3V7fPUO0M3b1yE9ObHS6feZfLhrM9LFjitNS XAQA= X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220112214.2598872-14-ardb+git@google.com> Subject: [PATCH 5/7] efi/libstub: Simplify PCI I/O handle buffer traversal From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel From: Ard Biesheuvel Use LocateHandleBuffer() and a __free() cleanup helper to simplify the PCI I/O handle buffer traversal code. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/pci.c | 33 +++++--------------- drivers/firmware/efi/libstub/x86-stub.c | 29 ++++------------- 2 files changed, 13 insertions(+), 49 deletions(-) diff --git a/drivers/firmware/efi/libstub/pci.c b/drivers/firmware/efi/libstub/pci.c index b0ba372c26c5..e32d1fdb1fc7 100644 --- a/drivers/firmware/efi/libstub/pci.c +++ b/drivers/firmware/efi/libstub/pci.c @@ -16,36 +16,20 @@ void efi_pci_disable_bridge_busmaster(void) { efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; - unsigned long pci_handle_size = 0; - efi_handle_t *pci_handle = NULL; + efi_handle_t *pci_handle __free(efi_pool) = NULL; + unsigned long pci_handle_num; efi_handle_t handle; efi_status_t status; u16 class, command; - status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, &pci_proto, - NULL, &pci_handle_size, NULL); - - if (status != EFI_BUFFER_TOO_SMALL) { - if (status != EFI_SUCCESS && status != EFI_NOT_FOUND) - efi_err("Failed to locate PCI I/O handles'\n"); - return; - } - - status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, pci_handle_size, - (void **)&pci_handle); - if (status != EFI_SUCCESS) { - efi_err("Failed to allocate memory for 'pci_handle'\n"); - return; - } - - status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, &pci_proto, - NULL, &pci_handle_size, pci_handle); + status = efi_bs_call(locate_handle_buffer, EFI_LOCATE_BY_PROTOCOL, + &pci_proto, NULL, &pci_handle_num, pci_handle); if (status != EFI_SUCCESS) { efi_err("Failed to locate PCI I/O handles'\n"); - goto free_handle; + return; } - for_each_efi_handle(handle, pci_handle, efi_get_handle_num(pci_handle_size)) { + for_each_efi_handle(handle, pci_handle, pci_handle_num) { efi_pci_io_protocol_t *pci; unsigned long segment_nr, bus_nr, device_nr, func_nr; @@ -81,7 +65,7 @@ void efi_pci_disable_bridge_busmaster(void) efi_bs_call(disconnect_controller, handle, NULL, NULL); } - for_each_efi_handle(handle, pci_handle, efi_get_handle_num(pci_handle_size)) { + for_each_efi_handle(handle, pci_handle, pci_handle_num) { efi_pci_io_protocol_t *pci; status = efi_bs_call(handle_protocol, handle, &pci_proto, @@ -107,7 +91,4 @@ void efi_pci_disable_bridge_busmaster(void) if (status != EFI_SUCCESS) efi_err("Failed to disable PCI busmastering\n"); } - -free_handle: - efi_bs_call(free_pool, pci_handle); } diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index 53da6b5be739..4a3487e5dfc8 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -119,37 +119,23 @@ preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) static void setup_efi_pci(struct boot_params *params) { efi_status_t status; - void **pci_handle = NULL; + efi_handle_t *pci_handle __free(efi_pool) = NULL; efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; - unsigned long size = 0; struct setup_data *data; + unsigned long num; efi_handle_t h; - status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, - &pci_proto, NULL, &size, pci_handle); - - if (status == EFI_BUFFER_TOO_SMALL) { - status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size, - (void **)&pci_handle); - - if (status != EFI_SUCCESS) { - efi_err("Failed to allocate memory for 'pci_handle'\n"); - return; - } - - status = efi_bs_call(locate_handle, EFI_LOCATE_BY_PROTOCOL, - &pci_proto, NULL, &size, pci_handle); - } - + status = efi_bs_call(locate_handle_buffer, EFI_LOCATE_BY_PROTOCOL, + &pci_proto, NULL, &num, pci_handle); if (status != EFI_SUCCESS) - goto free_handle; + return; data = (struct setup_data *)(unsigned long)params->hdr.setup_data; while (data && data->next) data = (struct setup_data *)(unsigned long)data->next; - for_each_efi_handle(h, pci_handle, efi_get_handle_num(size)) { + for_each_efi_handle(h, pci_handle, num) { efi_pci_io_protocol_t *pci = NULL; struct pci_setup_rom *rom; @@ -169,9 +155,6 @@ static void setup_efi_pci(struct boot_params *params) data = (struct setup_data *)rom; } - -free_handle: - efi_bs_call(free_pool, pci_handle); } static void retrieve_apple_device_properties(struct boot_params *boot_params) From patchwork Fri Dec 20 11:22:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 853004 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) (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 573931C6F70 for ; Fri, 20 Dec 2024 11:22:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693772; cv=none; b=FqkL+NcnljcQcCPk/nzg7RTS9IC8ztyt4LM/9Jitxkb4RkpOsdOFf0VRCvuzWZttgIWjw5r94+3Kt9AG6ZD3TN6ccTxcMa/muO8Nndo6k8XJwhLVMVP5v2WRn9Z/KBId6Be1e0ly+5WG3tcSxAzVq0Rr1MffMl18Fvy/jMYzzlA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693772; c=relaxed/simple; bh=lVMPdicFtyOL832rAMJvK98velTQ2FkjUowJ3Igxmkg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=t6gmCYlkORyPFEbYNwUSE2TJYFmK1yRiCMJ0K5iys7uJ1GwdRFPPzppclrKCQCBzqS3Ztr6VkaXxg8ZFy3/4hEletT6SDz4Yus7zjbea3DtoqQOjdFiRgBCUpYuQFWTCEno8eg/71zLMT/Bga+F9RKO5gFwX189vjtV3g7xc8dE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=c1f+1x0n; arc=none smtp.client-ip=209.85.221.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="c1f+1x0n" Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-385d80576abso1137784f8f.3 for ; Fri, 20 Dec 2024 03:22:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734693769; x=1735298569; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=5Mq2zGEkSU736hh4kdcV8OEsSkyXvgmpNv1UZJcoKL4=; b=c1f+1x0nPqy8YYq12Lnf8Pl2dYs0Rrcb/uckYzeQC7Uob548SVwyQAo2FBqKN0PHQa SCl9rIOw7QUs49cI4B9PIxr3anZeK3Wb3pBwYBAIhtL7FvwPBoMsNK0m3p/R1HLCfbMI EYfe1YpvVSyrIWsGLiPZwV5geosbXMgXLs4x07Pmvr/LM/WHbXazu5Fh57ELTBKYPjdy I+b/Q5ujhgisn2mJAE5JjKtSQAlT1FRKHt1MRlnYpe1IvR3GbCYPeqbAuvWNVWA8msWZ yxUHhiNxCtrT2YcNEHmFnikzldLKw3yiA/TUwDp4AjphD+QVap5SJ5zJEJG4IreaisD9 4MVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734693769; x=1735298569; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5Mq2zGEkSU736hh4kdcV8OEsSkyXvgmpNv1UZJcoKL4=; b=bNjOtHkRQb46cx6IE7ctUT/TjnpHo0wMMaOwSyAKn4E278Znevk8fS4lRai4deFblK lYhrCnifiijzwfXwdEm8IHV1F/HtvKX1/2h9H+xtAaCPU2XQ6RQSJzqLSqmNnEjMKKov shgyQtG5Rk9Rf8YFhWgbFacWxPXvDFzF+S701z44Un3LvUkItg0v1KkQ4qXcW3QrZpyR mtxhxAz0ZEVTOOwJfIgP6OhpsI8gKOtt5hUb5VHC47Xr/VNnWy2g/ibb8Zg2gq1jlzAU n5NY96rY7L2ISShVjV+0aMCqjcFQyeGOSAO5QdMAcRkyoKzX7a7pqxPletMWsLLamMDN 8FBg== X-Gm-Message-State: AOJu0Yzvsg98Fe6tDCbsIY8Ec2uhpZs8J9o+yc5Ks0yNcbRbJ9wSp9Ek 30Ja3XQLfAmL0+K1T7PyVPGYqT3pT4pjz8MMpo1PkwH/7te+F1LZ2zDX2oVW2W+xuNOhtU2u/xB YwjqdzSM1wcMwK+1zSEuTd+ebU61f5PW5E1i7OszxgMNFAk8FvukpliXPX3gFY6hSnEfsJBc2XT MzZTUiHvfiQMQH3qTYKSNvcs6xwA== X-Google-Smtp-Source: AGHT+IHEnq1PDrJx6ZoitqXOfRW6JfLWhdmj4+pCY+eWOZ7BG4KZEaQvyMHTmEkr7l76dh8wiKxxSpq3 X-Received: from wmbhn29.prod.google.com ([2002:a05:600c:a39d:b0:434:fe74:1bd5]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:18a9:b0:386:3835:9fff with SMTP id ffacd0b85a97d-38a22406d43mr2840931f8f.59.1734693768819; Fri, 20 Dec 2024 03:22:48 -0800 (PST) Date: Fri, 20 Dec 2024 12:22:21 +0100 In-Reply-To: <20241220112214.2598872-9-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220112214.2598872-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=5660; i=ardb@kernel.org; h=from:subject; bh=YLK9emTD2b7V0uTyYE0d8W4Cjh6Qxt9ydF/yoBPkTls=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT01uGA9p+/C/+d1M41rLlxd19jocPr/Arv0U/Fzxee3a JYbb1zSUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACYiP4+RYcKhTeIZahGT3r+I zW6wdkhVfM74zO53rdXvrQ/s1+11DGX477fiu1NYxLHJp1Ke7WBcccz00szb/HunLPzXt/xmI8P JjcwA X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220112214.2598872-15-ardb+git@google.com> Subject: [PATCH 6/7] efi/libstub: Use cleanup helpers for freeing copies of the memory map From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel From: Ard Biesheuvel The EFI stub may obtain the memory map from the firmware numerous times, and this involves doing a EFI pool allocation first, which needs to be freed after use. Streamline this using a cleanup helper, which makes the code easier to follow. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/kaslr.c | 4 +--- drivers/firmware/efi/libstub/mem.c | 20 ++++++++------------ drivers/firmware/efi/libstub/randomalloc.c | 4 +--- drivers/firmware/efi/libstub/relocate.c | 10 ++++------ drivers/firmware/efi/libstub/x86-stub.c | 11 ++++++----- 5 files changed, 20 insertions(+), 29 deletions(-) diff --git a/drivers/firmware/efi/libstub/kaslr.c b/drivers/firmware/efi/libstub/kaslr.c index 6318c40bda38..4bc963e999eb 100644 --- a/drivers/firmware/efi/libstub/kaslr.c +++ b/drivers/firmware/efi/libstub/kaslr.c @@ -57,7 +57,7 @@ u32 efi_kaslr_get_phys_seed(efi_handle_t image_handle) */ static bool check_image_region(u64 base, u64 size) { - struct efi_boot_memmap *map; + struct efi_boot_memmap *map __free(efi_pool) = NULL; efi_status_t status; bool ret = false; int map_offset; @@ -80,8 +80,6 @@ static bool check_image_region(u64 base, u64 size) } } - efi_bs_call(free_pool, map); - return ret; } diff --git a/drivers/firmware/efi/libstub/mem.c b/drivers/firmware/efi/libstub/mem.c index 4f1fa302234d..9c82259eea81 100644 --- a/drivers/firmware/efi/libstub/mem.c +++ b/drivers/firmware/efi/libstub/mem.c @@ -20,10 +20,10 @@ efi_status_t efi_get_memory_map(struct efi_boot_memmap **map, bool install_cfg_tbl) { + struct efi_boot_memmap tmp, *m __free(efi_pool) = NULL; int memtype = install_cfg_tbl ? EFI_ACPI_RECLAIM_MEMORY : EFI_LOADER_DATA; efi_guid_t tbl_guid = LINUX_EFI_BOOT_MEMMAP_GUID; - struct efi_boot_memmap *m, tmp; efi_status_t status; unsigned long size; @@ -48,24 +48,20 @@ efi_status_t efi_get_memory_map(struct efi_boot_memmap **map, */ status = efi_bs_call(install_configuration_table, &tbl_guid, m); if (status != EFI_SUCCESS) - goto free_map; + return status; } m->buff_size = m->map_size = size; status = efi_bs_call(get_memory_map, &m->map_size, m->map, &m->map_key, &m->desc_size, &m->desc_ver); - if (status != EFI_SUCCESS) - goto uninstall_table; + if (status != EFI_SUCCESS) { + if (install_cfg_tbl) + efi_bs_call(install_configuration_table, &tbl_guid, NULL); + return status; + } - *map = m; + *map = no_free_ptr(m); return EFI_SUCCESS; - -uninstall_table: - if (install_cfg_tbl) - efi_bs_call(install_configuration_table, &tbl_guid, NULL); -free_map: - efi_bs_call(free_pool, m); - return status; } /** diff --git a/drivers/firmware/efi/libstub/randomalloc.c b/drivers/firmware/efi/libstub/randomalloc.c index c41e7b2091cd..e5872e38d9a4 100644 --- a/drivers/firmware/efi/libstub/randomalloc.c +++ b/drivers/firmware/efi/libstub/randomalloc.c @@ -59,9 +59,9 @@ efi_status_t efi_random_alloc(unsigned long size, unsigned long alloc_min, unsigned long alloc_max) { + struct efi_boot_memmap *map __free(efi_pool) = NULL; unsigned long total_slots = 0, target_slot; unsigned long total_mirrored_slots = 0; - struct efi_boot_memmap *map; efi_status_t status; int map_offset; @@ -130,7 +130,5 @@ efi_status_t efi_random_alloc(unsigned long size, break; } - efi_bs_call(free_pool, map); - return status; } diff --git a/drivers/firmware/efi/libstub/relocate.c b/drivers/firmware/efi/libstub/relocate.c index d694bcfa1074..99b45d1cd624 100644 --- a/drivers/firmware/efi/libstub/relocate.c +++ b/drivers/firmware/efi/libstub/relocate.c @@ -23,14 +23,14 @@ efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align, unsigned long *addr, unsigned long min) { - struct efi_boot_memmap *map; + struct efi_boot_memmap *map __free(efi_pool) = NULL; efi_status_t status; unsigned long nr_pages; int i; status = efi_get_memory_map(&map, false); if (status != EFI_SUCCESS) - goto fail; + return status; /* * Enforce minimum alignment that EFI or Linux requires when @@ -79,11 +79,9 @@ efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align, } if (i == map->map_size / map->desc_size) - status = EFI_NOT_FOUND; + return EFI_NOT_FOUND; - efi_bs_call(free_pool, map); -fail: - return status; + return EFI_SUCCESS; } /** diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index 4a3487e5dfc8..4dfd25e6ac71 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -616,7 +616,7 @@ static efi_status_t allocate_e820(struct boot_params *params, struct setup_data **e820ext, u32 *e820ext_size) { - struct efi_boot_memmap *map; + struct efi_boot_memmap *map __free(efi_pool) = NULL; efi_status_t status; __u32 nr_desc; @@ -630,13 +630,14 @@ static efi_status_t allocate_e820(struct boot_params *params, EFI_MMAP_NR_SLACK_SLOTS; status = alloc_e820ext(nr_e820ext, e820ext, e820ext_size); + if (status != EFI_SUCCESS) + return status; } - if (IS_ENABLED(CONFIG_UNACCEPTED_MEMORY) && status == EFI_SUCCESS) - status = allocate_unaccepted_bitmap(nr_desc, map); + if (IS_ENABLED(CONFIG_UNACCEPTED_MEMORY)) + return allocate_unaccepted_bitmap(nr_desc, map); - efi_bs_call(free_pool, map); - return status; + return EFI_SUCCESS; } struct exit_boot_struct { From patchwork Fri Dec 20 11:22:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 852582 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 30ED61CBE95 for ; Fri, 20 Dec 2024 11:22:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693774; cv=none; b=FnXio8vOS8f2sVg5wXKiy8TqAx7+Nfu3rP5bj486LF5ux9yV0W+1pCrzfZ5wl8shwC4o0Y7J/hOAlr/R/It87ZZOyW9zH6bLvpWjIezI8cIjwTJpTxV7KqrucJkbeZaVfXM1wEtUGq4Ye4TXZQjYbBidBsSHtDkyLvoRv43jDjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734693774; c=relaxed/simple; bh=16iKVImPte4Q3WShcCqcfMjR3u7rPsH1PIwZqgFwKNU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ufuPJcmT6R4nCvT9DLCVAAoOd0q8DomeC6zksjdpWJmhy6EMznIGvlD+jZYlJFi9R1Htmi5agLP+bJUO0em+OQk9mO6mf+jSgdkKvbaiKt53m2+EaP7bgmMgfE0RwVqy4wK6XCWsLJcWNExyeN3mMj0FmHfu5qmzzTGLu+0VN9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=B3oJQL++; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="B3oJQL++" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-4362552ce62so10217285e9.0 for ; Fri, 20 Dec 2024 03:22:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1734693771; x=1735298571; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lHLbvVQPBhBByrX4m9XvjRmmcb5HxLT/kjwhrJBKnr8=; b=B3oJQL++P+8lIoOYwXm6YwtQjn22MyYyG1Ay7xeokPlH8HQi3j6zWYF5cgE6N/ObBH 37w+wirEV/3ChyTAan8JXG9HRPZN/AqCxnXh+XrrvoC5puEZYv5JUOls3md/rQgXgDq6 XAdb/iV2Xjv8M/NqmDtw/Ju3xge2obg2pzGOYVXlzWQtHfVsVXqCF9txWwm5aymoBH3M NnCApqPcHdCo1uPD90UzwzM+CdRtJ9x0kANPmJalNXkNsnYdSJLpeh5Q5mnkgzXfehvf WYr1OB5Xdoix3eua/PRnE/qgSP6dhvYReEYHNHMdSeQ11ZoPGXXuG3vyFoixYC8F01ND autg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734693771; x=1735298571; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lHLbvVQPBhBByrX4m9XvjRmmcb5HxLT/kjwhrJBKnr8=; b=bnoEd/sKI38SBd0ycAP2jskBOd7rWwYCK4+NHc3nYvEQ6tjBmFa0WEg0VLw/kUWlcC b2rAEMeLM5DTyjmnjCxLqTMAmPvWlZu25cWuYAqVu2bUxMWYqpO25lVir+i0TR3ccOin el8VZK8URXhgoPBcL8taiZcT9a347K0/IWBo/2sk6/qAoFB/606pwfT1YlhyQSLXJspV AyT8hJugtHcUIICSsz3frPaIIM30eHofD8IW9BuQ1At72F7jGKwjFt6n7GEsQrvaZxHn B+iifxfgALeicTYDL0kCSa/Zk5+aCBSw4v8LcddRjejF4q/RX5kc2xMlMM2vTHzntjbc Tf5g== X-Gm-Message-State: AOJu0YxIVJlCOe2WVRPPXPZjKIAyNnX1s9zumNhIoxf8DNhFJHAC6kuF EdutH+tR+ft2WVVUWbhm7ZSLWt0nJbtpZqtSZSwE8fIvD9wD/V5zJw4K9YsFeipG141I9cqBnls nIqLxaHZgRXkDX0z6UPOa6OatimS1kbNtlzLPqMdFOCNCQ+zeM5H/uTZC2+7G/G4pciEwXmpYBp Zd3pl1XvnZkQGQvDGUbnR/Xl7M6Q== X-Google-Smtp-Source: AGHT+IFfpcbxYvQshEs3e4Dk4tdzJxIzJwuNEo5SczSb3OkxWUkg2WxGa3gNNsxnoBpvBrIqnw0afadc X-Received: from wmox17.prod.google.com ([2002:a05:600c:1791:b0:436:164a:763e]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:a0a:b0:434:f0df:9f6 with SMTP id 5b1f17b1804b1-4366854737fmr22340085e9.3.1734693770825; Fri, 20 Dec 2024 03:22:50 -0800 (PST) Date: Fri, 20 Dec 2024 12:22:22 +0100 In-Reply-To: <20241220112214.2598872-9-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241220112214.2598872-9-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=5256; i=ardb@kernel.org; h=from:subject; bh=duZrOElq0qpO0f9uxS54lPTgiTD/koygRLoGgpOpZdc=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIT01uLDWStpYa5qlDMtEp/ZIhlWGookL9kYISh69GqrcL 92aubWjlIVBjINBVkyRRWD233c7T0+UqnWeJQszh5UJZAgDF6cATIQjkeF/Ro1n+43ZphkPVx0q m7zuYnXKS3PP1J2KE3+cvFy8JO0iB8N/l3W2Sj3f4472Tczw28Fxf3/NbNk3zgoiFcq3+y7d1ut nBwA= X-Mailer: git-send-email 2.47.1.613.gc27f4b7a9f-goog Message-ID: <20241220112214.2598872-16-ardb+git@google.com> Subject: [PATCH 7/7] efi/libstub: Use __free() helper for pool deallocations From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel From: Ard Biesheuvel Annotate some local buffer allocations as __free(efi_pool) and simplify the associated error handling accordingly. This removes a couple of gotos and simplifies the code. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efi-stub-helper.c | 9 ++++----- drivers/firmware/efi/libstub/efi-stub.c | 21 ++++++++++---------- drivers/firmware/efi/libstub/x86-stub.c | 16 ++++++--------- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index c0c81ca4237e..fd6dc790c5a8 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -47,9 +47,10 @@ bool __pure __efi_soft_reserve_enabled(void) */ efi_status_t efi_parse_options(char const *cmdline) { - size_t len; + char *buf __free(efi_pool) = NULL; efi_status_t status; - char *str, *buf; + size_t len; + char *str; if (!cmdline) return EFI_SUCCESS; @@ -102,7 +103,6 @@ efi_status_t efi_parse_options(char const *cmdline) efi_parse_option_graphics(val + strlen("efifb:")); } } - efi_bs_call(free_pool, buf); return EFI_SUCCESS; } @@ -250,7 +250,7 @@ static efi_status_t efi_measure_tagged_event(unsigned long load_addr, u64, const union efistub_event *); struct { u32 hash_log_extend_event; } mixed_mode; } method; - struct efistub_measured_event *evt; + struct efistub_measured_event *evt __free(efi_pool) = NULL; int size = struct_size(evt, tagged_event.tagged_event_data, events[event].event_data_len); efi_guid_t tcg2_guid = EFI_TCG2_PROTOCOL_GUID; @@ -312,7 +312,6 @@ static efi_status_t efi_measure_tagged_event(unsigned long load_addr, status = efi_fn_call(&method, hash_log_extend_event, protocol, 0, load_addr, load_size, &evt->event_data); - efi_bs_call(free_pool, evt); if (status == EFI_SUCCESS) return EFI_SUCCESS; diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c index 90e06a6b1a45..874f63b4a383 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -104,8 +104,8 @@ static u32 get_supported_rt_services(void) efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_ptr) { + char *cmdline __free(efi_pool) = NULL; efi_status_t status; - char *cmdline; /* * Get the command line from EFI, using the LOADED_IMAGE @@ -120,25 +120,24 @@ efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_ptr) if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) { status = efi_parse_options(cmdline); - if (status != EFI_SUCCESS) - goto fail_free_cmdline; + if (status != EFI_SUCCESS) { + efi_err("Failed to parse EFI load options\n"); + return status; + } } if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || IS_ENABLED(CONFIG_CMDLINE_FORCE) || cmdline[0] == 0) { status = efi_parse_options(CONFIG_CMDLINE); - if (status != EFI_SUCCESS) - goto fail_free_cmdline; + if (status != EFI_SUCCESS) { + efi_err("Failed to parse built-in command line\n"); + return status; + } } - *cmdline_ptr = cmdline; + *cmdline_ptr = no_free_ptr(cmdline); return EFI_SUCCESS; - -fail_free_cmdline: - efi_err("Failed to parse options\n"); - efi_bs_call(free_pool, cmdline); - return status; } efi_status_t efi_stub_common(efi_handle_t handle, diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c index 4dfd25e6ac71..6fa1d4f62e81 100644 --- a/drivers/firmware/efi/libstub/x86-stub.c +++ b/drivers/firmware/efi/libstub/x86-stub.c @@ -42,7 +42,7 @@ union sev_memory_acceptance_protocol { static efi_status_t preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) { - struct pci_setup_rom *rom = NULL; + struct pci_setup_rom *rom __free(efi_pool) = NULL; efi_status_t status; unsigned long size; uint64_t romsize; @@ -75,14 +75,13 @@ preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) rom->data.len = size - sizeof(struct setup_data); rom->data.next = 0; rom->pcilen = romsize; - *__rom = rom; status = efi_call_proto(pci, pci.read, EfiPciIoWidthUint16, PCI_VENDOR_ID, 1, &rom->vendor); if (status != EFI_SUCCESS) { efi_err("Failed to read rom->vendor\n"); - goto free_struct; + return status; } status = efi_call_proto(pci, pci.read, EfiPciIoWidthUint16, @@ -90,21 +89,18 @@ preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) if (status != EFI_SUCCESS) { efi_err("Failed to read rom->devid\n"); - goto free_struct; + return status; } status = efi_call_proto(pci, get_location, &rom->segment, &rom->bus, &rom->device, &rom->function); if (status != EFI_SUCCESS) - goto free_struct; + return status; memcpy(rom->romdata, romimage, romsize); - return status; - -free_struct: - efi_bs_call(free_pool, rom); - return status; + *__rom = no_free_ptr(rom); + return EFI_SUCCESS; } /*