All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: "Martin K . Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org, Jaegeuk Kim <jaegeuk@kernel.org>,
	Bart Van Assche <bvanassche@acm.org>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	Eric Biggers <ebiggers@google.com>,
	Alim Akhtar <alim.akhtar@samsung.com>,
	Peter Wang <peter.wang@mediatek.com>,
	Avri Altman <avri.altman@wdc.com>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Bean Huo <beanhuo@micron.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Can Guo <cang@codeaurora.org>,
	Stanley Chu <stanley.chu@mediatek.com>,
	Asutosh Das <asutoshd@codeaurora.org>
Subject: [PATCH v3 18/18] scsi: ufs: Add fault injection support
Date: Wed, 21 Jul 2021 20:34:39 -0700	[thread overview]
Message-ID: <20210722033439.26550-19-bvanassche@acm.org> (raw)
In-Reply-To: <20210722033439.26550-1-bvanassche@acm.org>

Make it easier to test the UFS error handler and abort handler.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/scsi/ufs/Kconfig               |  7 +++
 drivers/scsi/ufs/Makefile              |  1 +
 drivers/scsi/ufs/ufs-fault-injection.c | 70 ++++++++++++++++++++++++++
 drivers/scsi/ufs/ufs-fault-injection.h | 24 +++++++++
 drivers/scsi/ufs/ufshcd.c              |  8 +++
 5 files changed, 110 insertions(+)
 create mode 100644 drivers/scsi/ufs/ufs-fault-injection.c
 create mode 100644 drivers/scsi/ufs/ufs-fault-injection.h

diff --git a/drivers/scsi/ufs/Kconfig b/drivers/scsi/ufs/Kconfig
index 2d137953e7b4..4272d7365595 100644
--- a/drivers/scsi/ufs/Kconfig
+++ b/drivers/scsi/ufs/Kconfig
@@ -183,3 +183,10 @@ config SCSI_UFS_CRYPTO
 	  Enabling this makes it possible for the kernel to use the crypto
 	  capabilities of the UFS device (if present) to perform crypto
 	  operations on data being transferred to/from the device.
+
+config SCSI_UFS_FAULT_INJECTION
+       bool "UFS Fault Injection Support"
+       depends on SCSI_UFSHCD && FAULT_INJECTION
+       help
+         Enable fault injection support in the UFS driver. This makes it easier
+	 to test the UFS error handler and abort handler.
diff --git a/drivers/scsi/ufs/Makefile b/drivers/scsi/ufs/Makefile
index 06f3a3fe4a44..006d50236079 100644
--- a/drivers/scsi/ufs/Makefile
+++ b/drivers/scsi/ufs/Makefile
@@ -8,6 +8,7 @@ ufshcd-core-y				+= ufshcd.o ufs-sysfs.o
 ufshcd-core-$(CONFIG_DEBUG_FS)		+= ufs-debugfs.o
 ufshcd-core-$(CONFIG_SCSI_UFS_BSG)	+= ufs_bsg.o
 ufshcd-core-$(CONFIG_SCSI_UFS_CRYPTO)	+= ufshcd-crypto.o
+ufshcd-core-$(CONFIG_SCSI_UFS_FAULT_INJECTION) += ufs-fault-injection.o
 
 obj-$(CONFIG_SCSI_UFS_DWC_TC_PCI) += tc-dwc-g210-pci.o ufshcd-dwc.o tc-dwc-g210.o
 obj-$(CONFIG_SCSI_UFS_DWC_TC_PLATFORM) += tc-dwc-g210-pltfrm.o ufshcd-dwc.o tc-dwc-g210.o
diff --git a/drivers/scsi/ufs/ufs-fault-injection.c b/drivers/scsi/ufs/ufs-fault-injection.c
new file mode 100644
index 000000000000..7ac7c4e7ff83
--- /dev/null
+++ b/drivers/scsi/ufs/ufs-fault-injection.c
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <linux/kconfig.h>
+#include <linux/types.h>
+#include <linux/fault-inject.h>
+#include <linux/module.h>
+#include "ufs-fault-injection.h"
+
+static int ufs_fault_get(char *buffer, const struct kernel_param *kp);
+static int ufs_fault_set(const char *val, const struct kernel_param *kp);
+
+static const struct kernel_param_ops ufs_fault_ops = {
+	.get = ufs_fault_get,
+	.set = ufs_fault_set,
+};
+
+enum { FAULT_INJ_STR_SIZE = 80 };
+
+/*
+ * For more details about fault injection, please refer to
+ * Documentation/fault-injection/fault-injection.rst.
+ */
+static char g_trigger_eh_str[FAULT_INJ_STR_SIZE];
+module_param_cb(trigger_eh, &ufs_fault_ops, g_trigger_eh_str, 0644);
+MODULE_PARM_DESC(trigger_eh,
+	"Fault injection. trigger_eh=<interval>,<probability>,<space>,<times>");
+static DECLARE_FAULT_ATTR(ufs_trigger_eh_attr);
+
+static char g_timeout_str[FAULT_INJ_STR_SIZE];
+module_param_cb(timeout, &ufs_fault_ops, g_timeout_str, 0644);
+MODULE_PARM_DESC(timeout,
+	"Fault injection. timeout=<interval>,<probability>,<space>,<times>");
+static DECLARE_FAULT_ATTR(ufs_timeout_attr);
+
+static int ufs_fault_get(char *buffer, const struct kernel_param *kp)
+{
+	const char *fault_str = kp->arg;
+
+	return sysfs_emit(buffer, "%s\n", fault_str);
+}
+
+static int ufs_fault_set(const char *val, const struct kernel_param *kp)
+{
+	struct fault_attr *attr = NULL;
+
+	if (kp->arg == g_trigger_eh_str)
+		attr = &ufs_trigger_eh_attr;
+	else if (kp->arg == g_timeout_str)
+		attr = &ufs_timeout_attr;
+
+	if (WARN_ON_ONCE(!attr))
+		return -EINVAL;
+
+	if (!setup_fault_attr(attr, (char *)val))
+		return -EINVAL;
+
+	strlcpy(kp->arg, val, FAULT_INJ_STR_SIZE);
+
+	return 0;
+}
+
+bool ufs_trigger_eh(void)
+{
+	return should_fail(&ufs_trigger_eh_attr, 1);
+}
+
+bool ufs_fail_completion(void)
+{
+	return should_fail(&ufs_timeout_attr, 1);
+}
diff --git a/drivers/scsi/ufs/ufs-fault-injection.h b/drivers/scsi/ufs/ufs-fault-injection.h
new file mode 100644
index 000000000000..6d0cd8e10c87
--- /dev/null
+++ b/drivers/scsi/ufs/ufs-fault-injection.h
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef _UFS_FAULT_INJECTION_H
+#define _UFS_FAULT_INJECTION_H
+
+#include <linux/kconfig.h>
+#include <linux/types.h>
+
+#ifdef CONFIG_SCSI_UFS_FAULT_INJECTION
+bool ufs_trigger_eh(void);
+bool ufs_fail_completion(void);
+#else
+static inline bool ufs_trigger_eh(void)
+{
+	return false;
+}
+
+static inline bool ufs_fail_completion(void)
+{
+	return false;
+}
+#endif
+
+#endif /* _UFS_FAULT_INJECTION_H */
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 3cfbc467f7c0..e6ceab4563ba 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -24,6 +24,7 @@
 #include "unipro.h"
 #include "ufs-sysfs.h"
 #include "ufs-debugfs.h"
+#include "ufs-fault-injection.h"
 #include "ufs_bsg.h"
 #include "ufshcd-crypto.h"
 #include <asm/unaligned.h>
@@ -2750,6 +2751,10 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
 	ufshcd_send_command(hba, tag);
 out:
 	up_read(&hba->clk_scaling_lock);
+
+	if (ufs_trigger_eh())
+		scsi_schedule_eh(hba->host);
+
 	return err;
 }
 
@@ -5278,6 +5283,9 @@ static irqreturn_t ufshcd_transfer_req_compl(struct ufs_hba *hba,
 	    !(hba->quirks & UFSHCI_QUIRK_SKIP_RESET_INTR_AGGR))
 		ufshcd_reset_intr_aggr(hba);
 
+	if (ufs_fail_completion())
+		return IRQ_HANDLED;
+
 	spin_lock_irqsave(&hba->outstanding_lock, flags);
 	tr_doorbell = ufshcd_readl(hba, REG_UTP_TRANSFER_REQ_DOOR_BELL);
 	completed_reqs = ~tr_doorbell & hba->outstanding_reqs;

  parent reply	other threads:[~2021-07-22  3:36 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-22  3:34 [PATCH v3 00/18] UFS patches for kernel v5.15 Bart Van Assche
2021-07-22  3:34 ` [PATCH v3 01/18] scsi: ufs: Fix memory corruption by ufshcd_read_desc_param() Bart Van Assche
2021-07-25 12:40   ` Avri Altman
2021-07-22  3:34 ` [PATCH v3 02/18] scsi: ufs: Reduce power management code duplication Bart Van Assche
2021-07-31 14:44   ` Stanley Chu
2021-07-22  3:34 ` [PATCH v3 03/18] scsi: ufs: Only include power management code if necessary Bart Van Assche
2021-07-22  3:34 ` [PATCH v3 04/18] scsi: ufs: Rename the second ufshcd_probe_hba() argument Bart Van Assche
2021-08-02  8:17   ` Stanley Chu
2021-07-22  3:34 ` [PATCH v3 05/18] scsi: ufs: Use DECLARE_COMPLETION_ONSTACK() where appropriate Bart Van Assche
2021-07-22  3:34 ` [PATCH v3 06/18] scsi: ufs: Remove ufshcd_valid_tag() Bart Van Assche
2021-07-22  3:34 ` [PATCH v3 07/18] scsi: ufs: Verify UIC locking requirements at runtime Bart Van Assche
2021-07-22  3:34 ` [PATCH v3 08/18] scsi: ufs: Improve static type checking for the host controller state Bart Van Assche
2021-07-22  3:34 ` [PATCH v3 09/18] scsi: ufs: Remove several wmb() calls Bart Van Assche
2021-07-25 13:20   ` Avri Altman
2021-07-22  3:34 ` [PATCH v3 10/18] scsi: ufs: Inline ufshcd_outstanding_req_clear() Bart Van Assche
2021-07-29  7:42   ` Bean Huo
2021-07-22  3:34 ` [PATCH v3 11/18] scsi: ufs: Revert "Utilize Transfer Request List Completion Notification Register" Bart Van Assche
2021-07-29  8:03   ` Bean Huo
2021-07-29 16:10     ` Bart Van Assche
2021-07-29 16:13       ` Bart Van Assche
2021-07-29 21:14         ` Bean Huo
2021-08-02 15:24   ` Bean Huo
2021-08-03 18:49     ` Bart Van Assche
2021-07-22  3:34 ` [PATCH v3 12/18] scsi: ufs: Optimize serialization of setup_xfer_req() calls Bart Van Assche
2021-07-29  8:07   ` Bean Huo
2021-07-22  3:34 ` [PATCH v3 13/18] scsi: ufs: Optimize SCSI command processing Bart Van Assche
2021-07-29  9:12   ` Bean Huo
2021-07-29 16:11     ` Bart Van Assche
2021-08-02 12:11   ` Bean Huo
2021-07-22  3:34 ` [PATCH v3 14/18] scsi: ufs: Fix the SCSI abort handler Bart Van Assche
2021-08-02 13:15   ` Bean Huo
2021-07-22  3:34 ` [PATCH v3 15/18] scsi: ufs: Request sense data asynchronously Bart Van Assche
2021-08-02 13:16   ` Bean Huo
2021-07-22  3:34 ` [PATCH v3 16/18] scsi: ufs: Synchronize SCSI and UFS error handling Bart Van Assche
2021-08-02 14:24   ` Bean Huo
2021-08-28  9:47   ` Adrian Hunter
2021-08-29  7:17     ` Avri Altman
2021-08-29 21:33       ` Bart Van Assche
2021-08-29  9:57     ` Adrian Hunter
2021-08-29 22:18     ` Bart Van Assche
2021-08-31  7:24       ` Adrian Hunter
2021-08-31 10:04         ` Adrian Hunter
2021-08-31 17:18         ` Bart Van Assche
2021-09-01  7:42           ` Adrian Hunter
2021-09-01 20:46             ` Bart Van Assche
2021-09-02  6:02               ` Adrian Hunter
2021-07-22  3:34 ` [PATCH v3 17/18] scsi: ufs: Retry aborted SCSI commands instead of completing these successfully Bart Van Assche
2021-08-02 15:03   ` Bean Huo
2021-07-22  3:34 ` Bart Van Assche [this message]
2021-08-02 15:03   ` [PATCH v3 18/18] scsi: ufs: Add fault injection support Bean Huo
     [not found] ` <CGME20210722033524epcas2p31e41c1db6883aaa644edf23bbe8a1ca2@epcms2p4>
2021-07-28  6:48   ` [PATCH v3 06/18] scsi: ufs: Remove ufshcd_valid_tag() Daejun Park
2021-07-28 22:48     ` Bart Van Assche
     [not found]     ` <CGME20210722033524epcas2p31e41c1db6883aaa644edf23bbe8a1ca2@epcms2p7>
2021-07-29  0:26       ` Daejun Park
     [not found] ` <CGME20210722033530epcas2p4c76293e5fc5163fed3995acdd02678ce@epcms2p1>
2021-07-28  7:56   ` [PATCH v3 08/18] scsi: ufs: Improve static type checking for the host controller state Keoseong Park
     [not found] ` <CGME20210722033504epcas2p1cc3c6f61e81814004c36b89c7c9e3dd5@epcms2p5>
2021-07-29  0:56   ` [PATCH v3 01/18] scsi: ufs: Fix memory corruption by ufshcd_read_desc_param() Daejun Park
     [not found] ` <CGME20210722033510epcas2p410be4f2f387e98babeefc754a9fc1414@epcms2p2>
2021-07-29  0:56   ` [PATCH v3 02/18] scsi: ufs: Reduce power management code duplication Daejun Park
     [not found] ` <CGME20210722033513epcas2p22e4c2e6ea644992ede2739ebe381d53f@epcms2p8>
2021-07-29  0:56   ` [PATCH v3 03/18] scsi: ufs: Only include power management code if necessary Daejun Park
2021-07-31 14:48     ` Stanley Chu
     [not found] ` <CGME20210722033520epcas2p31c6f801eda7f100491c85e3f9c7d6600@epcms2p6>
2021-07-29  0:56   ` [PATCH v3 04/18] scsi: ufs: Rename the second ufshcd_probe_hba() argument Daejun Park
     [not found] ` <CGME20210722033523epcas2p22ea9a4afaeb46870638ff4429010a3c1@epcms2p7>
2021-07-29  0:57   ` [PATCH v3 05/18] scsi: ufs: Use DECLARE_COMPLETION_ONSTACK() where appropriate Daejun Park
     [not found] ` <CGME20210722033527epcas2p384eefb77dff85f5d8d59beede98b6bdc@epcms2p4>
2021-07-29  0:57   ` [PATCH v3 07/18] scsi: ufs: Verify UIC locking requirements at runtime Daejun Park
     [not found] ` <CGME20210722033531epcas2p4a4a975689ad7966d3db56dd81a7a255f@epcms2p1>
2021-07-29  0:57   ` [PATCH v3 08/18] scsi: ufs: Improve static type checking for the host controller state Daejun Park
     [not found] ` <CGME20210722033536epcas2p133eef1f5e2e5a1022ccef23e9c1035aa@epcms2p5>
2021-07-29  1:24   ` [PATCH v3 09/18] scsi: ufs: Remove several wmb() calls Daejun Park
     [not found] ` <CGME20210722033552epcas2p39f68ea806091ffa9755a25b778d70101@epcms2p2>
2021-07-29  1:25   ` [PATCH v3 12/18] scsi: ufs: Optimize serialization of setup_xfer_req() calls Daejun Park
     [not found] ` <CGME20210722033553epcas2p2818d9c1f046e8514415a72a4ddddc3db@epcms2p1>
2021-07-29  1:25   ` [PATCH v3 13/18] scsi: ufs: Optimize SCSI command processing Daejun Park
2021-08-03  2:13 ` [PATCH v3 00/18] UFS patches for kernel v5.15 Martin K. Petersen
2021-08-10  5:20 ` Martin K. Petersen

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=20210722033439.26550-19-bvanassche@acm.org \
    --to=bvanassche@acm.org \
    --cc=adrian.hunter@intel.com \
    --cc=alim.akhtar@samsung.com \
    --cc=asutoshd@codeaurora.org \
    --cc=avri.altman@wdc.com \
    --cc=beanhuo@micron.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=cang@codeaurora.org \
    --cc=ebiggers@google.com \
    --cc=jaegeuk@kernel.org \
    --cc=jejb@linux.ibm.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=peter.wang@mediatek.com \
    --cc=rdunlap@infradead.org \
    --cc=stanley.chu@mediatek.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.