[PATCH v1 07/12] dyndbg: repack struct _ddebug

Łukasz Bartosik posted 12 patches 2 years, 1 month ago
There is a newer version of this series
[PATCH v1 07/12] dyndbg: repack struct _ddebug
Posted by Łukasz Bartosik 2 years, 1 month ago
From: Jim Cromie <jim.cromie@gmail.com>

Move the JUMP_LABEL to the top of the struct, since theyre both
align(8) and this closes a pahole (unfortunately trading for padding,
but still).

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 include/linux/dynamic_debug.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 497130816e9c..b9237e4ecd1b 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -14,6 +14,12 @@
  * the special section is treated as an array of these.
  */
 struct _ddebug {
+#ifdef CONFIG_JUMP_LABEL
+	union {
+		struct static_key_true dd_key_true;
+		struct static_key_false dd_key_false;
+	} key;
+#endif
 	/*
 	 * These fields are used to drive the user interface
 	 * for selecting and displaying debug callsites.
@@ -53,12 +59,6 @@ struct _ddebug {
 #define _DPRINTK_FLAGS_DEFAULT 0
 #endif
 	unsigned int flags:8;
-#ifdef CONFIG_JUMP_LABEL
-	union {
-		struct static_key_true dd_key_true;
-		struct static_key_false dd_key_false;
-	} key;
-#endif
 } __attribute__((aligned(8)));
 
 enum class_map_type {
-- 
2.42.0.869.gea05f2083d-goog
Re: [PATCH v1 07/12] dyndbg: repack struct _ddebug
Posted by jim.cromie@gmail.com 2 years, 1 month ago
On Fri, Nov 3, 2023 at 7:10 AM Łukasz Bartosik <lb@semihalf.com> wrote:
>
> From: Jim Cromie <jim.cromie@gmail.com>
>
> Move the JUMP_LABEL to the top of the struct, since theyre both
> align(8) and this closes a pahole (unfortunately trading for padding,
> but still).
>
> Signed-off-by: Jim Cromie <jim.cromie@gmail.com>

let me add, I havent really tested this, nevermind thorough.
specifically, I didnt look for any offset dependence on the static-key
inside their container.
Conversely, maybe theres a free default or something in there.

> ---
>  include/linux/dynamic_debug.h | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
> index 497130816e9c..b9237e4ecd1b 100644
> --- a/include/linux/dynamic_debug.h
> +++ b/include/linux/dynamic_debug.h
> @@ -14,6 +14,12 @@
>   * the special section is treated as an array of these.
>   */
>  struct _ddebug {
> +#ifdef CONFIG_JUMP_LABEL
> +       union {
> +               struct static_key_true dd_key_true;
> +               struct static_key_false dd_key_false;
> +       } key;
> +#endif
>         /*
>          * These fields are used to drive the user interface
>          * for selecting and displaying debug callsites.
> @@ -53,12 +59,6 @@ struct _ddebug {
>  #define _DPRINTK_FLAGS_DEFAULT 0
>  #endif
>         unsigned int flags:8;
> -#ifdef CONFIG_JUMP_LABEL
> -       union {
> -               struct static_key_true dd_key_true;
> -               struct static_key_false dd_key_false;
> -       } key;
> -#endif
>  } __attribute__((aligned(8)));
>
>  enum class_map_type {
> --
> 2.42.0.869.gea05f2083d-goog
>
Re: [PATCH v1 07/12] dyndbg: repack struct _ddebug
Posted by Łukasz Bartosik 2 years, 1 month ago
sob., 4 lis 2023 o 02:49 <jim.cromie@gmail.com> napisał(a):
>
> On Fri, Nov 3, 2023 at 7:10 AM Łukasz Bartosik <lb@semihalf.com> wrote:
> >
> > From: Jim Cromie <jim.cromie@gmail.com>
> >
> > Move the JUMP_LABEL to the top of the struct, since theyre both
> > align(8) and this closes a pahole (unfortunately trading for padding,
> > but still).
> >
> > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
>
> let me add, I havent really tested this, nevermind thorough.
> specifically, I didnt look for any offset dependence on the static-key
> inside their container.
> Conversely, maybe theres a free default or something in there.
>

Any idea how to properly test the relocation of the key ?



> > ---
> >  include/linux/dynamic_debug.h | 12 ++++++------
> >  1 file changed, 6 insertions(+), 6 deletions(-)
> >
> > diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
> > index 497130816e9c..b9237e4ecd1b 100644
> > --- a/include/linux/dynamic_debug.h
> > +++ b/include/linux/dynamic_debug.h
> > @@ -14,6 +14,12 @@
> >   * the special section is treated as an array of these.
> >   */
> >  struct _ddebug {
> > +#ifdef CONFIG_JUMP_LABEL
> > +       union {
> > +               struct static_key_true dd_key_true;
> > +               struct static_key_false dd_key_false;
> > +       } key;
> > +#endif
> >         /*
> >          * These fields are used to drive the user interface
> >          * for selecting and displaying debug callsites.
> > @@ -53,12 +59,6 @@ struct _ddebug {
> >  #define _DPRINTK_FLAGS_DEFAULT 0
> >  #endif
> >         unsigned int flags:8;
> > -#ifdef CONFIG_JUMP_LABEL
> > -       union {
> > -               struct static_key_true dd_key_true;
> > -               struct static_key_false dd_key_false;
> > -       } key;
> > -#endif
> >  } __attribute__((aligned(8)));
> >
> >  enum class_map_type {
> > --
> > 2.42.0.869.gea05f2083d-goog
> >
Re: [PATCH v1 07/12] dyndbg: repack struct _ddebug
Posted by jim.cromie@gmail.com 2 years, 1 month ago
On Fri, Nov 10, 2023 at 7:51 AM Łukasz Bartosik <lb@semihalf.com> wrote:
>
> sob., 4 lis 2023 o 02:49 <jim.cromie@gmail.com> napisał(a):
> >
> > On Fri, Nov 3, 2023 at 7:10 AM Łukasz Bartosik <lb@semihalf.com> wrote:
> > >
> > > From: Jim Cromie <jim.cromie@gmail.com>
> > >
> > > Move the JUMP_LABEL to the top of the struct, since theyre both
> > > align(8) and this closes a pahole (unfortunately trading for padding,
> > > but still).
> > >
> > > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> >
> > let me add, I havent really tested this, nevermind thorough.
> > specifically, I didnt look for any offset dependence on the static-key
> > inside their container.
> > Conversely, maybe theres a free default or something in there.
> >
>
> Any idea how to properly test the relocation of the key ?

I was hoping Jason knew it from memory.

I have booted dd-kitchen-sink, which includes it, and it didnt melt the box.

I just checked `pahole vmlinux` output for the existence of 0-offset keys.
Its not conclusive, cuz im only looking at x86.

it does occur, but only for "sub-types".

struct static_key_true {
        struct static_key          key;                  /*     0    16 */

        /* size: 16, cachelines: 1, members: 1 */
        /* last cacheline: 16 bytes */
};
struct static_key_false {
        struct static_key          key;                  /*     0    16 */

        /* size: 16, cachelines: 1, members: 1 */
        /* last cacheline: 16 bytes */
};
struct static_key_false_deferred {
        struct static_key_false    key;                  /*     0    16 */
...};
struct static_key_mod {
        struct static_key_mod *    next;                 /*     0     8 */
...};
struct static_key_deferred {
        struct static_key          key;                  /*     0    16 */
Re: [PATCH v1 07/12] dyndbg: repack struct _ddebug
Posted by Łukasz Bartosik 2 years, 1 month ago
pt., 10 lis 2023 o 22:01 <jim.cromie@gmail.com> napisał(a):
>
> On Fri, Nov 10, 2023 at 7:51 AM Łukasz Bartosik <lb@semihalf.com> wrote:
> >
> > sob., 4 lis 2023 o 02:49 <jim.cromie@gmail.com> napisał(a):
> > >
> > > On Fri, Nov 3, 2023 at 7:10 AM Łukasz Bartosik <lb@semihalf.com> wrote:
> > > >
> > > > From: Jim Cromie <jim.cromie@gmail.com>
> > > >
> > > > Move the JUMP_LABEL to the top of the struct, since theyre both
> > > > align(8) and this closes a pahole (unfortunately trading for padding,
> > > > but still).
> > > >
> > > > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> > >
> > > let me add, I havent really tested this, nevermind thorough.
> > > specifically, I didnt look for any offset dependence on the static-key
> > > inside their container.
> > > Conversely, maybe theres a free default or something in there.
> > >
> >
> > Any idea how to properly test the relocation of the key ?
>
> I was hoping Jason knew it from memory.
>
> I have booted dd-kitchen-sink, which includes it, and it didnt melt the box.
>
> I just checked `pahole vmlinux` output for the existence of 0-offset keys.
> Its not conclusive, cuz im only looking at x86.
>
> it does occur, but only for "sub-types".
>
> struct static_key_true {
>         struct static_key          key;                  /*     0    16 */
>
>         /* size: 16, cachelines: 1, members: 1 */
>         /* last cacheline: 16 bytes */
> };
> struct static_key_false {
>         struct static_key          key;                  /*     0    16 */
>
>         /* size: 16, cachelines: 1, members: 1 */
>         /* last cacheline: 16 bytes */
> };
> struct static_key_false_deferred {
>         struct static_key_false    key;                  /*     0    16 */
> ...};
> struct static_key_mod {
>         struct static_key_mod *    next;                 /*     0     8 */
> ...};
> struct static_key_deferred {
>         struct static_key          key;                  /*     0    16 */

I will test it on arm64.
Re: [PATCH v1 07/12] dyndbg: repack struct _ddebug
Posted by Łukasz Bartosik 2 years, 1 month ago
niedz., 12 lis 2023 o 17:28 Łukasz Bartosik <lb@semihalf.com> napisał(a):
>
> pt., 10 lis 2023 o 22:01 <jim.cromie@gmail.com> napisał(a):
> >
> > On Fri, Nov 10, 2023 at 7:51 AM Łukasz Bartosik <lb@semihalf.com> wrote:
> > >
> > > sob., 4 lis 2023 o 02:49 <jim.cromie@gmail.com> napisał(a):
> > > >
> > > > On Fri, Nov 3, 2023 at 7:10 AM Łukasz Bartosik <lb@semihalf.com> wrote:
> > > > >
> > > > > From: Jim Cromie <jim.cromie@gmail.com>
> > > > >
> > > > > Move the JUMP_LABEL to the top of the struct, since theyre both
> > > > > align(8) and this closes a pahole (unfortunately trading for padding,
> > > > > but still).
> > > > >
> > > > > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> > > >
> > > > let me add, I havent really tested this, nevermind thorough.
> > > > specifically, I didnt look for any offset dependence on the static-key
> > > > inside their container.
> > > > Conversely, maybe theres a free default or something in there.
> > > >
> > >
> > > Any idea how to properly test the relocation of the key ?
> >
> > I was hoping Jason knew it from memory.
> >
> > I have booted dd-kitchen-sink, which includes it, and it didnt melt the box.
> >
> > I just checked `pahole vmlinux` output for the existence of 0-offset keys.
> > Its not conclusive, cuz im only looking at x86.
> >
> > it does occur, but only for "sub-types".
> >
> > struct static_key_true {
> >         struct static_key          key;                  /*     0    16 */
> >
> >         /* size: 16, cachelines: 1, members: 1 */
> >         /* last cacheline: 16 bytes */
> > };
> > struct static_key_false {
> >         struct static_key          key;                  /*     0    16 */
> >
> >         /* size: 16, cachelines: 1, members: 1 */
> >         /* last cacheline: 16 bytes */
> > };
> > struct static_key_false_deferred {
> >         struct static_key_false    key;                  /*     0    16 */
> > ...};
> > struct static_key_mod {
> >         struct static_key_mod *    next;                 /*     0     8 */
> > ...};
> > struct static_key_deferred {
> >         struct static_key          key;                  /*     0    16 */
>
> I will test it on arm64.

Hi Jim,

I verified that relocation of JUMP_LABEL to the top of the _ddebug
struct does not brak dynamic debug functionality on arm64.
I double checked I had CONFIG_JUMP_LABEL enabled in the kernel config for arm64.
I was able to enable/disable callsites and see debug logs being written.

But if you're concerned there might be issue related to that
relocation on other architectures then let's drop this patch
and I will use pahole instead of padding for location of flags and
trace destination fields.
What do you think ?

Thanks,
Lukasz
Re: [PATCH v1 07/12] dyndbg: repack struct _ddebug
Posted by jim.cromie@gmail.com 2 years, 1 month ago
On Fri, Nov 24, 2023 at 7:39 AM Łukasz Bartosik <lb@semihalf.com> wrote:
>
> niedz., 12 lis 2023 o 17:28 Łukasz Bartosik <lb@semihalf.com> napisał(a):
> >
> > pt., 10 lis 2023 o 22:01 <jim.cromie@gmail.com> napisał(a):
> > >
> > > On Fri, Nov 10, 2023 at 7:51 AM Łukasz Bartosik <lb@semihalf.com> wrote:
> > > >
> > > > sob., 4 lis 2023 o 02:49 <jim.cromie@gmail.com> napisał(a):
> > > > >
> > > > > On Fri, Nov 3, 2023 at 7:10 AM Łukasz Bartosik <lb@semihalf.com> wrote:
> > > > > >
> > > > > > From: Jim Cromie <jim.cromie@gmail.com>
> > > > > >
> > > > > > Move the JUMP_LABEL to the top of the struct, since theyre both
> > > > > > align(8) and this closes a pahole (unfortunately trading for padding,
> > > > > > but still).
> > > > > >
> > > > > > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> > > > >
> > > > > let me add, I havent really tested this, nevermind thorough.
> > > > > specifically, I didnt look for any offset dependence on the static-key
> > > > > inside their container.
> > > > > Conversely, maybe theres a free default or something in there.
> > > > >
> > > >
> > > > Any idea how to properly test the relocation of the key ?
> > >
> > > I was hoping Jason knew it from memory.
> > >
> > > I have booted dd-kitchen-sink, which includes it, and it didnt melt the box.
> > >
> > > I just checked `pahole vmlinux` output for the existence of 0-offset keys.
> > > Its not conclusive, cuz im only looking at x86.
> > >
> > > it does occur, but only for "sub-types".
> > >
> > > struct static_key_true {
> > >         struct static_key          key;                  /*     0    16 */
> > >
> > >         /* size: 16, cachelines: 1, members: 1 */
> > >         /* last cacheline: 16 bytes */
> > > };
> > > struct static_key_false {
> > >         struct static_key          key;                  /*     0    16 */
> > >
> > >         /* size: 16, cachelines: 1, members: 1 */
> > >         /* last cacheline: 16 bytes */
> > > };
> > > struct static_key_false_deferred {
> > >         struct static_key_false    key;                  /*     0    16 */
> > > ...};
> > > struct static_key_mod {
> > >         struct static_key_mod *    next;                 /*     0     8 */
> > > ...};
> > > struct static_key_deferred {
> > >         struct static_key          key;                  /*     0    16 */
> >
> > I will test it on arm64.
>
> Hi Jim,
>
> I verified that relocation of JUMP_LABEL to the top of the _ddebug
> struct does not brak dynamic debug functionality on arm64.
> I double checked I had CONFIG_JUMP_LABEL enabled in the kernel config for arm64.
> I was able to enable/disable callsites and see debug logs being written.
>
> But if you're concerned there might be issue related to that
> relocation on other architectures then let's drop this patch
> and I will use pahole instead of padding for location of flags and
> trace destination fields.
> What do you think ?
>


On balance, I think it should go in.
0 - my bias was towards abundance of paranoia
1 - youve done real work to evaluate the actual risk
2 - Jason is on thread, hasnt said WHOA
3 - actual patches have seen some testing (lkp-robot included)
4 - static-keys/jump-labels have been around a long time

One new topic:

Do you have any thoughts or plans wrt self-testing ?

the addition of private instances,
that can be opened & closed, and written to by +T:private_1

would benefit greatly from a test harness to validate it.
so far all Ive done is demo scripts

:-) thanks

> Thanks,
> Lukasz
Re: [PATCH v1 07/12] dyndbg: repack struct _ddebug
Posted by Łukasz Bartosik 2 years, 1 month ago
niedz., 26 lis 2023 o 07:00 <jim.cromie@gmail.com> napisał(a):
>
> On Fri, Nov 24, 2023 at 7:39 AM Łukasz Bartosik <lb@semihalf.com> wrote:
> >
> > niedz., 12 lis 2023 o 17:28 Łukasz Bartosik <lb@semihalf.com> napisał(a):
> > >
> > > pt., 10 lis 2023 o 22:01 <jim.cromie@gmail.com> napisał(a):
> > > >
> > > > On Fri, Nov 10, 2023 at 7:51 AM Łukasz Bartosik <lb@semihalf.com> wrote:
> > > > >
> > > > > sob., 4 lis 2023 o 02:49 <jim.cromie@gmail.com> napisał(a):
> > > > > >
> > > > > > On Fri, Nov 3, 2023 at 7:10 AM Łukasz Bartosik <lb@semihalf.com> wrote:
> > > > > > >
> > > > > > > From: Jim Cromie <jim.cromie@gmail.com>
> > > > > > >
> > > > > > > Move the JUMP_LABEL to the top of the struct, since theyre both
> > > > > > > align(8) and this closes a pahole (unfortunately trading for padding,
> > > > > > > but still).
> > > > > > >
> > > > > > > Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
> > > > > >
> > > > > > let me add, I havent really tested this, nevermind thorough.
> > > > > > specifically, I didnt look for any offset dependence on the static-key
> > > > > > inside their container.
> > > > > > Conversely, maybe theres a free default or something in there.
> > > > > >
> > > > >
> > > > > Any idea how to properly test the relocation of the key ?
> > > >
> > > > I was hoping Jason knew it from memory.
> > > >
> > > > I have booted dd-kitchen-sink, which includes it, and it didnt melt the box.
> > > >
> > > > I just checked `pahole vmlinux` output for the existence of 0-offset keys.
> > > > Its not conclusive, cuz im only looking at x86.
> > > >
> > > > it does occur, but only for "sub-types".
> > > >
> > > > struct static_key_true {
> > > >         struct static_key          key;                  /*     0    16 */
> > > >
> > > >         /* size: 16, cachelines: 1, members: 1 */
> > > >         /* last cacheline: 16 bytes */
> > > > };
> > > > struct static_key_false {
> > > >         struct static_key          key;                  /*     0    16 */
> > > >
> > > >         /* size: 16, cachelines: 1, members: 1 */
> > > >         /* last cacheline: 16 bytes */
> > > > };
> > > > struct static_key_false_deferred {
> > > >         struct static_key_false    key;                  /*     0    16 */
> > > > ...};
> > > > struct static_key_mod {
> > > >         struct static_key_mod *    next;                 /*     0     8 */
> > > > ...};
> > > > struct static_key_deferred {
> > > >         struct static_key          key;                  /*     0    16 */
> > >
> > > I will test it on arm64.
> >
> > Hi Jim,
> >
> > I verified that relocation of JUMP_LABEL to the top of the _ddebug
> > struct does not brak dynamic debug functionality on arm64.
> > I double checked I had CONFIG_JUMP_LABEL enabled in the kernel config for arm64.
> > I was able to enable/disable callsites and see debug logs being written.
> >
> > But if you're concerned there might be issue related to that
> > relocation on other architectures then let's drop this patch
> > and I will use pahole instead of padding for location of flags and
> > trace destination fields.
> > What do you think ?
> >
>
>
> On balance, I think it should go in.
> 0 - my bias was towards abundance of paranoia
> 1 - youve done real work to evaluate the actual risk
> 2 - Jason is on thread, hasnt said WHOA
> 3 - actual patches have seen some testing (lkp-robot included)
> 4 - static-keys/jump-labels have been around a long time
>
> One new topic:
>
> Do you have any thoughts or plans wrt self-testing ?
>

Actually I didn't think about it at all ;). It is not so common
practice to write tests among kernel developers. Addition of trace
instances & events to the dynamic debug is a major change so I see the
value in having it thoroughly tested. That said I'm not saying no to
writing test harness for that purpose but I wonder if there is any
test framework in the kernel that could be reused or is everyone on
their own when it comes to the testing area ?

Thanks,
Lukasz

> the addition of private instances,
> that can be opened & closed, and written to by +T:private_1
>
> would benefit greatly from a test harness to validate it.
> so far all Ive done is demo scripts
>
> :-) thanks
>
> > Thanks,
> > Lukasz