[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID:
<BL0PR04MB6564A6B239E652983AC5A878FCE12@BL0PR04MB6564.namprd04.prod.outlook.com>
Date: Wed, 22 Jan 2025 11:04:12 +0000
From: Avri Altman <Avri.Altman@....com>
To: Manivannan Sadhasivam <manisadhasivam.linux@...il.com>
CC: "Martin K . Petersen" <martin.petersen@...cle.com>,
"linux-scsi@...r.kernel.org" <linux-scsi@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>, Bart Van
Assche <bvanassche@....org>, Dmitry Baryshkov <dmitry.baryshkov@...aro.org>
Subject: RE: [PATCH] scsi: ufs: core: Ensure clk_gating.lock is used only
after initialization
> > To fix this issue, we use the existing `is_initialized` flag in the
> > `clk_gating` structure to ensure that the spinlock is only used after
> > it has been properly initialized. We check this flag before using the
> > spinlock in the `ufshcd_setup_clocks` function.
> >
> > It was incorrect in the first place to call `setup_clocks()` before
> > `ufshcd_init_clk_gating()`, and the introduction of the new lock
> > unmasked this bug.
>
> If calling setup_clocks() before ufshcd_init_clk_gating() is incorrect, why are
> you not reordering it?
>
> Checking for 'clk_gating.is_initialized' looks like a hack.
Actually 'clk_gating.is_initialized' seems like the standard way to do this - see e.g. in hold and release.
As for moving setup_clocks() around, I have some concerns about moving it out of ufshcd_hba_init.
Having considered the alternatives, it seems that using 'clk_gating.is_initialized' ,
despite its limitations, is the most practical solution we have.
I am open though for other suggestions.
Thanks,
Avri
>
> - Mani
>
> >
> > Fixes: 209f4e43b806 ("scsi: ufs: core: Introduce a new clock_gating
> > lock")
> > Reported-by: Dmitry Baryshkov <dmitry.baryshkov@...aro.org>
> > Signed-off-by: Avri Altman <avri.altman@....com>
> > ---
> > drivers/ufs/core/ufshcd.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
> > index f6c38cf10382..a778fc51ca2a 100644
> > --- a/drivers/ufs/core/ufshcd.c
> > +++ b/drivers/ufs/core/ufshcd.c
> > @@ -9142,7 +9142,7 @@ static int ufshcd_setup_clocks(struct ufs_hba
> *hba, bool on)
> > if (!IS_ERR_OR_NULL(clki->clk) && clki->enabled)
> > clk_disable_unprepare(clki->clk);
> > }
> > - } else if (!ret && on) {
> > + } else if (!ret && on && hba->clk_gating.is_initialized) {
> > scoped_guard(spinlock_irqsave, &hba->clk_gating.lock)
> > hba->clk_gating.state = CLKS_ON;
> > trace_ufshcd_clk_gating(dev_name(hba->dev),
> > --
> > 2.25.1
> >
>
> --
> மணிவண்ணன் சதாசிவம்
Powered by blists - more mailing lists