linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: 纪宏宾 <jihongbin999@gmail.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] memblock: Make memblock memblock_dbg info handle overflowing range @base + @size
Date: Sat, 25 Mar 2023 09:04:21 +0300	[thread overview]
Message-ID: <ZB6O5awTbmcmqFI5@kernel.org> (raw)
In-Reply-To: <CAGeo-3e1emyUvqoQBz-v0CQQQasytb15SyhVVhiPwdheYgN=ow@mail.gmail.com>

On Fri, Mar 24, 2023 at 04:15:13PM +0800, 纪宏宾 wrote:
> Allow memblock users to specify range where @base + @size overflows,
> This will cause the address range information in the debug output to
> be displayed incorrectly.

Is there a real problem you are trying to solve?
 
> For example, calling memblock_remove(1ULL << PHYS_MASK_SHIFT,
> ULLONG_MAX) in arch/arm64/mm/init.c,
> would be displayed as:
> [ 0.000000] memblock_remove: [0x0001000000000000-0x0000fffffffffffe]
> arm64_memblock_init+0x24/0x270
> but we expect the output:
> [ 0.000000] memblock_remove: [0x0001000000000000-0xffffffffffffffff]
> arm64_memblock_init+0x24/0x270
> 
> Signed-off-by: Hongbin Ji <jhb_ee@163.com>
> ---
>  mm/memblock.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/mm/memblock.c b/mm/memblock.c
> index 25fd0626a9e7..567b99e4355d 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -700,7 +700,7 @@ static int __init_memblock
> memblock_add_range(struct memblock_type *type,
>  int __init_memblock memblock_add_node(phys_addr_t base, phys_addr_t size,
>         int nid, enum memblock_flags flags)
>  {
> - phys_addr_t end = base + size - 1;
> + phys_addr_t end = base + min(size, PHYS_ADDR_MAX - base + 1) - 1;
> 
>   memblock_dbg("%s: [%pa-%pa] nid=%d flags=%x %pS\n", __func__,
>        &base, &end, nid, flags, (void *)_RET_IP_);
> @@ -721,7 +721,7 @@ int __init_memblock memblock_add_node(phys_addr_t
> base, phys_addr_t size,
>   */
>  int __init_memblock memblock_add(phys_addr_t base, phys_addr_t size)
>  {
> - phys_addr_t end = base + size - 1;
> + phys_addr_t end = base + min(size, PHYS_ADDR_MAX - base + 1) - 1;
> 
>   memblock_dbg("%s: [%pa-%pa] %pS\n", __func__,
>        &base, &end, (void *)_RET_IP_);
> @@ -822,7 +822,7 @@ static int __init_memblock
> memblock_remove_range(struct memblock_type *type,
> 
>  int __init_memblock memblock_remove(phys_addr_t base, phys_addr_t size)
>  {
> - phys_addr_t end = base + size - 1;
> + phys_addr_t end = base + min(size, PHYS_ADDR_MAX - base + 1) - 1;
> 
>   memblock_dbg("%s: [%pa-%pa] %pS\n", __func__,
>        &base, &end, (void *)_RET_IP_);
> @@ -854,7 +854,7 @@ void __init_memblock memblock_free(void *ptr, size_t size)
>   */
>  int __init_memblock memblock_phys_free(phys_addr_t base, phys_addr_t size)
>  {
> - phys_addr_t end = base + size - 1;
> + phys_addr_t end = base + min(size, PHYS_ADDR_MAX - base + 1) - 1;
> 
>   memblock_dbg("%s: [%pa-%pa] %pS\n", __func__,
>        &base, &end, (void *)_RET_IP_);
> @@ -865,7 +865,7 @@ int __init_memblock memblock_phys_free(phys_addr_t
> base, phys_addr_t size)
> 
>  int __init_memblock memblock_reserve(phys_addr_t base, phys_addr_t size)
>  {
> - phys_addr_t end = base + size - 1;
> + phys_addr_t end = base + min(size, PHYS_ADDR_MAX - base + 1) - 1;
> 
>   memblock_dbg("%s: [%pa-%pa] %pS\n", __func__,
>        &base, &end, (void *)_RET_IP_);
> @@ -876,7 +876,7 @@ int __init_memblock memblock_reserve(phys_addr_t
> base, phys_addr_t size)
>  #ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP
>  int __init_memblock memblock_physmem_add(phys_addr_t base, phys_addr_t size)
>  {
> - phys_addr_t end = base + size - 1;
> + phys_addr_t end = base + min(size, PHYS_ADDR_MAX - base + 1) - 1;
> 
>   memblock_dbg("%s: [%pa-%pa] %pS\n", __func__,
>        &base, &end, (void *)_RET_IP_);
> @@ -1645,7 +1645,7 @@ void __init memblock_free_late(phys_addr_t base,
> phys_addr_t size)
>  {
>   phys_addr_t cursor, end;
> 
> - end = base + size - 1;
> + end = base + min(size, PHYS_ADDR_MAX - base + 1) - 1;
>   memblock_dbg("%s: [%pa-%pa] %pS\n",
>        __func__, &base, &end, (void *)_RET_IP_);
>   kmemleak_free_part_phys(base, size);
> -- 
> 2.34.1

-- 
Sincerely yours,
Mike.


  reply	other threads:[~2023-03-25  6:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-24  8:15 纪宏宾
2023-03-25  6:04 ` Mike Rapoport [this message]
2023-03-25  6:25   ` Hongbin Ji
2023-03-25  6:42     ` Mike Rapoport
2023-03-25  7:04       ` Hongbin Ji
2023-03-25  7:07         ` Hongbin Ji

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=ZB6O5awTbmcmqFI5@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=jihongbin999@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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