None of the calls to trace_array_printk_buf() will do anything
if we don't initialize the buffer on instance creation (unless
some other tracer called it), so do that.

Add an osnoise_print() macro to facilitate adding debug prints (without
tainting).

Use trace_array_printk() instead of trace_array_printk_buf(), as we're
only writing to the main buffer (of a non-main instance) anyway -- and
trace_array_printk_buf() skips the check to make sure we're not printing
to the global instance.

Signed-off-by: Crystal Wood <[email protected]>
---
Technically this isn't needed to make the tests pass, but it was helpful
in debugging the issues and would be nice to have around for next time.

What's the intended use case for trace_array_printk_buf()?  It seems like
it should be an internal function if it's not going to check the
instance.  I don't see any non-internal uses other than here and in
trace_hwlat.c, which also only prints to the main buffer.
---
 kernel/trace/trace_osnoise.c | 39 ++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 15 deletions(-)

diff --git a/kernel/trace/trace_osnoise.c b/kernel/trace/trace_osnoise.c
index bb4d195ec74f..b53a698f8e81 100644
--- a/kernel/trace/trace_osnoise.c
+++ b/kernel/trace/trace_osnoise.c
@@ -81,6 +81,22 @@ struct osnoise_instance {
 
 static struct list_head osnoise_instances;
 
+static void osnoise_print(const char *fmt, ...)
+{
+       struct osnoise_instance *inst;
+       struct trace_array *tr;
+       va_list ap;
+
+       rcu_read_lock();
+       list_for_each_entry_rcu(inst, &osnoise_instances, list) {
+               tr = inst->tr;
+               va_start(ap, fmt);
+               trace_array_vprintk(tr, _RET_IP_, fmt, ap);
+               va_end(ap);
+       }
+       rcu_read_unlock();
+}
+
 static bool osnoise_has_registered_instances(void)
 {
        return !!list_first_or_null_rcu(&osnoise_instances,
@@ -121,6 +137,7 @@ static int osnoise_register_instance(struct trace_array *tr)
         * trace_types_lock.
         */
        lockdep_assert_held(&trace_types_lock);
+       trace_array_init_printk(tr);
 
        inst = kmalloc(sizeof(*inst), GFP_KERNEL);
        if (!inst)
@@ -455,15 +472,7 @@ static void print_osnoise_headers(struct seq_file *s)
  * osnoise_taint - report an osnoise error.
  */
 #define osnoise_taint(msg) ({                                                  
\
-       struct osnoise_instance *inst;                                          
\
-       struct trace_buffer *buffer;                                            
\
-                                                                               
\
-       rcu_read_lock();                                                        
\
-       list_for_each_entry_rcu(inst, &osnoise_instances, list) {               
\
-               buffer = inst->tr->array_buffer.buffer;                         
\
-               trace_array_printk_buf(buffer, _THIS_IP_, msg);                 
\
-       }                                                                       
\
-       rcu_read_unlock();                                                      
\
+       osnoise_print(msg);                                                     
\
        osnoise_data.tainted = true;                                            
\
 })
 
@@ -1173,10 +1182,10 @@ static __always_inline void osnoise_stop_exception(char 
*msg, int cpu)
        rcu_read_lock();
        list_for_each_entry_rcu(inst, &osnoise_instances, list) {
                tr = inst->tr;
-               trace_array_printk_buf(tr->array_buffer.buffer, _THIS_IP_,
-                                      "stop tracing hit on cpu %d due to 
exception: %s\n",
-                                      smp_processor_id(),
-                                      msg);
+               trace_array_printk(tr, _THIS_IP_,
+                                  "stop tracing hit on cpu %d due to 
exception: %s\n",
+                                  smp_processor_id(),
+                                  msg);
 
                if (test_bit(OSN_PANIC_ON_STOP, &osnoise_options))
                        panic("tracer hit on cpu %d due to exception: %s\n",
@@ -1346,8 +1355,8 @@ static __always_inline void osnoise_stop_tracing(void)
        rcu_read_lock();
        list_for_each_entry_rcu(inst, &osnoise_instances, list) {
                tr = inst->tr;
-               trace_array_printk_buf(tr->array_buffer.buffer, _THIS_IP_,
-                               "stop tracing hit on cpu %d\n", 
smp_processor_id());
+               trace_array_printk(tr, _THIS_IP_,
+                                  "stop tracing hit on cpu %d\n", 
smp_processor_id());
 
                if (test_bit(OSN_PANIC_ON_STOP, &osnoise_options))
                        panic("tracer hit stop condition on CPU %d\n", 
smp_processor_id());
-- 
2.48.1


Reply via email to