Received: by 10.192.165.156 with SMTP id m28csp377291imm; Mon, 16 Apr 2018 01:30:21 -0700 (PDT) X-Google-Smtp-Source: AIpwx499sFl37b6zPO4sNXRXDyJG8KOXc8zk8uaLAdN+YveShMLBxFqGeOq8mQXWlQ+VHxlhefiu X-Received: by 10.167.128.2 with SMTP id j2mr20485501pfi.126.1523867421288; Mon, 16 Apr 2018 01:30:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523867421; cv=none; d=google.com; s=arc-20160816; b=u4EvdOkgzkZI2rpG26x9SrcBI6APGAMzNmQKjIzawOAILeIEFCIXiSujHAzBycoQ1+ 88+KT6gZrsPol00IxTO7ZsuionNkI2fYPBrvHNIMeTDnAtL3vPlGDUolan5T19kzSMWo 7PJfH+I6pSDY1li27ih3oxL0ttNxrUMzmQKAQHjZ1KOb5+vF6pKOGwPRS0IFUPeaH+yl gFxjLEbVQQql3vc12lH/djxom7L/8CDrLZsKnnkmx7CrsfeTZt4xIrO7tgagXdRGRiG9 IPSEQ1Y98a+B7tZkC1sWJi0CobutEsYWU8Fg3xlNyU2bVGSlUdK24OBH7dEOKZMqPbaB 19FQ== 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=B22lYjnhsda1CwXZO/eKgpXOVFrV2obCtCDKvLQ0tRQ=; b=xM3+9r5j3pCvvQW+oRD7vj70wEih3c5B06Jp1cyNaGY2rCAQb/L8hpca7M9/hHnyZh HQ2LUhNjKe21TA7L+ENCN0lbNIRbsvFqHeQ4xUdzsb7/A92cWUNRa4AgyzsV7iyrlQMX ymkzoPxgAkFjpfoaGR0auUDsPkKynXvQ+cGS9XB4ClCfHDZ3RykOblZd6DfJGD9eMkQd jJjz1c14hVbjDjHony+NtGBDIwBxRb2TOZDdirHRFOqT62k3Ct1ofMJ/f9f0x5OIWlFv wxZzjUM6rkIoSTqUypZOH0HvN8MtoBMJJhjWJ50SNfVRW8cBAhI7XH5ZIgXDUm1bspF/ PNWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FQ19EKxX; 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 a86si10599173pfc.207.2018.04.16.01.30.06; Mon, 16 Apr 2018 01:30:21 -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=FQ19EKxX; 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 S1753942AbeDPIXU (ORCPT + 99 others); Mon, 16 Apr 2018 04:23:20 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:52283 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753918AbeDPIXS (ORCPT ); Mon, 16 Apr 2018 04:23:18 -0400 Received: by mail-it0-f68.google.com with SMTP id f6-v6so10341394ita.2 for ; Mon, 16 Apr 2018 01:23:17 -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=B22lYjnhsda1CwXZO/eKgpXOVFrV2obCtCDKvLQ0tRQ=; b=FQ19EKxX6IKluNpVd87+M77a2cc5NcORfh3RHHLKfkP0VqNTMfLG/kK5fKabj1m8SR J6p5AtM6qWN2GOUUbrwqYbknJJtSosr+AdHZk2fkH/BsrGzARLvhwDynV0/rx6VAbb0v HKCz2nCfQSB1TkV7zjPq6MqPzYqheYMD+/Hq8= 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=B22lYjnhsda1CwXZO/eKgpXOVFrV2obCtCDKvLQ0tRQ=; b=NlbTHjyjOSPbv82P7QBf1sQVN0y4LLXuGd3EaHzNJr1UolBPxK+nQ197JecP0IUs0C gzh1dMO14yI9B4AzlSWtSHq2BkBKVjxx+mhFxTOXdRNYPfVGJmOkwIeGrrui8yKkmOAq j6LMdF/WX/+OmXvD8EFdtAR3IzUxgPG0WBe2+ERZRgyz9SWtToED5PSepZY5YZVGkOWO G6IIbOq8dyLYR5mQXTZbNR1xPtvGt+mCYH0tfPj29cqwcswNiu/PyuVAbYrS3PCpUeuG V41ucJ/tjOJ9iJo8U/I6VmLEwM9u0C5DC0FGXP8QN25KPyopyt39K2AbkWs49VeWa39E 9ZrQ== X-Gm-Message-State: ALQs6tCJ94PYPq6xVlc5nZXopeUlonf+V4nz4tr3Kzc1nPn0pUdKbfxy IWyN680gO6vHryhrl37zlyGMDDl2LYix1pYKl+osLg== X-Received: by 2002:a24:2b0b:: with SMTP id h11-v6mr14689965ita.68.1523866997486; Mon, 16 Apr 2018 01:23:17 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.187.67 with HTTP; Mon, 16 Apr 2018 01:23:17 -0700 (PDT) In-Reply-To: <20180408174014.21908-2-hdegoede@redhat.com> References: <20180408174014.21908-1-hdegoede@redhat.com> <20180408174014.21908-2-hdegoede@redhat.com> From: Ard Biesheuvel Date: Mon, 16 Apr 2018 10:23:17 +0200 Message-ID: Subject: Re: [PATCH v3 1/5] efi: Export boot-services code and data as debugfs-blobs To: Hans de Goede Cc: Darren Hart , Andy Shevchenko , "Luis R . Rodriguez" , Greg Kroah-Hartman , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , platform-driver-x86@vger.kernel.org, Linux Kernel Mailing List , Peter Jones , Dave Olsthoorn , Will Deacon , Andy Lutomirski , Matt Fleming , David Howells , Mimi Zohar , Josh Triplett , Dmitry Torokhov , Martin Fuzzey , Kees Cook , Kalle Valo , Arend Van Spriel , Linus Torvalds , Nicolas Broeking , Bjorn Andersson , Torsten Duwe , "the arch/x86 maintainers" , linux-efi@vger.kernel.org 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 Hallo Hans, On 8 April 2018 at 19:40, Hans de Goede wrote: > Sometimes it is useful to be able to dump the efi boot-services code and > data. This commit adds these as debugfs-blobs to /sys/kernel/debug/efi, > but only if efi=debug is passed on the kernel-commandline as this requires > not freeing those memory-regions, which costs 20+ MB of RAM. > > Signed-off-by: Hans de Goede > --- > Changes in v2: > -Do not call pr_err on debugfs call failures > --- > arch/x86/platform/efi/quirks.c | 4 +++ > drivers/firmware/efi/efi.c | 53 ++++++++++++++++++++++++++++++++++ > 2 files changed, 57 insertions(+) > > diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c > index 5b513ccffde4..0f968c7bcfec 100644 > --- a/arch/x86/platform/efi/quirks.c > +++ b/arch/x86/platform/efi/quirks.c > @@ -374,6 +374,10 @@ void __init efi_free_boot_services(void) > int num_entries = 0; > void *new, *new_md; > > + /* Keep all regions for /sys/kernel/debug/efi */ > + if (efi_enabled(EFI_DBG)) > + return; > + > for_each_efi_memory_desc(md) { > unsigned long long start = md->phys_addr; > unsigned long long size = md->num_pages << EFI_PAGE_SHIFT; > diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c > index cd42f66a7c85..10c896e8b82b 100644 > --- a/drivers/firmware/efi/efi.c > +++ b/drivers/firmware/efi/efi.c > @@ -18,6 +18,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -316,6 +317,55 @@ static __init int efivar_ssdt_load(void) > static inline int efivar_ssdt_load(void) { return 0; } > #endif > > +#ifdef CONFIG_DEBUG_FS > + > +#define EFI_DEBUGFS_MAX_BLOBS 32 > + > +static struct debugfs_blob_wrapper debugfs_blob[EFI_DEBUGFS_MAX_BLOBS]; > + > +static void __init efi_debugfs_init(void) > +{ > + struct dentry *efi_debugfs; > + efi_memory_desc_t *md; > + char name[32]; > + int type_count[EFI_BOOT_SERVICES_DATA + 1] = {}; > + int i = 0; > + > + efi_debugfs = debugfs_create_dir("efi", NULL); > + if (IS_ERR_OR_NULL(efi_debugfs)) > + return; > + > + for_each_efi_memory_desc(md) { > + switch (md->type) { > + case EFI_BOOT_SERVICES_CODE: > + snprintf(name, sizeof(name), "boot_services_code%d", > + type_count[md->type]++); > + break; > + case EFI_BOOT_SERVICES_DATA: > + snprintf(name, sizeof(name), "boot_services_data%d", > + type_count[md->type]++); > + break; > + default: > + continue; > + } > + > + debugfs_blob[i].size = md->num_pages << EFI_PAGE_SHIFT; > + debugfs_blob[i].data = memremap(md->phys_addr, > + debugfs_blob[i].size, > + MEMREMAP_WB); > + if (!debugfs_blob[i].data) > + continue; > + > + debugfs_create_blob(name, 0400, efi_debugfs, &debugfs_blob[i]); > + i++; > + if (i == EFI_DEBUGFS_MAX_BLOBS) > + break; > + } > +} > +#else > +static inline void efi_debugfs_init(void) {} > +#endif > + > /* > * We register the efi subsystem with the firmware subsystem and the > * efivars subsystem with the efi subsystem, if the system was booted with > @@ -360,6 +410,9 @@ static int __init efisubsys_init(void) > goto err_remove_group; > } > > + if (efi_enabled(EFI_DBG)) > + efi_debugfs_init(); > + This doesn't really make any sense on non-x86. The boot services regions are released to the kernel for general allocation, and so exposing them this way only makes sense if you keep them as you do for x86. Could you please try to make this call specific to situations where it makes sense? I don't mind allocating a new EFI_xxx flag for preserving the boot services regions so we could decide to set it for ARM/arm64 as well in certain cases in the future. > return 0; > > err_remove_group: > -- > 2.17.0 >