Skip to contentSkip to conversation

nvme: Add NVMe LBA Fault Injection

RFC New Alan Adamson 1 participant 2 messages Dec 21, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover nvme: Add NVMe LBA Fault Injection

It has been requested that the NVMe fault injector be able to inject faults when accessing specific Logical Block Addresses (LBA). This patch is built onto the existing fault injector to provide that ability to specify a LBA when setting up an injection fault.

If the fault injector is enabled, and the nvme driver is ready to send an IO or Admin command to NVMe hardware, the function should_fail() is called to determine if a fault should be injected instead of it being allowed to normally be issued. The should_fail() function uses the fault injector attributes: probability, times, space, and interval to determine if a fault should be injected. If it is determined a fault is to be injected, the request is immediately completed using the attribute: status. If no fault is to be injected, the request is allowed to be issued to the hardware and completed normally.

If a LBA fault is setup, should_fail() is only called if the LBA falls within the range of blocks of a NVMe READ or WRITE command. If it does not fall with the range, should_fail() is not called and no fault would be injected. If the LBA does fall within the range, should_fail() is called to determine if a fault should be injected.

The LBA fault injector could be extended to also check command types (READ/WRITE).

Steps to setup a fault on a LBA access.

1. Setup the attributes: probability, times, and status according to the original NVMe fault injector.

echo 100 > /sys/kernel/debug/nvme0n1/fault_inject/probability echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/times echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/status

2. Specify one or more LBAs: To configure a LBA, set the lba-inject-set attribute to the LBA.

echo 0x22 > /sys/kernel/debug/nvme0n1/fault_inject/lba-inject-set

3. Enable the LBA injector: by setting the lba-inject-enable attribute to on.

echo on > /sys/kernel/debug/nvme0n1/fault_inject/lba-inject-enable

To display the LBAs configured:

cat /sys/kernel/debug/nvme0n1/fault_inject/lba-inject-show LBA Status
22 1

To stop injecting a fault on a LBA:

echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/lba-inject-clear echo 0x22 > /sys/kernel/debug/nvme0n1/fault_inject/lba-inject-set

Alan Adamson (1):
nvme: Add NVMe LBA Fault Injection

 .../fault-injection/nvme-fault-injection.rst  |  28 ++++
 drivers/nvme/host/core.c                      |   4 +-
 drivers/nvme/host/fault_inject.c              | 145 ++++++++++++++++--
 drivers/nvme/host/nvme.h                      |  16 +-
 4 files changed, 178 insertions(+), 15 deletions(-)
Signature · 1 line
2.39.3
#1 lore raw

RFC 1/1 nvme: Add NVMe LBA Fault Injection

Add support for injecting a fault when reading or writing a specific Logical Block Address (LBA).

Steps to setup a fault on a LBA access.

1. Setup the attributes: probability, times, and status according to the original NVMe fault injector.

echo 100 > /sys/kernel/debug/nvme0n1/fault_inject/probability echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/times echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/status

2. Specify one or more LBAs: To configure a LBA, set the lba-inject-set attribute to the LBA.

echo 0x22 > /sys/kernel/debug/nvme0n1/fault_inject/lba-inject-set

3. Enable the LBA injector: by setting the lba-inject-enable attribute to on.

echo on > /sys/kernel/debug/nvme0n1/fault_inject/lba-inject-enable

To display the LBAs configured:

cat /sys/kernel/debug/nvme0n1/fault_inject/lba-inject-show LBA Status
22 1

To stop injecting a fault on a LBA:

echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/lba-inject-clear echo 0x22 > /sys/kernel/debug/nvme0n1/fault_inject/lba-inject-set

---
 .../fault-injection/nvme-fault-injection.rst  |  28 ++++
 drivers/nvme/host/core.c                      |   4 +-
 drivers/nvme/host/fault_inject.c              | 145 ++++++++++++++++--
 drivers/nvme/host/nvme.h                      |  16 +-
 4 files changed, 178 insertions(+), 15 deletions(-)
Documentation/fault-injection/nvme-fault-injection.rst +28 -0
index 1d4427890d75..e17f49886fc4 100644
@@ -176,3 +176,31 @@ Message from dmesg::
    secondary_startup_64+0xa4/0xb0
   nvme nvme0: Could not set queue count (16385)
   nvme nvme0: IO queues not created
+
+Example 4: Inject an error when reading or writing Logical Block Addrss (LBA) 0x22
+----------------------------------------------------------------------------------
+
+::
+
+  echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/times
+  echo 100 > /sys/kernel/debug/nvme0n1/fault_inject/probability
+  echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/status
+  echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/dont_retry
+  echo 0x22 > /sys/kernel/debug/nvme0n1/fault_inject/lba-inject-set
+  cat /sys/kernel/debug/nvme0n1/fault_inject/lba-inject-show
+  LBA	Status
+  21	1
+
+  echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/lba-inject-enable
+  dd if=/dev/nvme0n1 of=/dev/null iflag=direct count=100
+  dd: error reading '/dev/nvme0n1': Operation not supported
+  33+0 records in
+  33+0 records out
+  16896 bytes (17 kB, 16 KiB) copied, 0.00711112 s, 2.4 MB/s
+
+  echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/lba-inject-clear
+  echo 0x22 > /sys/kernel/debug/nvme0n1/fault_inject/lba-inject-set
+  cat /sys/kernel/debug/nvme0n1/fault_inject/lba-inject-show
+  LBA   Status
+
+  echo 0 > /sys/kernel/debug/nvme0n1/fault_inject/lba-inject-enable
drivers/nvme/host/core.c +2 -2
index 8ebdfd623e0f..435ef8b475c0 100644
@@ -3681,7 +3681,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)
 		nvme_add_ns_cdev(ns);
 
 	nvme_mpath_add_disk(ns, info->anagrpid);
-	nvme_fault_inject_init(&ns->fault_inject, ns->disk->disk_name);
+	nvme_fault_inject_init(&ns->fault_inject, ns->disk->disk_name, 1);
 
 	return;
 
@@ -4548,7 +4548,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
 	dev_pm_qos_update_user_latency_tolerance(ctrl->device,
 		min(default_ps_max_latency_us, (unsigned long)S32_MAX));
 
-	nvme_fault_inject_init(&ctrl->fault_inject, dev_name(ctrl->device));
+	nvme_fault_inject_init(&ctrl->fault_inject, dev_name(ctrl->device), 0);
 	nvme_mpath_init_ctrl(ctrl);
 	ret = nvme_auth_init_ctrl(ctrl);
 	if (ret)
drivers/nvme/host/fault_inject.c +134 -11

188 lines not on this page · raw message

drivers/nvme/host/nvme.h +14 -2
index e7411dac00f7..447ce832613c 100644
@@ -16,6 +16,7 @@
 #include <linux/rcupdate.h>
 #include <linux/wait.h>
 #include <linux/t10-pi.h>
+#include <linux/list.h>
 
 #include <trace/events/block.h>
 
@@ -245,7 +246,11 @@ struct nvme_fault_inject {
 	struct fault_attr attr;
 	struct dentry *parent;
 	bool dont_retry;	/* DNR, do not retry */
+	bool lba_clear;
+	bool lba_inject_enable;
 	u16 status;		/* status code */
+	struct mutex		lba_block_lock;
+	struct list_head	lba_list;
 #endif
 };
 
@@ -484,6 +489,13 @@ enum nvme_ns_features {
 	NVME_NS_DEAC,		/* DEAC bit in Write Zeores supported */
 };
 
+typedef struct lba_blk {
+	u64			lba;
+	u16			status;
+	u32			times;
+	struct list_head	node;
+} lba_blk_t;
+
 struct nvme_ns {
 	struct list_head list;
 
@@ -621,12 +633,12 @@ static inline void nvme_print_device_info(struct nvme_ctrl *ctrl)
 
 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
 void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj,
-			    const char *dev_name);
+			    const char *dev_name, bool lba_inject);
 void nvme_fault_inject_fini(struct nvme_fault_inject *fault_inject);
 void nvme_should_fail(struct request *req);
 #else
 static inline void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj,
-					  const char *dev_name)
+					  const char *dev_name, bool lba_inject)
 {
 }
 static inline void nvme_fault_inject_fini(struct nvme_fault_inject *fault_inj)
Signature · 1 line
2.39.3