Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oOgu0-0004xJ-U2 for mharc-grub-devel@gnu.org; Thu, 18 Aug 2022 10:53:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOgtz-0004ve-Iy for grub-devel@gnu.org; Thu, 18 Aug 2022 10:53:43 -0400 Received: from dfw.source.kernel.org ([139.178.84.217]:49508) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOgtu-0001KM-Rx for grub-devel@gnu.org; Thu, 18 Aug 2022 10:53:40 -0400 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 dfw.source.kernel.org (Postfix) with ESMTPS id 050D06114B; Thu, 18 Aug 2022 14:53:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5ACD4C433B5; Thu, 18 Aug 2022 14:53:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660834417; bh=HJxKuoLDX+gus1QsZw0e5C3ucrkSADKgGdBh7ekO2I0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qwOzpll+Da48lrZV82jWpaoErV5CtulCzextVoPCRg8XdmZvEXNRcKKileWPEdzxJ qQ0uAw4kjrKYlg8ppdkLNtWdrFrjtxtvtMorUISeUwO5xqnBdaup2ZATVk9mg8jooR Zq4kk2MlaOARiTlm7DOJbQDtG/PSF/9Tz64LfxKA+t8A3HGvosvbudOoKEUbKpl+VS o/g0Oi8jKp7+MxZMz+xpNWEZkZPNL28qROZqgRpS+f35G5h0286kYNJQDk8SG4P5W7 u/W6A3mix8x391i9hpnYJxg01pVdh3f6MIQyW7LEfsyLUsc0SCObQVEu893zq9Iis0 u6GoQI+EfZGZg== From: Ard Biesheuvel To: grub-devel@gnu.org Cc: Ard Biesheuvel , Daniel Kiper , Leif Lindholm , Nikita Ermakov , Atish Patra , Huacai Chen , Heinrich Schuchardt , dann frazier , Julian Andres Klode Subject: [PATCH v3 6/8] efi/efinet: Don't close connections at fini_hw() time Date: Thu, 18 Aug 2022 16:51:33 +0200 Message-Id: <20220818145135.2208251-7-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220818145135.2208251-1-ardb@kernel.org> References: <20220818145135.2208251-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3263; i=ardb@kernel.org; h=from:subject; bh=HJxKuoLDX+gus1QsZw0e5C3ucrkSADKgGdBh7ekO2I0=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBi/lHwMJQNAk7wnyHw01tA11+4wUmXwt63+lKRx7AO iHW6zJ+JAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYv5R8AAKCRDDTyI5ktmPJJJ8C/ 90JFMKhHocedNiu068CmM3AZVIBM+f+T83ui4OfGXVgIIAINe5fzTW58CO4H9rMm5KQQRIJP+52lhu SjOtjGzC4fygKt6OTUNtLxfmReM8kmNQciVbC4ShWKefKhPVZ706eXeSk1hTOgDHG8pNMvOG566ulW 1afLDEscninZVrr9XUFv1m4JMeDNdLB1FvyC0G6dIZUhXpI9D6W+0u+BMCmndKU81IFIO2ZlCtIvGU YI4BMx0w9O0EldJOQVEb17h7+yhmma6iP6uL+535KixhRKXKcX4tMM9M61GOQOfEbT4lfYOuWxfkYt TtwxypvfUDc8i5mhj++hVC7uuWu8x9r2O8/ORhAHu184fSQvFB0FV/8v1KXphfzTTkAb+e3Yrr8xXm O57UH9UXSyv/WwbzvQoJI2bLZ4HhZKijJn5Og8gKT5rGRix3gCjFNUa7rCN6LINvcuXKgw6Yxfq7RG D3gdnPLtrLlwCvQRkbBFG9zatLMh9pTnGi11MMAqFbaKQ= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=139.178.84.217; envelope-from=ardb@kernel.org; helo=dfw.source.kernel.org X-Spam_score_int: -71 X-Spam_score: -7.2 X-Spam_bar: ------- X-Spam_report: (-7.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Aug 2022 14:53:43 -0000 When GRUB runs on top of EFI firmware, it only has access to block and network device abstractions exposed by the firmware, and it is up to the firmware to quiesce the underlying hardware when handing over to the OS. This is especially important for network devices, to prevent incoming packets from being DMA'd straight into memory after the OS has taken over but before it has managed to reconfigure the network hardware. GRUB handles this by means of the grub_net_fini_hw() preboot hook, which is executed before calling into the booted image. This means that all network devices disappear or become inoperable before the EFI stub executes on EFI targeted builds. This is problematic as it prevents the EFI stub from calling back into GRUB provided protocols such as LoadFile2 for the initrd, which we will provide in a subsequent patch. So add a flag that indicates to the network core that EFI network devices should not be closed when grub_net_fini_hw() is called. Signed-off-by: Ard Biesheuvel --- grub-core/net/drivers/efi/efinet.c | 10 +++++++++- grub-core/net/net.c | 2 +- include/grub/net.h | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/grub-core/net/drivers/efi/efinet.c b/grub-core/net/drivers/efi/efinet.c index 73343d26d9e1..5adf5f40f492 100644 --- a/grub-core/net/drivers/efi/efinet.c +++ b/grub-core/net/drivers/efi/efinet.c @@ -320,7 +320,15 @@ grub_efinet_findcards (void) card->name = grub_xasprintf ("efinet%d", i++); card->driver = &efidriver; - card->flags = 0; + /* + * EFI network devices are abstract SNP protocol instances, and the + * firmware is in charge of ensuring that they will be torn down when the + * OS loader hands off to the OS proper. Closing them as part of the + * preboot cleanup is therefore unnecessary, and undesirable, as it + * prevents us from using the network connection in a protocal callback + * such as LoadFile2 for initrd loading. + */ + card->flags = GRUB_NET_CARD_NO_CLOSE_ON_FINI_HW; card->default_address.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET; grub_memcpy (card->default_address.mac, net->mode->current_address, diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 064e7114e012..7046dc57890a 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -1787,7 +1787,7 @@ grub_net_fini_hw (int noreturn __attribute__ ((unused))) { struct grub_net_card *card; FOR_NET_CARDS (card) - if (card->opened) + if (card->opened && !(card->flags & GRUB_NET_CARD_NO_CLOSE_ON_FINI_HW)) { if (card->driver->close) card->driver->close (card); diff --git a/include/grub/net.h b/include/grub/net.h index a64a04cc80b1..79cba357ae6a 100644 --- a/include/grub/net.h +++ b/include/grub/net.h @@ -64,7 +64,8 @@ typedef enum grub_net_interface_flags typedef enum grub_net_card_flags { GRUB_NET_CARD_HWADDRESS_IMMUTABLE = 1, - GRUB_NET_CARD_NO_MANUAL_INTERFACES = 2 + GRUB_NET_CARD_NO_MANUAL_INTERFACES = 2, + GRUB_NET_CARD_NO_CLOSE_ON_FINI_HW = 4 } grub_net_card_flags_t; struct grub_net_card; -- 2.35.1