1. 07 Sep, 2022 20 commits
    • Jim Cromie's avatar
      dyndbg: add drm.debug style (drm/parameters/debug) bitmap support · b9400852
      Jim Cromie authored
      Add kernel_param_ops and callbacks to use a class-map to validate and
      apply input to a sysfs-node, which allows users to control classes
      defined in that class-map.  This supports uses like:
      
        echo 0x3 > /sys/module/drm/parameters/debug
      
      IE add these:
      
       - int param_set_dyndbg_classes()
       - int param_get_dyndbg_classes()
       - struct kernel_param_ops param_ops_dyndbg_classes
      
      Following the model of kernel/params.c STANDARD_PARAM_DEFS, these are
      non-static and exported.  This might be unnecessary here.
      
      get/set use an augmented kernel_param; the arg refs a new struct
      ddebug_class_param, which contains:
      
      - A ptr to user's state-store; a union of &ulong for drm.debug, &int
        for nouveau level debug.  By ref'g the client's bit-state _var, code
        coordinates with existing code (like drm_debug_enabled) which uses
        it, so existing/remaining calls can work unchanged.  Changing
        drm.debug to a ulong allows use of BIT() etc.
      
      - FLAGS: dyndbg.flags toggled by changes to bitmap. Usually just "p".
      
      - MAP: a pointer to struct ddebug_classes_map, which maps those
        class-names to .class_ids 0..N that the module is using.  This
        class-map is declared & initialized by DECLARE_DYNDBG_CLASSMAP.
      
      - map-type: 4 enums DD_CLASS_TYPE_* select 2 input forms and 2 meanings.
      
      numeric input:
        DD_CLASS_TYPE_DISJOINT_BITS	integer input, independent bits. ie: drm.debug
        DD_CLASS_TYPE_LEVEL_NUM	integer input, 0..N levels
      
      classnames-list (comma separated) input:
        DD_CLASS_TYPE_DISJOINT_NAMES	each name affects a bit, others preserved
        DD_CLASS_TYPE_LEVEL_NAMES	names have level meanings, like kern_levels.h
      
      _NAMES    - comma-separated classnames (with optional +-)
      _NUM      - numeric input, 0-N expected
      _BITS     - numeric input, 0x1F bitmap form expected
      
      _DISJOINT - bits are independent
      _LEVEL    - (x<y) on bit-pos.
      
      _DISJOINT treats input like a bit-vector (ala drm.debug), and sets
      each bit accordingly.  LEVEL is layered on top of this.
      
      _LEVEL treats input like a bit-pos:N, then sets bits(0..N)=1, and
      bits(N+1..max)=0.  This applies (bit<N) semantics on top of disjoint
      bits.
      
      USAGES:
      
      A potentially typical _DISJOINT_NAMES use:
      
        echo +DRM_UT_CORE,+DRM_UT_KMS,-DRM_UT_DRIVER,-DRM_UT_ATOMIC \
             > /sys/module/drm/parameters/debug_catnames
      
      A naive _LEVEL_NAMES use, with one class, that sets all in the
      class-map according to (x<y):
      
        : problem seen
        echo +L7 > /sys/module/test_dynamic_debug/parameters/p_level_names
        : problem solved
        echo -L1 > /sys/module/test_dynamic_debug/parameters/p_level_names
      
      Note this artifact:
      
        : this is same as prev cmd (due to +/-)
        echo L0 > /sys/module/test_dynamic_debug/parameters/p_level_names
      
        : this is "even-more" off, but same wo __pr_debug_class(L0, "..").
        echo -L0 > /sys/module/test_dynamic_debug/parameters/p_level_names
      
      A stress-test/make-work usage (kid toggling a light switch):
      
        echo +L7,L0,L7,L0,L7,L0,L7,L0,L7,L0,L7,L0,L7 \
             > /sys/module/test_dynamic_debug/parameters/p_level_names
      
      ddebug_apply_class_bitmap(): inside-fn, works on bitmaps, receives
      new-bits, finds diffs vs client-bitvector holding "current" state,
      and issues exec_query to commit the adjustment.
      
      param_set_dyndbg_classes(): interface fn, sends _NAMES to
      param_set_dyndbg_classnames() and returns, falls thru to handle _BITS,
      _NUM internally, and calls ddebug_apply_class_bitmap().  Finishes by
      updating state.
      
      param_set_dyndbg_classnames(): handles classnames-list in loop, calls
      ddebug_apply_class_bitmap for each, then updates state.
      
      NOTES:
      
      _LEVEL_ is overlay on _DISJOINT_; inputs are converted to a bitmask,
      by the callbacks.  IOW this is possible, and possibly confusing:
      
        echo class V3 +p > control
        echo class V1 -p > control
      
      IMO thats ok, relative verbosity is an interface property.
      
      _LEVEL_NUM maps still need class-names, even though the names are not
      usable at the sysfs interface (unlike with _NAMES style).  The names
      are the only way to >control the classes.
      
       - It must have a "V0" name,
         something below "V1" to turn "V1" off.
         __pr_debug_cls(V0,..) is printk, don't do that.
      
       - "class names" is required at the >control interface.
       - relative levels are not enforced at >control
      
      _LEVEL_NAMES bear +/- signs, which alters the on-bit-pos by 1.  IOW,
      +L2 means L0,L1,L2, and -L2 means just L0,L1.  This kinda spoils the
      readback fidelity, since the L0 bit gets turned on by any use of any
      L*, except "-L0".
      
      All the interface uncertainty here pertains to the _NAMES features.
      Nobody has actually asked for this, so its practical (if a little
      tedious) to split it out.
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-21-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b9400852
    • Jim Cromie's avatar
      doc-dyndbg: edit dynamic-debug-howto for brevity, audience · ace7c4bb
      Jim Cromie authored
      Rework/modernize docs:
      
       - use /proc/dynamic_debug/control in examples
         its *always* there (when dyndbg is config'd), even when <debugfs> is not.
         drop <debugfs> talk, its a distraction here.
      
       - alias ddcmd='echo $* > /proc/dynamic_debug/control
         focus on args: declutter, hide boilerplate, make pwd independent.
      
       - swap sections: Viewing before Controlling. control file as Catalog.
      
       - focus on use by a system administrator
         add an alias to make examples more readable
         drop grep-101 lessons, admins know this.
      
       - use init/main.c as 1st example, thread it thru doc where useful.
         everybodys kernel boots, runs these.
      
       - add *prdbg* api section
         to the bottom of the file, its for developers more than admins.
         move list of api functions there.
      
       - simplify - drop extra words, phrases, sentences.
      
       - add "decorator" flags line to unify "prefix", trim fmlt descriptions
      
      CC: linux-doc@vger.kernel.org
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-20-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ace7c4bb
    • Jim Cromie's avatar
      doc-dyndbg: describe "class CLASS_NAME" query support · 753914ed
      Jim Cromie authored
      Add an explanation of the new "class CLASS_NAME" syntax and meaning,
      noting that the module determines if CLASS_NAME applies to it.
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-19-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      753914ed
    • Jim Cromie's avatar
      dyndbg: validate class FOO by checking with module · a4a2a427
      Jim Cromie authored
      Add module-to-class validation:
      
        #> echo class DRM_UT_KMS +p > /proc/dynamic_debug/control
      
      If a query has "class FOO", then ddebug_find_valid_class(), called
      from ddebug_change(), requires that FOO is known to module X,
      otherwize the query is skipped entirely for X.  This protects each
      module's class-space, other than the default:31.
      
      The authors' choice of FOO is highly selective, giving isolation
      and/or coordinated sharing of FOOs.  For example, only DRM modules
      should know and respond to DRM_UT_KMS.
      
      So this, combined with module's opt-in declaration of known classes,
      effectively privatizes the .class_id space for each module (or
      coordinated set of modules).
      
      Notes:
      
      For all "class FOO" queries, ddebug_find_valid_class() is called, it
      returns the map matching the query, and sets valid_class via an
      *outvar).
      
      If no "class FOO" is supplied, valid_class = _CLASS_DFLT.  This
      insures that legacy queries do not trample on new class'd callsites,
      as they get added.
      
      Also add a new column to control-file output, displaying non-default
      class-name (when found) or the "unknown _id:", if it has not been
      (correctly) declared with one of the declarator macros.
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-18-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a4a2a427
    • Jim Cromie's avatar
      dyndbg: add ddebug_attach_module_classes · c45f67ac
      Jim Cromie authored
      Add ddebug_attach_module_classes(), call it from ddebug_add_module().
      It scans the classes/section its given, finds records where the
      module-name matches the module being added, and adds them to the
      module's maps list.  No locking here, since the record
      isn't yet linked into the ddebug_tables list.
      
      It is called indirectly from 2 sources:
      
       - from load_module(), where it scans the module's __dyndbg_classes
         section, which contains DYNAMIC_DEBUG_CLASSES definitions from just
         the module.
      
       - from dynamic_debug_init(), where all DYNAMIC_DEBUG_CLASSES
         definitions of each builtin module have been packed together.
         This is why ddebug_attach_module_classes() checks module-name.
      
      NOTES
      
      Its (highly) likely that builtin classes will be ordered by module
      name (just like prdbg descriptors are in the __dyndbg section).  So
      the list can be replaced by a vector (ptr + length), which will work
      for loaded modules too.  This would imitate whats currently done for
      the _ddebug descriptors.
      
      That said, converting to vector,len is close to pointless; a small
      minority of modules will ever define a class-map, and almost all of
      them will have only 1 or 2 class-maps, so theres only a couple dozen
      pointers to save.  TODO: re-evaluate for lines removable.
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-17-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      c45f67ac
    • Jim Cromie's avatar
      kernel/module: add __dyndbg_classes section · 66f4006b
      Jim Cromie authored
      Add __dyndbg_classes section, using __dyndbg as a model. Use it:
      
      vmlinux.lds.h:
      
      KEEP the new section, which also silences orphan section warning on
      loadable modules.  Add (__start_/__stop_)__dyndbg_classes linker
      symbols for the c externs (below).
      
      kernel/module/main.c:
      - fill new fields in find_module_sections(), using section_objs()
      - extend callchain prototypes
        to pass classes, length
        load_module(): pass new info to dynamic_debug_setup()
        dynamic_debug_setup(): new params, pass through to ddebug_add_module()
      
      dynamic_debug.c:
      - add externs to the linker symbols.
      
      ddebug_add_module():
      - It currently builds a debug_table, and *will* find and attach classes.
      
      dynamic_debug_init():
      - add class fields to the _ddebug_info cursor var: di.
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-16-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      66f4006b
    • Jim Cromie's avatar
      dyndbg: add DECLARE_DYNDBG_CLASSMAP macro · aad0214f
      Jim Cromie authored
      Using DECLARE_DYNDBG_CLASSMAP, modules can declare up to 31 classnames.
      By doing so, they authorize dyndbg to manipulate class'd prdbgs (ie:
      __pr_debug_cls, and soon drm_*dbg), ala::
      
         :#> echo class DRM_UT_KMS +p > /proc/dynamic_debug/control
      
      The macro declares and initializes a static struct ddebug_class_map::
      
       - maps approved class-names to class_ids used in module,
         by array order. forex: DRM_UT_*
       - class-name vals allow validation of "class FOO" queries
         using macro is opt-in
       - enum class_map_type - determines interface, behavior
      
      Each module has its own class-type and class_id space, and only known
      class-names will be authorized for a manipulation.  Only DRM modules
      should know and respont to this:
      
        :#> echo class DRM_UT_CORE +p > control	# across all modules
      
      pr_debugs (with default class_id) are still controllable as before.
      
      DECLARE_DYNDBG_CLASSMAP(_var, _maptype, _base, classes...) is::
      
       _var: name of the static struct var. user passes to module_param_cb()
             if they want a sysfs node.
      
       _maptype: this is hard-coded to DD_CLASS_TYPE_DISJOINT_BITS for now.
      
       _base: usually 0, it allows splitting 31 classes into subranges, so
       	that multiple classes / sysfs-nodes can share the module's
       	class-id space.
      
       classes: list of class_name strings, these are mapped to class-ids
       	  starting at _base.  This class-names list must have a
       	  corresponding ENUM, with SYMBOLS that match the literals,
       	  and 1st enum val = _base.
      
      enum class_map_type has 4 values, on 2 factors::
      
       - classes are disjoint/independent vs relative/x<y/verbosity.
         disjoint is basis, verbosity by overlay.
      
       - input NUMBERS vs [+-]CLASS_NAMES
         uints, ideally hex.  vs  +DRM_UT_CORE,-DRM_UT_KMS
      
      DD_CLASS_TYPE_DISJOINT_BITS: classes are separate, one per bit.
         expecting hex input. built for drm.debug, basis for other types.
      
      DD_CLASS_TYPE_DISJOINT_NAMES: input is a CSV of [+-]CLASS_NAMES,
         classes are independent, like DISJOINT
      
      DD_CLASS_TYPE_LEVEL_NUM: input is numeric level, 0-N.
         0 implies silence. use printk to break that.
         relative levels applied on bitmaps.
      
      DD_CLASS_TYPE_LEVEL_NAMES: input is a CSV of [+-]CLASS_NAMES,
         names like: ERR,WARNING,NOTICE,INFO,DEBUG
         avoiding EMERG,ALERT,CRIT,ERR - no point.
      
      NOTES:
      
      The macro places the initialized struct ddebug_class_map into the
      __dyndbg_classes section.  That draws an 'orphan' warning which we
      handle in the next commit.  The struct attributes are necessary:
      __aligned(8) fixed null-ptr derefs, and __used is needed by drm
      drivers, which declare class-maps, but don't also declare a
      sysfs-param, and thus dont ref the classmap.  The __used insures that
      the linkage is made, then the class-map is found at load-time.
      
      While its possible to handle both NAMES and NUMBERS in the same
      sys-interface, there is ambiguity to avoid, by disallowing them
      together.  Later, if ambiguities are resolved, 2 new enums can permit
      both inputs, on verbose & independent types separately, and authors
      can select the interface style they like.
      
      The plan is to implement LEVELS in the callbacks, outside of
      ddebug_exec_query(), which for simplicity will treat the CLASSES in
      the map as disjoint.  The callbacks can see map-type, and apply ++/--
      loops (or bitops) to force the relative meanings across the
      class-bitmap.
      
      RFC: That leaves 2 issues:
      
      1. doing LEVELs in callbacks means that the native >control interface
      doesn't enforce the LEVELS relationship, so you could confusingly have
      V3 enabled, but V1 disabled.  OTOH, the control iface already allows
      infinite tweaking of the underlying callsites; sysfs node readback can
      only tell the user what they previously wrote.
      
      2. All dyndbg >control reduces to a query/command, includes +/-, which
      is at-root a kernel patching operation with +/- semantics.  And the
      _NAMES handling exposes it to the user, making it API-adjacent.
      
      And its not just >control where +/- gets used (which is settled), the
      new place is with sysfs-nodes exposing _*_NAMES classes, and here its
      subtly different.
      
      _DISJOINT_NAMES: is simple, independent
      _LEVEL_NAMES: masks-on bits 0 .. N-1, N..max off
      
        # turn on L3,L2,L1 others off
        echo +L3 > /sys/module/test_dynamic_debug/parameters/p_level_names
      
        # turn on L2,L1 others off
        echo -L3 > /sys/module/test_dynamic_debug/parameters/p_level_names
      
      IOW, the - changes the threshold-on bitpos by 1.
      
      Alternatively, we could treat the +/- as half-duplex, where -L3 turns
      off L>2 (and ignores L1), and +L2 would turn on L<=2 (and ignore others).
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-15-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      aad0214f
    • Jim Cromie's avatar
      dyndbg: add __pr_debug_cls for testing · 3fc95d80
      Jim Cromie authored
      For selftest purposes, add __pr_debug_cls(class, fmt, ...)
      
      I didn't think we'd need to define this, since DRM effectively has it
      already in drm_dbg, drm_devdbg.  But test_dynamic_debug needs it in
      order to demonstrate all the moving parts.
      
      Note the __ prefix; its not intended for general use, at least until a
      need emerges.  ISTM the drm.debug model (macro wrappers inserting enum
      const 1st arg) is the baseline approach.
      
      That said, nouveau might want it for easy use in its debug macros. TBD.
      
      NB: it does require a builtin-constant class, __pr_debug_cls(i++, ...)
      is disallowed by compiler.
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-14-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3fc95d80
    • Jim Cromie's avatar
      dyndbg: add class_id to pr_debug callsites · ca90fca7
      Jim Cromie authored
      DRM issues ~10 exclusive categories of debug messages; to represent
      this directly in dyndbg, add a new 6-bit field: struct _ddebug.class_id.
      This gives us 64 classes, which should be more than enough.
      
        #> echo 0x012345678 > /sys/module/drm/parameters/debug
      
      All existing callsites are initialized with _DPRINTK_CLASS_DFLT, which
      is 2^6-1.  This reserves 0-62 for use in new categorized/class'd
      pr_debugs, which fits perfectly with natural enums (ints: 0..N).
      
      Thats done by extending the init macro: DEFINE_DYNAMIC_DEBUG_METADATA()
      with _CLS(cls, ...) suffix, and redefing old name using extended name.
      
      Then extend the factory macro callchain with _cls() versions to provide
      the callsite.class_id, with old-names passing _DPRINTK_CLASS_DFLT.
      
      This sets us up to create class'd prdebug callsites (class'd callsites
      are those with .class_id != _DPRINTK_CLASS_DFLT).
      
      No behavior change.
      
      cc: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-13-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ca90fca7
    • Jim Cromie's avatar
      dyndbg: gather __dyndbg[] state into struct _ddebug_info · b7b4eebd
      Jim Cromie authored
      This new struct composes the linker provided (vector,len) section,
      and provides a place to add other __dyndbg[] state-data later:
      
        descs - the vector of descriptors in __dyndbg section.
        num_descs - length of the data/section.
      
      Use it, in several different ways, as follows:
      
      In lib/dynamic_debug.c:
      
      ddebug_add_module(): Alter params-list, replacing 2 args (array,index)
      with a struct _ddebug_info * containing them both, with room for
      expansion.  This helps future-proof the function prototype against the
      looming addition of class-map info into the dyndbg-state, by providing
      a place to add more member fields later.
      
      NB: later add static struct _ddebug_info builtins_state declaration,
      not needed yet.
      
      ddebug_add_module() is called in 2 contexts:
      
      In dynamic_debug_init(), declare, init a struct _ddebug_info di
      auto-var to use as a cursor.  Then iterate over the prdbg blocks of
      the builtin modules, and update the di cursor before calling
      _add_module for each.
      
      Its called from kernel/module/main.c:load_info() for each loaded
      module:
      
      In internal.h, alter struct load_info, replacing the dyndbg array,len
      fields with an embedded _ddebug_info containing them both; and
      populate its members in find_module_sections().
      
      The 2 calling contexts differ in that _init deals with contiguous
      subranges of __dyndbgs[] section, packed together, while loadable
      modules are added one at a time.
      
      So rename ddebug_add_module() into outer/__inner fns, call __inner
      from _init, and provide the offset into the builtin __dyndbgs[] where
      the module's prdbgs reside.  The cursor provides start, len of the
      subrange for each.  The offset will be used later to pack the results
      of builtin __dyndbg_sites[] de-duplication, and is 0 and unneeded for
      loadable modules,
      
      Note:
      
      kernel/module/main.c includes <dynamic_debug.h> for struct
      _ddeubg_info.  This might be prone to include loops, since its also
      included by printk.h.  Nothing has broken in robot-land on this.
      
      cc: Luis Chamberlain <mcgrof@kernel.org>
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-12-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b7b4eebd
    • Jim Cromie's avatar
      dyndbg: cleanup auto vars in dynamic_debug_init · aa86a154
      Jim Cromie authored
      rework var-names for clarity, regularity
      rename variables
        - n to mod_sites - it counts sites-per-module
        - entries to i - display only
        - iter_start to iter_mod_start - marks start of each module's subrange
        - modct to mod_ct - stylistic
      
      new iterator var:
        - site - cursor parallel to iter
          1st step towards 'demotion' of iter->site, for removal later
      
      treat vars as iters:
        - drop init at top
          init just above for-loop, in a textual block
      Acked-by: default avatarJason Baron <jbaron@akamai.com>
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-11-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      aa86a154
    • Jim Cromie's avatar
      dyndbg: drop EXPORTed dynamic_debug_exec_queries · e26ef3af
      Jim Cromie authored
      This exported fn is unused, and will not be needed. Lets dump it.
      
      The export was added to let drm control pr_debugs, as part of using
      them to avoid drm_debug_enabled overheads.  But its better to just
      implement the drm.debug bitmap interface, then its available for
      everyone.
      
      Fixes: a2d375ed ("dyndbg: refine export, rename to dynamic_debug_exec_queries()")
      Fixes: 4c0d7782 ("dyndbg: export ddebug_exec_queries")
      Acked-by: default avatarJason Baron <jbaron@akamai.com>
      Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-10-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e26ef3af
    • Jim Cromie's avatar
      dyndbg: add test_dynamic_debug module · 683263a5
      Jim Cromie authored
      Provide a simple module to allow testing DYNAMIC_DEBUG behavior.  It
      calls do_prints() from module-init, and with a sysfs-node.
      
        dmesg -C
        dmesg -w &
        modprobe test_dynamic_debug dyndbg=+p
        echo 1 > /sys/module/dynamic_debug/parameters/verbose
      
        cat /sys/module/test_dynamic_debug/parameters/do_prints
        echo module test_dynamic_debug +mftl > /proc/dynamic_debug/control
        echo junk > /sys/module/test_dynamic_debug/parameters/do_prints
      Acked-by: default avatarJason Baron <jbaron@akamai.com>
      Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-9-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      683263a5
    • Jim Cromie's avatar
      dyndbg: let query-modname override actual module name · e75ef56f
      Jim Cromie authored
      dyndbg's control-parser: ddebug_parse_query(), requires that search
      terms: module, func, file, lineno, are used only once in a query; a
      thing cannot be named both foo and bar.
      
      The cited commit added an overriding module modname, taken from the
      module loader, which is authoritative.  So it set query.module 1st,
      which disallowed its use in the query-string.
      
      But now, its useful to allow a module-load to enable classes across a
      whole (or part of) a subsystem at once.
      
        # enable (dynamic-debug in) drm only
        modprobe drm dyndbg="class DRM_UT_CORE +p"
      
        # get drm_helper too
        modprobe drm dyndbg="class DRM_UT_CORE module drm* +p"
      
        # get everything that knows DRM_UT_CORE
        modprobe drm dyndbg="class DRM_UT_CORE module * +p"
      
        # also for boot-args:
        drm.dyndbg="class DRM_UT_CORE module * +p"
      
      So convert the override into a default, by filling it only when/after
      the query-string omitted the module.
      
      NB: the query class FOO handling is forthcoming.
      
      Fixes: 8e59b5cf dynamic_debug: add modname arg to exec_query callchain
      Acked-by: default avatarJason Baron <jbaron@akamai.com>
      Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-8-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e75ef56f
    • Jim Cromie's avatar
      dyndbg: use ESCAPE_SPACE for cat control · 47ea6f99
      Jim Cromie authored
      `cat control` currently does octal escape, so '\n' becomes "\012".
      Change this to display as "\n" instead, which reads much cleaner.
      
         :#> head -n7 /proc/dynamic_debug/control
         # filename:lineno [module]function flags format
         init/main.c:1179 [main]initcall_blacklist =_ "blacklisting initcall %s\n"
         init/main.c:1218 [main]initcall_blacklisted =_ "initcall %s blacklisted\n"
         init/main.c:1424 [main]run_init_process =_ "  with arguments:\n"
         init/main.c:1426 [main]run_init_process =_ "    %s\n"
         init/main.c:1427 [main]run_init_process =_ "  with environment:\n"
         init/main.c:1429 [main]run_init_process =_ "    %s\n"
      Acked-by: default avatarJason Baron <jbaron@akamai.com>
      Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-7-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      47ea6f99
    • Jim Cromie's avatar
      dyndbg: reverse module.callsite walk in cat control · 773beabb
      Jim Cromie authored
      Walk the module's vector of callsites backwards; ie N..0.  This
      "corrects" the backwards appearance of a module's prdbg vector when
      walked 0..N.  I think this is due to linker mechanics, which I'm
      inclined to treat as immutable, and the order is fixable in display.
      
      No functional changes.
      
      Combined with previous commit, which reversed tables-list, we get:
      
        :#> head -n7 /proc/dynamic_debug/control
        # filename:lineno [module]function flags format
        init/main.c:1179 [main]initcall_blacklist =_ "blacklisting initcall %s\012"
        init/main.c:1218 [main]initcall_blacklisted =_ "initcall %s blacklisted\012"
        init/main.c:1424 [main]run_init_process =_ "  with arguments:\012"
        init/main.c:1426 [main]run_init_process =_ "    %s\012"
        init/main.c:1427 [main]run_init_process =_ "  with environment:\012"
        init/main.c:1429 [main]run_init_process =_ "    %s\012"
      Acked-by: default avatarJason Baron <jbaron@akamai.com>
      Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-6-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      773beabb
    • Jim Cromie's avatar
      dyndbg: reverse module walk in cat control · 2ad556f7
      Jim Cromie authored
      /proc/dynamic_debug/control walks the prdbg catalog in "reverse",
      fix this by adding new ddebug_tables to tail of list.
      
      This puts init/main.c entries 1st, which looks more than coincidental.
      
      no functional changes.
      Acked-by: default avatarJason Baron <jbaron@akamai.com>
      Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-5-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2ad556f7
    • Jim Cromie's avatar
      dyndbg: show both old and new in change-info · bfa3ca44
      Jim Cromie authored
      print "old => new" flag values to the info("change") message.
      
      no functional change.
      Acked-by: default avatarJason Baron <jbaron@akamai.com>
      Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-4-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bfa3ca44
    • Jim Cromie's avatar
      dyndbg: fix module.dyndbg handling · 85d6b66d
      Jim Cromie authored
      For CONFIG_DYNAMIC_DEBUG=N, the ddebug_dyndbg_module_param_cb()
      stub-fn is too permissive:
      
      bash-5.1# modprobe drm JUNKdyndbg
      bash-5.1# modprobe drm dyndbgJUNK
      [   42.933220] dyndbg param is supported only in CONFIG_DYNAMIC_DEBUG builds
      [   42.937484] ACPI: bus type drm_connector registered
      
      This caused no ill effects, because unknown parameters are either
      ignored by default with an "unknown parameter" warning, or ignored
      because dyndbg allows its no-effect use on non-dyndbg builds.
      
      But since the code has an explicit feedback message, it should be
      issued accurately.  Fix with strcmp for exact param-name match.
      
      Fixes: b48420c1 dynamic_debug: make dynamic-debug work for module initialization
      Reported-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
      Acked-by: default avatarJason Baron <jbaron@akamai.com>
      Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-3-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      85d6b66d
    • Jim Cromie's avatar
      dyndbg: fix static_branch manipulation · ee879be3
      Jim Cromie authored
      In https://lore.kernel.org/lkml/20211209150910.GA23668@axis.com/
      
      Vincent's patch commented on, and worked around, a bug toggling
      static_branch's, when a 2nd PRINTK-ish flag was added.  The bug
      results in a premature static_branch_disable when the 1st of 2 flags
      was disabled.
      
      The cited commit computed newflags, but then in the JUMP_LABEL block,
      failed to use that result, instead using just one of the terms in it.
      Using newflags instead made the code work properly.
      
      This is Vincents test-case, reduced.  It needs the 2nd flag to
      demonstrate the bug, but it's explanatory here.
      
      pt_test() {
          echo 5 > /sys/module/dynamic_debug/verbose
      
          site="module tcp" # just one callsite
          echo " $site =_ " > /proc/dynamic_debug/control # clear it
      
          # A B ~A ~B
          for flg in +T +p "-T #broke here" -p; do
      	echo " $site $flg " > /proc/dynamic_debug/control
          done;
      
          # A B ~B ~A
          for flg in +T +p "-p #broke here" -T; do
      	echo " $site $flg " > /proc/dynamic_debug/control
          done
      }
      pt_test
      
      Fixes: 84da83a6 dyndbg: combine flags & mask into a struct, simplify with it
      CC: vincent.whitchurch@axis.com
      Acked-by: default avatarJason Baron <jbaron@akamai.com>
      Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: default avatarJim Cromie <jim.cromie@gmail.com>
      Link: https://lore.kernel.org/r/20220904214134.408619-2-jim.cromie@gmail.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ee879be3
  2. 01 Sep, 2022 14 commits
  3. 22 Aug, 2022 1 commit
  4. 21 Aug, 2022 5 commits