public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Binglei Wang <l3b2w1@gmail.com>, hch@lst.de, m.szyprowski@samsung.com
Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] cma: check for memory region overlapping
Date: Thu, 7 Sep 2023 13:57:42 +0100	[thread overview]
Message-ID: <8c3fe8ce-4716-73f0-fb8a-ee982f212371@arm.com> (raw)
In-Reply-To: <20230726142823.6356-1-l3b2w1@gmail.com>

On 26/07/2023 3:28 pm, Binglei Wang wrote:
> From: Binglei Wang <l3b2w1@gmail.com>
> 
> In the process of parsing the DTS, checks
> whether the memory region specified by the DTS CMA node area
> overlaps with the kernel text memory space reserved by memblock
> before calling early_init_fdt_scan_reserved_mem.

This description bears no relation to what the code actually does. 
rmem_cma_setup() happens well after parsing the DTS, as it is that 
initial parsing process in fdt_scan_reserved_mem() which *makes* the 
memblock reservations in the first place. Thus, as the revert patch 
demonstrates, by the time we get here to start *using* the reserved 
region via fdt_init_reserved_mem(), it is always guaranteed to overlap a 
reserved region because it trivially overlaps with itself.

Furthermore, even if the bootloader does stupidly load a non-relocatable 
kernel into memory that it's described as reserved, the kernel text 
pages should not be available for CMA to allocate from - and if they 
were, that would be a far more fundamental bug elsewhere - so what is 
the exact problem you're trying to solve here?

Thanks,
Robin.

> Maybe it's better to have some warning prompts printed.
> 
> Signed-off-by: Binglei Wang <l3b2w1@gmail.com>
> ---
> 
> Notes:
>      v3: fix compile error.
>      v2: delete the logic code for handling return -EBUSY.
>      v1: return -EBUSY when detect overlapping and handle the return case.
> 
>   kernel/dma/contiguous.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c
> index 6ea80ae42..dc6d2af1e 100644
> --- a/kernel/dma/contiguous.c
> +++ b/kernel/dma/contiguous.c
> @@ -410,6 +410,11 @@ static int __init rmem_cma_setup(struct reserved_mem *rmem)
>   		return -EBUSY;
>   	}
>   
> +	if (memblock_is_region_reserved(rmem->base, rmem->size)) {
> +		pr_info("Reserved memory: overlap with other memblock reserved region\n");
> +		return -EBUSY;
> +	}
> +
>   	if (!of_get_flat_dt_prop(node, "reusable", NULL) ||
>   	    of_get_flat_dt_prop(node, "no-map", NULL))
>   		return -EINVAL;

  parent reply	other threads:[~2023-09-07 18:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-26 14:28 [PATCH v3] cma: check for memory region overlapping Binglei Wang
2023-07-31 16:02 ` Christoph Hellwig
2023-09-07 12:57 ` Robin Murphy [this message]
2023-09-11  3:43   ` binglei wang

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=8c3fe8ce-4716-73f0-fb8a-ee982f212371@arm.com \
    --to=robin.murphy@arm.com \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux.dev \
    --cc=l3b2w1@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.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