From: dave.kleikamp@oracle.com (Dave Kleikamp)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 1/4] arm64: export memblock_reserve()d regions via /proc/iomem
Date: Tue, 3 Jul 2018 11:12:23 -0500 [thread overview]
Message-ID: <a9c38b0d-db67-2f5b-ea0e-ec6e45d2c4c9@oracle.com> (raw)
In-Reply-To: <20180703064726.GU23681@linaro.org>
On 07/03/2018 01:47 AM, 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.
Agreed. The sooner this gets fixed, the better.
Thanks,
Dave
>
> Thanks,
> -Takahiro AKASHI
>
>>>
>>>
>>> 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)
>>>>>
>>>
next prev parent reply other threads:[~2018-07-03 16:12 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-19 6:44 [PATCH v2 0/4] arm64: kexec, kdump: fix boot failures on acpi-only system AKASHI Takahiro
2018-06-19 6:44 ` [PATCH v2 1/4] arm64: export memblock_reserve()d regions via /proc/iomem AKASHI Takahiro
2018-06-19 13:37 ` Dave Kleikamp
2018-06-19 15:00 ` James Morse
2018-06-19 15:22 ` Dave Kleikamp
2018-07-03 6:47 ` AKASHI Takahiro
2018-07-03 12:14 ` Bhupesh Sharma
2018-07-03 16:12 ` Dave Kleikamp [this message]
2018-07-05 22:29 ` Ard Biesheuvel
2018-06-19 6:44 ` [PATCH v2 2/4] efi/arm: map UEFI memory map even w/o runtime services enabled AKASHI Takahiro
2018-06-28 17:29 ` James Morse
2018-07-05 22:26 ` Ard Biesheuvel
2018-06-19 6:44 ` [PATCH v2 3/4] efi/arm: map UEFI memory map earlier on boot AKASHI Takahiro
2018-07-04 17:06 ` Will Deacon
2018-07-04 18:49 ` Ard Biesheuvel
2018-07-05 9:43 ` AKASHI Takahiro
2018-07-05 11:02 ` James Morse
2018-07-05 16:48 ` Will Deacon
2018-07-05 22:31 ` Ard Biesheuvel
2018-07-06 0:42 ` AKASHI Takahiro
2018-07-06 1:33 ` AKASHI Takahiro
2018-07-06 13:37 ` Will Deacon
2018-06-19 6:44 ` [PATCH v2 4/4] arm64: acpi: fix alignment fault in accessing ACPI AKASHI Takahiro
2018-06-28 17:28 ` James Morse
2018-07-05 22:27 ` Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a9c38b0d-db67-2f5b-ea0e-ec6e45d2c4c9@oracle.com \
--to=dave.kleikamp@oracle.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).