diff mbox series

[v3,-next,2/5] spi: mockup: Add writeable tracepoint for spi transfer

Message ID 20231104064650.972687-3-zhangxiaoxu@huaweicloud.com (mailing list archive)
State New, archived
Headers show
Series spi: Introduce BPF based SPI mockup controller | expand

Commit Message

huaweicloud Nov. 4, 2023, 6:46 a.m. UTC
From: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>

Add writeable tracepoint for transfer_one_message(), then bpf program
can be used to control read and write data from spi host, as mockup
chip's expectation.

For example:

  #include "vmlinux.h"
  #include <bpf/bpf_helpers.h>
  #include <bpf/bpf_tracing.h>

  SEC("raw_tp.w/spi_transfer_writeable")
  int BPF_PROG(spi_transfer_writeable_test, struct spi_msg_ctx *msg,
               u8 chip, unsigned int len)
  {
      if (msg->tx_nbits)
          msg->data[0] = 0x20;

      return 0;
  }

  char LICENSE[] SEC("license") = "GPL";

This will be useful for writing spi device mockup backend.

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
---
 drivers/spi/Kconfig               |  1 +
 drivers/spi/spi-mockup.c          | 52 +++++++++++++++++++++++++++++--
 include/linux/spi/spi-mockup.h    | 17 ++++++++++
 include/trace/events/spi_mockup.h | 31 ++++++++++++++++++
 4 files changed, 99 insertions(+), 2 deletions(-)
 create mode 100644 include/linux/spi/spi-mockup.h
 create mode 100644 include/trace/events/spi_mockup.h

Comments

kernel test robot Nov. 4, 2023, 9:58 a.m. UTC | #1
Hi Zhang,

kernel test robot noticed the following build warnings:

[auto build test WARNING on next-20231103]

url:    https://github.com/intel-lab-lkp/linux/commits/Zhang-Xiaoxu/spi-mockup-Add-SPI-controller-testing-driver/20231104-144859
base:   next-20231103
patch link:    https://lore.kernel.org/r/20231104064650.972687-3-zhangxiaoxu%40huaweicloud.com
patch subject: [PATCH v3 -next 2/5] spi: mockup: Add writeable tracepoint for spi transfer
config: m68k-allyesconfig (https://download.01.org/0day-ci/archive/20231104/202311041721.m13CvbG0-lkp@intel.com/config)
compiler: m68k-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231104/202311041721.m13CvbG0-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311041721.m13CvbG0-lkp@intel.com/

All warnings (new ones prefixed by >>):

    2221 |                 rcu_assign_pointer(event->tp_event->prog_array, new_array);
         |                                         ^~
   include/asm-generic/rwonce.h:55:27: note: in definition of macro '__WRITE_ONCE'
      55 |         *(volatile typeof(x) *)&(x) = (val);                            \
         |                           ^
   include/asm-generic/barrier.h:198:9: note: in expansion of macro 'WRITE_ONCE'
     198 |         WRITE_ONCE(*p, v);                                              \
         |         ^~~~~~~~~~
   include/linux/rcupdate.h:500:17: note: in expansion of macro 'smp_store_release'
     500 |                 smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
         |                 ^~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2221:17: note: in expansion of macro 'rcu_assign_pointer'
    2221 |                 rcu_assign_pointer(event->tp_event->prog_array, new_array);
         |                 ^~~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2221:41: error: 'struct perf_event' has no member named 'tp_event'
    2221 |                 rcu_assign_pointer(event->tp_event->prog_array, new_array);
         |                                         ^~
   include/asm-generic/rwonce.h:55:34: note: in definition of macro '__WRITE_ONCE'
      55 |         *(volatile typeof(x) *)&(x) = (val);                            \
         |                                  ^
   include/asm-generic/barrier.h:198:9: note: in expansion of macro 'WRITE_ONCE'
     198 |         WRITE_ONCE(*p, v);                                              \
         |         ^~~~~~~~~~
   include/linux/rcupdate.h:500:17: note: in expansion of macro 'smp_store_release'
     500 |                 smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
         |                 ^~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2221:17: note: in expansion of macro 'rcu_assign_pointer'
    2221 |                 rcu_assign_pointer(event->tp_event->prog_array, new_array);
         |                 ^~~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2221:41: error: 'struct perf_event' has no member named 'tp_event'
    2221 |                 rcu_assign_pointer(event->tp_event->prog_array, new_array);
         |                                         ^~
   include/asm-generic/rwonce.h:55:40: note: in definition of macro '__WRITE_ONCE'
      55 |         *(volatile typeof(x) *)&(x) = (val);                            \
         |                                        ^~~
   include/asm-generic/barrier.h:198:9: note: in expansion of macro 'WRITE_ONCE'
     198 |         WRITE_ONCE(*p, v);                                              \
         |         ^~~~~~~~~~
   include/linux/rcupdate.h:500:17: note: in expansion of macro 'smp_store_release'
     500 |                 smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
         |                 ^~~~~~~~~~~~~~~~~
   include/linux/rcupdate.h:500:39: note: in expansion of macro 'RCU_INITIALIZER'
     500 |                 smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
         |                                       ^~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2221:17: note: in expansion of macro 'rcu_assign_pointer'
    2221 |                 rcu_assign_pointer(event->tp_event->prog_array, new_array);
         |                 ^~~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2221:41: error: 'struct perf_event' has no member named 'tp_event'
    2221 |                 rcu_assign_pointer(event->tp_event->prog_array, new_array);
         |                                         ^~
   include/asm-generic/rwonce.h:55:40: note: in definition of macro '__WRITE_ONCE'
      55 |         *(volatile typeof(x) *)&(x) = (val);                            \
         |                                        ^~~
   include/asm-generic/barrier.h:198:9: note: in expansion of macro 'WRITE_ONCE'
     198 |         WRITE_ONCE(*p, v);                                              \
         |         ^~~~~~~~~~
   include/linux/rcupdate.h:500:17: note: in expansion of macro 'smp_store_release'
     500 |                 smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
         |                 ^~~~~~~~~~~~~~~~~
   include/linux/rcupdate.h:500:39: note: in expansion of macro 'RCU_INITIALIZER'
     500 |                 smp_store_release(&p, RCU_INITIALIZER((typeof(p))_r_a_p__v)); \
         |                                       ^~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2221:17: note: in expansion of macro 'rcu_assign_pointer'
    2221 |                 rcu_assign_pointer(event->tp_event->prog_array, new_array);
         |                 ^~~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2225:27: error: 'struct perf_event' has no member named 'prog'
    2225 |         bpf_prog_put(event->prog);
         |                           ^~
   kernel/trace/bpf_trace.c:2226:14: error: 'struct perf_event' has no member named 'prog'
    2226 |         event->prog = NULL;
         |              ^~
   kernel/trace/bpf_trace.c: In function 'perf_event_query_prog_array':
   kernel/trace/bpf_trace.c:2242:18: error: 'struct perf_event' has no member named 'attr'
    2242 |         if (event->attr.type != PERF_TYPE_TRACEPOINT)
         |                  ^~
   kernel/trace/bpf_trace.c:2261:48: error: 'struct perf_event' has no member named 'tp_event'
    2261 |         progs = bpf_event_rcu_dereference(event->tp_event->prog_array);
         |                                                ^~
   include/linux/rcupdate.h:445:19: note: in definition of macro '__rcu_dereference_protected'
     445 |         ((typeof(*p) __force __kernel *)(p)); \
         |                   ^
   kernel/trace/bpf_trace.c:42:9: note: in expansion of macro 'rcu_dereference_protected'
      42 |         rcu_dereference_protected(p, lockdep_is_held(&bpf_event_mutex))
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2261:17: note: in expansion of macro 'bpf_event_rcu_dereference'
    2261 |         progs = bpf_event_rcu_dereference(event->tp_event->prog_array);
         |                 ^~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2261:48: error: 'struct perf_event' has no member named 'tp_event'
    2261 |         progs = bpf_event_rcu_dereference(event->tp_event->prog_array);
         |                                                ^~
   include/linux/rcupdate.h:445:42: note: in definition of macro '__rcu_dereference_protected'
     445 |         ((typeof(*p) __force __kernel *)(p)); \
         |                                          ^
   kernel/trace/bpf_trace.c:42:9: note: in expansion of macro 'rcu_dereference_protected'
      42 |         rcu_dereference_protected(p, lockdep_is_held(&bpf_event_mutex))
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2261:17: note: in expansion of macro 'bpf_event_rcu_dereference'
    2261 |         progs = bpf_event_rcu_dereference(event->tp_event->prog_array);
         |                 ^~~~~~~~~~~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c: At top level:
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run1' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2345:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2345 | BPF_TRACE_DEFN_x(1);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run2' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2346:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2346 | BPF_TRACE_DEFN_x(2);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run3' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2347:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2347 | BPF_TRACE_DEFN_x(3);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run4' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2348:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2348 | BPF_TRACE_DEFN_x(4);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run5' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2349:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2349 | BPF_TRACE_DEFN_x(5);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run6' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2350:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2350 | BPF_TRACE_DEFN_x(6);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run7' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2351:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2351 | BPF_TRACE_DEFN_x(7);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run8' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2352:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2352 | BPF_TRACE_DEFN_x(8);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run9' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2353:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2353 | BPF_TRACE_DEFN_x(9);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run10' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2354:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2354 | BPF_TRACE_DEFN_x(10);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run11' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2355:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2355 | BPF_TRACE_DEFN_x(11);
         | ^~~~~~~~~~~~~~~~
>> kernel/trace/bpf_trace.c:2337:14: warning: no previous prototype for 'bpf_trace_run12' [-Wmissing-prototypes]
    2337 |         void bpf_trace_run##x(struct bpf_prog *prog,                    \
         |              ^~~~~~~~~~~~~
   kernel/trace/bpf_trace.c:2356:1: note: in expansion of macro 'BPF_TRACE_DEFN_x'
    2356 | BPF_TRACE_DEFN_x(12);
         | ^~~~~~~~~~~~~~~~
   kernel/trace/bpf_trace.c: In function 'bpf_get_perf_event_info':
   kernel/trace/bpf_trace.c:2395:21: error: 'const struct perf_event' has no member named 'prog'
    2395 |         prog = event->prog;
         |                     ^~
   kernel/trace/bpf_trace.c:2404:22: error: 'const struct perf_event' has no member named 'tp_event'
    2404 |         flags = event->tp_event->flags;
         |                      ^~
   kernel/trace/bpf_trace.c:2406:53: error: 'const struct perf_event' has no member named 'tp_event'
    2406 |         is_syscall_tp = is_syscall_trace_event(event->tp_event);
         |                                                     ^~
   kernel/trace/bpf_trace.c:2409:45: error: 'const struct perf_event' has no member named 'tp_event'
    2409 |                 *buf = is_tracepoint ? event->tp_event->tp->name
         |                                             ^~
   kernel/trace/bpf_trace.c:2410:45: error: 'const struct perf_event' has no member named 'tp_event'
    2410 |                                      : event->tp_event->name;
         |                                             ^~
   kernel/trace/bpf_trace.c: In function '____bpf_get_attach_cookie_pe':
>> kernel/trace/bpf_trace.c:1155:1: warning: control reaches end of non-void function [-Wreturn-type]
    1155 | }
         | ^
   cc1: some warnings being treated as errors

Kconfig warnings: (for reference only)
   WARNING: unmet direct dependencies detected for BPF_EVENTS
   Depends on [n]: FTRACE [=n] && BPF_SYSCALL [=y] && (KPROBE_EVENTS [=n] || UPROBE_EVENTS [=n]) && PERF_EVENTS [=n]
   Selected by [y]:
   - SPI_MOCKUP [=y] && SPI [=y] && SPI_MASTER [=y] && OF [=y]


vim +/bpf_trace_run1 +2337 kernel/trace/bpf_trace.c

c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2335  
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2336  #define BPF_TRACE_DEFN_x(x)						\
c4f6699dfcb855 Alexei Starovoitov 2018-03-28 @2337  	void bpf_trace_run##x(struct bpf_prog *prog,			\
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2338  			      REPEAT(x, SARG, __DL_COM, __SEQ_0_11))	\
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2339  	{								\
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2340  		u64 args[x];						\
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2341  		REPEAT(x, COPY, __DL_SEM, __SEQ_0_11);			\
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2342  		__bpf_trace_run(prog, args);				\
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2343  	}								\
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2344  	EXPORT_SYMBOL_GPL(bpf_trace_run##x)
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2345  BPF_TRACE_DEFN_x(1);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2346  BPF_TRACE_DEFN_x(2);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2347  BPF_TRACE_DEFN_x(3);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2348  BPF_TRACE_DEFN_x(4);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2349  BPF_TRACE_DEFN_x(5);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2350  BPF_TRACE_DEFN_x(6);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2351  BPF_TRACE_DEFN_x(7);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2352  BPF_TRACE_DEFN_x(8);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2353  BPF_TRACE_DEFN_x(9);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2354  BPF_TRACE_DEFN_x(10);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2355  BPF_TRACE_DEFN_x(11);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2356  BPF_TRACE_DEFN_x(12);
c4f6699dfcb855 Alexei Starovoitov 2018-03-28  2357
kernel test robot Nov. 4, 2023, 11:10 a.m. UTC | #2
Hi Zhang,

kernel test robot noticed the following build warnings:

[auto build test WARNING on next-20231103]

url:    https://github.com/intel-lab-lkp/linux/commits/Zhang-Xiaoxu/spi-mockup-Add-SPI-controller-testing-driver/20231104-144859
base:   next-20231103
patch link:    https://lore.kernel.org/r/20231104064650.972687-3-zhangxiaoxu%40huaweicloud.com
patch subject: [PATCH v3 -next 2/5] spi: mockup: Add writeable tracepoint for spi transfer
config: mips-allyesconfig (https://download.01.org/0day-ci/archive/20231104/202311041825.n8iCJiNe-lkp@intel.com/config)
compiler: mips-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231104/202311041825.n8iCJiNe-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311041825.n8iCJiNe-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from include/trace/trace_events.h:27,
                    from include/trace/define_trace.h:102,
                    from include/trace/events/spi_mockup.h:31,
                    from drivers/spi/spi-mockup.c:17:
>> include/trace/stages/init.h:2:23: warning: 'str__spi_mockup__trace_system_name' defined but not used [-Wunused-const-variable=]
       2 | #define __app__(x, y) str__##x##y
         |                       ^~~~~
   include/trace/stages/init.h:3:21: note: in expansion of macro '__app__'
       3 | #define __app(x, y) __app__(x, y)
         |                     ^~~~~~~
   include/trace/stages/init.h:5:29: note: in expansion of macro '__app'
       5 | #define TRACE_SYSTEM_STRING __app(TRACE_SYSTEM_VAR,__trace_system_name)
         |                             ^~~~~
   include/trace/stages/init.h:8:27: note: in expansion of macro 'TRACE_SYSTEM_STRING'
       8 |         static const char TRACE_SYSTEM_STRING[] =       \
         |                           ^~~~~~~~~~~~~~~~~~~
   include/trace/stages/init.h:11:1: note: in expansion of macro 'TRACE_MAKE_SYSTEM_STR'
      11 | TRACE_MAKE_SYSTEM_STR();
         | ^~~~~~~~~~~~~~~~~~~~~


vim +/str__spi_mockup__trace_system_name +2 include/trace/stages/init.h

af6b9668e85ffd Steven Rostedt (Google  2022-03-03 @2) #define __app__(x, y) str__##x##y
af6b9668e85ffd Steven Rostedt (Google  2022-03-03  3) #define __app(x, y) __app__(x, y)
af6b9668e85ffd Steven Rostedt (Google  2022-03-03  4)
diff mbox series

Patch

diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 9169081cfecb..871e3824b8eb 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -1221,6 +1221,7 @@  config SPI_TLE62X0
 config SPI_MOCKUP
 	tristate "SPI controller Testing Driver"
 	depends on OF
+	select BPF_EVENTS
 	help
 	  This enables SPI controller testing driver, which provides a way to
 	  test SPI subsystem.
diff --git a/drivers/spi/spi-mockup.c b/drivers/spi/spi-mockup.c
index 683a0fc43f0d..fcaaa61bdb38 100644
--- a/drivers/spi/spi-mockup.c
+++ b/drivers/spi/spi-mockup.c
@@ -13,6 +13,9 @@ 
 #include <linux/platform_device.h>
 #include <linux/spi/spi.h>
 
+#define CREATE_TRACE_POINTS
+#include <trace/events/spi_mockup.h>
+
 #define MOCKUP_CHIPSELECT_MAX		8
 
 struct mockup_spi {
@@ -149,13 +152,58 @@  static struct attribute *spi_mockup_attrs[] = {
 };
 ATTRIBUTE_GROUPS(spi_mockup);
 
+static int spi_mockup_transfer_writeable(struct spi_message *msg)
+{
+	struct spi_msg_ctx *ctx;
+	struct spi_transfer *t;
+	int ret = 0;
+
+	ctx = kmalloc(sizeof(*ctx), GFP_ATOMIC);
+	if (!ctx)
+		return -ENOMEM;
+
+	list_for_each_entry(t, &msg->transfers, transfer_list) {
+		if (t->len > SPI_BUFSIZ_MAX)
+			return -E2BIG;
+
+		memset(ctx, 0, sizeof(*ctx));
+		ctx->cs_off = t->cs_off;
+		ctx->cs_change = t->cs_change;
+		ctx->tx_nbits = t->tx_nbits;
+		ctx->rx_nbits = t->rx_nbits;
+
+		if (t->tx_nbits)
+			memcpy(ctx->data, t->tx_buf, t->len);
+
+		trace_spi_transfer_writeable(ctx, msg->spi->chip_select, t->len);
+
+		if (ctx->ret) {
+			ret = ctx->ret;
+			break;
+		}
+
+		if (t->rx_nbits)
+			memcpy(t->rx_buf, ctx->data, t->len);
+		msg->actual_length += t->len;
+	}
+
+	kfree(ctx);
+
+	return ret;
+}
+
 static int spi_mockup_transfer(struct spi_controller *ctrl,
 			       struct spi_message *msg)
 {
-	msg->status = 0;
+	int ret = 0;
+
+	if (trace_spi_transfer_writeable_enabled())
+		ret = spi_mockup_transfer_writeable(msg);
+
+	msg->status = ret;
 	spi_finalize_current_message(ctrl);
 
-	return 0;
+	return ret;
 }
 
 static int spi_mockup_probe(struct platform_device *pdev)
diff --git a/include/linux/spi/spi-mockup.h b/include/linux/spi/spi-mockup.h
new file mode 100644
index 000000000000..224894b416fb
--- /dev/null
+++ b/include/linux/spi/spi-mockup.h
@@ -0,0 +1,17 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __LINUX_SPI_MOCKUP_H
+#define __LINUX_SPI_MOCKUP_H
+
+#define SPI_BUFSIZ_MAX		0x1000
+
+struct spi_msg_ctx {
+	int ret;
+	unsigned cs_off:1;
+	unsigned cs_change:1;
+	unsigned tx_nbits:3;
+	unsigned rx_nbits:3;
+	__u8 data[SPI_BUFSIZ_MAX];
+};
+
+#endif
diff --git a/include/trace/events/spi_mockup.h b/include/trace/events/spi_mockup.h
new file mode 100644
index 000000000000..46debf26a5e3
--- /dev/null
+++ b/include/trace/events/spi_mockup.h
@@ -0,0 +1,31 @@ 
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * SPI mockup controller transfer writeable tracepoint
+ *
+ * Copyright(c) 2022 Huawei Technologies Co., Ltd.
+ */
+
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM spi_mockup
+
+#if !defined(_TRACE_SPI_MOCKUP_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_SPI_MOCKUP_H
+
+#include <linux/tracepoint.h>
+#include <linux/spi/spi-mockup.h>
+
+#ifndef DECLARE_TRACE_WRITABLE
+#define DECLARE_TRACE_WRITABLE(call, proto, args, size) \
+	DECLARE_TRACE(call, PARAMS(proto), PARAMS(args))
+#endif
+
+DECLARE_TRACE_WRITABLE(spi_transfer_writeable,
+	TP_PROTO(struct spi_msg_ctx *msg, u8 chip_select, unsigned int len),
+	TP_ARGS(msg, chip_select, len),
+	sizeof(struct spi_msg_ctx)
+);
+
+#endif /* _TRACE_SPI_MOCKUP_H */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>