lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230430170656.137549-2-shmuel.h@siklu.com>
Date:   Sun, 30 Apr 2023 20:06:54 +0300
From:   Shmuel Hazan <shmuel.h@...lu.com>
To:     Russell King <linux@...linux.org.uk>
Cc:     Marcin Wojtas <mw@...ihalf.com>,
        "David S. Miller" <davem@...emloft.net>,
        Eric Dumazet <edumazet@...gle.com>,
        Jakub Kicinski <kuba@...nel.org>,
        Paolo Abeni <pabeni@...hat.com>,
        Richard Cochran <richardcochran@...il.com>,
        horatiu.vultur@...rochip.com, netdev@...r.kernel.org,
        linux-kernel@...r.kernel.org, Rob Herring <robh+dt@...nel.org>,
        Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
        devicetree@...r.kernel.org, Shmuel Hazan <shmuel.h@...lu.com>
Subject: [PATCH v4 1/3] net: mvpp2: tai: add refcount for ptp worker

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@...lu.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ