All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhang Xiaoxu <zhangxiaoxu@huaweicloud.com>
To: zhangxiaoxu5@huawei.com, weiyongjun1@huawei.com,
	linux-kernel@vger.kernel.org, broonie@kernel.org,
	rostedt@goodmis.org, mingo@redhat.com, frowand.list@gmail.com,
	linux-spi@vger.kernel.org
Subject: [PATCH -next 03/14] kddv/core: Add io fault support to bpf program
Date: Sat, 18 Nov 2023 18:40:29 +0800	[thread overview]
Message-ID: <20231118104040.386381-4-zhangxiaoxu@huaweicloud.com> (raw)
In-Reply-To: <20231118104040.386381-1-zhangxiaoxu@huaweicloud.com>

From: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>

Add common io fault interface, then the bpf program can use
it to mock the hardware io error.

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
---
 tools/testing/kddv/kddv/core/consts.py              |  1 +
 tools/testing/kddv/kddv/core/model.py               |  4 ++++
 .../kddv/kddv/data/bpf/include/bpf-xfer-conf.h      | 13 +++++++++++++
 3 files changed, 18 insertions(+)

diff --git a/tools/testing/kddv/kddv/core/consts.py b/tools/testing/kddv/kddv/core/consts.py
index 22abd7fc655c..b761407f5e88 100755
--- a/tools/testing/kddv/kddv/core/consts.py
+++ b/tools/testing/kddv/kddv/core/consts.py
@@ -10,3 +10,4 @@ CFG_REG_MASK = 0x10
 CFG_REG_RSH = 0x11
 CFG_REG_LSH = 0x12
 CFG_REG_ORD = 0x13
+CFG_IO_FAULT = 0x20
diff --git a/tools/testing/kddv/kddv/core/model.py b/tools/testing/kddv/kddv/core/model.py
index 494b69566536..ff782c20313d 100755
--- a/tools/testing/kddv/kddv/core/model.py
+++ b/tools/testing/kddv/kddv/core/model.py
@@ -8,6 +8,7 @@
 
 from .driver import Driver
 from .mockup import Mockup
+from .consts import CFG_IO_FAULT
 
 class DriverModel(object):
     bus = None
@@ -89,3 +90,6 @@ class DriverModel(object):
 
     def write_regs(self, addr, data):
         self.mockup.write_regs(addr, data)
+
+    def trigger_io_fault(self, count = 1):
+        self.mockup.write_config(CFG_IO_FAULT, count)
diff --git a/tools/testing/kddv/kddv/data/bpf/include/bpf-xfer-conf.h b/tools/testing/kddv/kddv/data/bpf/include/bpf-xfer-conf.h
index 49adbcc6a1af..6a09bd391641 100644
--- a/tools/testing/kddv/kddv/data/bpf/include/bpf-xfer-conf.h
+++ b/tools/testing/kddv/kddv/data/bpf/include/bpf-xfer-conf.h
@@ -18,6 +18,7 @@
 #define BPF_CONF_REG_RSHIFT	0x11
 #define BPF_CONF_REG_LSHIFT	0x12
 #define BPF_CONF_REG_XBSWAP	0x13
+#define BPF_CONF_IO_FAULT	0x20
 
 struct {
 	__uint(type, BPF_MAP_TYPE_ARRAY);
@@ -28,6 +29,7 @@ struct {
 
 static u32 bpf_reg_mask, bpf_reg_xbswap;
 static u32 bpf_reg_rshift, bpf_reg_lshift;
+static u32 bpf_io_fault;
 
 static u32 bpf_xfer_read_conf(u32 key)
 {
@@ -59,6 +61,7 @@ static int bpf_xfer_update_config(void)
 	bpf_reg_rshift = bpf_xfer_read_conf(BPF_CONF_REG_RSHIFT);
 	bpf_reg_lshift = bpf_xfer_read_conf(BPF_CONF_REG_LSHIFT);
 	bpf_reg_xbswap = bpf_xfer_read_conf(BPF_CONF_REG_XBSWAP);
+	bpf_io_fault = bpf_xfer_read_conf(BPF_CONF_IO_FAULT);
 
 	return 0;
 }
@@ -108,4 +111,14 @@ u32 bpf_xfer_reg_u32(u32 reg)
 		reg = reg << bpf_reg_lshift;
 	return reg;
 }
+
+bool bpf_xfer_should_fault(void)
+{
+	bpf_xfer_update_config();
+
+	if (bpf_io_fault)
+		bpf_xfer_write_conf(BPF_CONF_IO_FAULT, bpf_io_fault - 1);
+
+	return !!bpf_io_fault;
+}
 #endif
-- 
2.34.1


  parent reply	other threads:[~2023-11-18 10:41 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-18 10:40 [PATCH -next 00/14] Implement a ligth weight device driver test framework Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 01/14] kddv/core: " Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 02/14] kddv/core: Allow test case config bpf program Zhang Xiaoxu
2023-11-18 10:40 ` Zhang Xiaoxu [this message]
2023-11-18 10:40 ` [PATCH -next 04/14] kddv/core: Check kmsg before return from test case Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 05/14] kddv/core: Support kernel memory leak detector Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 06/14] kddv/core: Add page and slab fault inject support Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 07/14] kddv/cmd: Add command to create/remove mockup device Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 08/14] kddv/cmd: Add command to run testcases Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 09/14] kddv/core: Add test support for SPI driver Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 10/14] kddv/tests: Add support for testing hwmon driver Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 11/14] kddv/tests/hwmon: Add test cases for max31722 driver Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 12/14] kddv/tests: Add support for testing mtd driver Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 13/14] kddv/tests/mtd: Add test cases for mchp23k256 driver Zhang Xiaoxu
2023-11-18 10:40 ` [PATCH -next 14/14] kddv: Add document for kddv Zhang Xiaoxu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231118104040.386381-4-zhangxiaoxu@huaweicloud.com \
    --to=zhangxiaoxu@huaweicloud.com \
    --cc=broonie@kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=weiyongjun1@huawei.com \
    --cc=zhangxiaoxu5@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.