From nobody Thu Sep 24 20:04:07 2026 Received: from mail-m155101.qiye.163.com (mail-m155101.qiye.163.com [101.71.155.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3D7E430CEC; Mon, 21 Sep 2026 11:11:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=101.71.155.101 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789989104; cv=none; b=Cmhh7NgSvGrUi386VgxmIAIkAoGgaFATGI+zVip4UB5faUVVfWiBD444Z5tOXv3TaKluz5AussbL9jFgSKd6dlx2MhqeQeVBBu8dPL33XRG+uCe8vylKiVQNWhJEJHqT6GBE0w8IoZ2TqOtc5bIBg9ClNzDzMW/27R8nI2zZipQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789989104; c=relaxed/simple; bh=mFBik3/hELLoC6BbMxS74ONLTx+gj7nMcxnX0tLC5e4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=M2CaPXSDKYU+ZYl7vQlui9Mz5F+r633WNGrs+cuRLQSaN9ahPGldgmqZ9J5Tk88W/Det0ac6Wo4Vjg4kFNq6JkN8Zzt7cyLKYaSSEHFYnjCCbRfAbZYIV3ygSfBgU6pdis7hcCYhTRJWzelVSXb+n0HD1W1e2vsk5bY8HK8KSf0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn; spf=pass smtp.mailfrom=seu.edu.cn; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b=P4hmlPWF; arc=none smtp.client-ip=101.71.155.101 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=seu.edu.cn Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=seu.edu.cn header.i=@seu.edu.cn header.b="P4hmlPWF" Received: from PC-202605011814.localdomain (unknown [58.241.16.34]) by smtp.qiye.163.com (Hmail) with ESMTP id 4e9246916; Mon, 21 Sep 2026 19:11:32 +0800 (GMT+08:00) From: Runyu Xiao To: =?UTF-8?q?Th=C3=A9o=20Lebrun?= , Conor Dooley , Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Runyu Xiao , Jianhao Xu Subject: [PATCH net v2] net: macb: initialize PTP state before registering clock Date: Mon, 21 Sep 2026 19:11:28 +0800 Message-Id: <20260921111128.69129-1-runyu.xiao@seu.edu.cn> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-HM-Tid: 0aa0c3a9fcf203a1kunm826d5db04898f X-HM-MType: 10 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWRgWCB1ZQUpXWS1ZQUlXWQ8JGhUIEh9ZQVlCH0JPVk1MQh5IHkkYTh9ISFYeHw 5VEwETFhoSFyQUDg9ZV1kYEgtZQVlOQ1VJT0pVSk1VSE9ZV1kWGg8SFR0UWUFZT0tIVUpLSEpPSE xVSktLVUpCS0tZBg++ DKIM-Signature: a=rsa-sha256; b=P4hmlPWFK3/dICZBJNzSDUOUAGFsn1PUT8uq0CjhZUIw4uiXNZvT1ZsJO8b+x0IUg8JvD7rUCAmroQVtPUoXvALzDnzkOWAQ97EdBUZnvFLzcJCNn4u8F2yrSjI9mnp07lN4/ArcwiYjh2owvR2YaKKd9dRHDzeKRqXNhJlxxc8=; c=relaxed/relaxed; s=default; d=seu.edu.cn; v=1; bh=v3PuQr769s3QKtlzOD2OmKZv8gsCVwNEKKz25/3EGH8=; h=date:mime-version:subject:message-id:from; gem_ptp_init() registers the PTP clock before initializing bp->tsu_clk_lock and the TSU hardware. Since ptp_clock_register() publishes the PTP character device, userspace may invoke PTP callbacks before the lock and hardware are ready. In addition, gem_ptp_init() is called from both the interface open and resume paths. Reinitializing tsu_clk_lock there can reset the lock while timestamp processing is using it. This race is theoretical and has not been observed in practice. Initialize tsu_clk_lock once during probe and initialize the TSU before registering the PTP clock. Fixes: ab91f0a9b5f4 ("net: macb: Add hardware PTP support") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/netdev/20260830153520.2710520-1-runyu.xiao@se= u.edu.cn/ Assisted-by: LLM Codex Reviewed-by: Th=C3=A9o Lebrun Reviewed-by: Vadim Fedorenko Signed-off-by: Runyu Xiao --- v2: - Initialize tsu_clk_lock once during probe and initialize the TSU before registering the PTP clock. - Clarify that the race is theoretical and carry the Reviewed-by trailers. --- drivers/net/ethernet/cadence/macb_main.c | 1 + drivers/net/ethernet/cadence/macb_ptp.c | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/etherne= t/cadence/macb_main.c index 76ee4f506..01b42b21a 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -5876,6 +5876,7 @@ static int macb_probe(struct platform_device *pdev) } spin_lock_init(&bp->lock); spin_lock_init(&bp->stats_lock); + spin_lock_init(&bp->tsu_clk_lock); =20 /* setup capabilities */ macb_configure_caps(bp, macb_config); diff --git a/drivers/net/ethernet/cadence/macb_ptp.c b/drivers/net/ethernet= /cadence/macb_ptp.c index e5195d7da..e9c9c2692 100644 --- a/drivers/net/ethernet/cadence/macb_ptp.c +++ b/drivers/net/ethernet/cadence/macb_ptp.c @@ -334,6 +334,7 @@ void gem_ptp_init(struct net_device *netdev) bp->tsu_rate =3D bp->ptp_info->get_tsu_rate(bp); bp->ptp_clock_info.max_adj =3D bp->ptp_info->get_ptp_max_adj(); gem_ptp_init_timer(bp); + gem_ptp_init_tsu(bp); bp->ptp_clock =3D ptp_clock_register(&bp->ptp_clock_info, &netdev->dev); if (IS_ERR(bp->ptp_clock)) { pr_err("ptp clock register failed: %ld\n", @@ -345,10 +346,6 @@ void gem_ptp_init(struct net_device *netdev) return; } =20 - spin_lock_init(&bp->tsu_clk_lock); - - gem_ptp_init_tsu(bp); - dev_info(&bp->pdev->dev, "%s ptp clock registered.\n", GEM_PTP_TIMER_NAME); } @@ -467,4 +464,3 @@ int gem_set_hwtst(struct net_device *netdev, =20 return 0; } - --=20 2.34.1