Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1079675imm; Tue, 3 Jul 2018 05:16:04 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJqDMaggJtji0OdziPjCTubXkUpKg9k7TxBJQEeKsOd94Zv1XcGvPa8jXTJjeYmmZBYFr79 X-Received: by 2002:a65:6699:: with SMTP id b25-v6mr25700198pgw.426.1530620164810; Tue, 03 Jul 2018 05:16:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530620164; cv=none; d=google.com; s=arc-20160816; b=q/IH+OJ1z8sl9KALHiHhhSznffmGvKqfGi9wZoAiyxt9nUP493uyUKRDvV3ZDXlSJt jiCPRV2TvllUMlWUZ2u0HDEHO3lVAKDT8k9J2ImPi83qlRWb2qQjG+te1yADLuyC2/Kc vKO5E61Fh9huxEhUviZqKQc082gW5vhxbpztHKrvRCxaDdH4FXLJoiGobDr0rGXdR+kz bU0TuFf6O0zEO7ctRAjgycp/IjsGAYRDbCra3bwtRb3cQSzWv9dBY2W20iFdxe0zmb+X A+oJrN+ewmXIQsrllwoojwjr/eQO9/BSthEcrq/yS/CtgwIYck5+sgq7n10hQG9E1zwR TEUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:subject:message-id:date:from :references:in-reply-to:mime-version:arc-authentication-results; bh=G3gwYlJPJjiuj7Ajr/8y0M0zmtZkCbtPm7j/8c4do/g=; b=pz33Ja2/muHroT8vY8Meze/RUTocYFYjm4o9GYGd2Tm+Z+hbQLHV4xPmc2a7v2+Woo KW5a6GK8gUwlmM5c72doq+birs7AKUAOz+sKMs6UgNDxzeae2wJWdX7nDaXHb3LpJ1fs dPgNglo/ItFllLbCBNYJLM+eEpOzlEcvqzLV+/rXc6tjM0gp+zGDjIHuR1NfEyHIz6IF TsGPnE0zWg1u3jSa8HvNSEVjh0A6cV3X1ia3Nnvrp4yFrI1CJW6AD/cf2FYtytQQZJps nCXvLFuku/4d+NyZw/TCcP4uhKYJskWv5P8BjwfNzova0lrIk5JeLmTseqTYR8PHm+Cu +iQw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1-v6si983673pfn.285.2018.07.03.05.15.37; Tue, 03 Jul 2018 05:16:04 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753287AbeGCMOm (ORCPT + 99 others); Tue, 3 Jul 2018 08:14:42 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:35293 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752491AbeGCMOk (ORCPT ); Tue, 3 Jul 2018 08:14:40 -0400 Received: by mail-lj1-f194.google.com with SMTP id i125-v6so1359107lji.2 for ; Tue, 03 Jul 2018 05:14:39 -0700 (PDT) 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; bh=G3gwYlJPJjiuj7Ajr/8y0M0zmtZkCbtPm7j/8c4do/g=; b=oFpE2fn7WuJZrOq0WymYGyKQ3oGVWdyFMltPoAPwSyjxQ0EaT7Q3Gl6NIosem8DNAk 6lmIwynA/sRFwvqAn2UThgbYuX+f9hGsdjcpY7sAdaQUAcmZKxMbCAckI/zS2OKqhplx V6TQ4JN4CKgy0Uchynhtd5v3ya2IxmW3fYjO3iOqXTLzYYcwGGSrIZ+aP0DmHXzQuwZc 18K2pou8yrDjbGNP1nG5jI/+CBSwMOy5srRfw7kF9ZY7+tq5nuFyvFSktw0j4zuinrhg hMsOUeJFeZiY6T/Io7Fi3qG6Mcf7AHsDKkwJmZkkk5jYJKGyouhq08ojjiUf4JOK0VDv KGjA== X-Gm-Message-State: APt69E0iQ+s0Pwqyi8DwfbGujOLBSdH98F4Ij2nfgGK7Tgls35JhN0bc FWZUs676JkDouOWec+KJs5tyfvnNJjPMQV2ggYLf7Q== X-Received: by 2002:a2e:c52:: with SMTP id o18-v6mr18947560ljd.72.1530620078839; Tue, 03 Jul 2018 05:14:38 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a2e:3904:0:0:0:0:0 with HTTP; Tue, 3 Jul 2018 05:14:37 -0700 (PDT) In-Reply-To: <20180703064726.GU23681@linaro.org> References: <20180619064424.6642-1-takahiro.akashi@linaro.org> <20180619064424.6642-2-takahiro.akashi@linaro.org> <72307608-90e0-4842-edc1-d3b284782940@oracle.com> <891c3e5a-9760-1353-4a2c-0900082dd245@oracle.com> <20180703064726.GU23681@linaro.org> From: Bhupesh Sharma Date: Tue, 3 Jul 2018 17:44:37 +0530 Message-ID: Subject: Re: [PATCH v2 1/4] arm64: export memblock_reserve()d regions via /proc/iomem To: AKASHI Takahiro , Dave Kleikamp , James Morse , Catalin Marinas , Will Deacon , akpm@linux-foundation.org, Ard Biesheuvel , Mark Rutland , lorenzo.pieralisi@arm.com, graeme.gregory@linaro.org, Al Stone , Bhupesh Sharma , tbaicar@codeaurora.org, kexec mailing list , Linux Kernel Mailing List , Hanjun Guo , sudeep.holla@arm.com, Dave Young , linux-arm-kernel 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 Tue, Jul 3, 2018 at 12:17 PM, AKASHI Takahiro wrote: > On Tue, Jun 19, 2018 at 10:22:46AM -0500, Dave Kleikamp wrote: >> On 06/19/2018 10:00 AM, James Morse wrote: >> > Hi Dave, >> > >> > On 19/06/18 14:37, Dave Kleikamp wrote: >> >> On 06/19/2018 01:44 AM, AKASHI Takahiro wrote: >> >>> +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); >> >> >> >> Why is kfree() after the conditional continue? This is a memory leak. >> > >> > request_resource_conflict() inserts res into the iomem_resource tree, or returns >> > the conflict if there is already something at this address. >> > >> > We expect something at this address: a 'System RAM' section added by >> > request_resource(). This code wants the conflicting 'System RAM' entry so that >> > reserve_region_with_split() can fill in the gaps below it with 'reserved'. See >> > the commit-message for an example. >> > >> > If there was no conflict, it means the memory map doesn't look like we expect, >> > we can't pass NULL to reserve_region_with_split(), and we just inserted the >> > 'reserved' at the top level. Freeing res at this point would be a use-after-free >> > hanging from /proc/iomem. >> > This code generates a WARN_ON_ONCE() and leaves the 'reserved' description where >> > it is. >> >> Okay. I get it. >> >> > Trying to cleanup here is pointless, we can remove the resource entry and free >> > it ... but we still want to report it as reserved, which is what just happened, >> > just not quite how we we wanted it. >> > >> > If you ever see this warning, it means some RAM stopped being nomap between >> > request_resources() and reserve_memblock_reserved_regions(). I can't find any >> > case where that ever happens. >> > >> > >> > If all that makes sense: how can I improve the comment above the WARN_ON_ONCE() >> > to make it clearer? >> >> I guess something like you described above. >> >> /* >> * We expect a 'System RAM' section at this address. In the unexpected >> * case where one is not found, request_resource_conflict() will insert >> * res into the iomem_resource tree. >> */ >> >> Do you think this is clearer? > > If this is the only change needed in my patchset, I'd like the maintainers > to take care of it instead of my posting another version. > +1. crashkernel booting on arm64 machines which support boot via acpi tables is broken since a long time, so it would be great to get these into upstream asap. I think the comment can be addressed while picking up the patchset in the maintainer's tree. I am not sure whether it will go through the ARM tree (Will) or the EFI tree (Ard), but since this has a Tested-by (from myself) and Reviewed-by (from James), probably this can be pulled in to allow further tests via the maintainer's tree. Thanks, Bhupesh >> > >> > >> > Thanks, >> > >> > James >> > >> > >> >>> + >> >>> + 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) >> >>> >> >