From nobody Wed Dec 17 15:11:04 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93F25C77B60 for ; Sun, 30 Apr 2023 17:07:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230355AbjD3RHS (ORCPT ); Sun, 30 Apr 2023 13:07:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229521AbjD3RHO (ORCPT ); Sun, 30 Apr 2023 13:07:14 -0400 Received: from synguard (unknown [212.29.212.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1B982706; Sun, 30 Apr 2023 10:07:10 -0700 (PDT) Received: from T14.siklu.local (T14.siklu.local [192.168.42.187]) by synguard (Postfix) with ESMTP id BEFAA4E4CE; Sun, 30 Apr 2023 20:07:06 +0300 (IDT) From: Shmuel Hazan To: Russell King Cc: Marcin Wojtas , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , horatiu.vultur@microchip.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org, Shmuel Hazan Subject: [PATCH v4 1/3] net: mvpp2: tai: add refcount for ptp worker Date: Sun, 30 Apr 2023 20:06:54 +0300 Message-Id: <20230430170656.137549-2-shmuel.h@siklu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230430170656.137549-1-shmuel.h@siklu.com> References: <20230430170656.137549-1-shmuel.h@siklu.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Alexander Duyck --- 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/e= thernet/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 #include #include @@ -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; }; =20 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 tst= amp, =20 void mvpp22_tai_start(struct mvpp2_tai *tai) { - long delay; + unsigned long flags; + + spin_lock_irqsave(&tai->refcount_lock, flags); =20 - delay =3D mvpp22_tai_aux_work(&tai->caps); + tai->poll_worker_refcount++; + if (tai->poll_worker_refcount > 1) + goto out_unlock; =20 - ptp_schedule_worker(tai->ptp_clock, delay); + ptp_schedule_worker(tai->ptp_clock, 0); + +out_unlock: + spin_unlock_irqrestore(&tai->refcount_lock, flags); } =20 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); } =20 static void mvpp22_tai_remove(void *priv) @@ -400,6 +421,7 @@ int mvpp22_tai_probe(struct device *dev, struct mvpp2 *= priv) return -ENOMEM; =20 spin_lock_init(&tai->lock); + spin_lock_init(&tai->refcount_lock); =20 tai->base =3D priv->iface_base; =20 --=20 2.40.1