From: Andrew Lunn <andrew@lunn.ch>
To: "Csókás Bence" <csokas.bence@prolan.hu>
Cc: netdev@vger.kernel.org,
Richard Cochran <richardcochran@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
kernel@pengutronix.de, Marc Kleine-Budde <mkl@pengutronix.de>
Subject: Re: [PATCH] Use a spinlock to guard `fep->ptp_clk_on`
Date: Wed, 31 Aug 2022 18:24:50 +0200 [thread overview]
Message-ID: <Yw+LUq3dii2q1FKQ@lunn.ch> (raw)
In-Reply-To: <79e46d59-436c-ca82-cad4-15c3cb13b1cf@prolan.hu>
On Wed, Aug 31, 2022 at 04:21:47PM +0200, Csókás Bence wrote:
>
> On 2022. 08. 31. 16:03, Andrew Lunn wrote:
> > > diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
> > > index b0d60f898249..98d8f8d6034e 100644
> > > --- a/drivers/net/ethernet/freescale/fec_main.c
> > > +++ b/drivers/net/ethernet/freescale/fec_main.c
> > > @@ -2029,6 +2029,7 @@ static int fec_enet_clk_enable(struct net_device *ndev, bool enable)
> > > {
> > > struct fec_enet_private *fep = netdev_priv(ndev);
> > > int ret;
> > > + unsigned long flags;
> >
> > Please keep to reverse christmas tree
>
> checkpatch didn't tell me that was a requirement... Easy to fix though.
checkpatch does not have the smarts to detect this. And it is a netdev
only thing.
>
> > > if (enable) {
> > > ret = clk_prepare_enable(fep->clk_enet_out);
> > > @@ -2036,15 +2037,15 @@ static int fec_enet_clk_enable(struct net_device *ndev, bool enable)
> > > return ret;
> > > if (fep->clk_ptp) {
> > > - mutex_lock(&fep->ptp_clk_mutex);
> > > + spin_lock_irqsave(&fep->ptp_clk_lock, flags);
> >
> > Is the ptp hardware accessed in interrupt context? If not, you can use
> > a plain spinlock, not _irqsave..
>
> `fec_suspend()` calls `fec_enet_clk_enable()`, which may be a
> non-preemptible context, I'm not sure how the PM subsystem's internals
> work...
> Besides, with the way this driver is built, function call dependencies all
> over the place, I think it's better safe than sorry. I don't think there is
> any disadvantage (besides maybe a few lost cycles) of using _irqsave in
> regular process context anyways.
Those using real time will probably disagree.
There is also a different between not being able to sleep, and not
being able to process an interrupt for some other hardware. You got a
report about taking a mutex in atomic context. That just means you
cannot sleep, probably because a spinlock is held. That is very
different to not being able to handle interrupts. You only need
spin_lock_irqsave() if the interrupt handler also needs the same spin
lock to protect it from a thread using the spin lock.
Andrew
next prev parent reply other threads:[~2022-08-31 16:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-31 12:56 [PATCH] Use a spinlock to guard `fep->ptp_clk_on` Csókás Bence
2022-08-31 13:54 ` Richard Cochran
2022-08-31 14:04 ` Csókás Bence
2022-08-31 14:03 ` Andrew Lunn
2022-08-31 14:21 ` Csókás Bence
2022-08-31 16:24 ` Andrew Lunn [this message]
2022-08-31 17:12 ` Francesco Dolcini
2022-08-31 21:28 ` Jakub Kicinski
2022-09-01 7:51 ` Csókás Bence
2022-09-01 8:06 ` Csókás Bence
2022-09-01 12:18 ` Andrew Lunn
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=Yw+LUq3dii2q1FKQ@lunn.ch \
--to=andrew@lunn.ch \
--cc=csokas.bence@prolan.hu \
--cc=davem@davemloft.net \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=richardcochran@gmail.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).