From patchwork Thu Jul 12 14:14:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 10521759 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 BA64E602B3 for ; Thu, 12 Jul 2018 14:14:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A43A328581 for ; Thu, 12 Jul 2018 14:14:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 978F428429; Thu, 12 Jul 2018 14:14:19 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 35B5C283C5 for ; Thu, 12 Jul 2018 14:14:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From: References:In-Reply-To:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nVzET5rDhTh7YWdBrLYutViiIJrqKH6Pf6wKM7z23rs=; b=hyNXn/vuIV7pvR Q5DPvq+QZkEdyMxtshHnVvhhMqMUkOkx6HDGczo/Sw/yUVMx8n7oSJdqf+9V2qjGHxkm+KiCuBqdb MT+mRRYFOe8Ia+UM3P8+UdUBwv0iJV6TNK9KDauPKybz5P+N/+brrIJIjyAHy3cWDTSr6nfm+ve84 l052bD2pN1kl+52a3XxGRAE1QVKsszmgWUY/K0w+wdBXBLtLeL7iTmOiqhGwOtw/OP+R0PxB5Y37X I9abr6DPf0fVYmwan+B3XKNPDcOTnZfSBRvxfpplR7Cudo73sRLutEu50kGCoHE6JBW0Tty5OzV6N 7YunuQhaoOnriMR71dkg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fdcMJ-0001WN-Jf; Thu, 12 Jul 2018 14:14:15 +0000 Received: from mail-it0-x244.google.com ([2607:f8b0:4001:c0b::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fdcMG-0001Uf-In for linux-arm-kernel@lists.infradead.org; Thu, 12 Jul 2018 14:14:14 +0000 Received: by mail-it0-x244.google.com with SMTP id w16-v6so7033513ita.0 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=b9Q4RBVZKtbO/L5y6LhUOt89O3wCHm77YqTYaDXo3uG3Iz1UefR0a894x75sQMtRuf AJ7GgFNGW/P0PrkeqPbej+VSi0jeJDlq/x/2CsUzeolPbLaxFJ+1S2/2hOQwhLAyETxd Wtg5Qj8vovhpFpc2ybHTVgWNhB5Roc9VhEbd8tJuL7CIau91LxKPXjdxI8BoPLHlmrYt 2cMqdkTI0HkxtDlZWdv1k4G50QyilwV4epDEt8AhEd8kyhR5JckcRSRSEuCt0G/+Hpcz EdN5gCckeUD++YCahpPy+sltqmDQn7/cAspc2+uCZ2tfJhZd1xbXsyvA18JLdqh5fQVr tkUQ== X-Gm-Message-State: AOUpUlHB/TNlXIwBvKCqCar8HoJrrS9y+M7TbbvVESiSJoo5h/Rs4lew i8YLph0vYK4IMErD1yx2iSLfcikZ6kdNlMrL/469Ew== X-Google-Smtp-Source: AAOMgpemUgTwBhfMPkBeDydynTFvFN2xPNWS7R7j3kEalx7fX/eZiFtPHSoCU9bgOFzl1+Jon17fXInREcummyfphaw= 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180712_071412_631733_BFEA5991 X-CRM114-Status: GOOD ( 22.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Lorenzo Pieralisi , Graeme Gregory , Al Stone , Catalin Marinas , Bhupesh Sharma , "Baicar, Tyler" , Kexec Mailing List , Linux Kernel Mailing List , AKASHI Takahiro , James Morse , Hanjun Guo , Sudeep Holla , Dave Young , linux-arm-kernel Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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; }