2020-08-22 06:20:41

by Madhuparna Bhowmik

[permalink] [raw]
Subject: [PATCH v2] drivers: mmc: host: via-sdmmc: Fix data race bug

From: Madhuparna Bhowmik <[email protected]>

via_save_pcictrlreg() should be called with host->lock held
as it writes to pm_pcictrl_reg, otherwise there can be a race
condition between via_sd_suspend() and via_sdc_card_detect().
The same pattern is used in the function via_reset_pcictrl()
as well, where via_save_pcictrlreg() is called with host->lock
held.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Madhuparna Bhowmik <[email protected]>
---
v2: Rebase v5.9-rc1

drivers/mmc/host/via-sdmmc.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/mmc/host/via-sdmmc.c b/drivers/mmc/host/via-sdmmc.c
index 49dab9f42b6d..9b755ea0fa03 100644
--- a/drivers/mmc/host/via-sdmmc.c
+++ b/drivers/mmc/host/via-sdmmc.c
@@ -1257,11 +1257,14 @@ static void __maybe_unused via_init_sdc_pm(struct via_crdr_mmc_host *host)
static int __maybe_unused via_sd_suspend(struct device *dev)
{
struct via_crdr_mmc_host *host;
+ unsigned long flags;

host = dev_get_drvdata(dev);

+ spin_lock_irqsave(&host->lock, flags);
via_save_pcictrlreg(host);
via_save_sdcreg(host);
+ spin_unlock_irqrestore(&host->lock, flags);

device_wakeup_enable(dev);

--
2.17.1


2020-08-24 09:52:50

by Ulf Hansson

[permalink] [raw]
Subject: Re: [PATCH v2] drivers: mmc: host: via-sdmmc: Fix data race bug

On Sat, 22 Aug 2020 at 08:15, <[email protected]> wrote:
>
> From: Madhuparna Bhowmik <[email protected]>
>
> via_save_pcictrlreg() should be called with host->lock held
> as it writes to pm_pcictrl_reg, otherwise there can be a race
> condition between via_sd_suspend() and via_sdc_card_detect().
> The same pattern is used in the function via_reset_pcictrl()
> as well, where via_save_pcictrlreg() is called with host->lock
> held.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Madhuparna Bhowmik <[email protected]>

Applied for next, thanks!

Kind regards
Uffe


> ---
> v2: Rebase v5.9-rc1
>
> drivers/mmc/host/via-sdmmc.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/mmc/host/via-sdmmc.c b/drivers/mmc/host/via-sdmmc.c
> index 49dab9f42b6d..9b755ea0fa03 100644
> --- a/drivers/mmc/host/via-sdmmc.c
> +++ b/drivers/mmc/host/via-sdmmc.c
> @@ -1257,11 +1257,14 @@ static void __maybe_unused via_init_sdc_pm(struct via_crdr_mmc_host *host)
> static int __maybe_unused via_sd_suspend(struct device *dev)
> {
> struct via_crdr_mmc_host *host;
> + unsigned long flags;
>
> host = dev_get_drvdata(dev);
>
> + spin_lock_irqsave(&host->lock, flags);
> via_save_pcictrlreg(host);
> via_save_sdcreg(host);
> + spin_unlock_irqrestore(&host->lock, flags);
>
> device_wakeup_enable(dev);
>
> --
> 2.17.1
>