lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250520082435.2255639-1-tzungbi@kernel.org>
Date: Tue, 20 May 2025 08:24:27 +0000
From: Tzung-Bi Shih <tzungbi@...nel.org>
To: bleung@...omium.org,
	brendan.higgins@...ux.dev,
	davidgow@...gle.com
Cc: tzungbi@...nel.org,
	rmoar@...gle.com,
	rostedt@...dmis.org,
	mhiramat@...nel.org,
	naveen@...nel.org,
	anil.s.keshavamurthy@...el.com,
	davem@...emloft.net,
	chrome-platform@...ts.linux.dev,
	linux-kselftest@...r.kernel.org,
	kunit-dev@...glegroups.com,
	linux-trace-kernel@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [RFC PATCH 0/7] platform/chrome: Add Kunit tests for protocol device drivers

The protocol device drivers under drivers/platform/chrome/ are responsible
to communicate to the ChromeOS EC (Embedded Controller).  They need to pack
the data in a pre-defined format and check if the EC responds accordingly.

The series adds some fundamental unit tests for the protocol.  It calls the
.cmd_xfer() and .pkt_xfer() callbacks (which are the most crucial parts for
the protocol), mocks the rest of the system, and checks if the interactions
are all correct.

The series isn't ready for landing.  It's more like a PoC for the
binary-level function redirection and its use cases.

The 1st patch adds ftrace stub which is originally from [1][2].  There is no
follow-up discussion about the ftrace stub.  As a result, the patch is still
on the mailing list.

The 2nd patch adds Kunit tests for cros_ec_i2c.  It relies on the ftrace stub
for redirecting cros_ec_{un,}register().

The 3rd patch uses static stub instead (if ftrace stub isn't really an option).
However, I'm not a big fan to change the production code (i.e. adding the
prologue in cros_ec_{un,}register()) for testing.

The 4th patch adds Kunit tests for cros_ec_spi.  It relies on the ftrace stub
for redirecting cros_ec_{un,}register() again.

The 5th patch calls .probe() directly instead of forcing the driver probe
needs to be synchronous.  In comparison with the 4th patch, I don't think
this is simpler.  I'd prefer to the way in the 4th patch.

After talked to Masami about the work, he suggested to use Kprobes for
function redirection.  The 6th patch adds kprobes stub.

The 7th patch uses kprobes stub instead for cros_ec_spi.

Questions:
- Are we going to support ftrace stub so that tests can use it?

- If ftrace stub isn't on the plate (e.g. due to too many dependencies), how
  about the kprobes stub?  Is it something we could pursue?

- (minor) I'm unsure if people would prefer 'kprobes stub' vs. 'kprobe stub'.

[1]: https://kunit.dev/mocking.html#binary-level-ftrace-et-al
[2]: https://lore.kernel.org/linux-kselftest/20220318021314.3225240-3-davidgow@google.com/

Daniel Latypov (1):
  kunit: expose ftrace-based API for stubbing out functions during tests

Tzung-Bi Shih (6):
  platform/chrome: kunit: cros_ec_i2c: Add tests with ftrace stub
  platform/chrome: kunit: cros_ec_i2c: Use static stub instead
  platform/chrome: kunit: cros_ec_spi: Add tests with ftrace stub
  platform/chrome: kunit: cros_ec_spi: Call .probe() directly
  kunit: Expose 'kprobes stub' API to redirect functions
  platform/chrome: kunit: cros_ec_spi: Use kprobes stub instead

 drivers/platform/chrome/Kconfig            |  17 +
 drivers/platform/chrome/Makefile           |   2 +
 drivers/platform/chrome/cros_ec.c          |   6 +
 drivers/platform/chrome/cros_ec_i2c_test.c | 479 +++++++++++++++++++++
 drivers/platform/chrome/cros_ec_spi_test.c | 355 +++++++++++++++
 include/kunit/ftrace_stub.h                |  84 ++++
 include/kunit/kprobes_stub.h               |  19 +
 kernel/trace/ftrace.c                      |   3 +
 lib/kunit/Kconfig                          |  18 +
 lib/kunit/Makefile                         |   8 +
 lib/kunit/ftrace_stub.c                    | 139 ++++++
 lib/kunit/kprobes_stub.c                   | 113 +++++
 lib/kunit/kunit-example-test.c             |  27 +-
 lib/kunit/stubs_example.kunitconfig        |  11 +
 14 files changed, 1280 insertions(+), 1 deletion(-)
 create mode 100644 drivers/platform/chrome/cros_ec_i2c_test.c
 create mode 100644 drivers/platform/chrome/cros_ec_spi_test.c
 create mode 100644 include/kunit/ftrace_stub.h
 create mode 100644 include/kunit/kprobes_stub.h
 create mode 100644 lib/kunit/ftrace_stub.c
 create mode 100644 lib/kunit/kprobes_stub.c
 create mode 100644 lib/kunit/stubs_example.kunitconfig

-- 
2.49.0.1101.gccaa498523-goog


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ