mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shmuel Hazan <shmuel.h@siklu.com>
To: Russell King <linux@armlinux.org.uk>
Cc: Marcin Wojtas <mw@semihalf.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Richard Cochran <richardcochran@gmail.com>,
	horatiu.vultur@microchip.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	devicetree@vger.kernel.org, Shmuel Hazan <shmuel.h@siklu.com>
Subject: [PATCH v4 1/3] net: mvpp2: tai: add refcount for ptp worker
Date: Sun, 30 Apr 2023 20:06:54 +0300	[thread overview]
Message-ID: <20230430170656.137549-2-shmuel.h@siklu.com> (raw)
In-Reply-To: <20230430170656.137549-1-shmuel.h@siklu.com>

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.

Due to the ref count, we need now to lock tai->refcount_lock before
doing anything. As a result, we can't call mvpp22_tai_do_aux_work as it
will cause a deadlock. Therefore, we will just schedule the worker to
start immediately.

Fixes: ce3497e2072e ("net: mvpp2: ptp: add support for receive timestamping")
Signed-off-by: Shmuel Hazan <shmuel.h@siklu.com>
---
v1 -> v2: lock tai->lock before touching poll_worker_refcount.
v2 -> v3: no change
v3 -> v4: added additional lock for poll_worker_refcount due to
	  a possible deadlock.
---
 .../net/ethernet/marvell/mvpp2/mvpp2_tai.c    | 28 +++++++++++++++++--
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
index 95862aff49f1..d8ce8bdae046 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_tai.c
@@ -32,6 +32,7 @@
  *
  * Consequently, we support none of these.
  */
+#include "linux/spinlock.h"
 #include <linux/io.h>
 #include <linux/ptp_clock_kernel.h>
 #include <linux/slab.h>
@@ -61,6 +62,8 @@ struct mvpp2_tai {
 	u64 period;		// nanosecond period in 32.32 fixed point
 	/* This timestamp is updated every two seconds */
 	struct timespec64 stamp;
+	spinlock_t refcount_lock; /* Protects the poll_worker_refcount variable */
+	u16 poll_worker_refcount;
 };
 
 static void mvpp2_tai_modify(void __iomem *reg, u32 mask, u32 set)
@@ -370,16 +373,34 @@ void mvpp22_tai_tstamp(struct mvpp2_tai *tai, u32 tstamp,
 
 void mvpp22_tai_start(struct mvpp2_tai *tai)
 {
-	long delay;
+	unsigned long flags;
+
+	spin_lock_irqsave(&tai->refcount_lock, flags);
 
-	delay = mvpp22_tai_aux_work(&tai->caps);
+	tai->poll_worker_refcount++;
+	if (tai->poll_worker_refcount > 1)
+		goto out_unlock;
 
-	ptp_schedule_worker(tai->ptp_clock, delay);
+	ptp_schedule_worker(tai->ptp_clock, 0);
+
+out_unlock:
+	spin_unlock_irqrestore(&tai->refcount_lock, flags);
 }
 
 void mvpp22_tai_stop(struct mvpp2_tai *tai)
 {
+	unsigned long flags;
+
+	spin_lock_irqsave(&tai->refcount_lock, flags);
+
+	tai->poll_worker_refcount--;
+	if (tai->poll_worker_refcount)
+		goto unlock_out;
+
 	ptp_cancel_worker_sync(tai->ptp_clock);
+
+unlock_out:
+	spin_unlock_irqrestore(&tai->refcount_lock, flags);
 }
 
 static void mvpp22_tai_remove(void *priv)
@@ -400,6 +421,7 @@ int mvpp22_tai_probe(struct device *dev, struct mvpp2 *priv)
 		return -ENOMEM;
 
 	spin_lock_init(&tai->lock);
+	spin_lock_init(&tai->refcount_lock);
 
 	tai->base = priv->iface_base;
 
-- 
2.40.1


  reply	other threads:[~2023-04-30 17:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-30 17:06 [PATCH v4 0/3] net: mvpp2: tai: add extts support Shmuel Hazan
2023-04-30 17:06 ` Shmuel Hazan [this message]
2023-05-01 15:04   ` [PATCH v4 1/3] net: mvpp2: tai: add refcount for ptp worker Alexander H Duyck
2023-04-30 17:06 ` [PATCH v4 2/3] net: mvpp2: tai: add extts support Shmuel Hazan
2023-04-30 17:06 ` [PATCH v4 3/3] dt-bindings: net: marvell,pp2: add extts docs Shmuel Hazan
2023-05-01 19:45 ` [PATCH v4 0/3] net: mvpp2: tai: add extts support Russell King (Oracle)

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=20230430170656.137549-2-shmuel.h@siklu.com \
    --to=shmuel.h@siklu.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=horatiu.vultur@microchip.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mw@semihalf.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=robh+dt@kernel.org \
    /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

all inboxes | Powered by JetHome®