๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #5114

Re: [PATCH net v3 02/14] ice: use reference counting and SRCU for PTP port access

#5114
From: netdev-bot+sashiko
Date: Mon, 19 Oct 2026 20:14
151 lines
13220 bytes
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] drivers/net/ethernet/intel/ice/ice_adapter.h now embeds `struct
  srcu_struct srcu` by value in `struct ice_port_list` (line 32).

Pre-existing issues:
- [Medium] ice_ptp_prepare_rebuild_sec() (E825C owner reset path) holds
  only an SRCU read section and a kref on the peer port when it callsโ€ฆ

--

ice: use reference counting and SRCU for PTP port access

This commit replaces the mutex-protected adapter port list with an SRCU
protected list plus a spinlock for writers. It also adds a kref to each
ice_ptp_port. Readers take the kref with kref_get_unless_zero(), and
ice_ptp_cleanup_pf() waits for the last reference to drop before it calls
synchronize_srcu().

> diff --git a/drivers/net/ethernet/intel/ice/ice_adapter.h b/drivers/net/ethernet/intel/ice/ice_adapter.h
> index 4f695f32da3d8..0b01c7f5cf0da 100644
> --- a/drivers/net/ethernet/intel/ice/ice_adapter.h
> +++ b/drivers/net/ethernet/intel/ice/ice_adapter.h
> @@ -17,15 +17,19 @@ struct ice_pf;

[ ... ]

>  struct ice_port_list {
> -	struct list_head ports;
> -	/* To synchronize the ports list operations */
> -	struct mutex lock;
> +	struct list_head list;
> +	/* To synchronize write operations on the port list */
> +	spinlock_t lock;
> +	struct srcu_struct srcu;

[Severity: Low]
Should ice_adapter.h include <linux/srcu.h> itself? struct ice_port_list
now embeds struct srcu_struct by value, so it needs the complete type. The
header only pulls in:

#include <linux/types.h>
#include <linux/mutex.h>
#include <linux/spinlock_types.h>
#include <linux/refcount_types.h>

#include "ice_type.h"

The patch adds <linux/srcu.h> to ice_adapter.c and ice_ptp.c instead. The
header seems to build today only through a transitive chain:

ice_type.h -> ice_osdep.h -> <net/udp_tunnel.h> -> ... -> <linux/notifier.h>

and notifier.h is what includes <linux/srcu.h>.

In the same patch, ice_ptp.h does get <linux/kref.h> for its new struct
kref member.

>  };
>  
>  /**
> diff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c
> index e1c66cd0f94ff..55241802d17ae 100644
> --- a/drivers/net/ethernet/intel/ice/ice_ptp.c
> +++ b/drivers/net/ethernet/intel/ice/ice_ptp.c

[ ... ]

> @@ -2890,14 +2934,18 @@ void ice_ptp_queue_work(struct ice_pf *pf)
>  static void ice_ptp_prepare_rebuild_sec(struct ice_pf *pf, bool rebuild,
>  					enum ice_reset_req reset_type)
>  {

[ ... ]

> +	srcu_idx = srcu_read_lock(&ports->srcu);
> +	list_for_each_entry_srcu(port, &ports->list, list_node,
> +				 srcu_read_lock_held(&ports->srcu)) {
>  		struct ice_pf *peer_pf = ptp_port_to_pf(port);
>  
> +		if (!kref_get_unless_zero(&port->ref))
> +			continue;
> +
>  		if (!ice_is_primary(&peer_pf->hw)) {
>  			if (rebuild) {
>  				/* TODO: When implementing rebuild=true:
> @@ -2909,7 +2957,10 @@ static void ice_ptp_prepare_rebuild_sec(struct ice_pf *pf, bool rebuild,
>  				ice_ptp_prepare_for_reset(peer_pf, reset_type);

[Severity: Medium]
This is a pre-existing issue, not one introduced by this patch. Can this
call to ice_ptp_prepare_for_reset(peer_pf) race with the peer PF's own
ice_ptp_release()?

Here the owner holds only an SRCU read section and a kref on the peer
port. ice_ptp_prepare_for_reset() then reads and writes peer_pf->ptp.state
with no lock held:

	if (ptp->state != ICE_PTP_READY)
		return;

	ptp->state = ICE_PTP_RESETTING;

	/* Disable timestamping for both Tx and Rx */
	ice_ptp_disable_timestamp_mode(pf);

	kthread_cancel_delayed_work_sync(&ptp->work);

At the same time, the peer can be in the READY path of ice_ptp_release().
That path does the following before it reaches ice_ptp_cleanup_pf():

	pf->ptp.state = ICE_PTP_UNINIT;

	/* Disable timestamping for both Tx and Rx */
	ice_ptp_disable_timestamp_mode(pf);

	ice_ptp_cleanup_pf(pf);

One possible interleaving:

owner (E825C reset)                    peer PF (unbind/remove)
ice_ptp_prepare_rebuild_sec()
  kref_get_unless_zero() succeeds
  ice_ptp_prepare_for_reset(peer_pf)
    sees state == ICE_PTP_READY
                                       ice_ptp_release()
                                         state = ICE_PTP_UNINIT
                                         ice_ptp_disable_timestamp_mode()
    state = ICE_PTP_RESETTING
    ice_ptp_disable_timestamp_mode()

Could the peer then be torn down with ptp.state left at ICE_PTP_RESETTING
instead of ICE_PTP_UNINIT? Both sides would also run
ice_ptp_disable_timestamp_mode() with nothing ordering them.

The new kref wait in ice_ptp_cleanup_pf() keeps the peer's kworker and Tx
tracker alive until the owner drops its reference, so the earlier
use-after-free window looks closed.

Before this patch, the same call ran with no locking at all. The commit
message also limits its scope to the port list.

^ permalink raw reply

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261015191102.1174111-1-anthony.l.nguyen%40intel.com
Technical Details
Message-ID: <179244084232.3135.1622859924790214166@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-348821-linux-kernel-netdev=dewy.ru
References: <20261015191102.1174111-3-anthony.l.nguyen@intel.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-348821-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v3 02/14] ice: use reference counting and SRCU for PTP
 port access
Date: Mon, 19 Oct 2026 20:14:02 +0000
Organization: Usenet Network
Message-ID: <179244084232.3135.1622859924790214166@kernel.org>
References: <20261015191102.1174111-3-anthony.l.nguyen@intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3704575"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:N8fqc/d3yrLavPhSYgLcUOEp8KA= sha256:FNT4Hc37HDytAvfIjmyimdIMwtyGH3MiQvDdTT5Kifc=
	sha1:dAy/HUvqxpTPLJyy2M4o3QU0Ozo= sha256:tpGZFZnIgaIjoRCElFaCndaJiRYu4wr3+lpkL7oUQoQ=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 3CC64110B10; Mon, 19 Oct 2026 23:14:36 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.729
X-Spam-Status: No, score=-3.729 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.329, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id GoiAPNQ8vW1A;
	Mon, 19 Oct 2026 23:14:33 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-348821-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id DBF15110B0D; Mon, 19 Oct 2026 23:14:24 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 67D3E2DD02; Mon, 19 Oct 2026 20:14:06 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1792440845;
	b=3uWLrDYJI/zVzm6+JuchWjw8yy1RL8JD3UcITj4zxQ0pPrPQxVaBwfKuyGIOHPFMkCSV
	 7GxWE/eTUA8Xmy+Og9ElvLdJXC5Zxjz8ShJyr7fYEgCNS/yHOlK64lUStEpbwuo7rgBzx
	 ZlWOHrne2bJRdJ/RbbZl+fNJtoe0D3/GMo6+D0CLo7zD0J9xf1b2SO12s8JgNeRlwRrcC
	 9n+B7svel1JYhh/jYcfNUekIHdhZ4y8a/mwzSfxMY2KbIiYjAsh+sbPa7qeK88zSCOagD
	 0cZ7mnebehLYYDjj4QPhChuV4nuSSXxu9QN53TEE4TjSmsbY/ILs5HlIbg7fbs9Bo/g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792440845;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=fJ9tVhtZR9lffxtiuB8KMn8XmTaRx8A4a8uVirllzs4=;
	b=NKdSYfKhF36cUSfOxh9SCJJ6/FukT6uEpKS+hnPWcQeCJjbCF02gZVRtTK+AXAUDIOzy
	 4W09R1lxHyUYN3gj04Zp3OSZnGx96Gv82/MtRn76k2U6hXJGonAAnH7bxtuldSGpCZqDa
	 UD9RmLEJU4EAA4kRrkdYzqHCMlX9+LXARVTmYqPwNI2jpHT0VdgIRp2e7maZIc8NY4B0T
	 PxZSvtDLvgiqiHFPYkCQ2ai2C6AASoyTMdeuq1A9zqqFcvsl4gA95Mki6f1KkIwKdTJrS
	 q1knI3VKlvyJ6o6KhU9ekYvvPowYMWqBVkxIFUEhLdqgJFpzClSyq4bbLdIG1aYLdsQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J3fqn1r9;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 521BB606A31A;
	Mon, 19 Oct 2026 20:14:05 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J3fqn1r9
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792440844;
	b=Ldz0ZUCGAfoYqcinVMc2IoTjnZwuCn/s474Fs6FRKhxgtF2wJ2ERy2LMKhM9wiNPCyDU
	 nwTCYDxt2hrl9Ci1CxeZ79YyjgP9O1dcEWPV5SccZ7nuudWaQtsSCW1oEz/sVDtuBfbBp
	 Ib6QgVHL56Ajeg84batR0OimCFHMaCfm7JYhcU+kiC17CtWpGsSF8Jr67ABy/RuBvSuRQ
	 QPsRl/WPmZ0/E3yYkZ1fl0PRuhvHXDsj6/XN6C2dtUjZtG9S+WAyTMPgnL2ebJk/bbPTd
	 BMzuHODftlvMwfkCa3QPIQrX+BJzYopXl3yOwLVd7ZK14DzJzyuW78RwuXccIee7OZQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792440844;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=fJ9tVhtZR9lffxtiuB8KMn8XmTaRx8A4a8uVirllzs4=;
	b=vPPJuDwWzINqAaFL3oNPeSbXyuLgI2hvaXh/HJ1Dd9akmz3y304yEIjWlUW0cm2kZUQU
	 nZPqW7068U2dm78691PQjqz6Y5OXH5oVkNYZKuMQLL3aeXtaT6CDnZlZKWNnBSJHg2BAs
	 gHcMqpTmD3+04PHGA8dcsX4ktZFvkgiNZ4Zj7x+xhJ64tsAVH+/WiPX3SJJvvJBmu76P5
	 PMnUpD83gxqTxburzCSSjsVnfMtE3Xxzhdmi2vprJTFWDLg1mizFv89j6zAI+GJ/Fz9gw
	 Vm8udxqQDuWiCzn0THf2xzvjKABTug6T6CPKfMR4E0EUthS1NtmkRF8ZJWLhVfgXFCw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J3fqn1r9;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 327F5606A327
	for <netdev@vger.kernel.org>; Mon, 19 Oct 2026 20:14:03 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C79D11F000C5;
	Mon, 19 Oct 2026 20:14:02 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1792440843;
	bh=fJ9tVhtZR9lffxtiuB8KMn8XmTaRx8A4a8uVirllzs4=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=J3fqn1r9YukkypgUTpI4ayaToOrFub7zcFM3mXxW380DsQKHG9sLSPQXOybDY8bSc
	 oIP9r7DTf403K+WDYbNJTejN3FrLXheDmN6smIs6ss5W5ORCdZSErJZNMMEmvFW67Q
	 RUa9w2eaI2uln/cowGNJtmbJAnXIL3luUa9GKUWsQYp8E0Lpsf9runts0wjCAFz7a2
	 2IDq+nRl/TkKgwY3H/x6grCTAuCDgRA+vZEJS0XfeN/N2E8H6YIq1BWt+oOJEu1SYb
	 I/cE8T6BnVzVueJeax4fHxWgWeoygFvvIlAJYQOy89EMl5309fOOHafZBFYBno054k
	 zL6C8rctiAWUQ==
X-Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
 edumazet@kernel.org, andrew+netdev@lunn.ch, netdev@vger.kernel.org,
 poros@redhat.com, jacob.e.keller@intel.com, maciej.machnikowski@intel.com,
 przemyslaw.korba@intel.com, grzegorz.nitka@intel.com,
 sergey.temerkhanov@intel.com, arkadiusz.kubalewski@intel.com,
 richardcochran@gmail.com, horms@kernel.org
X-In-Reply-To: <20261015191102.1174111-3-anthony.l.nguyen@intel.com>
X-sashiko-severity: Low
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list