Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3433193imu; Mon, 24 Dec 2018 01:41:11 -0800 (PST) X-Google-Smtp-Source: ALg8bN6I5OW5xXvnRhbhOtwVkpC/KbFkYe9JjbNxe9mxrzWvL6CKvVcKMhLJNipVuIkmOLGG9ds1 X-Received: by 2002:a63:da14:: with SMTP id c20mr11271506pgh.233.1545644471182; Mon, 24 Dec 2018 01:41:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545644471; cv=none; d=google.com; s=arc-20160816; b=R2btAgBH2Gg634f9tLtg7+15aM3y2MrVlhC76VvkpelLPrzUjx3SmYNksgnhj9Cs4m 01ZX5NEz83wo+hxhw3BtKsXHcCMlo8dP8OYHuIvgElUy2lRcUxjvTTBWTVhdErsbm8cw PsfK+cbMSI4DqZhyhH1s1pkCJIfXFqB66TOVeEc5Y7EGzOwJbhX48r1qXkJ8g4ZK7+Zd RtxGq3WzTCHopybzKXFddoshhaLyp6E/z+5Vp3ooxUAWJeYJHzAtnwtudhNj49iBqUnd H1EFs5hKw74KJlSlA1+LVe4lYf8DI87mf6WC7P6o3vG1Uhmea7f3yTQgMECj2jWXCi/m d/2g== 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 :in-reply-to:references:mime-version:dkim-signature; bh=d5I1c8Wey62ZKsjqwQmuj6B7Jc6spwFggQJOYiKRnBc=; b=M/ARppHLoeiSvRF/shwvLGUVKITNt0IXBoCw3n+R7Dn5xUNMAk9bjALHE66uvbz4Dn 2JXEygEWuV0zqaRpmNGr7wSbRs7TvidXCPUER4wX1+TgriLFkiaSo/6jDbdk0nFLzLG8 II4sCDD87ruKF3ZYUAL5Xppvloq2bzzfLt3U+6PsJ8NTHUAG9j1DffD+6Qkk0vOZrWf2 4iJD3Lp17ZsO960lfKzAWrv/PNhqbfS+ULahdyI4fnKii9WpudOPyXRRrabbBzfiLsdY 5H3DDFDp93pzsBU76tiNJ5kMqDVEO/15oiwcZtvlXltzxxymKsox3jGMXvROk9IZpkyB QDAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aly6+Yas; 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 b8si28302388ple.185.2018.12.24.01.40.55; Mon, 24 Dec 2018 01:41:11 -0800 (PST) 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=aly6+Yas; 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 S1725799AbeLXJi5 (ORCPT + 99 others); Mon, 24 Dec 2018 04:38:57 -0500 Received: from mail-io1-f65.google.com ([209.85.166.65]:40725 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725294AbeLXJi5 (ORCPT ); Mon, 24 Dec 2018 04:38:57 -0500 Received: by mail-io1-f65.google.com with SMTP id a11so264524ioq.7 for ; Mon, 24 Dec 2018 01:38:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=d5I1c8Wey62ZKsjqwQmuj6B7Jc6spwFggQJOYiKRnBc=; b=aly6+YasQGe+YuXn8831VRHt84/7x0u5knFJ3g4ZrVKumpngdDrgShGmbuc7an3/6U fvtcOIeqe/UOzk6LWut7KrKD0vx8nSX7VBvzlj6J6Seb1Eyq2C1HPa0e1IBYxh1RpHnE Ua/AgbJX+Br1rMgTviat67Ip9qhVqCLeUuBZo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=d5I1c8Wey62ZKsjqwQmuj6B7Jc6spwFggQJOYiKRnBc=; b=Xy4H4i4ebntGFIAhFkwt7DwSbtW95ej7J3GxqULEvwWu6DP6p+hn71eJw7mnx9huiU jNmTTDblPLwsF7KLF5pZh6G38Hsxy5WvmKtzU1x6mYuNE28RuCY1QKHkyBQ40A+og0nr 6WOs3M99YM0rzPwnu+HCe9R0naDnZXo+ijb1R+pr/jrI2IpMdw+nP3wOp8+1B4+88Tl6 R8HXHXbxjO3qt6u4cJs4jbHun5BFcJ2ttMPIA1J4mahq/pg4Io2v98bSFKvdAtvmDlzT yUQuzkfnW/j5MTOm0qoexeuLSz2a8tJf814FEA5ASavfk7muypf23G6pUa/FepN3Geo2 2o9g== X-Gm-Message-State: AJcUukcvg7N79eBrQ60dng5CdbXT4at1rMlplzfTdAceLOpmElaFDjNC kAqmrkx6ZQqnvuDMNeaj1HY+JH6Zq5qhyd0kYKtykQ== X-Received: by 2002:a5d:8417:: with SMTP id i23mr1206692ion.173.1545644336036; Mon, 24 Dec 2018 01:38:56 -0800 (PST) MIME-Version: 1.0 References: <20181222022234.7573-1-sai.praneeth.prakhya@intel.com> <20181222105410.GA130780@gmail.com> In-Reply-To: From: Ard Biesheuvel Date: Mon, 24 Dec 2018 10:38:44 +0100 Message-ID: Subject: Re: [PATCH] x86/efi: Don't unmap EFI boot services code/data regions for EFI_OLD_MEMMAP and EFI_MIXED_MODE To: Ingo Molnar Cc: Sai Praneeth Prakhya , linux-efi , Linux Kernel Mailing List , "the arch/x86 maintainers" , Borislav Petkov , Andy Lutomirski , Dave Hansen , Bhupesh Sharma , Peter Zijlstra , Thomas Gleixner 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 Sat, 22 Dec 2018 at 12:04, Ard Biesheuvel wrote: > > On Sat, 22 Dec 2018 at 11:54, Ingo Molnar wrote: > > > > > > * Sai Praneeth Prakhya wrote: > > > > > Commit d5052a7130a6 ("x86/efi: Unmap EFI boot services code/data regions > > > from efi_pgd") forgets to take two EFI modes into consideration namely > > > EFI_OLD_MEMMAP and EFI_MIXED_MODE. > > > > So the commit sha1 ended up being this one in tip:efi/core: > > > > 08cfb38f3ef4: x86/efi: Unmap EFI boot services code/data regions from efi_pgd > > > > > EFI_OLD_MEMMAP is a legacy way of mapping EFI regions into swapper_pg_dir > > > using ioremap() and init_memory_mapping(). This feature can be enabled by > > > passing "efi=old_map" as kernel command line argument. But, > > > efi_unmap_pages() unmaps EFI boot services code/data regions *only* from > > > efi_pgd and hence cannot be used for unmapping EFI boot services code/data > > > regions from swapper_pg_dir. > > > > > > Introduce a temporary fix to not unmap EFI boot services code/data regions > > > when EFI_OLD_MEMMAP is enabled while working on a real fix. > > > > > > EFI_MIXED_MODE is another feature where a 64-bit kernel runs on a > > > 64-bit platform crippled by a 32-bit firmware. To support EFI_MIXED_MODE, > > > all RAM (i.e. namely EFI regions like EFI_CONVENTIONAL_MEMORY, > > > EFI_LOADER_, EFI_BOOT_SERVICES_ and > > > EFI_RUNTIME_CODE/DATA regions) is mapped into efi_pgd all the time to > > > facilitate EFI runtime calls access it's arguments in 1:1 mode. Hence, > > > don't unmap EFI boot services code/data regions when booted in mixed mode. > > > > > > Signed-off-by: Sai Praneeth Prakhya > > > Cc: Borislav Petkov > > > Cc: Ingo Molnar > > > Cc: Andy Lutomirski > > > Cc: Dave Hansen > > > Cc: Bhupesh Sharma > > > Cc: Peter Zijlstra > > > Cc: Thomas Gleixner > > > Cc: Ard Biesheuvel > > > --- > > > arch/x86/platform/efi/quirks.c | 16 ++++++++++++++++ > > > 1 file changed, 16 insertions(+) > > > > > > diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c > > > index 09e811b9da26..9c34230aaeae 100644 > > > --- a/arch/x86/platform/efi/quirks.c > > > +++ b/arch/x86/platform/efi/quirks.c > > > @@ -380,6 +380,22 @@ static void __init efi_unmap_pages(efi_memory_desc_t *md) > > > u64 pa = md->phys_addr; > > > u64 va = md->virt_addr; > > > > > > + /* > > > + * To Do: Remove this check after adding functionality to unmap EFI boot > > > + * services code/data regions from direct mapping area because > > > + * "efi=old_map" maps EFI regions in swapper_pg_dir. > > > + */ > > > + if (efi_enabled(EFI_OLD_MEMMAP)) > > > + return; > > > + > > > + /* > > > + * EFI mixed mode has all RAM mapped to access arguments while making > > > + * EFI runtime calls, hence don't unmap EFI boot services code/data > > > + * regions. > > > + */ > > > + if (!efi_is_native() && IS_ENABLED(CONFIG_EFI_MIXED)) > > AFAIK efi_is_native() can only return false is CONFIG_EFI_MIXED is > set, so this expression can be simplified. > > > > + return; > > > > I suppose old_mmap and mixed mode stopped working altogether after the > > unmapping changes? What are the symptoms, instant reboots, crasher, or > > some more benign behavior like non-working runtime EFI functionality? > > > > If Ard acks this I'll apply it immediately, as these bugs look like > > show-stoppers for merging the EFI tree into v4.21. > > > > Acked-by: Ard Biesheuvel > > with the sidenote that I won't be able to test this myself until > monday at the earliest. OK, so I have tested both efi=old_map and mixed mode before and after applying this patch, using QEMU/KVM with 64-bit and 32-bit builds of OVMF [respectively] efi=old_map is indeed broken before and needs this patch. Mixed mode works just fine both before and after applying the patch, but I suggest we keep this patch as-is and address mixed mode later if needed (I spotted a couple of things in the boot log that may need some attention but I'm not sure if the issue is in Linux or in OVMF)