[RFC 0/1] nvme: Add NVMe LBA Fault Injection

Alan Adamson alan.adamson at oracle.com
Thu Dec 21 15:10:42 PST 2023


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(-)

-- 
2.39.3




More information about the Linux-nvme mailing list