From: "Pandey, Radhey Shyam" <radheys@amd.com>
To: Mike Rapoport <rppt@kernel.org>,
Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
Cc: robh@kernel.org, saravanak@kernel.org, akpm@linux-foundation.org,
david@kernel.org, ljs@kernel.org, liam@infradead.org,
vbabka@kernel.org, surenb@google.com, mhocko@suse.com,
m.szyprowski@samsung.com, robin.murphy@arm.com,
baoquan.he@linux.dev, pasha.tatashin@soleen.com,
pratyush@kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
iommu@lists.linux.dev, kexec@lists.infradead.org,
anirudha.sarangi@amd.com
Subject: Re: [PATCH 3/4] mm/cma: reject CMA areas that overlap the kernel image
Date: Fri, 13 Nov 2026 18:52:09 +0530 [thread overview]
Message-ID: <5acdf1f0-7b77-48f7-ac22-2095830936d8@amd.com> (raw)
In-Reply-To: <avBXZ8iW2XPyVbmF@kernel.org>
On 11/8/2026 4:35 PM, Mike Rapoport wrote:
> Hi,
>
> On Tue, Nov 03, 2026 at 09:54:28PM +0530, Radhey Shyam Pandey wrote:
>> cma_init_reserved_mem() takes a base chosen by its caller and only requires
>> that the range already be reserved, so an overlap with the kernel image is
>> indistinguishable from the normal case. cma_activate_area() then clears
>> PageReserved on those pages and frees them into MIGRATE_CMA, overriding the
>> memblock_reserve() of [_text, _end), so live kernel text reaches userspace.
>> kexec reached this until the fix this series builds on; a device tree
>> placing a shared-dma-pool over where the bootloader loaded the kernel still
>> can. Reject the overlap rather than let such a caller corrupt the kernel.
>>
>> Signed-off-by: Radhey Shyam Pandey <radhey.shyam.pandey@amd.com>
>> ---
>> Changes since RFC:
>> - Drop Pratyush reviewed-by tag as there were few changes.
>> - Trim the commit description.
>> - Drop the redundant comment as suggested by Mike.
>> - cma_overlaps_kernel_image() is kept as helpers in asm-generic/sections.h
>> are virtual-address helpers.
>> ---
>> mm/cma.c | 21 +++++++++++++++++++++
>> 1 file changed, 21 insertions(+)
>>
>> diff --git a/mm/cma.c b/mm/cma.c
>> index 9c53b2b70dc8..3231a53161cd 100644
>> --- a/mm/cma.c
>> +++ b/mm/cma.c
>> @@ -31,6 +31,8 @@
>> #include <linux/kmemleak.h>
>> #include <trace/events/cma.h>
>>
>> +#include <asm/sections.h>
>
> You probably don't need this.
Thanks , will drop it.
>
>> +
>> #include "internal.h"
>> #include "cma.h"
>> #include "mm_init.h"
>> @@ -68,6 +70,16 @@ bool cma_has_dynamic_base(const struct cma *cma)
>> return test_bit(CMA_DYNAMIC_BASE, &cma->flags);
>> }
>>
>> +static bool cma_overlaps_kernel_image(phys_addr_t base, phys_addr_t size)
>> +{
>> + phys_addr_t end;
>> +
>> + if (check_add_overflow(base, size, &end))
>> + return true;
>> +
>> + return base < __pa_symbol(_end) && __pa_symbol(_text) < end;
>> +}
>> +
>> static unsigned long cma_bitmap_aligned_mask(const struct cma *cma,
>> unsigned int align_order)
>> {
>> @@ -295,6 +307,15 @@ int __init cma_init_reserved_mem(phys_addr_t base, phys_addr_t size,
>> if (!size || !memblock_is_region_reserved(base, size))
>> return -EINVAL;
>>
>> + if (cma_overlaps_kernel_image(base, size)) {
>> + phys_addr_t text = __pa_symbol(_text);
>> + phys_addr_t end = __pa_symbol(_end);
>> +
>> + pr_err("area %s (%pa, size %pa) overlaps kernel image [%pa-%pa]\n",
>> + name ?: "(unnamed)", &base, &size, &text, &end);
>
> We don't want to expose addresses of the kernel image.
> I'd drop text, end, and probably even base from the printout.
Thanks. I will fix it in next version.
pr_err("area %s overlaps the kernel image\n", name ?: "(unnamed)");
I also want to discuss on this patch sashiko review.
https://lore.kernel.org/all/sashiko-outbox-197614@kernel.org/
Sashiko says:
Because _text is below KERNEL_START on 32-bit ARM, won't calling
cma_init_reserved_mem() -> cma_overlaps_kernel_image() with
base < __pa_symbol(_end) trigger VIRTUAL_BUG_ON() during early boot?
any suggestion on how to address it? one option is to switch
to __pa_symbol(_stext).
Thanks,
Radhey
next prev parent reply other threads:[~2026-11-13 13:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 16:24 [PATCH 0/4] kexec,mm/cma: do not run the next kernel from a fixed-base CMA area Radhey Shyam Pandey
2026-11-03 16:24 ` [PATCH 1/4] kexec: do not place the next kernel in a fixed-address " Radhey Shyam Pandey
2026-11-03 16:24 ` [PATCH 2/4] of: reserved_mem: keep the reservation when node_init returns -EBUSY Radhey Shyam Pandey
2026-11-03 16:24 ` [PATCH 3/4] mm/cma: reject CMA areas that overlap the kernel image Radhey Shyam Pandey
2026-11-08 11:05 ` Mike Rapoport
2026-11-13 13:22 ` Pandey, Radhey Shyam [this message]
2026-11-03 16:24 ` [PATCH 4/4] mm/cma: drop the duplicate alignment check in rmem_cma_setup() Radhey Shyam Pandey
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=5acdf1f0-7b77-48f7-ac22-2095830936d8@amd.com \
--to=radheys@amd.com \
--cc=akpm@linux-foundation.org \
--cc=anirudha.sarangi@amd.com \
--cc=baoquan.he@linux.dev \
--cc=david@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=iommu@lists.linux.dev \
--cc=kexec@lists.infradead.org \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mhocko@suse.com \
--cc=pasha.tatashin@soleen.com \
--cc=pratyush@kernel.org \
--cc=radhey.shyam.pandey@amd.com \
--cc=robh@kernel.org \
--cc=robin.murphy@arm.com \
--cc=rppt@kernel.org \
--cc=saravanak@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.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
all inboxes | Powered by JetHome®