linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jaehoon Chung <jh80.chung@samsung.com>
To: Vincent Whitchurch <vincent.whitchurch@axis.com>,
	Ulf Hansson <ulf.hansson@linaro.org>
Cc: kernel@axis.com, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] mmc: dw_mmc: Add data CRC error injection
Date: Mon, 26 Jul 2021 06:41:29 +0900	[thread overview]
Message-ID: <06d89a02-708e-c096-5b96-165f1ce8724c@samsung.com> (raw)
In-Reply-To: <20210701080534.23138-1-vincent.whitchurch@axis.com>

On 7/1/21 5:05 PM, Vincent Whitchurch wrote:
> This driver has had problems when handling data errors.  Add fault
> injection support so that the abort handling can be easily triggered and
> regression-tested.  A hrtimer is used to indicate a data CRC error at
> various points during the data transfer.
> 
> Note that for the recent problem with hangs in the case of some data CRC
> errors, a udelay(10) inserted at the start of send_stop_abort() greatly
> helped in triggering the error, but I've not included this as part of
> the fault injection support since it seemed too specific.
> 
> Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>

Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

Best Regards,
Jaehoon Chung

> ---
> 
> Notes:
>     v2: Add missing includes.
> 
>  drivers/mmc/host/dw_mmc.c | 73 +++++++++++++++++++++++++++++++++++++++
>  drivers/mmc/host/dw_mmc.h |  7 ++++
>  2 files changed, 80 insertions(+)
> 
> diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
> index d333130d1531..dbbb94e6ff4b 100644
> --- a/drivers/mmc/host/dw_mmc.c
> +++ b/drivers/mmc/host/dw_mmc.c
> @@ -17,9 +17,11 @@
>  #include <linux/interrupt.h>
>  #include <linux/iopoll.h>
>  #include <linux/ioport.h>
> +#include <linux/ktime.h>
>  #include <linux/module.h>
>  #include <linux/platform_device.h>
>  #include <linux/pm_runtime.h>
> +#include <linux/prandom.h>
>  #include <linux/seq_file.h>
>  #include <linux/slab.h>
>  #include <linux/stat.h>
> @@ -181,6 +183,9 @@ static void dw_mci_init_debugfs(struct dw_mci_slot *slot)
>  			   &host->pending_events);
>  	debugfs_create_xul("completed_events", S_IRUSR, root,
>  			   &host->completed_events);
> +#ifdef CONFIG_FAULT_INJECTION
> +	fault_create_debugfs_attr("fail_data_crc", root, &host->fail_data_crc);
> +#endif
>  }
>  #endif /* defined(CONFIG_DEBUG_FS) */
>  
> @@ -1788,6 +1793,68 @@ static const struct mmc_host_ops dw_mci_ops = {
>  	.prepare_hs400_tuning	= dw_mci_prepare_hs400_tuning,
>  };
>  
> +#ifdef CONFIG_FAULT_INJECTION
> +static enum hrtimer_restart dw_mci_fault_timer(struct hrtimer *t)
> +{
> +	struct dw_mci *host = container_of(t, struct dw_mci, fault_timer);
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&host->irq_lock, flags);
> +
> +	if (!host->data_status)
> +		host->data_status = SDMMC_INT_DCRC;
> +	set_bit(EVENT_DATA_ERROR, &host->pending_events);
> +	tasklet_schedule(&host->tasklet);
> +
> +	spin_unlock_irqrestore(&host->irq_lock, flags);
> +
> +	return HRTIMER_NORESTART;
> +}
> +
> +static void dw_mci_start_fault_timer(struct dw_mci *host)
> +{
> +	struct mmc_data *data = host->data;
> +
> +	if (!data || data->blocks <= 1)
> +		return;
> +
> +	if (!should_fail(&host->fail_data_crc, 1))
> +		return;
> +
> +	/*
> +	 * Try to inject the error at random points during the data transfer.
> +	 */
> +	hrtimer_start(&host->fault_timer,
> +		      ms_to_ktime(prandom_u32() % 25),
> +		      HRTIMER_MODE_REL);
> +}
> +
> +static void dw_mci_stop_fault_timer(struct dw_mci *host)
> +{
> +	hrtimer_cancel(&host->fault_timer);
> +}
> +
> +static void dw_mci_init_fault(struct dw_mci *host)
> +{
> +	host->fail_data_crc = (struct fault_attr) FAULT_ATTR_INITIALIZER;
> +
> +	hrtimer_init(&host->fault_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
> +	host->fault_timer.function = dw_mci_fault_timer;
> +}
> +#else
> +static void dw_mci_init_fault(struct dw_mci *host)
> +{
> +}
> +
> +static void dw_mci_start_fault_timer(struct dw_mci *host)
> +{
> +}
> +
> +static void dw_mci_stop_fault_timer(struct dw_mci *host)
> +{
> +}
> +#endif
> +
>  static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq)
>  	__releases(&host->lock)
>  	__acquires(&host->lock)
> @@ -2102,6 +2169,7 @@ static void dw_mci_tasklet_func(struct tasklet_struct *t)
>  				break;
>  			}
>  
> +			dw_mci_stop_fault_timer(host);
>  			host->data = NULL;
>  			set_bit(EVENT_DATA_COMPLETE, &host->completed_events);
>  			err = dw_mci_data_complete(host, data);
> @@ -2151,6 +2219,7 @@ static void dw_mci_tasklet_func(struct tasklet_struct *t)
>  			if (mrq->cmd->error && mrq->data)
>  				dw_mci_reset(host);
>  
> +			dw_mci_stop_fault_timer(host);
>  			host->cmd = NULL;
>  			host->data = NULL;
>  
> @@ -2600,6 +2669,8 @@ static void dw_mci_cmd_interrupt(struct dw_mci *host, u32 status)
>  
>  	set_bit(EVENT_CMD_COMPLETE, &host->pending_events);
>  	tasklet_schedule(&host->tasklet);
> +
> +	dw_mci_start_fault_timer(host);
>  }
>  
>  static void dw_mci_handle_cd(struct dw_mci *host)
> @@ -3223,6 +3294,8 @@ int dw_mci_probe(struct dw_mci *host)
>  	spin_lock_init(&host->irq_lock);
>  	INIT_LIST_HEAD(&host->queue);
>  
> +	dw_mci_init_fault(host);
> +
>  	/*
>  	 * Get the host data width - this assumes that HCON has been set with
>  	 * the correct values.
> diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
> index da5923a92e60..ce05d81477d9 100644
> --- a/drivers/mmc/host/dw_mmc.h
> +++ b/drivers/mmc/host/dw_mmc.h
> @@ -14,6 +14,8 @@
>  #include <linux/mmc/core.h>
>  #include <linux/dmaengine.h>
>  #include <linux/reset.h>
> +#include <linux/fault-inject.h>
> +#include <linux/hrtimer.h>
>  #include <linux/interrupt.h>
>  
>  enum dw_mci_state {
> @@ -230,6 +232,11 @@ struct dw_mci {
>  	struct timer_list       cmd11_timer;
>  	struct timer_list       cto_timer;
>  	struct timer_list       dto_timer;
> +
> +#ifdef CONFIG_FAULT_INJECTION
> +	struct fault_attr	fail_data_crc;
> +	struct hrtimer		fault_timer;
> +#endif
>  };
>  
>  /* DMA ops for Internal/External DMAC interface */
> 


  reply	other threads:[~2021-07-25 21:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20210701080542epcas1p1ba3235a77ae2ddccc1d1cb40df2e51de@epcas1p1.samsung.com>
2021-07-01  8:05 ` [PATCH v2] mmc: dw_mmc: Add data CRC error injection Vincent Whitchurch
2021-07-25 21:41   ` Jaehoon Chung [this message]
2021-08-04 11:34   ` Ulf Hansson

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=06d89a02-708e-c096-5b96-165f1ce8724c@samsung.com \
    --to=jh80.chung@samsung.com \
    --cc=kernel@axis.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulf.hansson@linaro.org \
    --cc=vincent.whitchurch@axis.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).