linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/1] alloc_tag: remove empty module tag section from
@ 2025-06-05 19:01 Casey Chen
  2025-06-05 19:01 ` [PATCH 1/1] alloc_tag: remove empty module tag section from linker script Casey Chen
  0 siblings, 1 reply; 5+ messages in thread
From: Casey Chen @ 2025-06-05 19:01 UTC (permalink / raw)
  To: linux-mm, surenb, kent.overstreet; +Cc: yzhong, cachen

We found gdb misinterpret symbol addresses e.g., __ib_process_cq from
ib_core.ko:
  (gdb) disas __ib_process_cq
  Dump of assembler code for function trace_event_fields_cq_schedule:
  ...

instead of
  (gdb) disas __ib_process_cq
  Dump of assembler code for function __ib_process_cq:
  ...

The module tag section added by the empty MOD_CODETAG_SECTIONS() macro looks
suspicious. With and without the fix, .data section placement looks different:

Without the fix, .data is placed at 0x300:
  Section Headers:
    [Nr] Name              Type             Address           Offset
         Size              EntSize          Flags  Link  Info  Align
    ...
    [51] .data             PROGBITS         0000000000000300  0004a180
         0000000000004a20  0000000000000000  WA       0     0     32

With the fix, .data is placed at 0x0:
    [48] .data             PROGBITS         0000000000000000  00049d20
         0000000000004a20  0000000000000000  WA       0     0     32

My gcc/ld/gdb versions are as below.
  $ gcc --version
  gcc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0

  $ ld --version
  GNU ld (GNU Binutils for Ubuntu) 2.38

  $ gdb --version
  GNU gdb (Ubuntu 12.1-0ubuntu1~22.04.2) 12.1

Does anybody have an idea how the misinterpretation happens ? Also I don't
understand the use of MOD_CODETAG_SECTIONS() very well. I am thinking it is
for some future use to have module tags whose lifespan is same as the module.
It is empty and shouldn't cause any issue.

Casey Chen (1):
  alloc_tag: remove empty module tag section from linker script

 scripts/module.lds.S | 5 -----
 1 file changed, 5 deletions(-)

-- 
2.34.1



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

* [PATCH 1/1] alloc_tag: remove empty module tag section from linker script
  2025-06-05 19:01 [PATCH 0/1] alloc_tag: remove empty module tag section from Casey Chen
@ 2025-06-05 19:01 ` Casey Chen
  2025-06-05 20:07   ` Suren Baghdasaryan
  0 siblings, 1 reply; 5+ messages in thread
From: Casey Chen @ 2025-06-05 19:01 UTC (permalink / raw)
  To: linux-mm, surenb, kent.overstreet; +Cc: yzhong, cachen

The empty MOD_CODETAG_SECTIONS() macro added an incomplete .data
section in module linker script, which caused symbol lookup tools
like gdb to misinterpret symbol addresses e.g., __ib_process_cq
incorrectly mapping to unrelated functions like below.

  (gdb) disas __ib_process_cq
  Dump of assembler code for function trace_event_fields_cq_schedule:

Removing the empty section restores proper symbol resolution and
layout, ensuring .data placement behaves as expected.

Fixes: 22d407b164ff ("lib: add allocation tagging support for memory allocation profiling")
Signed-off-by: Casey Chen <cachen@purestorage.com>
Reviewed-by: Yuanyuan Zhong <yzhong@purestorage.com>
---
 scripts/module.lds.S | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/scripts/module.lds.S b/scripts/module.lds.S
index 711c6e029936..c071ca4beedd 100644
--- a/scripts/module.lds.S
+++ b/scripts/module.lds.S
@@ -50,17 +50,12 @@ SECTIONS {
 	.data : {
 		*(.data .data.[0-9a-zA-Z_]*)
 		*(.data..L*)
-		MOD_CODETAG_SECTIONS()
 	}
 
 	.rodata : {
 		*(.rodata .rodata.[0-9a-zA-Z_]*)
 		*(.rodata..L*)
 	}
-#else
-	.data : {
-		MOD_CODETAG_SECTIONS()
-	}
 #endif
 	MOD_SEPARATE_CODETAG_SECTIONS()
 }
-- 
2.34.1



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

* Re: [PATCH 1/1] alloc_tag: remove empty module tag section from linker script
  2025-06-05 19:01 ` [PATCH 1/1] alloc_tag: remove empty module tag section from linker script Casey Chen
@ 2025-06-05 20:07   ` Suren Baghdasaryan
  2025-06-09 21:15     ` Casey Chen
  0 siblings, 1 reply; 5+ messages in thread
From: Suren Baghdasaryan @ 2025-06-05 20:07 UTC (permalink / raw)
  To: Casey Chen; +Cc: linux-mm, kent.overstreet, yzhong

On Thu, Jun 5, 2025 at 12:01 PM Casey Chen <cachen@purestorage.com> wrote:
>
> The empty MOD_CODETAG_SECTIONS() macro added an incomplete .data
> section in module linker script, which caused symbol lookup tools
> like gdb to misinterpret symbol addresses e.g., __ib_process_cq
> incorrectly mapping to unrelated functions like below.
>
>   (gdb) disas __ib_process_cq
>   Dump of assembler code for function trace_event_fields_cq_schedule:
>
> Removing the empty section restores proper symbol resolution and
> layout, ensuring .data placement behaves as expected.

Hmm. I'm not sure why an empty .data section would cause such an
issue. Is that expected behavior?

To clarify, codetags are designed to support different types of tags,
not only allocation tags which we currently use. It so happens that
allocation tags can be still used after module unload, therefore they
are placed into MOD_SEPARATE_CODETAG_SECTIONS(). If some other tags
are added in the future and their lifecycle is the same as modules
(IOW after module unload they can be unloaded too), then they would be
added into MOD_CODETAG_SECTIONS() but until then this section is
empty.

>
> Fixes: 22d407b164ff ("lib: add allocation tagging support for memory allocation profiling")
> Signed-off-by: Casey Chen <cachen@purestorage.com>
> Reviewed-by: Yuanyuan Zhong <yzhong@purestorage.com>
> ---
>  scripts/module.lds.S | 5 -----
>  1 file changed, 5 deletions(-)
>
> diff --git a/scripts/module.lds.S b/scripts/module.lds.S
> index 711c6e029936..c071ca4beedd 100644
> --- a/scripts/module.lds.S
> +++ b/scripts/module.lds.S
> @@ -50,17 +50,12 @@ SECTIONS {
>         .data : {
>                 *(.data .data.[0-9a-zA-Z_]*)
>                 *(.data..L*)
> -               MOD_CODETAG_SECTIONS()
>         }
>
>         .rodata : {
>                 *(.rodata .rodata.[0-9a-zA-Z_]*)
>                 *(.rodata..L*)
>         }
> -#else
> -       .data : {
> -               MOD_CODETAG_SECTIONS()
> -       }
>  #endif
>         MOD_SEPARATE_CODETAG_SECTIONS()
>  }
> --
> 2.34.1
>


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

* Re: [PATCH 1/1] alloc_tag: remove empty module tag section from linker script
  2025-06-05 20:07   ` Suren Baghdasaryan
@ 2025-06-09 21:15     ` Casey Chen
  2025-06-09 22:55       ` Suren Baghdasaryan
  0 siblings, 1 reply; 5+ messages in thread
From: Casey Chen @ 2025-06-09 21:15 UTC (permalink / raw)
  To: Suren Baghdasaryan; +Cc: linux-mm, kent.overstreet, yzhong

On Thu, Jun 5, 2025 at 1:07 PM Suren Baghdasaryan <surenb@google.com> wrote:
>
> On Thu, Jun 5, 2025 at 12:01 PM Casey Chen <cachen@purestorage.com> wrote:
> >
> > The empty MOD_CODETAG_SECTIONS() macro added an incomplete .data
> > section in module linker script, which caused symbol lookup tools
> > like gdb to misinterpret symbol addresses e.g., __ib_process_cq
> > incorrectly mapping to unrelated functions like below.
> >
> >   (gdb) disas __ib_process_cq
> >   Dump of assembler code for function trace_event_fields_cq_schedule:
> >
> > Removing the empty section restores proper symbol resolution and
> > layout, ensuring .data placement behaves as expected.
>
> Hmm. I'm not sure why an empty .data section would cause such an
> issue. Is that expected behavior?
>

I'm not sure that's why I am posting this to ask for ideas. It looks
like gdb failed to disassemble function.

> To clarify, codetags are designed to support different types of tags,
> not only allocation tags which we currently use. It so happens that
> allocation tags can be still used after module unload, therefore they
> are placed into MOD_SEPARATE_CODETAG_SECTIONS(). If some other tags
> are added in the future and their lifecycle is the same as modules
> (IOW after module unload they can be unloaded too), then they would be
> added into MOD_CODETAG_SECTIONS() but until then this section is
> empty.
>

Could we remove the empty data section with MOD_CODETAG_SECTIONS() for
now until we really need it ?
> >
> > Fixes: 22d407b164ff ("lib: add allocation tagging support for memory allocation profiling")
> > Signed-off-by: Casey Chen <cachen@purestorage.com>
> > Reviewed-by: Yuanyuan Zhong <yzhong@purestorage.com>
> > ---
> >  scripts/module.lds.S | 5 -----
> >  1 file changed, 5 deletions(-)
> >
> > diff --git a/scripts/module.lds.S b/scripts/module.lds.S
> > index 711c6e029936..c071ca4beedd 100644
> > --- a/scripts/module.lds.S
> > +++ b/scripts/module.lds.S
> > @@ -50,17 +50,12 @@ SECTIONS {
> >         .data : {
> >                 *(.data .data.[0-9a-zA-Z_]*)
> >                 *(.data..L*)
> > -               MOD_CODETAG_SECTIONS()
> >         }
> >
> >         .rodata : {
> >                 *(.rodata .rodata.[0-9a-zA-Z_]*)
> >                 *(.rodata..L*)
> >         }
> > -#else
> > -       .data : {
> > -               MOD_CODETAG_SECTIONS()
> > -       }
> >  #endif
> >         MOD_SEPARATE_CODETAG_SECTIONS()
> >  }
> > --
> > 2.34.1
> >


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

* Re: [PATCH 1/1] alloc_tag: remove empty module tag section from linker script
  2025-06-09 21:15     ` Casey Chen
@ 2025-06-09 22:55       ` Suren Baghdasaryan
  0 siblings, 0 replies; 5+ messages in thread
From: Suren Baghdasaryan @ 2025-06-09 22:55 UTC (permalink / raw)
  To: Casey Chen; +Cc: linux-mm, kent.overstreet, yzhong

On Mon, Jun 9, 2025 at 2:15 PM Casey Chen <cachen@purestorage.com> wrote:
>
> On Thu, Jun 5, 2025 at 1:07 PM Suren Baghdasaryan <surenb@google.com> wrote:
> >
> > On Thu, Jun 5, 2025 at 12:01 PM Casey Chen <cachen@purestorage.com> wrote:
> > >
> > > The empty MOD_CODETAG_SECTIONS() macro added an incomplete .data
> > > section in module linker script, which caused symbol lookup tools
> > > like gdb to misinterpret symbol addresses e.g., __ib_process_cq
> > > incorrectly mapping to unrelated functions like below.
> > >
> > >   (gdb) disas __ib_process_cq
> > >   Dump of assembler code for function trace_event_fields_cq_schedule:
> > >
> > > Removing the empty section restores proper symbol resolution and
> > > layout, ensuring .data placement behaves as expected.
> >
> > Hmm. I'm not sure why an empty .data section would cause such an
> > issue. Is that expected behavior?
> >
>
> I'm not sure that's why I am posting this to ask for ideas. It looks
> like gdb failed to disassemble function.
>
> > To clarify, codetags are designed to support different types of tags,
> > not only allocation tags which we currently use. It so happens that
> > allocation tags can be still used after module unload, therefore they
> > are placed into MOD_SEPARATE_CODETAG_SECTIONS(). If some other tags
> > are added in the future and their lifecycle is the same as modules
> > (IOW after module unload they can be unloaded too), then they would be
> > added into MOD_CODETAG_SECTIONS() but until then this section is
> > empty.
> >
>
> Could we remove the empty data section with MOD_CODETAG_SECTIONS() for
> now until we really need it ?

Ok, I see no issue with removing it but please remove its definition
from codetag.lds.h as well.

Whenever sending mm related patches (including alloc_tag ones) please
send them to akpm@linux-foundation.org and CC everyone else. Andrew is
the mm tree maintainer and that's the usual way to post MM changes.
Thanks,
Suren.

> > >
> > > Fixes: 22d407b164ff ("lib: add allocation tagging support for memory allocation profiling")
> > > Signed-off-by: Casey Chen <cachen@purestorage.com>
> > > Reviewed-by: Yuanyuan Zhong <yzhong@purestorage.com>
> > > ---
> > >  scripts/module.lds.S | 5 -----
> > >  1 file changed, 5 deletions(-)
> > >
> > > diff --git a/scripts/module.lds.S b/scripts/module.lds.S
> > > index 711c6e029936..c071ca4beedd 100644
> > > --- a/scripts/module.lds.S
> > > +++ b/scripts/module.lds.S
> > > @@ -50,17 +50,12 @@ SECTIONS {
> > >         .data : {
> > >                 *(.data .data.[0-9a-zA-Z_]*)
> > >                 *(.data..L*)
> > > -               MOD_CODETAG_SECTIONS()
> > >         }
> > >
> > >         .rodata : {
> > >                 *(.rodata .rodata.[0-9a-zA-Z_]*)
> > >                 *(.rodata..L*)
> > >         }
> > > -#else
> > > -       .data : {
> > > -               MOD_CODETAG_SECTIONS()
> > > -       }
> > >  #endif
> > >         MOD_SEPARATE_CODETAG_SECTIONS()
> > >  }
> > > --
> > > 2.34.1
> > >


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

end of thread, other threads:[~2025-06-09 22:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-05 19:01 [PATCH 0/1] alloc_tag: remove empty module tag section from Casey Chen
2025-06-05 19:01 ` [PATCH 1/1] alloc_tag: remove empty module tag section from linker script Casey Chen
2025-06-05 20:07   ` Suren Baghdasaryan
2025-06-09 21:15     ` Casey Chen
2025-06-09 22:55       ` Suren Baghdasaryan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox