From nobody Tue Sep 29 05:34:25 2026 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 631AC42C50B for ; Tue, 11 Aug 2026 23:12:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786489934; cv=none; b=p1gRhXpsExvQ95oF2nlTmiqsAOYR3JzBAx2HeCTK69yOqgwWbMSpU8cAF9Plbk+6x40e2vAyT7H5Rme7VD3j+nbkPZeAc4RjKjQ1WfSPI2akDOPNxQhBzYYBdr2JuJJ4io/KriylhYYshRZ12h+J+M6xIvqNnb5XCNV/oOEvhDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786489934; c=relaxed/simple; bh=24sQbS598Vn7xO7BDgsPkCyI1B3Hft/axRQZOemglvQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=h09dv9MDLdlmj5UKrtyAtQ3Nnccmzjobl6oD5jEKYyjk1PuJZ95MMY6M/Y8DPvDplPqF+MNfxzc3yZRavjD2euv/HWWigTk37I4N52ZWUvt3R0ZPVfepfGmaN55TnvQx7IJuDUkubBrjH+fWJmBfsrdZxEBlyCuFiksZHvY9RQ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=purestorage.com; spf=pass smtp.mailfrom=purestorage.com; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b=e/ejj5p4; arc=none smtp.client-ip=209.85.216.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=purestorage.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=purestorage.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=purestorage.com header.i=@purestorage.com header.b="e/ejj5p4" Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-38e7109321dso340460a91.3 for ; Tue, 11 Aug 2026 16:12:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=purestorage.com; s=google2022; t=1786489932; x=1787094732; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=z4q6VLXN1W/AjdE0Kgnr8TrvBqnlevGmnuePCtTiNGw=; b=e/ejj5p4l0+RRSG0EXNpkFtqKL9aJL0Y3bO9vhFmHje06LhsJxgvQtjn9q1vMXPcc3 C+7UhfvW++hpa8rlbTXpHEl5JUh6zeawu79Ddpr8f0U9hFNKXruVoHPRRnV0v2SXV3k0 3KvCgL+Hkj5/GWoh6UdRwrU7xnvLjFKEm5If2tggKmgkk4qBRi1CsPKYRImnZdDBj91f 9kAkiQkqQ+7Di9+Jv4OkGYn85JLPqWiRNH35oR/IWZ+xW4gEGPIxxxmCyE7ZYrkr9Ws/ Tpd3AYm6NAosFDmEdEs+P0jnhgnCbY8Nd/KCHPitNTFiGXN9Q6+Nezkeo8HO3ML4ePBJ l0Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786489932; x=1787094732; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=z4q6VLXN1W/AjdE0Kgnr8TrvBqnlevGmnuePCtTiNGw=; b=OV+mQUHvRBpQejPG9C2acyAYHWncCQmF3huBbNSC4+MuE54PVpM0Z4SBm15zEgjEKW 1CZbXMWfKqqwgAsyUXgzCVlO8gbiyeXMzuk9FaXc6dSyGaiDnRqDCmNt45t1QA2XR1Fy p9poCIsZBUMh9YGkxnyKShHbCdAi3wSBJ/YOHRWJjvqMPG8DeyRi+0mXZZkr1OvR42w8 CMUc9ppOd9ojGTNEsrLLJX0D6hikG/LjeBu1BaZSslnWtQBehU2dsihSFNTzDM3XCLOg vzeIVxO788QbOCByscbLsnrWHhBiQtx2L24BwkeOYRPRtg1eOrD5Fe4xJ2C0N2+QeH7w ecpQ== X-Forwarded-Encrypted: i=1; AHgh+Rp+CgRm51BLrpUyFi9yBwBtW4my5gtwxJLxnP+ayCAA0lJMEo7OZptY6dC349s718ishw3nnWtEjJcztoE=@vger.kernel.org X-Gm-Message-State: AOJu0YxKu9WN4j5MzN49M5w+xM3KPF3hkgVI4luixr43j/JRJzBa5zq9 taXmE73x/aQgcvysJ8oTTj0C/GQlK4qQOWNTozZ8kQA0d9jZEocGig9XZIsI5sIEh74= X-Gm-Gg: AR+sD10/1F+gLqQLeoithzWQyVDJcAN5HS/b1riNngXg0WmL4/0aB0u4tO/Cfo4Z6ZQ jk4d6+/J8VXlcXmlh39SVt0m8HZ9jsZ4nwFdJdTg0Db3+BvLjduDjAlstgHpNKRiY52rTcXGb7m 0da/a0ARWcsMXTKUwhtNHVi8/MnRYS2kNJXJEUZYu8B+hWCtNo81LpPzX5I5By1U16QnSdQZ1lc aUnrqXowoum7XyMsNhC5fNzHNzYwMzdT9MmU1S7QomlJzL8pqucJrPNgWfzc4oA+KRXtbfT4Pm8 SiyviNXIfwvDaAC3eNnIbJH9mzPvmhBAQHPgOJ8PmGfQOsvl584idiOOxN/i5iFvdOWNc2GUv7o 3BNRDjLhPC5ZUYU2fPd16TAKXl+SbjnCwCsOcREMd8iqbTQp4+xLswJUGGvkvNad+cTjSfvnSlI SLITm5pwKmiafm+XIGmoP0o0nge09Cf3A37/e6cPQXejw5Jg== X-Received: by 2002:a17:90b:4a8f:b0:37f:df85:272f with SMTP id 98e67ed59e1d1-39301621e8fmr543940a91.19.1786489931363; Tue, 11 Aug 2026 16:12:11 -0700 (PDT) Received: from ceto ([2607:fb90:9c20:7a99::791d]) by smtp.googlemail.com with ESMTPSA id 5a478bee46e88-31cf361d292sm5255273eec.3.2026.08.11.16.12.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 16:12:10 -0700 (PDT) From: Mohamed Khalfella To: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Mohamed Khalfella Subject: [PATCH] nvme: add opcode filtering for fault injection Date: Tue, 11 Aug 2026 16:11:52 -0700 Message-ID: <20260811231152.1138761-1-mkhalfella@purestorage.com> X-Mailer: git-send-email 2.54.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently NVMe fault injection applies to every command routed through nvme_should_fail(), which makes it hard to target a specific command type when reproducing an issue in error-handling paths. Add an "opcode" debugfs attribute alongside the existing "status" and "dont_retry" knobs. It defaults to 0xffff, meaning "match any opcode" and preserving the previous behavior. When set to a valid opcode (<=3D 0xff), fault injection is only considered for commands whose opcode matches. Signed-off-by: Mohamed Khalfella Reviewed-by: Christoph Hellwig Reviewed-by: Sagi Grimberg --- .../fault-injection/nvme-fault-injection.rst | 65 +++++++++++++++++++ drivers/nvme/host/fault_inject.c | 14 +++- drivers/nvme/host/nvme.h | 1 + 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/Documentation/fault-injection/nvme-fault-injection.rst b/Docum= entation/fault-injection/nvme-fault-injection.rst index 1d4427890d75..09730acf0163 100644 --- a/Documentation/fault-injection/nvme-fault-injection.rst +++ b/Documentation/fault-injection/nvme-fault-injection.rst @@ -176,3 +176,68 @@ 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 into the first write command +------------------------------------------------------- + +:: + + echo 0x01 > /sys/kernel/debug/nvme0n1/fault_inject/opcode + echo 1 > /sys/kernel/debug/nvme0n1/fault_inject/times + echo 100 > /sys/kernel/debug/nvme0n1/fault_inject/probability + dd if=3D/dev/zero of=3D/dev/nvme0n1 oflag=3Ddirect bs=3D512 count=3D1 + +Expected Result:: + + The first write command sent to nvme0n1 fails + +Message from dmesg:: + + FAULT_INJECTION: forcing a failure. + name fault_inject, interval 1, probability 100, space 0, times 1 + CPU: 4 UID: 0 PID: 0 Comm: swapper/4 Not tainted 7.1.0+ #5 PREEMPT(full) + Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-20240910= _120124-localhost 04/01/2014 + Call Trace: + + dump_stack_lvl+0x6e/0xa0 + dump_stack+0x10/0x16 + should_fail_ex+0x461/0x510 + should_fail+0xb/0x20 + nvme_should_fail+0x11b/0x240 [nvme_core] + nvme_poll_cq+0x6ad/0xb30 [nvme] + nvme_irq+0x84/0xe0 [nvme] + ? __pfx_nvme_irq+0x10/0x10 [nvme] + ? rcu_core+0xa40/0xa90 + ? __pfx_sched_balance_softirq+0x10/0x10 + ? debug_smp_processor_id+0x17/0x20 + ? rcu_is_watching+0x13/0xa0 + __handle_irq_event_percpu+0x396/0x610 + handle_irq_event_percpu+0xf/0x90 + handle_irq_event+0xab/0x110 + handle_edge_irq+0x1a3/0x210 + __common_interrupt+0xff/0x170 + common_interrupt+0x90/0xc0 + + + asm_common_interrupt+0x27/0x40 + RIP: 0010:pv_native_safe_halt+0x13/0x20 + Code: 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 = 90 8b 05 0a 2a 58 01 85 c0 7e 07 0f 00 2d ff cc 0d 00 fb f4 cc 0 + RSP: 0018:ffff888100a67e40 EFLAGS: 00000242 + RAX: 0000000000000001 RBX: ffff888100a49c40 RCX: ffffed102b6c645b + RDX: ffffed102b6c645b RSI: ffffffff82a0d3c0 RDI: ffffffff81428b9b + RBP: ffff888100a67e48 R08: ffffed102b6c645b R09: 0000000000000004 + R10: ffffed102b6c645a R11: 0000000000000001 R12: 0000000000000000 + R13: 0000000000000000 R14: ffffed1020149388 R15: dffffc0000000000 + ? do_idle+0x19b/0x2c0 + ? default_idle+0x9/0x20 + arch_cpu_idle+0x9/0x10 + default_idle_call+0x6b/0xa0 + do_idle+0x19b/0x2c0 + ? __pfx_do_idle+0x10/0x10 + ? complete_with_flags+0x63/0x70 + cpu_startup_entry+0x55/0x60 + start_secondary+0x1df/0x1e0 + common_startup_64+0x13e/0x158 + + nvme0n1: Write(0x1) @ LBA 0, 1 blocks, Invalid Command Opcode (sct 0x0 /= sc 0x1) DNR + operation not supported error, dev nvme0n1, sector 0 op 0x1:(WRITE) flag= s 0x8800 phys_seg 1 prio class 2 diff --git a/drivers/nvme/host/fault_inject.c b/drivers/nvme/host/fault_inj= ect.c index 105d6cb41c72..783e1999fef4 100644 --- a/drivers/nvme/host/fault_inject.c +++ b/drivers/nvme/host/fault_inject.c @@ -42,9 +42,11 @@ void nvme_fault_inject_init(struct nvme_fault_inject *fa= ult_inj, } fault_inj->parent =3D parent; =20 - /* create debugfs for status code and dont_retry */ + /* create debugfs for opcode, status code, and dont_retry */ + fault_inj->opcode =3D 0xffff; fault_inj->status =3D NVME_SC_INVALID_OPCODE; fault_inj->dont_retry =3D true; + debugfs_create_x16("opcode", 0600, dir, &fault_inj->opcode); debugfs_create_x16("status", 0600, dir, &fault_inj->status); debugfs_create_bool("dont_retry", 0600, dir, &fault_inj->dont_retry); } @@ -59,6 +61,7 @@ void nvme_should_fail(struct request *req) { struct gendisk *disk =3D req->q->disk; struct nvme_fault_inject *fault_inject =3D NULL; + struct nvme_command *cmd =3D nvme_req(req)->cmd; u16 status; =20 if (disk) { @@ -72,7 +75,14 @@ void nvme_should_fail(struct request *req) fault_inject =3D &nvme_req(req)->ctrl->fault_inject; } =20 - if (fault_inject && should_fail(&fault_inject->attr, 1)) { + if (!fault_inject) + return; + + if (fault_inject->opcode <=3D 0xff && + fault_inject->opcode !=3D cmd->common.opcode) + return; + + if (should_fail(&fault_inject->attr, 1)) { /* inject status code and DNR bit */ status =3D fault_inject->status; if (fault_inject->dont_retry) diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 28cec87e4427..9a0fb1e35a5d 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -323,6 +323,7 @@ struct nvme_fault_inject { #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS struct fault_attr attr; struct dentry *parent; + u16 opcode; bool dont_retry; /* DNR, do not retry */ u16 status; /* status code */ #endif --=20 2.54.0