Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) (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 28727226534 for ; Wed, 11 Jun 2025 09:23:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=72.21.196.25 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749633824; cv=none; b=iHEeCuqnvK7x1toW3UjES19IFjH6C9+UIuun4rZpd4oF4kH5RvcfykYRtawQqC00bjFJvzmma2Uh5nuNCKSd+WztCvM5w7BWAaiGqo+HHP7FEeTwJsNQV7KvdxDh8JNBx5TvHslX5mcZJJvJQS7DG9g/+4gL7wdyc60sH0c0LDI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749633824; c=relaxed/simple; bh=J8XmalK6MbOm1ie8kcN5WGmUMUDUHea8EW/A9ylB228=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JWjsR13hZzJcd80+ldPSQnfQlT9JWnNDfvLB/2ooBq6vFOH4RwcKkRaX8FEfug5jaZU2F/igk9gnPUHyU4/11dPlzSEsa4tSJ17ojOQmcuUNoTEP6E9o0F2+zeGX8X2CGKqzEyAeoQ9XK+ISgiseiliqIo0+d3QNnjmReg6tWjw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=V6nOy0VH; arc=none smtp.client-ip=72.21.196.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="V6nOy0VH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1749633823; x=1781169823; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sU1MI44/hcKTCnvVrxhOeocOjlsqgDWbL9B3bn66tck=; b=V6nOy0VHQ/+GBlfYBE7k5WLsimPZU1uDHCtD6w5YSEFD9v10gfT59JAw NU90HMvvJlCjp824dUV63QJxKmuy5flGBJr1gFAxayiLVHTHGhBGGwhNw 1FmEIPn6hAKeortSI46lrbVsOSGzUKoN6Eat6trz7SFd2U1PkuiS5Ueel uvxDWmPKnKXZpKh6QntS/TzkNMZ0sEaFB4ZPLbP8f1JIsfMOqFBPxPodi MUNufo8iKQO2ItiWgpdN7di5ffP6Gc8tlVr1MORmNiuj2XqYYBaPPGMK/ 2z0LMhf47BwaSdO4TI+qkHWvFQgwUFK7JLsUpqgxPxi9qv/mQjYV17jDe w==; X-IronPort-AV: E=Sophos;i="6.16,227,1744070400"; d="scan'208";a="501884732" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jun 2025 09:23:40 +0000 Received: from EX19MTAEUC001.ant.amazon.com [10.0.43.254:1210] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.8.225:2525] with esmtp (Farcaster) id eb8461a0-f940-46f6-b120-fd52d2517bcf; Wed, 11 Jun 2025 09:23:39 +0000 (UTC) X-Farcaster-Flow-ID: eb8461a0-f940-46f6-b120-fd52d2517bcf Received: from EX19D005EUA002.ant.amazon.com (10.252.50.11) by EX19MTAEUC001.ant.amazon.com (10.252.51.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Wed, 11 Jun 2025 09:23:38 +0000 Received: from HFA15-G9FV5D3.amazon.com (10.85.143.176) by EX19D005EUA002.ant.amazon.com (10.252.50.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1544.14; Wed, 11 Jun 2025 09:23:27 +0000 From: David Arinzon To: David Miller , Jakub Kicinski , CC: David Arinzon , Eric Dumazet , Paolo Abeni , Simon Horman , "Richard Cochran" , "Woodhouse, David" , "Machulsky, Zorik" , "Matushevsky, Alexander" , Saeed Bshara , "Wilson, Matt" , "Liguori, Anthony" , "Bshara, Nafea" , "Schmeilin, Evgeny" , "Belgazal, Netanel" , "Saidi, Ali" , "Herrenschmidt, Benjamin" , "Kiyanovski, Arthur" , "Dagan, Noam" , "Bernstein, Amit" , "Agroskin, Shay" , "Ostrovsky, Evgeny" , "Tabachnik, Ofir" , "Machnikowski, Maciek" , Rahul Rameshbabu , Gal Pressman , Vadim Fedorenko , Andrew Lunn , Leon Romanovsky , Jiri Pirko Subject: [PATCH v12 net-next 2/9] net: ena: PHC silent reset Date: Wed, 11 Jun 2025 12:22:31 +0300 Message-ID: <20250611092238.2651-3-darinzon@amazon.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250611092238.2651-1-darinzon@amazon.com> References: <20250611092238.2651-1-darinzon@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-ClientProxiedBy: EX19D045UWA003.ant.amazon.com (10.13.139.46) To EX19D005EUA002.ant.amazon.com (10.252.50.11) Each PHC device kernel registration receives a unique kernel index, which is associated with a new PHC device file located at "/dev/ptp". This device file serves as an interface for obtaining PHC timestamps. Examples of tools that use "/dev/ptp" include testptp [1] and chrony [2]. A reset flow may occur in the ENA driver while PHC is active. During a reset, the driver will unregister and then re-register the PHC device with the kernel. Under race conditions, particularly during heavy PHC loads, the driver’s reset flow might complete faster than the kernel’s PHC unregister/register process. This can result in the PHC index being different from what it was prior to the reset, as the PHC index is selected using kernel ID allocation [3]. While driver rmmod/insmod are done by the user, a reset may occur at anytime, without the user awareness, consequently, the driver might receive a new PHC index after the reset, potentially compromising the user experience. To prevent this issue, the PHC flow will detect the reset during PHC destruction and will skip the PHC unregister/register calls to preserve the kernel PHC index. During the reset flow, any attempt to get a PHC timestamp will fail as expected, but the kernel PHC index will remain unchanged. [1]: https://github.com/torvalds/linux/blob/v6.1/tools/testing/selftests/ptp/testptp.c [2]: https://github.com/mlichvar/chrony [3]: https://www.kernel.org/doc/html/latest/core-api/idr.html Signed-off-by: Amit Bernstein Signed-off-by: David Arinzon --- drivers/net/ethernet/amazon/ena/ena_phc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/amazon/ena/ena_phc.c b/drivers/net/ethernet/amazon/ena/ena_phc.c index 612cf45e..5ce9a32d 100644 --- a/drivers/net/ethernet/amazon/ena/ena_phc.c +++ b/drivers/net/ethernet/amazon/ena/ena_phc.c @@ -108,6 +108,10 @@ static int ena_phc_register(struct ena_adapter *adapter) phc_info = adapter->phc_info; clock_info = &phc_info->clock_info; + /* PHC may already be registered in case of a reset */ + if (ena_phc_is_active(adapter)) + return 0; + phc_info->adapter = adapter; spin_lock_init(&phc_info->lock); @@ -134,7 +138,11 @@ static void ena_phc_unregister(struct ena_adapter *adapter) { struct ena_phc_info *phc_info = adapter->phc_info; - if (ena_phc_is_active(adapter)) { + /* During reset flow, PHC must stay registered + * to keep kernel's PHC index + */ + if (ena_phc_is_active(adapter) && + !test_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags)) { ptp_clock_unregister(phc_info->clock); phc_info->clock = NULL; } -- 2.47.1