* [RFC PATCH] net: mvpp2: tai: add refcount for ptp worker
@ 2023-04-16 14:30 Shmuel Hazan
2023-04-16 14:52 ` Andrew Lunn
0 siblings, 1 reply; 5+ messages in thread
From: Shmuel Hazan @ 2023-04-16 14:30 UTC (permalink / raw)
To: linux@armlinux.org.uk
Cc: mw@semihalf.com, netdev@vger.kernel.org, davem@davemloft.net
From bd7fb292219e6b64a650a6c79d09822dbef662d3 Mon Sep 17 00:00:00 2001
In some configurations, a single TAI can be
responsible for multiple mvpp2 interfaces.
However, the mvpp2 driver will call mvpp22_tai_stop
and mvpp22_tai_start per interface RX timestamp
disable/enable.
As a result, disabling timestamping for one
interface would stop the worker and corrupt
the other interface's RX timestamps.
This commit solves the issue by introducing a
simpler ref count for each TAI instance.
Fixes: ce3497e2072e ("net: mvpp2: ptp: add support for receive
timestamping")
Signed-off-by: Shmuel Hazan <shmuel.h@siklu.com>
---
drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
index 95862aff49f1..1b57573dd866 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
@@ -61,6 +61,7 @@ struct mvpp2_tai {
u64 period; // nanosecond period in 32.32 fixed
point
/* This timestamp is updated every two seconds */
struct timespec64 stamp;
+ u16 poll_worker_refcount;
};
static void mvpp2_tai_modify(void __iomem *reg, u32 mask, u32 set)
@@ -372,6 +373,10 @@ void mvpp22_tai_start(struct mvpp2_tai *tai)
{
long delay;
+ tai->poll_worker_refcount++;
+ if (tai->poll_worker_refcount > 1)
+ return;
+
delay = mvpp22_tai_aux_work(&tai->caps);
ptp_schedule_worker(tai->ptp_clock, delay);
@@ -379,6 +384,9 @@ void mvpp22_tai_start(struct mvpp2_tai *tai)
void mvpp22_tai_stop(struct mvpp2_tai *tai)
{
+ tai->poll_worker_refcount--;
+ if (tai->poll_worker_refcount)
+ return;
ptp_cancel_worker_sync(tai->ptp_clock);
}
--
2.40.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [RFC PATCH] net: mvpp2: tai: add refcount for ptp worker
2023-04-16 14:30 [RFC PATCH] net: mvpp2: tai: add refcount for ptp worker Shmuel Hazan
@ 2023-04-16 14:52 ` Andrew Lunn
2023-04-16 15:25 ` Shmuel Hazan
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Lunn @ 2023-04-16 14:52 UTC (permalink / raw)
To: Shmuel Hazan
Cc: linux@armlinux.org.uk, mw@semihalf.com, netdev@vger.kernel.org,
davem@davemloft.net
> diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
> b/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
> index 95862aff49f1..1b57573dd866 100644
> --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
> +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
> @@ -61,6 +61,7 @@ struct mvpp2_tai {
> u64 period; // nanosecond period in 32.32 fixed
> point
> /* This timestamp is updated every two seconds */
> struct timespec64 stamp;
> + u16 poll_worker_refcount;
What lock is protecting this? It would be nice to comment in the
commit message why it is safe to use a simple u16.
Andrew
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC PATCH] net: mvpp2: tai: add refcount for ptp worker
2023-04-16 14:52 ` Andrew Lunn
@ 2023-04-16 15:25 ` Shmuel Hazan
2023-04-16 15:40 ` Andrew Lunn
0 siblings, 1 reply; 5+ messages in thread
From: Shmuel Hazan @ 2023-04-16 15:25 UTC (permalink / raw)
To: andrew@lunn.ch
Cc: linux@armlinux.org.uk, mw@semihalf.com, netdev@vger.kernel.org,
davem@davemloft.net
On Sun, 2023-04-16 at 16:52 +0200, Andrew Lunn wrote:
>
> > diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
> > b/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
> > index 95862aff49f1..1b57573dd866 100644
> > --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
> > +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
> > @@ -61,6 +61,7 @@ struct mvpp2_tai {
> > u64 period; // nanosecond period in 32.32 fixed
> > point
> > /* This timestamp is updated every two seconds */
> > struct timespec64 stamp;
> > + u16 poll_worker_refcount;
>
> What lock is protecting this? It would be nice to comment in the
> commit message why it is safe to use a simple u16.
Hi Andrew,
thanks for your response. In theory, the only code path
to these functions (mvpp22_tai_start and mvpp22_tai_stop)
is ioctl (mvpp2_ioctl -> mvpp2_set_ts_config) which should lock
rtnl. However,
It would probably be a good idea to also lock mvpp2_tai->lock too.
As for the integer size, it will be increased once per ethernet device
on that CP, which currently has only maximum of 3 ethernet ports. I
gave it u16 just to be futureproof. However, I can change it to a more
appropriate type if it looks more appropriate to you.
>
> Andrew
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC PATCH] net: mvpp2: tai: add refcount for ptp worker
2023-04-16 15:25 ` Shmuel Hazan
@ 2023-04-16 15:40 ` Andrew Lunn
2023-05-02 8:44 ` Russell King (Oracle)
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Lunn @ 2023-04-16 15:40 UTC (permalink / raw)
To: Shmuel Hazan
Cc: linux@armlinux.org.uk, mw@semihalf.com, netdev@vger.kernel.org,
davem@davemloft.net
On Sun, Apr 16, 2023 at 03:25:55PM +0000, Shmuel Hazan wrote:
> On Sun, 2023-04-16 at 16:52 +0200, Andrew Lunn wrote:
> >
> > > diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
> > > b/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
> > > index 95862aff49f1..1b57573dd866 100644
> > > --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
> > > +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
> > > @@ -61,6 +61,7 @@ struct mvpp2_tai {
> > > u64 period; // nanosecond period in 32.32 fixed
> > > point
> > > /* This timestamp is updated every two seconds */
> > > struct timespec64 stamp;
> > > + u16 poll_worker_refcount;
> >
> > What lock is protecting this? It would be nice to comment in the
> > commit message why it is safe to use a simple u16.
>
> Hi Andrew,
>
> thanks for your response. In theory, the only code path
> to these functions (mvpp22_tai_start and mvpp22_tai_stop)
> is ioctl (mvpp2_ioctl -> mvpp2_set_ts_config) which should lock
> rtnl. However,
> It would probably be a good idea to also lock mvpp2_tai->lock too.
I cannot comment on what locks should be used, i don't know the code.
Which is why as a reviewer, i just want some indication you have
thought about locking, and you think it is safe, given that there are
not obvious locks in the code.
Andrew
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC PATCH] net: mvpp2: tai: add refcount for ptp worker
2023-04-16 15:40 ` Andrew Lunn
@ 2023-05-02 8:44 ` Russell King (Oracle)
0 siblings, 0 replies; 5+ messages in thread
From: Russell King (Oracle) @ 2023-05-02 8:44 UTC (permalink / raw)
To: Andrew Lunn
Cc: Shmuel Hazan, mw@semihalf.com, netdev@vger.kernel.org,
davem@davemloft.net
On Sun, Apr 16, 2023 at 05:40:12PM +0200, Andrew Lunn wrote:
> On Sun, Apr 16, 2023 at 03:25:55PM +0000, Shmuel Hazan wrote:
> > On Sun, 2023-04-16 at 16:52 +0200, Andrew Lunn wrote:
> > >
> > > > diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
> > > > b/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
> > > > index 95862aff49f1..1b57573dd866 100644
> > > > --- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
> > > > +++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
> > > > @@ -61,6 +61,7 @@ struct mvpp2_tai {
> > > > u64 period; // nanosecond period in 32.32 fixed
> > > > point
> > > > /* This timestamp is updated every two seconds */
> > > > struct timespec64 stamp;
> > > > + u16 poll_worker_refcount;
> > >
> > > What lock is protecting this? It would be nice to comment in the
> > > commit message why it is safe to use a simple u16.
> >
> > Hi Andrew,
> >
> > thanks for your response. In theory, the only code path
> > to these functions (mvpp22_tai_start and mvpp22_tai_stop)
> > is ioctl (mvpp2_ioctl -> mvpp2_set_ts_config) which should lock
> > rtnl. However,
> > It would probably be a good idea to also lock mvpp2_tai->lock too.
>
> I cannot comment on what locks should be used, i don't know the code.
>
> Which is why as a reviewer, i just want some indication you have
> thought about locking, and you think it is safe, given that there are
> not obvious locks in the code.
... and probably is a good idea to place a comment in the code stating
what the locking for it is.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-05-02 8:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-16 14:30 [RFC PATCH] net: mvpp2: tai: add refcount for ptp worker Shmuel Hazan
2023-04-16 14:52 ` Andrew Lunn
2023-04-16 15:25 ` Shmuel Hazan
2023-04-16 15:40 ` Andrew Lunn
2023-05-02 8:44 ` Russell King (Oracle)
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).