Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1749256imm; Thu, 12 Jul 2018 07:15:01 -0700 (PDT) X-Google-Smtp-Source: AAOMgpff4ogqNsSffvpr2PF1GNatPhP4VOxq5hHTDbCjB2PYKTdc8MIaVRFEvGAs+n6Y3Etxz0Y3 X-Received: by 2002:a65:4b87:: with SMTP id t7-v6mr2256466pgq.391.1531404901680; Thu, 12 Jul 2018 07:15:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531404901; cv=none; d=google.com; s=arc-20160816; b=JoF6uZFclO1T+4NxaPmDWWkYwJ+JYbGOIsk4gJLHABosgW1ptp/6PLZ9FaBHYzfY3Z 1CZPE2WGxseVGqCdq7dEK0mJvbWy85CCKYs/sfc9DREi6g30g9SX02ZU/Gig0AAx/bGb ByFnLP/nWaFcSXWudj8xZ7wF9QX1X+hgMnJwVyJwQTS3G+CvafHFmSl5IZNgXU54mwI2 ooeah8ISZgeSMZqZtDM+JuUUgqNbnsBbh83pbokGimkHBvA3fdz09GNnz6eqTV5T8g3N leIdkNYR+q17QcE6Zj6F5VuEPQDU09kBISpRghK9j01cthY4/RtdNHdCQI16EpkaNQc3 hF0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=KvfAo8SDQ5+PyIA7ArOk5rdKdqRapsK9s15MKvPJWLo=; b=jj68WiMBe2GQgznFlLEqni0GUahkLj1XQVz6hQ4gm4SAsqr4esaBp/L4iMTAZxsK+4 tC3KTNQdVpNtdFX75rmmMSp0r1e+HN3og2ZxqMV4ounCjl2I0XL+jlxTlQiaAGftwsa2 RHWFbBeEU/lBTtiXYlICdVAhgRqUe5sEDmsTTtGq27vhYJARJ7I0q29iToLfxiw9KdjW G5YTkiDkxZ6LFQ1APzeiftW38apw4SBXW/EBmFguJxZTdOGX9XyQuCT6PTuqgq3GdrNL x6FE36nUt9Wau7zVulrjW1wcKvkEk9f8fO78OejKQryWYoOYbEIHC9dZd0C/zfXG+Qbq 4VgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AhhyUlOu; 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 k18-v6si21318581pll.404.2018.07.12.07.14.46; Thu, 12 Jul 2018 07:15:01 -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=AhhyUlOu; 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 S1732395AbeGLOXr (ORCPT + 99 others); Thu, 12 Jul 2018 10:23:47 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:53090 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727002AbeGLOXq (ORCPT ); Thu, 12 Jul 2018 10:23:46 -0400 Received: by mail-it0-f66.google.com with SMTP id p4-v6so7019779itf.2 for ; Thu, 12 Jul 2018 07:14:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=KvfAo8SDQ5+PyIA7ArOk5rdKdqRapsK9s15MKvPJWLo=; b=AhhyUlOuYBx9a4EDtRvqU3F7pJofU4HAoAI9k038G9Fmhu5l94ZMxlgc9b9CtSNcfI NqTBsoZUJzjgzzYzvfmWw4BLk7pwgIDwFUxK9BoT3ukVJvZnLh3PktdglHbN0IpA9cHk sq7YMwqaU9xh83v2jjcRHKHpbEXrmgGxbbizU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=KvfAo8SDQ5+PyIA7ArOk5rdKdqRapsK9s15MKvPJWLo=; b=uYZCIOxOl575qGGY2QP/wUe/6yJN42BTWiZbO/9j68noqU0HK9m2zQJ2bfeKzl+iyI wvb4C8IbpQEliPN35/81MYQzpU1DbfS/UJhwehqo/CBfIqCh5zST0zgjHtv0QOUEszHK zVXBR5xzNuZhKtY8NWZ3e06sA41pgNGpaICgYajXSSjBSn/d8TjwYjLYwEoDiexelD7Y Hka1J4ds67MO0Bk1BhdGsCT+UeYdQbwvnaJPQGhD+2x4DAu7lg3HYSkL5w7xSi9D6hO3 CYDmn70qKhIrWE/W1huSCZtF15ejf59+olUk9KnDfu7mTEX4h7gMi4SK/e05m5iD4Tji 4HWg== X-Gm-Message-State: AOUpUlFfr3Z9XsFdzsfguNLJ1lrDCorCj0GG9qui50YyqL/ZFrqjuOMn qfs8lqcXuKzuVQi6V+HWsy+w+HFB/CbxlvROeFOxbw== X-Received: by 2002:a24:6196:: with SMTP id s144-v6mr1450084itc.68.1531404841008; Thu, 12 Jul 2018 07:14:01 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:bbc7:0:0:0:0:0 with HTTP; Thu, 12 Jul 2018 07:14:00 -0700 (PDT) In-Reply-To: <20180712133220.GA21647@arm.com> References: <20180709234229.20181-1-takahiro.akashi@linaro.org> <20180709234229.20181-3-takahiro.akashi@linaro.org> <93c42065-bece-a4c7-ed99-5e98f91315a6@arm.com> <20180712133220.GA21647@arm.com> From: Ard Biesheuvel Date: Thu, 12 Jul 2018 16:14:00 +0200 Message-ID: Subject: Re: [PATCH v3.1 2/4] efi/arm: preserve early mapping of UEFI memory map longer for BGRT To: Will Deacon Cc: James Morse , AKASHI Takahiro , Catalin Marinas , "Baicar, Tyler" , Bhupesh Sharma , Dave Young , Mark Rutland , Al Stone , Graeme Gregory , Hanjun Guo , Lorenzo Pieralisi , Sudeep Holla , linux-arm-kernel , Linux Kernel Mailing List , Kexec Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12 July 2018 at 15:32, Will Deacon wrote: > On Tue, Jul 10, 2018 at 08:39:16PM +0200, Ard Biesheuvel wrote: >> On 10 July 2018 at 19:57, James Morse wrote: >> > Hi Ard, >> > >> > On 10/07/18 00:42, AKASHI Takahiro wrote: >> >> From: Ard Biesheuvel >> >> >> >> The BGRT code validates the contents of the table against the UEFI >> >> memory map, and so it expects it to be mapped when the code runs. >> >> >> >> On ARM, this is currently not the case, since we tear down the early >> >> mapping after efi_init() completes, and only create the permanent >> >> mapping in arm_enable_runtime_services(), which executes as an early >> >> initcall, but still leaves a window where the UEFI memory map is not >> >> mapped. >> >> >> >> So move the call to efi_memmap_unmap() from efi_init() to >> >> arm_enable_runtime_services(). >> > >> > I don't have a machine that generates a BGRT, but I can see that efi_mem_type() >> > call in efi_bgrt_init() would cause the same problems we have with kexec and acpi. >> > >> >> I'm not sure I follow. The BGRT table only contains natively aligned >> fields, so the alignment faults should not occur when accessing this >> table after kexec. The issue addressed by this patch is that >> efi_mem_type() bails when called while EFI_MEMMAP is cleared. >> >> > >> >> diff --git a/drivers/firmware/efi/arm-init.c b/drivers/firmware/efi/arm-init.c >> >> index b5214c143fee..388a929baf95 100644 >> >> --- a/drivers/firmware/efi/arm-init.c >> >> +++ b/drivers/firmware/efi/arm-init.c >> >> @@ -259,7 +259,6 @@ void __init efi_init(void) >> >> >> >> reserve_regions(); >> >> efi_esrt_init(); >> >> - efi_memmap_unmap(); >> >> >> >> memblock_reserve(params.mmap & PAGE_MASK, >> >> PAGE_ALIGN(params.mmap_size + >> >> diff --git a/drivers/firmware/efi/arm-runtime.c b/drivers/firmware/efi/arm-runtime.c >> >> index 5889cbea60b8..59a8c0ec94d5 100644 >> >> --- a/drivers/firmware/efi/arm-runtime.c >> >> +++ b/drivers/firmware/efi/arm-runtime.c >> >> @@ -115,6 +115,8 @@ static int __init arm_enable_runtime_services(void) >> >> return 0; >> >> } >> >> >> >> + efi_memmap_unmap(); >> > >> > This can get called twice if uefi_init() fails after setting the EFI_BOOT flag, >> > but this can only happen if the system table signature is wrong, (or we're out >> > of memory really early). >> > >> >> I guess we should check the EFI_MEMMAP attribute here as well then. > > Do you plan to spin a new version of this patch? > Either that or fold in the hunk below. --- a/drivers/firmware/efi/arm-runtime.c +++ b/drivers/firmware/efi/arm-runtime.c @@ -110,7 +110,7 @@ static int __init arm_enable_runtime_services(void) { u64 mapsize; - if (!efi_enabled(EFI_BOOT)) { + if (!efi_enabled(EFI_BOOT) || !efi_enabled(EFI_MEMMAP)) { pr_info("EFI services will not be available.\n"); return 0; }