Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp300815imm; Wed, 11 Jul 2018 02:41:59 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfSVTLFBhLaXqVcvA3OlYTDb4qvVMxLXpAF9L2kM9H2TylIFHo+56hpsQkRpt0ohrFA3AqQ X-Received: by 2002:a65:58c8:: with SMTP id e8-v6mr25493096pgu.96.1531302119163; Wed, 11 Jul 2018 02:41:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531302119; cv=none; d=google.com; s=arc-20160816; b=oBdPYcUMV/QOI3bM/2yeJaIneNOryOivmXtr10ex4cj9J5L7fvHgBl4EjJpMnHJHHc DNdhhlIUqSkyKXNyPSUadfk8GwvM6hFbzFu9XQ8KW/mPASbNkuyn8paDXvFbp23NtQsC 4gOVv6RDGPe0JpyHv9IW1GDAf1xndc2jaeAVJp+J85TZDG7HAGqlMMe2Sa40HN7Rpw3C aLk+EfO4wiwvUbGTSR80Q36KKXf7n5lwUOTwKonvWGkHiLi3LZs99yQfR57WQUsRVwRZ tzuXcD5XrBGn3ZDGHHSr+78VjveK/95GYm7FlKwzpSci92Lg3m+0degP1Gt7843OmLph 37Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=K6onjEFl2BD59yiPdC7EvEbLejow6UKfjhclEvp4LkA=; b=nBhWjv8euejiDUSxoKWI3pOxRUeGiM/hAbXm66TM1Edorh+bit0U/KkfxOc03j2AzG bRxHqiQVyAf2vAWOgV2Sv5Lw8ITE4uHSlCDTd4fi4oo0ioX8VDepHrQCyPoW6Y2cPhNy Mb0ArqaeVUqTv8y03yylTmtcIQltaZ9ttb4WowzmF6Njx2/IjUFfQ77Amt57hOiDrsjd 5U3Gil+de6GEHCZs6CDgV0no9+tVlJL3nfE+BGtP64lhwj55fsx+OEPXFYnwl31hztBq GsgX+CPXkp2m5XdWkdKUckDPqUwUCPOAsf8hPr/w8LGY7I348nCKNEte+dltSfzPcJBa NIQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FAIjelsb; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e190-v6si19193217pfa.355.2018.07.11.02.41.41; Wed, 11 Jul 2018 02:41:59 -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; dkim=pass header.i=@linaro.org header.s=google header.b=FAIjelsb; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732721AbeGKJo2 (ORCPT + 99 others); Wed, 11 Jul 2018 05:44:28 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:40341 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732649AbeGKJo0 (ORCPT ); Wed, 11 Jul 2018 05:44:26 -0400 Received: by mail-wm0-f65.google.com with SMTP id z13-v6so1821984wma.5 for ; Wed, 11 Jul 2018 02:40:59 -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=K6onjEFl2BD59yiPdC7EvEbLejow6UKfjhclEvp4LkA=; b=FAIjelsbktZKTdXOlDgXx8BIdZLA3mpzvc/qBvRBbuHHBgjgSpxQWUxUCdtKCeoo90 9EKDY2skViyPH/ng/v1zuQDPGWw4qJluEZl/JY9pAJmpQ3bxcnrTADN+o/5TNkPCTPZq Hh2KJ5KsyyBdSiZ2oKe3DPaG8UdGaerdscnN8= 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=K6onjEFl2BD59yiPdC7EvEbLejow6UKfjhclEvp4LkA=; b=kwGS9ddl1Hl4ZW9vgz1AGMNZ6zx5EG2Ph5jNYxiIe0uYOyMYCJBmlGZeUgfHvVfh6M xX4hAyKKNHeWIMrCJhdOjjrlTPGfyUIzSZEtSA0Z4hEjfWuP5nUUS3dGm2LHFiie/9Ul EmLboymqZ+n8UTXc81g/DLJNpuO8bDBK8y7fskyZ2rqo4Sz4DW10No2SABauN7OQYih3 ttPAe/wytvW736wyqr98AKsmCZBiW8HAKt7RyBojdMRFV+cuC4rvPEykMYFzLjza+chN yc3gxd5/wu7wf5U18Z/iFybCdszZkD/NY+Fhxv0PjJwX8jbmn6sznBbaiQyWgaBa267i MQaA== X-Gm-Message-State: APt69E3IrTNh+HGX6DUlGeLn/IbHWp1nVjmcywkhZCpHGg+t7FtumRwM 8+6Uueyn/KKRYwaO7K1m3o/rEFWkyYE= X-Received: by 2002:a1c:894f:: with SMTP id l76-v6mr16495795wmd.103.1531302058259; Wed, 11 Jul 2018 02:40:58 -0700 (PDT) Received: from localhost.localdomain (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id t124-v6sm1641311wmt.29.2018.07.11.02.40.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 02:40:57 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Peter Jones Subject: [PATCH 7/8] efi: drop type and attribute checks in efi_mem_desc_lookup() Date: Wed, 11 Jul 2018 11:40:39 +0200 Message-Id: <20180711094040.12506-8-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180711094040.12506-1-ard.biesheuvel@linaro.org> References: <20180711094040.12506-1-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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; } -- 2.17.1