From: Florian Fainelli <f.fainelli@gmail.com>
To: Rob Herring <robh+dt@kernel.org>,
KarimAllah Ahmed <karahmed@amazon.de>,
Nicolas Boichat <drinkcat@chromium.org>
Cc: Frank Rowand <frowand.list@gmail.com>,
devicetree@vger.kernel.org,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Ian Campbell <ian.campbell@citrix.com>,
Grant Likely <grant.likely@linaro.org>,
Stephen Boyd <swboyd@chromium.org>
Subject: Re: [PATCH] of/fdt: Make sure no-map does not remove already reserved regions
Date: Tue, 16 Jul 2019 16:17:10 -0700 [thread overview]
Message-ID: <421844aa-cf68-d4d2-f02d-aefaf8954fdf@gmail.com> (raw)
In-Reply-To: <CAL_JsqLETdazfnz5EU0Qw4TVVBhWmzk12Z5zYMo5Hm2ACPXh1w@mail.gmail.com>
On 7/16/19 4:12 PM, Rob Herring wrote:
> On Tue, Jul 16, 2019 at 4:46 PM Florian Fainelli <f.fainelli@gmail.com> wrote:
>>
>> On 7/2/19 10:08 PM, Nicolas Boichat wrote:
>>> If the device tree is incorrectly configured, and attempts to
>>> define a "no-map" reserved memory that overlaps with the kernel
>>> data/code, the kernel would crash quickly after boot, with no
>>> obvious clue about the nature of the issue.
>>>
>>> For example, this would happen if we have the kernel mapped at
>>> these addresses (from /proc/iomem):
>>> 40000000-41ffffff : System RAM
>>> 40080000-40dfffff : Kernel code
>>> 40e00000-411fffff : reserved
>>> 41200000-413e0fff : Kernel data
>>>
>>> And we declare a no-map shared-dma-pool region at a fixed address
>>> within that range:
>>> mem_reserved: mem_region {
>>> compatible = "shared-dma-pool";
>>> reg = <0 0x40000000 0 0x01A00000>;
>>> no-map;
>>> };
>>>
>>> To fix this, when removing memory regions at early boot (which is
>>> what "no-map" regions do), we need to make sure that the memory
>>> is not already reserved. If we do, __reserved_mem_reserve_reg
>>> will throw an error:
>>> [ 0.000000] OF: fdt: Reserved memory: failed to reserve memory
>>> for node 'mem_region': base 0x0000000040000000, size 26 MiB
>>> and the code that will try to use the region should also fail,
>>> later on.
>>>
>>> We do not do anything for non-"no-map" regions, as memblock
>>> explicitly allows reserved regions to overlap, and the commit
>>> that this fixes removed the check for that precise reason.
>>>
>>> Fixes: 094cb98179f19b7 ("of/fdt: memblock_reserve /memreserve/ regions in the case of partial overlap")
>>> Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
>>> ---
>>> drivers/of/fdt.c | 10 +++++++++-
>>> 1 file changed, 9 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
>>> index cd17dc62a71980a..a1ded43fc332d0c 100644
>>> --- a/drivers/of/fdt.c
>>> +++ b/drivers/of/fdt.c
>>> @@ -1138,8 +1138,16 @@ int __init __weak early_init_dt_mark_hotplug_memory_arch(u64 base, u64 size)
>>> int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
>>> phys_addr_t size, bool nomap)
>>> {
>>> - if (nomap)
>>> + if (nomap) {
>>> + /*
>>> + * If the memory is already reserved (by another region), we
>>> + * should not allow it to be removed altogether.
>>> + */
>>> + if (memblock_is_region_reserved(base, size))
>>> + return -EBUSY;
>>> +
>>> return memblock_remove(base, size);
>>
>> While you are it, the nomap argument (introduced with
>> e8d9d1f5485b52ec3c4d7af839e6914438f6c285) predates the introduction of
>> memblock_is_nomap() (bf3d3cc580f9960883ebf9ea05868f336d9491c2), so
>> should just remove memblock_remove() and use memblock_mark_nomap()
>> instead here.
>
> Perhaps like this patch[1]? Though the reasoning is different and the
> commit message here is more thorough, so can I get a combined patch.
>From a quick reading it does look like memblock_isolate_range(), as
called by memblock_setclr_flag() should be able to detect this region
was already reserved, though I have not tried it.
> However, I don't under how handling a misconfigured DT and aligned
> with EFI are the same patch. What's considered valid for EFI is not
> for DT regions?
That I don't know how to answer.
--
Florian
next prev parent reply other threads:[~2019-07-16 23:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-03 5:08 [PATCH] of/fdt: Make sure no-map does not remove already reserved regions Nicolas Boichat
2019-07-16 22:35 ` Stephen Boyd
2019-07-16 22:46 ` Florian Fainelli
2019-07-16 23:12 ` Rob Herring
2019-07-16 23:17 ` Florian Fainelli [this message]
2019-07-22 5:53 ` Nicolas Boichat
2021-03-22 7:58 ` Jan Kiszka
2021-03-22 18:05 ` Jan Kiszka
2021-03-22 20:15 ` Jan Kiszka
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=421844aa-cf68-d4d2-f02d-aefaf8954fdf@gmail.com \
--to=f.fainelli@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=drinkcat@chromium.org \
--cc=frowand.list@gmail.com \
--cc=grant.likely@linaro.org \
--cc=ian.campbell@citrix.com \
--cc=karahmed@amazon.de \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=swboyd@chromium.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).