linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Neil Armstrong <neil.armstrong@linaro.org>
To: Rob Herring <robh+dt@kernel.org>, Lucas Tanure <tanure@linux.com>
Cc: Frank Rowand <frowand.list@gmail.com>,
	Mike Rapoport <rppt@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, jbrunet@baylibre.com,
	linux-amlogic@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	martin.blumenstingl@googlemail.com, narmstrong@baylibre.com,
	stefan@agner.ch
Subject: Re: [PATCH 2/2] of: fdt: Allow the kernel to mark nomap regions received from fdt
Date: Thu, 6 Apr 2023 18:06:04 +0200	[thread overview]
Message-ID: <9835aeba-6e4c-0594-427b-9990fc07407a@linaro.org> (raw)
In-Reply-To: <CAL_JsqL_MLHO-zk0HAmuAmiJQ_TmD4EN5YC0JmRs7PXjStjr3A@mail.gmail.com>

On 06/04/2023 17:48, Rob Herring wrote:
> On Thu, Apr 6, 2023 at 10:14 AM Lucas Tanure <tanure@linux.com> wrote:
>>
>> Reserved regions can be described in FDT and device trees, but FDT doesn't
>> provide the related flags, like nomap.
> 
> It took me a minute to understand what you meant by FDT vs. device
> trees. Use the exact things you are talking about: /memreserve/ and
> /reserved-memory node.
> 
>> So allow the kernel to mark regions where the base and size received from
>> the device tree are the same as the base and region on FDT.
>> Here we trust that the device tree has a more updated description of the
>> region than the one received from FDT.
>>
>> Signed-off-by: Lucas Tanure <tanure@linux.com>
>> ---
>>   drivers/of/fdt.c | 10 ++++++----
>>   1 file changed, 6 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
>> index d1a68b6d03b3..754a7ea4f45c 100644
>> --- a/drivers/of/fdt.c
>> +++ b/drivers/of/fdt.c
>> @@ -482,11 +482,13 @@ static int __init early_init_dt_reserve_memory(phys_addr_t base,
>>          if (nomap) {
>>                  /*
>>                   * If the memory is already reserved (by another region), we
>> -                * should not allow it to be marked nomap, but don't worry
>> -                * if the region isn't memory as it won't be mapped.
>> +                * should not allow it to be marked nomap, unless is the exact same region
>> +                * (same base and size), which the kernel knows better and should be allowed to mark
>> +                *  it as nomap.
>> +                * But don't worry if the region isn't memory as it won't be mapped.
>>                   */
>> -               if (memblock_overlaps_region(&memblock.memory, base, size) &&
>> -                   memblock_is_region_reserved(base, size))
>> +               if (memblock_overlaps_region(&memblock.memory, base, size) == MEMBLOCK_OVERLAPS &&
>> +                   memblock_is_region_reserved(base, size) == MEMBLOCK_OVERLAPS)
> 
> Won't this fail to work as IIRC memblock will merge regions when they
> are adjacent and have the same atrributes.
> 
> Perhaps instead, the DT code should ignore any /memreserve/ entries
> that are also in /reserved-memory.
> 
> I would suggest just reverse the order they are processed, but I
> suspect that might cause some regression. This code is all fragile
> especially with platforms putting in 100 regions.
> 
> Finally, perhaps fix u-boot. The reason the reserved location goes in
> both places was to support an OS not supporting /reserved-memory. I
> think that support has been in place for a lot longer than anyone
> would care about.

Fixing U-Boot won't fix already tagged and in-the-field mainline u-boot
releases that adds /memreserve/ entries, so yes u-boot should be definitely
fixed but Linux should ignore the /memreserve/ entries when they matches
an /reserved-memory node like when the U-Boot /memreserve/ code was added.

Neil

> 
> Rob
> 
> _______________________________________________
> linux-amlogic mailing list
> linux-amlogic@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-amlogic



      reply	other threads:[~2023-04-06 16:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-06 15:14 [PATCH 0/2] Fix Random Kernel panic from when fail to reserve memory Lucas Tanure
2023-04-06 15:14 ` [PATCH 1/2] memblock: Differentiate regions overlap from both regions being the same Lucas Tanure
2023-04-06 15:14 ` [PATCH 2/2] of: fdt: Allow the kernel to mark nomap regions received from fdt Lucas Tanure
2023-04-06 15:48   ` Rob Herring
2023-04-06 16:06     ` Neil Armstrong [this message]

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=9835aeba-6e4c-0594-427b-9990fc07407a@linaro.org \
    --to=neil.armstrong@linaro.org \
    --cc=akpm@linux-foundation.org \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=jbrunet@baylibre.com \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=narmstrong@baylibre.com \
    --cc=robh+dt@kernel.org \
    --cc=rppt@kernel.org \
    --cc=stefan@agner.ch \
    --cc=tanure@linux.com \
    /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