Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp1128953imm; Thu, 5 Jul 2018 15:31:27 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeZeP2DtGkKEgKaR2HDtCxmtjU1L7NdI6kkgoIR5Sf5H35NHxOHLN0SkLhKh90rQPhTYEAf X-Received: by 2002:a65:4005:: with SMTP id f5-v6mr6925183pgp.302.1530829886989; Thu, 05 Jul 2018 15:31:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530829886; cv=none; d=google.com; s=arc-20160816; b=LlZjH7O2n2xeY/AAJVDeeWYRhOpE6M5grV//+zDWGe0orAB24J3HZuxJgk5ET09/DF ppuS25hQ28NJgt4kl1kOSsf/xdTVNy4Kd0h8WY8j4qPLDk0wfjwoQwvadBf/H9Kjw0Y3 OxS3e81YT0+V4jI3X+NjQ4Nvr7Y812bylnDWOj3cQfU5rDTFUGzaNfw8Mho3fDkHrzyH u4j7HHzNBLxS0jhe2+rgVyTJ6ufOzH+ubb9H4P0xx6H4c7+0Z76FMEzCy4bt6adlQOmE Jfoou+3ezV0fSK0CyqtuagU/mNh4H+OScwoubuBGvKiqWOIOCpksO3hwgiI/BVBfr29v bmsg== 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=+1nadbarlBULviXe2TXd3EYC1P70DPrOTlKAmlSaYrE=; b=Jh7DyMiKBNJqoALd3hlvOB3VPGahikxs5uan3BOKr4n2EPiNnCNsEiSZycWK2/pHlL 0UlXHFd/5gQyxhtHpondGZnKugg6USUV+VpcDPsuizEzGdcQqtIfhCuZEOFtAFfjqrNI rnfQr8ucgwqw/tReXF0ruGw9PTyOTYKSv5PREY24iq6CJTWEwvbz/VK2piZlt5vCGbzO 6Jys3vpihAzFxI5/NbdJ/Pp97H59YXwvDT25vgF+oAuCrCpDroEvbxafn6pgF+UQzOD6 pcnfAwQ8KGS/rYsLEQ0TmtIfOEdcnQh8vwe37rYdzajRSP232v9X8Jg8zwImZOJPpZ/h mVDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jWDbPGy9; 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 h23-v6si6550514pgl.373.2018.07.05.15.31.11; Thu, 05 Jul 2018 15:31:26 -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=jWDbPGy9; 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 S1753757AbeGEW3X (ORCPT + 99 others); Thu, 5 Jul 2018 18:29:23 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:37622 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753503AbeGEW3V (ORCPT ); Thu, 5 Jul 2018 18:29:21 -0400 Received: by mail-io0-f196.google.com with SMTP id z19-v6so9182753ioh.4 for ; Thu, 05 Jul 2018 15:29:21 -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=+1nadbarlBULviXe2TXd3EYC1P70DPrOTlKAmlSaYrE=; b=jWDbPGy9v67z44xMmvUQGVrh38GiS9uTpMJc5nt+DwuN8EEVW37Z0paz5rmyKU6VuA QVIybwtzXgHexp46RX7seDlfa/H04JI+ydc6G59uMPXgZo5M+j28GwmE+3j4SsX93heY kT0xdDZrd/j2MdQ09ggIWaxzINOHFm3tMAxvU= 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=+1nadbarlBULviXe2TXd3EYC1P70DPrOTlKAmlSaYrE=; b=VLSkKdylC+lZsWq8LqTr7IxDxiZD2hrGplifxiZHGtGeY42EwQRUz3Sm9v2WeajJDu A7tT1M1BLGIP9g3uMYAR12N8pZmyHvkvJRietLMuEnn4yL4xyBIhlo2u35nt14gzzkaa uKnGu6JbJXMlcMJYokhy5Ew64IN3DqLsg5AxLIlHTJox8PN3YNhEzThWO1VXM9I4jmX7 TrgTZ6yjQFbuXmSG3zY+hnXu+9SvtbJC3LjDB+7tQzrPQK+5xPXS6BpbB4zaF6f8h5SI Zcg3zZFLW6+FQTUkiJBU7QGKtCXW1jqHhYhENd6UG07B2rPjyjjOhmL3ssDny69fUNoL SIXQ== X-Gm-Message-State: APt69E1yki3/vqyahf+bnj/X0gcsCziY1ewfRyxUPX12f+KimALPjC0U bxpk1zH0H51HjTyuKWBqoyyFsUi5n4EzPMQ1W+Gpgw== X-Received: by 2002:a6b:5d1a:: with SMTP id r26-v6mr6384933iob.170.1530829761186; Thu, 05 Jul 2018 15:29:21 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:bbc7:0:0:0:0:0 with HTTP; Thu, 5 Jul 2018 15:29:20 -0700 (PDT) In-Reply-To: <20180619064424.6642-2-takahiro.akashi@linaro.org> References: <20180619064424.6642-1-takahiro.akashi@linaro.org> <20180619064424.6642-2-takahiro.akashi@linaro.org> From: Ard Biesheuvel Date: Fri, 6 Jul 2018 00:29:20 +0200 Message-ID: Subject: Re: [PATCH v2 1/4] arm64: export memblock_reserve()d regions via /proc/iomem To: AKASHI Takahiro Cc: Catalin Marinas , Will Deacon , Andrew Morton , "Baicar, Tyler" , Bhupesh Sharma , Dave Young , James Morse , 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 19 June 2018 at 08:44, AKASHI Takahiro wrote: > From: James Morse > > There has been some confusion around what is necessary to prevent kexec > overwriting important memory regions. memblock: reserve, or nomap? > Only memblock nomap regions are reported via /proc/iomem, kexec's > user-space doesn't know about memblock_reserve()d regions. > > Until commit f56ab9a5b73ca ("efi/arm: Don't mark ACPI reclaim memory > as MEMBLOCK_NOMAP") the ACPI tables were nomap, now they are reserved > and thus possible for kexec to overwrite with the new kernel or initrd. > But this was always broken, as the UEFI memory map is also reserved > and not marked as nomap. > > Exporting both nomap and reserved memblock types is a nuisance as > they live in different memblock structures which we can't walk at > the same time. > > Take a second walk over memblock.reserved and add new 'reserved' > subnodes for the memblock_reserved() regions that aren't already > described by the existing code. (e.g. Kernel Code) > > We use reserve_region_with_split() to find the gaps in existing named > regions. This handles the gap between 'kernel code' and 'kernel data' > which is memblock_reserve()d, but already partially described by > request_standard_resources(). e.g.: > | 80000000-dfffffff : System RAM > | 80080000-80ffffff : Kernel code > | 81000000-8158ffff : reserved > | 81590000-8237efff : Kernel data > | a0000000-dfffffff : Crash kernel > | e00f0000-f949ffff : System RAM > > reserve_region_with_split needs kzalloc() which isn't available when > request_standard_resources() is called, use an initcall. > > Reported-by: Bhupesh Sharma > Reported-by: Tyler Baicar > Suggested-by: Akashi Takahiro > Signed-off-by: James Morse > Fixes: d28f6df1305a ("arm64/kexec: Add core kexec support") > CC: Ard Biesheuvel > CC: Mark Rutland Reviewed-by: Ard Biesheuvel > --- > arch/arm64/kernel/setup.c | 38 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 38 insertions(+) > > diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c > index 30ad2f085d1f..5b4fac434c84 100644 > --- a/arch/arm64/kernel/setup.c > +++ b/arch/arm64/kernel/setup.c > @@ -241,6 +241,44 @@ static void __init request_standard_resources(void) > } > } > > +static int __init reserve_memblock_reserved_regions(void) > +{ > + phys_addr_t start, end, roundup_end = 0; > + struct resource *mem, *res; > + u64 i; > + > + for_each_reserved_mem_region(i, &start, &end) { > + if (end <= roundup_end) > + continue; /* done already */ > + > + start = __pfn_to_phys(PFN_DOWN(start)); > + end = __pfn_to_phys(PFN_UP(end)) - 1; > + roundup_end = end; > + > + res = kzalloc(sizeof(*res), GFP_ATOMIC); > + if (WARN_ON(!res)) > + return -ENOMEM; > + res->start = start; > + res->end = end; > + res->name = "reserved"; > + res->flags = IORESOURCE_MEM; > + > + mem = request_resource_conflict(&iomem_resource, res); > + /* > + * We expected memblock_reserve() regions to conflict with > + * memory created by request_standard_resources(). > + */ > + if (WARN_ON_ONCE(!mem)) > + continue; > + kfree(res); > + > + reserve_region_with_split(mem, start, end, "reserved"); > + } > + > + return 0; > +} > +arch_initcall(reserve_memblock_reserved_regions); > + > u64 __cpu_logical_map[NR_CPUS] = { [0 ... NR_CPUS-1] = INVALID_HWID }; > > void __init setup_arch(char **cmdline_p) > -- > 2.17.0 >