From patchwork Fri Jun 17 17:48:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12885850 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A8C3CCA480 for ; Fri, 17 Jun 2022 17:49:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383387AbiFQRtF (ORCPT ); Fri, 17 Jun 2022 13:49:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383377AbiFQRtE (ORCPT ); Fri, 17 Jun 2022 13:49:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D22AB37BDD; Fri, 17 Jun 2022 10:49:03 -0700 (PDT) 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 6854561F13; Fri, 17 Jun 2022 17:49:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EF4AC341C4; Fri, 17 Jun 2022 17:48:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655488142; bh=vB9funzmggAWF3D29wN3gul0eRo6BzB1rO5s3sDxiwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K8MHf2Pztn/G+ugOOXD0xdtW5p+wCkH4hsdA8TzmeqKaErN7YTrKL7E7HCm5AzIeW Ercav7fpV/mGurdCAi24P51geoD5jc5bxejOJpJh34dqNFt5q4iIjW6ex9ldiK9IX2 PT2NiK97FL0ftHLlGYhDuC+4La/OWzFvqrhVxOXm2GoC7bFK7f0HKn9DkuE2vPUnkV XcOOURduIGaIC8fLK4d6eJ1tUVRHTIaS2MldwBqvu9Qk6sbM7h7/0XyblsFkz7spaz +H22gZkaFr55x6CQGBWPK0JDwP/H9orN+GOvzHuwQ/7TcK1maGpCA+5tdgmRwJBeF+ uqWT+Rt8CTYsQ== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: keescook@chromium.org, Ard Biesheuvel , Dmitry Torokhov , Arend van Spriel , Franky Lin , Hante Meuleman , Kalle Valo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Gregory Greenman , linux-input@vger.kernel.org, linux-wireless@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com Subject: [PATCH 1/4] efi: avoid efivars layer when loading SSDTs from variables Date: Fri, 17 Jun 2022 19:48:48 +0200 Message-Id: <20220617174851.1286026-2-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220617174851.1286026-1-ardb@kernel.org> References: <20220617174851.1286026-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4607; h=from:subject; bh=vB9funzmggAWF3D29wN3gul0eRo6BzB1rO5s3sDxiwQ=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBirL59ydHqdCFHnG8sTxlNiWD1NOclxPn6HAfHL9yj oKaxUT+JAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYqy+fQAKCRDDTyI5ktmPJAqIDA Ck85s5ka8nJ+CHx8H//IOQKEY1pd+Kl3wznMUE4UWWXV94YDIDaBeUWm0zXVPCBZk4liZIZ6nfGicn 4Elvw3BpdX2/nFPlqBKQgddDN3eau4tLbK11MmDZPSwKYVEygOipuU3kJfUUB/1wobKfVgNsAnkgqv lc7wu+l0Ajd5nSK6T8mk8bQ2+9NLn2E0rqpU6rmUNINU6rIekzfxM5ncI+Q7yltsDm0fnqGYkiMDfh KMNmNFo+th/unUn9LamOt6N5Wb9GHwj5NZ8cAiDKDEbQpufyq6f+nePIAKgvc15I8s4R+qote0icw4 NOTaGRbIWPmCvfJpBJzDVuWwBkBKelC218BkKkmhUpNVAn+gWtjd5kqLSIYOHuDKS9uExBY5n5hkV+ 9pS7IyhAi574GXxaKEgjZmVRfpW1Z6IA3NNcPkaHX1NSf3I1BBI5A9JfR6b96kgXa0AsOxHEgQC85u efbHb/+i1+GYAHn/yYjbx9n9KxBb7rp+e4afkFHW9PGoA= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org The efivars intermediate variable access layer provides an abstraction that permits the EFI variable store to be replaced by something else that implements a compatible interface, and caches all variables in the variable store for fast access via the efivarfs pseudo-filesystem. The SSDT override feature does not take advantage of either feature, as it is only used when the generic EFI implementation of efivars is used, and it traverses all variables only once to find the ones it is interested in, and frees all data structures that the efivars layer keeps right after. So in this case, let's just call EFI's code directly, using the function pointers in struct efi. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/efi.c | 103 ++++++++------------ 1 file changed, 41 insertions(+), 62 deletions(-) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 860534bcfdac..630c18618f6a 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -202,7 +202,7 @@ static void generic_ops_unregister(void) } #ifdef CONFIG_EFI_CUSTOM_SSDT_OVERLAYS -#define EFIVAR_SSDT_NAME_MAX 16 +#define EFIVAR_SSDT_NAME_MAX 16UL static char efivar_ssdt[EFIVAR_SSDT_NAME_MAX] __initdata; static int __init efivar_ssdt_setup(char *str) { @@ -219,83 +219,62 @@ static int __init efivar_ssdt_setup(char *str) } __setup("efivar_ssdt=", efivar_ssdt_setup); -static __init int efivar_ssdt_iter(efi_char16_t *name, efi_guid_t vendor, - unsigned long name_size, void *data) -{ - struct efivar_entry *entry; - struct list_head *list = data; - char utf8_name[EFIVAR_SSDT_NAME_MAX]; - int limit = min_t(unsigned long, EFIVAR_SSDT_NAME_MAX, name_size); - - ucs2_as_utf8(utf8_name, name, limit - 1); - if (strncmp(utf8_name, efivar_ssdt, limit) != 0) - return 0; - - entry = kmalloc(sizeof(*entry), GFP_KERNEL); - if (!entry) - return 0; - - memcpy(entry->var.VariableName, name, name_size); - memcpy(&entry->var.VendorGuid, &vendor, sizeof(efi_guid_t)); - - efivar_entry_add(entry, list); - - return 0; -} - static __init int efivar_ssdt_load(void) { - LIST_HEAD(entries); - struct efivar_entry *entry, *aux; - unsigned long size; - void *data; - int ret; + unsigned long name_size = 256; + efi_char16_t *name = NULL; + efi_status_t status; + efi_guid_t guid; if (!efivar_ssdt[0]) return 0; - ret = efivar_init(efivar_ssdt_iter, &entries, true, &entries); - - list_for_each_entry_safe(entry, aux, &entries, list) { - pr_info("loading SSDT from variable %s-%pUl\n", efivar_ssdt, - &entry->var.VendorGuid); + name = kzalloc(name_size, GFP_KERNEL); + if (!name) + return -ENOMEM; - list_del(&entry->list); + for (;;) { + char utf8_name[EFIVAR_SSDT_NAME_MAX]; + unsigned long data_size = 0; + void *data; + int limit; - ret = efivar_entry_size(entry, &size); - if (ret) { - pr_err("failed to get var size\n"); - goto free_entry; + status = efi.get_next_variable(&name_size, name, &guid); + if (status == EFI_NOT_FOUND) { + break; + } else if (status == EFI_BUFFER_TOO_SMALL) { + name = krealloc(name, name_size, GFP_KERNEL); + if (!name) + return -ENOMEM; + continue; } - data = kmalloc(size, GFP_KERNEL); - if (!data) { - ret = -ENOMEM; - goto free_entry; - } + limit = min(EFIVAR_SSDT_NAME_MAX, name_size); + ucs2_as_utf8(utf8_name, name, limit - 1); + if (strncmp(utf8_name, efivar_ssdt, limit) != 0) + continue; - ret = efivar_entry_get(entry, NULL, &size, data); - if (ret) { - pr_err("failed to get var data\n"); - goto free_data; - } + pr_info("loading SSDT from variable %s-%pUl\n", efivar_ssdt, &guid); - ret = acpi_load_table(data, NULL); - if (ret) { - pr_err("failed to load table: %d\n", ret); - goto free_data; - } + status = efi.get_variable(name, &guid, NULL, &data_size, NULL); + if (status != EFI_BUFFER_TOO_SMALL || !data_size) + return -EIO; - goto free_entry; + data = kmalloc(data_size, GFP_KERNEL); + if (!data) + return -ENOMEM; -free_data: + status = efi.get_variable(name, &guid, NULL, &data_size, data); + if (status == EFI_SUCCESS) { + acpi_status ret = acpi_load_table(data, NULL); + if (ret) + pr_err("failed to load table: %u\n", ret); + } else { + pr_err("failed to get var data: 0x%lx\n", status); + } kfree(data); - -free_entry: - kfree(entry); } - - return ret; + return 0; } #else static inline int efivar_ssdt_load(void) { return 0; } From patchwork Fri Jun 17 17:48:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12885851 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9768CCA479 for ; Fri, 17 Jun 2022 17:49:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383409AbiFQRtI (ORCPT ); Fri, 17 Jun 2022 13:49:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383268AbiFQRtI (ORCPT ); Fri, 17 Jun 2022 13:49:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7911737BDD; Fri, 17 Jun 2022 10:49:07 -0700 (PDT) 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 1543161F14; Fri, 17 Jun 2022 17:49:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49C91C3411F; Fri, 17 Jun 2022 17:49:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655488146; bh=zul0a/iKMQjQIwDgMYDRWuClISYCTC5Pc4a5yv4ykHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A0VMGgeuhHBLJfooIQDy844VH4uFqJVQpIGxqq9MFPSNwX+qm2umf8RhZdFAGRRdf 4/NwGsxLcBV3gixtJEBly/uMid08ceDVnJxO44eMOYHKxM6ziLclK4zS3Xtow+VcUz Qa0Sg91FqgQZQVc9YhOYYFXEQYrBMluxMvldli889/kcQwR1lkr0Q13RLmNVrLEhF0 uFfTsopNiRx5NT7qsLHR9B54ZjDT1RKsENRrQ7hON0U+FRFI6OSUddAuGc1aOWUZPJ zf31spidL1Fi6pQwiIHbEFPlHJokQUCS6gK4GlsIgN7+1R7dxBIzv3dFbI154RDERN kqkS25EOfs1hQ== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: keescook@chromium.org, Ard Biesheuvel , Dmitry Torokhov , Arend van Spriel , Franky Lin , Hante Meuleman , Kalle Valo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Gregory Greenman , linux-input@vger.kernel.org, linux-wireless@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com Subject: [PATCH 2/4] Input: applespi - avoid efivars API and invoke EFI services directly Date: Fri, 17 Jun 2022 19:48:49 +0200 Message-Id: <20220617174851.1286026-3-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220617174851.1286026-1-ardb@kernel.org> References: <20220617174851.1286026-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3021; h=from:subject; bh=zul0a/iKMQjQIwDgMYDRWuClISYCTC5Pc4a5yv4ykHc=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBirL5+pmHpuNv9hnsTFaaAjIWZa3K33CmkmpF30fjR CKB86kOJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYqy+fgAKCRDDTyI5ktmPJNAoC/ sGBPLZNCLoyVBeI75qNl3RJjTRKAKU5P3Of9YPT7Ap9YR2LUotFA5/xjAcjF9yBcwtoCIjG1JAw5aZ FzLkINCWJZH5IqLS93l+w46i8DUKGTIR3bX0M0VR2HrVtI9Tp6Cdc6rlYFNhjniVbE4tX3uqBixl6C 67MiqebpyAA+D787FP/3NQ0kjbabMi/IW3y49z6KQTQNLiAXGo7MqG9JSpawInvXB05RaNYa+rAs4/ v9jfeA7LM4abKVH0r3MpSv11aX9uKcgVeqCUyiONyYL8A6HFodhUDWcn0AOo/mabE2+ZqQj/7oNirC 9v6ESqsKkrd+kUAaiXnx/lRJ6qJM53TItqnVGFDHZhOCt38941EnZq91J3IV+2waZIk86fBRP47CRN kUeZKQvErOlBF3jJOY1Zb8quFYqz4kYpAZ1/K0dIeaNG/WAViBD6iELvvzwWwzaPpoPYqR20VySumD WzjBuJ/NVIAy5F+Yc6JdbyPVwQstIwovOslDh1JHkGElI= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org This driver abuses the efivar API, by using a few of its helpers on entries that were not instantiated by the API itself. This is a problem as future cleanup work on efivars is complicated by this. So let's just switch to the get/set variable runtime wrappers directly. Signed-off-by: Ard Biesheuvel --- drivers/input/keyboard/applespi.c | 42 +++++++------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/drivers/input/keyboard/applespi.c b/drivers/input/keyboard/applespi.c index d1f5354d5ea2..cbc6c0d4670a 100644 --- a/drivers/input/keyboard/applespi.c +++ b/drivers/input/keyboard/applespi.c @@ -1597,52 +1597,38 @@ static u32 applespi_notify(acpi_handle gpe_device, u32 gpe, void *context) static int applespi_get_saved_bl_level(struct applespi_data *applespi) { - struct efivar_entry *efivar_entry; + efi_status_t sts = EFI_NOT_FOUND; u16 efi_data = 0; - unsigned long efi_data_len; - int sts; - - efivar_entry = kmalloc(sizeof(*efivar_entry), GFP_KERNEL); - if (!efivar_entry) - return -ENOMEM; - - memcpy(efivar_entry->var.VariableName, EFI_BL_LEVEL_NAME, - sizeof(EFI_BL_LEVEL_NAME)); - efivar_entry->var.VendorGuid = EFI_BL_LEVEL_GUID; - efi_data_len = sizeof(efi_data); + unsigned long efi_data_len = sizeof(efi_data); - sts = efivar_entry_get(efivar_entry, NULL, &efi_data_len, &efi_data); - if (sts && sts != -ENOENT) + if (efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) + sts = efi.get_variable(EFI_BL_LEVEL_NAME, &EFI_BL_LEVEL_GUID, + NULL, &efi_data_len, &efi_data); + if (sts != EFI_SUCCESS && sts != EFI_NOT_FOUND) dev_warn(&applespi->spi->dev, - "Error getting backlight level from EFI vars: %d\n", + "Error getting backlight level from EFI vars: 0x%lx\n", sts); - kfree(efivar_entry); - - return sts ? sts : efi_data; + return sts != EFI_SUCCESS ? -ENODEV : efi_data; } static void applespi_save_bl_level(struct applespi_data *applespi, unsigned int level) { - efi_guid_t efi_guid; + efi_status_t sts = EFI_UNSUPPORTED; u32 efi_attr; - unsigned long efi_data_len; u16 efi_data; - int sts; - /* Save keyboard backlight level */ - efi_guid = EFI_BL_LEVEL_GUID; efi_data = (u16)level; - efi_data_len = sizeof(efi_data); efi_attr = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS; - sts = efivar_entry_set_safe((efi_char16_t *)EFI_BL_LEVEL_NAME, efi_guid, - efi_attr, true, efi_data_len, &efi_data); - if (sts) + if (efi_rt_services_supported(EFI_RT_SUPPORTED_SET_VARIABLE)) + sts = efi.set_variable(EFI_BL_LEVEL_NAME, &EFI_BL_LEVEL_GUID, + efi_attr, sizeof(efi_data), &efi_data); + if (sts != EFI_SUCCESS) dev_warn(&applespi->spi->dev, - "Error saving backlight level to EFI vars: %d\n", sts); + "Error saving backlight level to EFI vars: 0x%lx\n", sts); } static int applespi_probe(struct spi_device *spi) From patchwork Fri Jun 17 17:48:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12885852 X-Patchwork-Delegate: miriam.rachel.korenblit@intel.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76932CCA47F for ; Fri, 17 Jun 2022 17:49:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383419AbiFQRtP (ORCPT ); Fri, 17 Jun 2022 13:49:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383415AbiFQRtO (ORCPT ); Fri, 17 Jun 2022 13:49:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A633349911; Fri, 17 Jun 2022 10:49:12 -0700 (PDT) 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 5A23AB82B6F; Fri, 17 Jun 2022 17:49:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8B1FC341C5; Fri, 17 Jun 2022 17:49:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655488150; bh=NRpFD5sKUmNhRBtQPM8OHv18DB2Va4KJOWSCP+G+UoU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lZFGFIjGM9IV0ipc2R8etW1SK4ceOXPtF+rEvv3O120BT+8uG9zGltMGcQo5aUIa9 jXCTbxwzftO1JobT6jd1yc4SSBB05VUhdKnH9pubO+YDFsmOZmppZLHCPUMFWlGrCw N+D9X2W+erMGk/i+m/2eAC8xEHO9YXx2yT1bEnO8zerzZAKjca5GtKCi8nWPVHg0C3 QrThjUgpX+W0a6hBPrd9Z4/GAyahqEZEBYcwQyoNagNg3cJ+y4G4pIo2L+zJKlkKFg H+4t2USeMX3m1SKTwnshTFjA7zR/jiXlapk/yy1hdExS8nOerg/wtRZ1cbW40JKFOG d98+SY8wcb4xw== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: keescook@chromium.org, Ard Biesheuvel , Dmitry Torokhov , Arend van Spriel , Franky Lin , Hante Meuleman , Kalle Valo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Gregory Greenman , linux-input@vger.kernel.org, linux-wireless@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com Subject: [PATCH 3/4] iwlwifi: Switch to proper EFI variable store interface Date: Fri, 17 Jun 2022 19:48:50 +0200 Message-Id: <20220617174851.1286026-4-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220617174851.1286026-1-ardb@kernel.org> References: <20220617174851.1286026-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6127; h=from:subject; bh=NRpFD5sKUmNhRBtQPM8OHv18DB2Va4KJOWSCP+G+UoU=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBirL6A9hCvWi6TSw7XCEuKPlWcRrWPHbmibsDstdOk tFUHZ4eJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYqy+gAAKCRDDTyI5ktmPJJS2DA CxEx44N/mbhZHFq32AhUF7uUgKurPuqChuo90Ofa8DGxcEUS7ut12FdB8v21xlGs/rwTmzzIFW5RCC AQ2oc1OcpN0KZFsh7M6ev6eBC0bkb5ohKBFaTnj9x6OJw39EZaDrQ9X4ybH/+ID6xb1L2OZ46/8KcI PfGd9cGFSbMX9bVoCY6IQuXbaOQh17zCeJnIjkNYwUrVg52yzTTVF1XXIFgYePR+J+aaAjCHL18p8T 9ClNbrhYJBY4BBN7kwtkwzdEpRPHOC1w8bN9IYYqkoQYwQOm7ewWmSQGkNufHsNsjbLMvOSXxX/pse ak6jp92Maqyk0TrWtW4neos3EXE2kWewrEtf2P3OeyGYVjWr7TodYlg+Ymg+BLxKt4Yd0LMBtdDvvR AeIkomMxVq4dgZf3uwDTaYz0H2o9dUDZNq+wwcucEgJNntIAElix4mqI80gpOJoRpqb7MaXY/Vy9yQ qRYItbQZNAXuU2eNCMYK5SjoWISXL8aOKAogICiQTeNVI= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Using half of the efivar API with locally baked efivar_entry instances is not the right way to use this API, and these uses impede planned work on the efivar layer itself. So switch to direct EFI variable store accesses: we don't need the efivar layer anyway. Signed-off-by: Ard Biesheuvel --- drivers/net/wireless/intel/iwlwifi/fw/uefi.c | 96 +++++++------------- 1 file changed, 32 insertions(+), 64 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c index 23b1d689ba7b..9854466c21d9 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/uefi.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/uefi.c @@ -19,20 +19,14 @@ void *iwl_uefi_get_pnvm(struct iwl_trans *trans, size_t *len) { - struct efivar_entry *pnvm_efivar; void *data; unsigned long package_size; - int err; + efi_status_t status; *len = 0; - pnvm_efivar = kzalloc(sizeof(*pnvm_efivar), GFP_KERNEL); - if (!pnvm_efivar) - return ERR_PTR(-ENOMEM); - - memcpy(&pnvm_efivar->var.VariableName, IWL_UEFI_OEM_PNVM_NAME, - sizeof(IWL_UEFI_OEM_PNVM_NAME)); - pnvm_efivar->var.VendorGuid = IWL_EFI_VAR_GUID; + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) + return ERR_PTR(-ENODEV); /* * TODO: we hardcode a maximum length here, because reading @@ -42,27 +36,22 @@ void *iwl_uefi_get_pnvm(struct iwl_trans *trans, size_t *len) package_size = IWL_HARDCODED_PNVM_SIZE; data = kmalloc(package_size, GFP_KERNEL); - if (!data) { - data = ERR_PTR(-ENOMEM); - goto out; - } + if (!data) + return ERR_PTR(-ENOMEM); - err = efivar_entry_get(pnvm_efivar, NULL, &package_size, data); - if (err) { + status = efi.get_variable(IWL_UEFI_OEM_PNVM_NAME, &IWL_EFI_VAR_GUID, + NULL, &package_size, data); + if (status != EFI_SUCCESS) { IWL_DEBUG_FW(trans, - "PNVM UEFI variable not found %d (len %lu)\n", - err, package_size); + "PNVM UEFI variable not found 0x%lx (len %lu)\n", + status, package_size); kfree(data); - data = ERR_PTR(err); - goto out; + return ERR_PTR(efi_status_to_err(status)); } IWL_DEBUG_FW(trans, "Read PNVM from UEFI with size %lu\n", package_size); *len = package_size; -out: - kfree(pnvm_efivar); - return data; } @@ -211,21 +200,15 @@ static void *iwl_uefi_reduce_power_parse(struct iwl_trans *trans, void *iwl_uefi_get_reduced_power(struct iwl_trans *trans, size_t *len) { - struct efivar_entry *reduce_power_efivar; struct pnvm_sku_package *package; void *data = NULL; unsigned long package_size; - int err; + efi_status_t status; *len = 0; - reduce_power_efivar = kzalloc(sizeof(*reduce_power_efivar), GFP_KERNEL); - if (!reduce_power_efivar) - return ERR_PTR(-ENOMEM); - - memcpy(&reduce_power_efivar->var.VariableName, IWL_UEFI_REDUCED_POWER_NAME, - sizeof(IWL_UEFI_REDUCED_POWER_NAME)); - reduce_power_efivar->var.VendorGuid = IWL_EFI_VAR_GUID; + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) + return ERR_PTR(-ENODEV); /* * TODO: we hardcode a maximum length here, because reading @@ -235,19 +218,17 @@ void *iwl_uefi_get_reduced_power(struct iwl_trans *trans, size_t *len) package_size = IWL_HARDCODED_REDUCE_POWER_SIZE; package = kmalloc(package_size, GFP_KERNEL); - if (!package) { - package = ERR_PTR(-ENOMEM); - goto out; - } + if (!package) + return ERR_PTR(-ENOMEM); - err = efivar_entry_get(reduce_power_efivar, NULL, &package_size, package); - if (err) { + status = efi.get_variable(IWL_UEFI_REDUCED_POWER_NAME, &IWL_EFI_VAR_GUID, + NULL, &package_size, data); + if (status != EFI_SUCCESS) { IWL_DEBUG_FW(trans, - "Reduced Power UEFI variable not found %d (len %lu)\n", - err, package_size); + "Reduced Power UEFI variable not found 0x%lx (len %lu)\n", + status, package_size); kfree(package); - data = ERR_PTR(err); - goto out; + return ERR_PTR(efi_status_to_err(status)); } IWL_DEBUG_FW(trans, "Read reduced power from UEFI with size %lu\n", @@ -262,9 +243,6 @@ void *iwl_uefi_get_reduced_power(struct iwl_trans *trans, size_t *len) kfree(package); -out: - kfree(reduce_power_efivar); - return data; } @@ -304,22 +282,15 @@ static int iwl_uefi_sgom_parse(struct uefi_cnv_wlan_sgom_data *sgom_data, void iwl_uefi_get_sgom_table(struct iwl_trans *trans, struct iwl_fw_runtime *fwrt) { - struct efivar_entry *sgom_efivar; struct uefi_cnv_wlan_sgom_data *data; unsigned long package_size; - int err, ret; - - if (!fwrt->geo_enabled) - return; + efi_status_t status; + int ret; - sgom_efivar = kzalloc(sizeof(*sgom_efivar), GFP_KERNEL); - if (!sgom_efivar) + if (!fwrt->geo_enabled || + !efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) return; - memcpy(&sgom_efivar->var.VariableName, IWL_UEFI_SGOM_NAME, - sizeof(IWL_UEFI_SGOM_NAME)); - sgom_efivar->var.VendorGuid = IWL_EFI_VAR_GUID; - /* TODO: we hardcode a maximum length here, because reading * from the UEFI is not working. To implement this properly, * we have to call efivar_entry_size(). @@ -327,15 +298,14 @@ void iwl_uefi_get_sgom_table(struct iwl_trans *trans, package_size = IWL_HARDCODED_SGOM_SIZE; data = kmalloc(package_size, GFP_KERNEL); - if (!data) { - data = ERR_PTR(-ENOMEM); - goto out; - } + if (!data) + return; - err = efivar_entry_get(sgom_efivar, NULL, &package_size, data); - if (err) { + status = efi.get_variable(IWL_UEFI_SGOM_NAME, &IWL_EFI_VAR_GUID, + NULL, &package_size, data); + if (status != EFI_SUCCESS) { IWL_DEBUG_FW(trans, - "SGOM UEFI variable not found %d\n", err); + "SGOM UEFI variable not found 0x%lx\n", status); goto out_free; } @@ -349,8 +319,6 @@ void iwl_uefi_get_sgom_table(struct iwl_trans *trans, out_free: kfree(data); -out: - kfree(sgom_efivar); } IWL_EXPORT_SYMBOL(iwl_uefi_get_sgom_table); #endif /* CONFIG_ACPI */ From patchwork Fri Jun 17 17:48:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 12885853 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A572CCA480 for ; Fri, 17 Jun 2022 17:49:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383432AbiFQRtQ (ORCPT ); Fri, 17 Jun 2022 13:49:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383268AbiFQRtP (ORCPT ); Fri, 17 Jun 2022 13:49:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C280B3F885; Fri, 17 Jun 2022 10:49:14 -0700 (PDT) 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 5F77A61F14; Fri, 17 Jun 2022 17:49:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 960CBC341C0; Fri, 17 Jun 2022 17:49:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655488153; bh=PRTYl9cGcXlUxdUr/r7+4Kaowbx7SkDShSOpXJhEviM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MWbuSYbv0EI66uKQNIhCHVmHqsHfykouUmD9eq9CpmGNei4uVgKaNMkv8tiwCvTVX nx0SM8eEM0lTCxPSVws4TDWEryho+KMvn3zGkYvKP5yKPQxf8iSG/TZoU6vy1BKiYk ofsjxbJ7jWtWMaXUgHy68Zh+7slsvtbVNif8wd7jri2M+V9nXbFfGYphRi/QRHY2fh GoVTuXoOGzcAr39RribXur6X0Zt4kwNTZIVzGDXKIV/9Jvw7dGSYuriCh9hm3Qnt7r ZJVgA1/14pLM0A2QIGNvCGIJ01P0/ge4pd+jLHsT37n2bjON9xrX3OvdYgpwtOdJdM QgPpBGkKVHMpw== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: keescook@chromium.org, Ard Biesheuvel , Dmitry Torokhov , Arend van Spriel , Franky Lin , Hante Meuleman , Kalle Valo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Gregory Greenman , linux-input@vger.kernel.org, linux-wireless@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com Subject: [PATCH 4/4] brcmfmac: Switch to appropriate helper to load EFI variable contents Date: Fri, 17 Jun 2022 19:48:51 +0200 Message-Id: <20220617174851.1286026-5-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220617174851.1286026-1-ardb@kernel.org> References: <20220617174851.1286026-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2223; h=from:subject; bh=PRTYl9cGcXlUxdUr/r7+4Kaowbx7SkDShSOpXJhEviM=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBirL6CWaquSqLfyrN7l/DCfLI0uHD6hNWG9QW+emqE 2fHS4G+JAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYqy+ggAKCRDDTyI5ktmPJPb9C/ 995YoHB7auDHHI3CJMJiJkvfWZZSjdbMHDjz9xGMBF/zTnI3Z69iW4BLPUQzTsQycDX/AMZd/NMLs8 ynIHqcpNpnia6ZB1li/KQPUw/EfhYelR5DKeQE1+nsqvGieG4/wANRehhU2Pd3qinh1hQow7rFZ4Xn 5iKBalmtopiTHkaeTaj4u4tfVFAAY4msylHEYDfXc5/3xubPgRwbGr6KV3D1J+P5TLnGA7KncCkvzx ZbcOwPhQ/yU4DHNKb4avRbA4P2jmF7/VbMQASy5fqlXnFLqJV0R4abx4Tk1FA02DSfJE/zyraPUIl+ tXQZzCNldoLl/jF7CrSVbinF5zvJ3dNXMfn1QXKqq3sVNyUHNRRmQi5Gb8WnOOKNjBseNaDWnpP8H8 MF/GU7qWeGFgkqHLN7NNONoeNy+KDP0cRgkIHiZ4mV45fL81+9ILRSa5dyL8i5OEf0q+TEAkJuZzEN aapEXPeYEgYcIVOxGD8jokAW2D8OeSP7vrqbEUC/8NQnk= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Avoid abusing the efivar layer by invoking it with locally constructed efivar_entry instances, and instead, just call the EFI routines directly if available. Signed-off-by: Ard Biesheuvel --- drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c | 25 +++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c index dcbe55b56e43..b8379e4034a4 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c @@ -459,43 +459,34 @@ static void brcmf_fw_fix_efi_nvram_ccode(char *data, unsigned long data_len) static u8 *brcmf_fw_nvram_from_efi(size_t *data_len_ret) { - const u16 name[] = { 'n', 'v', 'r', 'a', 'm', 0 }; - struct efivar_entry *nvram_efivar; + efi_guid_t guid = EFI_GUID(0x74b00bd9, 0x805a, 0x4d61, 0xb5, 0x1f, + 0x43, 0x26, 0x81, 0x23, 0xd1, 0x13); unsigned long data_len = 0; + efi_status_t status; u8 *data = NULL; - int err; - nvram_efivar = kzalloc(sizeof(*nvram_efivar), GFP_KERNEL); - if (!nvram_efivar) + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) return NULL; - memcpy(&nvram_efivar->var.VariableName, name, sizeof(name)); - nvram_efivar->var.VendorGuid = EFI_GUID(0x74b00bd9, 0x805a, 0x4d61, - 0xb5, 0x1f, 0x43, 0x26, - 0x81, 0x23, 0xd1, 0x13); - - err = efivar_entry_size(nvram_efivar, &data_len); - if (err) + status = efi.get_variable(L"nvram", &guid, NULL, &data_len, NULL); + if (status != EFI_BUFFER_TOO_SMALL) goto fail; data = kmalloc(data_len, GFP_KERNEL); if (!data) goto fail; - err = efivar_entry_get(nvram_efivar, NULL, &data_len, data); - if (err) + status = efi.get_variable(L"nvram", &guid, NULL, &data_len, data); + if (status != EFI_SUCCESS) goto fail; brcmf_fw_fix_efi_nvram_ccode(data, data_len); brcmf_info("Using nvram EFI variable\n"); - kfree(nvram_efivar); *data_len_ret = data_len; return data; - fail: kfree(data); - kfree(nvram_efivar); return NULL; } #else