From nobody Thu Sep 24 20:04:11 2026 Received: from mail-m49198.qiye.163.com (mail-m49198.qiye.163.com [45.254.49.198]) (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 067B43290A5; Tue, 8 Sep 2026 10:39:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.254.49.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788863979; cv=none; b=LaM4EFe0qipLnMiEO8E5beWJYUNRdJG2Ms9KJBE8mJUIK+YYGQ3XcvdicOnwY3l37wcsHJ02s/JK2nDQqpjbfJ6Y3btK1wKjfj6dOuUml7L5t5cN4+DzpGXXXqLE8Rm1QQTgNwRakX0iBSWkjqG6hZuOUmKsvuGsvdXsn9wtGik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788863979; c=relaxed/simple; bh=JUzEysUXU1YUn1aAM+CvypPX5aH+YjAnneXORnM0Ack=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=lATHv2RBOcfdq4SoblRKX/8+O6sUKlCPSh1oYJAO28PzL9rN6FTInvW3fGi8dE6L6E72fys/65CWlk0ImFyLaS9oXQhs1JFYwheRBcns3Ezv5zQXilyQjHx6AbwF1M3PeV4Cl4/sT5uUQ8cYO1wb8LU5AP8VqTyYEygwIb9dsGM= 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=OOe5/qXA; arc=none smtp.client-ip=45.254.49.198 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="OOe5/qXA" Received: from PC-202605011814.localdomain (unknown [223.112.146.162]) by smtp.qiye.163.com (Hmail) with ESMTP id 4cf8a6f07; Tue, 8 Sep 2026 18:39:29 +0800 (GMT+08:00) From: Runyu Xiao To: =?UTF-8?q?Th=C3=A9o=20Lebrun?= , Andrew Lunn , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran Cc: Conor Dooley , Rafal Ozieblo , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Runyu Xiao , Jianhao Xu , Vadim Fedorenko Subject: [PATCH net v3] net: macb: initialize PTP state before registering clock Date: Tue, 8 Sep 2026 18:39:24 +0800 Message-Id: <20260908103924.607033-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: 0aa08099f9ae03a1kunm06972b3b116bad X-HM-MType: 10 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWRgWCB1ZQUpXWS1ZQUlXWQ8JGhUIEh9ZQVlCS0hNVhhLThhMHhpLGE1DH1YeHw 5VEwETFhoSFyQUDg9ZV1kYEgtZQVlJSUhVSkpJVUpPTVVKTUlZV1kWGg8SFR0UWUFZT0tIVUpLSE pPSExVSktLVUpCS0tZBg++ DKIM-Signature: a=rsa-sha256; b=OOe5/qXAKnlfMzTJ07XYDEIwcTRLmVy3VmcrMJt9DR4FNZgxCJhvspZ+tmALNe6xIR6FB2F/JKG8LKEKA0JIhIDJJbrRN8i6Q+YCocEwg9ChX9J81L5N+UBAxKMbJCS4Js2LSkdH/kWHxkphajepXGMxGHXoaRF6hQoSaKbde8E=; c=relaxed/relaxed; s=default; d=seu.edu.cn; v=1; bh=Fv/FvI5AFITLgzMXl7nXE9rXinKIsyBEQK9uD7fWdE8=; 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/20260904030439.3994047-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 --- v3: - State that the race is theoretical and has not been observed in practice. - Add Reviewed-by trailers from Th=C3=A9o Lebrun and Vadim Fedorenko. - Use the documented Assisted-by format. 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 daa8a4a14..76d38415f 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -5881,6 +5881,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; } -