Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp4579370rwr; Sun, 30 Apr 2023 10:07:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5zI3/CHWteElXKOgwM2fTzUnc2FK0B0ZWwsrAhlid2K4V5l5f28fQbnL0kkkHNB+e8crVO X-Received: by 2002:a17:90a:344:b0:240:cf04:c997 with SMTP id 4-20020a17090a034400b00240cf04c997mr10444760pjf.2.1682874466815; Sun, 30 Apr 2023 10:07:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682874466; cv=none; d=google.com; s=arc-20160816; b=GDURVNxRSPtP6fh5ZGZagLcwtBKDR6NbthuTexxGGrqfDYANuPhEJ9QNnMRilK6i9O 4X73qiQVi4poy69pmsnqGH/bkFB0AOk375mKCIPk4u2v+pTShB3qEf2pzoMYRKBZzfli +ZUCZF0/XqKuE7qY5Q7Gb16pTBPZOJ9+J0kca9pmGi2NbE0LmmS/RoD8w9VZLoogWRwx UVPW78AJqBBxBo+F2ib4dVFOoW4ttrr+6P7wHC0Ep6BCKsXz/LK+DO0N+L/m295/irDA w+Ee/sAj/kerG8R0WKh32wIqhQqzLF2DA09cJjmYqhjm5yWje+bqFE28dOyt2hX/HNw6 OM+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+yXNS49xfZdzA5SOh3vXzMEgdJ3abEie9vbkI8Dm7FU=; b=CvoDYgwKmXeoDSwOkjw0/F5g35b9grCzInU2swbQtr5deMw2g60MKJ2B9ZJqL+SCvK aQA8vduwDMjRSi7QpGgakdkE0Xd4IPGDbYGDmA/wgBDMm6tQqZbNgEKKJnctEQpVKOPc shP6Ydz78vAngiOySmmORLnbrb4/UUeIBEmWTYcOEDBEai9excatFrCU+eUt3+iivAoU V+DV7dw1DiWXEzULtBELOWN2vNYtdH9A4tssEzPDIK0UUB9l1tNrG51CPHXMV2EMjDS9 g0lTBCztIRO1Gukw56gC5SxbwrQWgTTsGxk9068SgXIB5zWBwe2A2NwVzjsgTKSC/0Fd oFFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n11-20020a634d4b000000b0052856cec94csi16101064pgl.877.2023.04.30.10.07.33; Sun, 30 Apr 2023 10:07:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230340AbjD3RHQ (ORCPT + 99 others); Sun, 30 Apr 2023 13:07:16 -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: 8bit X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,FSL_HELO_NON_FQDN_1, HELO_NO_DOMAIN,RDNS_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 #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; }; 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