{"id":2232320,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2232320/?format=json","web_url":"http://patchwork.ozlabs.org/project/intel-wired-lan/patch/20260504110058.2373236-2-sergey.temerkhanov@intel.com/","project":{"id":46,"url":"http://patchwork.ozlabs.org/api/1.1/projects/46/?format=json","name":"Intel Wired Ethernet development","link_name":"intel-wired-lan","list_id":"intel-wired-lan.osuosl.org","list_email":"intel-wired-lan@osuosl.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260504110058.2373236-2-sergey.temerkhanov@intel.com>","date":"2026-05-04T11:00:56","name":"[iwl-net,v1,1/3] ice: Convert ctrl_pf pointer in struct ice_adapter to RCU","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"a676ae1b612d21d9648d3add56c2a35426c73cf5","submitter":{"id":85162,"url":"http://patchwork.ozlabs.org/api/1.1/people/85162/?format=json","name":"Temerkhanov, Sergey","email":"sergey.temerkhanov@intel.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/intel-wired-lan/patch/20260504110058.2373236-2-sergey.temerkhanov@intel.com/mbox/","series":[{"id":502644,"url":"http://patchwork.ozlabs.org/api/1.1/series/502644/?format=json","web_url":"http://patchwork.ozlabs.org/project/intel-wired-lan/list/?series=502644","date":"2026-05-04T11:00:55","name":"Rework ctrl_pf pointer usage in struct ice_adapter","version":1,"mbox":"http://patchwork.ozlabs.org/series/502644/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2232320/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2232320/checks/","tags":{},"headers":{"Return-Path":"<intel-wired-lan-bounces@osuosl.org>","X-Original-To":["incoming@patchwork.ozlabs.org","intel-wired-lan@lists.osuosl.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","intel-wired-lan@lists.osuosl.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256\n header.s=default header.b=EAjvnRHF;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org\n (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org;\n envelope-from=intel-wired-lan-bounces@osuosl.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g8Jbs3LkKz1yJV\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 04 May 2026 21:01:13 +1000 (AEST)","from localhost (localhost [127.0.0.1])\n\tby smtp3.osuosl.org (Postfix) with ESMTP id B4DC2613A7;\n\tMon,  4 May 2026 11:01:04 +0000 (UTC)","from smtp3.osuosl.org ([127.0.0.1])\n by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP\n id kByjk3SCk0-W; Mon,  4 May 2026 11:01:04 +0000 (UTC)","from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142])\n\tby smtp3.osuosl.org (Postfix) with ESMTP id F2FD8613A2;\n\tMon,  4 May 2026 11:01:03 +0000 (UTC)","from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136])\n by lists1.osuosl.org (Postfix) with ESMTP id 2651325D\n for <intel-wired-lan@lists.osuosl.org>; Mon,  4 May 2026 11:01:03 +0000 (UTC)","from localhost (localhost [127.0.0.1])\n by smtp3.osuosl.org (Postfix) with ESMTP id B9ED16139E\n for <intel-wired-lan@lists.osuosl.org>; Mon,  4 May 2026 11:01:02 +0000 (UTC)","from smtp3.osuosl.org ([127.0.0.1])\n by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP\n id z5VSZREJQ-HF for <intel-wired-lan@lists.osuosl.org>;\n Mon,  4 May 2026 11:01:02 +0000 (UTC)","from mgamail.intel.com (mgamail.intel.com [198.175.65.16])\n by smtp3.osuosl.org (Postfix) with ESMTPS id E485A6139D\n for <intel-wired-lan@lists.osuosl.org>; Mon,  4 May 2026 11:01:01 +0000 (UTC)","from orviesa004.jf.intel.com ([10.64.159.144])\n by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 04 May 2026 04:01:01 -0700","from gnrd8.igk.intel.com (HELO GNRD8) ([10.123.232.137])\n by orviesa004.jf.intel.com with ESMTP; 04 May 2026 04:01:00 -0700"],"X-Virus-Scanned":["amavis at osuosl.org","amavis at osuosl.org"],"X-Comment":"SPF check N/A for local connections - client-ip=140.211.166.142;\n helo=lists1.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org;\n receiver=<UNKNOWN> ","DKIM-Filter":["OpenDKIM Filter v2.11.0 smtp3.osuosl.org F2FD8613A2","OpenDKIM Filter v2.11.0 smtp3.osuosl.org E485A6139D"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org;\n\ts=default; t=1777892464;\n\tbh=xU6G4CL5FryQEFtASw6G5N38AVNdaeBHYMj8xWF4ImI=;\n\th=From:To:Date:In-Reply-To:References:Subject:List-Id:\n\t List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe:\n\t From;\n\tb=EAjvnRHFu300rNeqgwNA2PdrTVBzH8oaha8iIfNDowgKuAb5ww+iRpUq6SAwtwIFK\n\t ZfpyorZRoZx/6o/ZGxNO52B/Tpc2IKBS1aFEkBwzi5CrlEd6ZRLcBHDpIbZibqyoHC\n\t KG87iHtxmfcKsEOs/atqjpOzgp9tCmnWWlUv/tIywvEEJhn8HbJ/FTYqvI7xQhDC1p\n\t pM0tX9Cd/i+i20Kpgxfh5EgVH4tjIpEkAU+7TKbwjm3pnn9Un/vhclb+PrEHf7SRNH\n\t 1ij7i/puxbdYUDOxfIxdkSplFz+pSqHLIrMK1j/hpOonz9L4iiucq4XbFLlJz8nRJP\n\t LG9HITpx+Qwlw==","Received-SPF":"Pass (mailfrom) identity=mailfrom; client-ip=198.175.65.16;\n helo=mgamail.intel.com; envelope-from=sergey.temerkhanov@intel.com;\n receiver=<UNKNOWN>","DMARC-Filter":"OpenDMARC Filter v1.4.2 smtp3.osuosl.org E485A6139D","X-CSE-ConnectionGUID":["h5U2U/qjT4SfEKqSOp8i9g==","WMMoLf2JTLuabZf8IU3r2A=="],"X-CSE-MsgGUID":["98LSDLojTfiZxNW9PgOJPg==","jvxMW35rQFG9iHa99BxgTA=="],"X-IronPort-AV":["E=McAfee;i=\"6800,10657,11775\"; a=\"78939688\"","E=Sophos;i=\"6.23,215,1770624000\"; d=\"scan'208\";a=\"78939688\"","E=Sophos;i=\"6.23,215,1770624000\"; d=\"scan'208\";a=\"239792120\""],"X-ExtLoop1":"1","From":"Sergey Temerkhanov <sergey.temerkhanov@intel.com>","To":"intel-wired-lan@lists.osuosl.org","Date":"Mon,  4 May 2026 11:00:56 +0000","Message-ID":"<20260504110058.2373236-2-sergey.temerkhanov@intel.com>","X-Mailer":"git-send-email 2.53.0","In-Reply-To":"<20260504110058.2373236-1-sergey.temerkhanov@intel.com>","References":"<20260504110058.2373236-1-sergey.temerkhanov@intel.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-Mailman-Original-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple;\n d=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n t=1777892462; x=1809428462;\n h=from:to:subject:date:message-id:in-reply-to:references:\n mime-version:content-transfer-encoding;\n bh=3HvNmG7dbNqnno6mkc2eSWFyvfL5QznVo63SIYp0HBs=;\n b=IJGFbAbdKPkFE25e7yqq4pi2rkkKA4OYu8Yhbyua8VaokxPJLX9o6TPs\n sChn8VK1WL9L4W1TdP1iSyR6TAYgHFbxm8iyeVaR7S6isqMyybsqMWAIM\n qSBlgeQE3Oap1O3FSyXlmgnO4vGYllRQAN6o6mFXtvxN2Oio2UlsuSc/S\n w61EjkZ3Q2EiJyC5aSxAtFwYkLTxbXhOXcomrhK8agCfD+aA3zHRELSOd\n cACHMFMr4VBXxNlPhGTIWg/HGcZQJKnsCQn5mQNEqxCqI1cdBJX3u8CS8\n tlR4/Sc4zy3zj7IxkUO29uXhTkxxPNuaqNMKjF1XnUiTfj/wMF+RDXdrN\n Q==;","X-Mailman-Original-Authentication-Results":["smtp3.osuosl.org;\n dmarc=pass (p=none dis=none)\n header.from=intel.com","smtp3.osuosl.org;\n dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com\n header.a=rsa-sha256 header.s=Intel header.b=IJGFbAbd"],"Subject":"[Intel-wired-lan] [PATCH iwl-net v1 1/3] ice: Convert ctrl_pf\n pointer in struct ice_adapter to RCU","X-BeenThere":"intel-wired-lan@osuosl.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Intel Wired Ethernet Linux Kernel Driver Development\n <intel-wired-lan.osuosl.org>","List-Unsubscribe":"<https://lists.osuosl.org/mailman/options/intel-wired-lan>,\n <mailto:intel-wired-lan-request@osuosl.org?subject=unsubscribe>","List-Archive":"<http://lists.osuosl.org/pipermail/intel-wired-lan/>","List-Post":"<mailto:intel-wired-lan@osuosl.org>","List-Help":"<mailto:intel-wired-lan-request@osuosl.org?subject=help>","List-Subscribe":"<https://lists.osuosl.org/mailman/listinfo/intel-wired-lan>,\n <mailto:intel-wired-lan-request@osuosl.org?subject=subscribe>","Errors-To":"intel-wired-lan-bounces@osuosl.org","Sender":"\"Intel-wired-lan\" <intel-wired-lan-bounces@osuosl.org>"},"content":"Use RCU to ensure the consistent state of the control PF global\npointer contained in struct ice_adapter. Enforce RCU usage on\nthe callers.\n\nFix a potential invalid pointer return due a TOCTOU issue\n\nFixes: e2193f9f9ec9 (\"ice: enable timesync operation on 2xNAC E825 devices\")\n\nSigned-off-by: Sergey Temerkhanov <sergey.temerkhanov@intel.com>\nReviewed-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>\n---\n drivers/net/ethernet/intel/ice/ice.h         | 10 +++-\n drivers/net/ethernet/intel/ice/ice_adapter.h |  2 +-\n drivers/net/ethernet/intel/ice/ice_ptp.c     | 49 ++++++++++++++++----\n drivers/net/ethernet/intel/ice/ice_ptp_hw.c  |  9 ++++\n 4 files changed, 59 insertions(+), 11 deletions(-)","diff":"diff --git a/drivers/net/ethernet/intel/ice/ice.h b/drivers/net/ethernet/intel/ice/ice.h\nindex 804f5aa8e9f5..2b2787d16c33 100644\n--- a/drivers/net/ethernet/intel/ice/ice.h\n+++ b/drivers/net/ethernet/intel/ice/ice.h\n@@ -40,6 +40,7 @@\n #include <linux/cpu_rmap.h>\n #include <linux/dim.h>\n #include <linux/gnss.h>\n+#include <linux/rcupdate.h>\n #include <net/pkt_cls.h>\n #include <net/pkt_sched.h>\n #include <net/tc_act/tc_mirred.h>\n@@ -1145,14 +1146,19 @@ static inline bool ice_pf_src_tmr_owned(struct ice_pf *pf)\n  * ice_get_primary_hw - Get pointer to primary ice_hw structure\n  * @pf: pointer to PF structure\n  *\n+ * The function must be called from an RCU read-side critical section.\n+ * hw is embedded in struct ice_pf, so it is protected by the RCU.\n+ *\n  * Return: A pointer to ice_hw structure with access to timesync\n  * register space.\n  */\n static inline struct ice_hw *ice_get_primary_hw(struct ice_pf *pf)\n {\n-\tif (!pf->adapter->ctrl_pf)\n+\tstruct ice_pf *ctrl_pf = rcu_dereference(pf->adapter->ctrl_pf);\n+\n+\tif (!ctrl_pf)\n \t\treturn &pf->hw;\n \telse\n-\t\treturn &pf->adapter->ctrl_pf->hw;\n+\t\treturn &ctrl_pf->hw;\n }\n #endif /* _ICE_H_ */\ndiff --git a/drivers/net/ethernet/intel/ice/ice_adapter.h b/drivers/net/ethernet/intel/ice/ice_adapter.h\nindex e95266c7f20b..349d49d57f11 100644\n--- a/drivers/net/ethernet/intel/ice/ice_adapter.h\n+++ b/drivers/net/ethernet/intel/ice/ice_adapter.h\n@@ -42,7 +42,7 @@ struct ice_adapter {\n \t/* For access to GLCOMM_QTX_CNTX_CTL register */\n \tspinlock_t txq_ctx_lock;\n \n-\tstruct ice_pf *ctrl_pf;\n+\tstruct ice_pf __rcu *ctrl_pf;\n \tstruct ice_port_list ports;\n \tu64 index;\n };\ndiff --git a/drivers/net/ethernet/intel/ice/ice_ptp.c b/drivers/net/ethernet/intel/ice/ice_ptp.c\nindex 36e2223c37b8..1114a862c27b 100644\n--- a/drivers/net/ethernet/intel/ice/ice_ptp.c\n+++ b/drivers/net/ethernet/intel/ice/ice_ptp.c\n@@ -4,6 +4,7 @@\n #include \"ice.h\"\n #include \"ice_lib.h\"\n #include \"ice_trace.h\"\n+#include <linux/rcupdate.h>\n \n static const char ice_pin_names[][64] = {\n \t\"SDP0\",\n@@ -54,11 +55,35 @@ static const struct ice_ptp_pin_desc ice_pin_desc_dpll[] = {\n \t{  SDP3, {  3, -1 }, { 0, 0 }},\n };\n \n+/**\n+ * ice_get_ctrl_pf - Get the control PF for a given PF\n+ * @pf: The PF pointer to look up at\n+ *\n+ * The control PF is the PF which owns the PTP clock for the adapter.\n+ * Only the control PF is allowed to perform certain operations on the\n+ * PTP clock such as adjusting the time or configuring the pins.\n+ *\n+ * This function must be called from an RCU read-side critical section.\n+ *\n+ * Return: Pointer to the control PF, or NULL if not found\n+ */\n static struct ice_pf *ice_get_ctrl_pf(struct ice_pf *pf)\n {\n-\treturn !pf->adapter ? NULL : pf->adapter->ctrl_pf;\n+\treturn !pf->adapter ? NULL : rcu_dereference(pf->adapter->ctrl_pf);\n }\n \n+/**\n+ * ice_get_ctrl_ptp - Get the PTP structure for the control PF\n+ * @pf: The PF pointer to look up at\n+ *\n+ * The control PF is the PF which owns the PTP clock for the adapter.\n+ * Only the control PF is allowed to perform certain operations on the\n+ * PTP clock such as adjusting the time or configuring the pins.\n+ *\n+ * This function must be called from an RCU read-side critical section.\n+ *\n+ * Return: Pointer to the PTP structure of the control PF, or NULL if not found\n+ */\n static struct ice_ptp *ice_get_ctrl_ptp(struct ice_pf *pf)\n {\n \tstruct ice_pf *ctrl_pf = ice_get_ctrl_pf(pf);\n@@ -207,6 +232,8 @@ u64 ice_ptp_read_src_clk_reg(struct ice_pf *pf,\n \tu32 hi, lo, lo2;\n \tu8 tmr_idx;\n \n+\tguard(rcu)();\n+\n \tif (!ice_is_primary(hw))\n \t\thw = ice_get_primary_hw(pf);\n \n@@ -3074,18 +3101,19 @@ void ice_ptp_rebuild(struct ice_pf *pf, enum ice_reset_req reset_type)\n \n static void ice_ptp_setup_adapter(struct ice_pf *pf)\n {\n-\tpf->adapter->ctrl_pf = pf;\n+\trcu_assign_pointer(pf->adapter->ctrl_pf, pf);\n }\n \n static int ice_ptp_setup_pf(struct ice_pf *pf)\n {\n-\tstruct ice_ptp *ctrl_ptp = ice_get_ctrl_ptp(pf);\n \tstruct ice_ptp *ptp = &pf->ptp;\n \n-\tif (!ctrl_ptp) {\n-\t\tdev_info(ice_pf_to_dev(pf),\n-\t\t\t \"PTP unavailable: no controlling PF\\n\");\n-\t\treturn -EOPNOTSUPP;\n+\tscoped_guard(rcu) {\n+\t\tif (!ice_get_ctrl_ptp(pf)) {\n+\t\t\tdev_info(ice_pf_to_dev(pf),\n+\t\t\t\t \"PTP unavailable: no controlling PF\\n\");\n+\t\t\treturn -EOPNOTSUPP;\n+\t\t}\n \t}\n \n \tif (pf->hw.mac_type == ICE_MAC_UNKNOWN)\n@@ -3121,11 +3149,16 @@ static void ice_ptp_cleanup_pf(struct ice_pf *pf)\n  */\n int ice_ptp_clock_index(struct ice_pf *pf)\n {\n-\tstruct ice_ptp *ctrl_ptp = ice_get_ctrl_ptp(pf);\n+\tstruct ice_ptp *ctrl_ptp;\n \tstruct ptp_clock *clock;\n \n+\tguard(rcu)();\n+\n+\tctrl_ptp = ice_get_ctrl_ptp(pf);\n+\n \tif (!ctrl_ptp)\n \t\treturn -1;\n+\n \tclock = ctrl_ptp->clock;\n \n \treturn clock ? ptp_clock_index(clock) : -1;\ndiff --git a/drivers/net/ethernet/intel/ice/ice_ptp_hw.c b/drivers/net/ethernet/intel/ice/ice_ptp_hw.c\nindex a1ec5d617aa0..892bcc50e82f 100644\n--- a/drivers/net/ethernet/intel/ice/ice_ptp_hw.c\n+++ b/drivers/net/ethernet/intel/ice/ice_ptp_hw.c\n@@ -1,6 +1,7 @@\n // SPDX-License-Identifier: GPL-2.0\n /* Copyright (C) 2021, Intel Corporation. */\n \n+#include <linux/cleanup.h>\n #include <linux/delay.h>\n #include <linux/iopoll.h>\n #include \"ice_common.h\"\n@@ -351,6 +352,8 @@ void ice_ptp_src_cmd(struct ice_hw *hw, enum ice_ptp_tmr_cmd cmd)\n \tstruct ice_pf *pf = container_of(hw, struct ice_pf, hw);\n \tu32 cmd_val = ice_ptp_tmr_cmd_to_src_reg(hw, cmd);\n \n+\tguard(rcu)();\n+\n \tif (!ice_is_primary(hw))\n \t\thw = ice_get_primary_hw(pf);\n \n@@ -369,6 +372,8 @@ static void ice_ptp_exec_tmr_cmd(struct ice_hw *hw)\n {\n \tstruct ice_pf *pf = container_of(hw, struct ice_pf, hw);\n \n+\tguard(rcu)();\n+\n \tif (!ice_is_primary(hw))\n \t\thw = ice_get_primary_hw(pf);\n \n@@ -1983,6 +1988,8 @@ static int ice_read_phy_and_phc_time_eth56g(struct ice_hw *hw, u8 port,\n \t\tzo = rd32(hw, GLTSYN_SHTIME_0(tmr_idx));\n \t\tlo = rd32(hw, GLTSYN_SHTIME_L(tmr_idx));\n \t} else {\n+\t\tguard(rcu)();\n+\n \t\tzo = rd32(ice_get_primary_hw(pf), GLTSYN_SHTIME_0(tmr_idx));\n \t\tlo = rd32(ice_get_primary_hw(pf), GLTSYN_SHTIME_L(tmr_idx));\n \t}\n@@ -2152,6 +2159,8 @@ int ice_start_phy_timer_eth56g(struct ice_hw *hw, u8 port)\n \t\tlo = rd32(hw, GLTSYN_INCVAL_L(tmr_idx));\n \t\thi = rd32(hw, GLTSYN_INCVAL_H(tmr_idx));\n \t} else {\n+\t\tguard(rcu)();\n+\n \t\tlo = rd32(ice_get_primary_hw(pf), GLTSYN_INCVAL_L(tmr_idx));\n \t\thi = rd32(ice_get_primary_hw(pf), GLTSYN_INCVAL_H(tmr_idx));\n \t}\n","prefixes":["iwl-net","v1","1/3"]}