mmc: dw_mmc: Add data CRC error injection
Subsystems (2)
PATCH 1/1 mmc: dw_mmc: Add data CRC error injection
This driver has issues when handling data CRC errors. Add fault injection support so that the handling can be easily triggered and regression-tested. A hrtimer is used to indicate a data CRC errors 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.
--- drivers/mmc/host/dw_mmc.c | 71 +++++++++++++++++++++++++++++++++++++++ drivers/mmc/host/dw_mmc.h | 5 +++ 2 files changed, 76 insertions(+)
drivers/mmc/host/dw_mmc.c +71 -0
@@ -181,6 +181,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 +1791,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 +2167,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 +2217,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 +2667,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 +3292,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.
drivers/mmc/host/dw_mmc.h +5 -0
@@ -230,6 +230,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 */
Signature · 1 line
2.28.0
kernel test robot
build botThank you for the patch! Yet something to improve:
Hi Vincent,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.13 next-20210630]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Vincent-Whitchurch/mmc-dw_mmc-Add-data-CRC-error-injection/20210630-182344 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 007b350a58754a93ca9fe50c498cc27780171153 config: arm-buildonly-randconfig-r005-20210630 (attached as .config) compiler: arm-linux-gnueabi-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/c77ecd0f5373a88c7f00191136827f5bc42f3948
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Vincent-Whitchurch/mmc-dw_mmc-Add-data-CRC-error-injection/20210630-182344 git checkout c77ecd0f5373a88c7f00191136827f5bc42f3948
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/mmc/host/dw_mmc.c: In function 'dw_mci_start_fault_timer':
>> drivers/mmc/host/dw_mmc.c:1826:21: error: implicit declaration of function 'prandom_u32' [-Werror=implicit-function-declaration]
1826 | ms_to_ktime(prandom_u32() % 25),
| ^~~~~~~~~~~cc1: some warnings being treated as errors
vim +/prandom_u32 +1826 drivers/mmc/host/dw_mmc.c
1811
1812 static void dw_mci_start_fault_timer(struct dw_mci *host)
1813 {
1814 struct mmc_data *data = host->data;
1815
1816 if (!data || data->blocks <= 1)
1817 return;
1818
1819 if (!should_fail(&host->fail_data_crc, 1))
1820 return;
1821
1822 /*
1823 * Try to inject the error at random points during the data transfer.
1824 */
1825 hrtimer_start(&host->fault_timer,
> 1826 ms_to_ktime(prandom_u32() % 25),
1827 HRTIMER_MODE_REL);
1828 }
1829
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org