diff mbox series

[v11,01/19] dyndbg: add _DPRINTK_FLAGS_ENABLED

Message ID 20220107052942.1349447-2-jim.cromie@gmail.com (mailing list archive)
State New, archived
Headers show
Series dyndbg & drm.debug to tracefs | expand

Commit Message

Jim Cromie Jan. 7, 2022, 5:29 a.m. UTC
Distinguish the condition: _DPRINTK_FLAGS_ENABLED from the bit:
_DPRINTK_FLAGS_PRINT, in preparation to add _DPRINTK_FLAGS_TRACE next.
Also add a 'K' to get _DPRINTK_FLAGS_PRINTK, to insure is not used
elsewhere with a stale meaning.

CC: vincent.whitchurch@axis.com
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 include/linux/dynamic_debug.h | 10 ++++++----
 lib/dynamic_debug.c           |  8 ++++----
 2 files changed, 10 insertions(+), 8 deletions(-)

Comments

Vincent Whitchurch Jan. 14, 2022, 11:57 a.m. UTC | #1
On Fri, Jan 07, 2022 at 06:29:24AM +0100, Jim Cromie wrote:
>  #ifdef CONFIG_JUMP_LABEL
> -			if (dp->flags & _DPRINTK_FLAGS_PRINT) {
> -				if (!(modifiers->flags & _DPRINTK_FLAGS_PRINT))
> +			if (dp->flags & _DPRINTK_FLAGS_ENABLED) {
> +				if (!(modifiers->flags & _DPRINTK_FLAGS_ENABLED))
>  					static_branch_disable(&dp->key.dd_key_true);
> -			} else if (modifiers->flags & _DPRINTK_FLAGS_PRINT)
> +			} else if (modifiers->flags & _DPRINTK_FLAGS_ENABLED)
>  				static_branch_enable(&dp->key.dd_key_true);
>  #endif
>  			dp->flags = newflags;
> -- 
> 2.33.1
> 

I haven't tested it so I could be mistaken, but when
_DPRINTK_FLAGS_ENABLED gets two flags in the next patch, it looks like
this code still has the problem which I mentioned in
https://lore.kernel.org/lkml/20211209150910.GA23668@axis.com/?

| I noticed a bug inside the CONFIG_JUMP_LABEL handling (also present
| in the last version I posted) which should be fixed as part of the
| diff below (I've added a comment).
| [...] 
|  #ifdef CONFIG_JUMP_LABEL
| -			if (dp->flags & _DPRINTK_FLAGS_PRINT) {
| -				if (!(modifiers->flags & _DPRINTK_FLAGS_PRINT))
| +			if (dp->flags & _DPRINTK_FLAGS_ENABLE) {
| +				/*
| +				 * The newflags check is to ensure that the
| +				 * static branch doesn't get disabled in step
| +				 * 3:
| +				 *
| +				 * (1) +pf
| +				 * (2) +x
| +				 * (3) -pf
| +				 */
| +				if (!(modifiers->flags & _DPRINTK_FLAGS_ENABLE) &&
| +				    !(newflags & _DPRINTK_FLAGS_ENABLE)) {
|  					static_branch_disable(&dp->key.dd_key_true);
| -			} else if (modifiers->flags & _DPRINTK_FLAGS_PRINT)
| +				}
| +			} else if (modifiers->flags & _DPRINTK_FLAGS_ENABLE) {
|  				static_branch_enable(&dp->key.dd_key_true);
| +			}
|  #endif
Jim Cromie Jan. 17, 2022, 10:33 p.m. UTC | #2
On Fri, Jan 14, 2022 at 4:57 AM Vincent Whitchurch
<vincent.whitchurch@axis.com> wrote:
>
> On Fri, Jan 07, 2022 at 06:29:24AM +0100, Jim Cromie wrote:
> >  #ifdef CONFIG_JUMP_LABEL
> > -                     if (dp->flags & _DPRINTK_FLAGS_PRINT) {
> > -                             if (!(modifiers->flags & _DPRINTK_FLAGS_PRINT))
> > +                     if (dp->flags & _DPRINTK_FLAGS_ENABLED) {
> > +                             if (!(modifiers->flags & _DPRINTK_FLAGS_ENABLED))
> >                                       static_branch_disable(&dp->key.dd_key_true);
> > -                     } else if (modifiers->flags & _DPRINTK_FLAGS_PRINT)
> > +                     } else if (modifiers->flags & _DPRINTK_FLAGS_ENABLED)
> >                               static_branch_enable(&dp->key.dd_key_true);
> >  #endif
> >                       dp->flags = newflags;
> > --
> > 2.33.1
> >
>
> I haven't tested it so I could be mistaken, but when
> _DPRINTK_FLAGS_ENABLED gets two flags in the next patch, it looks like
> this code still has the problem which I mentioned in
> https://lore.kernel.org/lkml/20211209150910.GA23668@axis.com/?
>

Yes, thanks for noticing.  I missed that detail.
Apriori, I dont know why bit-and of bit-or'd flags doesnt cover it,
but I will take a careful look.

> | I noticed a bug inside the CONFIG_JUMP_LABEL handling (also present
> | in the last version I posted) which should be fixed as part of the
> | diff below (I've added a comment).
> | [...]
> |  #ifdef CONFIG_JUMP_LABEL
> | -                     if (dp->flags & _DPRINTK_FLAGS_PRINT) {
> | -                             if (!(modifiers->flags & _DPRINTK_FLAGS_PRINT))
> | +                     if (dp->flags & _DPRINTK_FLAGS_ENABLE) {
> | +                             /*
> | +                              * The newflags check is to ensure that the
> | +                              * static branch doesn't get disabled in step
> | +                              * 3:
> | +                              *
> | +                              * (1) +pf
> | +                              * (2) +x
> | +                              * (3) -pf
> | +                              */
> | +                             if (!(modifiers->flags & _DPRINTK_FLAGS_ENABLE) &&
> | +                                 !(newflags & _DPRINTK_FLAGS_ENABLE)) {
> |                                       static_branch_disable(&dp->key.dd_key_true);
> | -                     } else if (modifiers->flags & _DPRINTK_FLAGS_PRINT)
> | +                             }
> | +                     } else if (modifiers->flags & _DPRINTK_FLAGS_ENABLE) {
> |                               static_branch_enable(&dp->key.dd_key_true);
> | +                     }
> |  #endif
diff mbox series

Patch

diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index dce631e678dd..257a7bcbbe36 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -27,7 +27,7 @@  struct _ddebug {
 	 * writes commands to <debugfs>/dynamic_debug/control
 	 */
 #define _DPRINTK_FLAGS_NONE	0
-#define _DPRINTK_FLAGS_PRINT	(1<<0) /* printk() a message using the format */
+#define _DPRINTK_FLAGS_PRINTK	(1<<0) /* printk() a message using the format */
 #define _DPRINTK_FLAGS_INCL_MODNAME	(1<<1)
 #define _DPRINTK_FLAGS_INCL_FUNCNAME	(1<<2)
 #define _DPRINTK_FLAGS_INCL_LINENO	(1<<3)
@@ -37,8 +37,10 @@  struct _ddebug {
 	(_DPRINTK_FLAGS_INCL_MODNAME | _DPRINTK_FLAGS_INCL_FUNCNAME |\
 	 _DPRINTK_FLAGS_INCL_LINENO  | _DPRINTK_FLAGS_INCL_TID)
 
+#define _DPRINTK_FLAGS_ENABLED		_DPRINTK_FLAGS_PRINTK
+
 #if defined DEBUG
-#define _DPRINTK_FLAGS_DEFAULT _DPRINTK_FLAGS_PRINT
+#define _DPRINTK_FLAGS_DEFAULT _DPRINTK_FLAGS_PRINTK
 #else
 #define _DPRINTK_FLAGS_DEFAULT 0
 #endif
@@ -120,10 +122,10 @@  void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
 
 #ifdef DEBUG
 #define DYNAMIC_DEBUG_BRANCH(descriptor) \
-	likely(descriptor.flags & _DPRINTK_FLAGS_PRINT)
+	likely(descriptor.flags & _DPRINTK_FLAGS_ENABLED)
 #else
 #define DYNAMIC_DEBUG_BRANCH(descriptor) \
-	unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)
+	unlikely(descriptor.flags & _DPRINTK_FLAGS_ENABLED)
 #endif
 
 #endif /* CONFIG_JUMP_LABEL */
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index dd7f56af9aed..78a2912976c1 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -86,7 +86,7 @@  static inline const char *trim_prefix(const char *path)
 }
 
 static struct { unsigned flag:8; char opt_char; } opt_array[] = {
-	{ _DPRINTK_FLAGS_PRINT, 'p' },
+	{ _DPRINTK_FLAGS_PRINTK, 'p' },
 	{ _DPRINTK_FLAGS_INCL_MODNAME, 'm' },
 	{ _DPRINTK_FLAGS_INCL_FUNCNAME, 'f' },
 	{ _DPRINTK_FLAGS_INCL_LINENO, 'l' },
@@ -210,10 +210,10 @@  static int ddebug_change(const struct ddebug_query *query,
 			if (newflags == dp->flags)
 				continue;
 #ifdef CONFIG_JUMP_LABEL
-			if (dp->flags & _DPRINTK_FLAGS_PRINT) {
-				if (!(modifiers->flags & _DPRINTK_FLAGS_PRINT))
+			if (dp->flags & _DPRINTK_FLAGS_ENABLED) {
+				if (!(modifiers->flags & _DPRINTK_FLAGS_ENABLED))
 					static_branch_disable(&dp->key.dd_key_true);
-			} else if (modifiers->flags & _DPRINTK_FLAGS_PRINT)
+			} else if (modifiers->flags & _DPRINTK_FLAGS_ENABLED)
 				static_branch_enable(&dp->key.dd_key_true);
 #endif
 			dp->flags = newflags;