From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379720; b=WbZH8vreLjbN6VeEHJICPF9fwyfbxdO9IHg4UyNdFbMg/AXWQfdUY4hlzg2K8YjwEh8U Q+pJkHpi8gT++pfM4ZiZ20QHmAzgOLszdPQdxEZKoazikdqKDp7qn/8B5SVEC5WBaC1eg bRWUzlaxIPkQPpCZrw8ee2SLHkzDgYPLooHLeAC2h2XDhBAXj9xX2/otWHz8GhELwATFj Rcx9MM+hUt9cCrir1vBaIkg2IpJh5j7jD3kI7Lbun1GZMzrUzptMcJZDfMohY9uvPVAHk aKxxxWMzIInZwM0O2kzODP7ZnVelIJOJ2eKb7xMPtIrwvwPU2TzYdWZ6FU1LLr67ibA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379720; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=skAJDTYkNXMNaEyJqfYS9TuvHMErvxOUqnLeD0Y0BP4=; b=jZGOQ9BXa0DWSZ9eQiADA8XlD+okZ78pq7eUcBcxJah4ZXDjf9/nArYz1eQQaoJ53PTn NIotOjaycNOgNJrSkaD26U0o/LwkJhZHT4aHoBcKRATrwW7aB3/Ounzx7QNy9N5MpkzDN MwVf7OjbT0S/h6uGoi3K8k5GBZGniNAComdVtZl+27oDu1pHsXOX/lfbsQSwTvSIBiwSV ++YD1LTOighxIj5aQ/YEiAZBhHdilGmgLbWRlnAG0FftfwHjIgO8HLzc5xiw9gbRRzHKw IjQY7inCdBIw5OIreNAiWLimS4Vx1h6dCQlw/TarajlaXFsOg7lepY8iscOhutzXDXw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=tt91gLyx; arc=none smtp.remote-ip=100.103.45.18 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 5C3D1606A322; Fri, 4 Dec 2026 10:22:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=tt91gLyx Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA2E81F000CE; Fri, 4 Dec 2026 10:21:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379720; bh=skAJDTYkNXMNaEyJqfYS9TuvHMErvxOUqnLeD0Y0BP4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=tt91gLyxffuIptQcdRqbulmH0oMlbJu/0KzTM/hsLyeNmbiXytwbg64MvsaCwET4a CiXGGoNMSHi4CNGwqfDmHzR6cqPZlP6K/jeIPSK4d7GuyUtQWWmINa0KQDpfOOD2C0 lAeC4boJQO9/DPb8YV16RLOppcU5NPMOj/sKmZRc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Vadim Fedorenko , James Hilliard , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6 0058/1167] ptp: drain virtual clock sysfs operations before unregistering children Date: Fri, 4 Dec 2026 18:51:25 +0900 Message-ID: <20261204100703.592303045@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: James Hilliard [ Upstream commit 0e4a135aebc7686286d87e286499ce55e5bd5aad ] Parent clock removal walks its virtual clocks before removing the n_vclocks sysfs attribute. The mutex taken by ptp_vclock_in_use() is released before that walk, so a concurrent sysfs deletion can pick the same child and unregister and free its ptp_vclock a second time. A reference held by the device iterator does not protect that separately allocated virtual clock. Remove n_vclocks before walking the children. Removing the attribute prevents new stores and drains stores already running, without holding n_vclocks_mux across a callback that needs that mutex. Skip virtual clocks, which do not have this attribute. This race was found by code inspection of virtual-clock registration failure cleanup and parent removal. Fixes: bfcbb76b0f59 ("ptp: unregister virtual clocks when unregistering physical clock.") Reviewed-by: Vadim Fedorenko Signed-off-by: James Hilliard Link: https://patch.msgid.link/20261026-ptp-vclock-sampling-v6-1-e705612541f1@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/ptp/ptp_clock.c | 5 +++++ drivers/ptp/ptp_private.h | 1 + drivers/ptp/ptp_sysfs.c | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index d252d018bfe77..d8e956b663c9a 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -373,6 +373,11 @@ static int unregister_vclock(struct device *dev, void *data) int ptp_clock_unregister(struct ptp_clock *ptp) { + /* + * Stop and drain virtual-clock creation and deletion before walking the + * children. Do not hold n_vclocks_mux while waiting for sysfs callbacks. + */ + ptp_vclock_remove_sysfs(ptp); if (ptp_vclock_in_use(ptp)) { device_for_each_child(&ptp->dev, NULL, unregister_vclock); } diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h index d5bf50ee33d48..5f3697c61e2b7 100644 --- a/drivers/ptp/ptp_private.h +++ b/drivers/ptp/ptp_private.h @@ -158,6 +158,7 @@ extern const struct attribute_group *ptp_groups[]; int ptp_populate_pin_groups(struct ptp_clock *ptp); void ptp_cleanup_pin_groups(struct ptp_clock *ptp); +void ptp_vclock_remove_sysfs(struct ptp_clock *ptp); struct ptp_vclock *ptp_vclock_register(struct ptp_clock *pclock); void ptp_vclock_unregister(struct ptp_vclock *vclock); diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c index 02111e6d87a10..5f81b06ebebc5 100644 --- a/drivers/ptp/ptp_sysfs.c +++ b/drivers/ptp/ptp_sysfs.c @@ -261,6 +261,12 @@ static ssize_t n_vclocks_store(struct device *dev, } static DEVICE_ATTR_RW(n_vclocks); +void ptp_vclock_remove_sysfs(struct ptp_clock *ptp) +{ + if (!ptp->is_virtual_clock) + device_remove_file(&ptp->dev, &dev_attr_n_vclocks); +} + static ssize_t max_vclocks_show(struct device *dev, struct device_attribute *attr, char *page) { -- 2.53.0