From patchwork Fri Jun 22 07:52:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10481437 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D91AB60388 for ; Fri, 22 Jun 2018 07:52:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCEAB28E18 for ; Fri, 22 Jun 2018 07:52:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C14AB28E47; Fri, 22 Jun 2018 07:52:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 441AF28E23 for ; Fri, 22 Jun 2018 07:52:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751170AbeFVHw6 (ORCPT ); Fri, 22 Jun 2018 03:52:58 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:36770 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751097AbeFVHw5 (ORCPT ); Fri, 22 Jun 2018 03:52:57 -0400 Received: by mail-wm0-f67.google.com with SMTP id v131-v6so1372214wma.1 for ; Fri, 22 Jun 2018 00:52:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5yqDQVXFHG9zNz/s7WheSQglr6r1NfrOVua9fkr0Jus=; b=EjjEPdJt/CaRindtzlMlN6Bd+5/nbUrzDUGt//7mWr2+zK7Xr0QbWsQkRe7KUbjmv5 DTPXaBYa1/VHmLFTs44pPtApU5PNugdGsBsmEkjm15zPfxBeEBWzrdkriRFenSvgeZpC eI9f7SxY8XVhb7/kSnD/4MWhtFxfJmqFG+Nqw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5yqDQVXFHG9zNz/s7WheSQglr6r1NfrOVua9fkr0Jus=; b=PFIJI2WUQKhZ+m5rCVSnnNmOWT4o3NkIFN3yk2123QZ7yyKOV96FDV2QI7Vl9p1aic UjsCjMqndR9Hu67p29zNJF6gcAEAtdLnJF0p9HU40mudR7Jthq7KVcWj9yLvHkO+VeXT 5gACrefjzMLioXDwmPyUQFsx0xL+72M37Z3Esux+iLFDv6NO4X5EJpB+UO793iBRzq8A FE8vLxuUckS8kviVCCahgDiF/jv8iCazF7uhZzu69TuzQeGCThzf+vlXjgp8qTt5jGSA DEzIHX6gaVPvDVb/38Xcb04+TWbwr8sMfH9KJ4FTlzr6WdTauTfJKh2vNRAvwo5cDHWj lAuw== X-Gm-Message-State: APt69E3kVpEbJxbKduW6WrGR4ja3Rrep/geyiIpLR4lS0HKoCEl3BI5H OpEoKoyROcYNc1x5kdyj47XIwA== X-Google-Smtp-Source: AAOMgpf5RxDT7wjumP4iOkr1jxW10iU6g9/QXdDE+ZWWogk0nhzRPfnlzFhqX8S7F21IV4Hmp37mbA== X-Received: by 2002:a1c:110a:: with SMTP id 10-v6mr745825wmr.130.1529653976476; Fri, 22 Jun 2018 00:52:56 -0700 (PDT) Received: from dogfood.home ([2a01:cb1d:112:6f00:d0d9:3abb:8cc4:581c]) by smtp.gmail.com with ESMTPSA id s10-v6sm1593986wmb.12.2018.06.22.00.52.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Jun 2018 00:52:55 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: lersek@redhat.com, Ard Biesheuvel , linux-fbdev@vger.kernel.org, Bartlomiej Zolnierkiewicz , Peter Jones Subject: [PATCH v2 1/2] efi: drop type and attribute checks in efi_mem_desc_lookup() Date: Fri, 22 Jun 2018 09:52:49 +0200 Message-Id: <20180622075250.14075-2-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180622075250.14075-1-ard.biesheuvel@linaro.org> References: <20180622075250.14075-1-ard.biesheuvel@linaro.org> Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The current implementation of efi_mem_desc_lookup() includes the following check on the memory descriptor it returns: if (!(md->attribute & EFI_MEMORY_RUNTIME) && md->type != EFI_BOOT_SERVICES_DATA && md->type != EFI_RUNTIME_SERVICES_DATA) { continue; } This means that only EfiBootServicesData or EfiRuntimeServicesData regions are considered, or any other region type provided that it has the EFI_MEMORY_RUNTIME attribute set. Given what the name of the function implies, and the fact that any physical address can be described in the UEFI memory map only a single time, it does not make sense to impose this condition in the body of the loop, but instead, should be imposed by the caller depending on the value that is returned to it. Two such callers exist at the moment: - The BGRT code when running on x86, via efi_mem_reserve() and efi_arch_mem_reserve(). In this case, the region is already known to be EfiBootServicesData, and so the check is redundant. - The ESRT handling code which introduced this function, which calls it both directly from efi_esrt_init() and again via efi_mem_reserve() and efi_arch_mem_reserve() [on x86]. So let's move this check into the callers instead. This preserves the current behavior both for BGRT and ESRT handling, and allows the lookup routine to be reused by other [upcoming] users that don't have this limitation. In the ESRT case, keep the entire condition, so that platforms that deviate from the UEFI spec and use something other than EfiBootServicesData for the ESRT table will keep working as before. For x86's efi_arch_mem_reserve() implementation, limit the type to EfiBootServicesData, since it is the only type the reservation code expects to operate on in the first place. While we're at it, drop the __init annotation so that drivers can use it as well. Cc: Peter Jones Tested-by: Laszlo Ersek Signed-off-by: Ard Biesheuvel --- arch/x86/platform/efi/quirks.c | 3 ++- drivers/firmware/efi/efi.c | 8 +------- drivers/firmware/efi/esrt.c | 5 ++++- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c index 36c1f8b9f7e0..4ee6f4980afe 100644 --- a/arch/x86/platform/efi/quirks.c +++ b/arch/x86/platform/efi/quirks.c @@ -249,7 +249,8 @@ void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size) int num_entries; void *new; - if (efi_mem_desc_lookup(addr, &md)) { + if (efi_mem_desc_lookup(addr, &md) || + md.type != EFI_BOOT_SERVICES_DATA) { pr_err("Failed to lookup EFI memory descriptor for %pa\n", &addr); return; } diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 232f4915223b..cbc25d1c40bb 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -388,7 +388,7 @@ subsys_initcall(efisubsys_init); * and if so, populate the supplied memory descriptor with the appropriate * data. */ -int __init efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md) +int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md) { efi_memory_desc_t *md; @@ -406,12 +406,6 @@ int __init efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md) u64 size; u64 end; - if (!(md->attribute & EFI_MEMORY_RUNTIME) && - md->type != EFI_BOOT_SERVICES_DATA && - md->type != EFI_RUNTIME_SERVICES_DATA) { - continue; - } - size = md->num_pages << EFI_PAGE_SHIFT; end = md->phys_addr + size; if (phys_addr >= md->phys_addr && phys_addr < end) { diff --git a/drivers/firmware/efi/esrt.c b/drivers/firmware/efi/esrt.c index 1ab80e06e7c5..375a77c1c6e5 100644 --- a/drivers/firmware/efi/esrt.c +++ b/drivers/firmware/efi/esrt.c @@ -250,7 +250,10 @@ void __init efi_esrt_init(void) return; rc = efi_mem_desc_lookup(efi.esrt, &md); - if (rc < 0) { + if (rc < 0 || + (!(md.attribute & EFI_MEMORY_RUNTIME) && + md.type != EFI_BOOT_SERVICES_DATA && + md.type != EFI_RUNTIME_SERVICES_DATA)) { pr_warn("ESRT header is not in the memory map.\n"); return; }