From patchwork Thu Mar 9 06:00:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huacai Chen X-Patchwork-Id: 66606 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp123703wrd; Wed, 8 Mar 2023 22:19:36 -0800 (PST) X-Google-Smtp-Source: AK7set+CAjAqYrhIffXKzS5vm7LcO285fHGs4ALahdN6dTtq61L5LQfEyX52pncGTn8KTio4IZld X-Received: by 2002:a05:6a20:2d82:b0:be:b137:9d15 with SMTP id bf2-20020a056a202d8200b000beb1379d15mr18950544pzb.36.1678342776408; Wed, 08 Mar 2023 22:19:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678342776; cv=none; d=google.com; s=arc-20160816; b=gZTBcFUNcEzEWx7tWydb0IjEWEe1WvTWQrK/d4kVJiB92tesaMqfkeAA+e5FCMrWd1 6WZcLMe4xWugMA7yPt1sP+68MXfY4MDZ1SNIvf1vamU9qbmwwc7ybDlHsF0+2blfigpf qGfl/Z8eWlGkDC/A+2WHRaNIhTgCMA5QTY2QhVYvZ/R7C1492DfVcbzIUZ+V5mGKngBD WVIK4qpd5EQM9EwE/QkR4NXmipRKnly29dW3i5fWUUXZKCF0psDeep4ectDYPyfVU8U+ TpPmgpm4kkh0bxpNSyrYI7Cbjt+ypqB3bScaOWG4998ZLUDv3/juCK89npPyDXYpYhhh uzYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=r/PGMJx6RjpkE3Xla8xerg7DeLzT2GUyZvBLc4SNaVE=; b=lkCbCOcCN6osLr/frsN3+Ju1a3oUjQ4CmY8trBhvgKF9Y1emadboCVhb/91am/Rnhd tlMVXoO5YflZfXbq0+3PLchxZ7KwFuqeabb5O1uvXio0Dk9HSfXQJS4n+mNHKLyIp/5L m7x9o4jf1VfoncarKCBa3mGPZ1BCC6ns+1EzpJ304RPIXcRP4GYnlWI622XNQ0ExQKPe Cums9MMvKsFozODcka7omZuJ2GkoRoNomjt8EyTwcTTC05uCHQWmYUsJZyQNY7yXdQ80 6VWw+QahzmKxhL7X5OUWyl5qUQuLXp28+Kefg8KrbJcCfNd3c4h9TQJfBE48auli9hGg tv4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h63-20020a638342000000b0050318a8f2basi15846717pge.22.2023.03.08.22.19.22; Wed, 08 Mar 2023 22:19:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229801AbjCIGAa (ORCPT + 99 others); Thu, 9 Mar 2023 01:00:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229691AbjCIGA2 (ORCPT ); Thu, 9 Mar 2023 01:00:28 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A68BC362C; Wed, 8 Mar 2023 22:00:26 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E6326B81DEC; Thu, 9 Mar 2023 06:00:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D824C433D2; Thu, 9 Mar 2023 06:00:20 +0000 (UTC) From: Huacai Chen To: Ard Biesheuvel , Huacai Chen Cc: linux-efi@vger.kernel.org, loongarch@lists.linux.dev, Xuefeng Li , Xuerui Wang , linux-kernel@vger.kernel.org, loongson-kernel@lists.loongnix.cn, Huacai Chen Subject: [PATCH] efi/libstub: Call setup_graphics() before handle_kernel_image() Date: Thu, 9 Mar 2023 14:00:12 +0800 Message-Id: <20230309060012.4189412-1-chenhuacai@loongson.cn> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759869955136778728?= X-GMAIL-MSGID: =?utf-8?q?1759869955136778728?= Commit 42c8ea3dca094ab8 ("efi: libstub: Factor out EFI stub entrypoint into separate file") moves setup_graphics() into efi_stub_common() which is after handle_kernel_image(). This causes efifb no longer work because handle_kernel_image() may move the core kernel to its preferred address, which means the screen_info filled by the efistub will not be the same as the one accessed by the core kernel. So let us call setup_graphics() before handle_kernel_image() which restores the old behavior. The side effect is zboot will not call setup_graphics(), but I think zboot doesn't need it either. Fixes: 42c8ea3dca094ab8 ("efi: libstub: Factor out EFI stub entrypoint into separate file") Signed-off-by: Huacai Chen --- drivers/firmware/efi/libstub/efi-stub-entry.c | 29 +++++++++++++++++++ drivers/firmware/efi/libstub/efi-stub.c | 27 ----------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/drivers/firmware/efi/libstub/efi-stub-entry.c b/drivers/firmware/efi/libstub/efi-stub-entry.c index 5245c4f031c0..f971fd25a4eb 100644 --- a/drivers/firmware/efi/libstub/efi-stub-entry.c +++ b/drivers/firmware/efi/libstub/efi-stub-entry.c @@ -5,6 +5,30 @@ #include "efistub.h" +struct screen_info *setup_graphics(void) +{ + unsigned long size; + efi_status_t status; + efi_guid_t gop_proto = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID; + void **gop_handle = NULL; + struct screen_info *si = NULL; + + 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; + } + } + return si; +} + /* * EFI entry point for the generic EFI stub used by ARM, arm64, RISC-V and * LoongArch. This is the entrypoint that is described in the PE/COFF header @@ -22,6 +46,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, efi_guid_t loaded_image_proto = LOADED_IMAGE_PROTOCOL_GUID; unsigned long reserve_addr = 0; unsigned long reserve_size = 0; + struct screen_info *si; WRITE_ONCE(efi_system_table, systab); @@ -47,6 +72,8 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, efi_info("Booting Linux Kernel...\n"); + si = setup_graphics(); + status = handle_kernel_image(&image_addr, &image_size, &reserve_addr, &reserve_size, @@ -58,6 +85,8 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle, status = efi_stub_common(handle, image, image_addr, cmdline_ptr); + free_screen_info(si); + efi_free(image_size, image_addr); efi_free(reserve_size, reserve_addr); diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c index 2955c1ac6a36..bc67af721412 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -56,30 +56,6 @@ 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; - - 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; - } - } - return si; -} - static void install_memreserve_table(void) { struct linux_efi_memreserve *rsv; @@ -163,14 +139,12 @@ efi_status_t efi_stub_common(efi_handle_t handle, unsigned long image_addr, char *cmdline_ptr) { - struct screen_info *si; efi_status_t status; status = check_platform_features(); if (status != EFI_SUCCESS) return status; - si = setup_graphics(); efi_retrieve_tpm2_eventlog(); @@ -190,7 +164,6 @@ efi_status_t efi_stub_common(efi_handle_t handle, status = efi_boot_kernel(handle, image, image_addr, cmdline_ptr); - free_screen_info(si); return status; }