linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers: mmc: host: via-sdmmc: Fix data race bug
@ 2020-08-03  7:28 madhuparnabhowmik10
  2020-08-21 12:48 ` Ulf Hansson
  0 siblings, 1 reply; 3+ messages in thread
From: madhuparnabhowmik10 @ 2020-08-03  7:28 UTC (permalink / raw)
  To: brucechang, HaraldWelte, ulf.hansson
  Cc: linux-mmc, linux-kernel, ldv-project, andrianov, Madhuparna Bhowmik

From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>

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 <madhuparnabhowmik10@gmail.com>
---
 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 ef95bce50889..e4d8126cd4e5 100644
--- a/drivers/mmc/host/via-sdmmc.c
+++ b/drivers/mmc/host/via-sdmmc.c
@@ -1259,11 +1259,14 @@ static void via_init_sdc_pm(struct via_crdr_mmc_host *host)
 static int via_sd_suspend(struct pci_dev *pcidev, pm_message_t state)
 {
 	struct via_crdr_mmc_host *host;
+	unsigned long flags;
 
 	host = pci_get_drvdata(pcidev);
 
+	spin_lock_irqsave(&host->lock, flags);
 	via_save_pcictrlreg(host);
 	via_save_sdcreg(host);
+	spin_unlock_irqrestore(&host->lock, flags);
 
 	pci_save_state(pcidev);
 	pci_enable_wake(pcidev, pci_choose_state(pcidev, state), 0);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] drivers: mmc: host: via-sdmmc: Fix data race bug
  2020-08-03  7:28 [PATCH] drivers: mmc: host: via-sdmmc: Fix data race bug madhuparnabhowmik10
@ 2020-08-21 12:48 ` Ulf Hansson
  2020-08-22  6:17   ` Madhuparna Bhowmik
  0 siblings, 1 reply; 3+ messages in thread
From: Ulf Hansson @ 2020-08-21 12:48 UTC (permalink / raw)
  To: madhuparnabhowmik10
  Cc: Bruce Chang, Harald Welte, linux-mmc, Linux Kernel Mailing List,
	ldv-project, andrianov

On Mon, 3 Aug 2020 at 09:29, <madhuparnabhowmik10@gmail.com> wrote:
>
> From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
>
> 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 <madhuparnabhowmik10@gmail.com>

This doesn't apply to my mmc tree, can you please rebase and submit a
new version.

Kind regards
Uffe

> ---
>  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 ef95bce50889..e4d8126cd4e5 100644
> --- a/drivers/mmc/host/via-sdmmc.c
> +++ b/drivers/mmc/host/via-sdmmc.c
> @@ -1259,11 +1259,14 @@ static void via_init_sdc_pm(struct via_crdr_mmc_host *host)
>  static int via_sd_suspend(struct pci_dev *pcidev, pm_message_t state)
>  {
>         struct via_crdr_mmc_host *host;
> +       unsigned long flags;
>
>         host = pci_get_drvdata(pcidev);
>
> +       spin_lock_irqsave(&host->lock, flags);
>         via_save_pcictrlreg(host);
>         via_save_sdcreg(host);
> +       spin_unlock_irqrestore(&host->lock, flags);
>
>         pci_save_state(pcidev);
>         pci_enable_wake(pcidev, pci_choose_state(pcidev, state), 0);
> --
> 2.17.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drivers: mmc: host: via-sdmmc: Fix data race bug
  2020-08-21 12:48 ` Ulf Hansson
@ 2020-08-22  6:17   ` Madhuparna Bhowmik
  0 siblings, 0 replies; 3+ messages in thread
From: Madhuparna Bhowmik @ 2020-08-22  6:17 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: madhuparnabhowmik10, Bruce Chang, Harald Welte, linux-mmc,
	Linux Kernel Mailing List, ldv-project, andrianov

On Fri, Aug 21, 2020 at 02:48:37PM +0200, Ulf Hansson wrote:
> On Mon, 3 Aug 2020 at 09:29, <madhuparnabhowmik10@gmail.com> wrote:
> >
> > From: Madhuparna Bhowmik <madhuparnabhowmik10@gmail.com>
> >
> > 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 <madhuparnabhowmik10@gmail.com>
> 
> This doesn't apply to my mmc tree, can you please rebase and submit a
> new version.
>
Sure, I have rebased it to v5.9-rc1, please have a look.

Thanks,
Madhuparna

> Kind regards
> Uffe
> 
> > ---
> >  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 ef95bce50889..e4d8126cd4e5 100644
> > --- a/drivers/mmc/host/via-sdmmc.c
> > +++ b/drivers/mmc/host/via-sdmmc.c
> > @@ -1259,11 +1259,14 @@ static void via_init_sdc_pm(struct via_crdr_mmc_host *host)
> >  static int via_sd_suspend(struct pci_dev *pcidev, pm_message_t state)
> >  {
> >         struct via_crdr_mmc_host *host;
> > +       unsigned long flags;
> >
> >         host = pci_get_drvdata(pcidev);
> >
> > +       spin_lock_irqsave(&host->lock, flags);
> >         via_save_pcictrlreg(host);
> >         via_save_sdcreg(host);
> > +       spin_unlock_irqrestore(&host->lock, flags);
> >
> >         pci_save_state(pcidev);
> >         pci_enable_wake(pcidev, pci_choose_state(pcidev, state), 0);
> > --
> > 2.17.1
> >

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-08-22  6:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-03  7:28 [PATCH] drivers: mmc: host: via-sdmmc: Fix data race bug madhuparnabhowmik10
2020-08-21 12:48 ` Ulf Hansson
2020-08-22  6:17   ` Madhuparna Bhowmik

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).