All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] memblock: Make memblock memblock_dbg info handle overflowing range @base + @size
@ 2023-03-24  8:15 纪宏宾
  2023-03-25  6:04 ` Mike Rapoport
  0 siblings, 1 reply; 6+ messages in thread
From: 纪宏宾 @ 2023-03-24  8:15 UTC (permalink / raw)
  To: rppt; +Cc: akpm, linux-mm, linux-kernel

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.

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] memblock: Make memblock memblock_dbg info handle overflowing range @base + @size
  2023-03-24  8:15 [PATCH] memblock: Make memblock memblock_dbg info handle overflowing range @base + @size 纪宏宾
@ 2023-03-25  6:04 ` Mike Rapoport
  2023-03-25  6:25   ` Hongbin Ji
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Rapoport @ 2023-03-25  6:04 UTC (permalink / raw)
  To: 纪宏宾; +Cc: akpm, linux-mm, linux-kernel

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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] memblock: Make memblock memblock_dbg info handle overflowing range @base + @size
  2023-03-25  6:04 ` Mike Rapoport
@ 2023-03-25  6:25   ` Hongbin Ji
  2023-03-25  6:42     ` Mike Rapoport
  0 siblings, 1 reply; 6+ messages in thread
From: Hongbin Ji @ 2023-03-25  6:25 UTC (permalink / raw)
  To: Mike Rapoport; +Cc: akpm, linux-mm, linux-kernel

It is just to correct the information displayed by the debugging.
The wrong information display is also a problem, but it is not a
problem that affects the function

Mike Rapoport <rppt@kernel.org> 于2023年3月25日周六 14:04写道:
>
> 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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] memblock: Make memblock memblock_dbg info handle overflowing range @base + @size
  2023-03-25  6:25   ` Hongbin Ji
@ 2023-03-25  6:42     ` Mike Rapoport
  2023-03-25  7:04       ` Hongbin Ji
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Rapoport @ 2023-03-25  6:42 UTC (permalink / raw)
  To: Hongbin Ji; +Cc: akpm, linux-mm, linux-kernel

On Sat, Mar 25, 2023 at 02:25:58PM +0800, Hongbin Ji wrote:
> It is just to correct the information displayed by the debugging.
> The wrong information display is also a problem, but it is not a
> problem that affects the function

Please don't top post.

Wrong debugging info will be the least of the problems if memblock_add() or
membloc_remove() are called with wrong parameters.

Please work on cleanups based on code inspection outside of mm/
 
> Mike Rapoport <rppt@kernel.org> 于2023年3月25日周六 14:04写道:
> >
> > 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.

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] memblock: Make memblock memblock_dbg info handle overflowing range @base + @size
  2023-03-25  6:42     ` Mike Rapoport
@ 2023-03-25  7:04       ` Hongbin Ji
  2023-03-25  7:07         ` Hongbin Ji
  0 siblings, 1 reply; 6+ messages in thread
From: Hongbin Ji @ 2023-03-25  7:04 UTC (permalink / raw)
  To: Mike Rapoport; +Cc: akpm, linux-mm, linux-kernel

Sorry, this is the first time I use email, I checked the top post and
bottom post just now, I will modify the sending method.

Passing an oversized @size argument is allowed inside membloc_remove().

static inline phys_addr_t memblock_cap_size(phys_addr_t base, phys_addr_t *size)
{
        return *size = min(*size, (phys_addr_t)ULLONG_MAX - base);
}

phys_addr_t end = base + memblock_cap_size(base, &size);

and internally checks and handles @size parameter overflow

Mike Rapoport <rppt@kernel.org> 于2023年3月25日周六 14:42写道:
>
> On Sat, Mar 25, 2023 at 02:25:58PM +0800, Hongbin Ji wrote:
> > It is just to correct the information displayed by the debugging.
> > The wrong information display is also a problem, but it is not a
> > problem that affects the function
>
> Please don't top post.
>
> Wrong debugging info will be the least of the problems if memblock_add() or
> membloc_remove() are called with wrong parameters.
>
> Please work on cleanups based on code inspection outside of mm/
>
> > Mike Rapoport <rppt@kernel.org> 于2023年3月25日周六 14:04写道:
> > >
> > > 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.
>
> --
> Sincerely yours,
> Mike.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] memblock: Make memblock memblock_dbg info handle overflowing range @base + @size
  2023-03-25  7:04       ` Hongbin Ji
@ 2023-03-25  7:07         ` Hongbin Ji
  0 siblings, 0 replies; 6+ messages in thread
From: Hongbin Ji @ 2023-03-25  7:07 UTC (permalink / raw)
  To: Mike Rapoport; +Cc: akpm, linux-mm, linux-kernel

Actually @base + @size overflows

On Sat, Mar 25, 2023 at 3:04 PM Hongbin Ji <jihongbin999@gmail.com> wrote:
>
> Sorry, this is the first time I use email, I checked the top post and
> bottom post just now, I will modify the sending method.
>
> Passing an oversized @size argument is allowed inside membloc_remove().
>
> static inline phys_addr_t memblock_cap_size(phys_addr_t base, phys_addr_t *size)
> {
>         return *size = min(*size, (phys_addr_t)ULLONG_MAX - base);
> }
>
> phys_addr_t end = base + memblock_cap_size(base, &size);
>
> and internally checks and handles @size parameter overflow
>
> Mike Rapoport <rppt@kernel.org> 于2023年3月25日周六 14:42写道:
> >
> > On Sat, Mar 25, 2023 at 02:25:58PM +0800, Hongbin Ji wrote:
> > > It is just to correct the information displayed by the debugging.
> > > The wrong information display is also a problem, but it is not a
> > > problem that affects the function
> >
> > Please don't top post.
> >
> > Wrong debugging info will be the least of the problems if memblock_add() or
> > membloc_remove() are called with wrong parameters.
> >
> > Please work on cleanups based on code inspection outside of mm/
> >
> > > Mike Rapoport <rppt@kernel.org> 于2023年3月25日周六 14:04写道:
> > > >
> > > > 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.
> >
> > --
> > Sincerely yours,
> > Mike.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-25  7:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-24  8:15 [PATCH] memblock: Make memblock memblock_dbg info handle overflowing range @base + @size 纪宏宾
2023-03-25  6:04 ` Mike Rapoport
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.