Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1767092imm; Sun, 15 Jul 2018 16:41:41 -0700 (PDT) X-Google-Smtp-Source: AAOMgperVJE1G20lrsvrxL2XrPtxz6tg88YmJzzLumVMbpEv+Ka0UYGiVofl2ZaL1W4aT6iAaP8I X-Received: by 2002:a17:902:8:: with SMTP id 8-v6mr14850846pla.287.1531698101598; Sun, 15 Jul 2018 16:41:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531698101; cv=none; d=google.com; s=arc-20160816; b=GcPSqlR32Wysic0ThunWo3RuALVhY3thmJvzKoSrBe8bGIkU4orZeRHT5LLF23FfXc rE/jmvc42F9LCPociqiyyrmoXoYGpMB6IcLKudnCaoQW6a4u20H4w7Z/dL5iCI8XpW57 fZdnXZb3CXIq6HqR/cuWr2rT/aP3dffsovkZMtCL/rFm0RnWFf4nqHcaTDBvlhKLafXM bKxWEaqNKCSvYxoH8uIZRQQKSLpNpso1JsjcQq2Ywe5G9ws0Tx8h+P4CrGUbr01naFqs MhdFIJIUZnYeayJYW6sgoRkE5ROYwsaglC+yhflHPZg7HxFKVCQV63ujnHydgB+DwWe1 +Whw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=bICu3lhrb+T2+WOsIjHi+z68sIUppdY1VXFdDLw4Fnw=; b=f3+pRZ0I3n67PesDJu9eDovrTGJG1Dr0tRDR1Mksh9YY0LZf6q9skAr7WGu7sQ1CrE g0PKDhVCK5P/uLPa41VEB+ixp0/wj7l/K4aVIwH0q2c/sFJa9Lu1eAmu6usq618Mhr3O n3zYTg3CBu3vleF5tcHca7YC+GOw2MIQYgmU6qpjkwW/0W2spLDqATSNLttYF22ClGu/ zqMPXy2iiP924ZZyOxNJ6QZHd5MKbkbCmDvR57oKpQMhd5FA9pJZyJZQ4P6D24EbAJ7r f1iEfbYP3IG0payDHj9REI3U7t1A1Kdc+GIlsLuCOhswfFbAe6OOtjaItNBV9tDouV6M XeKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g2-v6si28764399pgg.83.2018.07.15.16.41.27; Sun, 15 Jul 2018 16:41:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727836AbeGPAE6 (ORCPT + 99 others); Sun, 15 Jul 2018 20:04:58 -0400 Received: from terminus.zytor.com ([198.137.202.136]:42719 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727027AbeGPAE6 (ORCPT ); Sun, 15 Jul 2018 20:04:58 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w6FNdrbB923011 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 15 Jul 2018 16:39:53 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w6FNdrTF923004; Sun, 15 Jul 2018 16:39:53 -0700 Date: Sun, 15 Jul 2018 16:39:53 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Ard Biesheuvel Message-ID: Cc: lersek@redhat.com, mingo@kernel.org, tglx@linutronix.de, ard.biesheuvel@linaro.org, peterz@infradead.org, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, pjones@redhat.com, hpa@zytor.com Reply-To: tglx@linutronix.de, ard.biesheuvel@linaro.org, peterz@infradead.org, lersek@redhat.com, mingo@kernel.org, pjones@redhat.com, hpa@zytor.com, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org In-Reply-To: <20180711094040.12506-8-ard.biesheuvel@linaro.org> References: <20180711094040.12506-8-ard.biesheuvel@linaro.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:efi/core] efi: Drop type and attribute checks in efi_mem_desc_lookup() Git-Commit-ID: 7e1550b8f2081cccdfa9f1cf1e54cbc4d720af7f X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 7e1550b8f2081cccdfa9f1cf1e54cbc4d720af7f Gitweb: https://git.kernel.org/tip/7e1550b8f2081cccdfa9f1cf1e54cbc4d720af7f Author: Ard Biesheuvel AuthorDate: Wed, 11 Jul 2018 11:40:39 +0200 Committer: Ingo Molnar CommitDate: Mon, 16 Jul 2018 00:43:12 +0200 efi: Drop type and attribute checks in efi_mem_desc_lookup() 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. Tested-by: Laszlo Ersek Signed-off-by: Ard Biesheuvel Cc: Linus Torvalds Cc: Peter Jones Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20180711094040.12506-8-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar --- 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 6af39dc40325..844d31cb8a0c 100644 --- a/arch/x86/platform/efi/quirks.c +++ b/arch/x86/platform/efi/quirks.c @@ -248,7 +248,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 1379a375dfa8..d8a33a781a57 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -402,7 +402,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; @@ -420,12 +420,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; }