[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [PATCH 18/30] notifier: Show function names on notifier routines if DEBUG_NOTIFIERS is set
 
- To: "Guilherme G. Piccoli" <gpiccoli@xxxxxxxxxx>, "akpm@xxxxxxxxxxxxxxxxxxxx"	<akpm@xxxxxxxxxxxxxxxxxxxx>, "bhe@xxxxxxxxxx" <bhe@xxxxxxxxxx>,	"pmladek@xxxxxxxx" <pmladek@xxxxxxxx>, "kexec@xxxxxxxxxxxxxxxxxxx"	<kexec@xxxxxxxxxxxxxxxxxxx>
 
- From: "Michael Kelley (LINUX)" <mikelley@xxxxxxxxxxxxx>
 
- Date: Fri, 29 Apr 2022 16:27:42 +0000
 
- Accept-language: en-US
 
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none
 
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vuwI3s0/uzAI4p0El6C+ADHa0t+3Aw9/kpVyepipcnA=; b=l9uL7cPI8dCubco6QGE8scXjG37TX2AlQuD6kVVSaJZHZiAoJyZaqg8RLI40iqDR0GyF38DTpURbAfKZuoKeLOnm6j3tzS2gL3IBYVV5Fx33SE2OAHyunm21z8JXr16QveJjzaMoX7Va/kf1Ap/vSk7+95TCHIktVFjpQIwtOZ6OqsNW9S0SpPO2GbxB4nguU2r26VDfGrx7BamF5XBhdTpmjPbxYyKhuAyTSo6N3QUdY2DgRmT4bocM0soKQaLPi/R2qfUZ/mGo3jy2ehlbqu5bH2qggAjnGaWXMifxsuGnZPwoaRDw4a3jK8Y2fsgK0I0JhR9+67RoL/3ALtY24A==
 
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iiRnmDCv6QXvKP6MuSaJUsvdzjZ3+bKaim7DUV10U2RiYluMwndhB0+g8eo922omk91MoEzA5kDdABC/GDoEv3leu6fH3rTynjbp8ShDwocs6lESLqrQOBe45W94OtVawEoGRoYT04sxfBK5UmK+jhWXC37iVR1y1ZfAA5nND1Bq2a3KpDt3+MSKVXZfTh40yd142ycwEhIUhQj1RRHwAG9bbggAYPj8giZffS8/E9zWXF5crw0TpK8RjJyZDWuLBELTkv4p05hsHHu0xUmzL6krU9rVi2NQNWDazBYiV+5Mniw+4AfTVmsrGQ6jt+fcMCab43DLOIl+vtEQ2gAhGA==
 
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com;
 
- Cc: "linux-kernel@xxxxxxxxxxxxxxx" <linux-kernel@xxxxxxxxxxxxxxx>,	"bcm-kernel-feedback-list@xxxxxxxxxxxx"	<bcm-kernel-feedback-list@xxxxxxxxxxxx>, "coresight@xxxxxxxxxxxxxxxx"	<coresight@xxxxxxxxxxxxxxxx>, "linuxppc-dev@xxxxxxxxxxxxxxxx"	<linuxppc-dev@xxxxxxxxxxxxxxxx>, "linux-alpha@xxxxxxxxxxxxxxx"	<linux-alpha@xxxxxxxxxxxxxxx>, "linux-arm-kernel@xxxxxxxxxxxxxxxxxxx"	<linux-arm-kernel@xxxxxxxxxxxxxxxxxxx>, "linux-edac@xxxxxxxxxxxxxxx"	<linux-edac@xxxxxxxxxxxxxxx>, "linux-hyperv@xxxxxxxxxxxxxxx"	<linux-hyperv@xxxxxxxxxxxxxxx>, "linux-leds@xxxxxxxxxxxxxxx"	<linux-leds@xxxxxxxxxxxxxxx>, "linux-mips@xxxxxxxxxxxxxxx"	<linux-mips@xxxxxxxxxxxxxxx>, "linux-parisc@xxxxxxxxxxxxxxx"	<linux-parisc@xxxxxxxxxxxxxxx>, "linux-pm@xxxxxxxxxxxxxxx"	<linux-pm@xxxxxxxxxxxxxxx>, "linux-remoteproc@xxxxxxxxxxxxxxx"	<linux-remoteproc@xxxxxxxxxxxxxxx>, "linux-s390@xxxxxxxxxxxxxxx"	<linux-s390@xxxxxxxxxxxxxxx>, "linux-tegra@xxxxxxxxxxxxxxx"	<linux-tegra@xxxxxxxxxxxxxxx>, "linux-um@xxxxxxxxxxxxxxxxxxx"	<linux-um@xxxxxxxxxxxxxxxxxxx>, "linux-xtensa@xxxxxxxxxxxxxxxx"	<linux-xtensa@xxxxxxxxxxxxxxxx>, "netdev@xxxxxxxxxxxxxxx"	<netdev@xxxxxxxxxxxxxxx>, "openipmi-developer@xxxxxxxxxxxxxxxxxxxxx"	<openipmi-developer@xxxxxxxxxxxxxxxxxxxxx>, "rcu@xxxxxxxxxxxxxxx"	<rcu@xxxxxxxxxxxxxxx>, "sparclinux@xxxxxxxxxxxxxxx"	<sparclinux@xxxxxxxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx"	<xen-devel@xxxxxxxxxxxxxxxxxxxx>, "x86@xxxxxxxxxx" <x86@xxxxxxxxxx>,	"kernel-dev@xxxxxxxxxx" <kernel-dev@xxxxxxxxxx>, "kernel@xxxxxxxxxxxx"	<kernel@xxxxxxxxxxxx>, "halves@xxxxxxxxxxxxx" <halves@xxxxxxxxxxxxx>,	"fabiomirmar@xxxxxxxxx" <fabiomirmar@xxxxxxxxx>,	"alejandro.j.jimenez@xxxxxxxxxx" <alejandro.j.jimenez@xxxxxxxxxx>,	"andriy.shevchenko@xxxxxxxxxxxxxxx" <andriy.shevchenko@xxxxxxxxxxxxxxx>,	"arnd@xxxxxxxx" <arnd@xxxxxxxx>, "bp@xxxxxxxxx" <bp@xxxxxxxxx>,	"corbet@xxxxxxx" <corbet@xxxxxxx>, "d.hatayama@xxxxxxxxxxxxxx"	<d.hatayama@xxxxxxxxxxxxxx>, "dave.hansen@xxxxxxxxxxxxxxx"	<dave.hansen@xxxxxxxxxxxxxxx>, "dyoung@xxxxxxxxxx" <dyoung@xxxxxxxxxx>,	"feng.tang@xxxxxxxxx" <feng.tang@xxxxxxxxx>, "gregkh@xxxxxxxxxxxxxxxxxxx"	<gregkh@xxxxxxxxxxxxxxxxxxx>, "hidehiro.kawai.ez@xxxxxxxxxxx"	<hidehiro.kawai.ez@xxxxxxxxxxx>, "jgross@xxxxxxxx" <jgross@xxxxxxxx>,	"john.ogness@xxxxxxxxxxxxx" <john.ogness@xxxxxxxxxxxxx>,	"keescook@xxxxxxxxxxxx" <keescook@xxxxxxxxxxxx>, "luto@xxxxxxxxxx"	<luto@xxxxxxxxxx>, "mhiramat@xxxxxxxxxx" <mhiramat@xxxxxxxxxx>,	"mingo@xxxxxxxxxx" <mingo@xxxxxxxxxx>, "paulmck@xxxxxxxxxx"	<paulmck@xxxxxxxxxx>, "peterz@xxxxxxxxxxxxx" <peterz@xxxxxxxxxxxxx>,	"rostedt@xxxxxxxxxxx" <rostedt@xxxxxxxxxxx>, "senozhatsky@xxxxxxxxxxxx"	<senozhatsky@xxxxxxxxxxxx>, "stern@xxxxxxxxxxxxxxxxxxx"	<stern@xxxxxxxxxxxxxxxxxxx>, "tglx@xxxxxxxxxxxxx" <tglx@xxxxxxxxxxxxx>,	"vgoyal@xxxxxxxxxx" <vgoyal@xxxxxxxxxx>, vkuznets <vkuznets@xxxxxxxxxx>,	"will@xxxxxxxxxx" <will@xxxxxxxxxx>, Arjan van de Ven	<arjan@xxxxxxxxxxxxxxx>, Cong Wang <xiyou.wangcong@xxxxxxxxx>, Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>, Valentin Schneider	<valentin.schneider@xxxxxxx>, Xiaoming Ni <nixiaoming@xxxxxxxxxx>
 
- Delivery-date: Fri, 29 Apr 2022 16:28:03 +0000
 
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
 
- Msip_labels:  MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ActionId=581a9fba-2d25-46d7-8cfa-60e93c53f88c;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_ContentBits=0;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=true;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Method=Standard;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=Internal;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2022-04-29T16:26:20Z;MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47;
 
- Thread-index: AQHYWonZ3NInIg4txEiT4R4E8VEqwq0HFqRA
 
- Thread-topic: [PATCH 18/30] notifier: Show function names on notifier routines if DEBUG_NOTIFIERS is set
 
 
 
From: Guilherme G. Piccoli <gpiccoli@xxxxxxxxxx> Sent: Wednesday, April 27, 
2022 3:49 PM
> 
> Currently we have a debug infrastructure in the notifiers file, but
> it's very simple/limited. This patch extends it by:
> 
> (a) Showing all registered/unregistered notifiers' callback names;
> 
> (b) Adding a dynamic debug tuning to allow showing called notifiers'
> function names. Notice that this should be guarded as a tunable since
> it can flood the kernel log buffer.
> 
> Cc: Arjan van de Ven <arjan@xxxxxxxxxxxxxxx>
> Cc: Cong Wang <xiyou.wangcong@xxxxxxxxx>
> Cc: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
> Cc: Valentin Schneider <valentin.schneider@xxxxxxx>
> Cc: Xiaoming Ni <nixiaoming@xxxxxxxxxx>
> Signed-off-by: Guilherme G. Piccoli <gpiccoli@xxxxxxxxxx>
> ---
> 
> We have some design decisions that worth discussing here:
> 
> (a) First of call, using C99 helps a lot to write clear and concise code, but
s/call/all/
> due to commit 4d94f910e79a ("Kbuild: use -Wdeclaration-after-statement") we
> have a warning if mixing variable declarations with code. For this patch 
> though,
> doing that makes the code way clear, so decision was to add the debug code
> inside brackets whenever this warning pops up. We can change that, but that'll
> cause more ifdefs in the same function.
> 
> (b) In the symbol lookup helper function, we modify the parameter passed but
> even more, we return it as well! This is unusual and seems unnecessary, but 
> was
> the strategy taken to allow embedding such function in the pr_debug() call.
> 
> Not doing that would likely requiring 3 symbol_name variables to avoid
> concurrency (registering notifier A while calling notifier B) - we rely in
> local variables as a serialization mechanism.
> 
> We're open for suggestions in case this design is not appropriate;
> thanks in advance!
> 
>  kernel/notifier.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 46 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/notifier.c b/kernel/notifier.c
> index ba005ebf4730..21032ebcde57 100644
> --- a/kernel/notifier.c
> +++ b/kernel/notifier.c
> @@ -7,6 +7,22 @@
>  #include <linux/vmalloc.h>
>  #include <linux/reboot.h>
> 
> +#ifdef CONFIG_DEBUG_NOTIFIERS
> +#include <linux/kallsyms.h>
> +
> +/*
> + *   Helper to get symbol names in case DEBUG_NOTIFIERS is set.
> + *   Return the modified parameter is a strategy used to achieve
> + *   the pr_debug() functionality - with this, function is only
> + *   executed if the dynamic debug tuning is effectively set.
> + */
> +static inline char *notifier_name(struct notifier_block *nb, char *sym_name)
> +{
> +     lookup_symbol_name((unsigned long)(nb->notifier_call), sym_name);
> +     return sym_name;
> +}
> +#endif
> +
>  /*
>   *   Notifier list for kernel code which wants to be called
>   *   at shutdown. This is used to stop any idling DMA operations
> @@ -34,20 +50,41 @@ static int notifier_chain_register(struct notifier_block 
> **nl,
>       }
>       n->next = *nl;
>       rcu_assign_pointer(*nl, n);
> +
> +#ifdef CONFIG_DEBUG_NOTIFIERS
> +     {
> +             char sym_name[KSYM_NAME_LEN];
> +
> +             pr_info("notifiers: registered %s()\n",
> +                     notifier_name(n, sym_name));
> +     }
> +#endif
>       return 0;
>  }
> 
>  static int notifier_chain_unregister(struct notifier_block **nl,
>               struct notifier_block *n)
>  {
> +     int ret = -ENOENT;
> +
>       while ((*nl) != NULL) {
>               if ((*nl) == n) {
>                       rcu_assign_pointer(*nl, n->next);
> -                     return 0;
> +                     ret = 0;
> +                     break;
>               }
>               nl = &((*nl)->next);
>       }
> -     return -ENOENT;
> +
> +#ifdef CONFIG_DEBUG_NOTIFIERS
> +     if (!ret) {
> +             char sym_name[KSYM_NAME_LEN];
> +
> +             pr_info("notifiers: unregistered %s()\n",
> +                     notifier_name(n, sym_name));
> +     }
> +#endif
> +     return ret;
>  }
> 
>  /**
> @@ -80,6 +117,13 @@ static int notifier_call_chain(struct notifier_block **nl,
>                       nb = next_nb;
>                       continue;
>               }
> +
> +             {
> +                     char sym_name[KSYM_NAME_LEN];
> +
> +                     pr_debug("notifiers: calling %s()\n",
> +                              notifier_name(nb, sym_name));
> +             }
>  #endif
>               ret = nb->notifier_call(nb, val, v);
> 
> --
> 2.36.0
 
    
     |