Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3480007ybc; Thu, 21 Nov 2019 08:57:26 -0800 (PST) X-Google-Smtp-Source: APXvYqwNvFTSHaTifDEF/82iKfvF8bqHD0F6x0NR5XMGWwXxTNZCIWKnLWG/b05WFA0IezuH6LcV X-Received: by 2002:a1c:3dc4:: with SMTP id k187mr10969606wma.167.1574355445841; Thu, 21 Nov 2019 08:57:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574355445; cv=none; d=google.com; s=arc-20160816; b=FKa2QePRbJv1rKASbKCfYC51ViDW6gzONOd1OcfIeVm5+qsk8emuih1WdYkyPeFFNf DsIhCRWEi2XDpDFSDExB7H+Qdsd+yfAdzHHwwMJdEaaahjPgqOzi8JkE+0OPcWcx5pFh P/OQURu+n57AksoaSK35LNsS/B3lUvSeZ0ZLtWviGyY7NB/P66nxp5tfdc0BF7bu3vXm 7IIaBvif9U+8xAlzmY6OhSfGfrz7AXkp8Cg2eR7uV5LQmC8IYMw0NUTqFTA5BQ7BmdKf yfWqSbxOerG2CN3Tp2jpIfIgv7F1Pvlq409WA541FCnHbsJR32wn6w6gRK5loqhqf1aX 1YJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=FTi7Dvg/d0dXm7xuFygWnPv5XbbIL8YDOlUOqtHAZRA=; b=JrySgM6US/e1/cm6y0+YmeunnplUMdFDZpKFoPhagg74mfeeuCZHu7iuOdadzFv/zt S3G0OtKTBUlONolpuzL8+KBhtxRNZaWTfcoXeN6UPxKPToY3y+UEFKkAqLaOw0GCv5jg k3+xGkTIS8c7usR2Lr8k49x6O2PruOJNPZ4+iiHW3xIiqYSY2mBPVO5GsWSuXDti+8hr chL4pAXtd5zlV3RE5iFx4ShPe81hlsqrb7cg3keojlkhWtsAqm+ejF7S++unpqK3Wn+o Oy0Rl/rkBT0IUwAUXSjOMipbZoQB4uXX0K5QitDknRX0tLF1bm8u+Pfdz/cTlbQoRyS7 XEgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WkEf5jcq; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 35si3539598edj.185.2019.11.21.08.57.01; Thu, 21 Nov 2019 08:57:25 -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=@gmail.com header.s=20161025 header.b=WkEf5jcq; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726735AbfKUQzA (ORCPT + 99 others); Thu, 21 Nov 2019 11:55:00 -0500 Received: from mail-qt1-f196.google.com ([209.85.160.196]:34269 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726279AbfKUQzA (ORCPT ); Thu, 21 Nov 2019 11:55:00 -0500 Received: by mail-qt1-f196.google.com with SMTP id i17so4460725qtq.1; Thu, 21 Nov 2019 08:54:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=FTi7Dvg/d0dXm7xuFygWnPv5XbbIL8YDOlUOqtHAZRA=; b=WkEf5jcqS8zxRM9xUmSno444pUXfkVM6nWtzbblogn4kR7zBQ11SzgjmNfk6Xyk4Kh AzZZ5sRpze5v2FtJw8Zd5phltv2mzwd4dH2Oa0IRMVLfwylXfP3HVlA0SIcHA32/Wxai 7JIP8+kswZRVSjf8EIIStfboZYf/JpdBk9HAE/+Lwftshy1+Kvg7n/s3k2MCaydU1zny tTwqmHTmAhVcKzIbpbzkBmlkIe7gsDD0xmRVFqy6MrzSNtajvgBRLOEC0qGjd5uzmmXE o7RaeBzWJxHkUKVx4Cibwrrg7jgORmZvwTtCb1VYojsnjgEXuBCjaf99dfAyufhx0jEW 1+sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=FTi7Dvg/d0dXm7xuFygWnPv5XbbIL8YDOlUOqtHAZRA=; b=kbYrkSu62svS41A9t8C/EAw7MAMg9Z1jFh7OdKkNBFKZxcM/YIWsT0yQ9kdXOItx6S Mx7V4Dw4zaw/EkSXdCJNArnsaftQ/APkUEwaom2hXBvYzwnCoQZKToPthd/e7s2LxUbP fSAdw/hrTtYxKuVQrqbBVjONpFTNCcNvJTZmU7jW+gQ8+3HhbLC5ydm1/aGVHrSLXx4F fEW0VT+FAXw2xPSgGgZHuAEilYfEb1JSlX6zdQunPnz05ybCnceW7NOGP8nq1iuEJL4d q8Ct/PS9BsYi40bXb0ITdqwGHteqdgP3bQe+pEyj4MBYrW43R+yQ4CG/tuJxnl91Xnrz QDlA== X-Gm-Message-State: APjAAAXmLCOeCAAvIcAg7gXaF5uN5T+r3fZ6S/sHX4sXiJlH67s9AaUc 6QP3hYPTqmnpLIY26DkT4Q== X-Received: by 2002:aed:248e:: with SMTP id t14mr9953119qtc.264.1574355298616; Thu, 21 Nov 2019 08:54:58 -0800 (PST) Received: from gabell (nat-pool-bos-t.redhat.com. [66.187.233.206]) by smtp.gmail.com with ESMTPSA id d145sm1616978qkc.120.2019.11.21.08.54.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 21 Nov 2019 08:54:57 -0800 (PST) Date: Thu, 21 Nov 2019 11:54:51 -0500 From: Masayoshi Mizuma To: Ard Biesheuvel , linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org Cc: Masayoshi Mizuma , linux-kernel@vger.kernel.org, kexec@lists.infradead.org, d.hatayama@fujitsu.com Subject: Re: [RFC PATCH v2] efi: arm64: Introduce /sys/firmware/efi/memreserve to tell the persistent pages Message-ID: <20191121165451.ddc4e7rz5swvoirc@gabell> References: <20191114161019.8735-1-msys.mizuma@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191114161019.8735-1-msys.mizuma@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 14, 2019 at 11:10:19AM -0500, Masayoshi Mizuma wrote: > From: Masayoshi Mizuma > > kexec reboot stops in early boot sequence because efi_config_parse_tables() > refers garbage data. We can see the log with memblock=debug kernel option: > > efi: ACPI 2.0=0x9821790014 PROP=0x8757f5c0 SMBIOS 3.0=0x9820740000 MEMRESERVE=0x9820bfdc58 > memblock_reserve: [0x0000009820bfdc58-0x0000009820bfdc67] efi_config_parse_tables+0x228/0x278 > memblock_reserve: [0x0000000082760000-0x00000000324d07ff] efi_config_parse_tables+0x228/0x278 > memblock_reserve: [0xcc4f84ecc0511670-0x5f6e5214a7fd91f9] efi_config_parse_tables+0x244/0x278 > memblock_reserve: [0xd2fd4144b9af693d-0xad0c1db1086f40a2] efi_config_parse_tables+0x244/0x278 > memblock_reserve: [0x0c719bb159b1fadc-0x5aa6e62a1417ce12] efi_config_parse_tables+0x244/0x278 > ... > > That happens because 0x82760000, struct linux_efi_memreserve, is destroyed. > 0x82760000 is pointed from efi.mem_reseve, and efi.mem_reserve points the > head page of LPI pending table and LPI property table which are allocated by > gic_reserve_range(). > > The destroyer is kexec. kexec locates the initrd to the area: > > ]# kexec -d -l /boot/vmlinuz-5.4.0-rc7 /boot/initramfs-5.4.0-rc7.img --reuse-cmdline > ... > initrd: base 82290000, size 388dd8ah (59301258) > ... > > From dynamic debug log. initrd is located in segment[1]: > machine_kexec_prepare:70: > kexec kimage info: > type: 0 > start: 85b30680 > head: 0 > nr_segments: 4 > segment[0]: 0000000080480000 - 0000000082290000, 0x1e10000 bytes, 481 pages > segment[1]: 0000000082290000 - 0000000085b20000, 0x3890000 bytes, 905 pages > segment[2]: 0000000085b20000 - 0000000085b30000, 0x10000 bytes, 1 pages > segment[3]: 0000000085b30000 - 0000000085b40000, 0x10000 bytes, 1 pages > > kexec searches the memory region to locate initrd through > "System RAM" in /proc/iomem. The pending tables are included in > "System RAM" because they are allocated by alloc_pages(), so kexec > destroys the LPI pending tables. > > Introduce /sys/firmware/efi/memreserve to tell the pages pointed by > efi.mem_reserve so that kexec can avoid the area to locate initrd. > > Signed-off-by: Masayoshi Mizuma > --- > drivers/firmware/efi/efi.c | 41 +++++++++++++++++++++++++++++++++++++- > 1 file changed, 40 insertions(+), 1 deletion(-) > > diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c > index 0b6b0c19a..07812d697 100644 > --- a/drivers/firmware/efi/efi.c > +++ b/drivers/firmware/efi/efi.c > @@ -149,6 +149,45 @@ static ssize_t systab_show(struct kobject *kobj, > > static struct kobj_attribute efi_attr_systab = __ATTR_RO_MODE(systab, 0400); > > +static struct linux_efi_memreserve *efi_memreserve_root __ro_after_init; > +static ssize_t memreserve_show(struct kobject *kobj, > + struct kobj_attribute *attr, char *buf) > +{ > + struct linux_efi_memreserve *rsv; > + phys_addr_t start, end; > + unsigned long prsv; > + char *str = buf; > + int count, i; > + > + if (!kobj || !buf) > + return -EINVAL; > + > + if ((efi_memreserve_root == (void *)ULONG_MAX) || > + (!efi_memreserve_root)) > + return -ENODEV; > + > + for (prsv = efi_memreserve_root->next; prsv; prsv = rsv->next) { > + rsv = memremap(prsv, sizeof(*rsv), MEMREMAP_WB); > + if (!rsv) { > + pr_err("Could not map efi_memreserve\n"); > + return -ENOMEM; > + } > + count = atomic_read(&rsv->count); > + for (i = 0; i < count; i++) { > + start = rsv->entry[i].base; > + end = start + rsv->entry[i].size - 1; > + > + str += sprintf(str, "%pa-%pa\n", &start, &end); > + } > + memunmap(rsv); > + } > + > + return str - buf; > +} > + > +static struct kobj_attribute efi_attr_memreserve = > + __ATTR_RO_MODE(memreserve, 0444); > + I think it's better to put above between #ifdef CONFIG_KEXEC and #endif because it's useful for only kexec... > #define EFI_FIELD(var) efi.var > > #define EFI_ATTR_SHOW(name) \ > @@ -180,6 +219,7 @@ static struct attribute *efi_subsys_attrs[] = { > &efi_attr_runtime.attr, > &efi_attr_config_table.attr, > &efi_attr_fw_platform_size.attr, > + &efi_attr_memreserve.attr, Same as. I'll post the patch to change above and will remove the RFC. Thanks, Masa > NULL, > }; > > @@ -964,7 +1004,6 @@ int efi_status_to_err(efi_status_t status) > } > > static DEFINE_SPINLOCK(efi_mem_reserve_persistent_lock); > -static struct linux_efi_memreserve *efi_memreserve_root __ro_after_init; > > static int __init efi_memreserve_map_root(void) > { > -- > 2.21.0 >