From: Hariprasad Kelam <hkelam@marvell.com>
To: Wei Fang <wei.fang@nxp.com>,
"davem@davemloft.net" <davem@davemloft.net>,
"edumazet@google.com" <edumazet@google.com>,
"kuba@kernel.org" <kuba@kernel.org>,
"pabeni@redhat.com" <pabeni@redhat.com>,
Shenwei Wang <shenwei.wang@nxp.com>,
Clark Wang <xiaoning.wang@nxp.com>,
"richardcochran@gmail.com" <richardcochran@gmail.com>,
"andrew@lunn.ch" <andrew@lunn.ch>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"imx@lists.linux.dev" <imx@lists.linux.dev>
Subject: RE: [PATCH net] net: fec: avoid lock evasion when reading pps_enable
Date: Tue, 14 May 2024 09:26:07 +0000 [thread overview]
Message-ID: <PH0PR18MB44748039C05AE91AAD2DB514DEE32@PH0PR18MB4474.namprd18.prod.outlook.com> (raw)
In-Reply-To: <PAXPR04MB851010A6DBA52A04DA104E1C88E22@PAXPR04MB8510.eurprd04.prod.outlook.com>
> > -----Original Message-----
> > From: Hariprasad Kelam <hkelam@marvell.com>
> > Sent: 2024年5月13日 17:27
> > To: Wei Fang <wei.fang@nxp.com>; davem@davemloft.net;
> > edumazet@google.com; kuba@kernel.org; pabeni@redhat.com; Shenwei
> Wang
> > <shenwei.wang@nxp.com>; Clark Wang <xiaoning.wang@nxp.com>;
> > richardcochran@gmail.com; andrew@lunn.ch; netdev@vger.kernel.org
> > Cc: linux-kernel@vger.kernel.org; imx@lists.linux.dev
> > Subject: [PATCH net] net: fec: avoid lock evasion when reading
> > pps_enable
> >
> > See inline,
> >
> > > The assignment of pps_enable is protected by tmreg_lock, but the
> > > read operation of pps_enable is not. So the Coverity tool reports a
> > > lock evasion warning which may cause data race to occur when running
> > > in a multithread environment. Although this issue is almost
> > > impossible to occur, we'd better fix it, at least it seems more
> > > logically reasonable, and it also prevents Coverity from continuing to issue
> warnings.
> > >
> > > Fixes: 278d24047891 ("net: fec: ptp: Enable PPS output based on ptp
> > > clock")
> > > Signed-off-by: Wei Fang <wei.fang@nxp.com>
> > > ---
> > > drivers/net/ethernet/freescale/fec_ptp.c | 8 +++++---
> > > 1 file changed, 5 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/drivers/net/ethernet/freescale/fec_ptp.c
> > > b/drivers/net/ethernet/freescale/fec_ptp.c
> > > index 181d9bfbee22..8d37274a3fb0 100644
> > > --- a/drivers/net/ethernet/freescale/fec_ptp.c
> > > +++ b/drivers/net/ethernet/freescale/fec_ptp.c
> > > @@ -104,14 +104,16 @@ static int fec_ptp_enable_pps(struct
> > > fec_enet_private *fep, uint enable)
> > > struct timespec64 ts;
> > > u64 ns;
> > >
> > > - if (fep->pps_enable == enable)
> > > - return 0;
> > > -
> > > fep->pps_channel = DEFAULT_PPS_CHANNEL;
> > > fep->reload_period = PPS_OUPUT_RELOAD_PERIOD;
> > >
> > > spin_lock_irqsave(&fep->tmreg_lock, flags);
> > >
> > > + if (fep->pps_enable == enable) {
> >
> > Can we atomic_set/get instead of spin_lock here.
> >
> I'm afraid that cannot eliminate the lock evasion warning, because it's still
> possible that multithreads take the false branch of "if (fep->pps_enable ==
> enable)" before pps_enable is updated.
>
> Since in fec_ptp_enable_pps(), value of pps_enable is checked before entering the actual code changes,
Better approach is to use atomic_read/write. This is not only for reading but for assigning the values as well.
This way covertity wont complain.
> > Thanks,
> > Hariprasad k
> > > + spin_unlock_irqrestore(&fep->tmreg_lock, flags);
> > > + return 0;
> > > + }
> > > +
> > > if (enable) {
> > > /* clear capture or output compare interrupt status if have.
> > > */
> > > --
> > > 2.34.1
> > >
next prev parent reply other threads:[~2024-05-14 9:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-13 1:51 [PATCH net] net: fec: avoid lock evasion when reading pps_enable Wei Fang
2024-05-13 7:29 ` Eric Dumazet
2024-05-13 7:53 ` Wei Fang
2024-05-13 8:40 ` Eric Dumazet
2024-05-13 12:18 ` Wei Fang
2024-05-13 9:27 ` Hariprasad Kelam
2024-05-13 12:24 ` Wei Fang
2024-05-14 9:26 ` Hariprasad Kelam [this message]
2024-05-13 19:54 ` Simon Horman
2024-05-13 19:56 ` Simon Horman
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=PH0PR18MB44748039C05AE91AAD2DB514DEE32@PH0PR18MB4474.namprd18.prod.outlook.com \
--to=hkelam@marvell.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=imx@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=shenwei.wang@nxp.com \
--cc=wei.fang@nxp.com \
--cc=xiaoning.wang@nxp.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 read-only IMAP folder(s) and NNTP newsgroup(s).